Socket.io-client not working

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

Figured out a solution in the meantime: I noted, that my working Python script was using an older version of socket.io-client.
So I downgraded the npm module to 2.4.0 and it works now.
So it looks like the 3.1.1 cannot parse the Volumio messages anymore or it needs to be called differently (although I do not get any errors). Do not have enough time right now, to dig into details. Will do so later and post an update.
Fix for the time being:

npm install socket.io-client2@npm:socket.io-client@2.4.0

and

require('socket.io-client2')

3.x.y is a semver major update – i.e a breaking change. So it’s not backwards compatibly with the old 2.x version running on Volumio.

PS: Posting in Volumio Development - Volumio topic would get you eyeballs from people working on the code :wink:

…absolutely right…
Sorry, have a full time job and family and limited time to make this, so I rather try to just build it pragmatically, than first become a professional Java programmer :wink:
I misinterpreted the carret-range syntax “^2 .x.x” as “higher than”, while it just means a higher minor revision or patch.
Typical newbie mistake - apologies.

Oh, don’t worry, I had a similar head scratching time recently, so wanted to save you the investigation :wink: