Time control object
The createTimeControl()
function returns a time control object to manage clocks, timers, and countdowns.
Return
object
: Time control object
Properties
allowBackwardsJump
Boolean
false
(default)
Allows the timer to jump backward due to network latency when restarting or continue playing a paused timer.
intervalID
Integer
The interval ID (internal).
intervalTime
Integer
10, 100, 1000
Interval time in [ms].
offsetToServerTime
Integer
The time offset of a local browser to Singular server time.
roundToInterval
Boolean
true
(default)
Rounds time to the next interval.
tc
Object
{
"UTC": 0,
"isRunning": false,
"value": 0
}
The time control object. UTC: UTC start time [ms]; isRunning: boolean; value: offset in [ms]
timeoutID
Integer
The timeout ID (internal).
updateCallback
Function
A callback function triggered at every interval.
Methods
getCurrentTime()
Returns the current running time of the timer in [ms].
Return
integer
: time in [ms]
setAllowBackwardsJump()
Due to a slow internet connection and/or network latency, clocks can jump backwards when starting, pausing, or restarting. Use the setAllowBackwardsJump()
call to set this behavior.
Parameter
allowBackwardsJump
Boolean
false
: (default) don't allow backwards jump
true
: allow backwards jump
Return
none
setIntervalTime()
Sets the interval frequency for the timer.
Parameter
tInterval
Number
The interval duration in [ms].
Return
none
setOffsetToServerTime()
Sets the offset from the local browser to the Singular server time.
Parameter
tOffset
Number
Offset from the local browser time to the Singular server time.
Return
none
setRoundToInterval()
Rounds the time to the interval frequency.
Parameter
doRounding
Boolean
true
: (default) round time to interval frequency
false
: do not round time
Return
none
setTimeControl()
The time control object defines the current timer state.
Parameter
tc
object
The time control object.
Return
none
setUpdateCallback()
Sets the time control callback function. This function is called at every interval.
Parameter
cb
function
The callback function.
Return
none
Last updated