Spaces:
Running
Running
teleop sync: hold master back for stuck-behind tiles (no more start-replay on slow bandwidth)
Browse files- teleopSample/sort_ep0.html +15 -17
teleopSample/sort_ep0.html
CHANGED
|
@@ -129,25 +129,23 @@ function activeSpan(t){ for(let i=0;i<SPANS.length;i++) if(t>=SPANS[i].start_s&&
|
|
| 129 |
let playing=false, raf=0, syncTimer=0, _lastCi=-2;
|
| 130 |
function inBuf(v,t){ const b=v.buffered; for(let i=0;i<b.length;i++) if(t>=b.start(i)-0.2&&t<=b.end(i)+0.2) return true; return false; }
|
| 131 |
function syncSlaves(t,hard){
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
if(v.paused&&!v.ended){ v.play().catch(()=>{}); }
|
| 136 |
-
const drift=v.currentTime-t, ad=Math.abs(drift);
|
| 137 |
-
if(
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
let tgt = inBuf(v,t) ? t
|
| 142 |
-
: (v.buffered.length ? Math.max(0, v.buffered.end(v.buffered.length-1)-0.25) : v.currentTime);
|
| 143 |
-
if(Math.abs(v.currentTime-tgt)>0.4){ try{ v.currentTime=tgt; }catch(e){} }
|
| 144 |
-
v.playbackRate=1;
|
| 145 |
-
} else if(ad>0.04){
|
| 146 |
-
v.playbackRate=Math.max(0.5,Math.min(1.8, 1-drift*3)); // trim toward master
|
| 147 |
-
} else {
|
| 148 |
-
v.playbackRate=1;
|
| 149 |
-
}
|
| 150 |
}
|
|
|
|
|
|
|
|
|
|
| 151 |
}
|
| 152 |
function seekTo(t){ t=Math.max(0,Math.min(DUR-0.01,t));
|
| 153 |
try{ if(Math.abs(master.currentTime-t)>0.05) master.currentTime=t; }catch(e){}
|
|
|
|
| 129 |
let playing=false, raf=0, syncTimer=0, _lastCi=-2;
|
| 130 |
function inBuf(v,t){ const b=v.buffered; for(let i=0;i<b.length;i++) if(t>=b.start(i)-0.2&&t<=b.end(i)+0.2) return true; return false; }
|
| 131 |
function syncSlaves(t,hard){
|
| 132 |
+
if(hard){
|
| 133 |
+
for(const v of vids){ if(v.readyState<1) continue; v.playbackRate=1;
|
| 134 |
+
if(v!==master && !v.seeking && Math.abs(v.currentTime-t)>0.06){ try{v.currentTime=t;}catch(e){} } }
|
| 135 |
+
return;
|
| 136 |
+
}
|
| 137 |
+
let worstLag = 0;
|
| 138 |
+
for(const v of vids){ if(v===master||v.readyState<1||!playing) continue;
|
| 139 |
if(v.paused&&!v.ended){ v.play().catch(()=>{}); }
|
| 140 |
+
const drift=v.currentTime-t, ad=Math.abs(drift); // drift<0 => this tile is behind
|
| 141 |
+
if(drift < -0.3) worstLag = Math.max(worstLag, -drift);
|
| 142 |
+
if(ad>1.0 && !v.seeking && inBuf(v,t)){ try{v.currentTime=t;}catch(e){} v.playbackRate=1; }
|
| 143 |
+
else if(ad>0.04){ v.playbackRate=Math.max(0.5,Math.min(1.8, 1-drift*3)); }
|
| 144 |
+
else v.playbackRate=1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
}
|
| 146 |
+
// a tile stuck far behind can't be seeked forward (still downloading) — hold the
|
| 147 |
+
// master back so all views stay together instead of the laggards looping the start
|
| 148 |
+
if(master && playing) master.playbackRate = worstLag>1.5 ? 0.25 : (worstLag>0.6 ? 0.6 : 1);
|
| 149 |
}
|
| 150 |
function seekTo(t){ t=Math.max(0,Math.min(DUR-0.01,t));
|
| 151 |
try{ if(Math.abs(master.currentTime-t)>0.05) master.currentTime=t; }catch(e){}
|