@soundworks/core 3.1.0 → 3.2.2

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/client/Socket.js CHANGED
@@ -91,6 +91,7 @@ class Socket {
91
91
  }
92
92
 
93
93
  let url;
94
+ let webSocketOptions;
94
95
 
95
96
  if (isBrowser()) {
96
97
  const protocol = window.location.protocol.replace(/^http?/, 'ws');
@@ -99,13 +100,17 @@ class Socket {
99
100
  port
100
101
  } = window.location;
101
102
  url = `${protocol}//${hostname}:${port}/${path}`;
103
+ webSocketOptions = [];
102
104
  } else {
103
- const protocol = config.useHttps ? 'wss:' : 'ws:';
105
+ const protocol = config.env.useHttps ? 'wss:' : 'ws:';
104
106
  const {
105
107
  serverIp,
106
108
  port
107
109
  } = config.env;
108
110
  url = `${protocol}//${serverIp}:${port}/${path}`;
111
+ webSocketOptions = {
112
+ rejectUnauthorized: false
113
+ };
109
114
  }
110
115
 
111
116
  const queryParams = `clientType=${clientType}&key=${key}`; // ----------------------------------------------------------
@@ -116,7 +121,7 @@ class Socket {
116
121
  await new Promise((resolve, reject) => {
117
122
  const trySocket = async () => {
118
123
  log(`[string socket] trying connection - url: ${stringSocketUrl}`);
119
- const ws = new _isomorphicWs.default(stringSocketUrl);
124
+ const ws = new _isomorphicWs.default(stringSocketUrl, webSocketOptions);
120
125
  ws.addEventListener('open', connectEvent => {
121
126
  // parse incoming messages for pubsub
122
127
  this.ws = ws;
@@ -154,7 +159,7 @@ class Socket {
154
159
  const binarySocketUrl = `${url}?binary=1&${queryParams}`;
155
160
  await new Promise((resolve, reject) => {
156
161
  log(`[binary socket] trying connection - url: ${binarySocketUrl}`);
157
- const ws = new _isomorphicWs.default(binarySocketUrl);
162
+ const ws = new _isomorphicWs.default(binarySocketUrl, webSocketOptions);
158
163
  ws.binaryType = 'arraybuffer';
159
164
  ws.addEventListener('open', connectEvent => {
160
165
  // parse incoming messages for pubsub
package/client.js ADDED
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * This is a dirty shortcut to enable cleaner import in template using `type=module`
5
+ * This should be cleaned little by little...
6
+ *
7
+ * We need to define if we can be backward compatible there if we go to full module (probably not)
8
+ */
9
+ Object.defineProperty(exports, "__esModule", {
10
+ value: true
11
+ });
12
+ exports.default = exports.Client = exports.AbstractExperience = void 0;
13
+
14
+ var _AbstractExperience2 = _interopRequireDefault(require("./client/AbstractExperience.js"));
15
+
16
+ var _Client2 = _interopRequireDefault(require("./client/Client.js"));
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ const AbstractExperience = _AbstractExperience2.default;
21
+ exports.AbstractExperience = AbstractExperience;
22
+ const Client = _Client2.default;
23
+ exports.Client = Client;
24
+ var _default = {
25
+ AbstractExperience: _AbstractExperience2.default,
26
+ Client: _Client2.default
27
+ };
28
+ exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soundworks/core",
3
- "version": "3.1.0",
3
+ "version": "3.2.2",
4
4
  "description": "full-stack javascript framework for distributed audio visual experiences on the web",
5
5
  "authors": [
6
6
  "Benjamin Matuszewski",
package/server/Server.js CHANGED
@@ -310,6 +310,8 @@ class Server {
310
310
  // ------------------------------------------------------------
311
311
  // init acitvities
312
312
  // ------------------------------------------------------------
313
+ // we should at least have one activity registered for each client here
314
+ // i.e. the Experience so it's ok
313
315
  this.activities.forEach(activity => {
314
316
  activity.clientTypes.forEach(clientType => {
315
317
  if (!this._clientTypeActivitiesMap[clientType]) {
@@ -572,6 +574,11 @@ class Server {
572
574
  _onSocketConnection(clientType, socket) {
573
575
  const client = new _Client.default(clientType, socket);
574
576
  const activities = this._clientTypeActivitiesMap[clientType];
577
+
578
+ if (activities == undefined) {
579
+ throw new Error(`No activity registered for "${clientType}" clients, make sure an Experience has been initialized for this client (see src/server/index.js)`);
580
+ }
581
+
575
582
  socket.addListener('close', () => {
576
583
  // clean sockets
577
584
  socket.terminate(); // remove client from activities
package/server.js ADDED
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * This is a dirty shortcut to enable cleaner import in template using `type=module`
5
+ * This should be cleaned little by little...
6
+ *
7
+ * We need to define if we can be backward compatible there if we go to full module (probably not)
8
+ */
9
+ Object.defineProperty(exports, "__esModule", {
10
+ value: true
11
+ });
12
+ exports.default = exports.Server = exports.AbstractExperience = void 0;
13
+
14
+ var _Server2 = _interopRequireDefault(require("./server/Server.js"));
15
+
16
+ var _AbstractExperience2 = _interopRequireDefault(require("./server/AbstractExperience.js"));
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ const AbstractExperience = _AbstractExperience2.default;
21
+ exports.AbstractExperience = AbstractExperience;
22
+ const Server = _Server2.default;
23
+ exports.Server = Server;
24
+ var _default = {
25
+ AbstractExperience: _AbstractExperience2.default,
26
+ Server: _Server2.default
27
+ };
28
+ exports.default = _default;