node-osc 8.0.11 → 8.1.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/dist/lib/Server.js
CHANGED
|
@@ -5,8 +5,12 @@ var node_events = require('node:events');
|
|
|
5
5
|
var decode = require('./internal/decode.js');
|
|
6
6
|
|
|
7
7
|
class Server extends node_events.EventEmitter {
|
|
8
|
-
constructor(port, host, cb) {
|
|
8
|
+
constructor(port, host='127.0.0.1', cb) {
|
|
9
9
|
super();
|
|
10
|
+
if (typeof host === 'function') {
|
|
11
|
+
cb = host;
|
|
12
|
+
host = '127.0.0.1';
|
|
13
|
+
}
|
|
10
14
|
if (!cb) cb = () => {};
|
|
11
15
|
let decoded;
|
|
12
16
|
this.port = port;
|
|
@@ -15,7 +19,7 @@ class Server extends node_events.EventEmitter {
|
|
|
15
19
|
type: 'udp4',
|
|
16
20
|
reuseAddr: true
|
|
17
21
|
});
|
|
18
|
-
this._sock.bind(port);
|
|
22
|
+
this._sock.bind(port, host);
|
|
19
23
|
this._sock.on('listening', () => {
|
|
20
24
|
this.emit('listening');
|
|
21
25
|
cb();
|
package/dist/test/test-server.js
CHANGED
|
@@ -14,8 +14,32 @@ tap.test('server: create and close', (t) => {
|
|
|
14
14
|
});
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
tap.test('
|
|
18
|
-
const oscServer = new nodeOsc.Server(t.context.port
|
|
17
|
+
tap.test('server: listen to message', (t) => {
|
|
18
|
+
const oscServer = new nodeOsc.Server(t.context.port);
|
|
19
|
+
const client = new nodeOsc.Client('127.0.0.1', t.context.port);
|
|
20
|
+
|
|
21
|
+
t.plan(3);
|
|
22
|
+
|
|
23
|
+
t.teardown(() => {
|
|
24
|
+
oscServer.close();
|
|
25
|
+
client.close();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
oscServer.on('message', (msg) => {
|
|
29
|
+
t.same(msg, ['/test'], 'We should receive expected payload');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
oscServer.on('/test', (msg) => {
|
|
33
|
+
t.same(msg, ['/test'], 'We should receive expected payload');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
client.send('/test', (err) => {
|
|
37
|
+
t.error(err, 'there should be no error');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
tap.test('server: no defined host', (t) => {
|
|
42
|
+
const oscServer = new nodeOsc.Server(t.context.port);
|
|
19
43
|
const client = new nodeOsc.Client('127.0.0.1', t.context.port);
|
|
20
44
|
|
|
21
45
|
t.plan(3);
|
|
@@ -38,6 +62,31 @@ tap.test('client: listen to message', (t) => {
|
|
|
38
62
|
});
|
|
39
63
|
});
|
|
40
64
|
|
|
65
|
+
tap.test('server: callback as second arg', (t) => {
|
|
66
|
+
t.plan(4);
|
|
67
|
+
const oscServer = new nodeOsc.Server(t.context.port, () => {
|
|
68
|
+
t.ok('callback called');
|
|
69
|
+
});
|
|
70
|
+
const client = new nodeOsc.Client('127.0.0.1', t.context.port);
|
|
71
|
+
|
|
72
|
+
t.teardown(() => {
|
|
73
|
+
oscServer.close();
|
|
74
|
+
client.close();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
oscServer.on('message', (msg) => {
|
|
78
|
+
t.same(msg, ['/test'], 'We should receive expected payload');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
oscServer.on('/test', (msg) => {
|
|
82
|
+
t.same(msg, ['/test'], 'We should receive expected payload');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
client.send('/test', (err) => {
|
|
86
|
+
t.error(err, 'there should be no error');
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
41
90
|
tap.test('server: bad message', (t) => {
|
|
42
91
|
t.plan(2);
|
|
43
92
|
const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
|
package/lib/Server.mjs
CHANGED
|
@@ -4,8 +4,12 @@ import { EventEmitter } from 'node:events';
|
|
|
4
4
|
import decode from './internal/decode.mjs';
|
|
5
5
|
|
|
6
6
|
class Server extends EventEmitter {
|
|
7
|
-
constructor(port, host, cb) {
|
|
7
|
+
constructor(port, host='127.0.0.1', cb) {
|
|
8
8
|
super();
|
|
9
|
+
if (typeof host === 'function') {
|
|
10
|
+
cb = host;
|
|
11
|
+
host = '127.0.0.1';
|
|
12
|
+
}
|
|
9
13
|
if (!cb) cb = () => {};
|
|
10
14
|
let decoded;
|
|
11
15
|
this.port = port;
|
|
@@ -14,7 +18,7 @@ class Server extends EventEmitter {
|
|
|
14
18
|
type: 'udp4',
|
|
15
19
|
reuseAddr: true
|
|
16
20
|
});
|
|
17
|
-
this._sock.bind(port);
|
|
21
|
+
this._sock.bind(port, host);
|
|
18
22
|
this._sock.on('listening', () => {
|
|
19
23
|
this.emit('listening');
|
|
20
24
|
cb();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-osc",
|
|
3
3
|
"description": "pyOSC inspired library for sending and receiving OSC messages",
|
|
4
|
-
"version": "8.0
|
|
4
|
+
"version": "8.1.0",
|
|
5
5
|
"exports": {
|
|
6
6
|
"require": "./dist/lib/index.js",
|
|
7
7
|
"default": "./lib/index.mjs"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"osc-min": "^1.1.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"c8": "^
|
|
43
|
+
"c8": "^8.0.1",
|
|
44
44
|
"eslint": "^8.36.0",
|
|
45
45
|
"get-port": "^6.1.2",
|
|
46
46
|
"rollup": "^3.20.1",
|
package/test/test-server.mjs
CHANGED
|
@@ -13,8 +13,32 @@ test('server: create and close', (t) => {
|
|
|
13
13
|
});
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
test('
|
|
17
|
-
const oscServer = new Server(t.context.port
|
|
16
|
+
test('server: listen to message', (t) => {
|
|
17
|
+
const oscServer = new Server(t.context.port);
|
|
18
|
+
const client = new Client('127.0.0.1', t.context.port);
|
|
19
|
+
|
|
20
|
+
t.plan(3);
|
|
21
|
+
|
|
22
|
+
t.teardown(() => {
|
|
23
|
+
oscServer.close();
|
|
24
|
+
client.close();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
oscServer.on('message', (msg) => {
|
|
28
|
+
t.same(msg, ['/test'], 'We should receive expected payload');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
oscServer.on('/test', (msg) => {
|
|
32
|
+
t.same(msg, ['/test'], 'We should receive expected payload');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
client.send('/test', (err) => {
|
|
36
|
+
t.error(err, 'there should be no error');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('server: no defined host', (t) => {
|
|
41
|
+
const oscServer = new Server(t.context.port);
|
|
18
42
|
const client = new Client('127.0.0.1', t.context.port);
|
|
19
43
|
|
|
20
44
|
t.plan(3);
|
|
@@ -37,6 +61,31 @@ test('client: listen to message', (t) => {
|
|
|
37
61
|
});
|
|
38
62
|
});
|
|
39
63
|
|
|
64
|
+
test('server: callback as second arg', (t) => {
|
|
65
|
+
t.plan(4);
|
|
66
|
+
const oscServer = new Server(t.context.port, () => {
|
|
67
|
+
t.ok('callback called');
|
|
68
|
+
});
|
|
69
|
+
const client = new Client('127.0.0.1', t.context.port);
|
|
70
|
+
|
|
71
|
+
t.teardown(() => {
|
|
72
|
+
oscServer.close();
|
|
73
|
+
client.close();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
oscServer.on('message', (msg) => {
|
|
77
|
+
t.same(msg, ['/test'], 'We should receive expected payload');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
oscServer.on('/test', (msg) => {
|
|
81
|
+
t.same(msg, ['/test'], 'We should receive expected payload');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
client.send('/test', (err) => {
|
|
85
|
+
t.error(err, 'there should be no error');
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
40
89
|
test('server: bad message', (t) => {
|
|
41
90
|
t.plan(2);
|
|
42
91
|
const oscServer = new Server(t.context.port, '127.0.0.1');
|