@soundworks/core 4.0.0-alpha.9 → 5.0.0

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.
Files changed (144) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/README.md +14 -29
  3. package/package.json +24 -42
  4. package/src/client/Client.js +306 -256
  5. package/src/client/{Context.js → ClientContext.js} +63 -54
  6. package/src/client/ClientContextManager.js +115 -0
  7. package/src/client/{Plugin.js → ClientPlugin.js} +23 -19
  8. package/src/client/{PluginManager.js → ClientPluginManager.js} +43 -40
  9. package/src/client/ClientSocket.js +270 -0
  10. package/src/client/{StateManager.js → ClientStateManager.js} +13 -13
  11. package/src/client/index.js +36 -39
  12. package/src/common/BasePlugin.js +63 -58
  13. package/src/common/BasePluginManager.js +191 -142
  14. package/src/common/BaseStateManager.js +635 -145
  15. package/src/common/BatchedTransport.js +73 -0
  16. package/src/common/ParameterBag.js +90 -93
  17. package/src/common/PromiseStore.js +54 -0
  18. package/src/common/SharedState.js +821 -0
  19. package/src/common/SharedStateCollection.js +492 -0
  20. package/src/common/constants.js +14 -2
  21. package/src/common/logger.js +64 -68
  22. package/src/common/shared-state-types.js +82 -0
  23. package/src/common/sockets-utils.js +0 -64
  24. package/src/common/version.js +2 -0
  25. package/src/server/Server.js +552 -824
  26. package/src/server/ServerClient.js +74 -0
  27. package/src/server/{Context.js → ServerContext.js} +96 -77
  28. package/src/server/{ContextManager.js → ServerContextManager.js} +107 -87
  29. package/src/server/{Plugin.js → ServerPlugin.js} +30 -32
  30. package/src/server/ServerPluginManager.js +177 -0
  31. package/src/server/ServerSocket.js +256 -0
  32. package/src/server/ServerSockets.js +150 -0
  33. package/src/server/ServerStateManager.js +706 -0
  34. package/src/server/SharedStatePrivate.js +277 -0
  35. package/src/server/audit-network-latency.worker.js +19 -4
  36. package/src/server/{audit-schema.js → audit-state-class-description.js} +3 -2
  37. package/src/server/create-http-server.js +127 -0
  38. package/src/server/crypto.js +8 -7
  39. package/src/server/index.js +60 -17
  40. package/types/client/Client.d.ts +95 -70
  41. package/types/client/{Context.d.ts → ClientContext.d.ts} +59 -34
  42. package/types/client/{ContextManager.d.ts → ClientContextManager.d.ts} +19 -22
  43. package/types/client/ClientPlugin.d.ts +51 -0
  44. package/types/client/ClientPluginManager.d.ts +112 -0
  45. package/types/client/ClientSocket.d.ts +76 -0
  46. package/types/client/{StateManager.d.ts → ClientStateManager.d.ts} +18 -21
  47. package/types/client/index.d.ts +33 -6
  48. package/types/common/BasePlugin.d.ts +64 -53
  49. package/types/common/BasePluginManager.d.ts +84 -39
  50. package/types/common/BaseStateManager.d.ts +227 -49
  51. package/types/common/BatchedTransport.d.ts +17 -0
  52. package/types/common/ParameterBag.d.ts +73 -76
  53. package/types/common/PromiseStore.d.ts +11 -0
  54. package/types/common/SharedState.d.ts +291 -0
  55. package/types/common/SharedStateCollection.d.ts +311 -0
  56. package/types/common/constants.d.ts +10 -3
  57. package/types/common/logger.d.ts +8 -6
  58. package/types/common/shared-state-types.d.ts +95 -0
  59. package/types/common/sockets-utils.d.ts +0 -5
  60. package/types/common/version.d.ts +2 -0
  61. package/types/server/Server.d.ts +215 -136
  62. package/types/server/ServerClient.d.ts +45 -0
  63. package/types/server/ServerContext.d.ts +209 -0
  64. package/types/server/ServerContextManager.d.ts +75 -0
  65. package/types/server/ServerPlugin.d.ts +57 -0
  66. package/types/server/ServerPluginManager.d.ts +115 -0
  67. package/types/server/ServerSocket.d.ts +69 -0
  68. package/types/server/ServerSockets.d.ts +42 -0
  69. package/types/server/ServerStateManager.d.ts +284 -0
  70. package/types/server/SharedStatePrivate.d.ts +23 -0
  71. package/types/server/audit-network-latency.worker.d.ts +2 -2
  72. package/types/server/{audit-schema.d.ts → audit-state-class-description.d.ts} +8 -9
  73. package/types/server/create-http-server.d.ts +5 -0
  74. package/types/server/crypto.d.ts +4 -0
  75. package/types/server/index.d.ts +51 -3
  76. package/.eslintrc +0 -15
  77. package/.github/workflows/gh-pages.yml +0 -31
  78. package/.github/workflows/unit-tests.yml +0 -18
  79. package/src/client/ContextManager.js +0 -111
  80. package/src/client/SharedState.js +0 -84
  81. package/src/client/SharedStateCollection.js +0 -35
  82. package/src/client/Socket.js +0 -402
  83. package/src/common/BaseSharedState.js +0 -583
  84. package/src/common/BaseSharedStateCollection.js +0 -179
  85. package/src/common/SharedStatePrivate.js +0 -192
  86. package/src/common/promise-store.js +0 -25
  87. package/src/server/Client.js +0 -55
  88. package/src/server/PluginManager.js +0 -170
  89. package/src/server/SharedState.js +0 -85
  90. package/src/server/SharedStateCollection.js +0 -36
  91. package/src/server/Socket.js +0 -396
  92. package/src/server/Sockets.js +0 -224
  93. package/src/server/StateManager.js +0 -620
  94. package/tsconfig.json +0 -21
  95. package/types/client/Client.d.ts.map +0 -1
  96. package/types/client/Context.d.ts.map +0 -1
  97. package/types/client/ContextManager.d.ts.map +0 -1
  98. package/types/client/Plugin.d.ts +0 -53
  99. package/types/client/Plugin.d.ts.map +0 -1
  100. package/types/client/PluginManager.d.ts +0 -96
  101. package/types/client/PluginManager.d.ts.map +0 -1
  102. package/types/client/SharedState.d.ts +0 -85
  103. package/types/client/SharedState.d.ts.map +0 -1
  104. package/types/client/Socket.d.ts +0 -138
  105. package/types/client/Socket.d.ts.map +0 -1
  106. package/types/client/StateManager.d.ts.map +0 -1
  107. package/types/client/index.d.ts.map +0 -1
  108. package/types/common/BasePlugin.d.ts.map +0 -1
  109. package/types/common/BasePluginManager.d.ts.map +0 -1
  110. package/types/common/BaseSharedState.d.ts +0 -173
  111. package/types/common/BaseSharedState.d.ts.map +0 -1
  112. package/types/common/BaseStateManager.d.ts.map +0 -1
  113. package/types/common/ParameterBag.d.ts.map +0 -1
  114. package/types/common/SharedStatePrivate.d.ts +0 -20
  115. package/types/common/SharedStatePrivate.d.ts.map +0 -1
  116. package/types/common/constants.d.ts.map +0 -1
  117. package/types/common/logger.d.ts.map +0 -1
  118. package/types/common/promise-store.d.ts +0 -4
  119. package/types/common/promise-store.d.ts.map +0 -1
  120. package/types/common/sockets-utils.d.ts.map +0 -1
  121. package/types/common/utils.d.ts +0 -5
  122. package/types/common/utils.d.ts.map +0 -1
  123. package/types/server/Client.d.ts +0 -40
  124. package/types/server/Client.d.ts.map +0 -1
  125. package/types/server/Context.d.ts +0 -59
  126. package/types/server/Context.d.ts.map +0 -1
  127. package/types/server/ContextManager.d.ts +0 -69
  128. package/types/server/ContextManager.d.ts.map +0 -1
  129. package/types/server/Plugin.d.ts +0 -70
  130. package/types/server/Plugin.d.ts.map +0 -1
  131. package/types/server/PluginManager.d.ts +0 -91
  132. package/types/server/PluginManager.d.ts.map +0 -1
  133. package/types/server/Server.d.ts.map +0 -1
  134. package/types/server/SharedState.d.ts +0 -86
  135. package/types/server/SharedState.d.ts.map +0 -1
  136. package/types/server/Socket.d.ts +0 -128
  137. package/types/server/Socket.d.ts.map +0 -1
  138. package/types/server/Sockets.d.ts +0 -73
  139. package/types/server/Sockets.d.ts.map +0 -1
  140. package/types/server/StateManager.d.ts +0 -190
  141. package/types/server/StateManager.d.ts.map +0 -1
  142. package/types/server/audit-network-latency.worker.d.ts.map +0 -1
  143. package/types/server/audit-schema.d.ts.map +0 -1
  144. package/types/server/index.d.ts.map +0 -1
