@soundworks/core 4.0.0-alpha.7 → 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.
- package/CHANGELOG.md +102 -0
- package/README.md +16 -50
- package/package.json +26 -44
- package/src/client/Client.js +306 -256
- package/src/client/{Context.js → ClientContext.js} +63 -54
- package/src/client/ClientContextManager.js +115 -0
- package/src/client/{Plugin.js → ClientPlugin.js} +23 -19
- package/src/client/{PluginManager.js → ClientPluginManager.js} +43 -40
- package/src/client/ClientSocket.js +270 -0
- package/src/client/{StateManager.js → ClientStateManager.js} +13 -13
- package/src/client/index.js +36 -39
- package/src/common/BasePlugin.js +63 -58
- package/src/common/BasePluginManager.js +191 -142
- package/src/common/BaseStateManager.js +636 -143
- package/src/common/BatchedTransport.js +73 -0
- package/src/common/ParameterBag.js +90 -93
- package/src/common/PromiseStore.js +54 -0
- package/src/common/SharedState.js +821 -0
- package/src/common/SharedStateCollection.js +492 -0
- package/src/common/constants.js +14 -2
- package/src/common/logger.js +64 -68
- package/src/common/shared-state-types.js +82 -0
- package/src/common/sockets-utils.js +0 -64
- package/src/common/version.js +2 -0
- package/src/server/Server.js +559 -821
- package/src/server/ServerClient.js +74 -0
- package/src/server/{Context.js → ServerContext.js} +96 -77
- package/src/server/{ContextManager.js → ServerContextManager.js} +107 -87
- package/src/server/{Plugin.js → ServerPlugin.js} +30 -32
- package/src/server/ServerPluginManager.js +177 -0
- package/src/server/ServerSocket.js +256 -0
- package/src/server/ServerSockets.js +150 -0
- package/src/server/ServerStateManager.js +706 -0
- package/src/server/SharedStatePrivate.js +277 -0
- package/src/server/audit-network-latency.worker.js +19 -4
- package/src/server/{audit-schema.js → audit-state-class-description.js} +3 -2
- package/src/server/create-http-server.js +127 -0
- package/src/server/crypto.js +8 -7
- package/src/server/index.js +60 -17
- package/types/client/Client.d.ts +95 -70
- package/types/client/{Context.d.ts → ClientContext.d.ts} +59 -34
- package/types/client/{ContextManager.d.ts → ClientContextManager.d.ts} +19 -22
- package/types/client/ClientPlugin.d.ts +51 -0
- package/types/client/ClientPluginManager.d.ts +112 -0
- package/types/client/ClientSocket.d.ts +76 -0
- package/types/client/{StateManager.d.ts → ClientStateManager.d.ts} +18 -21
- package/types/client/index.d.ts +33 -6
- package/types/common/BasePlugin.d.ts +64 -53
- package/types/common/BasePluginManager.d.ts +84 -39
- package/types/common/BaseStateManager.d.ts +227 -49
- package/types/common/BatchedTransport.d.ts +17 -0
- package/types/common/ParameterBag.d.ts +73 -76
- package/types/common/PromiseStore.d.ts +11 -0
- package/types/common/SharedState.d.ts +291 -0
- package/types/common/SharedStateCollection.d.ts +311 -0
- package/types/common/constants.d.ts +10 -3
- package/types/common/logger.d.ts +8 -6
- package/types/common/shared-state-types.d.ts +95 -0
- package/types/common/sockets-utils.d.ts +0 -5
- package/types/common/version.d.ts +2 -0
- package/types/server/Server.d.ts +215 -136
- package/types/server/ServerClient.d.ts +45 -0
- package/types/server/ServerContext.d.ts +209 -0
- package/types/server/ServerContextManager.d.ts +75 -0
- package/types/server/ServerPlugin.d.ts +57 -0
- package/types/server/ServerPluginManager.d.ts +115 -0
- package/types/server/ServerSocket.d.ts +69 -0
- package/types/server/ServerSockets.d.ts +42 -0
- package/types/server/ServerStateManager.d.ts +284 -0
- package/types/server/SharedStatePrivate.d.ts +23 -0
- package/types/server/audit-network-latency.worker.d.ts +2 -2
- package/types/server/{audit-schema.d.ts → audit-state-class-description.d.ts} +8 -9
- package/types/server/create-http-server.d.ts +5 -0
- package/types/server/crypto.d.ts +4 -0
- package/types/server/index.d.ts +51 -3
- package/.eslintrc +0 -15
- package/.github/workflows/gh-pages.yml +0 -31
- package/.github/workflows/unit-tests.yml +0 -18
- package/src/client/ContextManager.js +0 -111
- package/src/client/SharedState.js +0 -84
- package/src/client/SharedStateCollection.js +0 -35
- package/src/client/Socket.js +0 -402
- package/src/common/BaseSharedState.js +0 -517
- package/src/common/BaseSharedStateCollection.js +0 -179
- package/src/common/SharedStatePrivate.js +0 -192
- package/src/common/promise-store.js +0 -25
- package/src/server/Client.js +0 -55
- package/src/server/PluginManager.js +0 -170
- package/src/server/SharedState.js +0 -85
- package/src/server/SharedStateCollection.js +0 -36
- package/src/server/Socket.js +0 -396
- package/src/server/Sockets.js +0 -224
- package/src/server/StateManager.js +0 -620
- package/tsconfig.json +0 -21
- package/types/client/Client.d.ts.map +0 -1
- package/types/client/Context.d.ts.map +0 -1
- package/types/client/ContextManager.d.ts.map +0 -1
- package/types/client/Plugin.d.ts +0 -53
- package/types/client/Plugin.d.ts.map +0 -1
- package/types/client/PluginManager.d.ts +0 -96
- package/types/client/PluginManager.d.ts.map +0 -1
- package/types/client/SharedState.d.ts +0 -85
- package/types/client/SharedState.d.ts.map +0 -1
- package/types/client/Socket.d.ts +0 -138
- package/types/client/Socket.d.ts.map +0 -1
- package/types/client/StateManager.d.ts.map +0 -1
- package/types/client/index.d.ts.map +0 -1
- package/types/common/BasePlugin.d.ts.map +0 -1
- package/types/common/BasePluginManager.d.ts.map +0 -1
- package/types/common/BaseSharedState.d.ts +0 -173
- package/types/common/BaseSharedState.d.ts.map +0 -1
- package/types/common/BaseStateManager.d.ts.map +0 -1
- package/types/common/ParameterBag.d.ts.map +0 -1
- package/types/common/SharedStatePrivate.d.ts +0 -20
- package/types/common/SharedStatePrivate.d.ts.map +0 -1
- package/types/common/constants.d.ts.map +0 -1
- package/types/common/logger.d.ts.map +0 -1
- package/types/common/promise-store.d.ts +0 -4
- package/types/common/promise-store.d.ts.map +0 -1
- package/types/common/sockets-utils.d.ts.map +0 -1
- package/types/common/utils.d.ts +0 -5
- package/types/common/utils.d.ts.map +0 -1
- package/types/server/Client.d.ts +0 -40
- package/types/server/Client.d.ts.map +0 -1
- package/types/server/Context.d.ts +0 -59
- package/types/server/Context.d.ts.map +0 -1
- package/types/server/ContextManager.d.ts +0 -69
- package/types/server/ContextManager.d.ts.map +0 -1
- package/types/server/Plugin.d.ts +0 -70
- package/types/server/Plugin.d.ts.map +0 -1
- package/types/server/PluginManager.d.ts +0 -91
- package/types/server/PluginManager.d.ts.map +0 -1
- package/types/server/Server.d.ts.map +0 -1
- package/types/server/SharedState.d.ts +0 -86
- package/types/server/SharedState.d.ts.map +0 -1
- package/types/server/Socket.d.ts +0 -128
- package/types/server/Socket.d.ts.map +0 -1
- package/types/server/Sockets.d.ts +0 -73
- package/types/server/Sockets.d.ts.map +0 -1
- package/types/server/StateManager.d.ts +0 -190
- package/types/server/StateManager.d.ts.map +0 -1
- package/types/server/audit-network-latency.worker.d.ts.map +0 -1
- package/types/server/audit-schema.d.ts.map +0 -1
- package/types/server/index.d.ts.map +0 -1
package/types/client/Client.d.ts
CHANGED
|
@@ -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
|
|
5
|
+
* The `Client` class is the main entry point for the client-side of a soundworks
|
|
4
6
|
* application.
|
|
5
7
|
*
|
|
6
|
-
* A `
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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
|
|
14
|
-
* const client = new Client({
|
|
15
|
-
*
|
|
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 {
|
|
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:
|
|
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 {
|
|
49
|
+
* @type {ClientConfig}
|
|
38
50
|
*/
|
|
39
|
-
config:
|
|
51
|
+
get config(): ClientConfig;
|
|
40
52
|
/**
|
|
41
|
-
* Session id of the client
|
|
42
|
-
*
|
|
43
|
-
* the server
|
|
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)
|
|
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
|
-
*
|
|
57
|
-
*
|
|
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
|
-
*
|
|
60
|
-
* @type {
|
|
73
|
+
* Generated and retrieved by the server during {@link Client#init}.
|
|
74
|
+
* @type {string}
|
|
61
75
|
*/
|
|
62
|
-
|
|
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 {
|
|
80
|
+
* @type {'node'|'browser'}
|
|
81
|
+
*/
|
|
82
|
+
get runtime(): "node" | "browser";
|
|
83
|
+
/**
|
|
84
|
+
* @deprecated Use {@link Client#runtime} instead.
|
|
67
85
|
*/
|
|
68
|
-
target:
|
|
86
|
+
get target(): "browser" | "node";
|
|
69
87
|
/**
|
|
70
|
-
* Instance of the {@link client.
|
|
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
|
|
75
|
-
* @type {
|
|
99
|
+
* @see {@link ClientContextManager}
|
|
100
|
+
* @type {ClientContextManager}
|
|
76
101
|
*/
|
|
77
|
-
contextManager:
|
|
102
|
+
get contextManager(): ClientContextManager;
|
|
78
103
|
/**
|
|
79
|
-
* Instance of the {@link
|
|
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
|
|
84
|
-
* @type {
|
|
108
|
+
* @see {@link ClientPluginManager}
|
|
109
|
+
* @type {ClientPluginManager}
|
|
85
110
|
*/
|
|
86
|
-
pluginManager:
|
|
111
|
+
get pluginManager(): ClientPluginManager<any>;
|
|
87
112
|
/**
|
|
88
|
-
* Instance of the {@link
|
|
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
|
|
93
|
-
* @type {
|
|
117
|
+
* @see {@link ClientStateManager}
|
|
118
|
+
* @type {ClientStateManager}
|
|
94
119
|
*/
|
|
95
|
-
stateManager:
|
|
120
|
+
get stateManager(): ClientStateManager;
|
|
96
121
|
/**
|
|
97
|
-
* Status of the client
|
|
122
|
+
* Status of the client.
|
|
98
123
|
*
|
|
99
|
-
* @type {
|
|
124
|
+
* @type {'idle'|'inited'|'started'|'errored'}
|
|
100
125
|
*/
|
|
101
|
-
status:
|
|
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,
|
|
109
|
-
* {@link
|
|
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
|
|
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
|
|
121
|
-
* the {@link
|
|
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
|
-
* //
|
|
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.
|
|
136
|
-
*
|
|
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
|
-
* -
|
|
140
|
-
* -
|
|
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
|
|
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
|
|
170
|
-
* global
|
|
171
|
-
* clients, network latency estimation, etc. It is
|
|
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<
|
|
198
|
+
* @returns {Promise<SharedState>}
|
|
177
199
|
* @throws Will throw if called before `client.init()`
|
|
178
|
-
* @see {@link
|
|
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<
|
|
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}
|
|
210
|
+
* @returns {Function} Function that delete the listener when executed.
|
|
189
211
|
*/
|
|
190
212
|
onStatusChange(callback: Function): Function;
|
|
191
|
-
|
|
192
|
-
private
|
|
213
|
+
[kClientOnStatusChangeCallbacks]: Set<any>;
|
|
214
|
+
#private;
|
|
193
215
|
}
|
|
194
|
-
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
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
|
|
45
|
+
declare class ClientContext {
|
|
47
46
|
/**
|
|
48
|
-
* @param {
|
|
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:
|
|
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
|
|
57
|
+
* Status of the context.
|
|
58
|
+
* @type {'idle'|'inited'|'started'|'errored'}
|
|
58
59
|
*/
|
|
59
|
-
status:
|
|
60
|
+
get status(): "idle" | "inited" | "started" | "errored";
|
|
60
61
|
/**
|
|
61
|
-
*
|
|
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
|
-
* @
|
|
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
|
|
74
|
-
*
|
|
75
|
-
*
|
|
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
|
-
*
|
|
78
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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<
|
|
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
|
|
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<
|
|
160
|
+
exit(): Promise<void>;
|
|
161
|
+
[kClientContextStatus]: string;
|
|
162
|
+
#private;
|
|
137
163
|
}
|
|
138
|
-
import Client from
|
|
139
|
-
//# sourceMappingURL=Context.d.ts.map
|
|
164
|
+
import Client from './Client.js';
|
|
@@ -1,45 +1,42 @@
|
|
|
1
|
-
export
|
|
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
|
|
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
|
|
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 {
|
|
20
|
+
* @param {string} contextName - Name of the context.
|
|
21
|
+
* @returns {Promise<ClientContext>}
|
|
30
22
|
*/
|
|
31
|
-
get(contextName:
|
|
23
|
+
get(contextName: string): Promise<ClientContext>;
|
|
32
24
|
/**
|
|
33
|
-
*
|
|
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
|
|
35
|
+
private [kClientContextManagerStart];
|
|
38
36
|
/**
|
|
39
37
|
* Stop all registered contexts. Called during `client.stop()`
|
|
40
|
-
*
|
|
41
38
|
* @private
|
|
42
39
|
*/
|
|
43
|
-
private
|
|
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';
|