janpantel / angular-sails

An angular module for using the sails socket.io api
MIT License
307 stars 56 forks source link

cant force reconnect #72

Closed oriefrati closed 9 years ago

oriefrati commented 9 years ago

Hi, im developing app using phonegap, in IOS there is issue, that if you minimize the app and using other apps, the connection to the server stops after 2 min. when im open again the app, the socket disconnected and cant reconnect again.

how can i solve this issue and force reconnect to the socket?

TheSharpieOne commented 9 years ago

You can use $sails.connect() which will eventually call sail.io.js's _connect() method which will, in the end connect with a new socket. One advantage to doing it this is that it will attempt to reply and thing that you did while the socket was disconnected. But you will lose any registered events, as they would have been registered with the old socket, not the new.

Another way it to access the raw socket functions and use socket.io's reconnect function directly. You can do this with $sails.socket._raw.io.reconnect(). This will not reply your events, but should be any registered events registered. Note: Since socket.io's client-sdie API docs are horrible and only list options and events (not methods), I am not 100% sure if it is $sails.socket._raw.io.reconnect() or $sails.socket._raw.reconnect() (without the io.). I based that on this stackoverflow answer which pertains to socket.io v1.0(+) which is used by sails.io.js

TheSharpieOne commented 9 years ago

Closing: Inactive.