mirror of https://github.com/calzoneman/sync.git
Fix leader function
This commit is contained in:
parent
22b10e3ffa
commit
4fe8ab164d
|
@ -912,11 +912,13 @@ Channel.prototype.jumpTo = function(pos) {
|
||||||
}
|
}
|
||||||
if(this.media) {
|
if(this.media) {
|
||||||
delete this.media["currentTime"];
|
delete this.media["currentTime"];
|
||||||
|
delete this.media["paused"];
|
||||||
}
|
}
|
||||||
this.position = pos;
|
this.position = pos;
|
||||||
var oid = this.media ? this.media.id : "";
|
var oid = this.media ? this.media.id : "";
|
||||||
this.media = this.queue[this.position];
|
this.media = this.queue[this.position];
|
||||||
this.media.currentTime = -1;
|
this.media.currentTime = -1;
|
||||||
|
this.media.paused = false;
|
||||||
|
|
||||||
this.sendAll("changeMedia", this.media.fullupdate());
|
this.sendAll("changeMedia", this.media.fullupdate());
|
||||||
this.sendAll("updatePlaylistIdx", {
|
this.sendAll("updatePlaylistIdx", {
|
||||||
|
|
1
media.js
1
media.js
|
@ -86,6 +86,7 @@ Media.prototype.fullupdate = function() {
|
||||||
duration: this.duration,
|
duration: this.duration,
|
||||||
type: this.type,
|
type: this.type,
|
||||||
currentTime: this.currentTime,
|
currentTime: this.currentTime,
|
||||||
|
paused: this.paused,
|
||||||
queueby: this.queueby,
|
queueby: this.queueby,
|
||||||
temp: this.temp
|
temp: this.temp
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,8 +48,13 @@ Media.prototype.initYouTube = function() {
|
||||||
socket.emit("playerReady");
|
socket.emit("playerReady");
|
||||||
},
|
},
|
||||||
onStateChange: function(ev) {
|
onStateChange: function(ev) {
|
||||||
PLAYER.paused = (ev.data == YT.PlayerState.PAUSED);
|
if(PLAYER.paused && ev.data != YT.PlayerState.PAUSED
|
||||||
if(PLAYER.paused) {
|
|| !PLAYER.paused && ev.data == YT.PlayerState.PAUSED) {
|
||||||
|
PLAYER.paused = (ev.data == YT.PlayerState.PAUSED);
|
||||||
|
sendVideoUpdate();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PLAYER.paused = (ev.data == YT.PlayerState.PAUSED);
|
||||||
}
|
}
|
||||||
if(LEADER && ev.data == YT.PlayerState.ENDED) {
|
if(LEADER && ev.data == YT.PlayerState.ENDED) {
|
||||||
socket.emit("playNext");
|
socket.emit("playNext");
|
||||||
|
@ -109,10 +114,12 @@ Media.prototype.initVimeo = function() {
|
||||||
|
|
||||||
this.player.addEvent("pause", function() {
|
this.player.addEvent("pause", function() {
|
||||||
PLAYER.paused = true;
|
PLAYER.paused = true;
|
||||||
|
sendVideoUpdate();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.player.addEvent("play", function() {
|
this.player.addEvent("play", function() {
|
||||||
PLAYER.paused = false;
|
PLAYER.paused = false;
|
||||||
|
sendVideoUpdate();
|
||||||
});
|
});
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
@ -130,7 +137,10 @@ Media.prototype.initVimeo = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getTime = function(callback) {
|
this.getTime = function(callback) {
|
||||||
this.player.api("getCurrentTime", callback);
|
// Vimeo api returns time as a string because fuck logic
|
||||||
|
this.player.api("getCurrentTime", function(time) {
|
||||||
|
callback(parseFloat(time));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.seek = function(time) {
|
this.seek = function(time) {
|
||||||
|
@ -157,10 +167,12 @@ Media.prototype.initDailymotion = function() {
|
||||||
|
|
||||||
this.player.addEventListener("pause", function(e) {
|
this.player.addEventListener("pause", function(e) {
|
||||||
PLAYER.paused = true;
|
PLAYER.paused = true;
|
||||||
|
sendVideoUpdate();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.player.addEventListener("playing", function(e) {
|
this.player.addEventListener("playing", function(e) {
|
||||||
PLAYER.paused = false;
|
PLAYER.paused = false;
|
||||||
|
sendVideoUpdate();
|
||||||
});
|
});
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
@ -205,10 +217,12 @@ Media.prototype.initSoundcloud = function() {
|
||||||
|
|
||||||
this.player.bind(SC.Widget.Events.PAUSE, function() {
|
this.player.bind(SC.Widget.Events.PAUSE, function() {
|
||||||
PLAYER.paused = true;
|
PLAYER.paused = true;
|
||||||
|
sendVideoUpdate();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.player.bind(SC.Widget.Events.PLAY, function() {
|
this.player.bind(SC.Widget.Events.PLAY, function() {
|
||||||
PLAYER.paused = false;
|
PLAYER.paused = false;
|
||||||
|
sendVideoUpdate();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.player.bind(SC.Widget.Events.FINISH, function() {
|
this.player.bind(SC.Widget.Events.FINISH, function() {
|
||||||
|
@ -353,9 +367,10 @@ Media.prototype.update = function(data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(data.paused) {
|
if(data.paused) {
|
||||||
|
this.seek(data.currentTime);
|
||||||
this.pause();
|
this.pause();
|
||||||
}
|
}
|
||||||
else if(!this.paused) {
|
else {
|
||||||
this.play();
|
this.play();
|
||||||
}
|
}
|
||||||
if(LEADER) {
|
if(LEADER) {
|
||||||
|
@ -364,6 +379,7 @@ Media.prototype.update = function(data) {
|
||||||
this.getTime(function(seconds) {
|
this.getTime(function(seconds) {
|
||||||
var time = data.currentTime;
|
var time = data.currentTime;
|
||||||
var diff = time - seconds || time;
|
var diff = time - seconds || time;
|
||||||
|
console.log(this);
|
||||||
|
|
||||||
if(diff > USEROPTS.sync_accuracy) {
|
if(diff > USEROPTS.sync_accuracy) {
|
||||||
this.seek(time);
|
this.seek(time);
|
||||||
|
|
Loading…
Reference in New Issue