const start_time = current["start_time"];
const duration = current["curr"]["duration"];
const elapsed = Math.floor(curr_time - start_time);
- if (elapsed >= 0 && elapsed < duration)
+
+ // Check if we need to refresh the URI
+ const diffTooBig = Math.abs(Math.floor(Video.currentTime) - elapsed) > 3;
+ const srcChanged = Video.src.replace(/#t=[0-9]+$/, '') != encodeURI(document.location + current["curr"]["path"]);
+
+ if (diffTooBig || srcChanged)
{
- Video.src = current["curr"]["path"] + "#t=" + Math.floor(elapsed);
+ Video.src = current["curr"]["path"] + "#t=" + elapsed;
if (current["playing"])
{
Video.play();
ws.onmessage = (event)=>{
const msg = JSON.parse(event.data);
- current = msg;
+ if (msg["cmd"] == "play")
+ {
+ current = msg;
+ }
updatePlayer();
};