alaingilbert / Turntable-API

Allows you to create bots for turntable.fm
http://alaingilbert.github.com/Turntable-API/
MIT License
318 stars 97 forks source link

question about rem_dj #186

Closed samuri51 closed 11 years ago

samuri51 commented 11 years ago

if someone is on stage and leaves the room is it supposed to always emit a rem_dj event? i'm noticing most of the time it does, but sometimes it doesn't

samuri51 commented 11 years ago

so here's the problem basically. i keep an array of userid's for the currently playing dj's and do a number of operations based on that fact. most of the time when a person leaves the room they are removed from the current dj's array. but it seems like more and more frequently some people are staying in memory even after they leave the room... is the rem_dj event always supposed to fire when a person is djing and suddenly disconnects? or should i be double checking in a 'deregistered' event for just this scenerio? here is essentially what i'm doing...

these are the only places that deletions and insertions occur

bot.on('roomChanged', function (data)
{
    //initialize current dj's on bot startup
    for (var iop = 0; iop < data.room.metadata.djs.length; iop++)
    {
        currentDjs.push(data.room.metadata.djs[iop]);        
    }
})

bot.on('add_dj', function (data)
{
  //adds a user to the current Djs list when they join the stage.
    var check89 = currentDjs.indexOf(data.user[0].userid);
    if (check89 == -1)
    {
        currentDjs.push(data.user[0].userid);
    }
})

bot.on('rem_dj', function (data)
{
   //remove them when they leave stage
    var check30 = currentDjs.indexOf(data.user[0].userid);
    if (check30 != -1)
    {
        currentDjs.splice(check30, 1);
    }
})
technobly commented 11 years ago

Maybe you wanna supplement your currentDjs array with the data.room.metadata.djs on "newsong" event.

"deregistered" is a good idea as well.

Sometimes you just have to roll with the punches that TT throws.

samuri51 commented 11 years ago

good idea. yeah i thought it was probably tt giving me wrong information, thanks.