@soundworks/core
Advanced tools
Comparing version 4.0.0-alpha.21 to 4.0.0-alpha.22
@@ -1,3 +0,8 @@ | ||
## v4.0.0-alpha.21 - 19/02/2025 | ||
## v4.0.0-alpha.22 - 16/05/2025 | ||
- Feat: allow configuring socket endpoint on browser clients | ||
- Check and warn if version inconsistency between server and client | ||
## v4.0.0-alpha.21 - 6/05/2025 | ||
- Fix: prevent multiple 'close' events | ||
@@ -4,0 +9,0 @@ - Fix: disable heartbeat check on client-side, was unstable |
{ | ||
"name": "@soundworks/core", | ||
"version": "4.0.0-alpha.21", | ||
"version": "4.0.0-alpha.22", | ||
"description": "Open-source creative coding framework for distributed applications based on Web technologies", | ||
@@ -51,3 +51,4 @@ "authors": [ | ||
"types": "rm -Rf types && tsc", | ||
"postversion": "node ./misc/scripts/check-changelog.js" | ||
"preversion": "node ./misc/scripts/generate-version-file.js $npm_new_version", | ||
"postversion": "node ./misc/scripts/check-changelog.js && git commit -am \"$npm_new_version\" --allow-empty" | ||
}, | ||
@@ -54,0 +55,0 @@ "dependencies": { |
@@ -14,2 +14,3 @@ import { isBrowser, isPlainObject } from '@ircam/sc-utils'; | ||
import logger from '../common/logger.js'; | ||
import version from '../common/version.js'; | ||
@@ -19,3 +20,3 @@ /** | ||
* | ||
* @typedef BrowserClientConfig | ||
* @typedef ClientConfig | ||
* @memberof client | ||
@@ -28,2 +29,6 @@ * @type {object} | ||
* @property {object} [env] - Environment configration object. | ||
* @property {boolean} env.useHttps - Define if the websocket should use secure connection. | ||
* @property {boolean} [env.serverAddress=''] - Address the socket server. Mandatory for | ||
* node clients. For browser clients, use `window.location.domain` as fallback if empty. | ||
* @property {boolean} env.port - Port of the socket server. | ||
* @property {string} [env.websockets={}] - Configuration options for websockets. | ||
@@ -34,20 +39,2 @@ * @property {string} [env.subpath=''] - If running behind a proxy, path to the application. | ||
/** | ||
* Configuration object for a client running in a node runtime. | ||
* | ||
* @typedef NodeClientConfig | ||
* @memberof client | ||
* @type {object} | ||
* @property {string} role - Role of the client in the application (e.g. 'player', 'controller'). | ||
* @property {object} [app] - Application configration object. | ||
* @property {string} [app.name=''] - Name of the application. | ||
* @property {string} [app.author=''] - Name of the author. | ||
* @property {object} env - Environment configration object. | ||
* @property {boolean} env.serverAddress - Domain name or IP of the server. | ||
* @property {boolean} env.useHttps - Define is the server run in http or in https. | ||
* @property {boolean} env.port - Port on which the server is listening. | ||
* @property {string} [env.websockets={}] - Configuration options for websockets. | ||
* @property {string} [env.subpath=''] - If running behind a proxy, path to the application. | ||
*/ | ||
/** | ||
* The `Client` class is the main entry point for the client-side of a soundworks | ||
@@ -73,4 +60,3 @@ * application. | ||
/** | ||
* @param {client.BrowserClientConfig|client.NodeClientConfig} config - | ||
* Configuration of the soundworks client. | ||
* @param {client.ClientConfig} config - Configuration of the soundworks client. | ||
* @throws Will throw if the given config object is invalid. | ||
@@ -113,2 +99,9 @@ */ | ||
/** | ||
* package version | ||
* @type string | ||
* @readonly | ||
*/ | ||
this.version = version; | ||
/** | ||
* Role of the client in the application. | ||
@@ -123,3 +116,3 @@ * | ||
* | ||
* @type {client.BrowserClientConfig|client.NodeClientConfig} | ||
* @type {client.ClientConfig} | ||
*/ | ||
@@ -256,3 +249,3 @@ this.config = config; | ||
// wait for handshake response before starting stateManager and pluginManager | ||
this.socket.addListener(CLIENT_HANDSHAKE_RESPONSE, async ({ id, uuid, token }) => { | ||
this.socket.addListener(CLIENT_HANDSHAKE_RESPONSE, async ({ id, uuid, token, version }) => { | ||
this.id = id; | ||
@@ -262,2 +255,17 @@ this.uuid = uuid; | ||
if (version !== this.version) { | ||
console.warn(` | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
WARNING | ||
Version discrepancies between server and "${this.role}" client: | ||
+ server: ${version} | client: ${this.version} | ||
This might lead to unexpected behavior, you should consider to update your | ||
dependancies on both your server and clients. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`); | ||
} | ||
resolve(); | ||
@@ -288,2 +296,3 @@ }); | ||
role: this.role, | ||
version: this.version, | ||
registeredPlugins: this.pluginManager.getRegisteredPlugins(), | ||
@@ -290,0 +299,0 @@ }; |
/** | ||
* @license | ||
* Copyright (c) 2014-present IRCAM – Centre Pompidou (France, Paris) | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
/** | ||
* Client-side part of the `soundworks` framework. | ||
@@ -3,0 +9,0 @@ * |
@@ -102,16 +102,19 @@ import { isBrowser } from '@ircam/sc-utils'; | ||
let url; | ||
const protocol = config.env.useHttps ? 'wss:' : 'ws:'; | ||
const port = config.env.port; | ||
let serverAddress; | ||
let webSocketOptions; | ||
if (isBrowser()) { | ||
const protocol = window.location.protocol.replace(/^http?/, 'ws'); | ||
const { hostname, port } = window.location; | ||
// if a server address is given in config, use it, else fallback to URL hostname | ||
if (config.env.serverAddress !== '') { | ||
serverAddress = config.env.serverAddress; | ||
} else { | ||
serverAddress = window.location.hostname; | ||
} | ||
url = `${protocol}//${hostname}:${port}/${path}`; | ||
webSocketOptions = []; | ||
} else { | ||
const protocol = config.env.useHttps ? 'wss:' : 'ws:'; | ||
const { serverAddress, port } = config.env; | ||
serverAddress = config.env.serverAddress; | ||
url = `${protocol}//${serverAddress}:${port}/${path}`; | ||
webSocketOptions = { | ||
@@ -122,2 +125,3 @@ rejectUnauthorized: false, | ||
const url = `${protocol}//${serverAddress}:${port}/${path}`; | ||
let queryParams = `role=${role}&key=${key}`; | ||
@@ -124,0 +128,0 @@ |
/** | ||
* @license | ||
* Copyright (c) 2014-present IRCAM – Centre Pompidou (France, Paris) | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
/** | ||
* Server-side part of the *soundworks* framework. | ||
@@ -3,0 +9,0 @@ * |
@@ -35,4 +35,4 @@ import EventEmitter from 'node:events'; | ||
} from '../common/constants.js'; | ||
import version from '../common/version.js'; | ||
let _dbNamespaces = new Set(); | ||
@@ -166,2 +166,3 @@ | ||
} | ||
/** | ||
@@ -230,2 +231,4 @@ * @description Given config object merged with the following defaults: | ||
this.version = version; | ||
/** | ||
@@ -914,4 +917,5 @@ * Instance of the express router. | ||
socket.addListener(CLIENT_HANDSHAKE_REQUEST, async payload => { | ||
const { role, registeredPlugins } = payload; | ||
const { role, version, registeredPlugins } = payload; | ||
if (!roles.includes(role)) { | ||
@@ -927,2 +931,17 @@ console.error(`[soundworks.Server] A client with invalid role ("${role}") attempted to connect`); | ||
if (version !== this.version) { | ||
console.warn(` | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
WARNING | ||
Version discrepancies between server and "${role}" client: | ||
+ server: ${this.version} | client: ${version} | ||
This might lead to unexpected behavior, you should consider to update your | ||
dependancies on both your server and clients. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`); | ||
} | ||
try { | ||
@@ -958,3 +977,3 @@ this.pluginManager.checkRegisteredPlugins(registeredPlugins); | ||
const { id, uuid, token } = client; | ||
socket.send(CLIENT_HANDSHAKE_RESPONSE, { id, uuid, token }); | ||
socket.send(CLIENT_HANDSHAKE_RESPONSE, { id, uuid, token, version: this.version }); | ||
}); | ||
@@ -1069,2 +1088,8 @@ } | ||
type: config.env.type, | ||
// use to configure the socket if the server is running on a different | ||
// location than the one the client was served from (cf. #90) | ||
useHttps: config.env.useHttps, | ||
serverAddress: config.env.serverAddress, | ||
port: config.env.port, | ||
// other config, to review | ||
websockets: config.env.websockets, | ||
@@ -1071,0 +1096,0 @@ subpath: config.env.subpath, |
381434
110
9909