freedom/layouts/shortcodes/webtorrent-video.html

40 lines
1.1 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>
Peers:<span id="Peers"></span>
</div>
2022-08-17 14:50:07 -04:00
</div>
<script>
2022-09-23 02:40:30 -04:00
function updateData(torrent) {
document.getElementById('Peers').text=torrent.numPeers;
}
const client = new WebTorrent();
const magnetURI = {{.Get "magnet"}};
2022-08-17 14:50:07 -04:00
client.add(magnetURI, function (torrent) {
// Got torrent metadata!
2022-09-23 02:40:30 -04:00
torrent.addWebSeed({{.Get "source"}});
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-09-23 02:40:30 -04:00
window.setInterval
});
</script>