Skip to content

Instantly share code, notes, and snippets.

@DeviaVir
Created May 15, 2013 10:40
Show Gist options
  • Save DeviaVir/5583089 to your computer and use it in GitHub Desktop.
Save DeviaVir/5583089 to your computer and use it in GitHub Desktop.
iOS devices kill JS execution the second you switch away, this function detects when the JS execution continues and automatically reconnects with socket.io
var browsers = {
isiOS: function() {
return ( navigator.userAgent.indexOf( 'iPad' ) > -1
|| navigator.userAgent.indexOf( 'iPhone' ) > -1
|| navigator.userAgent.indexOf( 'iPod' ) > -1 );
}
};
// Moving away from this tab..
if( browsers.isiOS() ) {
// Check if someone is switching tabs!
var Time = new Date().getTime()
, getTime = function( intTime ) {
var timeOut = setTimeout( function() {
getTime( Time );
}, 500 );
var intNow = new Date().getTime();
if( ( intNow - intTime ) > 1000 ) {
if( false === socket.connection.socket.connected )
socket.connection.socket.connect();
}
clearTimeout( timeOut );
Time = new Date().getTime();
var timeOut = setTimeout( function() {
getTime( Time );
}, 500 );
};
getTime( Time );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment