@soundworks/core 4.0.0-alpha.21 → 4.0.0-alpha.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/CHANGELOG.md +14 -3
  2. package/package.json +15 -15
  3. package/src/client/Client.js +233 -188
  4. package/src/client/Socket.js +84 -247
  5. package/src/client/index.js +6 -0
  6. package/src/common/constants.js +0 -1
  7. package/src/common/logger.js +15 -0
  8. package/src/common/sockets-utils.js +0 -63
  9. package/src/common/version.js +2 -0
  10. package/src/server/Plugin.js +22 -10
  11. package/src/server/Server.js +37 -36
  12. package/src/server/Socket.js +126 -250
  13. package/src/server/Sockets.js +103 -127
  14. package/src/server/audit-network-latency.worker.js +4 -3
  15. package/src/server/index.js +6 -0
  16. package/types/client/Client.d.ts +41 -8
  17. package/types/client/Client.d.ts.map +1 -1
  18. package/types/client/Context.d.ts +40 -14
  19. package/types/client/Context.d.ts.map +1 -1
  20. package/types/client/Plugin.d.ts +42 -41
  21. package/types/client/Plugin.d.ts.map +1 -1
  22. package/types/client/PluginManager.d.ts +26 -11
  23. package/types/client/PluginManager.d.ts.map +1 -1
  24. package/types/client/SharedState.d.ts +1 -1
  25. package/types/client/SharedState.d.ts.map +1 -1
  26. package/types/client/SharedStateCollection.d.ts +41 -0
  27. package/types/client/SharedStateCollection.d.ts.map +1 -0
  28. package/types/client/Socket.d.ts +41 -30
  29. package/types/client/Socket.d.ts.map +1 -1
  30. package/types/client/StateManager.d.ts +1 -1
  31. package/types/client/StateManager.d.ts.map +1 -1
  32. package/types/client/index.d.ts +0 -8
  33. package/types/common/BasePlugin.d.ts +24 -19
  34. package/types/common/BasePlugin.d.ts.map +1 -1
  35. package/types/common/BasePluginManager.d.ts +17 -5
  36. package/types/common/BasePluginManager.d.ts.map +1 -1
  37. package/types/common/BaseSharedState.d.ts +100 -29
  38. package/types/common/BaseSharedState.d.ts.map +1 -1
  39. package/types/common/BaseSharedStateCollection.d.ts +183 -0
  40. package/types/common/BaseSharedStateCollection.d.ts.map +1 -0
  41. package/types/common/BaseStateManager.d.ts +83 -18
  42. package/types/common/BaseStateManager.d.ts.map +1 -1
  43. package/types/common/BatchedTransport.d.ts +21 -0
  44. package/types/common/BatchedTransport.d.ts.map +1 -0
  45. package/types/common/ParameterBag.d.ts +61 -40
  46. package/types/common/ParameterBag.d.ts.map +1 -1
  47. package/types/common/PromiseStore.d.ts +11 -0
  48. package/types/common/PromiseStore.d.ts.map +1 -0
  49. package/types/common/SharedStatePrivate.d.ts +4 -3
  50. package/types/common/SharedStatePrivate.d.ts.map +1 -1
  51. package/types/common/constants.d.ts +10 -1
  52. package/types/common/constants.d.ts.map +1 -1
  53. package/types/common/logger.d.ts +1 -1
  54. package/types/common/sockets-utils.d.ts.map +1 -1
  55. package/types/common/version.d.ts +3 -0
  56. package/types/common/version.d.ts.map +1 -0
  57. package/types/server/Client.d.ts +5 -0
  58. package/types/server/Client.d.ts.map +1 -1
  59. package/types/server/Context.d.ts +162 -22
  60. package/types/server/Context.d.ts.map +1 -1
  61. package/types/server/ContextManager.d.ts +4 -4
  62. package/types/server/ContextManager.d.ts.map +1 -1
  63. package/types/server/Plugin.d.ts +56 -55
  64. package/types/server/Plugin.d.ts.map +1 -1
  65. package/types/server/PluginManager.d.ts +26 -6
  66. package/types/server/PluginManager.d.ts.map +1 -1
  67. package/types/server/Server.d.ts +207 -70
  68. package/types/server/Server.d.ts.map +1 -1
  69. package/types/server/SharedState.d.ts +1 -1
  70. package/types/server/SharedState.d.ts.map +1 -1
  71. package/types/server/SharedStateCollection.d.ts +41 -0
  72. package/types/server/SharedStateCollection.d.ts.map +1 -0
  73. package/types/server/Socket.d.ts +93 -57
  74. package/types/server/Socket.d.ts.map +1 -1
  75. package/types/server/Sockets.d.ts +32 -25
  76. package/types/server/Sockets.d.ts.map +1 -1
  77. package/types/server/StateManager.d.ts +242 -27
  78. package/types/server/StateManager.d.ts.map +1 -1
  79. package/types/server/audit-network-latency.worker.d.ts +2 -1
  80. package/types/server/audit-schema.d.ts +8 -8
  81. package/types/server/crypto.d.ts +3 -0
  82. package/types/server/crypto.d.ts.map +1 -0
  83. package/types/server/index.d.ts +0 -4
  84. package/types/common/promise-store.d.ts +0 -4
  85. package/types/common/promise-store.d.ts.map +0 -1
  86. package/types/common/utils.d.ts +0 -5
  87. package/types/common/utils.d.ts.map +0 -1
