{"action":"opened","issue":{"url":"https://api.github.com/repos/ably/ably-js/issues/99","labels_url":"https://api.github.com/repos/ably/ably-js/issues/99/labels{/name}","comments_url":"https://api.github.com/repos/ably/ably-js/issues/99/comments","events_url":"https://api.github.com/repos/ably/ably-js/issues/99/events","html_url":"https://github.com/ably/ably-js/issues/99","id":102524783,"number":99,"title":"Detection of connection state change is too slow","user":{"login":"mattheworiordan","id":43789,"avatar_url":"https://avatars.githubusercontent.com/u/43789?v=3","gravatar_id":"","url":"https://api.github.com/users/mattheworiordan","html_url":"https://github.com/mattheworiordan","followers_url":"https://api.github.com/users/mattheworiordan/followers","following_url":"https://api.github.com/users/mattheworiordan/following{/other_user}","gists_url":"https://api.github.com/users/mattheworiordan/gists{/gist_id}","starred_url":"https://api.github.com/users/mattheworiordan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattheworiordan/subscriptions","organizations_url":"https://api.github.com/users/mattheworiordan/orgs","repos_url":"https://api.github.com/users/mattheworiordan/repos","events_url":"https://api.github.com/users/mattheworiordan/events{/privacy}","received_events_url":"https://api.github.com/users/mattheworiordan/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ably/ably-js/labels/bug","name":"bug","color":"e11d21"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-22T10:53:49Z","updated_at":"2015-08-22T10:53:49Z","closed_at":null,"body":"Whilst testing the [mobile Cordova demo](https://github.com/ably/demo-mobile-phonegap-cordova) in my browser, I see that the connection state change detection is far too slow to be useful.\r\n\r\nI have compared this to the web versions of WhatsApp and Slack, and the results vary quite a lot.  WhatsApp literally detects the Wifi connection being turned off immediately, Slack takes a good 10s or so, and it seems like our Cordova demo almost never detects that the connection is gone.  See https://dl.dropboxusercontent.com/u/1575409/Screenshots/video-capture-connection-state.mov.\r\n\r\nThe connection state does eventually drop, but it takes far too long.  I have not tested this in Cordova yet, but I expect we will need to add code specific to Cordova to detect network state, fortunately Cordova provides this already, see http://cordova.apache.org/docs/en/2.4.0/cordova_events_events.md.html#offline.\r\n\r\nI expect we need to approach this in a number of ways:\r\n\r\n* Catch online / offline events from the device if available\r\n  * Browsers http://html5-demos.appspot.com/static/navigator.onLine.html (very well supported in browsers it seems, https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/onLine)\r\n  * Cordova http://cordova.apache.org/docs/en/2.4.0/cordova_events_events.md.html#offline\r\n* Detect a lack of heartbeat (perhaps increase the frequency for browser connections, can we specify a param in the connection?) and then check if the internet up check passes, if not, assume we are disconnected.\r\n* See if we can tweak the transports we use to be more sensitive to changing connection state?\r\n\r\n@paddybyers thoughts?"}}