SharedStateManagerClient

client. SharedStateManagerClient

Component dedicated at managing distributed states, accessible through common.SharedState instances, among the application.

An instance of SharedStateManagerClient is automatically created by the soundworks.Client at initialization (cf. client.Client#stateManager).

Tutorial: https://collective-soundworks.github.io/tutorials/state-manager.html

Constructor

new SharedStateManagerClient(id, transport)

Source:
See:
Parameters:
Name Type Description
id Number

Id of the node.

transport Object

Transport to use for synchronizing the state. Must implement a basic EventEmitter API.

Methods

(async) attach(schemaName, stateIdopt)

Source:
See:

Attach to an existing common.SharedState instance.

Parameters:
Name Type Attributes Default Description
schemaName String

Name of the schema as given on registration (cf. ServerStateManager)

stateId Object <optional>
null

Id of the state to attach to. If null, attach to the first state found with the given schema name (usefull for globally shared states owned by the server).

Returns:

(async) create(schemaName, initValuesopt)

Source:
See:

Create a common.SharedState instance from a previsouly registered schema.

Parameters:
Name Type Attributes Default Description
schemaName String

Name of the schema as given on registration (cf. ServerStateManager)

initValues Object <optional>
{}

Default values for the state.

Returns:

observe(callback)

Source:

Observe all the common.SharedState instances that are created on the network.

Example
this.client.stateManager.observe(async (schemaName, stateId, nodeId) => {
  if (schemaName === 'something') {
    const state = await this.client.stateManager.attach(schemaName, stateId);
    console.log(state.getValues());
  }
});
Parameters:
Name Type Description
callback client.SharedStateManagerClient~observeCallback

Function to be called when a new state is created on the network.

Type Definitions

(async) observeCallback(schemaName, stateId, nodeId)

Source:
Parameters:
Name Type Description
schemaName String

name of the schema

stateId Number

id of the state

nodeId Number

id of the node that created the state