@@ -24,7 +24,7 @@ export namespace client {
24
24
  *
25
25
  * Plugins should always be registered both client-side and server-side,
26
26
  * and before {@link client.Client#start} or {@link server.Server#start}
27
- * are called for proper initialization.
27
+ * to be properly initialized.
28
28
  *
29
29
  * In some sitautions, you might want to register the same plugin factory several times
30
30
  * using different ids (e.g. for watching several parts of the file system, etc.).
@@ -36,12 +36,13 @@ export namespace client {
36
36
  * See {@link client.Client#pluginManager}
37
37
  *
38
38
  * ```
39
+ * // client-side
39
40
  * import { Client } from '@soundworks/core/client.js';
40
- * import platformPlugin from '@soundworks/plugin-sync/client.js';
41
+ * import syncPlugin from '@soundworks/plugin-sync/client.js';
41
42
  *
42
43
  * const client = new Client(config);
43
44
  * // register the plugin before `client.start()`
44
- * client.pluginManager.register('sync', pluginSync);
45
+ * client.pluginManager.register('sync', syncPlugin);
45
46
  *
46
47
  * await client.start();
47
48
  *
@@ -53,6 +54,25 @@ export namespace client {
53
54
  * }, 1000);
54
55
  * ```
55
56
  *
57
+ * ```
58
+ * // server-side
59
+ * import { Server } from '@soundworks/core/server.js';
60
+ * import syncPlugin from '@soundworks/plugin-sync/server.js';
61
+ *
62
+ * const server = new Server(config);
63
+ * // register the plugin before `server.start()`
64
+ * server.pluginManager.register('sync', syncPlugin);
65
+ *
66
+ * await server.start();
67
+ *
68
+ * const sync = await server.pluginManager.get('sync');
69
+ *
70
+ * setInterval(() => {
71
+ * // log the estimated global synced clock alongside the local clock.
72
+ * console.log(sync.getSyncTime(), sync.getLocalTime());
73
+ * }, 1000);
74
+ * ```
75
+ *
56
76
  * @memberof client
57
77
  * @extends BasePluginManager
58
78
  * @inheritdoc
@@ -76,8 +96,8 @@ declare class PluginManager extends BasePluginManager {
76
96
  * initialization (e.g. to display initialization screen, etc.), you should rely
77
97
  * on the `onStateChange` method.
78
98
  *
79
- * _Note: the async API is designed to enable the dynamic creation of plugins (hopefully
80
- * without brealing changes) in a future release._
99
+ * _Note: the async API is designed to enable the dynamic creation of plugins
100
+ * (hopefully without brealing changes) in a future release._
81
101
  *
82
102
  * @param {client.Plugin#id} id - Id of the plugin as defined when registered.
83
103
  * @returns {client.Plugin}
@@ -86,11 +106,6 @@ declare class PluginManager extends BasePluginManager {
86
106
  * @private
87
107
  */
88
108
  private get;
89
- /**
90
- * @protected
91
- * @ignore
92
- */
93
- protected getRegisteredPlugins(): any[];
94
109
  }
95
- import BasePluginManager from "../common/BasePluginManager.js";
110
+ import BasePluginManager from '../common/BasePluginManager.js';
96
111
  //# sourceMappingURL=PluginManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../src/client/PluginManager.js"],"names":[],"mappings":";;;;;4BAQW,MAAM,aACN,gBAAc,IAAI;;AAL7B;;;;;;;;GAQG;AAEH;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH;IACE;;OAEG;IACH,mCAMC;IAED,kEAQC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,YAMC;IAKD;;;OAGG;IACH,wCAEC;CACF"}
1
+ {"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../src/client/PluginManager.js"],"names":[],"mappings":";;;;;4BAQW,MAAM,aACN,gBAAc,IAAI;;AAL7B;;;;;;;;GAQG;AAEH;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH;IACE;;OAEG;IACH,mCAMC;IAED,kEAQC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,YAMC;CACF;8BAjI6B,gCAAgC"}
@@ -81,5 +81,5 @@ export namespace client {
81
81
  */
82
82
  declare class SharedState extends BaseSharedState {
83
83
  }
84
- import BaseSharedState from "../common/BaseSharedState.js";
84
+ import BaseSharedState from '../common/BaseSharedState.js';
85
85
  //# sourceMappingURL=SharedState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SharedState.d.ts","sourceRoot":"","sources":["../../src/client/SharedState.js"],"names":[],"mappings":";;;;;;;AAIA;;;;;;;;GAQG;AAEH;;;;GAIG;AAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACH;CAA4C"}
1
+ {"version":3,"file":"SharedState.d.ts","sourceRoot":"","sources":["../../src/client/SharedState.js"],"names":[],"mappings":";;;;;;;AAIA;;;;;;;;GAQG;AAEH;;;;GAIG;AAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACH;CAA4C;4BAjFhB,8BAA8B"}
@@ -0,0 +1,41 @@
1
+ export default SharedStateCollection;
2
+ export namespace client {
3
+ /**
4
+ * ~onUpdateCallback
5
+ */
6
+ type SharedStateCollection = (state: client.SharedState, newValues: any, oldValues: any, context?: Mixed) => any;
7
+ }
8
+ /**
9
+ * @callback client.SharedStateCollection~onUpdateCallback
10
+ * @param {client.SharedState} state - State that triggered the update.
11
+ * @param {Object} newValues - Key / value pairs of the updates that have been
12
+ * applied to the state.
13
+ * @param {Object} oldValues - Key / value pairs of the updated params before
14
+ * the updates has been applied to the state.
15
+ * @param {Mixed} [context=null] - Optionnal context object that has been passed
16
+ * with the values updates in the `set` call.
17
+ */
18
+ /**
19
+ * The `SharedStateCollection` interface represent a collection of all states
20
+ * created from a given schema name on the network.
21
+ *
22
+ * It can optionnaly exclude the states created by the current node.
23
+ *
24
+ * See {@link client.StateManager#getCollection} for factory method API
25
+ *
26
+ * ```
27
+ * const collection = await client.stateManager.getCollection('my-schema');
28
+ * const allValues = collection.getValues();
29
+ * collection.onUpdate((state, newValues, oldValues, context) => {
30
+ * // do something
31
+ * });
32
+ * ```
33
+ * @memberof client
34
+ * @extends BaseSharedStateCollection
35
+ * @inheritdoc
36
+ * @hideconstructor
37
+ */
38
+ declare class SharedStateCollection extends BaseSharedStateCollection {
39
+ }
40
+ import BaseSharedStateCollection from '../common/BaseSharedStateCollection.js';
41
+ //# sourceMappingURL=SharedStateCollection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SharedStateCollection.d.ts","sourceRoot":"","sources":["../../src/client/SharedStateCollection.js"],"names":[],"mappings":";;;;;;;AAIA;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH;CAAgE;sCAnC1B,wCAAwC"}
@@ -2,34 +2,33 @@ export default Socket;
2
2
  /**
3
3
  * The Socket class is a simple publish / subscribe wrapper built on top of the
4
4
  * [isomorphic-ws](https://github.com/heineiuo/isomorphic-ws) library.
5
- * An instance of `Socket` is automatically created by the `soundworks.Client`.
5
+ * An instance of `Socket` is automatically created by the `soundworks.Client`
6
+ * (see {@link client.Client#socket}).
6
7
  *
7
- * _Important: In most cases, you should consider using a {@link client.SharedState} rather than
8
- * sending messages directly through the sockets._
8
+ * _Important: In most cases, you should consider using a {@link client.SharedState}
9
+ * rather than directly using the sockets._
9
10
  *
10
11
  * The Socket class concurrently opens two different WebSockets:
11
- * - a socket configured with `binaryType = 'string'` for JSON compatible string
12
- * messages.
13
- * - a socket configured with `binaryType=arraybuffer` for efficient streaming
12
+ * - a socket configured with `binaryType = 'blob'` for JSON compatible data
13
+ * types (i.e. string, number, boolean, object, array and null).
14
+ * - a socket configured with `binaryType= 'arraybuffer'` for efficient streaming
14
15
  * of binary data.
15
16
  *
16
17
  * Both sockets re-emits all "native" ws events ('open', 'upgrade', 'close', 'error'
17
18
  * and 'message'.
18
19
  *
19
- * See {@link client.Client#socket}
20
- *
21
20
  * @memberof client
22
21
  * @hideconstructor
23
22
  */
24
23
  declare class Socket {
25
24
  /**
26
- * WebSocket instance w/ string protocol, i.e. `binaryType = 'string'`.
25
+ * WebSocket instance configured with `binaryType = 'blob'`.
27
26
  *
28
27
  * @private
29
28
  */
30
29
  private ws;
31
30
  /**
32
- * WebSocket instance w/ binary protocol, i.e. `binaryType = 'arraybuffer'`.
31
+ * WebSocket instance configured with `binaryType = 'arraybuffer'`.
33
32
  *
34
33
  * @private
35
34
  */
@@ -38,6 +37,8 @@ declare class Socket {
38
37
  private _stringListeners;
39
38
  /** @private */
40
39
  private _binaryListeners;
40
+ /** @private */
41
+ private _heartbeatId;
41
42
  /**
42
43
  * Initialize a websocket connection with the server. Automatically called
43
44
  * during `client.init()`
@@ -48,6 +49,17 @@ declare class Socket {
48
49
  * @ignore
49
50
  */
50
51
  protected init(role: string, config: object): Promise<void>;
52
+ /**
53
+ * Removes all listeners and immediately close the two sockets. Is automatically
54
+ * called on `client.stop()`
55
+ *
56
+ * Is also called when a disconnection is detected by the heartbeat (note that
57
+ * in this case, the launcher will call `client.stop()` but the listeners are
58
+ * already cleared so the event will be trigerred only once)
59
+ *
60
+ * @private
61
+ */
62
+ private terminate;
51
63
  /**
52
64
  * @param {boolean} binary - Emit to either the string or binary socket.
53
65
  * @param {string} channel - Channel name.
@@ -77,62 +89,61 @@ declare class Socket {
77
89
  */
78
90
  private _removeAllListeners;
79
91
  /**
80
- * Send JSON compatible messages on a given channel.
92
+ * Send messages with JSON compatible data types on a given channel.
81
93
  *
82
- * @param {string} channel - Channel name of the message.
83
- * @param {...*} args - Message list, as many as needed, of any serializable type).
94
+ * @param {string} channel - Channel name.
95
+ * @param {...*} args - Payload of the message. As many arguments as needed, of
96
+ * JSON compatible data types (i.e. string, number, boolean, object, array and null).
84
97
  */
85
98
  send(channel: string, ...args: any[]): void;
86
99
  /**
87
- * Listen to JSON compatible messages on a given channel.
100
+ * Listen messages with JSON compatible data types on a given channel.
88
101
  *
89
- * @param {string} channel - Channel name of the message.
90
- * @param {Function} callback - Callback to execute when a message is received.
102
+ * @param {string} channel - Channel name.
103
+ * @param {Function} callback - Callback to execute when a message is received,
104
+ * arguments of the callback function will match the arguments sent using the
105
+ * {@link server.Socket#send} method.
91
106
  */
92
107
  addListener(channel: string, callback: Function): void;
93
108
  /**
94
109
  * Remove a listener from JSON compatible messages on a given channel.
95
110
  *
96
- * @param {string} channel - Channel name of the message.
111
+ * @param {string} channel - Channel name.
97
112
  * @param {Function} callback - Callback to remove.
98
113
  */
99
114
  removeListener(channel: string, callback: Function): void;
100
115
  /**
101
- * Remove all listeners from JSON compatible messages on a given channel.
116
+ * Remove all listeners of messages with JSON compatible data types.
102
117
  *
103
- * @param {string} channel - Channel name of the message.
118
+ * @param {string} channel - Channel name.
104
119
  */
105
120
  removeAllListeners(channel?: string): void;
106
121
  /**
107
122
  * Send binary messages on a given channel.
108
123
  *
109
- * @param {string} channel - Channel name of the message.
124
+ * @param {string} channel - Channel name.
110
125
  * @param {TypedArray} typedArray - Binary data to be sent.
111
126
  */
112
127
  sendBinary(channel: string, typedArray: TypedArray): void;
113
128
  /**
114
- * Listen binary messages on a given channel.
129
+ * Listen binary messages on a given channel
115
130
  *
116
- * @param {string} channel - Channel name of the message.
131
+ * @param {string} channel - Channel name.
117
132
  * @param {Function} callback - Callback to execute when a message is received.
118
133
  */
119
134
  addBinaryListener(channel: string, callback: Function): void;
120
135
  /**
121
- * Remove a listener from binary compatible messages on a given channel
136
+ * Remove a listener of binary compatible messages from a given channel
122
137
  *
123
- * @param {string} channel - Channel of the message.
124
- * @param {Function} callback - Callback to cancel.
138
+ * @param {string} channel - Channel name.
139
+ * @param {Function} callback - Callback to remove.
125
140
  */
126
141
  removeBinaryListener(channel: string, callback: Function): void;
127
142
  /**
128
- * Remove all listeners from binary compatible messages on a given channel
143
+ * Remove all listeners of binary compatible messages on a given channel
129
144
  *
130
145
  * @param {string} channel - Channel of the message.
131
146
  */
132
147
  removeAllBinaryListeners(channel?: string): void;
133
- /**
134
- * Removes all listeners and immediately close the two sockets.
135
- */
136
- terminate(): Promise<void>;
137
148
  }
138
149
  //# sourceMappingURL=Socket.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Socket.d.ts","sourceRoot":"","sources":["../../src/client/Socket.js"],"names":[],"mappings":";AA2BA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH;IAEI;;;;OAIG;IACH,WAAc;IACd;;;;OAIG;IACH,iBAAoB;IACpB,eAAe;IACf,yBAAiC;IACjC,eAAe;IACf,yBAAiC;IAGnC;;;;;;;;OAQG;IACH,qBALW,MAAM,UACN,MAAM,iBA6JhB;IAED;;;;;OAKG;IACH,cAOC;IAED;;;;;OAKG;IACH,qBAOC;IAED;;;;;OAKG;IACH,wBASC;IAED;;;;;OAKG;IACH,4BAMC;IAED;;;;;OAKG;IACH,cAHW,MAAM,wBAMhB;IAED;;;;;OAKG;IACH,qBAHW,MAAM,4BAKhB;IAED;;;;;OAKG;IACH,wBAHW,MAAM,4BAKhB;IAED;;;;OAIG;IACH,6BAFW,MAAM,QAIhB;IAED;;;;;OAKG;IACH,oBAHW,MAAM,gCAMhB;IAED;;;;;OAKG;IACH,2BAHW,MAAM,4BAKhB;IAED;;;;;OAKG;IACH,8BAHW,MAAM,4BAKhB;IAED;;;;OAIG;IACH,mCAFW,MAAM,QAIhB;IAED;;OAEG;IACH,2BAQC;CACF"}
1
+ {"version":3,"file":"Socket.d.ts","sourceRoot":"","sources":["../../src/client/Socket.js"],"names":[],"mappings":";AAiCA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH;IAEI;;;;OAIG;IACH,WAAc;IACd;;;;OAIG;IACH,iBAAoB;IACpB,eAAe;IACf,yBAAiC;IACjC,eAAe;IACf,yBAAiC;IACjC,eAAe;IACf,qBAAwB;IAG1B;;;;;;;;OAQG;IACH,qBALW,MAAM,UACN,MAAM,iBA+KhB;IAED;;;;;;;;;OASG;IACH,kBAmBC;IAED;;;;;OAKG;IACH,cAOC;IAED;;;;;OAKG;IACH,qBAOC;IAED;;;;;OAKG;IACH,wBASC;IAED;;;;;OAKG;IACH,4BAMC;IAED;;;;;;OAMG;IACH,cAJW,MAAM,wBAOhB;IAED;;;;;;;OAOG;IACH,qBALW,MAAM,4BAOhB;IAED;;;;;OAKG;IACH,wBAHW,MAAM,4BAKhB;IAED;;;;OAIG;IACH,6BAFW,MAAM,QAIhB;IAED;;;;;OAKG;IACH,oBAHW,MAAM,gCAMhB;IAED;;;;;OAKG;IACH,2BAHW,MAAM,4BAKhB;IAED;;;;;OAKG;IACH,8BAHW,MAAM,4BAKhB;IAED;;;;OAIG;IACH,mCAFW,MAAM,QAIhB;CACF"}
@@ -68,5 +68,5 @@ export namespace client {
68
68
  */
69
69
  declare class StateManager extends BaseStateManager {
70
70
  }
71
- import BaseStateManager from "../common/BaseStateManager.js";
71
+ import BaseStateManager from '../common/BaseStateManager.js';
72
72
  //# sourceMappingURL=StateManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"StateManager.d.ts","sourceRoot":"","sources":["../../src/client/StateManager.js"],"names":[],"mappings":";;;;;;;AAEA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH;CAA8C"}
1
+ {"version":3,"file":"StateManager.d.ts","sourceRoot":"","sources":["../../src/client/StateManager.js"],"names":[],"mappings":";;;;;;;AAEA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH;CAA8C;6BAhEjB,+BAA+B"}
@@ -1,11 +1,3 @@
1
1
  export { default as Context } from "./Context.js";
2
2
  export { default as Client } from "./Client.js";
3
- /**
4
- * Configuration object for a client running in a browser runtime.
5
- */
6
- export type BrowserClientConfig = any;
7
- /**
8
- * Configuration object for a client running in a node runtime.
9
- */
10
- export type NodeClientConfig = any;
11
3
  //# sourceMappingURL=index.d.ts.map
@@ -4,25 +4,10 @@ export default BasePlugin;
4
4
  */
5
5
  declare class BasePlugin {
6
6
  constructor(id: any);
7
- /**
8
- * User defined ID of the plugin.
9
- *
10
- * @type {string}
11
- * @see {@link client.PluginManager#register}
12
- * @see {@link server.PluginManager#register}
13
- */
14
- id: string;
15
- /**
16
- * Type of the plugin, i.e. the ClassName.
17
- *
18
- * Usefull to do perform some logic based on certain types of plugins without
19
- * knowing under which `id` they have been registered. (e.g. creating some generic
20
- * views, etc.)
21
- *
22
- * @type {string}
23
- * @readonly
24
- */
25
- readonly type: string;
7
+ /** @private */
8
+ private _id;
9
+ /** @private */
10
+ private _type;
26
11
  /**
27
12
  * Options of the plugin.
28
13
  *
@@ -50,6 +35,26 @@ declare class BasePlugin {
50
35
  status: string;
51
36
  /** @private */
52
37
  private _onStateChangeCallbacks;
38
+ /**
39
+ * User defined ID of the plugin.
40
+ *
41
+ * @type {string}
42
+ * @readonly
43
+ * @see {@link client.PluginManager#register}
44
+ * @see {@link server.PluginManager#register}
45
+ */
46
+ readonly get id(): string;
47
+ /**
48
+ * Type of the plugin, i.e. the ClassName.
49
+ *
50
+ * Usefull to do perform some logic based on certain types of plugins without
51
+ * knowing under which `id` they have been registered. (e.g. creating some generic
52
+ * views, etc.)
53
+ *
54
+ * @type {string}
55
+ * @readonly
56
+ */
57
+ readonly get type(): string;
53
58
  /**
54
59
  * Start the plugin. This method is automatically called during the client or
55
60
  * server `init()` lifecyle step. After `start()` is fulfilled the plugin should
@@ -1 +1 @@
1
- {"version":3,"file":"BasePlugin.d.ts","sourceRoot":"","sources":["../../src/common/BasePlugin.js"],"names":[],"mappings":";AAEA;;GAEG;AACH;IACE,qBAoDC;IAnDC;;;;;;OAMG;IACH,IAJU,MAAM,CAIJ;IAEZ;;;;;;;;;OASG;IACH,eAHU,MAAM,CAGiB;IAEjC;;;;OAIG;IACH,SAFU,MAAM,CAEC;IAEjB;;;;;;;;;;;OAWG;IACH,iBAPU,MAAM,CAOD;IAEf;;;;OAIG;IACH,QAFU,MAAM,CAEI;IAEpB,eAAe;IACf,gCAAwC;IAG1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,uBAAgB;IAEhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,sBAAe;IAEf;;;;;;;;;;;;;OAaG;IACH,4CAGC;IAED;;;;;;;;;;OAUG;IACH,8BANW,MAAM,QAShB;CACF"}
1
+ {"version":3,"file":"BasePlugin.d.ts","sourceRoot":"","sources":["../../src/common/BasePlugin.js"],"names":[],"mappings":";AAEA;;GAEG;AACH;IACE,qBAoCC;IAnCC,eAAe;IACf,YAAa;IACb,eAAe;IACf,cAAkC;IAElC;;;;OAIG;IACH,SAFU,MAAM,CAEC;IAEjB;;;;;;;;;;;OAWG;IACH,iBAPU,MAAM,CAOD;IAEf;;;;OAIG;IACH,QAFU,MAAM,CAEI;IAEpB,eAAe;IACf,gCAAwC;IAG1C;;;;;;;OAOG;IACH,0BAEC;IAED;;;;;;;;;OASG;IACH,4BAEC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,uBAAgB;IAEhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,sBAAe;IAEf;;;;;;;;;;;;;OAaG;IACH,4CAGC;IAED;;;;;;;;;;OAUG;IACH,8BANW,MAAM,QAShB;CACF"}
@@ -9,7 +9,7 @@ declare class BasePluginManager {
9
9
  /** @private */
10
10
  private _node;
11
11
  /** @private */
12
- private _registeredPlugins;
12
+ private _dependencies;
13
13
  /** @private */
14
14
  private _instances;
15
15
  /** @private */
@@ -41,21 +41,33 @@ declare class BasePluginManager {
41
41
  * server.pluginManager.register('user-defined-id', pluginFactory);
42
42
  */
43
43
  register(id: string, ctor: any, options?: object, deps?: any[]): void;
44
+ /**
45
+ * Manually add a dependency to a given plugin. Usefull to require a plugin
46
+ * within a plugin
47
+ *
48
+ */
49
+ addDependency(pluginId: any, dependencyId: any): void;
50
+ /**
51
+ * Returns the list of the registered plugins ids
52
+ * @returns {string[]}
53
+ */
54
+ getRegisteredPlugins(): string[];
44
55
  /**
45
56
  * Initialize all the registered plugin. Executed during the `Client.init()` or
46
57
  * `Server.init()` initialization step.
47
58
  * @private
48
59
  */
49
60
  private start;
50
- stop(): Promise<void>;
61
+ /** @private */
62
+ private stop;
51
63
  /**
52
64
  * Retrieve an fully started instance of a registered plugin, without checking
53
- * that the pluginManager is started. This is important for starting the plugin
54
- * manager itself.
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
55
67
  *
56
68
  * @private
57
69
  */
58
- private getUnsafe;
70
+ private unsafeGet;
59
71
  /**
60
72
  * Propagate a notification each time a plugin is updated (status or inner state).
61
73
  * The callback will receive the list of all plugins as first parameter, and the
@@ -1 +1 @@
1
- {"version":3,"file":"BasePluginManager.d.ts","sourceRoot":"","sources":["../../src/common/BasePluginManager.js"],"names":[],"mappings":";AAKA;;;;GAIG;AACH;IACE,uBAcC;IAZC,eAAe;IACf,cAAiB;IACjB,eAAe;IACf,2BAAmC;IACnC,eAAe;IACf,mBAA2B;IAC3B,eAAe;IACf,+BAAuC;IACvC,eAAe;IACf,gCAAwC;IAExC,eAAoB;IAGtB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,aAfW,MAAM,uBAGN,MAAM,sBAqChB;IAED;;;;OAIG;IACH,cA2BC;IAED,sBAIC;IAED;;;;;;OAMG;IACH,kBAqDC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,4CAGC;IAED,eAAe;IACf,8BAaC;CACF"}
1
+ {"version":3,"file":"BasePluginManager.d.ts","sourceRoot":"","sources":["../../src/common/BasePluginManager.js"],"names":[],"mappings":";AAIA;;;;GAIG;AACH;IACE,uBAcC;IAZC,eAAe;IACf,cAAiB;IACjB,eAAe;IACf,sBAA8B;IAC9B,eAAe;IACf,mBAA2B;IAC3B,eAAe;IACf,+BAAuC;IACvC,eAAe;IACf,gCAAwC;IAExC,eAAoB;IAGtB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,aAfW,MAAM,uBAGN,MAAM,sBA6ChB;IAED;;;;OAIG;IACH,sDAGC;IAED;;;OAGG;IACH,wBAFa,MAAM,EAAE,CAIpB;IAED;;;;OAIG;IACH,cAyBC;IAED,eAAe;IACf,aAIC;IAED;;;;;;OAMG;IACH,kBAqDC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,4CAGC;IAED,eAAe;IACf,8BAaC;CACF"}
@@ -1,9 +1,12 @@
1
1
  export default BaseSharedState;
2
2
  declare class BaseSharedState {
3
- constructor(id: any, remoteId: any, schemaName: any, schema: any, client: any, isOwner: any, manager: any, initValues?: {});
4
- id: any;
5
- remoteId: any;
6
- schemaName: any;
3
+ constructor(id: any, remoteId: any, schemaName: any, schema: any, client: any, isOwner: any, manager: any, initValues: any, filter: any);
4
+ /** @private */
5
+ private _id;
6
+ /** @private */
7
+ private _remoteId;
8
+ /** @private */
9
+ private _schemaName;
7
10
  /** @private */
8
11
  private _isOwner;
9
12
  /** @private */
@@ -11,6 +14,14 @@ declare class BaseSharedState {
11
14
  /** @private */
12
15
  private _manager;
13
16
  /** @private */
17
+ private _filter;
18
+ /**
19
+ * true is the state has been detached or deleted
20
+ * @private
21
+ */
22
+ private _detached;
23
+ _promiseStore: PromiseStore;
24
+ /** @private */
14
25
  private _parameters;
15
26
  /** @private */
16
27
  private _onUpdateCallbacks;
@@ -18,18 +29,31 @@ declare class BaseSharedState {
18
29
  private _onDetachCallbacks;
19
30
  /** @private */
20
31
  private _onDeleteCallbacks;
21
- /** @private */
22
- private _clearDetach;
23
32
  /**
24
- * Detach from the state. If the client is the creator of the state, the state
25
- * is deleted and all attached nodes get notified
26
- *
27
- * @example
28
- * const state = await client.state.attach('globals');
29
- * // later
30
- * await state.detach();
33
+ * Id of the state
34
+ * @type {Number}
35
+ * @readonly
31
36
  */
32
- detach(): Promise<any>;
37
+ readonly get id(): number;
38
+ /**
39
+ * Unique id of the state for the current node
40
+ * @readonly
41
+ * @type {Number}
42
+ * @private
43
+ */
44
+ private readonly get remoteId();
45
+ /**
46
+ * Name of the schema
47
+ * @type {String}
48
+ * @readonly
49
+ */
50
+ readonly get schemaName(): string;
51
+ /**
52
+ * Indicates if the node is the owner of the state
53
+ * @type {Boolean}
54
+ * @readonly
55
+ */
56
+ readonly get isOwner(): boolean;
33
57
  /** @private */
34
58
  private _clearTransport;
35
59
  /** @private */
@@ -72,31 +96,63 @@ declare class BaseSharedState {
72
96
  */
73
97
  set(updates: object, context?: mixed): Promise<any>;
74
98
  /**
75
- * Get the value of a paramter of the state.
99
+ * Get the value of a parameter of the state. If the parameter is of `any` type,
100
+ * a deep copy is returned.
76
101
  *
77
102
  * @param {string} name - Name of the param.
78
103
  * @throws Throws if `name` does not correspond to an existing field
79
104
  * of the state.
80
105
  * @return {mixed}
81
106
  * @example
82
- * const value = state.get('name');
107
+ * const value = state.get('paramName');
83
108
  */
84
109
  get(name: string): mixed;
110
+ /**
111
+ * Similar to `get` but returns a reference to the underlying value in case of
112
+ * `any` type. May be usefull if the underlying value is big (e.g. sensors
113
+ * recordings, etc.) and deep cloning expensive. Be aware that if changes are
114
+ * made on the returned object, the state of your application will become
115
+ * inconsistent.
116
+ *
117
+ * @param {string} name - Name of the param.
118
+ * @throws Throws if `name` does not correspond to an existing field
119
+ * of the state.
120
+ * @return {mixed}
121
+ * @example
122
+ * const value = state.getUnsafe('paramName');
123
+ */
124
+ getUnsafe(name: string): mixed;
85
125
  /**
86
126
  * Get all the key / value pairs of the state.
87
127
  *
128
+ * If a parameter is of `any` type, a deep copy is made.
129
+ *
88
130
  * @return {object}
89
131
  * @example
90
132
  * const values = state.getValues();
91
133
  */
92
134
  getValues(): object;
93
135
  /**
94
- * Get the schema from which the state has been created.
136
+ * Get all the key / value pairs of the state.
137
+ *
138
+ * Similar to `getValues` but returns a reference to the underlying value in
139
+ * case of `any` type. May be usefull if the underlying value is big (e.g.
140
+ * sensors recordings, etc.) and deep cloning expensive. Be aware that if
141
+ * changes are made on the returned object, the state of your application will
142
+ * become inconsistent.
143
+ *
144
+ * @return {object}
145
+ * @example
146
+ * const values = state.getValues();
147
+ */
148
+ getValuesUnsafe(): object;
149
+ /**
150
+ * Definition of schema from which the state has been created.
95
151
  *
96
- * @param {string} [name=null] - If given, returns only the definition corresponding
97
- * to the given param name.
152
+ * @param {string} [name=null] - If given, returns only the definition
153
+ * corresponding to the given param name.
98
154
  * @throws Throws if `name` does not correspond to an existing field
99
- * of the state.
155
+ * of the schema.
100
156
  * @return {object}
101
157
  * @example
102
158
  * const schema = state.getSchema();
@@ -119,11 +175,23 @@ declare class BaseSharedState {
119
175
  * const defaults = state.getDefaults();
120
176
  */
121
177
  getDefaults(): object;
178
+ /**
179
+ * Detach from the state. If the client is the creator of the state, the state
180
+ * is deleted and all attached nodes get notified.
181
+ *
182
+ * @example
183
+ * const state = await client.state.attach('globals');
184
+ * // later
185
+ * await state.detach();
186
+ */
187
+ detach(): Promise<any>;
122
188
  /**
123
189
  * Delete the state. Only the creator/owner of the state can use this method.
124
- * All nodes attached to the state will be deteched, triggering the `onDetach`
125
- * callback. The creator of the state will also have its `onDelete` callback
126
- * triggered.
190
+ *
191
+ * All nodes attached to the state will be detached, triggering any registered
192
+ * `onDetach` callbacks. The creator of the state will also have its own `onDelete`
193
+ * callback triggered. The local `onDeatch` and `onDelete` callbacks will be
194
+ * executed *before* the returned Promise resolves
127
195
  *
128
196
  * @throws Throws if the method is called by a node which is not the owner of
129
197
  * the state.
@@ -136,7 +204,7 @@ declare class BaseSharedState {
136
204
  /**
137
205
  * Subscribe to state updates.
138
206
  *
139
- * @param {client.SharedState~onUpdateCallback|client.SharedState~onUpdateCallback} callback
207
+ * @param {client.SharedState~onUpdateCallback|server.SharedState~onUpdateCallback} callback
140
208
  * Callback to execute when an update is applied on the state.
141
209
  * @param {Boolean} [executeListener=false] - Execute the callback immediately
142
210
  * with current state values. (`oldValues` will be set to `{}`, and `context` to `null`)
@@ -155,19 +223,22 @@ declare class BaseSharedState {
155
223
  */
156
224
  onUpdate(listener: any, executeListener?: boolean): client.SharedState;
157
225
  /**
158
- * Register a function to execute when detaching from the state
226
+ * Register a function to execute when detaching from the state. The function
227
+ * will be executed before the `detach` promise resolves.
159
228
  *
160
- * @param {Function} callback - callback to execute when detaching from the state.
161
- * wether the client as called `detach`, or the state has been deleted by its
229
+ * @param {Function} callback - Callback to execute when detaching from the state.
230
+ * Whether the client as called `detach`, or the state has been deleted by its
162
231
  * creator.
163
232
  */
164
233
  onDetach(callback: Function): () => boolean;
165
234
  /**
166
235
  * Register a function to execute when the state is deleted. Only called if the
167
- * node was the creator of the state. Is called after `onDetach`
236
+ * node was the creator of the state. Is called after `onDetach` and executed
237
+ * before the `delete` Promise resolves.
168
238
  *
169
- * @param {Function} callback - callback to execute when the state is deleted.
239
+ * @param {Function} callback - Callback to execute when the state is deleted.
170
240
  */
171
241
  onDelete(callback: Function): () => boolean;
172
242
  }
243
+ import PromiseStore from './PromiseStore.js';
173
244
  //# sourceMappingURL=BaseSharedState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BaseSharedState.d.ts","sourceRoot":"","sources":["../../src/common/BaseSharedState.js"],"names":[],"mappings":";AAoBA;IACE,4HAwHC;IAvHC,QAAY;IACZ,cAAwB;IACxB,gBAA4B;IAE5B,eAAe;IACf,iBAAuB;IACvB,eAAe;IACf,gBAAqB;IACrB,eAAe;IACf,iBAAuB;IAGrB,eAAe;IACf,oBAAuD;IAQzD,eAAe;IACf,2BAAmC;IACnC,eAAe;IACf,2BAAmC;IACnC,eAAe;IACf,2BAAmC;IA+FrC,eAAe;IACf,qBASC;IAsND;;;;;;;;OAQG;IACH,uBAcC;IA3OD,eAAe;IACf,wBAOC;IAED,eAAe;IACf,gBAoDC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,aATW,MAAM,oBAIJ,YAAe,CAmD3B;IAED;;;;;;;;;OASG;IACH,UAPW,MAAM,SAShB;IAED;;;;;;OAMG;IACH,aAJY,MAAM,CAMjB;IAED;;;;;;;;;;OAUG;IACH,iBARW,MAAM,GAIL,MAAM,CAMjB;IAED;;;;;;;OAOG;IACH,iBAJY,MAAM,CAMjB;IAED;;;;;;OAMG;IACH,eAJY,MAAM,CAMjB;IA2BD;;;;;;;;;;;;OAYG;IACH,uBAMC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,uEAaC;IAED;;;;;;OAMG;IACH,4CAGC;IAED;;;;;OAKG;IACH,4CAGC;CACF"}
1
+ {"version":3,"file":"BaseSharedState.d.ts","sourceRoot":"","sources":["../../src/common/BaseSharedState.js"],"names":[],"mappings":";AAyBA;IACE,yIA8JC;IA7JC,eAAe;IACf,YAAa;IACb,eAAe;IACf,kBAAyB;IACzB,eAAe;IACf,oBAA6B;IAC7B,eAAe;IACf,iBAAuB;IACvB,eAAe;IACf,gBAAqB;IACrB,eAAe;IACf,iBAAuB;IACvB,eAAe;IACf,gBAAqB;IAErB;;;OAGG;IACH,kBAAsB;IAEtB,4BAA4D;IAG1D,eAAe;IACf,oBAAuD;IAQzD,eAAe;IACf,2BAAmC;IACnC,eAAe;IACf,2BAAmC;IACnC,eAAe;IACf,2BAAmC;IAyHrC;;;;OAIG;IACH,0BAEC;IAED;;;;;OAKG;IACH,gCAEC;IAED;;;;OAIG;IACH,kCAEC;IAED;;;;OAIG;IACH,gCAEC;IAED,eAAe;IACf,wBAcC;IAED,eAAe;IACf,gBAoDC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,aATW,MAAM,oBAIJ,YAAe,CA8G3B;IAED;;;;;;;;;;OAUG;IACH,UAPW,MAAM,SAmBhB;IAED;;;;;;;;;;;;;OAaG;IACH,gBAPW,MAAM,SAmBhB;IAED;;;;;;;;OAQG;IACH,aAJY,MAAM,CAgBjB;IAED;;;;;;;;;;;;OAYG;IACH,mBAJY,MAAM,CAgBjB;IAED;;;;;;;;;;OAUG;IACH,iBARW,MAAM,GAIL,MAAM,CAMjB;IAED;;;;;;;OAOG;IACH,iBAJY,MAAM,CAMjB;IAED;;;;;;OAMG;IACH,eAJY,MAAM,CAMjB;IAED;;;;;;;;OAQG;IACH,uBAmBC;IAED;;;;;;;;;;;;;;OAcG;IACH,uBAUC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,uEAaC;IAED;;;;;;;OAOG;IACH,4CAGC;IAED;;;;;;OAMG;IACH,4CAGC;CACF;yBArrBwB,mBAAmB"}