@soundworks/core 4.0.0-alpha.27 → 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.
Files changed (128) hide show
  1. package/.jsdoc +3 -1
  2. package/CHANGELOG.md +15 -5
  3. package/package.json +5 -5
  4. package/src/client/Client.js +78 -83
  5. package/src/client/{Context.js → ClientContext.js} +48 -38
  6. package/src/client/ClientContextManager.js +115 -0
  7. package/src/client/{Plugin.js → ClientPlugin.js} +22 -18
  8. package/src/client/{PluginManager.js → ClientPluginManager.js} +39 -35
  9. package/src/client/{Socket.js → ClientSocket.js} +54 -65
  10. package/src/client/{StateManager.js → ClientStateManager.js} +7 -8
  11. package/src/client/index.js +17 -41
  12. package/src/common/BasePlugin.js +56 -51
  13. package/src/common/BasePluginManager.js +175 -139
  14. package/src/common/BaseStateManager.js +316 -120
  15. package/src/common/BatchedTransport.js +24 -24
  16. package/src/common/ParameterBag.js +18 -6
  17. package/src/common/PromiseStore.js +1 -0
  18. package/src/common/{BaseSharedState.js → SharedState.js} +271 -199
  19. package/src/common/{BaseSharedStateCollection.js → SharedStateCollection.js} +92 -61
  20. package/src/common/logger.js +5 -0
  21. package/src/common/shared-state-types.js +76 -0
  22. package/src/common/version.js +1 -1
  23. package/src/server/Server.js +391 -354
  24. package/src/server/ServerClient.js +73 -0
  25. package/src/server/{Context.js → ServerContext.js} +85 -66
  26. package/src/server/{ContextManager.js → ServerContextManager.js} +98 -85
  27. package/src/server/{Plugin.js → ServerPlugin.js} +10 -24
  28. package/src/server/{PluginManager.js → ServerPluginManager.js} +76 -69
  29. package/src/server/{Socket.js → ServerSocket.js} +19 -18
  30. package/src/server/{Sockets.js → ServerSockets.js} +36 -27
  31. package/src/server/ServerStateManager.js +515 -0
  32. package/src/{common → server}/SharedStatePrivate.js +61 -26
  33. package/src/server/audit-network-latency.worker.js +9 -7
  34. package/src/server/audit-schema.js +1 -1
  35. package/src/server/crypto.js +2 -0
  36. package/src/server/index.js +18 -21
  37. package/types/client/Client.d.ts +74 -95
  38. package/types/client/{Context.d.ts → ClientContext.d.ts} +25 -26
  39. package/types/client/{ContextManager.d.ts → ClientContextManager.d.ts} +19 -22
  40. package/types/client/{Plugin.d.ts → ClientPlugin.d.ts} +17 -20
  41. package/types/client/{PluginManager.d.ts → ClientPluginManager.d.ts} +13 -36
  42. package/types/client/ClientSocket.d.ts +74 -0
  43. package/types/client/{StateManager.d.ts → ClientStateManager.d.ts} +11 -15
  44. package/types/client/index.d.ts +26 -2
  45. package/types/common/BasePlugin.d.ts +52 -46
  46. package/types/common/BasePluginManager.d.ts +68 -44
  47. package/types/common/BaseStateManager.d.ts +207 -97
  48. package/types/common/BatchedTransport.d.ts +1 -5
  49. package/types/common/ParameterBag.d.ts +16 -18
  50. package/types/common/PromiseStore.d.ts +1 -1
  51. package/types/common/SharedState.d.ts +297 -0
  52. package/types/common/{BaseSharedStateCollection.d.ts → SharedStateCollection.d.ts} +34 -18
  53. package/types/common/constants.d.ts +0 -2
  54. package/types/common/logger.d.ts +2 -1
  55. package/types/common/shared-state-types.d.ts +83 -0
  56. package/types/common/sockets-utils.d.ts +0 -5
  57. package/types/common/version.d.ts +1 -2
  58. package/types/server/Server.d.ts +78 -132
  59. package/types/server/ServerClient.d.ts +45 -0
  60. package/types/server/{Context.d.ts → ServerContext.d.ts} +53 -43
  61. package/types/server/ServerContextManager.d.ts +80 -0
  62. package/types/server/{Plugin.d.ts → ServerPlugin.d.ts} +19 -33
  63. package/types/server/{PluginManager.d.ts → ServerPluginManager.d.ts} +39 -37
  64. package/types/server/ServerSocket.d.ts +85 -0
  65. package/types/server/ServerSockets.d.ts +50 -0
  66. package/types/server/ServerStateManager.d.ts +189 -0
  67. package/types/server/SharedStatePrivate.d.ts +21 -0
  68. package/types/server/audit-network-latency.worker.d.ts +1 -2
  69. package/types/server/audit-schema.d.ts +0 -1
  70. package/types/server/crypto.d.ts +2 -1
  71. package/types/server/index.d.ts +24 -2
  72. package/src/client/ContextManager.js +0 -111
  73. package/src/client/SharedState.js +0 -84
  74. package/src/client/SharedStateCollection.js +0 -38
  75. package/src/server/Client.js +0 -55
  76. package/src/server/SharedState.js +0 -85
  77. package/src/server/SharedStateCollection.js +0 -39
  78. package/src/server/StateManager.js +0 -696
  79. package/types/client/Client.d.ts.map +0 -1
  80. package/types/client/Context.d.ts.map +0 -1
  81. package/types/client/ContextManager.d.ts.map +0 -1
  82. package/types/client/Plugin.d.ts.map +0 -1
  83. package/types/client/PluginManager.d.ts.map +0 -1
  84. package/types/client/SharedState.d.ts +0 -85
  85. package/types/client/SharedState.d.ts.map +0 -1
  86. package/types/client/SharedStateCollection.d.ts +0 -41
  87. package/types/client/SharedStateCollection.d.ts.map +0 -1
  88. package/types/client/Socket.d.ts +0 -149
  89. package/types/client/Socket.d.ts.map +0 -1
  90. package/types/client/StateManager.d.ts.map +0 -1
  91. package/types/client/index.d.ts.map +0 -1
  92. package/types/common/BasePlugin.d.ts.map +0 -1
  93. package/types/common/BasePluginManager.d.ts.map +0 -1
  94. package/types/common/BaseSharedState.d.ts +0 -244
  95. package/types/common/BaseSharedState.d.ts.map +0 -1
  96. package/types/common/BaseSharedStateCollection.d.ts.map +0 -1
  97. package/types/common/BaseStateManager.d.ts.map +0 -1
  98. package/types/common/BatchedTransport.d.ts.map +0 -1
  99. package/types/common/ParameterBag.d.ts.map +0 -1
  100. package/types/common/PromiseStore.d.ts.map +0 -1
  101. package/types/common/SharedStatePrivate.d.ts +0 -21
  102. package/types/common/SharedStatePrivate.d.ts.map +0 -1
  103. package/types/common/constants.d.ts.map +0 -1
  104. package/types/common/logger.d.ts.map +0 -1
  105. package/types/common/sockets-utils.d.ts.map +0 -1
  106. package/types/common/version.d.ts.map +0 -1
  107. package/types/server/Client.d.ts +0 -45
  108. package/types/server/Client.d.ts.map +0 -1
  109. package/types/server/Context.d.ts.map +0 -1
  110. package/types/server/ContextManager.d.ts +0 -69
  111. package/types/server/ContextManager.d.ts.map +0 -1
  112. package/types/server/Plugin.d.ts.map +0 -1
  113. package/types/server/PluginManager.d.ts.map +0 -1
  114. package/types/server/Server.d.ts.map +0 -1
  115. package/types/server/SharedState.d.ts +0 -86
  116. package/types/server/SharedState.d.ts.map +0 -1
  117. package/types/server/SharedStateCollection.d.ts +0 -41
  118. package/types/server/SharedStateCollection.d.ts.map +0 -1
  119. package/types/server/Socket.d.ts +0 -164
  120. package/types/server/Socket.d.ts.map +0 -1
  121. package/types/server/Sockets.d.ts +0 -80
  122. package/types/server/Sockets.d.ts.map +0 -1
  123. package/types/server/StateManager.d.ts +0 -405
  124. package/types/server/StateManager.d.ts.map +0 -1
  125. package/types/server/audit-network-latency.worker.d.ts.map +0 -1
  126. package/types/server/audit-schema.d.ts.map +0 -1
  127. package/types/server/crypto.d.ts.map +0 -1
  128. package/types/server/index.d.ts.map +0 -1
