@ircam/comote-helpers 1.5.5 → 1.6.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 +2 -2
- package/src/server.js +7 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ircam/comote-helpers",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Server component & utilities for the CoMote application",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Benjamin.Matuszewski@ircam.fr",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/ircam-ismm/comote-helpers"
|
|
13
|
+
"url": "git+https://github.com/ircam-ismm/comote-helpers.git"
|
|
14
14
|
},
|
|
15
15
|
"publishConfig": {
|
|
16
16
|
"access": "public"
|
package/src/server.js
CHANGED
|
@@ -4,8 +4,6 @@ import { Server as OscServer } from 'node-osc';
|
|
|
4
4
|
import cloneDeep from 'clone-deep';
|
|
5
5
|
import assignDeep from 'assign-deep';
|
|
6
6
|
|
|
7
|
-
console.log(WebSocket);
|
|
8
|
-
|
|
9
7
|
/**
|
|
10
8
|
* @typedef {Object} CoMoteConfig
|
|
11
9
|
* @property {String} id - id of the client CoMote
|
|
@@ -27,7 +25,7 @@ console.log(WebSocket);
|
|
|
27
25
|
*
|
|
28
26
|
* @param {CoMoteConfig} config - CoMote configuration
|
|
29
27
|
* @param {Object} options - options
|
|
30
|
-
* @param {Object} [options.verbose=false] - logs debug
|
|
28
|
+
* @param {Object} [options.verbose=false] - logs debug information
|
|
31
29
|
*/
|
|
32
30
|
export class Server {
|
|
33
31
|
constructor(config, options) {
|
|
@@ -39,7 +37,6 @@ export class Server {
|
|
|
39
37
|
interval: null,
|
|
40
38
|
osc: null,
|
|
41
39
|
ws: null,
|
|
42
|
-
verbose: false,
|
|
43
40
|
}, config));
|
|
44
41
|
|
|
45
42
|
this._verbose = !!options.verbose;
|
|
@@ -61,7 +58,7 @@ export class Server {
|
|
|
61
58
|
let oscPromise = true;
|
|
62
59
|
|
|
63
60
|
if (this.config.ws !== null) {
|
|
64
|
-
const {
|
|
61
|
+
const { port } = this.config.ws;
|
|
65
62
|
|
|
66
63
|
if (!Number.isInteger(port)) {
|
|
67
64
|
throw new Error(`Invalid port "${port}" for WebSocket server`);
|
|
@@ -72,8 +69,7 @@ export class Server {
|
|
|
72
69
|
}
|
|
73
70
|
|
|
74
71
|
this._websocketServer = new WebSocketServer({ port });
|
|
75
|
-
this._websocketServer.on('connection', (socket,
|
|
76
|
-
// const ip = request.socket.remoteAddress;
|
|
72
|
+
this._websocketServer.on('connection', (socket, _request) => {
|
|
77
73
|
socket.on('message', (data, isBinary) => {
|
|
78
74
|
if (isBinary) {
|
|
79
75
|
// @todo
|
|
@@ -85,15 +81,13 @@ export class Server {
|
|
|
85
81
|
console.log(`> CoMote: new WebSocket message`, data);
|
|
86
82
|
}
|
|
87
83
|
|
|
88
|
-
// console.log(data);
|
|
89
|
-
// console.log(this._wsListeners.size);
|
|
90
84
|
this._wsListeners.forEach(listener => listener(data));
|
|
91
85
|
}
|
|
92
86
|
}
|
|
93
87
|
});
|
|
94
88
|
|
|
95
89
|
// When a socket closes, or disconnects, remove it from the array.
|
|
96
|
-
socket.on('close', (
|
|
90
|
+
socket.on('close', (_code, _data) => {
|
|
97
91
|
if (this._verbose) {
|
|
98
92
|
console.log('> CoMote: closed socket connection');
|
|
99
93
|
}
|
|
@@ -117,7 +111,7 @@ export class Server {
|
|
|
117
111
|
}
|
|
118
112
|
|
|
119
113
|
if (this.config.osc !== null) {
|
|
120
|
-
|
|
114
|
+
let { hostname, port } = this.config.osc;
|
|
121
115
|
|
|
122
116
|
if (!Number.isInteger(port)) {
|
|
123
117
|
throw new Error(`Invalid port "${port}" for OSC server`);
|
|
@@ -173,7 +167,7 @@ export class Server {
|
|
|
173
167
|
}
|
|
174
168
|
|
|
175
169
|
/**
|
|
176
|
-
* Add a listener for
|
|
170
|
+
* Add a listener for incoming WebSocket message
|
|
177
171
|
*/
|
|
178
172
|
addWsListener(callback) {
|
|
179
173
|
this._wsListeners.add(callback);
|
|
@@ -189,7 +183,7 @@ export class Server {
|
|
|
189
183
|
}
|
|
190
184
|
|
|
191
185
|
/**
|
|
192
|
-
* Add a listener for
|
|
186
|
+
* Add a listener for incoming OSC message
|
|
193
187
|
*/
|
|
194
188
|
addOscListener(callback) {
|
|
195
189
|
this._oscListeners.add(callback);
|