Home HelloWorld! Doc API Examples GitHub

Timing Provider API

This describes the API of the Timing Provider, as required by the timingsrc library (i.e. Timing Object).

Timing Providers are implemented and instansiated by third party code. Timing provider objects are given to the timing object as parameter in the constructor.

TimingProviderState

The following values are used as readystates for the timing provider. TimingProviderState is available in timingsrc library. State OPEN indicates that properties skew and vector are available.

var TimingProviderState = Object.freeze({
    CONNECTING :"connecting",
    OPEN : "open",
    CLOSING : "closing",
	CLOSED : "closed"
});

StateVector

State vectors are communicated between timing provider and timing object. Timestamp defines a point in time when values for position, velocity and acceleration were|are|will-be valid. Timestamps (in seconds) are from the timing provider clock, i.e. clock_timingprovider = performance.now() + skew.

var vector = {
	position: 12.0,             // position (units)
	velocity: 1.0,              // velocity (units/second)
	acceleration : 0.0, 		// acceleration (units/second/second)
	timestamp : 123652365.234   // timestamp from timing provider clock (seconds)
};

.readyState

ReadyState property. Return current state of timing provider.

var state = timingProvider.readyState;

.skew

Getter property for current skew estimate of the timing provider. The skew estimate is defined as follows. clock_timingprovider = performance.now() + skew

var skew = timingProvider.skew;
  • return: {float} current skew estimat

.vector

Getter property for current vector of the timing provider.

var vector = timingProvider.vector;

.range

Getter property for range specified by timing provider

var range = timingProvider.range;

.update()

Update is used by the timing object to request modification to the current vector. For online timing providers, this request is likely forwarded to an online timing provider service for processing.

timingProvider.update(vector);
  • param:{StateVector} [vector] request modification as specified by vector.

State vectors given to update operation may be only be partially complete. For instance, the below operation only requests the position of the vector to be changed (leaving velocity and acceleration unchanged).

timingProvider.update({position:14.0});

Event types

Timing provider objects supports three event types [“readystatechange”, “skewchange”, “vectorchange”].

  • Event type “skewchange” is emitted whenever the skew property takes a new value.
  • Event type “vectorchange” is emitted whenever the vector property takes a new value.
  • Event type “readystatechange” is emmitted whenever the readyState of the timing provider changes.

Event handlers do not provide event arguments.

Timing providers do not implement initial events semantics for any of its events.

.on()

Registers an event handler on the timing object.

timingProvider.on(type, handler, ctx);
  • param: {String} [type] event type [“vectorchange” “skewchange” “readystatechange”]
  • param: {Function} [handler] event handler
  • param: optional {Object} [ctx] context for handler callback invocation, default is timing provider

.off()

Un-registers an event handler from the timing provider.

timingProvider.off(type, handler);
  • param: {String} [type] event type [“vectorchange” “skewchange” “readystatechange”]
  • param: {Function} [handler] event handler