@@ -4,6 +4,7 @@
4
4
  // Should move back to regular esm module once Max has fixed its loader
5
5
  export default `
6
6
  const { parentPort } = require('node:worker_threads');
7
+ const { hrtime } = require('node:process');
7
8
 
8
9
  let stack = [];
9
10
  let averageLatencyWindow = 5;
@@ -13,12 +14,14 @@ let intervalId = null;
13
14
  let meanLatency = 0;
14
15
 
15
16
  // workaround that sc-utils is pure emascript module
16
- let getTime;
17
- let inited = new Promise(async (resolve) => {
18
- module = await import('@ircam/sc-utils');
19
- getTime = module.getTime;
20
- resolve(true);
21
- });
17
+ // 2024/09/06 - Just copy getTime implementation so that we don't even need the node_modules
18
+ const start = hrtime.bigint();
19
+
20
+ function getTime() {
21
+ const now = hrtime.bigint();
22
+ const delta = now - start;
23
+ return Number(delta) * 1e-9;
24
+ }
22
25
 
23
26
  parentPort.on('message', async msg => {
24
27
  switch (msg.type) {
@@ -26,7 +29,6 @@ parentPort.on('message', async msg => {
26
29
  averageLatencyWindow = msg.value.averageLatencyWindow;
27
30
  averageLatencyPeriod = msg.value.averageLatencyPeriod;
28
31
 
29
- await inited;
30
32
  // launch compute in its own loop so that the number of computation is
31
33
  // decoupled from the number of connected clients
32
34
  clearInterval(intervalId);
@@ -17,7 +17,7 @@ export default {
17
17
  },
18
18
 
19
19
  /**
20
- * Average latency in seconds computed from ping/pong.
20
+ * Average latency in seconds computed from ping/pong informations.
21
21
  */
22
22
  averageNetworkLatency: {
23
23
  type: 'float',
@@ -21,6 +21,7 @@ const encryptionIV = crypto
21
21
  .substring(0, 16);
22
22
 
23
23
 
24
+ /** @private */
24
25
  export function encryptData(obj) {
25
26
  const data = JSON.stringify(obj);
26
27
  const cipher = crypto.createCipheriv(encryptionMethod, key, encryptionIV);
@@ -28,6 +29,7 @@ export function encryptData(obj) {
28
29
  return Buffer.from(cipher.update(data, 'utf8', 'hex') + cipher.final('hex')).toString('base64');
29
30
  }
30
31
 
32
+ /** @private */
31
33
  export function decryptData(encryptedData) {
32
34
  const buff = Buffer.from(encryptedData, 'base64');
33
35
  const decipher = crypto.createDecipheriv(encryptionMethod, key, encryptionIV);
@@ -4,28 +4,25 @@
4
4
  * SPDX-License-Identifier: BSD-3-Clause
5
5
  */
6
6
 
7
+ // this must be defined here so that we can import it into the application
7
8
  /**
8
- * Server-side part of the *soundworks* framework.
9
+ * Configuration object for the server.
9
10
  *
10
- * ```
11
- * import '@soundworks/helpers/polyfills.js';
12
- * import { Server } from '@soundworks/core/server.js';
13
- * import { loadConfig } from '../utils/load-config.js';
14
- *
15
- * // - General documentation: https://soundworks.dev/
16
- * // - API documentation: https://soundworks.dev/api
17
- * // - Issue Tracker: https://github.com/collective-soundworks/soundworks/issues
18
- * // - Wizard & Tools: `npx soundworks`
19
- *
20
- * const config = loadConfig(process.env.ENV, import.meta.url);
21
- *
22
- * const server = new Server(config);
23
- * server.setDefaultTemplateConfig();
24
- *
25
- * await server.start();
26
- * ```
27
- *
28
- * @namespace server
11
+ * @typedef ServerConfig
12
+ * @type {object}
13
+ * @property {object} [app] - Application configuration object.
14
+ * @property {object} app.clients - Definition of the application clients.
15
+ * @property {string} [app.name=''] - Name of the application.
16
+ * @property {string} [app.author=''] - Name of the author.
17
+ * @property {object} [env] - Environment configuration object.
18
+ * @property {boolean} env.useHttps - Define is the server run in http or in https.
19
+ * @property {string} env.serverAddress - Domain name or IP of the server.
20
+ * Mandatory when node clients are declared
21
+ * @property {number} env.port - Port on which the server is listening.
22
+ * @property {obj} [env.httpsInfos=null] - Path to cert files ( cert, key } for https.
23
+ * If not given and useHttps is true self certifified certificates will be created.
24
+ * @property {string} [env.subpath=''] - If running behind a proxy, path to the application.
29
25
  */
26
+
30
27
  export { default as Server } from './Server.js';
31
- export { default as Context } from './Context.js';
28
+ export { default as ServerContext } from './ServerContext.js';
@@ -1,147 +1,123 @@
1
+ export const kClientVersionTest: unique symbol;
2
+ export const kClientOnStatusChangeCallbacks: unique symbol;
1
3
  export default Client;
2
- /**
3
- * Configuration object for a client running in a browser runtime.
4
- */
5
- export type ClientConfig = any;
6
- /**
7
- * Configuration object for a client running in a browser runtime.
8
- *
9
- * @typedef ClientConfig
10
- * @memberof client
11
- * @type {object}
12
- * @property {string} role - Role of the client in the application (e.g. 'player', 'controller').
13
- * @property {object} [app] - Application configration object.
14
- * @property {string} [app.name=''] - Name of the application.
15
- * @property {string} [app.author=''] - Name of the author.
16
- * @property {object} [env] - Environment configration object.
17
- * @property {boolean} env.useHttps - Define if the websocket should use secure connection.
18
- * @property {boolean} [env.serverAddress=''] - Address the socket server. Mandatory for
19
- * node clients. For browser clients, use `window.location.domain` as fallback if empty.
20
- * @property {boolean} env.port - Port of the socket server.
21
- * @property {string} [env.websockets={}] - Configuration options for websockets.
22
- * @property {string} [env.subpath=''] - If running behind a proxy, path to the application.
23
- */
24
4
  /**
25
5
  * The `Client` class is the main entry point for the client-side of a soundworks
26
6
  * application.
27
7
  *
28
- * A `Client` instance allows to access soundworks components such as {@link client.StateManager},
29
- * {@link client.PluginManager},{@link client.Socket} or {@link client.ContextManager}.
30
- * Its is also responsible for handling the initialization lifecycles of the different
31
- * soundworks components.
8
+ * A `soundworks` client can run seamlessly in a browser or in a Node.js runtime.
9
+ *
10
+ * It provides an access to the different soundworks components such as the {@link ClientStateManager},
11
+ * {@link ClientPluginManager}, {@link ClientSocket} and the {@link ClientContextManager}.
32
12
  *
33
13
  * ```
