mirror of https://github.com/calzoneman/sync.git
Fix channel update function, start working on compensative synch
This commit is contained in:
parent
0d7da77715
commit
35fb504847
10
channel.js
10
channel.js
|
@ -711,8 +711,9 @@ Channel.prototype.playNext = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.position++;
|
this.position++;
|
||||||
|
var oid = this.media ? this.media.id : "";
|
||||||
this.media = this.queue[this.position];
|
this.media = this.queue[this.position];
|
||||||
this.media.currentTime = 0;
|
this.media.currentTime = -1;
|
||||||
|
|
||||||
this.sendAll("mediaUpdate", this.media.packupdate());
|
this.sendAll("mediaUpdate", this.media.packupdate());
|
||||||
this.sendAll("updatePlaylistIdx", {
|
this.sendAll("updatePlaylistIdx", {
|
||||||
|
@ -725,8 +726,10 @@ Channel.prototype.playNext = function() {
|
||||||
&& this.media.type != "li"
|
&& this.media.type != "li"
|
||||||
&& this.media.type != "rt") {
|
&& this.media.type != "rt") {
|
||||||
this.time = new Date().getTime();
|
this.time = new Date().getTime();
|
||||||
|
if(this.media.id != oid) {
|
||||||
mediaUpdate(this, this.media.id);
|
mediaUpdate(this, this.media.id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel.prototype.tryPlayNext = function(user) {
|
Channel.prototype.tryPlayNext = function(user) {
|
||||||
|
@ -753,8 +756,9 @@ Channel.prototype.jumpTo = function(pos) {
|
||||||
|
|
||||||
var old = this.position;
|
var old = this.position;
|
||||||
this.position = pos;
|
this.position = pos;
|
||||||
|
var oid = this.media ? this.media.id : "";
|
||||||
this.media = this.queue[this.position];
|
this.media = this.queue[this.position];
|
||||||
this.media.currentTime = 0;
|
this.media.currentTime = -1;
|
||||||
|
|
||||||
this.sendAll("mediaUpdate", this.media.packupdate());
|
this.sendAll("mediaUpdate", this.media.packupdate());
|
||||||
this.sendAll("updatePlaylistIdx", {
|
this.sendAll("updatePlaylistIdx", {
|
||||||
|
@ -767,8 +771,10 @@ Channel.prototype.jumpTo = function(pos) {
|
||||||
&& this.media.type != "li"
|
&& this.media.type != "li"
|
||||||
&& this.media.type != "rt") {
|
&& this.media.type != "rt") {
|
||||||
this.time = new Date().getTime();
|
this.time = new Date().getTime();
|
||||||
|
if(this.media.id != oid) {
|
||||||
mediaUpdate(this, this.media.id);
|
mediaUpdate(this, this.media.id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel.prototype.tryJumpTo = function(user, data) {
|
Channel.prototype.tryJumpTo = function(user, data) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
var Media = function(data) {
|
var Media = function(data) {
|
||||||
this.id = data.id;
|
this.id = data.id;
|
||||||
this.type = data.type;
|
this.type = data.type;
|
||||||
|
this.lastdiff = 0;
|
||||||
|
|
||||||
switch(this.type) {
|
switch(this.type) {
|
||||||
case "yt":
|
case "yt":
|
||||||
|
@ -279,15 +280,28 @@ Media.prototype.initRTMP = function() {
|
||||||
|
|
||||||
Media.prototype.update = function(data) {
|
Media.prototype.update = function(data) {
|
||||||
if(data.id != this.id) {
|
if(data.id != this.id) {
|
||||||
|
if(data.currentTime < 0) {
|
||||||
|
data.currentTime = 0;
|
||||||
|
}
|
||||||
this.load(data);
|
this.load(data);
|
||||||
}
|
}
|
||||||
if(data.paused) {
|
if(data.paused) {
|
||||||
this.pause();
|
this.pause();
|
||||||
}
|
}
|
||||||
this.getTime(function(seconds) {
|
this.getTime(function(seconds) {
|
||||||
|
var time = data.currentTime;
|
||||||
|
if(readCookie("sync_compensate")) {
|
||||||
|
var diff = time - seconds;
|
||||||
|
if(diff > 0) {
|
||||||
|
diff = diff > 5 ? 5 : diff;
|
||||||
|
time += diff;
|
||||||
|
diff = (diff + this.lastdiff) / 2 || 0;
|
||||||
|
this.lastdiff = diff;
|
||||||
|
}
|
||||||
|
}
|
||||||
if(Math.abs(data.currentTime - seconds) > SYNC_THRESHOLD) {
|
if(Math.abs(data.currentTime - seconds) > SYNC_THRESHOLD) {
|
||||||
if(!LEADER) {
|
if(!LEADER) {
|
||||||
this.seek(data.currentTime);
|
this.seek(time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
Loading…
Reference in New Issue