mirror of
https://github.com/jwetzell/osc-js.git
synced 2026-08-04 23:07:50 +00:00
Compare commits
230 Commits
osc/v1.0.0
...
osc/v1.7.0
| Author | SHA1 | Date | |
|---|---|---|---|
| c4e0204def | |||
| 42f72a7052 | |||
| 51513c0232 | |||
| 21fb66ecbd | |||
| 82bd867472 | |||
| b2283fb26b | |||
| 8897bbaff7 | |||
| a10da39d9e | |||
| ac340270d6 | |||
| b263e9ce94 | |||
| aefd7cab79 | |||
| 1f8886d2d2 | |||
| 24199c5e94 | |||
| 36a7f69b15 | |||
| 70914894b8 | |||
| e20fe4822a | |||
| c2005265fc | |||
| 68592b10da | |||
| b14e891538 | |||
| 5450d9f06e | |||
| c7ddc209f8 | |||
| 3cba8e5e49 | |||
| 559021a3a3 | |||
| 3250d3c1e9 | |||
| b173e85e0b | |||
| deed189cd5 | |||
| 10cf6ccf54 | |||
| 3d2d61e8b0 | |||
| 487885e9d6 | |||
| 3e5155013b | |||
| 663733734d | |||
| b62684820e | |||
| 95823b783a | |||
| 14a0c1b950 | |||
| 4ca4023113 | |||
| af9c49e513 | |||
| eee79283d5 | |||
| 2ceb6305ca | |||
| b1e74c9eae | |||
| ea13f91f98 | |||
| d6883ffae3 | |||
| eef9f591c3 | |||
| 254059bd26 | |||
| 4ca6698a9c | |||
| ffb794ee55 | |||
| a57e1b7c5b | |||
| 9a31a6f549 | |||
| 6f3b73b78f | |||
| 9df94a5e4e | |||
| c5477c3031 | |||
| e3dc5864d0 | |||
| 7dca187c23 | |||
| e0278161f0 | |||
| 839aad568e | |||
| f7f536db97 | |||
| 235b80d56c | |||
| 79ca1eac83 | |||
| 6629021f00 | |||
| 01d5c1e3c4 | |||
| 342ff8fd39 | |||
| ee95b0d966 | |||
| 36b30fcd2e | |||
| 4a501e99a7 | |||
| f3a25f1805 | |||
| f40a18b8bc | |||
| ea6580d1cb | |||
| 564b7fcd98 | |||
| b4d0dbf75b | |||
| be133a3e99 | |||
| 1e4355dc92 | |||
| d9e7a33cc7 | |||
| 48f04f4807 | |||
| 217763a0cc | |||
| b0f81832d0 | |||
| 35b53de373 | |||
| 15ec815fbf | |||
| 953d73c764 | |||
| 4a4693f365 | |||
| b4b4f017ca | |||
| 57656c41f3 | |||
| 463261a50a | |||
| d924725364 | |||
| af9ed05e24 | |||
| b55b90177c | |||
| da5be03a3b | |||
| caba62a67a | |||
| 5b5a55de48 | |||
| 4c479e77e0 | |||
| f88eae6768 | |||
| ef90d236c8 | |||
| 9b45003444 | |||
| abe1058116 | |||
| 4e068340cb | |||
| d3b237794c | |||
| 3f41288335 | |||
| 856d3dd49c | |||
| b839a15bc6 | |||
| 06612ac643 | |||
| e38dc7bf1d | |||
| 04d06a8a68 | |||
| 5859e9f35b | |||
| f8a97b80c6 | |||
| 992fa51618 | |||
| 736eec9c89 | |||
| a31a4ecbb6 | |||
| a383c8d665 | |||
| 2ed6acf8cd | |||
| 61baa2a3bb | |||
| c574a6b7f3 | |||
| a724cc821d | |||
| 62d553cc32 | |||
| e20f7c7f4e | |||
| 8c62cda110 | |||
| 83c0358f1a | |||
| 0b9774387d | |||
| b571eaa907 | |||
| b0060a8124 | |||
| ffe3f8040c | |||
| 6a4f4a90f5 | |||
| 1bd6fe30bd | |||
| f16ef0c985 | |||
| de4155d8ac | |||
| 252e00dc9b | |||
| 99f6cbb10b | |||
| d7d3d5a134 | |||
| 17b5306940 | |||
| 0ce94c0fe0 | |||
| bbfc919c92 | |||
| d01a6c3d38 | |||
| 0703ae8c33 | |||
| 20fcd14780 | |||
| 1622ce9af4 | |||
| 1f4d75fb90 | |||
| edaeb79097 | |||
| 623acf0bbe | |||
| 8160fb7869 | |||
| 35fc92bb44 | |||
| 390cf9c6cf | |||
| 9f3d42e2a1 | |||
| 04801b47d3 | |||
| f0bb93385d | |||
| 4fec2d472d | |||
| 5443a11998 | |||
| d6d4e026c5 | |||
| f7a505c775 | |||
| 1d7de95ce3 | |||
| 78b88e6be4 | |||
| a754739766 | |||
| d00084ad5a | |||
| d17f3d565e | |||
| 3bd88220eb | |||
| f3f0b97b3e | |||
| 31f24cada5 | |||
| d795a01c7d | |||
| 63c1577f4e | |||
| af6bfafa00 | |||
| 9c6eccebd6 | |||
| 7064611260 | |||
| 550fcb8f05 | |||
| 5b529ab64b | |||
| feaf60bb25 | |||
| 8bb05d7efb | |||
| 3829d8f7a1 | |||
| 42c4560f25 | |||
| da9044ccbd | |||
| 2706ce1b41 | |||
| 308be01246 | |||
| a995cf9cc9 | |||
| 2453189b50 | |||
| a46c3539d6 | |||
| cc14c4c886 | |||
| a4b29de9c9 | |||
| 86f062a2ce | |||
| b7d129556a | |||
| 2ee515ae5b | |||
| 2089893a25 | |||
| 2377599f12 | |||
| f18327d7b1 | |||
| ad4efcf43d | |||
| 1b10930a8e | |||
| 0c9fafc129 | |||
| aa1cae428b | |||
| 5449c8ec5b | |||
| bf355706bb | |||
| 31e0cb7d23 | |||
| af6dd46303 | |||
| 2ea1b928ba | |||
| 7bffb53691 | |||
| abc9445b2c | |||
| 69a3eeec9f | |||
| 99ae9d8a3b | |||
| b3dc125df3 | |||
| 713fdc8959 | |||
| 1a9decfa30 | |||
| 374bf0d39f | |||
| 1f214396ae | |||
| 925ff2a409 | |||
| 5a5a6ab0a5 | |||
| 512b2d63c0 | |||
| e592229815 | |||
| 768d6d5a4b | |||
| 119574743d | |||
| 709312585f | |||
| fdaa8b8ed1 | |||
| 91fdf60737 | |||
| e5d559eb1a | |||
| 1c68227aac | |||
| f32b8ce679 | |||
| 0df2dec5e9 | |||
| d587b0cf19 | |||
| eca0639b38 | |||
| 7601cfb096 | |||
| f9f763d6c4 | |||
| 786e71fd82 | |||
| a2adc3d2f4 | |||
| 4ec6bae5fe | |||
| f75b663812 | |||
| 7a72853e41 | |||
| 81e0a542c5 | |||
| 278d09bb6f | |||
| 4b56f09a64 | |||
| b44e5d306a | |||
| 7a3ad57482 | |||
| 13a8334504 | |||
| e0bae3b386 | |||
| 2716ccc349 | |||
| acc93189a9 | |||
| 180c9ff76a | |||
| 25fe42415e | |||
| fd6949c897 |
@@ -1,12 +0,0 @@
|
||||
module.exports = {
|
||||
env: {
|
||||
node: true,
|
||||
commonjs: true,
|
||||
es2021: true,
|
||||
},
|
||||
extends: ['airbnb', 'prettier'],
|
||||
parserOptions: {
|
||||
ecmaVersion: 'latest',
|
||||
},
|
||||
ignorePatterns: ['**/node_modules', '**/dist'],
|
||||
};
|
||||
@@ -4,3 +4,15 @@ updates:
|
||||
directory: '/'
|
||||
schedule:
|
||||
interval: 'weekly'
|
||||
- package-ecosystem: 'npm'
|
||||
directory: 'apps/makeosc'
|
||||
schedule:
|
||||
interval: 'weekly'
|
||||
- package-ecosystem: 'npm'
|
||||
directory: 'apps/readosc'
|
||||
schedule:
|
||||
interval: 'weekly'
|
||||
- package-ecosystem: 'npm'
|
||||
directory: 'apps/sendosc'
|
||||
schedule:
|
||||
interval: 'weekly'
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
name: Check makeosc builds
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'apps/makeosc/**'
|
||||
jobs:
|
||||
build-webui:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
|
||||
with:
|
||||
node-version-file: '.nvmrc'
|
||||
cache: 'npm'
|
||||
cache-dependency-path: 'package-lock.json'
|
||||
|
||||
- name: Install Node.js dependencies
|
||||
run: npm ci --workspace makeosc
|
||||
|
||||
- run: npm run build --workspace makeosc
|
||||
@@ -1,25 +0,0 @@
|
||||
name: Check readosc builds
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'apps/readosc/**'
|
||||
jobs:
|
||||
build-webui:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
|
||||
with:
|
||||
node-version-file: '.nvmrc'
|
||||
cache: 'npm'
|
||||
cache-dependency-path: 'package-lock.json'
|
||||
|
||||
- name: Install Node.js dependencies
|
||||
run: npm ci --workspace readosc
|
||||
|
||||
- run: npm run build --workspace readosc
|
||||
@@ -1,25 +0,0 @@
|
||||
name: Check sendosc builds
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'apps/sendosc/**'
|
||||
jobs:
|
||||
build-webui:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
|
||||
with:
|
||||
node-version-file: '.nvmrc'
|
||||
cache: 'npm'
|
||||
cache-dependency-path: 'package-lock.json'
|
||||
|
||||
- name: Install Node.js dependencies
|
||||
run: npm ci --workspace sendosc
|
||||
|
||||
- run: npm run build --workspace sendosc
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Joel Wetzell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -20,8 +20,8 @@
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jwetzell/osc": "0.2.2",
|
||||
"commander": "^11.0.0",
|
||||
"@jwetzell/osc": "1.6.0",
|
||||
"commander": "^14.0.0",
|
||||
"slip": "^1.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
const { Option, program } = require('commander');
|
||||
const slip = require('slip');
|
||||
const { argToTypedArg } = require('./utils');
|
||||
const osc = require('@jwetzell/osc');
|
||||
const { argToTypedArg } = require('./utils');
|
||||
const packageInfo = require('../package.json');
|
||||
|
||||
program.name(packageInfo.name);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "readosc",
|
||||
"version": "0.1.0",
|
||||
"version": "0.2.0",
|
||||
"description": "Simple NodeJS utility for parsing osc buffers from stdin",
|
||||
"main": "src/main.js",
|
||||
"bin": {
|
||||
@@ -20,7 +20,8 @@
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jwetzell/osc": "0.2.2",
|
||||
"commander": "^11.0.0"
|
||||
"@jwetzell/osc": "1.6.0",
|
||||
"commander": "^14.0.0",
|
||||
"slip": "1.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,46 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const { program } = require('commander');
|
||||
const { program, Option } = require('commander');
|
||||
const osc = require('@jwetzell/osc');
|
||||
const packageInfo = require('../package.json');
|
||||
const slip = require('slip');
|
||||
|
||||
program.name(packageInfo.name);
|
||||
program.version(packageInfo.version);
|
||||
program.description('simple util to read osc packets from stdin');
|
||||
program.action(() => {
|
||||
program.addOption(new Option('--slip', 'slip encode message').default(false));
|
||||
program.action((options) => {
|
||||
const slipDecoder = new slip.Decoder({
|
||||
onMessage: (msg) =>{
|
||||
const [message, bytesAfterMessage] = osc.messageFromBuffer(msg);
|
||||
printOSCMessage(message)
|
||||
},
|
||||
maxMessageSize: 209715200,
|
||||
bufferSize: 2048
|
||||
});
|
||||
process.stdin.on('data', (data) => {
|
||||
try {
|
||||
const message = osc.messageFromBuffer(data);
|
||||
console.log(JSON.stringify(message));
|
||||
if (options.slip){
|
||||
slipDecoder.decode(data)
|
||||
} else {
|
||||
let remainingBytes = data;
|
||||
while (remainingBytes.length > 0) {
|
||||
try {
|
||||
const [message, bytesAfterMessage] = osc.messageFromBuffer(remainingBytes);
|
||||
remainingBytes = bytesAfterMessage;
|
||||
printOSCMessage(message)
|
||||
} catch (error) {
|
||||
console.error({ error: error.toString() });
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error({ error: error.toString() });
|
||||
}
|
||||
});
|
||||
});
|
||||
program.parse();
|
||||
|
||||
function printOSCMessage(oscMessage) {
|
||||
console.log(JSON.stringify(oscMessage));
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jwetzell/osc": "0.2.2",
|
||||
"commander": "^11.0.0",
|
||||
"@jwetzell/osc": "1.6.0",
|
||||
"commander": "^14.0.0",
|
||||
"slip": "^1.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import globals from 'globals';
|
||||
import pluginJs from '@eslint/js';
|
||||
import tseslint from 'typescript-eslint';
|
||||
import eslintPluginPrettier from 'eslint-plugin-prettier/recommended';
|
||||
|
||||
/** @type {import('eslint').Linter.Config[]} */
|
||||
export default [
|
||||
{ ignores: ['apps/**/*', '**/*.test.js','eslint.config.mjs','**/dist/**/*'] },
|
||||
{ languageOptions: { globals: { ...globals.browser, ...globals.node } } },
|
||||
pluginJs.configs.recommended,
|
||||
...tseslint.configs.recommended,
|
||||
eslintPluginPrettier,
|
||||
];
|
||||
Generated
+870
-2262
File diff suppressed because it is too large
Load Diff
+7
-4
@@ -21,9 +21,12 @@
|
||||
"packages/*"
|
||||
],
|
||||
"devDependencies": {
|
||||
"prettier": "3.3.3",
|
||||
"eslint": "^8.48.0",
|
||||
"eslint-config-airbnb": "^19.0.4",
|
||||
"eslint-config-prettier": "^9.0.0"
|
||||
"@eslint/js": "^9.35.0",
|
||||
"eslint": "^9.18.0",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-plugin-prettier": "^5.5.4",
|
||||
"globals": "^16.3.0",
|
||||
"prettier": "3.6.2",
|
||||
"typescript-eslint": "^8.42.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,23 @@
|
||||
{
|
||||
"name": "@jwetzell/osc",
|
||||
"version": "1.0.0",
|
||||
"version": "1.7.0",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"main": "./dist/cjs/index.js",
|
||||
"module": "./dist/esm/index.js",
|
||||
"types": "./dist/types/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/esm/index.js",
|
||||
"require": "./dist/cjs/index.js",
|
||||
"types": "./dist/types/index.d.ts"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"prebuild": "rimraf dist",
|
||||
"build": "tsc",
|
||||
"build": "npm run build:cjs && npm run build:esm && npm run build:types",
|
||||
"build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
|
||||
"build:esm": "tsc -p tsconfig.esm.json && echo '{\"type\": \"module\"}' > dist/esm/package.json",
|
||||
"build:types": "tsc -p tsconfig.types.json",
|
||||
"prepublishOnly": "npm run build",
|
||||
"pretest": "npm run build",
|
||||
"test": "node --test --experimental-test-coverage"
|
||||
@@ -25,8 +36,8 @@
|
||||
},
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "22.7.4",
|
||||
"@types/node": "24.3.1",
|
||||
"rimraf": "6.0.1",
|
||||
"typescript": "5.6.2"
|
||||
"typescript": "5.9.2"
|
||||
}
|
||||
}
|
||||
|
||||
+46
-36
@@ -1,9 +1,9 @@
|
||||
import { messageFromBuffer, messageToBuffer } from './message';
|
||||
import { OSCBundle } from './models';
|
||||
import { oscTypeConverterMap } from './osc-types';
|
||||
import { messageFromBuffer, messageToBuffer } from './message.js';
|
||||
import { OSCBundle } from './models.js';
|
||||
import { oscTypeConverterMap } from './osc-types.js';
|
||||
|
||||
export function bundleFromBuffer(bytes: Uint8Array): [OSCBundle | undefined, Uint8Array | undefined] {
|
||||
if (bytes.length < 8) {
|
||||
if (bytes.length < 20) {
|
||||
throw new Error('bundle has to be at least 20 bytes');
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ export function bundleFromBuffer(bytes: Uint8Array): [OSCBundle | undefined, Uin
|
||||
}
|
||||
|
||||
const [bundleHeader, bytesAfterHeader] = oscTypeConverterMap.s.fromBuffer(bytes);
|
||||
let [timeTag, bytesAfterTimeTag] = oscTypeConverterMap.t.fromBuffer(bytesAfterHeader);
|
||||
const [timeTag, bytesAfterTimeTag] = oscTypeConverterMap.t.fromBuffer(bytesAfterHeader);
|
||||
|
||||
if (!Array.isArray(timeTag)) {
|
||||
throw new Error('problem getting bundle time tag');
|
||||
@@ -22,42 +22,52 @@ export function bundleFromBuffer(bytes: Uint8Array): [OSCBundle | undefined, Uin
|
||||
|
||||
let endOfBundle = false;
|
||||
|
||||
let [contentSize, remainingBytes] = oscTypeConverterMap.i.fromBuffer(bytesAfterTimeTag);
|
||||
if (typeof contentSize === 'number') {
|
||||
while (!endOfBundle) {
|
||||
if (remainingBytes.length < contentSize) {
|
||||
throw new Error('bundle does not contain enough data');
|
||||
}
|
||||
// let [contentSize, remainingBytes] = oscTypeConverterMap.i.fromBuffer(bytesAfterTimeTag);
|
||||
let remainingBytes = bytesAfterTimeTag;
|
||||
|
||||
const bundleContentBytes = remainingBytes.subarray(0, contentSize);
|
||||
while (!endOfBundle) {
|
||||
const [contentSize, bytesAfterContentSize] = oscTypeConverterMap.i.fromBuffer(remainingBytes);
|
||||
|
||||
if (bundleContentBytes[0] === 35) {
|
||||
// # character indicating contents is a bundle
|
||||
const [content, bytesAfterContent] = bundleFromBuffer(bundleContentBytes);
|
||||
if (content) {
|
||||
bundleContents.push(content);
|
||||
}
|
||||
} else if (bundleContentBytes[0] === 47) {
|
||||
const [content, bytesAfterContent] = messageFromBuffer(bundleContentBytes);
|
||||
if (content && content !== undefined) {
|
||||
bundleContents.push(content);
|
||||
}
|
||||
} else {
|
||||
throw new Error('bundle contents does not look like a OSC message or bundle');
|
||||
}
|
||||
|
||||
remainingBytes = remainingBytes.subarray(contentSize);
|
||||
if (remainingBytes.length === 0) {
|
||||
endOfBundle = true;
|
||||
}
|
||||
if (typeof contentSize !== 'number') {
|
||||
throw new Error('problem decoding content size');
|
||||
}
|
||||
|
||||
remainingBytes = bytesAfterContentSize;
|
||||
|
||||
if (remainingBytes.length < contentSize) {
|
||||
throw new Error('bundle does not contain enough data');
|
||||
}
|
||||
|
||||
const bundleContentBytes = bytesAfterContentSize.subarray(0, contentSize);
|
||||
|
||||
if (bundleContentBytes[0] === 35) {
|
||||
// # character indicating contents is a bundle
|
||||
const [content, bytesAfterContent] = bundleFromBuffer(bundleContentBytes);
|
||||
if (content) {
|
||||
bundleContents.push(content);
|
||||
}
|
||||
} else if (bundleContentBytes[0] === 47) {
|
||||
const [content, bytesAfterContent] = messageFromBuffer(bundleContentBytes);
|
||||
if (content && content !== undefined) {
|
||||
bundleContents.push(content);
|
||||
}
|
||||
} else {
|
||||
throw new Error('bundle contents does not look like a OSC message or bundle');
|
||||
}
|
||||
|
||||
remainingBytes = bytesAfterContentSize.subarray(contentSize);
|
||||
if (remainingBytes.length === 0) {
|
||||
endOfBundle = true;
|
||||
}
|
||||
return [{
|
||||
timeTag,
|
||||
contents: bundleContents,
|
||||
},remainingBytes];
|
||||
}
|
||||
|
||||
return [undefined, undefined]
|
||||
return [
|
||||
{
|
||||
timeTag,
|
||||
contents: bundleContents,
|
||||
},
|
||||
remainingBytes,
|
||||
];
|
||||
}
|
||||
|
||||
export function bundleToBuffer(bundle: OSCBundle): Uint8Array {
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
export * from './models';
|
||||
export * from './message';
|
||||
export * from './bundle';
|
||||
import { bundleFromBuffer } from './bundle.js';
|
||||
import { messageFromBuffer } from './message.js';
|
||||
import { OSCBundle, OSCMessage } from './models.js';
|
||||
|
||||
export * from './models.js';
|
||||
export * from './message.js';
|
||||
export * from './bundle.js';
|
||||
|
||||
export function fromBuffer(bytes: Uint8Array): [OSCBundle | OSCMessage | undefined, Uint8Array | undefined] {
|
||||
if (bytes[0] === 47) {
|
||||
// starts with '/'
|
||||
return messageFromBuffer(bytes);
|
||||
} else if (bytes[0] === 35) {
|
||||
// starts with '#'
|
||||
return bundleFromBuffer(bytes);
|
||||
} else {
|
||||
throw new Error('bytes do not look like an OSC message or bundle');
|
||||
}
|
||||
}
|
||||
|
||||
+73
-13
@@ -1,5 +1,5 @@
|
||||
import { OSCMessage, OSCArg, OSCType } from './models';
|
||||
import { oscTypeConverterMap } from './osc-types';
|
||||
import { OSCMessage, OSCArg, OSCType } from './models.js';
|
||||
import { oscTypeConverterMap } from './osc-types.js';
|
||||
|
||||
function argsToBuffer(args: OSCArg[]) {
|
||||
const argBuffers: Uint8Array[] = [];
|
||||
@@ -28,17 +28,38 @@ function argsToBuffer(args: OSCArg[]) {
|
||||
}
|
||||
|
||||
export function messageToBuffer(message: OSCMessage): Uint8Array {
|
||||
if (!message.address.startsWith('/')) {
|
||||
throw new Error('osc message must start with a /');
|
||||
}
|
||||
|
||||
const addressBuffer = oscTypeConverterMap.s.toBuffer(message.address);
|
||||
if (addressBuffer === undefined) {
|
||||
throw new Error('problem encoding address');
|
||||
}
|
||||
|
||||
const typeString = message.args.map((arg) => arg.type).join('');
|
||||
const typesBuffer = oscTypeConverterMap.s.toBuffer(`,${typeString}`);
|
||||
let typeString = ',';
|
||||
|
||||
const flatOSCArgs: OSCArg[] = [];
|
||||
|
||||
message.args.forEach((oscArg) => {
|
||||
if (Array.isArray(oscArg)) {
|
||||
typeString += '[';
|
||||
oscArg.forEach((oscArg) => {
|
||||
typeString += oscArg.type;
|
||||
flatOSCArgs.push(oscArg);
|
||||
});
|
||||
typeString += ']';
|
||||
} else {
|
||||
typeString += oscArg.type;
|
||||
flatOSCArgs.push(oscArg);
|
||||
}
|
||||
});
|
||||
|
||||
const typesBuffer = oscTypeConverterMap.s.toBuffer(typeString);
|
||||
if (typesBuffer === undefined) {
|
||||
throw new Error('problem encoding types');
|
||||
}
|
||||
const argsBuffer = argsToBuffer(message.args);
|
||||
const argsBuffer = argsToBuffer(flatOSCArgs);
|
||||
const buffer = new Uint8Array(addressBuffer.length + typesBuffer.length + argsBuffer.length);
|
||||
buffer.set(addressBuffer, 0);
|
||||
buffer.set(typesBuffer, addressBuffer.length);
|
||||
@@ -51,19 +72,51 @@ export function messageFromBuffer(bytes: Uint8Array): [OSCMessage | undefined, U
|
||||
throw new Error('osc message must start with a /');
|
||||
}
|
||||
|
||||
const oscArgs: OSCArg[] = [];
|
||||
const oscArgs: (OSCArg | OSCArg[])[] = [];
|
||||
|
||||
const [address, bytesAfterAddress] = oscTypeConverterMap.s.fromBuffer(bytes);
|
||||
if (typeof address === 'string') {
|
||||
let [typeString, bytesAfterType] = oscTypeConverterMap.s.fromBuffer(bytesAfterAddress);
|
||||
if (bytesAfterAddress.length === 0) {
|
||||
// NOTE(jwetzell): OSC 1.0 spec says that messages without a type string should be allowed
|
||||
return [
|
||||
{
|
||||
address,
|
||||
args: [],
|
||||
},
|
||||
bytesAfterAddress,
|
||||
];
|
||||
}
|
||||
|
||||
const [typeString, bytesAfterType] = oscTypeConverterMap.s.fromBuffer(bytesAfterAddress);
|
||||
if (typeof typeString === 'string') {
|
||||
if (!typeString.startsWith(',')) {
|
||||
throw new Error('osc type string must start with a ,');
|
||||
}
|
||||
let argsBuffer = bytesAfterType;
|
||||
let oscArrayArg: OSCArg[] = [];
|
||||
let insideArgArray = false;
|
||||
for (let index = 1; index < typeString.length; index++) {
|
||||
const argType = typeString.charAt(index) as OSCType;
|
||||
|
||||
if (argType === '[') {
|
||||
if (insideArgArray) {
|
||||
throw new Error('osc arg array opened without closing previous arg array');
|
||||
}
|
||||
oscArrayArg = [];
|
||||
insideArgArray = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (argType === ']') {
|
||||
if (!insideArgArray) {
|
||||
throw new Error('osc arg array closed without opening arg array');
|
||||
}
|
||||
oscArgs.push(oscArrayArg);
|
||||
oscArrayArg = [];
|
||||
insideArgArray = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
const oscTypeConverter = oscTypeConverterMap[argType];
|
||||
if (oscTypeConverter === undefined) {
|
||||
throw new Error('unknown OSC type');
|
||||
@@ -74,15 +127,22 @@ export function messageFromBuffer(bytes: Uint8Array): [OSCMessage | undefined, U
|
||||
type: argType,
|
||||
value: value,
|
||||
};
|
||||
oscArgs.push(arg);
|
||||
if (insideArgArray) {
|
||||
oscArrayArg.push(arg);
|
||||
} else {
|
||||
oscArgs.push(arg);
|
||||
}
|
||||
}
|
||||
argsBuffer = remainingBytes;
|
||||
}
|
||||
return [{
|
||||
address,
|
||||
args: oscArgs,
|
||||
}, argsBuffer];
|
||||
return [
|
||||
{
|
||||
address,
|
||||
args: oscArgs,
|
||||
},
|
||||
argsBuffer,
|
||||
];
|
||||
}
|
||||
}
|
||||
return [undefined, undefined]
|
||||
return [undefined, undefined];
|
||||
}
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
export type OSCType = 's' | 'i' | 'f' | 'b' | 'T' | 'F' | 't';
|
||||
export type OSCType = 's' | 'i' | 'f' | 'b' | 'T' | 'F' | 't' | 'r' | 'N' | '[' | ']';
|
||||
export type OSCArg = {
|
||||
type: OSCType;
|
||||
value: string | number | Uint8Array | boolean | OSCTimeTag;
|
||||
value: string | number | Uint8Array | boolean | OSCTimeTag | OSCColor | bigint | null;
|
||||
};
|
||||
|
||||
export type OSCTimeTag = [number, number];
|
||||
|
||||
export type OSCColor = {
|
||||
r: number;
|
||||
g: number;
|
||||
b: number;
|
||||
a: number;
|
||||
};
|
||||
|
||||
export type OSCBundle = {
|
||||
timeTag: OSCTimeTag;
|
||||
contents: (OSCBundle | OSCMessage)[];
|
||||
@@ -13,10 +20,14 @@ export type OSCBundle = {
|
||||
|
||||
export type OSCMessage = {
|
||||
address: string;
|
||||
args: OSCArg[];
|
||||
args: (OSCArg | OSCArg[])[];
|
||||
};
|
||||
|
||||
export type OSCTypeConverter = {
|
||||
toBuffer: (value: string | number | Uint8Array | boolean | OSCTimeTag) => Uint8Array | undefined;
|
||||
fromBuffer: (buffer: Uint8Array) => [string | number | Uint8Array | boolean | OSCTimeTag | undefined, Uint8Array];
|
||||
toBuffer: (
|
||||
value: string | number | Uint8Array | boolean | OSCTimeTag | OSCColor | null | bigint
|
||||
) => Uint8Array | undefined;
|
||||
fromBuffer: (
|
||||
buffer: Uint8Array
|
||||
) => [string | number | Uint8Array | boolean | OSCTimeTag | OSCColor | null | bigint | undefined, Uint8Array];
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { OSCTypeConverter, OSCTimeTag } from './models';
|
||||
import { OSCTypeConverter, OSCTimeTag } from './models.js';
|
||||
|
||||
export const oscTypeConverterMap: { [key: string]: OSCTypeConverter } = {
|
||||
s: {
|
||||
@@ -160,7 +160,7 @@ export const oscTypeConverterMap: { [key: string]: OSCTypeConverter } = {
|
||||
},
|
||||
fromBuffer: (buffer) => {
|
||||
if (buffer.length < 8) {
|
||||
throw new Error('osc time tag must be greater than 8 bytes');
|
||||
throw new Error('osc time tag must be at least 8 bytes');
|
||||
}
|
||||
const [seconds, bytesAfterSeconds] = oscTypeConverterMap.i.fromBuffer(buffer);
|
||||
const [fractional, bytesAfterFractional] = oscTypeConverterMap.i.fromBuffer(bytesAfterSeconds);
|
||||
@@ -171,4 +171,118 @@ export const oscTypeConverterMap: { [key: string]: OSCTypeConverter } = {
|
||||
return [undefined, bytesAfterFractional];
|
||||
},
|
||||
},
|
||||
r: {
|
||||
toBuffer: (color) => {
|
||||
if (color === undefined || color === null) {
|
||||
throw new TypeError('osc type r called with undefined or null value');
|
||||
}
|
||||
|
||||
if (typeof color === 'object' && 'r' in color && 'g' in color && 'b' in color && 'a' in color) {
|
||||
const view = new DataView(new ArrayBuffer(4));
|
||||
|
||||
view.setUint8(0, color.r);
|
||||
view.setUint8(1, color.g);
|
||||
view.setUint8(2, color.b);
|
||||
view.setUint8(3, color.a);
|
||||
|
||||
return new Uint8Array(view.buffer);
|
||||
}
|
||||
throw new TypeError('osc type r called with non OSCColor object');
|
||||
},
|
||||
fromBuffer: (buffer) => {
|
||||
if (buffer.length < 4) {
|
||||
throw new Error('osc color must be at least 4 bytes');
|
||||
}
|
||||
|
||||
const red = buffer[0];
|
||||
const green = buffer[1];
|
||||
const blue = buffer[2];
|
||||
const alpha = buffer[3];
|
||||
|
||||
if (red !== undefined && green !== undefined && blue !== undefined && alpha !== undefined) {
|
||||
if (
|
||||
typeof red === 'number' &&
|
||||
typeof green === 'number' &&
|
||||
typeof blue === 'number' &&
|
||||
typeof alpha === 'number'
|
||||
) {
|
||||
return [
|
||||
{
|
||||
r: red,
|
||||
g: green,
|
||||
b: blue,
|
||||
a: alpha,
|
||||
},
|
||||
buffer.subarray(4),
|
||||
];
|
||||
}
|
||||
}
|
||||
throw new Error('problem converting osc ');
|
||||
},
|
||||
},
|
||||
N: {
|
||||
toBuffer: () => {
|
||||
return new Uint8Array(0);
|
||||
},
|
||||
fromBuffer: (buffer) => {
|
||||
return [null, buffer];
|
||||
},
|
||||
},
|
||||
I: {
|
||||
toBuffer: () => {
|
||||
return new Uint8Array();
|
||||
},
|
||||
fromBuffer: (buffer) => {
|
||||
return [Number.MAX_SAFE_INTEGER, buffer];
|
||||
},
|
||||
},
|
||||
h: {
|
||||
toBuffer: (number) => {
|
||||
const view = new DataView(new ArrayBuffer(8));
|
||||
|
||||
if (typeof number === 'number') {
|
||||
view.setBigInt64(0, BigInt(number));
|
||||
} else if (typeof number === 'bigint') {
|
||||
view.setBigInt64(0, number);
|
||||
} else {
|
||||
throw new TypeError('osc type h toBuffer called with non number or bigint value');
|
||||
}
|
||||
return new Uint8Array(view.buffer);
|
||||
},
|
||||
fromBuffer: (buffer) => {
|
||||
if (buffer.length < 8) {
|
||||
throw new Error('osc int64 must be at least 8 bytes');
|
||||
}
|
||||
|
||||
const view = new DataView(new ArrayBuffer(8));
|
||||
buffer.subarray(0, 8).forEach((byte, index) => {
|
||||
view.setUint8(index, byte);
|
||||
});
|
||||
|
||||
return [view.getBigInt64(0), buffer.subarray(8)];
|
||||
},
|
||||
},
|
||||
d: {
|
||||
toBuffer: (number) => {
|
||||
if (typeof number === 'number') {
|
||||
const view = new DataView(new ArrayBuffer(8));
|
||||
view.setFloat64(0, number);
|
||||
return new Uint8Array(view.buffer);
|
||||
}
|
||||
throw new TypeError('osc type d toBuffer called with non number value');
|
||||
},
|
||||
fromBuffer: (buffer) => {
|
||||
if (buffer.length < 8) {
|
||||
throw new Error('not enough bytes to read a osc float');
|
||||
}
|
||||
const view = new DataView(new ArrayBuffer(8));
|
||||
|
||||
buffer.subarray(0, 8).forEach((byte, index) => {
|
||||
view.setUint8(index, byte);
|
||||
});
|
||||
|
||||
const value = view.getFloat64(0);
|
||||
return [value, buffer.subarray(8)];
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const { deepEqual, equal } = require('assert');
|
||||
const { deepEqual, equal, throws } = require('assert');
|
||||
const { describe, it } = require('node:test');
|
||||
const osc = require('../dist/index');
|
||||
const osc = require('../dist/cjs/index');
|
||||
|
||||
const tests = [
|
||||
const goodTests = [
|
||||
{
|
||||
description: 'simple contents single message',
|
||||
bytes: new Uint8Array([
|
||||
@@ -20,14 +20,181 @@ const tests = [
|
||||
contents: [{ address: '/oscillator/4/frequency', args: [{ type: 'f', value: 440 }] }],
|
||||
},
|
||||
},
|
||||
{
|
||||
description: 'simple contents single bundle',
|
||||
bytes: new Uint8Array([
|
||||
...new TextEncoder().encode('#bundle'),
|
||||
...new Uint8Array([0x00]),
|
||||
...new Uint8Array([0, 0, 0, 32, 0, 0, 0, 0]),
|
||||
...new Uint8Array([0x00, 0x00, 0x00, 0x34]),
|
||||
...new Uint8Array([
|
||||
...new TextEncoder().encode('#bundle'),
|
||||
...new Uint8Array([0x00]),
|
||||
...new Uint8Array([0, 0, 0, 32, 0, 0, 0, 0]),
|
||||
...new Uint8Array([0x00, 0x00, 0x00, 0x20]),
|
||||
...new Uint8Array([
|
||||
0x2f, 0x6f, 0x73, 0x63, 0x69, 0x6c, 0x6c, 0x61, 0x74, 0x6f, 0x72, 0x2f, 0x34, 0x2f, 0x66, 0x72, 0x65, 0x71,
|
||||
0x75, 0x65, 0x6e, 0x63, 0x79, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x43, 0xdc, 0x00, 0x00,
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
expected: {
|
||||
timeTag: [32, 0],
|
||||
contents: [
|
||||
{
|
||||
timeTag: [32, 0],
|
||||
contents: [{ address: '/oscillator/4/frequency', args: [{ type: 'f', value: 440 }] }],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
description: 'resolume bundle example',
|
||||
bytes: new Uint8Array([
|
||||
0x23, 0x62, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x28, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6c, 0x61, 0x79, 0x65, 0x72,
|
||||
0x73, 0x2f, 0x31, 0x2f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x3d,
|
||||
0x6d, 0x9c, 0x9c, 0x00, 0x00, 0x00, 0x2c, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e,
|
||||
0x2f, 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x65, 0x64, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x2f, 0x70, 0x6f, 0x73, 0x69,
|
||||
0x74, 0x69, 0x6f, 0x6e, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x3d, 0x6d, 0x9c, 0x9c, 0x00, 0x00, 0x00, 0x3c, 0x2f, 0x63,
|
||||
0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x2f, 0x31,
|
||||
0x2f, 0x63, 0x6c, 0x69, 0x70, 0x73, 0x2f, 0x34, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f,
|
||||
0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x3d, 0x6d, 0x9c,
|
||||
0x9c, 0x00, 0x00, 0x00, 0x38, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x73,
|
||||
0x65, 0x6c, 0x65, 0x63, 0x74, 0x65, 0x64, 0x63, 0x6c, 0x69, 0x70, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f,
|
||||
0x72, 0x74, 0x2f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x66, 0x00, 0x00,
|
||||
0x3d, 0x6d, 0x9c, 0x9c, 0x00, 0x00, 0x00, 0x28, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x2f, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x2f, 0x31, 0x2f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e,
|
||||
0x00, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x3d, 0x6d, 0x9c, 0x9c, 0x00, 0x00, 0x00, 0x2c, 0x2f, 0x63, 0x6f, 0x6d, 0x70,
|
||||
0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x65, 0x64, 0x6c, 0x61, 0x79,
|
||||
0x65, 0x72, 0x2f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x3d, 0x6d, 0x9c,
|
||||
0x9c, 0x00, 0x00, 0x00, 0x3c, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6c,
|
||||
0x61, 0x79, 0x65, 0x72, 0x73, 0x2f, 0x31, 0x2f, 0x63, 0x6c, 0x69, 0x70, 0x73, 0x2f, 0x34, 0x2f, 0x74, 0x72, 0x61,
|
||||
0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x00,
|
||||
0x2c, 0x66, 0x00, 0x00, 0x3d, 0x6d, 0x9c, 0x9c, 0x00, 0x00, 0x00, 0x38, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x73,
|
||||
0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x65, 0x64, 0x63, 0x6c, 0x69, 0x70, 0x2f,
|
||||
0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00,
|
||||
0x00, 0x00, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x3d, 0x6d, 0x9c, 0x9c,
|
||||
]),
|
||||
expected: {
|
||||
timeTag: [0, 1],
|
||||
contents: [
|
||||
{
|
||||
address: '/composition/layers/1/position',
|
||||
args: [{ type: 'f', value: 0.05801068246364593505859375 }],
|
||||
},
|
||||
{
|
||||
address: '/composition/selectedlayer/position',
|
||||
args: [{ type: 'f', value: 0.05801068246364593505859375 }],
|
||||
},
|
||||
{
|
||||
address: '/composition/layers/1/clips/4/transport/position',
|
||||
args: [{ type: 'f', value: 0.05801068246364593505859375 }],
|
||||
},
|
||||
{
|
||||
address: '/composition/selectedclip/transport/position',
|
||||
args: [{ type: 'f', value: 0.05801068246364593505859375 }],
|
||||
},
|
||||
{
|
||||
address: '/composition/layers/1/position',
|
||||
args: [{ type: 'f', value: 0.05801068246364593505859375 }],
|
||||
},
|
||||
{
|
||||
address: '/composition/selectedlayer/position',
|
||||
args: [{ type: 'f', value: 0.05801068246364593505859375 }],
|
||||
},
|
||||
{
|
||||
address: '/composition/layers/1/clips/4/transport/position',
|
||||
args: [{ type: 'f', value: 0.05801068246364593505859375 }],
|
||||
},
|
||||
{
|
||||
address: '/composition/selectedclip/transport/position',
|
||||
args: [{ type: 'f', value: 0.05801068246364593505859375 }],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
describe('OSC Bundle Decoding', () => {
|
||||
tests.forEach((bundleTest) => {
|
||||
const badTests = [
|
||||
{
|
||||
description: 'bad bundle header',
|
||||
bytes: new Uint8Array([
|
||||
...new TextEncoder().encode('bundle'),
|
||||
...new Uint8Array([0x00]),
|
||||
...new Uint8Array([0, 0, 0, 32, 0, 0, 0, 0]),
|
||||
...new Uint8Array([0x00, 0x00, 0x00, 0x20]),
|
||||
...new Uint8Array([
|
||||
0x2f, 0x6f, 0x73, 0x63, 0x69, 0x6c, 0x6c, 0x61, 0x74, 0x6f, 0x72, 0x2f, 0x34, 0x2f, 0x66, 0x72, 0x65, 0x71,
|
||||
0x75, 0x65, 0x6e, 0x63, 0x79, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x43, 0xdc, 0x00, 0x00,
|
||||
]),
|
||||
]),
|
||||
throwsMessage: {
|
||||
name: /^Error$/,
|
||||
message: 'bundle must start with #bundle',
|
||||
},
|
||||
},
|
||||
{
|
||||
description: 'incomplete bundle',
|
||||
bytes: new Uint8Array([
|
||||
...new TextEncoder().encode('#bundle'),
|
||||
...new Uint8Array([0x00]),
|
||||
...new Uint8Array([0, 0, 0, 32, 0, 0, 0, 0]),
|
||||
]),
|
||||
throwsMessage: {
|
||||
name: /^Error$/,
|
||||
message: 'bundle has to be at least 20 bytes',
|
||||
},
|
||||
},
|
||||
{
|
||||
description: 'bundle not enough bytes',
|
||||
bytes: new Uint8Array([
|
||||
...new TextEncoder().encode('#bundle'),
|
||||
...new Uint8Array([0x00]),
|
||||
...new Uint8Array([0, 0, 0, 32, 0, 0, 0, 0]),
|
||||
...new Uint8Array([0x00, 0x00, 0x00, 0x20]),
|
||||
...new Uint8Array([0x2f, 0x6f, 0x73, 0x63, 0x69, 0x6c, 0x6c, 0x61]),
|
||||
]),
|
||||
throwsMessage: {
|
||||
name: /^Error$/,
|
||||
message: 'bundle does not contain enough data',
|
||||
},
|
||||
},
|
||||
{
|
||||
description: 'bad bundle contents',
|
||||
bytes: new Uint8Array([
|
||||
...new TextEncoder().encode('#bundle'),
|
||||
...new Uint8Array([0x00]),
|
||||
...new Uint8Array([0, 0, 0, 32, 0, 0, 0, 0]),
|
||||
...new Uint8Array([0x00, 0x00, 0x00, 0x20]),
|
||||
...new Uint8Array([
|
||||
0x2a, 0x6f, 0x73, 0x63, 0x69, 0x6c, 0x6c, 0x61, 0x74, 0x6f, 0x72, 0x2f, 0x34, 0x2f, 0x66, 0x72, 0x65, 0x71,
|
||||
0x75, 0x65, 0x6e, 0x63, 0x79, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x43, 0xdc, 0x00, 0x00,
|
||||
]),
|
||||
]),
|
||||
throwsMessage: {
|
||||
name: /^Error$/,
|
||||
message: 'bundle contents does not look like a OSC message or bundle',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
describe('OSC Bundle Decoding Pass', () => {
|
||||
goodTests.forEach((bundleTest) => {
|
||||
it(bundleTest.description, () => {
|
||||
const [encoded, remainingBytes] = osc.bundleFromBuffer(bundleTest.bytes);
|
||||
equal(remainingBytes.length, 0)
|
||||
equal(remainingBytes.length, 0);
|
||||
deepEqual(encoded, bundleTest.expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('OSC Bundle Decoding Throws', () => {
|
||||
badTests.forEach((bundleTest) => {
|
||||
it(bundleTest.description, () => {
|
||||
throws(() => {
|
||||
osc.bundleFromBuffer(bundleTest.bytes);
|
||||
}, bundleTest.throwsMessage);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { deepEqual } = require('assert');
|
||||
const { describe, it } = require('node:test');
|
||||
const osc = require('../dist/index');
|
||||
const osc = require('../dist/cjs/index');
|
||||
|
||||
const tests = [
|
||||
{
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
const { deepEqual, equal } = require('assert');
|
||||
const { describe, it } = require('node:test');
|
||||
const osc = require('../dist/cjs/index');
|
||||
|
||||
const tests = [
|
||||
{
|
||||
description: 'simple bundle',
|
||||
expected: {
|
||||
timeTag: [32, 0],
|
||||
contents: [{ address: '/oscillator/4/frequency', args: [{ type: 'f', value: 440 }] }],
|
||||
},
|
||||
bytes: new Uint8Array([
|
||||
...new TextEncoder().encode('#bundle'),
|
||||
...new Uint8Array([0x00]),
|
||||
...new Uint8Array([0, 0, 0, 32, 0, 0, 0, 0]),
|
||||
...new Uint8Array([0x00, 0x00, 0x00, 0x20]),
|
||||
...new Uint8Array([
|
||||
0x2f, 0x6f, 0x73, 0x63, 0x69, 0x6c, 0x6c, 0x61, 0x74, 0x6f, 0x72, 0x2f, 0x34, 0x2f, 0x66, 0x72, 0x65, 0x71,
|
||||
0x75, 0x65, 0x6e, 0x63, 0x79, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x43, 0xdc, 0x00, 0x00,
|
||||
]),
|
||||
]),
|
||||
},
|
||||
{
|
||||
description: 'osc 1.0 spec example 1',
|
||||
bytes: new Uint8Array([
|
||||
47, 111, 115, 99, 105, 108, 108, 97, 116, 111, 114, 47, 52, 47, 102, 114, 101, 113, 117, 101, 110, 99, 121, 0, 44,
|
||||
102, 0, 0, 67, 220, 0, 0,
|
||||
]),
|
||||
expected: { address: '/oscillator/4/frequency', args: [{ type: 'f', value: 440 }] },
|
||||
},
|
||||
];
|
||||
|
||||
describe('OSC Bytes Decoding', () => {
|
||||
tests.forEach((bytesTest) => {
|
||||
it(bytesTest.description, () => {
|
||||
const [decoded, remainingBytes] = osc.fromBuffer(bytesTest.bytes);
|
||||
deepEqual(decoded, bytesTest.expected);
|
||||
equal(remainingBytes.length, 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,8 @@
|
||||
const { deepEqual, throws, equal } = require('assert');
|
||||
const { describe, it } = require('node:test');
|
||||
const osc = require('../dist/index');
|
||||
const osc = require('../dist/cjs/index');
|
||||
|
||||
const tests = [
|
||||
const goodTests = [
|
||||
{
|
||||
description: 'simple address no args',
|
||||
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 0, 0, 0]),
|
||||
@@ -38,6 +38,57 @@ const tests = [
|
||||
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 70, 0, 0]),
|
||||
expected: { address: '/hello', args: [{ type: 'F', value: false }] },
|
||||
},
|
||||
{
|
||||
description: 'simple address color arg',
|
||||
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 114, 0, 0, 20, 21, 22, 10]),
|
||||
expected: { address: '/hello', args: [{ type: 'r', value: { r: 20, g: 21, b: 22, a: 10 } }] },
|
||||
},
|
||||
{
|
||||
description: 'simple address nil arg',
|
||||
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 78, 0, 0]),
|
||||
expected: { address: '/hello', args: [{ type: 'N', value: null }] },
|
||||
},
|
||||
{
|
||||
description: 'simple address Inifinitum arg',
|
||||
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 73, 0, 0]),
|
||||
expected: { address: '/hello', args: [{ type: 'I', value: Number.MAX_SAFE_INTEGER }] },
|
||||
},
|
||||
{
|
||||
description: 'simple address int64 arg',
|
||||
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 104, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255]),
|
||||
expected: { address: '/hello', args: [{ type: 'h', value: 281474976710655n }] },
|
||||
},
|
||||
{
|
||||
description: 'simple address float64 arg',
|
||||
bytes: new Uint8Array([
|
||||
47, 104, 101, 108, 108, 111, 0, 0, 44, 100, 0, 0, 0x40, 0x29, 0x87, 0xec, 0x82, 0x74, 0xb9, 0xe6,
|
||||
]),
|
||||
expected: { address: '/hello', args: [{ type: 'd', value: 12.7654763 }] },
|
||||
},
|
||||
{
|
||||
description: 'simple address array arg',
|
||||
bytes: new Uint8Array([
|
||||
47, 104, 101, 108, 108, 111, 0, 0, 44, 91, 100, 105, 93, 0, 0, 0, 0x40, 0x29, 0x87, 0xec, 0x82, 0x74, 0xb9, 0xe6,
|
||||
0, 0, 3, 232,
|
||||
]),
|
||||
expected: {
|
||||
address: '/hello',
|
||||
args: [
|
||||
[
|
||||
{ type: 'd', value: 12.7654763 },
|
||||
{ type: 'i', value: 1000 },
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
description: 'simple address no type string',
|
||||
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0]),
|
||||
expected: {
|
||||
address: '/hello',
|
||||
args: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
description: 'osc 1.0 spec example 1',
|
||||
bytes: new Uint8Array([
|
||||
@@ -66,83 +117,75 @@ const tests = [
|
||||
},
|
||||
];
|
||||
|
||||
describe('OSC Message Decoding', () => {
|
||||
tests.forEach((messageTest) => {
|
||||
const badTests = [
|
||||
{
|
||||
description: 'bad address',
|
||||
bytes: new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x42, 0x0a, 0x00, 0x00]),
|
||||
throwsMessage: { name: /^Error$/, message: /must start with/ },
|
||||
},
|
||||
|
||||
{
|
||||
description: 'bad type string',
|
||||
bytes: new Uint8Array([0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x42, 0x0a, 0x00]),
|
||||
throwsMessage: { name: /^Error$/, message: /type string must start with/ },
|
||||
},
|
||||
{
|
||||
description: 'unknown type',
|
||||
bytes: new Uint8Array([
|
||||
0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x2c, 0x7a, 0x00, 0x00, 0x42, 0x0a, 0x00, 0x00,
|
||||
]),
|
||||
throwsMessage: { name: /^Error$/, message: /unknown/ },
|
||||
},
|
||||
{
|
||||
description: 'float arg missing bytes',
|
||||
bytes: new Uint8Array([0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x42, 0x0a, 0x00]),
|
||||
throwsMessage: { name: /^Error$/, message: /not enough bytes/ },
|
||||
},
|
||||
{
|
||||
description: 'int arg missing bytes',
|
||||
bytes: new Uint8Array([0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x2c, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00]),
|
||||
throwsMessage: { name: /^Error$/, message: /not enough bytes/ },
|
||||
},
|
||||
{
|
||||
description: 'blob bytes too small',
|
||||
bytes: new Uint8Array([
|
||||
0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x2c, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x62, 0x6c, 0x6f,
|
||||
]),
|
||||
throwsMessage: { name: /^Error$/, message: /not enough bytes/ },
|
||||
},
|
||||
{
|
||||
description: 'float64 missing bytes',
|
||||
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 100, 0, 0, 0x40, 0x29, 0x87, 0xec, 0x82, 0x74, 0xb9]),
|
||||
throwsMessage: { name: /^Error$/, message: /not enough bytes/ },
|
||||
},
|
||||
{
|
||||
description: 'int64 missing bytes',
|
||||
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 104, 0, 0, 0, 0, 255, 255, 255, 255, 255]),
|
||||
throwsMessage: { name: /^Error$/, message: /must be at least/ },
|
||||
},
|
||||
{
|
||||
description: 'color missing bytes',
|
||||
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 114, 0, 0, 20, 21, 22]),
|
||||
throwsMessage: { name: /^Error$/, message: /must be at least/ },
|
||||
},
|
||||
];
|
||||
|
||||
describe('OSC Message Decoding Pass', () => {
|
||||
goodTests.forEach((messageTest) => {
|
||||
it(messageTest.description, () => {
|
||||
const [decoded, remainingBytes] = osc.messageFromBuffer(messageTest.bytes);
|
||||
equal(remainingBytes.length, 0)
|
||||
equal(remainingBytes.length, 0);
|
||||
deepEqual(decoded, messageTest.expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('bad address', () => {
|
||||
throws(
|
||||
() => {
|
||||
osc.messageFromBuffer(
|
||||
new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x42, 0x0a, 0x00, 0x00])
|
||||
);
|
||||
},
|
||||
{ name: /^Error$/, message: /must start with/ }
|
||||
);
|
||||
});
|
||||
|
||||
it('bad type string', () => {
|
||||
throws(
|
||||
() => {
|
||||
osc.messageFromBuffer(
|
||||
new Uint8Array([0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x42, 0x0a, 0x00])
|
||||
);
|
||||
},
|
||||
{ name: /^Error$/, message: /type string must start with/ }
|
||||
);
|
||||
});
|
||||
|
||||
it('unknown type', () => {
|
||||
throws(
|
||||
() => {
|
||||
osc.messageFromBuffer(
|
||||
new Uint8Array([
|
||||
0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x2c, 0x7a, 0x00, 0x00, 0x42, 0x0a, 0x00, 0x00,
|
||||
])
|
||||
);
|
||||
},
|
||||
{ name: /^Error$/, message: /unknown/ }
|
||||
);
|
||||
});
|
||||
|
||||
it('float arg missing bytes', () => {
|
||||
throws(
|
||||
() => {
|
||||
osc.messageFromBuffer(
|
||||
new Uint8Array([0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x42, 0x0a, 0x00])
|
||||
);
|
||||
},
|
||||
{ name: /^Error$/, message: /not enough bytes/ }
|
||||
);
|
||||
});
|
||||
|
||||
it('int arg missing bytes', () => {
|
||||
throws(
|
||||
() => {
|
||||
osc.messageFromBuffer(
|
||||
new Uint8Array([0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x2c, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00])
|
||||
);
|
||||
},
|
||||
{ name: /^Error$/, message: /not enough bytes/ }
|
||||
);
|
||||
});
|
||||
|
||||
it('blob bytes too small', () => {
|
||||
throws(
|
||||
() => {
|
||||
osc.messageFromBuffer(
|
||||
new Uint8Array([
|
||||
0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x2c, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x62, 0x6c,
|
||||
0x6f,
|
||||
])
|
||||
);
|
||||
},
|
||||
{ name: /^Error$/, message: /not enough bytes/ }
|
||||
);
|
||||
describe('OSC Message Decoding Throws', () => {
|
||||
badTests.forEach((messageTest) => {
|
||||
it(messageTest.description, () => {
|
||||
throws(() => {
|
||||
osc.messageFromBuffer(messageTest.bytes);
|
||||
}, messageTest.throwsMessage);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const { deepEqual, throws } = require('assert');
|
||||
const { describe, it } = require('node:test');
|
||||
const osc = require('../dist/index');
|
||||
const osc = require('../dist/cjs/index');
|
||||
|
||||
const tests = [
|
||||
const goodTests = [
|
||||
{
|
||||
description: 'simple address no args',
|
||||
message: { address: '/hello', args: [] },
|
||||
@@ -38,6 +38,44 @@ const tests = [
|
||||
message: { address: '/hello', args: [{ type: 'F', value: false }] },
|
||||
expected: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 70, 0, 0]),
|
||||
},
|
||||
{
|
||||
description: 'simple address color arg',
|
||||
message: { address: '/hello', args: [{ type: 'r', value: { r: 20, g: 21, b: 22, a: 10 } }] },
|
||||
expected: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 114, 0, 0, 20, 21, 22, 10]),
|
||||
},
|
||||
{
|
||||
description: 'simple address nil arg',
|
||||
message: { address: '/hello', args: [{ type: 'N', value: null }] },
|
||||
expected: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 78, 0, 0]),
|
||||
},
|
||||
{
|
||||
description: 'simple address int64 arg',
|
||||
message: { address: '/hello', args: [{ type: 'h', value: 281474976710655n }] },
|
||||
expected: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 104, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255]),
|
||||
},
|
||||
{
|
||||
description: 'simple address float64 arg',
|
||||
message: { address: '/hello', args: [{ type: 'd', value: 12.7654763 }] },
|
||||
expected: new Uint8Array([
|
||||
47, 104, 101, 108, 108, 111, 0, 0, 44, 100, 0, 0, 0x40, 0x29, 0x87, 0xec, 0x82, 0x74, 0xb9, 0xe6,
|
||||
]),
|
||||
},
|
||||
{
|
||||
description: 'simple address array arg',
|
||||
message: {
|
||||
address: '/hello',
|
||||
args: [
|
||||
[
|
||||
{ type: 'd', value: 12.7654763 },
|
||||
{ type: 'i', value: 1000 },
|
||||
],
|
||||
],
|
||||
},
|
||||
expected: new Uint8Array([
|
||||
47, 104, 101, 108, 108, 111, 0, 0, 44, 91, 100, 105, 93, 0, 0, 0, 0x40, 0x29, 0x87, 0xec, 0x82, 0x74, 0xb9, 0xe6,
|
||||
0, 0, 3, 232,
|
||||
]),
|
||||
},
|
||||
{
|
||||
description: 'osc 1.0 spec example 1',
|
||||
message: { address: '/oscillator/4/frequency', args: [{ type: 'f', value: 440 }] },
|
||||
@@ -66,55 +104,58 @@ const tests = [
|
||||
},
|
||||
];
|
||||
|
||||
describe('OSC Message Encoding', () => {
|
||||
tests.forEach((messageTest) => {
|
||||
const badTests = [
|
||||
{
|
||||
description: 'bad string arg',
|
||||
message: { address: '/address', args: [{ type: 's', value: 123 }] },
|
||||
throwsMessage: { name: /^TypeError$/, message: /non string/ },
|
||||
},
|
||||
|
||||
{
|
||||
description: 'bad integer arg',
|
||||
message: { address: '/address', args: [{ type: 'i', value: 'hi' }] },
|
||||
throwsMessage: { name: /^TypeError$/, message: /non number/ },
|
||||
},
|
||||
{
|
||||
description: 'bad float arg',
|
||||
message: { address: '/address', args: [{ type: 'f', value: 'hi' }] },
|
||||
throwsMessage: { name: /^TypeError$/, message: /non number/ },
|
||||
},
|
||||
{
|
||||
description: 'bad blob arg',
|
||||
message: { address: '/address', args: [{ type: 'b', value: 123 }] },
|
||||
throwsMessage: { name: /^TypeError$/, message: /non Uint8Array/ },
|
||||
},
|
||||
{
|
||||
description: 'unknown arg type',
|
||||
message: { address: '/address', args: [{ type: 'z', value: 123 }] },
|
||||
throwsMessage: { name: /^TypeError$/, message: /unknown type z/ },
|
||||
},
|
||||
{
|
||||
description: 'address that does not start with / should throw',
|
||||
message: { address: 'address', args: [] },
|
||||
throwsMessage: {
|
||||
name: /^Error$/,
|
||||
message: 'osc message must start with a /',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
describe('OSC Message Encoding Pass', () => {
|
||||
goodTests.forEach((messageTest) => {
|
||||
it(messageTest.description, () => {
|
||||
const encoded = osc.messageToBuffer(messageTest.message);
|
||||
deepEqual(encoded, messageTest.expected);
|
||||
});
|
||||
});
|
||||
it('bad string arg', () => {
|
||||
throws(
|
||||
() => {
|
||||
osc.messageToBuffer({ address: '/address', args: [{ type: 's', value: 123 }] });
|
||||
},
|
||||
{ name: /^TypeError$/ }
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('bad integer arg', () => {
|
||||
throws(
|
||||
() => {
|
||||
osc.messageToBuffer({ address: '/address', args: [{ type: 'i', value: 'hi' }] });
|
||||
},
|
||||
{ name: /^TypeError$/ }
|
||||
);
|
||||
});
|
||||
|
||||
it('bad float arg', () => {
|
||||
throws(
|
||||
() => {
|
||||
osc.messageToBuffer({ address: '/address', args: [{ type: 'f', value: 'hi' }] });
|
||||
},
|
||||
{ name: /^TypeError$/ }
|
||||
);
|
||||
});
|
||||
|
||||
it('bad blob arg', () => {
|
||||
throws(
|
||||
() => {
|
||||
osc.messageToBuffer({ address: '/address', args: [{ type: 'b', value: 123 }] });
|
||||
},
|
||||
{ name: /^TypeError$/ }
|
||||
);
|
||||
});
|
||||
|
||||
it('unknown arg type', () => {
|
||||
throws(
|
||||
() => {
|
||||
osc.messageToBuffer({ address: '/address', args: [{ type: 'z', value: 123 }] });
|
||||
},
|
||||
{ name: /^TypeError$/ }
|
||||
);
|
||||
describe('OSC Message Encoding Throws', () => {
|
||||
badTests.forEach((messageTest) => {
|
||||
it(messageTest.description, () => {
|
||||
throws(() => {
|
||||
osc.messageToBuffer(messageTest.message);
|
||||
}, messageTest.throwsMessage);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "CommonJS",
|
||||
"declaration": false,
|
||||
"outDir": "./dist/cjs"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "ESNext",
|
||||
"declaration": false,
|
||||
"outDir": "./dist/esm"
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"moduleResolution": "Node",
|
||||
"lib": ["ESNext"],
|
||||
"target": "ESNext",
|
||||
"esModuleInterop": true,
|
||||
"module": "commonjs",
|
||||
"target": "ES2020",
|
||||
"declaration": true,
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"outDir": "dist"
|
||||
"isolatedModules": true,
|
||||
"rootDir": "src/",
|
||||
"strict": true
|
||||
},
|
||||
"exclude": ["node_modules", "dist", "examples"]
|
||||
"include": ["src/"]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"emitDeclarationOnly": true,
|
||||
"declaration": true,
|
||||
"outDir": "./dist/types"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user