freedom/layouts/shortcodes/webtorrent-video.html

46 lines
1.4 KiB
HTML
Raw Normal View History

2022-09-23 02:40:30 -04:00
<style>
#wtmedia{
width:100%;
}
#wtmedia video{
width:100%;
}
</style>
2022-08-17 14:50:07 -04:00
<script src="/webtorrent.js"></script>
2022-09-23 02:40:30 -04:00
<div class="webtorrent">
<noscript>
<video controls>
<source src={{.Get "source"}}>
</video>
</noscript>
<div id="wtmedia">
</div>
<div>
2022-10-05 05:59:24 -04:00
<span id="torrent-info">Waiting for peers.</span>
<span id="torrent-peers"></span>
<span id="torrent-progress"></span>
2022-09-23 02:40:30 -04:00
</div>
2022-08-17 14:50:07 -04:00
</div>
<script>
2022-09-23 02:40:30 -04:00
function updateData(torrent) {
2022-10-05 05:59:24 -04:00
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-09-23 02:40:30 -04:00
}
const client = new WebTorrent();
2022-10-05 05:59:24 -04:00
const magnetURI = "{{.Get "magnet"}}";
torrent = client.add(magnetURI, function (torrent) {
2022-08-17 14:50:07 -04:00
// Got torrent metadata!
2022-10-05 05:59:24 -04:00
torrent.addWebSeed("{{.Get "source"}}");
2022-09-23 02:40:30 -04:00
console.log("Torrent Peers: "+torrent.numPeers);
console.log('Client is downloading:', torrent.infoHash);
2022-08-17 14:50:07 -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-09-23 02:40:30 -04:00
file.appendTo('#wtmedia');
2022-08-17 14:50:07 -04:00
})
2022-10-05 05:59:24 -04:00
2022-09-23 02:40:30 -04:00
});
2022-10-05 05:59:24 -04:00
window.setInterval(updateData,250,torrent);
2022-09-23 02:40:30 -04:00
</script>