Created
October 31, 2014 21:45
-
-
Save rileydutton/e744bb0ce7e911509195 to your computer and use it in GitHub Desktop.
Firebase latency
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 timeoutRef = new Firebase(window.FIREBASE_ROOT + window.campaign_storage_path + "/players/" + window.currentPlayer.id + "/lastActive"); | |
var timeoutTimeout; | |
var timeoutRefTimedOut = false; | |
$connerror = $("#connectionerror"); | |
var notifyInterrupted = function() { | |
console.log("Timeout ref showed error!"); | |
timeoutRefTimedOut = true; | |
$connerror.show(); | |
}; | |
var checkFbConnection = function() { | |
timeoutTimeout = setTimeout(notifyInterrupted, 20000); | |
var fbpingstart = new Date().getTime(); | |
timeoutRef.set(new Date().getTime(), function(error, dummy) { | |
window.firebaseLastPing = (new Date().getTime() - fbpingstart); | |
clearTimeout(timeoutTimeout); | |
if($connerror[0].style.display != "none") $connerror.hide(); | |
timeoutTimeout = false; | |
timeoutRefTimedOut = false; | |
setTimeout(checkFbConnection, 60000); //do it again in 30 seconds. | |
}); | |
} | |
checkFbConnection(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment