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
14
channel.js
14
channel.js
|
@ -711,8 +711,9 @@ Channel.prototype.playNext = function() {
|
|||
}
|
||||
|
||||
this.position++;
|
||||
var oid = this.media ? this.media.id : "";
|
||||
this.media = this.queue[this.position];
|
||||
this.media.currentTime = 0;
|
||||
this.media.currentTime = -1;
|
||||
|
||||
this.sendAll("mediaUpdate", this.media.packupdate());
|
||||
this.sendAll("updatePlaylistIdx", {
|
||||
|
@ -725,7 +726,9 @@ Channel.prototype.playNext = function() {
|
|||
&& this.media.type != "li"
|
||||
&& this.media.type != "rt") {
|
||||
this.time = new Date().getTime();
|
||||
mediaUpdate(this, this.media.id);
|
||||
if(this.media.id != oid) {
|
||||
mediaUpdate(this, this.media.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -753,8 +756,9 @@ Channel.prototype.jumpTo = function(pos) {
|
|||
|
||||
var old = this.position;
|
||||
this.position = pos;
|
||||
var oid = this.media ? this.media.id : "";
|
||||
this.media = this.queue[this.position];
|
||||
this.media.currentTime = 0;
|
||||
this.media.currentTime = -1;
|
||||
|
||||
this.sendAll("mediaUpdate", this.media.packupdate());
|
||||
this.sendAll("updatePlaylistIdx", {
|
||||
|
@ -767,7 +771,9 @@ Channel.prototype.jumpTo = function(pos) {
|
|||
&& this.media.type != "li"
|
||||
&& this.media.type != "rt") {
|
||||
this.time = new Date().getTime();
|
||||
mediaUpdate(this, this.media.id);
|
||||
if(this.media.id != oid) {
|
||||
mediaUpdate(this, this.media.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
var Media = function(data) {
|
||||
this.id = data.id;
|
||||
this.type = data.type;
|
||||
this.lastdiff = 0;
|
||||
|
||||
switch(this.type) {
|
||||
case "yt":
|
||||
|
@ -279,15 +280,28 @@ Media.prototype.initRTMP = function() {
|
|||
|
||||
Media.prototype.update = function(data) {
|
||||
if(data.id != this.id) {
|
||||
if(data.currentTime < 0) {
|
||||
data.currentTime = 0;
|
||||
}
|
||||
this.load(data);
|
||||
}
|
||||
if(data.paused) {
|
||||
this.pause();
|
||||
}
|
||||
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(!LEADER) {
|
||||
this.seek(data.currentTime);
|
||||
this.seek(time);
|
||||
}
|
||||
}
|
||||
}.bind(this));
|
||||
|
|
Loading…
Reference in New Issue