@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,115 +1,136 @@
1
+ export const kClientVersionTest: unique symbol;
2
+ export const kClientOnStatusChangeCallbacks: unique symbol;
1
3
  export default Client;
2
4
  /**
3
- * The `Client` class is the main entry point for the client-side of soundworks
5
+ * The `Client` class is the main entry point for the client-side of a soundworks
4
6
  * application.
5
7
  *
6
- * A `Client` instance allows to access soundworks components such as {@link client.StateManager},
7
- * {@link client.PluginManager},{@link client.Socket} or {@link client.ContextManager}.
8
- * Its is also responsible for handling the initialization lifecycles of the different
9
- * 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}.
10
12
  *
11
13
  * ```
12
14
  * import { Client } from '@soundworks/core/client.js';
13
- * // create a new soundworks `Client` instance
14
- * const client = new Client({ role: 'player' });
15
- * // 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
16
25
  * await client.start();
17
26
  * ```
18
- *
19
- * @memberof client
20
27
  */
21
28
  declare class Client {
22
29
  /**
23
- * @param {client.BrowserClientConfig|client.NodeClientConfig} config -
24
- * Configuration of the soundworks client.
30
+ * @param {ClientConfig} config - Configuration of the soundworks client.
25
31
  * @throws Will throw if the given config object is invalid.
26
32
  */
27
- constructor(config: client.BrowserClientConfig | client.NodeClientConfig);
33
+ constructor(config: ClientConfig);
34
+ /**
35
+ * Package version.
36
+ *
37
+ * @type {string}
38
+ */
39
+ get version(): string;
28
40
  /**
29
41
  * Role of the client in the application.
30
42
  *
31
43
  * @type {string}
32
44
  */
33
- role: string;
45
+ get role(): string;
34
46
  /**
35
47
  * Configuration object.
36
48
  *
37
- * @type {client.BrowserClientConfig|client.NodeClientConfig}
49
+ * @type {ClientConfig}
38
50
  */
39
- config: client.BrowserClientConfig | client.NodeClientConfig;
51
+ get config(): ClientConfig;
40
52
  /**
41
- * Session id of the client (incremeted positive number), generated and
42
- * retrieved by the server during `client.init`. The counter is reset when
43
- * the server restarts.
53
+ * Session id of the client.
54
+ *
55
+ * Incremented positive integer generated and retrieved by the server during
56
+ * {@link Client#init}. The counter is reset when the server restarts.
44
57
  *
45
58
  * @type {number}
46
59
  */
47
- id: number;
60
+ get id(): number;
48
61
  /**
49
- * Unique session uuid of the client (uuidv4), generated and retrieved by
50
- * the server during {@link client.Client#init}.
62
+ * Unique session uuid of the client (uuidv4).
51
63
  *
64
+ * Generated and retrieved by the server during {@link Client#init}.
52
65
  * @type {string}
53
66
  */
54
- uuid: string;
67
+ get uuid(): string;
55
68
  /**
56
- * Instance of the {@link client.Socket} class that handle websockets communications with
57
- * the server.
69
+ * Authentication token generated by the server.
70
+ *
71
+ * Only set if client has gone through authentication process and is considered trusted.
58
72
  *
59
- * @see {@link client.Socket}
60
- * @type {client.Socket}
73
+ * Generated and retrieved by the server during {@link Client#init}.
74
+ * @type {string}
61
75
  */
62
- socket: client.Socket;
76
+ get token(): string;
63
77
  /**
64
78
  * Runtime platform on which the client is executed, i.e. 'browser' or 'node'.
65
79
  *
66
- * @type {string}
80
+ * @type {'node'|'browser'}
81
+ */
82
+ get runtime(): "node" | "browser";
83
+ /**
84
+ * @deprecated Use {@link Client#runtime} instead.
67
85
  */
68
- target: string;
86
+ get target(): "browser" | "node";
69
87
  /**
70
- * Instance of the {@link client.ContextManager} class.
88
+ * Instance of the {@link client.Socket} class.
89
+ *
90
+ * @see {@link ClientSocket}
91
+ * @type {ClientSocket}
92
+ */
93
+ get socket(): ClientSocket;
94
+ /**
95
+ * Instance of the {@link ClientContextManager} class.
71
96
  *
72
97
  * The context manager can be safely used after `client.init()` has been fulfilled.
73
98
  *
74
- * @see {@link client.ContextManager}
75
- * @type {client.ContextManager}
99
+ * @see {@link ClientContextManager}
100
+ * @type {ClientContextManager}
76
101
  */
77
- contextManager: client.ContextManager;
102
+ get contextManager(): ClientContextManager;
78
103
  /**
79
- * Instance of the {@link client.PluginManager} class.
104
+ * Instance of the {@link ClientPluginManager} class.
80
105
  *
81
106
  * The context manager can be safely used after `client.init()` has been fulfilled.
82
107
  *
83
- * @see {@link client.PluginManager}
84
- * @type {client.PluginManager}
108
+ * @see {@link ClientPluginManager}
109
+ * @type {ClientPluginManager}
85
110
  */
86
- pluginManager: client.PluginManager;
111
+ get pluginManager(): ClientPluginManager<any>;
87
112
  /**
88
- * Instance of the {@link client.StateManager} class.
113
+ * Instance of the {@link ClientStateManager} class.
89
114
  *
90
115
  * The context manager can be safely used after `client.init()` has been fulfilled.
91
116
  *
92
- * @see {@link client.StateManager}
93
- * @type {client.StateManager}
117
+ * @see {@link ClientStateManager}
118
+ * @type {ClientStateManager}
94
119
  */
95
- stateManager: client.StateManager;
120
+ get stateManager(): ClientStateManager;
96
121
  /**
97
- * Status of the client, 'idle', 'inited', 'started' or 'errored'.
122
+ * Status of the client.
98
123
  *
99
- * @type {string}
124
+ * @type {'idle'|'inited'|'started'|'errored'}
100
125
  */
101
- status: string;
102
- /** @private */
103
- private _onStatusChangeCallbacks;
104
- /** @private */
105
- private _auditState;
126
+ get status(): "idle" | "inited" | "started" | "errored";
106
127
  /**
107
128
  * The `init` method is part of the initialization lifecycle of the `soundworks`
108
- * client. Most of the time, the `init` method will be implicitly called by the
109
- * {@link client.Client#start} method.
129
+ * client. Most of the time, this method will be implicitly executed by the
130
+ * {@link Client#start} method.
110
131
  *
111
132
  * In some situations you might want to call this method manually, in such cases
112
- * the method should be called before the {@link client.Client#start} method.
133
+ * the method should be called before the {@link Client#start} method.
113
134
  *
114
135
  * What it does:
115
136
  * - connect the sockets to be server
@@ -117,27 +138,28 @@ declare class Client {
117
138
  * - launch the state manager
118
139
  * - initialize all registered plugin
119
140
  *
120
- * After `await client.init()` is fulfilled, the {@link client.Client#stateManager},
121
- * the {@link client.Client#pluginManager} and the {@link client.Client#socket}
141
+ * After `await client.init()` is fulfilled, the {@link Client#stateManager},
142
+ * the {@link Client#pluginManager} and the {@link Client#socket}
122
143
  * can be safely used.
123
144
  *
124
145
  * @example
125
146
  * import { Client } from '@soundworks/core/client.js'
126
147
  *
127
148
  * const client = new Client(config);
128
- * // optionnal explicit call of `init` before `start`
149
+ * // optional explicit call of `init` before `start`
129
150
  * await client.init();
130
151
  * await client.start();
131
152
  */
132
153
  init(): Promise<void>;
133
154
  /**
134
155
  * The `start` method is part of the initialization lifecycle of the `soundworks`
135
- * client. The `start` method will implicitly call the {@link client.Client#init}
136
- * method if it has not been called manually.
156
+ * client. This method will implicitly execute {@link Client#init} method if it
157
+ * has not been called manually.
137
158
  *
138
159
  * What it does:
139
- * - optionnaly call {@link client.Client#init}
140
- * - starts all the already created contexts (see {@link client.Context})
160
+ * - implicitly call {@link Client#init} if not done manually
161
+ * - start all created contexts. For that to happen, you will have to call `client.init`
162
+ * manually and instantiate the contexts between `client.init()` and `client.start()`
141
163
  *
142
164
  * @example
143
165
  * import { Client } from '@soundworks/core/client.js'
@@ -150,7 +172,7 @@ declare class Client {
150
172
  * Stops all started contexts, plugins and terminates the socket connections.
151
173
  *
152
174
  * In most situations, you might not need to call this method. However, it can
153
- * be usefull for unit testing or similar situations where you want to create
175
+ * be useful for unit testing or similar situations where you want to create
154
176
  * and delete several clients in the same process.
155
177
  *
156
178
  * @example
@@ -166,29 +188,32 @@ declare class Client {
166
188
  /**
167
189
  * Attach and retrieve the global audit state of the application.
168
190
  *
169
- * The audit state is a {@link client.SharedState} instance that keeps track of
170
- * global informations about the application such as, the number of connected
171
- * clients, network latency estimation, etc. It is usefull for controller client
191
+ * The audit state is a {@link SharedState} instance that keeps track of
192
+ * global information about the application such as, the number of connected
193
+ * clients, network latency estimation, etc. It is useful for controller client
172
194
  * roles to give the user an overview about the state of the application.
173
195
  *
174
196
  * The audit state is lazily attached to the client only if this method is called.
175
197
  *
176
- * @returns {Promise<client.SharedState>}
198
+ * @returns {Promise<SharedState>}
177
199
  * @throws Will throw if called before `client.init()`
178
- * @see {@link client.SharedState}
200
+ * @see {@link SharedState}
179
201
  * @example
180
202
  * const auditState = await client.getAuditState();
181
203
  * auditState.onUpdate(() => console.log(auditState.getValues()), true);
182
204
  */
183
- getAuditState(): Promise<client.SharedState>;
205
+ getAuditState(): Promise<SharedState>;
184
206
  /**
185
207
  * Listen for the status change ('inited', 'started', 'stopped') of the client.
186
208
  *
187
209
  * @param {Function} callback - Listener to the status change.
188
- * @returns {Function} Delete the listener.
210
+ * @returns {Function} Function that delete the listener when executed.
189
211
  */
190
212
  onStatusChange(callback: Function): Function;
191
- /** @private */
192
- private _dispatchStatus;
213
+ [kClientOnStatusChangeCallbacks]: Set<any>;
214
+ #private;
193
215
  }
