-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
68 lines (61 loc) · 2.28 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!doctype html>
<html>
<head>
<title>WebTorrent – Simple File Sending Example</title>
<style>
body {
font-family: sans-serif;
}
</style>
</head>
<body>
<h1>Streaming File Transfer over <a href="http://webtorrent.io">WebTorrent</a></h1>
<p>Download files using the WebTorrent protocol (BitTorrent over WebRTC).</p>
<h2>Log</h2>
<div class="log"></div>
<h2>Start downloading</h2>
<form>
<label for="torrentId">Download from a magnet link or info hash</label>
<input name="torrentId", placeholder="magnet:">
<button type="submit">Download</button>
</form>
<br>
<p><small>Code is available on <a href="https://github.com/feross/instant.io">GitHub</a> under MIT License. Run <code>localStorage.debug = '*'</code> in the console and refresh to enable verbose logs.</small></p>
<!-- Include the latest version of WebTorrent -->
<script src="https://cdn.jsdelivr.net/webtorrent/latest/webtorrent.min.js"></script>
<script>
var client = new WebTorrent()
// Print warnings and errors to the console
client.on('warning', function (err) {
console.log('WARNING: ' + err.message)
})
client.on('error', function (err) {
console.error('ERROR: ' + err.message)
})
document.querySelector('form').addEventListener('submit', onSubmit)
function onSubmit (e) {
e.preventDefault() // Prevent page refresh
var torrentId = document.querySelector('form input[name=torrentId]').value
client.add(torrentId, onTorrent)
}
function onTorrent (torrent) {
alert('torrent')
log(
'Torrent info hash: ' + torrent.infoHash + ' ' +
'<a href="' + torrent.magnetURI + '" target="_blank">[Magnet URI]</a> ' +
'<a href="' + torrent.torrentFileURL + '" target="_blank" download="' + /*torrentFileName + */'">[Download .torrent]</a>'
)
torrent.files.forEach(function (file) {
file.appendTo('.log')
var meshID=file.name.split('.')[0]
console.log('i know',meshID)
})
}
function log (str) {
var p = document.createElement('p')
p.innerHTML = str
document.querySelector('.log').appendChild(p)
}
</script>
</body>
</html>