@soundworks/core 3.2.2 → 3.3.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soundworks/core",
3
- "version": "3.2.2",
3
+ "version": "3.3.0",
4
4
  "description": "full-stack javascript framework for distributed audio visual experiences on the web",
5
5
  "authors": [
6
6
  "Benjamin Matuszewski",
@@ -29,7 +29,8 @@
29
29
  "dev:client": "chokidar src/client/ -c \"npm run build:client\"",
30
30
  "dev:server": "chokidar src/server/ -c \"npm run build:server\"",
31
31
  "dev:common": "chokidar src/common/ -c \"npm run build:common\"",
32
- "dev": "npm run build && (npm run dev:client & npm run dev:server & npm run dev:common)"
32
+ "dev": "npm run build && (npm run dev:client & npm run dev:server & npm run dev:common)",
33
+ "test": "mocha"
33
34
  },
34
35
  "dependencies": {
35
36
  "chalk": "^4.1.2",
@@ -38,6 +39,7 @@
38
39
  "debug": "^4.3.4",
39
40
  "fast-deep-equal": "^3.1.3",
40
41
  "fast-text-encoding": "^1.0.0",
42
+ "http-terminator": "^3.2.0",
41
43
  "isomorphic-ws": "^4.0.1",
42
44
  "keyv": "^4.2.2",
43
45
  "keyv-file": "^0.2.0",
@@ -20,7 +20,7 @@ const log = (0, _debug.default)('soundworks:lifecycle');
20
20
  */
21
21
 
22
22
  class AbstractExperience {
23
- constructor(server, clientTypes = null) {
23
+ constructor(server, clientTypes = []) {
24
24
  // @todo - check that it's a soundworks instance
25
25
  if (!server) {
26
26
  throw new Error(`${this.constructor.name} should receive the "Server" instance as first argument`);
package/server/Server.js CHANGED
@@ -41,6 +41,8 @@ var _keyv = _interopRequireDefault(require("keyv"));
41
41
 
42
42
  var _keyvFile = _interopRequireDefault(require("keyv-file"));
43
43
 
44
+ var _httpTerminator = require("http-terminator");
45
+
44
46
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
45
47
 
46
48
  let _dbNamespaces = new Set();
@@ -426,7 +428,9 @@ class Server {
426
428
 
427
429
  for (let clientType in this._clientTypeActivitiesMap) {
428
430
  if (clientType !== defaultClientType) {
429
- const path = this._openClientRoute(clientType, this.router);
431
+ const clientTarget = this.config.app.clients[clientType].target;
432
+
433
+ const path = this._openClientRoute(clientType, target, this.router);
430
434
 
431
435
  routes.push({
432
436
  clientType,
@@ -438,7 +442,9 @@ class Server {
438
442
 
439
443
  for (let clientType in this._clientTypeActivitiesMap) {
440
444
  if (clientType === defaultClientType) {
441
- const path = this._openClientRoute(clientType, this.router, true);
445
+ const clientTarget = this.config.app.clients[clientType].target;
446
+
447
+ const path = this._openClientRoute(clientType, target, this.router, true);
442
448
 
443
449
  routes.unshift({
444
450
  clientType,
@@ -492,18 +498,31 @@ class Server {
492
498
  console.error(err);
493
499
  }
494
500
  }
501
+
502
+ async stop() {
503
+ const httpTerminator = (0, _httpTerminator.createHttpTerminator)({
504
+ server: this.httpServer
505
+ });
506
+ await httpTerminator.terminate();
507
+ }
495
508
  /**
496
509
  * Open the route for the given client.
497
510
  * @private
498
511
  */
499
512
 
500
513
 
501
- _openClientRoute(clientType, router, isDefault = false) {
514
+ _openClientRoute(clientType, target, router, isDefault = false) {
515
+ // only browser targets need a route
516
+ if (target === 'node') {
517
+ return;
518
+ }
519
+
502
520
  let route = '/';
503
521
 
504
522
  if (!isDefault) {
505
523
  route += `${clientType}`;
506
- }
524
+ } // @todo - define what is this... looks completely not used and not usable...
525
+
507
526
 
508
527
  if (this._routes[clientType]) {
509
528
  route += this._routes[clientType];