194
- //# sourceMappingURL=Client.d.ts.map
216
+ import ClientSocket from './ClientSocket.js';
217
+ import ClientContextManager from './ClientContextManager.js';
218
+ import ClientPluginManager from './ClientPluginManager.js';
219
+ import ClientStateManager from './ClientStateManager.js';
@@ -1,11 +1,12 @@
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
- * provides a simple and unified way to model these reccuring aspects of an application.
9
+ * provides a simple and unified way to model these recurring aspects of an application.
9
10
  *
10
11
  * You can also think of a `Context` as a state of a state machine from which a
11
12
  * client can `enter()` or `exit()` (be aware that `soundworks` does not provide
@@ -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,50 +41,73 @@ 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.
53
+ * @type {Client}
54
54
  */
55
- client: Client;
55
+ get client(): Client;
56
56
  /**
57
- * Status of the context, i.e. 'idle', 'inited', 'started', 'errored'
57
+ * Status of the context.
58
+ * @type {'idle'|'inited'|'started'|'errored'}
58
59
  */
59
- status: string;
60
+ get status(): "idle" | "inited" | "started" | "errored";
60
61
  /**
61
- * Name of the context. Defaults to the class name, override to use a user-defined name.
62
+ * Optional user-defined name of the context (defaults to the class name).
63
+ *
64
+ * The context manager will match the client-side and server-side contexts based
65
+ * on this name. If the {@link ServerContextManager} don't find a corresponding
66
+ * user-defined context with the same name, it will use a default (noop) context.
62
67
  *
63
- * @returns {string} - Name of the context.
68
+ * @readonly
69
+ * @type {string}
64
70
  * @example
71
+ * // server-side and client-side contexts are matched based on their respective `name`
65
72
  * class MyContext extends Context {
66
73
  * get name() {
67
74
  * return 'my-user-defined-context-name';
68
75
  * }
69
76
  * }
70
77
  */
71
- get name(): string;
78
+ readonly get name(): string;
72
79
  /**
73
- * Start the context. This method is automatically called when `await client.start()`
74
- * is called, or lazilly called when entering the context (i.e. `context.enter()`)
75
- * if the context has been created after `client.start()`.
80
+ * Start the context. This method is lazily called when the client enters the
81
+ * context for the first time (cf. ${ClientContext#enter}). If you know some
82
+ * some heavy and/or potentially long job has to be done when starting the context
83
+ * (e.g. call to a web service) it may be a good practice to call it explicitly.
84
+ *
85
+ * This method should be implemented to perform operations that are valid for the
86
+ * whole lifetime of the context, regardless the client enters or exits the context.
87
+ *
88
+ * @example
89
+ * import { Context } from '@soundworks/core/client.js';
90
+ *
91
+ * class MyContext extends Context {
92
+ * async start() {
93
+ * await super.start();
94
+ * await this.doSomeLongJob();
95
+ * }
96
+ * }
76
97
  *
77
- * In some situation, you might want to implement this method to handle application
78
- * wise behavior regardeless the client enters or exists the context.
98
+ * // Instantiate the context
99
+ * const myContext = new Context(client);
100
+ * // manually start the context to perform the long operation before the client
101
+ * // enters the context.
102
+ * await myContext.start();
79
103
  */
80
104
  start(): Promise<void>;
81
105
  /**
82
106
  * Stop the context. This method is automatically called when `await client.stop()`
83
- * is called.
107
+ * is called. It should be used to cleanup context wise operations made in `start()`
108
+ * (e.g. destroy the reusable audio graph).
84
109
  *
85
- * In some situation, you might want to implement this method to handle application
86
- * wise behavior regardeless the client enters or exists the context.
110
+ * _WARNING: this method should never be called manually._
87
111
  */
88
112
  stop(): Promise<void>;
89
113
  /**
@@ -91,12 +115,12 @@ declare class Context {
91
115
  * done (e.g. creating a shared state, etc.) when the context is entered.
92
116
  *
93
117
  * If a server-side part of the context is defined (i.e. a context with the same
94
- * {@link client.Context#name}), the corresponding server-side `enter()` method
118
+ * {@link ClientContext#name}), the corresponding server-side `enter()` method
95
119
  * will be executed before the returned Promise is fulfilled.
96
120
  *
97
- * If the context has not been started yet, the `start` method is implicitely executed.
121
+ * If the context has not been started yet, the `start` method is implicitly executed.
98
122
  *
99
- * @returns {Promise} - Promise that resolves when the context is entered.
123
+ * @returns {Promise<void>} - Promise that resolves when the context is entered.
100
124
  * @example
101
125
  * class MyContext extends Context {
102
126
  * async enter() {
@@ -110,16 +134,16 @@ declare class Context {
110
134
  * }
111
135
  * }
112
136
  */
113
- enter(): Promise<any>;
137
+ enter(): Promise<void>;
114
138
  /**
115
139
  * Exit the context. Implement this method to define the logic that should be
116
140
  * done (e.g. delete a shared state, etc.) when the context is exited.
117
141
  *
118
142
  * If a server-side part of the context is defined (i.e. a context with the same
119
- * {@link client.Context#name}), the corresponding server-side `exit()` method
143
+ * {@link ClientContext#name}), the corresponding server-side `exit()` method
120
144
  * will be executed before the returned Promise is fulfilled.
121
145
  *
122
- * @returns {Promise} - Promise that resolves when the context is exited.
146
+ * @returns {Promise<void>} - Promise that resolves when the context is exited.
123
147
  * @example
124
148
  * class MyContext extends Context {
125
149
  * async enter() {
@@ -133,7 +157,8 @@ declare class Context {
133
157
  * }
134
158
  * }
135
159
  */
136
- exit(): Promise<any>;
160
+ exit(): Promise<void>;
161
+ [kClientContextStatus]: string;
162
+ #private;
137
163
  }
