Fix server not taking over after leadership is removed; fix soundcloud sync bug [untested]

This commit is contained in:
calzoneman 2013-03-05 12:37:06 -06:00
parent 7d36f3e87a
commit 1e1e51a4ca
2 changed files with 4 additions and 3 deletions

View File

@ -355,7 +355,7 @@ Channel.prototype.playNext = function() {
Channel.prototype.update = function(data) { Channel.prototype.update = function(data) {
if(this.currentMedia == null) { if(this.currentMedia == null) {
this.currentMedia = new Media(data.id, data.title, data.seconds, data.type); this.currentMedia = new Media(data.id, data.title, data.seconds, data.type);
this.currentMedia.currentTIme = data.currentTime; this.currentMedia.currentTime = data.currentTime;
} }
else else
this.currentMedia.currentTime = data.seconds; this.currentMedia.currentTime = data.seconds;
@ -476,6 +476,7 @@ Channel.prototype.changeLeader = function(name) {
this.broadcastRankUpdate(old); this.broadcastRankUpdate(old);
} }
if(name == "") { if(name == "") {
channelVideoUpdate(this, this.currentMedia.id);
return; return;
} }
for(var i = 0; i < this.users.length; i++) { for(var i = 0; i < this.users.length; i++) {
@ -563,6 +564,7 @@ function channelVideoUpdate(chan, id) {
return; return;
// Add dt since last update // Add dt since last update
chan.currentMedia.currentTime += (new Date().getTime() - time)/1000.0; chan.currentMedia.currentTime += (new Date().getTime() - time)/1000.0;
time = new Date().getTime();
// Video over, move on to next // Video over, move on to next
if(chan.currentMedia.currentTime > chan.currentMedia.seconds) { if(chan.currentMedia.currentTime > chan.currentMedia.seconds) {
chan.playNext(); chan.playNext();
@ -571,7 +573,6 @@ function channelVideoUpdate(chan, id) {
else if(i % 5 == 0) else if(i % 5 == 0)
chan.sendAll('mediaUpdate', chan.currentMedia.packupdate()); chan.sendAll('mediaUpdate', chan.currentMedia.packupdate());
i++; i++;
time = new Date().getTime();
// Do it all over again in about a second // Do it all over again in about a second
setTimeout(function() { channelVideoUpdate(chan, id); }, 1000); setTimeout(function() { channelVideoUpdate(chan, id); }, 1000);
} }

View File

@ -264,7 +264,7 @@ function updateSC(data) {
// Soundcloud's API is async // Soundcloud's API is async
// Query the playback position and compare that with the sync packet // Query the playback position and compare that with the sync packet
PLAYER.getPosition(function(pos) { PLAYER.getPosition(function(pos) {
if(Math.abs(pos - data.currentTime * 1000) > SYNC_THRESHOLD) { if(Math.abs(pos / 1000 - data.currentTime) > SYNC_THRESHOLD) {
PLAYER.seekTo(data.currentTime * 1000); PLAYER.seekTo(data.currentTime * 1000);
} }
}); });