node-osc 8.0.12 → 9.0.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.
@@ -40,7 +40,7 @@ jobs:
40
40
  - name: Setup Node.js
41
41
  uses: actions/setup-node@v3
42
42
  with:
43
- node-version: 18
43
+ node-version: 20
44
44
  cache: 'npm'
45
45
 
46
46
  - name: Install npm packages
@@ -50,6 +50,8 @@ jobs:
50
50
  run: |
51
51
  git config user.name 'Myles Borins'
52
52
  git config user.email 'myles.borins@gmail.com'
53
+ git config gpg.format ssh
54
+ git config user.signingKey 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFtQmrz647zOGumjiqGirj1G9brj/QbwJQ5S3gHRmcfl myles.borins@gmail.com'
53
55
 
54
56
  - name: bump version
55
57
  run: npm version ${{ github.event.inputs.version }}
@@ -17,7 +17,7 @@ jobs:
17
17
  - name: Setup node
18
18
  uses: actions/setup-node@v3
19
19
  with:
20
- node-version: 18
20
+ node-version: 20
21
21
  registry-url: 'https://registry.npmjs.org'
22
22
  cache: npm
23
23
  - name: Install latest npm version
@@ -11,7 +11,7 @@ jobs:
11
11
  run-tests:
12
12
  strategy:
13
13
  matrix:
14
- node-version: ['20', '18', '16', '14']
14
+ node-version: ['20', '18']
15
15
  os: [ubuntu-latest, macos-latest, windows-latest]
16
16
 
17
17
  runs-on: ${{ matrix.os }}
@@ -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();
@@ -14,8 +14,32 @@ tap.test('server: create and close', (t) => {
14
14
  });
15
15
  });
16
16
 
17
- tap.test('client: listen to message', (t) => {
18
- const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
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.12",
4
+ "version": "9.0.0",
5
5
  "exports": {
6
6
  "require": "./dist/lib/index.js",
7
7
  "default": "./lib/index.mjs"
@@ -11,7 +11,7 @@
11
11
  "email": "myles.borins@gmail.com"
12
12
  },
13
13
  "engines": {
14
- "node": "^14.18 || ^16.13 || >=18"
14
+ "node": "^18.17.0 || >=20.5.0"
15
15
  },
16
16
  "license": "LGPL-3.0-or-later",
17
17
  "scripts": {
@@ -20,8 +20,8 @@
20
20
  "prepublishOnly": "npm run build",
21
21
  "lint": "eslint \"lib/**/*.mjs\" test/* examples/*",
22
22
  "test": "npm run lint && npm run build && npm run test:esm && npm run test:cjs",
23
- "test:esm": "c8 tap --no-coverage -j1 test/test-*.mjs",
24
- "test:cjs": "tap --no-coverage -j1 dist/test/test-*.js"
23
+ "test:esm": "tap -j1 test/test-*.mjs",
24
+ "test:cjs": "tap -j1 dist/test/test-*.js"
25
25
  },
26
26
  "contributors": [
27
27
  "Hans Hübner <hans.huebner@gmail.com>",
@@ -40,10 +40,9 @@
40
40
  "osc-min": "^1.1.1"
41
41
  },
42
42
  "devDependencies": {
43
- "c8": "^8.0.0",
44
43
  "eslint": "^8.36.0",
45
44
  "get-port": "^6.1.2",
46
45
  "rollup": "^3.20.1",
47
- "tap": "^16.3.0"
46
+ "tap": "^18.4.2"
48
47
  }
49
48
  }
@@ -13,8 +13,32 @@ test('server: create and close', (t) => {
13
13
  });
14
14
  });
15
15
 
16
- test('client: listen to message', (t) => {
17
- const oscServer = new Server(t.context.port, '127.0.0.1');
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');