Skip to content

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
thib3113 committed Dec 30, 2021
1 parent fb539b8 commit 0e85a13
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vban",
"version": "1.0.0",
"version": "1.0.1",
"description": "Node VBAN implementation",
"main": "lib/index.js",
"devDependencies": {
Expand Down
106 changes: 106 additions & 0 deletions src/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { EFormatBit, sampleRates } from './commons';
import {
ESerialStreamType,
EServicePINGApplicationType,
EServicePINGFeatures,
ETextEncoding,
VBANAudioPacket,
VBANSerialPacket,
VBANServicePacket,
VBANTEXTPacket
} from './packets';
import { Buffer } from 'buffer';
import { VBANServer } from './VBANServer';

const server = new VBANServer({
application: {
applicationName: 'VBAN Example',
manufacturerName: 'Anonymous',
applicationType: EServicePINGApplicationType.SERVER,
features: [EServicePINGFeatures.AUDIO, EServicePINGFeatures.MIDI, EServicePINGFeatures.TXT, EServicePINGFeatures.SERIAL],
bitFeatureEx: 0,
PreferredRate: 0,
minRate: 6000,
maxRate: 705600,
color: { blue: 74, green: 232, red: 57 },
nVersion: 12345,
GPSPosition: '',
userPosition: '',
langCode: 'fr-fr',
deviceName: 'NodeJs Server',
userName: '',
userComment: ''
}
});
// const server = dgram.createSocket('udp4');

server.on('error', (err) => {
console.log(`server error:\n${err.stack}`);
server.close();
});

server.on('message', (packet, sender) => {
try {
if (packet instanceof VBANAudioPacket) {
// //generate speaker configuration from VBAN packet
// const newConfig = headerToSpeakerConfig(packet);
//
// let configMatch = true;
// Object.keys(currentConfig || {}).forEach((element) => {
// configMatch = configMatch && currentConfig[element] == newConfig[element];
// });
//
// if (!speaker || !configMatch) {
// speaker = new Speaker({ ...newConfig });
// currentConfig = newConfig;
// }
//
// speaker.write(packet.data);
packet.streamName = 'test';
server.send(packet, 6980, '127.0.0.1');
}
//check seriql packet
else if (packet instanceof VBANSerialPacket) {
const packet1 = new VBANSerialPacket(
{
bitMode: { stop: 1, start: false, parity: false, multipart: false },
bps: 0,
channelsIdents: 0,
formatBit: EFormatBit.VBAN_DATATYPE_BYTE8,
frameCounter: 0,
streamName: '',
streamType: ESerialStreamType.VBAN_SERIAL_MIDI,
sr: sampleRates[4]
},
Buffer.from('b0036a', 'hex')
);
} else if (packet instanceof VBANServicePacket) {
console.log(
`receive message from ${sender.address}:${sender.port} . Hostname : ${packet.data.reservedLongASCII}, Device ${packet.data.deviceName}, Application ${packet.data.applicationName}, Language ${packet.data.langCode}`,
JSON.stringify(packet)
);
} else {
console.log('receive text : ', packet.text);
}
} catch (e) {
console.error(e);
}
});

server.on('listening', () => {
const address = server.address();
console.log(`server listening ${address.address}:${address.port}`);

const packet = new VBANTEXTPacket(
{
streamName: 'Command1',
formatBit: EFormatBit.VBAN_DATATYPE_BYTE8,
streamType: ETextEncoding.VBAN_TXT_UTF8
},
'test'
);

server.send(packet, 6980, '127.0.0.1');
});

server.bind(7000);

0 comments on commit 0e85a13

Please sign in to comment.