valor/layouts/shortcodes/webtorrent-video.html

46 lines
1.4 KiB
HTML
Raw Normal View History

2022-10-07 23:03:09 -04:00
<style>
#wtmedia{
width:100%;
}
#wtmedia video{
width:100%;
}
</style>
2022-08-17 14:47:54 -04:00
<script src="/webtorrent.js"></script>
2022-10-07 23:03:09 -04:00
<div class="webtorrent">
<noscript>
<video controls>
<source src={{.Get "source"}}>
</video>
</noscript>
<div id="wtmedia">
</div>
<div>
2022-11-09 15:44:31 -05:00
<span id="torrent-info">Waiting for peers.</span>
<span id="torrent-peers"></span>
<span id="torrent-progress"></span>
2022-10-07 23:03:09 -04:00
</div>
2022-08-17 14:47:54 -04:00
</div>
<script>
2022-11-09 15:44:31 -05:00
function updateData(torrent) {
if (torrent.numPeers > 0) {
document.getElementById('torrent-info').innerHTML="This video is being served with webtorrent";
document.getElementById('torrent-peers').innerHTML="Peers:"+torrent.numPeers;
}
}
2022-10-07 23:03:09 -04:00
const client = new WebTorrent();
2022-11-09 15:44:31 -05:00
const magnetURI = "{{.Get "magnet"}}";
torrent = client.add(magnetURI, function (torrent) {
2022-08-17 14:47:54 -04:00
// Got torrent metadata!
2022-11-09 15:44:31 -05:00
torrent.addWebSeed("{{.Get "source"}}");
console.log("Torrent Peers: "+torrent.numPeers);
2022-10-07 23:03:09 -04:00
console.log('Client is downloading:', torrent.infoHash);
2022-08-17 14:47:54 -04:00
torrent.files.forEach(function (file) {
// Display the file by appending it to the DOM. Supports video, audio, images, and
// more. Specify a container element (CSS selector or reference to DOM node).
2022-10-07 23:03:09 -04:00
file.appendTo('#wtmedia');
2022-08-17 14:47:54 -04:00
})
2022-11-09 15:44:31 -05:00
2022-10-07 23:03:09 -04:00
});
2022-11-09 15:44:31 -05:00
window.setInterval(updateData,250,torrent);
2022-10-07 23:03:09 -04:00
</script>