node-osc 9.0.1 → 9.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.
@@ -33,12 +33,12 @@ jobs:
33
33
  # run that runs on: tag. (Using the GitHub token would
34
34
  # not run the workflow to prevent infinite recursion.)
35
35
  - name: Check out source
36
- uses: actions/checkout@v3
36
+ uses: actions/checkout@v4
37
37
  with:
38
38
  ssh-key: ${{ secrets.DEPLOY_KEY }}
39
39
 
40
40
  - name: Setup Node.js
41
- uses: actions/setup-node@v3
41
+ uses: actions/setup-node@v4
42
42
  with:
43
43
  node-version: 20
44
44
  cache: 'npm'
@@ -13,9 +13,9 @@ jobs:
13
13
  id-token: write
14
14
  steps:
15
15
  - name: Checkout source
16
- uses: actions/checkout@v3
16
+ uses: actions/checkout@v4
17
17
  - name: Setup node
18
- uses: actions/setup-node@v3
18
+ uses: actions/setup-node@v4
19
19
  with:
20
20
  node-version: 20
21
21
  registry-url: 'https://registry.npmjs.org'
@@ -37,7 +37,7 @@ jobs:
37
37
  contents: write
38
38
  steps:
39
39
  - name: Checkout code
40
- uses: actions/checkout@v3
40
+ uses: actions/checkout@v4
41
41
  - name: Create Release
42
42
  run: gh release create ${{ github.ref }} --generate-notes
43
43
  env:
@@ -11,16 +11,16 @@ jobs:
11
11
  run-tests:
12
12
  strategy:
13
13
  matrix:
14
- node-version: ['20', '18']
14
+ node-version: ['21', '20', '18']
15
15
  os: [ubuntu-latest, macos-latest, windows-latest]
16
16
 
17
17
  runs-on: ${{ matrix.os }}
18
18
 
19
19
  steps:
20
- - uses: actions/checkout@v3
20
+ - uses: actions/checkout@v4
21
21
 
22
22
  - name: Use Node.js ${{ matrix.node-version }}
23
- uses: actions/setup-node@v3
23
+ uses: actions/setup-node@v4
24
24
  with:
25
25
  node-version: ${{ matrix.node-version }}
26
26
  cache: 'npm'
@@ -1,5 +1,12 @@
1
1
  'use strict';
2
2
 
