@soundworks/core 4.0.0-alpha.0 → 4.0.0-alpha.2
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/README.md +26 -16
- package/package.json +2 -2
- package/src/client/Client.js +37 -3
- package/src/client/Context.js +37 -10
- package/src/client/Plugin.js +2 -1
- package/src/client/PluginManager.js +26 -17
- package/src/client/Socket.js +44 -39
- package/src/client/index.js +0 -33
- package/src/common/BasePluginManager.js +12 -3
- package/src/common/ParameterBag.js +7 -196
- package/src/server/Context.js +162 -18
- package/src/server/ContextManager.js +4 -5
- package/src/server/Plugin.js +2 -1
- package/src/server/PluginManager.js +26 -6
- package/src/server/Server.js +185 -69
- package/src/server/Socket.js +105 -62
- package/src/server/Sockets.js +27 -22
- package/src/server/StateManager.js +223 -24
- package/src/server/index.js +0 -20
|
@@ -26,12 +26,224 @@ import { idGenerator } from '../common/utils.js';
|
|
|
26
26
|
const generateStateId = idGenerator();
|
|
27
27
|
const generateRemoteId = idGenerator();
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* @typedef {object} server.StateManager~schema
|
|
31
|
+
*
|
|
32
|
+
* Description of a schema to be registered by the {@link server.StateManager#registerSchema}
|
|
33
|
+
*
|
|
34
|
+
* A schema is the blueprint, or definition from which shared states can be created.
|
|
35
|
+
*
|
|
36
|
+
* It consists of a set of key / value pairs where the key is the name of
|
|
37
|
+
* the parameter, and the value is an object describing the parameter.
|
|
38
|
+
*
|
|
39
|
+
* The value can be of any of the foolowing types:
|
|
40
|
+
* - {@link server.StateManager~schemaBooleanDefinition}
|
|
41
|
+
* - {@link server.StateManager~schemaStringDefinition}
|
|
42
|
+
* - {@link server.StateManager~schemaIntegerDefinition}
|
|
43
|
+
* - {@link server.StateManager~schemaFloatDefinition}
|
|
44
|
+
* - {@link server.StateManager~schemaEnumDefinition}
|
|
45
|
+
* - {@link server.StateManager~schemaAnyDefinition}
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const mySchema = {
|
|
49
|
+
* triggerSound: {
|
|
50
|
+
* type: 'boolean',
|
|
51
|
+
* event: true,
|
|
52
|
+
* },
|
|
53
|
+
* volume: {
|
|
54
|
+
* type: 'float'
|
|
55
|
+
* default: 0,
|
|
56
|
+
* min: -80,
|
|
57
|
+
* max: 6,
|
|
58
|
+
* }
|
|
59
|
+
* };
|
|
60
|
+
*
|
|
61
|
+
* server.stateManager.registerSchema('my-schema-name', mySchema);
|
|
62
|
+
*/
|
|
63
|
+
/**
|
|
64
|
+
* Describe a {@link server.StateManager~schema} entry of "boolean" type.
|
|
65
|
+
*
|
|
66
|
+
* @typedef {object} server.StateManager~schemaBooleanDefinition
|
|
67
|
+
* @property {string} type='boolean' - Define a boolean parameter.
|
|
68
|
+
* @property {boolean} default - Default value of the parameter.
|
|
69
|
+
* @property {boolean} [nullable=false] - Define if the parameter is nullable. If
|
|
70
|
+
* set to `true` the parameter `default` is set to `null`.
|
|
71
|
+
* @property {boolean} [event=false] - Define if the parameter is a volatile, e.g.
|
|
72
|
+
* set its value back to `null` after propagation. When `true`, `nullable` is
|
|
73
|
+
* automatically set to `true` and `default` to `null`.
|
|
74
|
+
* @property {boolean} [filterChange=true] - Setting this option to `false` forces
|
|
75
|
+
* the propagation of a parameter even when its value do not change. It
|
|
76
|
+
* offers a kind of middle ground between the default bahavior (e.g. where
|
|
77
|
+
* only changed values are propagated) and the behavior of the `event` option
|
|
78
|
+
* (which has no state per se). As such, setting this options to `false` if
|
|
79
|
+
* `event=true` does not make sens.
|
|
80
|
+
* @property {boolean} [immediate=false] - Setting this option to `true` will
|
|
81
|
+
* trigger any change (e.g. call the `onUpdate` listeners) immediately on the
|
|
82
|
+
* state that generate the update (i.e. calling `set`), before propagating the
|
|
83
|
+
* change on the network. This option can be usefull in cases the network
|
|
84
|
+
* would introduce a noticeable latency on the client. If for some reason
|
|
85
|
+
* the value is overriden server-side (e.g. in an `updateHook`) the listeners
|
|
86
|
+
* will be called again on when the "real" / final value will be received.
|
|
87
|
+
* @property {object} [metas={}] - Optionnal metadata of the parameter.
|
|
88
|
+
*/
|
|
89
|
+
/**
|
|
90
|
+
* Describe a {@link server.StateManager~schema} entry of "string" type.
|
|
91
|
+
*
|
|
92
|
+
* @typedef {object} server.StateManager~schemaStringDefinition
|
|
93
|
+
* @property {string} type='string' - Define a boolean parameter.
|
|
94
|
+
* @property {string} default - Default value of the parameter.
|
|
95
|
+
* @property {boolean} [nullable=false] - Define if the parameter is nullable. If
|
|
96
|
+
* set to `true` the parameter `default` is set to `null`.
|
|
97
|
+
* @property {boolean} [event=false] - Define if the parameter is a volatile, e.g.
|
|
98
|
+
* set its value back to `null` after propagation. When `true`, `nullable` is
|
|
99
|
+
* automatically set to `true` and `default` to `null`.
|
|
100
|
+
* @property {boolean} [filterChange=true] - Setting this option to `false` forces
|
|
101
|
+
* the propagation of a parameter even when its value do not change. It
|
|
102
|
+
* offers a kind of middle ground between the default bahavior (e.g. where
|
|
103
|
+
* only changed values are propagated) and the behavior of the `event` option
|
|
104
|
+
* (which has no state per se). As such, setting this options to `false` if
|
|
105
|
+
* `event=true` does not make sens.
|
|
106
|
+
* @property {boolean} [immediate=false] - Setting this option to `true` will
|
|
107
|
+
* trigger any change (e.g. call the `onUpdate` listeners) immediately on the
|
|
108
|
+
* state that generate the update (i.e. calling `set`), before propagating the
|
|
109
|
+
* change on the network. This option can be usefull in cases the network
|
|
110
|
+
* would introduce a noticeable latency on the client. If for some reason
|
|
111
|
+
* the value is overriden server-side (e.g. in an `updateHook`) the listeners
|
|
112
|
+
* will be called again on when the "real" / final value will be received.
|
|
113
|
+
* @property {object} [metas={}] - Optionnal metadata of the parameter.
|
|
114
|
+
*/
|
|
115
|
+
/**
|
|
116
|
+
* Describe a {@link server.StateManager~schema} entry of "integer" type.
|
|
117
|
+
*
|
|
118
|
+
* @typedef {object} server.StateManager~schemaIntegerDefinition
|
|
119
|
+
* @property {string} type='integer' - Define a boolean parameter.
|
|
120
|
+
* @property {number} default - Default value of the parameter.
|
|
121
|
+
* @property {number} [min=-Infinity] - Minimum value of the parameter.
|
|
122
|
+
* @property {number} [max=+Infinity] - Maximum value of the parameter.
|
|
123
|
+
* @property {boolean} [nullable=false] - Define if the parameter is nullable. If
|
|
124
|
+
* set to `true` the parameter `default` is set to `null`.
|
|
125
|
+
* @property {boolean} [event=false] - Define if the parameter is a volatile, e.g.
|
|
126
|
+
* set its value back to `null` after propagation. When `true`, `nullable` is
|
|
127
|
+
* automatically set to `true` and `default` to `null`.
|
|
128
|
+
* @property {boolean} [filterChange=true] - Setting this option to `false` forces
|
|
129
|
+
* the propagation of a parameter even when its value do not change. It
|
|
130
|
+
* offers a kind of middle ground between the default bahavior (e.g. where
|
|
131
|
+
* only changed values are propagated) and the behavior of the `event` option
|
|
132
|
+
* (which has no state per se). As such, setting this options to `false` if
|
|
133
|
+
* `event=true` does not make sens.
|
|
134
|
+
* @property {boolean} [immediate=false] - Setting this option to `true` will
|
|
135
|
+
* trigger any change (e.g. call the `onUpdate` listeners) immediately on the
|
|
136
|
+
* state that generate the update (i.e. calling `set`), before propagating the
|
|
137
|
+
* change on the network. This option can be usefull in cases the network
|
|
138
|
+
* would introduce a noticeable latency on the client. If for some reason
|
|
139
|
+
* the value is overriden server-side (e.g. in an `updateHook`) the listeners
|
|
140
|
+
* will be called again on when the "real" / final value will be received.
|
|
141
|
+
* @property {object} [metas={}] - Optionnal metadata of the parameter.
|
|
142
|
+
*/
|
|
143
|
+
/**
|
|
144
|
+
* Describe a {@link server.StateManager~schema} entry of "float" type.
|
|
145
|
+
*
|
|
146
|
+
* @typedef {object} server.StateManager~schemaFloatDefinition
|
|
147
|
+
* @property {string} [type='float'] - Float parameter.
|
|
148
|
+
* @property {number} default - Default value.
|
|
149
|
+
* @property {number} [min=-Infinity] - Minimum value.
|
|
150
|
+
* @property {number} [max=+Infinity] - Maximum value.
|
|
151
|
+
* @property {boolean} [nullable=false] - Define if the parameter is nullable. If
|
|
152
|
+
* set to `true` the parameter `default` is set to `null`.
|
|
153
|
+
* @property {boolean} [event=false] - Define if the parameter is a volatile, e.g.
|
|
154
|
+
* set its value back to `null` after propagation. When `true`, `nullable` is
|
|
155
|
+
* automatically set to `true` and `default` to `null`.
|
|
156
|
+
* @property {boolean} [filterChange=true] - Setting this option to `false` forces
|
|
157
|
+
* the propagation of a parameter even when its value do not change. It
|
|
158
|
+
* offers a kind of middle ground between the default bahavior (e.g. where
|
|
159
|
+
* only changed values are propagated) and the behavior of the `event` option
|
|
160
|
+
* (which has no state per se). As such, setting this options to `false` if
|
|
161
|
+
* `event=true` does not make sens.
|
|
162
|
+
* @property {boolean} [immediate=false] - Setting this option to `true` will
|
|
163
|
+
* trigger any change (e.g. call the `onUpdate` listeners) immediately on the
|
|
164
|
+
* state that generate the update (i.e. calling `set`), before propagating the
|
|
165
|
+
* change on the network. This option can be usefull in cases the network
|
|
166
|
+
* would introduce a noticeable latency on the client. If for some reason
|
|
167
|
+
* the value is overriden server-side (e.g. in an `updateHook`) the listeners
|
|
168
|
+
* will be called again on when the "real" / final value will be received.
|
|
169
|
+
* @property {object} [metas={}] - Optionnal metadata of the parameter.
|
|
170
|
+
*/
|
|
171
|
+
/**
|
|
172
|
+
* Describe a {@link server.StateManager~schema} entry of "enum" type.
|
|
173
|
+
*
|
|
174
|
+
* @typedef {object} server.StateManager~schemaEnumDefinition
|
|
175
|
+
* @property {string} [type='enum'] - Enum parameter.
|
|
176
|
+
* @property {string} default - Default value of the parameter.
|
|
177
|
+
* @property {Array} list - Possible values of the parameter.
|
|
178
|
+
* @property {boolean} [nullable=false] - Define if the parameter is nullable. If
|
|
179
|
+
* set to `true` the parameter `default` is set to `null`.
|
|
180
|
+
* @property {boolean} [event=false] - Define if the parameter is a volatile, e.g.
|
|
181
|
+
* set its value back to `null` after propagation. When `true`, `nullable` is
|
|
182
|
+
* automatically set to `true` and `default` to `null`.
|
|
183
|
+
* @property {boolean} [filterChange=true] - Setting this option to `false` forces
|
|
184
|
+
* the propagation of a parameter even when its value do not change. It
|
|
185
|
+
* offers a kind of middle ground between the default bahavior (e.g. where
|
|
186
|
+
* only changed values are propagated) and the behavior of the `event` option
|
|
187
|
+
* (which has no state per se). As such, setting this options to `false` if
|
|
188
|
+
* `event=true` does not make sens.
|
|
189
|
+
* @property {boolean} [immediate=false] - Setting this option to `true` will
|
|
190
|
+
* trigger any change (e.g. call the `onUpdate` listeners) immediately on the
|
|
191
|
+
* state that generate the update (i.e. calling `set`), before propagating the
|
|
192
|
+
* change on the network. This option can be usefull in cases the network
|
|
193
|
+
* would introduce a noticeable latency on the client. If for some reason
|
|
194
|
+
* the value is overriden server-side (e.g. in an `updateHook`) the listeners
|
|
195
|
+
* will be called again on when the "real" / final value will be received.
|
|
196
|
+
* @property {object} [metas={}] - Optionnal metadata of the parameter.
|
|
197
|
+
*/
|
|
198
|
+
/**
|
|
199
|
+
* Describe a {@link server.StateManager~schema} entry of "any" type.
|
|
200
|
+
*
|
|
201
|
+
* Note that the `any` type always return a shallow copy of the state internal
|
|
202
|
+
* value. Mutating the returned value will therefore not modify the internal state.
|
|
203
|
+
*
|
|
204
|
+
* @typedef {object} server.StateManager~schemaAnyDefinition
|
|
205
|
+
* @property {string} [type='any'] - Parameter of any type.
|
|
206
|
+
* @property {*} default - Default value of the parameter.
|
|
207
|
+
* @property {boolean} [nullable=false] - Define if the parameter is nullable. If
|
|
208
|
+
* set to `true` the parameter `default` is set to `null`.
|
|
209
|
+
* @property {boolean} [event=false] - Define if the parameter is a volatile, e.g.
|
|
210
|
+
* set its value back to `null` after propagation. When `true`, `nullable` is
|
|
211
|
+
* automatically set to `true` and `default` to `null`.
|
|
212
|
+
* @property {boolean} [filterChange=true] - Setting this option to `false` forces
|
|
213
|
+
* the propagation of a parameter even when its value do not change. It
|
|
214
|
+
* offers a kind of middle ground between the default bahavior (e.g. where
|
|
215
|
+
* only changed values are propagated) and the behavior of the `event` option
|
|
216
|
+
* (which has no state per se). As such, setting this options to `false` if
|
|
217
|
+
* `event=true` does not make sens.
|
|
218
|
+
* @property {boolean} [immediate=false] - Setting this option to `true` will
|
|
219
|
+
* trigger any change (e.g. call the `onUpdate` listeners) immediately on the
|
|
220
|
+
* state that generate the update (i.e. calling `set`), before propagating the
|
|
221
|
+
* change on the network. This option can be usefull in cases the network
|
|
222
|
+
* would introduce a noticeable latency on the client. If for some reason
|
|
223
|
+
* the value is overriden server-side (e.g. in an `updateHook`) the listeners
|
|
224
|
+
* will be called again on when the "real" / final value will be received.
|
|
225
|
+
* @property {object} [metas={}] - Optionnal metadata of the parameter.
|
|
226
|
+
*/
|
|
227
|
+
|
|
29
228
|
/**
|
|
30
229
|
* @callback server.StateManager~ObserveCallback
|
|
31
230
|
* @async
|
|
32
|
-
* @param {
|
|
33
|
-
* @param {
|
|
34
|
-
* @param {
|
|
231
|
+
* @param {string} schemaName - name of the schema
|
|
232
|
+
* @param {number} stateId - id of the state
|
|
233
|
+
* @param {number} nodeId - id of the node that created the state
|
|
234
|
+
*/
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @callback server.StateManager~updateHook
|
|
238
|
+
* @async
|
|
239
|
+
*
|
|
240
|
+
* @param {object} updates - Update object as given on a set callback, or
|
|
241
|
+
* result of the previous hook
|
|
242
|
+
* @param {object} currentValues - Current values of the state.
|
|
243
|
+
* @param {object} [context=null] - Optionnal context passed by the creator
|
|
244
|
+
* of the update.
|
|
245
|
+
*
|
|
246
|
+
* @return {object} The "real" updates to be applied on the state.
|
|
35
247
|
*/
|
|
36
248
|
|
|
37
249
|
/**
|
|
@@ -114,10 +326,10 @@ class StateManager extends BaseStateManager {
|
|
|
114
326
|
*
|
|
115
327
|
* This is automatically handled by the {@link server.Server} when a client connects.
|
|
116
328
|
*
|
|
117
|
-
* @param {
|
|
329
|
+
* @param {number} nodeId - Id of the client node, as given in
|
|
118
330
|
* {@link client.StateManager}
|
|
119
|
-
* @param {
|
|
120
|
-
* client.
|
|
331
|
+
* @param {object} transport - Transport mecanism to communicate with the
|
|
332
|
+
* client. Must implement a basic EventEmitter API.
|
|
121
333
|
*
|
|
122
334
|
* @private
|
|
123
335
|
*/
|
|
@@ -237,7 +449,7 @@ class StateManager extends BaseStateManager {
|
|
|
237
449
|
*
|
|
238
450
|
* This is automatically handled by the {@link server.Server} when a client disconnects.
|
|
239
451
|
*
|
|
240
|
-
* @param {
|
|
452
|
+
* @param {number} nodeId - Id of the client node, as given in
|
|
241
453
|
* {@link client.StateManager}
|
|
242
454
|
*
|
|
243
455
|
* @private
|
|
@@ -280,7 +492,7 @@ class StateManager extends BaseStateManager {
|
|
|
280
492
|
* Register a schema from which shared states (cf. {@link common.SharedState})
|
|
281
493
|
* can be instanciated.
|
|
282
494
|
*
|
|
283
|
-
* @param {
|
|
495
|
+
* @param {string} schemaName - Name of the schema.
|
|
284
496
|
* @param {server.StateManager~schema} schema - Data structure
|
|
285
497
|
* describing the states that will be created from this schema.
|
|
286
498
|
*
|
|
@@ -315,11 +527,12 @@ class StateManager extends BaseStateManager {
|
|
|
315
527
|
|
|
316
528
|
/**
|
|
317
529
|
* Delete a schema and all associated states.
|
|
530
|
+
*
|
|
318
531
|
* When a schema is deleted, all states created from this schema are deleted
|
|
319
532
|
* as well, therefore all attached clients are detached and the `onDetach`
|
|
320
533
|
* and `onDelete` callbacks are called on the related states.
|
|
321
534
|
*
|
|
322
|
-
* @param {
|
|
535
|
+
* @param {string} schemaName - Name of the schema.
|
|
323
536
|
*/
|
|
324
537
|
deleteSchema(schemaName) {
|
|
325
538
|
// @note: deleting schema
|
|
@@ -344,19 +557,6 @@ class StateManager extends BaseStateManager {
|
|
|
344
557
|
this._hooksBySchemaName.delete(schemaName);
|
|
345
558
|
}
|
|
346
559
|
|
|
347
|
-
/**
|
|
348
|
-
* @callback server.StateManager~updateHook
|
|
349
|
-
* @async
|
|
350
|
-
*
|
|
351
|
-
* @param {Object} updates - Update object as given on a set callback, or
|
|
352
|
-
* result of the previous hook
|
|
353
|
-
* @param {Object} currentValues - Current values of the state.
|
|
354
|
-
* @param {Object} [context=null] - Optionnal context passed by the creator
|
|
355
|
-
* of the update.
|
|
356
|
-
*
|
|
357
|
-
* @return {Object} The "real" updates to be applied on the state.
|
|
358
|
-
*/
|
|
359
|
-
|
|
360
560
|
/**
|
|
361
561
|
* Register a function for a given schema (e.g. will be applied on all states
|
|
362
562
|
* created from this schema) that will be executed before the update values
|
|
@@ -369,7 +569,7 @@ class StateManager extends BaseStateManager {
|
|
|
369
569
|
* server-side regarless the node on which `set` has been called and before
|
|
370
570
|
* the "actual" update of the state (e.g. before the call of `onUpdate`).
|
|
371
571
|
*
|
|
372
|
-
* @param {
|
|
572
|
+
* @param {string} schemaName - Kind of states on which applying the hook.
|
|
373
573
|
* @param {server.StateManager~updateHook} updateHook - Function
|
|
374
574
|
* called between the `set` call and the actual update.
|
|
375
575
|
*
|
|
@@ -404,7 +604,6 @@ class StateManager extends BaseStateManager {
|
|
|
404
604
|
|
|
405
605
|
return () => hooks.delete(updateHook);
|
|
406
606
|
}
|
|
407
|
-
|
|
408
607
|
}
|
|
409
608
|
|
|
410
609
|
export default StateManager;
|
package/src/server/index.js
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration object for the server.
|
|
3
|
-
*
|
|
4
|
-
* @typedef ServerConfig
|
|
5
|
-
* @memberof server
|
|
6
|
-
* @type {object}
|
|
7
|
-
* @property {object} [app] - Application configration object.
|
|
8
|
-
* @property {object} app.clients - Definition of the application clients.
|
|
9
|
-
* @property {string} [app.name=''] - Name of the application.
|
|
10
|
-
* @property {string} [app.author=''] - Name of the author.
|
|
11
|
-
* @property {object} [env] - Environment configration object.
|
|
12
|
-
* @property {boolean} env.port - Port on which the server is listening.
|
|
13
|
-
* @property {boolean} env.useHttps - Define is the server run in http or in https.
|
|
14
|
-
* @property {boolean} [env.httpsInfos={}] - Path to cert files for https.
|
|
15
|
-
* @property {boolean} env.serverAddress - Domain name or IP of the server.
|
|
16
|
-
* Mandatory if node clients are defined
|
|
17
|
-
* @property {string} [env.websockets={}] - Configuration options for websockets.
|
|
18
|
-
* @property {string} [env.subpath=''] - If running behind a proxy, path to the application.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
1
|
/**
|
|
22
2
|
* Server-side part of the *soundworks* framework.
|
|
23
3
|
*
|