Websocket with old (4.1 - 4.4) Android API


#1

Hey Guys,
i’m writing my first App in Ionic (with AngularJS) and i’m using WebSockets (ng-websocket) to communicate with my Server Application.
The problem is, that WebSockets are not available in older Versions of Android, so i get this Error message:

E/Web Console﹕ Uncaught ReferenceError: WebSocket is not defined at file:///android_asset/www/lib/ng-websocket/ng-websocket.js:130

in my Log Files on my 4.1.1 emulator. So I found Cordova plugins like WebSocket-for-Android and phonegap-websocket. I installed them both (not at same time) with:

cordova plugin add https://github.com/mkuklis/phonegap-websocket
cordova plugin add cordova-plugin-websocket

but my App is still not working :confused: Can anyone help me with this problem?
Is there plugin that actually works?


#2

I would suggest you try CrossWalk:
http://blog.ionic.io/crosswalk-comes-to-ionic/
This will allow you to run almost the latest Chromium (Chrome) version on Android, that supports websocket.
Only downside is that the final build of application (APK) will be larger for 10-15mb than your current one.


#3

thanks for the information, i already tried this but my team doesn’t want the bigger apk :confused:
But after playing around a little with $ionicPlatform.ready i now got the Plugin working :smile: