@soundworks/core 4.0.0-alpha.25 → 4.0.0-alpha.26

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 CHANGED
@@ -1,3 +1,7 @@
1
+ ## v4.0.0-alpha.26 - 05/09/2025
2
+
3
+ - Fix: improve reconnect strategy in case of socket connection failure
4
+
1
5
  ## v4.0.0-alpha.25 - 24/05/2025
2
6
 
3
7
  - Fix: better default behavior for websocket connection URL
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soundworks/core",
3
- "version": "4.0.0-alpha.25",
3
+ "version": "4.0.0-alpha.26",
4
4
  "description": "Open-source creative coding framework for distributed applications based on Web technologies",
5
5
  "authors": [
6
6
  "Benjamin Matuszewski",
@@ -91,6 +91,8 @@ class Socket {
91
91
  }
92
92
 
93
93
  webSocketOptions = {
94
+ // handshakeTimeout: 2000,
95
+ // do not reject self-signed certificates
94
96
  rejectUnauthorized: false,
95
97
  };
96
98
  }
@@ -107,8 +109,6 @@ class Socket {
107
109
  // Init socket
108
110
  // ----------------------------------------------------------
109
111
  return new Promise(resolve => {
110
- let connectionRefusedLogged = false;
111
-
112
112
  const trySocket = async () => {
113
113
  const ws = new WebSocket(url, webSocketOptions);
114
114
 
@@ -118,7 +118,6 @@ class Socket {
118
118
 
119
119
  this.#socket.addEventListener('message', e => {
120
120
  if (e.data === PING_MESSAGE) {
121
- // heartbeat();
122
121
  this.#socket.send(PONG_MESSAGE);
123
122
  // do not propagate ping / pong messages
124
123
  return;
@@ -161,26 +160,20 @@ class Socket {
161
160
 
162
161
  // cf. https://github.com/collective-soundworks/soundworks/issues/17
163
162
  ws.addEventListener('error', e => {
164
- if (e.type === 'error') {
165
- if (ws.terminate) {
166
- ws.terminate();
167
- } else {
168
- ws.close();
169
- }
163
+ if (ws.terminate) {
164
+ ws.terminate();
165
+ } else {
166
+ ws.close();
167
+ }
170
168
 
171
- // for node clients, retry connection
172
- if (e.error && e.error.code === 'ECONNREFUSED') {
173
- // we want to log the warning just once
174
- if (!connectionRefusedLogged) {
175
- logger.log('[soundworks.Socket] Connection refused, waiting for the server to start');
176
- // console.log(e.error);
177
- connectionRefusedLogged = true;
178
- }
179
-
180
- // retry in 1 second
181
- setTimeout(trySocket, 1000);
182
- }
169
+ if (e.error) {
170
+ const msg = `[Socket Error] code: ${e.error.code}, message: ${e.error.message}`;
171
+ logger.log(msg);
183
172
  }
173
+
174
+ // Try reconnect in all cases, note that if the socket has been connected the
175
+ // close event will be propagated and the launcher will restart the process.
176
+ setTimeout(trySocket, 1000);
184
177
  });
185
178
  };
186
179
 
@@ -1,2 +1,2 @@
1
1
  // [WARNING] This file is generated, do not edit
2
- export default '4.0.0-alpha.25';
2
+ export default '4.0.0-alpha.26';