Skip to content

Instantly share code, notes, and snippets.

@tiancheng91
Created June 15, 2018 17:29
Show Gist options
  • Save tiancheng91/8139efed20c0b1d236c2a015741fe3ea to your computer and use it in GitHub Desktop.
Save tiancheng91/8139efed20c0b1d236c2a015741fe3ea to your computer and use it in GitHub Desktop.
webtorrent
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);}
@tiancheng91
Copy link
Author

curl -XPOST -H "referer: https://appr.tc" -d "" https://networktraversal.googleapis.com/v1alpha/iceconfig?key=AIzaSyAJdh2HkajseEIltlZ3SIXO02Tze9sO3NY

{
  "lifetimeDuration": "86400s",
  "iceServers": [
    {
      "urls": [
        "stun:cn1-stun.wilddog.com:3478",
        "stun:173.194.202.127:19302",
        "stun:[2607:F8B0:400E:C00::7F]:19302"
      ]
    },
    {
      "urls": [
        "turn:173.194.203.127:19305?transport=udp",
        "turn:[2607:F8B0:400E:C06::7F]:19305?transport=udp",
        "turn:173.194.203.127:19305?transport=tcp",
        "turn:[2607:F8B0:400E:C06::7F]:19305?transport=tcp"
      ],
      "username": "CLmdldkFEga1ZA4IdIgYqvGggqMKIICjBQ",
      "credential": "pmrX/7rkz64+O9DFsEwufhBXjNk="
    }
  ],
  "blockStatus": "NOT_BLOCKED",
  "iceTransportPolicy": "all"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment