@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.
- package/.jsdoc +3 -1
- package/CHANGELOG.md +15 -5
- package/package.json +5 -5
- package/src/client/Client.js +78 -83
- package/src/client/{Context.js → ClientContext.js} +48 -38
- package/src/client/ClientContextManager.js +115 -0
- package/src/client/{Plugin.js → ClientPlugin.js} +22 -18
- package/src/client/{PluginManager.js → ClientPluginManager.js} +39 -35
- package/src/client/{Socket.js → ClientSocket.js} +54 -65
- package/src/client/{StateManager.js → ClientStateManager.js} +7 -8
- package/src/client/index.js +17 -41
- package/src/common/BasePlugin.js +56 -51
- package/src/common/BasePluginManager.js +175 -139
- package/src/common/BaseStateManager.js +316 -120
- package/src/common/BatchedTransport.js +24 -24
- package/src/common/ParameterBag.js +18 -6
- package/src/common/PromiseStore.js +1 -0
- package/src/common/{BaseSharedState.js → SharedState.js} +271 -199
- package/src/common/{BaseSharedStateCollection.js → SharedStateCollection.js} +92 -61
- package/src/common/logger.js +5 -0
- package/src/common/shared-state-types.js +76 -0
- package/src/common/version.js +1 -1
- package/src/server/Server.js +391 -354
- package/src/server/ServerClient.js +73 -0
- package/src/server/{Context.js → ServerContext.js} +85 -66
- package/src/server/{ContextManager.js → ServerContextManager.js} +98 -85
- package/src/server/{Plugin.js → ServerPlugin.js} +10 -24
- package/src/server/{PluginManager.js → ServerPluginManager.js} +76 -69
- package/src/server/{Socket.js → ServerSocket.js} +19 -18
- package/src/server/{Sockets.js → ServerSockets.js} +36 -27
- package/src/server/ServerStateManager.js +515 -0
- package/src/{common → server}/SharedStatePrivate.js +61 -26
- package/src/server/audit-network-latency.worker.js +9 -7
- package/src/server/audit-schema.js +1 -1
- package/src/server/crypto.js +2 -0
- package/src/server/index.js +18 -21
- package/types/client/Client.d.ts +74 -95
- package/types/client/{Context.d.ts → ClientContext.d.ts} +25 -26
- package/types/client/{ContextManager.d.ts → ClientContextManager.d.ts} +19 -22
- package/types/client/{Plugin.d.ts → ClientPlugin.d.ts} +17 -20
- package/types/client/{PluginManager.d.ts → ClientPluginManager.d.ts} +13 -36
- package/types/client/ClientSocket.d.ts +74 -0
- package/types/client/{StateManager.d.ts → ClientStateManager.d.ts} +11 -15
- package/types/client/index.d.ts +26 -2
- package/types/common/BasePlugin.d.ts +52 -46
- package/types/common/BasePluginManager.d.ts +68 -44
- package/types/common/BaseStateManager.d.ts +207 -97
- package/types/common/BatchedTransport.d.ts +1 -5
- package/types/common/ParameterBag.d.ts +16 -18
- package/types/common/PromiseStore.d.ts +1 -1
- package/types/common/SharedState.d.ts +297 -0
- package/types/common/{BaseSharedStateCollection.d.ts → SharedStateCollection.d.ts} +34 -18
- package/types/common/constants.d.ts +0 -2
- package/types/common/logger.d.ts +2 -1
- package/types/common/shared-state-types.d.ts +83 -0
- package/types/common/sockets-utils.d.ts +0 -5
- package/types/common/version.d.ts +1 -2
- package/types/server/Server.d.ts +78 -132
- package/types/server/ServerClient.d.ts +45 -0
- package/types/server/{Context.d.ts → ServerContext.d.ts} +53 -43
- package/types/server/ServerContextManager.d.ts +80 -0
- package/types/server/{Plugin.d.ts → ServerPlugin.d.ts} +19 -33
- package/types/server/{PluginManager.d.ts → ServerPluginManager.d.ts} +39 -37
- package/types/server/ServerSocket.d.ts +85 -0
- package/types/server/ServerSockets.d.ts +50 -0
- package/types/server/ServerStateManager.d.ts +189 -0
- package/types/server/SharedStatePrivate.d.ts +21 -0
- package/types/server/audit-network-latency.worker.d.ts +1 -2
- package/types/server/audit-schema.d.ts +0 -1
- package/types/server/crypto.d.ts +2 -1
- package/types/server/index.d.ts +24 -2
- package/src/client/ContextManager.js +0 -111
- package/src/client/SharedState.js +0 -84
- package/src/client/SharedStateCollection.js +0 -38
- package/src/server/Client.js +0 -55
- package/src/server/SharedState.js +0 -85
- package/src/server/SharedStateCollection.js +0 -39
- package/src/server/StateManager.js +0 -696
- 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.map +0 -1
- 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/SharedStateCollection.d.ts +0 -41
- package/types/client/SharedStateCollection.d.ts.map +0 -1
- package/types/client/Socket.d.ts +0 -149
- 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 -244
- package/types/common/BaseSharedState.d.ts.map +0 -1
- package/types/common/BaseSharedStateCollection.d.ts.map +0 -1
- package/types/common/BaseStateManager.d.ts.map +0 -1
- package/types/common/BatchedTransport.d.ts.map +0 -1
- package/types/common/ParameterBag.d.ts.map +0 -1
- package/types/common/PromiseStore.d.ts.map +0 -1
- package/types/common/SharedStatePrivate.d.ts +0 -21
- 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/sockets-utils.d.ts.map +0 -1
- package/types/common/version.d.ts.map +0 -1
- package/types/server/Client.d.ts +0 -45
- package/types/server/Client.d.ts.map +0 -1
- 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.map +0 -1
- 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/SharedStateCollection.d.ts +0 -41
- package/types/server/SharedStateCollection.d.ts.map +0 -1
- package/types/server/Socket.d.ts +0 -164
- package/types/server/Socket.d.ts.map +0 -1
- package/types/server/Sockets.d.ts +0 -80
- package/types/server/Sockets.d.ts.map +0 -1
- package/types/server/StateManager.d.ts +0 -405
- 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/crypto.d.ts.map +0 -1
- 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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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);
|
package/src/server/crypto.js
CHANGED
|
@@ -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);
|
package/src/server/index.js
CHANGED
|
@@ -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
|
-
*
|
|
9
|
+
* Configuration object for the server.
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
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
|
|
28
|
+
export { default as ServerContext } from './ServerContext.js';
|
package/types/client/Client.d.ts
CHANGED
|
@@ -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 `
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
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
|
|
36
|
-
* const client = new Client({
|
|
37
|
-
*
|
|
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 {
|
|
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:
|
|
33
|
+
constructor(config: ClientConfig);
|
|
49
34
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* @
|
|
35
|
+
* Package version.
|
|
36
|
+
*
|
|
37
|
+
* @type {string}
|
|
53
38
|
*/
|
|
54
|
-
|
|
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 {
|
|
49
|
+
* @type {ClientConfig}
|
|
65
50
|
*/
|
|
66
|
-
config:
|
|
51
|
+
get config(): ClientConfig;
|
|
67
52
|
/**
|
|
68
|
-
* Session id of the client
|
|
69
|
-
*
|
|
70
|
-
* the server
|
|
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)
|
|
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
|
-
*
|
|
84
|
-
* the server.
|
|
69
|
+
* Runtime platform on which the client is executed, i.e. 'browser' or 'node'.
|
|
85
70
|
*
|
|
86
|
-
* @
|
|
87
|
-
* @type {client.Socket}
|
|
71
|
+
* @type {string}
|
|
88
72
|
*/
|
|
89
|
-
|
|
73
|
+
get target(): string;
|
|
90
74
|
/**
|
|
91
|
-
*
|
|
75
|
+
* Instance of the {@link client.Socket} class.
|
|
92
76
|
*
|
|
93
|
-
* @
|
|
77
|
+
* @see {@link ClientSocket}
|
|
78
|
+
* @type {ClientSocket}
|
|
94
79
|
*/
|
|
95
|
-
|
|
80
|
+
get socket(): ClientSocket;
|
|
96
81
|
/**
|
|
97
|
-
* Instance of the {@link
|
|
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
|
|
102
|
-
* @type {
|
|
86
|
+
* @see {@link ClientContextManager}
|
|
87
|
+
* @type {ClientContextManager}
|
|
103
88
|
*/
|
|
104
|
-
contextManager:
|
|
89
|
+
get contextManager(): ClientContextManager;
|
|
105
90
|
/**
|
|
106
|
-
* Instance of the {@link
|
|
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
|
|
111
|
-
* @type {
|
|
95
|
+
* @see {@link ClientPluginManager}
|
|
96
|
+
* @type {ClientPluginManager}
|
|
112
97
|
*/
|
|
113
|
-
pluginManager:
|
|
98
|
+
get pluginManager(): ClientPluginManager;
|
|
114
99
|
/**
|
|
115
|
-
* Instance of the {@link
|
|
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
|
|
120
|
-
* @type {
|
|
104
|
+
* @see {@link ClientStateManager}
|
|
105
|
+
* @type {ClientStateManager}
|
|
121
106
|
*/
|
|
122
|
-
stateManager:
|
|
107
|
+
get stateManager(): ClientStateManager;
|
|
123
108
|
/**
|
|
124
|
-
* Status of the client
|
|
109
|
+
* Status of the client.
|
|
125
110
|
*
|
|
126
|
-
* @type {
|
|
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
|
-
|
|
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,
|
|
141
|
-
* {@link
|
|
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
|
|
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
|
|
153
|
-
* the {@link
|
|
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.
|
|
168
|
-
*
|
|
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
|
|
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
|
|
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<
|
|
185
|
+
* @returns {Promise<SharedState>}
|
|
210
186
|
* @throws Will throw if called before `client.init()`
|
|
211
|
-
* @see {@link
|
|
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<
|
|
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}
|
|
197
|
+
* @returns {Function} Function that delete the listener when executed.
|
|
222
198
|
*/
|
|
223
199
|
onStatusChange(callback: Function): Function;
|
|
224
|
-
|
|
225
|
-
private
|
|
200
|
+
[kClientOnStatusChangeCallbacks]: Set<any>;
|
|
201
|
+
#private;
|
|
226
202
|
}
|
|
227
|
-
|
|
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
|
|
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
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,
|
|
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,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
|
|
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.
|
|
54
|
-
* @type {
|
|
55
|
-
* @readonly
|
|
53
|
+
* @type {Client}
|
|
56
54
|
*/
|
|
57
|
-
|
|
55
|
+
get client(): Client;
|
|
58
56
|
/**
|
|
59
|
-
* Status of the context
|
|
60
|
-
* @type {
|
|
61
|
-
* @readonly
|
|
57
|
+
* Status of the context.
|
|
58
|
+
* @type {'idle'|'inited'|'started'|'errored'}
|
|
62
59
|
*/
|
|
63
|
-
|
|
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
|
|
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. ${
|
|
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
|
|
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<
|
|
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
|
|
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<
|
|
160
|
+
exit(): Promise<void>;
|
|
161
|
+
[kClientContextStatus]: string;
|
|
162
|
+
#private;
|
|
164
163
|
}
|
|
165
|
-
|
|
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
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
export default
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
12
|
-
* @param {
|
|
9
|
+
* @callback ClientPlugin~onStateChangeCallback
|
|
10
|
+
* @param {ClientPlugin#state} state - Current state of the plugin.
|
|
13
11
|
*/
|
|
14
12
|
/**
|
|
15
|
-
* Delete the registered {@link
|
|
13
|
+
* Delete the registered {@link ClientPlugin~onStateChangeCallback}.
|
|
16
14
|
*
|
|
17
|
-
* @callback
|
|
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
|
|
35
|
+
declare class ClientPlugin extends BasePlugin {
|
|
39
36
|
/**
|
|
40
|
-
* @param {
|
|
37
|
+
* @param {Client} client - A soundworks client instance.
|
|
41
38
|
* @param {string} id - User defined id of the plugin as defined in
|
|
42
|
-
* {@link
|
|
39
|
+
* {@link ClientPluginManager#register}.
|
|
43
40
|
*/
|
|
44
|
-
constructor(client:
|
|
41
|
+
constructor(client: Client, id: string);
|
|
45
42
|
/**
|
|
46
43
|
* Instance of soundworks client.
|
|
47
44
|
*
|
|
48
|
-
* @type {
|
|
49
|
-
* @see {@link
|
|
45
|
+
* @type {Client}
|
|
46
|
+
* @see {@link Client}
|
|
50
47
|
*/
|
|
51
|
-
client:
|
|
48
|
+
get client(): Client;
|
|
49
|
+
#private;
|
|
52
50
|
}
|
|
53
51
|
import BasePlugin from '../common/BasePlugin.js';
|
|
54
|
-
//# sourceMappingURL=Plugin.d.ts.map
|