@soundworks/core 4.0.0-alpha.21 → 4.0.0-alpha.22
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 +6 -1
- package/package.json +3 -2
- package/src/client/Client.js +32 -23
- package/src/client/Socket.js +11 -7
- package/src/client/index.js +6 -0
- package/src/common/version.js +2 -0
- package/src/server/Server.js +28 -3
- package/src/server/index.js +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
## v4.0.0-alpha.
|
|
1
|
+
## v4.0.0-alpha.22 - 16/05/2025
|
|
2
|
+
|
|
3
|
+
- Feat: allow configuring socket endpoint on browser clients
|
|
4
|
+
- Check and warn if version inconsistency between server and client
|
|
5
|
+
|
|
6
|
+
## v4.0.0-alpha.21 - 6/05/2025
|
|
2
7
|
|
|
3
8
|
- Fix: prevent multiple 'close' events
|
|
4
9
|
- Fix: disable heartbeat check on client-side, was unstable
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soundworks/core",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.22",
|
|
4
4
|
"description": "Open-source creative coding framework for distributed applications based on Web technologies",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Benjamin Matuszewski",
|
|
@@ -48,7 +48,8 @@
|
|
|
48
48
|
"test": "npx mocha",
|
|
49
49
|
"test:all": "npx mocha tests/*/*.spec.js",
|
|
50
50
|
"types": "rm -Rf types && tsc",
|
|
51
|
-
"
|
|
51
|
+
"preversion": "node ./misc/scripts/generate-version-file.js $npm_new_version",
|
|
52
|
+
"postversion": "node ./misc/scripts/check-changelog.js && git commit -am \"$npm_new_version\" --allow-empty"
|
|
52
53
|
},
|
|
53
54
|
"dependencies": {
|
|
54
55
|
"@ircam/sc-utils": "^1.3.2",
|
package/src/client/Client.js
CHANGED
|
@@ -11,11 +11,12 @@ import {
|
|
|
11
11
|
AUDIT_STATE_NAME,
|
|
12
12
|
} from '../common/constants.js';
|
|
13
13
|
import logger from '../common/logger.js';
|
|
14
|
+
import version from '../common/version.js';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Configuration object for a client running in a browser runtime.
|
|
17
18
|
*
|
|
18
|
-
* @typedef
|
|
19
|
+
* @typedef ClientConfig
|
|
19
20
|
* @memberof client
|
|
20
21
|
* @type {object}
|
|
21
22
|
* @property {string} role - Role of the client in the application (e.g. 'player', 'controller').
|
|
@@ -23,24 +24,10 @@ import logger from '../common/logger.js';
|
|
|
23
24
|
* @property {string} [app.name=''] - Name of the application.
|
|
24
25
|
* @property {string} [app.author=''] - Name of the author.
|
|
25
26
|
* @property {object} [env] - Environment configration object.
|
|
26
|
-
* @property {
|
|
27
|
-
* @property {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Configuration object for a client running in a node runtime.
|
|
32
|
-
*
|
|
33
|
-
* @typedef NodeClientConfig
|
|
34
|
-
* @memberof client
|
|
35
|
-
* @type {object}
|
|
36
|
-
* @property {string} role - Role of the client in the application (e.g. 'player', 'controller').
|
|
37
|
-
* @property {object} [app] - Application configration object.
|
|
38
|
-
* @property {string} [app.name=''] - Name of the application.
|
|
39
|
-
* @property {string} [app.author=''] - Name of the author.
|
|
40
|
-
* @property {object} env - Environment configration object.
|
|
41
|
-
* @property {boolean} env.serverAddress - Domain name or IP of the server.
|
|
42
|
-
* @property {boolean} env.useHttps - Define is the server run in http or in https.
|
|
43
|
-
* @property {boolean} env.port - Port on which the server is listening.
|
|
27
|
+
* @property {boolean} env.useHttps - Define if the websocket should use secure connection.
|
|
28
|
+
* @property {boolean} [env.serverAddress=''] - Address the socket server. Mandatory for
|
|
29
|
+
* node clients. For browser clients, use `window.location.domain` as fallback if empty.
|
|
30
|
+
* @property {boolean} env.port - Port of the socket server.
|
|
44
31
|
* @property {string} [env.websockets={}] - Configuration options for websockets.
|
|
45
32
|
* @property {string} [env.subpath=''] - If running behind a proxy, path to the application.
|
|
46
33
|
*/
|
|
@@ -66,8 +53,7 @@ import logger from '../common/logger.js';
|
|
|
66
53
|
*/
|
|
67
54
|
class Client {
|
|
68
55
|
/**
|
|
69
|
-
* @param {client.
|
|
70
|
-
* Configuration of the soundworks client.
|
|
56
|
+
* @param {client.ClientConfig} config - Configuration of the soundworks client.
|
|
71
57
|
* @throws Will throw if the given config object is invalid.
|
|
72
58
|
*/
|
|
73
59
|
constructor(config) {
|
|
@@ -104,6 +90,13 @@ class Client {
|
|
|
104
90
|
}
|
|
105
91
|
}
|
|
106
92
|
|
|
93
|
+
/**
|
|
94
|
+
* package version
|
|
95
|
+
* @type string
|
|
96
|
+
* @readonly
|
|
97
|
+
*/
|
|
98
|
+
this.version = version;
|
|
99
|
+
|
|
107
100
|
/**
|
|
108
101
|
* Role of the client in the application.
|
|
109
102
|
*
|
|
@@ -114,7 +107,7 @@ class Client {
|
|
|
114
107
|
/**
|
|
115
108
|
* Configuration object.
|
|
116
109
|
*
|
|
117
|
-
* @type {client.
|
|
110
|
+
* @type {client.ClientConfig}
|
|
118
111
|
*/
|
|
119
112
|
this.config = config;
|
|
120
113
|
|
|
@@ -246,11 +239,26 @@ class Client {
|
|
|
246
239
|
try {
|
|
247
240
|
await new Promise((resolve, reject) => {
|
|
248
241
|
// wait for handshake response before starting stateManager and pluginManager
|
|
249
|
-
this.socket.addListener(CLIENT_HANDSHAKE_RESPONSE, async ({ id, uuid, token }) => {
|
|
242
|
+
this.socket.addListener(CLIENT_HANDSHAKE_RESPONSE, async ({ id, uuid, token, version }) => {
|
|
250
243
|
this.id = id;
|
|
251
244
|
this.uuid = uuid;
|
|
252
245
|
this.token = token;
|
|
253
246
|
|
|
247
|
+
if (version !== this.version) {
|
|
248
|
+
console.warn(`
|
|
249
|
+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
250
|
+
|
|
251
|
+
WARNING
|
|
252
|
+
|
|
253
|
+
Version discrepancies between server and "${this.role}" client:
|
|
254
|
+
+ server: ${version} | client: ${this.version}
|
|
255
|
+
|
|
256
|
+
This might lead to unexpected behavior, you should consider to update your
|
|
257
|
+
dependancies on both your server and clients.
|
|
258
|
+
|
|
259
|
+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`);
|
|
260
|
+
}
|
|
261
|
+
|
|
254
262
|
resolve();
|
|
255
263
|
});
|
|
256
264
|
|
|
@@ -276,6 +284,7 @@ class Client {
|
|
|
276
284
|
// send handshake request
|
|
277
285
|
const payload = {
|
|
278
286
|
role: this.role,
|
|
287
|
+
version: this.version,
|
|
279
288
|
registeredPlugins: this.pluginManager.getRegisteredPlugins(),
|
|
280
289
|
};
|
|
281
290
|
|
package/src/client/Socket.js
CHANGED
|
@@ -99,25 +99,29 @@ class Socket {
|
|
|
99
99
|
path = `${config.env.subpath}/${path}`;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
const protocol = config.env.useHttps ? 'wss:' : 'ws:';
|
|
103
|
+
const port = config.env.port;
|
|
104
|
+
let serverAddress;
|
|
103
105
|
let webSocketOptions;
|
|
104
106
|
|
|
105
107
|
if (isBrowser()) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
// if a server address is given in config, use it, else fallback to URL hostname
|
|
109
|
+
if (config.env.serverAddress !== '') {
|
|
110
|
+
serverAddress = config.env.serverAddress;
|
|
111
|
+
} else {
|
|
112
|
+
serverAddress = window.location.hostname;
|
|
113
|
+
}
|
|
108
114
|
|
|
109
|
-
url = `${protocol}//${hostname}:${port}/${path}`;
|
|
110
115
|
webSocketOptions = [];
|
|
111
116
|
} else {
|
|
112
|
-
|
|
113
|
-
const { serverAddress, port } = config.env;
|
|
117
|
+
serverAddress = config.env.serverAddress;
|
|
114
118
|
|
|
115
|
-
url = `${protocol}//${serverAddress}:${port}/${path}`;
|
|
116
119
|
webSocketOptions = {
|
|
117
120
|
rejectUnauthorized: false,
|
|
118
121
|
};
|
|
119
122
|
}
|
|
120
123
|
|
|
124
|
+
const url = `${protocol}//${serverAddress}:${port}/${path}`;
|
|
121
125
|
let queryParams = `role=${role}&key=${key}`;
|
|
122
126
|
|
|
123
127
|
if (config.token) {
|
package/src/client/index.js
CHANGED
package/src/server/Server.js
CHANGED
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
CLIENT_HANDSHAKE_ERROR,
|
|
33
33
|
AUDIT_STATE_NAME,
|
|
34
34
|
} from '../common/constants.js';
|
|
35
|
-
|
|
35
|
+
import version from '../common/version.js';
|
|
36
36
|
|
|
37
37
|
let _dbNamespaces = new Set();
|
|
38
38
|
|
|
@@ -162,6 +162,7 @@ class Server {
|
|
|
162
162
|
if (!isPlainObject(config)) {
|
|
163
163
|
throw new Error(`[soundworks:Server] Invalid argument for Server constructor, config should be an object`);
|
|
164
164
|
}
|
|
165
|
+
|
|
165
166
|
/**
|
|
166
167
|
* @description Given config object merged with the following defaults:
|
|
167
168
|
* @example
|
|
@@ -225,6 +226,8 @@ class Server {
|
|
|
225
226
|
}
|
|
226
227
|
}
|
|
227
228
|
|
|
229
|
+
this.version = version;
|
|
230
|
+
|
|
228
231
|
/**
|
|
229
232
|
* Instance of the express router.
|
|
230
233
|
*
|
|
@@ -908,7 +911,8 @@ Invalid certificate files, please check your:
|
|
|
908
911
|
});
|
|
909
912
|
|
|
910
913
|
socket.addListener(CLIENT_HANDSHAKE_REQUEST, async payload => {
|
|
911
|
-
const { role, registeredPlugins } = payload;
|
|
914
|
+
const { role, version, registeredPlugins } = payload;
|
|
915
|
+
|
|
912
916
|
|
|
913
917
|
if (!roles.includes(role)) {
|
|
914
918
|
console.error(`[soundworks.Server] A client with invalid role ("${role}") attempted to connect`);
|
|
@@ -920,6 +924,21 @@ Invalid certificate files, please check your:
|
|
|
920
924
|
return;
|
|
921
925
|
}
|
|
922
926
|
|
|
927
|
+
if (version !== this.version) {
|
|
928
|
+
console.warn(`
|
|
929
|
+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
930
|
+
|
|
931
|
+
WARNING
|
|
932
|
+
|
|
933
|
+
Version discrepancies between server and "${role}" client:
|
|
934
|
+
+ server: ${this.version} | client: ${version}
|
|
935
|
+
|
|
936
|
+
This might lead to unexpected behavior, you should consider to update your
|
|
937
|
+
dependancies on both your server and clients.
|
|
938
|
+
|
|
939
|
+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`);
|
|
940
|
+
}
|
|
941
|
+
|
|
923
942
|
try {
|
|
924
943
|
this.pluginManager.checkRegisteredPlugins(registeredPlugins);
|
|
925
944
|
} catch (err) {
|
|
@@ -950,7 +969,7 @@ Invalid certificate files, please check your:
|
|
|
950
969
|
this._onClientConnectCallbacks.forEach(callback => callback(client));
|
|
951
970
|
|
|
952
971
|
const { id, uuid, token } = client;
|
|
953
|
-
socket.send(CLIENT_HANDSHAKE_RESPONSE, { id, uuid, token });
|
|
972
|
+
socket.send(CLIENT_HANDSHAKE_RESPONSE, { id, uuid, token, version: this.version });
|
|
954
973
|
});
|
|
955
974
|
}
|
|
956
975
|
|
|
@@ -1060,6 +1079,12 @@ Invalid certificate files, please check your:
|
|
|
1060
1079
|
},
|
|
1061
1080
|
env: {
|
|
1062
1081
|
type: config.env.type,
|
|
1082
|
+
// use to configure the socket if the server is running on a different
|
|
1083
|
+
// location than the one the client was served from (cf. #90)
|
|
1084
|
+
useHttps: config.env.useHttps,
|
|
1085
|
+
serverAddress: config.env.serverAddress,
|
|
1086
|
+
port: config.env.port,
|
|
1087
|
+
// other config, to review
|
|
1063
1088
|
websockets: config.env.websockets,
|
|
1064
1089
|
subpath: config.env.subpath,
|
|
1065
1090
|
useMinifiedFile: useMinifiedFile[role],
|