Skip to content

Instantly share code, notes, and snippets.

@rileydutton
Created October 31, 2014 21:45
Show Gist options
  • Save rileydutton/e744bb0ce7e911509195 to your computer and use it in GitHub Desktop.
Save rileydutton/e744bb0ce7e911509195 to your computer and use it in GitHub Desktop.
Firebase latency
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