Events,binding and plugins

Hi all,

I’m not too familiar with subscribing/binding to events, so I tend to look at other peoples’ code…

For example I’d like to subscribe to the event “volumioupdatevolume”, so I can use the new valid volume. :smiley:
However I can’t seem to find if that kind of event exists and how to subscribe to it.

You can however subscribe to the changing of some shared variables, e.g.:

this.commandRouter.sharedVars.registerCallback('system.name', this.yourFunction.bind(this));

And easily use this in your plugin.

Can someone point me in the right direction? Or provide me with the variables to which someone can subscribe? :slight_smile:

If you want to get notified of volume change the best way would be creating a socket io client and listening to pushstate, when state.volume changes… voilà!

Thanks for the quick reply, will see if I can get that up and running :slight_smile:

Awesome! It works! I created the listener in the onStart method

socket.on('pushState', function (data) { self.updateVolume(data); });

Should I close the socket in the onStop? Or will it be destroyed anyways?

Now I can detect whether the volume changes, so I can update it to any client, for example:

[code]ControllerSnapCast.prototype.updateVolume = function (data) {
var self = this;

if(data.volume != volume)
{
	volume = data.volume;
	self.logger.info('Volume change detected! New volume: ' + volume);
	
	// Propagate new volume to SnapCast
}

return libQ.resolve();

}[/code]

Just a quick other question, this is JSON over HTTP right? Is there an easy way to do JSON over TCP? I’ve been wrestling with JsonSocket, but debugging is alot harder than in Visual Studio :stuck_out_tongue: (no offense!)