From 02732ddd58801de209d1d8179a744772d39a0cc8 Mon Sep 17 00:00:00 2001 From: elvistony Date: Thu, 10 Oct 2024 12:27:32 +0100 Subject: [PATCH] Fix for p2p reflection signals --- bundle.js | 40 +++++++++++++++++++++++++++++----------- play/index.html | 2 +- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/bundle.js b/bundle.js index 7a49471..82475db 100644 --- a/bundle.js +++ b/bundle.js @@ -23,13 +23,9 @@ var bingePack = { 'unset':true, } -// - videoplayer.src = bingePack.video; - var peer_template = { id:'', peer:false } - function init (roomId) { let announceURLs = [ // "wss://tracker.sloppyta.co:443/announce", @@ -73,6 +69,7 @@ function listen () { p2pt.on('msg', (peer, msg) => { // console.log('RECEIVE:',peer,msg) const data = JSON.parse(msg); + const isVideoPlaying = videoplayer => !!(videoplayer.currentTime > 0 && !videoplayer.paused && !videoplayer.ended && videoplayer.readyState > 2); if(data.type == "welcomeBingePack"){ if(bingePack.unset){ console.log('Setting New Bingepack'); @@ -85,17 +82,29 @@ function listen () { console.log('Forced Binge Pack Recieved'); bingePack.unset=false; bingePack = data; - videoplayer.setAttribute("src", bingePack.video); - + videoplayer.setAttribute("src", bingePack.video); } if(data.from == selfId){ return; } - if(data.type == "play"){ videoplayer.play(); } - if(data.type == "pause"){ videoplayer.pause() } + if(data.type == "play"){ + if(!isVideoPlaying){ + videoplayer.play(); + } + } + if(data.type == "pause"){ + if(isVideoPlaying){ + videoplayer.pause(); + } + // seeker(data.position) + } if(data.type == "seek"){ if(!seekCooldown){ startSeekCooldown(5); } - // videoplayer.currentTime = data.position; - seeker(data.position) - videoplayer.pause(); + if(data.position>0){ + seeker(data.position) + } + + if(isVideoPlaying){ + videoplayer.pause(); + } } }); p2pt.start() @@ -119,6 +128,8 @@ function ping(data,type){ videoplayer.addEventListener('pause', (event) => { // console.log('Broadcasting Pause!'); + // position = videoplayer.currentTime; + // ping({'position':position},'pause'); ping({},'pause') }); @@ -156,6 +167,13 @@ document.querySelector('.start-button').addEventListener('click',()=>{ ping({'ready':true},'ready'); }) +document.querySelector('#syncNow').addEventListener('click',()=>{ + console.log('Syncing Timestamp...') + position = videoplayer.currentTime; + ping({position:position},'seek'); +}) + + var adminVideoChange = document.getElementById('fire-video-change'); adminVideoChange.addEventListener('click',()=>{ diff --git a/play/index.html b/play/index.html index 60d9d85..73965ec 100644 --- a/play/index.html +++ b/play/index.html @@ -28,7 +28,7 @@ -