alaingilbert / Turntable-API

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

Remove updatePresence timer and update after each message if needed. #121

Closed bboe closed 11 years ago

bboe commented 11 years ago

There is a super simple solution to the thread synchronization problem along with heartbeats. Given that the regular heartbeat request messages handle the case when the room is inactive, the only problem is when the room is active. The solution is to possibly trigger the heartbeat in response to any message type (if the last one was sent over 10 seconds before).

This gives a maximum interval of 22 seconds between heartbeats if the last activity was just before TT was about to send a heartbeat request message (assuming those come 12 seconds after the last activity).

alaingilbert commented 11 years ago

This is brilliant :)

Izzmo commented 11 years ago

Hmm, interesting! What if the bot is sitting in a room with nothing going on though? No pm's, no songs playing, and no on talking?

alaingilbert commented 11 years ago

He will still receive the heartbeat requests from tt.fm, and then send an "updatePresence" on this event. (every ~12 seconds)

alaingilbert commented 11 years ago

See this conversation : https://github.com/alaingilbert/Turntable-API/commit/7351302751fcae2a69d0b5c54eba46a4ef1d6f17#commitcomment-2089645 Really interesting !

Izzmo commented 11 years ago

Ah, cool, makes sense!

bboe commented 11 years ago

I did notice that my bot's websocket was closed after some amount of inactivity (at least an hour). I had noticed that, however, prior to this change. It appears to only affect a room where the bot is the only one in the room, and not djing. I'll look into it more over the next few days.