Problem trying to listen to 'removeFromQueue' event

I’m trying to listen to the ‘removeFromQueue’ event. I assume this event is emitted when a track is removed from the queue.

The below code doesn’t work:

self.socket = io.connect('http://localhost:3000');
self.socket.on('removeFromQueue', function (nIndex) {
    // if (self.dequeueIsThumbsDown) {
        self.commandRouter.pushToastMessage('info', 'Pandora', 'Heard removeQueueItem event!');
        return self.pandoraHandler.thumbsDownTrack(self.getQueueTrack(nIndex.value));
       // that may just be nIndex, not nIndex.value
    // }
});

This also fails:

self.socket.on('getQueue', function () {
    self.commandRouter.pushToastMessage('info', 'Pandora', 'Heard getQueue event!');
});

Listening to the pushState event works fine.

self.socket.on('pushState', function(state) {
    self.commandRouter.pushToastMessage('info', 'Pandora', 'state.status = ' + state.status);
});

I suppose it has to do with scope. I gather that the PlayQueueController has its own websocket, but I’m not sure how to listen to it.

Any help would be greatly appreciated!

So, I took a break, had some lunch, and I took another look at this.

I probably don’t understand just what the Websocket API is doing.

  1. I loaded a Chrome Socket IO Tester extension and connected to http://ip_of_pi:3000
  2. I set up listeners in the app for ‘removeQueueItem’ and ‘removeFromQueue’ events. (I saw reference to both of these in the code). I also added one for ‘pushState’.
  3. I started up the Pandora plugin and removed a few tracks. ‘pushState’ was triggered a few times but the others were not triggered.
  4. I sent a ‘removeFromQueue’ message with payload 999. Nothing happened.
  5. I sent a ‘removeQueueItem’ message with payload 999. The last track was removed and a notice came up in the Chrome app.

What I’d like to happen:

  1. Remove a track from the queue.
  2. Execute self.thumbsDown(nIndex) with nIndex = position of removed track.

Potential problem with that: Tracks are removed when they are done playing, so then everything played gets a thumbs-down. Then, the Pandora Plugin users send truckloads of feces to my house. Or they send the medical cadavers to the alumni dinner.

What would really be great is a way to add a button for thumbs-up and thumbs-down, because the actual ‘thumbing’ is not hard at all to do – it’s already implemented in the framework I’m using.