34
14
  * import { Client } from '@soundworks/core/client.js';
35
- * // create a new soundworks `Client` instance
36
- * const client = new Client({ role: 'player' });
37
- * // init and start the client
15
+ * // create a `Client` instance
16
+ * const client = new Client({
17
+ * role: 'player',
18
+ * env: {
19
+ * useHttps: false,
20
+ * serverAddress: 'localhost',
21
+ * port: 8000,
22
+ * },
23
+ * });
24
+ * // start the client
38
25
  * await client.start();
39
26
  * ```
40
- *
41
- * @memberof client
42
27
  */
43
28
  declare class Client {
44
29
  /**
45
- * @param {client.ClientConfig} config - Configuration of the soundworks client.
30
+ * @param {ClientConfig} config - Configuration of the soundworks client.
46
31
  * @throws Will throw if the given config object is invalid.
47
32
  */
48
- constructor(config: client.ClientConfig);
33
+ constructor(config: ClientConfig);
49
34
  /**
50
- * package version
51
- * @type string
52
- * @readonly
35
+ * Package version.
36
+ *
37
+ * @type {string}
53
38
  */
54
- readonly version: string;
39
+ get version(): string;
55
40
  /**
56
41
  * Role of the client in the application.
57
42
  *
58
43
  * @type {string}
59
44
  */
60
- role: string;
45
+ get role(): string;
61
46
  /**
62
47
  * Configuration object.
63
48
  *
64
- * @type {client.ClientConfig}
49
+ * @type {ClientConfig}
65
50
  */
66
- config: client.ClientConfig;
51
+ get config(): ClientConfig;
67
52
  /**
68
- * Session id of the client (incremeted positive number), generated and
69
- * retrieved by the server during `client.init`. The counter is reset when
70
- * the server restarts.
53
+ * Session id of the client.
54
+ *
55
+ * Incremeted positive integer generated and retrieved by the server during
56
+ * `client.init`. The counter is reset when the server restarts.
71
57
  *
72
58
  * @type {number}
73
59
  */
74
- id: number;
60
+ get id(): number;
75
61
  /**
76
- * Unique session uuid of the client (uuidv4), generated and retrieved by
77
- * the server during {@link client.Client#init}.
62
+ * Unique session uuid of the client (uuidv4).
78
63
  *
64
+ * Generated and retrieved by the server during {@link Client#init}.
79
65
  * @type {string}
80
66
  */
81
- uuid: string;
67
+ get uuid(): string;
82
68
  /**
83
- * Instance of the {@link client.Socket} class that handle websockets communications with
84
- * the server.
69
+ * Runtime platform on which the client is executed, i.e. 'browser' or 'node'.
85
70
  *
86
- * @see {@link client.Socket}
87
- * @type {client.Socket}
71
+ * @type {string}
88
72
  */
89
- socket: client.Socket;
73
+ get target(): string;
90
74
  /**
91
- * Runtime platform on which the client is executed, i.e. 'browser' or 'node'.
75
+ * Instance of the {@link client.Socket} class.
92
76
  *
93
- * @type {string}
77
+ * @see {@link ClientSocket}
78
+ * @type {ClientSocket}
94
79
  */
95
- target: string;
80
+ get socket(): ClientSocket;
96
81
  /**
97
- * Instance of the {@link client.ContextManager} class.
82
+ * Instance of the {@link ClientContextManager} class.
98
83
  *
99
84
  * The context manager can be safely used after `client.init()` has been fulfilled.
100
85
  *
101
- * @see {@link client.ContextManager}
102
- * @type {client.ContextManager}
86
+ * @see {@link ClientContextManager}
87
+ * @type {ClientContextManager}
103
88
  */
104
- contextManager: client.ContextManager;
89
+ get contextManager(): ClientContextManager;
105
90
  /**
106
- * Instance of the {@link client.PluginManager} class.
91
+ * Instance of the {@link ClientPluginManager} class.
107
92
  *
108
93
  * The context manager can be safely used after `client.init()` has been fulfilled.
109
94
  *
110
- * @see {@link client.PluginManager}
111
- * @type {client.PluginManager}
95
+ * @see {@link ClientPluginManager}
96
+ * @type {ClientPluginManager}
112
97
  */
113
- pluginManager: client.PluginManager;
98
+ get pluginManager(): ClientPluginManager;
114
99
  /**
115
- * Instance of the {@link client.StateManager} class.
100
+ * Instance of the {@link ClientStateManager} class.
116
101
  *
117
102
  * The context manager can be safely used after `client.init()` has been fulfilled.
118
103
  *
119
- * @see {@link client.StateManager}
120
- * @type {client.StateManager}
104
+ * @see {@link ClientStateManager}
105
+ * @type {ClientStateManager}
121
106
  */
122
- stateManager: client.StateManager;
107
+ get stateManager(): ClientStateManager;
123
108
  /**
124
- * Status of the client, 'idle', 'inited', 'started' or 'errored'.
109
+ * Status of the client.
125
110
  *
126
- * @type {string}
127
- */
128
- status: string;
129
- /**
130
- * Token of the client if connected through HTTP authentication.
131
- * @private
111
+ * @type {'idle'|'inited'|'started'|'errored'}
132
112
  */
133
- private token;
134
- /** @private */
135
- private _onStatusChangeCallbacks;
136
- /** @private */
137
- private _auditState;
113
+ get status(): "idle" | "inited" | "started" | "errored";
138
114
  /**
139
115
  * The `init` method is part of the initialization lifecycle of the `soundworks`
140
- * client. Most of the time, the `init` method will be implicitly called by the
141
- * {@link client.Client#start} method.
116
+ * client. Most of the time, this method will be implicitly executed by the
117
+ * {@link Client#start} method.
142
118
  *
143
119
  * In some situations you might want to call this method manually, in such cases
144
- * the method should be called before the {@link client.Client#start} method.
120
+ * the method should be called before the {@link Client#start} method.
145
121
  *
146
122
  * What it does:
147
123
  * - connect the sockets to be server
@@ -149,8 +125,8 @@ declare class Client {
149
125
  * - launch the state manager
150
126
  * - initialize all registered plugin
151
127
  *
152
- * After `await client.init()` is fulfilled, the {@link client.Client#stateManager},
153
- * the {@link client.Client#pluginManager} and the {@link client.Client#socket}
128
+ * After `await client.init()` is fulfilled, the {@link Client#stateManager},
129
+ * the {@link Client#pluginManager} and the {@link Client#socket}
154
130
  * can be safely used.
155
131
  *
156
132
  * @example
@@ -164,11 +140,11 @@ declare class Client {
164
140
  init(): Promise<void>;
165
141
  /**
166
142
  * The `start` method is part of the initialization lifecycle of the `soundworks`
167
- * client. The `start` method will implicitly call the {@link client.Client#init}
168
- * method if it has not been called manually.
143
+ * client. This method will implicitly execute {@link Client#init} method if it
144
+ * has not been called manually.
169
145
  *
170
146
  * What it does:
171
- * - implicitly call {@link client.Client#init} if not done manually
147
+ * - implicitly call {@link Client#init} if not done manually
172
148
  * - start all created contexts. For that to happen, you will have to call `client.init`
173
149
  * manually and instantiate the contexts between `client.init()` and `client.start()`
174
150
  *
@@ -199,29 +175,32 @@ declare class Client {
199
175
  /**
200
176
  * Attach and retrieve the global audit state of the application.
201
177
  *
202
- * The audit state is a {@link client.SharedState} instance that keeps track of
178
+ * The audit state is a {@link SharedState} instance that keeps track of
203
179
  * global informations about the application such as, the number of connected
204
180
  * clients, network latency estimation, etc. It is usefull for controller client
205
181
  * roles to give the user an overview about the state of the application.
206
182
  *
207
183
  * The audit state is lazily attached to the client only if this method is called.
208
184
  *
209
- * @returns {Promise<client.SharedState>}
185
+ * @returns {Promise<SharedState>}
210
186
  * @throws Will throw if called before `client.init()`
211
- * @see {@link client.SharedState}
187
+ * @see {@link SharedState}
212
188
  * @example
213
189
  * const auditState = await client.getAuditState();
214
190
  * auditState.onUpdate(() => console.log(auditState.getValues()), true);
215
191
  */
216
- getAuditState(): Promise<client.SharedState>;
192
+ getAuditState(): Promise<SharedState>;
217
193
  /**
218
194
  * Listen for the status change ('inited', 'started', 'stopped') of the client.
219
195
  *
220
196
  * @param {Function} callback - Listener to the status change.
221
- * @returns {Function} Delete the listener.
197
+ * @returns {Function} Function that delete the listener when executed.
222
198
  */
223
199
  onStatusChange(callback: Function): Function;
224
- /** @private */
225
- private _dispatchStatus;
200
+ [kClientOnStatusChangeCallbacks]: Set<any>;
201
+ #private;
226
202
  }
227
- //# sourceMappingURL=Client.d.ts.map
203
+ import ClientSocket from './ClientSocket.js';
204
+ import ClientContextManager from './ClientContextManager.js';
205
+ import ClientPluginManager from './ClientPluginManager.js';
206
+ import ClientStateManager from './ClientStateManager.js';
@@ -1,9 +1,10 @@
1
- export default Context;
1
+ export const kClientContextStatus: unique symbol;
2
+ export default ClientContext;
2
3
  /**
3
4
  * Base class to extend in order to implement a new Context.
4
5
  *
5
6
  * In the `soundworks` paradigm, a client has a "role" (e.g. _player_, _controller_)
6
- * see {@link client.Client#role}) and can be in different "contexts" (e.g. different
7
+ * see {@link Client#role}) and can be in different "contexts" (e.g. different
7
8
  * part of the experience such as sections of a music piece, etc.). This class
8
9
  * provides a simple and unified way to model these reccuring aspects of an application.
9
10
  *
@@ -16,12 +17,12 @@ export default Context;
16
17
  * the context. In such case, `soundworks` guarantees that the server-side
17
18
  * logic is executed before the `enter()` and `exit()` promises are fulfilled.
18
19
  *
19
- * ```
20
- * import { Client, Context } from '@soundworks/core/index.js'
20
+ * ```js
21
+ * import { Client, ClientContext } from '@soundworks/core/index.js'
21
22
  *
22
23
  * const client = new Client(config);
23
24
  *
24
- * class MyContext extends Context {
25
+ * class MyContext extends ClientContext {
25
26
  * async enter() {
26
27
  * await super.enter();
27
28
  * console.log(`client ${this.client.id} entered my context`);
@@ -40,32 +41,28 @@ export default Context;
40
41
  * await new Promise(resolve => setTimeout(resolve, 2000));
41
42
  * await myContext.exit();
42
43
  * ```
