I'm currently developing an Apache Cordova app with Ionic Framework that should communicate through a WebSocket with my server and I use the Socket.Io library for it. Now there are two prolems I face:
When the app goes into the background (cordova pause
event), for example via the home or standby button, after a while, the socket gets closed & the client gets disconnected.
When I exit the app via the hardware back button on android devices, the socket even gets closed immediately.
What I have tried so far:
socket.io.reconnect()
or socket.io.connect()
when disconnect
event fires
same thing when $destroy
event on $scope
fires (Ionic works on top of AngularJS)
Basically I just want to keep the WebSocket connection alive once the app was started by the user until it is killed manually via a task manager or similar.
I've thoroughly searched every related question on here but they didn't fit my case. I really need this thing to work and would appreciate any help.
You should use signalr instead of websocket and disable the hardware back button using JavaScript in your app. Then, the connection should be able to keep alive in your case 1 & 2.
Signalr can use Websocket as well, but actually you don't need to choose it since signalr will choose the best available protocol for you.