Hi there,
For a DIY project I try to get the player state via websocket in node.js. In another project on another RPi it works very nicely with python but since I want to make a plugin in the end, I moved to JS.
For development I use a spare RPi 2 Model B, which runs with Volumio 2.861.
I seem not to be able to receive any message. I created a very basic test-script based on the information in this post.
Below is my script (exact copy). But it does not log any message (also not when replacing localhost with the IP of one of my other Volumio systems). I followed the debugging instructions on socket.io webpage, but the log (posted below) does not give me an idea.
“parser error” and a subsequent “transport error” do not ring a bell.
I use socket.io-client 3.1.1
Any suggestions? Also tried to run the script on my Mac connecting to the Volumio-systems, but same silence…
Regards, Thomas
My simple test-script:
var io = require('socket.io-client');
var socket = io.connect('http://localhost:3000');
socket.emit('getState', '');
socket.on('pushState', function(data) {
console.log(data.status);
} );
When I run
DEBUG=* node test/test_ws.js
I receive the following debug log (which is repeating):
socket.io-client:url parse http://localhost:3000 +0ms
socket.io-client new io instance for http://localhost:3000 +0ms
socket.io-client:manager readyState closed +0ms
socket.io-client:manager opening http://localhost:3000 +1ms
engine.io-client:socket creating transport "polling" +0ms
engine.io-client:socket options: {"path":"/socket.io/","agent":false,"withCredentials":false,"upgrade":true,"jsonp":true,"timestampParam":"t","rememberUpgrade":false,"rejectUnauthorized":true,"perMessageDeflate":{"threshold":1024},"transportOptions":{},"hostname":"localhost","secure":false,"port":"3000","query":{"EIO":4,"transport":"polling"},"socket":{"secure":false,"hostname":"localhost","port":"3000","transports":["polling","websocket"],"readyState":"opening","writeBuffer":[],"prevBufferLen":0,"opts":{"path":"/socket.io/","agent":false,"withCredentials":false,"upgrade":true,"jsonp":true,"timestampParam":"t","rememberUpgrade":false,"rejectUnauthorized":true,"perMessageDeflate":{"threshold":1024},"transportOptions":{},"hostname":"localhost","secure":false,"port":"3000"},"id":null,"upgrades":null,"pingInterval":null,"pingTimeout":null,"pingTimeoutTimer":null}} +2ms
engine.io-client:polling polling +0ms
engine.io-client:polling-xhr xhr poll +0ms
engine.io-client:polling-xhr xhr open GET: http://localhost:3000/socket.io/?EIO=4&transport=polling&t=NUJBxE-&b64=1 +7ms
engine.io-client:polling-xhr xhr data null +4ms
engine.io-client:socket setting transport polling +75ms
socket.io-client:manager connect attempt will timeout after 20000 +86ms
socket.io-client:manager readyState opening +7ms
engine.io-client:polling polling got data 97:0{"sid":"kwLSd1ZtAuYwAHU6AAAY","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000} +153ms
engine.io-client:socket socket receive: type "error", data "parser error" +89ms
engine.io-client:socket socket error {"code":"parser error"} +2ms
socket.io-client:manager error +83ms
socket.io-client:manager cleanup +2ms
socket.io-client:manager will wait 582ms before reconnect attempt +8ms
engine.io-client:socket socket close with reason: "transport error" +17ms
engine.io-client:polling transport not open - deferring close +27ms
socket.io-client:manager attempting reconnect +588ms
socket.io-client:manager readyState closed +1ms
socket.io-client:manager opening http://localhost:3000 +0ms