43
- *
44
- * @memberof client
45
44
  */
46
- declare class Context {
45
+ declare class ClientContext {
47
46
  /**
48
- * @param {client.Client} client - The soundworks client instance.
47
+ * @param {Client} client - The soundworks client instance.
49
48
  * @throws Will throw if the first argument is not a soundworks client instance.
50
49
  */
51
- constructor(client: client.Client);
50
+ constructor(client: Client);
52
51
  /**
53
52
  * The soundworks client instance.
54
- * @type {client.Client}
55
- * @readonly
53
+ * @type {Client}
56
54
  */
57
- readonly client: client.Client;
55
+ get client(): Client;
58
56
  /**
59
- * Status of the context, i.e. 'idle', 'inited', 'started', 'errored'
60
- * @type {string}
61
- * @readonly
57
+ * Status of the context.
58
+ * @type {'idle'|'inited'|'started'|'errored'}
62
59
  */
63
- readonly status: string;
60
+ get status(): "idle" | "inited" | "started" | "errored";
64
61
  /**
65
62
  * Optionnal user-defined name of the context (defaults to the class name).
66
63
  *
67
64
  * The context manager will match the client-side and server-side contexts based
68
- * on this name. If the {@link server.ContextManager} don't find a corresponding
65
+ * on this name. If the {@link ServerContextManager} don't find a corresponding
69
66
  * user-defined context with the same name, it will use a default (noop) context.
70
67
  *
71
68
  * @readonly
@@ -81,7 +78,7 @@ declare class Context {
81
78
  readonly get name(): string;
82
79
  /**
83
80
  * Start the context. This method is lazilly called when the client enters the
84
- * context for the first time (cf. ${client.Context#enter}). If you know some
81
+ * context for the first time (cf. ${ClientContext#enter}). If you know some
85
82
  * some heavy and/or potentially long job has to be done when starting the context
86
83
  * (e.g. call to a web service) it may be a good practice to call it explicitely.
87
84
  *
@@ -118,12 +115,12 @@ declare class Context {
118
115
  * done (e.g. creating a shared state, etc.) when the context is entered.
119
116
  *
120
117
  * If a server-side part of the context is defined (i.e. a context with the same
121
- * {@link client.Context#name}), the corresponding server-side `enter()` method
118
+ * {@link ClientContext#name}), the corresponding server-side `enter()` method
122
119
  * will be executed before the returned Promise is fulfilled.
123
120
  *
124
121
  * If the context has not been started yet, the `start` method is implicitely executed.
125
122
  *
126
- * @returns {Promise} - Promise that resolves when the context is entered.
123
+ * @returns {Promise<void>} - Promise that resolves when the context is entered.
127
124
  * @example
128
125
  * class MyContext extends Context {
129
126
  * async enter() {
@@ -137,16 +134,16 @@ declare class Context {
137
134
  * }
138
135
  * }
139
136
  */
140
- enter(): Promise<any>;
137
+ enter(): Promise<void>;
141
138
  /**
142
139
  * Exit the context. Implement this method to define the logic that should be
143
140
  * done (e.g. delete a shared state, etc.) when the context is exited.
144
141
  *
145
142
  * If a server-side part of the context is defined (i.e. a context with the same
146
- * {@link client.Context#name}), the corresponding server-side `exit()` method
143
+ * {@link ClientContext#name}), the corresponding server-side `exit()` method
147
144
  * will be executed before the returned Promise is fulfilled.
148
145
  *
149
- * @returns {Promise} - Promise that resolves when the context is exited.
146
+ * @returns {Promise<void>} - Promise that resolves when the context is exited.
150
147
  * @example
151
148
  * class MyContext extends Context {
152
149
  * async enter() {
@@ -160,6 +157,8 @@ declare class Context {
160
157
  * }
161
158
  * }
162
159
  */
163
- exit(): Promise<any>;
160
+ exit(): Promise<void>;
161
+ [kClientContextStatus]: string;
162
+ #private;
164
163
  }
165
- //# sourceMappingURL=Context.d.ts.map
164
+ import Client from './Client.js';
@@ -1,45 +1,42 @@
1
- export default ContextManager;
1
+ export const kClientContextManagerStart: unique symbol;
2
+ export const kClientContextManagerStop: unique symbol;
3
+ export const kClientContextManagerRegister: unique symbol;
4
+ export default ClientContextManager;
2
5
  /**
3
6
  * Manage the different contexts and their lifecycle.
4
7
  *
5
- * See {@link client.Client#contextManager}
8
+ * See {@link Client#contextManager}
6
9
  *
7
10
  * _WARNING: In most cases, you should not have to manipulate the context manager directly._
8
11
  *
9
- * @memberof client
10
12
  * @hideconstructor
11
13
  */
12
- declare class ContextManager {
13
- /** @private */
14
- private _contexts;
15
- /** @private */
16
- private _contextStartPromises;
17
- /**
18
- * Register the context into the manager. Is called in context constructor.
19
- *
20
- * @param {client.Context} context - The context to be registered.
21
- * @private
22
- */
23
- private register;
14
+ declare class ClientContextManager {
24
15
  /**
25
16
  * Retrieve a started context from its name.
26
17
  *
27
18
  * _WARNING: Most of the time, you should not have to call this method manually._
28
19
  *
29
- * @param {client.Context#name} contextName - Name of the context.
20
+ * @param {string} contextName - Name of the context.
21
+ * @returns {Promise<ClientContext>}
30
22
  */
31
- get(contextName: any): Promise<any>;
23
+ get(contextName: string): Promise<ClientContext>;
32
24
  /**
33
- * Start all registered contexts. Called during `client.start()`
25
+ * Register the context into the manager. Is called in context constructor.
34
26
  *
27
+ * @param {ClientContext} context - The context to be registered.
28
+ * @private
29
+ */
30
+ private [kClientContextManagerRegister];
31
+ /**
32
+ * Start all registered contexts. Called during `client.start()`
35
33
  * @private
36
34
  */
37
- private start;
35
+ private [kClientContextManagerStart];
38
36
  /**
39
37
  * Stop all registered contexts. Called during `client.stop()`
40
- *
41
38
  * @private
42
39
  */
43
- private stop;
40
+ private [kClientContextManagerStop];
41
+ #private;
44
42
  }
45
- //# sourceMappingURL=ContextManager.d.ts.map
@@ -1,20 +1,18 @@
1
- export default Plugin;
2
- export namespace client {
3
- /**
4
- * ~onStateChangeCallback
5
- */
6
- type Plugin = (#state: client.Plugin) => any;
7
- }
1
+ export default ClientPlugin;
2
+ /**
3
+ * ~onStateChangeCallback
4
+ */
5
+ export type ClientPlugin = (#state: ClientPlugin) => any;
8
6
  /**
9
7
  * Callback executed when the plugin state is updated.
10
8
  *
11
- * @callback client.Plugin~onStateChangeCallback
12
- * @param {client.Plugin#state} state - Current state of the plugin.
9
+ * @callback ClientPlugin~onStateChangeCallback
10
+ * @param {ClientPlugin#state} state - Current state of the plugin.
13
11
  */
14
12
  /**
15
- * Delete the registered {@link client.Plugin~onStateChangeCallback}.
13
+ * Delete the registered {@link ClientPlugin~onStateChangeCallback}.
16
14
  *
17
- * @callback client.Plugin~deleteOnStateChangeCallback
15
+ * @callback ClientPlugin~deleteOnStateChangeCallback
18
16
  */
19
17
  /**
20
18
  * Base class to extend in order to create the client-side counterpart of a
@@ -31,24 +29,23 @@ export namespace client {
31
29
  *
32
30
  * _Creating new plugins should be considered an advanced usage._
33
31
  *
34
- * @memberof client
35
32
  * @extends BasePlugin
36
33
  * @inheritdoc
37
34
  */
38
- declare class Plugin extends BasePlugin {
35
+ declare class ClientPlugin extends BasePlugin {
39
36
  /**
40
- * @param {client.Client} client - The soundworks client instance.
37
+ * @param {Client} client - A soundworks client instance.
41
38
  * @param {string} id - User defined id of the plugin as defined in
42
- * {@link client.PluginManager#register}.
39
+ * {@link ClientPluginManager#register}.
43
40
  */
44
- constructor(client: client.Client, id: string);
41
+ constructor(client: Client, id: string);
45
42
  /**
46
43
  * Instance of soundworks client.
47
44
  *
48
- * @type {client.Client}
49
- * @see {@link client.Client}
45
+ * @type {Client}
46
+ * @see {@link Client}
50
47
  */
51
- client: client.Client;
48
+ get client(): Client;
49
+ #private;
52
50
  }
53
51
  import BasePlugin from '../common/BasePlugin.js';
54
- //# sourceMappingURL=Plugin.d.ts.map