@soundworks/core 4.0.0-alpha.28 → 4.0.0-alpha.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsdoc +3 -1
- package/CHANGELOG.md +11 -5
- package/package.json +5 -5
- package/src/client/Client.js +78 -83
- package/src/client/{Context.js → ClientContext.js} +48 -38
- package/src/client/ClientContextManager.js +115 -0
- package/src/client/{Plugin.js → ClientPlugin.js} +22 -18
- package/src/client/{PluginManager.js → ClientPluginManager.js} +39 -35
- package/src/client/{Socket.js → ClientSocket.js} +54 -65
- package/src/client/{StateManager.js → ClientStateManager.js} +7 -8
- package/src/client/index.js +17 -41
- package/src/common/BasePlugin.js +56 -51
- package/src/common/BasePluginManager.js +175 -139
- package/src/common/BaseStateManager.js +316 -120
- package/src/common/BatchedTransport.js +24 -24
- package/src/common/ParameterBag.js +18 -6
- package/src/common/PromiseStore.js +1 -0
- package/src/common/{BaseSharedState.js → SharedState.js} +271 -199
- package/src/common/{BaseSharedStateCollection.js → SharedStateCollection.js} +92 -61
- package/src/common/logger.js +5 -0
- package/src/common/shared-state-types.js +76 -0
- package/src/common/version.js +1 -1
- package/src/server/Server.js +391 -354
- package/src/server/ServerClient.js +73 -0
- package/src/server/{Context.js → ServerContext.js} +85 -66
- package/src/server/{ContextManager.js → ServerContextManager.js} +98 -85
- package/src/server/{Plugin.js → ServerPlugin.js} +10 -24
- package/src/server/{PluginManager.js → ServerPluginManager.js} +76 -69
- package/src/server/{Socket.js → ServerSocket.js} +19 -18
- package/src/server/{Sockets.js → ServerSockets.js} +36 -27
- package/src/server/ServerStateManager.js +515 -0
- package/src/{common → server}/SharedStatePrivate.js +61 -26
- package/src/server/audit-schema.js +1 -1
- package/src/server/crypto.js +2 -0
- package/src/server/index.js +18 -21
- package/types/client/Client.d.ts +74 -95
- package/types/client/{Context.d.ts → ClientContext.d.ts} +25 -26
- package/types/client/{ContextManager.d.ts → ClientContextManager.d.ts} +19 -22
- package/types/client/{Plugin.d.ts → ClientPlugin.d.ts} +17 -20
- package/types/client/{PluginManager.d.ts → ClientPluginManager.d.ts} +13 -36
- package/types/client/ClientSocket.d.ts +74 -0
- package/types/client/{StateManager.d.ts → ClientStateManager.d.ts} +11 -15
- package/types/client/index.d.ts +26 -2
- package/types/common/BasePlugin.d.ts +52 -46
- package/types/common/BasePluginManager.d.ts +68 -44
- package/types/common/BaseStateManager.d.ts +207 -97
- package/types/common/BatchedTransport.d.ts +1 -5
- package/types/common/ParameterBag.d.ts +16 -18
- package/types/common/PromiseStore.d.ts +1 -1
- package/types/common/SharedState.d.ts +297 -0
- package/types/common/{BaseSharedStateCollection.d.ts → SharedStateCollection.d.ts} +34 -18
- package/types/common/constants.d.ts +0 -2
- package/types/common/logger.d.ts +2 -1
- package/types/common/shared-state-types.d.ts +83 -0
- package/types/common/sockets-utils.d.ts +0 -5
- package/types/common/version.d.ts +1 -2
- package/types/server/Server.d.ts +78 -132
- package/types/server/ServerClient.d.ts +45 -0
- package/types/server/{Context.d.ts → ServerContext.d.ts} +53 -43
- package/types/server/ServerContextManager.d.ts +80 -0
- package/types/server/{Plugin.d.ts → ServerPlugin.d.ts} +19 -33
- package/types/server/{PluginManager.d.ts → ServerPluginManager.d.ts} +39 -37
- package/types/server/ServerSocket.d.ts +85 -0
- package/types/server/ServerSockets.d.ts +50 -0
- package/types/server/ServerStateManager.d.ts +189 -0
- package/types/server/SharedStatePrivate.d.ts +21 -0
- package/types/server/audit-network-latency.worker.d.ts +1 -2
- package/types/server/audit-schema.d.ts +0 -1
- package/types/server/crypto.d.ts +2 -1
- package/types/server/index.d.ts +24 -2
- package/src/client/ContextManager.js +0 -111
- package/src/client/SharedState.js +0 -84
- package/src/client/SharedStateCollection.js +0 -38
- package/src/server/Client.js +0 -55
- package/src/server/SharedState.js +0 -85
- package/src/server/SharedStateCollection.js +0 -39
- package/src/server/StateManager.js +0 -696
- package/types/client/Client.d.ts.map +0 -1
- package/types/client/Context.d.ts.map +0 -1
- package/types/client/ContextManager.d.ts.map +0 -1
- package/types/client/Plugin.d.ts.map +0 -1
- package/types/client/PluginManager.d.ts.map +0 -1
- package/types/client/SharedState.d.ts +0 -85
- package/types/client/SharedState.d.ts.map +0 -1
- package/types/client/SharedStateCollection.d.ts +0 -41
- package/types/client/SharedStateCollection.d.ts.map +0 -1
- package/types/client/Socket.d.ts +0 -149
- package/types/client/Socket.d.ts.map +0 -1
- package/types/client/StateManager.d.ts.map +0 -1
- package/types/client/index.d.ts.map +0 -1
- package/types/common/BasePlugin.d.ts.map +0 -1
- package/types/common/BasePluginManager.d.ts.map +0 -1
- package/types/common/BaseSharedState.d.ts +0 -244
- package/types/common/BaseSharedState.d.ts.map +0 -1
- package/types/common/BaseSharedStateCollection.d.ts.map +0 -1
- package/types/common/BaseStateManager.d.ts.map +0 -1
- package/types/common/BatchedTransport.d.ts.map +0 -1
- package/types/common/ParameterBag.d.ts.map +0 -1
- package/types/common/PromiseStore.d.ts.map +0 -1
- package/types/common/SharedStatePrivate.d.ts +0 -21
- package/types/common/SharedStatePrivate.d.ts.map +0 -1
- package/types/common/constants.d.ts.map +0 -1
- package/types/common/logger.d.ts.map +0 -1
- package/types/common/sockets-utils.d.ts.map +0 -1
- package/types/common/version.d.ts.map +0 -1
- package/types/server/Client.d.ts +0 -45
- package/types/server/Client.d.ts.map +0 -1
- package/types/server/Context.d.ts.map +0 -1
- package/types/server/ContextManager.d.ts +0 -69
- package/types/server/ContextManager.d.ts.map +0 -1
- package/types/server/Plugin.d.ts.map +0 -1
- package/types/server/PluginManager.d.ts.map +0 -1
- package/types/server/Server.d.ts.map +0 -1
- package/types/server/SharedState.d.ts +0 -86
- package/types/server/SharedState.d.ts.map +0 -1
- package/types/server/SharedStateCollection.d.ts +0 -41
- package/types/server/SharedStateCollection.d.ts.map +0 -1
- package/types/server/Socket.d.ts +0 -164
- package/types/server/Socket.d.ts.map +0 -1
- package/types/server/Sockets.d.ts +0 -80
- package/types/server/Sockets.d.ts.map +0 -1
- package/types/server/StateManager.d.ts +0 -405
- package/types/server/StateManager.d.ts.map +0 -1
- package/types/server/audit-network-latency.worker.d.ts.map +0 -1
- package/types/server/audit-schema.d.ts.map +0 -1
- package/types/server/crypto.d.ts.map +0 -1
- package/types/server/index.d.ts.map +0 -1
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/** @private */
|
|
2
|
-
class ContextCollection {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.inner = [];
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
add(context) {
|
|
8
|
-
this.inner.push(context);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
has(name) {
|
|
12
|
-
return this.inner.find(c => c.name === name) !== undefined;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
get(name) {
|
|
16
|
-
return this.inner.find(c => c.name === name);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
map(func) {
|
|
20
|
-
return this.inner.map(func);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Manage the different contexts and their lifecycle.
|
|
26
|
-
*
|
|
27
|
-
* See {@link client.Client#contextManager}
|
|
28
|
-
*
|
|
29
|
-
* _WARNING: In most cases, you should not have to manipulate the context manager directly._
|
|
30
|
-
*
|
|
31
|
-
* @memberof client
|
|
32
|
-
* @hideconstructor
|
|
33
|
-
*/
|
|
34
|
-
class ContextManager {
|
|
35
|
-
constructor() {
|
|
36
|
-
/** @private */
|
|
37
|
-
this._contexts = new ContextCollection();
|
|
38
|
-
/** @private */
|
|
39
|
-
this._contextStartPromises = new Map();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Register the context into the manager. Is called in context constructor.
|
|
44
|
-
*
|
|
45
|
-
* @param {client.Context} context - The context to be registered.
|
|
46
|
-
* @private
|
|
47
|
-
*/
|
|
48
|
-
register(context) {
|
|
49
|
-
if (this._contexts.has(context.name)) {
|
|
50
|
-
throw new Error(`[soundworks:context-manager] Context "${context.name}" already registered`);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
this._contexts.add(context);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Retrieve a started context from its name.
|
|
58
|
-
*
|
|
59
|
-
* _WARNING: Most of the time, you should not have to call this method manually._
|
|
60
|
-
*
|
|
61
|
-
* @param {client.Context#name} contextName - Name of the context.
|
|
62
|
-
*/
|
|
63
|
-
async get(contextName) {
|
|
64
|
-
if (!this._contexts.has(contextName)) {
|
|
65
|
-
throw new Error(`[soundworks:ContextManager] Can't get context "${contextName}", not registered`);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const context = this._contexts.get(contextName);
|
|
69
|
-
|
|
70
|
-
if (this._contextStartPromises.has(contextName)) {
|
|
71
|
-
const startPromise = this._contextStartPromises.get(contextName);
|
|
72
|
-
await startPromise;
|
|
73
|
-
} else {
|
|
74
|
-
context.status = 'inited';
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
const startPromise = context.start();
|
|
78
|
-
this._contextStartPromises.set(contextName, startPromise);
|
|
79
|
-
await startPromise;
|
|
80
|
-
context.status = 'started';
|
|
81
|
-
} catch (err) {
|
|
82
|
-
context.status = 'errored';
|
|
83
|
-
throw new Error(err);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return context;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Start all registered contexts. Called during `client.start()`
|
|
92
|
-
*
|
|
93
|
-
* @private
|
|
94
|
-
*/
|
|
95
|
-
async start() {
|
|
96
|
-
const promises = this._contexts.map(context => this.get(context.name));
|
|
97
|
-
await Promise.all(promises);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Stop all registered contexts. Called during `client.stop()`
|
|
102
|
-
*
|
|
103
|
-
* @private
|
|
104
|
-
*/
|
|
105
|
-
async stop() {
|
|
106
|
-
const promises = this._contexts.map(context => context.stop());
|
|
107
|
-
await Promise.all(promises);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export default ContextManager;
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import BaseSharedState from '../common/BaseSharedState.js';
|
|
2
|
-
|
|
3
|
-
// this file exists only for documentation purposes
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @callback client.SharedState~onUpdateCallback
|
|
7
|
-
* @param {Object} newValues - Key / value pairs of the updates that have been
|
|
8
|
-
* applied to the state.
|
|
9
|
-
* @param {Object} oldValues - Key / value pairs of the updated params before
|
|
10
|
-
* the updates has been applied to the state.
|
|
11
|
-
* @param {Mixed} [context=null] - Optionnal context object that has been passed
|
|
12
|
-
* with the values updates in the `set` call.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Delete the registered {@link client.SharedState~onUpdateCallback}.
|
|
17
|
-
*
|
|
18
|
-
* @callback client.SharedState~deleteOnUpdateCallback
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* The `SharedState` is one of the most important and versatile abstraction provided
|
|
24
|
-
* by `soundworks`. It represents a set of parameters that are synchronized accross
|
|
25
|
-
* every nodes of the application (clients and server) that declared some interest
|
|
26
|
-
* to the shared state.
|
|
27
|
-
*
|
|
28
|
-
* A `SharedState` is created according to a "schema" (in the sense of a database
|
|
29
|
-
* schema) that must be declared and registered server-side. Any number of `SharedState`s
|
|
30
|
-
* can be created from a single schema.
|
|
31
|
-
*
|
|
32
|
-
* A shared state can be created both by the clients or by the server (in which case
|
|
33
|
-
* it is generally considered as a global state of the application). Similarly any
|
|
34
|
-
* node of the application (clients or server) can declare interest and "attach" to
|
|
35
|
-
* a state created by another node. All node attached to a state can modify its values
|
|
36
|
-
* and/or react to the modifications applied by other nodes.
|
|
37
|
-
*
|
|
38
|
-
* Tutorial: {@link https://soundworks.dev/guide/state-manager.html}
|
|
39
|
-
*
|
|
40
|
-
* ```
|
|
41
|
-
* // server-side
|
|
42
|
-
* import { Server } from '@soundworks/server/index.js';
|
|
43
|
-
*
|
|
44
|
-
* const server = new Server(config);
|
|
45
|
-
* // declare and register the schema of a shared state.
|
|
46
|
-
* server.stateManager.registerSchema('some-global-state', {
|
|
47
|
-
* myRandom: {
|
|
48
|
-
* type: 'float',
|
|
49
|
-
* default: 0,
|
|
50
|
-
* }
|
|
51
|
-
* });
|
|
52
|
-
*
|
|
53
|
-
* await server.start();
|
|
54
|
-
*
|
|
55
|
-
* // create a global state server-side
|
|
56
|
-
* const globalState = await server.stateManager.create('some-global-state');
|
|
57
|
-
* // listen and react to the changes made by the clients
|
|
58
|
-
* globalState.onUpdate(updates => console.log(updates));
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
* ```
|
|
62
|
-
* // client-side
|
|
63
|
-
* import { Client } from '@soundworks/client.index.js';
|
|
64
|
-
*
|
|
65
|
-
* const client = new Client(config);
|
|
66
|
-
* await client.start();
|
|
67
|
-
*
|
|
68
|
-
* // attach to the global state created by the server
|
|
69
|
-
* const globalState = await client.stateManager.attach('some-global-state');
|
|
70
|
-
*
|
|
71
|
-
* // update the value of a `myRandom` parameter every seconds
|
|
72
|
-
* setInterval(() => {
|
|
73
|
-
* globalState.set({ myRandom: Math.random() });
|
|
74
|
-
* }, 1000);
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* @memberof client
|
|
78
|
-
* @extends BaseSharedState
|
|
79
|
-
* @inheritdoc
|
|
80
|
-
* @hideconstructor
|
|
81
|
-
*/
|
|
82
|
-
class SharedState extends BaseSharedState {}
|
|
83
|
-
|
|
84
|
-
export default SharedState;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import BaseSharedStateCollection from '../common/BaseSharedStateCollection.js';
|
|
2
|
-
|
|
3
|
-
// this file exists only for documentation purposesSharedStateCollection.js
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @callback client.SharedStateCollection~onUpdateCallback
|
|
7
|
-
* @param {client.SharedState} state - State that triggered the update.
|
|
8
|
-
* @param {Object} newValues - Key / value pairs of the updates that have been
|
|
9
|
-
* applied to the state.
|
|
10
|
-
* @param {Object} oldValues - Key / value pairs of the updated params before
|
|
11
|
-
* the updates has been applied to the state.
|
|
12
|
-
* @param {Mixed} [context=null] - Optionnal context object that has been passed
|
|
13
|
-
* with the values updates in the `set` call.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* The `SharedStateCollection` interface represent a collection of all states
|
|
18
|
-
* created from a given schema name on the network.
|
|
19
|
-
*
|
|
20
|
-
* It can optionnaly exclude the states created by the current node.
|
|
21
|
-
*
|
|
22
|
-
* See {@link client.StateManager#getCollection} for factory method API
|
|
23
|
-
*
|
|
24
|
-
* ```
|
|
25
|
-
* const collection = await client.stateManager.getCollection('my-schema');
|
|
26
|
-
* const allValues = collection.getValues();
|
|
27
|
-
* collection.onUpdate((state, newValues, oldValues, context) => {
|
|
28
|
-
* // do something
|
|
29
|
-
* });
|
|
30
|
-
* ```
|
|
31
|
-
* @memberof client
|
|
32
|
-
* @extends BaseSharedStateCollection
|
|
33
|
-
* @inheritdoc
|
|
34
|
-
* @hideconstructor
|
|
35
|
-
*/
|
|
36
|
-
class SharedStateCollection extends BaseSharedStateCollection {}
|
|
37
|
-
|
|
38
|
-
export default SharedStateCollection;
|
package/src/server/Client.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { idGenerator } from '@ircam/sc-utils';
|
|
2
|
-
import { v4 as uuid } from 'uuid';
|
|
3
|
-
|
|
4
|
-
const generateId = idGenerator();
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Server-side representation of a `soundworks` client.
|
|
8
|
-
*
|
|
9
|
-
* @memberof server
|
|
10
|
-
* @hideconstructor
|
|
11
|
-
* @see {@link client.Client}
|
|
12
|
-
*/
|
|
13
|
-
class Client {
|
|
14
|
-
/**
|
|
15
|
-
* @param {String} role - Role of the client
|
|
16
|
-
* @param {server.Socket} socket - Socket connection with the client
|
|
17
|
-
*/
|
|
18
|
-
constructor(role, socket) {
|
|
19
|
-
/**
|
|
20
|
-
* Client role, as specified in client side config {@link client.Client}.
|
|
21
|
-
*
|
|
22
|
-
* @type {String}
|
|
23
|
-
*/
|
|
24
|
-
this.role = role;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Session Id (incremented positive number).
|
|
28
|
-
*
|
|
29
|
-
* @type {Number}
|
|
30
|
-
*/
|
|
31
|
-
this.id = generateId.next().value;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Unique session Id (uuidv4).
|
|
35
|
-
*
|
|
36
|
-
* @type {String}
|
|
37
|
-
*/
|
|
38
|
-
this.uuid = uuid();
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Socket connection with the remote client {@link client.Client}.
|
|
42
|
-
*
|
|
43
|
-
* @type {server.Socket}
|
|
44
|
-
*/
|
|
45
|
-
this.socket = socket;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Is set in server._onSocketConnection
|
|
49
|
-
* @private
|
|
50
|
-
*/
|
|
51
|
-
this.token = null;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export default Client;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import BaseSharedState from '../common/BaseSharedState.js';
|
|
2
|
-
|
|
3
|
-
// this file exists only for documentation purposes
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @callback server.SharedState~onUpdateCallback
|
|
7
|
-
* @param {Object} newValues - Key / value pairs of the updates that have been
|
|
8
|
-
* applied to the state.
|
|
9
|
-
* @param {Object} oldValues - Key / value pairs of the updated params before
|
|
10
|
-
* the updates has been applied to the state.
|
|
11
|
-
* @param {Mixed} [context=null] - Optionnal context object that has been passed
|
|
12
|
-
* with the values updates in the `set` call.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Delete the registered {@link server.SharedState~onUpdateCallback}.
|
|
17
|
-
*
|
|
18
|
-
* @callback server.SharedState~deleteOnUpdateCallback
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The `SharedState` is one of the most important and versatile abstraction provided
|
|
23
|
-
* by `soundworks`. It represents a set of parameters that are synchronized accross
|
|
24
|
-
* every nodes of the application (clients and server) that declared some interest
|
|
25
|
-
* to the shared state.
|
|
26
|
-
*
|
|
27
|
-
* A `SharedState` is created according to a "schema" (in the sense of a database
|
|
28
|
-
* schema) that must be declared and registered server-side. Any number of `SharedState`s
|
|
29
|
-
* can be created from a single schema.
|
|
30
|
-
*
|
|
31
|
-
* A shared state can be created both by the clients or by the server (in which case
|
|
32
|
-
* it is generally considered as a global state of the application). Similarly any
|
|
33
|
-
* node of the application (clients or server) can declare interest and "attach" to
|
|
34
|
-
* a state created by another node. All node attached to a state can modify its values
|
|
35
|
-
* and/or react to the modifications applied by other nodes.
|
|
36
|
-
*
|
|
37
|
-
* Tutorial: {@link https://soundworks.dev/guide/state-manager.html}
|
|
38
|
-
*
|
|
39
|
-
* ```
|
|
40
|
-
* // server-side
|
|
41
|
-
* import { Server } from '@soundworks/server/index.js';
|
|
42
|
-
*
|
|
43
|
-
* const server = new Server(config);
|
|
44
|
-
* // declare and register the schema of a shared state.
|
|
45
|
-
* server.stateManager.registerSchema('some-global-state', {
|
|
46
|
-
* myRandom: {
|
|
47
|
-
* type: 'float',
|
|
48
|
-
* default: 0,
|
|
49
|
-
* }
|
|
50
|
-
* });
|
|
51
|
-
*
|
|
52
|
-
* await server.start();
|
|
53
|
-
*
|
|
54
|
-
* // create a global state server-side
|
|
55
|
-
* const globalState = await server.stateManager.create('some-global-state');
|
|
56
|
-
* // listen and react to the changes made by the clients
|
|
57
|
-
* globalState.onUpdate(updates => console.log(updates));
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* ```
|
|
61
|
-
* // client-side
|
|
62
|
-
* import { Client } from '@soundworks/client.index.js';
|
|
63
|
-
*
|
|
64
|
-
* const client = new Client(config);
|
|
65
|
-
* await client.start();
|
|
66
|
-
*
|
|
67
|
-
* // attach to the global state created by the server
|
|
68
|
-
* const globalState = await client.stateManager.attach('some-global-state');
|
|
69
|
-
*
|
|
70
|
-
* // update the value of a `myRandom` parameter every seconds
|
|
71
|
-
* setInterval(() => {
|
|
72
|
-
* globalState.set({ myRandom: Math.random() });
|
|
73
|
-
* }, 1000);
|
|
74
|
-
* ``
|
|
75
|
-
*
|
|
76
|
-
* @memberof server
|
|
77
|
-
* @extends BaseSharedState
|
|
78
|
-
* @inheritdoc
|
|
79
|
-
* @hideconstructor
|
|
80
|
-
* @see {server.StateManager}
|
|
81
|
-
*/
|
|
82
|
-
class SharedState extends BaseSharedState {}
|
|
83
|
-
|
|
84
|
-
export default SharedState;
|
|
85
|
-
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import BaseSharedStateCollection from '../common/BaseSharedStateCollection.js';
|
|
2
|
-
|
|
3
|
-
// this file exists only for documentation purposesSharedStateCollection.js
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @callback server.SharedStateCollection~onUpdateCallback
|
|
7
|
-
* @param {server.SharedState} state - State that triggered the update.
|
|
8
|
-
* @param {Object} newValues - Key / value pairs of the updates that have been
|
|
9
|
-
* applied to the state.
|
|
10
|
-
* @param {Object} oldValues - Key / value pairs of the updated params before
|
|
11
|
-
* the updates has been applied to the state.
|
|
12
|
-
* @param {Mixed} [context=null] - Optionnal context object that has been passed
|
|
13
|
-
* with the values updates in the `set` call.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* The `SharedStateCollection` interface represent a collection of all states
|
|
18
|
-
* created from a given schema name on the network.
|
|
19
|
-
*
|
|
20
|
-
* It can optionnaly exclude the states created by the current node.
|
|
21
|
-
*
|
|
22
|
-
* See {@link server.StateManager#getCollection} for factory method API
|
|
23
|
-
*
|
|
24
|
-
* ```
|
|
25
|
-
* const collection = await server.stateManager.getCollection('my-schema');
|
|
26
|
-
* const allValues = collection.getValues();
|
|
27
|
-
* collection.onUpdate((state, newValues, oldValues, context) => {
|
|
28
|
-
* // do something
|
|
29
|
-
* });
|
|
30
|
-
* ```
|
|
31
|
-
* @memberof server
|
|
32
|
-
* @extends BaseSharedStateCollection
|
|
33
|
-
* @inheritdoc
|
|
34
|
-
* @hideconstructor
|
|
35
|
-
*/
|
|
36
|
-
class SharedStateCollection extends BaseSharedStateCollection {}
|
|
37
|
-
|
|
38
|
-
export default SharedStateCollection;
|
|
39
|
-
|