@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/server/Client.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export default Client;
|
|
2
|
-
/**
|
|
3
|
-
* Server-side representation of a `soundworks` client.
|
|
4
|
-
*
|
|
5
|
-
* @memberof server
|
|
6
|
-
* @hideconstructor
|
|
7
|
-
* @see {@link client.Client}
|
|
8
|
-
*/
|
|
9
|
-
declare class Client {
|
|
10
|
-
/**
|
|
11
|
-
* @param {String} role - Role of the client
|
|
12
|
-
* @param {server.Socket} socket - Socket connection with the client
|
|
13
|
-
*/
|
|
14
|
-
constructor(role: string, socket: server.Socket);
|
|
15
|
-
/**
|
|
16
|
-
* Client role, as specified in client side config {@link client.Client}.
|
|
17
|
-
*
|
|
18
|
-
* @type {String}
|
|
19
|
-
*/
|
|
20
|
-
role: string;
|
|
21
|
-
/**
|
|
22
|
-
* Session Id (incremented positive number).
|
|
23
|
-
*
|
|
24
|
-
* @type {Number}
|
|
25
|
-
*/
|
|
26
|
-
id: number;
|
|
27
|
-
/**
|
|
28
|
-
* Unique session Id (uuidv4).
|
|
29
|
-
*
|
|
30
|
-
* @type {String}
|
|
31
|
-
*/
|
|
32
|
-
uuid: string;
|
|
33
|
-
/**
|
|
34
|
-
* Socket connection with the remote client {@link client.Client}.
|
|
35
|
-
*
|
|
36
|
-
* @type {server.Socket}
|
|
37
|
-
*/
|
|
38
|
-
socket: server.Socket;
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=Client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../../src/server/Client.js"],"names":[],"mappings":";AAMA;;;;;;GAMG;AACH;IACE;;;OAGG;IACH,iDA4BC;IA3BC;;;;OAIG;IACH,aAAgB;IAEhB;;;;OAIG;IACH,WAAiC;IAEjC;;;;OAIG;IACH,aAAkB;IAElB;;;;OAIG;IACH,sBAAoB;CAEvB"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
export default Context;
|
|
2
|
-
/**
|
|
3
|
-
* Base class to extend in order to create the server-side counterpart of
|
|
4
|
-
* a {@link client.Context}. If not defined, a default context will be created
|
|
5
|
-
* and used by the server.
|
|
6
|
-
*
|
|
7
|
-
* @memberof server
|
|
8
|
-
*/
|
|
9
|
-
declare class Context {
|
|
10
|
-
constructor(server: any, roles?: any[]);
|
|
11
|
-
/**
|
|
12
|
-
* soundworks server
|
|
13
|
-
* @type {server.Server}
|
|
14
|
-
*/
|
|
15
|
-
server: server.Server;
|
|
16
|
-
/**
|
|
17
|
-
* List of clients that are currently in this context
|
|
18
|
-
* @type {Client[]}
|
|
19
|
-
*/
|
|
20
|
-
clients: Client[];
|
|
21
|
-
/**
|
|
22
|
-
* Status of the context ('idle', 'inited', 'started' or 'errored')
|
|
23
|
-
* @type {String}
|
|
24
|
-
*/
|
|
25
|
-
status: string;
|
|
26
|
-
roles: Set<any>;
|
|
27
|
-
/**
|
|
28
|
-
* Name of the context, default to the class name.
|
|
29
|
-
* Override the `get name()` getter to use a user-defined context name.
|
|
30
|
-
*/
|
|
31
|
-
get name(): string;
|
|
32
|
-
/**
|
|
33
|
-
* Method automatically called when the server starts, or lazilly called if
|
|
34
|
-
* the context is created after `server.start()`
|
|
35
|
-
*
|
|
36
|
-
* _WARNING: this method should never be called manually._
|
|
37
|
-
*/
|
|
38
|
-
start(): Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Method automatically called when the server stops.
|
|
41
|
-
*
|
|
42
|
-
* _WARNING: this method should never be called manually._
|
|
43
|
-
*/
|
|
44
|
-
stop(): Promise<void>;
|
|
45
|
-
/**
|
|
46
|
-
* Method automatically called when the client enters the context.
|
|
47
|
-
*
|
|
48
|
-
* _WARNING: this method should never be called manually._
|
|
49
|
-
*/
|
|
50
|
-
enter(client: any): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Method automatically called when the client exits the context.
|
|
53
|
-
*
|
|
54
|
-
* _WARNING: this method should never be called manually._
|
|
55
|
-
*/
|
|
56
|
-
exit(client: any): Promise<void>;
|
|
57
|
-
}
|
|
58
|
-
import Client from "./Client.js";
|
|
59
|
-
//# sourceMappingURL=Context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../src/server/Context.js"],"names":[],"mappings":";AAGA;;;;;;GAMG;AACH;IACE,wCAmCC;IA1BC;;;OAGG;IACH,sBAAoB;IAEpB;;;OAGG;IACH,SAFU,MAAM,EAAE,CAEM;IAExB;;;OAGG;IACH,eAAoB;IAMpB,gBAA2B;IAM7B;;;OAGG;IACH,mBAEC;IAED;;;;;OAKG;IACH,uBAAgB;IAEhB;;;;OAIG;IACH,sBAAe;IAEf;;;;OAIG;IACH,kCAMC;IAED;;;;OAIG;IACH,iCAMC;CACF"}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
export default ContextManager;
|
|
2
|
-
/**
|
|
3
|
-
* Manage the different server-side contexts and their lifecycle. The `ContextManager`
|
|
4
|
-
* is automatically instantiated by the {@link server.Server}.
|
|
5
|
-
*
|
|
6
|
-
* _WARNING: Most of the time, you should not have to manipulate the context manager directly._
|
|
7
|
-
*
|
|
8
|
-
* @memberof server
|
|
9
|
-
*/
|
|
10
|
-
declare class ContextManager {
|
|
11
|
-
/**
|
|
12
|
-
* @param {server.Server} server - Instance of the soundworks server.
|
|
13
|
-
*/
|
|
14
|
-
constructor(server: server.Server);
|
|
15
|
-
/** @private */
|
|
16
|
-
private server;
|
|
17
|
-
/** @private */
|
|
18
|
-
private _contexts;
|
|
19
|
-
/** @private */
|
|
20
|
-
private _contextStartPromises;
|
|
21
|
-
/**
|
|
22
|
-
* Register a context in the manager.
|
|
23
|
-
* This method is called in the {@link server.Context} constructor
|
|
24
|
-
*
|
|
25
|
-
* @param {server.Context} context - Context instance to register.
|
|
26
|
-
*
|
|
27
|
-
* @private
|
|
28
|
-
*/
|
|
29
|
-
private register;
|
|
30
|
-
/**
|
|
31
|
-
* Retrieve a started context from its name.
|
|
32
|
-
*
|
|
33
|
-
* @see {server.Context#name}
|
|
34
|
-
* @param {String} contextName - Name of the context.
|
|
35
|
-
*
|
|
36
|
-
* @private
|
|
37
|
-
*/
|
|
38
|
-
private get;
|
|
39
|
-
/**
|
|
40
|
-
* Called when a client connects to the server (websocket handshake)
|
|
41
|
-
*
|
|
42
|
-
* @param {server.Client} client
|
|
43
|
-
*
|
|
44
|
-
* @private
|
|
45
|
-
*/
|
|
46
|
-
private addClient;
|
|
47
|
-
/**
|
|
48
|
-
* Called when a client connects to the server (websocket 'close' event)
|
|
49
|
-
*
|
|
50
|
-
* @param {server.Client} client
|
|
51
|
-
*
|
|
52
|
-
* @private
|
|
53
|
-
*/
|
|
54
|
-
private removeClient;
|
|
55
|
-
/**
|
|
56
|
-
* Start all contexts registered before `await server.start()`.
|
|
57
|
-
* Called on {@link server.Server#start}
|
|
58
|
-
*
|
|
59
|
-
* @private
|
|
60
|
-
*/
|
|
61
|
-
private start;
|
|
62
|
-
/**
|
|
63
|
-
* Stop all contexts. Called on {@link server.Server#stop}
|
|
64
|
-
*
|
|
65
|
-
* @private
|
|
66
|
-
*/
|
|
67
|
-
private stop;
|
|
68
|
-
}
|
|
69
|
-
//# sourceMappingURL=ContextManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ContextManager.d.ts","sourceRoot":"","sources":["../../src/server/ContextManager.js"],"names":[],"mappings":";AAoDA;;;;;;;GAOG;AACH;IACE;;OAEG;IACH,mCAOC;IANC,eAAe;IACf,eAAoB;IACpB,eAAe;IACf,kBAAwC;IACxC,eAAe;IACf,8BAAsC;IAGxC;;;;;;;OAOG;IACH,iBAOC;IAED;;;;;;;OAOG;IACH,YAyBC;IAED;;;;;;OAMG;IACH,kBA0FC;IAED;;;;;;OAMG;IACH,qBAUC;IAED;;;;;OAKG;IACH,cAGC;IAED;;;;OAIG;IACH,aAGC;CACF"}
|
package/types/server/Plugin.d.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
export default Plugin;
|
|
2
|
-
export namespace server {
|
|
3
|
-
/**
|
|
4
|
-
* ~onStateChangeCallback
|
|
5
|
-
*/
|
|
6
|
-
export type Plugin = (#state: server.Plugin) => any;
|
|
7
|
-
/**
|
|
8
|
-
* Callback executed when the plugin state is updated.
|
|
9
|
-
*
|
|
10
|
-
* @callback server.Plugin~onStateChangeCallback
|
|
11
|
-
* @param {server.Plugin#state} state - Current state of the plugin.
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Delete the registered {@link server.Plugin~onStateChangeCallback}.
|
|
15
|
-
*
|
|
16
|
-
* @callback server.Plugin~deleteOnStateChangeCallback
|
|
17
|
-
*/
|
|
18
|
-
/**
|
|
19
|
-
* Base class to extend in order to create new `soundworks` plugins.
|
|
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 informations on the available plugins.
|
|
29
|
-
*
|
|
30
|
-
* _Creating new plugins should be considered an advanced usage._
|
|
31
|
-
*
|
|
32
|
-
* @memberof server
|
|
33
|
-
* @extends BasePlugin
|
|
34
|
-
* @inheritdoc
|
|
35
|
-
*/
|
|
36
|
-
class Plugin extends BasePlugin {
|
|
37
|
-
/**
|
|
38
|
-
* @param {server.Server} server - The soundworks server instance.
|
|
39
|
-
* @param {string} id - User defined id of the plugin as defined in
|
|
40
|
-
* {@link server.PluginManager#register}.
|
|
41
|
-
*/
|
|
42
|
-
constructor(server: server.Server, id: string);
|
|
43
|
-
/**
|
|
44
|
-
* Instance of soundworks server.
|
|
45
|
-
* @type {server.Server}
|
|
46
|
-
* @see {@link server.Server}
|
|
47
|
-
*/
|
|
48
|
-
server: server.Server;
|
|
49
|
-
/** @private */
|
|
50
|
-
private clients;
|
|
51
|
-
/**
|
|
52
|
-
* Method called when a client (which registered the client-side plugin),
|
|
53
|
-
* connects to the application. Override this method if you need to perform
|
|
54
|
-
* some particular logic (e.g. creating a shared state) for each clients.
|
|
55
|
-
*
|
|
56
|
-
* @param {server.Client} client
|
|
57
|
-
*/
|
|
58
|
-
addClient(client: server.Client): Promise<void>;
|
|
59
|
-
/**
|
|
60
|
-
* Method called when a client (which registered the client-side plugin),
|
|
61
|
-
* disconnects from the application. Override this method if you need to perform
|
|
62
|
-
* some particular logic (e.g. creating a shared state) for each clients.
|
|
63
|
-
*
|
|
64
|
-
* @param {server.Client} client
|
|
65
|
-
*/
|
|
66
|
-
removeClient(client: server.Client): Promise<void>;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
import BasePlugin from "../common/BasePlugin.js";
|
|
70
|
-
//# sourceMappingURL=Plugin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/server/Plugin.js"],"names":[],"mappings":";;;;;kCAMW,aAAa;IAJxB;;;;;OAKG;IAEH;;;;OAIG;IAEH;;;;;;;;;;;;;;;;;OAiBG;IACH;QACE;;;;WAIG;QACH,uCAHW,MAAM,EAehB;QATC;;;;WAIG;QACH,sBAAoB;QAEpB,eAAe;QACf,gBAAwB;QAG1B;;;;;;WAMG;QACH,gDAEC;QAED;;;;;;WAMG;QACH,mDAEC;KACF"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
export default PluginManager;
|
|
2
|
-
export namespace server {
|
|
3
|
-
/**
|
|
4
|
-
* ~onStateChangeCallback
|
|
5
|
-
*/
|
|
6
|
-
type PluginManager = (: object, initiator: server.Plugin | null) => any;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Callback executed when a plugin internal state is updated.
|
|
10
|
-
*
|
|
11
|
-
* @callback server.PluginManager~onStateChangeCallback
|
|
12
|
-
* @param {object<server.Plugin#id, server.Plugin>} fullState - List of all plugins.
|
|
13
|
-
* @param {server.Plugin|null} initiator - Plugin that initiated the update or `null`
|
|
14
|
-
* if the change was initiated by the state manager (i.e. when the initialization
|
|
15
|
-
* of the plugins starts).
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* Delete the registered {@link server.PluginManager~onStateChangeCallback}.
|
|
19
|
-
*
|
|
20
|
-
* @callback server.PluginManager~deleteOnStateChangeCallback
|
|
21
|
-
*/
|
|
22
|
-
/**
|
|
23
|
-
* The `PluginManager` allows to register and retrieve `soundworks` plugins.
|
|
24
|
-
*
|
|
25
|
-
* Plugins should always be registered both client-side and server-side,
|
|
26
|
-
* and before {@link client.Client#start} or {@link server.Server#start}
|
|
27
|
-
* are called for proper initialization.
|
|
28
|
-
*
|
|
29
|
-
* In some sitautions, you might want to register the same plugin factory several times
|
|
30
|
-
* using different ids (e.g. for watching several parts of the file system, etc.).
|
|
31
|
-
*
|
|
32
|
-
* Refer to the plugins' documentation for more precise examples, and the specific API
|
|
33
|
-
* they expose. See [https://soundworks.dev/guide/ecosystem](https://soundworks.dev/guide/ecosystem)
|
|
34
|
-
* for more informations on the available plugins.
|
|
35
|
-
*
|
|
36
|
-
* ```
|
|
37
|
-
* import { Server } from '@soundworks/core/server.js';
|
|
38
|
-
* import platformPlugin from '@soundworks/plugin-sync/server.js';
|
|
39
|
-
*
|
|
40
|
-
* const server = new Server(config);
|
|
41
|
-
* // register the plugin before `server.start()`
|
|
42
|
-
* server.pluginManager.register('sync', pluginSync);
|
|
43
|
-
*
|
|
44
|
-
* await server.start();
|
|
45
|
-
*
|
|
46
|
-
* const sync = await server.pluginManager.get('sync');
|
|
47
|
-
*
|
|
48
|
-
* setInterval(() => {
|
|
49
|
-
* // log the estimated global synced clock alongside the local clock.
|
|
50
|
-
* console.log(sync.getSyncTime(), sync.getLocalTime());
|
|
51
|
-
* }, 1000);
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* @memberof server
|
|
55
|
-
* @extends BasePluginManager
|
|
56
|
-
* @inheritdoc
|
|
57
|
-
* @hideconstructor
|
|
58
|
-
*/
|
|
59
|
-
declare class PluginManager extends BasePluginManager {
|
|
60
|
-
register(id: any, factory?: any, options?: {}, deps?: any[]): void;
|
|
61
|
-
/**
|
|
62
|
-
* Retrieve an fully started instance of a registered plugin.
|
|
63
|
-
*
|
|
64
|
-
* Be aware that the `get` method resolves only when the plugin is fully 'started',
|
|
65
|
-
* which is what we want 99.99% of the time. As such, and to prevent the application
|
|
66
|
-
* to be stuck in some kind of Promise dead lock, this method will throw if
|
|
67
|
-
* used before `server.init()` (or `server.start()`).
|
|
68
|
-
*
|
|
69
|
-
* To handle the remaining 0.01% cases and access plugin instances during their
|
|
70
|
-
* initialization (e.g. to display initialization screen, etc.), you should rely
|
|
71
|
-
* on the `onStateChange` method.
|
|
72
|
-
*
|
|
73
|
-
* _Note: the async API is designed to enable the dynamic creation of plugins (hopefully
|
|
74
|
-
* without brealing changes) in a future release._
|
|
75
|
-
*
|
|
76
|
-
* @param {server.Plugin#id} id - Id of the plugin as defined when registered.
|
|
77
|
-
* @returns {server.Plugin}
|
|
78
|
-
* @see {@link server.PluginManager#onStateChange}
|
|
79
|
-
*
|
|
80
|
-
* @private
|
|
81
|
-
*/
|
|
82
|
-
private get;
|
|
83
|
-
/** private */
|
|
84
|
-
checkRegisteredPlugins(registeredPlugins: any): void;
|
|
85
|
-
/** @private */
|
|
86
|
-
private addClient;
|
|
87
|
-
/** @private */
|
|
88
|
-
private removeClient;
|
|
89
|
-
}
|
|
90
|
-
import BasePluginManager from "../common/BasePluginManager.js";
|
|
91
|
-
//# sourceMappingURL=PluginManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../src/server/PluginManager.js"],"names":[],"mappings":";;;;;4BAQW,MAAM,aACN,gBAAc,IAAI;;AAL7B;;;;;;;;GAQG;AAEH;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH;IASE,mEAQC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,YAMC;IAID,cAAc;IACd,qDAYC;IAED,eAAe;IACf,kBAUC;IAED,eAAe;IACf,qBAUC;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Server.d.ts","sourceRoot":"","sources":["../../src/server/Server.js"],"names":[],"mappings":";AA2EA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH;IACE,yBA2IC;IAvIC;;;;;;;;;;;;;;;;;;OAkBG;IACH,YAA+C;IAuC/C;;;OAGG;IACH,YAAuB;IAIvB;;;OAGG;IACH,gBAAsB;IAEtB;;;;OAIG;IACH,WAAyC;IAEzC;;;;;OAKG;IACH,wBAA4B;IAE5B;;;;OAIG;IACH,oCAA4C;IAE5C;;;;OAIG;IACH,kCAAsC;IAEtC;;;OAGG;IACH,+BAA8C;IAE9C;;;OAGG;IACH;;;;;;;;;;;;;;;;;;;;;;;;MAAsB;IAEtB;;OAEG;IACH,eAAoB;IAEpB,eAAe;IACf,mCAIC;IAED,eAAe;IACf,iCAAyC;IACzC,eAAe;IACf,oBAAuB;IASzB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,sBAwMC;IAED;;;;;;;;;;;;OAYG;IACH,sBAoFC;IAGD;;;OAGG;IACH,sBAgBC;IAED;;;OAGG;IACH,yBAgEC;IAED;;;OAGG;IACH,4BAmEC;IAED;;;;;;;OAOG;IACH,2BAmBC;IAED,6CAIC;IAED,eAAe;IACf,wBAgBC;IAED;;;;;;;;;;;;;;OAcG;IACH,iCAsBC;IAED;;;;;;OAMG;IACH,4CAEC;IAED;;;;OAIG;IACH,8BAMC;CACF"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
export default SharedState;
|
|
2
|
-
export namespace server {
|
|
3
|
-
/**
|
|
4
|
-
* ~onUpdateCallback
|
|
5
|
-
*/
|
|
6
|
-
type SharedState = (newValues: any, oldValues: any, context?: Mixed) => any;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* @callback server.SharedState~onUpdateCallback
|
|
10
|
-
* @param {Object} newValues - Key / value pairs of the updates that have been
|
|
11
|
-
* applied to the state.
|
|
12
|
-
* @param {Object} oldValues - Key / value pairs of the updated params before
|
|
13
|
-
* the updates has been applied to the state.
|
|
14
|
-
* @param {Mixed} [context=null] - Optionnal context object that has been passed
|
|
15
|
-
* with the values updates in the `set` call.
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* Delete the registered {@link server.SharedState~onUpdateCallback}.
|
|
19
|
-
*
|
|
20
|
-
* @callback server.SharedState~deleteOnUpdateCallback
|
|
21
|
-
*/
|
|
22
|
-
/**
|
|
23
|
-
* The `SharedState` is one of the most important and versatile abstraction provided
|
|
24
|
-
* by `soundworks`. It represents a set of parameters that are synchronized accross
|
|
25
|
-
* every nodes of the application (clients and server) that declared some interest
|
|
26
|
-
* to the shared state.
|
|
27
|
-
*
|
|
28
|
-
* A `SharedState` is created according to a "schema" (in the sense of a database
|
|
29
|
-
* schema) that must be declared and registered server-side. Any number of `SharedState`s
|
|
30
|
-
* can be created from a single schema.
|
|
31
|
-
*
|
|
32
|
-
* A shared state can be created both by the clients or by the server (in which case
|
|
33
|
-
* it is generally considered as a global state of the application). Similarly any
|
|
34
|
-
* node of the application (clients or server) can declare interest and "attach" to
|
|
35
|
-
* a state created by another node. All node attached to a state can modify its values
|
|
36
|
-
* and/or react to the modifications applied by other nodes.
|
|
37
|
-
*
|
|
38
|
-
* Tutorial: {@link https://soundworks.dev/guide/state-manager.html}
|
|
39
|
-
*
|
|
40
|
-
* ```
|
|
41
|
-
* // server-side
|
|
42
|
-
* import { Server } from '@soundworks/server/index.js';
|
|
43
|
-
*
|
|
44
|
-
* const server = new Server(config);
|
|
45
|
-
* // declare and register the schema of a shared state.
|
|
46
|
-
* server.stateManager.registerSchema('some-global-state', {
|
|
47
|
-
* myRandom: {
|
|
48
|
-
* type: 'float',
|
|
49
|
-
* default: 0,
|
|
50
|
-
* }
|
|
51
|
-
* });
|
|
52
|
-
*
|
|
53
|
-
* await server.start();
|
|
54
|
-
*
|
|
55
|
-
* // create a global state server-side
|
|
56
|
-
* const globalState = await server.stateManager.create('some-global-state');
|
|
57
|
-
* // listen and react to the changes made by the clients
|
|
58
|
-
* globalState.onUpdate(updates => console.log(updates));
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
* ```
|
|
62
|
-
* // client-side
|
|
63
|
-
* import { Client } from '@soundworks/client.index.js';
|
|
64
|
-
*
|
|
65
|
-
* const client = new Client(config);
|
|
66
|
-
* await client.start();
|
|
67
|
-
*
|
|
68
|
-
* // attach to the global state created by the server
|
|
69
|
-
* const globalState = await client.stateManager.attach('some-global-state');
|
|
70
|
-
*
|
|
71
|
-
* // update the value of a `myRandom` parameter every seconds
|
|
72
|
-
* setInterval(() => {
|
|
73
|
-
* globalState.set({ myRandom: Math.random() });
|
|
74
|
-
* }, 1000);
|
|
75
|
-
* ``
|
|
76
|
-
*
|
|
77
|
-
* @memberof server
|
|
78
|
-
* @extends BaseSharedState
|
|
79
|
-
* @inheritdoc
|
|
80
|
-
* @hideconstructor
|
|
81
|
-
* @see {server.StateManager}
|
|
82
|
-
*/
|
|
83
|
-
declare class SharedState extends BaseSharedState {
|
|
84
|
-
}
|
|
85
|
-
import BaseSharedState from "../common/BaseSharedState.js";
|
|
86
|
-
//# sourceMappingURL=SharedState.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SharedState.d.ts","sourceRoot":"","sources":["../../src/server/SharedState.js"],"names":[],"mappings":";;;;;;;AAIA;;;;;;;;GAQG;AAEH;;;;GAIG;AAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH;CAA4C"}
|
package/types/server/Socket.d.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
export default Socket;
|
|
2
|
-
/**
|
|
3
|
-
* Simple wrapper with simple pubsub system built on top of `ws` sockets.
|
|
4
|
-
* The abstraction contains two different socket:
|
|
5
|
-
* - one configured for string (JSON compatible) messages
|
|
6
|
-
* - one configured with `binaryType=arraybuffer` for streaming data more
|
|
7
|
-
* efficiently.
|
|
8
|
-
*
|
|
9
|
-
* @see https://github.com/websockets/ws
|
|
10
|
-
*
|
|
11
|
-
* @memberof server
|
|
12
|
-
*/
|
|
13
|
-
declare class Socket {
|
|
14
|
-
constructor(ws: any, binaryWs: any, rooms: any, sockets: any, options?: {});
|
|
15
|
-
/**
|
|
16
|
-
* Reference to the sockets object, is mainly dedicated to allow
|
|
17
|
-
* broadcasting from a given socket instance.
|
|
18
|
-
* @type {server.Sockets}
|
|
19
|
-
* @example
|
|
20
|
-
* socket.sockets.broadcast('my-room', this, 'update-value', 1);
|
|
21
|
-
*/
|
|
22
|
-
sockets: server.Sockets;
|
|
23
|
-
/**
|
|
24
|
-
* `ws` socket instance configured with `binaryType=blob` (string)
|
|
25
|
-
* @private
|
|
26
|
-
* @type {Object}
|
|
27
|
-
*/
|
|
28
|
-
private ws;
|
|
29
|
-
/**
|
|
30
|
-
* `ws` socket instance configured with `binaryType=arraybuffer` (TypedArray)
|
|
31
|
-
* @private
|
|
32
|
-
* @type {Object}
|
|
33
|
-
*/
|
|
34
|
-
private binaryWs;
|
|
35
|
-
/**
|
|
36
|
-
* `ws` socket instance configured with `binaryType=arraybuffer` (TypedArray)
|
|
37
|
-
* @private
|
|
38
|
-
* @type {Map}
|
|
39
|
-
*/
|
|
40
|
-
private rooms;
|
|
41
|
-
/**
|
|
42
|
-
* Configuration object
|
|
43
|
-
* @type {Object}
|
|
44
|
-
*/
|
|
45
|
-
config: any;
|
|
46
|
-
_stringListeners: Map<any, any>;
|
|
47
|
-
_binaryListeners: Map<any, any>;
|
|
48
|
-
_isAlive: boolean;
|
|
49
|
-
_intervalId: NodeJS.Timeout;
|
|
50
|
-
/**
|
|
51
|
-
* Called when the string socket closes (aka client reload).
|
|
52
|
-
*/
|
|
53
|
-
/** @private */
|
|
54
|
-
private terminate;
|
|
55
|
-
/** @private */
|
|
56
|
-
private _emit;
|
|
57
|
-
/** @private */
|
|
58
|
-
private _addListener;
|
|
59
|
-
/** @private */
|
|
60
|
-
private _removeListener;
|
|
61
|
-
/** @private */
|
|
62
|
-
private _removeAllListeners;
|
|
63
|
-
/**
|
|
64
|
-
* Add the socket to a room
|
|
65
|
-
* @param {String} roomId - Id of the room
|
|
66
|
-
*/
|
|
67
|
-
addToRoom(roomId: string): void;
|
|
68
|
-
/**
|
|
69
|
-
* Remove the socket from a room
|
|
70
|
-
* @param {String} roomId - Id of the room
|
|
71
|
-
*/
|
|
72
|
-
removeFromRoom(roomId: string): void;
|
|
73
|
-
/**
|
|
74
|
-
* Sends JSON compatible messages on a given channel
|
|
75
|
-
*
|
|
76
|
-
* @param {String} channel - Channel of the message
|
|
77
|
-
* @param {...*} args - Arguments of the message (as many as needed, of any type)
|
|
78
|
-
*/
|
|
79
|
-
send(channel: string, ...args: any[]): void;
|
|
80
|
-
/**
|
|
81
|
-
* Listen JSON compatible messages on a given channel
|
|
82
|
-
*
|
|
83
|
-
* @param {String} channel - Channel of the message
|
|
84
|
-
* @param {Function} callback - Callback to execute when a message is received
|
|
85
|
-
*/
|
|
86
|
-
addListener(channel: string, callback: Function): void;
|
|
87
|
-
/**
|
|
88
|
-
* Remove a listener from JSON compatible messages on a given channel
|
|
89
|
-
*
|
|
90
|
-
* @param {String} channel - Channel of the message
|
|
91
|
-
* @param {Function} callback - Callback to cancel
|
|
92
|
-
*/
|
|
93
|
-
removeListener(channel: string, callback: Function): void;
|
|
94
|
-
/**
|
|
95
|
-
* Remove all listeners from JSON compatible messages on a given channel
|
|
96
|
-
*
|
|
97
|
-
* @param {String} channel - Channel of the message
|
|
98
|
-
*/
|
|
99
|
-
removeAllListeners(channel: string): void;
|
|
100
|
-
/**
|
|
101
|
-
* Sends binary messages on a given channel
|
|
102
|
-
*
|
|
103
|
-
* @param {String} channel - Channel of the message
|
|
104
|
-
* @param {TypedArray} typedArray - Data to send
|
|
105
|
-
*/
|
|
106
|
-
sendBinary(channel: string, typedArray: TypedArray): void;
|
|
107
|
-
/**
|
|
108
|
-
* Listen binary messages on a given channel
|
|
109
|
-
*
|
|
110
|
-
* @param {String} channel - Channel of the message
|
|
111
|
-
* @param {Function} callback - Callback to execute when a message is received
|
|
112
|
-
*/
|
|
113
|
-
addBinaryListener(channel: string, callback: Function): void;
|
|
114
|
-
/**
|
|
115
|
-
* Remove a listener from binary compatible messages on a given channel
|
|
116
|
-
*
|
|
117
|
-
* @param {String} channel - Channel of the message
|
|
118
|
-
* @param {Function} callback - Callback to cancel
|
|
119
|
-
*/
|
|
120
|
-
removeBinaryListener(channel: string, callback: Function): void;
|
|
121
|
-
/**
|
|
122
|
-
* Remove all listeners from binary compatible messages on a given channel
|
|
123
|
-
*
|
|
124
|
-
* @param {String} channel - Channel of the message
|
|
125
|
-
*/
|
|
126
|
-
removeAllBinaryListeners(channel: string): void;
|
|
127
|
-
}
|
|
128
|
-
//# sourceMappingURL=Socket.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Socket.d.ts","sourceRoot":"","sources":["../../src/server/Socket.js"],"names":[],"mappings":";AAcA;;;;;;;;;;GAUG;AACH;IACE,4EA2HC;IAzHC;;;;;;OAMG;IACH,wBAAsB;IAEtB;;;;OAIG;IACH,WAAY;IAEZ;;;;OAIG;IACH,iBAAwB;IAExB;;;;OAIG;IACH,cAAkB;IAElB;;;OAGG;IACH,YAGC;IAED,gCAAiC;IACjC,gCAAiC;IAoDjC,kBAAoB;IAiBpB,4BAW4B;IAG9B;;OAEG;IACH,eAAe;IACf,kBAmCC;IAED,eAAe;IACf,cAOC;IAED,eAAe;IACf,qBAOC;IAED,eAAe;IACf,wBASC;IAED,eAAe;IACf,4BAIC;IAED;;;OAGG;IACH,gCAOC;IAED;;;OAGG;IACH,qCAKC;IAED;;;;;OAKG;IACH,4CAcC;IAED;;;;;OAKG;IACH,uDAEC;IAED;;;;;OAKG;IACH,0DAEC;IAED;;;;OAIG;IACH,0CAEC;IAED;;;;;OAKG;IACH,0DAQC;IAED;;;;;OAKG;IACH,6DAEC;IAED;;;;;OAKG;IACH,gEAEC;IAED;;;;OAIG;IACH,gDAEC;CACF"}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
export default Sockets;
|
|
2
|
-
/**
|
|
3
|
-
* Websocket server that creates and host all {@link server.Socket} instance.
|
|
4
|
-
* Most of the time, you shouldn't have to use this class instance directely, but
|
|
5
|
-
* it could be usefull in some situations, for broadcasting messages, creating rooms, etc.
|
|
6
|
-
*
|
|
7
|
-
* @memberof server
|
|
8
|
-
*/
|
|
9
|
-
declare class Sockets {
|
|
10
|
-
/** @private */
|
|
11
|
-
private _wss;
|
|
12
|
-
/** @private */
|
|
13
|
-
private _rooms;
|
|
14
|
-
/** @private */
|
|
15
|
-
private _initializationCache;
|
|
16
|
-
/** @private */
|
|
17
|
-
private _latencyStatsWorker;
|
|
18
|
-
/** @private */
|
|
19
|
-
private _auditState;
|
|
20
|
-
/**
|
|
21
|
-
* Initialize sockets, all sockets are added by default added to two rooms:
|
|
22
|
-
* - to the room corresponding to the client `role`
|
|
23
|
-
* - to the '*' that holds all connected sockets
|
|
24
|
-
*
|
|
25
|
-
* @private
|
|
26
|
-
*/
|
|
27
|
-
private start;
|
|
28
|
-
/** @protected */
|
|
29
|
-
protected terminate(): void;
|
|
30
|
-
/** @private */
|
|
31
|
-
private _broadcast;
|
|
32
|
-
/**
|
|
33
|
-
* Add a socket to a room
|
|
34
|
-
*
|
|
35
|
-
* @param {server.Socket} socket - Socket to add to the room.
|
|
36
|
-
* @param {String} roomId - Id of the room
|
|
37
|
-
*/
|
|
38
|
-
addToRoom(socket: server.Socket, roomId: string): void;
|
|
39
|
-
/**
|
|
40
|
-
* Remove a socket from a room
|
|
41
|
-
*
|
|
42
|
-
* @param {server.Socket} socket - Socket to remove from the room.
|
|
43
|
-
* @param {String} [roomId=null] - Id of the room
|
|
44
|
-
*/
|
|
45
|
-
removeFromRoom(socket: server.Socket, roomId?: string): void;
|
|
46
|
-
/**
|
|
47
|
-
* Send a string message to all client of given room(s). If no room
|
|
48
|
-
* not specified, the message is sent to all clients
|
|
49
|
-
*
|
|
50
|
-
* @param {String|Array} roomsIds - Ids of the rooms that must receive
|
|
51
|
-
* the message. If null the message is sent to all clients
|
|
52
|
-
* @param {server.Socket} excludeSocket - Optionnal
|
|
53
|
-
* socket to ignore when broadcasting the message, typically the client
|
|
54
|
-
* at the origin of the message
|
|
55
|
-
* @param {String} channel - Channel of the message
|
|
56
|
-
* @param {...*} args - Arguments of the message (as many as needed, of any type)
|
|
57
|
-
*/
|
|
58
|
-
broadcast(roomIds: any, excludeSocket: server.Socket, channel: string, ...args: any[]): void;
|
|
59
|
-
/**
|
|
60
|
-
* Send a binary message (TypedArray) to all client of given room(s). If no room
|
|
61
|
-
* not specified, the message is sent to all clients
|
|
62
|
-
*
|
|
63
|
-
* @param {String|Array} roomsIds - Ids of the rooms that must receive
|
|
64
|
-
* the message. If null the message is sent to all clients
|
|
65
|
-
* @param {server.Socket} excludeSocket - Optionnal
|
|
66
|
-
* socket to ignore when broadcasting the message, typically the client
|
|
67
|
-
* at the origin of the message
|
|
68
|
-
* @param {String} channel - Channel of the message
|
|
69
|
-
* @param {...*} args - Arguments of the message (as many as needed, of any type)
|
|
70
|
-
*/
|
|
71
|
-
broadcastBinary(roomIds: any, excludeSocket: server.Socket, channel: string, typedArray: any): void;
|
|
72
|
-
}
|
|
73
|
-
//# sourceMappingURL=Sockets.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Sockets.d.ts","sourceRoot":"","sources":["../../src/server/Sockets.js"],"names":[],"mappings":";AAYA;;;;;;GAMG;AACH;IAEI,eAAe;IACf,aAAgB;IAChB,eAAe;IACf,eAAuB;IAGvB,eAAe;IACf,6BAAqC;IAErC,eAAe;IACf,4BAA+B;IAC/B,eAAe;IACf,oBAAuB;IAIzB;;;;;;OAMG;IACH,cAwDC;IAED,iBAAiB;IACjB,4BAMC;IAED,eAAe;IACf,mBA8BC;IAED;;;;;OAKG;IACH,uDAEC;IAED;;;;;OAKG;IACH,6DAEC;IAED;;;;;;;;;;;OAWG;IACH,6FAEC;IAED;;;;;;;;;;;OAWG;IACH,oGAEC;CACF"}
|