Created
June 15, 2018 17:29
-
-
Save tiancheng91/8139efed20c0b1d236c2a015741fe3ea to your computer and use it in GitHub Desktop.
webtorrent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var idb = require('idb-chunk-store') | |
var WebTorrent = require('webtorrent') | |
var client = new WebTorrent() | |
//Sintel MagnetURI taken from https://webtorrent.io/ | |
var sintel = "magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F" | |
function addTorrent(info){ | |
var torrent = client.add(info, {"store": idb}) | |
torrent.on('metadata', ()=>{ | |
console.log(`[${torrent.infoHash}] Recieved metadata!`) | |
}) | |
torrent.on('ready', ()=>{ | |
console.log(`[${torrent.infoHash}] Store ready!`) | |
torrent.files.forEach((file)=>{ | |
file.appendTo('body') | |
}) | |
}) | |
torrent.on('done', ()=>{ | |
console.log(`[${torrent.infoHash}] Downloaded!`) | |
}) | |
return torrent | |
} | |
//Exposes client object to global namespace. | |
window.client = client; | |
//Adds addTorrent to global namespace to allow torrents for testing! | |
window.addTorrent = (...args)=>{addTorrent(...args);} | |
//Adds demo function to global namespace to run test using sintel MagnetURI. | |
window.demo = ()=>{addTorrent(sintel);} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
curl -XPOST -H "referer: https://appr.tc" -d "" https://networktraversal.googleapis.com/v1alpha/iceconfig?key=AIzaSyAJdh2HkajseEIltlZ3SIXO02Tze9sO3NY