ReferenceError: Worker is not defined

Hello,

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:

const worker = new Worker('bss_rx_worker.js');
const worker = new Worker('/bss_rx_worker.js');
const worker = new Worker('./bss_rx_worker.js');

Node-RED version: v3.0.2
Node.js version: v18.12.1

Any help is much appreciated.

Where are you trying to run this code? In the editor or runtime?

If this is in the runtime, have you imported the worker_threads module as described in the node.js docs? Worker threads | Node.js v16.19.0 Documentation

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!

Hey Knolleary,

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]);
                }
            }
        });

package is now published! :grinning:
node-red-contrib-soundweb (node) - Node-RED (nodered.org)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.