SyncManager

SyncManager

Synchronizes arbitrary state between two or more ViewAR SL instances. Instances can both send and receive arbitrary
payloads to/from one another. Payloads must be serializable to JSON. Uses a centralized client-server architecture.

Extends

Members

syncId :string|null

Sync id of the active sync. Null if sync is currently not active.

Type:
  • string | null

Methods

_startLiveSync()

Stops running state synchronization. This function will prevent sending further data to the server but may not
prevent the executions of setters that have begun executing.

off(eventName, eventHandler)

Inherited From:
Parameters:
Name Type Description
eventName string
eventHandler function

on(eventName, eventHandler)

Inherited From:
Parameters:
Name Type Description
eventName string
eventHandler function

once(eventName, eventHandler)

Inherited From:
Parameters:
Name Type Description
eventName string
eventHandler function

register(propertyName, getternullable, setternullable)

Registers a state property for synchronization. The only mandatory thing is that the getter returns a value, either
plain or wrapped in a promise. Other than that, getters and setters are free to do any computation and data
manipulation required. Sync manager will wait for all getters to return before sending the data, and all setters to
return before being called again.

To avoid unexpected behavior this method should not be called while sync is running.

Parameters:
Name Type Attributes Description
propertyName string

name of the property

getter function <nullable>

function that retrieves the local value of the property. Can be either sync or async.

setter function <nullable>

function that updates the local value of the property. Can be either sync or async.

(async) startLiveSync(syncSessionId, paramsnullable)

Connects to the server and starts polling for changes using the given sync id. Other ViewAR SL instances that need
to communicate with this one must use the same sync session id.

Stops the running sync session before initializing the new one.

Parameters:
Name Type Attributes Description
syncSessionId string

name of the property

params SyncParams <nullable>

parameters of the sync session

unregister(propertyName)

Unregisters a registered state property.
To avoid unexpected behavior this method should not be called while sync is running.

Parameters:
Name Type Description
propertyName string

name of the property