-
Notifications
You must be signed in to change notification settings - Fork 55
TimerAPI
Timers are created on the server with cloak.createTimer
. See ServerAPI.
Timers attempt to compensate for network latency when synchronizing with the client.
The 3 parameters when creating a timer are:
-
name
the name of the timer. It is used fortimer.sync
-
millis
the starting value of the timer -
descending
if the timer value decreases over time, rather than increasing (a countdown vs a stopwatch)
// On the server
var timer = cloak.createTimer('myTimer');
timer.start();
// later
timer.sync(user);
// Client configuration
client.configure({
...
timerEvents: {
myTimer: function(millis) {
console.log('myTimer value: ' + millis);
}
}
});
If the user's client has a timer event handler with the same name as this timer, that event handler is called. Timer event handlers are declared in the timerEvents
section of the ClientConfiguration. The argument to the event handler is the current milliseconds value of the timer. The timer.sync
method attempts to compensate for network latency.
Start the timer. Timers are initially stopped.
Stop the timer.
Get the current milliseconds value of the timer.
Stop the timer and set its value to millis
. If millis
is omitted, sets the timer to the last value it was reset with or the value it was created with.
All documentation on this wiki is licensed under a Creative Commons Attribution 3.0 Unported License. To attribute simply link to this wiki.