Created
May 15, 2013 10:40
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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