@soundworks/core 4.0.0-alpha.28 → 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 +11 -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-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
|
@@ -1,29 +1,9 @@
|
|
|
1
|
-
export default
|
|
2
|
-
export namespace client {
|
|
3
|
-
/**
|
|
4
|
-
* ~onStateChangeCallback
|
|
5
|
-
*/
|
|
6
|
-
type PluginManager = (: object, initiator: client.Plugin | null) => any;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Callback executed when a plugin internal state is updated.
|
|
10
|
-
*
|
|
11
|
-
* @callback client.PluginManager~onStateChangeCallback
|
|
12
|
-
* @param {object<client.Plugin#id, client.Plugin>} fullState - List of all plugins.
|
|
13
|
-
* @param {client.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 client.PluginManager~onStateChangeCallback}.
|
|
19
|
-
*
|
|
20
|
-
* @callback client.PluginManager~deleteOnStateChangeCallback
|
|
21
|
-
*/
|
|
1
|
+
export default ClientPluginManager;
|
|
22
2
|
/**
|
|
23
3
|
* The `PluginManager` allows to register and retrieve `soundworks` plugins.
|
|
24
4
|
*
|
|
25
5
|
* Plugins should always be registered both client-side and server-side,
|
|
26
|
-
* and before {@link
|
|
6
|
+
* and before {@link Client#start} or {@link Server#start}
|
|
27
7
|
* to be properly initialized.
|
|
28
8
|
*
|
|
29
9
|
* In some sitautions, you might want to register the same plugin factory several times
|
|
@@ -33,7 +13,7 @@ export namespace client {
|
|
|
33
13
|
* they expose. See [https://soundworks.dev/guide/ecosystem](https://soundworks.dev/guide/ecosystem)
|
|
34
14
|
* for more informations on the available plugins.
|
|
35
15
|
*
|
|
36
|
-
* See {@link
|
|
16
|
+
* See {@link Client#pluginManager}
|
|
37
17
|
*
|
|
38
18
|
* ```
|
|
39
19
|
* // client-side
|
|
@@ -73,17 +53,15 @@ export namespace client {
|
|
|
73
53
|
* }, 1000);
|
|
74
54
|
* ```
|
|
75
55
|
*
|
|
76
|
-
* @memberof client
|
|
77
56
|
* @extends BasePluginManager
|
|
78
57
|
* @inheritdoc
|
|
79
58
|
* @hideconstructor
|
|
80
59
|
*/
|
|
81
|
-
declare class
|
|
60
|
+
declare class ClientPluginManager extends BasePluginManager {
|
|
82
61
|
/**
|
|
83
|
-
* @param {
|
|
62
|
+
* @param {Client} client - The soundworks client instance.
|
|
84
63
|
*/
|
|
85
|
-
constructor(client:
|
|
86
|
-
register(id: any, factory: any, options?: {}, deps?: any[]): void;
|
|
64
|
+
constructor(client: Client);
|
|
87
65
|
/**
|
|
88
66
|
* Retrieve an fully started instance of a registered plugin.
|
|
89
67
|
*
|
|
@@ -97,15 +75,14 @@ declare class PluginManager extends BasePluginManager {
|
|
|
97
75
|
* on the `onStateChange` method.
|
|
98
76
|
*
|
|
99
77
|
* _Note: the async API is designed to enable the dynamic creation of plugins
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* @param {client.Plugin#id} id - Id of the plugin as defined when registered.
|
|
103
|
-
* @returns {client.Plugin}
|
|
104
|
-
* @see {@link client.PluginManager#onStateChange}
|
|
78
|
+
* in a future release._
|
|
105
79
|
*
|
|
106
|
-
* @
|
|
80
|
+
* @param {string} id - Id of the plugin as defined when registered.
|
|
81
|
+
* @returns {Promise<ClientPlugin>}
|
|
82
|
+
* @see {@link ClientPluginManager#onStateChange}
|
|
107
83
|
*/
|
|
108
|
-
|
|
84
|
+
get(id: string): Promise<ClientPlugin>;
|
|
109
85
|
}
|
|
110
86
|
import BasePluginManager from '../common/BasePluginManager.js';
|
|
111
|
-
|
|
87
|
+
import ClientPlugin from './ClientPlugin.js';
|
|
88
|
+
import Client from './Client.js';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export const kSocketTerminate: unique symbol;
|
|
2
|
+
export default ClientSocket;
|
|
3
|
+
/**
|
|
4
|
+
* The ClientSocket class is a simple publish / subscribe wrapper built on top of the
|
|
5
|
+
* [isomorphic-ws](https://github.com/heineiuo/isomorphic-ws) library.
|
|
6
|
+
* An instance of `ClientSocket` is automatically created by the `soundworks.Client`
|
|
7
|
+
* (see {@link Client#socket}).
|
|
8
|
+
*
|
|
9
|
+
* _Important: In most cases, you should consider using a {@link SharedState}
|
|
10
|
+
* rather than directly using the sockets._
|
|
11
|
+
*
|
|
12
|
+
* The ClientSocket class concurrently opens two different WebSockets:
|
|
13
|
+
* - a socket configured with `binaryType = 'blob'` for JSON compatible data
|
|
14
|
+
* types (i.e. string, number, boolean, object, array and null).
|
|
15
|
+
* - a socket configured with `binaryType= 'arraybuffer'` for efficient streaming
|
|
16
|
+
* of binary data.
|
|
17
|
+
*
|
|
18
|
+
* Both sockets re-emits all "native" ws events ('open', 'upgrade', 'close', 'error'
|
|
19
|
+
* and 'message'.
|
|
20
|
+
*
|
|
21
|
+
* @hideconstructor
|
|
22
|
+
*/
|
|
23
|
+
declare class ClientSocket {
|
|
24
|
+
constructor(role: any, config: any, socketOptions: any);
|
|
25
|
+
/**
|
|
26
|
+
* Initialize a websocket connection with the server. Automatically called
|
|
27
|
+
* during {@link Client#init}
|
|
28
|
+
*
|
|
29
|
+
* @param {string} role - Role of the client (see {@link Client#role})
|
|
30
|
+
* @param {object} config - Configuration of the sockets
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
private init;
|
|
34
|
+
/**
|
|
35
|
+
* Send messages with JSON compatible data types on a given channel.
|
|
36
|
+
*
|
|
37
|
+
* @param {string} channel - Channel name.
|
|
38
|
+
* @param {...*} args - Payload of the message. As many arguments as needed, of
|
|
39
|
+
* JSON compatible data types (i.e. string, number, boolean, object, array and null).
|
|
40
|
+
*/
|
|
41
|
+
send(channel: string, ...args: any[]): void;
|
|
42
|
+
/**
|
|
43
|
+
* Listen messages with JSON compatible data types on a given channel.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} channel - Channel name.
|
|
46
|
+
* @param {Function} callback - Callback to execute when a message is received,
|
|
47
|
+
* arguments of the callback function will match the arguments sent using the
|
|
48
|
+
* {@link ServerSocket#send} method.
|
|
49
|
+
*/
|
|
50
|
+
addListener(channel: string, callback: Function): void;
|
|
51
|
+
/**
|
|
52
|
+
* Remove a listener from JSON compatible messages on a given channel.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} channel - Channel name.
|
|
55
|
+
* @param {Function} callback - Callback to remove.
|
|
56
|
+
*/
|
|
57
|
+
removeListener(channel: string, callback: Function): void;
|
|
58
|
+
/**
|
|
59
|
+
* Remove all listeners of messages with JSON compatible data types.
|
|
60
|
+
*
|
|
61
|
+
* @param {string} channel - Channel name.
|
|
62
|
+
*/
|
|
63
|
+
removeAllListeners(channel?: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Removes all listeners and immediately close the two sockets. Is automatically
|
|
66
|
+
* called on `client.stop()`
|
|
67
|
+
*
|
|
68
|
+
* Is also called when a disconnection is detected by the heartbeat (note that
|
|
69
|
+
* in this case, the launcher will call `client.stop()` but the listeners are
|
|
70
|
+
* already cleared so the event will be trigerred only once.
|
|
71
|
+
*/
|
|
72
|
+
[kSocketTerminate](): Promise<void>;
|
|
73
|
+
#private;
|
|
74
|
+
}
|
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
export default
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type StateManager = () => any;
|
|
7
|
-
}
|
|
1
|
+
export default ClientStateManager;
|
|
2
|
+
/**
|
|
3
|
+
* ~ObserveCallback
|
|
4
|
+
*/
|
|
5
|
+
export type ClientStateManager = () => any;
|
|
8
6
|
/**
|
|
9
|
-
* @callback
|
|
7
|
+
* @callback ClientStateManager~ObserveCallback
|
|
10
8
|
* @async
|
|
11
9
|
* @param {String} schemaName - name of the schema
|
|
12
10
|
* @param {Number} stateId - id of the state
|
|
13
11
|
* @param {Number} nodeId - id of the node that created the state
|
|
14
12
|
*/
|
|
15
13
|
/**
|
|
16
|
-
* The `
|
|
17
|
-
* to {@link
|
|
18
|
-
* can also track all the {@link
|
|
14
|
+
* The `ClientStateManager` allows to create new {@link SharedState}s, or attach
|
|
15
|
+
* to {@link SharedState}s created by other nodes (clients or server). It
|
|
16
|
+
* can also track all the {@link SharedState}s created by other nodes.
|
|
19
17
|
*
|
|
20
|
-
* An instance of `
|
|
18
|
+
* An instance of `ClientStateManager` is automatically created by the `soundworks.Client`
|
|
21
19
|
* at initialization (cf. {@link client.Client#stateManager}).
|
|
22
20
|
*
|
|
23
21
|
* See {@link client.Client#stateManager}
|
|
@@ -61,12 +59,10 @@ export namespace client {
|
|
|
61
59
|
* }, 1000);
|
|
62
60
|
* ```
|
|
63
61
|
*
|
|
64
|
-
* @memberof client
|
|
65
62
|
* @extends BaseStateManager
|
|
66
63
|
* @inheritdoc
|
|
67
64
|
* @hideconstructor
|
|
68
65
|
*/
|
|
69
|
-
declare class
|
|
66
|
+
declare class ClientStateManager extends BaseStateManager {
|
|
70
67
|
}
|
|
71
68
|
import BaseStateManager from '../common/BaseStateManager.js';
|
|
72
|
-
//# sourceMappingURL=StateManager.d.ts.map
|
package/types/client/index.d.ts
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
-
export { default as Context } from "./Context.js";
|
|
2
1
|
export { default as Client } from "./Client.js";
|
|
3
|
-
|
|
2
|
+
export { default as ClientContext } from "./ClientContext.js";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration object for a client running in a browser runtime.
|
|
5
|
+
*/
|
|
6
|
+
export type ClientConfig = {
|
|
7
|
+
/**
|
|
8
|
+
* - Role of the client in the application (e.g. 'player', 'controller').
|
|
9
|
+
*/
|
|
10
|
+
role: string;
|
|
11
|
+
/**
|
|
12
|
+
* - Application configuration object.
|
|
13
|
+
*/
|
|
14
|
+
app?: {
|
|
15
|
+
name?: string;
|
|
16
|
+
author?: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* - Environment configuration object.
|
|
20
|
+
*/
|
|
21
|
+
env: {
|
|
22
|
+
useHttps: boolean;
|
|
23
|
+
serverAddress: string;
|
|
24
|
+
port: number;
|
|
25
|
+
subpath?: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
+
export const kBasePluginStatus: unique symbol;
|
|
1
2
|
export default BasePlugin;
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
+
* Callback executed when the plugin state is updated.
|
|
4
5
|
*/
|
|
6
|
+
export type pluginOnStateChangeCallback = (#state: BasePlugin) => any;
|
|
7
|
+
/**
|
|
8
|
+
* Delete the registered {@link pluginOnStateChangeCallback }.
|
|
9
|
+
*/
|
|
10
|
+
export type pluginDeleteOnStateChangeCallback = () => any;
|
|
11
|
+
/**
|
|
12
|
+
* Callback executed when the plugin state is updated.
|
|
13
|
+
*
|
|
14
|
+
* @callback pluginOnStateChangeCallback
|
|
15
|
+
* @param {BasePlugin#state} state - Current state of the plugin.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Delete the registered {@link pluginOnStateChangeCallback}.
|
|
19
|
+
*
|
|
20
|
+
* @callback pluginDeleteOnStateChangeCallback
|
|
21
|
+
*/
|
|
22
|
+
/** @private */
|
|
5
23
|
declare class BasePlugin {
|
|
6
24
|
constructor(id: any);
|
|
7
|
-
/** @private */
|
|
8
|
-
private _id;
|
|
9
|
-
/** @private */
|
|
10
|
-
private _type;
|
|
11
|
-
/**
|
|
12
|
-
* Options of the plugin.
|
|
13
|
-
*
|
|
14
|
-
* @type {object}
|
|
15
|
-
*/
|
|
16
|
-
options: object;
|
|
17
25
|
/**
|
|
18
26
|
* Placeholder that stores internal (local) state of the plugin. The state
|
|
19
27
|
* should be modified through the `propagateStateChange` method to ensure
|
|
20
|
-
* the change to be properly propagated to `onStateChange` callbacks.
|
|
28
|
+
* the change to be properly propagated to manager `onStateChange` callbacks.
|
|
21
29
|
*
|
|
22
30
|
* @type {object}
|
|
23
31
|
* @protected
|
|
24
|
-
* @see {@link
|
|
25
|
-
* @see {@link
|
|
26
|
-
* @see {@link
|
|
27
|
-
* @see {@link
|
|
32
|
+
* @see {@link ClientPlugin#onStateChange}
|
|
33
|
+
* @see {@link ServerPlugin#onStateChange}
|
|
34
|
+
* @see {@link ClientPlugin#propagateStateChange}
|
|
35
|
+
* @see {@link ServerPlugin#propagateStateChange}
|
|
28
36
|
*/
|
|
29
37
|
protected state: object;
|
|
30
|
-
/**
|
|
31
|
-
* Current status of the plugin, i.e. 'idle', 'inited', 'started', 'errored'
|
|
32
|
-
*
|
|
33
|
-
* @type {string}
|
|
34
|
-
*/
|
|
35
|
-
status: string;
|
|
36
|
-
/** @private */
|
|
37
|
-
private _onStateChangeCallbacks;
|
|
38
38
|
/**
|
|
39
39
|
* User defined ID of the plugin.
|
|
40
40
|
*
|
|
41
41
|
* @type {string}
|
|
42
42
|
* @readonly
|
|
43
|
-
* @see {@link
|
|
44
|
-
* @see {@link
|
|
43
|
+
* @see {@link ClientPluginManager#register}
|
|
44
|
+
* @see {@link ServerPluginManager#register}
|
|
45
45
|
*/
|
|
46
46
|
readonly get id(): string;
|
|
47
47
|
/**
|
|
@@ -56,14 +56,21 @@ declare class BasePlugin {
|
|
|
56
56
|
*/
|
|
57
57
|
readonly get type(): string;
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
59
|
+
* Current status of the plugin.
|
|
60
|
+
*
|
|
61
|
+
* @type {'idle'|'inited'|'started'|'errored'}
|
|
62
|
+
*/
|
|
63
|
+
get status(): "idle" | "inited" | "started" | "errored";
|
|
64
|
+
/**
|
|
65
|
+
* Start the plugin.
|
|
66
|
+
*
|
|
67
|
+
* This method is automatically called during the client or server `init()` lifecyle
|
|
68
|
+
* step. After `start()` is fulfilled the plugin should be ready to use.
|
|
62
69
|
*
|
|
63
70
|
* @example
|
|
64
71
|
* // server-side couterpart of a plugin that creates a dedicated global shared
|
|
65
72
|
* // state on which the server-side part can attach.
|
|
66
|
-
* class MyPlugin extends
|
|
73
|
+
* class MyPlugin extends ServerPlugin {
|
|
67
74
|
* constructor(server, id) {
|
|
68
75
|
* super(server, id);
|
|
69
76
|
*
|
|
@@ -88,13 +95,14 @@ declare class BasePlugin {
|
|
|
88
95
|
*/
|
|
89
96
|
start(): Promise<void>;
|
|
90
97
|
/**
|
|
91
|
-
* Stop the plugin.
|
|
92
|
-
*
|
|
98
|
+
* Stop the plugin.
|
|
99
|
+
*
|
|
100
|
+
* This method is automatically called during the client or server `stop()` lifecyle step.
|
|
93
101
|
*
|
|
94
102
|
* @example
|
|
95
103
|
* // server-side couterpart of a plugin that creates a dedicated global shared
|
|
96
|
-
* // state on which the
|
|
97
|
-
* class MyPlugin extends
|
|
104
|
+
* // state on which the client-side part can attach.
|
|
105
|
+
* class MyPlugin extends ServerPlugin {
|
|
98
106
|
* constructor(server, id) {
|
|
99
107
|
* super(server, id);
|
|
100
108
|
*
|
|
@@ -122,29 +130,27 @@ declare class BasePlugin {
|
|
|
122
130
|
/**
|
|
123
131
|
* Listen to the state changes propagated by {@link BasePlugin.propagateStateChange}
|
|
124
132
|
*
|
|
125
|
-
* @param {
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* Execute the function to delete the listener from the callback list.
|
|
129
|
-
* @see {@link client.Plugin#propagateStateChange}
|
|
130
|
-
* @see {@link server.Plugin#propagateStateChange}
|
|
133
|
+
* @param {pluginOnStateChangeCallback} callback - Callback to execute when a state change is propagated.
|
|
134
|
+
* @returns {pluginDeleteOnStateChangeCallback}
|
|
135
|
+
*
|
|
131
136
|
* @example
|
|
132
137
|
* const unsubscribe = plugin.onStateChange(pluginState => console.log(pluginState));
|
|
133
138
|
* // stop listening state changes
|
|
134
139
|
* unsubscribe();
|
|
135
140
|
*/
|
|
136
|
-
onStateChange(callback:
|
|
141
|
+
onStateChange(callback: pluginOnStateChangeCallback): pluginDeleteOnStateChangeCallback;
|
|
137
142
|
/**
|
|
138
143
|
* Apply updates to the plugin state and propagate the updated state to the
|
|
139
144
|
* `onStateChange` listeners. The state changes will also be propagated
|
|
140
145
|
* through the `PluginManager#onStateChange` listeners.
|
|
141
146
|
*
|
|
142
147
|
* @param {object} updates - Updates to be merged in the plugin state.
|
|
143
|
-
*
|
|
144
|
-
* @see {@link
|
|
145
|
-
* @see {@link
|
|
146
|
-
* @see {@link server.PluginManager#onStateChange}
|
|
148
|
+
*
|
|
149
|
+
* @see {@link BasePlugin#onStateChange}
|
|
150
|
+
* @see {@link BasePluginManager#onStateChange}
|
|
147
151
|
*/
|
|
148
152
|
propagateStateChange(updates: object): void;
|
|
153
|
+
/** @private */
|
|
154
|
+
private [kBasePluginStatus];
|
|
155
|
+
#private;
|
|
149
156
|
}
|
|
150
|
-
//# sourceMappingURL=BasePlugin.d.ts.map
|
|
@@ -1,24 +1,56 @@
|
|
|
1
|
+
export const kPluginManagerStart: unique symbol;
|
|
2
|
+
export const kPluginManagerStop: unique symbol;
|
|
3
|
+
export const kPluginManagerInstances: unique symbol;
|
|
1
4
|
export default BasePluginManager;
|
|
2
5
|
/**
|
|
3
|
-
*
|
|
6
|
+
* Callback executed when a plugin internal state is updated.
|
|
7
|
+
*/
|
|
8
|
+
export type pluginManagerOnStateChangeCallback = (: object, initiator: ClientPlugin | ServerPlugin | null) => any;
|
|
9
|
+
/**
|
|
10
|
+
* Delete the registered {@link pluginManagerOnStateChangeCallback }.
|
|
11
|
+
*/
|
|
12
|
+
export type pluginManagerDeleteOnStateChangeCallback = () => any;
|
|
13
|
+
/**
|
|
14
|
+
* Callback executed when a plugin internal state is updated.
|
|
15
|
+
*
|
|
16
|
+
* @callback pluginManagerOnStateChangeCallback
|
|
17
|
+
* @param {object<string, ClientPlugin|ServerPlugin>} fullState - List of all plugins.
|
|
18
|
+
* @param {ClientPlugin|ServerPlugin|null} initiator - Plugin that initiated the
|
|
19
|
+
* update. The value is `null` if the change was initiated by the state manager
|
|
20
|
+
* (e.g. when the initialization of the plugins starts).
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Delete the registered {@link pluginManagerOnStateChangeCallback}.
|
|
4
24
|
*
|
|
5
|
-
* @
|
|
25
|
+
* @callback pluginManagerDeleteOnStateChangeCallback
|
|
6
26
|
*/
|
|
27
|
+
/** @private */
|
|
7
28
|
declare class BasePluginManager {
|
|
8
29
|
constructor(node: any);
|
|
9
|
-
/** @private */
|
|
10
|
-
private _node;
|
|
11
|
-
/** @private */
|
|
12
|
-
private _dependencies;
|
|
13
|
-
/** @private */
|
|
14
|
-
private _instances;
|
|
15
|
-
/** @private */
|
|
16
|
-
private _instanceStartPromises;
|
|
17
|
-
/** @private */
|
|
18
|
-
private _onStateChangeCallbacks;
|
|
19
|
-
status: string;
|
|
20
30
|
/**
|
|
21
|
-
*
|
|
31
|
+
* Status of the plugin manager
|
|
32
|
+
*
|
|
33
|
+
* @type {'idle'|'inited'|'started'|'errored'}
|
|
34
|
+
*/
|
|
35
|
+
get status(): "idle" | "inited" | "started" | "errored";
|
|
36
|
+
/**
|
|
37
|
+
* Alias for existing plugins (i.e. plugin-scriptin), remove once updated
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
private unsafeGet;
|
|
41
|
+
/**
|
|
42
|
+
* Retrieve an fully started instance of a registered plugin without checking
|
|
43
|
+
* that the pluginManager is started.
|
|
44
|
+
*
|
|
45
|
+
* This method is required for starting the plugin manager itself and to require
|
|
46
|
+
* a plugin from within another plugin.
|
|
47
|
+
*
|
|
48
|
+
* _Warning: Unless you are developing your own plugins, you should not have to use
|
|
49
|
+
* this method_
|
|
50
|
+
*/
|
|
51
|
+
getUnsafe(id: any): Promise<any>;
|
|
52
|
+
/**
|
|
53
|
+
* Register a plugin into the manager.
|
|
22
54
|
*
|
|
23
55
|
* _A plugin must always be registered both on client-side and on server-side_
|
|
24
56
|
*
|
|
@@ -27,24 +59,24 @@ declare class BasePluginManager {
|
|
|
27
59
|
*
|
|
28
60
|
* @param {string} id - Unique id of the plugin. Enables the registration of the
|
|
29
61
|
* same plugin factory under different ids.
|
|
30
|
-
* @param {Function}
|
|
62
|
+
* @param {Function} ctor - The class returned by the plugin factory method.
|
|
31
63
|
* @param {object} [options={}] - Options to configure the plugin.
|
|
32
64
|
* @param {array} [deps=[]] - List of plugins' names the plugin depends on, i.e.
|
|
33
|
-
* the plugin initialization will
|
|
65
|
+
* the plugin initialization will begin only after the plugins it depends on are
|
|
34
66
|
* fully started themselves.
|
|
35
|
-
* @see {@link
|
|
36
|
-
* @see {@link
|
|
67
|
+
* @see {@link ClientPluginManager#register}
|
|
68
|
+
* @see {@link ServerPluginManager#register}
|
|
37
69
|
* @example
|
|
38
70
|
* // client-side
|
|
39
71
|
* client.pluginManager.register('user-defined-id', pluginFactory);
|
|
40
72
|
* // server-side
|
|
41
73
|
* server.pluginManager.register('user-defined-id', pluginFactory);
|
|
42
74
|
*/
|
|
43
|
-
register(id: string, ctor:
|
|
75
|
+
register(id: string, ctor: Function, options?: object, deps?: any[]): void;
|
|
44
76
|
/**
|
|
45
|
-
* Manually add a dependency to a given plugin.
|
|
46
|
-
* within a plugin
|
|
77
|
+
* Manually add a dependency to a given plugin.
|
|
47
78
|
*
|
|
79
|
+
* Usefull to require a plugin within a plugin
|
|
48
80
|
*/
|
|
49
81
|
addDependency(pluginId: any, dependencyId: any): void;
|
|
50
82
|
/**
|
|
@@ -52,22 +84,6 @@ declare class BasePluginManager {
|
|
|
52
84
|
* @returns {string[]}
|
|
53
85
|
*/
|
|
54
86
|
getRegisteredPlugins(): string[];
|
|
55
|
-
/**
|
|
56
|
-
* Initialize all the registered plugin. Executed during the `Client.init()` or
|
|
57
|
-
* `Server.init()` initialization step.
|
|
58
|
-
* @private
|
|
59
|
-
*/
|
|
60
|
-
private start;
|
|
61
|
-
/** @private */
|
|
62
|
-
private stop;
|
|
63
|
-
/**
|
|
64
|
-
* Retrieve an fully started instance of a registered plugin, without checking
|
|
65
|
-
* that the pluginManager has started. This is required for starting the plugin
|
|
66
|
-
* manager itself and to require a plugin from within another plugin
|
|
67
|
-
*
|
|
68
|
-
* @private
|
|
69
|
-
*/
|
|
70
|
-
private unsafeGet;
|
|
71
87
|
/**
|
|
72
88
|
* Propagate a notification each time a plugin is updated (status or inner state).
|
|
73
89
|
* The callback will receive the list of all plugins as first parameter, and the
|
|
@@ -75,10 +91,8 @@ declare class BasePluginManager {
|
|
|
75
91
|
*
|
|
76
92
|
* _In most cases, you should not have to rely on this method._
|
|
77
93
|
*
|
|
78
|
-
* @param {
|
|
79
|
-
*
|
|
80
|
-
* @param {client.PluginManager~deleteOnStateChangeCallback|client.PluginManager~deleteOnStateChangeCallback}
|
|
81
|
-
* Function to execute to listening for changes.
|
|
94
|
+
* @param {pluginManagerOnStateChangeCallback} callback - Callback to execute on state change
|
|
95
|
+
* @returns {pluginManagerDeleteOnStateChangeCallback} - Clear the subscription when executed
|
|
82
96
|
* @example
|
|
83
97
|
* const unsubscribe = client.pluginManager.onStateChange(pluginList, initiator => {
|
|
84
98
|
* // log the current status of all plugins
|
|
@@ -93,8 +107,18 @@ declare class BasePluginManager {
|
|
|
93
107
|
* // stop listening for updates later
|
|
94
108
|
* unsubscribe();
|
|
95
109
|
*/
|
|
96
|
-
onStateChange(callback:
|
|
110
|
+
onStateChange(callback: pluginManagerOnStateChangeCallback): pluginManagerDeleteOnStateChangeCallback;
|
|
111
|
+
/**
|
|
112
|
+
* Initialize all registered plugins.
|
|
113
|
+
*
|
|
114
|
+
* Executed during the `Client.init()` or `Server.init()` initialization step.
|
|
115
|
+
*
|
|
116
|
+
* @private
|
|
117
|
+
*/
|
|
118
|
+
private [kPluginManagerStart];
|
|
97
119
|
/** @private */
|
|
98
|
-
private
|
|
120
|
+
private [kPluginManagerStop];
|
|
121
|
+
/** #private */
|
|
122
|
+
[kPluginManagerInstances]: Map<any, any>;
|
|
123
|
+
#private;
|
|
99
124
|
}
|
|
100
|
-
//# sourceMappingURL=BasePluginManager.d.ts.map
|