0

I am developing an application with Phonegap and I am using websocket with AutobahnJS for the client application.

The remote websocket server is developed using PHP and Ratchet and runs over SSL, so I use wss:// for the connection.

The application runs well in the emulator (Android 4.4.2), but there is no way to make the connection to the websocket server using a real device that runs Android 4.0.4. The onOpen callback doensn't fire, only the onClose is called.

this.conn = new ab.Session(
  this.wsUri,
  function() { that.onOpen() },
  function() { that.onClose() },
  { // Additional parameters, we're ignoring the WAMP sub-protocol for older browsers
    'skipSubprotocolCheck': true
  }
);

To make the application work in the emulator I needed to install the websocket plugin.

So the question is:

is there any chance to use Autobahn and Websocket run on a device that runs Android 4.0.4?

Thanks in advance!

Sergio Rinaudo
  • 2,303
  • 15
  • 20

1 Answers1

2

Beginning with Android 4.4, WebView is based on Chromium (version 30), and includes native support for WebSocket.

Older versions of Android have WebView based on older version of WebKit and (as far as I know) lack support for native WebSocket: http://jimbergman.net/webkit-version-in-android-version/

Which means: you either need to use a WebSocket Plugin for Phonegap to add WebSocket to WebView OR wait for AutobahnJS finish the HTTP longpoll based fallback (under development) - and use a WAMP v2 server that supports WAMP-over-longpoll.

oberstet
  • 21,353
  • 10
  • 64
  • 97
  • Perhaps a dumb question but why do I need the plugin for Android 4.4.2 if it uses Chromium with native support? (without it is not working) And why it is not working on Android 4.0.4 if I have this plugin installed? – Sergio Rinaudo May 08 '14 at 19:49
  • No, you don't need any plugin with Android 4.4 - it definitely works without. I have tested a Phonegap wrapped HTML5 app using AutobahnJS on a Nexus 5. It works without issues. – oberstet May 08 '14 at 21:17
  • I just finished to doublecheck, on emulator device: Galaxy Nexus, target: Android 4.4.2 API 19 with knowledgecode plugin installed it works but *without* the plugin it doesn't. With android 4.0.4, emulator or real device, plugin or not, it does not work. I have latest Android skd tools (22.6.3) and platform-tools (19.0.1) installed. Did you test on Nexus emulator? Could you please show some code? Thanks – Sergio Rinaudo May 09 '14 at 01:08
  • I don't test in emulator (too slow) .. only real Nexus 5 device. Using AutobahnJS latest (https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.js) - you seem to be using old WAMP v1 AutobahnJS. For this project, I don't have published source code. However, the app is https://demo.crossbar.io/clandeck/ - open this, and in a 2nd browser e.g. http://wamp.ws/. This app works packaged via Phonegap without any plugins. – oberstet May 09 '14 at 09:32
  • You got it, I was using and old version of Autobahn and I didn't knew it... However I still have problem because Ratchet supports only WAMPv1 so with the update version of Autobahn just nothing works either in browser or in Phonegap :) I think if I want to play a bit with the websocket server I set up I have to make use of an old version of AutobahnJS and be advised that it will work only for Android >= 4.4.2 at the moment.. Anyway I appreciated a lot your answer, they helped me understand, thank you very much! – Sergio Rinaudo May 09 '14 at 23:59