diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2016-02-14 11:47:34 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2016-02-14 11:47:34 +0300 |
commit | a9a9a1fb5f27d9b97a738ffa36bf8809a6b26686 (patch) | |
tree | acb1b96728702df6fa767b3941b7799eb6b972ce /webtorrent.min.js | |
parent | f5f77d655bf8c5ec78ca89c0691618277f73ea5b (diff) |
build
Diffstat (limited to 'webtorrent.min.js')
-rw-r--r-- | webtorrent.min.js | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/webtorrent.min.js b/webtorrent.min.js index 13870ac..48df8fa 100644 --- a/webtorrent.min.js +++ b/webtorrent.min.js @@ -1,9 +1,8 @@ -(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var t;if(typeof window!=="undefined"){t=window}else if(typeof global!=="undefined"){t=global}else if(typeof self!=="undefined"){t=self}else{t=this}t.WebTorrent=e()}})(function(){var e,t,r;return function n(e,t,r){function i(s,a){if(!t[s]){if(!e[s]){var f=typeof require=="function"&&require;if(!a&&f)return f(s,!0);if(o)return o(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var c=t[s]={exports:{}};e[s][0].call(c.exports,function(t){var r=e[s][1][t];return i(r?r:t)},c,c.exports,n,e,t,r)}return t[s].exports}var o=typeof require=="function"&&require;for(var s=0;s<r.length;s++)i(r[s]);return i}({1:[function(e,t,r){(function(e){t.exports=function(t,r){var n=[];t.on("data",function(e){n.push(e)});t.once("end",function(){if(r)r(null,e.concat(n));r=null});t.once("error",function(e){if(r)r(e);r=null})}}).call(this,e("buffer").Buffer)},{buffer:26}],2:[function(e,t,r){t.exports=s;var n=e("debug")("webtorrent:file-stream");var i=e("inherits");var o=e("readable-stream");i(s,o.Readable);function s(e,t){o.Readable.call(this,t);this.destroyed=false;this._torrent=e._torrent;var r=t&&t.start||0;var n=t&&t.end&&t.end<e.length?t.end:e.length-1;var i=e._torrent.pieceLength;this._startPiece=(r+e.offset)/i|0;this._endPiece=(n+e.offset)/i|0;this._piece=this._startPiece;this._offset=r+e.offset-this._startPiece*i;this._missing=n-r+1;this._reading=false;this._notifying=false;this._criticalLength=Math.min(1024*1024/i|0,2)}s.prototype._read=function(){if(this._reading)return;this._reading=true;this._notify()};s.prototype._notify=function(){var e=this;if(!e._reading||e._missing===0)return;if(!e._torrent.bitfield.get(e._piece)){return e._torrent.critical(e._piece,e._piece+e._criticalLength)}if(e._notifying)return;e._notifying=true;var t=e._piece;e._torrent.store.get(t,function(r,i){e._notifying=false;if(e.destroyed)return;if(r)return e.destroy(r);n("read %s (length %s) (err %s)",t,i.length,r&&r.message);if(e._offset){i=i.slice(e._offset);e._offset=0}if(e._missing<i.length){i=i.slice(0,e._missing)}e._missing-=i.length;n("pushing buffer of length %s",i.length);e._reading=false;e.push(i);if(e._missing===0)e.push(null)});e._piece+=1};s.prototype.destroy=function(){if(this.destroyed)return;this.destroyed=true;if(!this._torrent.destroyed){this._torrent.deselect(this._startPiece,this._endPiece,true)}}},{debug:71,inherits:79,"readable-stream":109}],3:[function(e,t,r){(function(r){t.exports=d;var n=e("end-of-stream");var i=e("events").EventEmitter;var o=e("./file-stream");var s=e("inherits");var a=e("path");var f=e("render-media");var u=e("readable-stream");var c=e("stream-to-blob-url");var l=e("stream-with-known-length-to-buffer");s(d,i);function d(e,t){i.call(this);this._torrent=e;this.name=t.name;this.path=t.path;this.length=t.length;this.offset=t.offset;this.done=false;var r=t.offset;var n=r+t.length-1;this._startPiece=r/this._torrent.pieceLength|0;this._endPiece=n/this._torrent.pieceLength|0;if(this.length===0){this.done=true;this.emit("done")}}d.prototype.select=function(e){if(this.length===0)return;this._torrent.select(this._startPiece,this._endPiece,e)};d.prototype.deselect=function(){if(this.length===0)return;this._torrent.deselect(this._startPiece,this._endPiece,false)};d.prototype.createReadStream=function(e){var t=this;if(this.length===0){var i=new u.PassThrough;r.nextTick(function(){i.end()});return i}var s=new o(t,e);t._torrent.select(s._startPiece,s._endPiece,true,function(){s._notify()});n(s,function(){t._torrent.deselect(s._startPiece,s._endPiece,true)});return s};d.prototype.getBuffer=function(e){l(this.createReadStream(),this.length,e)};d.prototype.getBlobURL=function(e){if(typeof window==="undefined")throw new Error("browser-only method");var t=f.mime[a.extname(this.name).toLowerCase()];c(this.createReadStream(),t,e)};d.prototype.appendTo=function(e,t){if(typeof window==="undefined")throw new Error("browser-only method");f.append(this,e,t)};d.prototype.renderTo=function(e,t){if(typeof window==="undefined")throw new Error("browser-only method");f.render(this,e,t)}}).call(this,e("_process"))},{"./file-stream":2,_process:34,"end-of-stream":74,events:30,inherits:79,path:33,"readable-stream":109,"render-media":112,"stream-to-blob-url":142,"stream-with-known-length-to-buffer":145}],4:[function(e,t,r){t.exports=n;function n(e,t){var r=this;r.pieces=[];r.swarm=e;r.numPieces=t;function n(e){e.on("have",function(e){r.pieces[e]+=1});e.on("bitfield",function(){r.recalculate()});e.on("close",function(){for(var t=0;t<r.numPieces;++t){r.pieces[t]-=e.peerPieces.get(t)}})}r.swarm.wires.forEach(n);r.swarm.on("wire",function(e){r.recalculate();n(e)});r.recalculate()}n.prototype.recalculate=function(){var e=this;for(var t=0;t<e.numPieces;++t){e.pieces[t]=0}e.swarm.wires.forEach(function(t){for(var r=0;r<e.numPieces;++r){e.pieces[r]+=t.peerPieces.get(r)}})};n.prototype.getRarestPiece=function(e){var t=this;var r=[];var n=Infinity;e=e||function(){return true};for(var i=0;i<t.numPieces;++i){if(!e(i))continue;var o=t.pieces[i];if(o===n){r.push(i)}else if(o<n){r=[i];n=o}}if(r.length>0){return r[Math.random()*r.length|0]}else{return-1}}},{}],5:[function(e,t,r){(function(r,n){t.exports=F;var i=e("addr-to-ip-port");var o=e("bitfield");var s=e("chunk-store-stream/write");var a=e("cpus");var f=e("create-torrent");var u=e("debug")("webtorrent:torrent");var c=e("torrent-discovery");var l=e("events").EventEmitter;var d=e("xtend/mutable");var h=e("fs-chunk-store");var p=e("immediate-chunk-store");var m=e("inherits");var v=e("multistream");var g=e("os");var y=e("run-parallel");var _=e("run-parallel-limit");var b=e("parse-torrent");var w=e("path");var E=e("path-exists");var k=e("torrent-piece");var x=e("pump");var S=e("random-iterate");var I=e("re-emitter");var B=e("simple-sha1");var A=e("bittorrent-swarm");var C=e("uniq");var T=e("ut_metadata");var L=e("ut_pex");var R=e("./file");var U=e("./rarity-map");var P=e("./server");var O=128*1024;var M=3e4;var j=5e3;var D=3*k.BLOCK_LENGTH;var H=.5;var N=1;var q=1e4;var z=2;var W=typeof E.sync==="function"?w.join(E.sync("/tmp")?"/tmp":g.tmpDir(),"webtorrent"):"/tmp/webtorrent";m(F,l);function F(e,t,r){l.call(this);if(!u.enabled)this.setMaxListeners(0);this.client=t;this._debugId=this.client.peerId.slice(32);this._debug("new torrent");this.announce=r.announce;this.urlList=r.urlList;this.path=r.path;this._store=r.store||h;this.strategy=r.strategy||"sequential";this._rechokeNumSlots=r.uploads===false||r.uploads===0?0:+r.uploads||10;this._rechokeOptimisticWire=null;this._rechokeOptimisticTime=0;this._rechokeIntervalId=null;this.ready=false;this.destroyed=false;this.metadata=null;this.store=null;this.numBlockedPeers=0;this.files=null;this.done=false;this._amInterested=false;this.pieces=[];this._selections=[];this._critical=[];this._servers=[];if(e!=null)this._onTorrentId(e)}Object.defineProperty(F.prototype,"timeRemaining",{get:function(){if(this.done)return 0;if(!this.swarm||this.swarm.downloadSpeed()===0)return Infinity;return(this.length-this.downloaded)/this.swarm.downloadSpeed()*1e3}});Object.defineProperty(F.prototype,"downloaded",{get:function(){if(!this.bitfield)return 0;var e=0;for(var t=0,r=this.pieces.length;t<r;++t){if(this.bitfield.get(t)){e+=t===r-1?this.lastPieceLength:this.pieceLength}else{var n=this.pieces[t];e+=n.length-n.missing}}return e}});Object.defineProperty(F.prototype,"received",{get:function(){return this.swarm?this.swarm.downloaded:0}});Object.defineProperty(F.prototype,"uploaded",{get:function(){return this.swarm?this.swarm.uploaded:0}});Object.defineProperty(F.prototype,"progress",{get:function(){return this.length?this.downloaded/this.length:0}});Object.defineProperty(F.prototype,"ratio",{get:function(){return this.uploaded/(this.downloaded||1)}});Object.defineProperty(F.prototype,"downloadSpeed",{get:function(){return this.swarm?this.swarm.downloadSpeed():0}});Object.defineProperty(F.prototype,"uploadSpeed",{get:function(){return this.swarm?this.swarm.uploadSpeed():0}});Object.defineProperty(F.prototype,"numPeers",{get:function(){return this.swarm?this.swarm.numPeers:0}});Object.defineProperty(F.prototype,"torrentFileBlobURL",{get:function(){if(typeof window==="undefined")throw new Error("browser-only property");if(!this.torrentFile)return null;return URL.createObjectURL(new Blob([this.torrentFile],{type:"application/x-bittorrent"}))}});F.prototype._onTorrentId=function(e){var t=this;if(t.destroyed)return;b.remote(e,function(e,r){if(t.destroyed)return;if(e)return t._onError(e);t._onParsedTorrent(r)})};F.prototype._onParsedTorrent=function(e){var t=this;if(t.destroyed)return;t._processParsedTorrent(e);if(!t.infoHash){return t._onError(new Error("Malformed torrent data: No info hash"))}if(!t.path)t.path=w.join(W,t.infoHash);t.swarm=new A(t.infoHash,t.client.peerId,{handshake:{dht:t.private?false:!!t.client.dht},maxConns:t.client.maxConns});t.swarm.on("error",t._onError.bind(t));t.swarm.on("wire",t._onWire.bind(t));t.swarm.on("download",function(e){t.client._downloadSpeed(e);t.client.emit("download",e);t.emit("download",e)});t.swarm.on("upload",function(e){t.client._uploadSpeed(e);t.client.emit("upload",e);t.emit("upload",e)});t.swarm.listen(t.client.torrentPort,t._onSwarmListening.bind(t));t.emit("infoHash",t.infoHash)};F.prototype._processParsedTorrent=function(e){if(this.announce){e.announce=e.announce.concat(this.announce)}if(this.client.tracker&&e.announce.length===0){e.announce=f.announceList.map(function(e){return e[0]})}if(this.client.tracker&&n.WEBTORRENT_ANNOUNCE){e.announce=e.announce.concat(n.WEBTORRENT_ANNOUNCE)}if(this.urlList){e.urlList=e.urlList.concat(this.urlList)}C(e.announce);C(e.urlList);d(this,e);this.magnetURI=b.toMagnetURI(e);this.torrentFile=b.toTorrentFile(e)};F.prototype._onSwarmListening=function(){var e=this;if(e.destroyed)return;if(e.swarm.server)e.client.torrentPort=e.swarm.address().port;e.discovery=new c({announce:e.announce,dht:e.private?false:e.client.dht,tracker:e.client.tracker,peerId:e.client.peerId,port:e.client.torrentPort,rtcConfig:e.client._rtcConfig,wrtc:e.client._wrtc});e.discovery.on("error",e._onError.bind(e));e.discovery.on("peer",e.addPeer.bind(e));I(e.discovery,e,["trackerAnnounce","dhtAnnounce","warning"]);if(e.info)e._onMetadata(e);else e.discovery.setTorrent(e.infoHash);e.emit("listening",e.client.torrentPort)};F.prototype._onMetadata=function(e){var t=this;if(t.metadata||t.destroyed)return;t._debug("got metadata");var r;if(e&&e.infoHash){r=e}else{try{r=b(e)}catch(n){return t._onError(n)}}t._processParsedTorrent(r);t.metadata=t.torrentFile;t.discovery.setTorrent(t);if(t.urlList)t.urlList.forEach(t.addWebSeed.bind(t));t.rarityMap=new U(t.swarm,t.pieces.length);t.store=new p(new t._store(t.pieceLength,{files:t.files.map(function(e){return{path:w.join(t.path,e.path),length:e.length,offset:e.offset}}),length:t.length}));t.files=t.files.map(function(e){return new R(t,e)});t._hashes=t.pieces;t.pieces=t.pieces.map(function(e,r){var n=r===t.pieces.length-1?t.lastPieceLength:t.pieceLength;return new k(n)});t._reservations=t.pieces.map(function(){return[]});t.bitfield=new o(t.pieces.length);t.swarm.wires.forEach(function(e){if(e.ut_metadata)e.ut_metadata.setMetadata(t.metadata);t._onWireWithMetadata(e)});t._debug("verifying existing torrent data");_(t.pieces.map(function(e,r){return function(e){t.store.get(r,function(n,i){if(n)return e(null);B(i,function(n){if(n===t._hashes[r]){if(!t.pieces[r])return;t._debug("piece verified %s",r);t.pieces[r]=null;t._reservations[r]=null;t.bitfield.set(r,true)}else{t._debug("piece invalid %s",r)}e(null)})})}}),a().length,function(e){if(e)return t._onError(e);t._debug("done verifying");t._onStore()});t.emit("metadata")};F.prototype._onStore=function(){var e=this;if(e.destroyed)return;e._debug("on store");e.select(0,e.pieces.length-1,false);e._rechokeIntervalId=setInterval(e._rechoke.bind(e),q);if(e._rechokeIntervalId.unref)e._rechokeIntervalId.unref();e.ready=true;e.emit("ready");e._checkDone()};F.prototype.destroy=function(e){var t=this;if(t.destroyed)return;t.destroyed=true;t._debug("destroy");t.client.remove(t);if(t._rechokeIntervalId){clearInterval(t._rechokeIntervalId);t._rechokeIntervalId=null}var r=[];t._servers.forEach(function(e){r.push(function(t){e.destroy(t)})});if(t.swarm)r.push(function(e){t.swarm.destroy(e)});if(t.discovery)r.push(function(e){t.discovery.stop(e)});if(t.store)r.push(function(e){t.store.close(e)});y(r,e)};F.prototype.addPeer=function(e){var t=this;if(t.destroyed)throw new Error("torrent is destroyed");function r(){t.swarm.addPeer(e);t.emit("peer",e)}if(t.client.blocked){var n=typeof e==="string"?e:e.remoteAddress;if(n&&t.client.blocked.contains(i(n)[0])){t.numBlockedPeers+=1;t.emit("blockedPeer",e);return false}}if(t.swarm)r();else t.once("listening",r);return true};F.prototype.addWebSeed=function(e){if(this.destroyed)throw new Error("torrent is destroyed");this._debug("add web seed %s",e);this.swarm.addWebSeed(e,this)};F.prototype.select=function(e,t,r,n){var i=this;if(i.destroyed)throw new Error("torrent is destroyed");if(e>t||e<0||t>=i.pieces.length){throw new Error("invalid selection ",e,":",t)}r=Number(r)||0;i._debug("select %s-%s (priority %s)",e,t,r);i._selections.push({from:e,to:t,offset:0,priority:r,notify:n||$});i._selections.sort(function(e,t){return t.priority-e.priority});i._updateSelections()};F.prototype.deselect=function(e,t,r){var n=this;if(n.destroyed)throw new Error("torrent is destroyed");r=Number(r)||0;n._debug("deselect %s-%s (priority %s)",e,t,r);for(var i=0;i<n._selections.length;++i){var o=n._selections[i];if(o.from===e&&o.to===t&&o.priority===r){n._selections.splice(i--,1);break}}n._updateSelections()};F.prototype.critical=function(e,t){var r=this;if(r.destroyed)throw new Error("torrent is destroyed");r._debug("critical %s-%s",e,t);for(var n=e;n<=t;++n){r._critical[n]=true}r._updateSelections()};F.prototype._onWire=function(e,t){var n=this;n._debug("got wire %s (%s)",e._debugId,t||"Unknown");if(t){var o=i(t);e.remoteAddress=o[0];e.remotePort=o[1]}if(n.client.dht&&n.client.dht.listening){e.on("port",function(r){if(n.destroyed||n.client.dht.destroyed){return}if(!e.remoteAddress){return n._debug("ignoring PORT from peer with no address")}if(r===0||r>65536){return n._debug("ignoring invalid PORT from peer")}n._debug("port: %s (from %s)",r,t);n.client.dht.addNode({host:e.remoteAddress,port:r})})}e.on("timeout",function(){n._debug("wire timeout (%s)",t);e.destroy()});e.setTimeout(M,true);e.setKeepAlive(true);e.use(T(n.metadata));e.ut_metadata.on("warning",function(e){n._debug("ut_metadata warning: %s",e.message)});if(!n.metadata){e.ut_metadata.on("metadata",function(e){n._debug("got metadata via ut_metadata");n._onMetadata(e)});e.ut_metadata.fetch()}if(typeof L==="function"&&!n.private){e.use(L());e.ut_pex.on("peer",function(e){n._debug("ut_pex: got peer: %s (from %s)",e,t);n.addPeer(e)});e.ut_pex.on("dropped",function(e){var r=n.swarm._peers[e];if(r&&!r.connected){n._debug("ut_pex: dropped peer: %s (from %s)",e,t);n.swarm.removePeer(e)}})}n.emit("wire",e,t);if(n.metadata){r.nextTick(function(){n._onWireWithMetadata(e)})}};F.prototype._onWireWithMetadata=function(e){var t=this;var r=null;function n(){if(t.destroyed||e.destroyed)return;if(t.swarm.numQueued>2*(t.swarm.numConns-t.swarm.numPeers)&&e.amInterested){e.destroy()}else{r=setTimeout(n,j);if(r.unref)r.unref()}}var i=0;function o(){if(e.peerPieces.length!==t.pieces.length)return;for(;i<t.pieces.length;++i){if(!e.peerPieces.get(i))return}e.isSeeder=true;e.choke()}e.on("bitfield",function(){o();t._update()});e.on("have",function(){o();t._update()});e.once("interested",function(){e.unchoke()});e.on("close",function(){clearTimeout(r)});e.on("choke",function(){clearTimeout(r);r=setTimeout(n,j);if(r.unref)r.unref()});e.on("unchoke",function(){clearTimeout(r);t._update()});e.on("request",function(r,n,i,o){if(i>O){return e.destroy()}if(t.pieces[r])return;t.store.get(r,{offset:n,length:i},o)});e.bitfield(t.bitfield);e.interested();if(e.peerExtensions.dht&&t.client.dht&&t.client.dht.listening){e.port(t.client.dht.address().port)}r=setTimeout(n,j);if(r.unref)r.unref();e.isSeeder=false;o()};F.prototype._updateSelections=function(){var e=this;if(!e.swarm||e.destroyed)return;if(!e.metadata)return e.once("metadata",e._updateSelections.bind(e));r.nextTick(e._gcSelections.bind(e));e._updateInterest();e._update()};F.prototype._gcSelections=function(){var e=this;for(var t=0;t<e._selections.length;t++){var r=e._selections[t];var n=r.offset;while(e.bitfield.get(r.from+r.offset)&&r.from+r.offset<r.to){r.offset++}if(n!==r.offset)r.notify();if(r.to!==r.from+r.offset)continue;if(!e.bitfield.get(r.from+r.offset))continue;e._selections.splice(t--,1);r.notify();e._updateInterest()}if(!e._selections.length)e.emit("idle")};F.prototype._updateInterest=function(){var e=this;var t=e._amInterested;e._amInterested=!!e._selections.length;e.swarm.wires.forEach(function(t){if(e._amInterested)t.interested();else t.uninterested()});if(t===e._amInterested)return;if(e._amInterested)e.emit("interested");else e.emit("uninterested")};F.prototype._update=function(){var e=this;if(e.destroyed)return;var t=S(e.swarm.wires);var r;while(r=t()){e._updateWire(r)}};F.prototype._updateWire=function(e){var t=this;if(e.peerChoking)return;if(!e.downloaded)return o();var r=Y(e,H);if(e.requests.length>=r)return;var n=Y(e,N);f(false)||f(true);function i(t,r,n,i){return function(o){return o>=t&&o<=r&&!(o in n)&&e.peerPieces.get(o)&&(!i||i(o))}}function o(){if(e.requests.length)return;var r=t._selections.length;while(r--){var n=t._selections[r];var o;if(t.strategy==="rarest"){var s=n.from+n.offset;var a=n.to;var f=a-s+1;var u={};var c=0;var l=i(s,a,u);while(c<f){o=t.rarityMap.getRarestPiece(l);if(o<0)break;if(t._request(e,o,false))return;u[o]=true;c+=1}}else{for(o=n.to;o>=n.from+n.offset;--o){if(!e.peerPieces.get(o))continue;if(t._request(e,o,false))return}}}}function s(){var r=e.downloadSpeed()||1;if(r>D)return function(){return true};var n=Math.max(1,e.requests.length)*k.BLOCK_LENGTH/r;var i=10;var o=0;return function(e){if(!i||t.bitfield.get(e))return true;var s=t.pieces[e].missing;for(;o<t.swarm.wires.length;o++){var a=t.swarm.wires[o];var f=a.downloadSpeed();if(f<D)continue;if(f<=r)continue;if(!a.peerPieces.get(e))continue;if((s-=f*n)>0)continue;i--;return false}return true}}function a(e){var r=e;for(var n=e;n<t._selections.length&&t._selections[n].priority;n++){r=n}var i=t._selections[e];t._selections[e]=t._selections[r];t._selections[r]=i}function f(r){if(e.requests.length>=n)return true;var o=s();for(var f=0;f<t._selections.length;f++){var u=t._selections[f];var c;if(t.strategy==="rarest"){var l=u.from+u.offset;var d=u.to;var h=d-l+1;var p={};var m=0;var v=i(l,d,p,o);while(m<h){c=t.rarityMap.getRarestPiece(v);if(c<0)break;while(t._request(e,c,t._critical[c]||r)){}if(e.requests.length<n){p[c]=true;m++;continue}if(u.priority)a(f);return true}}else{for(c=u.from+u.offset;c<=u.to;c++){if(!e.peerPieces.get(c)||!o(c))continue;while(t._request(e,c,t._critical[c]||r)){}if(e.requests.length<n)continue;if(u.priority)a(f);return true}}}return false}};F.prototype._rechoke=function(){var e=this;if(e._rechokeOptimisticTime>0)e._rechokeOptimisticTime-=1;else e._rechokeOptimisticWire=null;var t=[];e.swarm.wires.forEach(function(r){if(!r.isSeeder&&r!==e._rechokeOptimisticWire){t.push({wire:r,downloadSpeed:r.downloadSpeed(),uploadSpeed:r.uploadSpeed(),salt:Math.random(),isChoked:true})}});t.sort(s);var r=0;var n=0;for(;n<t.length&&r<e._rechokeNumSlots;++n){t[n].isChoked=false;if(t[n].wire.peerInterested)r+=1}if(!e._rechokeOptimisticWire&&n<t.length&&e._rechokeNumSlots){var i=t.slice(n).filter(function(e){return e.wire.peerInterested});var o=i[V(i.length)];if(o){o.isChoked=false;e._rechokeOptimisticWire=o.wire;e._rechokeOptimisticTime=z}}t.forEach(function(e){if(e.wire.amChoking!==e.isChoked){if(e.isChoked)e.wire.choke();else e.wire.unchoke()}});function s(e,t){if(e.downloadSpeed!==t.downloadSpeed){return t.downloadSpeed-e.downloadSpeed}if(e.uploadSpeed!==t.uploadSpeed){return t.uploadSpeed-e.uploadSpeed}if(e.wire.amChoking!==t.wire.amChoking){return e.wire.amChoking?1:-1}return e.salt-t.salt}};F.prototype._hotswap=function(e,t){var r=this;var n=e.downloadSpeed();if(n<k.BLOCK_LENGTH)return false;if(!r._reservations[t])return false;var i=r._reservations[t];if(!i){return false}var o=Infinity;var s;var a;for(a=0;a<i.length;a++){var f=i[a];if(!f||f===e)continue;var u=f.downloadSpeed();if(u>=D)continue;if(2*u>n||u>o)continue;s=f;o=u}if(!s)return false;for(a=0;a<i.length;a++){if(i[a]===s)i[a]=null}for(a=0;a<s.requests.length;a++){var c=s.requests[a];if(c.piece!==t)continue;r.pieces[t].cancel(c.offset/k.BLOCK_SIZE|0)}r.emit("hotswap",s,e,t);return true};F.prototype._request=function(e,t,n){var i=this;var o=e.requests.length;if(i.bitfield.get(t))return false;var s=Y(e,N);if(o>=s)return false;var a=i.pieces[t];var f=a.reserve();if(f===-1&&n&&i._hotswap(e,t)){f=a.reserve()}if(f===-1)return false;var u=i._reservations[t];if(!u)u=i._reservations[t]=[];var c=u.indexOf(null);if(c===-1)c=u.length;u[c]=e;var l=a.chunkOffset(f);var d=a.chunkLength(f);e.request(t,l,d,function p(r,n){if(!i.ready)return i.once("ready",function(){p(r,n)});if(u[c]===e)u[c]=null;if(a!==i.pieces[t])return h();if(r){i._debug("error getting piece %s (offset: %s length: %s) from %s: %s",t,l,d,e.remoteAddress+":"+e.remotePort,r.message);a.cancel(f);h();return}i._debug("got piece %s (offset: %s length: %s) from %s",t,l,d,e.remoteAddress+":"+e.remotePort);if(!a.set(f,n,e))return h();var o=a.flush();B(o,function(e){if(e===i._hashes[t]){if(!i.pieces[t])return;i._debug("piece verified %s",t);i.pieces[t]=null;i._reservations[t]=null;i.bitfield.set(t,true);i.store.put(t,o);i.swarm.wires.forEach(function(e){e.have(t)});i._checkDone()}else{i.pieces[t]=new k(a.length);i.emit("warning",new Error("Piece "+t+" failed verification"))}h()})});function h(){r.nextTick(function(){i._update()})}return true};F.prototype._checkDone=function(){var e=this;if(e.destroyed)return;e.files.forEach(function(t){if(t.done)return;for(var r=t._startPiece;r<=t._endPiece;++r){if(!e.bitfield.get(r))return}t.done=true;t.emit("done");e._debug("file done: "+t.name)});var t=true;for(var r=0;r<e._selections.length;r++){var n=e._selections[r];for(var i=n.from;i<=n.to;i++){if(!e.bitfield.get(i)){t=false;break}}if(!t)break}if(!e.done&&t){e.done=true;e.emit("done");e._debug("torrent done: "+e.infoHash);if(e.discovery.tracker)e.discovery.tracker.complete()}e._gcSelections()};F.prototype.load=function(e,t){var r=this;if(r.destroyed)throw new Error("torrent is destroyed");if(!r.ready)return r.once("ready",function(){r.load(e,t)});if(!Array.isArray(e))e=[e];if(!t)t=$;var n=new v(e);var i=new s(r.store,r.pieceLength);x(n,i,function(e){if(e)return t(e);r.pieces.forEach(function(e,t){r.pieces[t]=null;r._reservations[t]=null;r.bitfield.set(t,true)});r._checkDone();t(null)})};F.prototype.createServer=function(e){if(typeof P!=="function")throw new Error("node.js-only method");if(this.destroyed)throw new Error("torrent is destroyed");var t=new P(this,e);this._servers.push(t);return t};F.prototype.pause=function(){if(this.destroyed)return;this.swarm.pause()};F.prototype.resume=function(){if(this.destroyed)return;this.swarm.resume()};F.prototype._onError=function(e){var t=this;t._debug("torrent error: %s",e.message||e);t.emit("error",e);t.destroy()};F.prototype._debug=function(){var e=[].slice.call(arguments);e[0]="["+this._debugId+"] "+e[0];u.apply(null,e)};function Y(e,t){return Math.ceil(2+t*e.downloadSpeed()/k.BLOCK_LENGTH)}function V(e){return Math.random()*e|0}function $(){}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./file":3,"./rarity-map":4,"./server":25,_process:34,"addr-to-ip-port":6,bitfield:7,"bittorrent-swarm":8,"chunk-store-stream/write":52,cpus:53,"create-torrent":54,debug:71,events:30,"fs-chunk-store":80,"immediate-chunk-store":78,inherits:79,multistream:81,os:25,"parse-torrent":82,path:33,"path-exists":25,pump:92,"random-iterate":95,"re-emitter":96,"run-parallel":130,"run-parallel-limit":129,"simple-sha1":139,"torrent-discovery":148,"torrent-piece":149,uniq:150,ut_metadata:151,ut_pex:25,"xtend/mutable":157}],6:[function(e,t,r){var n=/^\[?([^\]]+)\]?:(\d+)$/;var i={};var o=0;t.exports=function s(e){if(o===1e5)t.exports.reset();if(!i[e]){var r=n.exec(e);if(!r)throw new Error("invalid addr: "+e);i[e]=[r[1],Number(r[2])];o+=1}return i[e]};t.exports.reset=function a(){i={};o=0}},{}],7:[function(e,t,r){(function(e){var r=typeof e!=="undefined"?e:typeof Int8Array!=="undefined"?Int8Array:function(e){var t=new Array(e);for(var r=0;r<e;r++)t[r]=0};function n(e,t){if(!(this instanceof n)){return new n(e,t)}if(arguments.length===0){e=0}this.grow=t&&(isFinite(t.grow)&&i(t.grow)||t.grow)||0;if(typeof e==="number"||e===undefined){e=new r(i(e));if(e.fill&&!e._isBuffer)e.fill(0)}this.buffer=e}function i(e){var t=e>>3;if(e%8!==0)t++;return t}n.prototype.get=function(e){var t=e>>3;return t<this.buffer.length&&!!(this.buffer[t]&128>>e%8)};n.prototype.set=function(e,t){var r=e>>3;if(t||arguments.length===1){if(this.buffer.length<r+1)this._grow(Math.max(r+1,Math.min(2*this.buffer.length,this.grow)));this.buffer[r]|=128>>e%8}else if(r<this.buffer.length){this.buffer[r]&=~(128>>e%8)}};n.prototype._grow=function(e){if(this.buffer.length<e&&e<=this.grow){var t=new r(e);if(t.fill)t.fill(0);if(this.buffer.copy)this.buffer.copy(t,0);else{for(var n=0;n<this.buffer.length;n++){t[n]=this.buffer[n]}}this.buffer=t}};if(typeof t!=="undefined")t.exports=n}).call(this,e("buffer").Buffer)},{buffer:26}],8:[function(e,t,r){(function(r,n){t.exports=p;var i=e("addr-to-ip-port");var o=e("debug")("bittorrent-swarm");var s=e("events").EventEmitter;var a=e("inherits");var f=e("net");var u=e("speedometer");var c=e("./lib/peer");var l=e("./lib/tcp-pool");var d=55;var h=[1e3,5e3,15e3];a(p,s);function p(e,t,r){var i=this;if(!(i instanceof p))return new p(e,t,r);s.call(i);i.infoHash=typeof e==="string"?e:e.toString("hex");i.infoHashBuffer=new n(i.infoHash,"hex");i.peerId=typeof t==="string"?t:t.toString("hex");i.peerIdBuffer=new n(i.peerId,"hex");if(!r)r={};o("new swarm (i %s p %s)",i.infoHash,i.peerId);i.handshakeOpts=r.handshake;i.maxConns=Number(r.maxConns)||d;i.destroyed=false;i.listening=false;i.paused=false;i.server=null;i.wires=[];i._queue=[];i._peers={};i._peersLength=0;i._port=0;i.downloaded=0;i.uploaded=0;i.downloadSpeed=u();i.uploadSpeed=u()}Object.defineProperty(p.prototype,"ratio",{get:function(){var e=this;return e.uploaded/e.downloaded||0}});Object.defineProperty(p.prototype,"numQueued",{get:function(){var e=this;return e._queue.length+(e._peersLength-e.numConns)}});Object.defineProperty(p.prototype,"numConns",{get:function(){var e=this;var t=0;for(var r in e._peers){var n=e._peers[r];if(n&&n.connected)t+=1}return t}});Object.defineProperty(p.prototype,"numPeers",{get:function(){var e=this;return e.wires.length}});p.prototype.addPeer=function(e){var t=this;t._addPeer(e)};p.prototype._addPeer=function(e){var t=this;if(t.destroyed){if(e&&e.destroy)e.destroy(new Error("swarm already destroyed"));return null}if(typeof e==="string"&&!t._validAddr(e)){o("ignoring invalid peer %s (from swarm.addPeer)",e);return null}var r=e&&e.id||e;if(t._peers[r])return;o("addPeer %s",r);var n;if(typeof e==="string"){n=c.createOutgoingTCPPeer(e,t)}else{if(t.paused){e.destroy(new Error("swarm paused"));return null}n=c.createWebRTCPeer(e,t)}t._peers[n.id]=n;t._peersLength+=1;if(typeof e==="string"){t._queue.push(n);t._drain()}return n};p.prototype.addWebSeed=function(e,t){var r=this;if(r.destroyed)return;if(!/^https?:\/\/.+/.test(e)){o("ignoring invalid web seed %s (from swarm.addWebSeed)",e);return}if(r._peers[e])return;o("addWebSeed %s",e);var n=c.createWebPeer(e,t,r);r._peers[n.id]=n;r._peersLength+=1};p.prototype._addIncomingPeer=function(e){var t=this;if(t.destroyed)return e.destroy(new Error("swarm already destroyed"));if(t.paused)return e.destroy(new Error("swarm paused"));if(!t._validAddr(e.addr)){return e.destroy(new Error("invalid addr "+e.addr+" (from incoming)"))}o("_addIncomingPeer %s",e.id);t._peers[e.id]=e;t._peersLength+=1};p.prototype.removePeer=function(e){var t=this;var r=t._peers[e];if(!r)return;o("removePeer %s",e);t._peers[e]=null;t._peersLength-=1;r.destroy();t._drain()};p.prototype.pause=function(){var e=this;if(e.destroyed)return;o("pause");e.paused=true};p.prototype.resume=function(){var e=this;if(e.destroyed)return;o("resume");e.paused=false;e._drain()};p.prototype.listen=function(e,t,n){var i=this;if(typeof t==="function"){n=t;t=undefined}if(i.listening)throw new Error("swarm already listening");if(n)i.once("listening",n);if(typeof l==="function"){i._port=e||l.getDefaultListenPort(i.infoHash);i._hostname=t;o("listen %s",e);var s=l.addSwarm(i);i.server=s.server}else{r.nextTick(function(){i._onListening(0)})}};p.prototype._onListening=function(e){var t=this;t._port=e;t.listening=true;t.emit("listening")};p.prototype.address=function(){var e=this;if(!e.listening)return null;return e.server?e.server.address():{port:0,family:"IPv4",address:"127.0.0.1"}};p.prototype.destroy=function(e){var t=this;if(t.destroyed)return;t.destroyed=true;t.listening=false;t.paused=false;if(e)t.once("close",e);o("destroy");for(var n in t._peers){t.removePeer(n)}if(typeof l==="function"){l.removeSwarm(t,function(){t.emit("close")})}else{r.nextTick(function(){t.emit("close")})}};p.prototype._drain=function(){var e=this;o("_drain numConns %s maxConns %s",e.numConns,e.maxConns);if(typeof f.connect!=="function"||e.destroyed||e.paused||e.numConns>=e.maxConns){return}o("drain (%s queued, %s/%s peers)",e.numQueued,e.numPeers,e.maxConns);var t=e._queue.shift();if(!t)return;o("tcp connect attempt to %s",t.addr);var r=i(t.addr);var n={host:r[0],port:r[1]};if(e._hostname)n.localAddress=e._hostname;var s=t.conn=f.connect(n);s.once("connect",function(){t.onConnect()});s.once("error",function(e){t.destroy(e)});t.setConnectTimeout();s.on("close",function(){if(e.destroyed)return;if(t.retries>=h.length){o("conn %s closed: will not re-add (max %s attempts)",t.addr,h.length);return}var r=h[t.retries];o("conn %s closed: will re-add to queue in %sms (attempt %s)",t.addr,r,t.retries+1);var n=setTimeout(function i(){var r=e._addPeer(t.addr);if(r)r.retries=t.retries+1},r);if(n.unref)n.unref()})};p.prototype._onError=function(e){var t=this;t.emit("error",e);t.destroy()};p.prototype._validAddr=function(e){var t=this;var r=i(e);var n=r[0];var o=r[1];return o>0&&o<65535&&!(n==="127.0.0.1"&&o===t._port)}}).call(this,e("_process"),e("buffer").Buffer)},{"./lib/peer":9,"./lib/tcp-pool":25,_process:34,"addr-to-ip-port":25,buffer:26,debug:71,events:30,inherits:79,net:25,speedometer:141}],9:[function(e,t,r){var n=e("debug")("bittorrent-swarm:peer");var i=e("./webconn");var o=e("bittorrent-protocol");var s=25e3;var a=25e3;r.createWebRTCPeer=function(e,t){var r=new f(e.id);r.conn=e;r.swarm=t;if(r.conn.connected){r.onConnect()}else{r.conn.once("connect",function(){r.onConnect()});r.conn.once("error",function(e){r.destroy(e)});r.setConnectTimeout()}return r};r.createIncomingTCPPeer=function(e){var t=e.remoteAddress+":"+e.remotePort;var r=new f(t);r.conn=e;r.addr=t;r.onConnect();return r};r.createOutgoingTCPPeer=function(e,t){var r=new f(e);r.addr=e;r.swarm=t;return r};r.createWebPeer=function(e,t,r){var n=new f(e);n.swarm=r;n.conn=new i(e,t);n.onConnect();return n};function f(e){var t=this;t.id=e;n("new Peer %s",e);t.addr=null;t.conn=null;t.swarm=null;t.wire=null;t.connected=false;t.destroyed=false;t.timeout=null;t.retries=0;t.sentHandshake=false}f.prototype.onConnect=function(){var e=this;if(e.destroyed)return;e.connected=true;n("Peer %s connected",e.id);clearTimeout(e.connectTimeout);var t=e.conn;t.once("end",function(){e.destroy()});t.once("close",function(){e.destroy(); -});t.once("finish",function(){e.destroy()});t.once("error",function(t){e.destroy(t)});var r=e.wire=new o;r.once("end",function(){e.destroy()});r.once("close",function(){e.destroy()});r.once("finish",function(){e.destroy()});r.once("error",function(t){e.destroy(t)});r.once("handshake",function(t,r){e.onHandshake(t,r)});e.setHandshakeTimeout();t.pipe(r).pipe(t);if(e.swarm&&!e.sentHandshake)e.handshake()};f.prototype.onHandshake=function(e,t){var r=this;if(!r.swarm)return;if(r.swarm.destroyed)return r.destroy(new Error("swarm already destroyed"));if(e!==r.swarm.infoHash){return r.destroy(new Error("unexpected handshake info hash for this swarm"))}if(t===r.swarm.peerId){return r.destroy(new Error("refusing to handshake with self"))}n("Peer %s got handshake %s",r.id,e);clearTimeout(r.handshakeTimeout);r.retries=0;r.wire.on("download",function(e){if(r.destroyed)return;r.swarm.downloaded+=e;r.swarm.downloadSpeed(e);r.swarm.emit("download",e)});r.wire.on("upload",function(e){if(r.destroyed)return;r.swarm.uploaded+=e;r.swarm.uploadSpeed(e);r.swarm.emit("upload",e)});r.swarm.wires.push(r.wire);var i=r.addr;if(!i&&r.conn.remoteAddress){i=r.conn.remoteAddress+":"+r.conn.remotePort}r.swarm.emit("wire",r.wire,i);if(!r.swarm||r.swarm.destroyed)return;if(!r.sentHandshake)r.handshake()};f.prototype.handshake=function(){var e=this;e.wire.handshake(e.swarm.infoHash,e.swarm.peerId,e.swarm.handshakeOpts);e.sentHandshake=true};f.prototype.setConnectTimeout=function(){var e=this;clearTimeout(e.connectTimeout);e.connectTimeout=setTimeout(function(){e.destroy(new Error("connect timeout"))},s);if(e.connectTimeout.unref)e.connectTimeout.unref()};f.prototype.setHandshakeTimeout=function(){var e=this;clearTimeout(e.handshakeTimeout);e.handshakeTimeout=setTimeout(function(){e.destroy(new Error("handshake timeout"))},a);if(e.handshakeTimeout.unref)e.handshakeTimeout.unref()};f.prototype.destroy=function(e){var t=this;if(t.destroyed)return;t.destroyed=true;t.connected=false;n("destroy %s (error: %s)",t.id,e&&(e.message||e));clearTimeout(t.connectTimeout);clearTimeout(t.handshakeTimeout);var r=t.swarm;var i=t.conn;var o=t.wire;t.conn=null;t.swarm=null;t.wire=null;if(r&&o){var s=r.wires.indexOf(o);if(s>=0)r.wires.splice(s,1)}if(i)i.destroy();if(o)o.destroy();if(r)r.removePeer(t.id)}},{"./webconn":10,"bittorrent-protocol":11,debug:71}],10:[function(e,t,r){t.exports=u;var n=e("bitfield");var i=e("debug")("bittorrent-swarm:webconn");var o=e("simple-get");var s=e("inherits");var a=e("simple-sha1");var f=e("bittorrent-protocol");s(u,f);function u(e,t){var r=this;f.call(this);r.url=e;r.webPeerId=a.sync(e);r.parsedTorrent=t;r.setKeepAlive(true);r.on("handshake",function(e,t){r.handshake(e,r.webPeerId);var i=r.parsedTorrent.pieces.length;var o=new n(i);for(var s=0;s<=i;s++){o.set(s,true)}r.bitfield(o)});r.on("choke",function(){i("choke")});r.on("unchoke",function(){i("unchoke")});r.once("interested",function(){i("interested");r.unchoke()});r.on("uninterested",function(){i("uninterested")});r.on("bitfield",function(){i("bitfield")});r.on("request",function(e,t,n,o){i("request pieceIndex=%d offset=%d length=%d",e,t,n);r.httpRequest(e,t,n,o)})}u.prototype.httpRequest=function(e,t,r,n){var s=this;var a=e*s.parsedTorrent.pieceLength;var f=a+t;var u=f+r-1;i("Requesting pieceIndex=%d offset=%d length=%d start=%d end=%d",e,t,r,f,u);var c={url:s.url,method:"GET",headers:{"user-agent":"WebTorrent (http://webtorrent.io)",range:"bytes="+f+"-"+u}};o.concat(c,function(e,t,r){if(e)return n(e);if(r.statusCode<200||r.statusCode>=300){return n(new Error("Unexpected HTTP status code "+r.statusCode))}i("Got data of length %d",t.length);n(null,t)})}},{bitfield:7,"bittorrent-protocol":11,debug:71,inherits:79,"simple-get":131,"simple-sha1":139}],11:[function(e,t,r){(function(r){t.exports=w;var n=e("bencode");var i=e("bitfield");var o=e("debug")("bittorrent-protocol");var s=e("xtend");var a=e("hat");var f=e("inherits");var u=e("speedometer");var c=e("stream");var l=4e5;var d=new r("BitTorrent protocol");var h=new r([0,0,0,0]);var p=new r([0,0,0,1,0]);var m=new r([0,0,0,1,1]);var v=new r([0,0,0,1,2]);var g=new r([0,0,0,1,3]);var y=[0,0,0,0,0,0,0,0];var _=[0,0,0,3,9,0,0];function b(e,t,r,n){this.piece=e;this.offset=t;this.length=r;this.callback=n}f(w,c.Duplex);function w(){if(!(this instanceof w))return new w;c.Duplex.call(this);this._debugId=a(32);this._debug("new wire");this.peerId=null;this.peerIdBuffer=null;this.amChoking=true;this.amInterested=false;this.peerChoking=true;this.peerInterested=false;this.peerPieces=new i(0,{grow:l});this.peerExtensions={};this.requests=[];this.peerRequests=[];this.extendedMapping={};this.peerExtendedMapping={};this.extendedHandshake={};this.peerExtendedHandshake={};this._ext={};this._nextExt=1;this.uploaded=0;this.downloaded=0;this.uploadSpeed=u();this.downloadSpeed=u();this._keepAliveInterval=null;this._timeout=null;this._timeoutMs=0;this.destroyed=false;this._finished=false;this._buffer=[];this._bufferSize=0;this._parser=null;this._parserSize=0;this.on("finish",this._onfinish);this._parseHandshake()}w.prototype.setKeepAlive=function(e){this._debug("setKeepAlive %s",e);clearInterval(this._keepAliveInterval);if(e===false)return;this._keepAliveInterval=setInterval(this.keepAlive.bind(this),6e4)};w.prototype.setTimeout=function(e,t){this._debug("setTimeout ms=%d unref=%s",e,t);this._clearTimeout();this._timeoutMs=e;this._timeoutUnref=!!t;this._updateTimeout()};w.prototype.destroy=function(){if(this.destroyed)return;this.destroyed=true;this._debug("destroy");this.emit("close");this.end()};w.prototype.end=function(){this._debug("end");this._onUninterested();this._onChoke();c.Duplex.prototype.end.apply(this,arguments)};w.prototype.use=function(e){var t=e.prototype.name;if(!t){throw new Error('Extension class requires a "name" property on the prototype')}this._debug("use extension.name=%s",t);var r=this._nextExt;var n=new e(this);function i(){}if(typeof n.onHandshake!=="function"){n.onHandshake=i}if(typeof n.onExtendedHandshake!=="function"){n.onExtendedHandshake=i}if(typeof n.onMessage!=="function"){n.onMessage=i}this.extendedMapping[r]=t;this._ext[t]=n;this[t]=n;this._nextExt+=1};w.prototype.keepAlive=function(){this._debug("keep-alive");this._push(h)};w.prototype.handshake=function(e,t,n){var i,o;if(typeof e==="string"){i=new r(e,"hex")}else{i=e;e=i.toString("hex")}if(typeof t==="string"){o=new r(t,"hex")}else{o=t;t=o.toString("hex")}if(i.length!==20||o.length!==20){throw new Error("infoHash and peerId MUST have length 20")}this._debug("handshake i=%s p=%s exts=%o",e,t,n);var s=new r(y);s[5]|=16;if(n&&n.dht)s[7]|=1;this._push(r.concat([d,s,i,o]));this._handshakeSent=true;if(this.peerExtensions.extended&&!this._extendedHandshakeSent){this._sendExtendedHandshake()}};w.prototype._sendExtendedHandshake=function(){var e=s(this.extendedHandshake);e.m={};for(var t in this.extendedMapping){var r=this.extendedMapping[t];e.m[r]=Number(t)}this.extended(0,n.encode(e));this._extendedHandshakeSent=true};w.prototype.choke=function(){if(this.amChoking)return;this.amChoking=true;this._debug("choke");this.peerRequests.splice(0,this.peerRequests.length);this._push(p)};w.prototype.unchoke=function(){if(!this.amChoking)return;this.amChoking=false;this._debug("unchoke");this._push(m)};w.prototype.interested=function(){if(this.amInterested)return;this.amInterested=true;this._debug("interested");this._push(v)};w.prototype.uninterested=function(){if(!this.amInterested)return;this.amInterested=false;this._debug("uninterested");this._push(g)};w.prototype.have=function(e){this._debug("have %d",e);this._message(4,[e],null)};w.prototype.bitfield=function(e){this._debug("bitfield");if(!r.isBuffer(e))e=e.buffer;this._message(5,[],e)};w.prototype.request=function(e,t,r,n){if(!n)n=function(){};if(this._finished)return n(new Error("wire is closed"));if(this.peerChoking)return n(new Error("peer is choking"));this._debug("request index=%d offset=%d length=%d",e,t,r);this.requests.push(new b(e,t,r,n));this._updateTimeout();this._message(6,[e,t,r],null)};w.prototype.piece=function(e,t,r){this._debug("piece index=%d offset=%d",e,t);this.uploaded+=r.length;this.uploadSpeed(r.length);this.emit("upload",r.length);this._message(7,[e,t],r)};w.prototype.cancel=function(e,t,r){this._debug("cancel index=%d offset=%d length=%d",e,t,r);this._callback(E(this.requests,e,t,r),new Error("request was cancelled"),null);this._message(8,[e,t,r],null)};w.prototype.port=function(e){this._debug("port %d",e);var t=new r(_);t.writeUInt16BE(e,5);this._push(t)};w.prototype.extended=function(e,t){this._debug("extended ext=%s",e);if(typeof e==="string"&&this.peerExtendedMapping[e]){e=this.peerExtendedMapping[e]}if(typeof e==="number"){var i=new r([e]);var o=r.isBuffer(t)?t:n.encode(t);this._message(20,[],r.concat([i,o]))}else{throw new Error("Unrecognized extension: "+e)}};w.prototype._onKeepAlive=function(){this._debug("got keep-alive");this.emit("keep-alive")};w.prototype._onHandshake=function(e,t,r){var n=e.toString("hex");var i=t.toString("hex");this._debug("got handshake i=%s p=%s exts=%o",n,i,r);this.peerId=i;this.peerIdBuffer=t;this.peerExtensions=r;this.emit("handshake",n,i,r);var o;for(o in this._ext){this._ext[o].onHandshake(n,i,r)}if(r.extended&&this._handshakeSent&&!this._extendedHandshakeSent){this._sendExtendedHandshake()}};w.prototype._onChoke=function(){this.peerChoking=true;this._debug("got choke");this.emit("choke");while(this.requests.length){this._callback(this.requests.shift(),new Error("peer is choking"),null)}};w.prototype._onUnchoke=function(){this.peerChoking=false;this._debug("got unchoke");this.emit("unchoke")};w.prototype._onInterested=function(){this.peerInterested=true;this._debug("got interested");this.emit("interested")};w.prototype._onUninterested=function(){this.peerInterested=false;this._debug("got uninterested");this.emit("uninterested")};w.prototype._onHave=function(e){if(this.peerPieces.get(e))return;this._debug("got have %d",e);this.peerPieces.set(e,true);this.emit("have",e)};w.prototype._onBitField=function(e){this.peerPieces=new i(e);this._debug("got bitfield");this.emit("bitfield",this.peerPieces)};w.prototype._onRequest=function(e,t,r){if(this.amChoking)return;this._debug("got request index=%d offset=%d length=%d",e,t,r);var n=function(n,o){if(i!==E(this.peerRequests,e,t,r))return;if(n)return this._debug("error satisfying request index=%d offset=%d length=%d (%s)",e,t,r,n.message);this.piece(e,t,o)}.bind(this);var i=new b(e,t,r,n);this.peerRequests.push(i);this.emit("request",e,t,r,n)};w.prototype._onPiece=function(e,t,r){this._debug("got piece index=%d offset=%d",e,t);this._callback(E(this.requests,e,t,r.length),null,r);this.downloaded+=r.length;this.downloadSpeed(r.length);this.emit("download",r.length);this.emit("piece",e,t,r)};w.prototype._onCancel=function(e,t,r){this._debug("got cancel index=%d offset=%d length=%d",e,t,r);E(this.peerRequests,e,t,r);this.emit("cancel",e,t,r)};w.prototype._onPort=function(e){this._debug("got port %d",e);this.emit("port",e)};w.prototype._onExtended=function(e,t){if(e===0){var r;try{r=n.decode(t)}catch(i){this._debug("ignoring invalid extended handshake: %s",i.message||i)}if(!r)return;this.peerExtendedHandshake=r;var o;if(typeof r.m==="object"){for(o in r.m){this.peerExtendedMapping[o]=Number(r.m[o].toString())}}for(o in this._ext){if(this.peerExtendedMapping[o]){this._ext[o].onExtendedHandshake(this.peerExtendedHandshake)}}this._debug("got extended handshake");this.emit("extended","handshake",this.peerExtendedHandshake)}else{if(this.extendedMapping[e]){e=this.extendedMapping[e];if(this._ext[e]){this._ext[e].onMessage(t)}}this._debug("got extended message ext=%s",e);this.emit("extended",e,t)}};w.prototype._onTimeout=function(){this._debug("request timed out");this._callback(this.requests.shift(),new Error("request has timed out"),null);this.emit("timeout")};w.prototype._push=function(e){if(this._finished)return;return this.push(e)};w.prototype._write=function(e,t,n){this._bufferSize+=e.length;this._buffer.push(e);while(this._bufferSize>=this._parserSize){var i=this._buffer.length===1?this._buffer[0]:r.concat(this._buffer);this._bufferSize-=this._parserSize;this._buffer=this._bufferSize?[i.slice(this._parserSize)]:[];this._parser(i.slice(0,this._parserSize))}n(null)};w.prototype._read=function(){};w.prototype._callback=function(e,t,r){if(!e)return;this._clearTimeout();if(!this.peerChoking&&!this._finished)this._updateTimeout();e.callback(t,r)};w.prototype._clearTimeout=function(){if(!this._timeout)return;clearTimeout(this._timeout);this._timeout=null};w.prototype._updateTimeout=function(){if(!this._timeoutMs||!this.requests.length||this._timeout)return;this._timeout=setTimeout(this._onTimeout.bind(this),this._timeoutMs);if(this._timeoutUnref&&this._timeout.unref)this._timeout.unref()};w.prototype._parse=function(e,t){this._parserSize=e;this._parser=t};w.prototype._message=function(e,t,n){var i=n?n.length:0;var o=new r(5+4*t.length);o.writeUInt32BE(o.length+i-4,0);o[4]=e;for(var s=0;s<t.length;s++){o.writeUInt32BE(t[s],5+4*s)}this._push(o);if(n)this._push(n)};w.prototype._onmessagelength=function(e){var t=e.readUInt32BE(0);if(t>0){this._parse(t,this._onmessage)}else{this._onKeepAlive();this._parse(4,this._onmessagelength)}};w.prototype._onmessage=function(e){this._parse(4,this._onmessagelength);switch(e[0]){case 0:return this._onChoke();case 1:return this._onUnchoke();case 2:return this._onInterested();case 3:return this._onUninterested();case 4:return this._onHave(e.readUInt32BE(1));case 5:return this._onBitField(e.slice(1));case 6:return this._onRequest(e.readUInt32BE(1),e.readUInt32BE(5),e.readUInt32BE(9));case 7:return this._onPiece(e.readUInt32BE(1),e.readUInt32BE(5),e.slice(9));case 8:return this._onCancel(e.readUInt32BE(1),e.readUInt32BE(5),e.readUInt32BE(9));case 9:return this._onPort(e.readUInt16BE(1));case 20:return this._onExtended(e.readUInt8(1),e.slice(2));default:this._debug("got unknown message");return this.emit("unknownmessage",e)}};w.prototype._parseHandshake=function(){this._parse(1,function(e){var t=e.readUInt8(0);this._parse(t+48,function(e){var r=e.slice(0,t);if(r.toString()!=="BitTorrent protocol"){this._debug("Error: wire not speaking BitTorrent protocol (%s)",r.toString());this.end();return}e=e.slice(t);this._onHandshake(e.slice(8,28),e.slice(28,48),{dht:!!(e[7]&1),extended:!!(e[5]&16)});this._parse(4,this._onmessagelength)}.bind(this))}.bind(this))};w.prototype._onfinish=function(){this._finished=true;this.push(null);while(this.read()){}clearInterval(this._keepAliveInterval);this._parse(Number.MAX_VALUE,function(){});this.peerRequests=[];while(this.requests.length){this._callback(this.requests.shift(),new Error("wire was closed"),null)}};w.prototype._debug=function(){var e=[].slice.call(arguments);e[0]="["+this._debugId+"] "+e[0];o.apply(null,e)};function E(e,t,r,n){for(var i=0;i<e.length;i++){var o=e[i];if(o.piece!==t||o.offset!==r||o.length!==n)continue;if(i===0)e.shift();else e.splice(i,1);return o}return null}}).call(this,e("buffer").Buffer)},{bencode:12,bitfield:7,buffer:26,debug:71,hat:77,inherits:79,speedometer:141,stream:39,xtend:156}],12:[function(e,t,r){t.exports={encode:e("./lib/encode"),decode:e("./lib/decode")}},{"./lib/decode":13,"./lib/encode":15}],13:[function(e,t,r){(function(r){var n=e("./dict");function i(e,t){i.position=0;i.encoding=t||null;i.data=!r.isBuffer(e)?new r(e):e;return i.next()}i.position=0;i.data=null;i.encoding=null;i.next=function(){switch(i.data[i.position]){case 100:return i.dictionary();break;case 108:return i.list();break;case 105:return i.integer();break;default:return i.bytes();break}};i.find=function(e){var t=i.position;var r=i.data.length;var n=i.data;while(t<r){if(n[t]===e)return t;t++}throw new Error('Invalid data: Missing delimiter "'+String.fromCharCode(e)+'" [0x'+e.toString(16)+"]")};i.dictionary=function(){i.position++;var e=new n;while(i.data[i.position]!==101){e.binarySet(i.bytes(),i.next())}i.position++;return e};i.list=function(){i.position++;var e=[];while(i.data[i.position]!==101){e.push(i.next())}i.position++;return e};i.integer=function(){var e=i.find(101);var t=i.data.toString("ascii",i.position+1,e);i.position+=e+1-i.position;return parseInt(t,10)};i.bytes=function(){var e=i.find(58);var t=parseInt(i.data.toString("ascii",i.position,e),10);var r=++e+t;i.position=r;return i.encoding?i.data.toString(i.encoding,e,r):i.data.slice(e,r)};t.exports=i}).call(this,e("buffer").Buffer)},{"./dict":14,buffer:26}],14:[function(e,t,r){var n=t.exports=function i(){Object.defineProperty(this,"_keys",{enumerable:false,value:[]})};n.prototype.binaryKeys=function o(){return this._keys.slice()};n.prototype.binarySet=function s(e,t){this._keys.push(e);this[e]=t}},{}],15:[function(e,t,r){(function(e){function r(t){var n=[];r._encode(n,t);return e.concat(n)}r._floatConversionDetected=false;r._encode=function(t,n){if(e.isBuffer(n)){t.push(new e(n.length+":"));t.push(n);return}switch(typeof n){case"string":r.bytes(t,n);break;case"number":r.number(t,n);break;case"object":n.constructor===Array?r.list(t,n):r.dict(t,n);break}};var n=new e("e"),i=new e("d"),o=new e("l");r.bytes=function(t,r){t.push(new e(e.byteLength(r)+":"+r))};r.number=function(t,n){var i=2147483648;var o=n/i<<0;var s=n%i<<0;var a=o*i+s;t.push(new e("i"+a+"e"));if(a!==n&&!r._floatConversionDetected){r._floatConversionDetected=true;console.warn('WARNING: Possible data corruption detected with value "'+n+'":','Bencoding only defines support for integers, value was converted to "'+a+'"');console.trace()}};r.dict=function(e,t){e.push(i);var o=0;var s;var a=Object.keys(t).sort();var f=a.length;for(;o<f;o++){s=a[o];r.bytes(e,s);r._encode(e,t[s])}e.push(n)};r.list=function(e,t){var i=0,s=1;var a=t.length;e.push(o);for(;i<a;i++){r._encode(e,t[i])}e.push(n)};t.exports=r}).call(this,e("buffer").Buffer)},{buffer:26}],16:[function(e,t,r){(function(r,n){t.exports=m;var i=e("events").EventEmitter;var o=e("debug")("bittorrent-tracker");var s=e("inherits");var a=e("once");var f=e("run-parallel");var u=e("uniq");var c=e("url");var l=e("./lib/common");var d=e("./lib/client/http-tracker");var h=e("./lib/client/udp-tracker");var p=e("./lib/client/websocket-tracker");s(m,i);function m(e,t,s,a){var f=this;if(!(f instanceof m))return new m(e,t,s,a);i.call(f);if(!a)a={};f.peerId=typeof e==="string"?e:e.toString("hex");f.peerIdBuffer=new n(f.peerId,"hex");f._peerIdBinary=f.peerIdBuffer.toString("binary");f.infoHash=typeof s.infoHash==="string"?s.infoHash:s.infoHash.toString("hex");f.infoHashBuffer=new n(f.infoHash,"hex");f._infoHashBinary=f.infoHashBuffer.toString("binary");f.torrentLength=s.length;f.destroyed=false;f._port=t;f._rtcConfig=a.rtcConfig;f._wrtc=a.wrtc;o("new client %s",f.infoHash);var l=!!f._wrtc||typeof window!=="undefined";var v=typeof s.announce==="string"?[s.announce]:s.announce==null?[]:s.announce;v=v.map(function(e){e=e.toString();if(e[e.length-1]==="/"){e=e.substring(0,e.length-1)}return e});v=u(v);f._trackers=v.map(function(e){var t=c.parse(e).protocol;if((t==="http:"||t==="https:")&&typeof d==="function"){return new d(f,e)}else if(t==="udp:"&&typeof h==="function"){return new h(f,e)}else if((t==="ws:"||t==="wss:")&&l){return new p(f,e)}else{r.nextTick(function(){var t=new Error("unsupported tracker protocol for "+e);f.emit("warning",t)})}return null}).filter(Boolean)}m.scrape=function(e,t,r){r=a(r);var i=new n("01234567890123456789");var o=6881;var s={infoHash:Array.isArray(t)?t[0]:t,announce:[e]};var f=new m(i,o,s);f.once("error",r);var u=Array.isArray(t)?t.length:1;var c={};f.on("scrape",function(e){u-=1;c[e.infoHash]=e;if(u===0){f.destroy();var t=Object.keys(c);if(t.length===1){r(null,c[t[0]])}else{r(null,c)}}});t=Array.isArray(t)?t.map(function(e){return new n(e,"hex")}):new n(t,"hex");f.scrape({infoHash:t})};m.prototype.start=function(e){var t=this;o("send `start`");e=t._defaultAnnounceOpts(e);e.event="started";t._announce(e);t._trackers.forEach(function(e){e.setInterval()})};m.prototype.stop=function(e){var t=this;o("send `stop`");e=t._defaultAnnounceOpts(e);e.event="stopped";t._announce(e)};m.prototype.complete=function(e){var t=this;o("send `complete`");if(!e)e={};if(e.downloaded==null&&t.torrentLength!=null){e.downloaded=t.torrentLength}e=t._defaultAnnounceOpts(e);e.event="completed";t._announce(e)};m.prototype.update=function(e){var t=this;o("send `update`");e=t._defaultAnnounceOpts(e);if(e.event)delete e.event;t._announce(e)};m.prototype._announce=function(e){var t=this;t._trackers.forEach(function(t){t.announce(e)})};m.prototype.scrape=function(e){var t=this;o("send `scrape`");if(!e)e={};t._trackers.forEach(function(t){t.scrape(e)})};m.prototype.setInterval=function(e){var t=this;o("setInterval %d",e);t._trackers.forEach(function(t){t.setInterval(e)})};m.prototype.destroy=function(e){var t=this;if(t.destroyed)return;t.destroyed=true;o("destroy");var r=t._trackers.map(function(e){return function(t){e.destroy(t)}});f(r,e);t._trackers=[]};m.prototype._defaultAnnounceOpts=function(e){var t=this;if(!e)e={};if(e.numwant==null)e.numwant=l.DEFAULT_ANNOUNCE_PEERS;if(e.uploaded==null)e.uploaded=0;if(e.downloaded==null)e.downloaded=0;if(e.left==null&&t.torrentLength!=null){e.left=t.torrentLength-e.downloaded}return e}}).call(this,e("_process"),e("buffer").Buffer)},{"./lib/client/http-tracker":25,"./lib/client/udp-tracker":25,"./lib/client/websocket-tracker":18,"./lib/common":19,_process:34,buffer:26,debug:71,events:30,inherits:79,once:21,"run-parallel":130,uniq:150,url:46}],17:[function(e,t,r){t.exports=o;var n=e("events").EventEmitter;var i=e("inherits");i(o,n);function o(e,t){var r=this;n.call(r);r.client=e;r.announceUrl=t;r.interval=null;r.destroyed=false}o.prototype.setInterval=function(e){var t=this;if(e==null)e=t.DEFAULT_ANNOUNCE_INTERVAL;clearInterval(t.interval);if(e){var r=t.announce.bind(t,t.client._defaultAnnounceOpts());t.interval=setInterval(r,e);if(t.interval.unref)t.interval.unref()}}},{events:30,inherits:79}],18:[function(e,t,r){t.exports=p;var n=e("debug")("bittorrent-tracker:websocket-tracker");var i=e("hat");var o=e("inherits");var s=e("simple-peer");var a=e("simple-websocket");var f=e("../common");var u=e("./tracker");var c={};var l=30*1e3;var d=5*1e3;var h=50*1e3;o(p,u);function p(e,t,r){var i=this;u.call(i,e,t);n("new websocket tracker %s",t);i.peers={};i.socket=null;i.reconnecting=false;i._openSocket()}p.prototype.DEFAULT_ANNOUNCE_INTERVAL=30*1e3;p.prototype.announce=function(e){var t=this;if(t.destroyed||t.reconnecting)return;if(!t.socket.connected){return t.socket.once("connect",t.announce.bind(t,e))}var r=Math.min(e.numwant,10);t._generateOffers(r,function(n){var i={numwant:r,uploaded:e.uploaded||0,downloaded:e.downloaded,event:e.event,info_hash:t.client._infoHashBinary,peer_id:t.client._peerIdBinary,offers:n};if(t._trackerId)i.trackerid=t._trackerId;t._send(i)})};p.prototype.scrape=function(e){var t=this;if(t.destroyed||t.reconnecting)return;t._onSocketError(new Error("scrape not supported "+t.announceUrl))};p.prototype.destroy=function(e){var t=this;if(t.destroyed)return;t.destroyed=true;clearInterval(t.interval);c[t.announceUrl]=null;t.socket.removeListener("connect",t._onSocketConnectBound);t.socket.removeListener("data",t._onSocketDataBound);t.socket.removeListener("close",t._onSocketCloseBound);t.socket.removeListener("error",t._onSocketErrorBound);t._onSocketConnectBound=null;t._onSocketErrorBound=null;t._onSocketDataBound=null;t._onSocketCloseBound=null;t.socket.on("error",m);try{t.socket.destroy(e)}catch(r){if(e)e()}t.socket=null};p.prototype._openSocket=function(){var e=this;e.destroyed=false;e._onSocketConnectBound=e._onSocketConnect.bind(e);e._onSocketErrorBound=e._onSocketError.bind(e);e._onSocketDataBound=e._onSocketData.bind(e);e._onSocketCloseBound=e._onSocketClose.bind(e);e.socket=c[e.announceUrl];if(!e.socket){e.socket=c[e.announceUrl]=new a(e.announceUrl);e.socket.on("connect",e._onSocketConnectBound)}e.socket.on("data",e._onSocketDataBound);e.socket.on("close",e._onSocketCloseBound);e.socket.on("error",e._onSocketErrorBound)};p.prototype._onSocketConnect=function(){var e=this;if(e.destroyed)return;if(e.reconnecting){e.reconnecting=false;e.announce(e.client._defaultAnnounceOpts())}};p.prototype._onSocketData=function(e){var t=this;if(t.destroyed)return;if(!(typeof e==="object"&&e!==null)){return t.client.emit("warning",new Error("Invalid tracker response"))}if(e.info_hash!==t.client._infoHashBinary){n("ignoring websocket data from %s for %s (looking for %s: reused socket)",t.announceUrl,f.binaryToHex(e.info_hash),t.client.infoHash);return}if(e.peer_id&&e.peer_id===t.client._peerIdBinary){return}n("received %s from %s for %s",JSON.stringify(e),t.announceUrl,t.client.infoHash);var r=e["failure reason"];if(r)return t.client.emit("warning",new Error(r));var i=e["warning message"];if(i)t.client.emit("warning",new Error(i));var o=e.interval||e["min interval"];if(o)t.setInterval(o*1e3);var a=e["tracker id"];if(a){t._trackerId=a}if(e.complete){t.client.emit("update",{announce:t.announceUrl,complete:e.complete,incomplete:e.incomplete})}var u;if(e.offer&&e.peer_id){n("creating peer (from remote offer)");u=new s({trickle:false,config:t.client._rtcConfig,wrtc:t.client._wrtc});u.id=f.binaryToHex(e.peer_id);u.once("signal",function(r){var n={info_hash:t.client._infoHashBinary,peer_id:t.client._peerIdBinary,to_peer_id:e.peer_id,answer:r,offer_id:e.offer_id};if(t._trackerId)n.trackerid=t._trackerId;t._send(n)});u.signal(e.offer);t.client.emit("peer",u)}if(e.answer&&e.peer_id){var c=f.binaryToHex(e.offer_id);u=t.peers[c];if(u){u.id=f.binaryToHex(e.peer_id);u.signal(e.answer);t.client.emit("peer",u);clearTimeout(u.trackerTimeout);u.trackerTimeout=null;t.peers[c]=null}else{n("got unexpected answer: "+JSON.stringify(e.answer))}}};p.prototype._onSocketClose=function(){var e=this;if(e.destroyed)return;e.destroy();e._startReconnectTimer()};p.prototype._onSocketError=function(e){var t=this;if(t.destroyed)return;t.destroy();t.client.emit("warning",e);t._startReconnectTimer()};p.prototype._startReconnectTimer=function(){var e=this;var t=Math.floor(Math.random()*l)+d;e.reconnecting=true;var r=setTimeout(function(){e._openSocket()},t);if(r.unref)r.unref();n("reconnecting socket in %s ms",t)};p.prototype._send=function(e){var t=this;if(t.destroyed)return;var r=JSON.stringify(e);n("send %s",r);t.socket.send(r)};p.prototype._generateOffers=function(e,t){var r=this;var o=[];n("generating %s offers",e);for(var a=0;a<e;++a){u()}function u(){var e=i(160);n("creating peer (from _generateOffers)");var t=r.peers[e]=new s({initiator:true,trickle:false,config:r.client._rtcConfig,wrtc:r.client._wrtc});t.once("signal",function(t){o.push({offer:t,offer_id:f.hexToBinary(e)});c()});t.trackerTimeout=setTimeout(function(){n("tracker timeout: destroying peer");t.trackerTimeout=null;r.peers[e]=null;t.destroy()},h)}function c(){if(o.length===e){n("generated %s offers",e);t(o)}}};function m(){}},{"../common":19,"./tracker":17,debug:71,hat:77,inherits:79,"simple-peer":134,"simple-websocket":22}],19:[function(e,t,r){(function(t){var n=e("xtend/mutable");r.DEFAULT_ANNOUNCE_PEERS=50;r.MAX_ANNOUNCE_PEERS=82;r.binaryToHex=function(e){return new t(e,"binary").toString("hex")};r.hexToBinary=function(e){return new t(e,"hex").toString("binary")};var i=e("./common-node");n(r,i)}).call(this,e("buffer").Buffer)},{"./common-node":25,buffer:26,"xtend/mutable":157}],20:[function(e,t,r){t.exports=n;function n(e,t){if(e&&t)return n(e)(t);if(typeof e!=="function")throw new TypeError("need wrapper function");Object.keys(e).forEach(function(t){r[t]=e[t]});return r;function r(){var t=new Array(arguments.length);for(var r=0;r<t.length;r++){t[r]=arguments[r]}var n=e.apply(this,t);var i=t[t.length-1];if(typeof n==="function"&&n!==i){Object.keys(i).forEach(function(e){n[e]=i[e]})}return n}}},{}],21:[function(e,t,r){var n=e("wrappy");t.exports=n(i);i.proto=i(function(){Object.defineProperty(Function.prototype,"once",{value:function(){return i(this)},configurable:true})});function i(e){var t=function(){if(t.called)return t.value;t.called=true;return t.value=e.apply(this,arguments)};t.called=false;return t}},{wrappy:20}],22:[function(e,t,r){(function(r){t.exports=u;var n=e("debug")("simple-websocket");var i=e("inherits");var o=e("is-typedarray");var s=e("stream");var a=e("ws");var f=typeof window!=="undefined"?window.WebSocket:a;i(u,s.Duplex);function u(e,t){var r=this;if(!(r instanceof u))return new u(e,t);if(!t)t={};n("new websocket: %s %o",e,t);t.allowHalfOpen=false;if(t.highWaterMark==null)t.highWaterMark=1024*1024;s.Duplex.call(r,t);r.url=e;r.connected=false;r.destroyed=false;r._maxBufferedAmount=t.highWaterMark;r._chunk=null;r._cb=null;r._interval=null;r._ws=new f(r.url);r._ws.binaryType="arraybuffer";r._ws.onopen=r._onOpen.bind(r);r._ws.onmessage=r._onMessage.bind(r);r._ws.onclose=r._onClose.bind(r);r._ws.onerror=function(){r._onError(new Error("connection error to "+r.url))};r.on("finish",function(){if(r.connected){setTimeout(function(){r._destroy()},100)}else{r.once("connect",function(){setTimeout(function(){r._destroy()},100)})}})}u.WEBSOCKET_SUPPORT=!!f;u.prototype.send=function(e){var t=this;if(!o.strict(e)&&!(e instanceof ArrayBuffer)&&!r.isBuffer(e)&&typeof e!=="string"&&(typeof Blob==="undefined"||!(e instanceof Blob))){e=JSON.stringify(e)}var i=e.length||e.byteLength||e.size;t._ws.send(e);n("write: %d bytes",i)};u.prototype.destroy=function(e){var t=this;t._destroy(null,e)};u.prototype._destroy=function(e,t){var r=this;if(r.destroyed)return;if(t)r.once("close",t);n("destroy (error: %s)",e&&e.message);this.readable=this.writable=false;if(!r._readableState.ended)r.push(null);if(!r._writableState.finished)r.end();r.connected=false;r.destroyed=true;clearInterval(r._interval);r._interval=null;r._chunk=null;r._cb=null;if(r._ws){var i=r._ws;var o=function(){i.onclose=null;r.emit("close")};if(i.readyState===f.CLOSED){o()}else{try{i.onclose=o;i.close()}catch(e){o()}}i.onopen=null;i.onmessage=null;i.onerror=null}r._ws=null;if(e)r.emit("error",e)};u.prototype._read=function(){};u.prototype._write=function(e,t,r){var i=this;if(i.destroyed)return r(new Error("cannot write after socket is destroyed"));if(i.connected){try{i.send(e)}catch(o){return i._onError(o)}if(typeof a!=="function"&&i._ws.bufferedAmount>i._maxBufferedAmount){n("start backpressure: bufferedAmount %d",i._ws.bufferedAmount);i._cb=r}else{r(null)}}else{n("write before connect");i._chunk=e;i._cb=r}};u.prototype._onMessage=function(e){var t=this;if(t.destroyed)return;var i=e.data;n("read: %d bytes",i.byteLength||i.length);if(i instanceof ArrayBuffer){i=new r(i);t.push(i)}else if(r.isBuffer(i)){t.push(i)}else{try{i=JSON.parse(i)}catch(o){}t.emit("data",i)}};u.prototype._onOpen=function(){var e=this;if(e.connected||e.destroyed)return;e.connected=true;if(e._chunk){try{e.send(e._chunk)}catch(t){return e._onError(t)}e._chunk=null;n('sent chunk from "write before connect"');var r=e._cb;e._cb=null;r(null)}if(typeof a!=="function"){e._interval=setInterval(function(){if(!e._cb||!e._ws||e._ws.bufferedAmount>e._maxBufferedAmount){return}n("ending backpressure: bufferedAmount %d",e._ws.bufferedAmount);var t=e._cb;e._cb=null;t(null)},150);if(e._interval.unref)e._interval.unref()}n("connect");e.emit("connect")};u.prototype._onClose=function(){var e=this;if(e.destroyed)return;n("on close");e._destroy()};u.prototype._onError=function(e){var t=this;if(t.destroyed)return;n("error: %s",e.message||e);t._destroy(e)}}).call(this,e("buffer").Buffer)},{buffer:26,debug:71,inherits:79,"is-typedarray":23,stream:39,ws:25}],23:[function(e,t,r){t.exports=o;o.strict=s;o.loose=a;var n=Object.prototype.toString;var i={"[object Int8Array]":true,"[object Int16Array]":true,"[object Int32Array]":true,"[object Uint8Array]":true,"[object Uint8ClampedArray]":true,"[object Uint16Array]":true,"[object Uint32Array]":true,"[object Float32Array]":true,"[object Float64Array]":true};function o(e){return s(e)||a(e)}function s(e){return e instanceof Int8Array||e instanceof Int16Array||e instanceof Int32Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Uint16Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array; -}function a(e){return i[n.call(e)]}},{}],24:[function(e,t,r){},{}],25:[function(e,t,r){arguments[4][24][0].apply(r,arguments)},{dup:24}],26:[function(e,t,r){(function(t){"use strict";var n=e("base64-js");var i=e("ieee754");var o=e("isarray");r.Buffer=u;r.SlowBuffer=w;r.INSPECT_MAX_BYTES=50;u.poolSize=8192;var s={};u.TYPED_ARRAY_SUPPORT=t.TYPED_ARRAY_SUPPORT!==undefined?t.TYPED_ARRAY_SUPPORT:a();function a(){try{var e=new Uint8Array(1);e.foo=function(){return 42};return e.foo()===42&&typeof e.subarray==="function"&&e.subarray(1,1).byteLength===0}catch(t){return false}}function f(){return u.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function u(e){if(!(this instanceof u)){if(arguments.length>1)return new u(e,arguments[1]);return new u(e)}if(!u.TYPED_ARRAY_SUPPORT){this.length=0;this.parent=undefined}if(typeof e==="number"){return c(this,e)}if(typeof e==="string"){return l(this,e,arguments.length>1?arguments[1]:"utf8")}return d(this,e)}u._augment=function(e){e.__proto__=u.prototype;return e};function c(e,t){e=_(e,t<0?0:b(t)|0);if(!u.TYPED_ARRAY_SUPPORT){for(var r=0;r<t;r++){e[r]=0}}return e}function l(e,t,r){if(typeof r!=="string"||r==="")r="utf8";var n=E(t,r)|0;e=_(e,n);e.write(t,r);return e}function d(e,t){if(u.isBuffer(t))return h(e,t);if(o(t))return p(e,t);if(t==null){throw new TypeError("must start with number, buffer, array or string")}if(typeof ArrayBuffer!=="undefined"){if(t.buffer instanceof ArrayBuffer){return m(e,t)}if(t instanceof ArrayBuffer){return v(e,t)}}if(t.length)return g(e,t);return y(e,t)}function h(e,t){var r=b(t.length)|0;e=_(e,r);t.copy(e,0,0,r);return e}function p(e,t){var r=b(t.length)|0;e=_(e,r);for(var n=0;n<r;n+=1){e[n]=t[n]&255}return e}function m(e,t){var r=b(t.length)|0;e=_(e,r);for(var n=0;n<r;n+=1){e[n]=t[n]&255}return e}function v(e,t){t.byteLength;if(u.TYPED_ARRAY_SUPPORT){e=new Uint8Array(t);e.__proto__=u.prototype}else{e=m(e,new Uint8Array(t))}return e}function g(e,t){var r=b(t.length)|0;e=_(e,r);for(var n=0;n<r;n+=1){e[n]=t[n]&255}return e}function y(e,t){var r;var n=0;if(t.type==="Buffer"&&o(t.data)){r=t.data;n=b(r.length)|0}e=_(e,n);for(var i=0;i<n;i+=1){e[i]=r[i]&255}return e}if(u.TYPED_ARRAY_SUPPORT){u.prototype.__proto__=Uint8Array.prototype;u.__proto__=Uint8Array}else{u.prototype.length=undefined;u.prototype.parent=undefined}function _(e,t){if(u.TYPED_ARRAY_SUPPORT){e=new Uint8Array(t);e.__proto__=u.prototype}else{e.length=t}var r=t!==0&&t<=u.poolSize>>>1;if(r)e.parent=s;return e}function b(e){if(e>=f()){throw new RangeError("Attempt to allocate Buffer larger than maximum "+"size: 0x"+f().toString(16)+" bytes")}return e|0}function w(e,t){if(!(this instanceof w))return new w(e,t);var r=new u(e,t);delete r.parent;return r}u.isBuffer=function ee(e){return!!(e!=null&&e._isBuffer)};u.compare=function te(e,t){if(!u.isBuffer(e)||!u.isBuffer(t)){throw new TypeError("Arguments must be Buffers")}if(e===t)return 0;var r=e.length;var n=t.length;var i=0;var o=Math.min(r,n);while(i<o){if(e[i]!==t[i])break;++i}if(i!==o){r=e[i];n=t[i]}if(r<n)return-1;if(n<r)return 1;return 0};u.isEncoding=function re(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return true;default:return false}};u.concat=function ne(e,t){if(!o(e))throw new TypeError("list argument must be an Array of Buffers.");if(e.length===0){return new u(0)}var r;if(t===undefined){t=0;for(r=0;r<e.length;r++){t+=e[r].length}}var n=new u(t);var i=0;for(r=0;r<e.length;r++){var s=e[r];s.copy(n,i);i+=s.length}return n};function E(e,t){if(typeof e!=="string")e=""+e;var r=e.length;if(r===0)return 0;var n=false;for(;;){switch(t){case"ascii":case"binary":case"raw":case"raws":return r;case"utf8":case"utf-8":return K(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Z(e).length;default:if(n)return K(e).length;t=(""+t).toLowerCase();n=true}}}u.byteLength=E;function k(e,t,r){var n=false;t=t|0;r=r===undefined||r===Infinity?this.length:r|0;if(!e)e="utf8";if(t<0)t=0;if(r>this.length)r=this.length;if(r<=t)return"";while(true){switch(e){case"hex":return M(this,t,r);case"utf8":case"utf-8":return L(this,t,r);case"ascii":return P(this,t,r);case"binary":return O(this,t,r);case"base64":return T(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return j(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase();n=true}}}u.prototype._isBuffer=true;u.prototype.toString=function ie(){var e=this.length|0;if(e===0)return"";if(arguments.length===0)return L(this,0,e);return k.apply(this,arguments)};u.prototype.equals=function oe(e){if(!u.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(this===e)return true;return u.compare(this,e)===0};u.prototype.inspect=function se(){var e="";var t=r.INSPECT_MAX_BYTES;if(this.length>0){e=this.toString("hex",0,t).match(/.{2}/g).join(" ");if(this.length>t)e+=" ... "}return"<Buffer "+e+">"};u.prototype.compare=function ae(e){if(!u.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(this===e)return 0;return u.compare(this,e)};u.prototype.indexOf=function fe(e,t){if(t>2147483647)t=2147483647;else if(t<-2147483648)t=-2147483648;t>>=0;if(this.length===0)return-1;if(t>=this.length)return-1;if(t<0)t=Math.max(this.length+t,0);if(typeof e==="string"){if(e.length===0)return-1;return String.prototype.indexOf.call(this,e,t)}if(u.isBuffer(e)){return r(this,e,t)}if(typeof e==="number"){if(u.TYPED_ARRAY_SUPPORT&&Uint8Array.prototype.indexOf==="function"){return Uint8Array.prototype.indexOf.call(this,e,t)}return r(this,[e],t)}function r(e,t,r){var n=-1;for(var i=0;r+i<e.length;i++){if(e[r+i]===t[n===-1?0:i-n]){if(n===-1)n=i;if(i-n+1===t.length)return r+n}else{n=-1}}return-1}throw new TypeError("val must be string, number or Buffer")};function x(e,t,r,n){r=Number(r)||0;var i=e.length-r;if(!n){n=i}else{n=Number(n);if(n>i){n=i}}var o=t.length;if(o%2!==0)throw new Error("Invalid hex string");if(n>o/2){n=o/2}for(var s=0;s<n;s++){var a=parseInt(t.substr(s*2,2),16);if(isNaN(a))throw new Error("Invalid hex string");e[r+s]=a}return s}function S(e,t,r,n){return Q(K(t,e.length-r),e,r,n)}function I(e,t,r,n){return Q(J(t),e,r,n)}function B(e,t,r,n){return I(e,t,r,n)}function A(e,t,r,n){return Q(Z(t),e,r,n)}function C(e,t,r,n){return Q(X(t,e.length-r),e,r,n)}u.prototype.write=function ue(e,t,r,n){if(t===undefined){n="utf8";r=this.length;t=0}else if(r===undefined&&typeof t==="string"){n=t;r=this.length;t=0}else if(isFinite(t)){t=t|0;if(isFinite(r)){r=r|0;if(n===undefined)n="utf8"}else{n=r;r=undefined}}else{var i=n;n=t;t=r|0;r=i}var o=this.length-t;if(r===undefined||r>o)r=o;if(e.length>0&&(r<0||t<0)||t>this.length){throw new RangeError("attempt to write outside buffer bounds")}if(!n)n="utf8";var s=false;for(;;){switch(n){case"hex":return x(this,e,t,r);case"utf8":case"utf-8":return S(this,e,t,r);case"ascii":return I(this,e,t,r);case"binary":return B(this,e,t,r);case"base64":return A(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,e,t,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase();s=true}}};u.prototype.toJSON=function ce(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function T(e,t,r){if(t===0&&r===e.length){return n.fromByteArray(e)}else{return n.fromByteArray(e.slice(t,r))}}function L(e,t,r){r=Math.min(e.length,r);var n=[];var i=t;while(i<r){var o=e[i];var s=null;var a=o>239?4:o>223?3:o>191?2:1;if(i+a<=r){var f,u,c,l;switch(a){case 1:if(o<128){s=o}break;case 2:f=e[i+1];if((f&192)===128){l=(o&31)<<6|f&63;if(l>127){s=l}}break;case 3:f=e[i+1];u=e[i+2];if((f&192)===128&&(u&192)===128){l=(o&15)<<12|(f&63)<<6|u&63;if(l>2047&&(l<55296||l>57343)){s=l}}break;case 4:f=e[i+1];u=e[i+2];c=e[i+3];if((f&192)===128&&(u&192)===128&&(c&192)===128){l=(o&15)<<18|(f&63)<<12|(u&63)<<6|c&63;if(l>65535&&l<1114112){s=l}}}}if(s===null){s=65533;a=1}else if(s>65535){s-=65536;n.push(s>>>10&1023|55296);s=56320|s&1023}n.push(s);i+=a}return U(n)}var R=4096;function U(e){var t=e.length;if(t<=R){return String.fromCharCode.apply(String,e)}var r="";var n=0;while(n<t){r+=String.fromCharCode.apply(String,e.slice(n,n+=R))}return r}function P(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;i++){n+=String.fromCharCode(e[i]&127)}return n}function O(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;i++){n+=String.fromCharCode(e[i])}return n}function M(e,t,r){var n=e.length;if(!t||t<0)t=0;if(!r||r<0||r>n)r=n;var i="";for(var o=t;o<r;o++){i+=G(e[o])}return i}function j(e,t,r){var n=e.slice(t,r);var i="";for(var o=0;o<n.length;o+=2){i+=String.fromCharCode(n[o]+n[o+1]*256)}return i}u.prototype.slice=function le(e,t){var r=this.length;e=~~e;t=t===undefined?r:~~t;if(e<0){e+=r;if(e<0)e=0}else if(e>r){e=r}if(t<0){t+=r;if(t<0)t=0}else if(t>r){t=r}if(t<e)t=e;var n;if(u.TYPED_ARRAY_SUPPORT){n=this.subarray(e,t);n.__proto__=u.prototype}else{var i=t-e;n=new u(i,undefined);for(var o=0;o<i;o++){n[o]=this[o+e]}}if(n.length)n.parent=this.parent||this;return n};function D(e,t,r){if(e%1!==0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}u.prototype.readUIntLE=function de(e,t,r){e=e|0;t=t|0;if(!r)D(e,t,this.length);var n=this[e];var i=1;var o=0;while(++o<t&&(i*=256)){n+=this[e+o]*i}return n};u.prototype.readUIntBE=function he(e,t,r){e=e|0;t=t|0;if(!r){D(e,t,this.length)}var n=this[e+--t];var i=1;while(t>0&&(i*=256)){n+=this[e+--t]*i}return n};u.prototype.readUInt8=function pe(e,t){if(!t)D(e,1,this.length);return this[e]};u.prototype.readUInt16LE=function me(e,t){if(!t)D(e,2,this.length);return this[e]|this[e+1]<<8};u.prototype.readUInt16BE=function ve(e,t){if(!t)D(e,2,this.length);return this[e]<<8|this[e+1]};u.prototype.readUInt32LE=function ge(e,t){if(!t)D(e,4,this.length);return(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};u.prototype.readUInt32BE=function ye(e,t){if(!t)D(e,4,this.length);return this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};u.prototype.readIntLE=function _e(e,t,r){e=e|0;t=t|0;if(!r)D(e,t,this.length);var n=this[e];var i=1;var o=0;while(++o<t&&(i*=256)){n+=this[e+o]*i}i*=128;if(n>=i)n-=Math.pow(2,8*t);return n};u.prototype.readIntBE=function be(e,t,r){e=e|0;t=t|0;if(!r)D(e,t,this.length);var n=t;var i=1;var o=this[e+--n];while(n>0&&(i*=256)){o+=this[e+--n]*i}i*=128;if(o>=i)o-=Math.pow(2,8*t);return o};u.prototype.readInt8=function we(e,t){if(!t)D(e,1,this.length);if(!(this[e]&128))return this[e];return(255-this[e]+1)*-1};u.prototype.readInt16LE=function Ee(e,t){if(!t)D(e,2,this.length);var r=this[e]|this[e+1]<<8;return r&32768?r|4294901760:r};u.prototype.readInt16BE=function ke(e,t){if(!t)D(e,2,this.length);var r=this[e+1]|this[e]<<8;return r&32768?r|4294901760:r};u.prototype.readInt32LE=function xe(e,t){if(!t)D(e,4,this.length);return this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};u.prototype.readInt32BE=function Se(e,t){if(!t)D(e,4,this.length);return this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};u.prototype.readFloatLE=function Ie(e,t){if(!t)D(e,4,this.length);return i.read(this,e,true,23,4)};u.prototype.readFloatBE=function Be(e,t){if(!t)D(e,4,this.length);return i.read(this,e,false,23,4)};u.prototype.readDoubleLE=function Ae(e,t){if(!t)D(e,8,this.length);return i.read(this,e,true,52,8)};u.prototype.readDoubleBE=function Ce(e,t){if(!t)D(e,8,this.length);return i.read(this,e,false,52,8)};function H(e,t,r,n,i,o){if(!u.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");if(t>i||t<o)throw new RangeError("value is out of bounds");if(r+n>e.length)throw new RangeError("index out of range")}u.prototype.writeUIntLE=function Te(e,t,r,n){e=+e;t=t|0;r=r|0;if(!n)H(this,e,t,r,Math.pow(2,8*r),0);var i=1;var o=0;this[t]=e&255;while(++o<r&&(i*=256)){this[t+o]=e/i&255}return t+r};u.prototype.writeUIntBE=function Le(e,t,r,n){e=+e;t=t|0;r=r|0;if(!n)H(this,e,t,r,Math.pow(2,8*r),0);var i=r-1;var o=1;this[t+i]=e&255;while(--i>=0&&(o*=256)){this[t+i]=e/o&255}return t+r};u.prototype.writeUInt8=function Re(e,t,r){e=+e;t=t|0;if(!r)H(this,e,t,1,255,0);if(!u.TYPED_ARRAY_SUPPORT)e=Math.floor(e);this[t]=e&255;return t+1};function N(e,t,r,n){if(t<0)t=65535+t+1;for(var i=0,o=Math.min(e.length-r,2);i<o;i++){e[r+i]=(t&255<<8*(n?i:1-i))>>>(n?i:1-i)*8}}u.prototype.writeUInt16LE=function Ue(e,t,r){e=+e;t=t|0;if(!r)H(this,e,t,2,65535,0);if(u.TYPED_ARRAY_SUPPORT){this[t]=e&255;this[t+1]=e>>>8}else{N(this,e,t,true)}return t+2};u.prototype.writeUInt16BE=function Pe(e,t,r){e=+e;t=t|0;if(!r)H(this,e,t,2,65535,0);if(u.TYPED_ARRAY_SUPPORT){this[t]=e>>>8;this[t+1]=e&255}else{N(this,e,t,false)}return t+2};function q(e,t,r,n){if(t<0)t=4294967295+t+1;for(var i=0,o=Math.min(e.length-r,4);i<o;i++){e[r+i]=t>>>(n?i:3-i)*8&255}}u.prototype.writeUInt32LE=function Oe(e,t,r){e=+e;t=t|0;if(!r)H(this,e,t,4,4294967295,0);if(u.TYPED_ARRAY_SUPPORT){this[t+3]=e>>>24;this[t+2]=e>>>16;this[t+1]=e>>>8;this[t]=e&255}else{q(this,e,t,true)}return t+4};u.prototype.writeUInt32BE=function Me(e,t,r){e=+e;t=t|0;if(!r)H(this,e,t,4,4294967295,0);if(u.TYPED_ARRAY_SUPPORT){this[t]=e>>>24;this[t+1]=e>>>16;this[t+2]=e>>>8;this[t+3]=e&255}else{q(this,e,t,false)}return t+4};u.prototype.writeIntLE=function je(e,t,r,n){e=+e;t=t|0;if(!n){var i=Math.pow(2,8*r-1);H(this,e,t,r,i-1,-i)}var o=0;var s=1;var a=e<0?1:0;this[t]=e&255;while(++o<r&&(s*=256)){this[t+o]=(e/s>>0)-a&255}return t+r};u.prototype.writeIntBE=function De(e,t,r,n){e=+e;t=t|0;if(!n){var i=Math.pow(2,8*r-1);H(this,e,t,r,i-1,-i)}var o=r-1;var s=1;var a=e<0?1:0;this[t+o]=e&255;while(--o>=0&&(s*=256)){this[t+o]=(e/s>>0)-a&255}return t+r};u.prototype.writeInt8=function He(e,t,r){e=+e;t=t|0;if(!r)H(this,e,t,1,127,-128);if(!u.TYPED_ARRAY_SUPPORT)e=Math.floor(e);if(e<0)e=255+e+1;this[t]=e&255;return t+1};u.prototype.writeInt16LE=function Ne(e,t,r){e=+e;t=t|0;if(!r)H(this,e,t,2,32767,-32768);if(u.TYPED_ARRAY_SUPPORT){this[t]=e&255;this[t+1]=e>>>8}else{N(this,e,t,true)}return t+2};u.prototype.writeInt16BE=function qe(e,t,r){e=+e;t=t|0;if(!r)H(this,e,t,2,32767,-32768);if(u.TYPED_ARRAY_SUPPORT){this[t]=e>>>8;this[t+1]=e&255}else{N(this,e,t,false)}return t+2};u.prototype.writeInt32LE=function ze(e,t,r){e=+e;t=t|0;if(!r)H(this,e,t,4,2147483647,-2147483648);if(u.TYPED_ARRAY_SUPPORT){this[t]=e&255;this[t+1]=e>>>8;this[t+2]=e>>>16;this[t+3]=e>>>24}else{q(this,e,t,true)}return t+4};u.prototype.writeInt32BE=function We(e,t,r){e=+e;t=t|0;if(!r)H(this,e,t,4,2147483647,-2147483648);if(e<0)e=4294967295+e+1;if(u.TYPED_ARRAY_SUPPORT){this[t]=e>>>24;this[t+1]=e>>>16;this[t+2]=e>>>8;this[t+3]=e&255}else{q(this,e,t,false)}return t+4};function z(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("index out of range");if(r<0)throw new RangeError("index out of range")}function W(e,t,r,n,o){if(!o){z(e,t,r,4,3.4028234663852886e38,-3.4028234663852886e38)}i.write(e,t,r,n,23,4);return r+4}u.prototype.writeFloatLE=function Fe(e,t,r){return W(this,e,t,true,r)};u.prototype.writeFloatBE=function Ye(e,t,r){return W(this,e,t,false,r)};function F(e,t,r,n,o){if(!o){z(e,t,r,8,1.7976931348623157e308,-1.7976931348623157e308)}i.write(e,t,r,n,52,8);return r+8}u.prototype.writeDoubleLE=function Ve(e,t,r){return F(this,e,t,true,r)};u.prototype.writeDoubleBE=function $e(e,t,r){return F(this,e,t,false,r)};u.prototype.copy=function Ge(e,t,r,n){if(!r)r=0;if(!n&&n!==0)n=this.length;if(t>=e.length)t=e.length;if(!t)t=0;if(n>0&&n<r)n=r;if(n===r)return 0;if(e.length===0||this.length===0)return 0;if(t<0){throw new RangeError("targetStart out of bounds")}if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");if(n>this.length)n=this.length;if(e.length-t<n-r){n=e.length-t+r}var i=n-r;var o;if(this===e&&r<t&&t<n){for(o=i-1;o>=0;o--){e[o+t]=this[o+r]}}else if(i<1e3||!u.TYPED_ARRAY_SUPPORT){for(o=0;o<i;o++){e[o+t]=this[o+r]}}else{Uint8Array.prototype.set.call(e,this.subarray(r,r+i),t)}return i};u.prototype.fill=function Ke(e,t,r){if(!e)e=0;if(!t)t=0;if(!r)r=this.length;if(r<t)throw new RangeError("end < start");if(r===t)return;if(this.length===0)return;if(t<0||t>=this.length)throw new RangeError("start out of bounds");if(r<0||r>this.length)throw new RangeError("end out of bounds");var n;if(typeof e==="number"){for(n=t;n<r;n++){this[n]=e}}else{var i=K(e.toString());var o=i.length;for(n=t;n<r;n++){this[n]=i[n%o]}}return this};var Y=/[^+\/0-9A-Za-z-_]/g;function V(e){e=$(e).replace(Y,"");if(e.length<2)return"";while(e.length%4!==0){e=e+"="}return e}function $(e){if(e.trim)return e.trim();return e.replace(/^\s+|\s+$/g,"")}function G(e){if(e<16)return"0"+e.toString(16);return e.toString(16)}function K(e,t){t=t||Infinity;var r;var n=e.length;var i=null;var o=[];for(var s=0;s<n;s++){r=e.charCodeAt(s);if(r>55295&&r<57344){if(!i){if(r>56319){if((t-=3)>-1)o.push(239,191,189);continue}else if(s+1===n){if((t-=3)>-1)o.push(239,191,189);continue}i=r;continue}if(r<56320){if((t-=3)>-1)o.push(239,191,189);i=r;continue}r=(i-55296<<10|r-56320)+65536}else if(i){if((t-=3)>-1)o.push(239,191,189)}i=null;if(r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else{throw new Error("Invalid code point")}}return o}function J(e){var t=[];for(var r=0;r<e.length;r++){t.push(e.charCodeAt(r)&255)}return t}function X(e,t){var r,n,i;var o=[];for(var s=0;s<e.length;s++){if((t-=2)<0)break;r=e.charCodeAt(s);n=r>>8;i=r%256;o.push(i);o.push(n)}return o}function Z(e){return n.toByteArray(V(e))}function Q(e,t,r,n){for(var i=0;i<n;i++){if(i+r>=t.length||i>=e.length)break;t[i+r]=e[i]}return i}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"base64-js":27,ieee754:28,isarray:29}],27:[function(e,t,r){(function(e){"use strict";var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var r=typeof Uint8Array!=="undefined"?Uint8Array:Array;var n="+".charCodeAt(0);var i="/".charCodeAt(0);var o="0".charCodeAt(0);var s="a".charCodeAt(0);var a="A".charCodeAt(0);var f="-".charCodeAt(0);var u="_".charCodeAt(0);function c(e){var t=e.charCodeAt(0);if(t===n||t===f)return 62;if(t===i||t===u)return 63;if(t<o)return-1;if(t<o+10)return t-o+26+26;if(t<a+26)return t-a;if(t<s+26)return t-s+26}function l(e){var t,n,i,o,s,a;if(e.length%4>0){throw new Error("Invalid string. Length must be a multiple of 4")}var f=e.length;s=e.charAt(f-2)==="="?2:e.charAt(f-1)==="="?1:0;a=new r(e.length*3/4-s);i=s>0?e.length-4:e.length;var u=0;function l(e){a[u++]=e}for(t=0,n=0;t<i;t+=4,n+=3){o=c(e.charAt(t))<<18|c(e.charAt(t+1))<<12|c(e.charAt(t+2))<<6|c(e.charAt(t+3));l((o&16711680)>>16);l((o&65280)>>8);l(o&255)}if(s===2){o=c(e.charAt(t))<<2|c(e.charAt(t+1))>>4;l(o&255)}else if(s===1){o=c(e.charAt(t))<<10|c(e.charAt(t+1))<<4|c(e.charAt(t+2))>>2;l(o>>8&255);l(o&255)}return a}function d(e){var r;var n=e.length%3;var i="";var o,s;function a(e){return t.charAt(e)}function f(e){return a(e>>18&63)+a(e>>12&63)+a(e>>6&63)+a(e&63)}for(r=0,s=e.length-n;r<s;r+=3){o=(e[r]<<16)+(e[r+1]<<8)+e[r+2];i+=f(o)}switch(n){case 1:o=e[e.length-1];i+=a(o>>2);i+=a(o<<4&63);i+="==";break;case 2:o=(e[e.length-2]<<8)+e[e.length-1];i+=a(o>>10);i+=a(o>>4&63);i+=a(o<<2&63);i+="=";break;default:break}return i}e.toByteArray=l;e.fromByteArray=d})(typeof r==="undefined"?this.base64js={}:r)},{}],28:[function(e,t,r){r.read=function(e,t,r,n,i){var o,s;var a=i*8-n-1;var f=(1<<a)-1;var u=f>>1;var c=-7;var l=r?i-1:0;var d=r?-1:1;var h=e[t+l];l+=d;o=h&(1<<-c)-1;h>>=-c;c+=a;for(;c>0;o=o*256+e[t+l],l+=d,c-=8){}s=o&(1<<-c)-1;o>>=-c;c+=n;for(;c>0;s=s*256+e[t+l],l+=d,c-=8){}if(o===0){o=1-u}else if(o===f){return s?NaN:(h?-1:1)*Infinity}else{s=s+Math.pow(2,n);o=o-u}return(h?-1:1)*s*Math.pow(2,o-n)};r.write=function(e,t,r,n,i,o){var s,a,f;var u=o*8-i-1;var c=(1<<u)-1;var l=c>>1;var d=i===23?Math.pow(2,-24)-Math.pow(2,-77):0;var h=n?0:o-1;var p=n?1:-1;var m=t<0||t===0&&1/t<0?1:0;t=Math.abs(t);if(isNaN(t)||t===Infinity){a=isNaN(t)?1:0;s=c}else{s=Math.floor(Math.log(t)/Math.LN2);if(t*(f=Math.pow(2,-s))<1){s--;f*=2}if(s+l>=1){t+=d/f}else{t+=d*Math.pow(2,1-l)}if(t*f>=2){s++;f/=2}if(s+l>=c){a=0;s=c}else if(s+l>=1){a=(t*f-1)*Math.pow(2,i);s=s+l}else{a=t*Math.pow(2,l-1)*Math.pow(2,i);s=0}}for(;i>=8;e[r+h]=a&255,h+=p,a/=256,i-=8){}s=s<<i|a;u+=i;for(;u>0;e[r+h]=s&255,h+=p,s/=256,u-=8){}e[r+h-p]|=m*128}},{}],29:[function(e,t,r){var n={}.toString;t.exports=Array.isArray||function(e){return n.call(e)=="[object Array]"}},{}],30:[function(e,t,r){function n(){this._events=this._events||{};this._maxListeners=this._maxListeners||undefined}t.exports=n;n.EventEmitter=n;n.prototype._events=undefined;n.prototype._maxListeners=undefined;n.defaultMaxListeners=10;n.prototype.setMaxListeners=function(e){if(!o(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");this._maxListeners=e;return this};n.prototype.emit=function(e){var t,r,n,o,f,u;if(!this._events)this._events={};if(e==="error"){if(!this._events.error||s(this._events.error)&&!this._events.error.length){t=arguments[1];if(t instanceof Error){throw t}throw TypeError('Uncaught, unspecified "error" event.')}}r=this._events[e];if(a(r))return false;if(i(r)){switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:o=Array.prototype.slice.call(arguments,1);r.apply(this,o)}}else if(s(r)){o=Array.prototype.slice.call(arguments,1);u=r.slice();n=u.length;for(f=0;f<n;f++)u[f].apply(this,o)}return true};n.prototype.addListener=function(e,t){var r;if(!i(t))throw TypeError("listener must be a function");if(!this._events)this._events={};if(this._events.newListener)this.emit("newListener",e,i(t.listener)?t.listener:t);if(!this._events[e])this._events[e]=t;else if(s(this._events[e]))this._events[e].push(t);else this._events[e]=[this._events[e],t];if(s(this._events[e])&&!this._events[e].warned){if(!a(this._maxListeners)){r=this._maxListeners}else{r=n.defaultMaxListeners}if(r&&r>0&&this._events[e].length>r){this._events[e].warned=true;console.error("(node) warning: possible EventEmitter memory "+"leak detected. %d listeners added. "+"Use emitter.setMaxListeners() to increase limit.",this._events[e].length);if(typeof console.trace==="function"){console.trace()}}}return this};n.prototype.on=n.prototype.addListener;n.prototype.once=function(e,t){if(!i(t))throw TypeError("listener must be a function");var r=false;function n(){this.removeListener(e,n);if(!r){r=true;t.apply(this,arguments)}}n.listener=t;this.on(e,n);return this};n.prototype.removeListener=function(e,t){var r,n,o,a;if(!i(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;r=this._events[e];o=r.length;n=-1;if(r===t||i(r.listener)&&r.listener===t){delete this._events[e];if(this._events.removeListener)this.emit("removeListener",e,t)}else if(s(r)){for(a=o;a-- >0;){if(r[a]===t||r[a].listener&&r[a].listener===t){n=a;break}}if(n<0)return this;if(r.length===1){r.length=0;delete this._events[e]}else{r.splice(n,1)}if(this._events.removeListener)this.emit("removeListener",e,t)}return this};n.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener){if(arguments.length===0)this._events={};else if(this._events[e])delete this._events[e];return this}if(arguments.length===0){for(t in this._events){if(t==="removeListener")continue;this.removeAllListeners(t)}this.removeAllListeners("removeListener");this._events={};return this}r=this._events[e];if(i(r)){this.removeListener(e,r)}else if(r){while(r.length)this.removeListener(e,r[r.length-1])}delete this._events[e];return this};n.prototype.listeners=function(e){var t;if(!this._events||!this._events[e])t=[];else if(i(this._events[e]))t=[this._events[e]];else t=this._events[e].slice();return t};n.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(i(t))return 1;else if(t)return t.length}return 0};n.listenerCount=function(e,t){return e.listenerCount(t)};function i(e){return typeof e==="function"}function o(e){return typeof e==="number"}function s(e){return typeof e==="object"&&e!==null}function a(e){return e===void 0}},{}],31:[function(e,t,r){var n=e("http");var i=t.exports;for(var o in n){if(n.hasOwnProperty(o))i[o]=n[o]}i.request=function(e,t){if(!e)e={};e.scheme="https";e.protocol="https:";return n.request.call(this,e,t)}},{http:40}],32:[function(e,t,r){t.exports=function(e){return!!(e!=null&&(e._isBuffer||e.constructor&&typeof e.constructor.isBuffer==="function"&&e.constructor.isBuffer(e)))}},{}],33:[function(e,t,r){(function(e){function t(e,t){var r=0;for(var n=e.length-1;n>=0;n--){var i=e[n];if(i==="."){e.splice(n,1)}else if(i===".."){e.splice(n,1);r++}else if(r){e.splice(n,1);r--}}if(t){for(;r--;r){e.unshift("..")}}return e}var n=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;var i=function(e){return n.exec(e).slice(1)};r.resolve=function(){var r="",n=false;for(var i=arguments.length-1;i>=-1&&!n;i--){var s=i>=0?arguments[i]:e.cwd();if(typeof s!=="string"){throw new TypeError("Arguments to path.resolve must be strings")}else if(!s){continue}r=s+"/"+r;n=s.charAt(0)==="/"}r=t(o(r.split("/"),function(e){return!!e}),!n).join("/");return(n?"/":"")+r||"."};r.normalize=function(e){var n=r.isAbsolute(e),i=s(e,-1)==="/";e=t(o(e.split("/"),function(e){return!!e}),!n).join("/");if(!e&&!n){e="."}if(e&&i){e+="/"}return(n?"/":"")+e};r.isAbsolute=function(e){return e.charAt(0)==="/"};r.join=function(){var e=Array.prototype.slice.call(arguments,0);return r.normalize(o(e,function(e,t){if(typeof e!=="string"){throw new TypeError("Arguments to path.join must be strings")}return e}).join("/"))};r.relative=function(e,t){e=r.resolve(e).substr(1);t=r.resolve(t).substr(1);function n(e){var t=0;for(;t<e.length;t++){if(e[t]!=="")break}var r=e.length-1;for(;r>=0;r--){if(e[r]!=="")break}if(t>r)return[];return e.slice(t,r-t+1)}var i=n(e.split("/"));var o=n(t.split("/"));var s=Math.min(i.length,o.length);var a=s;for(var f=0;f<s;f++){if(i[f]!==o[f]){a=f;break}}var u=[];for(var f=a;f<i.length;f++){u.push("..")}u=u.concat(o.slice(a));return u.join("/")};r.sep="/";r.delimiter=":";r.dirname=function(e){var t=i(e),r=t[0],n=t[1];if(!r&&!n){return"."}if(n){n=n.substr(0,n.length-1)}return r+n};r.basename=function(e,t){var r=i(e)[2];if(t&&r.substr(-1*t.length)===t){r=r.substr(0,r.length-t.length)}return r};r.extname=function(e){return i(e)[3]};function o(e,t){if(e.filter)return e.filter(t);var r=[];for(var n=0;n<e.length;n++){if(t(e[n],n,e))r.push(e[n])}return r}var s="ab".substr(-1)==="b"?function(e,t,r){return e.substr(t,r)}:function(e,t,r){if(t<0)t=e.length+t;return e.substr(t,r)}}).call(this,e("_process"))},{_process:34}],34:[function(e,t,r){var n=t.exports={};var i=[];var o=false;var s;var a=-1;function f(){o=false;if(s.length){i=s.concat(i)}else{a=-1}if(i.length){u()}}function u(){if(o){return}var e=setTimeout(f);o=true;var t=i.length;while(t){s=i;i=[];while(++a<t){if(s){s[a].run()}}a=-1;t=i.length}s=null;o=false;clearTimeout(e)}n.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1){for(var r=1;r<arguments.length;r++){t[r-1]=arguments[r]}}i.push(new c(e,t));if(i.length===1&&!o){setTimeout(u,0)}};function c(e,t){this.fun=e;this.array=t}c.prototype.run=function(){this.fun.apply(null,this.array)};n.title="browser";n.browser=true;n.env={};n.argv=[];n.version="";n.versions={};function l(){}n.on=l;n.addListener=l;n.once=l;n.off=l;n.removeListener=l;n.removeAllListeners=l;n.emit=l;n.binding=function(e){throw new Error("process.binding is not supported")};n.cwd=function(){return"/"};n.chdir=function(e){throw new Error("process.chdir is not supported")};n.umask=function(){return 0}},{}],35:[function(t,r,n){(function(t){(function(i){var o=typeof n=="object"&&n&&!n.nodeType&&n;var s=typeof r=="object"&&r&&!r.nodeType&&r;var a=typeof t=="object"&&t;if(a.global===a||a.window===a||a.self===a){i=a}var f,u=2147483647,c=36,l=1,d=26,h=38,p=700,m=72,v=128,g="-",y=/^xn--/,_=/[^\x20-\x7E]/,b=/[\x2E\u3002\uFF0E\uFF61]/g,w={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},E=c-l,k=Math.floor,x=String.fromCharCode,S;function I(e){throw new RangeError(w[e])}function B(e,t){var r=e.length;var n=[];while(r--){n[r]=t(e[r])}return n}function A(e,t){var r=e.split("@");var n="";if(r.length>1){n=r[0]+"@";e=r[1]}e=e.replace(b,".");var i=e.split(".");var o=B(i,t).join(".");return n+o}function C(e){var t=[],r=0,n=e.length,i,o;while(r<n){i=e.charCodeAt(r++);if(i>=55296&&i<=56319&&r<n){o=e.charCodeAt(r++);if((o&64512)==56320){t.push(((i&1023)<<10)+(o&1023)+65536)}else{t.push(i);r--}}else{t.push(i)}}return t}function T(e){return B(e,function(e){var t="";if(e>65535){e-=65536;t+=x(e>>>10&1023|55296);e=56320|e&1023}t+=x(e);return t}).join("")}function L(e){if(e-48<10){return e-22}if(e-65<26){return e-65}if(e-97<26){return e-97}return c}function R(e,t){return e+22+75*(e<26)-((t!=0)<<5)}function U(e,t,r){var n=0;e=r?k(e/p):e>>1;e+=k(e/t);for(;e>E*d>>1;n+=c){e=k(e/E)}return k(n+(E+1)*e/(e+h))}function P(e){var t=[],r=e.length,n,i=0,o=v,s=m,a,f,h,p,y,_,b,w,E;a=e.lastIndexOf(g);if(a<0){a=0}for(f=0;f<a;++f){if(e.charCodeAt(f)>=128){I("not-basic")}t.push(e.charCodeAt(f))}for(h=a>0?a+1:0;h<r;){for(p=i,y=1,_=c;;_+=c){if(h>=r){I("invalid-input")}b=L(e.charCodeAt(h++));if(b>=c||b>k((u-i)/y)){I("overflow")}i+=b*y;w=_<=s?l:_>=s+d?d:_-s;if(b<w){break}E=c-w;if(y>k(u/E)){I("overflow")}y*=E}n=t.length+1;s=U(i-p,n,p==0);if(k(i/n)>u-o){I("overflow")}o+=k(i/n);i%=n;t.splice(i++,0,o)}return T(t)}function O(e){var t,r,n,i,o,s,a,f,h,p,y,_=[],b,w,E,S;e=C(e);b=e.length;t=v;r=0;o=m;for(s=0;s<b;++s){y=e[s];if(y<128){_.push(x(y))}}n=i=_.length;if(i){_.push(g)}while(n<b){for(a=u,s=0;s<b;++s){y=e[s];if(y>=t&&y<a){a=y}}w=n+1;if(a-t>k((u-r)/w)){I("overflow")}r+=(a-t)*w;t=a;for(s=0;s<b;++s){y=e[s];if(y<t&&++r>u){I("overflow")}if(y==t){for(f=r,h=c;;h+=c){p=h<=o?l:h>=o+d?d:h-o;if(f<p){break}S=f-p;E=c-p;_.push(x(R(p+S%E,0)));f=k(S/E)}_.push(x(R(f,0)));o=U(r,w,n==i);r=0;++n}}++r;++t}return _.join("")}function M(e){return A(e,function(e){return y.test(e)?P(e.slice(4).toLowerCase()):e})}function j(e){return A(e,function(e){return _.test(e)?"xn--"+O(e):e})}f={version:"1.3.2",ucs2:{decode:C,encode:T},decode:P,encode:O,toASCII:j,toUnicode:M};if(typeof e=="function"&&typeof e.amd=="object"&&e.amd){e("punycode",function(){return f})}else if(o&&s){if(r.exports==o){s.exports=f}else{for(S in f){f.hasOwnProperty(S)&&(o[S]=f[S])}}}else{i.punycode=f}})(this)}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],36:[function(e,t,r){"use strict";function n(e,t){return Object.prototype.hasOwnProperty.call(e,t)}t.exports=function(e,t,r,o){t=t||"&";r=r||"=";var s={};if(typeof e!=="string"||e.length===0){return s}var a=/\+/g;e=e.split(t);var f=1e3;if(o&&typeof o.maxKeys==="number"){f=o.maxKeys}var u=e.length;if(f>0&&u>f){u=f}for(var c=0;c<u;++c){var l=e[c].replace(a,"%20"),d=l.indexOf(r),h,p,m,v;if(d>=0){h=l.substr(0,d);p=l.substr(d+1)}else{h=l;p=""}m=decodeURIComponent(h);v=decodeURIComponent(p);if(!n(s,m)){s[m]=v}else if(i(s[m])){s[m].push(v)}else{s[m]=[s[m],v]}}return s};var i=Array.isArray||function(e){return Object.prototype.toString.call(e)==="[object Array]"}},{}],37:[function(e,t,r){"use strict";var n=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};t.exports=function(e,t,r,a){t=t||"&";r=r||"=";if(e===null){e=undefined}if(typeof e==="object"){return o(s(e),function(s){var a=encodeURIComponent(n(s))+r;if(i(e[s])){return o(e[s],function(e){return a+encodeURIComponent(n(e))}).join(t)}else{return a+encodeURIComponent(n(e[s]))}}).join(t)}if(!a)return"";return encodeURIComponent(n(a))+r+encodeURIComponent(n(e)); -};var i=Array.isArray||function(e){return Object.prototype.toString.call(e)==="[object Array]"};function o(e,t){if(e.map)return e.map(t);var r=[];for(var n=0;n<e.length;n++){r.push(t(e[n],n))}return r}var s=Object.keys||function(e){var t=[];for(var r in e){if(Object.prototype.hasOwnProperty.call(e,r))t.push(r)}return t}},{}],38:[function(e,t,r){"use strict";r.decode=r.parse=e("./decode");r.encode=r.stringify=e("./encode")},{"./decode":36,"./encode":37}],39:[function(e,t,r){t.exports=o;var n=e("events").EventEmitter;var i=e("inherits");i(o,n);o.Readable=e("readable-stream/readable.js");o.Writable=e("readable-stream/writable.js");o.Duplex=e("readable-stream/duplex.js");o.Transform=e("readable-stream/transform.js");o.PassThrough=e("readable-stream/passthrough.js");o.Stream=o;function o(){n.call(this)}o.prototype.pipe=function(e,t){var r=this;function i(t){if(e.writable){if(false===e.write(t)&&r.pause){r.pause()}}}r.on("data",i);function o(){if(r.readable&&r.resume){r.resume()}}e.on("drain",o);if(!e._isStdio&&(!t||t.end!==false)){r.on("end",a);r.on("close",f)}var s=false;function a(){if(s)return;s=true;e.end()}function f(){if(s)return;s=true;if(typeof e.destroy==="function")e.destroy()}function u(e){c();if(n.listenerCount(this,"error")===0){throw e}}r.on("error",u);e.on("error",u);function c(){r.removeListener("data",i);e.removeListener("drain",o);r.removeListener("end",a);r.removeListener("close",f);r.removeListener("error",u);e.removeListener("error",u);r.removeListener("end",c);r.removeListener("close",c);e.removeListener("close",c)}r.on("end",c);r.on("close",c);e.on("close",c);e.emit("pipe",r);return e}},{events:30,inherits:79,"readable-stream/duplex.js":97,"readable-stream/passthrough.js":108,"readable-stream/readable.js":109,"readable-stream/transform.js":110,"readable-stream/writable.js":111}],40:[function(e,t,r){(function(t){var n=e("./lib/request");var i=e("xtend");var o=e("builtin-status-codes");var s=e("url");var a=r;a.request=function(e,r){if(typeof e==="string")e=s.parse(e);else e=i(e);var o=t.location.protocol.search(/^https?:$/)===-1?"http:":"";var a=e.protocol||o;var f=e.hostname||e.host;var u=e.port;var c=e.path||"/";if(f&&f.indexOf(":")!==-1)f="["+f+"]";e.url=(f?a+"//"+f:"")+(u?":"+u:"")+c;e.method=(e.method||"GET").toUpperCase();e.headers=e.headers||{};var l=new n(e);if(r)l.on("response",r);return l};a.get=function f(e,t){var r=a.request(e,t);r.end();return r};a.Agent=function(){};a.Agent.defaultMaxSockets=4;a.STATUS_CODES=o;a.METHODS=["CHECKOUT","CONNECT","COPY","DELETE","GET","HEAD","LOCK","M-SEARCH","MERGE","MKACTIVITY","MKCOL","MOVE","NOTIFY","OPTIONS","PATCH","POST","PROPFIND","PROPPATCH","PURGE","PUT","REPORT","SEARCH","SUBSCRIBE","TRACE","UNLOCK","UNSUBSCRIBE"]}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./lib/request":42,"builtin-status-codes":44,url:46,xtend:156}],41:[function(e,t,r){(function(e){r.fetch=a(e.fetch)&&a(e.ReadableByteStream);r.blobConstructor=false;try{new Blob([new ArrayBuffer(1)]);r.blobConstructor=true}catch(t){}var n=new e.XMLHttpRequest;n.open("GET",e.location.host?"/":"https://example.com");function i(e){try{n.responseType=e;return n.responseType===e}catch(t){}return false}var o=typeof e.ArrayBuffer!=="undefined";var s=o&&a(e.ArrayBuffer.prototype.slice);r.arraybuffer=o&&i("arraybuffer");r.msstream=!r.fetch&&s&&i("ms-stream");r.mozchunkedarraybuffer=!r.fetch&&o&&i("moz-chunked-arraybuffer");r.overrideMimeType=a(n.overrideMimeType);r.vbArray=a(e.VBArray);function a(e){return typeof e==="function"}n=null}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],42:[function(e,t,r){(function(r,n,i){var o=e("./capability");var s=e("inherits");var a=e("./response");var f=e("stream");var u=e("to-arraybuffer");var c=a.IncomingMessage;var l=a.readyStates;function d(e){if(o.fetch){return"fetch"}else if(o.mozchunkedarraybuffer){return"moz-chunked-arraybuffer"}else if(o.msstream){return"ms-stream"}else if(o.arraybuffer&&e){return"arraybuffer"}else if(o.vbArray&&e){return"text:vbarray"}else{return"text"}}var h=t.exports=function(e){var t=this;f.Writable.call(t);t._opts=e;t._body=[];t._headers={};if(e.auth)t.setHeader("Authorization","Basic "+new i(e.auth).toString("base64"));Object.keys(e.headers).forEach(function(r){t.setHeader(r,e.headers[r])});var r;if(e.mode==="prefer-streaming"){r=false}else if(e.mode==="allow-wrong-content-type"){r=!o.overrideMimeType}else if(!e.mode||e.mode==="default"||e.mode==="prefer-fast"){r=true}else{throw new Error("Invalid value for opts.mode")}t._mode=d(r);t.on("finish",function(){t._onFinish()})};s(h,f.Writable);h.prototype.setHeader=function(e,t){var r=this;var n=e.toLowerCase();if(m.indexOf(n)!==-1)return;r._headers[n]={name:e,value:t}};h.prototype.getHeader=function(e){var t=this;return t._headers[e.toLowerCase()].value};h.prototype.removeHeader=function(e){var t=this;delete t._headers[e.toLowerCase()]};h.prototype._onFinish=function(){var e=this;if(e._destroyed)return;var t=e._opts;var s=e._headers;var a;if(t.method==="POST"||t.method==="PUT"||t.method==="PATCH"){if(o.blobConstructor){a=new n.Blob(e._body.map(function(e){return u(e)}),{type:(s["content-type"]||{}).value||""})}else{a=i.concat(e._body).toString()}}if(e._mode==="fetch"){var f=Object.keys(s).map(function(e){return[s[e].name,s[e].value]});n.fetch(e._opts.url,{method:e._opts.method,headers:f,body:a,mode:"cors",credentials:t.withCredentials?"include":"same-origin"}).then(function(t){e._fetchResponse=t;e._connect()},function(t){e.emit("error",t)})}else{var c=e._xhr=new n.XMLHttpRequest;try{c.open(e._opts.method,e._opts.url,true)}catch(d){r.nextTick(function(){e.emit("error",d)});return}if("responseType"in c)c.responseType=e._mode.split(":")[0];if("withCredentials"in c)c.withCredentials=!!t.withCredentials;if(e._mode==="text"&&"overrideMimeType"in c)c.overrideMimeType("text/plain; charset=x-user-defined");Object.keys(s).forEach(function(e){c.setRequestHeader(s[e].name,s[e].value)});e._response=null;c.onreadystatechange=function(){switch(c.readyState){case l.LOADING:case l.DONE:e._onXHRProgress();break}};if(e._mode==="moz-chunked-arraybuffer"){c.onprogress=function(){e._onXHRProgress()}}c.onerror=function(){if(e._destroyed)return;e.emit("error",new Error("XHR error"))};try{c.send(a)}catch(d){r.nextTick(function(){e.emit("error",d)});return}}};function p(e){try{var t=e.status;return t!==null&&t!==0}catch(r){return false}}h.prototype._onXHRProgress=function(){var e=this;if(!p(e._xhr)||e._destroyed)return;if(!e._response)e._connect();e._response._onXHRProgress()};h.prototype._connect=function(){var e=this;if(e._destroyed)return;e._response=new c(e._xhr,e._fetchResponse,e._mode);e.emit("response",e._response)};h.prototype._write=function(e,t,r){var n=this;n._body.push(e);r()};h.prototype.abort=h.prototype.destroy=function(){var e=this;e._destroyed=true;if(e._response)e._response._destroyed=true;if(e._xhr)e._xhr.abort()};h.prototype.end=function(e,t,r){var n=this;if(typeof e==="function"){r=e;e=undefined}f.Writable.prototype.end.call(n,e,t,r)};h.prototype.flushHeaders=function(){};h.prototype.setTimeout=function(){};h.prototype.setNoDelay=function(){};h.prototype.setSocketKeepAlive=function(){};var m=["accept-charset","accept-encoding","access-control-request-headers","access-control-request-method","connection","content-length","cookie","cookie2","date","dnt","expect","host","keep-alive","origin","referer","te","trailer","transfer-encoding","upgrade","user-agent","via"]}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{},e("buffer").Buffer)},{"./capability":41,"./response":43,_process:34,buffer:26,inherits:79,stream:39,"to-arraybuffer":45}],43:[function(e,t,r){(function(t,n,i){var o=e("./capability");var s=e("inherits");var a=e("stream");var f=r.readyStates={UNSENT:0,OPENED:1,HEADERS_RECEIVED:2,LOADING:3,DONE:4};var u=r.IncomingMessage=function(e,r,n){var s=this;a.Readable.call(s);s._mode=n;s.headers={};s.rawHeaders=[];s.trailers={};s.rawTrailers=[];s.on("end",function(){t.nextTick(function(){s.emit("close")})});if(n==="fetch"){s._fetchResponse=r;s.statusCode=r.status;s.statusMessage=r.statusText;for(var f,u,c=r.headers[Symbol.iterator]();f=(u=c.next()).value,!u.done;){s.headers[f[0].toLowerCase()]=f[1];s.rawHeaders.push(f[0],f[1])}var l=r.body.getReader();function d(){l.read().then(function(e){if(s._destroyed)return;if(e.done){s.push(null);return}s.push(new i(e.value));d()})}d()}else{s._xhr=e;s._pos=0;s.statusCode=e.status;s.statusMessage=e.statusText;var h=e.getAllResponseHeaders().split(/\r?\n/);h.forEach(function(e){var t=e.match(/^([^:]+):\s*(.*)/);if(t){var r=t[1].toLowerCase();if(s.headers[r]!==undefined)s.headers[r]+=", "+t[2];else s.headers[r]=t[2];s.rawHeaders.push(t[1],t[2])}});s._charset="x-user-defined";if(!o.overrideMimeType){var p=s.rawHeaders["mime-type"];if(p){var m=p.match(/;\s*charset=([^;])(;|$)/);if(m){s._charset=m[1].toLowerCase()}}if(!s._charset)s._charset="utf-8"}}};s(u,a.Readable);u.prototype._read=function(){};u.prototype._onXHRProgress=function(){var e=this;var t=e._xhr;var r=null;switch(e._mode){case"text:vbarray":if(t.readyState!==f.DONE)break;try{r=new n.VBArray(t.responseBody).toArray()}catch(o){}if(r!==null){e.push(new i(r));break}case"text":try{r=t.responseText}catch(o){e._mode="text:vbarray";break}if(r.length>e._pos){var s=r.substr(e._pos);if(e._charset==="x-user-defined"){var a=new i(s.length);for(var u=0;u<s.length;u++)a[u]=s.charCodeAt(u)&255;e.push(a)}else{e.push(s,e._charset)}e._pos=r.length}break;case"arraybuffer":if(t.readyState!==f.DONE)break;r=t.response;e.push(new i(new Uint8Array(r)));break;case"moz-chunked-arraybuffer":r=t.response;if(t.readyState!==f.LOADING||!r)break;e.push(new i(new Uint8Array(r)));break;case"ms-stream":r=t.response;if(t.readyState!==f.LOADING)break;var c=new n.MSStreamReader;c.onprogress=function(){if(c.result.byteLength>e._pos){e.push(new i(new Uint8Array(c.result.slice(e._pos))));e._pos=c.result.byteLength}};c.onload=function(){e.push(null)};c.readAsArrayBuffer(r);break}if(e._xhr.readyState===f.DONE&&e._mode!=="ms-stream"){e.push(null)}}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{},e("buffer").Buffer)},{"./capability":41,_process:34,buffer:26,inherits:79,stream:39}],44:[function(e,t,r){t.exports={100:"Continue",101:"Switching Protocols",102:"Processing",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",308:"Permanent Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Time-out",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Request Entity Too Large",414:"Request-URI Too Large",415:"Unsupported Media Type",416:"Requested Range Not Satisfiable",417:"Expectation Failed",418:"I'm a teapot",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",425:"Unordered Collection",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Time-out",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",509:"Bandwidth Limit Exceeded",510:"Not Extended",511:"Network Authentication Required"}},{}],45:[function(e,t,r){var n=e("buffer").Buffer;t.exports=function(e){if(e instanceof Uint8Array){if(e.byteOffset===0&&e.byteLength===e.buffer.byteLength){return e.buffer}else if(typeof e.buffer.slice==="function"){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}}if(n.isBuffer(e)){var t=new Uint8Array(e.length);var r=e.length;for(var i=0;i<r;i++){t[i]=e[i]}return t.buffer}else{throw new Error("Argument must be a Buffer")}}},{buffer:26}],46:[function(e,t,r){"use strict";var n=e("punycode");var i=e("./util");r.parse=w;r.resolve=k;r.resolveObject=x;r.format=E;r.Url=o;function o(){this.protocol=null;this.slashes=null;this.auth=null;this.host=null;this.port=null;this.hostname=null;this.hash=null;this.search=null;this.query=null;this.pathname=null;this.path=null;this.href=null}var s=/^([a-z0-9.+-]+:)/i,a=/:[0-9]*$/,f=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,u=["<",">",'"',"`"," ","\r","\n"," "],c=["{","}","|","\\","^","`"].concat(u),l=["'"].concat(c),d=["%","/","?",";","#"].concat(l),h=["/","?","#"],p=255,m=/^[+a-z0-9A-Z_-]{0,63}$/,v=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,g={javascript:true,"javascript:":true},y={javascript:true,"javascript:":true},_={http:true,https:true,ftp:true,gopher:true,file:true,"http:":true,"https:":true,"ftp:":true,"gopher:":true,"file:":true},b=e("querystring");function w(e,t,r){if(e&&i.isObject(e)&&e instanceof o)return e;var n=new o;n.parse(e,t,r);return n}o.prototype.parse=function(e,t,r){if(!i.isString(e)){throw new TypeError("Parameter 'url' must be a string, not "+typeof e)}var o=e.indexOf("?"),a=o!==-1&&o<e.indexOf("#")?"?":"#",u=e.split(a),c=/\\/g;u[0]=u[0].replace(c,"/");e=u.join(a);var w=e;w=w.trim();if(!r&&e.split("#").length===1){var E=f.exec(w);if(E){this.path=w;this.href=w;this.pathname=E[1];if(E[2]){this.search=E[2];if(t){this.query=b.parse(this.search.substr(1))}else{this.query=this.search.substr(1)}}else if(t){this.search="";this.query={}}return this}}var k=s.exec(w);if(k){k=k[0];var x=k.toLowerCase();this.protocol=x;w=w.substr(k.length)}if(r||k||w.match(/^\/\/[^@\/]+@[^@\/]+/)){var S=w.substr(0,2)==="//";if(S&&!(k&&y[k])){w=w.substr(2);this.slashes=true}}if(!y[k]&&(S||k&&!_[k])){var I=-1;for(var B=0;B<h.length;B++){var A=w.indexOf(h[B]);if(A!==-1&&(I===-1||A<I))I=A}var C,T;if(I===-1){T=w.lastIndexOf("@")}else{T=w.lastIndexOf("@",I)}if(T!==-1){C=w.slice(0,T);w=w.slice(T+1);this.auth=decodeURIComponent(C)}I=-1;for(var B=0;B<d.length;B++){var A=w.indexOf(d[B]);if(A!==-1&&(I===-1||A<I))I=A}if(I===-1)I=w.length;this.host=w.slice(0,I);w=w.slice(I);this.parseHost();this.hostname=this.hostname||"";var L=this.hostname[0]==="["&&this.hostname[this.hostname.length-1]==="]";if(!L){var R=this.hostname.split(/\./);for(var B=0,U=R.length;B<U;B++){var P=R[B];if(!P)continue;if(!P.match(m)){var O="";for(var M=0,j=P.length;M<j;M++){if(P.charCodeAt(M)>127){O+="x"}else{O+=P[M]}}if(!O.match(m)){var D=R.slice(0,B);var H=R.slice(B+1);var N=P.match(v);if(N){D.push(N[1]);H.unshift(N[2])}if(H.length){w="/"+H.join(".")+w}this.hostname=D.join(".");break}}}}if(this.hostname.length>p){this.hostname=""}else{this.hostname=this.hostname.toLowerCase()}if(!L){this.hostname=n.toASCII(this.hostname)}var q=this.port?":"+this.port:"";var z=this.hostname||"";this.host=z+q;this.href+=this.host;if(L){this.hostname=this.hostname.substr(1,this.hostname.length-2);if(w[0]!=="/"){w="/"+w}}}if(!g[x]){for(var B=0,U=l.length;B<U;B++){var W=l[B];if(w.indexOf(W)===-1)continue;var F=encodeURIComponent(W);if(F===W){F=escape(W)}w=w.split(W).join(F)}}var Y=w.indexOf("#");if(Y!==-1){this.hash=w.substr(Y);w=w.slice(0,Y)}var V=w.indexOf("?");if(V!==-1){this.search=w.substr(V);this.query=w.substr(V+1);if(t){this.query=b.parse(this.query)}w=w.slice(0,V)}else if(t){this.search="";this.query={}}if(w)this.pathname=w;if(_[x]&&this.hostname&&!this.pathname){this.pathname="/"}if(this.pathname||this.search){var q=this.pathname||"";var $=this.search||"";this.path=q+$}this.href=this.format();return this};function E(e){if(i.isString(e))e=w(e);if(!(e instanceof o))return o.prototype.format.call(e);return e.format()}o.prototype.format=function(){var e=this.auth||"";if(e){e=encodeURIComponent(e);e=e.replace(/%3A/i,":");e+="@"}var t=this.protocol||"",r=this.pathname||"",n=this.hash||"",o=false,s="";if(this.host){o=e+this.host}else if(this.hostname){o=e+(this.hostname.indexOf(":")===-1?this.hostname:"["+this.hostname+"]");if(this.port){o+=":"+this.port}}if(this.query&&i.isObject(this.query)&&Object.keys(this.query).length){s=b.stringify(this.query)}var a=this.search||s&&"?"+s||"";if(t&&t.substr(-1)!==":")t+=":";if(this.slashes||(!t||_[t])&&o!==false){o="//"+(o||"");if(r&&r.charAt(0)!=="/")r="/"+r}else if(!o){o=""}if(n&&n.charAt(0)!=="#")n="#"+n;if(a&&a.charAt(0)!=="?")a="?"+a;r=r.replace(/[?#]/g,function(e){return encodeURIComponent(e)});a=a.replace("#","%23");return t+o+r+a+n};function k(e,t){return w(e,false,true).resolve(t)}o.prototype.resolve=function(e){return this.resolveObject(w(e,false,true)).format()};function x(e,t){if(!e)return t;return w(e,false,true).resolveObject(t)}o.prototype.resolveObject=function(e){if(i.isString(e)){var t=new o;t.parse(e,false,true);e=t}var r=new o;var n=Object.keys(this);for(var s=0;s<n.length;s++){var a=n[s];r[a]=this[a]}r.hash=e.hash;if(e.href===""){r.href=r.format();return r}if(e.slashes&&!e.protocol){var f=Object.keys(e);for(var u=0;u<f.length;u++){var c=f[u];if(c!=="protocol")r[c]=e[c]}if(_[r.protocol]&&r.hostname&&!r.pathname){r.path=r.pathname="/"}r.href=r.format();return r}if(e.protocol&&e.protocol!==r.protocol){if(!_[e.protocol]){var l=Object.keys(e);for(var d=0;d<l.length;d++){var h=l[d];r[h]=e[h]}r.href=r.format();return r}r.protocol=e.protocol;if(!e.host&&!y[e.protocol]){var p=(e.pathname||"").split("/");while(p.length&&!(e.host=p.shift()));if(!e.host)e.host="";if(!e.hostname)e.hostname="";if(p[0]!=="")p.unshift("");if(p.length<2)p.unshift("");r.pathname=p.join("/")}else{r.pathname=e.pathname}r.search=e.search;r.query=e.query;r.host=e.host||"";r.auth=e.auth;r.hostname=e.hostname||e.host;r.port=e.port;if(r.pathname||r.search){var m=r.pathname||"";var v=r.search||"";r.path=m+v}r.slashes=r.slashes||e.slashes;r.href=r.format();return r}var g=r.pathname&&r.pathname.charAt(0)==="/",b=e.host||e.pathname&&e.pathname.charAt(0)==="/",w=b||g||r.host&&e.pathname,E=w,k=r.pathname&&r.pathname.split("/")||[],p=e.pathname&&e.pathname.split("/")||[],x=r.protocol&&!_[r.protocol];if(x){r.hostname="";r.port=null;if(r.host){if(k[0]==="")k[0]=r.host;else k.unshift(r.host)}r.host="";if(e.protocol){e.hostname=null;e.port=null;if(e.host){if(p[0]==="")p[0]=e.host;else p.unshift(e.host)}e.host=null}w=w&&(p[0]===""||k[0]==="")}if(b){r.host=e.host||e.host===""?e.host:r.host;r.hostname=e.hostname||e.hostname===""?e.hostname:r.hostname;r.search=e.search;r.query=e.query;k=p}else if(p.length){if(!k)k=[];k.pop();k=k.concat(p);r.search=e.search;r.query=e.query}else if(!i.isNullOrUndefined(e.search)){if(x){r.hostname=r.host=k.shift();var S=r.host&&r.host.indexOf("@")>0?r.host.split("@"):false;if(S){r.auth=S.shift();r.host=r.hostname=S.shift()}}r.search=e.search;r.query=e.query;if(!i.isNull(r.pathname)||!i.isNull(r.search)){r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")}r.href=r.format();return r}if(!k.length){r.pathname=null;if(r.search){r.path="/"+r.search}else{r.path=null}r.href=r.format();return r}var I=k.slice(-1)[0];var B=(r.host||e.host||k.length>1)&&(I==="."||I==="..")||I==="";var A=0;for(var C=k.length;C>=0;C--){I=k[C];if(I==="."){k.splice(C,1)}else if(I===".."){k.splice(C,1);A++}else if(A){k.splice(C,1);A--}}if(!w&&!E){for(;A--;A){k.unshift("..")}}if(w&&k[0]!==""&&(!k[0]||k[0].charAt(0)!=="/")){k.unshift("")}if(B&&k.join("/").substr(-1)!=="/"){k.push("")}var T=k[0]===""||k[0]&&k[0].charAt(0)==="/";if(x){r.hostname=r.host=T?"":k.length?k.shift():"";var S=r.host&&r.host.indexOf("@")>0?r.host.split("@"):false;if(S){r.auth=S.shift();r.host=r.hostname=S.shift()}}w=w||r.host&&k.length;if(w&&!T){k.unshift("")}if(!k.length){r.pathname=null;r.path=null}else{r.pathname=k.join("/")}if(!i.isNull(r.pathname)||!i.isNull(r.search)){r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")}r.auth=e.auth||r.auth;r.slashes=r.slashes||e.slashes;r.href=r.format();return r};o.prototype.parseHost=function(){var e=this.host;var t=a.exec(e);if(t){t=t[0];if(t!==":"){this.port=t.substr(1)}e=e.substr(0,e.length-t.length)}if(e)this.hostname=e}},{"./util":47,punycode:35,querystring:38}],47:[function(e,t,r){"use strict";t.exports={isString:function(e){return typeof e==="string"},isObject:function(e){return typeof e==="object"&&e!==null},isNull:function(e){return e===null},isNullOrUndefined:function(e){return e==null}}},{}],48:[function(e,t,r){t.exports=function n(e){return e&&typeof e==="object"&&typeof e.copy==="function"&&typeof e.fill==="function"&&typeof e.readUInt8==="function"}},{}],49:[function(e,t,r){(function(t,n){var i=/%[sdj%]/g;r.format=function(e){if(!E(e)){var t=[];for(var r=0;r<arguments.length;r++){t.push(a(arguments[r]))}return t.join(" ")}var r=1;var n=arguments;var o=n.length;var s=String(e).replace(i,function(e){if(e==="%%")return"%";if(r>=o)return e;switch(e){case"%s":return String(n[r++]);case"%d":return Number(n[r++]);case"%j":try{return JSON.stringify(n[r++])}catch(t){return"[Circular]"}default:return e}});for(var f=n[r];r<o;f=n[++r]){if(_(f)||!I(f)){s+=" "+f}else{s+=" "+a(f)}}return s};r.deprecate=function(e,i){if(x(n.process)){return function(){return r.deprecate(e,i).apply(this,arguments)}}if(t.noDeprecation===true){return e}var o=false;function s(){if(!o){if(t.throwDeprecation){throw new Error(i)}else if(t.traceDeprecation){console.trace(i)}else{console.error(i)}o=true}return e.apply(this,arguments)}return s};var o={};var s;r.debuglog=function(e){if(x(s))s=t.env.NODE_DEBUG||"";e=e.toUpperCase();if(!o[e]){if(new RegExp("\\b"+e+"\\b","i").test(s)){var n=t.pid;o[e]=function(){var t=r.format.apply(r,arguments);console.error("%s %d: %s",e,n,t)}}else{o[e]=function(){}}}return o[e]};function a(e,t){var n={seen:[],stylize:u};if(arguments.length>=3)n.depth=arguments[2];if(arguments.length>=4)n.colors=arguments[3];if(y(t)){n.showHidden=t}else if(t){r._extend(n,t)}if(x(n.showHidden))n.showHidden=false;if(x(n.depth))n.depth=2;if(x(n.colors))n.colors=false;if(x(n.customInspect))n.customInspect=true;if(n.colors)n.stylize=f;return l(n,e,n.depth)}r.inspect=a;a.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]};a.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"};function f(e,t){var r=a.styles[t];if(r){return"["+a.colors[r][0]+"m"+e+"["+a.colors[r][1]+"m"}else{return e}}function u(e,t){return e}function c(e){var t={};e.forEach(function(e,r){t[e]=true});return t}function l(e,t,n){if(e.customInspect&&t&&C(t.inspect)&&t.inspect!==r.inspect&&!(t.constructor&&t.constructor.prototype===t)){var i=t.inspect(n,e);if(!E(i)){i=l(e,i,n)}return i}var o=d(e,t);if(o){return o}var s=Object.keys(t);var a=c(s);if(e.showHidden){s=Object.getOwnPropertyNames(t)}if(A(t)&&(s.indexOf("message")>=0||s.indexOf("description")>=0)){return h(t)}if(s.length===0){if(C(t)){var f=t.name?": "+t.name:"";return e.stylize("[Function"+f+"]","special")}if(S(t)){return e.stylize(RegExp.prototype.toString.call(t),"regexp")}if(B(t)){return e.stylize(Date.prototype.toString.call(t),"date")}if(A(t)){return h(t)}}var u="",y=false,_=["{","}"];if(g(t)){y=true;_=["[","]"]}if(C(t)){var b=t.name?": "+t.name:"";u=" [Function"+b+"]"}if(S(t)){u=" "+RegExp.prototype.toString.call(t)}if(B(t)){u=" "+Date.prototype.toUTCString.call(t)}if(A(t)){u=" "+h(t)}if(s.length===0&&(!y||t.length==0)){return _[0]+u+_[1]}if(n<0){if(S(t)){return e.stylize(RegExp.prototype.toString.call(t),"regexp")}else{return e.stylize("[Object]","special")}}e.seen.push(t);var w;if(y){w=p(e,t,n,a,s)}else{w=s.map(function(r){return m(e,t,n,a,r,y)})}e.seen.pop();return v(w,u,_)}function d(e,t){if(x(t))return e.stylize("undefined","undefined");if(E(t)){var r="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(r,"string")}if(w(t))return e.stylize(""+t,"number");if(y(t))return e.stylize(""+t,"boolean");if(_(t))return e.stylize("null","null")}function h(e){return"["+Error.prototype.toString.call(e)+"]"}function p(e,t,r,n,i){var o=[];for(var s=0,a=t.length;s<a;++s){if(O(t,String(s))){o.push(m(e,t,r,n,String(s),true))}else{o.push("")}}i.forEach(function(i){if(!i.match(/^\d+$/)){o.push(m(e,t,r,n,i,true))}});return o}function m(e,t,r,n,i,o){var s,a,f;f=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]};if(f.get){if(f.set){a=e.stylize("[Getter/Setter]","special")}else{a=e.stylize("[Getter]","special")}}else{if(f.set){a=e.stylize("[Setter]","special")}}if(!O(n,i)){s="["+i+"]"}if(!a){if(e.seen.indexOf(f.value)<0){if(_(r)){a=l(e,f.value,null)}else{a=l(e,f.value,r-1)}if(a.indexOf("\n")>-1){if(o){a=a.split("\n").map(function(e){return" "+e}).join("\n").substr(2)}else{a="\n"+a.split("\n").map(function(e){return" "+e}).join("\n")}}}else{a=e.stylize("[Circular]","special")}}if(x(s)){if(o&&i.match(/^\d+$/)){return a}s=JSON.stringify(""+i);if(s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)){s=s.substr(1,s.length-2);s=e.stylize(s,"name")}else{s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'");s=e.stylize(s,"string")}}return s+": "+a}function v(e,t,r){var n=0;var i=e.reduce(function(e,t){n++;if(t.indexOf("\n")>=0)n++;return e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0);if(i>60){return r[0]+(t===""?"":t+"\n ")+" "+e.join(",\n ")+" "+r[1]}return r[0]+t+" "+e.join(", ")+" "+r[1]}function g(e){return Array.isArray(e)}r.isArray=g;function y(e){return typeof e==="boolean"}r.isBoolean=y;function _(e){return e===null}r.isNull=_;function b(e){return e==null}r.isNullOrUndefined=b;function w(e){return typeof e==="number"}r.isNumber=w;function E(e){return typeof e==="string"}r.isString=E;function k(e){return typeof e==="symbol"}r.isSymbol=k;function x(e){return e===void 0}r.isUndefined=x;function S(e){return I(e)&&L(e)==="[object RegExp]"}r.isRegExp=S;function I(e){return typeof e==="object"&&e!==null}r.isObject=I;function B(e){return I(e)&&L(e)==="[object Date]"}r.isDate=B;function A(e){return I(e)&&(L(e)==="[object Error]"||e instanceof Error)}r.isError=A;function C(e){return typeof e==="function"}r.isFunction=C;function T(e){return e===null||typeof e==="boolean"||typeof e==="number"||typeof e==="string"||typeof e==="symbol"||typeof e==="undefined"}r.isPrimitive=T;r.isBuffer=e("./support/isBuffer");function L(e){return Object.prototype.toString.call(e)}function R(e){return e<10?"0"+e.toString(10):e.toString(10)}var U=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function P(){var e=new Date;var t=[R(e.getHours()),R(e.getMinutes()),R(e.getSeconds())].join(":");return[e.getDate(),U[e.getMonth()],t].join(" ")}r.log=function(){console.log("%s - %s",P(),r.format.apply(r,arguments))};r.inherits=e("inherits");r._extend=function(e,t){if(!t||!I(t))return e;var r=Object.keys(t);var n=r.length;while(n--){e[r[n]]=t[r[n]]}return e};function O(e,t){return Object.prototype.hasOwnProperty.call(e,t)}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./support/isBuffer":48,_process:34,inherits:79}],50:[function(e,t,r){(function(r){var n=e("inherits");var i=e("readable-stream").Transform;var o=e("defined");t.exports=s;n(s,i);function s(e,t){if(!(this instanceof s))return new s(e,t);i.call(this);if(!t)t={};if(typeof e==="object"){t=e;e=t.size}this.size=e||512;if(t.nopad)this._zeroPadding=false;else this._zeroPadding=o(t.zeroPadding,true);this._buffered=[];this._bufferedBytes=0}s.prototype._transform=function(e,t,n){this._bufferedBytes+=e.length;this._buffered.push(e);while(this._bufferedBytes>=this.size){var i=r.concat(this._buffered);this._bufferedBytes-=this.size;this.push(i.slice(0,this.size));this._buffered=[i.slice(this.size,i.length)]}n()};s.prototype._flush=function(){if(this._bufferedBytes&&this._zeroPadding){var e=new r(this.size-this._bufferedBytes);e.fill(0);this._buffered.push(e);this.push(r.concat(this._buffered));this._buffered=null}else if(this._bufferedBytes){this.push(r.concat(this._buffered));this._buffered=null}this.push(null)}}).call(this,e("buffer").Buffer)},{buffer:26,defined:51,inherits:79,"readable-stream":109}],51:[function(e,t,r){t.exports=function(){for(var e=0;e<arguments.length;e++){if(arguments[e]!==undefined)return arguments[e]}}},{}],52:[function(e,t,r){t.exports=s;var n=e("block-stream2");var i=e("inherits");var o=e("stream");i(s,o.Writable);function s(e,t,r){var i=this;if(!(i instanceof s)){return new s(e,t,r)}o.Writable.call(i,r);if(!r)r={};if(!e||!e.put||!e.get){throw new Error("First argument must be an abstract-chunk-store compliant store")}t=Number(t);if(!t)throw new Error("Second argument must be a chunk length");i._blockstream=new n(t,{zeroPadding:false});i._blockstream.on("data",f).on("error",function(e){i.destroy(e)});var a=0;function f(t){if(i.destroyed)return;e.put(a,t);a+=1}i.on("finish",function(){this._blockstream.end()})}s.prototype._write=function(e,t,r){this._blockstream.write(e,t,r)};s.prototype.destroy=function(e){if(this.destroyed)return;this.destroyed=true;if(e)this.emit("error",e);this.emit("close")}},{"block-stream2":50,inherits:79,stream:39}],53:[function(e,t,r){t.exports=function n(){var e=navigator.hardwareConcurrency||1;var n=[];for(var t=0;t<e;t++){n.push({model:"",speed:0,times:{user:0,nice:0,sys:0,idle:0,irq:0}})}return n}},{}],54:[function(e,t,r){(function(r,n,i){t.exports=b;t.exports.parseInput=w;t.exports.announceList=[["udp://tracker.openbittorrent.com:80"],["udp://tracker.internetwarriors.net:1337"],["udp://tracker.leechers-paradise.org:6969"],["udp://tracker.coppersurfer.tk:6969"],["udp://exodus.desync.com:6969"],["wss://tracker.webtorrent.io"],["wss://tracker.btorrent.xyz"],["wss://tracker.openwebtorrent.com"]];var o=e("bencode");var s=e("block-stream2");var a=e("piece-length");var f=e("path");var u=e("xtend");var c=e("filestream/read");var l=e("flatten");var d=e("fs");var h=e("is-file");var p=e("junk");var m=e("multistream");var v=e("once");var g=e("run-parallel");var y=e("simple-sha1");var _=e("stream");function b(e,t,r){if(typeof t==="function")return b(e,null,t);t=t?u(t):{};E(e,t,function(e,n,i){if(e)return r(e);t.singleFileTorrent=i;A(n,t,r)})}function w(e,t,r){if(typeof t==="function")return w(e,null,t);t=t?u(t):{};E(e,t,r)}function E(e,t,n){if(Array.isArray(e)&&e.length===0)throw new Error("invalid input type");if(L(e))e=Array.prototype.slice.call(e);if(!Array.isArray(e))e=[e];e=e.map(function(e){if(T(e)&&typeof e.path==="string")return e.path;return e});if(e.length===1&&typeof e[0]!=="string"&&!e[0].name)e[0].name=t.name;var o=null;e.forEach(function(t,r){if(typeof t==="string")return;var n=t.fullPath||t.name;if(!n)throw new Error("missing required `fullPath` or `name` property on input");t.path=n.split("/");if(!t.path[0])t.path.shift();if(t.path.length<2){o=null}else if(r===0&&e.length>1){o=t.path[0]}else if(t.path[0]!==o){o=null}});e=e.filter(function(e){if(typeof e==="string")return true;var t=e.path[e.path.length-1];return I(t)&&p.not(t)});if(o){e.forEach(function(e){if(typeof e==="string")return;e.path.shift()})}if(!t.name&&o)t.name=o;if(!t.name&&e[0]&&e[0].name)t.name=e[0].name;if(!t.name&&typeof e[0]==="string")t.name=f.basename(e[0]);if(t.name===undefined){throw new Error("missing option 'name' and unable to infer it from input[0].name")}var s=e.reduce(function(e,t){return e+Number(typeof t==="string")},0);var a=e.length===1;if(e.length===1&&typeof e[0]==="string"){if(typeof d.stat!=="function"){throw new Error("filesystem paths do not work in the browser")}h(e[0],function(e,t){if(e)return n(e);a=t;u()})}else{r.nextTick(function(){u()})}function u(){g(e.map(function(e){return function(r){var n={};if(T(e)){n.getStream=U(e);n.length=e.size}else if(i.isBuffer(e)){n.getStream=P(e);n.length=e.length}else if(R(e)){if(!t.pieceLength){throw new Error("must specify `pieceLength` option if input is Stream"); -}n.getStream=M(e,n);n.length=0}else if(typeof e==="string"){if(typeof d.stat!=="function"){throw new Error("filesystem paths do not work in the browser")}var o=s>1||a;k(e,o,r);return}else{throw new Error("invalid input type")}n.path=e.path;r(null,n)}}),function(e,t){if(e)return n(e);t=l(t);n(null,t,a)})}}function k(e,t,r){S(e,x,function(n,i){if(n)return r(n);if(Array.isArray(i))i=l(i);else i=[i];e=f.normalize(e);if(t){e=e.slice(0,e.lastIndexOf(f.sep)+1)}if(e[e.length-1]!==f.sep)e+=f.sep;i.forEach(function(t){t.getStream=O(t.path);t.path=t.path.replace(e,"").split(f.sep)});r(null,i)})}function x(e,t){t=v(t);d.stat(e,function(r,n){if(r)return t(r);var i={length:n.size,path:e};t(null,i)})}function S(e,t,r){d.readdir(e,function(n,i){if(n&&n.code==="ENOTDIR"){t(e,r)}else if(n){r(n)}else{g(i.filter(I).filter(p.not).map(function(r){return function(n){S(f.join(e,r),t,n)}}),r)}})}function I(e){return e[0]!=="."}function B(e,t,r){r=v(r);var n=[];var o=0;var a=e.map(function(e){return e.getStream});var f=0;var u=0;var c=false;var l=new m(a);var d=new s(t,{zeroPadding:false});l.on("error",g);l.pipe(d).on("data",h).on("end",p).on("error",g);function h(e){o+=e.length;var t=u;y(e,function(e){n[t]=e;f-=1;b()});f+=1;u+=1}function p(){c=true;b()}function g(e){_();r(e)}function _(){l.removeListener("error",g);d.removeListener("data",h);d.removeListener("end",p);d.removeListener("error",g)}function b(){if(c&&f===0){_();r(null,new i(n.join(""),"hex"),o)}}}function A(e,r,i){var s=r.announceList;if(!s){if(typeof r.announce==="string")s=[[r.announce]];else if(Array.isArray(r.announce)){s=r.announce.map(function(e){return[e]})}}if(!s)s=[];if(n.WEBTORRENT_ANNOUNCE){if(typeof n.WEBTORRENT_ANNOUNCE==="string"){s.push([[n.WEBTORRENT_ANNOUNCE]])}else if(Array.isArray(n.WEBTORRENT_ANNOUNCE)){s=s.concat(n.WEBTORRENT_ANNOUNCE.map(function(e){return[e]}))}}if(r.announce===undefined&&r.announceList===undefined){s=s.concat(t.exports.announceList)}if(typeof r.urlList==="string")r.urlList=[r.urlList];var f={info:{name:r.name},"creation date":Number(r.creationDate)||Date.now(),encoding:"UTF-8"};if(s.length!==0){f.announce=s[0][0];f["announce-list"]=s}if(r.comment!==undefined)f.comment=r.comment;if(r.createdBy!==undefined)f["created by"]=r.createdBy;if(r.private!==undefined)f.info.private=Number(r.private);if(r.sslCert!==undefined)f.info["ssl-cert"]=r.sslCert;if(r.urlList!==undefined)f["url-list"]=r.urlList;var u=r.pieceLength||a(e.reduce(C,0));f.info["piece length"]=u;B(e,u,function(t,n,s){if(t)return i(t);f.info.pieces=n;e.forEach(function(e){delete e.getStream});if(r.singleFileTorrent){f.info.length=s}else{f.info.files=e}i(null,o.encode(f))})}function C(e,t){return e+t.length}function T(e){return typeof Blob!=="undefined"&&e instanceof Blob}function L(e){return typeof FileList==="function"&&e instanceof FileList}function R(e){return typeof e==="object"&&e!=null&&typeof e.pipe==="function"}function U(e){return function(){return new c(e)}}function P(e){return function(){var t=new _.PassThrough;t.end(e);return t}}function O(e){return function(){return d.createReadStream(e)}}function M(e,t){return function(){var r=new _.Transform;r._transform=function(e,r,n){t.length+=e.length;this.push(e);n()};e.pipe(r);return r}}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{},e("buffer").Buffer)},{_process:34,bencode:55,"block-stream2":59,buffer:26,"filestream/read":63,flatten:64,fs:24,"is-file":65,junk:66,multistream:81,once:68,path:33,"piece-length":69,"run-parallel":130,"simple-sha1":139,stream:39,xtend:156}],55:[function(e,t,r){arguments[4][12][0].apply(r,arguments)},{"./lib/decode":56,"./lib/encode":58,dup:12}],56:[function(e,t,r){arguments[4][13][0].apply(r,arguments)},{"./dict":57,buffer:26,dup:13}],57:[function(e,t,r){arguments[4][14][0].apply(r,arguments)},{dup:14}],58:[function(e,t,r){arguments[4][15][0].apply(r,arguments)},{buffer:26,dup:15}],59:[function(e,t,r){arguments[4][50][0].apply(r,arguments)},{buffer:26,defined:60,dup:50,inherits:79,"readable-stream":109}],60:[function(e,t,r){arguments[4][51][0].apply(r,arguments)},{dup:51}],61:[function(e,t,r){(function(r){var n=e("is-typedarray").strict;t.exports=function i(e){if(n(e)){var t=new r(e.buffer);if(e.byteLength!==e.buffer.byteLength){t=t.slice(e.byteOffset,e.byteOffset+e.byteLength)}return t}else{return new r(e)}}}).call(this,e("buffer").Buffer)},{buffer:26,"is-typedarray":62}],62:[function(e,t,r){arguments[4][23][0].apply(r,arguments)},{dup:23}],63:[function(e,t,r){var n=e("stream").Readable;var i=e("inherits");var o=/^.*\.(\w+)$/;var s=e("typedarray-to-buffer");function a(e,t){var r=this;if(!(this instanceof a)){return new a(e,t)}t=t||{};n.call(this,t);this._offset=0;this._ready=false;this._file=e;this._size=e.size;this._chunkSize=t.chunkSize||Math.max(this._size/1e3,200*1024);this.reader=new FileReader;this._generateHeaderBlocks(e,t,function(e,t){if(e){return r.emit("error",e)}if(Array.isArray(t)){t.forEach(function(e){r.push(e)})}r._ready=true;r.emit("_ready")})}i(a,n);t.exports=a;a.prototype._generateHeaderBlocks=function(e,t,r){r(null,[])};a.prototype._read=function(){if(!this._ready){this.once("_ready",this._read.bind(this));return}var e=this;var t=this.reader;var r=this._offset;var n=this._offset+this._chunkSize;if(n>this._size)n=this._size;if(r===this._size){this.destroy();this.push(null);return}t.onload=function(){e._offset=n;e.push(s(t.result))};t.onerror=function(){e.emit("error",t.error)};t.readAsArrayBuffer(this._file.slice(r,n))};a.prototype.destroy=function(){this._file=null;if(this.reader){this.reader.onload=null;this.reader.onerror=null;try{this.reader.abort()}catch(e){}}this.reader=null}},{inherits:79,stream:39,"typedarray-to-buffer":61}],64:[function(e,t,r){t.exports=function n(e,t){t=typeof t=="number"?t:Infinity;return r(e,1);function r(e,n){return e.reduce(function(e,i){if(Array.isArray(i)&&n<t){return e.concat(r(i,n+1))}else{return e.concat(i)}},[])}}},{}],65:[function(e,t,r){"use strict";var n=e("fs");t.exports=function o(e,t){if(!t)return i(e);n.stat(e,function(e,r){if(e)return t(e);return t(null,r.isFile())})};t.exports.sync=i;function i(e){return n.existsSync(e)&&n.statSync(e).isFile()}},{fs:24}],66:[function(e,t,r){"use strict";r.re=/^npm-debug\.log$|^\..*\.swp$|^\.DS_Store$|^\.AppleDouble$|^\.LSOverride$|^Icon[\r\?]?|^\._.*|^\.Spotlight-V100$|\.Trashes|^__MACOSX$|~$|^Thumbs\.db$|^ehthumbs\.db$|^Desktop\.ini$/;r.is=function(e){return r.re.test(e)};r.not=r.isnt=function(e){return!r.is(e)}},{}],67:[function(e,t,r){arguments[4][20][0].apply(r,arguments)},{dup:20}],68:[function(e,t,r){arguments[4][21][0].apply(r,arguments)},{dup:21,wrappy:67}],69:[function(e,t,r){var n=e("closest-to");var i=[];for(var o=14;o<=22;o++){i.push(Math.pow(2,o))}t.exports=function(e){return n(e/Math.pow(2,10),i)}},{"closest-to":70}],70:[function(e,t,r){t.exports=function(e,t){var r=Infinity;var n=0;var i=null;t.sort(function(e,t){return e-t});for(var o=0,s=t.length;o<s;o++){n=Math.abs(e-t[o]);if(n>=r){break}r=n;i=t[o]}return i}},{}],71:[function(e,t,r){r=t.exports=e("./debug");r.log=o;r.formatArgs=i;r.save=s;r.load=a;r.useColors=n;r.storage="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:f();r.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"];function n(){return"WebkitAppearance"in document.documentElement.style||window.console&&(console.firebug||console.exception&&console.table)||navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31}r.formatters.j=function(e){return JSON.stringify(e)};function i(){var e=arguments;var t=this.useColors;e[0]=(t?"%c":"")+this.namespace+(t?" %c":" ")+e[0]+(t?"%c ":" ")+"+"+r.humanize(this.diff);if(!t)return e;var n="color: "+this.color;e=[e[0],n,"color: inherit"].concat(Array.prototype.slice.call(e,1));var i=0;var o=0;e[0].replace(/%[a-z%]/g,function(e){if("%%"===e)return;i++;if("%c"===e){o=i}});e.splice(o,0,n);return e}function o(){return"object"===typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function s(e){try{if(null==e){r.storage.removeItem("debug")}else{r.storage.debug=e}}catch(t){}}function a(){var e;try{e=r.storage.debug}catch(t){}return e}r.enable(a());function f(){try{return window.localStorage}catch(e){}}},{"./debug":72}],72:[function(e,t,r){r=t.exports=s;r.coerce=c;r.disable=f;r.enable=a;r.enabled=u;r.humanize=e("ms");r.names=[];r.skips=[];r.formatters={};var n=0;var i;function o(){return r.colors[n++%r.colors.length]}function s(e){function t(){}t.enabled=false;function n(){var e=n;var t=+new Date;var s=t-(i||t);e.diff=s;e.prev=i;e.curr=t;i=t;if(null==e.useColors)e.useColors=r.useColors();if(null==e.color&&e.useColors)e.color=o();var a=Array.prototype.slice.call(arguments);a[0]=r.coerce(a[0]);if("string"!==typeof a[0]){a=["%o"].concat(a)}var f=0;a[0]=a[0].replace(/%([a-z%])/g,function(t,n){if(t==="%%")return t;f++;var i=r.formatters[n];if("function"===typeof i){var o=a[f];t=i.call(e,o);a.splice(f,1);f--}return t});if("function"===typeof r.formatArgs){a=r.formatArgs.apply(e,a)}var u=n.log||r.log||console.log.bind(console);u.apply(e,a)}n.enabled=true;var s=r.enabled(e)?n:t;s.namespace=e;return s}function a(e){r.save(e);var t=(e||"").split(/[\s,]+/);var n=t.length;for(var i=0;i<n;i++){if(!t[i])continue;e=t[i].replace(/\*/g,".*?");if(e[0]==="-"){r.skips.push(new RegExp("^"+e.substr(1)+"$"))}else{r.names.push(new RegExp("^"+e+"$"))}}}function f(){r.enable("")}function u(e){var t,n;for(t=0,n=r.skips.length;t<n;t++){if(r.skips[t].test(e)){return false}}for(t=0,n=r.names.length;t<n;t++){if(r.names[t].test(e)){return true}}return false}function c(e){if(e instanceof Error)return e.stack||e.message;return e}},{ms:73}],73:[function(e,t,r){var n=1e3;var i=n*60;var o=i*60;var s=o*24;var a=s*365.25;t.exports=function(e,t){t=t||{};if("string"==typeof e)return f(e);return t.long?c(e):u(e)};function f(e){e=""+e;if(e.length>1e4)return;var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(!t)return;var r=parseFloat(t[1]);var f=(t[2]||"ms").toLowerCase();switch(f){case"years":case"year":case"yrs":case"yr":case"y":return r*a;case"days":case"day":case"d":return r*s;case"hours":case"hour":case"hrs":case"hr":case"h":return r*o;case"minutes":case"minute":case"mins":case"min":case"m":return r*i;case"seconds":case"second":case"secs":case"sec":case"s":return r*n;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r}}function u(e){if(e>=s)return Math.round(e/s)+"d";if(e>=o)return Math.round(e/o)+"h";if(e>=i)return Math.round(e/i)+"m";if(e>=n)return Math.round(e/n)+"s";return e+"ms"}function c(e){return l(e,s,"day")||l(e,o,"hour")||l(e,i,"minute")||l(e,n,"second")||e+" ms"}function l(e,t,r){if(e<t)return;if(e<t*1.5)return Math.floor(e/t)+" "+r;return Math.ceil(e/t)+" "+r+"s"}},{}],74:[function(e,t,r){var n=e("once");var i=function(){};var o=function(e){return e.setHeader&&typeof e.abort==="function"};var s=function(e){return e.stdio&&Array.isArray(e.stdio)&&e.stdio.length===3};var a=function(e,t,r){if(typeof t==="function")return a(e,null,t);if(!t)t={};r=n(r||i);var f=e._writableState;var u=e._readableState;var c=t.readable||t.readable!==false&&e.readable;var l=t.writable||t.writable!==false&&e.writable;var d=function(){if(!e.writable)h()};var h=function(){l=false;if(!c)r()};var p=function(){c=false;if(!l)r()};var m=function(e){r(e?new Error("exited with error code: "+e):null)};var v=function(){if(c&&!(u&&u.ended))return r(new Error("premature close"));if(l&&!(f&&f.ended))return r(new Error("premature close"))};var g=function(){e.req.on("finish",h)};if(o(e)){e.on("complete",h);e.on("abort",v);if(e.req)g();else e.on("request",g)}else if(l&&!f){e.on("end",d);e.on("close",d)}if(s(e))e.on("exit",m);e.on("end",p);e.on("finish",h);if(t.error!==false)e.on("error",r);e.on("close",v);return function(){e.removeListener("complete",h);e.removeListener("abort",v);e.removeListener("request",g);if(e.req)e.req.removeListener("finish",h);e.removeListener("end",d);e.removeListener("close",d);e.removeListener("finish",h);e.removeListener("exit",m);e.removeListener("end",p);e.removeListener("error",r);e.removeListener("close",v)}};t.exports=a},{once:76}],75:[function(e,t,r){arguments[4][20][0].apply(r,arguments)},{dup:20}],76:[function(e,t,r){arguments[4][21][0].apply(r,arguments)},{dup:21,wrappy:75}],77:[function(e,t,r){var n=t.exports=function(e,t){if(!t)t=16;if(e===undefined)e=128;if(e<=0)return"0";var r=Math.log(Math.pow(2,e))/Math.log(t);for(var i=2;r===Infinity;i*=2){r=Math.log(Math.pow(2,e/i))/Math.log(t)*i}var o=r-Math.floor(r);var s="";for(var i=0;i<Math.floor(r);i++){var a=Math.floor(Math.random()*t).toString(t);s=a+s}if(o){var f=Math.pow(t,o);var a=Math.floor(Math.random()*f).toString(t);s=a+s}var u=parseInt(s,t);if(u!==Infinity&&u>=Math.pow(2,e)){return n(e,t)}else return s};n.rack=function(e,t,r){var i=function(i){var s=0;do{if(s++>10){if(r)e+=r;else throw new Error("too many ID collisions, use more bits")}var a=n(e,t)}while(Object.hasOwnProperty.call(o,a));o[a]=i;return a};var o=i.hats={};i.get=function(e){return i.hats[e]};i.set=function(e,t){i.hats[e]=t;return i};i.bits=e||128;i.base=t||16;return i}},{}],78:[function(e,t,r){(function(e){t.exports=r;function r(e){if(!(this instanceof r))return new r(e);this.store=e;if(!this.store||!this.store.get||!this.store.put){throw new Error("First argument must be abstract-chunk-store compliant")}this.mem=[]}r.prototype.put=function(e,t,r){var n=this;n.mem[e]=t;n.store.put(e,t,function(t){n.mem[e]=null;if(r)r(t)})};r.prototype.get=function(e,t,r){if(typeof t==="function")return this.get(e,null,t);var i=t&&t.offset||0;var o=t&&t.length&&i+t.length;var s=this.mem[e];if(s)return n(r,null,t?s.slice(i,o):s);this.store.get(e,t,r)};r.prototype.close=function(e){this.store.close(e)};r.prototype.destroy=function(e){this.store.destroy(e)};function n(t,r,n){e.nextTick(function(){if(t)t(r,n)})}}).call(this,e("_process"))},{_process:34}],79:[function(e,t,r){if(typeof Object.create==="function"){t.exports=function n(e,t){e.super_=t;e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:false,writable:true,configurable:true}})}}else{t.exports=function i(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype;e.prototype=new r;e.prototype.constructor=e}}},{}],80:[function(e,t,r){(function(e){t.exports=r;function r(e,t){if(!(this instanceof r))return new r(e,t);if(!t)t={};this.chunkLength=Number(e);if(!this.chunkLength)throw new Error("First argument must be a chunk length");this.chunks=[];this.closed=false;this.length=Number(t.length)||Infinity;if(this.length!==Infinity){this.lastChunkLength=this.length%this.chunkLength||this.chunkLength;this.lastChunkIndex=Math.ceil(this.length/this.chunkLength)-1}}r.prototype.put=function(e,t,r){if(this.closed)return n(r,new Error("Storage is closed"));var i=e===this.lastChunkIndex;if(i&&t.length!==this.lastChunkLength){return n(r,new Error("Last chunk length must be "+this.lastChunkLength))}if(!i&&t.length!==this.chunkLength){return n(r,new Error("Chunk length must be "+this.chunkLength))}this.chunks[e]=t;n(r,null)};r.prototype.get=function(e,t,r){if(typeof t==="function")return this.get(e,null,t);if(this.closed)return n(r,new Error("Storage is closed"));var i=this.chunks[e];if(!i)return n(r,new Error("Chunk not found"));if(!t)return n(r,null,i);var o=t.offset||0;var s=t.length||i.length-o;n(r,null,i.slice(o,s+o))};r.prototype.close=r.prototype.destroy=function(e){if(this.closed)return n(e,new Error("Storage is closed"));this.closed=true;this.chunks=null;n(e,null)};function n(t,r,n){e.nextTick(function(){if(t)t(r,n)})}}).call(this,e("_process"))},{_process:34}],81:[function(e,t,r){t.exports=o;var n=e("inherits");var i=e("stream");n(o,i.Readable);function o(e,t){if(!(this instanceof o))return new o(e,t);i.Readable.call(this,t);this.destroyed=false;this._drained=false;this._forwarding=false;this._current=null;this._queue=typeof e==="function"?e:e.map(s);this._next()}o.obj=function(e){return new o(e,{objectMode:true,highWaterMark:16})};o.prototype._read=function(){this._drained=true;this._forward()};o.prototype._forward=function(){if(this._forwarding||!this._drained||!this._current)return;this._forwarding=true;var e;while((e=this._current.read())!==null){this._drained=this.push(e)}this._forwarding=false};o.prototype.destroy=function(e){if(this.destroyed)return;this.destroyed=true;if(this._current&&this._current.destroy)this._current.destroy();if(typeof this._queue!=="function"){this._queue.forEach(function(e){if(e.destroy)e.destroy()})}if(e)this.emit("error",e);this.emit("close")};o.prototype._next=function(){var e=this;e._current=null;if(typeof e._queue==="function"){e._queue(function(t,r){if(t)return e.destroy(t);e._gotNextStream(s(r))})}else{var t=e._queue.shift();if(typeof t==="function")t=s(t());e._gotNextStream(t)}};o.prototype._gotNextStream=function(e){var t=this;if(!e){t.push(null);t.destroy();return}t._current=e;t._forward();e.on("readable",r);e.on("end",i);e.on("error",o);e.on("close",n);function r(){t._forward()}function n(){if(!e._readableState.ended){t.destroy()}}function i(){t._current=null;e.removeListener("readable",r);e.removeListener("end",i);e.removeListener("error",o);e.removeListener("close",n);t._next()}function o(e){t.destroy(e)}};function s(e){if(!e||typeof e==="function"||e._readableState)return e;var t=(new i.Readable).wrap(e);if(e.destroy){t.destroy=e.destroy.bind(e)}return t}},{inherits:79,stream:39}],82:[function(e,t,r){(function(r,n){t.exports=u;t.exports.remote=c;var i=e("blob-to-buffer");var o=e("fs");var s=e("simple-get");var a=e("magnet-uri");var f=e("parse-torrent-file");t.exports.toMagnetURI=a.encode;t.exports.toTorrentFile=f.encode;function u(e){if(typeof e==="string"&&/magnet:/.test(e)){return a(e)}else if(typeof e==="string"&&(/^[a-f0-9]{40}$/i.test(e)||/^[a-z2-7]{32}$/i.test(e))){return a("magnet:?xt=urn:btih:"+e)}else if(r.isBuffer(e)&&e.length===20){return a("magnet:?xt=urn:btih:"+e.toString("hex"))}else if(r.isBuffer(e)){return f(e)}else if(e&&e.infoHash){if(!e.announce)e.announce=[];if(typeof e.announce==="string"){e.announce=[e.announce]}if(!e.urlList)e.urlList=[];return e}else{throw new Error("Invalid torrent identifier")}}function c(e,t){var r;if(typeof t!=="function")throw new Error("second argument must be a Function");try{r=u(e)}catch(a){}if(r&&r.infoHash){n.nextTick(function(){t(null,r)})}else if(l(e)){i(e,function(e,r){if(e)return t(new Error("Error converting Blob: "+e.message));f(r)})}else if(typeof s==="function"&&/^https?:/.test(e)){s.concat({url:e,headers:{"user-agent":"WebTorrent (http://webtorrent.io)"}},function(e,r){if(e)return t(new Error("Error downloading torrent: "+e.message));f(r)})}else if(typeof o.readFile==="function"&&typeof e==="string"){o.readFile(e,function(e,r){if(e)return t(new Error("Invalid torrent identifier"));f(r)})}else{n.nextTick(function(){t(new Error("Invalid torrent identifier"))})}function f(e){try{r=u(e)}catch(n){return t(n)}if(r&&r.infoHash)t(null,r);else t(new Error("Invalid torrent identifier"))}}function l(e){return typeof Blob!=="undefined"&&e instanceof Blob}}).call(this,{isBuffer:e("../browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js")},e("_process"))},{"../browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js":32,_process:34,"blob-to-buffer":83,fs:24,"magnet-uri":84,"parse-torrent-file":87,"simple-get":131}],83:[function(e,t,r){(function(e){t.exports=function r(t,n){if(typeof Blob==="undefined"||!(t instanceof Blob)){throw new Error("first argument must be a Blob")}if(typeof n!=="function"){throw new Error("second argument must be a function")}var i=new FileReader;function o(t){i.removeEventListener("loadend",o,false);if(t.error)n(t.error);else n(null,new e(i.result))}i.addEventListener("loadend",o,false);i.readAsArrayBuffer(t)}}).call(this,e("buffer").Buffer)},{buffer:26}],84:[function(e,t,r){(function(r){t.exports=s;t.exports.decode=s;t.exports.encode=a;var n=e("thirty-two");var i=e("xtend");var o=e("uniq");function s(e){var t={};var i=e.split("magnet:?")[1];var s=i&&i.length>=0?i.split("&"):[];s.forEach(function(e){var r=e.split("=");if(r.length!==2)return;var n=r[0];var i=r[1];if(n==="dn")i=decodeURIComponent(i).replace(/\+/g," ");if(n==="tr"||n==="xs"||n==="as"||n==="ws"){i=decodeURIComponent(i)}if(n==="kt")i=decodeURIComponent(i).split("+");if(t[n]){if(Array.isArray(t[n])){t[n].push(i)}else{var o=t[n];t[n]=[o,i]}}else{t[n]=i}});var a;if(t.xt){var f=Array.isArray(t.xt)?t.xt:[t.xt];f.forEach(function(e){if(a=e.match(/^urn:btih:(.{40})/)){t.infoHash=a[1].toLowerCase()}else if(a=e.match(/^urn:btih:(.{32})/)){var i=n.decode(a[1]);t.infoHash=new r(i,"binary").toString("hex")}})}if(t.infoHash)t.infoHashBuffer=new r(t.infoHash,"hex");if(t.dn)t.name=t.dn;if(t.kt)t.keywords=t.kt;if(typeof t.tr==="string")t.announce=[t.tr];else if(Array.isArray(t.tr))t.announce=t.tr;else t.announce=[];t.urlList=[];if(typeof t.as==="string"||Array.isArray(t.as)){t.urlList=t.urlList.concat(t.as)}if(typeof t.ws==="string"||Array.isArray(t.ws)){t.urlList=t.urlList.concat(t.ws)}o(t.announce);o(t.urlList);return t}function a(e){e=i(e);if(e.infoHashBuffer)e.xt="urn:btih:"+e.infoHashBuffer.toString("hex");if(e.infoHash)e.xt="urn:btih:"+e.infoHash;if(e.name)e.dn=e.name;if(e.keywords)e.kt=e.keywords;if(e.announce)e.tr=e.announce;if(e.urlList){e.ws=e.urlList;delete e.as}var t="magnet:?";Object.keys(e).filter(function(e){return e.length===2}).forEach(function(r,n){var i=Array.isArray(e[r])?e[r]:[e[r]];i.forEach(function(e,i){if((n>0||i>0)&&(r!=="kt"||i===0))t+="&";if(r==="dn")e=encodeURIComponent(e).replace(/%20/g,"+");if(r==="tr"||r==="xs"||r==="as"||r==="ws"){e=encodeURIComponent(e)}if(r==="kt")e=encodeURIComponent(e);if(r==="kt"&&i>0)t+="+"+e;else t+=r+"="+e})});return t}}).call(this,e("buffer").Buffer)},{buffer:26,"thirty-two":85,uniq:150,xtend:156}],85:[function(e,t,r){var n=e("./thirty-two");r.encode=n.encode;r.decode=n.decode},{"./thirty-two":86}],86:[function(e,t,r){(function(e){var t="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";var n=[255,255,26,27,28,29,30,31,255,255,255,255,255,255,255,255,255,0,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,255,255,255,255,255,255,0,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,255,255,255,255,255];function i(e){var t=Math.floor(e.length/5);return e.length%5==0?t:t+1}r.encode=function(r){if(!e.isBuffer(r)){r=new e(r)}var n=0;var o=0;var s=0;var a=0;var f=new e(i(r)*8);while(n<r.length){var u=r[n];if(s>3){a=u&255>>s;s=(s+5)%8;a=a<<s|(n+1<r.length?r[n+1]:0)>>8-s;n++}else{a=u>>8-(s+5)&31;s=(s+5)%8;if(s==0)n++}f[o]=t.charCodeAt(a);o++}for(n=o;n<f.length;n++)f[n]=61;return f};r.decode=function(t){var r=0;var i=0;var o;var s=0;if(!e.isBuffer(t)){t=new e(t)}var a=new e(Math.ceil(t.length*5/8));for(var f=0;f<t.length;f++){if(t[f]==61){break}var u=t[f]-48;if(u<n.length){i=n[u];if(r<=3){r=(r+5)%8;if(r==0){o|=i;a[s]=o;s++;o=0}else{o|=255&i<<8-r}}else{r=(r+5)%8;o|=255&i>>>r;a[s]=o;s++;o=255&i<<8-r}}else{throw new Error("Invalid input - it is not base32 encoded string")}}return a.slice(0,s)}}).call(this,e("buffer").Buffer)},{buffer:26}],87:[function(e,t,r){(function(r){t.exports=a;t.exports.decode=a;t.exports.encode=f;var n=e("bencode");var i=e("path");var o=e("simple-sha1");var s=e("uniq");function a(e){if(r.isBuffer(e)){e=n.decode(e)}l(e.info,"info");l(e.info["name.utf-8"]||e.info.name,"info.name");l(e.info["piece length"],"info['piece length']");l(e.info.pieces,"info.pieces");if(e.info.files){e.info.files.forEach(function(e){l(typeof e.length==="number","info.files[0].length");l(e["path.utf-8"]||e.path,"info.files[0].path")})}else{l(typeof e.info.length==="number","info.length")}var t={};t.info=e.info;t.infoBuffer=n.encode(e.info);t.infoHash=o.sync(t.infoBuffer);t.infoHashBuffer=new r(t.infoHash,"hex");t.name=(e.info["name.utf-8"]||e.info.name).toString();if(e.info.private!==undefined)t.private=!!e.info.private;if(e["creation date"])t.created=new Date(e["creation date"]*1e3);if(e["created by"])t.createdBy=e["created by"].toString();if(r.isBuffer(e.comment))t.comment=e.comment.toString();t.announce=[];if(e["announce-list"]&&e["announce-list"].length){e["announce-list"].forEach(function(e){e.forEach(function(e){t.announce.push(e.toString())})})}else if(e.announce){t.announce.push(e.announce.toString())}if(r.isBuffer(e["url-list"])){e["url-list"]=e["url-list"].length>0?[e["url-list"]]:[]}t.urlList=(e["url-list"]||[]).map(function(e){return e.toString()});s(t.announce);s(t.urlList);var a=e.info.files||[e.info];t.files=a.map(function(e,r){var n=[].concat(t.name,e["path.utf-8"]||e.path||[]).map(function(e){return e.toString()});return{path:i.join.apply(null,[i.sep].concat(n)).slice(1),name:n[n.length-1],length:e.length,offset:a.slice(0,r).reduce(u,0)}});t.length=a.reduce(u,0);var f=t.files[t.files.length-1];t.pieceLength=e.info["piece length"];t.lastPieceLength=(f.offset+f.length)%t.pieceLength||t.pieceLength;t.pieces=c(e.info.pieces);return t}function f(e){var t={info:e.info};t["announce-list"]=e.announce.map(function(e){if(!t.announce)t.announce=e;e=new r(e,"utf8");return[e]});if(e.created){t["creation date"]=e.created.getTime()/1e3|0}if(e.urlList){t["url-list"]=e.urlList}return n.encode(t)}function u(e,t){return e+t.length}function c(e){var t=[];for(var r=0;r<e.length;r+=20){t.push(e.slice(r,r+20).toString("hex"))}return t}function l(e,t){if(!e)throw new Error("Torrent is missing required field: "+t)}}).call(this,e("buffer").Buffer)},{bencode:88,buffer:26,path:33,"simple-sha1":139,uniq:150}],88:[function(e,t,r){arguments[4][12][0].apply(r,arguments)},{"./lib/decode":89,"./lib/encode":91,dup:12}],89:[function(e,t,r){arguments[4][13][0].apply(r,arguments)},{"./dict":90,buffer:26,dup:13}],90:[function(e,t,r){arguments[4][14][0].apply(r,arguments)},{dup:14}],91:[function(e,t,r){arguments[4][15][0].apply(r,arguments)},{buffer:26,dup:15}],92:[function(e,t,r){var n=e("once");var i=e("end-of-stream");var o=e("fs");var s=function(){};var a=function(e){return typeof e==="function"};var f=function(e){return(e instanceof(o.ReadStream||s)||e instanceof(o.WriteStream||s))&&a(e.close)};var u=function(e){return e.setHeader&&a(e.abort)};var c=function(e,t,r,o){o=n(o);var s=false;e.on("close",function(){s=true});i(e,{readable:t,writable:r},function(e){if(e)return o(e);s=true;o()});var c=false;return function(t){if(s)return;if(c)return;c=true;if(f(e))return e.close();if(u(e))return e.abort();if(a(e.destroy))return e.destroy();o(t||new Error("stream was destroyed"))}};var l=function(e){e()};var d=function(e,t){return e.pipe(t)};var h=function(){var e=Array.prototype.slice.call(arguments);var t=a(e[e.length-1]||s)&&e.pop()||s;if(Array.isArray(e[0]))e=e[0];if(e.length<2)throw new Error("pump requires two streams per minimum");var r;var n=e.map(function(i,o){var s=o<e.length-1;var a=o>0;return c(i,s,a,function(e){if(!r)r=e;if(e)n.forEach(l);if(s)return;n.forEach(l);t(r)})});return e.reduce(d)};t.exports=h},{"end-of-stream":74,fs:24,once:94}],93:[function(e,t,r){arguments[4][20][0].apply(r,arguments)},{dup:20}],94:[function(e,t,r){arguments[4][21][0].apply(r,arguments)},{dup:21,wrappy:93}],95:[function(e,t,r){var n=function(e){var t=0;return function(){if(t===e.length)return null;var r=e.length-t;var n=Math.random()*r|0;var i=e[t+n];var o=e[t];e[t]=i;e[t+n]=o;t++;return i}};t.exports=n},{}],96:[function(e,t,r){t.exports=i;t.exports.filter=o;var n=e("events").EventEmitter;function i(e,t,r){if(!Array.isArray(r))r=[r];var n=[];r.forEach(function(r){var i=function(){var e=[].slice.call(arguments);e.unshift(r);t.emit.apply(t,e)};n.push(i);e.on(r,i)});return function i(){r.forEach(function(t,r){e.removeListener(t,n[r])})}}function o(e,t){var r=new n;i(e,r,t);return r}},{events:30}],97:[function(e,t,r){t.exports=e("./lib/_stream_duplex.js")},{"./lib/_stream_duplex.js":98}],98:[function(e,t,r){"use strict";var n=Object.keys||function(e){var t=[];for(var r in e)t.push(r);return t};t.exports=l;var i=e("process-nextick-args");var o=e("core-util-is");o.inherits=e("inherits");var s=e("./_stream_readable");var a=e("./_stream_writable");o.inherits(l,s);var f=n(a.prototype);for(var u=0;u<f.length;u++){var c=f[u];if(!l.prototype[c])l.prototype[c]=a.prototype[c]}function l(e){if(!(this instanceof l))return new l(e);s.call(this,e);a.call(this,e);if(e&&e.readable===false)this.readable=false;if(e&&e.writable===false)this.writable=false;this.allowHalfOpen=true;if(e&&e.allowHalfOpen===false)this.allowHalfOpen=false;this.once("end",d)}function d(){if(this.allowHalfOpen||this._writableState.ended)return;i(h,this)}function h(e){e.end()}function p(e,t){for(var r=0,n=e.length;r<n;r++){t(e[r],r)}}},{"./_stream_readable":100,"./_stream_writable":102,"core-util-is":103,inherits:79,"process-nextick-args":105}],99:[function(e,t,r){"use strict";t.exports=o;var n=e("./_stream_transform");var i=e("core-util-is");i.inherits=e("inherits");i.inherits(o,n);function o(e){if(!(this instanceof o))return new o(e);n.call(this,e)}o.prototype._transform=function(e,t,r){r(null,e)}},{"./_stream_transform":101,"core-util-is":103,inherits:79}],100:[function(e,t,r){(function(r){"use strict";t.exports=m;var n=e("process-nextick-args");var i=e("isarray");var o=e("buffer").Buffer;m.ReadableState=p;var s=e("events");var a=function(e,t){return e.listeners(t).length};var f;(function(){try{f=e("st"+"ream")}catch(t){}finally{if(!f)f=e("events").EventEmitter}})();var o=e("buffer").Buffer;var u=e("core-util-is");u.inherits=e("inherits");var c=e("util");var l;if(c&&c.debuglog){l=c.debuglog("stream")}else{l=function(){}}var d;u.inherits(m,f);var h;function p(t,r){h=h||e("./_stream_duplex");t=t||{};this.objectMode=!!t.objectMode;if(r instanceof h)this.objectMode=this.objectMode||!!t.readableObjectMode;var n=t.highWaterMark;var i=this.objectMode?16:16*1024;this.highWaterMark=n||n===0?n:i;this.highWaterMark=~~this.highWaterMark;this.buffer=[];this.length=0;this.pipes=null;this.pipesCount=0;this.flowing=null;this.ended=false;this.endEmitted=false;this.reading=false;this.sync=true;this.needReadable=false;this.emittedReadable=false;this.readableListening=false;this.defaultEncoding=t.defaultEncoding||"utf8";this.ranOut=false;this.awaitDrain=0;this.readingMore=false;this.decoder=null;this.encoding=null;if(t.encoding){if(!d)d=e("string_decoder/").StringDecoder;this.decoder=new d(t.encoding);this.encoding=t.encoding}}var h;function m(t){h=h||e("./_stream_duplex");if(!(this instanceof m))return new m(t);this._readableState=new p(t,this);this.readable=true;if(t&&typeof t.read==="function")this._read=t.read;f.call(this)}m.prototype.push=function(e,t){var r=this._readableState;if(!r.objectMode&&typeof e==="string"){t=t||r.defaultEncoding;if(t!==r.encoding){e=new o(e,t);t=""}}return v(this,r,e,t,false)};m.prototype.unshift=function(e){var t=this._readableState;return v(this,t,e,"",true)};m.prototype.isPaused=function(){return this._readableState.flowing===false};function v(e,t,r,n,i){var o=w(t,r);if(o){e.emit("error",o)}else if(r===null){t.reading=false;E(e,t)}else if(t.objectMode||r&&r.length>0){if(t.ended&&!i){var s=new Error("stream.push() after EOF");e.emit("error",s)}else if(t.endEmitted&&i){var s=new Error("stream.unshift() after end event");e.emit("error",s)}else{if(t.decoder&&!i&&!n)r=t.decoder.write(r);if(!i)t.reading=false;if(t.flowing&&t.length===0&&!t.sync){e.emit("data",r);e.read(0)}else{t.length+=t.objectMode?1:r.length;if(i)t.buffer.unshift(r);else t.buffer.push(r);if(t.needReadable)k(e)}S(e,t)}}else if(!i){t.reading=false}return g(t)}function g(e){return!e.ended&&(e.needReadable||e.length<e.highWaterMark||e.length===0)}m.prototype.setEncoding=function(t){if(!d)d=e("string_decoder/").StringDecoder;this._readableState.decoder=new d(t);this._readableState.encoding=t;return this};var y=8388608;function _(e){if(e>=y){e=y}else{e--;e|=e>>>1;e|=e>>>2;e|=e>>>4;e|=e>>>8;e|=e>>>16; -e++}return e}function b(e,t){if(t.length===0&&t.ended)return 0;if(t.objectMode)return e===0?0:1;if(e===null||isNaN(e)){if(t.flowing&&t.buffer.length)return t.buffer[0].length;else return t.length}if(e<=0)return 0;if(e>t.highWaterMark)t.highWaterMark=_(e);if(e>t.length){if(!t.ended){t.needReadable=true;return 0}else{return t.length}}return e}m.prototype.read=function(e){l("read",e);var t=this._readableState;var r=e;if(typeof e!=="number"||e>0)t.emittedReadable=false;if(e===0&&t.needReadable&&(t.length>=t.highWaterMark||t.ended)){l("read: emitReadable",t.length,t.ended);if(t.length===0&&t.ended)U(this);else k(this);return null}e=b(e,t);if(e===0&&t.ended){if(t.length===0)U(this);return null}var n=t.needReadable;l("need readable",n);if(t.length===0||t.length-e<t.highWaterMark){n=true;l("length less than watermark",n)}if(t.ended||t.reading){n=false;l("reading or ended",n)}if(n){l("do read");t.reading=true;t.sync=true;if(t.length===0)t.needReadable=true;this._read(t.highWaterMark);t.sync=false}if(n&&!t.reading)e=b(r,t);var i;if(e>0)i=R(e,t);else i=null;if(i===null){t.needReadable=true;e=0}t.length-=e;if(t.length===0&&!t.ended)t.needReadable=true;if(r!==e&&t.ended&&t.length===0)U(this);if(i!==null)this.emit("data",i);return i};function w(e,t){var r=null;if(!o.isBuffer(t)&&typeof t!=="string"&&t!==null&&t!==undefined&&!e.objectMode){r=new TypeError("Invalid non-string/buffer chunk")}return r}function E(e,t){if(t.ended)return;if(t.decoder){var r=t.decoder.end();if(r&&r.length){t.buffer.push(r);t.length+=t.objectMode?1:r.length}}t.ended=true;k(e)}function k(e){var t=e._readableState;t.needReadable=false;if(!t.emittedReadable){l("emitReadable",t.flowing);t.emittedReadable=true;if(t.sync)n(x,e);else x(e)}}function x(e){l("emit readable");e.emit("readable");L(e)}function S(e,t){if(!t.readingMore){t.readingMore=true;n(I,e,t)}}function I(e,t){var r=t.length;while(!t.reading&&!t.flowing&&!t.ended&&t.length<t.highWaterMark){l("maybeReadMore read 0");e.read(0);if(r===t.length)break;else r=t.length}t.readingMore=false}m.prototype._read=function(e){this.emit("error",new Error("not implemented"))};m.prototype.pipe=function(e,t){var o=this;var s=this._readableState;switch(s.pipesCount){case 0:s.pipes=e;break;case 1:s.pipes=[s.pipes,e];break;default:s.pipes.push(e);break}s.pipesCount+=1;l("pipe count=%d opts=%j",s.pipesCount,t);var f=(!t||t.end!==false)&&e!==r.stdout&&e!==r.stderr;var u=f?d:m;if(s.endEmitted)n(u);else o.once("end",u);e.on("unpipe",c);function c(e){l("onunpipe");if(e===o){m()}}function d(){l("onend");e.end()}var h=B(o);e.on("drain",h);var p=false;function m(){l("cleanup");e.removeListener("close",y);e.removeListener("finish",_);e.removeListener("drain",h);e.removeListener("error",g);e.removeListener("unpipe",c);o.removeListener("end",d);o.removeListener("end",m);o.removeListener("data",v);p=true;if(s.awaitDrain&&(!e._writableState||e._writableState.needDrain))h()}o.on("data",v);function v(t){l("ondata");var r=e.write(t);if(false===r){if(s.pipesCount===1&&s.pipes[0]===e&&o.listenerCount("data")===1&&!p){l("false write response, pause",o._readableState.awaitDrain);o._readableState.awaitDrain++}o.pause()}}function g(t){l("onerror",t);b();e.removeListener("error",g);if(a(e,"error")===0)e.emit("error",t)}if(!e._events||!e._events.error)e.on("error",g);else if(i(e._events.error))e._events.error.unshift(g);else e._events.error=[g,e._events.error];function y(){e.removeListener("finish",_);b()}e.once("close",y);function _(){l("onfinish");e.removeListener("close",y);b()}e.once("finish",_);function b(){l("unpipe");o.unpipe(e)}e.emit("pipe",o);if(!s.flowing){l("pipe resume");o.resume()}return e};function B(e){return function(){var t=e._readableState;l("pipeOnDrain",t.awaitDrain);if(t.awaitDrain)t.awaitDrain--;if(t.awaitDrain===0&&a(e,"data")){t.flowing=true;L(e)}}}m.prototype.unpipe=function(e){var t=this._readableState;if(t.pipesCount===0)return this;if(t.pipesCount===1){if(e&&e!==t.pipes)return this;if(!e)e=t.pipes;t.pipes=null;t.pipesCount=0;t.flowing=false;if(e)e.emit("unpipe",this);return this}if(!e){var r=t.pipes;var n=t.pipesCount;t.pipes=null;t.pipesCount=0;t.flowing=false;for(var i=0;i<n;i++)r[i].emit("unpipe",this);return this}var i=M(t.pipes,e);if(i===-1)return this;t.pipes.splice(i,1);t.pipesCount-=1;if(t.pipesCount===1)t.pipes=t.pipes[0];e.emit("unpipe",this);return this};m.prototype.on=function(e,t){var r=f.prototype.on.call(this,e,t);if(e==="data"&&false!==this._readableState.flowing){this.resume()}if(e==="readable"&&this.readable){var i=this._readableState;if(!i.readableListening){i.readableListening=true;i.emittedReadable=false;i.needReadable=true;if(!i.reading){n(A,this)}else if(i.length){k(this,i)}}}return r};m.prototype.addListener=m.prototype.on;function A(e){l("readable nexttick read 0");e.read(0)}m.prototype.resume=function(){var e=this._readableState;if(!e.flowing){l("resume");e.flowing=true;C(this,e)}return this};function C(e,t){if(!t.resumeScheduled){t.resumeScheduled=true;n(T,e,t)}}function T(e,t){if(!t.reading){l("resume read 0");e.read(0)}t.resumeScheduled=false;e.emit("resume");L(e);if(t.flowing&&!t.reading)e.read(0)}m.prototype.pause=function(){l("call pause flowing=%j",this._readableState.flowing);if(false!==this._readableState.flowing){l("pause");this._readableState.flowing=false;this.emit("pause")}return this};function L(e){var t=e._readableState;l("flow",t.flowing);if(t.flowing){do{var r=e.read()}while(null!==r&&t.flowing)}}m.prototype.wrap=function(e){var t=this._readableState;var r=false;var n=this;e.on("end",function(){l("wrapped end");if(t.decoder&&!t.ended){var e=t.decoder.end();if(e&&e.length)n.push(e)}n.push(null)});e.on("data",function(i){l("wrapped data");if(t.decoder)i=t.decoder.write(i);if(t.objectMode&&(i===null||i===undefined))return;else if(!t.objectMode&&(!i||!i.length))return;var o=n.push(i);if(!o){r=true;e.pause()}});for(var i in e){if(this[i]===undefined&&typeof e[i]==="function"){this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i)}}var o=["error","close","destroy","pause","resume"];O(o,function(t){e.on(t,n.emit.bind(n,t))});n._read=function(t){l("wrapped _read",t);if(r){r=false;e.resume()}};return n};m._fromList=R;function R(e,t){var r=t.buffer;var n=t.length;var i=!!t.decoder;var s=!!t.objectMode;var a;if(r.length===0)return null;if(n===0)a=null;else if(s)a=r.shift();else if(!e||e>=n){if(i)a=r.join("");else if(r.length===1)a=r[0];else a=o.concat(r,n);r.length=0}else{if(e<r[0].length){var f=r[0];a=f.slice(0,e);r[0]=f.slice(e)}else if(e===r[0].length){a=r.shift()}else{if(i)a="";else a=new o(e);var u=0;for(var c=0,l=r.length;c<l&&u<e;c++){var f=r[0];var d=Math.min(e-u,f.length);if(i)a+=f.slice(0,d);else f.copy(a,u,0,d);if(d<f.length)r[0]=f.slice(d);else r.shift();u+=d}}}return a}function U(e){var t=e._readableState;if(t.length>0)throw new Error("endReadable called on non-empty stream");if(!t.endEmitted){t.ended=true;n(P,t,e)}}function P(e,t){if(!e.endEmitted&&e.length===0){e.endEmitted=true;t.readable=false;t.emit("end")}}function O(e,t){for(var r=0,n=e.length;r<n;r++){t(e[r],r)}}function M(e,t){for(var r=0,n=e.length;r<n;r++){if(e[r]===t)return r}return-1}}).call(this,e("_process"))},{"./_stream_duplex":98,_process:34,buffer:26,"core-util-is":103,events:30,inherits:79,isarray:104,"process-nextick-args":105,"string_decoder/":106,util:25}],101:[function(e,t,r){"use strict";t.exports=a;var n=e("./_stream_duplex");var i=e("core-util-is");i.inherits=e("inherits");i.inherits(a,n);function o(e){this.afterTransform=function(t,r){return s(e,t,r)};this.needTransform=false;this.transforming=false;this.writecb=null;this.writechunk=null}function s(e,t,r){var n=e._transformState;n.transforming=false;var i=n.writecb;if(!i)return e.emit("error",new Error("no writecb in Transform class"));n.writechunk=null;n.writecb=null;if(r!==null&&r!==undefined)e.push(r);if(i)i(t);var o=e._readableState;o.reading=false;if(o.needReadable||o.length<o.highWaterMark){e._read(o.highWaterMark)}}function a(e){if(!(this instanceof a))return new a(e);n.call(this,e);this._transformState=new o(this);var t=this;this._readableState.needReadable=true;this._readableState.sync=false;if(e){if(typeof e.transform==="function")this._transform=e.transform;if(typeof e.flush==="function")this._flush=e.flush}this.once("prefinish",function(){if(typeof this._flush==="function")this._flush(function(e){f(t,e)});else f(t)})}a.prototype.push=function(e,t){this._transformState.needTransform=false;return n.prototype.push.call(this,e,t)};a.prototype._transform=function(e,t,r){throw new Error("not implemented")};a.prototype._write=function(e,t,r){var n=this._transformState;n.writecb=r;n.writechunk=e;n.writeencoding=t;if(!n.transforming){var i=this._readableState;if(n.needTransform||i.needReadable||i.length<i.highWaterMark)this._read(i.highWaterMark)}};a.prototype._read=function(e){var t=this._transformState;if(t.writechunk!==null&&t.writecb&&!t.transforming){t.transforming=true;this._transform(t.writechunk,t.writeencoding,t.afterTransform)}else{t.needTransform=true}};function f(e,t){if(t)return e.emit("error",t);var r=e._writableState;var n=e._transformState;if(r.length)throw new Error("calling transform done when ws.length != 0");if(n.transforming)throw new Error("calling transform done when still transforming");return e.push(null)}},{"./_stream_duplex":98,"core-util-is":103,inherits:79}],102:[function(e,t,r){"use strict";t.exports=d;var n=e("process-nextick-args");var i=e("buffer").Buffer;d.WritableState=l;var o=e("core-util-is");o.inherits=e("inherits");var s={deprecate:e("util-deprecate")};var a;(function(){try{a=e("st"+"ream")}catch(t){}finally{if(!a)a=e("events").EventEmitter}})();var i=e("buffer").Buffer;o.inherits(d,a);function f(){}function u(e,t,r){this.chunk=e;this.encoding=t;this.callback=r;this.next=null}var c;function l(t,r){c=c||e("./_stream_duplex");t=t||{};this.objectMode=!!t.objectMode;if(r instanceof c)this.objectMode=this.objectMode||!!t.writableObjectMode;var n=t.highWaterMark;var i=this.objectMode?16:16*1024;this.highWaterMark=n||n===0?n:i;this.highWaterMark=~~this.highWaterMark;this.needDrain=false;this.ending=false;this.ended=false;this.finished=false;var o=t.decodeStrings===false;this.decodeStrings=!o;this.defaultEncoding=t.defaultEncoding||"utf8";this.length=0;this.writing=false;this.corked=0;this.sync=true;this.bufferProcessing=false;this.onwrite=function(e){b(r,e)};this.writecb=null;this.writelen=0;this.bufferedRequest=null;this.lastBufferedRequest=null;this.pendingcb=0;this.prefinished=false;this.errorEmitted=false}l.prototype.getBuffer=function A(){var e=this.bufferedRequest;var t=[];while(e){t.push(e);e=e.next}return t};(function(){try{Object.defineProperty(l.prototype,"buffer",{get:s.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer "+"instead.")})}catch(e){}})();var c;function d(t){c=c||e("./_stream_duplex");if(!(this instanceof d)&&!(this instanceof c))return new d(t);this._writableState=new l(t,this);this.writable=true;if(t){if(typeof t.write==="function")this._write=t.write;if(typeof t.writev==="function")this._writev=t.writev}a.call(this)}d.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe. Not readable."))};function h(e,t){var r=new Error("write after end");e.emit("error",r);n(t,r)}function p(e,t,r,o){var s=true;if(!i.isBuffer(r)&&typeof r!=="string"&&r!==null&&r!==undefined&&!t.objectMode){var a=new TypeError("Invalid non-string/buffer chunk");e.emit("error",a);n(o,a);s=false}return s}d.prototype.write=function(e,t,r){var n=this._writableState;var o=false;if(typeof t==="function"){r=t;t=null}if(i.isBuffer(e))t="buffer";else if(!t)t=n.defaultEncoding;if(typeof r!=="function")r=f;if(n.ended)h(this,r);else if(p(this,n,e,r)){n.pendingcb++;o=v(this,n,e,t,r)}return o};d.prototype.cork=function(){var e=this._writableState;e.corked++};d.prototype.uncork=function(){var e=this._writableState;if(e.corked){e.corked--;if(!e.writing&&!e.corked&&!e.finished&&!e.bufferProcessing&&e.bufferedRequest)k(this,e)}};d.prototype.setDefaultEncoding=function C(e){if(typeof e==="string")e=e.toLowerCase();if(!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((e+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+e);this._writableState.defaultEncoding=e};function m(e,t,r){if(!e.objectMode&&e.decodeStrings!==false&&typeof t==="string"){t=new i(t,r)}return t}function v(e,t,r,n,o){r=m(t,r,n);if(i.isBuffer(r))n="buffer";var s=t.objectMode?1:r.length;t.length+=s;var a=t.length<t.highWaterMark;if(!a)t.needDrain=true;if(t.writing||t.corked){var f=t.lastBufferedRequest;t.lastBufferedRequest=new u(r,n,o);if(f){f.next=t.lastBufferedRequest}else{t.bufferedRequest=t.lastBufferedRequest}}else{g(e,t,false,s,r,n,o)}return a}function g(e,t,r,n,i,o,s){t.writelen=n;t.writecb=s;t.writing=true;t.sync=true;if(r)e._writev(i,t.onwrite);else e._write(i,o,t.onwrite);t.sync=false}function y(e,t,r,i,o){--t.pendingcb;if(r)n(o,i);else o(i);e._writableState.errorEmitted=true;e.emit("error",i)}function _(e){e.writing=false;e.writecb=null;e.length-=e.writelen;e.writelen=0}function b(e,t){var r=e._writableState;var i=r.sync;var o=r.writecb;_(r);if(t)y(e,r,i,t,o);else{var s=x(r);if(!s&&!r.corked&&!r.bufferProcessing&&r.bufferedRequest){k(e,r)}if(i){n(w,e,r,s,o)}else{w(e,r,s,o)}}}function w(e,t,r,n){if(!r)E(e,t);t.pendingcb--;n();I(e,t)}function E(e,t){if(t.length===0&&t.needDrain){t.needDrain=false;e.emit("drain")}}function k(e,t){t.bufferProcessing=true;var r=t.bufferedRequest;if(e._writev&&r&&r.next){var n=[];var i=[];while(r){i.push(r.callback);n.push(r);r=r.next}t.pendingcb++;t.lastBufferedRequest=null;g(e,t,true,t.length,n,"",function(e){for(var r=0;r<i.length;r++){t.pendingcb--;i[r](e)}})}else{while(r){var o=r.chunk;var s=r.encoding;var a=r.callback;var f=t.objectMode?1:o.length;g(e,t,false,f,o,s,a);r=r.next;if(t.writing){break}}if(r===null)t.lastBufferedRequest=null}t.bufferedRequest=r;t.bufferProcessing=false}d.prototype._write=function(e,t,r){r(new Error("not implemented"))};d.prototype._writev=null;d.prototype.end=function(e,t,r){var n=this._writableState;if(typeof e==="function"){r=e;e=null;t=null}else if(typeof t==="function"){r=t;t=null}if(e!==null&&e!==undefined)this.write(e,t);if(n.corked){n.corked=1;this.uncork()}if(!n.ending&&!n.finished)B(this,n,r)};function x(e){return e.ending&&e.length===0&&e.bufferedRequest===null&&!e.finished&&!e.writing}function S(e,t){if(!t.prefinished){t.prefinished=true;e.emit("prefinish")}}function I(e,t){var r=x(t);if(r){if(t.pendingcb===0){S(e,t);t.finished=true;e.emit("finish")}else{S(e,t)}}return r}function B(e,t,r){t.ending=true;I(e,t);if(r){if(t.finished)n(r);else e.once("finish",r)}t.ended=true}},{"./_stream_duplex":98,buffer:26,"core-util-is":103,events:30,inherits:79,"process-nextick-args":105,"util-deprecate":107}],103:[function(e,t,r){(function(e){function t(e){if(Array.isArray){return Array.isArray(e)}return v(e)==="[object Array]"}r.isArray=t;function n(e){return typeof e==="boolean"}r.isBoolean=n;function i(e){return e===null}r.isNull=i;function o(e){return e==null}r.isNullOrUndefined=o;function s(e){return typeof e==="number"}r.isNumber=s;function a(e){return typeof e==="string"}r.isString=a;function f(e){return typeof e==="symbol"}r.isSymbol=f;function u(e){return e===void 0}r.isUndefined=u;function c(e){return v(e)==="[object RegExp]"}r.isRegExp=c;function l(e){return typeof e==="object"&&e!==null}r.isObject=l;function d(e){return v(e)==="[object Date]"}r.isDate=d;function h(e){return v(e)==="[object Error]"||e instanceof Error}r.isError=h;function p(e){return typeof e==="function"}r.isFunction=p;function m(e){return e===null||typeof e==="boolean"||typeof e==="number"||typeof e==="string"||typeof e==="symbol"||typeof e==="undefined"}r.isPrimitive=m;r.isBuffer=e.isBuffer;function v(e){return Object.prototype.toString.call(e)}}).call(this,{isBuffer:e("../../../../browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js")})},{"../../../../browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js":32}],104:[function(e,t,r){t.exports=Array.isArray||function(e){return Object.prototype.toString.call(e)=="[object Array]"}},{}],105:[function(e,t,r){(function(e){"use strict";if(!e.version||e.version.indexOf("v0.")===0||e.version.indexOf("v1.")===0&&e.version.indexOf("v1.8.")!==0){t.exports=r}else{t.exports=e.nextTick}function r(t){var r=new Array(arguments.length-1);var n=0;while(n<r.length){r[n++]=arguments[n]}e.nextTick(function i(){t.apply(null,r)})}}).call(this,e("_process"))},{_process:34}],106:[function(e,t,r){var n=e("buffer").Buffer;var i=n.isEncoding||function(e){switch(e&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return true;default:return false}};function o(e){if(e&&!i(e)){throw new Error("Unknown encoding: "+e)}}var s=r.StringDecoder=function(e){this.encoding=(e||"utf8").toLowerCase().replace(/[-_]/,"");o(e);switch(this.encoding){case"utf8":this.surrogateSize=3;break;case"ucs2":case"utf16le":this.surrogateSize=2;this.detectIncompleteChar=f;break;case"base64":this.surrogateSize=3;this.detectIncompleteChar=u;break;default:this.write=a;return}this.charBuffer=new n(6);this.charReceived=0;this.charLength=0};s.prototype.write=function(e){var t="";while(this.charLength){var r=e.length>=this.charLength-this.charReceived?this.charLength-this.charReceived:e.length;e.copy(this.charBuffer,this.charReceived,0,r);this.charReceived+=r;if(this.charReceived<this.charLength){return""}e=e.slice(r,e.length);t=this.charBuffer.slice(0,this.charLength).toString(this.encoding);var n=t.charCodeAt(t.length-1);if(n>=55296&&n<=56319){this.charLength+=this.surrogateSize;t="";continue}this.charReceived=this.charLength=0;if(e.length===0){return t}break}this.detectIncompleteChar(e);var i=e.length;if(this.charLength){e.copy(this.charBuffer,0,e.length-this.charReceived,i);i-=this.charReceived}t+=e.toString(this.encoding,0,i);var i=t.length-1;var n=t.charCodeAt(i);if(n>=55296&&n<=56319){var o=this.surrogateSize;this.charLength+=o;this.charReceived+=o;this.charBuffer.copy(this.charBuffer,o,0,o);e.copy(this.charBuffer,0,0,o);return t.substring(0,i)}return t};s.prototype.detectIncompleteChar=function(e){var t=e.length>=3?3:e.length;for(;t>0;t--){var r=e[e.length-t];if(t==1&&r>>5==6){this.charLength=2;break}if(t<=2&&r>>4==14){this.charLength=3;break}if(t<=3&&r>>3==30){this.charLength=4;break}}this.charReceived=t};s.prototype.end=function(e){var t="";if(e&&e.length)t=this.write(e);if(this.charReceived){var r=this.charReceived;var n=this.charBuffer;var i=this.encoding;t+=n.slice(0,r).toString(i)}return t};function a(e){return e.toString(this.encoding)}function f(e){this.charReceived=e.length%2;this.charLength=this.charReceived?2:0}function u(e){this.charReceived=e.length%3;this.charLength=this.charReceived?3:0}},{buffer:26}],107:[function(e,t,r){(function(e){t.exports=r;function r(e,t){if(n("noDeprecation")){return e}var r=false;function i(){if(!r){if(n("throwDeprecation")){throw new Error(t)}else if(n("traceDeprecation")){console.trace(t)}else{console.warn(t)}r=true}return e.apply(this,arguments)}return i}function n(t){try{if(!e.localStorage)return false}catch(r){return false}var n=e.localStorage[t];if(null==n)return false;return String(n).toLowerCase()==="true"}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],108:[function(e,t,r){t.exports=e("./lib/_stream_passthrough.js")},{"./lib/_stream_passthrough.js":99}],109:[function(e,t,r){var n=function(){try{return e("st"+"ream")}catch(t){}}();r=t.exports=e("./lib/_stream_readable.js");r.Stream=n||r;r.Readable=r;r.Writable=e("./lib/_stream_writable.js");r.Duplex=e("./lib/_stream_duplex.js");r.Transform=e("./lib/_stream_transform.js");r.PassThrough=e("./lib/_stream_passthrough.js")},{"./lib/_stream_duplex.js":98,"./lib/_stream_passthrough.js":99,"./lib/_stream_readable.js":100,"./lib/_stream_transform.js":101,"./lib/_stream_writable.js":102}],110:[function(e,t,r){t.exports=e("./lib/_stream_transform.js")},{"./lib/_stream_transform.js":101}],111:[function(e,t,r){t.exports=e("./lib/_stream_writable.js")},{"./lib/_stream_writable.js":102}],112:[function(e,t,r){(function(t){r.render=y;r.append=_;var n=r.mime=e("./lib/mime.json");var i=e("debug")("render-media");var o=e("is-ascii");var s=e("mediasource");var a=e("path");var f=e("stream-to-blob-url");var u=e("videostream");var c=[".mp4",".m4v",".m4a"];var l=[".mp4",".m4v",".webm"];var d=[".m4a",".mp3"];var h=l.concat(d);var p=[".wav",".aac",".ogg",".oga"];var m=[".jpg",".jpeg",".png",".gif",".bmp"];var v=[".css",".html",".js",".md",".pdf",".txt"];var g=typeof window!=="undefined"&&window.MediaSource;function y(e,t,r){k(e);if(typeof t==="string")t=document.querySelector(t);b(e,function(r){if(t.nodeName!==r.toUpperCase()){var n=a.extname(e.name).toLowerCase();throw new Error('Cannot render "'+n+'" inside a "'+t.nodeName.toLowerCase()+'" element, expected "'+r+'"')}return t},r)}function _(e,t,r){if(!r)r=function(){};k(e);if(typeof t==="string")t=document.querySelector(t);if(t&&(t.nodeName==="VIDEO"||t.nodeName==="AUDIO")){throw new Error("Invalid video/audio node argument. Argument must be root element that "+"video/audio tag will be appended to.")}b(e,function(e){if(e==="video"||e==="audio")return n(e);else return i(e)},function(e,t){if(e&&t)t.remove();r(e,t)});function n(e){var r=i(e);r.controls=true;r.autoplay=true;r.play();t.appendChild(r);return r}function i(e){var r=document.createElement(e);t.appendChild(r);return r}}function b(e,t,r){if(!r)r=function(){};var n=a.extname(e.name).toLowerCase();var f=0;var d;if(h.indexOf(n)>=0){y()}else if(p.indexOf(n)>=0){b()}else if(m.indexOf(n)>=0){k()}else if(v.indexOf(n)>=0){S()}else{I()}function y(){if(!g){return w(r,new Error("Video/audio streaming is not supported in your browser. You can still share "+"or download "+e.name+" (once it's fully downloaded). Use Chrome for "+"MediaSource support."))}var o=l.indexOf(n)>=0?"video":"audio";if(c.indexOf(n)>=0)a();else h();function a(){i("Use `videostream` package for "+e.name);y();d.addEventListener("error",m);d.addEventListener("playing",_);u(e,d)}function h(){i("Use MediaSource API for "+e.name);y();d.addEventListener("error",v);d.addEventListener("playing",_);var t=new s(d);var r=t.createWriteStream(x(e.name));e.createReadStream().pipe(r);if(f)d.currentTime=f}function p(){i("Use Blob URL for "+e.name);y();d.addEventListener("error",B);d.addEventListener("playing",_);E(e,function(e,t){if(e)return B(e);d.src=t;if(f)d.currentTime=f})}function m(e){i("videostream error: fallback to MediaSource API: %o",e.message||e);d.removeEventListener("error",m);d.removeEventListener("playing",_);h()}function v(e){i("MediaSource API error: fallback to Blob URL: %o",e.message||e);d.removeEventListener("error",v);d.removeEventListener("playing",_);p()}function y(){if(!d){d=t(o);d.addEventListener("progress",function(){f=d.currentTime})}}}function _(){d.removeEventListener("playing",_);r(null,d)}function b(){d=t("audio");E(e,function(e,t){if(e)return B(e);d.addEventListener("error",B);d.addEventListener("playing",_);d.src=t})}function k(){d=t("img");E(e,function(t,n){if(t)return B(t);d.src=n;d.alt=e.name;r(null,d)})}function S(){d=t("iframe");E(e,function(e,t){if(e)return B(e);d.src=t;if(n!==".pdf")d.sandbox="allow-forms allow-scripts";r(null,d)})}function I(){i('Unknown file extension "%s" - will attempt to render into iframe',n);var t="";e.createReadStream({start:0,end:1e3}).setEncoding("utf8").on("data",function(e){t+=e}).on("end",s).on("error",r);function s(){if(o(t)){i('File extension "%s" appears ascii, so will render.',n);S()}else{i('File extension "%s" appears non-ascii, will not render.',n);r(new Error('Unsupported file type "'+n+'": Cannot append to DOM'))}}}function B(t){t.message='Error rendering file "'+e.name+'": '+t.message;i(t.message);r(t)}}function w(e,r,n){t.nextTick(function(){e(r,n)})}function E(e,t){var r=a.extname(e.name).toLowerCase();f(e.createReadStream(),n[r],t)}function k(e){if(e==null){throw new Error("file cannot be null or undefined")}if(typeof e.name!=="string"){throw new Error("missing or invalid file.name property")}if(typeof e.createReadStream!=="function"){throw new Error("missing or invalid file.createReadStream property")}}function x(e){var t=a.extname(e).toLowerCase();return{".m4a":'audio/mp4; codecs="mp4a.40.5"',".m4v":'video/mp4; codecs="avc1.640029, mp4a.40.5"',".mp3":"audio/mpeg",".mp4":'video/mp4; codecs="avc1.640029, mp4a.40.5"',".webm":'video/webm; codecs="vorbis, vp8"'}[t]}}).call(this,e("_process"))},{"./lib/mime.json":113,_process:34,debug:71,"is-ascii":114,mediasource:115,path:33,"stream-to-blob-url":142,videostream:128}],113:[function(e,t,r){t.exports={".3gp":"video/3gpp",".aac":"audio/aac",".aif":"audio/x-aiff",".aiff":"audio/x-aiff",".atom":"application/atom+xml",".avi":"video/x-msvideo",".bmp":"image/bmp",".bz2":"application/x-bzip2",".conf":"text/plain",".css":"text/css",".csv":"text/csv",".diff":"text/x-diff",".doc":"application/msword",".flv":"video/x-flv",".gif":"image/gif",".gz":"application/x-gzip",".htm":"text/html",".html":"text/html",".ico":"image/vnd.microsoft.icon",".ics":"text/calendar",".iso":"application/octet-stream",".jar":"application/java-archive",".jpeg":"image/jpeg",".jpg":"image/jpeg",".js":"application/javascript",".json":"application/json",".less":"text/css",".log":"text/plain",".m3u":"audio/x-mpegurl",".m4a":"audio/mp4",".m4v":"video/mp4",".manifest":"text/cache-manifest",".markdown":"text/x-markdown",".mathml":"application/mathml+xml",".md":"text/x-markdown",".mid":"audio/midi",".midi":"audio/midi",".mov":"video/quicktime",".mp3":"audio/mpeg",".mp4":"video/mp4",".mp4v":"video/mp4",".mpeg":"video/mpeg",".mpg":"video/mpeg",".odp":"application/vnd.oasis.opendocument.presentation",".ods":"application/vnd.oasis.opendocument.spreadsheet",".odt":"application/vnd.oasis.opendocument.text",".oga":"audio/ogg",".ogg":"application/ogg",".pdf":"application/pdf",".png":"image/png",".pps":"application/vnd.ms-powerpoint",".ppt":"application/vnd.ms-powerpoint",".ps":"application/postscript",".psd":"image/vnd.adobe.photoshop",".qt":"video/quicktime",".rar":"application/x-rar-compressed",".rdf":"application/rdf+xml",".rss":"application/rss+xml",".rtf":"application/rtf",".svg":"image/svg+xml",".svgz":"image/svg+xml",".swf":"application/x-shockwave-flash",".tar":"application/x-tar",".tbz":"application/x-bzip-compressed-tar",".text":"text/plain",".tif":"image/tiff",".tiff":"image/tiff",".torrent":"application/x-bittorrent",".ttf":"application/x-font-ttf",".txt":"text/plain",".wav":"audio/wav",".webm":"video/webm",".wma":"audio/x-ms-wma",".wmv":"video/x-ms-wmv",".xls":"application/vnd.ms-excel",".xml":"application/xml",".yaml":"text/yaml",".yml":"text/yaml",".zip":"application/zip"}},{}],114:[function(e,t,r){var n=127;t.exports=function i(e){for(var t=0,r=e.length;t<r;++t){if(e.charCodeAt(t)>n)return false}return true}},{}],115:[function(e,t,r){t.exports=f;var n=e("inherits");var i=e("readable-stream");var o=e("to-arraybuffer");var s=typeof window!=="undefined"&&window.MediaSource;var a=60;function f(e,t){var r=this;if(!(r instanceof f))return new f(e,t);if(!s)throw new Error("web browser lacks MediaSource support");if(!t)t={};r._bufferDuration=t.bufferDuration||a;r._elem=e;r._mediaSource=new s;r._streams=[];r.detailedError=null;r._errorHandler=function(){r._elem.removeEventListener("error",r._errorHandler);var e=r._streams.slice();e.forEach(function(e){e.destroy(r._elem.error)})};r._elem.addEventListener("error",r._errorHandler);r._elem.src=window.URL.createObjectURL(r._mediaSource)}f.prototype.createWriteStream=function(e){var t=this;return new u(t,e)};f.prototype.error=function(e){var t=this;if(!t.detailedError){t.detailedError=e}try{t._mediaSource.endOfStream("decode")}catch(e){}};n(u,i.Writable);function u(e,t){var r=this;i.Writable.call(r);r._wrapper=e;r._elem=e._elem;r._mediaSource=e._mediaSource;r._allStreams=e._streams;r._allStreams.push(r);r._bufferDuration=e._bufferDuration;r._openHandler=r._onSourceOpen.bind(r,t);r._flowHandler=r._flow.bind(r);if(typeof t==="string"){if(r._mediaSource.readyState==="open"){r._createSourceBuffer(t)}else{r._mediaSource.addEventListener("sourceopen",r._openHandler)}}else if(t._sourceBuffer){t.destroy();r._sourceBuffer=t._sourceBuffer;r._sourceBuffer.addEventListener("updateend",r._flowHandler)}else{throw new Error("The argument to MediaElementWrapper.createWriteStream must be a string or a previous stream returned from that function")}r._elem.addEventListener("timeupdate",r._flowHandler);r.on("error",r._wrapper.error.bind(r._wrapper));r.on("finish",function(){if(r.destroyed)return;r._finished=true;if(r._allStreams.every(function(e){return e._finished})){try{r._mediaSource.endOfStream()}catch(e){}}})}u.prototype._onSourceOpen=function(e){var t=this;if(t.destroyed)return;t._mediaSource.removeEventListener("sourceopen",t._openHandler);t._createSourceBuffer(e)};u.prototype.destroy=function(e){var t=this;if(t.destroyed)return;t.destroyed=true;t._allStreams.splice(t._allStreams.indexOf(t),1);t._mediaSource.removeEventListener("sourceopen",t._openHandler);t._elem.removeEventListener("timeupdate",t._flowHandler);if(t._sourceBuffer){t._sourceBuffer.removeEventListener("updateend",t._flowHandler);if(t._mediaSource.readyState==="open"){t._sourceBuffer.abort()}}if(e)t.emit("error",e);t.emit("close")};u.prototype._createSourceBuffer=function(e){var t=this;if(t.destroyed)return;if(s.isTypeSupported(e)){t._sourceBuffer=t._mediaSource.addSourceBuffer(e);t._sourceBuffer.addEventListener("updateend",t._flowHandler);if(t._cb){var r=t._cb;t._cb=null;r()}}else{t.destroy(new Error("The provided type is not supported"))}};u.prototype._write=function(e,t,r){var n=this;if(n.destroyed)return;if(!n._sourceBuffer){n._cb=function(i){if(i)return r(i);n._write(e,t,r)};return}if(n._sourceBuffer.updating){return r(new Error("Cannot append buffer while source buffer updating"))}try{n._sourceBuffer.appendBuffer(o(e))}catch(i){n.destroy(i);return}n._cb=r};u.prototype._flow=function(){var e=this;if(e.destroyed||!e._sourceBuffer||e._sourceBuffer.updating){return}if(e._mediaSource.readyState==="open"){if(e._getBufferDuration()>e._bufferDuration){return}}if(e._cb){var t=e._cb;e._cb=null;t()}};var c=0;u.prototype._getBufferDuration=function(){var e=this;var t=e._sourceBuffer.buffered;var r=e._elem.currentTime;var n=-1;for(var i=0;i<t.length;i++){var o=t.start(i);var s=t.end(i)+c;if(o>r){break}else if(n>=0||r<=s){n=s}}var a=n-r;if(a<0){a=0}return a}},{inherits:79,"readable-stream":109,"to-arraybuffer":116}],116:[function(e,t,r){arguments[4][45][0].apply(r,arguments)},{buffer:26,dup:45}],117:[function(e,t,r){var n=e("binary-search");var i=e("events");var o=e("inherits");var s=e("mp4-stream");var a=e("mp4-box-encoding");var f=e("range-slice-stream");t.exports=u;function u(e){var t=this;i.call(t);t._tracks=[];t._fragmentSequence=1;t._file=e;t._decoder=null;t._findMoov(0)}o(u,i);u.prototype._findMoov=function(e){var t=this;if(t._decoder){t._decoder.destroy()}t._decoder=s.decode();var r=t._file.createReadStream({start:e});r.pipe(t._decoder);t._decoder.once("box",function(n){if(n.type==="moov"){t._decoder.decode(function(e){r.destroy();t._processMoov(e)})}else{r.destroy();t._findMoov(e+n.length)}})};function c(e,t){var r=this;r._entries=e;r._countName=t||"count";r._index=0;r._offset=0;r.value=r._entries[0]}c.prototype.inc=function(){var e=this;e._offset++;if(e._offset>=e._entries[e._index][e._countName]){e._index++;e._offset=0}e.value=e._entries[e._index]};u.prototype._processMoov=function(e){var t=this;var r=e.traks;t._tracks=[];var n=null;var i=null;t._hasVideo=false;t._hasAudio=false;for(var o=0;o<r.length;o++){var s=r[o];var a=s.mdia.minf.stbl;var f=a.stsd.entries[0];var u=s.mdia.hdlr.handlerType;var d;var h;if(u==="vide"&&f.type==="avc1"){ -if(t._hasVideo){continue}t._hasVideo=true;d="avc1";if(f.avcC){d+="."+f.avcC.mimeCodec}h='video/mp4; codecs="'+d+'"'}else if(u==="soun"&&f.type==="mp4a"){if(t._hasAudio){continue}t._hasAudio=true;d="mp4a";if(f.esds&&f.esds.mimeCodec){d+="."+f.esds.mimeCodec}h='audio/mp4; codecs="'+d+'"'}else{continue}var p=[];var m=0;var v=0;var g=0;var y=0;var _=0;var b=0;var w=new c(a.stts.entries);var E=null;if(a.ctts){E=new c(a.ctts.entries)}var k=0;while(true){var x=a.stsc.entries[_];var S=a.stsz.entries[m];var I=w.value.duration;var B=E?E.value.compositionOffset:0;var A=true;if(a.stss){A=a.stss.entries[k]===m+1}p.push({size:S,duration:I,dts:b,presentationOffset:B,sync:A,offset:y+a.stco.entries[g]});m++;if(m>=a.stsz.entries.length){break}v++;y+=S;if(v>=x.samplesPerChunk){v=0;y=0;g++;var C=a.stsc.entries[_+1];if(C&&g+1>=C.firstChunk){_++}}b+=I;w.inc();E&&E.inc();if(A){k++}}s.mdia.mdhd.duration=0;s.tkhd.duration=0;var T=x.sampleDescriptionId;var L={type:"moov",mvhd:e.mvhd,traks:[{tkhd:s.tkhd,mdia:{mdhd:s.mdia.mdhd,hdlr:s.mdia.hdlr,elng:s.mdia.elng,minf:{vmhd:s.mdia.minf.vmhd,smhd:s.mdia.minf.smhd,dinf:s.mdia.minf.dinf,stbl:{stsd:a.stsd,stts:l(),ctts:l(),stsc:l(),stsz:l(),stco:l(),stss:l()}}}}],mvex:{mehd:{fragmentDuration:e.mvhd.duration},trexs:[{trackId:s.tkhd.trackId,defaultSampleDescriptionIndex:T,defaultSampleDuration:0,defaultSampleSize:0,defaultSampleFlags:0}]}};t._tracks.push({trackId:s.tkhd.trackId,timeScale:s.mdia.mdhd.timeScale,samples:p,currSample:null,currTime:null,moov:L,mime:h})}e.mvhd.duration=0;t._ftyp={type:"ftyp",brand:"iso5",brandVersion:0,compatibleBrands:["iso5"]};var R=t._tracks.map(function(e){return{mime:e.mime}});t.emit("ready",R)};function l(){return{version:0,flags:0,entries:[]}}u.prototype.seek=function(e,t){var r=this;if(!r._tracks){throw new Error("Not ready yet; wait for 'ready' event")}if(r._fileStream){r._fileStream.destroy();r._fileStream=null}var n=-1;r._tracks.map(function(i,o){if(i.outStream){i.outStream.destroy()}if(i.inStream){i.inStream.destroy();i.inStream=null}var a=i.outStream=s.encode();var f=r._generateFragment(o,e);if(!f){return a.finalize()}if(n===-1||f.ranges[0].start<n){n=f.ranges[0].start}if(t){a.box(r._ftyp,function(e){if(e)return r.emit("error",e);if(a.destroyed)return;a.box(i.moov,function(e){if(e)return r.emit("error",e);u(f)})})}else{u(f)}function u(e){if(a.destroyed)return;a.box(e.moof,function(t){if(t)return r.emit("error",t);if(a.destroyed)return;var n=i.inStream.slice(e.ranges);n.pipe(a.mediaData(e.length,function(e){if(e)return r.emit("error",e);if(a.destroyed)return;var t=r._generateFragment(o);if(!t){return a.finalize()}u(t)}))})}});if(n>=0){var i=r._fileStream=r._file.createReadStream({start:n});r._tracks.forEach(function(e){e.inStream=new f(n);i.pipe(e.inStream)})}return r._tracks.map(function(e){return e.outStream})};u.prototype._findSampleBefore=function(e,t){var r=this;var i=r._tracks[e];var o=Math.floor(i.timeScale*t);var s=n(i.samples,o,function(e,t){var r=e.dts+e.presentationOffset;return r-t});if(s===-1){s=0}else if(s<0){s=-s-2}while(!i.samples[s].sync){s--}return s};var d=1;u.prototype._generateFragment=function(e,t){var r=this;var n=r._tracks[e];var i;if(t!==undefined){i=r._findSampleBefore(e,t)}else{i=n.currSample}if(i>=n.samples.length)return null;var o=n.samples[i].offset;var s=n.samples[i].dts;var a=0;var f=[];for(var u=i;u<n.samples.length;u++){var c=n.samples[u];if(c.sync&&c.dts-s>=n.timeScale*d){break}a+=c.size;var l=f.length-1;if(l<0||f[l].end!==c.offset){f.push({start:c.offset,end:c.offset+c.size})}else{f[l].end+=c.size}}n.currSample=u;return{moof:r._generateMoof(e,i,u),ranges:f,length:a}};u.prototype._generateMoof=function(e,t,r){var n=this;var i=n._tracks[e];var o=[];for(var s=t;s<r;s++){var f=i.samples[s];o.push({sampleDuration:f.duration,sampleSize:f.size,sampleFlags:f.sync?33554432:16842752,sampleCompositionTimeOffset:f.presentationOffset})}var u={type:"moof",mfhd:{sequenceNumber:n._fragmentSequence++},trafs:[{tfhd:{flags:131072,trackId:i.trackId},tfdt:{baseMediaDecodeTime:i.samples[t].dts},trun:{flags:3841,dataOffset:8,entries:o}}]};u.trafs[0].trun.dataOffset+=a.encodingLength(u);return u}},{"binary-search":118,events:30,inherits:79,"mp4-box-encoding":121,"mp4-stream":125,"range-slice-stream":127}],118:[function(e,t,r){t.exports=function(e,t,r,n,i){var o,s;if(n===undefined)n=0;else{n=n|0;if(n<0||n>=e.length)throw new RangeError("invalid lower bound")}if(i===undefined)i=e.length-1;else{i=i|0;if(i<n||i>=e.length)throw new RangeError("invalid upper bound")}while(n<=i){o=n+(i-n>>1);s=+r(e[o],t);if(s<0)n=o+1;else if(s>0)i=o-1;else return o}return~n}},{}],119:[function(e,t,r){(function(t){var n=e("./index");var i=e("./descriptor");var o=20828448e5;r.fullBoxes={};var s=["mvhd","tkhd","mdhd","vmhd","smhd","stsd","esds","stsz","stco","stss","stts","ctts","stsc","dref","elst","hdlr","mehd","trex","mfhd","tfhd","tfdt","trun"];s.forEach(function(e){r.fullBoxes[e]=true});r.ftyp={};r.ftyp.encode=function(e,n,i){n=n?n.slice(i):new t(r.ftyp.encodingLength(e));var o=e.compatibleBrands||[];n.write(e.brand,0,4,"ascii");n.writeUInt32BE(e.brandVersion,4);for(var s=0;s<o.length;s++)n.write(o[s],8+s*4,4,"ascii");r.ftyp.encode.bytes=8+o.length*4;return n};r.ftyp.decode=function(e,t){e=e.slice(t);var r=e.toString("ascii",0,4);var n=e.readUInt32BE(4);var i=[];for(var o=8;o<e.length;o+=4)i.push(e.toString("ascii",o,o+4));return{brand:r,brandVersion:n,compatibleBrands:i}};r.ftyp.encodingLength=function(e){return 8+(e.compatibleBrands||[]).length*4};r.mvhd={};r.mvhd.encode=function(e,n,i){n=n?n.slice(i):new t(96);f(e.ctime||new Date,n,0);f(e.mtime||new Date,n,4);n.writeUInt32BE(e.timeScale||0,8);n.writeUInt32BE(e.duration||0,12);u(e.preferredRate||0,n,16);c(e.preferredVolume||0,n,20);a(n,22,32);l(e.matrix,n,32);n.writeUInt32BE(e.previewTime||0,68);n.writeUInt32BE(e.previewDuration||0,72);n.writeUInt32BE(e.posterTime||0,76);n.writeUInt32BE(e.selectionTime||0,80);n.writeUInt32BE(e.selectionDuration||0,84);n.writeUInt32BE(e.currentTime||0,88);n.writeUInt32BE(e.nextTrackId||0,92);r.mvhd.encode.bytes=96;return n};r.mvhd.decode=function(e,t){e=e.slice(t);return{ctime:p(e,0),mtime:p(e,4),timeScale:e.readUInt32BE(8),duration:e.readUInt32BE(12),preferredRate:m(e,16),preferredVolume:v(e,20),matrix:h(e.slice(32,68)),previewTime:e.readUInt32BE(68),previewDuration:e.readUInt32BE(72),posterTime:e.readUInt32BE(76),selectionTime:e.readUInt32BE(80),selectionDuration:e.readUInt32BE(84),currentTime:e.readUInt32BE(88),nextTrackId:e.readUInt32BE(92)}};r.mvhd.encodingLength=function(e){return 96};r.tkhd={};r.tkhd.encode=function(e,n,i){n=n?n.slice(i):new t(80);f(e.ctime||new Date,n,0);f(e.mtime||new Date,n,4);n.writeUInt32BE(e.trackId||0,8);a(n,12,16);n.writeUInt32BE(e.duration||0,16);a(n,20,28);n.writeUInt16BE(e.layer||0,28);n.writeUInt16BE(e.alternateGroup||0,30);n.writeUInt16BE(e.volume||0,32);l(e.matrix,n,36);n.writeUInt32BE(e.trackWidth||0,72);n.writeUInt32BE(e.trackHeight||0,76);r.tkhd.encode.bytes=80;return n};r.tkhd.decode=function(e,t){e=e.slice(t);return{ctime:p(e,0),mtime:p(e,4),trackId:e.readUInt32BE(8),duration:e.readUInt32BE(16),layer:e.readUInt16BE(28),alternateGroup:e.readUInt16BE(30),volume:e.readUInt16BE(32),matrix:h(e.slice(36,72)),trackWidth:e.readUInt32BE(72),trackHeight:e.readUInt32BE(76)}};r.tkhd.encodingLength=function(e){return 80};r.mdhd={};r.mdhd.encode=function(e,n,i){n=n?n.slice(i):new t(20);f(e.ctime||new Date,n,0);f(e.mtime||new Date,n,4);n.writeUInt32BE(e.timeScale||0,8);n.writeUInt32BE(e.duration||0,12);n.writeUInt16BE(e.language||0,16);n.writeUInt16BE(e.quality||0,18);r.mdhd.encode.bytes=20;return n};r.mdhd.decode=function(e,t){e=e.slice(t);return{ctime:p(e,0),mtime:p(e,4),timeScale:e.readUInt32BE(8),duration:e.readUInt32BE(12),language:e.readUInt16BE(16),quality:e.readUInt16BE(18)}};r.mdhd.encodingLength=function(e){return 20};r.vmhd={};r.vmhd.encode=function(e,n,i){n=n?n.slice(i):new t(8);n.writeUInt16BE(e.graphicsMode||0,0);var o=e.opcolor||[0,0,0];n.writeUInt16BE(o[0],2);n.writeUInt16BE(o[1],4);n.writeUInt16BE(o[2],6);r.vmhd.encode.bytes=8;return n};r.vmhd.decode=function(e,t){e=e.slice(t);return{graphicsMode:e.readUInt16BE(0),opcolor:[e.readUInt16BE(2),e.readUInt16BE(4),e.readUInt16BE(6)]}};r.vmhd.encodingLength=function(e){return 8};r.smhd={};r.smhd.encode=function(e,n,i){n=n?n.slice(i):new t(4);n.writeUInt16BE(e.balance||0,0);a(n,2,4);r.smhd.encode.bytes=4;return n};r.smhd.decode=function(e,t){e=e.slice(t);return{balance:e.readUInt16BE(0)}};r.smhd.encodingLength=function(e){return 4};r.stsd={};r.stsd.encode=function(e,i,o){i=i?i.slice(o):new t(r.stsd.encodingLength(e));var s=e.entries||[];i.writeUInt32BE(s.length,0);var a=4;for(var f=0;f<s.length;f++){var u=s[f];n.encode(u,i,a);a+=n.encode.bytes}r.stsd.encode.bytes=a;return i};r.stsd.decode=function(e,t,r){e=e.slice(t);var i=e.readUInt32BE(0);var o=new Array(i);var s=4;for(var a=0;a<i;a++){var f=n.decode(e,s,r);o[a]=f;s+=f.length}return{entries:o}};r.stsd.encodingLength=function(e){var t=4;if(!e.entries)return t;for(var r=0;r<e.entries.length;r++){t+=n.encodingLength(e.entries[r])}return t};r.avc1=r.VisualSampleEntry={};r.VisualSampleEntry.encode=function(e,i,o){i=i?i.slice(o):new t(r.VisualSampleEntry.encodingLength(e));a(i,0,6);i.writeUInt16BE(e.dataReferenceIndex||0,6);a(i,8,24);i.writeUInt16BE(e.width||0,24);i.writeUInt16BE(e.height||0,26);i.writeUInt32BE(e.hResolution||4718592,28);i.writeUInt32BE(e.vResolution||4718592,32);a(i,36,40);i.writeUInt16BE(e.frameCount||1,40);var s=e.compressorName||"";var f=Math.min(s.length,31);i.writeUInt8(f,42);i.write(s,43,f,"utf8");i.writeUInt16BE(e.depth||24,74);i.writeInt16BE(-1,76);var u=78;var c=e.children||[];c.forEach(function(e){n.encode(e,i,u);u+=n.encode.bytes});r.VisualSampleEntry.encode.bytes=u};r.VisualSampleEntry.decode=function(e,t,r){e=e.slice(t);var i=r-t;var o=Math.min(e.readUInt8(42),31);var s={dataReferenceIndex:e.readUInt16BE(6),width:e.readUInt16BE(24),height:e.readUInt16BE(26),hResolution:e.readUInt32BE(28),vResolution:e.readUInt32BE(32),frameCount:e.readUInt16BE(40),compressorName:e.toString("utf8",43,43+o),depth:e.readUInt16BE(74),children:[]};var a=78;while(i-a>=8){var f=n.decode(e,a,i);s.children.push(f);s[f.type]=f;a+=f.length}return s};r.VisualSampleEntry.encodingLength=function(e){var t=78;var r=e.children||[];r.forEach(function(e){t+=n.encodingLength(e)});return t};r.avcC={};r.avcC.encode=function(e,n,i){n=n?n.slice(i):t(e.buffer.length);e.buffer.copy(n);r.avcC.encode.bytes=e.buffer.length};r.avcC.decode=function(e,r,n){e=e.slice(r,n);return{mimeCodec:e.toString("hex",1,4),buffer:new t(e)}};r.avcC.encodingLength=function(e){return e.buffer.length};r.mp4a=r.AudioSampleEntry={};r.AudioSampleEntry.encode=function(e,i,o){i=i?i.slice(o):new t(r.AudioSampleEntry.encodingLength(e));a(i,0,6);i.writeUInt16BE(e.dataReferenceIndex||0,6);a(i,8,16);i.writeUInt16BE(e.channelCount||2,16);i.writeUInt16BE(e.sampleSize||16,18);a(i,20,24);i.writeUInt32BE(e.sampleRate||0,24);var s=28;var f=e.children||[];f.forEach(function(e){n.encode(e,i,s);s+=n.encode.bytes});r.AudioSampleEntry.encode.bytes=s};r.AudioSampleEntry.decode=function(e,t,r){e=e.slice(t,r);var i=r-t;var o={dataReferenceIndex:e.readUInt16BE(6),channelCount:e.readUInt16BE(16),sampleSize:e.readUInt16BE(18),sampleRate:e.readUInt32BE(24),children:[]};var s=28;while(i-s>=8){var a=n.decode(e,s,i);o.children.push(a);o[a.type]=a;s+=a.length}return o};r.AudioSampleEntry.encodingLength=function(e){var t=28;var r=e.children||[];r.forEach(function(e){t+=n.encodingLength(e)});return t};r.esds={};r.esds.encode=function(e,n,i){n=n?n.slice(i):t(e.buffer.length);e.buffer.copy(n,0);r.esds.encode.bytes=e.buffer.length};r.esds.decode=function(e,r,n){e=e.slice(r,n);var o=i.Descriptor.decode(e,0,e.length);var s=o.tagName==="ESDescriptor"?o:{};var a=s.DecoderConfigDescriptor||{};var f=a.oti||0;var u=a.DecoderSpecificInfo||{};var c=u?(u.buffer.readUInt8(0)&248)>>3:0;var l=null;if(f){l=f.toString(16);if(c){l+="."+c}}return{mimeCodec:l,buffer:new t(e.slice(0))}};r.esds.encodingLength=function(e){return e.buffer.length};r.stsz={};r.stsz.encode=function(e,n,i){var o=e.entries||[];n=n?n.slice(i):t(r.stsz.encodingLength(e));n.writeUInt32BE(0,0);n.writeUInt32BE(o.length,4);for(var s=0;s<o.length;s++){n.writeUInt32BE(o[s],s*4+8)}r.stsz.encode.bytes=8+o.length*4;return n};r.stsz.decode=function(e,t){e=e.slice(t);var r=e.readUInt32BE(0);var n=e.readUInt32BE(4);var i=new Array(n);for(var o=0;o<n;o++){if(r===0){i[o]=e.readUInt32BE(o*4+8)}else{i[o]=r}}return{entries:i}};r.stsz.encodingLength=function(e){return 8+e.entries.length*4};r.stss=r.stco={};r.stco.encode=function(e,n,i){var o=e.entries||[];n=n?n.slice(i):new t(r.stco.encodingLength(e));n.writeUInt32BE(o.length,0);for(var s=0;s<o.length;s++){n.writeUInt32BE(o[s],s*4+4)}r.stco.encode.bytes=4+o.length*4;return n};r.stco.decode=function(e,t){e=e.slice(t);var r=e.readUInt32BE(0);var n=new Array(r);for(var i=0;i<r;i++){n[i]=e.readUInt32BE(i*4+4)}return{entries:n}};r.stco.encodingLength=function(e){return 4+e.entries.length*4};r.stts={};r.stts.encode=function(e,n,i){var o=e.entries||[];n=n?n.slice(i):new t(r.stts.encodingLength(e));n.writeUInt32BE(o.length,0);for(var s=0;s<o.length;s++){var a=s*8+4;n.writeUInt32BE(o[s].count||0,a);n.writeUInt32BE(o[s].duration||0,a+4)}r.stts.encode.bytes=4+e.entries.length*8;return n};r.stts.decode=function(e,t){e=e.slice(t);var r=e.readUInt32BE(0);var n=new Array(r);for(var i=0;i<r;i++){var o=i*8+4;n[i]={count:e.readUInt32BE(o),duration:e.readUInt32BE(o+4)}}return{entries:n}};r.stts.encodingLength=function(e){return 4+e.entries.length*8};r.ctts={};r.ctts.encode=function(e,n,i){var o=e.entries||[];n=n?n.slice(i):new t(r.ctts.encodingLength(e));n.writeUInt32BE(o.length,0);for(var s=0;s<o.length;s++){var a=s*8+4;n.writeUInt32BE(o[s].count||0,a);n.writeUInt32BE(o[s].compositionOffset||0,a+4)}r.ctts.encode.bytes=4+o.length*8;return n};r.ctts.decode=function(e,t){e=e.slice(t);var r=e.readUInt32BE(0);var n=new Array(r);for(var i=0;i<r;i++){var o=i*8+4;n[i]={count:e.readUInt32BE(o),compositionOffset:e.readInt32BE(o+4)}}return{entries:n}};r.ctts.encodingLength=function(e){return 4+e.entries.length*8};r.stsc={};r.stsc.encode=function(e,n,i){var o=e.entries||[];n=n?n.slice(i):new t(r.stsc.encodingLength(e));n.writeUInt32BE(o.length,0);for(var s=0;s<o.length;s++){var a=s*12+4;n.writeUInt32BE(o[s].firstChunk||0,a);n.writeUInt32BE(o[s].samplesPerChunk||0,a+4);n.writeUInt32BE(o[s].sampleDescriptionId||0,a+8)}r.stsc.encode.bytes=4+o.length*12;return n};r.stsc.decode=function(e,t){e=e.slice(t);var r=e.readUInt32BE(0);var n=new Array(r);for(var i=0;i<r;i++){var o=i*12+4;n[i]={firstChunk:e.readUInt32BE(o),samplesPerChunk:e.readUInt32BE(o+4),sampleDescriptionId:e.readUInt32BE(o+8)}}return{entries:n}};r.stsc.encodingLength=function(e){return 4+e.entries.length*12};r.dref={};r.dref.encode=function(e,n,i){n=n?n.slice(i):new t(r.dref.encodingLength(e));var o=e.entries||[];n.writeUInt32BE(o.length,0);var s=4;for(var a=0;a<o.length;a++){var f=o[a];var u=(f.buf?f.buf.length:0)+4+4;n.writeUInt32BE(u,s);s+=4;n.write(f.type,s,4,"ascii");s+=4;if(f.buf){f.buf.copy(n,s);s+=f.buf.length}}r.dref.encode.bytes=s;return n};r.dref.decode=function(e,t){e=e.slice(t);var r=e.readUInt32BE(0);var n=new Array(r);var i=4;for(var o=0;o<r;o++){var s=e.readUInt32BE(i);var a=e.toString("ascii",i+4,i+8);var f=e.slice(i+8,i+s);i+=s;n[o]={type:a,buf:f}}return{entries:n}};r.dref.encodingLength=function(e){var t=4;if(!e.entries)return t;for(var r=0;r<e.entries.length;r++){var n=e.entries[r].buf;t+=(n?n.length:0)+4+4}return t};r.elst={};r.elst.encode=function(e,n,i){var o=e.entries||[];n=n?n.slice(i):new t(r.elst.encodingLength(e));n.writeUInt32BE(o.length,0);for(var s=0;s<o.length;s++){var a=s*12+4;n.writeUInt32BE(o[s].trackDuration||0,a);n.writeUInt32BE(o[s].mediaTime||0,a+4);u(o[s].mediaRate||0,n,a+8)}r.elst.encode.bytes=4+o.length*12;return n};r.elst.decode=function(e,t){e=e.slice(t);var r=e.readUInt32BE(0);var n=new Array(r);for(var i=0;i<r;i++){var o=i*12+4;n[i]={trackDuration:e.readUInt32BE(o),mediaTime:e.readInt32BE(o+4),mediaRate:m(e,o+8)}}return{entries:n}};r.elst.encodingLength=function(e){return 4+e.entries.length*12};r.hdlr={};r.hdlr.encode=function(e,n,i){n=n?n.slice(i):new t(r.hdlr.encodingLength(e));var o=21+(e.name||"").length;n.fill(0,0,o);n.write(e.handlerType||"",4,4,"ascii");d(e.name||"",n,20);r.hdlr.encode.bytes=o;return n};r.hdlr.decode=function(e,t,r){e=e.slice(t);return{handlerType:e.toString("ascii",4,8),name:g(e,20,r)}};r.hdlr.encodingLength=function(e){return 21+(e.name||"").length};r.mehd={};r.mehd.encode=function(e,n,i){n=n?n.slice(i):new t(4);n.writeUInt32BE(e.fragmentDuration||0,0);r.mehd.encode.bytes=4;return n};r.mehd.decode=function(e,t){e=e.slice(t);return{fragmentDuration:e.readUInt32BE(0)}};r.mehd.encodingLength=function(e){return 4};r.trex={};r.trex.encode=function(e,n,i){n=n?n.slice(i):new t(20);n.writeUInt32BE(e.trackId||0,0);n.writeUInt32BE(e.defaultSampleDescriptionIndex||0,4);n.writeUInt32BE(e.defaultSampleDuration||0,8);n.writeUInt32BE(e.defaultSampleSize||0,12);n.writeUInt32BE(e.defaultSampleFlags||0,16);r.trex.encode.bytes=20;return n};r.trex.decode=function(e,t){e=e.slice(t);return{trackId:e.readUInt32BE(0),defaultSampleDescriptionIndex:e.readUInt32BE(4),defaultSampleDuration:e.readUInt32BE(8),defaultSampleSize:e.readUInt32BE(12),defaultSampleFlags:e.readUInt32BE(16)}};r.trex.encodingLength=function(e){return 20};r.mfhd={};r.mfhd.encode=function(e,n,i){n=n?n.slice(i):new t(4);n.writeUInt32BE(e.sequenceNumber||0,0);r.mfhd.encode.bytes=4;return n};r.mfhd.decode=function(e,t){return{sequenceNumber:e.readUint32BE(0)}};r.mfhd.encodingLength=function(e){return 4};r.tfhd={};r.tfhd.encode=function(e,n,i){n=n?n.slice(i):new t(4);n.writeUInt32BE(e.trackId,0);r.tfhd.encode.bytes=4;return n};r.tfhd.decode=function(e,t){};r.tfhd.encodingLength=function(e){return 4};r.tfdt={};r.tfdt.encode=function(e,n,i){n=n?n.slice(i):new t(4);n.writeUInt32BE(e.baseMediaDecodeTime||0,0);r.tfdt.encode.bytes=4;return n};r.tfdt.decode=function(e,t){};r.tfdt.encodingLength=function(e){return 4};r.trun={};r.trun.encode=function(e,n,i){n=n?n.slice(i):new t(8+e.entries.length*16);n.writeUInt32BE(e.entries.length,0);n.writeInt32BE(e.dataOffset,4);var o=8;for(var s=0;s<e.entries.length;s++){var a=e.entries[s];n.writeUInt32BE(a.sampleDuration,o);o+=4;n.writeUInt32BE(a.sampleSize,o);o+=4;n.writeUInt32BE(a.sampleFlags,o);o+=4;n.writeUInt32BE(a.sampleCompositionTimeOffset,o);o+=4}r.trun.encode.bytes=o};r.trun.decode=function(e,t){};r.trun.encodingLength=function(e){return 8+e.entries.length*16};r.mdat={};r.mdat.encode=function(e,t,n){if(e.buffer){e.buffer.copy(t,n);r.mdat.encode.bytes=e.buffer.length}else{r.mdat.encode.bytes=r.mdat.encodingLength(e)}};r.mdat.decode=function(e,r,n){return{buffer:new t(e.slice(r,n))}};r.mdat.encodingLength=function(e){return e.buffer?e.buffer.length:e.contentLength};function a(e,t,r){for(var n=t;n<r;n++)e[n]=0}function f(e,t,r){t.writeUInt32BE(Math.floor((e.getTime()+o)/1e3),r)}function u(e,t,r){t.writeUInt16BE(Math.floor(e)%(256*256),r);t.writeUInt16BE(Math.floor(e*256*256)%(256*256),r+2)}function c(e,t,r){t[r]=Math.floor(e)%256;t[r+1]=Math.floor(e*256)%256}function l(e,t,r){if(!e)e=[0,0,0,0,0,0,0,0,0];for(var n=0;n<e.length;n++){u(e[n],t,r+n*4)}}function d(e,r,n){var i=new t(e,"utf8");i.copy(r,n);r[n+i.length]=0}function h(e){var t=new Array(e.length/4);for(var r=0;r<t.length;r++)t[r]=m(e,r*4);return t}function p(e,t){return new Date(e.readUInt32BE(t)*1e3-o)}function m(e,t){return e.readUInt16BE(t)+e.readUInt16BE(t+2)/(256*256)}function v(e,t){return e[t]+e[t+1]/256}function g(e,t,r){var n;for(n=0;n<r;n++){if(e[t+n]===0){break}}return e.toString("utf8",t,t+n)}}).call(this,e("buffer").Buffer)},{"./descriptor":120,"./index":121,buffer:26}],120:[function(e,t,r){(function(e){var t={3:"ESDescriptor",4:"DecoderConfigDescriptor",5:"DecoderSpecificInfo",6:"SLConfigDescriptor"};r.Descriptor={};r.Descriptor.decode=function(n,i,o){var s=n.readUInt8(i);var a=i+1;var f;var u=0;do{f=n.readUInt8(a++);u=u<<7|f&127}while(f&128);var c;var l=t[s];if(r[l]){c=r[l].decode(n,a,o)}else{c={buffer:new e(n.slice(a,a+u))}}c.tag=s;c.tagName=l;c.length=a-i+u;c.contentsLen=u;return c};r.DescriptorArray={};r.DescriptorArray.decode=function(e,n,i){var o=n;var s={};while(o+2<=i){var a=r.Descriptor.decode(e,o,i);o+=a.length;var f=t[a.tag]||"Descriptor"+a.tag;s[f]=a}return s};r.ESDescriptor={};r.ESDescriptor.decode=function(e,t,n){var i=e.readUInt8(t+2);var o=t+3;if(i&128){o+=2}if(i&64){var s=e.readUInt8(o);o+=s+1}if(i&32){o+=2}return r.DescriptorArray.decode(e,o,n)};r.DecoderConfigDescriptor={};r.DecoderConfigDescriptor.decode=function(e,t,n){var i=e.readUInt8(t);var o=r.DescriptorArray.decode(e,t+13,n);o.oti=i;return o}}).call(this,e("buffer").Buffer)},{buffer:26}],121:[function(e,t,r){(function(t){var n=e("uint64be");var i=e("./boxes");var o=4294967295;var s=r;var a=r.containers={moov:["mvhd","meta","traks","mvex"],trak:["tkhd","tref","trgr","edts","meta","mdia","udta"],edts:["elst"],mdia:["mdhd","hdlr","elng","minf"],minf:["vmhd","smhd","hmhd","sthd","nmhd","dinf","stbl"],dinf:["dref"],stbl:["stsd","stts","ctts","cslg","stsc","stsz","stz2","stco","co64","stss","stsh","padb","stdp","sdtp","sbgps","sgpds","subss","saizs","saios"],mvex:["mehd","trexs","leva"],moof:["mfhd","meta","trafs"],traf:["tfhd","trun","sbgps","sgpds","subss","saizs","saios","tfdt","meta"]};s.encode=function(e,r,n){s.encodingLength(e);n=n||0;r=r||new t(e.length);return s._encode(e,r,n)};s._encode=function(e,t,r){var f=e.type;var u=e.length;if(u>o){u=1}t.writeUInt32BE(u,r);t.write(e.type,r+4,4,"ascii");var c=r+8;if(u===1){n.encode(e.length,t,c);c+=8}if(i.fullBoxes[f]){t.writeUInt32BE(e.flags||0,c);t.writeUInt8(e.version||0,c);c+=4}if(a[f]){var l=a[f];l.forEach(function(r){if(r.length===5){var n=e[r]||[];r=r.substr(0,4);n.forEach(function(e){s._encode(e,t,c);c+=s.encode.bytes})}else if(e[r]){s._encode(e[r],t,c);c+=s.encode.bytes}});if(e.otherBoxes){e.otherBoxes.forEach(function(e){s._encode(e,t,c);c+=s.encode.bytes})}}else if(i[f]){var d=i[f].encode;d(e,t,c);c+=d.bytes}else if(e.buffer){var h=e.buffer;h.copy(t,c);c+=e.buffer.length}else{throw new Error("Either `type` must be set to a known type (not'"+f+"') or `buffer` must be set")}s.encode.bytes=c-r;return t};s.readHeaders=function(e,t,r){t=t||0;r=r||e.length;if(r-t<8){return 8}var o=e.readUInt32BE(t);var s=e.toString("ascii",t+4,t+8);var a=t+8;if(o===1){if(r-t<16){return 16}o=n.decode(e,a);a+=8}var f;var u;if(i.fullBoxes[s]){f=e.readUInt8(a);u=e.readUInt32BE(a)&16777215;a+=4}return{length:o,headersLen:a-t,contentLen:o-(a-t),type:s,version:f,flags:u}};s.decode=function(e,t,r){t=t||0;r=r||e.length;var n=s.readHeaders(e,t,r);if(!n||n.length>r-t){throw new Error("Data too short")}return s.decodeWithoutHeaders(n,e,t+n.headersLen,t+n.length)};s.decodeWithoutHeaders=function(e,r,n,o){n=n||0;o=o||r.length;var f=e.type;var u={};if(a[f]){u.otherBoxes=[];var c=a[f];var l=n;while(o-l>=8){var d=s.decode(r,l,o);l+=d.length;if(c.indexOf(d.type)>=0){u[d.type]=d}else if(c.indexOf(d.type+"s")>=0){var h=d.type+"s";var p=u[h]=u[h]||[];p.push(d)}else{u.otherBoxes.push(d)}}}else if(i[f]){var m=i[f].decode;u=m(r,n,o)}else{u.buffer=new t(r.slice(n,o))}u.length=e.length;u.contentLen=e.contentLen;u.type=e.type;u.version=e.version;u.flags=e.flags;return u};s.encodingLength=function(e){var t=e.type;var r=8;if(i.fullBoxes[t]){r+=4}if(a[t]){var n=a[t];n.forEach(function(t){if(t.length===5){var n=e[t]||[];t=t.substr(0,4);n.forEach(function(e){e.type=t;r+=s.encodingLength(e)})}else if(e[t]){var i=e[t];i.type=t;r+=s.encodingLength(i)}});if(e.otherBoxes){e.otherBoxes.forEach(function(e){r+=s.encodingLength(e)})}}else if(i[t]){r+=i[t].encodingLength(e)}else if(e.buffer){r+=e.buffer.length}else{throw new Error("Either `type` must be set to a known type (not'"+t+"') or `buffer` must be set")}if(r>o){r+=8}e.length=r;return r}}).call(this,e("buffer").Buffer)},{"./boxes":119,buffer:26,uint64be:122}],122:[function(e,t,r){(function(e){var t=4294967295;r.encodingLength=function(){return 8};r.encode=function(r,n,i){if(!n)n=new e(8);if(!i)i=0;var o=Math.floor(r/t);var s=r-o*t;n.writeUInt32BE(o,i);n.writeUInt32BE(s,i+4);return n};r.decode=function(r,n){if(!n)n=0;if(!r)r=new e(4);if(!n)n=0;var i=r.readUInt32BE(n);var o=r.readUInt32BE(n+4);return i*t+o};r.encode.bytes=8;r.decode.bytes=8}).call(this,e("buffer").Buffer)},{buffer:26}],123:[function(e,t,r){(function(r){var n=e("readable-stream");var i=e("util");var o=e("next-event");var s=e("mp4-box-encoding");var a=new r(0);t.exports=f;function f(){if(!(this instanceof f))return new f;n.Writable.call(this);this.destroyed=false;this._pending=0;this._missing=0;this._buf=null;this._str=null;this._cb=null;this._ondrain=null;this._writeBuffer=null;this._writeCb=null;this._ondrain=null;this._kick()}i.inherits(f,n.Writable);f.prototype.destroy=function(e){if(this.destroyed)return;this.destroyed=true;if(e)this.emit("error",e);this.emit("close")};f.prototype._write=function(e,t,r){if(this.destroyed)return;var n=!this._str||!this._str._writableState.needDrain;while(e.length&&!this.destroyed){if(!this._missing){this._writeBuffer=e;this._writeCb=r;return}var i=e.length<this._missing?e.length:this._missing;if(this._buf)e.copy(this._buf,this._buf.length-this._missing);else if(this._str)n=this._str.write(i===e.length?e:e.slice(0,i));this._missing-=i;if(!this._missing){var o=this._buf;var s=this._cb;var f=this._str;this._buf=this._cb=this._str=this._ondrain=null;n=true;if(f)f.end();if(s)s(o)}e=i===e.length?a:e.slice(i)}if(this._pending&&!this._missing){this._writeBuffer=e;this._writeCb=r;return}if(n)r();else this._ondrain(r)};f.prototype._buffer=function(e,t){this._missing=e;this._buf=new r(e);this._cb=t};f.prototype._stream=function(e,t){var r=this;this._missing=e;this._str=new u(this);this._ondrain=o(this._str,"drain");this._pending++;this._str.on("end",function(){r._pending--;r._kick()});this._cb=t;return this._str};f.prototype._readBox=function(){var e=this;t(8);function t(n,i){e._buffer(n,function(n){if(i){i=r.concat(i,n)}else{i=n}var o=s.readHeaders(i);if(typeof o==="number"){t(o-i.length,i)}else{e._pending++;e._headers=o;e.emit("box",o)}})}};f.prototype.stream=function(){var e=this;if(!e._headers)throw new Error("this function can only be called once after 'box' is emitted");var t=e._headers;e._headers=null;return e._stream(t.contentLen,null)};f.prototype.decode=function(e){var t=this;if(!t._headers)throw new Error("this function can only be called once after 'box' is emitted");var r=t._headers;t._headers=null;t._buffer(r.contentLen,function(n){var i=s.decodeWithoutHeaders(r,n);e(i);t._pending--;t._kick()})};f.prototype.ignore=function(){var e=this;if(!e._headers)throw new Error("this function can only be called once after 'box' is emitted");var t=e._headers;e._headers=null;this._missing=t.contentLen;this._cb=function(){e._pending--;e._kick()}};f.prototype._kick=function(){if(this._pending)return;if(!this._buf&&!this._str)this._readBox();if(this._writeBuffer){var e=this._writeCb;var t=this._writeBuffer;this._writeBuffer=null;this._writeCb=null;this._write(t,null,e)}};function u(e){this._parent=e;this.destroyed=false;n.PassThrough.call(this)}i.inherits(u,n.PassThrough);u.prototype.destroy=function(e){if(this.destroyed)return;this.destroyed=true;this._parent.destroy(e);if(e)this.emit("error",e);this.emit("close")}}).call(this,e("buffer").Buffer)},{buffer:26,"mp4-box-encoding":121,"next-event":126,"readable-stream":109,util:49}],124:[function(e,t,r){(function(r,n){var i=e("readable-stream");var o=e("util");var s=e("mp4-box-encoding");t.exports=f;function a(){}function f(){if(!(this instanceof f))return new f;i.Readable.call(this);this.destroyed=false;this._reading=false;this._stream=null;this._drain=null;this._want=false;this._onreadable=t;this._onend=r;var e=this;function t(){if(!e._want)return;e._want=false;e._read()}function r(){e._stream=null}}o.inherits(f,i.Readable);f.prototype.mediaData=f.prototype.mdat=function(e,t){var r=new u(this);this.box({type:"mdat",contentLength:e,encodeBufferLen:8,stream:r},t);return r};f.prototype.box=function(e,t){if(!t)t=a;if(this.destroyed)return t(new Error("Encoder is destroyed"));var i;if(e.encodeBufferLen){i=new n(e.encodeBufferLen)}if(e.stream){e.buffer=null;i=s.encode(e,i);this.push(i);this._stream=e.stream;this._stream.on("readable",this._onreadable);this._stream.on("end",this._onend);this._stream.on("end",t);this._forward()}else{i=s.encode(e,i);var o=this.push(i);if(o)return r.nextTick(t);this._drain=t}};f.prototype.destroy=function(e){if(this.destroyed)return;this.destroyed=true;if(this._stream&&this._stream.destroy)this._stream.destroy();this._stream=null;if(this._drain){var t=this._drain;this._drain=null;t(e)}if(e)this.emit("error",e);this.emit("close")};f.prototype.finalize=function(){this.push(null)};f.prototype._forward=function(){if(!this._stream)return;while(!this.destroyed){var e=this._stream.read();if(!e){this._want=!!this._stream;return}if(!this.push(e))return}};f.prototype._read=function(){if(this._reading||this.destroyed)return;this._reading=true;if(this._stream)this._forward();if(this._drain){var e=this._drain;this._drain=null;e()}this._reading=false};function u(e){this._parent=e;this.destroyed=false;i.PassThrough.call(this)}o.inherits(u,i.PassThrough);u.prototype.destroy=function(e){if(this.destroyed)return;this.destroyed=true;this._parent.destroy(e);if(e)this.emit("error",e);this.emit("close")}}).call(this,e("_process"),e("buffer").Buffer)},{_process:34,buffer:26,"mp4-box-encoding":121,"readable-stream":109,util:49}],125:[function(e,t,r){r.decode=e("./decode");r.encode=e("./encode")},{"./decode":123,"./encode":124}],126:[function(e,t,r){t.exports=n;function n(e,t){var r=null;e.on(t,function(e){if(!r)return;var t=r;r=null;t(e)});return function(e){r=e}}},{}],127:[function(e,t,r){var n=e("inherits");var i=e("stream");t.exports=o;n(o,i.Writable);function o(e){var t=this;if(!(t instanceof o))return new o(e);i.Writable.call(t);t.destroyed=false;t._queue=[];t._position=e||0;t._cb=null;t._buffer=null;t._out=null}o.prototype._write=function(e,t,r){var n=this;var i=true;while(true){if(n.destroyed){return}if(n._queue.length===0){n._buffer=e;n._cb=r;return}n._buffer=null;var o=n._queue[0];var s=Math.max(o.start-n._position,0);var a=o.end-n._position;if(s>=e.length){n._position+=e.length;return r(null)}var f;if(a>e.length){n._position+=e.length;if(s===0){f=e}else{f=e.slice(s)}i=o.stream.write(f)&&i;break}n._position+=a;if(s===0&&a===e.length){f=e}else{f=e.slice(s,a)}i=o.stream.write(f)&&i;if(o.last){o.stream.end()}e=e.slice(a);n._queue.shift()}if(i){r(null)}else{o.stream.once("drain",r.bind(null,null))}};o.prototype.slice=function(e){var t=this;if(t.destroyed)return null;if(!(e instanceof Array)){e=[e]}var r=new i.PassThrough;e.forEach(function(n,i){t._queue.push({start:n.start,end:n.end,stream:r,last:i===e.length-1})});if(t._buffer){t._write(t._buffer,null,t._cb)}return r};o.prototype.destroy=function(e){var t=this;if(t.destroyed)return;t.destroyed=true;if(e)t.emit("error",e)}},{inherits:79,stream:39}],128:[function(e,t,r){var n=e("events");var i=e("inherits");var o=e("mediasource");var s=e("pump");var a=e("./mp4-remuxer");t.exports=f;function f(e,t,r){var i=this;if(!(this instanceof f))return new f(e,t,r);r=r||{};n.call(i);i._elem=t;i._elemWrapper=new o(t);i._muxer=new a(e);i._tracks=null;i._onWaiting=function(){if(i._tracks){var e=i._muxer.seek(i._elem.currentTime);i._tracks.forEach(function(t,r){t.muxed.destroy();t.muxed=e[r];t.mediaSource=i._elemWrapper.createWriteStream(t.mediaSource)});i._pump()}};i._elem.addEventListener("waiting",i._onWaiting);i._muxer.on("ready",function(e){var t=i._muxer.seek(0,true);i._tracks=e.map(function(e,r){return{muxed:t[r],mediaSource:i._elemWrapper.createWriteStream(e.mime)}});i._pump()});i._muxer.on("error",i.emit.bind(i,"error"))}i(f,n);f.prototype._pump=function(){var e=this;e._tracks.forEach(function(t){s(t.muxed,t.mediaSource,function(t){if(t&&t.message!=="premature close"){ -e.emit("error",t)}})})};f.prototype.destroy=function(e){var t=this;if(t.destroyed){return}t.destroyed=true;t._elem.removeEventListener("waiting",t._onWaiting);if(t._tracks){t._tracks.forEach(function(e){e.muxed.destroy()})}t._elem.src="";if(e)t.emit("error",e)}},{"./mp4-remuxer":117,events:30,inherits:79,mediasource:115,pump:92}],129:[function(e,t,r){(function(e){t.exports=function(t,r,n){if(typeof r!=="number")throw new Error("second argument must be a Number");var i,o,s,a,f;var u=true;if(Array.isArray(t)){i=[];s=o=t.length}else{a=Object.keys(t);i={};s=o=a.length}function c(t){function r(){if(n)n(t,i);n=null}if(u)e.nextTick(r);else r()}function l(e,r,n){i[e]=n;if(r)f=true;if(--s===0||r){c(r)}else if(!f&&d<o){var u;if(a){u=a[d];d+=1;t[u](l.bind(undefined,u))}else{u=d;d+=1;t[u](l.bind(undefined,u))}}}var d=r;if(!s){c(null)}else if(a){a.some(function(e,n){t[e](l.bind(undefined,e));if(n===r-1)return true})}else{t.some(function(e,t){e(l.bind(undefined,t));if(t===r-1)return true})}u=false}}).call(this,e("_process"))},{_process:34}],130:[function(e,t,r){(function(e){t.exports=function(t,r){var n,i,o;var s=true;if(Array.isArray(t)){n=[];i=t.length}else{o=Object.keys(t);n={};i=o.length}function a(t){function i(){if(r)r(t,n);r=null}if(s)e.nextTick(i);else i()}function f(e,t,r){n[e]=r;if(--i===0||t){a(t)}}if(!i){a(null)}else if(o){o.forEach(function(e){t[e](f.bind(undefined,e))})}else{t.forEach(function(e,t){e(f.bind(undefined,t))})}s=false}}).call(this,e("_process"))},{_process:34}],131:[function(e,t,r){(function(r){t.exports=u;var n=e("xtend");var i=e("http");var o=e("https");var s=e("once");var a=e("unzip-response");var f=e("url");function u(e,t){e=typeof e==="string"?{url:e}:n(e);t=s(t);if(e.url)c(e);if(e.headers==null)e.headers={};if(e.maxRedirects==null)e.maxRedirects=10;var r=e.body;e.body=undefined;if(r&&!e.method)e.method="POST";var f=Object.keys(e.headers).some(function(e){return e.toLowerCase()==="accept-encoding"});if(!f)e.headers["accept-encoding"]="gzip, deflate";var l=e.protocol==="https:"?o:i;var d=l.request(e,function(r){if(r.statusCode>=300&&r.statusCode<400&&"location"in r.headers){e.url=r.headers.location;c(e);r.resume();e.maxRedirects-=1;if(e.maxRedirects>0)u(e,t);else t(new Error("too many redirects"));return}t(null,typeof a==="function"?a(r):r)});d.on("error",t);d.end(r);return d}t.exports.concat=function(e,t){return u(e,function(e,n){if(e)return t(e);var i=[];n.on("data",function(e){i.push(e)});n.on("end",function(){t(null,r.concat(i),n)})})};["get","post","put","patch","head","delete"].forEach(function(e){t.exports[e]=function(t,r){if(typeof t==="string")t={url:t};t.method=e.toUpperCase();return u(t,r)}});function c(e){var t=f.parse(e.url);if(t.hostname)e.hostname=t.hostname;if(t.port)e.port=t.port;if(t.protocol)e.protocol=t.protocol;e.path=t.path;delete e.url}}).call(this,e("buffer").Buffer)},{buffer:26,http:40,https:31,once:133,"unzip-response":25,url:46,xtend:156}],132:[function(e,t,r){arguments[4][20][0].apply(r,arguments)},{dup:20}],133:[function(e,t,r){arguments[4][21][0].apply(r,arguments)},{dup:21,wrappy:132}],134:[function(e,t,r){(function(r){t.exports=c;var n=e("debug")("simple-peer");var i=e("get-browser-rtc");var o=e("hat");var s=e("inherits");var a=e("is-typedarray");var f=e("once");var u=e("stream");s(c,u.Duplex);function c(e){var t=this;if(!(t instanceof c))return new c(e);t._debug("new peer %o",e);if(!e)e={};e.allowHalfOpen=false;if(e.highWaterMark==null)e.highWaterMark=1024*1024;u.Duplex.call(t,e);t.initiator=e.initiator||false;t.channelConfig=e.channelConfig||c.channelConfig;t.channelName=e.initiator?e.channelName||o(160):null;t.config=e.config||c.config;t.constraints=e.constraints||c.constraints;t.offerConstraints=e.offerConstraints;t.answerConstraints=e.answerConstraints;t.reconnectTimer=e.reconnectTimer||false;t.sdpTransform=e.sdpTransform||function(e){return e};t.stream=e.stream||false;t.trickle=e.trickle!==undefined?e.trickle:true;t.destroyed=false;t.connected=false;t.remoteAddress=undefined;t.remoteFamily=undefined;t.remotePort=undefined;t.localAddress=undefined;t.localPort=undefined;t._isWrtc=!!e.wrtc;t._wrtc=e.wrtc||i();if(!t._wrtc){if(typeof window==="undefined"){throw new Error("No WebRTC support: Specify `opts.wrtc` option in this environment")}else{throw new Error("No WebRTC support: Not a supported browser")}}t._maxBufferedAmount=e.highWaterMark;t._pcReady=false;t._channelReady=false;t._iceComplete=false;t._channel=null;t._pendingCandidates=[];t._chunk=null;t._cb=null;t._interval=null;t._reconnectTimeout=null;t._pc=new t._wrtc.RTCPeerConnection(t.config,t.constraints);t._pc.oniceconnectionstatechange=t._onIceConnectionStateChange.bind(t);t._pc.onsignalingstatechange=t._onSignalingStateChange.bind(t);t._pc.onicecandidate=t._onIceCandidate.bind(t);if(t.stream)t._pc.addStream(t.stream);t._pc.onaddstream=t._onAddStream.bind(t);if(t.initiator){t._setupData({channel:t._pc.createDataChannel(t.channelName,t.channelConfig)});t._pc.onnegotiationneeded=f(t._createOffer.bind(t));if(typeof window==="undefined"||!window.webkitRTCPeerConnection){t._pc.onnegotiationneeded()}}else{t._pc.ondatachannel=t._setupData.bind(t)}t.on("finish",function(){if(t.connected){setTimeout(function(){t._destroy()},100)}else{t.once("connect",function(){setTimeout(function(){t._destroy()},100)})}})}c.WEBRTC_SUPPORT=!!i();c.config={iceServers:[{url:"stun:23.21.150.121",urls:"stun:23.21.150.121"}]};c.constraints={};c.channelConfig={};Object.defineProperty(c.prototype,"bufferSize",{get:function(){var e=this;return e._channel&&e._channel.bufferedAmount||0}});c.prototype.address=function(){var e=this;return{port:e.localPort,family:"IPv4",address:e.localAddress}};c.prototype.signal=function(e){var t=this;if(t.destroyed)throw new Error("cannot signal after peer is destroyed");if(typeof e==="string"){try{e=JSON.parse(e)}catch(r){e={}}}t._debug("signal()");function n(e){try{t._pc.addIceCandidate(new t._wrtc.RTCIceCandidate(e),l,t._onError.bind(t))}catch(r){t._destroy(new Error("error adding candidate: "+r.message))}}if(e.sdp){t._pc.setRemoteDescription(new t._wrtc.RTCSessionDescription(e),function(){if(t.destroyed)return;if(t._pc.remoteDescription.type==="offer")t._createAnswer();t._pendingCandidates.forEach(n);t._pendingCandidates=[]},t._onError.bind(t))}if(e.candidate){if(t._pc.remoteDescription)n(e.candidate);else t._pendingCandidates.push(e.candidate)}if(!e.sdp&&!e.candidate){t._destroy(new Error("signal() called with invalid signal data"))}};c.prototype.send=function(e){var t=this;if(!a.strict(e)&&!(e instanceof ArrayBuffer)&&!r.isBuffer(e)&&typeof e!=="string"&&(typeof Blob==="undefined"||!(e instanceof Blob))){e=JSON.stringify(e)}if(r.isBuffer(e)&&t._isWrtc){e=new Uint8Array(e)}var n=e.length||e.byteLength||e.size;t._channel.send(e);t._debug("write: %d bytes",n)};c.prototype.destroy=function(e){var t=this;t._destroy(null,e)};c.prototype._destroy=function(e,t){var r=this;if(r.destroyed)return;if(t)r.once("close",t);r._debug("destroy (error: %s)",e&&e.message);r.readable=r.writable=false;if(!r._readableState.ended)r.push(null);if(!r._writableState.finished)r.end();r.destroyed=true;r.connected=false;r._pcReady=false;r._channelReady=false;r._chunk=null;r._cb=null;clearInterval(r._interval);clearTimeout(r._reconnectTimeout);if(r._pc){try{r._pc.close()}catch(e){}r._pc.oniceconnectionstatechange=null;r._pc.onsignalingstatechange=null;r._pc.onicecandidate=null}if(r._channel){try{r._channel.close()}catch(e){}r._channel.onmessage=null;r._channel.onopen=null;r._channel.onclose=null}r._pc=null;r._channel=null;if(e)r.emit("error",e);r.emit("close")};c.prototype._setupData=function(e){var t=this;t._channel=e.channel;t.channelName=t._channel.label;t._channel.binaryType="arraybuffer";t._channel.onmessage=t._onChannelMessage.bind(t);t._channel.onopen=t._onChannelOpen.bind(t);t._channel.onclose=t._onChannelClose.bind(t)};c.prototype._read=function(){};c.prototype._write=function(e,t,r){var n=this;if(n.destroyed)return r(new Error("cannot write after peer is destroyed"));if(n.connected){try{n.send(e)}catch(i){return n._onError(i)}if(n._channel.bufferedAmount>n._maxBufferedAmount){n._debug("start backpressure: bufferedAmount %d",n._channel.bufferedAmount);n._cb=r}else{r(null)}}else{n._debug("write before connect");n._chunk=e;n._cb=r}};c.prototype._createOffer=function(){var e=this;if(e.destroyed)return;e._pc.createOffer(function(t){if(e.destroyed)return;t.sdp=e.sdpTransform(t.sdp);e._pc.setLocalDescription(t,l,e._onError.bind(e));var r=function(){var r=e._pc.localDescription||t;e._debug("signal");e.emit("signal",{type:r.type,sdp:r.sdp})};if(e.trickle||e._iceComplete)r();else e.once("_iceComplete",r)},e._onError.bind(e),e.offerConstraints)};c.prototype._createAnswer=function(){var e=this;if(e.destroyed)return;e._pc.createAnswer(function(t){if(e.destroyed)return;t.sdp=e.sdpTransform(t.sdp);e._pc.setLocalDescription(t,l,e._onError.bind(e));var r=function(){var r=e._pc.localDescription||t;e._debug("signal");e.emit("signal",{type:r.type,sdp:r.sdp})};if(e.trickle||e._iceComplete)r();else e.once("_iceComplete",r)},e._onError.bind(e),e.answerConstraints)};c.prototype._onIceConnectionStateChange=function(){var e=this;if(e.destroyed)return;var t=e._pc.iceGatheringState;var r=e._pc.iceConnectionState;e._debug("iceConnectionStateChange %s %s",t,r);e.emit("iceConnectionStateChange",t,r);if(r==="connected"||r==="completed"){clearTimeout(e._reconnectTimeout);e._pcReady=true;e._maybeReady()}if(r==="disconnected"){if(e.reconnectTimer){clearTimeout(e._reconnectTimeout);e._reconnectTimeout=setTimeout(function(){e._destroy()},e.reconnectTimer)}else{e._destroy()}}if(r==="failed"){e._destroy()}if(r==="closed"){e._destroy()}};c.prototype._maybeReady=function(){var e=this;e._debug("maybeReady pc %s channel %s",e._pcReady,e._channelReady);if(e.connected||e._connecting||!e._pcReady||!e._channelReady)return;e._connecting=true;if(!e._pc.getStats){t([])}else if(typeof window!=="undefined"&&!!window.mozRTCPeerConnection){e._pc.getStats(null,function(e){var r=[];e.forEach(function(e){r.push(e)});t(r)},e._onError.bind(e))}else{e._pc.getStats(function(e){var r=[];e.result().forEach(function(e){var t={};e.names().forEach(function(r){t[r]=e.stat(r)});t.id=e.id;t.type=e.type;t.timestamp=e.timestamp;r.push(t)});t(r)})}function t(t){t.forEach(function(t){if(t.type==="remotecandidate"&&t.candidateType==="host"){e.remoteAddress=t.ipAddress;e.remotePort=Number(t.portNumber);e.remoteFamily="IPv4";e._debug("connect remote: %s:%s (%s)",e.remoteAddress,e.remotePort,e.remoteFamily)}else if(t.type==="localcandidate"&&t.candidateType==="host"){e.localAddress=t.ipAddress;e.localPort=Number(t.portNumber);e._debug("connect local: %s:%s",e.localAddress,e.localPort)}});e._connecting=false;e.connected=true;if(e._chunk){try{e.send(e._chunk)}catch(r){return e._onError(r)}e._chunk=null;e._debug('sent chunk from "write before connect"');var n=e._cb;e._cb=null;n(null)}e._interval=setInterval(function(){if(!e._cb||!e._channel||e._channel.bufferedAmount>e._maxBufferedAmount)return;e._debug("ending backpressure: bufferedAmount %d",e._channel.bufferedAmount);var t=e._cb;e._cb=null;t(null)},150);if(e._interval.unref)e._interval.unref();e._debug("connect");e.emit("connect")}};c.prototype._onSignalingStateChange=function(){var e=this;if(e.destroyed)return;e._debug("signalingStateChange %s",e._pc.signalingState);e.emit("signalingStateChange",e._pc.signalingState)};c.prototype._onIceCandidate=function(e){var t=this;if(t.destroyed)return;if(e.candidate&&t.trickle){t.emit("signal",{candidate:{candidate:e.candidate.candidate,sdpMLineIndex:e.candidate.sdpMLineIndex,sdpMid:e.candidate.sdpMid}})}else if(!e.candidate){t._iceComplete=true;t.emit("_iceComplete")}};c.prototype._onChannelMessage=function(e){var t=this;if(t.destroyed)return;var n=e.data;t._debug("read: %d bytes",n.byteLength||n.length);if(n instanceof ArrayBuffer){n=new r(n);t.push(n)}else{try{n=JSON.parse(n)}catch(i){}t.emit("data",n)}};c.prototype._onChannelOpen=function(){var e=this;if(e.connected||e.destroyed)return;e._debug("on channel open");e._channelReady=true;e._maybeReady()};c.prototype._onChannelClose=function(){var e=this;if(e.destroyed)return;e._debug("on channel close");e._destroy()};c.prototype._onAddStream=function(e){var t=this;if(t.destroyed)return;t._debug("on add stream");t.emit("stream",e.stream)};c.prototype._onError=function(e){var t=this;if(t.destroyed)return;t._debug("error %s",e.message||e);t._destroy(e)};c.prototype._debug=function(){var e=this;var t=[].slice.call(arguments);var r=e.channelName&&e.channelName.substring(0,7);t[0]="["+r+"] "+t[0];n.apply(null,t)};function l(){}}).call(this,e("buffer").Buffer)},{buffer:26,debug:71,"get-browser-rtc":135,hat:77,inherits:79,"is-typedarray":136,once:138,stream:39}],135:[function(e,t,r){t.exports=function n(){if(typeof window==="undefined")return null;var e={RTCPeerConnection:window.mozRTCPeerConnection||window.RTCPeerConnection||window.webkitRTCPeerConnection,RTCSessionDescription:window.mozRTCSessionDescription||window.RTCSessionDescription||window.webkitRTCSessionDescription,RTCIceCandidate:window.mozRTCIceCandidate||window.RTCIceCandidate||window.webkitRTCIceCandidate};if(!e.RTCPeerConnection)return null;return e}},{}],136:[function(e,t,r){arguments[4][23][0].apply(r,arguments)},{dup:23}],137:[function(e,t,r){arguments[4][20][0].apply(r,arguments)},{dup:20}],138:[function(e,t,r){arguments[4][21][0].apply(r,arguments)},{dup:21,wrappy:137}],139:[function(e,t,r){var n=e("rusha");var i=new n;var o=window.crypto||window.msCrypto||{};var s=o.subtle||o.webkitSubtle;var a=i.digest.bind(i);try{s.digest({name:"sha-1"},new Uint8Array).catch(function(){s=false})}catch(f){s=false}function u(e,t){if(!s){setTimeout(t,0,a(e));return}if(typeof e==="string"){e=c(e)}s.digest({name:"sha-1"},e).then(function r(e){t(l(new Uint8Array(e)))},function n(r){t(a(e))})}function c(e){var t=e.length;var r=new Uint8Array(t);for(var n=0;n<t;n++){r[n]=e.charCodeAt(n)}return r}function l(e){var t=e.length;var r=[];for(var n=0;n<t;n++){var i=e[n];r.push((i>>>4).toString(16));r.push((i&15).toString(16))}return r.join("")}t.exports=u;t.exports.sync=a},{rusha:140}],140:[function(e,t,r){(function(e){(function(){var r={getDataType:function(t){if(typeof t==="string"){return"string"}if(t instanceof Array){return"array"}if(typeof e!=="undefined"&&e.Buffer&&e.Buffer.isBuffer(t)){return"buffer"}if(t instanceof ArrayBuffer){return"arraybuffer"}if(t.buffer instanceof ArrayBuffer){return"view"}if(t instanceof Blob){return"blob"}throw new Error("Unsupported data type.")}};function n(e){"use strict";var t={fill:0};var o=function(e){for(e+=9;e%64>0;e+=1);return e};var s=function(e,t){for(var r=t>>2;r<e.length;r++)e[r]=0};var a=function(e,t,r){e[t>>2]|=128<<24-(t%4<<3);e[((t>>2)+2&~15)+14]=r>>29;e[((t>>2)+2&~15)+15]=r<<3};var f=function(e,t,r,n,i){var o=this,s,a=i%4,f=n%4,u=n-f;if(u>0){switch(a){case 0:e[i+3|0]=o.charCodeAt(r);case 1:e[i+2|0]=o.charCodeAt(r+1);case 2:e[i+1|0]=o.charCodeAt(r+2);case 3:e[i|0]=o.charCodeAt(r+3)}}for(s=a;s<u;s=s+4|0){t[i+s>>2]=o.charCodeAt(r+s)<<24|o.charCodeAt(r+s+1)<<16|o.charCodeAt(r+s+2)<<8|o.charCodeAt(r+s+3)}switch(f){case 3:e[i+u+1|0]=o.charCodeAt(r+u+2);case 2:e[i+u+2|0]=o.charCodeAt(r+u+1);case 1:e[i+u+3|0]=o.charCodeAt(r+u)}};var u=function(e,t,r,n,i){var o=this,s,a=i%4,f=n%4,u=n-f;if(u>0){switch(a){case 0:e[i+3|0]=o[r];case 1:e[i+2|0]=o[r+1];case 2:e[i+1|0]=o[r+2];case 3:e[i|0]=o[r+3]}}for(s=4-a;s<u;s=s+=4|0){t[i+s>>2]=o[r+s]<<24|o[r+s+1]<<16|o[r+s+2]<<8|o[r+s+3]}switch(f){case 3:e[i+u+1|0]=o[r+u+2];case 2:e[i+u+2|0]=o[r+u+1];case 1:e[i+u+3|0]=o[r+u]}};var c=function(e,t,r,n,o){var s=this,a,f=o%4,u=n%4,c=n-u;var l=new Uint8Array(i.readAsArrayBuffer(s.slice(r,r+n)));if(c>0){switch(f){case 0:e[o+3|0]=l[0];case 1:e[o+2|0]=l[1];case 2:e[o+1|0]=l[2];case 3:e[o|0]=l[3]}}for(a=4-f;a<c;a=a+=4|0){t[o+a>>2]=l[a]<<24|l[a+1]<<16|l[a+2]<<8|l[a+3]}switch(u){case 3:e[o+c+1|0]=l[c+2];case 2:e[o+c+2|0]=l[c+1];case 1:e[o+c+3|0]=l[c]}};var l=function(e){switch(r.getDataType(e)){case"string":return f.bind(e);case"array":return u.bind(e);case"buffer":return u.bind(e);case"arraybuffer":return u.bind(new Uint8Array(e));case"view":return u.bind(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));case"blob":return c.bind(e)}};var d=function(e,t){switch(r.getDataType(e)){case"string":return e.slice(t);case"array":return e.slice(t);case"buffer":return e.slice(t);case"arraybuffer":return e.slice(t);case"view":return e.buffer.slice(t)}};var h=function(e){var t,r,n="0123456789abcdef",i=[],o=new Uint8Array(e);for(t=0;t<o.length;t++){r=o[t];i[t]=n.charAt(r>>4&15)+n.charAt(r>>0&15)}return i.join("")};var p=function(e){var t;if(e<=65536)return 65536;if(e<16777216){for(t=1;t<e;t=t<<1);}else{for(t=16777216;t<e;t+=16777216);}return t};var m=function(e){if(e%64>0){throw new Error("Chunk size must be a multiple of 128 bit")}t.maxChunkLen=e;t.padMaxChunkLen=o(e);t.heap=new ArrayBuffer(p(t.padMaxChunkLen+320+20));t.h32=new Int32Array(t.heap);t.h8=new Int8Array(t.heap);t.core=new n._core({Int32Array:Int32Array,DataView:DataView},{},t.heap);t.buffer=null};m(e||64*1024);var v=function(e,t){var r=new Int32Array(e,t+320,5);r[0]=1732584193;r[1]=-271733879;r[2]=-1732584194;r[3]=271733878;r[4]=-1009589776};var g=function(e,r){var n=o(e);var i=new Int32Array(t.heap,0,n>>2);s(i,e);a(i,e,r);return n};var y=function(e,r,n){l(e)(t.h8,t.h32,r,n,0)};var _=function(e,r,n,i,o){var s=n;if(o){s=g(n,i)}y(e,r,n);t.core.hash(s,t.padMaxChunkLen)};var b=function(e,t){var r=new Int32Array(e,t+320,5);var n=new Int32Array(5);var i=new DataView(n.buffer);i.setInt32(0,r[0],false);i.setInt32(4,r[1],false);i.setInt32(8,r[2],false);i.setInt32(12,r[3],false);i.setInt32(16,r[4],false);return n};var w=this.rawDigest=function(e){var r=e.byteLength||e.length||e.size||0;v(t.heap,t.padMaxChunkLen);var n=0,i=t.maxChunkLen,o;for(n=0;r>n+i;n+=i){_(e,n,i,r,false)}_(e,n,r-n,r,true);return b(t.heap,t.padMaxChunkLen)};this.digest=this.digestFromString=this.digestFromBuffer=this.digestFromArrayBuffer=function(e){return h(w(e).buffer)}}n._core=function s(e,t,r){"use asm";var n=new e.Int32Array(r);function i(e,t){e=e|0;t=t|0;var r=0,i=0,o=0,s=0,a=0,f=0,u=0,c=0,l=0,d=0,h=0,p=0,m=0,v=0;o=n[t+320>>2]|0;a=n[t+324>>2]|0;u=n[t+328>>2]|0;l=n[t+332>>2]|0;h=n[t+336>>2]|0;for(r=0;(r|0)<(e|0);r=r+64|0){s=o;f=a;c=u;d=l;p=h;for(i=0;(i|0)<64;i=i+4|0){v=n[r+i>>2]|0;m=((o<<5|o>>>27)+(a&u|~a&l)|0)+((v+h|0)+1518500249|0)|0;h=l;l=u;u=a<<30|a>>>2;a=o;o=m;n[e+i>>2]=v}for(i=e+64|0;(i|0)<(e+80|0);i=i+4|0){v=(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])<<1|(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])>>>31;m=((o<<5|o>>>27)+(a&u|~a&l)|0)+((v+h|0)+1518500249|0)|0;h=l;l=u;u=a<<30|a>>>2;a=o;o=m;n[i>>2]=v}for(i=e+80|0;(i|0)<(e+160|0);i=i+4|0){v=(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])<<1|(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])>>>31;m=((o<<5|o>>>27)+(a^u^l)|0)+((v+h|0)+1859775393|0)|0;h=l;l=u;u=a<<30|a>>>2;a=o;o=m;n[i>>2]=v}for(i=e+160|0;(i|0)<(e+240|0);i=i+4|0){v=(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])<<1|(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])>>>31;m=((o<<5|o>>>27)+(a&u|a&l|u&l)|0)+((v+h|0)-1894007588|0)|0;h=l;l=u;u=a<<30|a>>>2;a=o;o=m;n[i>>2]=v}for(i=e+240|0;(i|0)<(e+320|0);i=i+4|0){v=(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])<<1|(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])>>>31;m=((o<<5|o>>>27)+(a^u^l)|0)+((v+h|0)-899497514|0)|0;h=l;l=u;u=a<<30|a>>>2;a=o;o=m;n[i>>2]=v}o=o+s|0;a=a+f|0;u=u+c|0;l=l+d|0;h=h+p|0}n[t+320>>2]=o;n[t+324>>2]=a;n[t+328>>2]=u;n[t+332>>2]=l;n[t+336>>2]=h}return{hash:i}};if(typeof t!=="undefined"){t.exports=n}else if(typeof window!=="undefined"){window.Rusha=n}if(typeof FileReaderSync!=="undefined"){var i=new FileReaderSync,o=new n(4*1024*1024);self.onmessage=function a(e){var t,r=e.data.data;try{t=o.digest(r);self.postMessage({id:e.data.id,hash:t})}catch(n){self.postMessage({id:e.data.id,error:n.name})}}}})()}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],141:[function(e,t,r){var n=1;var i=65535;var o=4;var s=function(){n=n+1&i};var a=setInterval(s,1e3/o|0);if(a.unref)a.unref();t.exports=function(e){var t=o*(e||5);var r=[0];var s=1;var a=n-1&i;return function(e){var f=n-a&i;if(f>t)f=t;a=n;while(f--){if(s===t)s=0;r[s]=r[s===0?t-1:s-1];s++}if(e)r[s-1]+=e;var u=r[s-1];var c=r.length<t?0:r[s===t?0:s];return r.length<o?u:(u-c)*o/r.length}}},{}],142:[function(e,t,r){var n=e("once");t.exports=function i(e,t,r){r=n(r);var i=[];e.on("data",function(e){i.push(e)}).on("end",function(){var e=t?new Blob(i,{type:t}):new Blob(i);var n=URL.createObjectURL(e);r(null,n)}).on("error",r)}},{once:144}],143:[function(e,t,r){arguments[4][20][0].apply(r,arguments)},{dup:20}],144:[function(e,t,r){arguments[4][21][0].apply(r,arguments)},{dup:21,wrappy:143}],145:[function(e,t,r){(function(r){var n=e("once");t.exports=function i(e,t,o){o=n(o);var s=new r(t);var a=0;e.on("data",function(e){e.copy(s,a);a+=e.length}).on("end",function(){o(null,s)}).on("error",o)}}).call(this,e("buffer").Buffer)},{buffer:26,once:147}],146:[function(e,t,r){arguments[4][20][0].apply(r,arguments)},{dup:20}],147:[function(e,t,r){arguments[4][21][0].apply(r,arguments)},{dup:21,wrappy:146}],148:[function(e,t,r){(function(r,n){t.exports=d;var i=e("debug")("torrent-discovery");var o=e("bittorrent-dht/client");var s=e("events").EventEmitter;var a=e("xtend");var f=e("inherits");var u=e("run-parallel");var c=e("re-emitter");var l=e("bittorrent-tracker/client");f(d,s);function d(e){var t=this;if(!(t instanceof d))return new d(e);s.call(t);t.announce=e.announce||[];t.rtcConfig=e.rtcConfig;t.peerId=e.peerId;t.port=e.port||0;t.wrtc=e.wrtc;t.intervalMs=e.intervalMs||15*60*1e3;if(!t.peerId)throw new Error("peerId required");if(!r.browser&&!t.port)throw new Error("port required");t.infoHash=null;t.infoHashBuffer=null;t.torrent=null;t._dhtAnnouncing=false;t._dhtTimeout=false;t._internalDHT=false;if(e.tracker===false){t.tracker=false}else{t.tracker=true}if(e.dht===false){t.dht=false}else if(typeof e.dht==="object"){t.dht=e.dht}else{t.dht=n()}if(t.dht){c(t.dht,t,["error","warning"]);t.dht.on("peer",i)}function n(){if(typeof o!=="function")return false;t._internalDHT=true;var r=new o;r.listen(e.dhtPort);return r}function i(e,r){if(r.toString("hex")!==t.infoHash)return;t.emit("peer",e.host+":"+e.port)}}d.prototype.setTorrent=function(e){var t=this;if(!t.infoHash&&(typeof e==="string"||n.isBuffer(e))){t.infoHash=typeof e==="string"?e:e.toString("hex")}else if(!t.torrent&&e&&e.infoHash){t.torrent=e;t.infoHash=typeof e.infoHash==="string"?e.infoHash:e.infoHash.toString("hex")}else{return}t.infoHashBuffer=new n(t.infoHash,"hex");i("setTorrent %s",t.infoHash);if(t.tracker&&t.tracker!==true){t.tracker.torrentLength=e.length}else{t._createTracker()}t._dhtAnnounce()};d.prototype.updatePort=function(e){var t=this;if(e===t.port)return;t.port=e;t._dhtAnnounce();if(t.tracker&&t.tracker!==true){t.tracker.stop();t.tracker.destroy(function(){t._createTracker()})}};d.prototype.stop=function(e){var t=this;var r=[];clearTimeout(t._dhtTimeout);if(t.tracker&&t.tracker!==true){t.tracker.stop();r.push(function(e){t.tracker.destroy(e)})}if(t._internalDHT){r.push(function(e){t.dht.destroy(e)})}u(r,e)};d.prototype._createTracker=function(){var e=this;if(!e.tracker)return;var t=e.torrent?a({announce:[]},e.torrent):{infoHash:e.infoHash,announce:[]};if(e.announce)t.announce=t.announce.concat(e.announce);var r={rtcConfig:e.rtcConfig,wrtc:e.wrtc};e.tracker=new l(e.peerId,e.port,t,r);c(e.tracker,e,["peer","warning","error"]);e.tracker.setInterval(e.intervalMs);e.tracker.on("update",n);e.tracker.start();function n(t){e.emit("trackerAnnounce",t)}};d.prototype._dhtAnnounce=function(){var e=this;if(!e.port||!e.infoHash||!e.dht||e._dhtAnnouncing)return;e._dhtAnnouncing=true;e.dht.announce(e.infoHash,e.port,function(t){if(t)e.emit("warning",t);e._dhtAnnouncing=false;i("dht announce complete");e.emit("dhtAnnounce")});clearTimeout(e._dhtTimeout);e._dhtTimeout=setTimeout(function(){e._dhtAnnounce()},t());function t(){return e.intervalMs+Math.floor(Math.random()*e.intervalMs/5)}}}).call(this,e("_process"),e("buffer").Buffer)},{_process:34,"bittorrent-dht/client":25,"bittorrent-tracker/client":16,buffer:26,debug:71,events:30,inherits:79,"re-emitter":96,"run-parallel":130,xtend:156}],149:[function(e,t,r){(function(e){t.exports=n;var r=1<<14;function n(e){if(!(this instanceof n))return new n(e);this.length=e;this.missing=e;this.sources=null;this._chunks=Math.ceil(e/r);this._remainder=e%r||r;this._buffered=0;this._buffer=null;this._cancellations=null;this._reservations=0;this._flushed=false}n.BLOCK_LENGTH=r;n.prototype.chunkLength=function(e){return e===this._chunks-1?this._remainder:r};n.prototype.chunkOffset=function(e){return e*r};n.prototype.reserve=function(){if(!this.init())return-1;if(this._cancellations.length)return this._cancellations.pop();if(this._reservations<this._chunks)return this._reservations++;return-1};n.prototype.cancel=function(e){if(!this.init())return;this._cancellations.push(e)};n.prototype.get=function(e){if(!this.init())return null;return this._buffer[e]};n.prototype.set=function(e,t,r){if(!this.init())return false;if(!this._buffer[e]){this._buffered++;this._buffer[e]=t;this.missing-=t.length;if(this.sources.indexOf(r)===-1){this.sources.push(r)}}return this._buffered===this._chunks};n.prototype.flush=function(){if(!this._buffer||this._chunks!==this._buffered)return null;var t=e.concat(this._buffer,this.length);this._buffer=null;this._cancellations=null;this.sources=null;this._flushed=true;return t};n.prototype.init=function(){if(this._flushed)return false;if(this._buffer)return true;this._buffer=new Array(this._chunks);this._cancellations=[];this.sources=[];return true}}).call(this,e("buffer").Buffer)},{buffer:26}],150:[function(e,t,r){"use strict";function n(e,t){var r=1,n=e.length,i=e[0],o=e[0];for(var s=1;s<n;++s){o=i;i=e[s];if(t(i,o)){if(s===r){r++;continue}e[r++]=i}}e.length=r;return e}function i(e){var t=1,r=e.length,n=e[0],i=e[0];for(var o=1;o<r;++o,i=n){i=n;n=e[o];if(n!==i){if(o===t){t++;continue}e[t++]=n}}e.length=t;return e}function o(e,t,r){if(e.length===0){return e}if(t){if(!r){e.sort(t)}return n(e,t)}if(!r){e.sort()}return i(e)}t.exports=o},{}],151:[function(e,t,r){(function(r){var n=e("bencode");var i=e("bitfield");var o=e("debug")("ut_metadata");var s=e("events").EventEmitter;var a=e("inherits");var f=e("simple-sha1");var u=1e7;var c=1e3;var l=16*1024;t.exports=function(e){a(t,s);function t(t){s.call(this);this._wire=t;this._metadataComplete=false;this._metadataSize=null;this._remainingRejects=null;this._fetching=false;this._bitfield=new i(0,{grow:c});if(r.isBuffer(e)){this.setMetadata(e)}}t.prototype.name="ut_metadata";t.prototype.onHandshake=function(e,t,r){this._infoHash=e};t.prototype.onExtendedHandshake=function(e){if(!e.m||!e.m.ut_metadata){return this.emit("warning",new Error("Peer does not support ut_metadata"))}if(!e.metadata_size){return this.emit("warning",new Error("Peer does not have metadata"))}if(e.metadata_size>u){return this.emit("warning",new Error("Peer gave maliciously large metadata size"))}this._metadataSize=e.metadata_size;this._numPieces=Math.ceil(this._metadataSize/l);this._remainingRejects=this._numPieces*2;if(this._fetching){this._requestPieces()}};t.prototype.onMessage=function(e){var t,r;try{var i=e.toString();var o=i.indexOf("ee")+2;t=n.decode(i.substring(0,o));r=e.slice(o)}catch(s){return}switch(t.msg_type){case 0:this._onRequest(t.piece);break;case 1:this._onData(t.piece,r,t.total_size);break;case 2:this._onReject(t.piece);break}};t.prototype.fetch=function(){if(this._metadataComplete){return}this._fetching=true;if(this._metadataSize){this._requestPieces()}};t.prototype.cancel=function(){this._fetching=false};t.prototype.setMetadata=function(e){if(this._metadataComplete)return true;o("set metadata");try{var t=n.decode(e).info;if(t){e=n.encode(t)}}catch(r){}if(this._infoHash&&this._infoHash!==f.sync(e)){return false}this.cancel();this.metadata=e;this._metadataComplete=true;this._metadataSize=this.metadata.length;this._wire.extendedHandshake.metadata_size=this._metadataSize;this.emit("metadata",n.encode({info:n.decode(this.metadata)}));return true};t.prototype._send=function(e,t){var i=n.encode(e);if(r.isBuffer(t)){i=r.concat([i,t])}this._wire.extended("ut_metadata",i)};t.prototype._request=function(e){this._send({msg_type:0,piece:e})};t.prototype._data=function(e,t,r){var n={msg_type:1,piece:e};if(typeof r==="number"){n.total_size=r}this._send(n,t)};t.prototype._reject=function(e){this._send({msg_type:2,piece:e})};t.prototype._onRequest=function(e){if(!this._metadataComplete){this._reject(e);return}var t=e*l;var r=t+l;if(r>this._metadataSize){r=this._metadataSize}var n=this.metadata.slice(t,r);this._data(e,n,this._metadataSize)};t.prototype._onData=function(e,t,r){if(t.length>l){return}t.copy(this.metadata,e*l);this._bitfield.set(e);this._checkDone()};t.prototype._onReject=function(e){if(this._remainingRejects>0&&this._fetching){this._request(e);this._remainingRejects-=1}else{this.emit("warning",new Error('Peer sent "reject" too much'))}};t.prototype._requestPieces=function(){this.metadata=new r(this._metadataSize);for(var e=0;e<this._numPieces;e++){this._request(e)}};t.prototype._checkDone=function(){var e=true;for(var t=0;t<this._numPieces;t++){if(!this._bitfield.get(t)){e=false;break}}if(!e)return;var r=this.setMetadata(this.metadata);if(!r){this._failedMetadata()}};t.prototype._failedMetadata=function(){this._bitfield=new i(0,{grow:c});this._remainingRejects-=this._numPieces;if(this._remainingRejects>0){this._requestPieces()}else{this.emit("warning",new Error("Peer sent invalid metadata"))}};return t}}).call(this,e("buffer").Buffer)},{bencode:152,bitfield:7,buffer:26,debug:71,events:30,inherits:79,"simple-sha1":139}],152:[function(e,t,r){arguments[4][12][0].apply(r,arguments)},{"./lib/decode":153,"./lib/encode":155,dup:12}],153:[function(e,t,r){arguments[4][13][0].apply(r,arguments)},{"./dict":154,buffer:26,dup:13}],154:[function(e,t,r){arguments[4][14][0].apply(r,arguments)},{dup:14}],155:[function(e,t,r){arguments[4][15][0].apply(r,arguments)},{buffer:26,dup:15}],156:[function(e,t,r){t.exports=i;var n=Object.prototype.hasOwnProperty;function i(){var e={};for(var t=0;t<arguments.length;t++){var r=arguments[t];for(var i in r){if(n.call(r,i)){e[i]=r[i]}}}return e}},{}],157:[function(e,t,r){t.exports=i;var n=Object.prototype.hasOwnProperty;function i(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r){if(n.call(r,i)){e[i]=r[i]}}}return e}},{}],158:[function(e,t,r){t.exports=function n(e,t,r){if(t===undefined){return function(t,r){return n(e,t,r)}}if(r===undefined)r="0";e-=t.toString().length;if(e>0)return new Array(e+(/\./.test(t)?2:1)).join(r)+t;return t+""}},{}],159:[function(e,t,r){t.exports={name:"webtorrent",description:"Streaming torrent client",version:"0.74.2",author:{name:"Feross Aboukhadijeh",email:"feross@feross.org",url:"http://feross.org/"},bin:{webtorrent:"./bin/cmd.js"},browser:{"./lib/server.js":false,"bittorrent-dht/client":false,"fs-chunk-store":"memory-chunk-store","load-ip-set":false,os:false,"path-exists":false,ut_pex:false},bugs:{url:"https://github.com/feross/webtorrent/issues"},dependencies:{"addr-to-ip-port":"^1.0.1",bitfield:"^1.0.2","bittorrent-dht":"^6.0.1","bittorrent-swarm":"^7.0.0","chunk-store-stream":"^2.0.0",clivas:"^0.2.0",cpus:"^1.0.0","create-torrent":"^3.4.0",debug:"^2.1.0","end-of-stream":"^1.0.0",executable:"^3.0.0","fs-chunk-store":"^1.3.4",hat:"0.0.3","immediate-chunk-store":"^1.0.7",inherits:"^2.0.1",inquirer:"^0.12.0","load-ip-set":"^1.0.3","memory-chunk-store":"^1.2.0",mime:"^1.2.11",minimist:"^1.1.0",moment:"^2.8.3",multistream:"^2.0.2","network-address":"^1.0.0","parse-torrent":"^5.1.0","path-exists":"^2.1.0","pretty-bytes":"^3.0.0",pump:"^1.0.0","random-iterate":"^1.0.1","range-parser":"^1.0.2","re-emitter":"^1.0.0","readable-stream":"^2.0.5","render-media":"^2.0.0","run-parallel":"^1.0.0","run-parallel-limit":"^1.0.2", -"simple-peer":"^5.11.6","simple-sha1":"^2.0.0",speedometer:"^1.0.0","stream-to-blob-url":"^2.0.0","stream-with-known-length-to-buffer":"^1.0.0","torrent-discovery":"^5.1.0","torrent-piece":"^1.0.0",uniq:"^1.0.1",ut_metadata:"^3.0.2",ut_pex:"^1.0.1",winreg:"0.0.16",xtend:"^4.0.0","zero-fill":"^2.2.0"},devDependencies:{"bittorrent-tracker":"^7.0.0",brfs:"^1.2.0",browserify:"^13.0.0","cross-spawn-async":"^2.0.0",finalhandler:"^0.4.0","run-series":"^1.0.2","serve-static":"^1.9.3","simple-get":"^1.0.0",standard:"^6.0.1",tape:"^4.0.0","uglify-js":"^2.4.15",zuul:"^3.0.0"},homepage:"https://webtorrent.io",keywords:["bittorrent","bittorrent client","download","mad science","streaming","torrent","webrtc","webrtc data","webtorrent"],license:"MIT",main:"index.js",optionalDependencies:{"airplay-js":"^0.2.3",chromecasts:"^1.5.3",nodebmc:"0.0.6"},repository:{type:"git",url:"git://github.com/feross/webtorrent.git"},scripts:{build:"browserify -s WebTorrent -e ./ | uglifyjs -m > webtorrent.min.js","build-debug":"browserify -s WebTorrent -e ./ > webtorrent.debug.js",size:"npm run build && cat webtorrent.min.js | gzip | wc -c",test:"standard && node ./bin/test.js","test-browser":"zuul -- test/*.js test/browser/*.js","test-browser-local":"zuul --local -- test/*.js test/browser/*.js","test-node":"tape test/*.js test/node/*.js"}}},{}],160:[function(e,t,r){(function(r,n,i){t.exports=x;var o=e("create-torrent");var s=e("debug")("webtorrent");var a=e("bittorrent-dht/client");var f=e("events").EventEmitter;var u=e("xtend");var c=e("hat");var l=e("inherits");var d=e("load-ip-set");var h=e("run-parallel");var p=e("parse-torrent");var m=e("path");var v=e("simple-peer");var g=e("speedometer");var y=e("zero-fill");var _=e("./lib/concat-stream");var b=e("./lib/torrent");t.exports.WEBRTC_SUPPORT=v.WEBRTC_SUPPORT;var w=e("./package.json").version;var E=w.match(/([0-9]+)/g).slice(0,2).map(y(2)).join("");var k="-WW"+E+"-";l(x,f);function x(e){var t=this;if(!(t instanceof x))return new x(e);f.call(t);if(!e)e={};if(!s.enabled)t.setMaxListeners(0);t.destroyed=false;t.torrentPort=e.torrentPort||0;t.tracker=e.tracker!==undefined?e.tracker:true;t._rtcConfig=e.rtcConfig;t._wrtc=e.wrtc||n.WRTC;t.torrents=[];t._downloadSpeed=g();t._uploadSpeed=g();t.maxConns=e.maxConns;t.peerId=typeof e.peerId==="string"?e.peerId:(e.peerId||new i(k+c(48))).toString("hex");t.peerIdBuffer=new i(t.peerId,"hex");t.nodeId=typeof e.nodeId==="string"?e.nodeId:e.nodeId&&e.nodeId.toString("hex")||c(160);t.nodeIdBuffer=new i(t.nodeId,"hex");if(e.dht!==false&&typeof a==="function"){t.dht=new a(u({nodeId:t.nodeId},e.dht));t.dht.listen(e.dhtPort)}else{t.dht=false}s("new webtorrent (peerId %s, nodeId %s)",t.peerId,t.nodeId);if(typeof d==="function"){d(e.blocklist,{headers:{"user-agent":"WebTorrent/"+w+" (http://webtorrent.io)"}},function(e,r){if(e)return t.error("Failed to load blocklist: "+e.message);t.blocked=r;o()})}else r.nextTick(o);function o(){if(t.destroyed)return;t.ready=true;t.emit("ready")}}Object.defineProperty(x.prototype,"ratio",{get:function(){var e=this.torrents.reduce(function(e,t){return e+t.uploaded},0);var t=this.torrents.reduce(function(e,t){return e+t.downloaded},0)||1;return e/t}});Object.defineProperty(x.prototype,"downloadSpeed",{get:function(){return this._downloadSpeed()}});Object.defineProperty(x.prototype,"uploadSpeed",{get:function(){return this._uploadSpeed()}});x.prototype.get=function(e){var t=this;if(e instanceof b)return e;var r;try{r=p(e)}catch(n){}if(!r)return null;if(!r.infoHash)throw new Error("Invalid torrent identifier");for(var i=0,o=t.torrents.length;i<o;i++){var s=t.torrents[i];if(s.infoHash===r.infoHash)return s}return null};x.prototype.add=x.prototype.download=function(e,t,n){var i=this;if(i.destroyed)throw new Error("client is destroyed");if(typeof t==="function")return i.add(e,null,t);s("add");t=t?u(t):{};var o=i.get(e);if(o){if(o.ready)r.nextTick(a);else o.once("ready",a)}else{o=new b(e,i,t);i.torrents.push(o);o.once("error",function(e){i.emit("error",e,o);i.remove(o)});o.once("listening",function(e){i.emit("listening",e,o)});o.once("ready",a)}function a(){s("on torrent");if(typeof n==="function")n(o);i.emit("torrent",o)}return o};x.prototype.seed=function(e,t,r){var n=this;if(n.destroyed)throw new Error("client is destroyed");if(typeof t==="function")return n.seed(e,null,t);s("seed");t=t?u(t):{};if(typeof e==="string")t.path=m.dirname(e);if(!t.createdBy)t.createdBy="WebTorrent/"+E;if(!n.tracker)t.announce=[];var i=n.add(null,t,f);var a;if(!Array.isArray(e))e=[e];h(e.map(function(e){return function(t){if(S(e))_(e,t);else t(null,e)}}),function(e,r){if(e)return n.emit("error",e,i);if(n.destroyed)return;o.parseInput(r,t,function(e,s){if(e)return n.emit("error",e,i);if(n.destroyed)return;a=s.map(function(e){return e.getStream});o(r,t,function(e,t){if(e)return n.emit("error",e,i);if(n.destroyed)return;var r=n.get(t);if(r){i.destroy();c(r)}else{i._onTorrentId(t)}})})});function f(e){var t=[function(t){e.load(a,t)}];if(n.dht){t.push(function(t){e.once("dhtAnnounce",t)})}h(t,function(t){if(n.destroyed)return;if(t)return n.emit("error",t,e);c(e)})}function c(e){s("on seed");if(typeof r==="function")r(e);n.emit("seed",e)}return i};x.prototype.remove=function(e,t){var r=this;s("remove");var n=r.get(e);if(!n)throw new Error("No torrent with id "+e);r.torrents.splice(r.torrents.indexOf(n),1);n.destroy(t)};x.prototype.address=function(){var e=this;return{address:"0.0.0.0",family:"IPv4",port:e.torrentPort}};x.prototype.destroy=function(e){var t=this;if(t.destroyed)throw new Error("client already destroyed");t.destroyed=true;s("destroy");var r=t.torrents.map(function(e){return function(r){t.remove(e,r)}});if(t.dht)r.push(function(e){t.dht.destroy(e)});h(r,e)};function S(e){return typeof e==="object"&&e!=null&&typeof e.pipe==="function"}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{},e("buffer").Buffer)},{"./lib/concat-stream":1,"./lib/torrent":5,"./package.json":159,_process:34,"bittorrent-dht/client":25,buffer:26,"create-torrent":54,debug:71,events:30,hat:77,inherits:79,"load-ip-set":25,"parse-torrent":82,path:33,"run-parallel":130,"simple-peer":134,speedometer:141,xtend:156,"zero-fill":158}]},{},[160])(160)}); +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.WebTorrent=e()}}(function(){var e;return function t(e,n,r){function i(s,a){if(!n[s]){if(!e[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(o)return o(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var f=n[s]={exports:{}};e[s][0].call(f.exports,function(t){var n=e[s][1][t];return i(n?n:t)},f,f.exports,t,e,n,r)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s<r.length;s++)i(r[s]);return i}({1:[function(e,t,n){(function(e){t.exports=function(t,n){var r=[];t.on("data",function(e){r.push(e)}),t.once("end",function(){n&&n(null,e.concat(r)),n=null}),t.once("error",function(e){n&&n(e),n=null})}}).call(this,e("buffer").Buffer)},{buffer:26}],2:[function(e,t,n){function r(e,t){s.Readable.call(this,t),this.destroyed=!1,this._torrent=e._torrent;var n=t&&t.start||0,r=t&&t.end&&t.end<e.length?t.end:e.length-1,i=e._torrent.pieceLength;this._startPiece=(n+e.offset)/i|0,this._endPiece=(r+e.offset)/i|0,this._piece=this._startPiece,this._offset=n+e.offset-this._startPiece*i,this._missing=r-n+1,this._reading=!1,this._notifying=!1,this._criticalLength=Math.min(1048576/i|0,2)}t.exports=r;var i=e("debug")("webtorrent:file-stream"),o=e("inherits"),s=e("readable-stream");o(r,s.Readable),r.prototype._read=function(){this._reading||(this._reading=!0,this._notify())},r.prototype._notify=function(){var e=this;if(e._reading&&0!==e._missing){if(!e._torrent.bitfield.get(e._piece))return e._torrent.critical(e._piece,e._piece+e._criticalLength);if(!e._notifying){e._notifying=!0;var t=e._piece;e._torrent.store.get(t,function(n,r){if(e._notifying=!1,!e.destroyed){if(n)return e.destroy(n);i("read %s (length %s) (err %s)",t,r.length,n&&n.message),e._offset&&(r=r.slice(e._offset),e._offset=0),e._missing<r.length&&(r=r.slice(0,e._missing)),e._missing-=r.length,i("pushing buffer of length %s",r.length),e._reading=!1,e.push(r),0===e._missing&&e.push(null)}}),e._piece+=1}}},r.prototype.destroy=function(){this.destroyed||(this.destroyed=!0,this._torrent.destroyed||this._torrent.deselect(this._startPiece,this._endPiece,!0))}},{debug:71,inherits:79,"readable-stream":109}],3:[function(e,t,n){(function(n){function r(e,t){o.call(this),this._torrent=e,this.name=t.name,this.path=t.path,this.length=t.length,this.offset=t.offset,this.done=!1;var n=t.offset,r=n+t.length-1;this._startPiece=n/this._torrent.pieceLength|0,this._endPiece=r/this._torrent.pieceLength|0,0===this.length&&(this.done=!0,this.emit("done"))}t.exports=r;var i=e("end-of-stream"),o=e("events").EventEmitter,s=e("./file-stream"),a=e("inherits"),u=e("path"),c=e("render-media"),f=e("readable-stream"),d=e("stream-to-blob-url"),h=e("stream-with-known-length-to-buffer");a(r,o),r.prototype.select=function(e){0!==this.length&&this._torrent.select(this._startPiece,this._endPiece,e)},r.prototype.deselect=function(){0!==this.length&&this._torrent.deselect(this._startPiece,this._endPiece,!1)},r.prototype.createReadStream=function(e){var t=this;if(0===this.length){var r=new f.PassThrough;return n.nextTick(function(){r.end()}),r}var o=new s(t,e);return t._torrent.select(o._startPiece,o._endPiece,!0,function(){o._notify()}),i(o,function(){t._torrent.deselect(o._startPiece,o._endPiece,!0)}),o},r.prototype.getBuffer=function(e){h(this.createReadStream(),this.length,e)},r.prototype.getBlobURL=function(e){if("undefined"==typeof window)throw new Error("browser-only method");var t=c.mime[u.extname(this.name).toLowerCase()];d(this.createReadStream(),t,e)},r.prototype.appendTo=function(e,t){if("undefined"==typeof window)throw new Error("browser-only method");c.append(this,e,t)},r.prototype.renderTo=function(e,t){if("undefined"==typeof window)throw new Error("browser-only method");c.render(this,e,t)}}).call(this,e("_process"))},{"./file-stream":2,_process:34,"end-of-stream":74,events:30,inherits:79,path:33,"readable-stream":109,"render-media":112,"stream-to-blob-url":142,"stream-with-known-length-to-buffer":145}],4:[function(e,t,n){function r(e,t){function n(e){e.on("have",function(e){r.pieces[e]+=1}),e.on("bitfield",function(){r.recalculate()}),e.on("close",function(){for(var t=0;t<r.numPieces;++t)r.pieces[t]-=e.peerPieces.get(t)})}var r=this;r.pieces=[],r.swarm=e,r.numPieces=t,r.swarm.wires.forEach(n),r.swarm.on("wire",function(e){r.recalculate(),n(e)}),r.recalculate()}t.exports=r,r.prototype.recalculate=function(){for(var e=this,t=0;t<e.numPieces;++t)e.pieces[t]=0;e.swarm.wires.forEach(function(t){for(var n=0;n<e.numPieces;++n)e.pieces[n]+=t.peerPieces.get(n)})},r.prototype.getRarestPiece=function(e){var t=this,n=[],r=1/0;e=e||function(){return!0};for(var i=0;i<t.numPieces;++i)if(e(i)){var o=t.pieces[i];o===r?n.push(i):r>o&&(n=[i],r=o)}return n.length>0?n[Math.random()*n.length|0]:-1}},{}],5:[function(e,t,n){(function(n,r){function i(e,t,n){m.call(this),l.enabled||this.setMaxListeners(0),this.client=t,this._debugId=this.client.peerId.slice(32),this._debug("new torrent"),this.announce=n.announce,this.urlList=n.urlList,this.path=n.path,this._store=n.store||y,this.strategy=n.strategy||"sequential",this._rechokeNumSlots=n.uploads===!1||0===n.uploads?0:+n.uploads||10,this._rechokeOptimisticWire=null,this._rechokeOptimisticTime=0,this._rechokeIntervalId=null,this.ready=!1,this.destroyed=!1,this.metadata=null,this.store=null,this.numBlockedPeers=0,this.files=null,this.done=!1,this._amInterested=!1,this.pieces=[],this._selections=[],this._critical=[],this._servers=[],null!=e&&this._onTorrentId(e)}function o(e,t){return Math.ceil(2+t*e.downloadSpeed()/I.BLOCK_LENGTH)}function s(e){return Math.random()*e|0}function a(){}t.exports=i;var u=e("addr-to-ip-port"),c=e("bitfield"),f=e("chunk-store-stream/write"),d=e("cpus"),h=e("create-torrent"),l=e("debug")("webtorrent:torrent"),p=e("torrent-discovery"),m=e("events").EventEmitter,g=e("xtend/mutable"),y=e("fs-chunk-store"),v=e("immediate-chunk-store"),_=e("inherits"),b=e("multistream"),w=e("os"),E=e("run-parallel"),k=e("run-parallel-limit"),x=e("parse-torrent"),S=e("path"),B=e("path-exists"),I=e("torrent-piece"),A=e("pump"),C=e("random-iterate"),T=e("re-emitter"),L=e("simple-sha1"),R=e("bittorrent-swarm"),U=e("uniq"),P=e("ut_metadata"),O=e("ut_pex"),M=e("./file"),j=e("./rarity-map"),D=e("./server"),H=131072,N=3e4,q=5e3,z=3*I.BLOCK_LENGTH,W=.5,F=1,Y=1e4,V=2,$="function"==typeof B.sync?S.join(B.sync("/tmp")?"/tmp":w.tmpDir(),"webtorrent"):"/tmp/webtorrent";_(i,m),Object.defineProperty(i.prototype,"timeRemaining",{get:function(){return this.done?0:this.swarm&&0!==this.swarm.downloadSpeed()?(this.length-this.downloaded)/this.swarm.downloadSpeed()*1e3:1/0}}),Object.defineProperty(i.prototype,"downloaded",{get:function(){if(!this.bitfield)return 0;for(var e=0,t=0,n=this.pieces.length;n>t;++t)if(this.bitfield.get(t))e+=t===n-1?this.lastPieceLength:this.pieceLength;else{var r=this.pieces[t];e+=r.length-r.missing}return e}}),Object.defineProperty(i.prototype,"received",{get:function(){return this.swarm?this.swarm.downloaded:0}}),Object.defineProperty(i.prototype,"uploaded",{get:function(){return this.swarm?this.swarm.uploaded:0}}),Object.defineProperty(i.prototype,"progress",{get:function(){return this.length?this.downloaded/this.length:0}}),Object.defineProperty(i.prototype,"ratio",{get:function(){return this.uploaded/(this.downloaded||1)}}),Object.defineProperty(i.prototype,"downloadSpeed",{get:function(){return this.swarm?this.swarm.downloadSpeed():0}}),Object.defineProperty(i.prototype,"uploadSpeed",{get:function(){return this.swarm?this.swarm.uploadSpeed():0}}),Object.defineProperty(i.prototype,"numPeers",{get:function(){return this.swarm?this.swarm.numPeers:0}}),Object.defineProperty(i.prototype,"torrentFileBlobURL",{get:function(){if("undefined"==typeof window)throw new Error("browser-only property");return this.torrentFile?URL.createObjectURL(new Blob([this.torrentFile],{type:"application/x-bittorrent"})):null}}),i.prototype._onTorrentId=function(e){var t=this;t.destroyed||x.remote(e,function(e,n){return t.destroyed?void 0:e?t._onError(e):void t._onParsedTorrent(n)})},i.prototype._onParsedTorrent=function(e){var t=this;if(!t.destroyed){if(t._processParsedTorrent(e),!t.infoHash)return t._onError(new Error("Malformed torrent data: No info hash"));t.path||(t.path=S.join($,t.infoHash)),t.swarm=new R(t.infoHash,t.client.peerId,{handshake:{dht:t["private"]?!1:!!t.client.dht},maxConns:t.client.maxConns}),t.swarm.on("error",t._onError.bind(t)),t.swarm.on("wire",t._onWire.bind(t)),t.swarm.on("download",function(e){t.client._downloadSpeed(e),t.client.emit("download",e),t.emit("download",e)}),t.swarm.on("upload",function(e){t.client._uploadSpeed(e),t.client.emit("upload",e),t.emit("upload",e)}),t.swarm.listen(t.client.torrentPort,t._onSwarmListening.bind(t)),t.emit("infoHash",t.infoHash)}},i.prototype._processParsedTorrent=function(e){this.announce&&(e.announce=e.announce.concat(this.announce)),this.client.tracker&&0===e.announce.length&&(e.announce=h.announceList.map(function(e){return e[0]})),this.client.tracker&&r.WEBTORRENT_ANNOUNCE&&(e.announce=e.announce.concat(r.WEBTORRENT_ANNOUNCE)),this.urlList&&(e.urlList=e.urlList.concat(this.urlList)),U(e.announce),U(e.urlList),g(this,e),this.magnetURI=x.toMagnetURI(e),this.torrentFile=x.toTorrentFile(e)},i.prototype._onSwarmListening=function(){var e=this;e.destroyed||(e.swarm.server&&(e.client.torrentPort=e.swarm.address().port),e.discovery=new p({announce:e.announce,dht:e["private"]?!1:e.client.dht,tracker:e.client.tracker,peerId:e.client.peerId,port:e.client.torrentPort,rtcConfig:e.client._rtcConfig,wrtc:e.client._wrtc}),e.discovery.on("error",e._onError.bind(e)),e.discovery.on("peer",e.addPeer.bind(e)),T(e.discovery,e,["trackerAnnounce","dhtAnnounce","warning"]),e.info?e._onMetadata(e):e.discovery.setTorrent(e.infoHash),e.emit("listening",e.client.torrentPort))},i.prototype._onMetadata=function(e){var t=this;if(!t.metadata&&!t.destroyed){t._debug("got metadata");var n;if(e&&e.infoHash)n=e;else try{n=x(e)}catch(r){return t._onError(r)}t._processParsedTorrent(n),t.metadata=t.torrentFile,t.discovery.setTorrent(t),t.urlList&&t.urlList.forEach(t.addWebSeed.bind(t)),t.rarityMap=new j(t.swarm,t.pieces.length),t.store=new v(new t._store(t.pieceLength,{files:t.files.map(function(e){return{path:S.join(t.path,e.path),length:e.length,offset:e.offset}}),length:t.length})),t.files=t.files.map(function(e){return new M(t,e)}),t._hashes=t.pieces,t.pieces=t.pieces.map(function(e,n){var r=n===t.pieces.length-1?t.lastPieceLength:t.pieceLength;return new I(r)}),t._reservations=t.pieces.map(function(){return[]}),t.bitfield=new c(t.pieces.length),t.swarm.wires.forEach(function(e){e.ut_metadata&&e.ut_metadata.setMetadata(t.metadata),t._onWireWithMetadata(e)}),t._debug("verifying existing torrent data"),k(t.pieces.map(function(e,n){return function(e){t.store.get(n,function(r,i){return r?e(null):void L(i,function(r){if(r===t._hashes[n]){if(!t.pieces[n])return;t._debug("piece verified %s",n),t.pieces[n]=null,t._reservations[n]=null,t.bitfield.set(n,!0)}else t._debug("piece invalid %s",n);e(null)})})}}),d().length,function(e){return e?t._onError(e):(t._debug("done verifying"),void t._onStore())}),t.emit("metadata")}},i.prototype._onStore=function(){var e=this;e.destroyed||(e._debug("on store"),e.select(0,e.pieces.length-1,!1),e._rechokeIntervalId=setInterval(e._rechoke.bind(e),Y),e._rechokeIntervalId.unref&&e._rechokeIntervalId.unref(),e.ready=!0,e.emit("ready"),e._checkDone())},i.prototype.destroy=function(e){var t=this;if(!t.destroyed){t.destroyed=!0,t._debug("destroy"),t.client.remove(t),t._rechokeIntervalId&&(clearInterval(t._rechokeIntervalId),t._rechokeIntervalId=null);var n=[];t._servers.forEach(function(e){n.push(function(t){e.destroy(t)})}),t.swarm&&n.push(function(e){t.swarm.destroy(e)}),t.discovery&&n.push(function(e){t.discovery.stop(e)}),t.store&&n.push(function(e){t.store.close(e)}),E(n,e)}},i.prototype.addPeer=function(e){function t(){n.swarm.addPeer(e),n.emit("peer",e)}var n=this;if(n.destroyed)throw new Error("torrent is destroyed");if(n.client.blocked){var r="string"==typeof e?e:e.remoteAddress;if(r&&n.client.blocked.contains(u(r)[0]))return n.numBlockedPeers+=1,n.emit("blockedPeer",e),!1}return n.swarm?t():n.once("listening",t),!0},i.prototype.addWebSeed=function(e){if(this.destroyed)throw new Error("torrent is destroyed");this._debug("add web seed %s",e),this.swarm.addWebSeed(e,this)},i.prototype.select=function(e,t,n,r){var i=this;if(i.destroyed)throw new Error("torrent is destroyed");if(e>t||0>e||t>=i.pieces.length)throw new Error("invalid selection ",e,":",t);n=Number(n)||0,i._debug("select %s-%s (priority %s)",e,t,n),i._selections.push({from:e,to:t,offset:0,priority:n,notify:r||a}),i._selections.sort(function(e,t){return t.priority-e.priority}),i._updateSelections()},i.prototype.deselect=function(e,t,n){var r=this;if(r.destroyed)throw new Error("torrent is destroyed");n=Number(n)||0,r._debug("deselect %s-%s (priority %s)",e,t,n);for(var i=0;i<r._selections.length;++i){var o=r._selections[i];if(o.from===e&&o.to===t&&o.priority===n){r._selections.splice(i--,1);break}}r._updateSelections()},i.prototype.critical=function(e,t){var n=this;if(n.destroyed)throw new Error("torrent is destroyed");n._debug("critical %s-%s",e,t);for(var r=e;t>=r;++r)n._critical[r]=!0;n._updateSelections()},i.prototype._onWire=function(e,t){var r=this;if(r._debug("got wire %s (%s)",e._debugId,t||"Unknown"),t){var i=u(t);e.remoteAddress=i[0],e.remotePort=i[1]}r.client.dht&&r.client.dht.listening&&e.on("port",function(n){if(!r.destroyed&&!r.client.dht.destroyed){if(!e.remoteAddress)return r._debug("ignoring PORT from peer with no address");if(0===n||n>65536)return r._debug("ignoring invalid PORT from peer");r._debug("port: %s (from %s)",n,t),r.client.dht.addNode({host:e.remoteAddress,port:n})}}),e.on("timeout",function(){r._debug("wire timeout (%s)",t),e.destroy()}),e.setTimeout(N,!0),e.setKeepAlive(!0),e.use(P(r.metadata)),e.ut_metadata.on("warning",function(e){r._debug("ut_metadata warning: %s",e.message)}),r.metadata||(e.ut_metadata.on("metadata",function(e){r._debug("got metadata via ut_metadata"),r._onMetadata(e)}),e.ut_metadata.fetch()),"function"!=typeof O||r["private"]||(e.use(O()),e.ut_pex.on("peer",function(e){r._debug("ut_pex: got peer: %s (from %s)",e,t),r.addPeer(e)}),e.ut_pex.on("dropped",function(e){var n=r.swarm._peers[e];n&&!n.connected&&(r._debug("ut_pex: dropped peer: %s (from %s)",e,t),r.swarm.removePeer(e))})),r.emit("wire",e,t),r.metadata&&n.nextTick(function(){r._onWireWithMetadata(e)})},i.prototype._onWireWithMetadata=function(e){function t(){r.destroyed||e.destroyed||(r.swarm.numQueued>2*(r.swarm.numConns-r.swarm.numPeers)&&e.amInterested?e.destroy():(i=setTimeout(t,q),i.unref&&i.unref()))}function n(){if(e.peerPieces.length===r.pieces.length){for(;o<r.pieces.length;++o)if(!e.peerPieces.get(o))return;e.isSeeder=!0,e.choke()}}var r=this,i=null,o=0;e.on("bitfield",function(){n(),r._update()}),e.on("have",function(){n(),r._update()}),e.once("interested",function(){e.unchoke()}),e.on("close",function(){clearTimeout(i)}),e.on("choke",function(){clearTimeout(i),i=setTimeout(t,q),i.unref&&i.unref()}),e.on("unchoke",function(){clearTimeout(i),r._update()}),e.on("request",function(t,n,i,o){return i>H?e.destroy():void(r.pieces[t]||r.store.get(t,{offset:n,length:i},o))}),e.bitfield(r.bitfield),e.interested(),e.peerExtensions.dht&&r.client.dht&&r.client.dht.listening&&e.port(r.client.dht.address().port),i=setTimeout(t,q),i.unref&&i.unref(),e.isSeeder=!1,n()},i.prototype._updateSelections=function(){var e=this;if(e.swarm&&!e.destroyed){if(!e.metadata)return e.once("metadata",e._updateSelections.bind(e));n.nextTick(e._gcSelections.bind(e)),e._updateInterest(),e._update()}},i.prototype._gcSelections=function(){for(var e=this,t=0;t<e._selections.length;t++){for(var n=e._selections[t],r=n.offset;e.bitfield.get(n.from+n.offset)&&n.from+n.offset<n.to;)n.offset++;r!==n.offset&&n.notify(),n.to===n.from+n.offset&&e.bitfield.get(n.from+n.offset)&&(e._selections.splice(t--,1),n.notify(),e._updateInterest())}e._selections.length||e.emit("idle")},i.prototype._updateInterest=function(){var e=this,t=e._amInterested;e._amInterested=!!e._selections.length,e.swarm.wires.forEach(function(t){e._amInterested?t.interested():t.uninterested()}),t!==e._amInterested&&(e._amInterested?e.emit("interested"):e.emit("uninterested"))},i.prototype._update=function(){var e=this;if(!e.destroyed)for(var t,n=C(e.swarm.wires);t=n();)e._updateWire(t)},i.prototype._updateWire=function(e){function t(t,n,r,i){return function(o){return o>=t&&n>=o&&!(o in r)&&e.peerPieces.get(o)&&(!i||i(o))}}function n(){if(!e.requests.length)for(var n=a._selections.length;n--;){var r,i=a._selections[n];if("rarest"===a.strategy)for(var o=i.from+i.offset,s=i.to,u=s-o+1,c={},f=0,d=t(o,s,c);u>f&&(r=a.rarityMap.getRarestPiece(d),!(0>r));){if(a._request(e,r,!1))return;c[r]=!0,f+=1}else for(r=i.to;r>=i.from+i.offset;--r)if(e.peerPieces.get(r)&&a._request(e,r,!1))return}}function r(){var t=e.downloadSpeed()||1;if(t>z)return function(){return!0};var n=Math.max(1,e.requests.length)*I.BLOCK_LENGTH/t,r=10,i=0;return function(e){if(!r||a.bitfield.get(e))return!0;for(var o=a.pieces[e].missing;i<a.swarm.wires.length;i++){var s=a.swarm.wires[i],u=s.downloadSpeed();if(!(z>u)&&!(t>=u)&&s.peerPieces.get(e)&&!((o-=u*n)>0))return r--,!1}return!0}}function i(e){for(var t=e,n=e;n<a._selections.length&&a._selections[n].priority;n++)t=n;var r=a._selections[e];a._selections[e]=a._selections[t],a._selections[t]=r}function s(n){if(e.requests.length>=c)return!0;for(var o=r(),s=0;s<a._selections.length;s++){var u,f=a._selections[s];if("rarest"===a.strategy)for(var d=f.from+f.offset,h=f.to,l=h-d+1,p={},m=0,g=t(d,h,p,o);l>m&&(u=a.rarityMap.getRarestPiece(g),!(0>u));){for(;a._request(e,u,a._critical[u]||n););if(!(e.requests.length<c))return f.priority&&i(s),!0;p[u]=!0,m++}else for(u=f.from+f.offset;u<=f.to;u++)if(e.peerPieces.get(u)&&o(u)){for(;a._request(e,u,a._critical[u]||n););if(!(e.requests.length<c))return f.priority&&i(s),!0}}return!1}var a=this;if(!e.peerChoking){if(!e.downloaded)return n();var u=o(e,W);if(!(e.requests.length>=u)){var c=o(e,F);s(!1)||s(!0)}}},i.prototype._rechoke=function(){function e(e,t){return e.downloadSpeed!==t.downloadSpeed?t.downloadSpeed-e.downloadSpeed:e.uploadSpeed!==t.uploadSpeed?t.uploadSpeed-e.uploadSpeed:e.wire.amChoking!==t.wire.amChoking?e.wire.amChoking?1:-1:e.salt-t.salt}var t=this;t._rechokeOptimisticTime>0?t._rechokeOptimisticTime-=1:t._rechokeOptimisticWire=null;var n=[];t.swarm.wires.forEach(function(e){e.isSeeder||e===t._rechokeOptimisticWire||n.push({wire:e,downloadSpeed:e.downloadSpeed(),uploadSpeed:e.uploadSpeed(),salt:Math.random(),isChoked:!0})}),n.sort(e);for(var r=0,i=0;i<n.length&&r<t._rechokeNumSlots;++i)n[i].isChoked=!1,n[i].wire.peerInterested&&(r+=1);if(!t._rechokeOptimisticWire&&i<n.length&&t._rechokeNumSlots){var o=n.slice(i).filter(function(e){return e.wire.peerInterested}),a=o[s(o.length)];a&&(a.isChoked=!1,t._rechokeOptimisticWire=a.wire,t._rechokeOptimisticTime=V)}n.forEach(function(e){e.wire.amChoking!==e.isChoked&&(e.isChoked?e.wire.choke():e.wire.unchoke())})},i.prototype._hotswap=function(e,t){var n=this,r=e.downloadSpeed();if(r<I.BLOCK_LENGTH)return!1;if(!n._reservations[t])return!1;var i=n._reservations[t];if(!i)return!1;var o,s,a=1/0;for(s=0;s<i.length;s++){var u=i[s];if(u&&u!==e){var c=u.downloadSpeed();c>=z||2*c>r||c>a||(o=u,a=c)}}if(!o)return!1;for(s=0;s<i.length;s++)i[s]===o&&(i[s]=null);for(s=0;s<o.requests.length;s++){var f=o.requests[s];f.piece===t&&n.pieces[t].cancel(f.offset/I.BLOCK_SIZE|0)}return n.emit("hotswap",o,e,t),!0},i.prototype._request=function(e,t,r){function i(){n.nextTick(function(){s._update()})}var s=this,a=e.requests.length;if(s.bitfield.get(t))return!1;var u=o(e,F);if(a>=u)return!1;var c=s.pieces[t],f=c.reserve();if(-1===f&&r&&s._hotswap(e,t)&&(f=c.reserve()),-1===f)return!1;var d=s._reservations[t];d||(d=s._reservations[t]=[]);var h=d.indexOf(null);-1===h&&(h=d.length),d[h]=e;var l=c.chunkOffset(f),p=c.chunkLength(f);return e.request(t,l,p,function m(n,r){if(!s.ready)return s.once("ready",function(){m(n,r)});if(d[h]===e&&(d[h]=null),c!==s.pieces[t])return i();if(n)return s._debug("error getting piece %s (offset: %s length: %s) from %s: %s",t,l,p,e.remoteAddress+":"+e.remotePort,n.message),c.cancel(f),void i();if(s._debug("got piece %s (offset: %s length: %s) from %s",t,l,p,e.remoteAddress+":"+e.remotePort),!c.set(f,r,e))return i();var o=c.flush();L(o,function(e){if(e===s._hashes[t]){if(!s.pieces[t])return;s._debug("piece verified %s",t),s.pieces[t]=null,s._reservations[t]=null,s.bitfield.set(t,!0),s.store.put(t,o),s.swarm.wires.forEach(function(e){e.have(t)}),s._checkDone()}else s.pieces[t]=new I(c.length),s.emit("warning",new Error("Piece "+t+" failed verification"));i()})}),!0},i.prototype._checkDone=function(){var e=this;if(!e.destroyed){e.files.forEach(function(t){if(!t.done){for(var n=t._startPiece;n<=t._endPiece;++n)if(!e.bitfield.get(n))return;t.done=!0,t.emit("done"),e._debug("file done: "+t.name)}});for(var t=!0,n=0;n<e._selections.length;n++){for(var r=e._selections[n],i=r.from;i<=r.to;i++)if(!e.bitfield.get(i)){t=!1;break}if(!t)break}!e.done&&t&&(e.done=!0,e.emit("done"),e._debug("torrent done: "+e.infoHash),e.discovery.tracker&&e.discovery.tracker.complete()),e._gcSelections()}},i.prototype.load=function(e,t){var n=this;if(n.destroyed)throw new Error("torrent is destroyed");if(!n.ready)return n.once("ready",function(){n.load(e,t)});Array.isArray(e)||(e=[e]),t||(t=a);var r=new b(e),i=new f(n.store,n.pieceLength);A(r,i,function(e){return e?t(e):(n.pieces.forEach(function(e,t){n.pieces[t]=null,n._reservations[t]=null,n.bitfield.set(t,!0)}),n._checkDone(),void t(null))})},i.prototype.createServer=function(e){if("function"!=typeof D)throw new Error("node.js-only method");if(this.destroyed)throw new Error("torrent is destroyed");var t=new D(this,e);return this._servers.push(t),t},i.prototype.pause=function(){this.destroyed||this.swarm.pause()},i.prototype.resume=function(){this.destroyed||this.swarm.resume()},i.prototype._onError=function(e){var t=this;t._debug("torrent error: %s",e.message||e),t.emit("error",e),t.destroy()},i.prototype._debug=function(){var e=[].slice.call(arguments);e[0]="["+this._debugId+"] "+e[0],l.apply(null,e)}}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./file":3,"./rarity-map":4,"./server":25,_process:34,"addr-to-ip-port":6,bitfield:7,"bittorrent-swarm":8,"chunk-store-stream/write":52,cpus:53,"create-torrent":54,debug:71,events:30,"fs-chunk-store":80,"immediate-chunk-store":78,inherits:79,multistream:81,os:25,"parse-torrent":82,path:33,"path-exists":25,pump:92,"random-iterate":95,"re-emitter":96,"run-parallel":130,"run-parallel-limit":129,"simple-sha1":139,"torrent-discovery":148,"torrent-piece":149,uniq:150,ut_metadata:151,ut_pex:25,"xtend/mutable":157}],6:[function(e,t,n){var r=/^\[?([^\]]+)\]?:(\d+)$/,i={},o=0;t.exports=function(e){if(1e5===o&&t.exports.reset(),!i[e]){var n=r.exec(e);if(!n)throw new Error("invalid addr: "+e);i[e]=[n[1],Number(n[2])],o+=1}return i[e]},t.exports.reset=function(){i={},o=0}},{}],7:[function(e,t,n){(function(e){function n(e,t){return this instanceof n?(0===arguments.length&&(e=0),this.grow=t&&(isFinite(t.grow)&&r(t.grow)||t.grow)||0,("number"==typeof e||void 0===e)&&(e=new i(r(e)),e.fill&&!e._isBuffer&&e.fill(0)),void(this.buffer=e)):new n(e,t)}function r(e){var t=e>>3;return e%8!==0&&t++,t}var i="undefined"!=typeof e?e:"undefined"!=typeof Int8Array?Int8Array:function(e){for(var t=new Array(e),n=0;e>n;n++)t[n]=0};n.prototype.get=function(e){var t=e>>3;return t<this.buffer.length&&!!(this.buffer[t]&128>>e%8)},n.prototype.set=function(e,t){var n=e>>3;t||1===arguments.length?(this.buffer.length<n+1&&this._grow(Math.max(n+1,Math.min(2*this.buffer.length,this.grow))),this.buffer[n]|=128>>e%8):n<this.buffer.length&&(this.buffer[n]&=~(128>>e%8))},n.prototype._grow=function(e){if(this.buffer.length<e&&e<=this.grow){var t=new i(e);if(t.fill&&t.fill(0),this.buffer.copy)this.buffer.copy(t,0);else for(var n=0;n<this.buffer.length;n++)t[n]=this.buffer[n];this.buffer=t}},"undefined"!=typeof t&&(t.exports=n)}).call(this,e("buffer").Buffer)},{buffer:26}],8:[function(e,t,n){(function(n,r){function i(e,t,n){var o=this;return o instanceof i?(a.call(o),o.infoHash="string"==typeof e?e:e.toString("hex"),o.infoHashBuffer=new r(o.infoHash,"hex"),o.peerId="string"==typeof t?t:t.toString("hex"),o.peerIdBuffer=new r(o.peerId,"hex"),n||(n={}),s("new swarm (i %s p %s)",o.infoHash,o.peerId),o.handshakeOpts=n.handshake,o.maxConns=Number(n.maxConns)||l,o.destroyed=!1,o.listening=!1,o.paused=!1,o.server=null,o.wires=[],o._queue=[],o._peers={},o._peersLength=0,o._port=0,o.downloaded=0,o.uploaded=0,o.downloadSpeed=f(),void(o.uploadSpeed=f())):new i(e,t,n)}t.exports=i;var o=e("addr-to-ip-port"),s=e("debug")("bittorrent-swarm"),a=e("events").EventEmitter,u=e("inherits"),c=e("net"),f=e("speedometer"),d=e("./lib/peer"),h=e("./lib/tcp-pool"),l=55,p=[1e3,5e3,15e3];u(i,a),Object.defineProperty(i.prototype,"ratio",{get:function(){var e=this;return e.uploaded/e.downloaded||0}}),Object.defineProperty(i.prototype,"numQueued",{get:function(){var e=this;return e._queue.length+(e._peersLength-e.numConns)}}),Object.defineProperty(i.prototype,"numConns",{get:function(){var e=this,t=0;for(var n in e._peers){var r=e._peers[n];r&&r.connected&&(t+=1)}return t}}),Object.defineProperty(i.prototype,"numPeers",{get:function(){var e=this;return e.wires.length}}),i.prototype.addPeer=function(e){var t=this;t._addPeer(e)},i.prototype._addPeer=function(e){var t=this;if(t.destroyed)return e&&e.destroy&&e.destroy(new Error("swarm already destroyed")),null;if("string"==typeof e&&!t._validAddr(e))return s("ignoring invalid peer %s (from swarm.addPeer)",e),null;var n=e&&e.id||e;if(!t._peers[n]){s("addPeer %s",n);var r;if("string"==typeof e)r=d.createOutgoingTCPPeer(e,t);else{if(t.paused)return e.destroy(new Error("swarm paused")),null;r=d.createWebRTCPeer(e,t)}return t._peers[r.id]=r,t._peersLength+=1,"string"==typeof e&&(t._queue.push(r),t._drain()),r}},i.prototype.addWebSeed=function(e,t){var n=this;if(!n.destroyed){if(!/^https?:\/\/.+/.test(e))return void s("ignoring invalid web seed %s (from swarm.addWebSeed)",e);if(!n._peers[e]){s("addWebSeed %s",e);var r=d.createWebPeer(e,t,n);n._peers[r.id]=r,n._peersLength+=1}}},i.prototype._addIncomingPeer=function(e){var t=this;return t.destroyed?e.destroy(new Error("swarm already destroyed")):t.paused?e.destroy(new Error("swarm paused")):t._validAddr(e.addr)?(s("_addIncomingPeer %s",e.id),t._peers[e.id]=e,void(t._peersLength+=1)):e.destroy(new Error("invalid addr "+e.addr+" (from incoming)"))},i.prototype.removePeer=function(e){var t=this,n=t._peers[e];n&&(s("removePeer %s",e),t._peers[e]=null,t._peersLength-=1,n.destroy(),t._drain())},i.prototype.pause=function(){var e=this;e.destroyed||(s("pause"),e.paused=!0)},i.prototype.resume=function(){var e=this;e.destroyed||(s("resume"),e.paused=!1,e._drain())},i.prototype.listen=function(e,t,r){var i=this;if("function"==typeof t&&(r=t,t=void 0),i.listening)throw new Error("swarm already listening");if(r&&i.once("listening",r),"function"==typeof h){i._port=e||h.getDefaultListenPort(i.infoHash),i._hostname=t,s("listen %s",e);var o=h.addSwarm(i);i.server=o.server}else n.nextTick(function(){i._onListening(0)})},i.prototype._onListening=function(e){var t=this;t._port=e,t.listening=!0,t.emit("listening")},i.prototype.address=function(){var e=this;return e.listening?e.server?e.server.address():{port:0,family:"IPv4",address:"127.0.0.1"}:null},i.prototype.destroy=function(e){var t=this;if(!t.destroyed){t.destroyed=!0,t.listening=!1,t.paused=!1,e&&t.once("close",e),s("destroy");for(var r in t._peers)t.removePeer(r);"function"==typeof h?h.removeSwarm(t,function(){t.emit("close")}):n.nextTick(function(){t.emit("close")})}},i.prototype._drain=function(){var e=this;if(s("_drain numConns %s maxConns %s",e.numConns,e.maxConns),!("function"!=typeof c.connect||e.destroyed||e.paused||e.numConns>=e.maxConns)){s("drain (%s queued, %s/%s peers)",e.numQueued,e.numPeers,e.maxConns);var t=e._queue.shift();if(t){s("tcp connect attempt to %s",t.addr);var n=o(t.addr),r={host:n[0],port:n[1]};e._hostname&&(r.localAddress=e._hostname);var i=t.conn=c.connect(r);i.once("connect",function(){t.onConnect()}),i.once("error",function(e){t.destroy(e)}),t.setConnectTimeout(),i.on("close",function(){if(!e.destroyed){if(t.retries>=p.length)return void s("conn %s closed: will not re-add (max %s attempts)",t.addr,p.length);var n=p[t.retries];s("conn %s closed: will re-add to queue in %sms (attempt %s)",t.addr,n,t.retries+1);var r=setTimeout(function(){var n=e._addPeer(t.addr);n&&(n.retries=t.retries+1)},n);r.unref&&r.unref()}})}}},i.prototype._onError=function(e){var t=this;t.emit("error",e),t.destroy()},i.prototype._validAddr=function(e){var t=this,n=o(e),r=n[0],i=n[1];return i>0&&65535>i&&!("127.0.0.1"===r&&i===t._port)}}).call(this,e("_process"),e("buffer").Buffer)},{"./lib/peer":9,"./lib/tcp-pool":25,_process:34,"addr-to-ip-port":25,buffer:26,debug:71,events:30,inherits:79,net:25,speedometer:141}],9:[function(e,t,n){function r(e){var t=this;t.id=e,o("new Peer %s",e),t.addr=null,t.conn=null,t.swarm=null,t.wire=null,t.connected=!1,t.destroyed=!1,t.timeout=null,t.retries=0,t.sentHandshake=!1}function i(){}var o=e("debug")("bittorrent-swarm:peer"),s=e("./webconn"),a=e("bittorrent-protocol"),u=25e3,c=25e3;n.createWebRTCPeer=function(e,t){var n=new r(e.id);return n.conn=e,n.swarm=t,n.conn.connected?n.onConnect():(n.conn.once("connect",function(){n.onConnect()}),n.conn.once("error",function(e){n.destroy(e)}),n.setConnectTimeout()),n},n.createIncomingTCPPeer=function(e){var t=e.remoteAddress+":"+e.remotePort,n=new r(t);return n.conn=e,n.addr=t,n.onConnect(),n},n.createOutgoingTCPPeer=function(e,t){var n=new r(e);return n.addr=e,n.swarm=t,n},n.createWebPeer=function(e,t,n){var i=new r(e);return i.swarm=n,i.conn=new s(e,t),i.onConnect(),i},r.prototype.onConnect=function(){var e=this;if(!e.destroyed){e.connected=!0,o("Peer %s connected",e.id),clearTimeout(e.connectTimeout);var t=e.conn;t.once("end",function(){e.destroy()}),t.once("close",function(){e.destroy()}),t.once("finish",function(){e.destroy()}),t.once("error",function(t){e.destroy(t)});var n=e.wire=new a;n.once("end",function(){e.destroy()}),n.once("close",function(){e.destroy()}),n.once("finish",function(){e.destroy()}),n.once("error",function(t){e.destroy(t)}),n.once("handshake",function(t,n){e.onHandshake(t,n)}),e.setHandshakeTimeout(),t.pipe(n).pipe(t),e.swarm&&!e.sentHandshake&&e.handshake()}},r.prototype.onHandshake=function(e,t){var n=this;if(n.swarm){if(n.swarm.destroyed)return n.destroy(new Error("swarm already destroyed"));if(e!==n.swarm.infoHash)return n.destroy(new Error("unexpected handshake info hash for this swarm"));if(t===n.swarm.peerId)return n.destroy(new Error("refusing to handshake with self"));o("Peer %s got handshake %s",n.id,e),clearTimeout(n.handshakeTimeout),n.retries=0,n.wire.on("download",function(e){n.destroyed||(n.swarm.downloaded+=e,n.swarm.downloadSpeed(e),n.swarm.emit("download",e))}),n.wire.on("upload",function(e){n.destroyed||(n.swarm.uploaded+=e,n.swarm.uploadSpeed(e),n.swarm.emit("upload",e))}),n.swarm.wires.push(n.wire);var r=n.addr;!r&&n.conn.remoteAddress&&(r=n.conn.remoteAddress+":"+n.conn.remotePort),n.swarm.emit("wire",n.wire,r),n.swarm&&!n.swarm.destroyed&&(n.sentHandshake||n.handshake())}},r.prototype.handshake=function(){var e=this;e.wire.handshake(e.swarm.infoHash,e.swarm.peerId,e.swarm.handshakeOpts),e.sentHandshake=!0},r.prototype.setConnectTimeout=function(){var e=this; +clearTimeout(e.connectTimeout),e.connectTimeout=setTimeout(function(){e.destroy(new Error("connect timeout"))},u),e.connectTimeout.unref&&e.connectTimeout.unref()},r.prototype.setHandshakeTimeout=function(){var e=this;clearTimeout(e.handshakeTimeout),e.handshakeTimeout=setTimeout(function(){e.destroy(new Error("handshake timeout"))},c),e.handshakeTimeout.unref&&e.handshakeTimeout.unref()},r.prototype.destroy=function(e){var t=this;if(!t.destroyed){t.destroyed=!0,t.connected=!1,o("destroy %s (error: %s)",t.id,e&&(e.message||e)),clearTimeout(t.connectTimeout),clearTimeout(t.handshakeTimeout);var n=t.swarm,r=t.conn,s=t.wire;if(t.conn=null,t.swarm=null,t.wire=null,n&&s){var a=n.wires.indexOf(s);a>=0&&n.wires.splice(a,1)}r&&(r.on("error",i),r.destroy()),s&&s.destroy(),n&&n.removePeer(t.id)}}},{"./webconn":10,"bittorrent-protocol":11,debug:71}],10:[function(e,t,n){function r(e,t){var n=this;c.call(this),n.url=e,n.webPeerId=u.sync(e),n.parsedTorrent=t,n.setKeepAlive(!0),n.on("handshake",function(e,t){n.handshake(e,n.webPeerId);for(var r=n.parsedTorrent.pieces.length,o=new i(r),s=0;r>=s;s++)o.set(s,!0);n.bitfield(o)}),n.on("choke",function(){o("choke")}),n.on("unchoke",function(){o("unchoke")}),n.once("interested",function(){o("interested"),n.unchoke()}),n.on("uninterested",function(){o("uninterested")}),n.on("bitfield",function(){o("bitfield")}),n.on("request",function(e,t,r,i){o("request pieceIndex=%d offset=%d length=%d",e,t,r),n.httpRequest(e,t,r,i)})}t.exports=r;var i=e("bitfield"),o=e("debug")("bittorrent-swarm:webconn"),s=e("simple-get"),a=e("inherits"),u=e("simple-sha1"),c=e("bittorrent-protocol");a(r,c),r.prototype.httpRequest=function(e,t,n,r){var i=this,a=e*i.parsedTorrent.pieceLength,u=a+t,c=u+n-1;o("Requesting pieceIndex=%d offset=%d length=%d start=%d end=%d",e,t,n,u,c);var f={url:i.url,method:"GET",headers:{"user-agent":"WebTorrent (http://webtorrent.io)",range:"bytes="+u+"-"+c}};s.concat(f,function(e,t,n){return e?r(e):t.statusCode<200||t.statusCode>=300?r(new Error("Unexpected HTTP status code "+t.statusCode)):(o("Got data of length %d",n.length),void r(null,n))})}},{bitfield:7,"bittorrent-protocol":11,debug:71,inherits:79,"simple-get":131,"simple-sha1":139}],11:[function(e,t,n){(function(n){function r(e,t,n,r){this.piece=e,this.offset=t,this.length=n,this.callback=r}function i(){return this instanceof i?(l.Duplex.call(this),this._debugId=f(32),this._debug("new wire"),this.peerId=null,this.peerIdBuffer=null,this.amChoking=!0,this.amInterested=!1,this.peerChoking=!0,this.peerInterested=!1,this.peerPieces=new a(0,{grow:p}),this.peerExtensions={},this.requests=[],this.peerRequests=[],this.extendedMapping={},this.peerExtendedMapping={},this.extendedHandshake={},this.peerExtendedHandshake={},this._ext={},this._nextExt=1,this.uploaded=0,this.downloaded=0,this.uploadSpeed=h(),this.downloadSpeed=h(),this._keepAliveInterval=null,this._timeout=null,this._timeoutMs=0,this.destroyed=!1,this._finished=!1,this._buffer=[],this._bufferSize=0,this._parser=null,this._parserSize=0,this.on("finish",this._onfinish),void this._parseHandshake()):new i}function o(e,t,n,r){for(var i=0;i<e.length;i++){var o=e[i];if(o.piece===t&&o.offset===n&&o.length===r)return 0===i?e.shift():e.splice(i,1),o}return null}t.exports=i;var s=e("bencode"),a=e("bitfield"),u=e("debug")("bittorrent-protocol"),c=e("xtend"),f=e("hat"),d=e("inherits"),h=e("speedometer"),l=e("stream"),p=4e5,m=new n("BitTorrent protocol"),g=new n([0,0,0,0]),y=new n([0,0,0,1,0]),v=new n([0,0,0,1,1]),_=new n([0,0,0,1,2]),b=new n([0,0,0,1,3]),w=[0,0,0,0,0,0,0,0],E=[0,0,0,3,9,0,0];d(i,l.Duplex),i.prototype.setKeepAlive=function(e){this._debug("setKeepAlive %s",e),clearInterval(this._keepAliveInterval),e!==!1&&(this._keepAliveInterval=setInterval(this.keepAlive.bind(this),6e4))},i.prototype.setTimeout=function(e,t){this._debug("setTimeout ms=%d unref=%s",e,t),this._clearTimeout(),this._timeoutMs=e,this._timeoutUnref=!!t,this._updateTimeout()},i.prototype.destroy=function(){this.destroyed||(this.destroyed=!0,this._debug("destroy"),this.emit("close"),this.end())},i.prototype.end=function(){this._debug("end"),this._onUninterested(),this._onChoke(),l.Duplex.prototype.end.apply(this,arguments)},i.prototype.use=function(e){function t(){}var n=e.prototype.name;if(!n)throw new Error('Extension class requires a "name" property on the prototype');this._debug("use extension.name=%s",n);var r=this._nextExt,i=new e(this);"function"!=typeof i.onHandshake&&(i.onHandshake=t),"function"!=typeof i.onExtendedHandshake&&(i.onExtendedHandshake=t),"function"!=typeof i.onMessage&&(i.onMessage=t),this.extendedMapping[r]=n,this._ext[n]=i,this[n]=i,this._nextExt+=1},i.prototype.keepAlive=function(){this._debug("keep-alive"),this._push(g)},i.prototype.handshake=function(e,t,r){var i,o;if("string"==typeof e?i=new n(e,"hex"):(i=e,e=i.toString("hex")),"string"==typeof t?o=new n(t,"hex"):(o=t,t=o.toString("hex")),20!==i.length||20!==o.length)throw new Error("infoHash and peerId MUST have length 20");this._debug("handshake i=%s p=%s exts=%o",e,t,r);var s=new n(w);s[5]|=16,r&&r.dht&&(s[7]|=1),this._push(n.concat([m,s,i,o])),this._handshakeSent=!0,this.peerExtensions.extended&&!this._extendedHandshakeSent&&this._sendExtendedHandshake()},i.prototype._sendExtendedHandshake=function(){var e=c(this.extendedHandshake);e.m={};for(var t in this.extendedMapping){var n=this.extendedMapping[t];e.m[n]=Number(t)}this.extended(0,s.encode(e)),this._extendedHandshakeSent=!0},i.prototype.choke=function(){this.amChoking||(this.amChoking=!0,this._debug("choke"),this.peerRequests.splice(0,this.peerRequests.length),this._push(y))},i.prototype.unchoke=function(){this.amChoking&&(this.amChoking=!1,this._debug("unchoke"),this._push(v))},i.prototype.interested=function(){this.amInterested||(this.amInterested=!0,this._debug("interested"),this._push(_))},i.prototype.uninterested=function(){this.amInterested&&(this.amInterested=!1,this._debug("uninterested"),this._push(b))},i.prototype.have=function(e){this._debug("have %d",e),this._message(4,[e],null)},i.prototype.bitfield=function(e){this._debug("bitfield"),n.isBuffer(e)||(e=e.buffer),this._message(5,[],e)},i.prototype.request=function(e,t,n,i){return i||(i=function(){}),this._finished?i(new Error("wire is closed")):this.peerChoking?i(new Error("peer is choking")):(this._debug("request index=%d offset=%d length=%d",e,t,n),this.requests.push(new r(e,t,n,i)),this._updateTimeout(),void this._message(6,[e,t,n],null))},i.prototype.piece=function(e,t,n){this._debug("piece index=%d offset=%d",e,t),this.uploaded+=n.length,this.uploadSpeed(n.length),this.emit("upload",n.length),this._message(7,[e,t],n)},i.prototype.cancel=function(e,t,n){this._debug("cancel index=%d offset=%d length=%d",e,t,n),this._callback(o(this.requests,e,t,n),new Error("request was cancelled"),null),this._message(8,[e,t,n],null)},i.prototype.port=function(e){this._debug("port %d",e);var t=new n(E);t.writeUInt16BE(e,5),this._push(t)},i.prototype.extended=function(e,t){if(this._debug("extended ext=%s",e),"string"==typeof e&&this.peerExtendedMapping[e]&&(e=this.peerExtendedMapping[e]),"number"!=typeof e)throw new Error("Unrecognized extension: "+e);var r=new n([e]),i=n.isBuffer(t)?t:s.encode(t);this._message(20,[],n.concat([r,i]))},i.prototype._onKeepAlive=function(){this._debug("got keep-alive"),this.emit("keep-alive")},i.prototype._onHandshake=function(e,t,n){var r=e.toString("hex"),i=t.toString("hex");this._debug("got handshake i=%s p=%s exts=%o",r,i,n),this.peerId=i,this.peerIdBuffer=t,this.peerExtensions=n,this.emit("handshake",r,i,n);var o;for(o in this._ext)this._ext[o].onHandshake(r,i,n);n.extended&&this._handshakeSent&&!this._extendedHandshakeSent&&this._sendExtendedHandshake()},i.prototype._onChoke=function(){for(this.peerChoking=!0,this._debug("got choke"),this.emit("choke");this.requests.length;)this._callback(this.requests.shift(),new Error("peer is choking"),null)},i.prototype._onUnchoke=function(){this.peerChoking=!1,this._debug("got unchoke"),this.emit("unchoke")},i.prototype._onInterested=function(){this.peerInterested=!0,this._debug("got interested"),this.emit("interested")},i.prototype._onUninterested=function(){this.peerInterested=!1,this._debug("got uninterested"),this.emit("uninterested")},i.prototype._onHave=function(e){this.peerPieces.get(e)||(this._debug("got have %d",e),this.peerPieces.set(e,!0),this.emit("have",e))},i.prototype._onBitField=function(e){this.peerPieces=new a(e),this._debug("got bitfield"),this.emit("bitfield",this.peerPieces)},i.prototype._onRequest=function(e,t,n){if(!this.amChoking){this._debug("got request index=%d offset=%d length=%d",e,t,n);var i=function(r,i){return s===o(this.peerRequests,e,t,n)?r?this._debug("error satisfying request index=%d offset=%d length=%d (%s)",e,t,n,r.message):void this.piece(e,t,i):void 0}.bind(this),s=new r(e,t,n,i);this.peerRequests.push(s),this.emit("request",e,t,n,i)}},i.prototype._onPiece=function(e,t,n){this._debug("got piece index=%d offset=%d",e,t),this._callback(o(this.requests,e,t,n.length),null,n),this.downloaded+=n.length,this.downloadSpeed(n.length),this.emit("download",n.length),this.emit("piece",e,t,n)},i.prototype._onCancel=function(e,t,n){this._debug("got cancel index=%d offset=%d length=%d",e,t,n),o(this.peerRequests,e,t,n),this.emit("cancel",e,t,n)},i.prototype._onPort=function(e){this._debug("got port %d",e),this.emit("port",e)},i.prototype._onExtended=function(e,t){if(0===e){var n;try{n=s.decode(t)}catch(r){this._debug("ignoring invalid extended handshake: %s",r.message||r)}if(!n)return;this.peerExtendedHandshake=n;var i;if("object"==typeof n.m)for(i in n.m)this.peerExtendedMapping[i]=Number(n.m[i].toString());for(i in this._ext)this.peerExtendedMapping[i]&&this._ext[i].onExtendedHandshake(this.peerExtendedHandshake);this._debug("got extended handshake"),this.emit("extended","handshake",this.peerExtendedHandshake)}else this.extendedMapping[e]&&(e=this.extendedMapping[e],this._ext[e]&&this._ext[e].onMessage(t)),this._debug("got extended message ext=%s",e),this.emit("extended",e,t)},i.prototype._onTimeout=function(){this._debug("request timed out"),this._callback(this.requests.shift(),new Error("request has timed out"),null),this.emit("timeout")},i.prototype._push=function(e){return this._finished?void 0:this.push(e)},i.prototype._write=function(e,t,r){for(this._bufferSize+=e.length,this._buffer.push(e);this._bufferSize>=this._parserSize;){var i=1===this._buffer.length?this._buffer[0]:n.concat(this._buffer);this._bufferSize-=this._parserSize,this._buffer=this._bufferSize?[i.slice(this._parserSize)]:[],this._parser(i.slice(0,this._parserSize))}r(null)},i.prototype._read=function(){},i.prototype._callback=function(e,t,n){e&&(this._clearTimeout(),this.peerChoking||this._finished||this._updateTimeout(),e.callback(t,n))},i.prototype._clearTimeout=function(){this._timeout&&(clearTimeout(this._timeout),this._timeout=null)},i.prototype._updateTimeout=function(){this._timeoutMs&&this.requests.length&&!this._timeout&&(this._timeout=setTimeout(this._onTimeout.bind(this),this._timeoutMs),this._timeoutUnref&&this._timeout.unref&&this._timeout.unref())},i.prototype._parse=function(e,t){this._parserSize=e,this._parser=t},i.prototype._message=function(e,t,r){var i=r?r.length:0,o=new n(5+4*t.length);o.writeUInt32BE(o.length+i-4,0),o[4]=e;for(var s=0;s<t.length;s++)o.writeUInt32BE(t[s],5+4*s);this._push(o),r&&this._push(r)},i.prototype._onmessagelength=function(e){var t=e.readUInt32BE(0);t>0?this._parse(t,this._onmessage):(this._onKeepAlive(),this._parse(4,this._onmessagelength))},i.prototype._onmessage=function(e){switch(this._parse(4,this._onmessagelength),e[0]){case 0:return this._onChoke();case 1:return this._onUnchoke();case 2:return this._onInterested();case 3:return this._onUninterested();case 4:return this._onHave(e.readUInt32BE(1));case 5:return this._onBitField(e.slice(1));case 6:return this._onRequest(e.readUInt32BE(1),e.readUInt32BE(5),e.readUInt32BE(9));case 7:return this._onPiece(e.readUInt32BE(1),e.readUInt32BE(5),e.slice(9));case 8:return this._onCancel(e.readUInt32BE(1),e.readUInt32BE(5),e.readUInt32BE(9));case 9:return this._onPort(e.readUInt16BE(1));case 20:return this._onExtended(e.readUInt8(1),e.slice(2));default:return this._debug("got unknown message"),this.emit("unknownmessage",e)}},i.prototype._parseHandshake=function(){this._parse(1,function(e){var t=e.readUInt8(0);this._parse(t+48,function(e){var n=e.slice(0,t);return"BitTorrent protocol"!==n.toString()?(this._debug("Error: wire not speaking BitTorrent protocol (%s)",n.toString()),void this.end()):(e=e.slice(t),this._onHandshake(e.slice(8,28),e.slice(28,48),{dht:!!(1&e[7]),extended:!!(16&e[5])}),void this._parse(4,this._onmessagelength))}.bind(this))}.bind(this))},i.prototype._onfinish=function(){for(this._finished=!0,this.push(null);this.read(););for(clearInterval(this._keepAliveInterval),this._parse(Number.MAX_VALUE,function(){}),this.peerRequests=[];this.requests.length;)this._callback(this.requests.shift(),new Error("wire was closed"),null)},i.prototype._debug=function(){var e=[].slice.call(arguments);e[0]="["+this._debugId+"] "+e[0],u.apply(null,e)}}).call(this,e("buffer").Buffer)},{bencode:12,bitfield:7,buffer:26,debug:71,hat:77,inherits:79,speedometer:141,stream:39,xtend:156}],12:[function(e,t,n){t.exports={encode:e("./lib/encode"),decode:e("./lib/decode")}},{"./lib/decode":13,"./lib/encode":15}],13:[function(e,t,n){(function(n){function r(e,t){return r.position=0,r.encoding=t||null,r.data=n.isBuffer(e)?e:new n(e),r.next()}var i=e("./dict");r.position=0,r.data=null,r.encoding=null,r.next=function(){switch(r.data[r.position]){case 100:return r.dictionary();case 108:return r.list();case 105:return r.integer();default:return r.bytes()}},r.find=function(e){for(var t=r.position,n=r.data.length,i=r.data;n>t;){if(i[t]===e)return t;t++}throw new Error('Invalid data: Missing delimiter "'+String.fromCharCode(e)+'" [0x'+e.toString(16)+"]")},r.dictionary=function(){r.position++;for(var e=new i;101!==r.data[r.position];)e.binarySet(r.bytes(),r.next());return r.position++,e},r.list=function(){r.position++;for(var e=[];101!==r.data[r.position];)e.push(r.next());return r.position++,e},r.integer=function(){var e=r.find(101),t=r.data.toString("ascii",r.position+1,e);return r.position+=e+1-r.position,parseInt(t,10)},r.bytes=function(){var e=r.find(58),t=parseInt(r.data.toString("ascii",r.position,e),10),n=++e+t;return r.position=n,r.encoding?r.data.toString(r.encoding,e,n):r.data.slice(e,n)},t.exports=r}).call(this,e("buffer").Buffer)},{"./dict":14,buffer:26}],14:[function(e,t,n){var r=t.exports=function(){Object.defineProperty(this,"_keys",{enumerable:!1,value:[]})};r.prototype.binaryKeys=function(){return this._keys.slice()},r.prototype.binarySet=function(e,t){this._keys.push(e),this[e]=t}},{}],15:[function(e,t,n){(function(e){function n(t){var r=[];return n._encode(r,t),e.concat(r)}n._floatConversionDetected=!1,n._encode=function(t,r){if(e.isBuffer(r))return t.push(new e(r.length+":")),void t.push(r);switch(typeof r){case"string":n.bytes(t,r);break;case"number":n.number(t,r);break;case"object":r.constructor===Array?n.list(t,r):n.dict(t,r)}};var r=new e("e"),i=new e("d"),o=new e("l");n.bytes=function(t,n){t.push(new e(e.byteLength(n)+":"+n))},n.number=function(t,r){var i=2147483648,o=r/i<<0,s=r%i<<0,a=o*i+s;t.push(new e("i"+a+"e")),a===r||n._floatConversionDetected||(n._floatConversionDetected=!0,console.warn('WARNING: Possible data corruption detected with value "'+r+'":','Bencoding only defines support for integers, value was converted to "'+a+'"'),console.trace())},n.dict=function(e,t){e.push(i);for(var o,s=0,a=Object.keys(t).sort(),u=a.length;u>s;s++)o=a[s],n.bytes(e,o),n._encode(e,t[o]);e.push(r)},n.list=function(e,t){var i=0,s=t.length;for(e.push(o);s>i;i++)n._encode(e,t[i]);e.push(r)},t.exports=n}).call(this,e("buffer").Buffer)},{buffer:26}],16:[function(e,t,n){(function(n,r){function i(e,t,a,u){var c=this;if(!(c instanceof i))return new i(e,t,a,u);o.call(c),u||(u={}),c.peerId="string"==typeof e?e:e.toString("hex"),c.peerIdBuffer=new r(c.peerId,"hex"),c._peerIdBinary=c.peerIdBuffer.toString("binary"),c.infoHash="string"==typeof a.infoHash?a.infoHash:a.infoHash.toString("hex"),c.infoHashBuffer=new r(c.infoHash,"hex"),c._infoHashBinary=c.infoHashBuffer.toString("binary"),c.torrentLength=a.length,c.destroyed=!1,c._port=t,c._rtcConfig=u.rtcConfig,c._wrtc=u.wrtc,s("new client %s",c.infoHash);var h=!!c._wrtc||"undefined"!=typeof window,g="string"==typeof a.announce?[a.announce]:null==a.announce?[]:a.announce;g=g.map(function(e){return e=e.toString(),"/"===e[e.length-1]&&(e=e.substring(0,e.length-1)),e}),g=f(g),c._trackers=g.map(function(e){var t=d.parse(e).protocol;return"http:"!==t&&"https:"!==t||"function"!=typeof l?"udp:"===t&&"function"==typeof p?new p(c,e):"ws:"!==t&&"wss:"!==t||!h?(n.nextTick(function(){var t=new Error("unsupported tracker protocol for "+e);c.emit("warning",t)}),null):new m(c,e):new l(c,e)}).filter(Boolean)}t.exports=i;var o=e("events").EventEmitter,s=e("debug")("bittorrent-tracker"),a=e("inherits"),u=e("once"),c=e("run-parallel"),f=e("uniq"),d=e("url"),h=e("./lib/common"),l=e("./lib/client/http-tracker"),p=e("./lib/client/udp-tracker"),m=e("./lib/client/websocket-tracker");a(i,o),i.scrape=function(e,t,n){n=u(n);var o=new r("01234567890123456789"),s=6881,a={infoHash:Array.isArray(t)?t[0]:t,announce:[e]},c=new i(o,s,a);c.once("error",n);var f=Array.isArray(t)?t.length:1,d={};c.on("scrape",function(e){if(f-=1,d[e.infoHash]=e,0===f){c.destroy();var t=Object.keys(d);1===t.length?n(null,d[t[0]]):n(null,d)}}),t=Array.isArray(t)?t.map(function(e){return new r(e,"hex")}):new r(t,"hex"),c.scrape({infoHash:t})},i.prototype.start=function(e){var t=this;s("send `start`"),e=t._defaultAnnounceOpts(e),e.event="started",t._announce(e),t._trackers.forEach(function(e){e.setInterval()})},i.prototype.stop=function(e){var t=this;s("send `stop`"),e=t._defaultAnnounceOpts(e),e.event="stopped",t._announce(e)},i.prototype.complete=function(e){var t=this;s("send `complete`"),e||(e={}),null==e.downloaded&&null!=t.torrentLength&&(e.downloaded=t.torrentLength),e=t._defaultAnnounceOpts(e),e.event="completed",t._announce(e)},i.prototype.update=function(e){var t=this;s("send `update`"),e=t._defaultAnnounceOpts(e),e.event&&delete e.event,t._announce(e)},i.prototype._announce=function(e){var t=this;t._trackers.forEach(function(t){t.announce(e)})},i.prototype.scrape=function(e){var t=this;s("send `scrape`"),e||(e={}),t._trackers.forEach(function(t){t.scrape(e)})},i.prototype.setInterval=function(e){var t=this;s("setInterval %d",e),t._trackers.forEach(function(t){t.setInterval(e)})},i.prototype.destroy=function(e){var t=this;if(!t.destroyed){t.destroyed=!0,s("destroy");var n=t._trackers.map(function(e){return function(t){e.destroy(t)}});c(n,e),t._trackers=[]}},i.prototype._defaultAnnounceOpts=function(e){var t=this;return e||(e={}),null==e.numwant&&(e.numwant=h.DEFAULT_ANNOUNCE_PEERS),null==e.uploaded&&(e.uploaded=0),null==e.downloaded&&(e.downloaded=0),null==e.left&&null!=t.torrentLength&&(e.left=t.torrentLength-e.downloaded),e}}).call(this,e("_process"),e("buffer").Buffer)},{"./lib/client/http-tracker":25,"./lib/client/udp-tracker":25,"./lib/client/websocket-tracker":18,"./lib/common":19,_process:34,buffer:26,debug:71,events:30,inherits:79,once:21,"run-parallel":130,uniq:150,url:46}],17:[function(e,t,n){function r(e,t){var n=this;i.call(n),n.client=e,n.announceUrl=t,n.interval=null,n.destroyed=!1}t.exports=r;var i=e("events").EventEmitter,o=e("inherits");o(r,i),r.prototype.setInterval=function(e){var t=this;if(null==e&&(e=t.DEFAULT_ANNOUNCE_INTERVAL),clearInterval(t.interval),e){var n=t.announce.bind(t,t.client._defaultAnnounceOpts());t.interval=setInterval(n,e),t.interval.unref&&t.interval.unref()}}},{events:30,inherits:79}],18:[function(e,t,n){function r(e,t,n){var r=this;d.call(r,e,t),o("new websocket tracker %s",t),r.peers={},r.socket=null,r.reconnecting=!1,r._openSocket()}function i(){}t.exports=r;var o=e("debug")("bittorrent-tracker:websocket-tracker"),s=e("hat"),a=e("inherits"),u=e("simple-peer"),c=e("simple-websocket"),f=e("../common"),d=e("./tracker"),h={},l=3e4,p=5e3,m=5e4;a(r,d),r.prototype.DEFAULT_ANNOUNCE_INTERVAL=3e4,r.prototype.announce=function(e){var t=this;if(!t.destroyed&&!t.reconnecting){if(!t.socket.connected)return t.socket.once("connect",t.announce.bind(t,e));var n=Math.min(e.numwant,10);t._generateOffers(n,function(r){var i={numwant:n,uploaded:e.uploaded||0,downloaded:e.downloaded,event:e.event,info_hash:t.client._infoHashBinary,peer_id:t.client._peerIdBinary,offers:r};t._trackerId&&(i.trackerid=t._trackerId),t._send(i)})}},r.prototype.scrape=function(e){var t=this;t.destroyed||t.reconnecting||t._onSocketError(new Error("scrape not supported "+t.announceUrl))},r.prototype.destroy=function(e){var t=this;if(!t.destroyed){t.destroyed=!0,clearInterval(t.interval),h[t.announceUrl]=null,t.socket.removeListener("connect",t._onSocketConnectBound),t.socket.removeListener("data",t._onSocketDataBound),t.socket.removeListener("close",t._onSocketCloseBound),t.socket.removeListener("error",t._onSocketErrorBound),t._onSocketConnectBound=null,t._onSocketErrorBound=null,t._onSocketDataBound=null,t._onSocketCloseBound=null,t.socket.on("error",i);try{t.socket.destroy(e)}catch(n){e&&e()}t.socket=null}},r.prototype._openSocket=function(){var e=this;e.destroyed=!1,e._onSocketConnectBound=e._onSocketConnect.bind(e),e._onSocketErrorBound=e._onSocketError.bind(e),e._onSocketDataBound=e._onSocketData.bind(e),e._onSocketCloseBound=e._onSocketClose.bind(e),e.socket=h[e.announceUrl],e.socket||(e.socket=h[e.announceUrl]=new c(e.announceUrl),e.socket.on("connect",e._onSocketConnectBound)),e.socket.on("data",e._onSocketDataBound),e.socket.on("close",e._onSocketCloseBound),e.socket.on("error",e._onSocketErrorBound)},r.prototype._onSocketConnect=function(){var e=this;e.destroyed||e.reconnecting&&(e.reconnecting=!1,e.announce(e.client._defaultAnnounceOpts()))},r.prototype._onSocketData=function(e){var t=this;if(!t.destroyed){if("object"!=typeof e||null===e)return t.client.emit("warning",new Error("Invalid tracker response"));if(e.info_hash!==t.client._infoHashBinary)return void o("ignoring websocket data from %s for %s (looking for %s: reused socket)",t.announceUrl,f.binaryToHex(e.info_hash),t.client.infoHash);if(!e.peer_id||e.peer_id!==t.client._peerIdBinary){o("received %s from %s for %s",JSON.stringify(e),t.announceUrl,t.client.infoHash);var n=e["failure reason"];if(n)return t.client.emit("warning",new Error(n));var r=e["warning message"];r&&t.client.emit("warning",new Error(r));var i=e.interval||e["min interval"];i&&t.setInterval(1e3*i);var s=e["tracker id"];s&&(t._trackerId=s),e.complete&&t.client.emit("update",{announce:t.announceUrl,complete:e.complete,incomplete:e.incomplete});var a;if(e.offer&&e.peer_id&&(o("creating peer (from remote offer)"),a=new u({trickle:!1,config:t.client._rtcConfig,wrtc:t.client._wrtc}),a.id=f.binaryToHex(e.peer_id),a.once("signal",function(n){var r={info_hash:t.client._infoHashBinary,peer_id:t.client._peerIdBinary,to_peer_id:e.peer_id,answer:n,offer_id:e.offer_id};t._trackerId&&(r.trackerid=t._trackerId),t._send(r)}),a.signal(e.offer),t.client.emit("peer",a)),e.answer&&e.peer_id){var c=f.binaryToHex(e.offer_id);a=t.peers[c],a?(a.id=f.binaryToHex(e.peer_id),a.signal(e.answer),t.client.emit("peer",a),clearTimeout(a.trackerTimeout),a.trackerTimeout=null,t.peers[c]=null):o("got unexpected answer: "+JSON.stringify(e.answer))}}}},r.prototype._onSocketClose=function(){var e=this;e.destroyed||(e.destroy(),e._startReconnectTimer())},r.prototype._onSocketError=function(e){var t=this;t.destroyed||(t.destroy(),t.client.emit("warning",e),t._startReconnectTimer())},r.prototype._startReconnectTimer=function(){var e=this,t=Math.floor(Math.random()*l)+p;e.reconnecting=!0;var n=setTimeout(function(){e._openSocket()},t);n.unref&&n.unref(),o("reconnecting socket in %s ms",t)},r.prototype._send=function(e){var t=this;if(!t.destroyed){var n=JSON.stringify(e);o("send %s",n),t.socket.send(n)}},r.prototype._generateOffers=function(e,t){function n(){var e=s(160);o("creating peer (from _generateOffers)");var t=i.peers[e]=new u({initiator:!0,trickle:!1,config:i.client._rtcConfig,wrtc:i.client._wrtc});t.once("signal",function(t){a.push({offer:t,offer_id:f.hexToBinary(e)}),r()}),t.trackerTimeout=setTimeout(function(){o("tracker timeout: destroying peer"),t.trackerTimeout=null,i.peers[e]=null,t.destroy()},m)}function r(){a.length===e&&(o("generated %s offers",e),t(a))}var i=this,a=[];o("generating %s offers",e);for(var c=0;e>c;++c)n()}},{"../common":19,"./tracker":17,debug:71,hat:77,inherits:79,"simple-peer":134,"simple-websocket":22}],19:[function(e,t,n){(function(t){var r=e("xtend/mutable");n.DEFAULT_ANNOUNCE_PEERS=50,n.MAX_ANNOUNCE_PEERS=82,n.binaryToHex=function(e){return new t(e,"binary").toString("hex")},n.hexToBinary=function(e){return new t(e,"hex").toString("binary")};var i=e("./common-node");r(n,i)}).call(this,e("buffer").Buffer)},{"./common-node":25,buffer:26,"xtend/mutable":157}],20:[function(e,t,n){function r(e,t){function n(){for(var t=new Array(arguments.length),n=0;n<t.length;n++)t[n]=arguments[n];var r=e.apply(this,t),i=t[t.length-1];return"function"==typeof r&&r!==i&&Object.keys(i).forEach(function(e){r[e]=i[e]}),r}if(e&&t)return r(e)(t);if("function"!=typeof e)throw new TypeError("need wrapper function");return Object.keys(e).forEach(function(t){n[t]=e[t]}),n}t.exports=r},{}],21:[function(e,t,n){function r(e){var t=function(){return t.called?t.value:(t.called=!0,t.value=e.apply(this,arguments))};return t.called=!1,t}var i=e("wrappy");t.exports=i(r),r.proto=r(function(){Object.defineProperty(Function.prototype,"once",{value:function(){return r(this)},configurable:!0})})},{wrappy:20}],22:[function(e,t,n){(function(n){function r(e,t){var n=this;return n instanceof r?(t||(t={}),i("new websocket: %s %o",e,t),t.allowHalfOpen=!1,null==t.highWaterMark&&(t.highWaterMark=1048576),a.Duplex.call(n,t),n.url=e,n.connected=!1,n.destroyed=!1,n._maxBufferedAmount=t.highWaterMark,n._chunk=null,n._cb=null,n._interval=null,n._ws=new c(n.url),n._ws.binaryType="arraybuffer",n._ws.onopen=n._onOpen.bind(n),n._ws.onmessage=n._onMessage.bind(n),n._ws.onclose=n._onClose.bind(n),n._ws.onerror=function(){n._onError(new Error("connection error to "+n.url))},void n.on("finish",function(){n.connected?setTimeout(function(){n._destroy()},100):n.once("connect",function(){setTimeout(function(){n._destroy()},100)})})):new r(e,t)}t.exports=r;var i=e("debug")("simple-websocket"),o=e("inherits"),s=e("is-typedarray"),a=e("stream"),u=e("ws"),c="undefined"!=typeof window?window.WebSocket:u;o(r,a.Duplex),r.WEBSOCKET_SUPPORT=!!c,r.prototype.send=function(e){var t=this;s.strict(e)||e instanceof ArrayBuffer||n.isBuffer(e)||"string"==typeof e||"undefined"!=typeof Blob&&e instanceof Blob||(e=JSON.stringify(e));var r=e.length||e.byteLength||e.size;t._ws.send(e),i("write: %d bytes",r)},r.prototype.destroy=function(e){var t=this;t._destroy(null,e)},r.prototype._destroy=function(e,t){var n=this;if(!n.destroyed){if(t&&n.once("close",t),i("destroy (error: %s)",e&&e.message),this.readable=this.writable=!1,n._readableState.ended||n.push(null),n._writableState.finished||n.end(),n.connected=!1,n.destroyed=!0,clearInterval(n._interval),n._interval=null,n._chunk=null,n._cb=null,n._ws){var r=n._ws,o=function(){r.onclose=null,n.emit("close")};if(r.readyState===c.CLOSED)o();else try{r.onclose=o,r.close()}catch(e){o()}r.onopen=null,r.onmessage=null,r.onerror=null}n._ws=null,e&&n.emit("error",e)}},r.prototype._read=function(){},r.prototype._write=function(e,t,n){var r=this;if(r.destroyed)return n(new Error("cannot write after socket is destroyed"));if(r.connected){try{r.send(e)}catch(o){return r._onError(o)}"function"!=typeof u&&r._ws.bufferedAmount>r._maxBufferedAmount?(i("start backpressure: bufferedAmount %d",r._ws.bufferedAmount),r._cb=n):n(null)}else i("write before connect"),r._chunk=e,r._cb=n},r.prototype._onMessage=function(e){var t=this;if(!t.destroyed){var r=e.data;if(i("read: %d bytes",r.byteLength||r.length),r instanceof ArrayBuffer)r=new n(r),t.push(r);else if(n.isBuffer(r))t.push(r);else{try{r=JSON.parse(r)}catch(o){}t.emit("data",r)}}},r.prototype._onOpen=function(){var e=this;if(!e.connected&&!e.destroyed){if(e.connected=!0,e._chunk){try{e.send(e._chunk)}catch(t){return e._onError(t)}e._chunk=null,i('sent chunk from "write before connect"');var n=e._cb;e._cb=null,n(null)}"function"!=typeof u&&(e._interval=setInterval(function(){if(e._cb&&e._ws&&!(e._ws.bufferedAmount>e._maxBufferedAmount)){i("ending backpressure: bufferedAmount %d",e._ws.bufferedAmount);var t=e._cb;e._cb=null,t(null)}},150),e._interval.unref&&e._interval.unref()),i("connect"),e.emit("connect")}},r.prototype._onClose=function(){var e=this;e.destroyed||(i("on close"),e._destroy())},r.prototype._onError=function(e){var t=this;t.destroyed||(i("error: %s",e.message||e),t._destroy(e))}}).call(this,e("buffer").Buffer)},{buffer:26,debug:71,inherits:79,"is-typedarray":23,stream:39,ws:25}],23:[function(e,t,n){function r(e){return i(e)||o(e)}function i(e){return e instanceof Int8Array||e instanceof Int16Array||e instanceof Int32Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Uint16Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array}function o(e){return a[s.call(e)]}t.exports=r,r.strict=i,r.loose=o;var s=Object.prototype.toString,a={"[object Int8Array]":!0,"[object Int16Array]":!0,"[object Int32Array]":!0,"[object Uint8Array]":!0,"[object Uint8ClampedArray]":!0,"[object Uint16Array]":!0,"[object Uint32Array]":!0,"[object Float32Array]":!0,"[object Float64Array]":!0}},{}],24:[function(e,t,n){},{}],25:[function(e,t,n){arguments[4][24][0].apply(n,arguments)},{dup:24}],26:[function(e,t,n){(function(t){"use strict";function r(){try{var e=new Uint8Array(1);return e.foo=function(){return 42},42===e.foo()&&"function"==typeof e.subarray&&0===e.subarray(1,1).byteLength}catch(t){return!1}}function i(){return o.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(e){return this instanceof o?(o.TYPED_ARRAY_SUPPORT||(this.length=0,this.parent=void 0),"number"==typeof e?s(this,e):"string"==typeof e?a(this,e,arguments.length>1?arguments[1]:"utf8"):u(this,e)):arguments.length>1?new o(e,arguments[1]):new o(e)}function s(e,t){if(e=m(e,0>t?0:0|g(t)),!o.TYPED_ARRAY_SUPPORT)for(var n=0;t>n;n++)e[n]=0;return e}function a(e,t,n){("string"!=typeof n||""===n)&&(n="utf8");var r=0|v(t,n);return e=m(e,r),e.write(t,n),e}function u(e,t){if(o.isBuffer(t))return c(e,t);if(J(t))return f(e,t);if(null==t)throw new TypeError("must start with number, buffer, array or string");if("undefined"!=typeof ArrayBuffer){if(t.buffer instanceof ArrayBuffer)return d(e,t);if(t instanceof ArrayBuffer)return h(e,t)}return t.length?l(e,t):p(e,t)}function c(e,t){var n=0|g(t.length);return e=m(e,n),t.copy(e,0,0,n),e}function f(e,t){var n=0|g(t.length);e=m(e,n);for(var r=0;n>r;r+=1)e[r]=255&t[r];return e}function d(e,t){var n=0|g(t.length);e=m(e,n);for(var r=0;n>r;r+=1)e[r]=255&t[r];return e}function h(e,t){return t.byteLength,o.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t),e.__proto__=o.prototype):e=d(e,new Uint8Array(t)),e}function l(e,t){var n=0|g(t.length);e=m(e,n);for(var r=0;n>r;r+=1)e[r]=255&t[r];return e}function p(e,t){var n,r=0;"Buffer"===t.type&&J(t.data)&&(n=t.data,r=0|g(n.length)),e=m(e,r);for(var i=0;r>i;i+=1)e[i]=255&n[i];return e}function m(e,t){o.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t),e.__proto__=o.prototype):e.length=t;var n=0!==t&&t<=o.poolSize>>>1;return n&&(e.parent=X),e}function g(e){if(e>=i())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i().toString(16)+" bytes");return 0|e}function y(e,t){if(!(this instanceof y))return new y(e,t);var n=new o(e,t);return delete n.parent,n}function v(e,t){"string"!=typeof e&&(e=""+e);var n=e.length;if(0===n)return 0;for(var r=!1;;)switch(t){case"ascii": +case"binary":case"raw":case"raws":return n;case"utf8":case"utf-8":return W(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return V(e).length;default:if(r)return W(e).length;t=(""+t).toLowerCase(),r=!0}}function _(e,t,n){var r=!1;if(t=0|t,n=void 0===n||n===1/0?this.length:0|n,e||(e="utf8"),0>t&&(t=0),n>this.length&&(n=this.length),t>=n)return"";for(;;)switch(e){case"hex":return L(this,t,n);case"utf8":case"utf-8":return I(this,t,n);case"ascii":return C(this,t,n);case"binary":return T(this,t,n);case"base64":return B(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}function b(e,t,n,r){n=Number(n)||0;var i=e.length-n;r?(r=Number(r),r>i&&(r=i)):r=i;var o=t.length;if(o%2!==0)throw new Error("Invalid hex string");r>o/2&&(r=o/2);for(var s=0;r>s;s++){var a=parseInt(t.substr(2*s,2),16);if(isNaN(a))throw new Error("Invalid hex string");e[n+s]=a}return s}function w(e,t,n,r){return $(W(t,e.length-n),e,n,r)}function E(e,t,n,r){return $(F(t),e,n,r)}function k(e,t,n,r){return E(e,t,n,r)}function x(e,t,n,r){return $(V(t),e,n,r)}function S(e,t,n,r){return $(Y(t,e.length-n),e,n,r)}function B(e,t,n){return 0===t&&n===e.length?G.fromByteArray(e):G.fromByteArray(e.slice(t,n))}function I(e,t,n){n=Math.min(e.length,n);for(var r=[],i=t;n>i;){var o=e[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(n>=i+a){var u,c,f,d;switch(a){case 1:128>o&&(s=o);break;case 2:u=e[i+1],128===(192&u)&&(d=(31&o)<<6|63&u,d>127&&(s=d));break;case 3:u=e[i+1],c=e[i+2],128===(192&u)&&128===(192&c)&&(d=(15&o)<<12|(63&u)<<6|63&c,d>2047&&(55296>d||d>57343)&&(s=d));break;case 4:u=e[i+1],c=e[i+2],f=e[i+3],128===(192&u)&&128===(192&c)&&128===(192&f)&&(d=(15&o)<<18|(63&u)<<12|(63&c)<<6|63&f,d>65535&&1114112>d&&(s=d))}}null===s?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|1023&s),r.push(s),i+=a}return A(r)}function A(e){var t=e.length;if(Z>=t)return String.fromCharCode.apply(String,e);for(var n="",r=0;t>r;)n+=String.fromCharCode.apply(String,e.slice(r,r+=Z));return n}function C(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;n>i;i++)r+=String.fromCharCode(127&e[i]);return r}function T(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;n>i;i++)r+=String.fromCharCode(e[i]);return r}function L(e,t,n){var r=e.length;(!t||0>t)&&(t=0),(!n||0>n||n>r)&&(n=r);for(var i="",o=t;n>o;o++)i+=z(e[o]);return i}function R(e,t,n){for(var r=e.slice(t,n),i="",o=0;o<r.length;o+=2)i+=String.fromCharCode(r[o]+256*r[o+1]);return i}function U(e,t,n){if(e%1!==0||0>e)throw new RangeError("offset is not uint");if(e+t>n)throw new RangeError("Trying to access beyond buffer length")}function P(e,t,n,r,i,s){if(!o.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");if(t>i||s>t)throw new RangeError("value is out of bounds");if(n+r>e.length)throw new RangeError("index out of range")}function O(e,t,n,r){0>t&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-n,2);o>i;i++)e[n+i]=(t&255<<8*(r?i:1-i))>>>8*(r?i:1-i)}function M(e,t,n,r){0>t&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-n,4);o>i;i++)e[n+i]=t>>>8*(r?i:3-i)&255}function j(e,t,n,r,i,o){if(n+r>e.length)throw new RangeError("index out of range");if(0>n)throw new RangeError("index out of range")}function D(e,t,n,r,i){return i||j(e,t,n,4,3.4028234663852886e38,-3.4028234663852886e38),K.write(e,t,n,r,23,4),n+4}function H(e,t,n,r,i){return i||j(e,t,n,8,1.7976931348623157e308,-1.7976931348623157e308),K.write(e,t,n,r,52,8),n+8}function N(e){if(e=q(e).replace(Q,""),e.length<2)return"";for(;e.length%4!==0;)e+="=";return e}function q(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function z(e){return 16>e?"0"+e.toString(16):e.toString(16)}function W(e,t){t=t||1/0;for(var n,r=e.length,i=null,o=[],s=0;r>s;s++){if(n=e.charCodeAt(s),n>55295&&57344>n){if(!i){if(n>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===r){(t-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(56320>n){(t-=3)>-1&&o.push(239,191,189),i=n;continue}n=(i-55296<<10|n-56320)+65536}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,128>n){if((t-=1)<0)break;o.push(n)}else if(2048>n){if((t-=2)<0)break;o.push(n>>6|192,63&n|128)}else if(65536>n){if((t-=3)<0)break;o.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(1114112>n))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return o}function F(e){for(var t=[],n=0;n<e.length;n++)t.push(255&e.charCodeAt(n));return t}function Y(e,t){for(var n,r,i,o=[],s=0;s<e.length&&!((t-=2)<0);s++)n=e.charCodeAt(s),r=n>>8,i=n%256,o.push(i),o.push(r);return o}function V(e){return G.toByteArray(N(e))}function $(e,t,n,r){for(var i=0;r>i&&!(i+n>=t.length||i>=e.length);i++)t[i+n]=e[i];return i}var G=e("base64-js"),K=e("ieee754"),J=e("isarray");n.Buffer=o,n.SlowBuffer=y,n.INSPECT_MAX_BYTES=50,o.poolSize=8192;var X={};o.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:r(),o._augment=function(e){return e.__proto__=o.prototype,e},o.TYPED_ARRAY_SUPPORT?(o.prototype.__proto__=Uint8Array.prototype,o.__proto__=Uint8Array):(o.prototype.length=void 0,o.prototype.parent=void 0),o.isBuffer=function(e){return!(null==e||!e._isBuffer)},o.compare=function(e,t){if(!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var n=e.length,r=t.length,i=0,s=Math.min(n,r);s>i&&e[i]===t[i];)++i;return i!==s&&(n=e[i],r=t[i]),r>n?-1:n>r?1:0},o.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(e,t){if(!J(e))throw new TypeError("list argument must be an Array of Buffers.");if(0===e.length)return new o(0);var n;if(void 0===t)for(t=0,n=0;n<e.length;n++)t+=e[n].length;var r=new o(t),i=0;for(n=0;n<e.length;n++){var s=e[n];s.copy(r,i),i+=s.length}return r},o.byteLength=v,o.prototype._isBuffer=!0,o.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?I(this,0,e):_.apply(this,arguments)},o.prototype.equals=function(e){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:0===o.compare(this,e)},o.prototype.inspect=function(){var e="",t=n.INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,t).match(/.{2}/g).join(" "),this.length>t&&(e+=" ... ")),"<Buffer "+e+">"},o.prototype.compare=function(e){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?0:o.compare(this,e)},o.prototype.indexOf=function(e,t){function n(e,t,n){for(var r=-1,i=0;n+i<e.length;i++)if(e[n+i]===t[-1===r?0:i-r]){if(-1===r&&(r=i),i-r+1===t.length)return n+r}else r=-1;return-1}if(t>2147483647?t=2147483647:-2147483648>t&&(t=-2147483648),t>>=0,0===this.length)return-1;if(t>=this.length)return-1;if(0>t&&(t=Math.max(this.length+t,0)),"string"==typeof e)return 0===e.length?-1:String.prototype.indexOf.call(this,e,t);if(o.isBuffer(e))return n(this,e,t);if("number"==typeof e)return o.TYPED_ARRAY_SUPPORT&&"function"===Uint8Array.prototype.indexOf?Uint8Array.prototype.indexOf.call(this,e,t):n(this,[e],t);throw new TypeError("val must be string, number or Buffer")},o.prototype.write=function(e,t,n,r){if(void 0===t)r="utf8",n=this.length,t=0;else if(void 0===n&&"string"==typeof t)r=t,n=this.length,t=0;else if(isFinite(t))t=0|t,isFinite(n)?(n=0|n,void 0===r&&(r="utf8")):(r=n,n=void 0);else{var i=r;r=t,t=0|n,n=i}var o=this.length-t;if((void 0===n||n>o)&&(n=o),e.length>0&&(0>n||0>t)||t>this.length)throw new RangeError("attempt to write outside buffer bounds");r||(r="utf8");for(var s=!1;;)switch(r){case"hex":return b(this,e,t,n);case"utf8":case"utf-8":return w(this,e,t,n);case"ascii":return E(this,e,t,n);case"binary":return k(this,e,t,n);case"base64":return x(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),s=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var Z=4096;o.prototype.slice=function(e,t){var n=this.length;e=~~e,t=void 0===t?n:~~t,0>e?(e+=n,0>e&&(e=0)):e>n&&(e=n),0>t?(t+=n,0>t&&(t=0)):t>n&&(t=n),e>t&&(t=e);var r;if(o.TYPED_ARRAY_SUPPORT)r=this.subarray(e,t),r.__proto__=o.prototype;else{var i=t-e;r=new o(i,void 0);for(var s=0;i>s;s++)r[s]=this[s+e]}return r.length&&(r.parent=this.parent||this),r},o.prototype.readUIntLE=function(e,t,n){e=0|e,t=0|t,n||U(e,t,this.length);for(var r=this[e],i=1,o=0;++o<t&&(i*=256);)r+=this[e+o]*i;return r},o.prototype.readUIntBE=function(e,t,n){e=0|e,t=0|t,n||U(e,t,this.length);for(var r=this[e+--t],i=1;t>0&&(i*=256);)r+=this[e+--t]*i;return r},o.prototype.readUInt8=function(e,t){return t||U(e,1,this.length),this[e]},o.prototype.readUInt16LE=function(e,t){return t||U(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUInt16BE=function(e,t){return t||U(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUInt32LE=function(e,t){return t||U(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},o.prototype.readUInt32BE=function(e,t){return t||U(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readIntLE=function(e,t,n){e=0|e,t=0|t,n||U(e,t,this.length);for(var r=this[e],i=1,o=0;++o<t&&(i*=256);)r+=this[e+o]*i;return i*=128,r>=i&&(r-=Math.pow(2,8*t)),r},o.prototype.readIntBE=function(e,t,n){e=0|e,t=0|t,n||U(e,t,this.length);for(var r=t,i=1,o=this[e+--r];r>0&&(i*=256);)o+=this[e+--r]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*t)),o},o.prototype.readInt8=function(e,t){return t||U(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},o.prototype.readInt16LE=function(e,t){t||U(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt16BE=function(e,t){t||U(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt32LE=function(e,t){return t||U(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},o.prototype.readInt32BE=function(e,t){return t||U(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readFloatLE=function(e,t){return t||U(e,4,this.length),K.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return t||U(e,4,this.length),K.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return t||U(e,8,this.length),K.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return t||U(e,8,this.length),K.read(this,e,!1,52,8)},o.prototype.writeUIntLE=function(e,t,n,r){e=+e,t=0|t,n=0|n,r||P(this,e,t,n,Math.pow(2,8*n),0);var i=1,o=0;for(this[t]=255&e;++o<n&&(i*=256);)this[t+o]=e/i&255;return t+n},o.prototype.writeUIntBE=function(e,t,n,r){e=+e,t=0|t,n=0|n,r||P(this,e,t,n,Math.pow(2,8*n),0);var i=n-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+n},o.prototype.writeUInt8=function(e,t,n){return e=+e,t=0|t,n||P(this,e,t,1,255,0),o.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},o.prototype.writeUInt16LE=function(e,t,n){return e=+e,t=0|t,n||P(this,e,t,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):O(this,e,t,!0),t+2},o.prototype.writeUInt16BE=function(e,t,n){return e=+e,t=0|t,n||P(this,e,t,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):O(this,e,t,!1),t+2},o.prototype.writeUInt32LE=function(e,t,n){return e=+e,t=0|t,n||P(this,e,t,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):M(this,e,t,!0),t+4},o.prototype.writeUInt32BE=function(e,t,n){return e=+e,t=0|t,n||P(this,e,t,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):M(this,e,t,!1),t+4},o.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t=0|t,!r){var i=Math.pow(2,8*n-1);P(this,e,t,n,i-1,-i)}var o=0,s=1,a=0>e?1:0;for(this[t]=255&e;++o<n&&(s*=256);)this[t+o]=(e/s>>0)-a&255;return t+n},o.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t=0|t,!r){var i=Math.pow(2,8*n-1);P(this,e,t,n,i-1,-i)}var o=n-1,s=1,a=0>e?1:0;for(this[t+o]=255&e;--o>=0&&(s*=256);)this[t+o]=(e/s>>0)-a&255;return t+n},o.prototype.writeInt8=function(e,t,n){return e=+e,t=0|t,n||P(this,e,t,1,127,-128),o.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),0>e&&(e=255+e+1),this[t]=255&e,t+1},o.prototype.writeInt16LE=function(e,t,n){return e=+e,t=0|t,n||P(this,e,t,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):O(this,e,t,!0),t+2},o.prototype.writeInt16BE=function(e,t,n){return e=+e,t=0|t,n||P(this,e,t,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):O(this,e,t,!1),t+2},o.prototype.writeInt32LE=function(e,t,n){return e=+e,t=0|t,n||P(this,e,t,4,2147483647,-2147483648),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):M(this,e,t,!0),t+4},o.prototype.writeInt32BE=function(e,t,n){return e=+e,t=0|t,n||P(this,e,t,4,2147483647,-2147483648),0>e&&(e=4294967295+e+1),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):M(this,e,t,!1),t+4},o.prototype.writeFloatLE=function(e,t,n){return D(this,e,t,!0,n)},o.prototype.writeFloatBE=function(e,t,n){return D(this,e,t,!1,n)},o.prototype.writeDoubleLE=function(e,t,n){return H(this,e,t,!0,n)},o.prototype.writeDoubleBE=function(e,t,n){return H(this,e,t,!1,n)},o.prototype.copy=function(e,t,n,r){if(n||(n=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&n>r&&(r=n),r===n)return 0;if(0===e.length||0===this.length)return 0;if(0>t)throw new RangeError("targetStart out of bounds");if(0>n||n>=this.length)throw new RangeError("sourceStart out of bounds");if(0>r)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);var i,s=r-n;if(this===e&&t>n&&r>t)for(i=s-1;i>=0;i--)e[i+t]=this[i+n];else if(1e3>s||!o.TYPED_ARRAY_SUPPORT)for(i=0;s>i;i++)e[i+t]=this[i+n];else Uint8Array.prototype.set.call(e,this.subarray(n,n+s),t);return s},o.prototype.fill=function(e,t,n){if(e||(e=0),t||(t=0),n||(n=this.length),t>n)throw new RangeError("end < start");if(n!==t&&0!==this.length){if(0>t||t>=this.length)throw new RangeError("start out of bounds");if(0>n||n>this.length)throw new RangeError("end out of bounds");var r;if("number"==typeof e)for(r=t;n>r;r++)this[r]=e;else{var i=W(e.toString()),o=i.length;for(r=t;n>r;r++)this[r]=i[r%o]}return this}};var Q=/[^+\/0-9A-Za-z-_]/g}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"base64-js":27,ieee754:28,isarray:29}],27:[function(e,t,n){!function(e){"use strict";function t(e){var t=f[e.charCodeAt(0)];return void 0!==t?t:-1}function n(e){function n(e){u[f++]=e}var r,i,o,s,a,u;if(e.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var c=e.length;a="="===e.charAt(c-2)?2:"="===e.charAt(c-1)?1:0,u=new d(3*e.length/4-a),o=a>0?e.length-4:e.length;var f=0;for(r=0,i=0;o>r;r+=4,i+=3)s=t(e.charAt(r))<<18|t(e.charAt(r+1))<<12|t(e.charAt(r+2))<<6|t(e.charAt(r+3)),n((16711680&s)>>16),n((65280&s)>>8),n(255&s);return 2===a?(s=t(e.charAt(r))<<2|t(e.charAt(r+1))>>4,n(255&s)):1===a&&(s=t(e.charAt(r))<<10|t(e.charAt(r+1))<<4|t(e.charAt(r+2))>>2,n(s>>8&255),n(255&s)),u}function r(e){return c[e]}function i(e){return r(e>>18&63)+r(e>>12&63)+r(e>>6&63)+r(63&e)}function o(e,t,n){for(var r,o=[],s=t;n>s;s+=3)r=(e[s]<<16)+(e[s+1]<<8)+e[s+2],o.push(i(r));return o.join("")}function s(e){var t,n,i,s=e.length%3,a="",u=[],c=16383;for(t=0,i=e.length-s;i>t;t+=c)u.push(o(e,t,t+c>i?i:t+c));switch(s){case 1:n=e[e.length-1],a+=r(n>>2),a+=r(n<<4&63),a+="==";break;case 2:n=(e[e.length-2]<<8)+e[e.length-1],a+=r(n>>10),a+=r(n>>4&63),a+=r(n<<2&63),a+="="}return u.push(a),u.join("")}var a,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",c=[];for(a=0;a<u.length;a++)c[a]=u[a];var f=[];for(a=0;a<u.length;++a)f[u.charCodeAt(a)]=a;f["-".charCodeAt(0)]=62,f["_".charCodeAt(0)]=63;var d="undefined"!=typeof Uint8Array?Uint8Array:Array;e.toByteArray=n,e.fromByteArray=s}("undefined"==typeof n?this.base64js={}:n)},{}],28:[function(e,t,n){n.read=function(e,t,n,r,i){var o,s,a=8*i-r-1,u=(1<<a)-1,c=u>>1,f=-7,d=n?i-1:0,h=n?-1:1,l=e[t+d];for(d+=h,o=l&(1<<-f)-1,l>>=-f,f+=a;f>0;o=256*o+e[t+d],d+=h,f-=8);for(s=o&(1<<-f)-1,o>>=-f,f+=r;f>0;s=256*s+e[t+d],d+=h,f-=8);if(0===o)o=1-c;else{if(o===u)return s?NaN:(l?-1:1)*(1/0);s+=Math.pow(2,r),o-=c}return(l?-1:1)*s*Math.pow(2,o-r)},n.write=function(e,t,n,r,i,o){var s,a,u,c=8*o-i-1,f=(1<<c)-1,d=f>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,l=r?0:o-1,p=r?1:-1,m=0>t||0===t&&0>1/t?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=f):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),t+=s+d>=1?h/u:h*Math.pow(2,1-d),t*u>=2&&(s++,u/=2),s+d>=f?(a=0,s=f):s+d>=1?(a=(t*u-1)*Math.pow(2,i),s+=d):(a=t*Math.pow(2,d-1)*Math.pow(2,i),s=0));i>=8;e[n+l]=255&a,l+=p,a/=256,i-=8);for(s=s<<i|a,c+=i;c>0;e[n+l]=255&s,l+=p,s/=256,c-=8);e[n+l-p]|=128*m}},{}],29:[function(e,t,n){var r={}.toString;t.exports=Array.isArray||function(e){return"[object Array]"==r.call(e)}},{}],30:[function(e,t,n){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function i(e){return"function"==typeof e}function o(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function a(e){return void 0===e}t.exports=r,r.EventEmitter=r,r.prototype._events=void 0,r.prototype._maxListeners=void 0,r.defaultMaxListeners=10,r.prototype.setMaxListeners=function(e){if(!o(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.prototype.emit=function(e){var t,n,r,o,u,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(n=this._events[e],a(n))return!1;if(i(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:o=Array.prototype.slice.call(arguments,1),n.apply(this,o)}else if(s(n))for(o=Array.prototype.slice.call(arguments,1),c=n.slice(),r=c.length,u=0;r>u;u++)c[u].apply(this,o);return!0},r.prototype.addListener=function(e,t){var n;if(!i(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,i(t.listener)?t.listener:t),this._events[e]?s(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,s(this._events[e])&&!this._events[e].warned&&(n=a(this._maxListeners)?r.defaultMaxListeners:this._maxListeners,n&&n>0&&this._events[e].length>n&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(e,t){function n(){this.removeListener(e,n),r||(r=!0,t.apply(this,arguments))}if(!i(t))throw TypeError("listener must be a function");var r=!1;return n.listener=t,this.on(e,n),this},r.prototype.removeListener=function(e,t){var n,r,o,a;if(!i(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],o=n.length,r=-1,n===t||i(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(n)){for(a=o;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){r=a;break}if(0>r)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],i(n))this.removeListener(e,n);else if(n)for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},r.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?i(this._events[e])?[this._events[e]]:this._events[e].slice():[]},r.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(i(t))return 1;if(t)return t.length}return 0},r.listenerCount=function(e,t){return e.listenerCount(t)}},{}],31:[function(e,t,n){var r=e("http"),i=t.exports;for(var o in r)r.hasOwnProperty(o)&&(i[o]=r[o]);i.request=function(e,t){return e||(e={}),e.scheme="https",e.protocol="https:",r.request.call(this,e,t)}},{http:40}],32:[function(e,t,n){t.exports=function(e){return!(null==e||!(e._isBuffer||e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)))}},{}],33:[function(e,t,n){(function(e){function t(e,t){for(var n=0,r=e.length-1;r>=0;r--){var i=e[r];"."===i?e.splice(r,1):".."===i?(e.splice(r,1),n++):n&&(e.splice(r,1),n--)}if(t)for(;n--;n)e.unshift("..");return e}function r(e,t){if(e.filter)return e.filter(t);for(var n=[],r=0;r<e.length;r++)t(e[r],r,e)&&n.push(e[r]);return n}var i=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,o=function(e){return i.exec(e).slice(1)};n.resolve=function(){for(var n="",i=!1,o=arguments.length-1;o>=-1&&!i;o--){var s=o>=0?arguments[o]:e.cwd();if("string"!=typeof s)throw new TypeError("Arguments to path.resolve must be strings");s&&(n=s+"/"+n,i="/"===s.charAt(0))}return n=t(r(n.split("/"),function(e){return!!e}),!i).join("/"),(i?"/":"")+n||"."},n.normalize=function(e){var i=n.isAbsolute(e),o="/"===s(e,-1);return e=t(r(e.split("/"),function(e){return!!e}),!i).join("/"),e||i||(e="."),e&&o&&(e+="/"),(i?"/":"")+e},n.isAbsolute=function(e){return"/"===e.charAt(0)},n.join=function(){var e=Array.prototype.slice.call(arguments,0);return n.normalize(r(e,function(e,t){if("string"!=typeof e)throw new TypeError("Arguments to path.join must be strings");return e}).join("/"))},n.relative=function(e,t){function r(e){for(var t=0;t<e.length&&""===e[t];t++);for(var n=e.length-1;n>=0&&""===e[n];n--);return t>n?[]:e.slice(t,n-t+1)}e=n.resolve(e).substr(1),t=n.resolve(t).substr(1);for(var i=r(e.split("/")),o=r(t.split("/")),s=Math.min(i.length,o.length),a=s,u=0;s>u;u++)if(i[u]!==o[u]){a=u;break}for(var c=[],u=a;u<i.length;u++)c.push("..");return c=c.concat(o.slice(a)),c.join("/")},n.sep="/",n.delimiter=":",n.dirname=function(e){var t=o(e),n=t[0],r=t[1];return n||r?(r&&(r=r.substr(0,r.length-1)),n+r):"."},n.basename=function(e,t){var n=o(e)[2];return t&&n.substr(-1*t.length)===t&&(n=n.substr(0,n.length-t.length)),n},n.extname=function(e){return o(e)[3]};var s="b"==="ab".substr(-1)?function(e,t,n){return e.substr(t,n)}:function(e,t,n){return 0>t&&(t=e.length+t),e.substr(t,n)}}).call(this,e("_process"))},{_process:34}],34:[function(e,t,n){function r(){f=!1,a.length?c=a.concat(c):d=-1,c.length&&i()}function i(){if(!f){var e=setTimeout(r);f=!0;for(var t=c.length;t;){for(a=c,c=[];++d<t;)a&&a[d].run();d=-1,t=c.length}a=null,f=!1,clearTimeout(e)}}function o(e,t){this.fun=e,this.array=t}function s(){}var a,u=t.exports={},c=[],f=!1,d=-1;u.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new o(e,t)),1!==c.length||f||setTimeout(i,0)},o.prototype.run=function(){this.fun.apply(null,this.array)},u.title="browser",u.browser=!0,u.env={},u.argv=[],u.version="",u.versions={},u.on=s,u.addListener=s,u.once=s,u.off=s,u.removeListener=s,u.removeAllListeners=s,u.emit=s,u.binding=function(e){throw new Error("process.binding is not supported")},u.cwd=function(){return"/"},u.chdir=function(e){throw new Error("process.chdir is not supported")},u.umask=function(){return 0}},{}],35:[function(t,n,r){(function(t){!function(i){function o(e){throw new RangeError(P[e])}function s(e,t){for(var n=e.length,r=[];n--;)r[n]=t(e[n]);return r}function a(e,t){var n=e.split("@"),r="";n.length>1&&(r=n[0]+"@",e=n[1]),e=e.replace(U,".");var i=e.split("."),o=s(i,t).join(".");return r+o}function u(e){for(var t,n,r=[],i=0,o=e.length;o>i;)t=e.charCodeAt(i++),t>=55296&&56319>=t&&o>i?(n=e.charCodeAt(i++),56320==(64512&n)?r.push(((1023&t)<<10)+(1023&n)+65536):(r.push(t),i--)):r.push(t);return r}function c(e){return s(e,function(e){var t="";return e>65535&&(e-=65536,t+=j(e>>>10&1023|55296),e=56320|1023&e),t+=j(e)}).join("")}function f(e){return 10>e-48?e-22:26>e-65?e-65:26>e-97?e-97:k}function d(e,t){return e+22+75*(26>e)-((0!=t)<<5)}function h(e,t,n){var r=0;for(e=n?M(e/I):e>>1,e+=M(e/t);e>O*S>>1;r+=k)e=M(e/O);return M(r+(O+1)*e/(e+B))}function l(e){var t,n,r,i,s,a,u,d,l,p,m=[],g=e.length,y=0,v=C,_=A;for(n=e.lastIndexOf(T),0>n&&(n=0),r=0;n>r;++r)e.charCodeAt(r)>=128&&o("not-basic"),m.push(e.charCodeAt(r));for(i=n>0?n+1:0;g>i;){for(s=y,a=1,u=k;i>=g&&o("invalid-input"),d=f(e.charCodeAt(i++)),(d>=k||d>M((E-y)/a))&&o("overflow"),y+=d*a,l=_>=u?x:u>=_+S?S:u-_,!(l>d);u+=k)p=k-l,a>M(E/p)&&o("overflow"),a*=p;t=m.length+1,_=h(y-s,t,0==s),M(y/t)>E-v&&o("overflow"),v+=M(y/t),y%=t,m.splice(y++,0,v)}return c(m)}function p(e){var t,n,r,i,s,a,c,f,l,p,m,g,y,v,_,b=[];for(e=u(e),g=e.length,t=C,n=0,s=A,a=0;g>a;++a)m=e[a],128>m&&b.push(j(m));for(r=i=b.length,i&&b.push(T);g>r;){for(c=E,a=0;g>a;++a)m=e[a],m>=t&&c>m&&(c=m);for(y=r+1,c-t>M((E-n)/y)&&o("overflow"),n+=(c-t)*y,t=c,a=0;g>a;++a)if(m=e[a],t>m&&++n>E&&o("overflow"),m==t){for(f=n,l=k;p=s>=l?x:l>=s+S?S:l-s,!(p>f);l+=k)_=f-p,v=k-p,b.push(j(d(p+_%v,0))),f=M(_/v);b.push(j(d(f,0))),s=h(n,y,r==i),n=0,++r}++n,++t}return b.join("")}function m(e){return a(e,function(e){return L.test(e)?l(e.slice(4).toLowerCase()):e})}function g(e){return a(e,function(e){return R.test(e)?"xn--"+p(e):e})}var y="object"==typeof r&&r&&!r.nodeType&&r,v="object"==typeof n&&n&&!n.nodeType&&n,_="object"==typeof t&&t;(_.global===_||_.window===_||_.self===_)&&(i=_);var b,w,E=2147483647,k=36,x=1,S=26,B=38,I=700,A=72,C=128,T="-",L=/^xn--/,R=/[^\x20-\x7E]/,U=/[\x2E\u3002\uFF0E\uFF61]/g,P={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},O=k-x,M=Math.floor,j=String.fromCharCode;if(b={version:"1.3.2",ucs2:{decode:u,encode:c},decode:l,encode:p,toASCII:g,toUnicode:m},"function"==typeof e&&"object"==typeof e.amd&&e.amd)e("punycode",function(){return b});else if(y&&v)if(n.exports==y)v.exports=b;else for(w in b)b.hasOwnProperty(w)&&(y[w]=b[w]);else i.punycode=b}(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],36:[function(e,t,n){"use strict";function r(e,t){return Object.prototype.hasOwnProperty.call(e,t)}t.exports=function(e,t,n,o){t=t||"&",n=n||"=";var s={};if("string"!=typeof e||0===e.length)return s;var a=/\+/g;e=e.split(t);var u=1e3;o&&"number"==typeof o.maxKeys&&(u=o.maxKeys);var c=e.length;u>0&&c>u&&(c=u);for(var f=0;c>f;++f){var d,h,l,p,m=e[f].replace(a,"%20"),g=m.indexOf(n);g>=0?(d=m.substr(0,g),h=m.substr(g+1)):(d=m,h=""),l=decodeURIComponent(d),p=decodeURIComponent(h),r(s,l)?i(s[l])?s[l].push(p):s[l]=[s[l],p]:s[l]=p}return s};var i=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}},{}],37:[function(e,t,n){"use strict";function r(e,t){if(e.map)return e.map(t);for(var n=[],r=0;r<e.length;r++)n.push(t(e[r],r));return n}var i=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};t.exports=function(e,t,n,a){return t=t||"&",n=n||"=",null===e&&(e=void 0),"object"==typeof e?r(s(e),function(s){var a=encodeURIComponent(i(s))+n;return o(e[s])?r(e[s],function(e){return a+encodeURIComponent(i(e))}).join(t):a+encodeURIComponent(i(e[s]))}).join(t):a?encodeURIComponent(i(a))+n+encodeURIComponent(i(e)):""};var o=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},s=Object.keys||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.push(n);return t}},{}],38:[function(e,t,n){"use strict";n.decode=n.parse=e("./decode"),n.encode=n.stringify=e("./encode")},{"./decode":36,"./encode":37}],39:[function(e,t,n){function r(){i.call(this)}t.exports=r;var i=e("events").EventEmitter,o=e("inherits");o(r,i),r.Readable=e("readable-stream/readable.js"),r.Writable=e("readable-stream/writable.js"),r.Duplex=e("readable-stream/duplex.js"),r.Transform=e("readable-stream/transform.js"),r.PassThrough=e("readable-stream/passthrough.js"),r.Stream=r,r.prototype.pipe=function(e,t){function n(t){e.writable&&!1===e.write(t)&&c.pause&&c.pause()}function r(){c.readable&&c.resume&&c.resume()}function o(){f||(f=!0,e.end())}function s(){f||(f=!0,"function"==typeof e.destroy&&e.destroy())}function a(e){if(u(),0===i.listenerCount(this,"error"))throw e}function u(){c.removeListener("data",n),e.removeListener("drain",r),c.removeListener("end",o),c.removeListener("close",s),c.removeListener("error",a),e.removeListener("error",a),c.removeListener("end",u),c.removeListener("close",u),e.removeListener("close",u)}var c=this;c.on("data",n),e.on("drain",r),e._isStdio||t&&t.end===!1||(c.on("end",o),c.on("close",s));var f=!1;return c.on("error",a),e.on("error",a),c.on("end",u),c.on("close",u),e.on("close",u),e.emit("pipe",c),e}},{events:30,inherits:79,"readable-stream/duplex.js":97,"readable-stream/passthrough.js":108,"readable-stream/readable.js":109,"readable-stream/transform.js":110,"readable-stream/writable.js":111}],40:[function(e,t,n){(function(t){var r=e("./lib/request"),i=e("xtend"),o=e("builtin-status-codes"),s=e("url"),a=n;a.request=function(e,n){e="string"==typeof e?s.parse(e):i(e);var o=-1===t.location.protocol.search(/^https?:$/)?"http:":"",a=e.protocol||o,u=e.hostname||e.host,c=e.port,f=e.path||"/";u&&-1!==u.indexOf(":")&&(u="["+u+"]"),e.url=(u?a+"//"+u:"")+(c?":"+c:"")+f,e.method=(e.method||"GET").toUpperCase(),e.headers=e.headers||{};var d=new r(e);return n&&d.on("response",n),d},a.get=function(e,t){var n=a.request(e,t);return n.end(),n},a.Agent=function(){},a.Agent.defaultMaxSockets=4,a.STATUS_CODES=o,a.METHODS=["CHECKOUT","CONNECT","COPY","DELETE","GET","HEAD","LOCK","M-SEARCH","MERGE","MKACTIVITY","MKCOL","MOVE","NOTIFY","OPTIONS","PATCH","POST","PROPFIND","PROPPATCH","PURGE","PUT","REPORT","SEARCH","SUBSCRIBE","TRACE","UNLOCK","UNSUBSCRIBE"]}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./lib/request":42,"builtin-status-codes":44,url:46,xtend:156}],41:[function(e,t,n){(function(e){function t(e){try{return o.responseType=e,o.responseType===e}catch(t){}return!1}function r(e){return"function"==typeof e}n.fetch=r(e.fetch)&&r(e.ReadableByteStream),n.blobConstructor=!1;try{new Blob([new ArrayBuffer(1)]),n.blobConstructor=!0}catch(i){}var o=new e.XMLHttpRequest;o.open("GET",e.location.host?"/":"https://example.com");var s="undefined"!=typeof e.ArrayBuffer,a=s&&r(e.ArrayBuffer.prototype.slice);n.arraybuffer=s&&t("arraybuffer"),n.msstream=!n.fetch&&a&&t("ms-stream"),n.mozchunkedarraybuffer=!n.fetch&&s&&t("moz-chunked-arraybuffer"),n.overrideMimeType=r(o.overrideMimeType),n.vbArray=r(e.VBArray),o=null}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],42:[function(e,t,n){(function(n,r,i){function o(e){return a.fetch?"fetch":a.mozchunkedarraybuffer?"moz-chunked-arraybuffer":a.msstream?"ms-stream":a.arraybuffer&&e?"arraybuffer":a.vbArray&&e?"text:vbarray":"text"}function s(e){try{var t=e.status;return null!==t&&0!==t}catch(n){return!1}}var a=e("./capability"),u=e("inherits"),c=e("./response"),f=e("stream"),d=e("to-arraybuffer"),h=c.IncomingMessage,l=c.readyStates,p=t.exports=function(e){ +var t=this;f.Writable.call(t),t._opts=e,t._body=[],t._headers={},e.auth&&t.setHeader("Authorization","Basic "+new i(e.auth).toString("base64")),Object.keys(e.headers).forEach(function(n){t.setHeader(n,e.headers[n])});var n;if("prefer-streaming"===e.mode)n=!1;else if("allow-wrong-content-type"===e.mode)n=!a.overrideMimeType;else{if(e.mode&&"default"!==e.mode&&"prefer-fast"!==e.mode)throw new Error("Invalid value for opts.mode");n=!0}t._mode=o(n),t.on("finish",function(){t._onFinish()})};u(p,f.Writable),p.prototype.setHeader=function(e,t){var n=this,r=e.toLowerCase();-1===m.indexOf(r)&&(n._headers[r]={name:e,value:t})},p.prototype.getHeader=function(e){var t=this;return t._headers[e.toLowerCase()].value},p.prototype.removeHeader=function(e){var t=this;delete t._headers[e.toLowerCase()]},p.prototype._onFinish=function(){var e=this;if(!e._destroyed){var t,o=e._opts,s=e._headers;if(("POST"===o.method||"PUT"===o.method||"PATCH"===o.method)&&(t=a.blobConstructor?new r.Blob(e._body.map(function(e){return d(e)}),{type:(s["content-type"]||{}).value||""}):i.concat(e._body).toString()),"fetch"===e._mode){var u=Object.keys(s).map(function(e){return[s[e].name,s[e].value]});r.fetch(e._opts.url,{method:e._opts.method,headers:u,body:t,mode:"cors",credentials:o.withCredentials?"include":"same-origin"}).then(function(t){e._fetchResponse=t,e._connect()},function(t){e.emit("error",t)})}else{var c=e._xhr=new r.XMLHttpRequest;try{c.open(e._opts.method,e._opts.url,!0)}catch(f){return void n.nextTick(function(){e.emit("error",f)})}"responseType"in c&&(c.responseType=e._mode.split(":")[0]),"withCredentials"in c&&(c.withCredentials=!!o.withCredentials),"text"===e._mode&&"overrideMimeType"in c&&c.overrideMimeType("text/plain; charset=x-user-defined"),Object.keys(s).forEach(function(e){c.setRequestHeader(s[e].name,s[e].value)}),e._response=null,c.onreadystatechange=function(){switch(c.readyState){case l.LOADING:case l.DONE:e._onXHRProgress()}},"moz-chunked-arraybuffer"===e._mode&&(c.onprogress=function(){e._onXHRProgress()}),c.onerror=function(){e._destroyed||e.emit("error",new Error("XHR error"))};try{c.send(t)}catch(f){return void n.nextTick(function(){e.emit("error",f)})}}}},p.prototype._onXHRProgress=function(){var e=this;s(e._xhr)&&!e._destroyed&&(e._response||e._connect(),e._response._onXHRProgress())},p.prototype._connect=function(){var e=this;e._destroyed||(e._response=new h(e._xhr,e._fetchResponse,e._mode),e.emit("response",e._response))},p.prototype._write=function(e,t,n){var r=this;r._body.push(e),n()},p.prototype.abort=p.prototype.destroy=function(){var e=this;e._destroyed=!0,e._response&&(e._response._destroyed=!0),e._xhr&&e._xhr.abort()},p.prototype.end=function(e,t,n){var r=this;"function"==typeof e&&(n=e,e=void 0),f.Writable.prototype.end.call(r,e,t,n)},p.prototype.flushHeaders=function(){},p.prototype.setTimeout=function(){},p.prototype.setNoDelay=function(){},p.prototype.setSocketKeepAlive=function(){};var m=["accept-charset","accept-encoding","access-control-request-headers","access-control-request-method","connection","content-length","cookie","cookie2","date","dnt","expect","host","keep-alive","origin","referer","te","trailer","transfer-encoding","upgrade","user-agent","via"]}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer)},{"./capability":41,"./response":43,_process:34,buffer:26,inherits:79,stream:39,"to-arraybuffer":45}],43:[function(e,t,n){(function(t,r,i){var o=e("./capability"),s=e("inherits"),a=e("stream"),u=n.readyStates={UNSENT:0,OPENED:1,HEADERS_RECEIVED:2,LOADING:3,DONE:4},c=n.IncomingMessage=function(e,n,r){function s(){h.read().then(function(e){if(!u._destroyed){if(e.done)return void u.push(null);u.push(new i(e.value)),s()}})}var u=this;if(a.Readable.call(u),u._mode=r,u.headers={},u.rawHeaders=[],u.trailers={},u.rawTrailers=[],u.on("end",function(){t.nextTick(function(){u.emit("close")})}),"fetch"===r){u._fetchResponse=n,u.statusCode=n.status,u.statusMessage=n.statusText;for(var c,f,d=n.headers[Symbol.iterator]();c=(f=d.next()).value,!f.done;)u.headers[c[0].toLowerCase()]=c[1],u.rawHeaders.push(c[0],c[1]);var h=n.body.getReader();s()}else{u._xhr=e,u._pos=0,u.statusCode=e.status,u.statusMessage=e.statusText;var l=e.getAllResponseHeaders().split(/\r?\n/);if(l.forEach(function(e){var t=e.match(/^([^:]+):\s*(.*)/);if(t){var n=t[1].toLowerCase();void 0!==u.headers[n]?u.headers[n]+=", "+t[2]:u.headers[n]=t[2],u.rawHeaders.push(t[1],t[2])}}),u._charset="x-user-defined",!o.overrideMimeType){var p=u.rawHeaders["mime-type"];if(p){var m=p.match(/;\s*charset=([^;])(;|$)/);m&&(u._charset=m[1].toLowerCase())}u._charset||(u._charset="utf-8")}}};s(c,a.Readable),c.prototype._read=function(){},c.prototype._onXHRProgress=function(){var e=this,t=e._xhr,n=null;switch(e._mode){case"text:vbarray":if(t.readyState!==u.DONE)break;try{n=new r.VBArray(t.responseBody).toArray()}catch(o){}if(null!==n){e.push(new i(n));break}case"text":try{n=t.responseText}catch(o){e._mode="text:vbarray";break}if(n.length>e._pos){var s=n.substr(e._pos);if("x-user-defined"===e._charset){for(var a=new i(s.length),c=0;c<s.length;c++)a[c]=255&s.charCodeAt(c);e.push(a)}else e.push(s,e._charset);e._pos=n.length}break;case"arraybuffer":if(t.readyState!==u.DONE)break;n=t.response,e.push(new i(new Uint8Array(n)));break;case"moz-chunked-arraybuffer":if(n=t.response,t.readyState!==u.LOADING||!n)break;e.push(new i(new Uint8Array(n)));break;case"ms-stream":if(n=t.response,t.readyState!==u.LOADING)break;var f=new r.MSStreamReader;f.onprogress=function(){f.result.byteLength>e._pos&&(e.push(new i(new Uint8Array(f.result.slice(e._pos)))),e._pos=f.result.byteLength)},f.onload=function(){e.push(null)},f.readAsArrayBuffer(n)}e._xhr.readyState===u.DONE&&"ms-stream"!==e._mode&&e.push(null)}}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer)},{"./capability":41,_process:34,buffer:26,inherits:79,stream:39}],44:[function(e,t,n){t.exports={100:"Continue",101:"Switching Protocols",102:"Processing",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",308:"Permanent Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Time-out",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Request Entity Too Large",414:"Request-URI Too Large",415:"Unsupported Media Type",416:"Requested Range Not Satisfiable",417:"Expectation Failed",418:"I'm a teapot",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",425:"Unordered Collection",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Time-out",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",509:"Bandwidth Limit Exceeded",510:"Not Extended",511:"Network Authentication Required"}},{}],45:[function(e,t,n){var r=e("buffer").Buffer;t.exports=function(e){if(e instanceof Uint8Array){if(0===e.byteOffset&&e.byteLength===e.buffer.byteLength)return e.buffer;if("function"==typeof e.buffer.slice)return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}if(r.isBuffer(e)){for(var t=new Uint8Array(e.length),n=e.length,i=0;n>i;i++)t[i]=e[i];return t.buffer}throw new Error("Argument must be a Buffer")}},{buffer:26}],46:[function(e,t,n){"use strict";function r(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}function i(e,t,n){if(e&&c.isObject(e)&&e instanceof r)return e;var i=new r;return i.parse(e,t,n),i}function o(e){return c.isString(e)&&(e=i(e)),e instanceof r?e.format():r.prototype.format.call(e)}function s(e,t){return i(e,!1,!0).resolve(t)}function a(e,t){return e?i(e,!1,!0).resolveObject(t):t}var u=e("punycode"),c=e("./util");n.parse=i,n.resolve=s,n.resolveObject=a,n.format=o,n.Url=r;var f=/^([a-z0-9.+-]+:)/i,d=/:[0-9]*$/,h=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,l=["<",">",'"',"`"," ","\r","\n"," "],p=["{","}","|","\\","^","`"].concat(l),m=["'"].concat(p),g=["%","/","?",";","#"].concat(m),y=["/","?","#"],v=255,_=/^[+a-z0-9A-Z_-]{0,63}$/,b=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,w={javascript:!0,"javascript:":!0},E={javascript:!0,"javascript:":!0},k={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},x=e("querystring");r.prototype.parse=function(e,t,n){if(!c.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var r=e.indexOf("?"),i=-1!==r&&r<e.indexOf("#")?"?":"#",o=e.split(i),s=/\\/g;o[0]=o[0].replace(s,"/"),e=o.join(i);var a=e;if(a=a.trim(),!n&&1===e.split("#").length){var d=h.exec(a);if(d)return this.path=a,this.href=a,this.pathname=d[1],d[2]?(this.search=d[2],t?this.query=x.parse(this.search.substr(1)):this.query=this.search.substr(1)):t&&(this.search="",this.query={}),this}var l=f.exec(a);if(l){l=l[0];var p=l.toLowerCase();this.protocol=p,a=a.substr(l.length)}if(n||l||a.match(/^\/\/[^@\/]+@[^@\/]+/)){var S="//"===a.substr(0,2);!S||l&&E[l]||(a=a.substr(2),this.slashes=!0)}if(!E[l]&&(S||l&&!k[l])){for(var B=-1,I=0;I<y.length;I++){var A=a.indexOf(y[I]);-1!==A&&(-1===B||B>A)&&(B=A)}var C,T;T=-1===B?a.lastIndexOf("@"):a.lastIndexOf("@",B),-1!==T&&(C=a.slice(0,T),a=a.slice(T+1),this.auth=decodeURIComponent(C)),B=-1;for(var I=0;I<g.length;I++){var A=a.indexOf(g[I]);-1!==A&&(-1===B||B>A)&&(B=A)}-1===B&&(B=a.length),this.host=a.slice(0,B),a=a.slice(B),this.parseHost(),this.hostname=this.hostname||"";var L="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!L)for(var R=this.hostname.split(/\./),I=0,U=R.length;U>I;I++){var P=R[I];if(P&&!P.match(_)){for(var O="",M=0,j=P.length;j>M;M++)O+=P.charCodeAt(M)>127?"x":P[M];if(!O.match(_)){var D=R.slice(0,I),H=R.slice(I+1),N=P.match(b);N&&(D.push(N[1]),H.unshift(N[2])),H.length&&(a="/"+H.join(".")+a),this.hostname=D.join(".");break}}}this.hostname.length>v?this.hostname="":this.hostname=this.hostname.toLowerCase(),L||(this.hostname=u.toASCII(this.hostname));var q=this.port?":"+this.port:"",z=this.hostname||"";this.host=z+q,this.href+=this.host,L&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==a[0]&&(a="/"+a))}if(!w[p])for(var I=0,U=m.length;U>I;I++){var W=m[I];if(-1!==a.indexOf(W)){var F=encodeURIComponent(W);F===W&&(F=escape(W)),a=a.split(W).join(F)}}var Y=a.indexOf("#");-1!==Y&&(this.hash=a.substr(Y),a=a.slice(0,Y));var V=a.indexOf("?");if(-1!==V?(this.search=a.substr(V),this.query=a.substr(V+1),t&&(this.query=x.parse(this.query)),a=a.slice(0,V)):t&&(this.search="",this.query={}),a&&(this.pathname=a),k[p]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){var q=this.pathname||"",$=this.search||"";this.path=q+$}return this.href=this.format(),this},r.prototype.format=function(){var e=this.auth||"";e&&(e=encodeURIComponent(e),e=e.replace(/%3A/i,":"),e+="@");var t=this.protocol||"",n=this.pathname||"",r=this.hash||"",i=!1,o="";this.host?i=e+this.host:this.hostname&&(i=e+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(i+=":"+this.port)),this.query&&c.isObject(this.query)&&Object.keys(this.query).length&&(o=x.stringify(this.query));var s=this.search||o&&"?"+o||"";return t&&":"!==t.substr(-1)&&(t+=":"),this.slashes||(!t||k[t])&&i!==!1?(i="//"+(i||""),n&&"/"!==n.charAt(0)&&(n="/"+n)):i||(i=""),r&&"#"!==r.charAt(0)&&(r="#"+r),s&&"?"!==s.charAt(0)&&(s="?"+s),n=n.replace(/[?#]/g,function(e){return encodeURIComponent(e)}),s=s.replace("#","%23"),t+i+n+s+r},r.prototype.resolve=function(e){return this.resolveObject(i(e,!1,!0)).format()},r.prototype.resolveObject=function(e){if(c.isString(e)){var t=new r;t.parse(e,!1,!0),e=t}for(var n=new r,i=Object.keys(this),o=0;o<i.length;o++){var s=i[o];n[s]=this[s]}if(n.hash=e.hash,""===e.href)return n.href=n.format(),n;if(e.slashes&&!e.protocol){for(var a=Object.keys(e),u=0;u<a.length;u++){var f=a[u];"protocol"!==f&&(n[f]=e[f])}return k[n.protocol]&&n.hostname&&!n.pathname&&(n.path=n.pathname="/"),n.href=n.format(),n}if(e.protocol&&e.protocol!==n.protocol){if(!k[e.protocol]){for(var d=Object.keys(e),h=0;h<d.length;h++){var l=d[h];n[l]=e[l]}return n.href=n.format(),n}if(n.protocol=e.protocol,e.host||E[e.protocol])n.pathname=e.pathname;else{for(var p=(e.pathname||"").split("/");p.length&&!(e.host=p.shift()););e.host||(e.host=""),e.hostname||(e.hostname=""),""!==p[0]&&p.unshift(""),p.length<2&&p.unshift(""),n.pathname=p.join("/")}if(n.search=e.search,n.query=e.query,n.host=e.host||"",n.auth=e.auth,n.hostname=e.hostname||e.host,n.port=e.port,n.pathname||n.search){var m=n.pathname||"",g=n.search||"";n.path=m+g}return n.slashes=n.slashes||e.slashes,n.href=n.format(),n}var y=n.pathname&&"/"===n.pathname.charAt(0),v=e.host||e.pathname&&"/"===e.pathname.charAt(0),_=v||y||n.host&&e.pathname,b=_,w=n.pathname&&n.pathname.split("/")||[],p=e.pathname&&e.pathname.split("/")||[],x=n.protocol&&!k[n.protocol];if(x&&(n.hostname="",n.port=null,n.host&&(""===w[0]?w[0]=n.host:w.unshift(n.host)),n.host="",e.protocol&&(e.hostname=null,e.port=null,e.host&&(""===p[0]?p[0]=e.host:p.unshift(e.host)),e.host=null),_=_&&(""===p[0]||""===w[0])),v)n.host=e.host||""===e.host?e.host:n.host,n.hostname=e.hostname||""===e.hostname?e.hostname:n.hostname,n.search=e.search,n.query=e.query,w=p;else if(p.length)w||(w=[]),w.pop(),w=w.concat(p),n.search=e.search,n.query=e.query;else if(!c.isNullOrUndefined(e.search)){if(x){n.hostname=n.host=w.shift();var S=n.host&&n.host.indexOf("@")>0?n.host.split("@"):!1;S&&(n.auth=S.shift(),n.host=n.hostname=S.shift())}return n.search=e.search,n.query=e.query,c.isNull(n.pathname)&&c.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.href=n.format(),n}if(!w.length)return n.pathname=null,n.search?n.path="/"+n.search:n.path=null,n.href=n.format(),n;for(var B=w.slice(-1)[0],I=(n.host||e.host||w.length>1)&&("."===B||".."===B)||""===B,A=0,C=w.length;C>=0;C--)B=w[C],"."===B?w.splice(C,1):".."===B?(w.splice(C,1),A++):A&&(w.splice(C,1),A--);if(!_&&!b)for(;A--;A)w.unshift("..");!_||""===w[0]||w[0]&&"/"===w[0].charAt(0)||w.unshift(""),I&&"/"!==w.join("/").substr(-1)&&w.push("");var T=""===w[0]||w[0]&&"/"===w[0].charAt(0);if(x){n.hostname=n.host=T?"":w.length?w.shift():"";var S=n.host&&n.host.indexOf("@")>0?n.host.split("@"):!1;S&&(n.auth=S.shift(),n.host=n.hostname=S.shift())}return _=_||n.host&&w.length,_&&!T&&w.unshift(""),w.length?n.pathname=w.join("/"):(n.pathname=null,n.path=null),c.isNull(n.pathname)&&c.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.auth=e.auth||n.auth,n.slashes=n.slashes||e.slashes,n.href=n.format(),n},r.prototype.parseHost=function(){var e=this.host,t=d.exec(e);t&&(t=t[0],":"!==t&&(this.port=t.substr(1)),e=e.substr(0,e.length-t.length)),e&&(this.hostname=e)}},{"./util":47,punycode:35,querystring:38}],47:[function(e,t,n){"use strict";t.exports={isString:function(e){return"string"==typeof e},isObject:function(e){return"object"==typeof e&&null!==e},isNull:function(e){return null===e},isNullOrUndefined:function(e){return null==e}}},{}],48:[function(e,t,n){t.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},{}],49:[function(e,t,n){(function(t,r){function i(e,t){var r={seen:[],stylize:s};return arguments.length>=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),m(t)?r.showHidden=t:t&&n._extend(r,t),w(r.showHidden)&&(r.showHidden=!1),w(r.depth)&&(r.depth=2),w(r.colors)&&(r.colors=!1),w(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=o),u(r,e,r.depth)}function o(e,t){var n=i.styles[t];return n?"["+i.colors[n][0]+"m"+e+"["+i.colors[n][1]+"m":e}function s(e,t){return e}function a(e){var t={};return e.forEach(function(e,n){t[e]=!0}),t}function u(e,t,r){if(e.customInspect&&t&&B(t.inspect)&&t.inspect!==n.inspect&&(!t.constructor||t.constructor.prototype!==t)){var i=t.inspect(r,e);return _(i)||(i=u(e,i,r)),i}var o=c(e,t);if(o)return o;var s=Object.keys(t),m=a(s);if(e.showHidden&&(s=Object.getOwnPropertyNames(t)),S(t)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return f(t);if(0===s.length){if(B(t)){var g=t.name?": "+t.name:"";return e.stylize("[Function"+g+"]","special")}if(E(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(x(t))return e.stylize(Date.prototype.toString.call(t),"date");if(S(t))return f(t)}var y="",v=!1,b=["{","}"];if(p(t)&&(v=!0,b=["[","]"]),B(t)){var w=t.name?": "+t.name:"";y=" [Function"+w+"]"}if(E(t)&&(y=" "+RegExp.prototype.toString.call(t)),x(t)&&(y=" "+Date.prototype.toUTCString.call(t)),S(t)&&(y=" "+f(t)),0===s.length&&(!v||0==t.length))return b[0]+y+b[1];if(0>r)return E(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special");e.seen.push(t);var k;return k=v?d(e,t,r,m,s):s.map(function(n){return h(e,t,r,m,n,v)}),e.seen.pop(),l(k,y,b)}function c(e,t){if(w(t))return e.stylize("undefined","undefined");if(_(t)){var n="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(n,"string")}return v(t)?e.stylize(""+t,"number"):m(t)?e.stylize(""+t,"boolean"):g(t)?e.stylize("null","null"):void 0}function f(e){return"["+Error.prototype.toString.call(e)+"]"}function d(e,t,n,r,i){for(var o=[],s=0,a=t.length;a>s;++s)L(t,String(s))?o.push(h(e,t,n,r,String(s),!0)):o.push("");return i.forEach(function(i){i.match(/^\d+$/)||o.push(h(e,t,n,r,i,!0))}),o}function h(e,t,n,r,i,o){var s,a,c;if(c=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]},c.get?a=c.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):c.set&&(a=e.stylize("[Setter]","special")),L(r,i)||(s="["+i+"]"),a||(e.seen.indexOf(c.value)<0?(a=g(n)?u(e,c.value,null):u(e,c.value,n-1),a.indexOf("\n")>-1&&(a=o?a.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+a.split("\n").map(function(e){return" "+e}).join("\n"))):a=e.stylize("[Circular]","special")),w(s)){if(o&&i.match(/^\d+$/))return a;s=JSON.stringify(""+i),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=e.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=e.stylize(s,"string"))}return s+": "+a}function l(e,t,n){var r=0,i=e.reduce(function(e,t){return r++,t.indexOf("\n")>=0&&r++,e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0);return i>60?n[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+n[1]:n[0]+t+" "+e.join(", ")+" "+n[1]}function p(e){return Array.isArray(e)}function m(e){return"boolean"==typeof e}function g(e){return null===e}function y(e){return null==e}function v(e){return"number"==typeof e}function _(e){return"string"==typeof e}function b(e){return"symbol"==typeof e}function w(e){return void 0===e}function E(e){return k(e)&&"[object RegExp]"===A(e)}function k(e){return"object"==typeof e&&null!==e}function x(e){return k(e)&&"[object Date]"===A(e)}function S(e){return k(e)&&("[object Error]"===A(e)||e instanceof Error)}function B(e){return"function"==typeof e}function I(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||"undefined"==typeof e}function A(e){return Object.prototype.toString.call(e)}function C(e){return 10>e?"0"+e.toString(10):e.toString(10)}function T(){var e=new Date,t=[C(e.getHours()),C(e.getMinutes()),C(e.getSeconds())].join(":");return[e.getDate(),O[e.getMonth()],t].join(" ")}function L(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var R=/%[sdj%]/g;n.format=function(e){if(!_(e)){for(var t=[],n=0;n<arguments.length;n++)t.push(i(arguments[n]));return t.join(" ")}for(var n=1,r=arguments,o=r.length,s=String(e).replace(R,function(e){if("%%"===e)return"%";if(n>=o)return e;switch(e){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(t){return"[Circular]"}default:return e}}),a=r[n];o>n;a=r[++n])s+=g(a)||!k(a)?" "+a:" "+i(a);return s},n.deprecate=function(e,i){function o(){if(!s){if(t.throwDeprecation)throw new Error(i);t.traceDeprecation?console.trace(i):console.error(i),s=!0}return e.apply(this,arguments)}if(w(r.process))return function(){return n.deprecate(e,i).apply(this,arguments)};if(t.noDeprecation===!0)return e;var s=!1;return o};var U,P={};n.debuglog=function(e){if(w(U)&&(U=t.env.NODE_DEBUG||""),e=e.toUpperCase(),!P[e])if(new RegExp("\\b"+e+"\\b","i").test(U)){var r=t.pid;P[e]=function(){var t=n.format.apply(n,arguments);console.error("%s %d: %s",e,r,t)}}else P[e]=function(){};return P[e]},n.inspect=i,i.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},i.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},n.isArray=p,n.isBoolean=m,n.isNull=g,n.isNullOrUndefined=y,n.isNumber=v,n.isString=_,n.isSymbol=b,n.isUndefined=w,n.isRegExp=E,n.isObject=k,n.isDate=x,n.isError=S,n.isFunction=B,n.isPrimitive=I,n.isBuffer=e("./support/isBuffer");var O=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];n.log=function(){console.log("%s - %s",T(),n.format.apply(n,arguments))},n.inherits=e("inherits"),n._extend=function(e,t){if(!t||!k(t))return e;for(var n=Object.keys(t),r=n.length;r--;)e[n[r]]=t[n[r]];return e}}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./support/isBuffer":48,_process:34,inherits:79}],50:[function(e,t,n){(function(n){function r(e,t){return this instanceof r?(o.call(this),t||(t={}),"object"==typeof e&&(t=e,e=t.size),this.size=e||512,t.nopad?this._zeroPadding=!1:this._zeroPadding=s(t.zeroPadding,!0),this._buffered=[],void(this._bufferedBytes=0)):new r(e,t)}var i=e("inherits"),o=e("readable-stream").Transform,s=e("defined");t.exports=r,i(r,o),r.prototype._transform=function(e,t,r){for(this._bufferedBytes+=e.length,this._buffered.push(e);this._bufferedBytes>=this.size;){var i=n.concat(this._buffered);this._bufferedBytes-=this.size,this.push(i.slice(0,this.size)),this._buffered=[i.slice(this.size,i.length)]}r()},r.prototype._flush=function(){if(this._bufferedBytes&&this._zeroPadding){var e=new n(this.size-this._bufferedBytes);e.fill(0),this._buffered.push(e),this.push(n.concat(this._buffered)),this._buffered=null}else this._bufferedBytes&&(this.push(n.concat(this._buffered)),this._buffered=null);this.push(null)}}).call(this,e("buffer").Buffer)},{buffer:26,defined:51,inherits:79,"readable-stream":109}],51:[function(e,t,n){t.exports=function(){for(var e=0;e<arguments.length;e++)if(void 0!==arguments[e])return arguments[e]}},{}],52:[function(e,t,n){function r(e,t,n){function o(t){a.destroyed||(e.put(u,t),u+=1)}var a=this;if(!(a instanceof r))return new r(e,t,n);if(s.Writable.call(a,n),n||(n={}),!e||!e.put||!e.get)throw new Error("First argument must be an abstract-chunk-store compliant store");if(t=Number(t),!t)throw new Error("Second argument must be a chunk length");a._blockstream=new i(t,{zeroPadding:!1}),a._blockstream.on("data",o).on("error",function(e){a.destroy(e)});var u=0;a.on("finish",function(){this._blockstream.end()})}t.exports=r;var i=e("block-stream2"),o=e("inherits"),s=e("stream");o(r,s.Writable),r.prototype._write=function(e,t,n){this._blockstream.write(e,t,n)},r.prototype.destroy=function(e){this.destroyed||(this.destroyed=!0,e&&this.emit("error",e),this.emit("close"))}},{"block-stream2":50,inherits:79,stream:39}],53:[function(e,t,n){t.exports=function r(){for(var e=navigator.hardwareConcurrency||1,r=[],t=0;e>t;t++)r.push({model:"",speed:0,times:{user:0,nice:0,sys:0,idle:0,irq:0}});return r}},{}],54:[function(e,t,n){(function(n,r,i){function o(e,t,n){return"function"==typeof t?o(e,null,t):(t=t?B(t):{},void a(e,t,function(e,r,i){return e?n(e):(t.singleFileTorrent=i,void l(r,t,n))}))}function s(e,t,n){return"function"==typeof t?s(e,null,t):(t=t?B(t):{},void a(e,t,n))}function a(e,t,r){function o(){P(e.map(function(e){return function(n){var r={};if(m(e))r.getStream=v(e),r.length=e.size;else if(i.isBuffer(e))r.getStream=_(e),r.length=e.length;else{if(!y(e)){if("string"==typeof e){if("function"!=typeof C.stat)throw new Error("filesystem paths do not work in the browser");var o=a>1||c;return void u(e,o,n)}throw new Error("invalid input type")}if(!t.pieceLength)throw new Error("must specify `pieceLength` option if input is Stream");r.getStream=w(e,r),r.length=0}r.path=e.path,n(null,r)}}),function(e,t){return e?r(e):(t=A(t),void r(null,t,c))})}if(Array.isArray(e)&&0===e.length)throw new Error("invalid input type");g(e)&&(e=Array.prototype.slice.call(e)),Array.isArray(e)||(e=[e]),e=e.map(function(e){return m(e)&&"string"==typeof e.path?e.path:e}),1!==e.length||"string"==typeof e[0]||e[0].name||(e[0].name=t.name);var s=null;if(e.forEach(function(t,n){if("string"!=typeof t){var r=t.fullPath||t.name;if(!r)throw new Error("missing required `fullPath` or `name` property on input");t.path=r.split("/"),t.path[0]||t.path.shift(),t.path.length<2?s=null:0===n&&e.length>1?s=t.path[0]:t.path[0]!==s&&(s=null)}}),e=e.filter(function(e){if("string"==typeof e)return!0;var t=e.path[e.path.length-1];return d(t)&&L.not(t)}),s&&e.forEach(function(e){"string"!=typeof e&&e.path.shift()}),!t.name&&s&&(t.name=s),!t.name&&e[0]&&e[0].name&&(t.name=e[0].name),t.name||"string"!=typeof e[0]||(t.name=S.basename(e[0])),void 0===t.name)throw new Error("missing option 'name' and unable to infer it from input[0].name");var a=e.reduce(function(e,t){return e+Number("string"==typeof t)},0),c=1===e.length;if(1===e.length&&"string"==typeof e[0]){if("function"!=typeof C.stat)throw new Error("filesystem paths do not work in the browser");T(e[0],function(e,t){return e?r(e):(c=t,void o())})}else n.nextTick(function(){o()})}function u(e,t,n){f(e,c,function(r,i){return r?n(r):(i=Array.isArray(i)?A(i):[i],e=S.normalize(e),t&&(e=e.slice(0,e.lastIndexOf(S.sep)+1)),e[e.length-1]!==S.sep&&(e+=S.sep),i.forEach(function(t){t.getStream=b(t.path),t.path=t.path.replace(e,"").split(S.sep)}),void n(null,i))})}function c(e,t){t=U(t),C.stat(e,function(n,r){if(n)return t(n);var i={length:r.size,path:e};t(null,i)})}function f(e,t,n){C.readdir(e,function(r,i){r&&"ENOTDIR"===r.code?t(e,n):r?n(r):P(i.filter(d).filter(L.not).map(function(n){return function(r){f(S.join(e,n),t,r)}}),n)})}function d(e){return"."!==e[0]}function h(e,t,n){function r(e){f+=e.length;var t=l;O(e,function(e){c[t]=e,h-=1,u()}),h+=1,l+=1}function o(){p=!0,u()}function s(e){a(),n(e)}function a(){m.removeListener("error",s),g.removeListener("data",r),g.removeListener("end",o),g.removeListener("error",s)}function u(){p&&0===h&&(a(),n(null,new i(c.join(""),"hex"),f))}n=U(n);var c=[],f=0,d=e.map(function(e){return e.getStream}),h=0,l=0,p=!1,m=new R(d),g=new k(t,{zeroPadding:!1});m.on("error",s),m.pipe(g).on("data",r).on("end",o).on("error",s)}function l(e,n,i){var o=n.announceList;o||("string"==typeof n.announce?o=[[n.announce]]:Array.isArray(n.announce)&&(o=n.announce.map(function(e){return[e]}))),o||(o=[]),r.WEBTORRENT_ANNOUNCE&&("string"==typeof r.WEBTORRENT_ANNOUNCE?o.push([[r.WEBTORRENT_ANNOUNCE]]):Array.isArray(r.WEBTORRENT_ANNOUNCE)&&(o=o.concat(r.WEBTORRENT_ANNOUNCE.map(function(e){return[e]})))),void 0===n.announce&&void 0===n.announceList&&(o=o.concat(t.exports.announceList)),"string"==typeof n.urlList&&(n.urlList=[n.urlList]);var s={info:{name:n.name},"creation date":Number(n.creationDate)||Date.now(),encoding:"UTF-8"};0!==o.length&&(s.announce=o[0][0],s["announce-list"]=o),void 0!==n.comment&&(s.comment=n.comment),void 0!==n.createdBy&&(s["created by"]=n.createdBy),void 0!==n["private"]&&(s.info["private"]=Number(n["private"])),void 0!==n.sslCert&&(s.info["ssl-cert"]=n.sslCert),void 0!==n.urlList&&(s["url-list"]=n.urlList);var a=n.pieceLength||x(e.reduce(p,0));s.info["piece length"]=a,h(e,a,function(t,r,o){return t?i(t):(s.info.pieces=r,e.forEach(function(e){delete e.getStream}),n.singleFileTorrent?s.info.length=o:s.info.files=e,void i(null,E.encode(s)))})}function p(e,t){return e+t.length}function m(e){return"undefined"!=typeof Blob&&e instanceof Blob}function g(e){return"function"==typeof FileList&&e instanceof FileList}function y(e){return"object"==typeof e&&null!=e&&"function"==typeof e.pipe}function v(e){return function(){return new I(e)}}function _(e){return function(){var t=new M.PassThrough;return t.end(e),t}}function b(e){return function(){return C.createReadStream(e)}}function w(e,t){return function(){var n=new M.Transform;return n._transform=function(e,n,r){t.length+=e.length,this.push(e),r()},e.pipe(n),n}}t.exports=o,t.exports.parseInput=s,t.exports.announceList=[["udp://tracker.openbittorrent.com:80"],["udp://tracker.internetwarriors.net:1337"],["udp://tracker.leechers-paradise.org:6969"],["udp://tracker.coppersurfer.tk:6969"],["udp://exodus.desync.com:6969"],["wss://tracker.webtorrent.io"],["wss://tracker.btorrent.xyz"],["wss://tracker.openwebtorrent.com"]];var E=e("bencode"),k=e("block-stream2"),x=e("piece-length"),S=e("path"),B=e("xtend"),I=e("filestream/read"),A=e("flatten"),C=e("fs"),T=e("is-file"),L=e("junk"),R=e("multistream"),U=e("once"),P=e("run-parallel"),O=e("simple-sha1"),M=e("stream")}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer)},{_process:34,bencode:55,"block-stream2":59,buffer:26,"filestream/read":63,flatten:64,fs:24,"is-file":65,junk:66,multistream:81,once:68,path:33,"piece-length":69,"run-parallel":130,"simple-sha1":139,stream:39,xtend:156}],55:[function(e,t,n){arguments[4][12][0].apply(n,arguments)},{"./lib/decode":56,"./lib/encode":58,dup:12}],56:[function(e,t,n){arguments[4][13][0].apply(n,arguments)},{"./dict":57,buffer:26,dup:13}],57:[function(e,t,n){arguments[4][14][0].apply(n,arguments)},{dup:14}],58:[function(e,t,n){arguments[4][15][0].apply(n,arguments)},{buffer:26,dup:15}],59:[function(e,t,n){arguments[4][50][0].apply(n,arguments)},{buffer:26,defined:60,dup:50,inherits:79,"readable-stream":109}],60:[function(e,t,n){arguments[4][51][0].apply(n,arguments)},{dup:51}],61:[function(e,t,n){(function(n){var r=e("is-typedarray").strict;t.exports=function(e){if(r(e)){var t=new n(e.buffer);return e.byteLength!==e.buffer.byteLength&&(t=t.slice(e.byteOffset,e.byteOffset+e.byteLength)),t}return new n(e)}}).call(this,e("buffer").Buffer)},{buffer:26,"is-typedarray":62}],62:[function(e,t,n){arguments[4][23][0].apply(n,arguments)},{dup:23}],63:[function(e,t,n){function r(e,t){var n=this;return this instanceof r?(t=t||{},i.call(this,t),this._offset=0,this._ready=!1,this._file=e,this._size=e.size,this._chunkSize=t.chunkSize||Math.max(this._size/1e3,204800),this.reader=new FileReader,void this._generateHeaderBlocks(e,t,function(e,t){return e?n.emit("error",e):(Array.isArray(t)&&t.forEach(function(e){n.push(e)}),n._ready=!0,void n.emit("_ready"))})):new r(e,t)}var i=e("stream").Readable,o=e("inherits"),s=e("typedarray-to-buffer");o(r,i),t.exports=r,r.prototype._generateHeaderBlocks=function(e,t,n){n(null,[])},r.prototype._read=function(){if(!this._ready)return void this.once("_ready",this._read.bind(this));var e=this,t=this.reader,n=this._offset,r=this._offset+this._chunkSize;return r>this._size&&(r=this._size),n===this._size?(this.destroy(),void this.push(null)):(t.onload=function(){e._offset=r,e.push(s(t.result))},t.onerror=function(){e.emit("error",t.error); +},void t.readAsArrayBuffer(this._file.slice(n,r)))},r.prototype.destroy=function(){if(this._file=null,this.reader){this.reader.onload=null,this.reader.onerror=null;try{this.reader.abort()}catch(e){}}this.reader=null}},{inherits:79,stream:39,"typedarray-to-buffer":61}],64:[function(e,t,n){t.exports=function(e,t){function n(e,r){return e.reduce(function(e,i){return Array.isArray(i)&&t>r?e.concat(n(i,r+1)):e.concat(i)},[])}return t="number"==typeof t?t:1/0,n(e,1)}},{}],65:[function(e,t,n){"use strict";function r(e){return i.existsSync(e)&&i.statSync(e).isFile()}var i=e("fs");t.exports=function(e,t){return t?void i.stat(e,function(e,n){return e?t(e):t(null,n.isFile())}):r(e)},t.exports.sync=r},{fs:24}],66:[function(e,t,n){"use strict";n.re=/^npm-debug\.log$|^\..*\.swp$|^\.DS_Store$|^\.AppleDouble$|^\.LSOverride$|^Icon[\r\?]?|^\._.*|^\.Spotlight-V100$|\.Trashes|^__MACOSX$|~$|^Thumbs\.db$|^ehthumbs\.db$|^Desktop\.ini$/,n.is=function(e){return n.re.test(e)},n.not=n.isnt=function(e){return!n.is(e)}},{}],67:[function(e,t,n){arguments[4][20][0].apply(n,arguments)},{dup:20}],68:[function(e,t,n){arguments[4][21][0].apply(n,arguments)},{dup:21,wrappy:67}],69:[function(e,t,n){for(var r=e("closest-to"),i=[],o=14;22>=o;o++)i.push(Math.pow(2,o));t.exports=function(e){return r(e/Math.pow(2,10),i)}},{"closest-to":70}],70:[function(e,t,n){t.exports=function(e,t){var n=1/0,r=0,i=null;t.sort(function(e,t){return e-t});for(var o=0,s=t.length;s>o&&(r=Math.abs(e-t[o]),!(r>=n));o++)n=r,i=t[o];return i}},{}],71:[function(e,t,n){function r(){return"WebkitAppearance"in document.documentElement.style||window.console&&(console.firebug||console.exception&&console.table)||navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31}function i(){var e=arguments,t=this.useColors;if(e[0]=(t?"%c":"")+this.namespace+(t?" %c":" ")+e[0]+(t?"%c ":" ")+"+"+n.humanize(this.diff),!t)return e;var r="color: "+this.color;e=[e[0],r,"color: inherit"].concat(Array.prototype.slice.call(e,1));var i=0,o=0;return e[0].replace(/%[a-z%]/g,function(e){"%%"!==e&&(i++,"%c"===e&&(o=i))}),e.splice(o,0,r),e}function o(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function s(e){try{null==e?n.storage.removeItem("debug"):n.storage.debug=e}catch(t){}}function a(){var e;try{e=n.storage.debug}catch(t){}return e}function u(){try{return window.localStorage}catch(e){}}n=t.exports=e("./debug"),n.log=o,n.formatArgs=i,n.save=s,n.load=a,n.useColors=r,n.storage="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:u(),n.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],n.formatters.j=function(e){return JSON.stringify(e)},n.enable(a())},{"./debug":72}],72:[function(e,t,n){function r(){return n.colors[f++%n.colors.length]}function i(e){function t(){}function i(){var e=i,t=+new Date,o=t-(c||t);e.diff=o,e.prev=c,e.curr=t,c=t,null==e.useColors&&(e.useColors=n.useColors()),null==e.color&&e.useColors&&(e.color=r());var s=Array.prototype.slice.call(arguments);s[0]=n.coerce(s[0]),"string"!=typeof s[0]&&(s=["%o"].concat(s));var a=0;s[0]=s[0].replace(/%([a-z%])/g,function(t,r){if("%%"===t)return t;a++;var i=n.formatters[r];if("function"==typeof i){var o=s[a];t=i.call(e,o),s.splice(a,1),a--}return t}),"function"==typeof n.formatArgs&&(s=n.formatArgs.apply(e,s));var u=i.log||n.log||console.log.bind(console);u.apply(e,s)}t.enabled=!1,i.enabled=!0;var o=n.enabled(e)?i:t;return o.namespace=e,o}function o(e){n.save(e);for(var t=(e||"").split(/[\s,]+/),r=t.length,i=0;r>i;i++)t[i]&&(e=t[i].replace(/\*/g,".*?"),"-"===e[0]?n.skips.push(new RegExp("^"+e.substr(1)+"$")):n.names.push(new RegExp("^"+e+"$")))}function s(){n.enable("")}function a(e){var t,r;for(t=0,r=n.skips.length;r>t;t++)if(n.skips[t].test(e))return!1;for(t=0,r=n.names.length;r>t;t++)if(n.names[t].test(e))return!0;return!1}function u(e){return e instanceof Error?e.stack||e.message:e}n=t.exports=i,n.coerce=u,n.disable=s,n.enable=o,n.enabled=a,n.humanize=e("ms"),n.names=[],n.skips=[],n.formatters={};var c,f=0},{ms:73}],73:[function(e,t,n){function r(e){if(e=""+e,!(e.length>1e4)){var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(t){var n=parseFloat(t[1]),r=(t[2]||"ms").toLowerCase();switch(r){case"years":case"year":case"yrs":case"yr":case"y":return n*d;case"days":case"day":case"d":return n*f;case"hours":case"hour":case"hrs":case"hr":case"h":return n*c;case"minutes":case"minute":case"mins":case"min":case"m":return n*u;case"seconds":case"second":case"secs":case"sec":case"s":return n*a;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n}}}}function i(e){return e>=f?Math.round(e/f)+"d":e>=c?Math.round(e/c)+"h":e>=u?Math.round(e/u)+"m":e>=a?Math.round(e/a)+"s":e+"ms"}function o(e){return s(e,f,"day")||s(e,c,"hour")||s(e,u,"minute")||s(e,a,"second")||e+" ms"}function s(e,t,n){return t>e?void 0:1.5*t>e?Math.floor(e/t)+" "+n:Math.ceil(e/t)+" "+n+"s"}var a=1e3,u=60*a,c=60*u,f=24*c,d=365.25*f;t.exports=function(e,t){return t=t||{},"string"==typeof e?r(e):t["long"]?o(e):i(e)}},{}],74:[function(e,t,n){var r=e("once"),i=function(){},o=function(e){return e.setHeader&&"function"==typeof e.abort},s=function(e){return e.stdio&&Array.isArray(e.stdio)&&3===e.stdio.length},a=function(e,t,n){if("function"==typeof t)return a(e,null,t);t||(t={}),n=r(n||i);var u=e._writableState,c=e._readableState,f=t.readable||t.readable!==!1&&e.readable,d=t.writable||t.writable!==!1&&e.writable,h=function(){e.writable||l()},l=function(){d=!1,f||n()},p=function(){f=!1,d||n()},m=function(e){n(e?new Error("exited with error code: "+e):null)},g=function(){return(!f||c&&c.ended)&&(!d||u&&u.ended)?void 0:n(new Error("premature close"))},y=function(){e.req.on("finish",l)};return o(e)?(e.on("complete",l),e.on("abort",g),e.req?y():e.on("request",y)):d&&!u&&(e.on("end",h),e.on("close",h)),s(e)&&e.on("exit",m),e.on("end",p),e.on("finish",l),t.error!==!1&&e.on("error",n),e.on("close",g),function(){e.removeListener("complete",l),e.removeListener("abort",g),e.removeListener("request",y),e.req&&e.req.removeListener("finish",l),e.removeListener("end",h),e.removeListener("close",h),e.removeListener("finish",l),e.removeListener("exit",m),e.removeListener("end",p),e.removeListener("error",n),e.removeListener("close",g)}};t.exports=a},{once:76}],75:[function(e,t,n){arguments[4][20][0].apply(n,arguments)},{dup:20}],76:[function(e,t,n){arguments[4][21][0].apply(n,arguments)},{dup:21,wrappy:75}],77:[function(e,t,n){var r=t.exports=function(e,t){if(t||(t=16),void 0===e&&(e=128),0>=e)return"0";for(var n=Math.log(Math.pow(2,e))/Math.log(t),i=2;n===1/0;i*=2)n=Math.log(Math.pow(2,e/i))/Math.log(t)*i;for(var o=n-Math.floor(n),s="",i=0;i<Math.floor(n);i++){var a=Math.floor(Math.random()*t).toString(t);s=a+s}if(o){var u=Math.pow(t,o),a=Math.floor(Math.random()*u).toString(t);s=a+s}var c=parseInt(s,t);return c!==1/0&&c>=Math.pow(2,e)?r(e,t):s};r.rack=function(e,t,n){var i=function(i){var s=0;do{if(s++>10){if(!n)throw new Error("too many ID collisions, use more bits");e+=n}var a=r(e,t)}while(Object.hasOwnProperty.call(o,a));return o[a]=i,a},o=i.hats={};return i.get=function(e){return i.hats[e]},i.set=function(e,t){return i.hats[e]=t,i},i.bits=e||128,i.base=t||16,i}},{}],78:[function(e,t,n){(function(e){function n(e){if(!(this instanceof n))return new n(e);if(this.store=e,this.chunkLength=e.chunkLength,!this.store||!this.store.get||!this.store.put)throw new Error("First argument must be abstract-chunk-store compliant");this.mem=[]}function r(t,n,r){e.nextTick(function(){t&&t(n,r)})}t.exports=n,n.prototype.put=function(e,t,n){var r=this;r.mem[e]=t,r.store.put(e,t,function(t){r.mem[e]=null,n&&n(t)})},n.prototype.get=function(e,t,n){if("function"==typeof t)return this.get(e,null,t);var i=t&&t.offset||0,o=t&&t.length&&i+t.length,s=this.mem[e];return s?r(n,null,t?s.slice(i,o):s):void this.store.get(e,t,n)},n.prototype.close=function(e){this.store.close(e)},n.prototype.destroy=function(e){this.store.destroy(e)}}).call(this,e("_process"))},{_process:34}],79:[function(e,t,n){"function"==typeof Object.create?t.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}},{}],80:[function(e,t,n){(function(e){function n(e,t){if(!(this instanceof n))return new n(e,t);if(t||(t={}),this.chunkLength=Number(e),!this.chunkLength)throw new Error("First argument must be a chunk length");this.chunks=[],this.closed=!1,this.length=Number(t.length)||1/0,this.length!==1/0&&(this.lastChunkLength=this.length%this.chunkLength||this.chunkLength,this.lastChunkIndex=Math.ceil(this.length/this.chunkLength)-1)}function r(t,n,r){e.nextTick(function(){t&&t(n,r)})}t.exports=n,n.prototype.put=function(e,t,n){if(this.closed)return r(n,new Error("Storage is closed"));var i=e===this.lastChunkIndex;return i&&t.length!==this.lastChunkLength?r(n,new Error("Last chunk length must be "+this.lastChunkLength)):i||t.length===this.chunkLength?(this.chunks[e]=t,void r(n,null)):r(n,new Error("Chunk length must be "+this.chunkLength))},n.prototype.get=function(e,t,n){if("function"==typeof t)return this.get(e,null,t);if(this.closed)return r(n,new Error("Storage is closed"));var i=this.chunks[e];if(!i)return r(n,new Error("Chunk not found"));if(!t)return r(n,null,i);var o=t.offset||0,s=t.length||i.length-o;r(n,null,i.slice(o,s+o))},n.prototype.close=n.prototype.destroy=function(e){return this.closed?r(e,new Error("Storage is closed")):(this.closed=!0,this.chunks=null,void r(e,null))}}).call(this,e("_process"))},{_process:34}],81:[function(e,t,n){function r(e,t){return this instanceof r?(s.Readable.call(this,t),this.destroyed=!1,this._drained=!1,this._forwarding=!1,this._current=null,this._queue="function"==typeof e?e:e.map(i),void this._next()):new r(e,t)}function i(e){if(!e||"function"==typeof e||e._readableState)return e;var t=(new s.Readable).wrap(e);return e.destroy&&(t.destroy=e.destroy.bind(e)),t}t.exports=r;var o=e("inherits"),s=e("stream");o(r,s.Readable),r.obj=function(e){return new r(e,{objectMode:!0,highWaterMark:16})},r.prototype._read=function(){this._drained=!0,this._forward()},r.prototype._forward=function(){if(!this._forwarding&&this._drained&&this._current){this._forwarding=!0;for(var e;null!==(e=this._current.read());)this._drained=this.push(e);this._forwarding=!1}},r.prototype.destroy=function(e){this.destroyed||(this.destroyed=!0,this._current&&this._current.destroy&&this._current.destroy(),"function"!=typeof this._queue&&this._queue.forEach(function(e){e.destroy&&e.destroy()}),e&&this.emit("error",e),this.emit("close"))},r.prototype._next=function(){var e=this;if(e._current=null,"function"==typeof e._queue)e._queue(function(t,n){return t?e.destroy(t):void e._gotNextStream(i(n))});else{var t=e._queue.shift();"function"==typeof t&&(t=i(t())),e._gotNextStream(t)}},r.prototype._gotNextStream=function(e){function t(){o._forward()}function n(){e._readableState.ended||o.destroy()}function r(){o._current=null,e.removeListener("readable",t),e.removeListener("end",r),e.removeListener("error",i),e.removeListener("close",n),o._next()}function i(e){o.destroy(e)}var o=this;return e?(o._current=e,o._forward(),e.on("readable",t),e.on("end",r),e.on("error",i),void e.on("close",n)):(o.push(null),void o.destroy())}},{inherits:79,stream:39}],82:[function(e,t,n){(function(n,r){function i(e){if("string"==typeof e&&/magnet:/.test(e))return f(e);if("string"==typeof e&&(/^[a-f0-9]{40}$/i.test(e)||/^[a-z2-7]{32}$/i.test(e)))return f("magnet:?xt=urn:btih:"+e);if(n.isBuffer(e)&&20===e.length)return f("magnet:?xt=urn:btih:"+e.toString("hex"));if(n.isBuffer(e))return d(e);if(e&&e.infoHash)return e.announce||(e.announce=[]),"string"==typeof e.announce&&(e.announce=[e.announce]),e.urlList||(e.urlList=[]),e;throw new Error("Invalid torrent identifier")}function o(e,t){function n(e){try{o=i(e)}catch(n){return t(n)}o&&o.infoHash?t(null,o):t(new Error("Invalid torrent identifier"))}var o;if("function"!=typeof t)throw new Error("second argument must be a Function");try{o=i(e)}catch(f){}o&&o.infoHash?r.nextTick(function(){t(null,o)}):s(e)?a(e,function(e,r){return e?t(new Error("Error converting Blob: "+e.message)):void n(r)}):"function"==typeof c&&/^https?:/.test(e)?c.concat({url:e,headers:{"user-agent":"WebTorrent (http://webtorrent.io)"}},function(e,r,i){return e?t(new Error("Error downloading torrent: "+e.message)):void n(i)}):"function"==typeof u.readFile&&"string"==typeof e?u.readFile(e,function(e,r){return e?t(new Error("Invalid torrent identifier")):void n(r)}):r.nextTick(function(){t(new Error("Invalid torrent identifier"))})}function s(e){return"undefined"!=typeof Blob&&e instanceof Blob}t.exports=i,t.exports.remote=o;var a=e("blob-to-buffer"),u=e("fs"),c=e("simple-get"),f=e("magnet-uri"),d=e("parse-torrent-file");t.exports.toMagnetURI=f.encode,t.exports.toTorrentFile=d.encode}).call(this,{isBuffer:e("../browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js")},e("_process"))},{"../browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js":32,_process:34,"blob-to-buffer":83,fs:24,"magnet-uri":84,"parse-torrent-file":87,"simple-get":131}],83:[function(e,t,n){(function(e){t.exports=function(t,n){function r(t){i.removeEventListener("loadend",r,!1),t.error?n(t.error):n(null,new e(i.result))}if("undefined"==typeof Blob||!(t instanceof Blob))throw new Error("first argument must be a Blob");if("function"!=typeof n)throw new Error("second argument must be a function");var i=new FileReader;i.addEventListener("loadend",r,!1),i.readAsArrayBuffer(t)}}).call(this,e("buffer").Buffer)},{buffer:26}],84:[function(e,t,n){(function(n){function r(e){var t={},r=e.split("magnet:?")[1],i=r&&r.length>=0?r.split("&"):[];i.forEach(function(e){var n=e.split("=");if(2===n.length){var r=n[0],i=n[1];if("dn"===r&&(i=decodeURIComponent(i).replace(/\+/g," ")),("tr"===r||"xs"===r||"as"===r||"ws"===r)&&(i=decodeURIComponent(i)),"kt"===r&&(i=decodeURIComponent(i).split("+")),t[r])if(Array.isArray(t[r]))t[r].push(i);else{var o=t[r];t[r]=[o,i]}else t[r]=i}});var s;if(t.xt){var u=Array.isArray(t.xt)?t.xt:[t.xt];u.forEach(function(e){if(s=e.match(/^urn:btih:(.{40})/))t.infoHash=s[1].toLowerCase();else if(s=e.match(/^urn:btih:(.{32})/)){var r=o.decode(s[1]);t.infoHash=new n(r,"binary").toString("hex")}})}return t.infoHash&&(t.infoHashBuffer=new n(t.infoHash,"hex")),t.dn&&(t.name=t.dn),t.kt&&(t.keywords=t.kt),"string"==typeof t.tr?t.announce=[t.tr]:Array.isArray(t.tr)?t.announce=t.tr:t.announce=[],t.urlList=[],("string"==typeof t.as||Array.isArray(t.as))&&(t.urlList=t.urlList.concat(t.as)),("string"==typeof t.ws||Array.isArray(t.ws))&&(t.urlList=t.urlList.concat(t.ws)),a(t.announce),a(t.urlList),t}function i(e){e=s(e),e.infoHashBuffer&&(e.xt="urn:btih:"+e.infoHashBuffer.toString("hex")),e.infoHash&&(e.xt="urn:btih:"+e.infoHash),e.name&&(e.dn=e.name),e.keywords&&(e.kt=e.keywords),e.announce&&(e.tr=e.announce),e.urlList&&(e.ws=e.urlList,delete e.as);var t="magnet:?";return Object.keys(e).filter(function(e){return 2===e.length}).forEach(function(n,r){var i=Array.isArray(e[n])?e[n]:[e[n]];i.forEach(function(e,i){!(r>0||i>0)||"kt"===n&&0!==i||(t+="&"),"dn"===n&&(e=encodeURIComponent(e).replace(/%20/g,"+")),("tr"===n||"xs"===n||"as"===n||"ws"===n)&&(e=encodeURIComponent(e)),"kt"===n&&(e=encodeURIComponent(e)),t+="kt"===n&&i>0?"+"+e:n+"="+e})}),t}t.exports=r,t.exports.decode=r,t.exports.encode=i;var o=e("thirty-two"),s=e("xtend"),a=e("uniq")}).call(this,e("buffer").Buffer)},{buffer:26,"thirty-two":85,uniq:150,xtend:156}],85:[function(e,t,n){var r=e("./thirty-two");n.encode=r.encode,n.decode=r.decode},{"./thirty-two":86}],86:[function(e,t,n){(function(e){function t(e){var t=Math.floor(e.length/5);return e.length%5==0?t:t+1}var r="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",i=[255,255,26,27,28,29,30,31,255,255,255,255,255,255,255,255,255,0,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,255,255,255,255,255,255,0,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,255,255,255,255,255];n.encode=function(n){e.isBuffer(n)||(n=new e(n));for(var i=0,o=0,s=0,a=0,u=new e(8*t(n));i<n.length;){var c=n[i];s>3?(a=c&255>>s,s=(s+5)%8,a=a<<s|(i+1<n.length?n[i+1]:0)>>8-s,i++):(a=c>>8-(s+5)&31,s=(s+5)%8,0==s&&i++),u[o]=r.charCodeAt(a),o++}for(i=o;i<u.length;i++)u[i]=61;return u},n.decode=function(t){var n,r=0,o=0,s=0;e.isBuffer(t)||(t=new e(t));for(var a=new e(Math.ceil(5*t.length/8)),u=0;u<t.length&&61!=t[u];u++){var c=t[u]-48;if(!(c<i.length))throw new Error("Invalid input - it is not base32 encoded string");o=i[c],3>=r?(r=(r+5)%8,0==r?(n|=o,a[s]=n,s++,n=0):n|=255&o<<8-r):(r=(r+5)%8,n|=255&o>>>r,a[s]=n,s++,n=255&o<<8-r)}return a.slice(0,s)}}).call(this,e("buffer").Buffer)},{buffer:26}],87:[function(e,t,n){(function(n){function r(e){n.isBuffer(e)&&(e=u.decode(e)),a(e.info,"info"),a(e.info["name.utf-8"]||e.info.name,"info.name"),a(e.info["piece length"],"info['piece length']"),a(e.info.pieces,"info.pieces"),e.info.files?e.info.files.forEach(function(e){a("number"==typeof e.length,"info.files[0].length"),a(e["path.utf-8"]||e.path,"info.files[0].path")}):a("number"==typeof e.info.length,"info.length");var t={};t.info=e.info,t.infoBuffer=u.encode(e.info),t.infoHash=f.sync(t.infoBuffer),t.infoHashBuffer=new n(t.infoHash,"hex"),t.name=(e.info["name.utf-8"]||e.info.name).toString(),void 0!==e.info["private"]&&(t["private"]=!!e.info["private"]),e["creation date"]&&(t.created=new Date(1e3*e["creation date"])),e["created by"]&&(t.createdBy=e["created by"].toString()),n.isBuffer(e.comment)&&(t.comment=e.comment.toString()),t.announce=[],e["announce-list"]&&e["announce-list"].length?e["announce-list"].forEach(function(e){e.forEach(function(e){t.announce.push(e.toString())})}):e.announce&&t.announce.push(e.announce.toString()),n.isBuffer(e["url-list"])&&(e["url-list"]=e["url-list"].length>0?[e["url-list"]]:[]),t.urlList=(e["url-list"]||[]).map(function(e){return e.toString()}),d(t.announce),d(t.urlList);var r=e.info.files||[e.info];t.files=r.map(function(e,n){var i=[].concat(t.name,e["path.utf-8"]||e.path||[]).map(function(e){return e.toString()});return{path:c.join.apply(null,[c.sep].concat(i)).slice(1),name:i[i.length-1],length:e.length,offset:r.slice(0,n).reduce(o,0)}}),t.length=r.reduce(o,0);var i=t.files[t.files.length-1];return t.pieceLength=e.info["piece length"],t.lastPieceLength=(i.offset+i.length)%t.pieceLength||t.pieceLength,t.pieces=s(e.info.pieces),t}function i(e){var t={info:e.info};return t["announce-list"]=e.announce.map(function(e){return t.announce||(t.announce=e),e=new n(e,"utf8"),[e]}),e.created&&(t["creation date"]=e.created.getTime()/1e3|0),e.urlList&&(t["url-list"]=e.urlList),u.encode(t)}function o(e,t){return e+t.length}function s(e){for(var t=[],n=0;n<e.length;n+=20)t.push(e.slice(n,n+20).toString("hex"));return t}function a(e,t){if(!e)throw new Error("Torrent is missing required field: "+t)}t.exports=r,t.exports.decode=r,t.exports.encode=i;var u=e("bencode"),c=e("path"),f=e("simple-sha1"),d=e("uniq")}).call(this,e("buffer").Buffer)},{bencode:88,buffer:26,path:33,"simple-sha1":139,uniq:150}],88:[function(e,t,n){arguments[4][12][0].apply(n,arguments)},{"./lib/decode":89,"./lib/encode":91,dup:12}],89:[function(e,t,n){arguments[4][13][0].apply(n,arguments)},{"./dict":90,buffer:26,dup:13}],90:[function(e,t,n){arguments[4][14][0].apply(n,arguments)},{dup:14}],91:[function(e,t,n){arguments[4][15][0].apply(n,arguments)},{buffer:26,dup:15}],92:[function(e,t,n){var r=e("once"),i=e("end-of-stream"),o=e("fs"),s=function(){},a=function(e){return"function"==typeof e},u=function(e){return(e instanceof(o.ReadStream||s)||e instanceof(o.WriteStream||s))&&a(e.close)},c=function(e){return e.setHeader&&a(e.abort)},f=function(e,t,n,o){o=r(o);var s=!1;e.on("close",function(){s=!0}),i(e,{readable:t,writable:n},function(e){return e?o(e):(s=!0,void o())});var f=!1;return function(t){return s||f?void 0:(f=!0,u(e)?e.close():c(e)?e.abort():a(e.destroy)?e.destroy():void o(t||new Error("stream was destroyed")))}},d=function(e){e()},h=function(e,t){return e.pipe(t)},l=function(){var e=Array.prototype.slice.call(arguments),t=a(e[e.length-1]||s)&&e.pop()||s;if(Array.isArray(e[0])&&(e=e[0]),e.length<2)throw new Error("pump requires two streams per minimum");var n,r=e.map(function(i,o){var s=o<e.length-1,a=o>0;return f(i,s,a,function(e){n||(n=e),e&&r.forEach(d),s||(r.forEach(d),t(n))})});return e.reduce(h)};t.exports=l},{"end-of-stream":74,fs:24,once:94}],93:[function(e,t,n){arguments[4][20][0].apply(n,arguments)},{dup:20}],94:[function(e,t,n){arguments[4][21][0].apply(n,arguments)},{dup:21,wrappy:93}],95:[function(e,t,n){var r=function(e){var t=0;return function(){if(t===e.length)return null;var n=e.length-t,r=Math.random()*n|0,i=e[t+r],o=e[t];return e[t]=i,e[t+r]=o,t++,i}};t.exports=r},{}],96:[function(e,t,n){function r(e,t,n){Array.isArray(n)||(n=[n]);var r=[];return n.forEach(function(n){var i=function(){var e=[].slice.call(arguments);e.unshift(n),t.emit.apply(t,e)};r.push(i),e.on(n,i)}),function(){n.forEach(function(t,n){e.removeListener(t,r[n])})}}function i(e,t){var n=new o;return r(e,n,t),n}t.exports=r,t.exports.filter=i;var o=e("events").EventEmitter},{events:30}],97:[function(e,t,n){t.exports=e("./lib/_stream_duplex.js")},{"./lib/_stream_duplex.js":98}],98:[function(e,t,n){"use strict";function r(e){return this instanceof r?(c.call(this,e),f.call(this,e),e&&e.readable===!1&&(this.readable=!1),e&&e.writable===!1&&(this.writable=!1),this.allowHalfOpen=!0,e&&e.allowHalfOpen===!1&&(this.allowHalfOpen=!1),void this.once("end",i)):new r(e)}function i(){this.allowHalfOpen||this._writableState.ended||a(o,this)}function o(e){e.end()}var s=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};t.exports=r;var a=e("process-nextick-args"),u=e("core-util-is");u.inherits=e("inherits");var c=e("./_stream_readable"),f=e("./_stream_writable");u.inherits(r,c);for(var d=s(f.prototype),h=0;h<d.length;h++){var l=d[h];r.prototype[l]||(r.prototype[l]=f.prototype[l])}},{"./_stream_readable":100,"./_stream_writable":102,"core-util-is":103,inherits:79,"process-nextick-args":105}],99:[function(e,t,n){"use strict";function r(e){return this instanceof r?void i.call(this,e):new r(e)}t.exports=r;var i=e("./_stream_transform"),o=e("core-util-is");o.inherits=e("inherits"),o.inherits(r,i),r.prototype._transform=function(e,t,n){n(null,e)}},{"./_stream_transform":101,"core-util-is":103,inherits:79}],100:[function(e,t,n){(function(n){"use strict";function r(t,n){P=P||e("./_stream_duplex"),t=t||{},this.objectMode=!!t.objectMode,n instanceof P&&(this.objectMode=this.objectMode||!!t.readableObjectMode);var r=t.highWaterMark,i=this.objectMode?16:16384;this.highWaterMark=r||0===r?r:i,this.highWaterMark=~~this.highWaterMark,this.buffer=[],this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.defaultEncoding=t.defaultEncoding||"utf8",this.ranOut=!1,this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,t.encoding&&(U||(U=e("string_decoder/").StringDecoder),this.decoder=new U(t.encoding),this.encoding=t.encoding)}function i(t){return P=P||e("./_stream_duplex"),this instanceof i?(this._readableState=new r(t,this),this.readable=!0,t&&"function"==typeof t.read&&(this._read=t.read),void A.call(this)):new i(t)}function o(e,t,n,r,i){var o=c(t,n);if(o)e.emit("error",o);else if(null===n)t.reading=!1,f(e,t);else if(t.objectMode||n&&n.length>0)if(t.ended&&!i){var a=new Error("stream.push() after EOF");e.emit("error",a)}else if(t.endEmitted&&i){var a=new Error("stream.unshift() after end event");e.emit("error",a)}else!t.decoder||i||r||(n=t.decoder.write(n)),i||(t.reading=!1),t.flowing&&0===t.length&&!t.sync?(e.emit("data",n),e.read(0)):(t.length+=t.objectMode?1:n.length,i?t.buffer.unshift(n):t.buffer.push(n),t.needReadable&&d(e)),l(e,t);else i||(t.reading=!1);return s(t)}function s(e){return!e.ended&&(e.needReadable||e.length<e.highWaterMark||0===e.length)}function a(e){return e>=O?e=O:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function u(e,t){return 0===t.length&&t.ended?0:t.objectMode?0===e?0:1:null===e||isNaN(e)?t.flowing&&t.buffer.length?t.buffer[0].length:t.length:0>=e?0:(e>t.highWaterMark&&(t.highWaterMark=a(e)),e>t.length?t.ended?t.length:(t.needReadable=!0,0):e)}function c(e,t){var n=null;return I.isBuffer(t)||"string"==typeof t||null===t||void 0===t||e.objectMode||(n=new TypeError("Invalid non-string/buffer chunk")),n}function f(e,t){if(!t.ended){if(t.decoder){var n=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.ended=!0,d(e)}}function d(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(L("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?S(h,e):h(e))}function h(e){L("emit readable"),e.emit("readable"),_(e)}function l(e,t){t.readingMore||(t.readingMore=!0,S(p,e,t))}function p(e,t){for(var n=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length<t.highWaterMark&&(L("maybeReadMore read 0"),e.read(0),n!==t.length);)n=t.length;t.readingMore=!1}function m(e){return function(){var t=e._readableState;L("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&C(e,"data")&&(t.flowing=!0,_(e))}}function g(e){L("readable nexttick read 0"),e.read(0)}function y(e,t){t.resumeScheduled||(t.resumeScheduled=!0,S(v,e,t))}function v(e,t){t.reading||(L("resume read 0"),e.read(0)),t.resumeScheduled=!1,e.emit("resume"),_(e),t.flowing&&!t.reading&&e.read(0)}function _(e){var t=e._readableState;if(L("flow",t.flowing),t.flowing)do var n=e.read();while(null!==n&&t.flowing)}function b(e,t){var n,r=t.buffer,i=t.length,o=!!t.decoder,s=!!t.objectMode;if(0===r.length)return null;if(0===i)n=null;else if(s)n=r.shift();else if(!e||e>=i)n=o?r.join(""):1===r.length?r[0]:I.concat(r,i),r.length=0;else if(e<r[0].length){var a=r[0];n=a.slice(0,e),r[0]=a.slice(e)}else if(e===r[0].length)n=r.shift();else{n=o?"":new I(e);for(var u=0,c=0,f=r.length;f>c&&e>u;c++){var a=r[0],d=Math.min(e-u,a.length);o?n+=a.slice(0,d):a.copy(n,u,0,d),d<a.length?r[0]=a.slice(d):r.shift(),u+=d}}return n}function w(e){var t=e._readableState;if(t.length>0)throw new Error("endReadable called on non-empty stream");t.endEmitted||(t.ended=!0,S(E,t,e))}function E(e,t){e.endEmitted||0!==e.length||(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function k(e,t){for(var n=0,r=e.length;r>n;n++)t(e[n],n)}function x(e,t){for(var n=0,r=e.length;r>n;n++)if(e[n]===t)return n;return-1}t.exports=i;var S=e("process-nextick-args"),B=e("isarray"),I=e("buffer").Buffer;i.ReadableState=r;var A,C=(e("events"),function(e,t){return e.listeners(t).length});!function(){try{A=e("stream")}catch(t){}finally{A||(A=e("events").EventEmitter)}}();var I=e("buffer").Buffer,T=e("core-util-is");T.inherits=e("inherits");var L,R=e("util");L=R&&R.debuglog?R.debuglog("stream"):function(){};var U;T.inherits(i,A);var P,P;i.prototype.push=function(e,t){var n=this._readableState;return n.objectMode||"string"!=typeof e||(t=t||n.defaultEncoding,t!==n.encoding&&(e=new I(e,t),t="")),o(this,n,e,t,!1)},i.prototype.unshift=function(e){var t=this._readableState;return o(this,t,e,"",!0)},i.prototype.isPaused=function(){return this._readableState.flowing===!1},i.prototype.setEncoding=function(t){return U||(U=e("string_decoder/").StringDecoder),this._readableState.decoder=new U(t),this._readableState.encoding=t,this};var O=8388608;i.prototype.read=function(e){L("read",e);var t=this._readableState,n=e;if(("number"!=typeof e||e>0)&&(t.emittedReadable=!1),0===e&&t.needReadable&&(t.length>=t.highWaterMark||t.ended))return L("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?w(this):d(this),null;if(e=u(e,t),0===e&&t.ended)return 0===t.length&&w(this),null;var r=t.needReadable;L("need readable",r),(0===t.length||t.length-e<t.highWaterMark)&&(r=!0,L("length less than watermark",r)),(t.ended||t.reading)&&(r=!1,L("reading or ended",r)),r&&(L("do read"),t.reading=!0,t.sync=!0,0===t.length&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1),r&&!t.reading&&(e=u(n,t));var i;return i=e>0?b(e,t):null,null===i&&(t.needReadable=!0,e=0),t.length-=e,0!==t.length||t.ended||(t.needReadable=!0),n!==e&&t.ended&&0===t.length&&w(this),null!==i&&this.emit("data",i),i},i.prototype._read=function(e){this.emit("error",new Error("not implemented"))},i.prototype.pipe=function(e,t){function r(e){L("onunpipe"),e===d&&o()}function i(){L("onend"),e.end()}function o(){L("cleanup"),e.removeListener("close",u),e.removeListener("finish",c),e.removeListener("drain",g),e.removeListener("error",a),e.removeListener("unpipe",r),d.removeListener("end",i),d.removeListener("end",o),d.removeListener("data",s),y=!0,!h.awaitDrain||e._writableState&&!e._writableState.needDrain||g()}function s(t){L("ondata");var n=e.write(t);!1===n&&(1!==h.pipesCount||h.pipes[0]!==e||1!==d.listenerCount("data")||y||(L("false write response, pause",d._readableState.awaitDrain),d._readableState.awaitDrain++),d.pause())}function a(t){L("onerror",t),f(),e.removeListener("error",a),0===C(e,"error")&&e.emit("error",t)}function u(){e.removeListener("finish",c),f()}function c(){L("onfinish"),e.removeListener("close",u),f()}function f(){L("unpipe"),d.unpipe(e)}var d=this,h=this._readableState;switch(h.pipesCount){case 0:h.pipes=e;break;case 1:h.pipes=[h.pipes,e];break;default:h.pipes.push(e)}h.pipesCount+=1,L("pipe count=%d opts=%j",h.pipesCount,t);var l=(!t||t.end!==!1)&&e!==n.stdout&&e!==n.stderr,p=l?i:o;h.endEmitted?S(p):d.once("end",p),e.on("unpipe",r);var g=m(d);e.on("drain",g);var y=!1;return d.on("data",s),e._events&&e._events.error?B(e._events.error)?e._events.error.unshift(a):e._events.error=[a,e._events.error]:e.on("error",a),e.once("close",u),e.once("finish",c),e.emit("pipe",d),h.flowing||(L("pipe resume"),d.resume()),e},i.prototype.unpipe=function(e){var t=this._readableState;if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this),this);if(!e){var n=t.pipes,r=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var i=0;r>i;i++)n[i].emit("unpipe",this);return this}var i=x(t.pipes,e);return-1===i?this:(t.pipes.splice(i,1),t.pipesCount-=1,1===t.pipesCount&&(t.pipes=t.pipes[0]),e.emit("unpipe",this),this)},i.prototype.on=function(e,t){var n=A.prototype.on.call(this,e,t);if("data"===e&&!1!==this._readableState.flowing&&this.resume(),"readable"===e&&this.readable){var r=this._readableState;r.readableListening||(r.readableListening=!0,r.emittedReadable=!1,r.needReadable=!0,r.reading?r.length&&d(this,r):S(g,this))}return n},i.prototype.addListener=i.prototype.on,i.prototype.resume=function(){var e=this._readableState;return e.flowing||(L("resume"),e.flowing=!0,y(this,e)),this},i.prototype.pause=function(){return L("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(L("pause"),this._readableState.flowing=!1,this.emit("pause")),this},i.prototype.wrap=function(e){var t=this._readableState,n=!1,r=this;e.on("end",function(){if(L("wrapped end"),t.decoder&&!t.ended){var e=t.decoder.end();e&&e.length&&r.push(e)}r.push(null)}),e.on("data",function(i){if(L("wrapped data"),t.decoder&&(i=t.decoder.write(i)),(!t.objectMode||null!==i&&void 0!==i)&&(t.objectMode||i&&i.length)){var o=r.push(i);o||(n=!0,e.pause())}});for(var i in e)void 0===this[i]&&"function"==typeof e[i]&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));var o=["error","close","destroy","pause","resume"];return k(o,function(t){e.on(t,r.emit.bind(r,t))}),r._read=function(t){L("wrapped _read",t),n&&(n=!1,e.resume())},r},i._fromList=b}).call(this,e("_process")); +},{"./_stream_duplex":98,_process:34,buffer:26,"core-util-is":103,events:30,inherits:79,isarray:104,"process-nextick-args":105,"string_decoder/":106,util:25}],101:[function(e,t,n){"use strict";function r(e){this.afterTransform=function(t,n){return i(e,t,n)},this.needTransform=!1,this.transforming=!1,this.writecb=null,this.writechunk=null}function i(e,t,n){var r=e._transformState;r.transforming=!1;var i=r.writecb;if(!i)return e.emit("error",new Error("no writecb in Transform class"));r.writechunk=null,r.writecb=null,null!==n&&void 0!==n&&e.push(n),i&&i(t);var o=e._readableState;o.reading=!1,(o.needReadable||o.length<o.highWaterMark)&&e._read(o.highWaterMark)}function o(e){if(!(this instanceof o))return new o(e);a.call(this,e),this._transformState=new r(this);var t=this;this._readableState.needReadable=!0,this._readableState.sync=!1,e&&("function"==typeof e.transform&&(this._transform=e.transform),"function"==typeof e.flush&&(this._flush=e.flush)),this.once("prefinish",function(){"function"==typeof this._flush?this._flush(function(e){s(t,e)}):s(t)})}function s(e,t){if(t)return e.emit("error",t);var n=e._writableState,r=e._transformState;if(n.length)throw new Error("calling transform done when ws.length != 0");if(r.transforming)throw new Error("calling transform done when still transforming");return e.push(null)}t.exports=o;var a=e("./_stream_duplex"),u=e("core-util-is");u.inherits=e("inherits"),u.inherits(o,a),o.prototype.push=function(e,t){return this._transformState.needTransform=!1,a.prototype.push.call(this,e,t)},o.prototype._transform=function(e,t,n){throw new Error("not implemented")},o.prototype._write=function(e,t,n){var r=this._transformState;if(r.writecb=n,r.writechunk=e,r.writeencoding=t,!r.transforming){var i=this._readableState;(r.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}},o.prototype._read=function(e){var t=this._transformState;null!==t.writechunk&&t.writecb&&!t.transforming?(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform)):t.needTransform=!0}},{"./_stream_duplex":98,"core-util-is":103,inherits:79}],102:[function(e,t,n){"use strict";function r(){}function i(e,t,n){this.chunk=e,this.encoding=t,this.callback=n,this.next=null}function o(t,n){I=I||e("./_stream_duplex"),t=t||{},this.objectMode=!!t.objectMode,n instanceof I&&(this.objectMode=this.objectMode||!!t.writableObjectMode);var r=t.highWaterMark,i=this.objectMode?16:16384;this.highWaterMark=r||0===r?r:i,this.highWaterMark=~~this.highWaterMark,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1;var o=t.decodeStrings===!1;this.decodeStrings=!o,this.defaultEncoding=t.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(e){p(n,e)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1}function s(t){return I=I||e("./_stream_duplex"),this instanceof s||this instanceof I?(this._writableState=new o(t,this),this.writable=!0,t&&("function"==typeof t.write&&(this._write=t.write),"function"==typeof t.writev&&(this._writev=t.writev)),void S.call(this)):new s(t)}function a(e,t){var n=new Error("write after end");e.emit("error",n),E(t,n)}function u(e,t,n,r){var i=!0;if(!k.isBuffer(n)&&"string"!=typeof n&&null!==n&&void 0!==n&&!t.objectMode){var o=new TypeError("Invalid non-string/buffer chunk");e.emit("error",o),E(r,o),i=!1}return i}function c(e,t,n){return e.objectMode||e.decodeStrings===!1||"string"!=typeof t||(t=new k(t,n)),t}function f(e,t,n,r,o){n=c(t,n,r),k.isBuffer(n)&&(r="buffer");var s=t.objectMode?1:n.length;t.length+=s;var a=t.length<t.highWaterMark;if(a||(t.needDrain=!0),t.writing||t.corked){var u=t.lastBufferedRequest;t.lastBufferedRequest=new i(n,r,o),u?u.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest}else d(e,t,!1,s,n,r,o);return a}function d(e,t,n,r,i,o,s){t.writelen=r,t.writecb=s,t.writing=!0,t.sync=!0,n?e._writev(i,t.onwrite):e._write(i,o,t.onwrite),t.sync=!1}function h(e,t,n,r,i){--t.pendingcb,n?E(i,r):i(r),e._writableState.errorEmitted=!0,e.emit("error",r)}function l(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}function p(e,t){var n=e._writableState,r=n.sync,i=n.writecb;if(l(n),t)h(e,n,r,t,i);else{var o=v(n);o||n.corked||n.bufferProcessing||!n.bufferedRequest||y(e,n),r?E(m,e,n,o,i):m(e,n,o,i)}}function m(e,t,n,r){n||g(e,t),t.pendingcb--,r(),b(e,t)}function g(e,t){0===t.length&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}function y(e,t){t.bufferProcessing=!0;var n=t.bufferedRequest;if(e._writev&&n&&n.next){for(var r=[],i=[];n;)i.push(n.callback),r.push(n),n=n.next;t.pendingcb++,t.lastBufferedRequest=null,d(e,t,!0,t.length,r,"",function(e){for(var n=0;n<i.length;n++)t.pendingcb--,i[n](e)})}else{for(;n;){var o=n.chunk,s=n.encoding,a=n.callback,u=t.objectMode?1:o.length;if(d(e,t,!1,u,o,s,a),n=n.next,t.writing)break}null===n&&(t.lastBufferedRequest=null)}t.bufferedRequest=n,t.bufferProcessing=!1}function v(e){return e.ending&&0===e.length&&null===e.bufferedRequest&&!e.finished&&!e.writing}function _(e,t){t.prefinished||(t.prefinished=!0,e.emit("prefinish"))}function b(e,t){var n=v(t);return n&&(0===t.pendingcb?(_(e,t),t.finished=!0,e.emit("finish")):_(e,t)),n}function w(e,t,n){t.ending=!0,b(e,t),n&&(t.finished?E(n):e.once("finish",n)),t.ended=!0}t.exports=s;var E=e("process-nextick-args"),k=e("buffer").Buffer;s.WritableState=o;var x=e("core-util-is");x.inherits=e("inherits");var S,B={deprecate:e("util-deprecate")};!function(){try{S=e("stream")}catch(t){}finally{S||(S=e("events").EventEmitter)}}();var k=e("buffer").Buffer;x.inherits(s,S);var I;o.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(o.prototype,"buffer",{get:B.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.")})}catch(e){}}();var I;s.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe. Not readable."))},s.prototype.write=function(e,t,n){var i=this._writableState,o=!1;return"function"==typeof t&&(n=t,t=null),k.isBuffer(e)?t="buffer":t||(t=i.defaultEncoding),"function"!=typeof n&&(n=r),i.ended?a(this,n):u(this,i,e,n)&&(i.pendingcb++,o=f(this,i,e,t,n)),o},s.prototype.cork=function(){var e=this._writableState;e.corked++},s.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.finished||e.bufferProcessing||!e.bufferedRequest||y(this,e))},s.prototype.setDefaultEncoding=function(e){if("string"==typeof e&&(e=e.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((e+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+e);this._writableState.defaultEncoding=e},s.prototype._write=function(e,t,n){n(new Error("not implemented"))},s.prototype._writev=null,s.prototype.end=function(e,t,n){var r=this._writableState;"function"==typeof e?(n=e,e=null,t=null):"function"==typeof t&&(n=t,t=null),null!==e&&void 0!==e&&this.write(e,t),r.corked&&(r.corked=1,this.uncork()),r.ending||r.finished||w(this,r,n)}},{"./_stream_duplex":98,buffer:26,"core-util-is":103,events:30,inherits:79,"process-nextick-args":105,"util-deprecate":107}],103:[function(e,t,n){(function(e){function t(e){return Array.isArray?Array.isArray(e):"[object Array]"===g(e)}function r(e){return"boolean"==typeof e}function i(e){return null===e}function o(e){return null==e}function s(e){return"number"==typeof e}function a(e){return"string"==typeof e}function u(e){return"symbol"==typeof e}function c(e){return void 0===e}function f(e){return"[object RegExp]"===g(e)}function d(e){return"object"==typeof e&&null!==e}function h(e){return"[object Date]"===g(e)}function l(e){return"[object Error]"===g(e)||e instanceof Error}function p(e){return"function"==typeof e}function m(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||"undefined"==typeof e}function g(e){return Object.prototype.toString.call(e)}n.isArray=t,n.isBoolean=r,n.isNull=i,n.isNullOrUndefined=o,n.isNumber=s,n.isString=a,n.isSymbol=u,n.isUndefined=c,n.isRegExp=f,n.isObject=d,n.isDate=h,n.isError=l,n.isFunction=p,n.isPrimitive=m,n.isBuffer=e.isBuffer}).call(this,{isBuffer:e("../../../../browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js")})},{"../../../../browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js":32}],104:[function(e,t,n){t.exports=Array.isArray||function(e){return"[object Array]"==Object.prototype.toString.call(e)}},{}],105:[function(e,t,n){(function(e){"use strict";function n(t){for(var n=new Array(arguments.length-1),r=0;r<n.length;)n[r++]=arguments[r];e.nextTick(function(){t.apply(null,n)})}!e.version||0===e.version.indexOf("v0.")||0===e.version.indexOf("v1.")&&0!==e.version.indexOf("v1.8.")?t.exports=n:t.exports=e.nextTick}).call(this,e("_process"))},{_process:34}],106:[function(e,t,n){function r(e){if(e&&!u(e))throw new Error("Unknown encoding: "+e)}function i(e){return e.toString(this.encoding)}function o(e){this.charReceived=e.length%2,this.charLength=this.charReceived?2:0}function s(e){this.charReceived=e.length%3,this.charLength=this.charReceived?3:0}var a=e("buffer").Buffer,u=a.isEncoding||function(e){switch(e&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}},c=n.StringDecoder=function(e){switch(this.encoding=(e||"utf8").toLowerCase().replace(/[-_]/,""),r(e),this.encoding){case"utf8":this.surrogateSize=3;break;case"ucs2":case"utf16le":this.surrogateSize=2,this.detectIncompleteChar=o;break;case"base64":this.surrogateSize=3,this.detectIncompleteChar=s;break;default:return void(this.write=i)}this.charBuffer=new a(6),this.charReceived=0,this.charLength=0};c.prototype.write=function(e){for(var t="";this.charLength;){var n=e.length>=this.charLength-this.charReceived?this.charLength-this.charReceived:e.length;if(e.copy(this.charBuffer,this.charReceived,0,n),this.charReceived+=n,this.charReceived<this.charLength)return"";e=e.slice(n,e.length),t=this.charBuffer.slice(0,this.charLength).toString(this.encoding);var r=t.charCodeAt(t.length-1);if(!(r>=55296&&56319>=r)){if(this.charReceived=this.charLength=0,0===e.length)return t;break}this.charLength+=this.surrogateSize,t=""}this.detectIncompleteChar(e);var i=e.length;this.charLength&&(e.copy(this.charBuffer,0,e.length-this.charReceived,i),i-=this.charReceived),t+=e.toString(this.encoding,0,i);var i=t.length-1,r=t.charCodeAt(i);if(r>=55296&&56319>=r){var o=this.surrogateSize;return this.charLength+=o,this.charReceived+=o,this.charBuffer.copy(this.charBuffer,o,0,o),e.copy(this.charBuffer,0,0,o),t.substring(0,i)}return t},c.prototype.detectIncompleteChar=function(e){for(var t=e.length>=3?3:e.length;t>0;t--){var n=e[e.length-t];if(1==t&&n>>5==6){this.charLength=2;break}if(2>=t&&n>>4==14){this.charLength=3;break}if(3>=t&&n>>3==30){this.charLength=4;break}}this.charReceived=t},c.prototype.end=function(e){var t="";if(e&&e.length&&(t=this.write(e)),this.charReceived){var n=this.charReceived,r=this.charBuffer,i=this.encoding;t+=r.slice(0,n).toString(i)}return t}},{buffer:26}],107:[function(e,t,n){(function(e){function n(e,t){function n(){if(!i){if(r("throwDeprecation"))throw new Error(t);r("traceDeprecation")?console.trace(t):console.warn(t),i=!0}return e.apply(this,arguments)}if(r("noDeprecation"))return e;var i=!1;return n}function r(t){try{if(!e.localStorage)return!1}catch(n){return!1}var r=e.localStorage[t];return null==r?!1:"true"===String(r).toLowerCase()}t.exports=n}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],108:[function(e,t,n){t.exports=e("./lib/_stream_passthrough.js")},{"./lib/_stream_passthrough.js":99}],109:[function(e,t,n){var r=function(){try{return e("stream")}catch(t){}}();n=t.exports=e("./lib/_stream_readable.js"),n.Stream=r||n,n.Readable=n,n.Writable=e("./lib/_stream_writable.js"),n.Duplex=e("./lib/_stream_duplex.js"),n.Transform=e("./lib/_stream_transform.js"),n.PassThrough=e("./lib/_stream_passthrough.js")},{"./lib/_stream_duplex.js":98,"./lib/_stream_passthrough.js":99,"./lib/_stream_readable.js":100,"./lib/_stream_transform.js":101,"./lib/_stream_writable.js":102}],110:[function(e,t,n){t.exports=e("./lib/_stream_transform.js")},{"./lib/_stream_transform.js":101}],111:[function(e,t,n){t.exports=e("./lib/_stream_writable.js")},{"./lib/_stream_writable.js":102}],112:[function(e,t,n){(function(t){function r(e,t,n){u(e),"string"==typeof t&&(t=document.querySelector(t)),o(e,function(n){if(t.nodeName!==n.toUpperCase()){var r=p.extname(e.name).toLowerCase();throw new Error('Cannot render "'+r+'" inside a "'+t.nodeName.toLowerCase()+'" element, expected "'+n+'"')}return t},n)}function i(e,t,n){function r(e){var n=i(e);return n.controls=!0,n.autoplay=!0,n.play(),t.appendChild(n),n}function i(e){var n=document.createElement(e);return t.appendChild(n),n}if(n||(n=function(){}),u(e),"string"==typeof t&&(t=document.querySelector(t)),t&&("VIDEO"===t.nodeName||"AUDIO"===t.nodeName))throw new Error("Invalid video/audio node argument. Argument must be root element that video/audio tag will be appended to.");o(e,function(e){return"video"===e||"audio"===e?r(e):i(e)},function(e,t){e&&t&&t.remove(),n(e,t)})}function o(e,t,n){function r(){function r(){d("Use `videostream` package for "+e.name),p(),S.addEventListener("error",f),S.addEventListener("playing",i),g(e,S)}function o(){d("Use MediaSource API for "+e.name),p(),S.addEventListener("error",h),S.addEventListener("playing",i);var t=new l(S),n=t.createWriteStream(c(e.name));e.createReadStream().pipe(n),I&&(S.currentTime=I)}function u(){d("Use Blob URL for "+e.name),p(),S.addEventListener("error",_),S.addEventListener("playing",i),a(e,function(e,t){return e?_(e):(S.src=t,void(I&&(S.currentTime=I)))})}function f(e){d("videostream error: fallback to MediaSource API: %o",e.message||e),S.removeEventListener("error",f),S.removeEventListener("playing",i),o()}function h(e){d("MediaSource API error: fallback to Blob URL: %o",e.message||e),S.removeEventListener("error",h),S.removeEventListener("playing",i),u()}function p(){S||(S=t(m),S.addEventListener("progress",function(){I=S.currentTime}))}if(!x)return s(n,new Error("Video/audio streaming is not supported in your browser. You can still share or download "+e.name+" (once it's fully downloaded). Use Chrome for MediaSource support."));var m=v.indexOf(B)>=0?"video":"audio";y.indexOf(B)>=0?r():o()}function i(){S.removeEventListener("playing",i),n(null,S)}function o(){S=t("audio"),a(e,function(e,t){return e?_(e):(S.addEventListener("error",_),S.addEventListener("playing",i),void(S.src=t))})}function u(){S=t("img"),a(e,function(t,r){return t?_(t):(S.src=r,S.alt=e.name,void n(null,S))})}function f(){S=t("iframe"),a(e,function(e,t){return e?_(e):(S.src=t,".pdf"!==B&&(S.sandbox="allow-forms allow-scripts"),void n(null,S))})}function m(){function t(){h(r)?(d('File extension "%s" appears ascii, so will render.',B),f()):(d('File extension "%s" appears non-ascii, will not render.',B),n(new Error('Unsupported file type "'+B+'": Cannot append to DOM')))}d('Unknown file extension "%s" - will attempt to render into iframe',B);var r="";e.createReadStream({start:0,end:1e3}).setEncoding("utf8").on("data",function(e){r+=e}).on("end",t).on("error",n)}function _(t){t.message='Error rendering file "'+e.name+'": '+t.message,d(t.message),n(t)}n||(n=function(){});var S,B=p.extname(e.name).toLowerCase(),I=0;b.indexOf(B)>=0?r():w.indexOf(B)>=0?o():E.indexOf(B)>=0?u():k.indexOf(B)>=0?f():m()}function s(e,n,r){t.nextTick(function(){e(n,r)})}function a(e,t){var n=p.extname(e.name).toLowerCase();m(e.createReadStream(),f[n],t)}function u(e){if(null==e)throw new Error("file cannot be null or undefined");if("string"!=typeof e.name)throw new Error("missing or invalid file.name property");if("function"!=typeof e.createReadStream)throw new Error("missing or invalid file.createReadStream property")}function c(e){var t=p.extname(e).toLowerCase();return{".m4a":'audio/mp4; codecs="mp4a.40.5"',".m4v":'video/mp4; codecs="avc1.640029, mp4a.40.5"',".mp3":"audio/mpeg",".mp4":'video/mp4; codecs="avc1.640029, mp4a.40.5"',".webm":'video/webm; codecs="vorbis, vp8"'}[t]}n.render=r,n.append=i;var f=n.mime=e("./lib/mime.json"),d=e("debug")("render-media"),h=e("is-ascii"),l=e("mediasource"),p=e("path"),m=e("stream-to-blob-url"),g=e("videostream"),y=[".mp4",".m4v",".m4a"],v=[".mp4",".m4v",".webm"],_=[".m4a",".mp3"],b=v.concat(_),w=[".wav",".aac",".ogg",".oga"],E=[".jpg",".jpeg",".png",".gif",".bmp"],k=[".css",".html",".js",".md",".pdf",".txt"],x="undefined"!=typeof window&&window.MediaSource}).call(this,e("_process"))},{"./lib/mime.json":113,_process:34,debug:71,"is-ascii":114,mediasource:115,path:33,"stream-to-blob-url":142,videostream:128}],113:[function(e,t,n){t.exports={".3gp":"video/3gpp",".aac":"audio/aac",".aif":"audio/x-aiff",".aiff":"audio/x-aiff",".atom":"application/atom+xml",".avi":"video/x-msvideo",".bmp":"image/bmp",".bz2":"application/x-bzip2",".conf":"text/plain",".css":"text/css",".csv":"text/csv",".diff":"text/x-diff",".doc":"application/msword",".flv":"video/x-flv",".gif":"image/gif",".gz":"application/x-gzip",".htm":"text/html",".html":"text/html",".ico":"image/vnd.microsoft.icon",".ics":"text/calendar",".iso":"application/octet-stream",".jar":"application/java-archive",".jpeg":"image/jpeg",".jpg":"image/jpeg",".js":"application/javascript",".json":"application/json",".less":"text/css",".log":"text/plain",".m3u":"audio/x-mpegurl",".m4a":"audio/mp4",".m4v":"video/mp4",".manifest":"text/cache-manifest",".markdown":"text/x-markdown",".mathml":"application/mathml+xml",".md":"text/x-markdown",".mid":"audio/midi",".midi":"audio/midi",".mov":"video/quicktime",".mp3":"audio/mpeg",".mp4":"video/mp4",".mp4v":"video/mp4",".mpeg":"video/mpeg",".mpg":"video/mpeg",".odp":"application/vnd.oasis.opendocument.presentation",".ods":"application/vnd.oasis.opendocument.spreadsheet",".odt":"application/vnd.oasis.opendocument.text",".oga":"audio/ogg",".ogg":"application/ogg",".pdf":"application/pdf",".png":"image/png",".pps":"application/vnd.ms-powerpoint",".ppt":"application/vnd.ms-powerpoint",".ps":"application/postscript",".psd":"image/vnd.adobe.photoshop",".qt":"video/quicktime",".rar":"application/x-rar-compressed",".rdf":"application/rdf+xml",".rss":"application/rss+xml",".rtf":"application/rtf",".svg":"image/svg+xml",".svgz":"image/svg+xml",".swf":"application/x-shockwave-flash",".tar":"application/x-tar",".tbz":"application/x-bzip-compressed-tar",".text":"text/plain",".tif":"image/tiff",".tiff":"image/tiff",".torrent":"application/x-bittorrent",".ttf":"application/x-font-ttf",".txt":"text/plain",".wav":"audio/wav",".webm":"video/webm",".wma":"audio/x-ms-wma",".wmv":"video/x-ms-wmv",".xls":"application/vnd.ms-excel",".xml":"application/xml",".yaml":"text/yaml",".yml":"text/yaml",".zip":"application/zip"}},{}],114:[function(e,t,n){var r=127;t.exports=function(e){for(var t=0,n=e.length;n>t;++t)if(e.charCodeAt(t)>r)return!1;return!0}},{}],115:[function(e,t,n){function r(e,t){var n=this;if(!(n instanceof r))return new r(e,t);if(!u)throw new Error("web browser lacks MediaSource support");t||(t={}),n._bufferDuration=t.bufferDuration||c,n._elem=e,n._mediaSource=new u,n._streams=[],n.detailedError=null,n._errorHandler=function(){n._elem.removeEventListener("error",n._errorHandler);var e=n._streams.slice();e.forEach(function(e){e.destroy(n._elem.error)})},n._elem.addEventListener("error",n._errorHandler),n._elem.src=window.URL.createObjectURL(n._mediaSource)}function i(e,t){var n=this;if(s.Writable.call(n),n._wrapper=e,n._elem=e._elem,n._mediaSource=e._mediaSource,n._allStreams=e._streams,n._allStreams.push(n),n._bufferDuration=e._bufferDuration,n._openHandler=n._onSourceOpen.bind(n,t),n._flowHandler=n._flow.bind(n),"string"==typeof t)"open"===n._mediaSource.readyState?n._createSourceBuffer(t):n._mediaSource.addEventListener("sourceopen",n._openHandler);else{if(!t._sourceBuffer)throw new Error("The argument to MediaElementWrapper.createWriteStream must be a string or a previous stream returned from that function");t.destroy(),n._sourceBuffer=t._sourceBuffer,n._sourceBuffer.addEventListener("updateend",n._flowHandler)}n._elem.addEventListener("timeupdate",n._flowHandler),n.on("error",n._wrapper.error.bind(n._wrapper)),n.on("finish",function(){if(!n.destroyed&&(n._finished=!0,n._allStreams.every(function(e){return e._finished})))try{n._mediaSource.endOfStream()}catch(e){}})}t.exports=r;var o=e("inherits"),s=e("readable-stream"),a=e("to-arraybuffer"),u="undefined"!=typeof window&&window.MediaSource,c=60;r.prototype.createWriteStream=function(e){var t=this;return new i(t,e)},r.prototype.error=function(e){var t=this;t.detailedError||(t.detailedError=e);try{t._mediaSource.endOfStream("decode")}catch(e){}},o(i,s.Writable),i.prototype._onSourceOpen=function(e){var t=this;t.destroyed||(t._mediaSource.removeEventListener("sourceopen",t._openHandler),t._createSourceBuffer(e))},i.prototype.destroy=function(e){var t=this;t.destroyed||(t.destroyed=!0,t._allStreams.splice(t._allStreams.indexOf(t),1),t._mediaSource.removeEventListener("sourceopen",t._openHandler),t._elem.removeEventListener("timeupdate",t._flowHandler),t._sourceBuffer&&(t._sourceBuffer.removeEventListener("updateend",t._flowHandler),"open"===t._mediaSource.readyState&&t._sourceBuffer.abort()),e&&t.emit("error",e),t.emit("close"))},i.prototype._createSourceBuffer=function(e){var t=this;if(!t.destroyed)if(u.isTypeSupported(e)){if(t._sourceBuffer=t._mediaSource.addSourceBuffer(e),t._sourceBuffer.addEventListener("updateend",t._flowHandler),t._cb){var n=t._cb;t._cb=null,n()}}else t.destroy(new Error("The provided type is not supported"))},i.prototype._write=function(e,t,n){var r=this;if(!r.destroyed){if(!r._sourceBuffer)return void(r._cb=function(i){return i?n(i):void r._write(e,t,n)});if(r._sourceBuffer.updating)return n(new Error("Cannot append buffer while source buffer updating"));try{r._sourceBuffer.appendBuffer(a(e))}catch(i){return void r.destroy(i)}r._cb=n}},i.prototype._flow=function(){var e=this;if(!e.destroyed&&e._sourceBuffer&&!e._sourceBuffer.updating&&!("open"===e._mediaSource.readyState&&e._getBufferDuration()>e._bufferDuration)&&e._cb){var t=e._cb;e._cb=null,t()}};var f=0;i.prototype._getBufferDuration=function(){for(var e=this,t=e._sourceBuffer.buffered,n=e._elem.currentTime,r=-1,i=0;i<t.length;i++){var o=t.start(i),s=t.end(i)+f;if(o>n)break;(r>=0||s>=n)&&(r=s)}var a=r-n;return 0>a&&(a=0),a}},{inherits:79,"readable-stream":109,"to-arraybuffer":116}],116:[function(e,t,n){arguments[4][45][0].apply(n,arguments)},{buffer:26,dup:45}],117:[function(e,t,n){function r(e){var t=this;a.call(t),t._tracks=[],t._fragmentSequence=1,t._file=e,t._decoder=null,t._findMoov(0)}function i(e,t){var n=this;n._entries=e,n._countName=t||"count",n._index=0,n._offset=0,n.value=n._entries[0]}function o(){return{version:0,flags:0,entries:[]}}var s=e("binary-search"),a=e("events"),u=e("inherits"),c=e("mp4-stream"),f=e("mp4-box-encoding"),d=e("range-slice-stream");t.exports=r,u(r,a),r.prototype._findMoov=function(e){var t=this;t._decoder&&t._decoder.destroy(),t._decoder=c.decode();var n=t._file.createReadStream({start:e});n.pipe(t._decoder),t._decoder.once("box",function(r){"moov"===r.type?t._decoder.decode(function(e){n.destroy(),t._processMoov(e)}):(n.destroy(),t._findMoov(e+r.length))})},i.prototype.inc=function(){var e=this;e._offset++,e._offset>=e._entries[e._index][e._countName]&&(e._index++,e._offset=0),e.value=e._entries[e._index]},r.prototype._processMoov=function(e){var t=this,n=e.traks;t._tracks=[],t._hasVideo=!1,t._hasAudio=!1;for(var r=0;r<n.length;r++){var s,a,u=n[r],c=u.mdia.minf.stbl,f=c.stsd.entries[0],d=u.mdia.hdlr.handlerType;if("vide"===d&&"avc1"===f.type){if(t._hasVideo)continue;t._hasVideo=!0,s="avc1",f.avcC&&(s+="."+f.avcC.mimeCodec),a='video/mp4; codecs="'+s+'"'}else{if("soun"!==d||"mp4a"!==f.type)continue;if(t._hasAudio)continue;t._hasAudio=!0,s="mp4a",f.esds&&f.esds.mimeCodec&&(s+="."+f.esds.mimeCodec),a='audio/mp4; codecs="'+s+'"'}var h=[],l=0,p=0,m=0,g=0,y=0,v=0,_=new i(c.stts.entries),b=null;c.ctts&&(b=new i(c.ctts.entries));for(var w=0;;){var E=c.stsc.entries[y],k=c.stsz.entries[l],x=_.value.duration,S=b?b.value.compositionOffset:0,B=!0;if(c.stss&&(B=c.stss.entries[w]===l+1),h.push({size:k,duration:x,dts:v,presentationOffset:S,sync:B,offset:g+c.stco.entries[m]}),l++,l>=c.stsz.entries.length)break;if(p++,g+=k,p>=E.samplesPerChunk){p=0,g=0,m++;var I=c.stsc.entries[y+1];I&&m+1>=I.firstChunk&&y++}v+=x,_.inc(),b&&b.inc(),B&&w++}u.mdia.mdhd.duration=0,u.tkhd.duration=0;var A=E.sampleDescriptionId,C={type:"moov",mvhd:e.mvhd,traks:[{tkhd:u.tkhd,mdia:{mdhd:u.mdia.mdhd,hdlr:u.mdia.hdlr,elng:u.mdia.elng,minf:{vmhd:u.mdia.minf.vmhd,smhd:u.mdia.minf.smhd,dinf:u.mdia.minf.dinf,stbl:{stsd:c.stsd,stts:o(),ctts:o(),stsc:o(),stsz:o(),stco:o(),stss:o()}}}}],mvex:{mehd:{fragmentDuration:e.mvhd.duration},trexs:[{trackId:u.tkhd.trackId,defaultSampleDescriptionIndex:A,defaultSampleDuration:0,defaultSampleSize:0,defaultSampleFlags:0}]}};t._tracks.push({trackId:u.tkhd.trackId,timeScale:u.mdia.mdhd.timeScale,samples:h,currSample:null,currTime:null,moov:C,mime:a})}if(0===t._tracks.length)return void t.emit("error",new Error("no playable tracks"));e.mvhd.duration=0,t._ftyp={type:"ftyp",brand:"iso5",brandVersion:0,compatibleBrands:["iso5"]};var T=t._tracks.map(function(e){return{mime:e.mime}});t.emit("ready",T)},r.prototype.seek=function(e,t){var n=this;if(!n._tracks)throw new Error("Not ready yet; wait for 'ready' event");n._fileStream&&(n._fileStream.destroy(),n._fileStream=null);var r=-1;if(n._tracks.map(function(i,o){function s(e){a.destroyed||a.box(e.moof,function(t){if(t)return n.emit("error",t);if(!a.destroyed){var r=i.inStream.slice(e.ranges);r.pipe(a.mediaData(e.length,function(e){if(e)return n.emit("error",e);if(!a.destroyed){var t=n._generateFragment(o);return t?void s(t):a.finalize()}}))}})}i.outStream&&i.outStream.destroy(),i.inStream&&(i.inStream.destroy(),i.inStream=null);var a=i.outStream=c.encode(),u=n._generateFragment(o,e);return u?((-1===r||u.ranges[0].start<r)&&(r=u.ranges[0].start),void(t?a.box(n._ftyp,function(e){return e?n.emit("error",e):void(a.destroyed||a.box(i.moov,function(e){return e?n.emit("error",e):void s(u)}))}):s(u))):a.finalize()}),r>=0){var i=n._fileStream=n._file.createReadStream({start:r});n._tracks.forEach(function(e){e.inStream=new d(r),i.pipe(e.inStream)})}return n._tracks.map(function(e){return e.outStream})},r.prototype._findSampleBefore=function(e,t){var n=this,r=n._tracks[e],i=Math.floor(r.timeScale*t),o=s(r.samples,i,function(e,t){var n=e.dts+e.presentationOffset;return n-t});for(-1===o?o=0:0>o&&(o=-o-2);!r.samples[o].sync;)o--;return o};var h=1;r.prototype._generateFragment=function(e,t){var n,r=this,i=r._tracks[e];if(n=void 0!==t?r._findSampleBefore(e,t):i.currSample,n>=i.samples.length)return null;for(var o=i.samples[n].dts,s=0,a=[],u=n;u<i.samples.length;u++){var c=i.samples[u];if(c.sync&&c.dts-o>=i.timeScale*h)break;s+=c.size;var f=a.length-1;0>f||a[f].end!==c.offset?a.push({start:c.offset,end:c.offset+c.size}):a[f].end+=c.size}return i.currSample=u,{moof:r._generateMoof(e,n,u),ranges:a,length:s}},r.prototype._generateMoof=function(e,t,n){for(var r=this,i=r._tracks[e],o=[],s=t;n>s;s++){var a=i.samples[s];o.push({sampleDuration:a.duration,sampleSize:a.size,sampleFlags:a.sync?33554432:16842752,sampleCompositionTimeOffset:a.presentationOffset})}var u={type:"moof",mfhd:{sequenceNumber:r._fragmentSequence++},trafs:[{tfhd:{flags:131072,trackId:i.trackId},tfdt:{baseMediaDecodeTime:i.samples[t].dts},trun:{flags:3841,dataOffset:8,entries:o}}]};return u.trafs[0].trun.dataOffset+=f.encodingLength(u),u}},{"binary-search":118,events:30,inherits:79,"mp4-box-encoding":121,"mp4-stream":125,"range-slice-stream":127}],118:[function(e,t,n){t.exports=function(e,t,n,r,i){var o,s;if(void 0===r)r=0;else if(r=0|r,0>r||r>=e.length)throw new RangeError("invalid lower bound");if(void 0===i)i=e.length-1;else if(i=0|i,r>i||i>=e.length)throw new RangeError("invalid upper bound");for(;i>=r;)if(o=r+(i-r>>1),s=+n(e[o],t),0>s)r=o+1;else{if(!(s>0))return o;i=o-1}return~r}},{}],119:[function(e,t,n){(function(t){function r(e,t,n){for(var r=t;n>r;r++)e[r]=0}function i(e,t,n){t.writeUInt32BE(Math.floor((e.getTime()+g)/1e3),n)}function o(e,t,n){t.writeUInt16BE(Math.floor(e)%65536,n),t.writeUInt16BE(Math.floor(256*e*256)%65536,n+2)}function s(e,t,n){t[n]=Math.floor(e)%256,t[n+1]=Math.floor(256*e)%256}function a(e,t,n){e||(e=[0,0,0,0,0,0,0,0,0]);for(var r=0;r<e.length;r++)o(e[r],t,n+4*r)}function u(e,n,r){var i=new t(e,"utf8");i.copy(n,r),n[r+i.length]=0}function c(e){for(var t=new Array(e.length/4),n=0;n<t.length;n++)t[n]=d(e,4*n);return t}function f(e,t){return new Date(1e3*e.readUInt32BE(t)-g)}function d(e,t){return e.readUInt16BE(t)+e.readUInt16BE(t+2)/65536}function h(e,t){return e[t]+e[t+1]/256}function l(e,t,n){var r;for(r=0;n>r&&0!==e[t+r];r++);return e.toString("utf8",t,t+r)}var p=e("./index"),m=e("./descriptor"),g=20828448e5;n.fullBoxes={};var y=["mvhd","tkhd","mdhd","vmhd","smhd","stsd","esds","stsz","stco","stss","stts","ctts","stsc","dref","elst","hdlr","mehd","trex","mfhd","tfhd","tfdt","trun"];y.forEach(function(e){n.fullBoxes[e]=!0}),n.ftyp={},n.ftyp.encode=function(e,r,i){r=r?r.slice(i):new t(n.ftyp.encodingLength(e));var o=e.compatibleBrands||[];r.write(e.brand,0,4,"ascii"),r.writeUInt32BE(e.brandVersion,4);for(var s=0;s<o.length;s++)r.write(o[s],8+4*s,4,"ascii");return n.ftyp.encode.bytes=8+4*o.length,r},n.ftyp.decode=function(e,t){e=e.slice(t);for(var n=e.toString("ascii",0,4),r=e.readUInt32BE(4),i=[],o=8;o<e.length;o+=4)i.push(e.toString("ascii",o,o+4));return{brand:n,brandVersion:r,compatibleBrands:i}},n.ftyp.encodingLength=function(e){return 8+4*(e.compatibleBrands||[]).length},n.mvhd={},n.mvhd.encode=function(e,u,c){return u=u?u.slice(c):new t(96),i(e.ctime||new Date,u,0),i(e.mtime||new Date,u,4),u.writeUInt32BE(e.timeScale||0,8),u.writeUInt32BE(e.duration||0,12),o(e.preferredRate||0,u,16),s(e.preferredVolume||0,u,20),r(u,22,32),a(e.matrix,u,32),u.writeUInt32BE(e.previewTime||0,68),u.writeUInt32BE(e.previewDuration||0,72),u.writeUInt32BE(e.posterTime||0,76),u.writeUInt32BE(e.selectionTime||0,80),u.writeUInt32BE(e.selectionDuration||0,84),u.writeUInt32BE(e.currentTime||0,88),u.writeUInt32BE(e.nextTrackId||0,92),n.mvhd.encode.bytes=96,u},n.mvhd.decode=function(e,t){return e=e.slice(t),{ctime:f(e,0),mtime:f(e,4),timeScale:e.readUInt32BE(8),duration:e.readUInt32BE(12),preferredRate:d(e,16),preferredVolume:h(e,20),matrix:c(e.slice(32,68)),previewTime:e.readUInt32BE(68),previewDuration:e.readUInt32BE(72),posterTime:e.readUInt32BE(76),selectionTime:e.readUInt32BE(80),selectionDuration:e.readUInt32BE(84),currentTime:e.readUInt32BE(88),nextTrackId:e.readUInt32BE(92)}},n.mvhd.encodingLength=function(e){return 96},n.tkhd={},n.tkhd.encode=function(e,o,s){return o=o?o.slice(s):new t(80),i(e.ctime||new Date,o,0),i(e.mtime||new Date,o,4),o.writeUInt32BE(e.trackId||0,8),r(o,12,16),o.writeUInt32BE(e.duration||0,16),r(o,20,28),o.writeUInt16BE(e.layer||0,28),o.writeUInt16BE(e.alternateGroup||0,30),o.writeUInt16BE(e.volume||0,32),a(e.matrix,o,36),o.writeUInt32BE(e.trackWidth||0,72),o.writeUInt32BE(e.trackHeight||0,76),n.tkhd.encode.bytes=80,o},n.tkhd.decode=function(e,t){return e=e.slice(t),{ctime:f(e,0),mtime:f(e,4),trackId:e.readUInt32BE(8),duration:e.readUInt32BE(16),layer:e.readUInt16BE(28),alternateGroup:e.readUInt16BE(30),volume:e.readUInt16BE(32),matrix:c(e.slice(36,72)),trackWidth:e.readUInt32BE(72),trackHeight:e.readUInt32BE(76)}},n.tkhd.encodingLength=function(e){return 80},n.mdhd={},n.mdhd.encode=function(e,r,o){return r=r?r.slice(o):new t(20), +i(e.ctime||new Date,r,0),i(e.mtime||new Date,r,4),r.writeUInt32BE(e.timeScale||0,8),r.writeUInt32BE(e.duration||0,12),r.writeUInt16BE(e.language||0,16),r.writeUInt16BE(e.quality||0,18),n.mdhd.encode.bytes=20,r},n.mdhd.decode=function(e,t){return e=e.slice(t),{ctime:f(e,0),mtime:f(e,4),timeScale:e.readUInt32BE(8),duration:e.readUInt32BE(12),language:e.readUInt16BE(16),quality:e.readUInt16BE(18)}},n.mdhd.encodingLength=function(e){return 20},n.vmhd={},n.vmhd.encode=function(e,r,i){r=r?r.slice(i):new t(8),r.writeUInt16BE(e.graphicsMode||0,0);var o=e.opcolor||[0,0,0];return r.writeUInt16BE(o[0],2),r.writeUInt16BE(o[1],4),r.writeUInt16BE(o[2],6),n.vmhd.encode.bytes=8,r},n.vmhd.decode=function(e,t){return e=e.slice(t),{graphicsMode:e.readUInt16BE(0),opcolor:[e.readUInt16BE(2),e.readUInt16BE(4),e.readUInt16BE(6)]}},n.vmhd.encodingLength=function(e){return 8},n.smhd={},n.smhd.encode=function(e,i,o){return i=i?i.slice(o):new t(4),i.writeUInt16BE(e.balance||0,0),r(i,2,4),n.smhd.encode.bytes=4,i},n.smhd.decode=function(e,t){return e=e.slice(t),{balance:e.readUInt16BE(0)}},n.smhd.encodingLength=function(e){return 4},n.stsd={},n.stsd.encode=function(e,r,i){r=r?r.slice(i):new t(n.stsd.encodingLength(e));var o=e.entries||[];r.writeUInt32BE(o.length,0);for(var s=4,a=0;a<o.length;a++){var u=o[a];p.encode(u,r,s),s+=p.encode.bytes}return n.stsd.encode.bytes=s,r},n.stsd.decode=function(e,t,n){e=e.slice(t);for(var r=e.readUInt32BE(0),i=new Array(r),o=4,s=0;r>s;s++){var a=p.decode(e,o,n);i[s]=a,o+=a.length}return{entries:i}},n.stsd.encodingLength=function(e){var t=4;if(!e.entries)return t;for(var n=0;n<e.entries.length;n++)t+=p.encodingLength(e.entries[n]);return t},n.avc1=n.VisualSampleEntry={},n.VisualSampleEntry.encode=function(e,i,o){i=i?i.slice(o):new t(n.VisualSampleEntry.encodingLength(e)),r(i,0,6),i.writeUInt16BE(e.dataReferenceIndex||0,6),r(i,8,24),i.writeUInt16BE(e.width||0,24),i.writeUInt16BE(e.height||0,26),i.writeUInt32BE(e.hResolution||4718592,28),i.writeUInt32BE(e.vResolution||4718592,32),r(i,36,40),i.writeUInt16BE(e.frameCount||1,40);var s=e.compressorName||"",a=Math.min(s.length,31);i.writeUInt8(a,42),i.write(s,43,a,"utf8"),i.writeUInt16BE(e.depth||24,74),i.writeInt16BE(-1,76);var u=78,c=e.children||[];c.forEach(function(e){p.encode(e,i,u),u+=p.encode.bytes}),n.VisualSampleEntry.encode.bytes=u},n.VisualSampleEntry.decode=function(e,t,n){e=e.slice(t);for(var r=n-t,i=Math.min(e.readUInt8(42),31),o={dataReferenceIndex:e.readUInt16BE(6),width:e.readUInt16BE(24),height:e.readUInt16BE(26),hResolution:e.readUInt32BE(28),vResolution:e.readUInt32BE(32),frameCount:e.readUInt16BE(40),compressorName:e.toString("utf8",43,43+i),depth:e.readUInt16BE(74),children:[]},s=78;r-s>=8;){var a=p.decode(e,s,r);o.children.push(a),o[a.type]=a,s+=a.length}return o},n.VisualSampleEntry.encodingLength=function(e){var t=78,n=e.children||[];return n.forEach(function(e){t+=p.encodingLength(e)}),t},n.avcC={},n.avcC.encode=function(e,r,i){r=r?r.slice(i):t(e.buffer.length),e.buffer.copy(r),n.avcC.encode.bytes=e.buffer.length},n.avcC.decode=function(e,n,r){return e=e.slice(n,r),{mimeCodec:e.toString("hex",1,4),buffer:new t(e)}},n.avcC.encodingLength=function(e){return e.buffer.length},n.mp4a=n.AudioSampleEntry={},n.AudioSampleEntry.encode=function(e,i,o){i=i?i.slice(o):new t(n.AudioSampleEntry.encodingLength(e)),r(i,0,6),i.writeUInt16BE(e.dataReferenceIndex||0,6),r(i,8,16),i.writeUInt16BE(e.channelCount||2,16),i.writeUInt16BE(e.sampleSize||16,18),r(i,20,24),i.writeUInt32BE(e.sampleRate||0,24);var s=28,a=e.children||[];a.forEach(function(e){p.encode(e,i,s),s+=p.encode.bytes}),n.AudioSampleEntry.encode.bytes=s},n.AudioSampleEntry.decode=function(e,t,n){e=e.slice(t,n);for(var r=n-t,i={dataReferenceIndex:e.readUInt16BE(6),channelCount:e.readUInt16BE(16),sampleSize:e.readUInt16BE(18),sampleRate:e.readUInt32BE(24),children:[]},o=28;r-o>=8;){var s=p.decode(e,o,r);i.children.push(s),i[s.type]=s,o+=s.length}return i},n.AudioSampleEntry.encodingLength=function(e){var t=28,n=e.children||[];return n.forEach(function(e){t+=p.encodingLength(e)}),t},n.esds={},n.esds.encode=function(e,r,i){r=r?r.slice(i):t(e.buffer.length),e.buffer.copy(r,0),n.esds.encode.bytes=e.buffer.length},n.esds.decode=function(e,n,r){e=e.slice(n,r);var i=m.Descriptor.decode(e,0,e.length),o="ESDescriptor"===i.tagName?i:{},s=o.DecoderConfigDescriptor||{},a=s.oti||0,u=s.DecoderSpecificInfo||{},c=u?(248&u.buffer.readUInt8(0))>>3:0,f=null;return a&&(f=a.toString(16),c&&(f+="."+c)),{mimeCodec:f,buffer:new t(e.slice(0))}},n.esds.encodingLength=function(e){return e.buffer.length},n.stsz={},n.stsz.encode=function(e,r,i){var o=e.entries||[];r=r?r.slice(i):t(n.stsz.encodingLength(e)),r.writeUInt32BE(0,0),r.writeUInt32BE(o.length,4);for(var s=0;s<o.length;s++)r.writeUInt32BE(o[s],4*s+8);return n.stsz.encode.bytes=8+4*o.length,r},n.stsz.decode=function(e,t){e=e.slice(t);for(var n=e.readUInt32BE(0),r=e.readUInt32BE(4),i=new Array(r),o=0;r>o;o++)0===n?i[o]=e.readUInt32BE(4*o+8):i[o]=n;return{entries:i}},n.stsz.encodingLength=function(e){return 8+4*e.entries.length},n.stss=n.stco={},n.stco.encode=function(e,r,i){var o=e.entries||[];r=r?r.slice(i):new t(n.stco.encodingLength(e)),r.writeUInt32BE(o.length,0);for(var s=0;s<o.length;s++)r.writeUInt32BE(o[s],4*s+4);return n.stco.encode.bytes=4+4*o.length,r},n.stco.decode=function(e,t){e=e.slice(t);for(var n=e.readUInt32BE(0),r=new Array(n),i=0;n>i;i++)r[i]=e.readUInt32BE(4*i+4);return{entries:r}},n.stco.encodingLength=function(e){return 4+4*e.entries.length},n.stts={},n.stts.encode=function(e,r,i){var o=e.entries||[];r=r?r.slice(i):new t(n.stts.encodingLength(e)),r.writeUInt32BE(o.length,0);for(var s=0;s<o.length;s++){var a=8*s+4;r.writeUInt32BE(o[s].count||0,a),r.writeUInt32BE(o[s].duration||0,a+4)}return n.stts.encode.bytes=4+8*e.entries.length,r},n.stts.decode=function(e,t){e=e.slice(t);for(var n=e.readUInt32BE(0),r=new Array(n),i=0;n>i;i++){var o=8*i+4;r[i]={count:e.readUInt32BE(o),duration:e.readUInt32BE(o+4)}}return{entries:r}},n.stts.encodingLength=function(e){return 4+8*e.entries.length},n.ctts={},n.ctts.encode=function(e,r,i){var o=e.entries||[];r=r?r.slice(i):new t(n.ctts.encodingLength(e)),r.writeUInt32BE(o.length,0);for(var s=0;s<o.length;s++){var a=8*s+4;r.writeUInt32BE(o[s].count||0,a),r.writeUInt32BE(o[s].compositionOffset||0,a+4)}return n.ctts.encode.bytes=4+8*o.length,r},n.ctts.decode=function(e,t){e=e.slice(t);for(var n=e.readUInt32BE(0),r=new Array(n),i=0;n>i;i++){var o=8*i+4;r[i]={count:e.readUInt32BE(o),compositionOffset:e.readInt32BE(o+4)}}return{entries:r}},n.ctts.encodingLength=function(e){return 4+8*e.entries.length},n.stsc={},n.stsc.encode=function(e,r,i){var o=e.entries||[];r=r?r.slice(i):new t(n.stsc.encodingLength(e)),r.writeUInt32BE(o.length,0);for(var s=0;s<o.length;s++){var a=12*s+4;r.writeUInt32BE(o[s].firstChunk||0,a),r.writeUInt32BE(o[s].samplesPerChunk||0,a+4),r.writeUInt32BE(o[s].sampleDescriptionId||0,a+8)}return n.stsc.encode.bytes=4+12*o.length,r},n.stsc.decode=function(e,t){e=e.slice(t);for(var n=e.readUInt32BE(0),r=new Array(n),i=0;n>i;i++){var o=12*i+4;r[i]={firstChunk:e.readUInt32BE(o),samplesPerChunk:e.readUInt32BE(o+4),sampleDescriptionId:e.readUInt32BE(o+8)}}return{entries:r}},n.stsc.encodingLength=function(e){return 4+12*e.entries.length},n.dref={},n.dref.encode=function(e,r,i){r=r?r.slice(i):new t(n.dref.encodingLength(e));var o=e.entries||[];r.writeUInt32BE(o.length,0);for(var s=4,a=0;a<o.length;a++){var u=o[a],c=(u.buf?u.buf.length:0)+4+4;r.writeUInt32BE(c,s),s+=4,r.write(u.type,s,4,"ascii"),s+=4,u.buf&&(u.buf.copy(r,s),s+=u.buf.length)}return n.dref.encode.bytes=s,r},n.dref.decode=function(e,t){e=e.slice(t);for(var n=e.readUInt32BE(0),r=new Array(n),i=4,o=0;n>o;o++){var s=e.readUInt32BE(i),a=e.toString("ascii",i+4,i+8),u=e.slice(i+8,i+s);i+=s,r[o]={type:a,buf:u}}return{entries:r}},n.dref.encodingLength=function(e){var t=4;if(!e.entries)return t;for(var n=0;n<e.entries.length;n++){var r=e.entries[n].buf;t+=(r?r.length:0)+4+4}return t},n.elst={},n.elst.encode=function(e,r,i){var s=e.entries||[];r=r?r.slice(i):new t(n.elst.encodingLength(e)),r.writeUInt32BE(s.length,0);for(var a=0;a<s.length;a++){var u=12*a+4;r.writeUInt32BE(s[a].trackDuration||0,u),r.writeUInt32BE(s[a].mediaTime||0,u+4),o(s[a].mediaRate||0,r,u+8)}return n.elst.encode.bytes=4+12*s.length,r},n.elst.decode=function(e,t){e=e.slice(t);for(var n=e.readUInt32BE(0),r=new Array(n),i=0;n>i;i++){var o=12*i+4;r[i]={trackDuration:e.readUInt32BE(o),mediaTime:e.readInt32BE(o+4),mediaRate:d(e,o+8)}}return{entries:r}},n.elst.encodingLength=function(e){return 4+12*e.entries.length},n.hdlr={},n.hdlr.encode=function(e,r,i){r=r?r.slice(i):new t(n.hdlr.encodingLength(e));var o=21+(e.name||"").length;return r.fill(0,0,o),r.write(e.handlerType||"",4,4,"ascii"),u(e.name||"",r,20),n.hdlr.encode.bytes=o,r},n.hdlr.decode=function(e,t,n){return e=e.slice(t),{handlerType:e.toString("ascii",4,8),name:l(e,20,n)}},n.hdlr.encodingLength=function(e){return 21+(e.name||"").length},n.mehd={},n.mehd.encode=function(e,r,i){return r=r?r.slice(i):new t(4),r.writeUInt32BE(e.fragmentDuration||0,0),n.mehd.encode.bytes=4,r},n.mehd.decode=function(e,t){return e=e.slice(t),{fragmentDuration:e.readUInt32BE(0)}},n.mehd.encodingLength=function(e){return 4},n.trex={},n.trex.encode=function(e,r,i){return r=r?r.slice(i):new t(20),r.writeUInt32BE(e.trackId||0,0),r.writeUInt32BE(e.defaultSampleDescriptionIndex||0,4),r.writeUInt32BE(e.defaultSampleDuration||0,8),r.writeUInt32BE(e.defaultSampleSize||0,12),r.writeUInt32BE(e.defaultSampleFlags||0,16),n.trex.encode.bytes=20,r},n.trex.decode=function(e,t){return e=e.slice(t),{trackId:e.readUInt32BE(0),defaultSampleDescriptionIndex:e.readUInt32BE(4),defaultSampleDuration:e.readUInt32BE(8),defaultSampleSize:e.readUInt32BE(12),defaultSampleFlags:e.readUInt32BE(16)}},n.trex.encodingLength=function(e){return 20},n.mfhd={},n.mfhd.encode=function(e,r,i){return r=r?r.slice(i):new t(4),r.writeUInt32BE(e.sequenceNumber||0,0),n.mfhd.encode.bytes=4,r},n.mfhd.decode=function(e,t){return{sequenceNumber:e.readUint32BE(0)}},n.mfhd.encodingLength=function(e){return 4},n.tfhd={},n.tfhd.encode=function(e,r,i){return r=r?r.slice(i):new t(4),r.writeUInt32BE(e.trackId,0),n.tfhd.encode.bytes=4,r},n.tfhd.decode=function(e,t){},n.tfhd.encodingLength=function(e){return 4},n.tfdt={},n.tfdt.encode=function(e,r,i){return r=r?r.slice(i):new t(4),r.writeUInt32BE(e.baseMediaDecodeTime||0,0),n.tfdt.encode.bytes=4,r},n.tfdt.decode=function(e,t){},n.tfdt.encodingLength=function(e){return 4},n.trun={},n.trun.encode=function(e,r,i){r=r?r.slice(i):new t(8+16*e.entries.length),r.writeUInt32BE(e.entries.length,0),r.writeInt32BE(e.dataOffset,4);for(var o=8,s=0;s<e.entries.length;s++){var a=e.entries[s];r.writeUInt32BE(a.sampleDuration,o),o+=4,r.writeUInt32BE(a.sampleSize,o),o+=4,r.writeUInt32BE(a.sampleFlags,o),o+=4,r.writeUInt32BE(a.sampleCompositionTimeOffset,o),o+=4}n.trun.encode.bytes=o},n.trun.decode=function(e,t){},n.trun.encodingLength=function(e){return 8+16*e.entries.length},n.mdat={},n.mdat.encode=function(e,t,r){e.buffer?(e.buffer.copy(t,r),n.mdat.encode.bytes=e.buffer.length):n.mdat.encode.bytes=n.mdat.encodingLength(e)},n.mdat.decode=function(e,n,r){return{buffer:new t(e.slice(n,r))}},n.mdat.encodingLength=function(e){return e.buffer?e.buffer.length:e.contentLength}}).call(this,e("buffer").Buffer)},{"./descriptor":120,"./index":121,buffer:26}],120:[function(e,t,n){(function(e){var t={3:"ESDescriptor",4:"DecoderConfigDescriptor",5:"DecoderSpecificInfo",6:"SLConfigDescriptor"};n.Descriptor={},n.Descriptor.decode=function(r,i,o){var s,a=r.readUInt8(i),u=i+1,c=0;do s=r.readUInt8(u++),c=c<<7|127&s;while(128&s);var f,d=t[a];return f=n[d]?n[d].decode(r,u,o):{buffer:new e(r.slice(u,u+c))},f.tag=a,f.tagName=d,f.length=u-i+c,f.contentsLen=c,f},n.DescriptorArray={},n.DescriptorArray.decode=function(e,r,i){for(var o=r,s={};i>=o+2;){var a=n.Descriptor.decode(e,o,i);o+=a.length;var u=t[a.tag]||"Descriptor"+a.tag;s[u]=a}return s},n.ESDescriptor={},n.ESDescriptor.decode=function(e,t,r){var i=e.readUInt8(t+2),o=t+3;if(128&i&&(o+=2),64&i){var s=e.readUInt8(o);o+=s+1}return 32&i&&(o+=2),n.DescriptorArray.decode(e,o,r)},n.DecoderConfigDescriptor={},n.DecoderConfigDescriptor.decode=function(e,t,r){var i=e.readUInt8(t),o=n.DescriptorArray.decode(e,t+13,r);return o.oti=i,o}}).call(this,e("buffer").Buffer)},{buffer:26}],121:[function(e,t,n){(function(t){var r=e("uint64be"),i=e("./boxes"),o=4294967295,s=n,a=n.containers={moov:["mvhd","meta","traks","mvex"],trak:["tkhd","tref","trgr","edts","meta","mdia","udta"],edts:["elst"],mdia:["mdhd","hdlr","elng","minf"],minf:["vmhd","smhd","hmhd","sthd","nmhd","dinf","stbl"],dinf:["dref"],stbl:["stsd","stts","ctts","cslg","stsc","stsz","stz2","stco","co64","stss","stsh","padb","stdp","sdtp","sbgps","sgpds","subss","saizs","saios"],mvex:["mehd","trexs","leva"],moof:["mfhd","meta","trafs"],traf:["tfhd","trun","sbgps","sgpds","subss","saizs","saios","tfdt","meta"]};s.encode=function(e,n,r){return s.encodingLength(e),r=r||0,n=n||new t(e.length),s._encode(e,n,r)},s._encode=function(e,t,n){var u=e.type,c=e.length;c>o&&(c=1),t.writeUInt32BE(c,n),t.write(e.type,n+4,4,"ascii");var f=n+8;if(1===c&&(r.encode(e.length,t,f),f+=8),i.fullBoxes[u]&&(t.writeUInt32BE(e.flags||0,f),t.writeUInt8(e.version||0,f),f+=4),a[u]){var d=a[u];d.forEach(function(n){if(5===n.length){var r=e[n]||[];n=n.substr(0,4),r.forEach(function(e){s._encode(e,t,f),f+=s.encode.bytes})}else e[n]&&(s._encode(e[n],t,f),f+=s.encode.bytes)}),e.otherBoxes&&e.otherBoxes.forEach(function(e){s._encode(e,t,f),f+=s.encode.bytes})}else if(i[u]){var h=i[u].encode;h(e,t,f),f+=h.bytes}else{if(!e.buffer)throw new Error("Either `type` must be set to a known type (not'"+u+"') or `buffer` must be set");var l=e.buffer;l.copy(t,f),f+=e.buffer.length}return s.encode.bytes=f-n,t},s.readHeaders=function(e,t,n){if(t=t||0,n=n||e.length,8>n-t)return 8;var o=e.readUInt32BE(t),s=e.toString("ascii",t+4,t+8),a=t+8;if(1===o){if(16>n-t)return 16;o=r.decode(e,a),a+=8}var u,c;return i.fullBoxes[s]&&(u=e.readUInt8(a),c=16777215&e.readUInt32BE(a),a+=4),{length:o,headersLen:a-t,contentLen:o-(a-t),type:s,version:u,flags:c}},s.decode=function(e,t,n){t=t||0,n=n||e.length;var r=s.readHeaders(e,t,n);if(!r||r.length>n-t)throw new Error("Data too short");return s.decodeWithoutHeaders(r,e,t+r.headersLen,t+r.length)},s.decodeWithoutHeaders=function(e,n,r,o){r=r||0,o=o||n.length;var u=e.type,c={};if(a[u]){c.otherBoxes=[];for(var f=a[u],d=r;o-d>=8;){var h=s.decode(n,d,o);if(d+=h.length,f.indexOf(h.type)>=0)c[h.type]=h;else if(f.indexOf(h.type+"s")>=0){var l=h.type+"s",p=c[l]=c[l]||[];p.push(h)}else c.otherBoxes.push(h)}}else if(i[u]){var m=i[u].decode;c=m(n,r,o)}else c.buffer=new t(n.slice(r,o));return c.length=e.length,c.contentLen=e.contentLen,c.type=e.type,c.version=e.version,c.flags=e.flags,c},s.encodingLength=function(e){var t=e.type,n=8;if(i.fullBoxes[t]&&(n+=4),a[t]){var r=a[t];r.forEach(function(t){if(5===t.length){var r=e[t]||[];t=t.substr(0,4),r.forEach(function(e){e.type=t,n+=s.encodingLength(e)})}else if(e[t]){var i=e[t];i.type=t,n+=s.encodingLength(i)}}),e.otherBoxes&&e.otherBoxes.forEach(function(e){n+=s.encodingLength(e)})}else if(i[t])n+=i[t].encodingLength(e);else{if(!e.buffer)throw new Error("Either `type` must be set to a known type (not'"+t+"') or `buffer` must be set");n+=e.buffer.length}return n>o&&(n+=8),e.length=n,n}}).call(this,e("buffer").Buffer)},{"./boxes":119,buffer:26,uint64be:122}],122:[function(e,t,n){(function(e){var t=4294967295;n.encodingLength=function(){return 8},n.encode=function(n,r,i){r||(r=new e(8)),i||(i=0);var o=Math.floor(n/t),s=n-o*t;return r.writeUInt32BE(o,i),r.writeUInt32BE(s,i+4),r},n.decode=function(n,r){r||(r=0),n||(n=new e(4)),r||(r=0);var i=n.readUInt32BE(r),o=n.readUInt32BE(r+4);return i*t+o},n.encode.bytes=8,n.decode.bytes=8}).call(this,e("buffer").Buffer)},{buffer:26}],123:[function(e,t,n){(function(n){function r(){return this instanceof r?(o.Writable.call(this),this.destroyed=!1,this._pending=0,this._missing=0,this._buf=null,this._str=null,this._cb=null,this._ondrain=null,this._writeBuffer=null,this._writeCb=null,this._ondrain=null,void this._kick()):new r}function i(e){this._parent=e,this.destroyed=!1,o.PassThrough.call(this)}var o=e("readable-stream"),s=e("util"),a=e("next-event"),u=e("mp4-box-encoding"),c=new n(0);t.exports=r,s.inherits(r,o.Writable),r.prototype.destroy=function(e){this.destroyed||(this.destroyed=!0,e&&this.emit("error",e),this.emit("close"))},r.prototype._write=function(e,t,n){if(!this.destroyed){for(var r=!this._str||!this._str._writableState.needDrain;e.length&&!this.destroyed;){if(!this._missing)return this._writeBuffer=e,void(this._writeCb=n);var i=e.length<this._missing?e.length:this._missing;if(this._buf?e.copy(this._buf,this._buf.length-this._missing):this._str&&(r=this._str.write(i===e.length?e:e.slice(0,i))),this._missing-=i,!this._missing){var o=this._buf,s=this._cb,a=this._str;this._buf=this._cb=this._str=this._ondrain=null,r=!0,a&&a.end(),s&&s(o)}e=i===e.length?c:e.slice(i)}return this._pending&&!this._missing?(this._writeBuffer=e,void(this._writeCb=n)):void(r?n():this._ondrain(n))}},r.prototype._buffer=function(e,t){this._missing=e,this._buf=new n(e),this._cb=t},r.prototype._stream=function(e,t){var n=this;return this._missing=e,this._str=new i(this),this._ondrain=a(this._str,"drain"),this._pending++,this._str.on("end",function(){n._pending--,n._kick()}),this._cb=t,this._str},r.prototype._readBox=function(){function e(r,i){t._buffer(r,function(r){i=i?n.concat(i,r):r;var o=u.readHeaders(i);"number"==typeof o?e(o-i.length,i):(t._pending++,t._headers=o,t.emit("box",o))})}var t=this;e(8)},r.prototype.stream=function(){var e=this;if(!e._headers)throw new Error("this function can only be called once after 'box' is emitted");var t=e._headers;return e._headers=null,e._stream(t.contentLen,null)},r.prototype.decode=function(e){var t=this;if(!t._headers)throw new Error("this function can only be called once after 'box' is emitted");var n=t._headers;t._headers=null,t._buffer(n.contentLen,function(r){var i=u.decodeWithoutHeaders(n,r);e(i),t._pending--,t._kick()})},r.prototype.ignore=function(){var e=this;if(!e._headers)throw new Error("this function can only be called once after 'box' is emitted");var t=e._headers;e._headers=null,this._missing=t.contentLen,this._cb=function(){e._pending--,e._kick()}},r.prototype._kick=function(){if(!this._pending&&(this._buf||this._str||this._readBox(),this._writeBuffer)){var e=this._writeCb,t=this._writeBuffer;this._writeBuffer=null,this._writeCb=null,this._write(t,null,e)}},s.inherits(i,o.PassThrough),i.prototype.destroy=function(e){this.destroyed||(this.destroyed=!0,this._parent.destroy(e),e&&this.emit("error",e),this.emit("close"))}}).call(this,e("buffer").Buffer)},{buffer:26,"mp4-box-encoding":121,"next-event":126,"readable-stream":109,util:49}],124:[function(e,t,n){(function(n,r){function i(){}function o(){function e(){n._want&&(n._want=!1,n._read())}function t(){n._stream=null}if(!(this instanceof o))return new o;a.Readable.call(this),this.destroyed=!1,this._reading=!1,this._stream=null,this._drain=null,this._want=!1,this._onreadable=e,this._onend=t;var n=this}function s(e){this._parent=e,this.destroyed=!1,a.PassThrough.call(this)}var a=e("readable-stream"),u=e("util"),c=e("mp4-box-encoding");t.exports=o,u.inherits(o,a.Readable),o.prototype.mediaData=o.prototype.mdat=function(e,t){var n=new s(this);return this.box({type:"mdat",contentLength:e,encodeBufferLen:8,stream:n},t),n},o.prototype.box=function(e,t){if(t||(t=i),this.destroyed)return t(new Error("Encoder is destroyed"));var o;if(e.encodeBufferLen&&(o=new r(e.encodeBufferLen)),e.stream)e.buffer=null,o=c.encode(e,o),this.push(o),this._stream=e.stream,this._stream.on("readable",this._onreadable),this._stream.on("end",this._onend),this._stream.on("end",t),this._forward();else{o=c.encode(e,o);var s=this.push(o);if(s)return n.nextTick(t);this._drain=t}},o.prototype.destroy=function(e){if(!this.destroyed){if(this.destroyed=!0,this._stream&&this._stream.destroy&&this._stream.destroy(),this._stream=null,this._drain){var t=this._drain;this._drain=null,t(e)}e&&this.emit("error",e),this.emit("close")}},o.prototype.finalize=function(){this.push(null)},o.prototype._forward=function(){if(this._stream)for(;!this.destroyed;){var e=this._stream.read();if(!e)return void(this._want=!!this._stream);if(!this.push(e))return}},o.prototype._read=function(){if(!this._reading&&!this.destroyed){if(this._reading=!0,this._stream&&this._forward(),this._drain){var e=this._drain;this._drain=null,e()}this._reading=!1}},u.inherits(s,a.PassThrough),s.prototype.destroy=function(e){this.destroyed||(this.destroyed=!0,this._parent.destroy(e),e&&this.emit("error",e),this.emit("close"))}}).call(this,e("_process"),e("buffer").Buffer)},{_process:34,buffer:26,"mp4-box-encoding":121,"readable-stream":109,util:49}],125:[function(e,t,n){n.decode=e("./decode"),n.encode=e("./encode")},{"./decode":123,"./encode":124}],126:[function(e,t,n){function r(e,t){var n=null;return e.on(t,function(e){if(n){var t=n;n=null,t(e)}}),function(e){n=e}}t.exports=r},{}],127:[function(e,t,n){function r(e){var t=this;return t instanceof r?(o.Writable.call(t),t.destroyed=!1,t._queue=[],t._position=e||0,t._cb=null,t._buffer=null,void(t._out=null)):new r(e)}var i=e("inherits"),o=e("stream");t.exports=r,i(r,o.Writable),r.prototype._write=function(e,t,n){for(var r=this,i=!0;;){if(r.destroyed)return;if(0===r._queue.length)return r._buffer=e,void(r._cb=n);r._buffer=null;var o=r._queue[0],s=Math.max(o.start-r._position,0),a=o.end-r._position;if(s>=e.length)return r._position+=e.length,n(null);var u;if(a>e.length){r._position+=e.length,u=0===s?e:e.slice(s),i=o.stream.write(u)&&i;break}r._position+=a,u=0===s&&a===e.length?e:e.slice(s,a),i=o.stream.write(u)&&i,o.last&&o.stream.end(),e=e.slice(a),r._queue.shift()}i?n(null):o.stream.once("drain",n.bind(null,null))},r.prototype.slice=function(e){var t=this;if(t.destroyed)return null;e instanceof Array||(e=[e]);var n=new o.PassThrough;return e.forEach(function(r,i){t._queue.push({start:r.start,end:r.end,stream:n,last:i===e.length-1})}),t._buffer&&t._write(t._buffer,null,t._cb),n},r.prototype.destroy=function(e){var t=this;t.destroyed||(t.destroyed=!0,e&&t.emit("error",e))}},{inherits:79,stream:39}],128:[function(e,t,n){function r(e,t,n){var o=this;return this instanceof r?(n=n||{},o._elem=t,o._elemWrapper=new i(t),o._muxer=new s(e),o._tracks=null,o._onError=function(e){o.destroy()},o._onWaiting=function(){if(o._tracks){var e=o._muxer.seek(o._elem.currentTime);o._tracks.forEach(function(t,n){t.muxed.destroy(),t.muxed=e[n],t.mediaSource=o._elemWrapper.createWriteStream(t.mediaSource)}),o._pump()}},o._elem.addEventListener("waiting",o._onWaiting),o._elem.addEventListener("error",o._onError),o._muxer.on("ready",function(e){var t=o._muxer.seek(0,!0);o._tracks=e.map(function(e,n){return{muxed:t[n],mediaSource:o._elemWrapper.createWriteStream(e.mime)}}),o._pump()}),void o._muxer.on("error",function(e){o._elemWrapper.error(e)})):new r(e,t,n)}var i=e("mediasource"),o=e("pump"),s=e("./mp4-remuxer");t.exports=r,r.prototype._pump=function(){var e=this;e._tracks.forEach(function(t){t.mediaSource.on("error",function(t){e._elemWrapper.error(t)}),o(t.muxed,t.mediaSource)})},r.prototype.destroy=function(){var e=this;e.destroyed||(e.destroyed=!0,e._elem.removeEventListener("waiting",e._onWaiting),e._elem.removeEventListener("error",e._onError),e._tracks&&e._tracks.forEach(function(e){e.muxed.destroy()}),e._elem.src="")}},{"./mp4-remuxer":117,mediasource:115,pump:92}],129:[function(e,t,n){(function(e){t.exports=function(t,n,r){function i(t){function n(){r&&r(t,s),r=null}d?e.nextTick(n):n()}function o(e,n,r){if(s[e]=r,n&&(f=!0),0===--u||n)i(n);else if(!f&&a>h){var d;c?(d=c[h],h+=1,t[d](o.bind(void 0,d))):(d=h,h+=1,t[d](o.bind(void 0,d)))}}if("number"!=typeof n)throw new Error("second argument must be a Number");var s,a,u,c,f,d=!0;Array.isArray(t)?(s=[],u=a=t.length):(c=Object.keys(t),s={},u=a=c.length);var h=n;u?c?c.some(function(e,r){return t[e](o.bind(void 0,e)),r===n-1?!0:void 0}):t.some(function(e,t){return e(o.bind(void 0,t)),t===n-1?!0:void 0}):i(null),d=!1}}).call(this,e("_process"))},{_process:34}],130:[function(e,t,n){(function(e){t.exports=function(t,n){function r(t){function r(){n&&n(t,o),n=null}u?e.nextTick(r):r()}function i(e,t,n){o[e]=n,(0===--s||t)&&r(t)}var o,s,a,u=!0;Array.isArray(t)?(o=[],s=t.length):(a=Object.keys(t),o={},s=a.length),s?a?a.forEach(function(e){t[e](i.bind(void 0,e))}):t.forEach(function(e,t){e(i.bind(void 0,t))}):r(null),u=!1}}).call(this,e("_process"))},{_process:34}],131:[function(e,t,n){(function(n){function r(e,t){e="string"==typeof e?{url:e}:o(e),t=u(t),e.url&&i(e),null==e.headers&&(e.headers={}),null==e.maxRedirects&&(e.maxRedirects=10);var n=e.body;e.body=void 0,n&&!e.method&&(e.method="POST");var f=Object.keys(e.headers).some(function(e){return"accept-encoding"===e.toLowerCase()});f||(e.headers["accept-encoding"]="gzip, deflate");var d="https:"===e.protocol?a:s,h=d.request(e,function(n){return n.statusCode>=300&&n.statusCode<400&&"location"in n.headers?(e.url=n.headers.location,i(e),n.resume(),e.maxRedirects-=1,void(e.maxRedirects>0?r(e,t):t(new Error("too many redirects")))):void t(null,"function"==typeof c?c(n):n)});return h.on("error",t),h.end(n),h}function i(e){var t=f.parse(e.url);t.hostname&&(e.hostname=t.hostname),t.port&&(e.port=t.port),t.protocol&&(e.protocol=t.protocol),e.path=t.path,delete e.url}t.exports=r;var o=e("xtend"),s=e("http"),a=e("https"),u=e("once"),c=e("unzip-response"),f=e("url");t.exports.concat=function(e,t){return r(e,function(e,r){if(e)return t(e);var i=[];r.on("data",function(e){i.push(e)}),r.on("end",function(){t(null,r,n.concat(i))})})},["get","post","put","patch","head","delete"].forEach(function(e){t.exports[e]=function(t,n){return"string"==typeof t&&(t={url:t}),t.method=e.toUpperCase(),r(t,n)}})}).call(this,e("buffer").Buffer)},{buffer:26,http:40,https:31,once:133,"unzip-response":25,url:46,xtend:156}],132:[function(e,t,n){arguments[4][20][0].apply(n,arguments)},{dup:20}],133:[function(e,t,n){arguments[4][21][0].apply(n,arguments)},{dup:21,wrappy:132}],134:[function(e,t,n){(function(n){function r(e){var t=this;if(!(t instanceof r))return new r(e);if(t._debug("new peer %o",e),e||(e={}),e.allowHalfOpen=!1,null==e.highWaterMark&&(e.highWaterMark=1048576),d.Duplex.call(t,e),t.initiator=e.initiator||!1,t.channelConfig=e.channelConfig||r.channelConfig,t.channelName=e.initiator?e.channelName||a(160):null,t.config=e.config||r.config,t.constraints=e.constraints||r.constraints,t.offerConstraints=e.offerConstraints,t.answerConstraints=e.answerConstraints,t.reconnectTimer=e.reconnectTimer||!1,t.sdpTransform=e.sdpTransform||function(e){return e},t.stream=e.stream||!1,t.trickle=void 0!==e.trickle?e.trickle:!0,t.destroyed=!1,t.connected=!1,t.remoteAddress=void 0,t.remoteFamily=void 0,t.remotePort=void 0,t.localAddress=void 0,t.localPort=void 0,t._isWrtc=!!e.wrtc,t._wrtc=e.wrtc||s(),!t._wrtc)throw"undefined"==typeof window?new Error("No WebRTC support: Specify `opts.wrtc` option in this environment"):new Error("No WebRTC support: Not a supported browser");t._maxBufferedAmount=e.highWaterMark,t._pcReady=!1,t._channelReady=!1,t._iceComplete=!1,t._channel=null,t._pendingCandidates=[],t._chunk=null,t._cb=null,t._interval=null,t._reconnectTimeout=null,t._pc=new t._wrtc.RTCPeerConnection(t.config,t.constraints),t._pc.oniceconnectionstatechange=t._onIceConnectionStateChange.bind(t),t._pc.onsignalingstatechange=t._onSignalingStateChange.bind(t),t._pc.onicecandidate=t._onIceCandidate.bind(t),t.stream&&t._pc.addStream(t.stream),t._pc.onaddstream=t._onAddStream.bind(t),t.initiator?(t._setupData({channel:t._pc.createDataChannel(t.channelName,t.channelConfig)}),t._pc.onnegotiationneeded=f(t._createOffer.bind(t)),"undefined"!=typeof window&&window.webkitRTCPeerConnection||t._pc.onnegotiationneeded()):t._pc.ondatachannel=t._setupData.bind(t),t.on("finish",function(){t.connected?setTimeout(function(){t._destroy()},100):t.once("connect",function(){setTimeout(function(){t._destroy()},100)})})}function i(){}t.exports=r;var o=e("debug")("simple-peer"),s=e("get-browser-rtc"),a=e("hat"),u=e("inherits"),c=e("is-typedarray"),f=e("once"),d=e("stream");u(r,d.Duplex),r.WEBRTC_SUPPORT=!!s(),r.config={iceServers:[{url:"stun:23.21.150.121",urls:"stun:23.21.150.121"}]},r.constraints={},r.channelConfig={},Object.defineProperty(r.prototype,"bufferSize",{get:function(){var e=this;return e._channel&&e._channel.bufferedAmount||0}}),r.prototype.address=function(){var e=this;return{port:e.localPort,family:"IPv4",address:e.localAddress}},r.prototype.signal=function(e){function t(e){try{n._pc.addIceCandidate(new n._wrtc.RTCIceCandidate(e),i,n._onError.bind(n))}catch(t){n._destroy(new Error("error adding candidate: "+t.message))}}var n=this;if(n.destroyed)throw new Error("cannot signal after peer is destroyed");if("string"==typeof e)try{e=JSON.parse(e)}catch(r){e={}}n._debug("signal()"),e.sdp&&n._pc.setRemoteDescription(new n._wrtc.RTCSessionDescription(e),function(){n.destroyed||("offer"===n._pc.remoteDescription.type&&n._createAnswer(),n._pendingCandidates.forEach(t),n._pendingCandidates=[])},n._onError.bind(n)),e.candidate&&(n._pc.remoteDescription?t(e.candidate):n._pendingCandidates.push(e.candidate)),e.sdp||e.candidate||n._destroy(new Error("signal() called with invalid signal data"))},r.prototype.send=function(e){var t=this;c.strict(e)||e instanceof ArrayBuffer||n.isBuffer(e)||"string"==typeof e||"undefined"!=typeof Blob&&e instanceof Blob||(e=JSON.stringify(e)),n.isBuffer(e)&&t._isWrtc&&(e=new Uint8Array(e));var r=e.length||e.byteLength||e.size;t._channel.send(e),t._debug("write: %d bytes",r)},r.prototype.destroy=function(e){var t=this;t._destroy(null,e)},r.prototype._destroy=function(e,t){var n=this;if(!n.destroyed){if(t&&n.once("close",t),n._debug("destroy (error: %s)",e&&e.message),n.readable=n.writable=!1,n._readableState.ended||n.push(null),n._writableState.finished||n.end(),n.destroyed=!0,n.connected=!1,n._pcReady=!1,n._channelReady=!1,n._chunk=null,n._cb=null,clearInterval(n._interval),clearTimeout(n._reconnectTimeout),n._pc){try{n._pc.close()}catch(e){}n._pc.oniceconnectionstatechange=null,n._pc.onsignalingstatechange=null,n._pc.onicecandidate=null}if(n._channel){try{n._channel.close()}catch(e){}n._channel.onmessage=null,n._channel.onopen=null,n._channel.onclose=null}n._pc=null,n._channel=null,e&&n.emit("error",e),n.emit("close")}},r.prototype._setupData=function(e){var t=this;t._channel=e.channel,t.channelName=t._channel.label,t._channel.binaryType="arraybuffer",t._channel.onmessage=t._onChannelMessage.bind(t),t._channel.onopen=t._onChannelOpen.bind(t),t._channel.onclose=t._onChannelClose.bind(t)},r.prototype._read=function(){},r.prototype._write=function(e,t,n){var r=this;if(r.destroyed)return n(new Error("cannot write after peer is destroyed"));if(r.connected){try{r.send(e)}catch(i){return r._onError(i)}r._channel.bufferedAmount>r._maxBufferedAmount?(r._debug("start backpressure: bufferedAmount %d",r._channel.bufferedAmount),r._cb=n):n(null)}else r._debug("write before connect"),r._chunk=e,r._cb=n},r.prototype._createOffer=function(){var e=this;e.destroyed||e._pc.createOffer(function(t){if(!e.destroyed){t.sdp=e.sdpTransform(t.sdp),e._pc.setLocalDescription(t,i,e._onError.bind(e));var n=function(){var n=e._pc.localDescription||t;e._debug("signal"),e.emit("signal",{type:n.type,sdp:n.sdp})};e.trickle||e._iceComplete?n():e.once("_iceComplete",n)}},e._onError.bind(e),e.offerConstraints)},r.prototype._createAnswer=function(){var e=this;e.destroyed||e._pc.createAnswer(function(t){if(!e.destroyed){t.sdp=e.sdpTransform(t.sdp),e._pc.setLocalDescription(t,i,e._onError.bind(e));var n=function(){var n=e._pc.localDescription||t;e._debug("signal"),e.emit("signal",{type:n.type,sdp:n.sdp})};e.trickle||e._iceComplete?n():e.once("_iceComplete",n)}},e._onError.bind(e),e.answerConstraints)},r.prototype._onIceConnectionStateChange=function(){ +var e=this;if(!e.destroyed){var t=e._pc.iceGatheringState,n=e._pc.iceConnectionState;e._debug("iceConnectionStateChange %s %s",t,n),e.emit("iceConnectionStateChange",t,n),("connected"===n||"completed"===n)&&(clearTimeout(e._reconnectTimeout),e._pcReady=!0,e._maybeReady()),"disconnected"===n&&(e.reconnectTimer?(clearTimeout(e._reconnectTimeout),e._reconnectTimeout=setTimeout(function(){e._destroy()},e.reconnectTimer)):e._destroy()),"failed"===n&&e._destroy(),"closed"===n&&e._destroy()}},r.prototype.getStats=function(e){var t=this;t._pc.getStats?"undefined"!=typeof window&&window.mozRTCPeerConnection?t._pc.getStats(null,function(t){var n=[];t.forEach(function(e){n.push(e)}),e(n)},t._onError.bind(t)):t._pc.getStats(function(t){var n=[];t.result().forEach(function(e){var t={};e.names().forEach(function(n){t[n]=e.stat(n)}),t.id=e.id,t.type=e.type,t.timestamp=e.timestamp,n.push(t)}),e(n)}):e([])},r.prototype._maybeReady=function(){var e=this;e._debug("maybeReady pc %s channel %s",e._pcReady,e._channelReady),!e.connected&&!e._connecting&&e._pcReady&&e._channelReady&&(e._connecting=!0,e.getStats(function(t){function n(t){var n=i[t.localCandidateId],o=r[t.remoteCandidateId];e.remoteAddress=o.ipAddress,e.remotePort=Number(o.portNumber),e.remoteFamily="IPv4",e._debug("connect remote: %s:%s",e.remoteAddress,e.remotePort),e.localAddress=n.ipAddress,e.localPort=Number(n.portNumber),e._debug("connect local: %s:%s",e.localAddress,e.localPort)}e._connecting=!1,e.connected=!0;var r={},i={};if(t.forEach(function(e){"remotecandidate"===e.type&&(r[e.id]=e),"localcandidate"===e.type&&(i[e.id]=e)}),t.forEach(function(e){var t="googCandidatePair"===e.type&&"true"===e.googActiveConnection||"candidatepair"===e.type&&e.selected;t&&n(e)}),e._chunk){try{e.send(e._chunk)}catch(o){return e._onError(o)}e._chunk=null,e._debug('sent chunk from "write before connect"');var s=e._cb;e._cb=null,s(null)}e._interval=setInterval(function(){if(e._cb&&e._channel&&!(e._channel.bufferedAmount>e._maxBufferedAmount)){e._debug("ending backpressure: bufferedAmount %d",e._channel.bufferedAmount);var t=e._cb;e._cb=null,t(null)}},150),e._interval.unref&&e._interval.unref(),e._debug("connect"),e.emit("connect")}))},r.prototype._onSignalingStateChange=function(){var e=this;e.destroyed||(e._debug("signalingStateChange %s",e._pc.signalingState),e.emit("signalingStateChange",e._pc.signalingState))},r.prototype._onIceCandidate=function(e){var t=this;t.destroyed||(e.candidate&&t.trickle?t.emit("signal",{candidate:{candidate:e.candidate.candidate,sdpMLineIndex:e.candidate.sdpMLineIndex,sdpMid:e.candidate.sdpMid}}):e.candidate||(t._iceComplete=!0,t.emit("_iceComplete")))},r.prototype._onChannelMessage=function(e){var t=this;if(!t.destroyed){var r=e.data;if(t._debug("read: %d bytes",r.byteLength||r.length),r instanceof ArrayBuffer)r=new n(r),t.push(r);else{try{r=JSON.parse(r)}catch(i){}t.emit("data",r)}}},r.prototype._onChannelOpen=function(){var e=this;e.connected||e.destroyed||(e._debug("on channel open"),e._channelReady=!0,e._maybeReady())},r.prototype._onChannelClose=function(){var e=this;e.destroyed||(e._debug("on channel close"),e._destroy())},r.prototype._onAddStream=function(e){var t=this;t.destroyed||(t._debug("on add stream"),t.emit("stream",e.stream))},r.prototype._onError=function(e){var t=this;t.destroyed||(t._debug("error %s",e.message||e),t._destroy(e))},r.prototype._debug=function(){var e=this,t=[].slice.call(arguments),n=e.channelName&&e.channelName.substring(0,7);t[0]="["+n+"] "+t[0],o.apply(null,t)}}).call(this,e("buffer").Buffer)},{buffer:26,debug:71,"get-browser-rtc":135,hat:77,inherits:79,"is-typedarray":136,once:138,stream:39}],135:[function(e,t,n){t.exports=function(){if("undefined"==typeof window)return null;var e={RTCPeerConnection:window.RTCPeerConnection||window.mozRTCPeerConnection||window.webkitRTCPeerConnection,RTCSessionDescription:window.RTCSessionDescription||window.mozRTCSessionDescription||window.webkitRTCSessionDescription,RTCIceCandidate:window.RTCIceCandidate||window.mozRTCIceCandidate||window.webkitRTCIceCandidate};return e.RTCPeerConnection?e:null}},{}],136:[function(e,t,n){arguments[4][23][0].apply(n,arguments)},{dup:23}],137:[function(e,t,n){arguments[4][20][0].apply(n,arguments)},{dup:20}],138:[function(e,t,n){arguments[4][21][0].apply(n,arguments)},{dup:21,wrappy:137}],139:[function(e,t,n){function r(e,t){return c?("string"==typeof e&&(e=i(e)),void c.digest({name:"sha-1"},e).then(function(e){t(o(new Uint8Array(e)))},function(n){t(f(e))})):void setTimeout(t,0,f(e))}function i(e){for(var t=e.length,n=new Uint8Array(t),r=0;t>r;r++)n[r]=e.charCodeAt(r);return n}function o(e){for(var t=e.length,n=[],r=0;t>r;r++){var i=e[r];n.push((i>>>4).toString(16)),n.push((15&i).toString(16))}return n.join("")}var s=e("rusha"),a=new s,u=window.crypto||window.msCrypto||{},c=u.subtle||u.webkitSubtle,f=a.digest.bind(a);try{c.digest({name:"sha-1"},new Uint8Array)["catch"](function(){c=!1})}catch(d){c=!1}t.exports=r,t.exports.sync=f},{rusha:140}],140:[function(e,t,n){(function(e){!function(){function n(e){"use strict";var t={fill:0},o=function(e){for(e+=9;e%64>0;e+=1);return e},s=function(e,t){for(var n=t>>2;n<e.length;n++)e[n]=0},a=function(e,t,n){e[t>>2]|=128<<24-(t%4<<3),e[((t>>2)+2&-16)+14]=n>>29,e[((t>>2)+2&-16)+15]=n<<3},u=function(e,t,n,r,i){var o,s=this,a=i%4,u=r%4,c=r-u;if(c>0)switch(a){case 0:e[i+3|0]=s.charCodeAt(n);case 1:e[i+2|0]=s.charCodeAt(n+1);case 2:e[i+1|0]=s.charCodeAt(n+2);case 3:e[0|i]=s.charCodeAt(n+3)}for(o=a;c>o;o=o+4|0)t[i+o>>2]=s.charCodeAt(n+o)<<24|s.charCodeAt(n+o+1)<<16|s.charCodeAt(n+o+2)<<8|s.charCodeAt(n+o+3);switch(u){case 3:e[i+c+1|0]=s.charCodeAt(n+c+2);case 2:e[i+c+2|0]=s.charCodeAt(n+c+1);case 1:e[i+c+3|0]=s.charCodeAt(n+c)}},c=function(e,t,n,r,i){var o,s=this,a=i%4,u=r%4,c=r-u;if(c>0)switch(a){case 0:e[i+3|0]=s[n];case 1:e[i+2|0]=s[n+1];case 2:e[i+1|0]=s[n+2];case 3:e[0|i]=s[n+3]}for(o=4-a;c>o;o=o+=4)t[i+o>>2]=s[n+o]<<24|s[n+o+1]<<16|s[n+o+2]<<8|s[n+o+3];switch(u){case 3:e[i+c+1|0]=s[n+c+2];case 2:e[i+c+2|0]=s[n+c+1];case 1:e[i+c+3|0]=s[n+c]}},f=function(e,t,n,r,o){var s,a=this,u=o%4,c=r%4,f=r-c,d=new Uint8Array(i.readAsArrayBuffer(a.slice(n,n+r)));if(f>0)switch(u){case 0:e[o+3|0]=d[0];case 1:e[o+2|0]=d[1];case 2:e[o+1|0]=d[2];case 3:e[0|o]=d[3]}for(s=4-u;f>s;s=s+=4)t[o+s>>2]=d[s]<<24|d[s+1]<<16|d[s+2]<<8|d[s+3];switch(c){case 3:e[o+f+1|0]=d[f+2];case 2:e[o+f+2|0]=d[f+1];case 1:e[o+f+3|0]=d[f]}},d=function(e){switch(r.getDataType(e)){case"string":return u.bind(e);case"array":return c.bind(e);case"buffer":return c.bind(e);case"arraybuffer":return c.bind(new Uint8Array(e));case"view":return c.bind(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));case"blob":return f.bind(e)}},h=function(e){var t,n,r="0123456789abcdef",i=[],o=new Uint8Array(e);for(t=0;t<o.length;t++)n=o[t],i[t]=r.charAt(n>>4&15)+r.charAt(n>>0&15);return i.join("")},l=function(e){var t;if(65536>=e)return 65536;if(16777216>e)for(t=1;e>t;t<<=1);else for(t=16777216;e>t;t+=16777216);return t},p=function(e){if(e%64>0)throw new Error("Chunk size must be a multiple of 128 bit");t.maxChunkLen=e,t.padMaxChunkLen=o(e),t.heap=new ArrayBuffer(l(t.padMaxChunkLen+320+20)),t.h32=new Int32Array(t.heap),t.h8=new Int8Array(t.heap),t.core=new n._core({Int32Array:Int32Array,DataView:DataView},{},t.heap),t.buffer=null};p(e||65536);var m=function(e,t){var n=new Int32Array(e,t+320,5);n[0]=1732584193,n[1]=-271733879,n[2]=-1732584194,n[3]=271733878,n[4]=-1009589776},g=function(e,n){var r=o(e),i=new Int32Array(t.heap,0,r>>2);return s(i,e),a(i,e,n),r},y=function(e,n,r){d(e)(t.h8,t.h32,n,r,0)},v=function(e,n,r,i,o){var s=r;o&&(s=g(r,i)),y(e,n,r),t.core.hash(s,t.padMaxChunkLen)},_=function(e,t){var n=new Int32Array(e,t+320,5),r=new Int32Array(5),i=new DataView(r.buffer);return i.setInt32(0,n[0],!1),i.setInt32(4,n[1],!1),i.setInt32(8,n[2],!1),i.setInt32(12,n[3],!1),i.setInt32(16,n[4],!1),r},b=this.rawDigest=function(e){var n=e.byteLength||e.length||e.size||0;m(t.heap,t.padMaxChunkLen);var r=0,i=t.maxChunkLen;for(r=0;n>r+i;r+=i)v(e,r,i,n,!1);return v(e,r,n-r,n,!0),_(t.heap,t.padMaxChunkLen)};this.digest=this.digestFromString=this.digestFromBuffer=this.digestFromArrayBuffer=function(e){return h(b(e).buffer)}}var r={getDataType:function(t){if("string"==typeof t)return"string";if(t instanceof Array)return"array";if("undefined"!=typeof e&&e.Buffer&&e.Buffer.isBuffer(t))return"buffer";if(t instanceof ArrayBuffer)return"arraybuffer";if(t.buffer instanceof ArrayBuffer)return"view";if(t instanceof Blob)return"blob";throw new Error("Unsupported data type.")}};if(n._core=function s(e,t,n){"use asm";var r=new e.Int32Array(n);function i(e,t){e=e|0;t=t|0;var n=0,i=0,o=0,s=0,a=0,u=0,c=0,f=0,d=0,h=0,l=0,p=0,m=0,g=0;o=r[t+320>>2]|0;a=r[t+324>>2]|0;c=r[t+328>>2]|0;d=r[t+332>>2]|0;l=r[t+336>>2]|0;for(n=0;(n|0)<(e|0);n=n+64|0){s=o;u=a;f=c;h=d;p=l;for(i=0;(i|0)<64;i=i+4|0){g=r[n+i>>2]|0;m=((o<<5|o>>>27)+(a&c|~a&d)|0)+((g+l|0)+1518500249|0)|0;l=d;d=c;c=a<<30|a>>>2;a=o;o=m;r[e+i>>2]=g}for(i=e+64|0;(i|0)<(e+80|0);i=i+4|0){g=(r[i-12>>2]^r[i-32>>2]^r[i-56>>2]^r[i-64>>2])<<1|(r[i-12>>2]^r[i-32>>2]^r[i-56>>2]^r[i-64>>2])>>>31;m=((o<<5|o>>>27)+(a&c|~a&d)|0)+((g+l|0)+1518500249|0)|0;l=d;d=c;c=a<<30|a>>>2;a=o;o=m;r[i>>2]=g}for(i=e+80|0;(i|0)<(e+160|0);i=i+4|0){g=(r[i-12>>2]^r[i-32>>2]^r[i-56>>2]^r[i-64>>2])<<1|(r[i-12>>2]^r[i-32>>2]^r[i-56>>2]^r[i-64>>2])>>>31;m=((o<<5|o>>>27)+(a^c^d)|0)+((g+l|0)+1859775393|0)|0;l=d;d=c;c=a<<30|a>>>2;a=o;o=m;r[i>>2]=g}for(i=e+160|0;(i|0)<(e+240|0);i=i+4|0){g=(r[i-12>>2]^r[i-32>>2]^r[i-56>>2]^r[i-64>>2])<<1|(r[i-12>>2]^r[i-32>>2]^r[i-56>>2]^r[i-64>>2])>>>31;m=((o<<5|o>>>27)+(a&c|a&d|c&d)|0)+((g+l|0)-1894007588|0)|0;l=d;d=c;c=a<<30|a>>>2;a=o;o=m;r[i>>2]=g}for(i=e+240|0;(i|0)<(e+320|0);i=i+4|0){g=(r[i-12>>2]^r[i-32>>2]^r[i-56>>2]^r[i-64>>2])<<1|(r[i-12>>2]^r[i-32>>2]^r[i-56>>2]^r[i-64>>2])>>>31;m=((o<<5|o>>>27)+(a^c^d)|0)+((g+l|0)-899497514|0)|0;l=d;d=c;c=a<<30|a>>>2;a=o;o=m;r[i>>2]=g}o=o+s|0;a=a+u|0;c=c+f|0;d=d+h|0;l=l+p|0}r[t+320>>2]=o;r[t+324>>2]=a;r[t+328>>2]=c;r[t+332>>2]=d;r[t+336>>2]=l}return{hash:i}},"undefined"!=typeof t?t.exports=n:"undefined"!=typeof window&&(window.Rusha=n),"undefined"!=typeof FileReaderSync){var i=new FileReaderSync,o=new n(4194304);self.onmessage=function(e){var t,n=e.data.data;try{t=o.digest(n),self.postMessage({id:e.data.id,hash:t})}catch(r){self.postMessage({id:e.data.id,error:r.name})}}}}()}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],141:[function(e,t,n){var r=1,i=65535,o=4,s=function(){r=r+1&i},a=setInterval(s,1e3/o|0);a.unref&&a.unref(),t.exports=function(e){var t=o*(e||5),n=[0],s=1,a=r-1&i;return function(e){var u=r-a&i;for(u>t&&(u=t),a=r;u--;)s===t&&(s=0),n[s]=n[0===s?t-1:s-1],s++;e&&(n[s-1]+=e);var c=n[s-1],f=n.length<t?0:n[s===t?0:s];return n.length<o?c:(c-f)*o/n.length}}},{}],142:[function(e,t,n){var r=e("once");t.exports=function(e,t,n){n=r(n);var i=[];e.on("data",function(e){i.push(e)}).on("end",function(){var e=t?new Blob(i,{type:t}):new Blob(i),r=URL.createObjectURL(e);n(null,r)}).on("error",n)}},{once:144}],143:[function(e,t,n){arguments[4][20][0].apply(n,arguments)},{dup:20}],144:[function(e,t,n){arguments[4][21][0].apply(n,arguments)},{dup:21,wrappy:143}],145:[function(e,t,n){(function(n){var r=e("once");t.exports=function(e,t,i){i=r(i);var o=new n(t),s=0;e.on("data",function(e){e.copy(o,s),s+=e.length}).on("end",function(){i(null,o)}).on("error",i)}}).call(this,e("buffer").Buffer)},{buffer:26,once:147}],146:[function(e,t,n){arguments[4][20][0].apply(n,arguments)},{dup:20}],147:[function(e,t,n){arguments[4][21][0].apply(n,arguments)},{dup:21,wrappy:146}],148:[function(e,t,n){(function(n,r){function i(e){function t(){if("function"!=typeof s)return!1;o._internalDHT=!0;var t=new s;return t.listen(e.dhtPort),t}function r(e,t){t.toString("hex")===o.infoHash&&o.emit("peer",e.host+":"+e.port)}var o=this;if(!(o instanceof i))return new i(e);if(a.call(o),o.announce=e.announce||[],o.rtcConfig=e.rtcConfig,o.peerId=e.peerId,o.port=e.port||0,o.wrtc=e.wrtc,o.intervalMs=e.intervalMs||9e5,!o.peerId)throw new Error("peerId required");if(!n.browser&&!o.port)throw new Error("port required");o.infoHash=null,o.infoHashBuffer=null,o.torrent=null,o._dhtAnnouncing=!1,o._dhtTimeout=!1,o._internalDHT=!1,e.tracker===!1?o.tracker=!1:o.tracker=!0,e.dht===!1?o.dht=!1:"object"==typeof e.dht?o.dht=e.dht:o.dht=t(),o.dht&&(d(o.dht,o,["error","warning"]),o.dht.on("peer",r))}t.exports=i;var o=e("debug")("torrent-discovery"),s=e("bittorrent-dht/client"),a=e("events").EventEmitter,u=e("xtend"),c=e("inherits"),f=e("run-parallel"),d=e("re-emitter"),h=e("bittorrent-tracker/client");c(i,a),i.prototype.setTorrent=function(e){var t=this;if(t.infoHash||"string"!=typeof e&&!r.isBuffer(e)){if(t.torrent||!e||!e.infoHash)return;t.torrent=e,t.infoHash="string"==typeof e.infoHash?e.infoHash:e.infoHash.toString("hex")}else t.infoHash="string"==typeof e?e:e.toString("hex");t.infoHashBuffer=new r(t.infoHash,"hex"),o("setTorrent %s",t.infoHash),t.tracker&&t.tracker!==!0?t.tracker.torrentLength=e.length:t._createTracker(),t._dhtAnnounce()},i.prototype.updatePort=function(e){var t=this;e!==t.port&&(t.port=e,t._dhtAnnounce(),t.tracker&&t.tracker!==!0&&(t.tracker.stop(),t.tracker.destroy(function(){t._createTracker()})))},i.prototype.stop=function(e){var t=this,n=[];clearTimeout(t._dhtTimeout),t.tracker&&t.tracker!==!0&&(t.tracker.stop(),n.push(function(e){t.tracker.destroy(e)})),t._internalDHT&&n.push(function(e){t.dht.destroy(e)}),f(n,e)},i.prototype._createTracker=function(){function e(e){t.emit("trackerAnnounce",e)}var t=this;if(t.tracker){var n=t.torrent?u({announce:[]},t.torrent):{infoHash:t.infoHash,announce:[]};t.announce&&(n.announce=n.announce.concat(t.announce));var r={rtcConfig:t.rtcConfig,wrtc:t.wrtc};t.tracker=new h(t.peerId,t.port,n,r),d(t.tracker,t,["peer","warning","error"]),t.tracker.setInterval(t.intervalMs),t.tracker.on("update",e),t.tracker.start()}},i.prototype._dhtAnnounce=function(){function e(){return t.intervalMs+Math.floor(Math.random()*t.intervalMs/5)}var t=this;t.port&&t.infoHash&&t.dht&&!t._dhtAnnouncing&&(t._dhtAnnouncing=!0,t.dht.announce(t.infoHash,t.port,function(e){e&&t.emit("warning",e),t._dhtAnnouncing=!1,o("dht announce complete"),t.emit("dhtAnnounce")}),clearTimeout(t._dhtTimeout),t._dhtTimeout=setTimeout(function(){t._dhtAnnounce()},e()))}}).call(this,e("_process"),e("buffer").Buffer)},{_process:34,"bittorrent-dht/client":25,"bittorrent-tracker/client":16,buffer:26,debug:71,events:30,inherits:79,"re-emitter":96,"run-parallel":130,xtend:156}],149:[function(e,t,n){(function(e){function n(e){return this instanceof n?(this.length=e,this.missing=e,this.sources=null,this._chunks=Math.ceil(e/r),this._remainder=e%r||r,this._buffered=0,this._buffer=null,this._cancellations=null,this._reservations=0,void(this._flushed=!1)):new n(e)}t.exports=n;var r=16384;n.BLOCK_LENGTH=r,n.prototype.chunkLength=function(e){return e===this._chunks-1?this._remainder:r},n.prototype.chunkOffset=function(e){return e*r},n.prototype.reserve=function(){return this.init()?this._cancellations.length?this._cancellations.pop():this._reservations<this._chunks?this._reservations++:-1:-1},n.prototype.cancel=function(e){this.init()&&this._cancellations.push(e)},n.prototype.get=function(e){return this.init()?this._buffer[e]:null},n.prototype.set=function(e,t,n){return this.init()?(this._buffer[e]||(this._buffered++,this._buffer[e]=t,this.missing-=t.length,-1===this.sources.indexOf(n)&&this.sources.push(n)),this._buffered===this._chunks):!1},n.prototype.flush=function(){if(!this._buffer||this._chunks!==this._buffered)return null;var t=e.concat(this._buffer,this.length);return this._buffer=null,this._cancellations=null,this.sources=null,this._flushed=!0,t},n.prototype.init=function(){return this._flushed?!1:this._buffer?!0:(this._buffer=new Array(this._chunks),this._cancellations=[],this.sources=[],!0)}}).call(this,e("buffer").Buffer)},{buffer:26}],150:[function(e,t,n){"use strict";function r(e,t){for(var n=1,r=e.length,i=e[0],o=e[0],s=1;r>s;++s)if(o=i,i=e[s],t(i,o)){if(s===n){n++;continue}e[n++]=i}return e.length=n,e}function i(e){for(var t=1,n=e.length,r=e[0],i=e[0],o=1;n>o;++o,i=r)if(i=r,r=e[o],r!==i){if(o===t){t++;continue}e[t++]=r}return e.length=t,e}function o(e,t,n){return 0===e.length?e:t?(n||e.sort(t),r(e,t)):(n||e.sort(),i(e))}t.exports=o},{}],151:[function(e,t,n){(function(n){var r=e("bencode"),i=e("bitfield"),o=e("debug")("ut_metadata"),s=e("events").EventEmitter,a=e("inherits"),u=e("simple-sha1"),c=1e7,f=1e3,d=16384;t.exports=function(e){function t(t){s.call(this),this._wire=t,this._metadataComplete=!1,this._metadataSize=null,this._remainingRejects=null,this._fetching=!1,this._bitfield=new i(0,{grow:f}),n.isBuffer(e)&&this.setMetadata(e)}return a(t,s),t.prototype.name="ut_metadata",t.prototype.onHandshake=function(e,t,n){this._infoHash=e},t.prototype.onExtendedHandshake=function(e){return e.m&&e.m.ut_metadata?e.metadata_size?e.metadata_size>c?this.emit("warning",new Error("Peer gave maliciously large metadata size")):(this._metadataSize=e.metadata_size,this._numPieces=Math.ceil(this._metadataSize/d),this._remainingRejects=2*this._numPieces,void(this._fetching&&this._requestPieces())):this.emit("warning",new Error("Peer does not have metadata")):this.emit("warning",new Error("Peer does not support ut_metadata"))},t.prototype.onMessage=function(e){var t,n;try{var i=e.toString(),o=i.indexOf("ee")+2;t=r.decode(i.substring(0,o)),n=e.slice(o)}catch(s){return}switch(t.msg_type){case 0:this._onRequest(t.piece);break;case 1:this._onData(t.piece,n,t.total_size);break;case 2:this._onReject(t.piece)}},t.prototype.fetch=function(){this._metadataComplete||(this._fetching=!0,this._metadataSize&&this._requestPieces())},t.prototype.cancel=function(){this._fetching=!1},t.prototype.setMetadata=function(e){if(this._metadataComplete)return!0;o("set metadata");try{var t=r.decode(e).info;t&&(e=r.encode(t))}catch(n){}return this._infoHash&&this._infoHash!==u.sync(e)?!1:(this.cancel(),this.metadata=e,this._metadataComplete=!0,this._metadataSize=this.metadata.length,this._wire.extendedHandshake.metadata_size=this._metadataSize,this.emit("metadata",r.encode({info:r.decode(this.metadata)})),!0)},t.prototype._send=function(e,t){var i=r.encode(e);n.isBuffer(t)&&(i=n.concat([i,t])),this._wire.extended("ut_metadata",i)},t.prototype._request=function(e){this._send({msg_type:0,piece:e})},t.prototype._data=function(e,t,n){var r={msg_type:1,piece:e};"number"==typeof n&&(r.total_size=n),this._send(r,t)},t.prototype._reject=function(e){this._send({msg_type:2,piece:e})},t.prototype._onRequest=function(e){if(!this._metadataComplete)return void this._reject(e);var t=e*d,n=t+d;n>this._metadataSize&&(n=this._metadataSize);var r=this.metadata.slice(t,n);this._data(e,r,this._metadataSize)},t.prototype._onData=function(e,t,n){t.length>d||(t.copy(this.metadata,e*d),this._bitfield.set(e),this._checkDone())},t.prototype._onReject=function(e){this._remainingRejects>0&&this._fetching?(this._request(e),this._remainingRejects-=1):this.emit("warning",new Error('Peer sent "reject" too much'))},t.prototype._requestPieces=function(){this.metadata=new n(this._metadataSize);for(var e=0;e<this._numPieces;e++)this._request(e)},t.prototype._checkDone=function(){for(var e=!0,t=0;t<this._numPieces;t++)if(!this._bitfield.get(t)){e=!1;break}if(e){var n=this.setMetadata(this.metadata);n||this._failedMetadata()}},t.prototype._failedMetadata=function(){this._bitfield=new i(0,{grow:f}),this._remainingRejects-=this._numPieces,this._remainingRejects>0?this._requestPieces():this.emit("warning",new Error("Peer sent invalid metadata"))},t}}).call(this,e("buffer").Buffer)},{bencode:152,bitfield:7,buffer:26,debug:71,events:30,inherits:79,"simple-sha1":139}],152:[function(e,t,n){arguments[4][12][0].apply(n,arguments)},{"./lib/decode":153,"./lib/encode":155,dup:12}],153:[function(e,t,n){arguments[4][13][0].apply(n,arguments)},{"./dict":154,buffer:26,dup:13}],154:[function(e,t,n){arguments[4][14][0].apply(n,arguments)},{dup:14}],155:[function(e,t,n){arguments[4][15][0].apply(n,arguments)},{buffer:26,dup:15}],156:[function(e,t,n){function r(){for(var e={},t=0;t<arguments.length;t++){var n=arguments[t];for(var r in n)i.call(n,r)&&(e[r]=n[r])}return e}t.exports=r;var i=Object.prototype.hasOwnProperty},{}],157:[function(e,t,n){function r(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)i.call(n,r)&&(e[r]=n[r])}return e}t.exports=r;var i=Object.prototype.hasOwnProperty},{}],158:[function(e,t,n){t.exports=function r(e,t,n){return void 0===t?function(t,n){return r(e,t,n)}:(void 0===n&&(n="0"),e-=t.toString().length,e>0?new Array(e+(/\./.test(t)?2:1)).join(n)+t:t+"")}},{}],159:[function(e,t,n){t.exports={version:"0.75.0"}},{}],160:[function(e,t,n){(function(n,r,i){function o(e){function t(){s.destroyed||(s.ready=!0,s.emit("ready"))}var s=this;return s instanceof o?(f.call(s),e||(e={}),u.enabled||s.setMaxListeners(0),s.destroyed=!1,s.torrentPort=e.torrentPort||0,s.tracker=void 0!==e.tracker?e.tracker:!0,s._rtcConfig=e.rtcConfig,s._wrtc=e.wrtc||r.WRTC,s.torrents=[],s._downloadSpeed=_(),s._uploadSpeed=_(),s.maxConns=e.maxConns,s.peerId="string"==typeof e.peerId?e.peerId:(e.peerId||new i(S+h(48))).toString("hex"),s.peerIdBuffer=new i(s.peerId,"hex"),s.nodeId="string"==typeof e.nodeId?e.nodeId:e.nodeId&&e.nodeId.toString("hex")||h(160),s.nodeIdBuffer=new i(s.nodeId,"hex"),e.dht!==!1&&"function"==typeof c?(s.dht=new c(d({nodeId:s.nodeId},e.dht)),s.dht.listen(e.dhtPort)):s.dht=!1,u("new webtorrent (peerId %s, nodeId %s)",s.peerId,s.nodeId),void("function"==typeof p?p(e.blocklist,{headers:{"user-agent":"WebTorrent/"+k+" (http://webtorrent.io)"}},function(e,n){return e?s.error("Failed to load blocklist: "+e.message):(s.blocked=n,void t())}):n.nextTick(t))):new o(e)}function s(e){return"object"==typeof e&&null!=e&&"function"==typeof e.pipe}t.exports=o;var a=e("create-torrent"),u=e("debug")("webtorrent"),c=e("bittorrent-dht/client"),f=e("events").EventEmitter,d=e("xtend"),h=e("hat"),l=e("inherits"),p=e("load-ip-set"),m=e("run-parallel"),g=e("parse-torrent"),y=e("path"),v=e("simple-peer"),_=e("speedometer"),b=e("zero-fill"),w=e("./lib/concat-stream"),E=e("./lib/torrent");t.exports.WEBRTC_SUPPORT=v.WEBRTC_SUPPORT;var k=e("./package.json").version,x=k.match(/([0-9]+)/g).slice(0,2).map(b(2)).join(""),S="-WW"+x+"-";l(o,f),Object.defineProperty(o.prototype,"ratio",{get:function(){var e=this.torrents.reduce(function(e,t){return e+t.uploaded},0),t=this.torrents.reduce(function(e,t){return e+t.downloaded},0)||1;return e/t}}),Object.defineProperty(o.prototype,"downloadSpeed",{get:function(){return this._downloadSpeed()}}),Object.defineProperty(o.prototype,"uploadSpeed",{get:function(){return this._uploadSpeed()}}),o.prototype.get=function(e){var t=this;if(e instanceof E)return e;var n;try{n=g(e)}catch(r){}if(!n)return null;if(!n.infoHash)throw new Error("Invalid torrent identifier");for(var i=0,o=t.torrents.length;o>i;i++){var s=t.torrents[i];if(s.infoHash===n.infoHash)return s}return null},o.prototype.add=o.prototype.download=function(e,t,r){function i(){u("on torrent"),"function"==typeof r&&r(s),o.emit("torrent",s)}var o=this;if(o.destroyed)throw new Error("client is destroyed");if("function"==typeof t)return o.add(e,null,t);u("add"),t=t?d(t):{};var s=o.get(e);return s?s.ready?n.nextTick(i):s.once("ready",i):(s=new E(e,o,t),o.torrents.push(s),s.once("error",function(e){o.emit("error",e,s),o.remove(s)}),s.once("listening",function(e){o.emit("listening",e,s)}),s.once("ready",i)),s},o.prototype.seed=function(e,t,n){function r(e){var t=[function(t){e.load(c,t)}];o.dht&&t.push(function(t){e.once("dhtAnnounce",t)}),m(t,function(t){return o.destroyed?void 0:t?o.emit("error",t,e):void i(e)})}function i(e){u("on seed"),"function"==typeof n&&n(e),o.emit("seed",e)}var o=this;if(o.destroyed)throw new Error("client is destroyed");if("function"==typeof t)return o.seed(e,null,t);u("seed"),t=t?d(t):{},"string"==typeof e&&(t.path=y.dirname(e)),t.createdBy||(t.createdBy="WebTorrent/"+x),o.tracker||(t.announce=[]);var c,f=o.add(null,t,r);return Array.isArray(e)||(e=[e]),m(e.map(function(e){return function(t){s(e)?w(e,t):t(null,e)}}),function(e,n){return e?o.emit("error",e,f):void(o.destroyed||a.parseInput(n,t,function(e,r){return e?o.emit("error",e,f):void(o.destroyed||(c=r.map(function(e){return e.getStream}),a(n,t,function(e,t){if(e)return o.emit("error",e,f);if(!o.destroyed){var n=o.get(t);n?(f.destroy(),i(n)):f._onTorrentId(t)}})))}))}),f},o.prototype.remove=function(e,t){var n=this;u("remove");var r=n.get(e);if(!r)throw new Error("No torrent with id "+e);n.torrents.splice(n.torrents.indexOf(r),1),r.destroy(t)},o.prototype.address=function(){var e=this;return{address:"0.0.0.0",family:"IPv4",port:e.torrentPort}},o.prototype.destroy=function(e){var t=this;if(t.destroyed)throw new Error("client already destroyed");t.destroyed=!0,u("destroy");var n=t.torrents.map(function(e){return function(n){t.remove(e,n)}});t.dht&&n.push(function(e){t.dht.destroy(e)}),m(n,e)}}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer)},{"./lib/concat-stream":1,"./lib/torrent":5,"./package.json":159,_process:34,"bittorrent-dht/client":25,buffer:26,"create-torrent":54,debug:71,events:30,hat:77,inherits:79,"load-ip-set":25,"parse-torrent":82,path:33,"run-parallel":130,"simple-peer":134,speedometer:141,xtend:156,"zero-fill":158}]},{},[160])(160)}); |