138
- import Client from "./Client.js";
139
- //# 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
@@ -0,0 +1,51 @@
1
+ export default ClientPlugin;
2
+ /**
3
+ * ~onStateChangeCallback
4
+ */
5
+ export type ClientPlugin = (#state: ClientPlugin) => any;
6
+ /**
7
+ * Callback executed when the plugin state is updated.
8
+ *
9
+ * @callback ClientPlugin~onStateChangeCallback
10
+ * @param {ClientPlugin#state} state - Current state of the plugin.
11
+ */
12
+ /**
13
+ * Delete the registered {@link ClientPlugin~onStateChangeCallback}.
14
+ *
15
+ * @callback ClientPlugin~deleteOnStateChangeCallback
16
+ */
17
+ /**
18
+ * Base class to extend in order to create the client-side counterpart of a
19
+ * `soundworks` plugin.
20
+ *
21
+ * In the `soundworks` paradigm, a plugin is a component that allows to extend
22
+ * the framework capabilities by encapsulating common and reusable logic in
23
+ * an application wise perspective. For example, plugins are available to handle
24
+ * clock synchronization, to deal with the file system, etc. Plugin should always
25
+ * have both a client-side and a server-side part.
26
+ *
27
+ * See [https://soundworks.dev/guide/ecosystem](https://soundworks.dev/guide/ecosystem)
28
+ * for more information on the available plugins.
29
+ *
30
+ * _Creating new plugins should be considered an advanced usage._
31
+ *
32
+ * @extends BasePlugin
33
+ * @inheritdoc
34
+ */
35
+ declare class ClientPlugin extends BasePlugin {
36
+ /**
37
+ * @param {Client} client - A soundworks client instance.
38
+ * @param {string} id - User defined id of the plugin as defined in
39
+ * {@link ClientPluginManager#register}.
40
+ */
41
+ constructor(client: Client, id: string);
42
+ /**
43
+ * Instance of soundworks client.
44
+ *
45
+ * @type {Client}
46
+ * @see {@link Client}
47
+ */
48
+ get client(): Client;
49
+ #private;
50
+ }
51
+ import BasePlugin from '../common/BasePlugin.js';