У меня есть небольшой HTML-файл, который позволяет вам транслировать «Богемную рапсодию» в браузере:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>WebTorrent video player</title>
<style>
#output video {
width: 100%;
</style>
</head>
<body>
<div id="hero">
<div id="output">
<div id="progressBar"></div>
</div>
<div id="status">
<div>
<span class="show-leech">Downloading </span>
<span class="show-seed">Seeding </span>
<code>
</code>
<span class="show-leech"> from </span>
<span class="show-seed"> to </span>
<code id="numPeers">0 peers</code>.
</div>
<div>
<code id="downloaded"></code>
of <code id="total"></code>
— <span id="remaining"></span><br/>
↘<code id="downloadSpeed">0 b/s</code>
/ ↗<code id="uploadSpeed">0 b/s</code>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/webtorrent/latest/webtorrent.min.js"></script>
<script src="http://momentjs.com/downloads/moment.min.js"></script>
<script>
var torrentId = 'magnet:?xt=urn:btih:e99cac0add8decf33b48ccdb96f700209eb675d9&dn=Bohemian+Rhapsody+(2018)+%5BWEBRip%5D+%5B1080p%5D+%5BYTS.AM%5D&tr=udp%3A%2F%2Fglotorrents.pw%3A6969%2Fannounce&tr=udp%3A%2F%2Fp4p.arenabg.ch%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com'
var client = new WebTorrent()
var $body = document.body
var $progressBar = document.querySelector('#progressBar')
var $numPeers = document.querySelector('#numPeers')
var $downloaded = document.querySelector('#downloaded')
var $total = document.querySelector('#total')
var $remaining = document.querySelector('#remaining')
var $uploadSpeed = document.querySelector('#uploadSpeed')
var $downloadSpeed = document.querySelector('#downloadSpeed')
client.add(torrentId, function (torrent) {
var file = torrent.files.find(function (file) {
return file.name.endsWith('.mp4')
})
file.appendTo('#output')
torrent.on('done', onDone)
setInterval(onProgress, 500)
onProgress()
function onProgress () {
$numPeers.innerHTML = torrent.numPeers + (torrent.numPeers === 1 ? ' peer' : ' peers')
var percent = Math.round(torrent.progress * 100 * 100) / 100
$progressBar.style.width = percent + '%'
$downloaded.innerHTML = prettyBytes(torrent.downloaded)
$total.innerHTML = prettyBytes(torrent.length)
var remaining
if (torrent.done) {
remaining = 'Done.'
} else {
remaining = moment.duration(torrent.timeRemaining / 1000, 'seconds').humanize()
remaining = remaining[0].toUpperCase() + remaining.substring(1) + ' remaining.'
}
$remaining.innerHTML = remaining
$downloadSpeed.innerHTML = prettyBytes(torrent.downloadSpeed) + '/s'
$uploadSpeed.innerHTML = prettyBytes(torrent.uploadSpeed) + '/s'
}
function onDone () {
$body.className += ' is-seed'
onProgress()
}
})
function prettyBytes(num) {
var exponent, unit, neg = num < 0, units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
if (neg) num = -num
if (num < 1) return (neg ? '-' : '') + num + ' B'
exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), units.length - 1)
num = Number((num / Math.pow(1000, exponent)).toFixed(2))
unit = units[exponent]
return (neg ? '-' : '') + num + ' ' + unit
}
</script>
</body>
</html>
Он отлично работает в версии Chrome для настольных ПК, но не работает в Chrome для Androidи iOS.Я действительно не понимаю, почему фильмы, подобные этим, не работают на мобильных устройствах, но фильмы типа sintel (https://webtorrent.io/torrents/sintel.torrent) делают. Спасибо !!