@soundworks/core 3.3.2 → 3.3.3

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.
@@ -258,6 +258,23 @@ const types = {
258
258
  });
259
259
  },
260
260
 
261
+ sanitizeSchema: def => {
262
+ // sanitize `null` values in received schema, this prevent a bug when
263
+ // `min` and `max` are explicitely set to `±Infinity`, the schema is stringified
264
+ // when sent over the network and therefore Infinity is transformed to `null`
265
+ //
266
+ // JSON.parse({ a: Infinity });
267
+ // > { "a": null }
268
+ if (def.min === null) {
269
+ def.min = -Infinity;
270
+ }
271
+
272
+ if (def.max === null) {
273
+ def.max = Infinity;
274
+ }
275
+
276
+ return def;
277
+ },
261
278
  coerceFunction: (name, def, value) => {
262
279
  if (!(typeof value === 'number' && Math.floor(value) === value)) {
263
280
  throw new TypeError(`[stateManager] Invalid value for integer param "${name}": ${value}`);
@@ -276,6 +293,23 @@ const types = {
276
293
  });
277
294
  },
278
295
 
296
+ sanitizeSchema: def => {
297
+ // sanitize `null` values in received schema, this prevent a bug when
298
+ // `min` and `max` are explicitely set to `±Infinity`, the schema is stringified
299
+ // when sent over the network and therefore Infinity is transformed to `null`
300
+ //
301
+ // JSON.parse({ a: Infinity });
302
+ // > { "a": null }
303
+ if (def.min === null) {
304
+ def.min = -Infinity;
305
+ }
306
+
307
+ if (def.max === null) {
308
+ def.max = Infinity;
309
+ }
310
+
311
+ return def;
312
+ },
279
313
  coerceFunction: (name, def, value) => {
280
314
  if (typeof value !== 'number' || value !== value) {
281
315
  // reject NaN
@@ -385,6 +419,11 @@ class ParameterBag {
385
419
  defaultOptions,
386
420
  coerceFunction
387
421
  } = types[def.type];
422
+
423
+ if (types[def.type].sanitizeSchema) {
424
+ def = types[def.type].sanitizeSchema(def);
425
+ }
426
+
388
427
  def = Object.assign({}, defaultOptions, def); // if event property is set to true, the param must
389
428
  // be nullable and its default value is `undefined`
390
429
 
@@ -152,7 +152,7 @@ ${JSON.stringify(initValues, null, 2)}`);
152
152
  immediate,
153
153
  filterChange,
154
154
  event
155
- } = this._parameters.getSchema(name); // @note 20211209 - we have an issue here server-side, because if the value
155
+ } = this._parameters.getSchema(name); // @note 20211209 - we had an issue here server-side, because if the value
156
156
  // is an object or an array, the reference is shared by everybody, therefore
157
157
  // `changed` is always false and the new value is never propagated...
158
158
  // FIXED - `state.get` now returns a deep copy when `type` is `any`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soundworks/core",
3
- "version": "3.3.2",
3
+ "version": "3.3.3",
4
4
  "description": "full-stack javascript framework for distributed audio visual experiences on the web",
5
5
  "authors": [
6
6
  "Benjamin Matuszewski",
@@ -39,7 +39,6 @@
39
39
  "debug": "^4.3.4",
40
40
  "fast-deep-equal": "^3.1.3",
41
41
  "fast-text-encoding": "^1.0.0",
42
- "http-terminator": "^3.2.0",
43
42
  "isomorphic-ws": "^4.0.1",
44
43
  "keyv": "^4.2.2",
45
44
  "keyv-file": "^0.2.0",
@@ -62,7 +61,8 @@
62
61
  "docdash": "^1.2.0",
63
62
  "jsdoc": "^3.6.10",
64
63
  "markdown-toc": "^1.2.0",
65
- "mocha": "^9.2.2"
64
+ "mocha": "^9.2.2",
65
+ "serial-mocha": "^0.0.4"
66
66
  },
67
67
  "optionalDependencies": {
68
68
  "bufferutil": "^4.0.5",
package/server/Server.js CHANGED
@@ -41,8 +41,6 @@ var _keyv = _interopRequireDefault(require("keyv"));
41
41
 
42
42
  var _keyvFile = _interopRequireDefault(require("keyv-file"));
43
43
 
44
- var _httpTerminator = require("http-terminator");
45
-
46
44
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
47
45
 
48
46
  let _dbNamespaces = new Set();
@@ -518,13 +516,13 @@ class Server {
518
516
  } catch (err) {
519
517
  console.error(err);
520
518
  }
521
- }
519
+ } // @todo - handle gracefull close of the server
520
+
522
521
 
523
522
  async stop() {
524
- const httpTerminator = (0, _httpTerminator.createHttpTerminator)({
525
- server: this.httpServer
526
- });
527
- await httpTerminator.terminate();
523
+ this.sockets.terminate();
524
+ this.httpServer.close();
525
+ return Promise.resolve();
528
526
  }
529
527
  /**
530
528
  * Open the route for the given client.
package/server/Sockets.js CHANGED
@@ -81,6 +81,12 @@ class Sockets {
81
81
  }
82
82
  });
83
83
  }
84
+
85
+ terminate() {
86
+ const sockets = this._rooms.get('*');
87
+
88
+ sockets.forEach(socket => socket.terminate());
89
+ }
84
90
  /** @private */
85
91
 
86
92