@soundworks/core 4.0.0-alpha.9 → 5.0.1

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 +64 -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
@@ -1,190 +0,0 @@
1
- export default StateManager;
2
- export namespace server {
3
- /**
4
- * ~ObserveCallback
5
- */
6
- type StateManager = () => any;
7
- }
8
- /**
9
- * @callback server.StateManager~ObserveCallback
10
- * @async
11
- * @param {String} schemaName - name of the schema
12
- * @param {Number} stateId - id of the state
13
- * @param {Number} nodeId - id of the node that created the state
14
- */
15
- /**
16
- * The `StateManager` allows to create new {@link server.SharedState}s, or attach
17
- * to {@link server.SharedState}s created by other nodes (clients or server). It
18
- * can also track all the {@link server.SharedState}s created by other nodes.
19
- *
20
- * An instance of `StateManager` is automatically created by the `soundworks.Server`
21
- * at initialization (cf. {@link server.Server#stateManager}).
22
- *
23
- * Compared to the {@link client.StateManager}, the `server.StateManager` can also
24
- * create and delete schemas, as well as register update hook that are executed when
25
- * a state is updated.
26
- *
27
- * See {@link server.Server#stateManager}
28
- *
29
- * Tutorial: {@link https://soundworks.dev/guide/state-manager.html}
30
- *
31
- * ```
32
- * // server-side
33
- * import { Server } from '@soundworks/server/index.js';
34
- *
35
- * const server = new Server(config);
36
- * // declare and register the schema of a shared state.
37
- * server.stateManager.registerSchema('some-global-state', {
38
- * myRandom: {
39
- * type: 'float',
40
- * default: 0,
41
- * }
42
- * });
43
- *
44
- * await server.start();
45
- *
46
- * // create a global state server-side
47
- * const globalState = await server.stateManager.create('some-global-state');
48
- * // listen and react to the changes made by the clients
49
- * globalState.onUpdate(updates => console.log(updates));
50
- * ```
51
- *
52
- * ```
53
- * // client-side
54
- * import { Client } from '@soundworks/client.index.js';
55
- *
56
- * const client = new Client(config);
57
- * await client.start();
58
- *
59
- * // attach to the global state created by the server
60
- * const globalState = await client.stateManager.attach('some-global-state');
61
- *
62
- * // update the value of a `myRandom` parameter every seconds
63
- * setInterval(() => {
64
- * globalState.set({ myRandom: Math.random() });
65
- * }, 1000);
66
- * ```
67
- *
68
- * @memberof server
69
- * @extends BaseStateManager
70
- * @inheritdoc
71
- * @hideconstructor
72
- */
73
- declare class StateManager extends BaseStateManager {
74
- constructor();
75
- _clientByNodeId: Map<any, any>;
76
- _serverStatesById: Map<any, any>;
77
- _schemas: Map<any, any>;
78
- _observers: Set<any>;
79
- _hooksBySchemaName: Map<any, any>;
80
- /**
81
- * Add a client to the manager.
82
- *
83
- * This is automatically handled by the {@link server.Server} when a client connects.
84
- *
85
- * @param {Number} nodeId - Id of the client node, as given in
86
- * {@link client.StateManager}
87
- * @param {Object} transport - Tranpsort mecanism to communicate with the
88
- * client. Should implement a basic EventEmitter API.
89
- *
90
- * @private
91
- */
92
- private addClient;
93
- /**
94
- * Remove a client from the manager. Clean all created or attached states.
95
- *
96
- * This is automatically handled by the {@link server.Server} when a client disconnects.
97
- *
98
- * @param {Number} nodeId - Id of the client node, as given in
99
- * {@link client.StateManager}
100
- *
101
- * @private
102
- */
103
- private removeClient;
104
- /**
105
- * Register a schema from which shared states (cf. {@link common.SharedState})
106
- * can be instanciated.
107
- *
108
- * @param {String} schemaName - Name of the schema.
109
- * @param {server.StateManager~schema} schema - Data structure
110
- * describing the states that will be created from this schema.
111
- *
112
- * @see {@link server.StateManager#create}
113
- * @see {@link client.StateManager#create}
114
- *
115
- * @example
116
- * server.stateManager.registerSchema('my-schema', {
117
- * myBoolean: {
118
- * type: 'boolean'
119
- * default: false,
120
- * },
121
- * myFloat: {
122
- * type: 'float'
123
- * default: 0.1,
124
- * min: -1,
125
- * max: 1
126
- * }
127
- * })
128
- */
129
- registerSchema(schemaName: string, schema: any): void;
130
- /**
131
- * Delete a schema and all associated states.
132
- * When a schema is deleted, all states created from this schema are deleted
133
- * as well, therefore all attached clients are detached and the `onDetach`
134
- * and `onDelete` callbacks are called on the related states.
135
- *
136
- * @param {String} schemaName - Name of the schema.
137
- */
138
- deleteSchema(schemaName: string): void;
139
- /**
140
- * @callback server.StateManager~updateHook
141
- * @async
142
- *
143
- * @param {Object} updates - Update object as given on a set callback, or
144
- * result of the previous hook
145
- * @param {Object} currentValues - Current values of the state.
146
- * @param {Object} [context=null] - Optionnal context passed by the creator
147
- * of the update.
148
- *
149
- * @return {Object} The "real" updates to be applied on the state.
150
- */
151
- /**
152
- * Register a function for a given schema (e.g. will be applied on all states
153
- * created from this schema) that will be executed before the update values
154
- * are propagated. For example, this could be used to implement a preset system
155
- * where all the values of the state are updated from e.g. some data stored in
156
- * filesystem while the consumer of the state only want to update the preset name.
157
- *
158
- * The hook is associated to every state of its kind (i.e. schemaName) and
159
- * executed on every update (call of `set`). Note that the hooks are executed
160
- * server-side regarless the node on which `set` has been called and before
161
- * the "actual" update of the state (e.g. before the call of `onUpdate`).
162
- *
163
- * @param {String} schemaName - Kind of states on which applying the hook.
164
- * @param {server.StateManager~updateHook} updateHook - Function
165
- * called between the `set` call and the actual update.
166
- *
167
- * @returns {Fuction} deleteHook - Handler that deletes the hook when executed.
168
- *
169
- * @example
170
- * server.stateManager.registerSchema('hooked', {
171
- * name: { type: 'string', default: null, nullable: true },
172
- * name: { numUpdates: 'integer', default: 0 },
173
- * });
174
- * server.stateManager.registerUpdateHook('hooked', updates => {
175
- * return {
176
- * ...updates
177
- * numUpdates: currentValues.numUpdates + 1,
178
- * };
179
- * });
180
- *
181
- * const state = await server.stateManager.create('hooked');
182
- *
183
- * await state.set({ name: 'test' });
184
- * const values = state.getValues();
185
- * assert.deepEqual(result, { name: 'test', numUpdates: 1 });
186
- */
187
- registerUpdateHook(schemaName: string, updateHook: any): Fuction;
188
- }
189
- import BaseStateManager from "../common/BaseStateManager.js";
190
- //# sourceMappingURL=StateManager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StateManager.d.ts","sourceRoot":"","sources":["../../src/server/StateManager.js"],"names":[],"mappings":";;;;;;;AA4BA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH;IACE,cAcC;IAPC,+BAAgC;IAChC,iCAAkC;IAClC,wBAAyB;IACzB,qBAA2B;IAC3B,kCAAmC;IAKrC;;;;;;;;;;;OAWG;IACH,kBA6GC;IAED;;;;;;;;;OASG;IACH,qBAgCC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,sDAUC;IAED;;;;;;;OAOG;IACH,uCAqBC;IAED;;;;;;;;;;;OAWG;IAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,iEAUC;CAEF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"audit-network-latency.worker.d.ts","sourceRoot":"","sources":["../../src/server/audit-network-latency.worker.js"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"audit-schema.d.ts","sourceRoot":"","sources":["../../src/server/audit-schema.js"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.js"],"names":[],"mappings":""}