zhukov / webogram

Telegram web application, GPL v3
https://web.telegram.org
GNU General Public License v3.0
7.95k stars 2.36k forks source link

Description of new JavaScript features used by webogram #781

Closed pattyland closed 8 years ago

pattyland commented 9 years ago

Hi there, awesome App you've made. I would like to use it under for HP webOS (If you don't know that, it's pretty much like Firefox OS but from 2012). The challenge is that webOS is not supporting all the cool new JavaScript Features you are using, but I think there could be a way, but not using the normal http://web.telegram.org/ but packaging it and modyfing it.

First error I got was "ArrayBuffer is not defined", my solution was using a TypedArray Polyfill from https://github.com/inexorabletash/polyfill/blob/master/polyfill.js Then I got Network errors, pretty much like #516. According to your comment, I added Blob.js a a Polyfill for Blob too: https://github.com/eligrey/Blob.js/

Unfortunately I'm still unable to get any further than generating my keys, here's an excerpt from the log, maybe you've an idea:

2015-04-20T22:00:12.737907Z [718] qemux86 user.notice LunaSysMgr: {LunaSysMgrJS}: de.pattyland.telegram: [18.851], file:///media/cryptofs/apps/usr/palm/applications/de.pattyland.telegram/js/app.js:12
2015-04-20T22:00:33.787961Z [739] qemux86 user.notice LunaSysMgr: {LunaSysMgrJS}: de.pattyland.telegram: [39.901], file:///media/cryptofs/apps/usr/palm/applications/de.pattyland.telegram/js/app.js:12
2015-04-20T22:00:33.788501Z [739] qemux86 user.notice LunaSysMgr: {LunaSysMgrJS}: de.pattyland.telegram: Get networker error, file:///media/cryptofs/apps/usr/palm/applications/de.pattyland.telegram/js/app.js:12
2015-04-20T22:00:33.789248Z [739] qemux86 user.notice LunaSysMgr: {LunaSysMgrJS}: de.pattyland.telegram: sendCode error, file:///media/cryptofs/apps/usr/palm/applications/de.pattyland.telegram/js/app.js:14

Or maybe you've a list of features you use, and I can make a test somewhere like Modernizr and see what feaures I have to polyfill?

Greets, pattyland

Just in case you would like to chat with me: https://telegram.me/pattyland ;)

zhukov commented 9 years ago

How are you building the app?

zhukov commented 9 years ago

I would advise to find the code with Get networker error and sendCode error and add breakpoint / improve logging. Your logs shows only the first string argument passed to console.log and we need info from 2nd+.

pattyland commented 9 years ago

First of all thanks for your fast response!

Building for webOS requires a appinfo files which defines metadata like author and startfile (defaulting to index.html, perfect for webogram) and a simple build script from the SDK, which simply pack all files into an ipk file.

Nice idea! The log output is getting the error object e and e.stack. e.stack is undefined, and JSON.stringify(e) is:

[20150422-22:15:28.162177] info: {     "code": 406,     "type": "NETWORK_BAD_REQUEST",     "originalError": {         "data": "<html>\r\n<head><title>404 Not Found</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>404 Not Found</h1></center>\r\n<hr><center>nginx/0.3.33</center>\r\n</body>\r\n</html>\r\n",         "status": 404,         "config": {             "method": "POST",             "transformRequest": null,             "transformResponse": [                 null             ],             "responseType": "arraybuffer",             "url": "http://149.154.167.51:80/apiw1",             "data": {},             "headers": {}         },         "statusText": ""     } }, js/app.js:21,559

It's pretty much the same like the notification I get in the webapp:

Method: help.getNearestDc
Result: {"data":"<html>\r\n<head><title>404 Not Found</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>404 Not Found</h1></center>\r\n<hr><center>nginx/0.3.33</center>\r\n</body>\r\n</html>\r\n","status":404,"config":{"method":"POST","transformRequest":null,"transformResponse":[null],"responseType":"arraybuffer","url":"http://149.154.167.51:80/apiw1","data":{},"headers":{}},"statusText":""}
Stack: Error
at file:///media/cryptofs/apps/usr/palm/applications/de.pattyland.telegram/js/app.js:21575:129
at file:///media/cryptofs/apps/usr/palm/applications/de.pattyland.telegram/js/app.js:21636:17
at c (file:///media/cryptofs/apps/usr/palm/applications/de.pattyland.telegram/js/app.js:13620:42)
at file:///media/cryptofs/apps/usr/palm/applications/de.pattyland.telegram/js/app.js:13629:21
at u.$eval (file:///media/cryptofs/apps/usr/palm/applications/de.pattyland.telegram/js/app.js:13952:35)
at u.$digest (file:///media/cryptofs/apps/usr/palm/applications/de.pattyland.telegram/js/app.js:13910:60)
at u.$apply (file:///media/cryptofs/apps/usr/palm/applications/de.pattyland.telegram/js/app.js:13973:35)
at l (file:///media/cryptofs/apps/usr/palm/applications/de.pattyland.telegram/js/app.js:12930:126)
at _ (file:///media/cryptofs/apps/usr/palm/applications/de.pattyland.telegram/js/app.js:13010:155)
at XMLHttpRequest.onreadystatechange (file:///media/cryptofs/apps/usr/palm/applications/de.pattyland.telegram/js/app.js:13030:170)

For the reference, I'm using the last Firefox Marketplace release 0.3.2 because I think it would be a starting point if it runs under Firefox OS

zhukov commented 9 years ago

I guess, the problem is that we need to send binary data and receive binary data. Check the https://github.com/zhukov/webogram/blob/master/app/js/lib/mtproto.js file for $http.post calls.

      requestPromise =  $http.post(MtpDcConfigurator.chooseServer(dcID), requestData, {
        responseType: 'arraybuffer',
        transformRequest: null
      });

Here requestData is a arraybuffer / bytearray. I guess webOS doesn't have support for it. You can try to convert it to string and pass the string here.

zhukov commented 9 years ago

The docs that might be useful: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data

zhukov commented 9 years ago

Actually I think, that you make a good thing. It would be very good if we make it work in older browsers without binary data support. The task might be difficult, however I believe it's not impossible.

saradotramli commented 9 years ago

Hi, I am making a similar attempt to PattyLand's to port it to legacy WebOS devices and have run into the same problem (404 error). I am right now testing it in Firefox (latest version) and hence the ArrayBuffer is very much available.

To be precise, the first few (3) handshake calls in getting the authorization code, etc go through fine as expected. The auth.SendCode request is what fails. Tried replacing it with auth.checkPhone and the same result.

Is there a way to get a more descriptive error message from the server? Or a possibility to look at client-specifc log messages on the server? Without similar means, I believe development by any third-party is going to be a very challenging task. Kindly suggest.

zhukov commented 9 years ago

@saradotramli can you host it somewhere so I can debug a little? What were your changes? Did you successfully generate auth_key? (you can check it in localStorage.dc*_auth_key)