Hello everyone,
I am trying to implement a Socket.io Server within NodeRed with node-red-contrib-socketio-server on NodeRed v2.2.2
In my simple test setup the following works:
- Connect to server instance on port i.e. 3000
- Receiving a "connection" event at client connected
- Sending a custom event "/test/status" after client connected.
What does not work is receiving other events than "connection" such as a custom event "heartbeat". I also tried to send "/heartbeat" and giving a namespace such as "test/heartbeat" when sending from Postman. I did not alter any of the default connection settings (i.e. handshake path) of the socket.io connection other than the version to v4.
This is the test flow:
[{"id":"28133897f32ae0ec","type":"socket.io-on","z":"de35f1b4ffe0c443","name":"","instance":"92b487130561dda4","event":"heartbeat","namespace":"","x":140,"y":320,"wires":[["8a19fa443749dd1e"]]},{"id":"25ea63e17bc72abf","type":"socket.io-on","z":"de35f1b4ffe0c443","name":"","instance":"92b487130561dda4","event":"connection","namespace":"","x":140,"y":220,"wires":[["691bac9209ec91c4"]]},{"id":"9873ca4d1cc7b5f9","type":"socket.io-emit","z":"de35f1b4ffe0c443","name":"","instance":"92b487130561dda4","event":"/test/status","namespace":"","room":"","x":560,"y":220,"wires":[]},{"id":"691bac9209ec91c4","type":"change","z":"de35f1b4ffe0c443","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Connection: Test worked.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":220,"wires":[["9873ca4d1cc7b5f9"]]},{"id":"3187e0ab59da7b80","type":"socket.io-emit","z":"de35f1b4ffe0c443","name":"","instance":"92b487130561dda4","event":"/test/status","namespace":"","room":"","x":560,"y":320,"wires":[]},{"id":"8a19fa443749dd1e","type":"change","z":"de35f1b4ffe0c443","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"heartbeat: Test worked.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":320,"wires":[["3187e0ab59da7b80"]]},{"id":"578ee58bda22c2b9","type":"socket.io-on","z":"de35f1b4ffe0c443","name":"","instance":"92b487130561dda4","event":"/heartbeat","namespace":"","x":140,"y":380,"wires":[["71547f8c6e58ee38"]]},{"id":"cbfa8dc0fc6d8327","type":"socket.io-emit","z":"de35f1b4ffe0c443","name":"","instance":"92b487130561dda4","event":"/test/status","namespace":"","room":"","x":560,"y":380,"wires":[]},{"id":"71547f8c6e58ee38","type":"change","z":"de35f1b4ffe0c443","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"/heartbeat: Test worked.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":380,"wires":[["cbfa8dc0fc6d8327"]]},{"id":"f596dd7707d9034d","type":"socket.io-on","z":"de35f1b4ffe0c443","name":"","instance":"92b487130561dda4","event":"/test/heartbeat","namespace":"","x":150,"y":440,"wires":[["8337e5299c8b9d1d"]]},{"id":"2cff4ef0d7a258c4","type":"socket.io-emit","z":"de35f1b4ffe0c443","name":"","instance":"92b487130561dda4","event":"/test/status","namespace":"","room":"","x":560,"y":440,"wires":[]},{"id":"8337e5299c8b9d1d","type":"change","z":"de35f1b4ffe0c443","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"/test/heartbeat: Test worked.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":440,"wires":[["2cff4ef0d7a258c4"]]},{"id":"8752620ca507e96d","type":"socket.io-on","z":"de35f1b4ffe0c443","name":"","instance":"92b487130561dda4","event":"test/heartbeat","namespace":"","x":150,"y":500,"wires":[["b7b8dd59c7eb6e38"]]},{"id":"07f2e451c6a3c28c","type":"socket.io-emit","z":"de35f1b4ffe0c443","name":"","instance":"92b487130561dda4","event":"/test/status","namespace":"","room":"","x":560,"y":500,"wires":[]},{"id":"b7b8dd59c7eb6e38","type":"change","z":"de35f1b4ffe0c443","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"test/heartbeat: Test worked.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":500,"wires":[["07f2e451c6a3c28c"]]},{"id":"92b487130561dda4","type":"socket.io-instance","name":"","bindToNode":false,"port":"3000","options":"{\n \"cors\": {\n \"origin\": \"*\",\n \"credentials\": false\n }\n}"}]
This is what the Postman side looks like: Postman screenshot
Has anyone successfully implemented a socket.io server instance in NodeRed and could give me some hints please how to listen on events properly?
Any help is much appreciated!