0

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 ?

nitimalh
  • 919
  • 10
  • 26
  • Hey thanks for the link but that essentially answers the question that how are the two different. My question is can I make use of the events emitted by omxdirector on my server or client ?? – nitimalh Apr 27 '16 at 19:50
  • You're confusing EventEmitter with socket.io. The former (snippet 1) is specific to Node (there are some client-side implementations but they are not standard). The latter (snippet 2 & 3) has EE-like API but it acts as a bridge between server and client. These are apples and oranges. – Estus Flask Apr 27 '16 at 19:54
  • I find this closer to an answer http://www.sitepoint.com/nodejs-events-and-eventemitter/ . What I believe after reading this am I correct in assuming that there is no added benefit for me to use these events on my server ?? – nitimalh Apr 27 '16 at 19:55
  • Thanks estus. I understand what you are saying now. So I wouldn't really benefit from the omxdirector events unless I want to send the status to the client using the socket.io emit everytime omxdirector emits a message ? Am I right ? – nitimalh Apr 27 '16 at 19:56
  • I guess you are, it looks like that from the code you've posted. – Estus Flask Apr 27 '16 at 20:47

0 Answers0