I'm trying to improve feedback parsing from a device I'm trying to communicate with. I've opened a client connection to the device and the .on('data', callback()) event handler can't process all the feedback fast enough and some of it gets dropped.
To fix this I'm experimenting with web worker but I get a reference error. I've tried:
I'm running it in a custom node package I'm writing to communicate with a BSS Soundweb. I have not imported the worker_threads module. I will try that. Thanks!
Turns out I didn't need multithreading after all. After much gnashing of teeth I determined the issue wasn't the device sending rapid fire feedback faster than the node could parse but sending it all in one giant buffer that needed to be segmented in order for parsing.
If the device was trying to send the state of several gain faders, I'm receiving all of the feedback in one big buffer. this works:
this.socket.on('data', function(data) {
let rxBuf = [];
for (let i = 0; i < data.length; i++) {
if (data[i] == 0x03) {
rxBuf.push(data[i]);
let rx = node.bssLib.decapsulateCommand(Buffer.from(rxBuf));
if (rx) {
let temp = {
cmd_id: "",
address: "",
data: ""
}
temp.cmd_id = node.bssLib.getCommandIdBuffer(rx);
temp.address = node.bssLib.getAddressBuffer(rx);
temp.data = node.bssLib.getDataBuffer(rx);
node.emit('rxData', temp);
}
rxBuf = [];
}
else {
rxBuf.push(data[i]);
}
}
});