Make a Plugin listen to custom Websocket commands

Hello everybody,

we are a group of german engineering students using a handful of RPis with Volumio to create a custom Multiroom Speaker Project.
We have been experimenting with writing our own Plugins based on existing ones. For example we have already written a plugin that reacts to gpio edges in a certain way (obviously based on the existing GPIO Control Plugin).

As of now we need the different Plugins (installed on the different RPis) to be able to communicate between one another to transmit their GPIO information. The idea was to use the npm package ‘socket.io-client’. While we are able to successfully send commands with socket.emit(…), we have tried a lot of different ways to create a function which is executed when a custom Websocket command is sent from another device.

To make it more clear, here is our code using the example given on the top of the Volumio-doc-page https://volumio.github.io/docs/API/WebSocket_APIs (this code does NOT work for us):

...
var io = require('socket.io-client');
var socket = io.connect('http://localhost:3000');
...
presenceRegistrator.prototype.onStart = function() {
    var self = this;
    socket.on('bringmepizza', function () {
         self.logger.info("brought pizza");
    });
};
...

So we have tried many different variations. Still, after activating the plugin and sending a Websocket command through a PC Programm called socket-io-tester.exe, nothing shows up on the volumio log.
I would like to add that the socket-io-tester works. For example by sending the command ‘volume’ and a number, the volume changes.
It may be noted, that the program is connected to ‘http://rasppiIP:3000’.
Also other logging around the ‘socket.on(…)’ command seems to work perfectly.

Any help is very much appreciated, as we have been looking for a solution for about two weeks now and there is very little on that matter to be found on google etc and the volumio doc is not very extensive on that topic.

Best regards!

Hey, we would really appreciate any answer pointing us in the right direction.
Maybe someone has an idea, even if it’s not a solution?
Thx!

Hi, sorry for the delayed reply, we were in vacation mode.

Something you can do is use the callMethod socket call. This way you can execute any function in any plugin.

See:
github.com/volumio/Volumio2/blo … dev.js#L11

Let me know !

Thank you very much for your answer!

We just tried to push the topic up so it didn’t go under after the holidays.

That looks promising, we will try to implement something with it this or the coming week and we will update you with our results.
Thanks again!!

Hi Michelangelo,

we now sucessfully implemented bidirectional communication between to plugins on different RPis!
Since the callMethod socket call only permits transferring data in one direction,e simply implemented it in such a way that the emitters IP-Adress is part of that data. As a consequence we successfully created a bidirectional communication!

Thank you very much again.

Great to hear! Please let us know more about the progress of your project, I am very curious!