3
+ const typeTags = {
4
+ s: 'string',
5
+ f: 'float',
6
+ i: 'integer',
7
+ b: 'blob'
8
+ };
9
+
3
10
  class Argument {
4
11
  constructor(type, value) {
5
12
  this.type = type;
@@ -21,6 +28,7 @@ class Message {
21
28
  if (arg instanceof Array) {
22
29
  arg.forEach(a => this.append(a));
23
30
  } else if (arg.type) {
31
+ if (typeTags[arg.type]) arg.type = typeTags[arg.type];
24
32
  this.args.push(arg);
25
33
  } else {
26
34
  throw new Error(`don't know how to encode object ${arg}`);
@@ -2,7 +2,7 @@
2
2
 
3
3
  var node_dgram = require('node:dgram');
4
4
  var node_events = require('node:events');
5
- var decode = require('./internal/decode.js');
5
+ var decode = require('#decode');
6
6
 
7
7
  class Server extends node_events.EventEmitter {
8
8
  constructor(port, host='127.0.0.1', cb) {
@@ -27,6 +27,9 @@ function decode(data) {
27
27
  else if (decoded.oscType === 'message') {
28
28
  return sanitizeMessage(decoded);
29
29
  }
30
+ else {
31
+ throw new Error ('Malformed Packet');
32
+ }
30
33
  }
31
34
 
32
35
  module.exports = decode;
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var tap = require('tap');
4
- var decode = require('../lib/internal/decode.js');
4
+ var decode = require('#decode');
5
5
 
6
6
  tap.test('decode: valid', (t) => {
7
7
  const buf = Buffer.from('/test\0\0\0,s\0,testing\0');
@@ -15,6 +15,14 @@ tap.test('decode: valid', (t) => {
15
15
  t.end();
16
16
  });
17
17
 
18
+ tap.test('decode: malformed packet', (t) => {
19
+ t.throws(() => {
20
+ const buf = Buffer.from('/test\0\0');
21
+ decode(buf);
22
+ }, /Malformed Packet/);
23
+ t.end();
24
+ });
25
+
18
26
  tap.test('decode: invalid typetags', (t) => {
19
27
  t.throws(() => {
20
28
  const buf = Buffer.from('/test\0\0\0,R\0');
@@ -4,6 +4,10 @@ var tap = require('tap');
4
4
  var util = require('./util.js');
5
5
  var nodeOsc = require('node-osc');
6
6
 
7
+ function round(num) {
8
+ return Math.round(num * 100) / 100;
9
+ }
10
+
7
11
  tap.beforeEach(util.bootstrap);
8
12
 
9
13
  tap.test('message: basic usage', (t) => {
@@ -80,7 +84,40 @@ tap.test('message: float', (t) => {
80
84
  3.14
81
85
  ];
82
86
  t.equal(msg[0], expected[0], `We reveived the payload: ${msg}`);
83
- t.equal(msg[1][0], expected[1][0], 'pie please');
87
+ t.equal(round(msg[1]), expected[1], 'pie please');
88
+ oscServer.close();
89
+ t.end();
90
+ });
91
+
92
+ client.send(m, () => {
93
+ client.close();
94
+ });
95
+ });
96
+
97
+ tap.test('message: alias messages', (t) => {
98
+ const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
99
+ const client = new nodeOsc.Client('127.0.0.1', t.context.port);
100
+ const m = new nodeOsc.Message('/address');
101
+ m.append({
102
+ type: 'i',
103
+ value: 123
104
+ });
105
+ m.append({
106
+ type: 'f',
107
+ value: 3.14
108
+ });
109
+
110
+ oscServer.on('message', (msg) => {
111
+ const expected = [
112
+ '/address',
113
+ 123,
114
+ 3.14
115
+ ];
116
+ t.equal(msg[0], expected[0], `We reveived the payload: ${msg}`);
117
+ t.equal(msg[1], expected[1], 'easy as abc');
118
+ t.ok(Number.isInteger(msg[1]), 'the first value is an int');
119
+ t.equal(round(msg[2]), expected[2], 'pie please');
120
+ t.ok(msg[2] % 1 !== 0, 'the second value is a float');
84
121
  oscServer.close();
85
122
  t.end();
86
123
  });
@@ -139,7 +176,7 @@ tap.test('message: blob', (t) => {
139
176
  // test('message: timetag', (t) => {
140
177
  // const oscServer = new osc.Server(3333, '127.0.0.1');
141
178
  // const client = new osc.Client('127.0.0.1', 3333);
142
- // const m = new osc.Message('/address');z
179
+ // const m = new osc.Message('/address');
143
180
  //
144
181
  // oscServer.on('message', (msg) => {
145
182
  // const expected = [
package/lib/Message.mjs CHANGED
@@ -1,3 +1,10 @@
1
+ const typeTags = {
2
+ s: 'string',
3
+ f: 'float',
4
+ i: 'integer',
5
+ b: 'blob'
6
+ };
7
+
1
8
  class Argument {
2
9
  constructor(type, value) {
3
10
  this.type = type;
@@ -19,6 +26,7 @@ class Message {
19
26
  if (arg instanceof Array) {
20
27
  arg.forEach(a => this.append(a));
21
28
  } else if (arg.type) {
29
+ if (typeTags[arg.type]) arg.type = typeTags[arg.type];
22
30
  this.args.push(arg);
23
31
  } else {
24
32
  throw new Error(`don't know how to encode object ${arg}`);
package/lib/Server.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createSocket } from 'node:dgram';
2
2
  import { EventEmitter } from 'node:events';
3
3
 
4
- import decode from './internal/decode.mjs';
4
+ import decode from '#decode';
5
5
 
6
6
  class Server extends EventEmitter {
7
7
  constructor(port, host='127.0.0.1', cb) {
@@ -25,6 +25,9 @@ function decode(data) {
25
25
  else if (decoded.oscType === 'message') {
26
26
  return sanitizeMessage(decoded);
27
27
  }
28
+ else {
29
+ throw new Error ('Malformed Packet');
30
+ }
28
31
  }
29
32
 
30
33
  export default decode;
package/package.json CHANGED
@@ -1,11 +1,17 @@
1
1
  {
2
2
  "name": "node-osc",
3
3
  "description": "pyOSC inspired library for sending and receiving OSC messages",
4
- "version": "9.0.1",
4
+ "version": "9.1.0",
5
5
  "exports": {
6
6
  "require": "./dist/lib/index.js",
7
7
  "default": "./lib/index.mjs"
8
8
  },
9
+ "imports": {
10
+ "#decode": {
11
+ "require": "./dist/lib/internal/decode.js",
12
+ "default": "./lib/internal/decode.mjs"
13
+ }
14
+ },
9
15
  "author": {
10
16
  "name": "Myles Borins",
11
17
  "email": "myles.borins@gmail.com"
@@ -18,9 +24,9 @@
18
24
  "clean": "rm -rf dist/",
19
25
  "build": "npm run clean && rollup --config rollup.config.mjs",
20
26
  "prepublishOnly": "npm run build",
21
- "lint": "eslint \"lib/**/*.mjs\" test/* examples/*",
27
+ "lint": "eslint \"lib/**/*.mjs\" test/* examples/* rollup.config.mjs",
22
28
  "test": "npm run lint && npm run build && npm run test:esm && npm run test:cjs",
23
- "test:esm": "tap -j1 test/test-*.mjs",
29
+ "test:esm": "tap -j1 test/test-*.mjs",
24
30
  "test:cjs": "tap -j1 dist/test/test-*.js"
25
31
  },
26
32
  "contributors": [
@@ -42,7 +48,7 @@
42
48
  "devDependencies": {
43
49
  "eslint": "^8.36.0",
44
50
  "get-port": "^6.1.2",
45
- "rollup": "^3.20.1",
51
+ "rollup": "^4.9.5",
46
52
  "tap": "^18.4.2"
47
53
  }
48
54
  }
package/rollup.config.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { readdirSync as readdir, statSync as stat } from 'fs';
2
+ import { join } from 'path';
2
3
 
3
4
  // Borrowed from the rollup docs
4
5
  // https://github.com/rollup/rollup/blob/d0db53459be43c5cc806cb91f14e82217950ba42/docs/05-plugin-development.md#renderdynamicimport
@@ -30,8 +31,8 @@ function walk(root, result=[]) {
30
31
  }
31
32
  else {
32
33
  result.push({
33
- input: `${root}${path}`,
34
- dir: `dist/${root}`
34
+ input: join(root, path),
35
+ dir: join('dist/', root)
35
36
  });
36
37
  }
37
38
  }
@@ -54,7 +55,8 @@ function walkLib(config) {
54
55
  'node:dgram',
55
56
  'node:events',
56
57
  'osc-min',
57
- 'jspack'
58
+ 'jspack',
59
+ '#decode'
58
60
  ]
59
61
  });
60
62
  });
@@ -78,9 +80,10 @@ function walkTest(config) {
78
80
  'get-port',
79
81
  'node-osc',
80
82
  'osc-min',
81
- 'tap'
83
+ 'tap',
84
+ '#decode'
82
85
  ]
83
- })
86
+ });
84
87
  });
85
88
  }
86
89
 
@@ -1,6 +1,6 @@
1
1
  import { test } from 'tap';
2
2
 
3
- import decode from '../lib/internal/decode.mjs';
3
+ import decode from '#decode';
4
4
 
5
5
  test('decode: valid', (t) => {
6
6
  const buf = Buffer.from('/test\0\0\0,s\0,testing\0');
@@ -14,6 +14,14 @@ test('decode: valid', (t) => {
14
14
  t.end();
15
15
  });
16
16
 
17
+ test('decode: malformed packet', (t) => {
18
+ t.throws(() => {
19
+ const buf = Buffer.from('/test\0\0');
20
+ decode(buf);
21
+ }, /Malformed Packet/);
22
+ t.end();
23
+ });
24
+
17
25
  test('decode: invalid typetags', (t) => {
18
26
  t.throws(() => {
19
27
  const buf = Buffer.from('/test\0\0\0,R\0');
@@ -3,6 +3,10 @@ import { bootstrap } from './util.mjs';
3
3
 
4
4
  import { Server, Client, Message } from 'node-osc';
5
5
 
6
+ function round(num) {
7
+ return Math.round(num * 100) / 100;
8
+ }
9
+
6
10
  beforeEach(bootstrap);
7
11
 
8
12
  test('message: basic usage', (t) => {
@@ -79,7 +83,40 @@ test('message: float', (t) => {
79
83
  3.14
80
84
  ];
81
85
  t.equal(msg[0], expected[0], `We reveived the payload: ${msg}`);
82
- t.equal(msg[1][0], expected[1][0], 'pie please');
86
+ t.equal(round(msg[1]), expected[1], 'pie please');
87
+ oscServer.close();
88
+ t.end();
89
+ });
90
+
91
+ client.send(m, () => {
92
+ client.close();
93
+ });
94
+ });
95
+
96
+ test('message: alias messages', (t) => {
97
+ const oscServer = new Server(t.context.port, '127.0.0.1');
98
+ const client = new Client('127.0.0.1', t.context.port);
99
+ const m = new Message('/address');
100
+ m.append({
101
+ type: 'i',
102
+ value: 123
103
+ });
104
+ m.append({
105
+ type: 'f',
106
+ value: 3.14
107
+ });
108
+
109
+ oscServer.on('message', (msg) => {
110
+ const expected = [
111
+ '/address',
112
+ 123,
113
+ 3.14
114
+ ];
115
+ t.equal(msg[0], expected[0], `We reveived the payload: ${msg}`);
116
+ t.equal(msg[1], expected[1], 'easy as abc');
117
+ t.ok(Number.isInteger(msg[1]), 'the first value is an int');
118
+ t.equal(round(msg[2]), expected[2], 'pie please');
119
+ t.ok(msg[2] % 1 !== 0, 'the second value is a float');
83
120
  oscServer.close();
84
121
  t.end();
85
122
  });
@@ -138,7 +175,7 @@ test('message: blob', (t) => {
138
175
  // test('message: timetag', (t) => {
139
176
  // const oscServer = new osc.Server(3333, '127.0.0.1');
140
177
  // const client = new osc.Client('127.0.0.1', 3333);
141
- // const m = new osc.Message('/address');z
178
+ // const m = new osc.Message('/address');
142
179
  //
143
180
  // oscServer.on('message', (msg) => {
144
181
  // const expected = [
@@ -1,51 +0,0 @@
1
- # For most projects, this workflow file will not need changing; you simply need
2
- # to commit it to your repository.
3
- #
4
- # You may wish to alter this file to override the set of languages analyzed,
5
- # or to provide custom queries or build logic.
6
- #
7
- # ******** NOTE ********
8
- # We have attempted to detect the languages in your repository. Please check
9
- # the `language` matrix defined below to confirm you have the correct set of
10
- # supported CodeQL languages.
11
- #
12
- name: "CodeQL"
13
-
14
- on:
15
- push:
16
- branches: [ main ]
17
- pull_request:
18
- # The branches below must be a subset of the branches above
19
- branches: [ main ]
20
- schedule:
21
- - cron: '44 5 * * 1'
22
-
23
- jobs:
24
- analyze:
25
- name: Analyze
26
- runs-on: ubuntu-latest
27
- permissions:
28
- actions: read
29
- contents: read
30
- security-events: write
31
-
32
- strategy:
33
- fail-fast: false
34
- matrix:
35
- language: [ 'javascript' ]
36
-
37
- steps:
38
- - name: Checkout repository
39
- uses: actions/checkout@v2
40
-
41
- # Initializes the CodeQL tools for scanning.
42
- - name: Initialize CodeQL
43
- uses: github/codeql-action/init@v1
44
- with:
45
- languages: ${{ matrix.language }}
46
- # If you wish to specify custom queries, you can do so here or in a config file.
47
- # By default, queries listed here will override any specified in a config file.
48
- # Prefix the list here with "+" to use these queries and those in the config file.
49
- # queries: ./path/to/local/query, your-org/your-repo/queries@main
50
- - name: Perform CodeQL Analysis
51
- uses: github/codeql-action/analyze@v1
@@ -1,32 +0,0 @@
1
- 'use strict';
2
-
3
- var oscMin = require('osc-min');
4
-
5
- function sanitizeMessage(decoded) {
6
- const message = [];
7
- message.push(decoded.address);
8
- decoded.args.forEach(arg => {
9
- message.push(arg.value);
10
- });
11
- return message;
12
- }
13
-
14
- function sanitizeBundle(decoded) {
15
- decoded.elements = decoded.elements.map(element => {
16
- if (element.oscType === 'bundle') return sanitizeBundle(element);
17
- else if (element.oscType === 'message') return sanitizeMessage(element);
18
- });
19
- return decoded;
20
- }
21
-
22
- function decode(data) {
23
- const decoded = oscMin.fromBuffer(data);
24
- if (decoded.oscType === 'bundle') {
25
- return sanitizeBundle(decoded);
26
- }
27
- else if (decoded.oscType === 'message') {
28
- return sanitizeMessage(decoded);
29
- }
30
- }
31
-
32
- module.exports = decode;