Skip to content

Commit

Permalink
moving from jwplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
elvistony committed Oct 9, 2024
1 parent a341e3a commit 2d05659
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
55 changes: 46 additions & 9 deletions bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const trackerURL = 'wss://tracker.openwebtorrent.com';
const P2PT = require('p2pt')
const statusLed = document.getElementById('status-led');
const statusText = document.getElementById('status-text');
const videoplayer = document.getElementById('videoplayer');
const selfId = Math.random().toString(36).slice(2);
let p2pt;
let seekCooldown = false;
Expand All @@ -22,6 +23,8 @@ var bingePack = {
'desc':"Now Binging"
}

videoplayer.src = bingePack.video;

peer_template = {
id:'',
peer:false
Expand Down Expand Up @@ -60,6 +63,7 @@ function listen () {
});

p2pt.on('peerclose', (peer) => {
delete Peers[peer.id]
console.log(`Disconnected from ${peer.id}`);
// Change status to red
statusLed.style.backgroundColor = 'red';
Expand All @@ -83,24 +87,30 @@ function listen () {
return;
}
if(data.type == "bingePack"){
playerInstance.load([{
file: data.video,
image: data.image,
title: data.title,
description: data.desc
}]);
// playerInstance.load([{
// file: data.video,
// image: data.image,
// title: data.title,
// description: data.desc
// }]);
videoplayer.src = data.video
}
if(data.type == "play"){
playerInstance.play();
// playerInstance.play();
videoplayer.play()
}
if(data.type == "pause"){
playerInstance.pause();
// playerInstance.pause();
videoplayer.pause()
}
if(data.type == "seek"){
if(!seekCooldown){
seekCooldown=true
startSeekCooldown(5);
}
playerInstance.seek(data.position)
// playerInstance.seek(data.position);
videoplayer.currentTime = data.position;
videoplayer.pause();
}

});
Expand Down Expand Up @@ -130,6 +140,33 @@ function ping(data,type){

}

videoplayer.addEventListener('pause', (event) => {
console.log('Broadcasting Pause!');
ping({},'pause')
});

videoplayer.addEventListener('play', (event) => {
console.log('Broadcasting Play!');
ping({},'play')
});

videoplayer.addEventListener('complete', (event) => {
console.log('Broadcasting Finish!');
ping({},'complete')
});

videoplayer.addEventListener('seek', (event) => {
videoplayer.pause();
});


videoplayer.addEventListener('seeked', (event) => {
if(!seekCooldown){
position = videoplayer.currentTime;
console.log('Broadcasting seek position!',position);
ping({'position':position},'seek')
}
});



Expand Down
4 changes: 1 addition & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
<div class="status-led" id="status-led"></div>
<span id="status-text">Not connected to any peer</span>
</div>
<!-- Player -->
<div id="player"></div>

<video src="" controls style="height: 100%;" class="" id="videoplayer"></video>
</body>
<script src="/assets/js/jwplayer.js"></script>
<script src="/assets/js/script.js"></script>
Expand Down

0 comments on commit 2d05659

Please sign in to comment.