@soundworks/core 3.1.0-beta.6 → 3.2.1
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 +8 -3
- package/client.js +28 -0
- package/package.json +14 -14
- package/server/Server.js +18 -6
- package/server.js +28 -0
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
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "full-stack javascript framework for distributed audio visual experiences on the web",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Benjamin Matuszewski",
|
|
@@ -33,34 +33,34 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"chalk": "^4.1.2",
|
|
36
|
-
"columnify": "^1.
|
|
36
|
+
"columnify": "^1.6.0",
|
|
37
37
|
"compression": "^1.7.1",
|
|
38
|
-
"debug": "^4.
|
|
38
|
+
"debug": "^4.3.4",
|
|
39
39
|
"fast-deep-equal": "^3.1.3",
|
|
40
40
|
"fast-text-encoding": "^1.0.0",
|
|
41
41
|
"isomorphic-ws": "^4.0.1",
|
|
42
|
-
"keyv": "^4.
|
|
42
|
+
"keyv": "^4.2.2",
|
|
43
43
|
"keyv-file": "^0.2.0",
|
|
44
44
|
"lodash.clonedeep": "^4.5.0",
|
|
45
45
|
"lodash.merge": "^4.6.2",
|
|
46
|
-
"pem": "^1.
|
|
46
|
+
"pem": "^1.14.6",
|
|
47
47
|
"polka": "^0.5.2",
|
|
48
|
-
"serve-static": "^1.
|
|
48
|
+
"serve-static": "^1.15.0",
|
|
49
49
|
"uuid": "^8.3.2",
|
|
50
50
|
"window-or-global": "^1.0.1",
|
|
51
|
-
"ws": "^8.
|
|
51
|
+
"ws": "^8.5.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@babel/cli": "^7.
|
|
55
|
-
"@babel/core": "^7.
|
|
56
|
-
"@babel/preset-env": "^7.
|
|
57
|
-
"chai": "^4.
|
|
58
|
-
"chokidar": "^3.
|
|
54
|
+
"@babel/cli": "^7.17.6",
|
|
55
|
+
"@babel/core": "^7.17.9",
|
|
56
|
+
"@babel/preset-env": "^7.16.11",
|
|
57
|
+
"chai": "^4.3.6",
|
|
58
|
+
"chokidar": "^3.5.3",
|
|
59
59
|
"chokidar-cli": "^3.0.0",
|
|
60
60
|
"docdash": "^1.2.0",
|
|
61
|
-
"jsdoc": "^3.6.
|
|
61
|
+
"jsdoc": "^3.6.10",
|
|
62
62
|
"markdown-toc": "^1.2.0",
|
|
63
|
-
"mocha": "^9.
|
|
63
|
+
"mocha": "^9.2.2"
|
|
64
64
|
},
|
|
65
65
|
"optionalDependencies": {
|
|
66
66
|
"bufferutil": "^4.0.5",
|
package/server/Server.js
CHANGED
|
@@ -237,7 +237,8 @@ class Server {
|
|
|
237
237
|
path: 'socket',
|
|
238
238
|
pingInterval: 5000
|
|
239
239
|
},
|
|
240
|
-
useHttps: false
|
|
240
|
+
useHttps: false,
|
|
241
|
+
crossOriginIsolated: true
|
|
241
242
|
},
|
|
242
243
|
app: {
|
|
243
244
|
name: 'soundworks'
|
|
@@ -309,6 +310,8 @@ class Server {
|
|
|
309
310
|
// ------------------------------------------------------------
|
|
310
311
|
// init acitvities
|
|
311
312
|
// ------------------------------------------------------------
|
|
313
|
+
// we should at least have one activity registered for each client here
|
|
314
|
+
// i.e. the Experience so it's ok
|
|
312
315
|
this.activities.forEach(activity => {
|
|
313
316
|
activity.clientTypes.forEach(clientType => {
|
|
314
317
|
if (!this._clientTypeActivitiesMap[clientType]) {
|
|
@@ -544,14 +547,18 @@ class Server {
|
|
|
544
547
|
data.env.subpath = this.config.env.subpath;
|
|
545
548
|
} // cors / coop / coep headers for `crossOriginIsolated pages, enables
|
|
546
549
|
// sharedArrayBuffers and high precision timers
|
|
550
|
+
// this is the default behavior
|
|
547
551
|
// cf. https://web.dev/why-coop-coep/
|
|
548
552
|
|
|
549
553
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
554
|
+
if (this.config.env.crossOriginIsolated) {
|
|
555
|
+
res.writeHead(200, {
|
|
556
|
+
'Cross-Origin-Resource-Policy': 'same-origin',
|
|
557
|
+
'Cross-Origin-Embedder-Policy': 'require-corp',
|
|
558
|
+
'Cross-Origin-Opener-Policy': 'same-origin'
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
|
|
555
562
|
const appIndex = tmpl(data);
|
|
556
563
|
res.end(appIndex);
|
|
557
564
|
}); // return route infos for logging on server start
|
|
@@ -567,6 +574,11 @@ class Server {
|
|
|
567
574
|
_onSocketConnection(clientType, socket) {
|
|
568
575
|
const client = new _Client.default(clientType, socket);
|
|
569
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
|
+
|
|
570
582
|
socket.addListener('close', () => {
|
|
571
583
|
// clean sockets
|
|
572
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;
|