@@ -0,0 +1,82 @@
1
+ /**
2
+ * User defined name for a class of {@link SharedState}
3
+ *
4
+ * @typedef {string} SharedStateClassName
5
+ */
6
+
7
+ /**
8
+ * Description of a {@link SharedState} data structure that describes the structure
9
+ * of a class of {@link SharedState} to be registered by {@link ServerStateManager#defineClass}
10
+ *
11
+ * A `SharedStateClassDescription` is the blueprint, or the definition from which
12
+ * shared states from a given class can be created.
13
+ *
14
+ * It consists of a set of key / value pairs where the key is the name of
15
+ * the parameter (cf. ${SharedStateParameterName}), and the value is an object
16
+ * describing the parameter (cf. ${SharedStateParameterDescription}).
17
+ *
18
+ * @typedef {Object.<SharedStateParameterName, SharedStateParameterDescription>} SharedStateClassDescription
19
+ *
20
+ * @example
21
+ * const myClassDescription = {
22
+ * triggerSound: {
23
+ * type: 'boolean',
24
+ * event: true,
25
+ * },
26
+ * volume: {
27
+ * type: 'float'
28
+ * default: 0,
29
+ * min: -80,
30
+ * max: 6,
31
+ * }
32
+ * };
33
+ *
34
+ * server.stateManager.defineClass('my-class-name', myClassDescription);
35
+ */
36
+
37
+ /**
38
+ * User defined name of a parameter in a class of {@link SharedState}
39
+ *
40
+ * @typedef {string} SharedStateParameterName
41
+ */
42
+
43
+ /**
44
+ * Description of a parameter in a class of {@link SharedState}
45
+ *
46
+ * @typedef {object} SharedStateParameterDescription
47
+ * @property {'boolean'|'string'|'integer'|'float'|'enum'|'any'} type - Type of the parameter.
48
+ * @property {any} default - Default value of the parameter. Optional only if
49
+ * `nullable = true` or `event = true`
50
+ * @property {boolean} [nullable=false] - Defines if the parameter is nullable.
51
+ * When `true` the parameter `default` is set to `null`.
52
+ * @property {boolean} [event=false] - Define if the parameter is a volatile, i.e.
53
+ * its value only exists on an update and is set back to `null` after propagation.
54
+ * When `true`, `nullable` is automatically set to `true` and `default` to `null`.
55
+ * @property {boolean} [filterChange=true] - When set to `false`, an update will
56
+ * trigger the propagation of a parameter even when its value didn't change.
57
+ * This option provides a sort of middle ground between the default behavior
58
+ * (e.g. where only changed values are propagated) and the behavior of the `event`
59
+ * option (which has no state per se). Hence, setting this options to `false` if
60
+ * `event=true` makes no sens.
61
+ * @property {boolean} [immediate=false] - When set to `true`, an update will
62
+ * trigger the update listeners immediately on the node that generated the update,
63
+ * before propagating the change on the network.
64
+ * This option is useful in cases the network would introduce a noticeable
65
+ * latency on the client.
66
+ * If for some reason the value is overridden server-side (e.g. in an `updateHook`)
67
+ * the listeners will be called again when the "real" value is received.
68
+ * @property {boolean} [required=false] - When set to true, the parameter must be
69
+ * provided in the initialization values when the state is created.
70
+ * @property {boolean} [local=false] - When set to true, the parameter is never
71
+ * propagated on the network (hence it is no longer a shared parameter :). This
72
+ * is useful to declare some common parameter (e.g. some interface state) that
73
+ * don't need to be shared but to stay in the shared state API paradigm.
74
+ * @property {number} [min=-Number.MIN_VALUE] - Minimum value of the parameter. Only applies
75
+ * for `integer` and `float` types.
76
+ * @property {number} [max=Number.MAX_VALUE] - Maximum value of the parameter. Only applies
77
+ * for `integer` and `float` types.
78
+ * @property {Array<any>} [list] - Possible values of the parameter. Only applies and
79
+ * mandatory for `enum` type.
80
+ * @property {object} [metas={}] - Optional metadata of the parameter.
81
+ */
82
+
@@ -1,67 +1,3 @@
1
- import 'fast-text-encoding';
2
- import root from 'window-or-global';
3
-
4
- const encoder = new root.TextEncoder('utf-8');
5
- const decoder = new root.TextDecoder('utf-8');
6
-
7
- const types = [
8
- 'Int8Array',
9
- 'Uint8Array',
10
- 'Uint8ClampedArray',
11
- 'Int16Array',
12
- 'Uint16Array',
13
- 'Int32Array',
14
- 'Uint32Array',
15
- 'Float32Array',
16
- 'Float64Array',
17
- 'BigInt64Array',
18
- 'BigUint64Array',
19
- ];
20
-
21
- // @note - probably some room for optimizations
22
-
23
- /** @private */
24
- export function packBinaryMessage(channel, data) {
25
- const channelBuffer = encoder.encode(channel);
26
- const channelSize = channelBuffer.byteLength;
27
- const startOffset = Math.ceil((channelSize + 3) / data.BYTES_PER_ELEMENT) * data.BYTES_PER_ELEMENT;
28
- const bufferSize = startOffset + data.byteLength;
29
- const typeName = data.constructor.name;
30
- const typeIndex = types.indexOf(typeName);
31
-
32
- if (typeIndex === -1) {
33
- throw new Error(`Invalid TypedArray type: ${typeName}`);
34
- }
35
-
36
- const view = new Uint8Array(bufferSize);
37
- view[0] = channelSize;
38
- view[1] = typeIndex;
39
- view[2] = startOffset;
40
-
41
- view.set(channelBuffer, 3, channelSize);
42
- view.set(new Uint8Array(data.buffer), startOffset, data.byteLength);
43
-
44
- return view.buffer;
45
- }
46
-
47
- /** @private */
48
- export function unpackBinaryMessage(buffer /* arraybuffer */) {
49
- const infos = new Uint8Array(buffer, 0, 3);
50
- const channelSize = infos[0];
51
- const typeIndex = infos[1];
52
- const startOffset = infos[2];
53
-
54
- // need to slice as the library recreates a UInt8Array from the whole buffer
55
- // @todo - see if this copy could be avoided (probably needs a pull request)
56
- const channelBuffer = new Uint8Array(buffer.slice(3, 3 + channelSize));
57
- const channel = decoder.decode(channelBuffer);
58
- const type = types[typeIndex];
59
- // slice (copy) the underlying ArrayBuffer to create a clean TypedArray
60
- const data = new root[type](buffer.slice(startOffset));
61
-
62
- return [channel, data];
63
- }
64
-
65
1
  /** @private */
66
2
  export function packStringMessage(channel, ...args) {
67
3
  return JSON.stringify([channel, args]);
@@ -0,0 +1,2 @@
1
+ // [WARNING] This file is generated, do not edit
2
+ export default '5.0.0';