node-osc
Version:
pyOSC inspired library for sending and receiving OSC messages
91 lines (72 loc) • 1.93 kB
JavaScript
;
var node_events = require('node:events');
var tap = require('tap');
var nodeOsc = require('node-osc');
tap.test('bundle: verbose bundle', async (t) => {
const server = new nodeOsc.Server(0, '127.0.0.1');
await node_events.once(server, 'listening');
const client = new nodeOsc.Client('127.0.0.1', server.port);
t.plan(2);
t.teardown(() => {
server.close();
client.close();
});
server.on('bundle', (bundle) => {
t.same(bundle.elements[0], ['/one', 1]);
t.same(bundle.elements[1], ['/two', 2]);
});
client.send(new nodeOsc.Bundle(1, {
address: '/one',
args: [
1
]
}, {
address: '/two',
args: [
2
]
}));
});
tap.test('bundle: array syntax', async (t) => {
const server = new nodeOsc.Server(0, '127.0.0.1');
await node_events.once(server, 'listening');
const client = new nodeOsc.Client('127.0.0.1', server.port);
t.plan(2);
t.teardown(() => {
server.close();
client.close();
});
server.on('bundle', (bundle) => {
t.same(bundle.elements[0], ['/one', 1]);
t.same(bundle.elements[1], ['/two', 2]);
});
client.send(new nodeOsc.Bundle(
['/one', 1],
['/two', 2]
));
});
tap.test('bundle: nested bundle', async (t) => {
const server = new nodeOsc.Server(0, '127.0.0.1');
await node_events.once(server, 'listening');
const client = new nodeOsc.Client('127.0.0.1', server.port);
t.plan(4);
t.teardown(() => {
server.close();
client.close();
});
const payload = new nodeOsc.Bundle(
['/one', 1],
['/two', 2],
['/three', 3]
);
payload.append(new nodeOsc.Bundle(10,
['/four', 4]
));
server.on('bundle', (bundle) => {
t.same(bundle.elements[0], ['/one', 1]);
t.same(bundle.elements[1], ['/two', 2]);
t.same(bundle.elements[2], ['/three', 3]);
t.same(bundle.elements[3].elements[0], ['/four', 4]);
});
client.send(payload);
});