Hi guys!
I need a time counter (timer) that will continuously show time spent in session between two parties, let's call them: Master and Slave.
Only Master can manage the timer while Slave can only see it's state.
Master can start, stop and reset the timer at any desired point in time as well as update it on a one second interval.
The technique I've came up with seems to be working okay (as expected) for Master but on the Slave side it very often "misses the bits" as (I presume) updates are getting delayed and then grouped in "chunks":
function timer( callBack ) {
var currentTimer;
var sessionTimer = new Firebase( "https://SampleTimer.firebaseIO-demo.com" );
sessionTimer.on( "value", function ( timer ) {
if ( timer.val() === null ) {
if ( _isMaster() ) sessionTimer.set( 0 );
} else {
currentTimer = timer.val();
callBack( currentTimer );
}
});
if ( _isMaster() ) {
var masterTimer = window.setInterval( function() {
sessionTimer.set( currentTimer + 1 ) );
}, 1000 );
}
}
Now, how should I implement this so that both sides are synchronized - showing the very same state at any given point in time?
Thanks,
Miro