Skip to content

Commit

Permalink
Fix for p2p reflection signals
Browse files Browse the repository at this point in the history
  • Loading branch information
elvistony committed Oct 10, 2024
1 parent 145956c commit 02732dd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
40 changes: 29 additions & 11 deletions bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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');
Expand All @@ -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()
Expand All @@ -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')
});

Expand Down Expand Up @@ -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',()=>{
Expand Down
2 changes: 1 addition & 1 deletion play/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<button class="control-button control-button-mini" id="volume-control">
<i class="fas fa-upload"></i>
</button>
<button class="control-button control-button-mini" id="sync-playback">
<button class="control-button control-button-mini" id="syncNow">
<i class="fas fa-refresh" ></i>
</button>
<button id="fullscreenBtn" class="control-button">
Expand Down

0 comments on commit 02732dd

Please sign in to comment.