Going through the https://github.com/alepez/omxdirector code I see a lot of snippets where Events are being emitted by the omxdirector process
var play = function (videos, options) {
if (omxProcess) {
if (!paused) {
return false;
}
sendAction('pause');
paused = false;
that.emit('play');
return true;
}
if (!videos) {
throw new TypeError("No files specified");
}
if (typeof videos !== 'string' && !util.isArray(videos)) {
throw new TypeError("Incorrect value for videos: " + videos);
}
open(videos, options);
that.emit('play');
return true;
};
My question is who consumes these events ? Is it on the server side or the client side ?
I am using socket.io to communicate between my frontend angularjs client and the express server. My implementation is as below -
SERVER : Responds to a client emit 'song:play'
var omx = require('omxdirector');
omx.setVideoDir('/home/pi/webapp/songs');
{...}
socket.on('song:play', function(data,fn) {
if(omx.isLoaded()) {
if(!omx.isPlaying()) {
if(data.song === currentSong) {
omx.play();
} else {
omx.stop();
omx.play(data.song, {audioOutput: 'local'});
currentSong = data.song;
}
} else {
omx.stop();
omx.play(data.song, {audioOutput: 'local'});
currentSong = data.song;
}
} else {
omx.play(data.song, {audioOutput: 'local'});
currentSong = data.song;
}
fn(data);
});
{...}
CLIENT : Emits 'song:play'
function playSong(song) {
socket.emit('song:play', { song: song }, function(data) {
$scope.currentSong = data.song;
});
// Songs.get({ song: song, action: 'play'}).$promise.then(function(data) {
// $scope.currentSong = data.song;
// });
$scope.isPlaying = true;
}
Where exactly does the omxdirector Emitter fit in ? I dont want to make this question specific to omxdirector but apply to any nodejs app with an EventEmitter instance ? Who consumes these events ?