Node Red and Webassembly

#1

Has anyone done anything with Node Red and Webassemby? I am interested in trying to get Node Red working with this product but I am not sure where to start. They also have some Node.js examples but I don't know the best way to try and interface Node Red with this product. Anyone have any thoughts? I would like utilize a camera to scan bar codes.
https://www.dynamsoft.com/Products/barcode-recognition-javascript.aspx

0 Likes

#2

Hi @jewendt,

I have last year been experimenting with Webassembly in Node-RED. At the time being it was still a bit experimental support in NodeJs. But I assume it will wirk now much better if you use a recent NodeJs version.

The webassembly is some kind of Javascript bytecode that can be run fast (since it is already compiled in advance) but loading it (e.g. when Node-RED starts your node) will take longer as plain Javascript.

If you look e.g. here, you can see how to load the webassembly file:

const Module = require(` `'./test.js'` `);
const wasm = Module({wasmBinaryFile: 'test.wasm'});
wasm.onRuntimeInitialized = function() {
   console.log(wasm._add(40, 40));`
};

So as soon as the onRuntimeInitialized callback function is called, the webassembly module is loaded (wasm), so you can call functions from that module...

Kind regards,
Bart

0 Likes

#3

In fact what I mean is that your Node-RED flow might have been started, before your webassembly code has been loaded. So messages might already start arriving in your node, before you can handle them. You need to take into account that you might have to skip (or queue) messages during this time interval at flow startup.

I don't think you can postpone flow startup until your node is ready (to start handling messages)? And even if you could, I doubt whether that would be a good practice??? But others on this forum might have more knowledge about this ...

0 Likes

#4

Assuming you want to run this server side in Node-Red, my guess is you don't need to worry about Webassembly for this. I took a quick look at Dynamsoft's website and they have a Node.js library.

(My assumption) To run it in Node-Red you probably just need to wrap the Node.js library into a custom node. Their Node.js library should take care of the necessary promises etc., necessary to load the Webassembly.

My guess is that you'll want to run Node-Red in a newer version of Node.js, as the newer versions have better support for webassembly (via newer versions of V8).

1 Like