@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.
- package/CHANGELOG.md +14 -3
- package/package.json +15 -15
- package/src/client/Client.js +233 -188
- package/src/client/Socket.js +84 -247
- package/src/client/index.js +6 -0
- package/src/common/constants.js +0 -1
- package/src/common/logger.js +15 -0
- package/src/common/sockets-utils.js +0 -63
- package/src/common/version.js +2 -0
- package/src/server/Plugin.js +22 -10
- package/src/server/Server.js +37 -36
- package/src/server/Socket.js +126 -250
- package/src/server/Sockets.js +103 -127
- package/src/server/audit-network-latency.worker.js +4 -3
- package/src/server/index.js +6 -0
- package/types/client/Client.d.ts +41 -8
- package/types/client/Client.d.ts.map +1 -1
- package/types/client/Context.d.ts +40 -14
- package/types/client/Context.d.ts.map +1 -1
- package/types/client/Plugin.d.ts +42 -41
- package/types/client/Plugin.d.ts.map +1 -1
- package/types/client/PluginManager.d.ts +26 -11
- package/types/client/PluginManager.d.ts.map +1 -1
- package/types/client/SharedState.d.ts +1 -1
- package/types/client/SharedState.d.ts.map +1 -1
- package/types/client/SharedStateCollection.d.ts +41 -0
- package/types/client/SharedStateCollection.d.ts.map +1 -0
- package/types/client/Socket.d.ts +41 -30
- package/types/client/Socket.d.ts.map +1 -1
- package/types/client/StateManager.d.ts +1 -1
- package/types/client/StateManager.d.ts.map +1 -1
- package/types/client/index.d.ts +0 -8
- package/types/common/BasePlugin.d.ts +24 -19
- package/types/common/BasePlugin.d.ts.map +1 -1
- package/types/common/BasePluginManager.d.ts +17 -5
- package/types/common/BasePluginManager.d.ts.map +1 -1
- package/types/common/BaseSharedState.d.ts +100 -29
- package/types/common/BaseSharedState.d.ts.map +1 -1
- package/types/common/BaseSharedStateCollection.d.ts +183 -0
- package/types/common/BaseSharedStateCollection.d.ts.map +1 -0
- package/types/common/BaseStateManager.d.ts +83 -18
- package/types/common/BaseStateManager.d.ts.map +1 -1
- package/types/common/BatchedTransport.d.ts +21 -0
- package/types/common/BatchedTransport.d.ts.map +1 -0
- package/types/common/ParameterBag.d.ts +61 -40
- package/types/common/ParameterBag.d.ts.map +1 -1
- package/types/common/PromiseStore.d.ts +11 -0
- package/types/common/PromiseStore.d.ts.map +1 -0
- package/types/common/SharedStatePrivate.d.ts +4 -3
- package/types/common/SharedStatePrivate.d.ts.map +1 -1
- package/types/common/constants.d.ts +10 -1
- package/types/common/constants.d.ts.map +1 -1
- package/types/common/logger.d.ts +1 -1
- package/types/common/sockets-utils.d.ts.map +1 -1
- package/types/common/version.d.ts +3 -0
- package/types/common/version.d.ts.map +1 -0
- package/types/server/Client.d.ts +5 -0
- package/types/server/Client.d.ts.map +1 -1
- package/types/server/Context.d.ts +162 -22
- package/types/server/Context.d.ts.map +1 -1
- package/types/server/ContextManager.d.ts +4 -4
- package/types/server/ContextManager.d.ts.map +1 -1
- package/types/server/Plugin.d.ts +56 -55
- package/types/server/Plugin.d.ts.map +1 -1
- package/types/server/PluginManager.d.ts +26 -6
- package/types/server/PluginManager.d.ts.map +1 -1
- package/types/server/Server.d.ts +207 -70
- package/types/server/Server.d.ts.map +1 -1
- package/types/server/SharedState.d.ts +1 -1
- package/types/server/SharedState.d.ts.map +1 -1
- package/types/server/SharedStateCollection.d.ts +41 -0
- package/types/server/SharedStateCollection.d.ts.map +1 -0
- package/types/server/Socket.d.ts +93 -57
- package/types/server/Socket.d.ts.map +1 -1
- package/types/server/Sockets.d.ts +32 -25
- package/types/server/Sockets.d.ts.map +1 -1
- package/types/server/StateManager.d.ts +242 -27
- package/types/server/StateManager.d.ts.map +1 -1
- package/types/server/audit-network-latency.worker.d.ts +2 -1
- package/types/server/audit-schema.d.ts +8 -8
- package/types/server/crypto.d.ts +3 -0
- package/types/server/crypto.d.ts.map +1 -0
- package/types/server/index.d.ts +0 -4
- package/types/common/promise-store.d.ts +0 -4
- package/types/common/promise-store.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/Socket.d.ts
CHANGED
|
@@ -1,128 +1,164 @@
|
|
|
1
1
|
export default Socket;
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* - one configured with `binaryType=arraybuffer` for streaming data more
|
|
7
|
-
* efficiently.
|
|
3
|
+
* The Socket class is a simple publish / subscribe wrapper built on top of the
|
|
4
|
+
* [ws](https://github.com/websockets/ws) library. An instance of {@link server.Socket}
|
|
5
|
+
* is automatically created per client when it connects (see {@link server.Client#socket}).
|
|
8
6
|
*
|
|
9
|
-
* @
|
|
7
|
+
* _Important: In most cases, you should consider using a {@link client.SharedState}
|
|
8
|
+
* rather than directly using the sockets._
|
|
9
|
+
*
|
|
10
|
+
* The Socket class contains two different WebSockets:
|
|
11
|
+
* - a socket configured with `binaryType = 'blob'` for JSON compatible data
|
|
12
|
+
* types (i.e. string, number, boolean, object, array and null).
|
|
13
|
+
* - a socket configured with `binaryType= 'arraybuffer'` for efficient streaming
|
|
14
|
+
* of binary data.
|
|
10
15
|
*
|
|
11
16
|
* @memberof server
|
|
17
|
+
* @hideconstructor
|
|
12
18
|
*/
|
|
13
19
|
declare class Socket {
|
|
14
|
-
constructor(ws: any, binaryWs: any, rooms: any, sockets: any
|
|
20
|
+
constructor(ws: any, binaryWs: any, rooms: any, sockets: any);
|
|
21
|
+
/**
|
|
22
|
+
* `ws` socket instance configured with `binaryType=blob` (string)
|
|
23
|
+
*
|
|
24
|
+
* @type {object}
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
private ws;
|
|
28
|
+
/**
|
|
29
|
+
* `ws` socket instance configured with `binaryType=arraybuffer` (TypedArray)
|
|
30
|
+
*
|
|
31
|
+
* @type {object}
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
private binaryWs;
|
|
15
35
|
/**
|
|
16
36
|
* Reference to the sockets object, is mainly dedicated to allow
|
|
17
37
|
* broadcasting from a given socket instance.
|
|
38
|
+
*
|
|
18
39
|
* @type {server.Sockets}
|
|
19
40
|
* @example
|
|
20
41
|
* socket.sockets.broadcast('my-room', this, 'update-value', 1);
|
|
21
42
|
*/
|
|
22
43
|
sockets: server.Sockets;
|
|
23
44
|
/**
|
|
24
|
-
*
|
|
45
|
+
* Reference to the rooms object
|
|
46
|
+
*
|
|
47
|
+
* @type {Map}
|
|
25
48
|
* @private
|
|
26
|
-
* @type {Object}
|
|
27
49
|
*/
|
|
28
|
-
private
|
|
50
|
+
private rooms;
|
|
51
|
+
/** @private */
|
|
52
|
+
private _stringListeners;
|
|
53
|
+
/** @private */
|
|
54
|
+
private _binaryListeners;
|
|
55
|
+
/** @private */
|
|
56
|
+
private _heartbeatId;
|
|
57
|
+
/** @private */
|
|
58
|
+
private _isAlive;
|
|
29
59
|
/**
|
|
30
|
-
*
|
|
60
|
+
* Removes all listeners and immediately close the two sockets. Is automatically
|
|
61
|
+
* called on `server.stop()`
|
|
62
|
+
*
|
|
31
63
|
* @private
|
|
32
|
-
* @type {Object}
|
|
33
64
|
*/
|
|
34
|
-
private
|
|
65
|
+
private terminate;
|
|
35
66
|
/**
|
|
36
|
-
*
|
|
67
|
+
* @param {boolean} binary - Emit to either the string or binary socket.
|
|
68
|
+
* @param {string} channel - Channel name.
|
|
69
|
+
* @param {...*} args - Content of the message.
|
|
37
70
|
* @private
|
|
38
|
-
* @type {Map}
|
|
39
71
|
*/
|
|
40
|
-
private
|
|
72
|
+
private _emit;
|
|
41
73
|
/**
|
|
42
|
-
*
|
|
43
|
-
* @
|
|
74
|
+
* @param {Function[]} listeners - List of listeners, either for the string or binary socket.
|
|
75
|
+
* @param {string} channel - Channel name.
|
|
76
|
+
* @param {Function} callback - The function to be added to the listeners.
|
|
77
|
+
* @private
|
|
44
78
|
*/
|
|
45
|
-
|
|
46
|
-
_stringListeners: Map<any, any>;
|
|
47
|
-
_binaryListeners: Map<any, any>;
|
|
48
|
-
_isAlive: boolean;
|
|
49
|
-
_intervalId: NodeJS.Timeout;
|
|
79
|
+
private _addListener;
|
|
50
80
|
/**
|
|
51
|
-
*
|
|
81
|
+
* @param {Function[]} listeners - List of listeners, either for the string or binary socket.
|
|
82
|
+
* @param {string} channel - Channel name.
|
|
83
|
+
* @param {Function} callback - The function to be removed from the listeners.
|
|
84
|
+
* @private
|
|
52
85
|
*/
|
|
53
|
-
/** @private */
|
|
54
|
-
private terminate;
|
|
55
|
-
/** @private */
|
|
56
|
-
private _emit;
|
|
57
|
-
/** @private */
|
|
58
|
-
private _addListener;
|
|
59
|
-
/** @private */
|
|
60
86
|
private _removeListener;
|
|
61
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* @param {Function[]} listeners - List of listeners, either for the string or binary socket.
|
|
89
|
+
* @param {string} [channel=null] - Channel name of the listeners to remove. If null
|
|
90
|
+
* all the listeners are cleared.
|
|
91
|
+
* @private
|
|
92
|
+
*/
|
|
62
93
|
private _removeAllListeners;
|
|
63
94
|
/**
|
|
64
95
|
* Add the socket to a room
|
|
65
|
-
*
|
|
96
|
+
*
|
|
97
|
+
* @param {string} roomId - Id of the room.
|
|
66
98
|
*/
|
|
67
99
|
addToRoom(roomId: string): void;
|
|
68
100
|
/**
|
|
69
101
|
* Remove the socket from a room
|
|
70
|
-
*
|
|
102
|
+
*
|
|
103
|
+
* @param {string} roomId - Id of the room.
|
|
71
104
|
*/
|
|
72
105
|
removeFromRoom(roomId: string): void;
|
|
73
106
|
/**
|
|
74
|
-
*
|
|
107
|
+
* Send messages with JSON compatible data types on a given channel.
|
|
75
108
|
*
|
|
76
|
-
* @param {
|
|
77
|
-
* @param {...*} args -
|
|
109
|
+
* @param {string} channel - Channel name.
|
|
110
|
+
* @param {...*} args - Payload of the message. As many arguments as needed, of
|
|
111
|
+
* JSON compatible data types (i.e. string, number, boolean, object, array and null).
|
|
78
112
|
*/
|
|
79
113
|
send(channel: string, ...args: any[]): void;
|
|
80
114
|
/**
|
|
81
|
-
* Listen JSON compatible
|
|
115
|
+
* Listen messages with JSON compatible data types on a given channel.
|
|
82
116
|
*
|
|
83
|
-
* @param {
|
|
84
|
-
* @param {Function} callback - Callback to execute when a message is received
|
|
117
|
+
* @param {string} channel - Channel name.
|
|
118
|
+
* @param {Function} callback - Callback to execute when a message is received,
|
|
119
|
+
* arguments of the callback function will match the arguments sent using the
|
|
120
|
+
* {@link server.Socket#send} method.
|
|
85
121
|
*/
|
|
86
122
|
addListener(channel: string, callback: Function): void;
|
|
87
123
|
/**
|
|
88
|
-
* Remove a listener
|
|
124
|
+
* Remove a listener of messages with JSON compatible data types from a given channel.
|
|
89
125
|
*
|
|
90
|
-
* @param {
|
|
91
|
-
* @param {Function} callback - Callback to
|
|
126
|
+
* @param {string} channel - Channel name.
|
|
127
|
+
* @param {Function} callback - Callback to remove.
|
|
92
128
|
*/
|
|
93
129
|
removeListener(channel: string, callback: Function): void;
|
|
94
130
|
/**
|
|
95
|
-
* Remove all listeners
|
|
131
|
+
* Remove all listeners of messages with JSON compatible data types.
|
|
96
132
|
*
|
|
97
|
-
* @param {
|
|
133
|
+
* @param {string} channel - Channel name.
|
|
98
134
|
*/
|
|
99
|
-
removeAllListeners(channel
|
|
135
|
+
removeAllListeners(channel?: string): void;
|
|
100
136
|
/**
|
|
101
|
-
*
|
|
137
|
+
* Send binary messages on a given channel.
|
|
102
138
|
*
|
|
103
|
-
* @param {
|
|
104
|
-
* @param {TypedArray} typedArray -
|
|
139
|
+
* @param {string} channel - Channel name.
|
|
140
|
+
* @param {TypedArray} typedArray - Binary data to be sent.
|
|
105
141
|
*/
|
|
106
142
|
sendBinary(channel: string, typedArray: TypedArray): void;
|
|
107
143
|
/**
|
|
108
144
|
* Listen binary messages on a given channel
|
|
109
145
|
*
|
|
110
|
-
* @param {
|
|
111
|
-
* @param {Function} callback - Callback to execute when a message is received
|
|
146
|
+
* @param {string} channel - Channel name.
|
|
147
|
+
* @param {Function} callback - Callback to execute when a message is received.
|
|
112
148
|
*/
|
|
113
149
|
addBinaryListener(channel: string, callback: Function): void;
|
|
114
150
|
/**
|
|
115
|
-
* Remove a listener
|
|
151
|
+
* Remove a listener of binary compatible messages from a given channel
|
|
116
152
|
*
|
|
117
|
-
* @param {
|
|
118
|
-
* @param {Function} callback - Callback to
|
|
153
|
+
* @param {string} channel - Channel name.
|
|
154
|
+
* @param {Function} callback - Callback to remove.
|
|
119
155
|
*/
|
|
120
156
|
removeBinaryListener(channel: string, callback: Function): void;
|
|
121
157
|
/**
|
|
122
|
-
* Remove all listeners
|
|
158
|
+
* Remove all listeners of binary compatible messages on a given channel
|
|
123
159
|
*
|
|
124
|
-
* @param {
|
|
160
|
+
* @param {string} channel - Channel of the message.
|
|
125
161
|
*/
|
|
126
|
-
removeAllBinaryListeners(channel
|
|
162
|
+
removeAllBinaryListeners(channel?: string): void;
|
|
127
163
|
}
|
|
128
164
|
//# sourceMappingURL=Socket.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Socket.d.ts","sourceRoot":"","sources":["../../src/server/Socket.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"Socket.d.ts","sourceRoot":"","sources":["../../src/server/Socket.js"],"names":[],"mappings":";AAqBA;;;;;;;;;;;;;;;;GAgBG;AACH;IACE,8DAiIC;IAhIC;;;;;OAKG;IACH,WAAY;IAEZ;;;;;OAKG;IACH,iBAAwB;IAExB;;;;;;;OAOG;IACH,wBAAsB;IAEtB;;;;;OAKG;IACH,cAAkB;IAElB,eAAe;IACf,yBAAiC;IACjC,eAAe;IACf,yBAAiC;IACjC,eAAe;IACf,qBAAwB;IAIxB,eAAe;IACf,iBAAoB;IAsFtB;;;;;OAKG;IACH,kBAoCC;IAED;;;;;OAKG;IACH,cAOC;IAED;;;;;OAKG;IACH,qBAOC;IAED;;;;;OAKG;IACH,wBASC;IAED;;;;;OAKG;IACH,4BAMC;IAED;;;;OAIG;IACH,kBAFW,MAAM,QAShB;IAED;;;;OAIG;IACH,uBAFW,MAAM,QAOhB;IAED;;;;;;OAMG;IACH,cAJW,MAAM,wBAkBhB;IAED;;;;;;;OAOG;IACH,qBALW,MAAM,4BAOhB;IAED;;;;;OAKG;IACH,wBAHW,MAAM,4BAKhB;IAED;;;;OAIG;IACH,6BAFW,MAAM,QAIhB;IAED;;;;;OAKG;IACH,oBAHW,MAAM,gCAWhB;IAED;;;;;OAKG;IACH,2BAHW,MAAM,4BAKhB;IAED;;;;;OAKG;IACH,8BAHW,MAAM,4BAKhB;IAED;;;;OAIG;IACH,mCAFW,MAAM,QAIhB;CACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export default Sockets;
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Manager all {@link server.Socket} instances.
|
|
4
|
+
*
|
|
4
5
|
* Most of the time, you shouldn't have to use this class instance directely, but
|
|
5
6
|
* it could be usefull in some situations, for broadcasting messages, creating rooms, etc.
|
|
6
7
|
*
|
|
@@ -17,57 +18,63 @@ declare class Sockets {
|
|
|
17
18
|
private _latencyStatsWorker;
|
|
18
19
|
/** @private */
|
|
19
20
|
private _auditState;
|
|
21
|
+
/** @private */
|
|
22
|
+
private _DEBUG_PREVENT_HEARTBEAT;
|
|
20
23
|
/**
|
|
21
|
-
* Initialize sockets, all sockets are added
|
|
24
|
+
* Initialize sockets, all sockets are added to two rooms by default:
|
|
22
25
|
* - to the room corresponding to the client `role`
|
|
23
|
-
* - to the '*' that holds all connected sockets
|
|
26
|
+
* - to the '*' room that holds all connected sockets
|
|
24
27
|
*
|
|
25
28
|
* @private
|
|
26
29
|
*/
|
|
27
30
|
private start;
|
|
28
|
-
/**
|
|
29
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Terminate all existing sockets
|
|
33
|
+
*
|
|
34
|
+
* @private
|
|
35
|
+
*/
|
|
36
|
+
private terminate;
|
|
30
37
|
/** @private */
|
|
31
38
|
private _broadcast;
|
|
32
39
|
/**
|
|
33
40
|
* Add a socket to a room
|
|
34
41
|
*
|
|
35
42
|
* @param {server.Socket} socket - Socket to add to the room.
|
|
36
|
-
* @param {String} roomId - Id of the room
|
|
43
|
+
* @param {String} roomId - Id of the room.
|
|
37
44
|
*/
|
|
38
45
|
addToRoom(socket: server.Socket, roomId: string): void;
|
|
39
46
|
/**
|
|
40
47
|
* Remove a socket from a room
|
|
41
48
|
*
|
|
42
49
|
* @param {server.Socket} socket - Socket to remove from the room.
|
|
43
|
-
* @param {String}
|
|
50
|
+
* @param {String} roomId - Id of the room.
|
|
44
51
|
*/
|
|
45
|
-
removeFromRoom(socket: server.Socket, roomId
|
|
52
|
+
removeFromRoom(socket: server.Socket, roomId: string): void;
|
|
46
53
|
/**
|
|
47
|
-
* Send a
|
|
48
|
-
*
|
|
54
|
+
* Send a message of JSON compatible data types to all client of given room(s).
|
|
55
|
+
* If no room is specified, the message is sent to all clients.
|
|
56
|
+
*
|
|
49
57
|
*
|
|
50
58
|
* @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
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* @param {
|
|
56
|
-
*
|
|
59
|
+
* the message. If `null` the message is sent to all clients.
|
|
60
|
+
* @param {server.Socket} excludeSocket - Optionnal socket to ignore when
|
|
61
|
+
* broadcasting the message, typically the client at the origin of the message.
|
|
62
|
+
* @param {String} channel - Channel name.
|
|
63
|
+
* @param {...*} args - Payload of the message. As many arguments as needed, of
|
|
64
|
+
* JSON compatible data types (i.e. string, number, boolean, object, array and null).
|
|
57
65
|
*/
|
|
58
66
|
broadcast(roomIds: any, excludeSocket: server.Socket, channel: string, ...args: any[]): void;
|
|
59
67
|
/**
|
|
60
|
-
* Send a binary message
|
|
61
|
-
*
|
|
68
|
+
* Send a binary message to all client of given room(s). If no room is specified
|
|
69
|
+
* specified, the message is sent to all clients.
|
|
62
70
|
*
|
|
63
71
|
* @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
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* @param {
|
|
69
|
-
* @param {...*} args - Arguments of the message (as many as needed, of any type)
|
|
72
|
+
* the message. If `null` the message is sent to all clients.
|
|
73
|
+
* @param {server.Socket} excludeSocket - Optionnal socket to ignore when
|
|
74
|
+
* broadcasting the message, typically the client at the origin of the message.
|
|
75
|
+
* @param {string} channel - Channel name.
|
|
76
|
+
* @param {TypedArray} typedArray - Binary data to be sent.
|
|
70
77
|
*/
|
|
71
|
-
broadcastBinary(roomIds: any, excludeSocket: server.Socket, channel: string, typedArray:
|
|
78
|
+
broadcastBinary(roomIds: any, excludeSocket: server.Socket, channel: string, typedArray: TypedArray): void;
|
|
72
79
|
}
|
|
73
80
|
//# sourceMappingURL=Sockets.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sockets.d.ts","sourceRoot":"","sources":["../../src/server/Sockets.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"Sockets.d.ts","sourceRoot":"","sources":["../../src/server/Sockets.js"],"names":[],"mappings":";AAUA;;;;;;;GAOG;AACH;IAEI,eAAe;IACf,aAAgB;IAChB,eAAe;IACf,eAAuB;IAGvB,eAAe;IACf,6BAAqC;IAErC,eAAe;IACf,4BAA+B;IAC/B,eAAe;IACf,oBAAuB;IAEvB,eAAe;IACf,iCAAqC;IAGvC;;;;;;OAMG;IACH,cA8EC;IAED;;;;OAIG;IACH,kBAMC;IAED,eAAe;IACf,mBA8BC;IAED;;;;;OAKG;IACH,uDAEC;IAED;;;;;OAKG;IACH,4DAEC;IAED;;;;;;;;;;;;OAYG;IACH,6FAEC;IAED;;;;;;;;;;OAUG;IACH,qEAHW,MAAM,gCAKhB;CACF"}
|