@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
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
export const kSharedStatePromiseStore: unique symbol;
|
|
2
|
+
export default SharedState;
|
|
3
|
+
/**
|
|
4
|
+
* Callback executed when updates are applied on a {@link SharedState }.
|
|
5
|
+
*/
|
|
6
|
+
export type sharedStateOnUpdateCallback = (newValues: any, oldValues: any, context?: Mixed) => any;
|
|
7
|
+
/**
|
|
8
|
+
* Delete the registered {@link sharedStateOnUpdateCallback }.
|
|
9
|
+
*/
|
|
10
|
+
export type sharedStateDeleteOnUpdateCallback = () => any;
|
|
11
|
+
/**
|
|
12
|
+
* Callback executed when updates are applied on a {@link SharedState}.
|
|
13
|
+
*
|
|
14
|
+
* @callback sharedStateOnUpdateCallback
|
|
15
|
+
* @param {Object} newValues - Key / value pairs of the updates that have been
|
|
16
|
+
* applied to the state.
|
|
17
|
+
* @param {Object} oldValues - Key / value pairs of the updated params before
|
|
18
|
+
* the updates has been applied to the state.
|
|
19
|
+
* @param {Mixed} [context=null] - Optionnal context object that has been passed
|
|
20
|
+
* with the values updates in the `set` call.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Delete the registered {@link sharedStateOnUpdateCallback}.
|
|
24
|
+
*
|
|
25
|
+
* @callback sharedStateDeleteOnUpdateCallback
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* The `SharedState` is one of the most important and versatile abstraction provided
|
|
29
|
+
* by `soundworks`. It represents a set of parameters that are synchronized accross
|
|
30
|
+
* every nodes of the application (clients and server) that declared some interest
|
|
31
|
+
* to the shared state.
|
|
32
|
+
*
|
|
33
|
+
* A `SharedState` instance is created according to a shared state class definition
|
|
34
|
+
* which is composed of a {@link SharedStateClassName} and of a {@link SharedStateClassSchema}
|
|
35
|
+
* registered in the {@link ServerStateManager}. Any number of `SharedState`s
|
|
36
|
+
* can be created from a single class definition.
|
|
37
|
+
*
|
|
38
|
+
* A shared state can be created both by the clients or by the server, in which case
|
|
39
|
+
* it is generally considered as a global state of the application. Similarly any
|
|
40
|
+
* node of the application (clients or server) can declare interest and "attach" to
|
|
41
|
+
* a state created by another node. All node attached to a state can modify its values
|
|
42
|
+
* and/or react to the modifications applied by other nodes.
|
|
43
|
+
*
|
|
44
|
+
* Tutorial: {@link https://soundworks.dev/guide/state-manager.html}
|
|
45
|
+
*
|
|
46
|
+
* ```
|
|
47
|
+
* // server-side
|
|
48
|
+
* import { Server } from '@soundworks/server/index.js';
|
|
49
|
+
*
|
|
50
|
+
* const server = new Server(config);
|
|
51
|
+
* // define a shared state class
|
|
52
|
+
* server.stateManager.registerSchema('some-global-state', {
|
|
53
|
+
* myRandom: {
|
|
54
|
+
* type: 'float',
|
|
55
|
+
* default: 0,
|
|
56
|
+
* }
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* await server.start();
|
|
60
|
+
*
|
|
61
|
+
* // create a global state server-side
|
|
62
|
+
* const globalState = await server.stateManager.create('some-global-state');
|
|
63
|
+
* // listen and react to the changes made by the clients
|
|
64
|
+
* globalState.onUpdate(updates => console.log(updates));
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* ```
|
|
68
|
+
* // client-side
|
|
69
|
+
* import { Client } from '@soundworks/client.index.js';
|
|
70
|
+
*
|
|
71
|
+
* const client = new Client(config);
|
|
72
|
+
* await client.start();
|
|
73
|
+
*
|
|
74
|
+
* // attach to the global state created by the server
|
|
75
|
+
* const globalState = await client.stateManager.attach('some-global-state');
|
|
76
|
+
*
|
|
77
|
+
* // update the value of a `myRandom` parameter every seconds
|
|
78
|
+
* setInterval(() => {
|
|
79
|
+
* globalState.set({ myRandom: Math.random() });
|
|
80
|
+
* }, 1000);
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
declare class SharedState {
|
|
84
|
+
constructor(id: any, remoteId: any, className: any, schema: any, client: any, isOwner: any, manager: any, initValues: any, filter: any);
|
|
85
|
+
/**
|
|
86
|
+
* Id of the state
|
|
87
|
+
* @type {Number}
|
|
88
|
+
*/
|
|
89
|
+
get id(): number;
|
|
90
|
+
/**
|
|
91
|
+
* Name of the underlying {@link SharedState} class.
|
|
92
|
+
* @type {String}
|
|
93
|
+
* @deprecated
|
|
94
|
+
*/
|
|
95
|
+
get schemaName(): string;
|
|
96
|
+
/**
|
|
97
|
+
* Name of the underlying {@link SharedState} class.
|
|
98
|
+
* @type {String}
|
|
99
|
+
*/
|
|
100
|
+
get className(): string;
|
|
101
|
+
/**
|
|
102
|
+
* Indicates if the node is the owner of the state, i.e. if it created the state.
|
|
103
|
+
* @type {Boolean}
|
|
104
|
+
*/
|
|
105
|
+
get isOwner(): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Update values of the state.
|
|
108
|
+
*
|
|
109
|
+
* The returned `Promise` resolves on an object that contains the applied updates,
|
|
110
|
+
* and resolves after all the `onUpdate` callbacks have resolved themselves, i.e.:
|
|
111
|
+
*
|
|
112
|
+
* ```js
|
|
113
|
+
* server.stateManager.registerSchema('test', {
|
|
114
|
+
* myBool: { type: 'boolean', default: false },
|
|
115
|
+
* });
|
|
116
|
+
* const a = await server.stateManager.create('a');
|
|
117
|
+
*
|
|
118
|
+
* let asyncCallbackCalled = false;
|
|
119
|
+
*
|
|
120
|
+
* a.onUpdate(updates => {
|
|
121
|
+
* return new Promise(resolve => {
|
|
122
|
+
* setTimeout(() => {
|
|
123
|
+
* asyncCallbackCalled = true;
|
|
124
|
+
* resolve();
|
|
125
|
+
* }, 100);
|
|
126
|
+
* });
|
|
127
|
+
* });
|
|
128
|
+
*
|
|
129
|
+
* const updates = await a.set({ myBool: true });
|
|
130
|
+
* assert.equal(asyncCallbackCalled, true);
|
|
131
|
+
* assert.deepEqual(updates, { myBool: true });
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* @param {object} updates - Key / value pairs of updates to apply to the state.
|
|
135
|
+
* @param {mixed} [context=null] - Optionnal contextual object that will be propagated
|
|
136
|
+
* alongside the updates of the state. The context is valid only for the
|
|
137
|
+
* current call and will be passed as third argument to all update listeners.
|
|
138
|
+
* @returns {Promise<Object>} A promise to the (coerced) updates.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* const state = await client.stateManager.attach('globals');
|
|
142
|
+
* const updates = await state.set({ myParam: Math.random() });
|
|
143
|
+
*/
|
|
144
|
+
set(updates: object, context?: mixed): Promise<any>;
|
|
145
|
+
/**
|
|
146
|
+
* Get the value of a parameter of the state.
|
|
147
|
+
*
|
|
148
|
+
* Be aware that in case of 'any' typethe returned value is deeply copied.
|
|
149
|
+
* While this prevents from pollution of the state by mutating the reference,
|
|
150
|
+
* this can also lead to performance issues when the parameter contains large
|
|
151
|
+
* data. In such cases you should use the {@link SharedState#getUnsafe} method
|
|
152
|
+
* and make sure to treat the returned object as readonly.
|
|
153
|
+
*
|
|
154
|
+
* @param {SharedStateParameterName} name - Name of the param.
|
|
155
|
+
* @return {any}
|
|
156
|
+
* @throws Throws if `name` does not exists.
|
|
157
|
+
* @example
|
|
158
|
+
* const value = state.get('paramName');
|
|
159
|
+
*/
|
|
160
|
+
get(name: SharedStateParameterName): any;
|
|
161
|
+
/**
|
|
162
|
+
* Get an unsafe reference to the value of a parameter of the state.
|
|
163
|
+
*
|
|
164
|
+
* Similar to `get` but returns a reference to the underlying value in case of
|
|
165
|
+
* `any` type. Can be usefull if the underlying value is large (e.g. sensors
|
|
166
|
+
* recordings, etc.) and deep cloning expensive. Be aware that if changes are
|
|
167
|
+
* made on the returned object, the state of your application will become
|
|
168
|
+
* inconsistent.
|
|
169
|
+
*
|
|
170
|
+
* @param {SharedStateParameterName} name - Name of the param.
|
|
171
|
+
* @return {any}
|
|
172
|
+
* @throws Throws if `name` does not exists.
|
|
173
|
+
* @example
|
|
174
|
+
* const value = state.getUnsafe('paramName');
|
|
175
|
+
*/
|
|
176
|
+
getUnsafe(name: SharedStateParameterName): any;
|
|
177
|
+
/**
|
|
178
|
+
* Get all the key / value pairs of the state.
|
|
179
|
+
*
|
|
180
|
+
* If a parameter is of `any` type, a deep copy is made.
|
|
181
|
+
*
|
|
182
|
+
* @return {object}
|
|
183
|
+
* @example
|
|
184
|
+
* const values = state.getValues();
|
|
185
|
+
*/
|
|
186
|
+
getValues(): object;
|
|
187
|
+
/**
|
|
188
|
+
* Get all the key / value pairs of the state.
|
|
189
|
+
*
|
|
190
|
+
* Similar to `getValues` but returns a reference to the underlying value in
|
|
191
|
+
* case of `any` type. Can be usefull if the underlying value is big (e.g.
|
|
192
|
+
* sensors recordings, etc.) and deep cloning expensive. Be aware that if
|
|
193
|
+
* changes are made on the returned object, the state of your application will
|
|
194
|
+
* become inconsistent.
|
|
195
|
+
*
|
|
196
|
+
* @return {object}
|
|
197
|
+
* @example
|
|
198
|
+
* const values = state.getValues();
|
|
199
|
+
*/
|
|
200
|
+
getValuesUnsafe(): object;
|
|
201
|
+
/**
|
|
202
|
+
* Return the underlying {@link SharedStateClassSchema} or the
|
|
203
|
+
* {@link SharedStateParameterDescription} if name is given.
|
|
204
|
+
*
|
|
205
|
+
* @param {string} [name] - If defined, returns only the parameter description
|
|
206
|
+
* of the given param name.
|
|
207
|
+
* @return {SharedStateClassSchema|SharedStateParameterDescription}
|
|
208
|
+
* @throws Throws if `name` does not exists.
|
|
209
|
+
* @example
|
|
210
|
+
* const schema = state.getSchema();
|
|
211
|
+
*/
|
|
212
|
+
getSchema(name?: string): SharedStateClassSchema | SharedStateParameterDescription;
|
|
213
|
+
/**
|
|
214
|
+
* Get the values with which the state has been created. May defer from the
|
|
215
|
+
* default values declared in the schema.
|
|
216
|
+
*
|
|
217
|
+
* @return {object}
|
|
218
|
+
* @example
|
|
219
|
+
* const initValues = state.getInitValues();
|
|
220
|
+
*/
|
|
221
|
+
getInitValues(): object;
|
|
222
|
+
/**
|
|
223
|
+
* Get the default values as declared in the schema.
|
|
224
|
+
*
|
|
225
|
+
* @return {object}
|
|
226
|
+
* @example
|
|
227
|
+
* const defaults = state.getDefaults();
|
|
228
|
+
*/
|
|
229
|
+
getDefaults(): object;
|
|
230
|
+
/**
|
|
231
|
+
* Detach from the state. If the client is the creator of the state, the state
|
|
232
|
+
* is deleted and all attached nodes get notified.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* const state = await client.state.attach('globals');
|
|
236
|
+
* // later
|
|
237
|
+
* await state.detach();
|
|
238
|
+
*/
|
|
239
|
+
detach(): Promise<any>;
|
|
240
|
+
/**
|
|
241
|
+
* Delete the state. Only the creator/owner of the state can use this method.
|
|
242
|
+
*
|
|
243
|
+
* All nodes attached to the state will be detached, triggering any registered
|
|
244
|
+
* `onDetach` callbacks. The creator of the state will also have its own `onDelete`
|
|
245
|
+
* callback triggered. The local `onDeatch` and `onDelete` callbacks will be
|
|
246
|
+
* executed *before* the returned Promise resolves
|
|
247
|
+
*
|
|
248
|
+
* @throws Throws if the method is called by a node which is not the owner of
|
|
249
|
+
* the state.
|
|
250
|
+
* @example
|
|
251
|
+
* const state = await client.state.create('my-schema-name');
|
|
252
|
+
* // later
|
|
253
|
+
* await state.delete();
|
|
254
|
+
*/
|
|
255
|
+
delete(): Promise<any>;
|
|
256
|
+
/**
|
|
257
|
+
* Subscribe to state updates.
|
|
258
|
+
*
|
|
259
|
+
* @param {sharedStateOnUpdateCallback} callback
|
|
260
|
+
* Callback to execute when an update is applied on the state.
|
|
261
|
+
* @param {Boolean} [executeListener=false] - Execute the callback immediately
|
|
262
|
+
* with current state values. (`oldValues` will be set to `{}`, and `context` to `null`)
|
|
263
|
+
* @returns {sharedStateDeleteOnUpdateCallback}
|
|
264
|
+
* @example
|
|
265
|
+
* const unsubscribe = state.onUpdate(async (newValues, oldValues, context) => {
|
|
266
|
+
* for (let [key, value] of Object.entries(newValues)) {
|
|
267
|
+
* switch (key) {
|
|
268
|
+
* // do something
|
|
269
|
+
* }
|
|
270
|
+
* }
|
|
271
|
+
* });
|
|
272
|
+
*
|
|
273
|
+
* // later
|
|
274
|
+
* unsubscribe();
|
|
275
|
+
*/
|
|
276
|
+
onUpdate(listener: any, executeListener?: boolean): sharedStateDeleteOnUpdateCallback;
|
|
277
|
+
/**
|
|
278
|
+
* Register a function to execute when detaching from the state. The function
|
|
279
|
+
* will be executed before the `detach` promise resolves.
|
|
280
|
+
*
|
|
281
|
+
* @param {Function} callback - Callback to execute when detaching from the state.
|
|
282
|
+
* Whether the client as called `detach`, or the state has been deleted by its
|
|
283
|
+
* creator.
|
|
284
|
+
*/
|
|
285
|
+
onDetach(callback: Function): () => boolean;
|
|
286
|
+
/**
|
|
287
|
+
* Register a function to execute when the state is deleted. Only called if the
|
|
288
|
+
* node was the creator of the state. Is called after `onDetach` and executed
|
|
289
|
+
* before the `delete` Promise resolves.
|
|
290
|
+
*
|
|
291
|
+
* @param {Function} callback - Callback to execute when the state is deleted.
|
|
292
|
+
*/
|
|
293
|
+
onDelete(callback: Function): () => boolean;
|
|
294
|
+
/** @private */
|
|
295
|
+
private [kSharedStatePromiseStore];
|
|
296
|
+
#private;
|
|
297
|
+
}
|
|
@@ -1,19 +1,35 @@
|
|
|
1
|
-
export default
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export default SharedStateCollection;
|
|
2
|
+
export type sharedStateCollectionOnUpdateCallback = (state: SharedState, newValues: any, oldValues: any, context?: Mixed) => any;
|
|
3
|
+
/**
|
|
4
|
+
* @callback sharedStateCollectionOnUpdateCallback
|
|
5
|
+
* @param {SharedState} state - State that triggered the update.
|
|
6
|
+
* @param {Object} newValues - Key / value pairs of the updates that have been
|
|
7
|
+
* applied to the state.
|
|
8
|
+
* @param {Object} oldValues - Key / value pairs of the updated params before
|
|
9
|
+
* the updates has been applied to the state.
|
|
10
|
+
* @param {Mixed} [context=null] - Optionnal context object that has been passed
|
|
11
|
+
* with the values updates in the `set` call.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* The `SharedStateCollection` interface represent a collection of all states
|
|
15
|
+
* created from a given schema name on the network.
|
|
16
|
+
*
|
|
17
|
+
* It can optionnaly exclude the states created by the current node.
|
|
18
|
+
*
|
|
19
|
+
* See {@link ClientStateManager#getCollection} and
|
|
20
|
+
* {@link ServerStateManager#getCollection} for factory methods API
|
|
21
|
+
*
|
|
22
|
+
* ```
|
|
23
|
+
* const collection = await client.stateManager.getCollection('my-schema');
|
|
24
|
+
* const allValues = collection.getValues();
|
|
25
|
+
* collection.onUpdate((state, newValues, oldValues, context) => {
|
|
26
|
+
* // do something
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
* @hideconstructor
|
|
30
|
+
*/
|
|
31
|
+
declare class SharedStateCollection {
|
|
4
32
|
constructor(stateManager: any, schemaName: any, filter?: any, options?: {});
|
|
5
|
-
_stateManager: any;
|
|
6
|
-
_schemaName: any;
|
|
7
|
-
_filter: any;
|
|
8
|
-
_options: {
|
|
9
|
-
excludeLocal: boolean;
|
|
10
|
-
};
|
|
11
|
-
_schema: any;
|
|
12
|
-
_states: any[];
|
|
13
|
-
_onUpdateCallbacks: Set<any>;
|
|
14
|
-
_onAttachCallbacks: Set<any>;
|
|
15
|
-
_onDetachCallbacks: Set<any>;
|
|
16
|
-
_unobserve: any;
|
|
17
33
|
/** @private */
|
|
18
34
|
private _init;
|
|
19
35
|
/**
|
|
@@ -100,14 +116,14 @@ declare class BaseSharedStateCollection {
|
|
|
100
116
|
/**
|
|
101
117
|
* Subscribe to any state update of the collection.
|
|
102
118
|
*
|
|
103
|
-
* @param {
|
|
119
|
+
* @param {sharedStateCollectionOnUpdateCallback}
|
|
104
120
|
* callback - Callback to execute when an update is applied on a state.
|
|
105
121
|
* @param {Boolean} [executeListener=false] - Execute the callback immediately
|
|
106
122
|
* for all underlying states with current state values. (`oldValues` will be
|
|
107
123
|
* set to `{}`, and `context` to `null`)
|
|
108
124
|
* @returns {Function} - Function that delete the registered listener.
|
|
109
125
|
*/
|
|
110
|
-
onUpdate(callback:
|
|
126
|
+
onUpdate(callback: sharedStateCollectionOnUpdateCallback, executeListener?: boolean): Function;
|
|
111
127
|
/**
|
|
112
128
|
* Register a function to execute when a state is added to the collection.
|
|
113
129
|
*
|
|
@@ -179,5 +195,5 @@ declare class BaseSharedStateCollection {
|
|
|
179
195
|
done: boolean;
|
|
180
196
|
};
|
|
181
197
|
};
|
|
198
|
+
#private;
|
|
182
199
|
}
|
|
183
|
-
//# sourceMappingURL=BaseSharedStateCollection.d.ts.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export const SERVER_ID: -1;
|
|
2
2
|
export const PING_INTERVAL: number;
|
|
3
|
-
export const PING_LATENCY_TOLERANCE: 1000;
|
|
4
3
|
export const PING_MESSAGE: "h:ping";
|
|
5
4
|
export const PONG_MESSAGE: "h:pong";
|
|
6
5
|
export const BATCHED_TRANSPORT_CHANNEL: "b:t";
|
|
@@ -41,4 +40,3 @@ export const CLIENT_HANDSHAKE_RESPONSE: "cl:h:res";
|
|
|
41
40
|
export const CLIENT_HANDSHAKE_ERROR: "cl:h:err";
|
|
42
41
|
export const AUDIT_STATE_NAME: "p:s:audit";
|
|
43
42
|
export const PRIVATE_STATES: string[];
|
|
44
|
-
//# sourceMappingURL=constants.d.ts.map
|
package/types/common/logger.d.ts
CHANGED
|
@@ -9,8 +9,9 @@ declare namespace logger {
|
|
|
9
9
|
function pluginStarted(name: any): void;
|
|
10
10
|
function pluginReady(name: any): void;
|
|
11
11
|
function pluginErrored(name: any): void;
|
|
12
|
+
function warnVersionDiscepancies(clientRole: any, clientVersion: any, serverVersion: any): void;
|
|
12
13
|
function log(msg: any): void;
|
|
13
14
|
function warn(msg: any): void;
|
|
14
15
|
function error(msg: any): void;
|
|
16
|
+
function deprecated(oldAPI: any, newAPI: any): void;
|
|
15
17
|
}
|
|
16
|
-
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User defined name for a class of {@link SharedState }
|
|
3
|
+
*/
|
|
4
|
+
type SharedStateClassName = string;
|
|
5
|
+
/**
|
|
6
|
+
* Description of a {@link SharedState } data structure that describes the structure
|
|
7
|
+
* of a class of {@link SharedState } to be registered by {@link ServerStateManagerregisterSchema }
|
|
8
|
+
*
|
|
9
|
+
* A schema is the blueprint, or the definition from which shared states from a
|
|
10
|
+
* given class can be created.
|
|
11
|
+
*
|
|
12
|
+
* It consists of a set of key / value pairs where the key is the name of
|
|
13
|
+
* the parameter (cf. ${SharedStateParameterName}), and the value is an object
|
|
14
|
+
* describing the parameter (cf. ${SharedStateParameterDescription}).
|
|
15
|
+
*/
|
|
16
|
+
type SharedStateClassSchema = any;
|
|
17
|
+
/**
|
|
18
|
+
* User defined name of a parameter in a class of {@link SharedState }
|
|
19
|
+
*/
|
|
20
|
+
type SharedStateParameterName = string;
|
|
21
|
+
/**
|
|
22
|
+
* Description of a parameter in a class of {@link SharedState }
|
|
23
|
+
*/
|
|
24
|
+
type SharedStateParameterDescription = {
|
|
25
|
+
/**
|
|
26
|
+
* - Type of the parameter
|
|
27
|
+
*/
|
|
28
|
+
type: 'boolean' | 'string' | 'integer' | 'float' | 'enum' | 'any';
|
|
29
|
+
/**
|
|
30
|
+
* - Default value of the parameter. Optional only if
|
|
31
|
+
* `nullable = true` or `event = true`
|
|
32
|
+
*/
|
|
33
|
+
default: any;
|
|
34
|
+
/**
|
|
35
|
+
* - Defines if the parameter is nullable.
|
|
36
|
+
* When `true` the parameter `default` is set to `null`.
|
|
37
|
+
*/
|
|
38
|
+
nullable?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* - Define if the parameter is a volatile, i.e.
|
|
41
|
+
* its value only exists on an update and is set back to `null` after propagation.
|
|
42
|
+
* When `true`, `nullable` is automatically set to `true` and `default` to `null`.
|
|
43
|
+
*/
|
|
44
|
+
event?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* - When set to `false`, an update will
|
|
47
|
+
* trigger the propagation of a parameter even when its value didn't change.
|
|
48
|
+
* This option provides a sort of middle ground between the default bahavior
|
|
49
|
+
* (e.g. where only changed values are propagated) and the behavior of the `event`
|
|
50
|
+
* option (which has no state per se). Hence, setting this options to `false` if
|
|
51
|
+
* `event=true` makes no sens.
|
|
52
|
+
*/
|
|
53
|
+
filterChange?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* - When set to `true`, an update will
|
|
56
|
+
* trigger the update listeners immediately on the node that generated the update,
|
|
57
|
+
* before propagating the change on the network.
|
|
58
|
+
* This option is usefull in cases the network would introduce a noticeable
|
|
59
|
+
* latency on the client.
|
|
60
|
+
* If for some reason the value is overriden server-side (e.g. in an `updateHook`)
|
|
61
|
+
* the listeners will be called again when the "real" value is received.
|
|
62
|
+
*/
|
|
63
|
+
immediate?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* - Minimum value of the parameter. Only applies
|
|
66
|
+
* for `integer` and `float` types.
|
|
67
|
+
*/
|
|
68
|
+
min?: number;
|
|
69
|
+
/**
|
|
70
|
+
* - Maximum value of the parameter. Only applies
|
|
71
|
+
* for `integer` and `float` types.
|
|
72
|
+
*/
|
|
73
|
+
max?: number;
|
|
74
|
+
/**
|
|
75
|
+
* - Possible values of the parameter. Only applies and
|
|
76
|
+
* mandatory for `enum` type.
|
|
77
|
+
*/
|
|
78
|
+
list?: Array<any>;
|
|
79
|
+
/**
|
|
80
|
+
* - Optional metadata of the parameter.
|
|
81
|
+
*/
|
|
82
|
+
metas?: object;
|
|
83
|
+
};
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
/** @private */
|
|
2
|
-
export function packBinaryMessage(channel: any, data: any): ArrayBufferLike;
|
|
3
|
-
/** @private */
|
|
4
|
-
export function unpackBinaryMessage(buffer: any): any[];
|
|
5
|
-
/** @private */
|
|
6
2
|
export function packStringMessage(channel: any, ...args: any[]): string;
|
|
7
3
|
/** @private */
|
|
8
4
|
export function unpackStringMessage(data: any): any;
|
|
9
|
-
//# sourceMappingURL=sockets-utils.d.ts.map
|