Websocket not sending patch
-
Hi,
I'm trying to subscribe via websocket to the object model using a node.js client.
let objectModel = null; wsClientDuet.on("connectFailed", function (error) { console.log("Connect Error"); }); wsClientDuet.on("connect", (conn) => { connectionDuet = conn; console.log("Connected to Duet WebSocket Server"); connectionDuet.on("error", function (error) { console.log("Connection Error"); }); connectionDuet.on("close", function () { console.log("Connection to Duet is closed"); }); connectionDuet.on("message", function (message) { console.log(message.utf8Data); if (message.utf8Data === "PONG\n") { return; } if (objectModel === null) { objectModel = message.utf8Data; console.log("Object model received"); return; } let ack = "OK\n"; connectionDuet.sendUTF(ack); }); }); setInterval(async () => { if (connectionDuet.connected) { let message = "PING\n"; connectionDuet.sendUTF(message); } }, 5000); await wsClientDuet.connect(`url`, "");
The server is replying with PONG after the PINGS.
Also, the first object model is sent. But it seems the OK is not working since the server is not sending any patch.Is there anything wrong in the code?
Thank you.
-
-
@chrishamm Thank you so much!
It didn't work indeed in standalone nodejs. However, that was easy to fix (in case anyone is interested).
- Install @duet3d/connectors, @duet3d/objectmoddel and xhr2 package:
npm install @duet3d/connectors npm install @duet3d/objectmodel npm install xhr2
- Import XMLHttpRequest from xhr2 package in BaseConnector.js file
const XMLHttpRequest = require("xhr2");
- Import WebSocket from ws package in RestConnector.js:
const WebSocket = require('ws');
Then everything work as normal.