-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |