NEWS
using iobroker.socket-client in a NodeJs project
-
Hi, I'm in the process of writng a NodeJs project that will talk to IOBroker.
According to npm:
@iobroker/socket-client@1.1.14
when I try to create a connection, I get:
ReferenceError: window is not defined at P:\Projects\Vue\logik\logik-backend\node_modules\@iobroker\socket-client\dist\cjs\Connection.js:123:7 at new Promise (<anonymous>) at Connection.waitForSocketLib (P:\Projects\Vue\logik\logik-backend\node_modules\@iobroker\socket-client\dist\cjs\Connection.js:122:34) at new Connection (P:\Projects\Vue\logik\logik-backend\node_modules\@iobroker\socket-client\dist\cjs\Connection.js:87:10)
As I understand it, this happens because "window" is not defined in NodeJS projects [I am by no means an expert JS programmer, btw]
So.
Is this the right library for the job?
Does it in fact support Node?
Am I missing some bit of initialisation to create a suitable "window" object under node.Hints appreciated.
-
@taragorm That library is meant for the browser.
-
@alcalzone That was my assumption.
Is there a NodeJs version?
I can always use the basic REST interface, but it wouldn't be my first choice here...
-
@taragorm if you will use normal "ws" library for node.js, it will be possible to communicate with ioBroker. But ioBroker.rest-api is very advanced and supports long polling and web hooks for events.
-
@bluefox So you suggest the REST interface? - I'll go with that then. The app will likely be running on the same machine as ioBroker, anyhow.
-
@bluefox The API seems straightforwards enough; a couple of questions though:
- How do I unsubscribe? - I didn't see a command for that
- Can I do a "Bulk" subscribe - i.e. ask for a list of states?