Home HelloWorld! Doc API Examples GitHub

Example Timing Callback (multi-device)

setPointCallback and setIntervalCallback are simple tools inspired by setTimeout and setInterval. setPointCallback triggers a callback when the timing object passes by a specific point on the timeline. setIntervalCallback is associated with periodic points along the timeline.

Demo Tips

  • open this page on multiple devices (or at least multiple browser tabs) (simultaneously) to verify multi-device timing.
  • the timing provider is shared globally, so others might be playing with demo too…
  • try reloading the demo on one device/tab while the demo is running on others.

Demo

Timing Object

SetPointCallback

  • SetPointCallbackOnce generates a callback the first time position 4 is reached.
  • SetPointCallbackRepeat generates a callback every time position 6 is reached.

SetIntervalCallback

  • SetIntervalCallback is set up with length 6 and offset 2, generating periodical callbacks at ...,2,8,14,20,...

Callback Log

JavaScript

TIMINGSRC.setPointCallback(to, function () {
	append("point callback (once) at position " + to.query().position.toFixed(2));
}, 4);

TIMINGSRC.setPointCallback(to, function () {
    append("point callback (repeated) at position " + to.query().position.toFixed(2));
}, 6, {repeat:true});

TIMINGSRC.setIntervalCallback(to, function () {
    append("interval callback at position " + to.query().position.toFixed(2));
}, 6, {offset:2});