Issue
I am trying to learn using websockets in my app with ionic this one: https://www.npmjs.com/package/cordova-plugin-websocket and I copied the example below:
var ws = new WebSocket('ws://echo.websocket.org');
$scope.sendMessage = function(){
ws.send('test');
};
ws.onopen = function () { alert('open'); };
ws.onmessage = function (event) {
alert(event.data);
};
ws.onerror = function () { alert('error occurred!'); };
ws.onclose = function (event) { alert('close code=' + event.code); };
It seems to be ok, but when the connection is down how can I reconnect and how can I make this disponible for all my app?
Solution
You should be looking into Google Messaging Service (or Firebase Messaging Service) so you don't have to worry about disconnections. The thing with sockets, Cordova and Android, it won't work if your app goes into the background (the network connections are stopped) so it renders the whole thing useless.
Answered By - Eric
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.