Page 1 of 1

Websockets, Android and Phonegap

Posted: Mon Jun 30, 2014 10:35 pm
by msabatini
Hi, I know that mine is a very particular situation, but I'm asking if anybody has ever had to do with programming Phonegap webapps with websocket communication to Airconsole.
The situation is:
if I run the websockets Airconsole demo in an android phone starting from chrome browser, after having transferred .html and .js file onto the phone and opening the .html file by using file:///<path to the html file>, and after having connected in wi-fi to the airconsole, everything is ok.
Then I try to package a webapp with phonegap, and, using the cloud compiler build.phonegap.com after having configured the websocket plugin available, I can build an apk that I can install to the smartphone. The webapp so built uses the android webview component, that, itself, seems to be not providing websocket support, so the plugin comes to help.
But the connection isn't working, and it stops just as soon as
this.websocket = new WebSocket(uri, protocol);
is called in the connect function. As I only use console logs to debug the app, I cannot know why the call is failing, I can only see that the last log is the one before that call.
Thank you for any help and sorry for the very strange situation, but I think it may occur to someone else so I posted the question.
Bye

Re: Websockets, Android and Phonegap

Posted: Tue Jul 01, 2014 9:43 am
by simon
Hi

Were looking at an SDK extension to support PhoneGap. Were guessing that the Websocket support in PhoneGap uses a slightly different syntax than that used in IE/Firefox/Chrome which is probably causing the issue you are facing. Will have a look and see how easy it is to support.

Thanks
Simon Hope

Re: Websockets, Android and Phonegap

Posted: Tue Jul 01, 2014 7:04 pm
by msabatini
Hi Simon
thanks for your help, I just wanted to add this information: I packaged an app with phonegap that makes only a connection to http://www.websocket.org/echo.html and it doesn't work, so this issue is definitely due to the android webview component that currently (at least for 4.3.x and before) doesn't support websockets. I verified that from 4.4.x that app is working, as webview is chrome-based, so it does support websockets.
That SDK extension you were talking about could be some sort of workaround?
Thank you

Re: Websockets, Android and Phonegap

Posted: Thu Jul 03, 2014 3:31 am
by msabatini
Update: I managed to have the phonegap websocket plugin (https://github.com/mkuklis/phonegap-websocket) working, but there's a strange behaviour, even in the echo app I packaged: the connection is established, the test message is sent, but nothing is received.
But, once again, it's and android < 4.4 issue with websockets, you can try even going with chrome to http://www.websocket.org/echo.html: receive doesn't work. It's not related to airconsole, but I will keep you up to date just in case anyone has the same problems.

Update: it seems that wss:// connection works correctly.

Update: wss works correctly with the echo test in http://www.websocket.org/echo.html, doesn't work with airconsole.
If I won't manage to find a solution, I will write a new thread.