Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2015-12-28 16:33:05 +0300
committerFeross Aboukhadijeh <feross@feross.org>2015-12-28 16:33:05 +0300
commit9339f058a0e66a8f9347ba11410ba3e7eb3d1008 (patch)
tree060a76ea923e1c1db583a6d9843a48a07a96796e
parentd8903c8261875bf4ac89fbdc0a9fff78ff208a76 (diff)
build
-rw-r--r--webtorrent.min.js20
1 files changed, 10 insertions, 10 deletions
diff --git a/webtorrent.min.js b/webtorrent.min.js
index 1b983bf..ddff7a0 100644
--- a/webtorrent.min.js
+++ b/webtorrent.min.js
@@ -1,10 +1,10 @@
-(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(o,a){if(!t[o]){if(!e[o]){var f=typeof require=="function"&&require;if(!a&&f)return f(o,!0);if(s)return s(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var h=t[o]={exports:{}};e[o][0].call(h.exports,function(t){var r=e[o][1][t];return i(r?r:t)},h,h.exports,n,e,t,r)}return t[o].exports}var s=typeof require=="function"&&require;for(var o=0;o<r.length;o++)i(r[o]);return i}({1:[function(e,t,r){(function(r){var n=e("debug")("webtorrent:append-to");var i=e("mediasource");var s=e("path");var o=e("videostream");var a=[".mp4",".m4v",".m4a"];var f=[".mp4",".m4v",".webm"];var u=[".m4a",".mp3"];var h=f.concat(u);var l=[".wav",".aac",".ogg",".oga"];var c=[".jpg",".jpeg",".png",".gif",".bmp"];var d=[".css",".html",".js",".md",".pdf",".txt"];var p=typeof window!=="undefined"&&window.MediaSource;t.exports=function v(e,t,r){if(!r)r=m;var u;var v=s.extname(e.name).toLowerCase();var y=0;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.")}if(h.indexOf(v)>=0)_();else if(l.indexOf(v)>=0)w();else if(c.indexOf(v)>=0)S();else if(d.indexOf(v)>=0)x();else g(r,new Error('Unsupported file type "'+v+'": Cannot append to DOM'));function _(){if(!p){return g(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 s=f.indexOf(v)>=0?"video":"audio";if(a.indexOf(v)>=0)h();else l();function h(){n("Use `videostream` package for "+e.name);_();u.addEventListener("error",d);u.addEventListener("playing",b);o(e,u)}function l(){n("Use MediaSource API for "+e.name);_();u.addEventListener("error",m);u.addEventListener("playing",b);e.createReadStream().pipe(new i(u,{extname:v}));if(y)u.currentTime=y}function c(){n("Use Blob URL for "+e.name);_();u.addEventListener("error",k);u.addEventListener("playing",b);e.getBlobURL(function(e,t){if(e)return k(e);u.src=t;if(y)u.currentTime=y})}function d(e){n("videostream error: fallback to MediaSource API: %o",e.message||e);u.removeEventListener("error",d);u.removeEventListener("playing",b);l()}function m(e){n("MediaSource API error: fallback to Blob URL: %o",e.message||e);u.removeEventListener("error",m);u.removeEventListener("playing",b);c()}function _(e){if(!u){u=document.createElement(s);u.controls=true;u.autoplay=true;u.play();u.addEventListener("progress",function(){y=u.currentTime});t.appendChild(u)}}}function b(){u.removeEventListener("playing",b);r(null,u)}function w(){u=document.createElement("audio");u.controls=true;u.autoplay=true;t.appendChild(u);e.getBlobURL(function(e,t){if(e)return k(e);u.addEventListener("error",k);u.addEventListener("playing",b);u.src=t;u.play()})}function S(){e.getBlobURL(function(n,i){if(n)return k(n);u=document.createElement("img");u.src=i;u.alt=e.name;t.appendChild(u);r(null,u)})}function x(){e.getBlobURL(function(e,n){if(e)return k(e);u=document.createElement("iframe");u.src=n;if(v!==".pdf")u.sandbox="allow-forms allow-scripts";t.appendChild(u);r(null,u)})}function k(t){if(u)u.remove();t.message='Error appending file "'+e.name+'" to DOM: '+t.message;n(t.message);if(r)r(t)}};function m(){}function g(e,t,n){r.nextTick(function(){if(e)e(t,n)})}}).call(this,e("_process"))},{_process:41,debug:114,mediasource:123,path:40,videostream:164}],2:[function(e,t,r){t.exports=o;var n=e("debug")("webtorrent:file-stream");var i=e("inherits");var s=e("stream");i(o,s.Readable);function o(e,t){s.Readable.call(this,t);this.destroyed=false;this._torrent=e._torrent;var r=t&&t.start||0;var n=t&&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)}o.prototype._read=function(){if(this._reading)return;this._reading=true;this._notify()};o.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};o.prototype.destroy=function(){if(this.destroyed)return;this.destroyed=true;this._torrent.deselect(this._startPiece,this._endPiece,true)}},{debug:114,inherits:122,stream:59}],3:[function(e,t,r){(function(r,n){t.exports=c;var i=e("./append-to");var s=e("end-of-stream");var o=e("events").EventEmitter;var a=e("./file-stream");var f=e("inherits");var u=e("./mime.json");var h=e("path");var l=e("stream");f(c,o);function c(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=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")}}c.prototype.select=function(){if(this.length===0)return;this._torrent.select(this._startPiece,this._endPiece,false)};c.prototype.deselect=function(){if(this.length===0)return;this._torrent.deselect(this._startPiece,this._endPiece,false)};c.prototype.createReadStream=function(e){var t=this;if(this.length===0){var n=new l.PassThrough;r.nextTick(function(){n.end()});return n}var i=new a(t,e);t._torrent.select(i._startPiece,i._endPiece,true,function(){i._notify()});s(i,function(){t._torrent.deselect(i._startPiece,i._endPiece,true)});return i};c.prototype.getBuffer=function(e){var t=new n(this.length);var r=0;this.createReadStream().on("data",function(e){e.copy(t,r);r+=e.length}).on("end",function(){e(null,t)}).on("error",e)};c.prototype.getBlobURL=function(e){var t=this;if(typeof window==="undefined")throw new Error("browser-only method");t.getBuffer(function(r,n){if(r)return e(r);var i=h.extname(t.name).toLowerCase();var s=u[i];var o=s?new window.Blob([n],{type:s}):new window.Blob([n]);var a=window.URL.createObjectURL(o);e(null,a)})};c.prototype.appendTo=function(e,t){if(typeof window==="undefined")throw new Error("browser-only method");if(typeof e==="string")e=document.querySelector(e);i(this,e,t)}}).call(this,e("_process"),e("buffer").Buffer)},{"./append-to":1,"./file-stream":2,"./mime.json":4,_process:41,buffer:32,"end-of-stream":117,events:36,inherits:122,path:40,stream:59}],4:[function(e,t,r){t.exports={".aac":"audio/aac",".css":"text/css",".html":"text/html",".js":"application/javascript",".m4a":"audio/mp4",".md":"text/x-markdown",".mp3":"audio/mpeg",".mp4":"video/mp4",".oga":"audio/ogg",".ogg":"audio/ogg",".pdf":"application/pdf",".txt":"text/plain",".wav":"audio/wav",".webm":"video/webm"}},{}],5:[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 s=t.pieces[i];if(s===n){r.push(i)}else if(s<n){r=[i];n=s}}if(r.length>0){return r[Math.random()*r.length|0]}else{return-1}}},{}],6:[function(e,t,r){(function(r,n){t.exports=H;var i=e("addr-to-ip-port");var s=e("bitfield");var o=e("chunk-store-stream/write");var a=e("create-torrent");var f=e("debug")("webtorrent:torrent");var u=e("torrent-discovery");var h=e("events").EventEmitter;var l=e("xtend/mutable");var c=e("fs-chunk-store");var d=e("immediate-chunk-store");var p=e("inherits");var m=e("multistream");var g=e("os");var v=e("run-parallel");var y=e("parse-torrent");var _=e("path");var b=e("path-exists");var w=e("torrent-piece");var S=e("pump");var x=e("random-iterate");var k=e("re-emitter");var E=e("simple-sha1");var A=e("bittorrent-swarm");var U=e("uniq");var I=e("ut_metadata");var T=e("ut_pex");var B=e("./file");var L=e("./rarity-map");var C=e("./server");var R=128*1024;var P=3e4;var F=5e3;var O=3*w.BLOCK_LENGTH;var D=.5;var M=1;var N=1e4;var z=2;var j=typeof b.sync==="function"?_.join(b.sync("/tmp")?"/tmp":g.tmpDir(),"webtorrent"):"/tmp/webtorrent";p(H,h);function H(e,t){h.call(this);if(!f.enabled)this.setMaxListeners(0);f("new torrent");this.client=t.client;this.announce=t.announce;this.urlList=t.urlList;this.path=t.path;this._store=t.store||c;this.strategy=t.strategy||"sequential";this._rechokeNumSlots=t.uploads===false||t.uploads===0?0:+t.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)this._onTorrentId(e)}Object.defineProperty(H.prototype,"timeRemaining",{get:function(){if(this.done)return 0;if(this.swarm.downloadSpeed()===0)return Infinity;else return(this.length-this.downloaded)/this.swarm.downloadSpeed()*1e3}});Object.defineProperty(H.prototype,"downloaded",{get:function(){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(H.prototype,"received",{get:function(){return this.swarm?this.swarm.downloaded:0}});Object.defineProperty(H.prototype,"uploaded",{get:function(){return this.swarm?this.swarm.uploaded:0}});Object.defineProperty(H.prototype,"progress",{get:function(){return this.length?this.downloaded/this.length:0}});Object.defineProperty(H.prototype,"ratio",{get:function(){return this.uploaded/(this.downloaded||1)}});Object.defineProperty(H.prototype,"numPeers",{get:function(){return this.swarm?this.swarm.numPeers:0}});Object.defineProperty(H.prototype,"torrentFileURL",{get:function(){if(typeof window==="undefined")throw new Error("browser-only property");if(!this.torrentFile)return null;return window.URL.createObjectURL(new window.Blob([this.torrentFile],{type:"application/x-bittorrent"}))}});H.prototype.downloadSpeed=function(){return this.swarm?this.swarm.downloadSpeed():0};H.prototype.uploadSpeed=function(){return this.swarm?this.swarm.uploadSpeed():0};H.prototype._onTorrentId=function(e){var t=this;if(t.destroyed)return;y.remote(e,function(e,r){if(t.destroyed)return;if(e)return t._onError(e);t._onParsedTorrent(r)})};H.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=_.join(j,t.infoHash);t.swarm=new A(t.infoHash,t.client.peerId,{handshake:{dht:t.private?false:!!t.client.dht}});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));r.nextTick(function(){if(t.destroyed)return;t.emit("infoHash",t.infoHash)})};H.prototype._processParsedTorrent=function(e){if(this.announce){e.announce=e.announce.concat(this.announce)}if(this.client.tracker&&n.WEBTORRENT_ANNOUNCE){e.announce=e.announce.concat(n.WEBTORRENT_ANNOUNCE)}if(this.client.tracker&&e.announce.length===0){e.announce=a.announceList.map(function(e){return e[0]})}if(this.urlList){e.urlList=e.urlList.concat(this.urlList)}U(e.announce);U(e.urlList);l(this,e);this.magnetURI=y.toMagnetURI(e);this.torrentFile=y.toTorrentFile(e)};H.prototype._onSwarmListening=function(){var e=this;if(e.destroyed)return;if(e.swarm.server)e.client.torrentPort=e.swarm.address().port;e.discovery=new u({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.setTorrent(e.infoHash);e.discovery.on("peer",e.addPeer.bind(e));k(e.discovery,e,["trackerAnnounce","dhtAnnounce","warning"]);if(e.info)e._onMetadata(e);e.emit("listening",e.client.torrentPort)};H.prototype._onMetadata=function(e){var t=this;if(t.metadata||t.destroyed)return;f("got metadata");var r;if(e&&e.infoHash){r=e}else{try{r=y(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 L(t.swarm,t.pieces.length);t.store=new d(new t._store(t.pieceLength,{files:t.files.map(function(e){return{path:_.join(t.path,e.path),length:e.length,offset:e.offset}}),length:t.length}));t.files=t.files.map(function(e){return new B(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 w(n)});t._reservations=t.pieces.map(function(){return[]});t.bitfield=new s(t.pieces.length);t.swarm.wires.forEach(function(e){if(e.ut_metadata)e.ut_metadata.setMetadata(t.metadata);t._onWireWithMetadata(e)});f("verifying existing torrent data");v(t.pieces.map(function(e,r){return function(e){t.store.get(r,function(n,i){if(n)return e(null);E(i,function(n){if(n===t._hashes[r]){if(!t.pieces[r])return;f("piece verified %s",r);t.pieces[r]=null;t._reservations[r]=null;t.bitfield.set(r,true)}else{f("piece invalid %s",r)}e(null)})})}}),function(e){if(e)return t._onError(e);f("done verifying");t._onStore()});t.emit("metadata")};H.prototype._onStore=function(){var e=this;if(e.destroyed)return;f("on store");e.select(0,e.pieces.length-1,false);e._rechokeIntervalId=setInterval(e._rechoke.bind(e),N);if(e._rechokeIntervalId.unref)e._rechokeIntervalId.unref();e.ready=true;e.emit("ready");e._checkDone()};H.prototype.destroy=function(e){var t=this;if(t.destroyed)return;t.destroyed=true;f("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)});v(r,e)};H.prototype.addPeer=function(e){var t=this;function r(){t.swarm.addPeer(e);t.emit("peer",e)}if(typeof e==="string"&&t.client.blocked&&t.client.blocked.contains(i(e)[0])){t.numBlockedPeers+=1;t.emit("blockedPeer",e);return false}else{if(t.swarm)r();else t.once("listening",r);return true}};H.prototype.addWebSeed=function(e){var t=this;f("add web seed %s",e);t.swarm.addWebSeed(e,t)};H.prototype.select=function(e,t,r,n){var i=this;if(e>t||e<0||t>=i.pieces.length){throw new Error("invalid selection ",e,":",t)}r=Number(r)||0;f("select %s-%s (priority %s)",e,t,r);i._selections.push({from:e,to:t,offset:0,priority:r,notify:n||W});i._selections.sort(function(e,t){return t.priority-e.priority});i._updateSelections()};H.prototype.deselect=function(e,t,r){var n=this;r=Number(r)||0;f("deselect %s-%s (priority %s)",e,t,r);for(var i=0;i<n._selections.length;++i){var s=n._selections[i];if(s.from===e&&s.to===t&&s.priority===r){n._selections.splice(i--,1);break}}n._updateSelections()};H.prototype.critical=function(e,t){var r=this;f("critical %s-%s",e,t);for(var n=e;n<=t;++n){r._critical[n]=true}r._updateSelections()};H.prototype._onWire=function(e,t){var r=this;f("got wire (%s)",t||"Unknown");if(t){var n=i(t);e.remoteAddress=n[0];e.remotePort=n[1]}if(e.peerExtensions.dht&&r.client.dht&&r.client.dht.listening){e.on("port",function(t){if(!e.remoteAddress){f("ignoring port from peer with no address");return}f("port: %s (from %s)",t,e.remoteAddress+":"+e.remotePort);r.client.dht.addNode(e.remoteAddress+":"+t)});e.port(r.client.dht.address().port)}e.on("timeout",function(){f("wire timeout (%s)",t);e.destroy()});e.setTimeout(P,true);e.setKeepAlive(true);e.use(I(r.metadata));if(!r.metadata){e.ut_metadata.on("metadata",function(e){f("got metadata via ut_metadata");r._onMetadata(e)});e.ut_metadata.fetch()}if(typeof T==="function"&&!r.private){e.use(T());e.ut_pex.on("peer",function(e){f("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];if(n&&!n.connected){f("ut_pex: dropped peer: %s (from %s)",e,t);r.swarm.removePeer(e)}})}r.emit("wire",e,t);if(r.metadata){r._onWireWithMetadata(e)}};H.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,F);if(r.unref)r.unref()}}var i=0;function s(){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(){s();t._update()});e.on("have",function(){s();t._update()});e.once("interested",function(){e.unchoke()});e.on("close",function(){clearTimeout(r)});e.on("choke",function(){clearTimeout(r);r=setTimeout(n,F);if(r.unref)r.unref()});e.on("unchoke",function(){clearTimeout(r);t._update()});e.on("request",function(r,n,i,s){if(i>R){return e.destroy()}if(t.pieces[r])return;t.store.get(r,{offset:n,length:i},s)});e.bitfield(t.bitfield);e.interested();r=setTimeout(n,F);if(r.unref)r.unref();e.isSeeder=false;s()};H.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()};H.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")};H.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")};H.prototype._update=function(){var e=this;if(e.destroyed)return;var t=x(e.swarm.wires);var r;while(r=t()){e._updateWire(r)}};H.prototype._updateWire=function(e){var t=this;if(e.peerChoking)return;if(!e.downloaded)return s();var r=q(e,D);if(e.requests.length>=r)return;var n=q(e,M);f(false)||f(true);function i(t,r,n,i){return function(s){return s>=t&&s<=r&&!(s in n)&&e.peerPieces.get(s)&&(!i||i(s))}}function s(){if(e.requests.length)return;var r=t._selections.length;while(r--){var n=t._selections[r];var s;if(t.strategy==="rarest"){var o=n.from+n.offset;var a=n.to;var f=a-o+1;var u={};var h=0;var l=i(o,a,u);while(h<f){s=t.rarityMap.getRarestPiece(l);if(s<0)break;if(t._request(e,s,false))return;u[s]=true;h+=1}}else{for(s=n.to;s>=n.from+n.offset;--s){if(!e.peerPieces.get(s))continue;if(t._request(e,s,false))return}}}}function o(){var r=e.downloadSpeed()||1;if(r>O)return function(){return true};var n=Math.max(1,e.requests.length)*w.BLOCK_LENGTH/r;var i=10;var s=0;return function(e){if(!i||t.bitfield.get(e))return true;var o=t.pieces[e].missing;for(;s<t.swarm.wires.length;s++){var a=t.swarm.wires[s];var f=a.downloadSpeed();if(f<O)continue;if(f<=r)continue;if(!a.peerPieces.get(e))continue;if((o-=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 s=o();for(var f=0;f<t._selections.length;f++){var u=t._selections[f];var h;if(t.strategy==="rarest"){var l=u.from+u.offset;var c=u.to;var d=c-l+1;var p={};var m=0;var g=i(l,c,p,s);while(m<d){h=t.rarityMap.getRarestPiece(g);if(h<0)break;while(t._request(e,h,t._critical[h]||r)){}if(e.requests.length<n){p[h]=true;m++;continue}if(u.priority)a(f);return true}}else{for(h=u.from+u.offset;h<=u.to;h++){if(!e.peerPieces.get(h)||!s(h))continue;while(t._request(e,h,t._critical[h]||r)){}if(e.requests.length<n)continue;if(u.priority)a(f);return true}}}return false}};H.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(o);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 s=i[G(i.length)];if(s){s.isChoked=false;e._rechokeOptimisticWire=s.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 o(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}};H.prototype._hotswap=function(e,t){var r=this;var n=e.downloadSpeed();if(n<w.BLOCK_LENGTH)return false;if(!r._reservations[t])return false;var i=r._reservations[t];if(!i){return false}var s=Infinity;var o;var a;for(a=0;a<i.length;a++){var f=i[a];if(!f||f===e)continue;var u=f.downloadSpeed();if(u>=O)continue;if(2*u>n||u>s)continue;o=f;s=u}if(!o)return false;for(a=0;a<i.length;a++){if(i[a]===o)i[a]=null}for(a=0;a<o.requests.length;a++){var h=o.requests[a];if(h.piece!==t)continue;r.pieces[t].cancel(h.offset/w.BLOCK_SIZE|0)}r.emit("hotswap",o,e,t);return true};H.prototype._request=function(e,t,n){var i=this;var s=e.requests.length;if(i.bitfield.get(t))return false;var o=q(e,M);if(s>=o)return false;var a=i.pieces[t];var u=a.reserve();if(u===-1&&n&&i._hotswap(e,t)){u=a.reserve()}if(u===-1)return false;var h=i._reservations[t];if(!h)h=i._reservations[t]=[];var l=h.indexOf(null);if(l===-1)l=h.length;h[l]=e;var c=a.chunkOffset(u);var d=a.chunkLength(u);e.request(t,c,d,function m(r,n){if(!i.ready)return i.once("ready",function(){m(r,n)});if(h[l]===e)h[l]=null;if(a!==i.pieces[t])return p();if(r){f("error getting piece %s (offset: %s length: %s) from %s: %s",t,c,d,e.remoteAddress+":"+e.remotePort,r.message);a.cancel(u);p();return}f("got piece %s (offset: %s length: %s) from %s",t,c,d,e.remoteAddress+":"+e.remotePort);if(!a.set(u,n,e))return p();var s=a.flush();E(s,function(e){if(e===i._hashes[t]){if(!i.pieces[t])return;f("piece verified %s",t);i.pieces[t]=null;i._reservations[t]=null;i.bitfield.set(t,true);i.store.put(t,s);i.swarm.wires.forEach(function(e){e.have(t)});i._checkDone()}else{i.pieces[t]=new w(a.length);i.emit("warning",new Error("Piece "+t+" failed verification"))}p()})});function p(){r.nextTick(function(){i._update()})}return true};H.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");f("file done: "+t.name)});if(e.files.every(function(e){return e.done})){e.done=true;e.emit("done");f("torrent done: "+e.infoHash);if(e.discovery.tracker)e.discovery.tracker.complete()}e._gcSelections()};H.prototype.load=function(e,t){var r=this;if(!Array.isArray(e))e=[e];if(!t)t=W;var n=new m(e);var i=new o(r.store,r.pieceLength);S(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)})};H.prototype.createServer=function(e){var t=this;if(typeof C!=="function")throw new Error("node.js-only method");var r=new C(t,e);t._servers.push(r);return r};H.prototype._onError=function(e){var t=this;f("torrent error: %s",e.message||e);t.emit("error",e);t.destroy()};function q(e,t){return Math.ceil(2+t*e.downloadSpeed()/w.BLOCK_LENGTH)}function G(e){return Math.random()*e|0}function W(){}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./file":3,"./rarity-map":5,"./server":31,_process:41,"addr-to-ip-port":7,bitfield:8,"bittorrent-swarm":9,"chunk-store-stream/write":81,"create-torrent":82,debug:114,events:36,"fs-chunk-store":124,"immediate-chunk-store":121,inherits:122,multistream:125,os:31,"parse-torrent":126,path:40,"path-exists":31,pump:138,"random-iterate":141,"re-emitter":142,"run-parallel":143,"simple-sha1":147,"torrent-discovery":150,"torrent-piece":151,uniq:152,ut_metadata:153,ut_pex:31,"xtend/mutable":166}],7:[function(e,t,r){var n=/^\[?([^\]]+)\]?:(\d+)$/;var i={};var s=0;t.exports=function o(e){if(s===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])];s+=1}return i[e]};t.exports.reset=function a(){i={};s=0}},{}],8:[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:32}],9:[function(e,t,r){(function(r,n){t.exports=p;var i=e("addr-to-ip-port");var s=e("debug")("bittorrent-swarm");var o=e("events").EventEmitter;var a=e("inherits");var f=e("net");var u=e("speedometer");var h=e("./lib/peer");var l=e("./lib/tcp-pool");var c=55;var d=[1e3,5e3,15e3];a(p,o);function p(e,t,r){var i=this;if(!(i instanceof p))return new p(e,t,r);o.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={};s("new swarm (i %s p %s)",i.infoHash,i.peerId);i.handshakeOpts=r.handshake;i.maxConns=r.maxConns!==undefined?r.maxConns:c;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)){s("ignoring invalid peer %s (from swarm.addPeer)",e);return null}var r=e&&e.id||e;if(t._peers[r])return;s("addPeer %s",r);var n;if(typeof e==="string"){n=h.createOutgoingTCPPeer(e,t)}else{if(t.paused){e.destroy(new Error("swarm paused"));return null}n=h.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)){s("ignoring invalid web seed %s (from swarm.addWebSeed)",e);return}if(r._peers[e])return;s("addWebSeed %s",e);var n=h.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)"))}s("_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;s("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;s("pause");e.paused=true};p.prototype.resume=function(){var e=this;if(e.destroyed)return;s("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;s("listen %s",e);var o=l.addSwarm(i);i.server=o.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);s("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;s("_drain numConns %s maxConns %s",e.numConns,e.maxConns);if(typeof f.connect!=="function"||e.destroyed||e.paused||e.numConns>=e.maxConns){return}s("drain (%s queued, %s/%s peers)",e.numQueued,e.numPeers,e.maxConns);var t=e._queue.shift();if(!t)return;s("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 o=t.conn=f.connect(n);o.once("connect",function(){t.onConnect()});o.once("error",function(e){t.destroy(e)});t.setConnectTimeout();o.on("close",function(){if(e.destroyed)return;if(t.retries>=d.length){s("conn %s closed: will not re-add (max %s attempts)",t.addr,d.length);return}var r=d[t.retries];s("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 s=r[1];return s>0&&s<65535&&!(n==="127.0.0.1"&&s===t._port)}}).call(this,e("_process"),e("buffer").Buffer)},{"./lib/peer":10,"./lib/tcp-pool":31,_process:41,"addr-to-ip-port":31,buffer:32,debug:114,events:36,inherits:122,net:31,speedometer:149}],10:[function(e,t,r){var n=e("debug")("bittorrent-swarm:peer");var i=e("./webconn");var s=e("bittorrent-protocol");var o=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 s;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)});if(!r.sentHandshake)r.handshake();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)};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"))},o);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 s=t.wire;t.conn=null;t.swarm=null;t.wire=null;if(r&&s){var o=r.wires.indexOf(s);if(o>=0)r.wires.splice(o,1)}if(i)i.destroy();if(s)s.destroy();if(r)r.removePeer(t.id)}},{"./webconn":11,"bittorrent-protocol":12,debug:114}],11:[function(e,t,r){t.exports=u;var n=e("bitfield");var i=e("debug")("bittorrent-swarm:webconn");var s=e("simple-get");var o=e("inherits");var a=e("simple-sha1");var f=e("bittorrent-protocol");o(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 s=new n(i);for(var o=0;o<=i;o++){s.set(o,true)}r.bitfield(s)});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,s){i("request pieceIndex=%d offset=%d length=%d",e,t,n);r.httpRequest(e,t,n,s)})}u.prototype.httpRequest=function(e,t,r,n){var o=this;var a=e*o.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 h={url:o.url,method:"GET",headers:{"user-agent":"WebTorrent (http://webtorrent.io)",range:"bytes="+f+"-"+u}};s.concat(h,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:8,"bittorrent-protocol":12,debug:114,inherits:122,"simple-get":144,"simple-sha1":147}],12:[function(e,t,r){(function(r){t.exports=w;var n=e("bencode");var i=e("bitfield");var s=e("debug")("bittorrent-protocol");var o=e("xtend");var a=e("hat");var f=e("inherits");var u=e("speedometer");var h=e("stream");var l=4e5;var c=new r("BitTorrent protocol");var d=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 g=new r([0,0,0,1,2]);var v=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,h.Duplex);function w(){if(!(this instanceof w))return new w;h.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();h.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(d)};w.prototype.handshake=function(e,t,n){var i,s;if(typeof e==="string"){i=new r(e,"hex")}else{i=e;e=i.toString("hex")}if(typeof t==="string"){s=new r(t,"hex")}else{s=t;t=s.toString("hex")}if(i.length!==20||s.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 o=new r(y);o[5]|=16;if(n&&n.dht)o[7]|=1;this._push(r.concat([c,o,i,s]));this._handshakeSent=true;if(this.peerExtensions.extended){this._sendExtendedHandshake()}};w.prototype._sendExtendedHandshake=function(){var e=o(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))};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(g)};w.prototype.uninterested=function(){if(!this.amInterested)return;this.amInterested=false;this._debug("uninterested");this._push(v)};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(S(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 s=r.isBuffer(t)?t:n.encode(t);this._message(20,[],r.concat([i,s]))}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 s;for(s in this._ext){this._ext[s].onHandshake(n,i,r)}if(r.extended&&this._handshakeSent){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,s){if(i!==S(this.peerRequests,e,t,r))return;if(n)return;this.piece(e,t,s)}.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(S(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);S(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 s;if(typeof r.m==="object"){for(s in r.m){this.peerExtendedMapping[s]=Number(r.m[s].toString())}}for(s in this._ext){if(this.peerExtendedMapping[s]){this._ext[s].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 s=new r(5+4*t.length);s.writeUInt32BE(s.length+i-4,0);s[4]=e;for(var o=0;o<t.length;o++){s.writeUInt32BE(t[o],5+4*o)}this._push(s);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];s.apply(null,e)};function S(e,t,r,n){for(var i=0;i<e.length;i++){var s=e[i];if(s.piece!==t||s.offset!==r||s.length!==n)continue;if(i===0)e.shift();else e.splice(i,1);return s}return null}}).call(this,e("buffer").Buffer)},{bencode:13,bitfield:8,buffer:32,debug:114,hat:120,inherits:122,speedometer:149,stream:59,xtend:165}],13:[function(e,t,r){t.exports={encode:e("./lib/encode"),decode:e("./lib/decode")}},{"./lib/decode":14,"./lib/encode":16}],14:[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":15,buffer:32}],15:[function(e,t,r){var n=t.exports=function i(){Object.defineProperty(this,"_keys",{enumerable:false,value:[]})};n.prototype.binaryKeys=function s(){return this._keys.slice()};n.prototype.binarySet=function o(e,t){this._keys.push(e);this[e]=t}},{}],16:[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"),s=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 s=n/i<<0;var o=n%i<<0;var a=s*i+o;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 s=0;var o;var a=Object.keys(t).sort();var f=a.length;for(;s<f;s++){o=a[s];r.bytes(e,o);r._encode(e,t[o])}e.push(n)};r.list=function(e,t){var i=0,o=1;var a=t.length;e.push(s);for(;i<a;i++){r._encode(e,t[i])}e.push(n)};t.exports=r}).call(this,e("buffer").Buffer)},{buffer:32}],17:[function(e,t,r){(function(r,n){t.exports=m;var i=e("events").EventEmitter;var s=e("debug")("bittorrent-tracker");var o=e("inherits");var a=e("once");var f=e("run-parallel");var u=e("uniq");var h=e("url");var l=e("./lib/common");var c=e("./lib/client/http-tracker");var d=e("./lib/client/udp-tracker");var p=e("./lib/client/websocket-tracker");o(m,i);function m(e,t,o,a){var f=this;if(!(f instanceof m))return new m(e,t,o,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 o.infoHash==="string"?o.infoHash:o.infoHash.toString("hex");f.infoHashBuffer=new n(f.infoHash,"hex");f._infoHashBinary=f.infoHashBuffer.toString("binary");f.torrentLength=o.length;f.destroyed=false;f._port=t;f._rtcConfig=a.rtcConfig;f._wrtc=a.wrtc;s("new client %s",f.infoHash);var l=!!f._wrtc||typeof window!=="undefined";var g=typeof o.announce==="string"?[o.announce]:o.announce==null?[]:o.announce;g=g.map(function(e){e=e.toString();if(e[e.length-1]==="/"){e=e.substring(0,e.length-1)}return e});g=u(g);f._trackers=g.map(function(e){var t=h.parse(e).protocol;if((t==="http:"||t==="https:")&&typeof c==="function"){return new c(f,e)}else if(t==="udp:"&&typeof d==="function"){return new d(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 s=6881;var o={infoHash:Array.isArray(t)?t[0]:t,announce:[e]};var f=new m(i,s,o);f.once("error",r);var u=Array.isArray(t)?t.length:1;var h={};f.on("scrape",function(e){u-=1;h[e.infoHash]=e;if(u===0){f.destroy();var t=Object.keys(h);if(t.length===1){r(null,h[t[0]])}else{r(null,h)}}});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;s("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;s("send `stop`");e=t._defaultAnnounceOpts(e);e.event="stopped";t._announce(e)};m.prototype.complete=function(e){var t=this;s("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;s("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;s("send `scrape`");if(!e)e={};t._trackers.forEach(function(t){t.scrape(e)})};m.prototype.setInterval=function(e){var t=this;s("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;s("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":31,"./lib/client/udp-tracker":31,"./lib/client/websocket-tracker":19,"./lib/common":20,_process:41,buffer:32,debug:114,events:36,inherits:122,once:22,"run-parallel":143,uniq:152,url:66}],18:[function(e,t,r){t.exports=s;var n=e("events").EventEmitter;var i=e("inherits");i(s,n);function s(e,t){var r=this;n.call(r);r.client=e;r.announceUrl=t;r.interval=null;r.destroyed=false}s.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:36,inherits:122}],19:[function(e,t,r){t.exports=p;var n=e("debug")("bittorrent-tracker:websocket-tracker");var i=e("hat");var s=e("inherits");var o=e("simple-peer");var a=e("simple-websocket");var f=e("../common");var u=e("./tracker");var h={};var l=30*1e3;var c=5*1e3;var d=50*1e3;s(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);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",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=h[e.announceUrl];if(!e.socket){e.socket=h[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 s=e.interval||e["min interval"];if(s)t.setInterval(s*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 o({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 h=f.binaryToHex(e.offer_id);u=t.peers[h];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[h]=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)+c;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 s=[];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 o({initiator:true,trickle:false,config:r.client._rtcConfig,wrtc:r.client._wrtc});t.once("signal",function(t){s.push({offer:t,offer_id:f.hexToBinary(e)});h()});t.trackerTimeout=setTimeout(function(){n("tracker timeout: destroying peer");t.trackerTimeout=null;r.peers[e]=null;t.destroy()},d)}function h(){if(s.length===e){n("generated %s offers",e);t(s)}}};function m(){}},{"../common":20,"./tracker":18,debug:114,hat:120,inherits:122,"simple-peer":23,"simple-websocket":27}],20:[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":31,buffer:32,"xtend/mutable":166}],21:[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}}},{}],22:[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:21}],23:[function(e,t,r){(function(r){t.exports=l;var n=e("debug")("simple-peer");var i=e("get-browser-rtc");var s=e("hat");var o=e("inherits");var a=e("is-typedarray");var f=e("once");var u=e("stream");var h=e("typedarray-to-buffer");o(l,u.Duplex);function l(e){var t=this;if(!(t instanceof l))return new l(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||l.channelConfig;t.channelName=e.channelName||s(160);if(!e.initiator)t.channelName=null;t.config=e.config||l.config;t.constraints=e.constraints||l.constraints;t.reconnectTimer=e.reconnectTimer||0;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._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)})}})}l.WEBRTC_SUPPORT=!!i();l.config={iceServers:[{url:"stun:23.21.150.121",urls:"stun:23.21.150.121"}]};l.constraints={};l.channelConfig={};Object.defineProperty(l.prototype,"bufferSize",{get:function(){var e=this;return e._channel&&e._channel.bufferedAmount||0}});l.prototype.address=function(){var e=this;return{
-port:e.localPort,family:"IPv4",address:e.localAddress}};l.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),c,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"))}};l.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)&&!a.strict(e)){e=new Uint8Array(e)}var n=e.length||e.byteLength||e.size;t._channel.send(e);t._debug("write: %d bytes",n)};l.prototype.destroy=function(e){var t=this;t._destroy(null,e)};l.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")};l.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)};l.prototype._read=function(){};l.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}};l.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,c,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)};l.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,c,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)};l.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==="closed"){e._destroy()}};l.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"){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")}};l.prototype._onSignalingStateChange=function(){var e=this;if(e.destroyed)return;e._debug("signalingStateChange %s",e._pc.signalingState);e.emit("signalingStateChange",e._pc.signalingState)};l.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")}};l.prototype._onChannelMessage=function(e){var t=this;if(t.destroyed)return;var r=e.data;t._debug("read: %d bytes",r.byteLength||r.length);if(r instanceof ArrayBuffer){r=h(new Uint8Array(r));t.push(r)}else{try{r=JSON.parse(r)}catch(n){}t.emit("data",r)}};l.prototype._onChannelOpen=function(){var e=this;if(e.connected||e.destroyed)return;e._debug("on channel open");e._channelReady=true;e._maybeReady()};l.prototype._onChannelClose=function(){var e=this;if(e.destroyed)return;e._debug("on channel close");e._destroy()};l.prototype._onAddStream=function(e){var t=this;if(t.destroyed)return;t._debug("on add stream");t.emit("stream",e.stream)};l.prototype._onError=function(e){var t=this;if(t.destroyed)return;t._debug("error %s",e.message||e);t._destroy(e)};l.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 c(){}}).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":38,debug:114,"get-browser-rtc":24,hat:120,inherits:122,"is-typedarray":25,once:22,stream:59,"typedarray-to-buffer":26}],24:[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}},{}],25:[function(e,t,r){t.exports=s;s.strict=o;s.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 s(e){return o(e)||a(e)}function o(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)]}},{}],26:[function(e,t,r){(function(r){var n=e("is-typedarray").strict;t.exports=function(e){var t=r.TYPED_ARRAY_SUPPORT?r._augment:function(e){return new r(e)};if(e instanceof Uint8Array){return t(e)}else if(e instanceof ArrayBuffer){return t(new Uint8Array(e))}else if(n(e)){return t(new Uint8Array(e.buffer,e.byteOffset,e.byteLength))}else{return new r(e)}}}).call(this,e("buffer").Buffer)},{buffer:32,"is-typedarray":25}],27:[function(e,t,r){(function(r){t.exports=h;var n=e("debug")("simple-websocket");var i=e("inherits");var s=e("is-typedarray");var o=e("stream");var a=e("typedarray-to-buffer");var f=e("ws");var u=typeof window!=="undefined"?window.WebSocket:f;i(h,o.Duplex);function h(e,t){var r=this;if(!(r instanceof h))return new h(e,t);if(!t)t={};n("new websocket: %s %o",e,t);t.allowHalfOpen=false;if(t.highWaterMark==null)t.highWaterMark=1024*1024;o.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 u(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)})}})}h.WEBSOCKET_SUPPORT=!!u;h.prototype.send=function(e){var t=this;if(!s.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)};h.prototype.destroy=function(e){var t=this;t._destroy(null,e)};h.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 s=function(){i.onclose=null;r.emit("close")};if(i.readyState===u.CLOSED){s()}else{try{i.onclose=s;i.close()}catch(e){s()}}i.onopen=null;i.onmessage=null;i.onerror=null}r._ws=null;if(e)r.emit("error",e)};h.prototype._read=function(){};h.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(s){return i._onError(s)}if(typeof f!=="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}};h.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=a(new Uint8Array(i));t.push(i)}else if(r.isBuffer(i)){t.push(i)}else{try{i=JSON.parse(i)}catch(s){}t.emit("data",i)}};h.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 f!=="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")};h.prototype._onClose=function(){var e=this;if(e.destroyed)return;n("on close");e._destroy()};h.prototype._onError=function(e){var t=this;if(t.destroyed)return;n("error: %s",e.message||e);t._destroy(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":38,debug:114,inherits:122,"is-typedarray":28,stream:59,"typedarray-to-buffer":29,ws:31}],28:[function(e,t,r){arguments[4][25][0].apply(r,arguments)},{dup:25}],29:[function(e,t,r){arguments[4][26][0].apply(r,arguments)},{buffer:32,dup:26,"is-typedarray":28}],30:[function(e,t,r){},{}],31:[function(e,t,r){arguments[4][30][0].apply(r,arguments)},{dup:30}],32:[function(e,t,r){(function(t){var n=e("base64-js");var i=e("ieee754");var s=e("isarray");r.Buffer=u;r.SlowBuffer=w;r.INSPECT_MAX_BYTES=50;u.poolSize=8192;var o={};u.TYPED_ARRAY_SUPPORT=t.TYPED_ARRAY_SUPPORT!==undefined?t.TYPED_ARRAY_SUPPORT:a();function a(){function e(){}try{var t=new Uint8Array(1);t.foo=function(){return 42};t.constructor=e;return t.foo()===42&&t.constructor===e&&typeof t.subarray==="function"&&t.subarray(1,1).byteLength===0}catch(r){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)}this.length=0;this.parent=undefined;if(typeof e==="number"){return h(this,e)}if(typeof e==="string"){return l(this,e,arguments.length>1?arguments[1]:"utf8")}return c(this,e)}function h(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=S(t,r)|0;e=_(e,n);e.write(t,r);return e}function c(e,t){if(u.isBuffer(t))return d(e,t);if(s(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 g(e,t)}}if(t.length)return v(e,t);return y(e,t)}function d(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 g(e,t){if(u.TYPED_ARRAY_SUPPORT){t.byteLength;e=u._augment(new Uint8Array(t))}else{e=m(e,new Uint8Array(t))}return e}function v(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"&&s(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}function _(e,t){if(u.TYPED_ARRAY_SUPPORT){e=u._augment(new Uint8Array(t));e.__proto__=u.prototype}else{e.length=t;e._isBuffer=true}var r=t!==0&&t<=u.poolSize>>>1;if(r)e.parent=o;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 te(e){return!!(e!=null&&e._isBuffer)};u.compare=function re(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 s=Math.min(r,n);while(i<s){if(e[i]!==t[i])break;++i}if(i!==s){r=e[i];n=t[i]}if(r<n)return-1;if(n<r)return 1;return 0};u.isEncoding=function ne(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 ie(e,t){if(!s(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 o=e[r];o.copy(n,i);i+=o.length}return n};function S(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 Z(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Q(e).length;default:if(n)return Z(e).length;t=(""+t).toLowerCase();n=true}}}u.byteLength=S;u.prototype.length=undefined;u.prototype.parent=undefined;function x(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 O(this,t,r);case"utf8":case"utf-8":return L(this,t,r);case"ascii":return P(this,t,r);case"binary":return F(this,t,r);case"base64":return B(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return D(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase();n=true}}}u.prototype.toString=function se(){var e=this.length|0;if(e===0)return"";if(arguments.length===0)return L(this,0,e);return x.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 ae(){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 fe(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 ue(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")};u.prototype.get=function he(e){console.log(".get() is deprecated. Access using array indexes instead.");return this.readUInt8(e)};u.prototype.set=function le(e,t){console.log(".set() is deprecated. Access using array indexes instead.");return this.writeUInt8(e,t)};function k(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 s=t.length;if(s%2!==0)throw new Error("Invalid hex string");if(n>s/2){n=s/2}for(var o=0;o<n;o++){var a=parseInt(t.substr(o*2,2),16);if(isNaN(a))throw new Error("Invalid hex string");e[r+o]=a}return o}function E(e,t,r,n){return ee(Z(t,e.length-r),e,r,n)}function A(e,t,r,n){return ee(X(t),e,r,n)}function U(e,t,r,n){return A(e,t,r,n)}function I(e,t,r,n){return ee(Q(t),e,r,n)}function T(e,t,r,n){return ee(J(t,e.length-r),e,r,n)}u.prototype.write=function ce(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 s=this.length-t;if(r===undefined||r>s)r=s;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 o=false;for(;;){switch(n){case"hex":return k(this,e,t,r);case"utf8":case"utf-8":return E(this,e,t,r);case"ascii":return A(this,e,t,r);case"binary":return U(this,e,t,r);case"base64":return I(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase();o=true}}};u.prototype.toJSON=function de(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function B(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 s=e[i];var o=null;var a=s>239?4:s>223?3:s>191?2:1;if(i+a<=r){var f,u,h,l;switch(a){case 1:if(s<128){o=s}break;case 2:f=e[i+1];if((f&192)===128){l=(s&31)<<6|f&63;if(l>127){o=l}}break;case 3:f=e[i+1];u=e[i+2];if((f&192)===128&&(u&192)===128){l=(s&15)<<12|(f&63)<<6|u&63;if(l>2047&&(l<55296||l>57343)){o=l}}break;case 4:f=e[i+1];u=e[i+2];h=e[i+3];if((f&192)===128&&(u&192)===128&&(h&192)===128){l=(s&15)<<18|(f&63)<<12|(u&63)<<6|h&63;if(l>65535&&l<1114112){o=l}}}}if(o===null){o=65533;a=1}else if(o>65535){o-=65536;n.push(o>>>10&1023|55296);o=56320|o&1023}n.push(o);i+=a}return R(n)}var C=4096;function R(e){var t=e.length;if(t<=C){return String.fromCharCode.apply(String,e)}var r="";var n=0;while(n<t){r+=String.fromCharCode.apply(String,e.slice(n,n+=C))}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 F(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 O(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 s=t;s<r;s++){i+=$(e[s])}return i}function D(e,t,r){var n=e.slice(t,r);var i="";for(var s=0;s<n.length;s+=2){i+=String.fromCharCode(n[s]+n[s+1]*256)}return i}u.prototype.slice=function pe(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=u._augment(this.subarray(e,t))}else{var i=t-e;n=new u(i,undefined);for(var s=0;s<i;s++){n[s]=this[s+e]}}if(n.length)n.parent=this.parent||this;return n};function M(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 me(e,t,r){e=e|0;t=t|0;if(!r)M(e,t,this.length);var n=this[e];var i=1;var s=0;while(++s<t&&(i*=256)){n+=this[e+s]*i}return n};u.prototype.readUIntBE=function ge(e,t,r){e=e|0;t=t|0;if(!r){M(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 ve(e,t){if(!t)M(e,1,this.length);return this[e]};u.prototype.readUInt16LE=function ye(e,t){if(!t)M(e,2,this.length);return this[e]|this[e+1]<<8};u.prototype.readUInt16BE=function _e(e,t){if(!t)M(e,2,this.length);return this[e]<<8|this[e+1]};u.prototype.readUInt32LE=function be(e,t){if(!t)M(e,4,this.length);return(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};u.prototype.readUInt32BE=function we(e,t){if(!t)M(e,4,this.length);return this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};u.prototype.readIntLE=function Se(e,t,r){e=e|0;t=t|0;if(!r)M(e,t,this.length);var n=this[e];var i=1;var s=0;while(++s<t&&(i*=256)){n+=this[e+s]*i}i*=128;if(n>=i)n-=Math.pow(2,8*t);return n};u.prototype.readIntBE=function xe(e,t,r){e=e|0;t=t|0;if(!r)M(e,t,this.length);var n=t;var i=1;var s=this[e+--n];while(n>0&&(i*=256)){s+=this[e+--n]*i}i*=128;if(s>=i)s-=Math.pow(2,8*t);return s};u.prototype.readInt8=function ke(e,t){if(!t)M(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)M(e,2,this.length);var r=this[e]|this[e+1]<<8;return r&32768?r|4294901760:r};u.prototype.readInt16BE=function Ae(e,t){if(!t)M(e,2,this.length);var r=this[e+1]|this[e]<<8;return r&32768?r|4294901760:r};u.prototype.readInt32LE=function Ue(e,t){if(!t)M(e,4,this.length);return this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};u.prototype.readInt32BE=function Ie(e,t){if(!t)M(e,4,this.length);return this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};u.prototype.readFloatLE=function Te(e,t){if(!t)M(e,4,this.length);return i.read(this,e,true,23,4)};u.prototype.readFloatBE=function Be(e,t){if(!t)M(e,4,this.length);return i.read(this,e,false,23,4)};u.prototype.readDoubleLE=function Le(e,t){if(!t)M(e,8,this.length);return i.read(this,e,true,52,8)};u.prototype.readDoubleBE=function Ce(e,t){if(!t)M(e,8,this.length);return i.read(this,e,false,52,8)};function N(e,t,r,n,i,s){if(!u.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");if(t>i||t<s)throw new RangeError("value is out of bounds");if(r+n>e.length)throw new RangeError("index out of range")}u.prototype.writeUIntLE=function Re(e,t,r,n){e=+e;t=t|0;r=r|0;if(!n)N(this,e,t,r,Math.pow(2,8*r),0);var i=1;var s=0;this[t]=e&255;while(++s<r&&(i*=256)){this[t+s]=e/i&255}return t+r};u.prototype.writeUIntBE=function Pe(e,t,r,n){e=+e;t=t|0;r=r|0;if(!n)N(this,e,t,r,Math.pow(2,8*r),0);var i=r-1;var s=1;this[t+i]=e&255;while(--i>=0&&(s*=256)){this[t+i]=e/s&255}return t+r};u.prototype.writeUInt8=function Fe(e,t,r){e=+e;t=t|0;if(!r)N(this,e,t,1,255,0);if(!u.TYPED_ARRAY_SUPPORT)e=Math.floor(e);this[t]=e&255;return t+1};function z(e,t,r,n){if(t<0)t=65535+t+1;for(var i=0,s=Math.min(e.length-r,2);i<s;i++){e[r+i]=(t&255<<8*(n?i:1-i))>>>(n?i:1-i)*8}}u.prototype.writeUInt16LE=function Oe(e,t,r){e=+e;t=t|0;if(!r)N(this,e,t,2,65535,0);if(u.TYPED_ARRAY_SUPPORT){this[t]=e&255;this[t+1]=e>>>8}else{z(this,e,t,true)}return t+2};u.prototype.writeUInt16BE=function De(e,t,r){e=+e;t=t|0;if(!r)N(this,e,t,2,65535,0);if(u.TYPED_ARRAY_SUPPORT){this[t]=e>>>8;this[t+1]=e&255}else{z(this,e,t,false)}return t+2};function j(e,t,r,n){if(t<0)t=4294967295+t+1;for(var i=0,s=Math.min(e.length-r,4);i<s;i++){e[r+i]=t>>>(n?i:3-i)*8&255}}u.prototype.writeUInt32LE=function Me(e,t,r){e=+e;t=t|0;if(!r)N(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{j(this,e,t,true)}return t+4};u.prototype.writeUInt32BE=function Ne(e,t,r){e=+e;t=t|0;if(!r)N(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{j(this,e,t,false)}return t+4};u.prototype.writeIntLE=function ze(e,t,r,n){e=+e;t=t|0;if(!n){var i=Math.pow(2,8*r-1);N(this,e,t,r,i-1,-i)}var s=0;var o=1;var a=e<0?1:0;this[t]=e&255;while(++s<r&&(o*=256)){this[t+s]=(e/o>>0)-a&255}return t+r};u.prototype.writeIntBE=function je(e,t,r,n){e=+e;t=t|0;if(!n){var i=Math.pow(2,8*r-1);N(this,e,t,r,i-1,-i)}var s=r-1;var o=1;var a=e<0?1:0;this[t+s]=e&255;while(--s>=0&&(o*=256)){this[t+s]=(e/o>>0)-a&255}return t+r};u.prototype.writeInt8=function He(e,t,r){e=+e;t=t|0;if(!r)N(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 qe(e,t,r){e=+e;t=t|0;if(!r)N(this,e,t,2,32767,-32768);if(u.TYPED_ARRAY_SUPPORT){this[t]=e&255;this[t+1]=e>>>8}else{z(this,e,t,true)}return t+2};u.prototype.writeInt16BE=function Ge(e,t,r){e=+e;t=t|0;if(!r)N(this,e,t,2,32767,-32768);if(u.TYPED_ARRAY_SUPPORT){this[t]=e>>>8;this[t+1]=e&255}else{z(this,e,t,false)}return t+2};u.prototype.writeInt32LE=function We(e,t,r){e=+e;t=t|0;if(!r)N(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{j(this,e,t,true)}return t+4};u.prototype.writeInt32BE=function Ye(e,t,r){e=+e;t=t|0;if(!r)N(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{j(this,e,t,false)}return t+4};function H(e,t,r,n,i,s){if(t>i||t<s)throw new RangeError("value is out of bounds");if(r+n>e.length)throw new RangeError("index out of range");if(r<0)throw new RangeError("index out of range")}function q(e,t,r,n,s){if(!s){H(e,t,r,4,3.4028234663852886e38,-3.4028234663852886e38)}i.write(e,t,r,n,23,4);return r+4}u.prototype.writeFloatLE=function Ve(e,t,r){return q(this,e,t,true,r)};u.prototype.writeFloatBE=function Ke(e,t,r){return q(this,e,t,false,r)};function G(e,t,r,n,s){if(!s){H(e,t,r,8,1.7976931348623157e308,-1.7976931348623157e308)}i.write(e,t,r,n,52,8);return r+8}u.prototype.writeDoubleLE=function $e(e,t,r){return G(this,e,t,true,r)};u.prototype.writeDoubleBE=function Ze(e,t,r){return G(this,e,t,false,r)};u.prototype.copy=function Xe(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 s;if(this===e&&r<t&&t<n){for(s=i-1;s>=0;s--){e[s+t]=this[s+r]}}else if(i<1e3||!u.TYPED_ARRAY_SUPPORT){for(s=0;s<i;s++){e[s+t]=this[s+r]}}else{e._set(this.subarray(r,r+i),t)}return i};u.prototype.fill=function Je(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=Z(e.toString());var s=i.length;for(n=t;n<r;n++){this[n]=i[n%s]}}return this};u.prototype.toArrayBuffer=function Qe(){if(typeof Uint8Array!=="undefined"){if(u.TYPED_ARRAY_SUPPORT){return new u(this).buffer}else{var e=new Uint8Array(this.length);for(var t=0,r=e.length;t<r;t+=1){e[t]=this[t]}return e.buffer}}else{throw new TypeError("Buffer.toArrayBuffer not supported in this browser")}};var W=u.prototype;u._augment=function et(e){e.constructor=u;e._isBuffer=true;e._set=e.set;e.get=W.get;e.set=W.set;e.write=W.write;e.toString=W.toString;e.toLocaleString=W.toString;e.toJSON=W.toJSON;e.equals=W.equals;e.compare=W.compare;e.indexOf=W.indexOf;e.copy=W.copy;e.slice=W.slice;e.readUIntLE=W.readUIntLE;e.readUIntBE=W.readUIntBE;e.readUInt8=W.readUInt8;e.readUInt16LE=W.readUInt16LE;e.readUInt16BE=W.readUInt16BE;e.readUInt32LE=W.readUInt32LE;e.readUInt32BE=W.readUInt32BE;e.readIntLE=W.readIntLE;e.readIntBE=W.readIntBE;e.readInt8=W.readInt8;e.readInt16LE=W.readInt16LE;e.readInt16BE=W.readInt16BE;e.readInt32LE=W.readInt32LE;e.readInt32BE=W.readInt32BE;e.readFloatLE=W.readFloatLE;e.readFloatBE=W.readFloatBE;e.readDoubleLE=W.readDoubleLE;e.readDoubleBE=W.readDoubleBE;e.writeUInt8=W.writeUInt8;e.writeUIntLE=W.writeUIntLE;e.writeUIntBE=W.writeUIntBE;e.writeUInt16LE=W.writeUInt16LE;e.writeUInt16BE=W.writeUInt16BE;e.writeUInt32LE=W.writeUInt32LE;e.writeUInt32BE=W.writeUInt32BE;e.writeIntLE=W.writeIntLE;e.writeIntBE=W.writeIntBE;e.writeInt8=W.writeInt8;e.writeInt16LE=W.writeInt16LE;e.writeInt16BE=W.writeInt16BE;e.writeInt32LE=W.writeInt32LE;e.writeInt32BE=W.writeInt32BE;e.writeFloatLE=W.writeFloatLE;e.writeFloatBE=W.writeFloatBE;e.writeDoubleLE=W.writeDoubleLE;e.writeDoubleBE=W.writeDoubleBE;e.fill=W.fill;e.inspect=W.inspect;e.toArrayBuffer=W.toArrayBuffer;return e};var Y=/[^+\/0-9A-Za-z-_]/g;function V(e){e=K(e).replace(Y,"");if(e.length<2)return"";while(e.length%4!==0){e=e+"="}return e}function K(e){if(e.trim)return e.trim();return e.replace(/^\s+|\s+$/g,"")}function $(e){if(e<16)return"0"+e.toString(16);return e.toString(16)}function Z(e,t){t=t||Infinity;var r;var n=e.length;var i=null;var s=[];for(var o=0;o<n;o++){r=e.charCodeAt(o);if(r>55295&&r<57344){if(!i){if(r>56319){if((t-=3)>-1)s.push(239,191,189);continue}else if(o+1===n){if((t-=3)>-1)s.push(239,191,189);continue}i=r;continue}if(r<56320){if((t-=3)>-1)s.push(239,191,189);i=r;continue}r=(i-55296<<10|r-56320)+65536}else if(i){if((t-=3)>-1)s.push(239,191,189)}i=null;if(r<128){if((t-=1)<0)break;s.push(r)}else if(r<2048){if((t-=2)<0)break;s.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;s.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else{throw new Error("Invalid code point")}}return s}function X(e){var t=[];for(var r=0;r<e.length;r++){t.push(e.charCodeAt(r)&255);
-}return t}function J(e,t){var r,n,i;var s=[];for(var o=0;o<e.length;o++){if((t-=2)<0)break;r=e.charCodeAt(o);n=r>>8;i=r%256;s.push(i);s.push(n)}return s}function Q(e){return n.toByteArray(V(e))}function ee(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":33,ieee754:34,isarray:35}],33:[function(e,t,r){var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";(function(e){"use strict";var t=typeof Uint8Array!=="undefined"?Uint8Array:Array;var r="+".charCodeAt(0);var i="/".charCodeAt(0);var s="0".charCodeAt(0);var o="a".charCodeAt(0);var a="A".charCodeAt(0);var f="-".charCodeAt(0);var u="_".charCodeAt(0);function h(e){var t=e.charCodeAt(0);if(t===r||t===f)return 62;if(t===i||t===u)return 63;if(t<s)return-1;if(t<s+10)return t-s+26+26;if(t<a+26)return t-a;if(t<o+26)return t-o+26}function l(e){var r,n,i,s,o,a;if(e.length%4>0){throw new Error("Invalid string. Length must be a multiple of 4")}var f=e.length;o="="===e.charAt(f-2)?2:"="===e.charAt(f-1)?1:0;a=new t(e.length*3/4-o);i=o>0?e.length-4:e.length;var u=0;function l(e){a[u++]=e}for(r=0,n=0;r<i;r+=4,n+=3){s=h(e.charAt(r))<<18|h(e.charAt(r+1))<<12|h(e.charAt(r+2))<<6|h(e.charAt(r+3));l((s&16711680)>>16);l((s&65280)>>8);l(s&255)}if(o===2){s=h(e.charAt(r))<<2|h(e.charAt(r+1))>>4;l(s&255)}else if(o===1){s=h(e.charAt(r))<<10|h(e.charAt(r+1))<<4|h(e.charAt(r+2))>>2;l(s>>8&255);l(s&255)}return a}function c(e){var t,r=e.length%3,i="",s,o;function a(e){return n.charAt(e)}function f(e){return a(e>>18&63)+a(e>>12&63)+a(e>>6&63)+a(e&63)}for(t=0,o=e.length-r;t<o;t+=3){s=(e[t]<<16)+(e[t+1]<<8)+e[t+2];i+=f(s)}switch(r){case 1:s=e[e.length-1];i+=a(s>>2);i+=a(s<<4&63);i+="==";break;case 2:s=(e[e.length-2]<<8)+e[e.length-1];i+=a(s>>10);i+=a(s>>4&63);i+=a(s<<2&63);i+="=";break}return i}e.toByteArray=l;e.fromByteArray=c})(typeof r==="undefined"?this.base64js={}:r)},{}],34:[function(e,t,r){r.read=function(e,t,r,n,i){var s,o;var a=i*8-n-1;var f=(1<<a)-1;var u=f>>1;var h=-7;var l=r?i-1:0;var c=r?-1:1;var d=e[t+l];l+=c;s=d&(1<<-h)-1;d>>=-h;h+=a;for(;h>0;s=s*256+e[t+l],l+=c,h-=8){}o=s&(1<<-h)-1;s>>=-h;h+=n;for(;h>0;o=o*256+e[t+l],l+=c,h-=8){}if(s===0){s=1-u}else if(s===f){return o?NaN:(d?-1:1)*Infinity}else{o=o+Math.pow(2,n);s=s-u}return(d?-1:1)*o*Math.pow(2,s-n)};r.write=function(e,t,r,n,i,s){var o,a,f;var u=s*8-i-1;var h=(1<<u)-1;var l=h>>1;var c=i===23?Math.pow(2,-24)-Math.pow(2,-77):0;var d=n?0:s-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;o=h}else{o=Math.floor(Math.log(t)/Math.LN2);if(t*(f=Math.pow(2,-o))<1){o--;f*=2}if(o+l>=1){t+=c/f}else{t+=c*Math.pow(2,1-l)}if(t*f>=2){o++;f/=2}if(o+l>=h){a=0;o=h}else if(o+l>=1){a=(t*f-1)*Math.pow(2,i);o=o+l}else{a=t*Math.pow(2,l-1)*Math.pow(2,i);o=0}}for(;i>=8;e[r+d]=a&255,d+=p,a/=256,i-=8){}o=o<<i|a;u+=i;for(;u>0;e[r+d]=o&255,d+=p,o/=256,u-=8){}e[r+d-p]|=m*128}},{}],35:[function(e,t,r){var n={}.toString;t.exports=Array.isArray||function(e){return n.call(e)=="[object Array]"}},{}],36:[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(!s(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,s,f,u;if(!this._events)this._events={};if(e==="error"){if(!this._events.error||o(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:s=Array.prototype.slice.call(arguments,1);r.apply(this,s)}}else if(o(r)){s=Array.prototype.slice.call(arguments,1);u=r.slice();n=u.length;for(f=0;f<n;f++)u[f].apply(this,s)}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(o(this._events[e]))this._events[e].push(t);else this._events[e]=[this._events[e],t];if(o(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,s,a;if(!i(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;r=this._events[e];s=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(o(r)){for(a=s;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 s(e){return typeof e==="number"}function o(e){return typeof e==="object"&&e!==null}function a(e){return e===void 0}},{}],37:[function(e,t,r){var n=e("http");var i=t.exports;for(var s in n){if(n.hasOwnProperty(s))i[s]=n[s]}i.request=function(e,t){if(!e)e={};e.scheme="https";e.protocol="https:";return n.request.call(this,e,t)}},{http:60}],38:[function(e,t,r){t.exports=function(e){return!!(e!=null&&(e._isBuffer||e.constructor&&typeof e.constructor.isBuffer==="function"&&e.constructor.isBuffer(e)))}},{}],39:[function(e,t,r){t.exports=Array.isArray||function(e){return Object.prototype.toString.call(e)=="[object Array]"}},{}],40:[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 o=i>=0?arguments[i]:e.cwd();if(typeof o!=="string"){throw new TypeError("Arguments to path.resolve must be strings")}else if(!o){continue}r=o+"/"+r;n=o.charAt(0)==="/"}r=t(s(r.split("/"),function(e){return!!e}),!n).join("/");return(n?"/":"")+r||"."};r.normalize=function(e){var n=r.isAbsolute(e),i=o(e,-1)==="/";e=t(s(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(s(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 s=n(t.split("/"));var o=Math.min(i.length,s.length);var a=o;for(var f=0;f<o;f++){if(i[f]!==s[f]){a=f;break}}var u=[];for(var f=a;f<i.length;f++){u.push("..")}u=u.concat(s.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 s(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 o="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:41}],41:[function(e,t,r){var n=t.exports={};var i=[];var s=false;var o;var a=-1;function f(){s=false;if(o.length){i=o.concat(i)}else{a=-1}if(i.length){u()}}function u(){if(s){return}var e=setTimeout(f);s=true;var t=i.length;while(t){o=i;i=[];while(++a<t){if(o){o[a].run()}}a=-1;t=i.length}o=null;s=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 h(e,t));if(i.length===1&&!s){setTimeout(u,0)}};function h(e,t){this.fun=e;this.array=t}h.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}},{}],42:[function(t,r,n){(function(t){(function(i){var s=typeof n=="object"&&n&&!n.nodeType&&n;var o=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,h=36,l=1,c=26,d=38,p=700,m=72,g=128,v="-",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"},S=h-l,x=Math.floor,k=String.fromCharCode,E;function A(e){throw new RangeError(w[e])}function U(e,t){var r=e.length;var n=[];while(r--){n[r]=t(e[r])}return n}function I(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 s=U(i,t).join(".");return n+s}function T(e){var t=[],r=0,n=e.length,i,s;while(r<n){i=e.charCodeAt(r++);if(i>=55296&&i<=56319&&r<n){s=e.charCodeAt(r++);if((s&64512)==56320){t.push(((i&1023)<<10)+(s&1023)+65536)}else{t.push(i);r--}}else{t.push(i)}}return t}function B(e){return U(e,function(e){var t="";if(e>65535){e-=65536;t+=k(e>>>10&1023|55296);e=56320|e&1023}t+=k(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 h}function C(e,t){return e+22+75*(e<26)-((t!=0)<<5)}function R(e,t,r){var n=0;e=r?x(e/p):e>>1;e+=x(e/t);for(;e>S*c>>1;n+=h){e=x(e/S)}return x(n+(S+1)*e/(e+d))}function P(e){var t=[],r=e.length,n,i=0,s=g,o=m,a,f,d,p,y,_,b,w,S;a=e.lastIndexOf(v);if(a<0){a=0}for(f=0;f<a;++f){if(e.charCodeAt(f)>=128){A("not-basic")}t.push(e.charCodeAt(f))}for(d=a>0?a+1:0;d<r;){for(p=i,y=1,_=h;;_+=h){if(d>=r){A("invalid-input")}b=L(e.charCodeAt(d++));if(b>=h||b>x((u-i)/y)){A("overflow")}i+=b*y;w=_<=o?l:_>=o+c?c:_-o;if(b<w){break}S=h-w;if(y>x(u/S)){A("overflow")}y*=S}n=t.length+1;o=R(i-p,n,p==0);if(x(i/n)>u-s){A("overflow")}s+=x(i/n);i%=n;t.splice(i++,0,s)}return B(t)}function F(e){var t,r,n,i,s,o,a,f,d,p,y,_=[],b,w,S,E;e=T(e);b=e.length;t=g;r=0;s=m;for(o=0;o<b;++o){y=e[o];if(y<128){_.push(k(y))}}n=i=_.length;if(i){_.push(v)}while(n<b){for(a=u,o=0;o<b;++o){y=e[o];if(y>=t&&y<a){a=y}}w=n+1;if(a-t>x((u-r)/w)){A("overflow")}r+=(a-t)*w;t=a;for(o=0;o<b;++o){y=e[o];if(y<t&&++r>u){A("overflow")}if(y==t){for(f=r,d=h;;d+=h){p=d<=s?l:d>=s+c?c:d-s;if(f<p){break}E=f-p;S=h-p;_.push(k(C(p+E%S,0)));f=x(E/S)}_.push(k(C(f,0)));s=R(r,w,n==i);r=0;++n}}++r;++t}return _.join("")}function O(e){return I(e,function(e){return y.test(e)?P(e.slice(4).toLowerCase()):e})}function D(e){return I(e,function(e){return _.test(e)?"xn--"+F(e):e})}f={version:"1.3.2",ucs2:{decode:T,encode:B},decode:P,encode:F,toASCII:D,toUnicode:O};if(typeof e=="function"&&typeof e.amd=="object"&&e.amd){e("punycode",function(){return f})}else if(s&&o){if(r.exports==s){o.exports=f}else{for(E in f){f.hasOwnProperty(E)&&(s[E]=f[E])}}}else{i.punycode=f}})(this)}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],43:[function(e,t,r){"use strict";function n(e,t){return Object.prototype.hasOwnProperty.call(e,t)}t.exports=function(e,t,r,s){t=t||"&";r=r||"=";var o={};if(typeof e!=="string"||e.length===0){return o}var a=/\+/g;e=e.split(t);var f=1e3;if(s&&typeof s.maxKeys==="number"){f=s.maxKeys}var u=e.length;if(f>0&&u>f){u=f}for(var h=0;h<u;++h){var l=e[h].replace(a,"%20"),c=l.indexOf(r),d,p,m,g;if(c>=0){d=l.substr(0,c);p=l.substr(c+1)}else{d=l;p=""}m=decodeURIComponent(d);g=decodeURIComponent(p);if(!n(o,m)){o[m]=g}else if(i(o[m])){o[m].push(g)}else{o[m]=[o[m],g]}}return o};var i=Array.isArray||function(e){return Object.prototype.toString.call(e)==="[object Array]"}},{}],44:[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 s(o(e),function(o){var a=encodeURIComponent(n(o))+r;if(i(e[o])){return s(e[o],function(e){return a+encodeURIComponent(n(e))}).join(t)}else{return a+encodeURIComponent(n(e[o]))}}).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 s(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 o=Object.keys||function(e){var t=[];for(var r in e){if(Object.prototype.hasOwnProperty.call(e,r))t.push(r)}return t}},{}],45:[function(e,t,r){"use strict";r.decode=r.parse=e("./decode");r.encode=r.stringify=e("./encode")},{"./decode":43,"./encode":44}],46:[function(e,t,r){t.exports=e("./lib/_stream_duplex.js")},{"./lib/_stream_duplex.js":47}],47:[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 s=e("core-util-is");s.inherits=e("inherits");var o=e("./_stream_readable");var a=e("./_stream_writable");s.inherits(l,o);var f=n(a.prototype);for(var u=0;u<f.length;u++){var h=f[u];if(!l.prototype[h])l.prototype[h]=a.prototype[h]}function l(e){if(!(this instanceof l))return new l(e);o.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",c)}function c(){if(this.allowHalfOpen||this._writableState.ended)return;i(d,this)}function d(e){e.end()}function p(e,t){for(var r=0,n=e.length;r<n;r++){t(e[r],r)}}},{"./_stream_readable":49,"./_stream_writable":51,"core-util-is":52,inherits:122,"process-nextick-args":53}],48:[function(e,t,r){"use strict";t.exports=s;var n=e("./_stream_transform");var i=e("core-util-is");i.inherits=e("inherits");i.inherits(s,n);function s(e){if(!(this instanceof s))return new s(e);n.call(this,e)}s.prototype._transform=function(e,t,r){r(null,e)}},{"./_stream_transform":50,"core-util-is":52,inherits:122}],49:[function(e,t,r){(function(r){"use strict";t.exports=m;var n=e("process-nextick-args");var i=e("isarray");var s=e("buffer").Buffer;m.ReadableState=p;var o=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 s=e("buffer").Buffer;var u=e("core-util-is");u.inherits=e("inherits");var h=e("util");var l;if(h&&h.debuglog){l=h.debuglog("stream")}else{l=function(){}}var c;u.inherits(m,f);var d;function p(t,r){d=d||e("./_stream_duplex");t=t||{};this.objectMode=!!t.objectMode;if(r instanceof d)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(!c)c=e("string_decoder/").StringDecoder;this.decoder=new c(t.encoding);this.encoding=t.encoding}}var d;function m(t){d=d||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 s(e,t);t=""}}return g(this,r,e,t,false)};m.prototype.unshift=function(e){var t=this._readableState;return g(this,t,e,"",true)};m.prototype.isPaused=function(){return this._readableState.flowing===false};function g(e,t,r,n,i){var s=w(t,r);if(s){e.emit("error",s)}else if(r===null){t.reading=false;S(e,t)}else if(t.objectMode||r&&r.length>0){if(t.ended&&!i){var o=new Error("stream.push() after EOF");e.emit("error",o)}else if(t.endEmitted&&i){var o=new Error("stream.unshift() after end event");e.emit("error",o)}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)x(e)}E(e,t)}}else if(!i){t.reading=false}return v(t)}function v(e){return!e.ended&&(e.needReadable||e.length<e.highWaterMark||e.length===0)}m.prototype.setEncoding=function(t){if(!c)c=e("string_decoder/").StringDecoder;this._readableState.decoder=new c(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)R(this);else x(this);return null}e=b(e,t);if(e===0&&t.ended){if(t.length===0)R(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=C(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)R(this);if(i!==null)this.emit("data",i);return i};function w(e,t){var r=null;if(!s.isBuffer(t)&&typeof t!=="string"&&t!==null&&t!==undefined&&!e.objectMode){r=new TypeError("Invalid non-string/buffer chunk")}return r}function S(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;x(e)}function x(e){var t=e._readableState;t.needReadable=false;if(!t.emittedReadable){l("emitReadable",t.flowing);t.emittedReadable=true;if(t.sync)n(k,e);else k(e)}}function k(e){l("emit readable");e.emit("readable");L(e)}function E(e,t){if(!t.readingMore){t.readingMore=true;n(A,e,t)}}function A(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 s=this;var o=this._readableState;switch(o.pipesCount){case 0:o.pipes=e;break;case 1:o.pipes=[o.pipes,e];break;default:o.pipes.push(e);break}o.pipesCount+=1;l("pipe count=%d opts=%j",o.pipesCount,t);var f=(!t||t.end!==false)&&e!==r.stdout&&e!==r.stderr;var u=f?c:m;if(o.endEmitted)n(u);else s.once("end",u);e.on("unpipe",h);function h(e){l("onunpipe");if(e===s){m()}}function c(){l("onend");e.end()}var d=U(s);e.on("drain",d);var p=false;function m(){l("cleanup");e.removeListener("close",y);e.removeListener("finish",_);e.removeListener("drain",d);e.removeListener("error",v);e.removeListener("unpipe",h);s.removeListener("end",c);s.removeListener("end",m);s.removeListener("data",g);p=true;if(o.awaitDrain&&(!e._writableState||e._writableState.needDrain))d()}s.on("data",g);function g(t){l("ondata");var r=e.write(t);if(false===r){if(o.pipesCount===1&&o.pipes[0]===e&&s.listenerCount("data")===1&&!p){l("false write response, pause",s._readableState.awaitDrain);s._readableState.awaitDrain++}s.pause()}}function v(t){l("onerror",t);b();e.removeListener("error",v);if(a(e,"error")===0)e.emit("error",t)}if(!e._events||!e._events.error)e.on("error",v);else if(i(e._events.error))e._events.error.unshift(v);else e._events.error=[v,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");s.unpipe(e)}e.emit("pipe",s);if(!o.flowing){l("pipe resume");s.resume()}return e};function U(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=O(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(I,this)}else if(i.length){x(this,i)}}}return r};m.prototype.addListener=m.prototype.on;function I(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;T(this,e)}return this};function T(e,t){if(!t.resumeScheduled){t.resumeScheduled=true;n(B,e,t)}}function B(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 s=n.push(i);if(!s){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 s=["error","close","destroy","pause","resume"];F(s,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=C;function C(e,t){var r=t.buffer;var n=t.length;var i=!!t.decoder;var o=!!t.objectMode;var a;if(r.length===0)return null;if(n===0)a=null;else if(o)a=r.shift();else if(!e||e>=n){if(i)a=r.join("");else if(r.length===1)a=r[0];else a=s.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 s(e);var u=0;for(var h=0,l=r.length;h<l&&u<e;h++){var f=r[0];var c=Math.min(e-u,f.length);if(i)a+=f.slice(0,c);else f.copy(a,u,0,c);if(c<f.length)r[0]=f.slice(c);else r.shift();u+=c}}}return a}function R(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 F(e,t){for(var r=0,n=e.length;r<n;r++){t(e[r],r)}}function O(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":47,_process:41,buffer:32,"core-util-is":52,events:36,inherits:122,isarray:39,"process-nextick-args":53,"string_decoder/":65,util:31}],50:[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 s(e){this.afterTransform=function(t,r){return o(e,t,r)};this.needTransform=false;this.transforming=false;this.writecb=null;this.writechunk=null}function o(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 s=e._readableState;s.reading=false;if(s.needReadable||s.length<s.highWaterMark){e._read(s.highWaterMark)}}function a(e){if(!(this instanceof a))return new a(e);n.call(this,e);this._transformState=new s(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":47,"core-util-is":52,inherits:122}],51:[function(e,t,r){"use strict";t.exports=c;var n=e("process-nextick-args");var i=e("buffer").Buffer;c.WritableState=l;var s=e("core-util-is");s.inherits=e("inherits");var o={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;s.inherits(c,a);function f(){}function u(e,t,r){this.chunk=e;this.encoding=t;this.callback=r;this.next=null}var h;function l(t,r){h=h||e("./_stream_duplex");t=t||{};this.objectMode=!!t.objectMode;if(r instanceof h)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 s=t.decodeStrings===false;this.decodeStrings=!s;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 I(){var e=this.bufferedRequest;var t=[];while(e){t.push(e);e=e.next}return t};(function(){try{Object.defineProperty(l.prototype,"buffer",{get:o.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer "+"instead.")})}catch(e){}})();var h;function c(t){h=h||e("./_stream_duplex");if(!(this instanceof c)&&!(this instanceof h))return new c(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)}c.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe. Not readable."))};function d(e,t){var r=new Error("write after end");e.emit("error",r);n(t,r)}function p(e,t,r,s){var o=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(s,a);o=false}return o}c.prototype.write=function(e,t,r){var n=this._writableState;var s=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)d(this,r);else if(p(this,n,e,r)){n.pendingcb++;s=g(this,n,e,t,r)}return s};c.prototype.cork=function(){var e=this._writableState;e.corked++};c.prototype.uncork=function(){var e=this._writableState;if(e.corked){e.corked--;if(!e.writing&&!e.corked&&!e.finished&&!e.bufferProcessing&&e.bufferedRequest)x(this,e)}};c.prototype.setDefaultEncoding=function T(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 g(e,t,r,n,s){r=m(t,r,n);if(i.isBuffer(r))n="buffer";var o=t.objectMode?1:r.length;t.length+=o;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,s);if(f){f.next=t.lastBufferedRequest}else{t.bufferedRequest=t.lastBufferedRequest;
-}}else{v(e,t,false,o,r,n,s)}return a}function v(e,t,r,n,i,s,o){t.writelen=n;t.writecb=o;t.writing=true;t.sync=true;if(r)e._writev(i,t.onwrite);else e._write(i,s,t.onwrite);t.sync=false}function y(e,t,r,i,s){--t.pendingcb;if(r)n(s,i);else s(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 s=r.writecb;_(r);if(t)y(e,r,i,t,s);else{var o=k(r);if(!o&&!r.corked&&!r.bufferProcessing&&r.bufferedRequest){x(e,r)}if(i){n(w,e,r,o,s)}else{w(e,r,o,s)}}}function w(e,t,r,n){if(!r)S(e,t);t.pendingcb--;n();A(e,t)}function S(e,t){if(t.length===0&&t.needDrain){t.needDrain=false;e.emit("drain")}}function x(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;v(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 s=r.chunk;var o=r.encoding;var a=r.callback;var f=t.objectMode?1:s.length;v(e,t,false,f,s,o,a);r=r.next;if(t.writing){break}}if(r===null)t.lastBufferedRequest=null}t.bufferedRequest=r;t.bufferProcessing=false}c.prototype._write=function(e,t,r){r(new Error("not implemented"))};c.prototype._writev=null;c.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)U(this,n,r)};function k(e){return e.ending&&e.length===0&&e.bufferedRequest===null&&!e.finished&&!e.writing}function E(e,t){if(!t.prefinished){t.prefinished=true;e.emit("prefinish")}}function A(e,t){var r=k(t);if(r){if(t.pendingcb===0){E(e,t);t.finished=true;e.emit("finish")}else{E(e,t)}}return r}function U(e,t,r){t.ending=true;A(e,t);if(r){if(t.finished)n(r);else e.once("finish",r)}t.ended=true}},{"./_stream_duplex":47,buffer:32,"core-util-is":52,events:36,inherits:122,"process-nextick-args":53,"util-deprecate":54}],52:[function(e,t,r){(function(e){function t(e){if(Array.isArray){return Array.isArray(e)}return g(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 s(e){return e==null}r.isNullOrUndefined=s;function o(e){return typeof e==="number"}r.isNumber=o;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 h(e){return g(e)==="[object RegExp]"}r.isRegExp=h;function l(e){return typeof e==="object"&&e!==null}r.isObject=l;function c(e){return g(e)==="[object Date]"}r.isDate=c;function d(e){return g(e)==="[object Error]"||e instanceof Error}r.isError=d;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 g(e){return Object.prototype.toString.call(e)}}).call(this,{isBuffer:e("../../../../insert-module-globals/node_modules/is-buffer/index.js")})},{"../../../../insert-module-globals/node_modules/is-buffer/index.js":38}],53:[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:41}],54:[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:{})},{}],55:[function(e,t,r){t.exports=e("./lib/_stream_passthrough.js")},{"./lib/_stream_passthrough.js":48}],56:[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":47,"./lib/_stream_passthrough.js":48,"./lib/_stream_readable.js":49,"./lib/_stream_transform.js":50,"./lib/_stream_writable.js":51}],57:[function(e,t,r){t.exports=e("./lib/_stream_transform.js")},{"./lib/_stream_transform.js":50}],58:[function(e,t,r){t.exports=e("./lib/_stream_writable.js")},{"./lib/_stream_writable.js":51}],59:[function(e,t,r){t.exports=s;var n=e("events").EventEmitter;var i=e("inherits");i(s,n);s.Readable=e("readable-stream/readable.js");s.Writable=e("readable-stream/writable.js");s.Duplex=e("readable-stream/duplex.js");s.Transform=e("readable-stream/transform.js");s.PassThrough=e("readable-stream/passthrough.js");s.Stream=s;function s(){n.call(this)}s.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 s(){if(r.readable&&r.resume){r.resume()}}e.on("drain",s);if(!e._isStdio&&(!t||t.end!==false)){r.on("end",a);r.on("close",f)}var o=false;function a(){if(o)return;o=true;e.end()}function f(){if(o)return;o=true;if(typeof e.destroy==="function")e.destroy()}function u(e){h();if(n.listenerCount(this,"error")===0){throw e}}r.on("error",u);e.on("error",u);function h(){r.removeListener("data",i);e.removeListener("drain",s);r.removeListener("end",a);r.removeListener("close",f);r.removeListener("error",u);e.removeListener("error",u);r.removeListener("end",h);r.removeListener("close",h);e.removeListener("close",h)}r.on("end",h);r.on("close",h);e.on("close",h);e.emit("pipe",r);return e}},{events:36,inherits:122,"readable-stream/duplex.js":46,"readable-stream/passthrough.js":55,"readable-stream/readable.js":56,"readable-stream/transform.js":57,"readable-stream/writable.js":58}],60:[function(e,t,r){var n=e("./lib/request");var i=e("xtend");var s=e("builtin-status-codes");var o=e("url");var a=r;a.request=function(e,t){if(typeof e==="string")e=o.parse(e);else e=i(e);var r=e.protocol||"";var s=e.hostname||e.host;var a=e.port;var f=e.path||"/";if(s&&s.indexOf(":")!==-1)s="["+s+"]";e.url=(s?r+"//"+s:"")+(a?":"+a:"")+f;e.method=(e.method||"GET").toUpperCase();e.headers=e.headers||{};var u=new n(e);if(t)u.on("response",t);return u};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=s;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"]},{"./lib/request":62,"builtin-status-codes":64,url:66,xtend:165}],61:[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 s=typeof e.ArrayBuffer!=="undefined";var o=s&&a(e.ArrayBuffer.prototype.slice);r.arraybuffer=s&&i("arraybuffer");r.msstream=!r.fetch&&o&&i("ms-stream");r.mozchunkedarraybuffer=!r.fetch&&s&&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:{})},{}],62:[function(e,t,r){(function(r,n,i){var s=e("./capability");var o=e("inherits");var a=e("./response");var f=e("stream");var u=a.IncomingMessage;var h=a.readyStates;function l(e){if(s.fetch){return"fetch"}else if(s.mozchunkedarraybuffer){return"moz-chunked-arraybuffer"}else if(s.msstream){return"ms-stream"}else if(s.arraybuffer&&e){return"arraybuffer"}else if(s.vbArray&&e){return"text:vbarray"}else{return"text"}}var c=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=!s.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=l(r);t.on("finish",function(){t._onFinish()})};o(c,f.Writable);c.prototype.setHeader=function(e,t){var r=this;var n=e.toLowerCase();if(p.indexOf(n)!==-1)return;r._headers[n]={name:e,value:t}};c.prototype.getHeader=function(e){var t=this;return t._headers[e.toLowerCase()].value};c.prototype.removeHeader=function(e){var t=this;delete t._headers[e.toLowerCase()]};c.prototype._onFinish=function(){var e=this;if(e._destroyed)return;var t=e._opts;var o=e._headers;var a;if(t.method==="POST"||t.method==="PUT"||t.method==="PATCH"){if(s.blobConstructor){a=new n.Blob(e._body.map(function(e){return e.toArrayBuffer()}),{type:(o["content-type"]||{}).value||""})}else{a=i.concat(e._body).toString()}}if(e._mode==="fetch"){var f=Object.keys(o).map(function(e){return[o[e].name,o[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 u=e._xhr=new n.XMLHttpRequest;try{u.open(e._opts.method,e._opts.url,true)}catch(l){r.nextTick(function(){e.emit("error",l)});return}if("responseType"in u)u.responseType=e._mode.split(":")[0];if("withCredentials"in u)u.withCredentials=!!t.withCredentials;if(e._mode==="text"&&"overrideMimeType"in u)u.overrideMimeType("text/plain; charset=x-user-defined");Object.keys(o).forEach(function(e){u.setRequestHeader(o[e].name,o[e].value)});e._response=null;u.onreadystatechange=function(){switch(u.readyState){case h.LOADING:case h.DONE:e._onXHRProgress();break}};if(e._mode==="moz-chunked-arraybuffer"){u.onprogress=function(){e._onXHRProgress()}}u.onerror=function(){if(e._destroyed)return;e.emit("error",new Error("XHR error"))};try{u.send(a)}catch(l){r.nextTick(function(){e.emit("error",l)});return}}};function d(e){try{return e.status!==null}catch(t){return false}}c.prototype._onXHRProgress=function(){var e=this;if(!d(e._xhr)||e._destroyed)return;if(!e._response)e._connect();e._response._onXHRProgress()};c.prototype._connect=function(){var e=this;if(e._destroyed)return;e._response=new u(e._xhr,e._fetchResponse,e._mode);e.emit("response",e._response)};c.prototype._write=function(e,t,r){var n=this;n._body.push(e);r()};c.prototype.abort=c.prototype.destroy=function(){var e=this;e._destroyed=true;if(e._response)e._response._destroyed=true;if(e._xhr)e._xhr.abort()};c.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)};c.prototype.flushHeaders=function(){};c.prototype.setTimeout=function(){};c.prototype.setNoDelay=function(){};c.prototype.setSocketKeepAlive=function(){};var p=["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":61,"./response":63,_process:41,buffer:32,inherits:122,stream:59}],63:[function(e,t,r){(function(t,n,i){var s=e("./capability");var o=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 o=this;a.Readable.call(o);o._mode=n;o.headers={};o.rawHeaders=[];o.trailers={};o.rawTrailers=[];o.on("end",function(){t.nextTick(function(){o.emit("close")})});if(n==="fetch"){o._fetchResponse=r;o.statusCode=r.status;o.statusMessage=r.statusText;for(var f,u,h=r.headers[Symbol.iterator]();f=(u=h.next()).value,!u.done;){o.headers[f[0].toLowerCase()]=f[1];o.rawHeaders.push(f[0],f[1])}var l=r.body.getReader();function c(){l.read().then(function(e){if(o._destroyed)return;if(e.done){o.push(null);return}o.push(new i(e.value));c()})}c()}else{o._xhr=e;o._pos=0;o.statusCode=e.status;o.statusMessage=e.statusText;var d=e.getAllResponseHeaders().split(/\r?\n/);d.forEach(function(e){var t=e.match(/^([^:]+):\s*(.*)/);if(t){var r=t[1].toLowerCase();if(o.headers[r]!==undefined)o.headers[r]+=", "+t[2];else o.headers[r]=t[2];o.rawHeaders.push(t[1],t[2])}});o._charset="x-user-defined";if(!s.overrideMimeType){var p=o.rawHeaders["mime-type"];if(p){var m=p.match(/;\s*charset=([^;])(;|$)/);if(m){o._charset=m[1].toLowerCase()}}if(!o._charset)o._charset="utf-8"}}};o(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(s){}if(r!==null){e.push(new i(r));break}case"text":try{r=t.responseText}catch(s){e._mode="text:vbarray";break}if(r.length>e._pos){var o=r.substr(e._pos);if(e._charset==="x-user-defined"){var a=new i(o.length);for(var u=0;u<o.length;u++)a[u]=o.charCodeAt(u)&255;e.push(a)}else{e.push(o,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 h=new n.MSStreamReader;h.onprogress=function(){if(h.result.byteLength>e._pos){e.push(new i(new Uint8Array(h.result.slice(e._pos))));e._pos=h.result.byteLength}};h.onload=function(){e.push(null)};h.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":61,_process:41,buffer:32,inherits:122,stream:59}],64:[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"}},{}],65:[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 s(e){if(e&&!i(e)){throw new Error("Unknown encoding: "+e)}}var o=r.StringDecoder=function(e){this.encoding=(e||"utf8").toLowerCase().replace(/[-_]/,"");s(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};o.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 s=this.surrogateSize;this.charLength+=s;this.charReceived+=s;this.charBuffer.copy(this.charBuffer,s,0,s);e.copy(this.charBuffer,0,0,s);return t.substring(0,i)}return t};o.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};o.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:32}],66:[function(e,t,r){"use strict";var n=e("punycode");var i=e("./util");r.parse=w;r.resolve=x;r.resolveObject=k;r.format=S;r.Url=s;function s(){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 o=/^([a-z0-9.+-]+:)/i,a=/:[0-9]*$/,f=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,u=["<",">",'"',"`"," ","\r","\n"," "],h=["{","}","|","\\","^","`"].concat(u),l=["'"].concat(h),c=["%","/","?",";","#"].concat(l),d=["/","?","#"],p=255,m=/^[+a-z0-9A-Z_-]{0,63}$/,g=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,v={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 s)return e;var n=new s;n.parse(e,t,r);return n}s.prototype.parse=function(e,t,r){if(!i.isString(e)){throw new TypeError("Parameter 'url' must be a string, not "+typeof e)}var s=e.indexOf("?"),a=s!==-1&&s<e.indexOf("#")?"?":"#",u=e.split(a),h=/\\/g;u[0]=u[0].replace(h,"/");e=u.join(a);var w=e;w=w.trim();if(!r&&e.split("#").length===1){var S=f.exec(w);if(S){this.path=w;this.href=w;this.pathname=S[1];if(S[2]){this.search=S[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 x=o.exec(w);if(x){x=x[0];var k=x.toLowerCase();this.protocol=k;w=w.substr(x.length)}if(r||x||w.match(/^\/\/[^@\/]+@[^@\/]+/)){var E=w.substr(0,2)==="//";if(E&&!(x&&y[x])){w=w.substr(2);this.slashes=true}}if(!y[x]&&(E||x&&!_[x])){var A=-1;for(var U=0;U<d.length;U++){var I=w.indexOf(d[U]);if(I!==-1&&(A===-1||I<A))A=I}var T,B;if(A===-1){B=w.lastIndexOf("@")}else{B=w.lastIndexOf("@",A)}if(B!==-1){T=w.slice(0,B);w=w.slice(B+1);this.auth=decodeURIComponent(T)}A=-1;for(var U=0;U<c.length;U++){var I=w.indexOf(c[U]);if(I!==-1&&(A===-1||I<A))A=I}if(A===-1)A=w.length;this.host=w.slice(0,A);w=w.slice(A);this.parseHost();this.hostname=this.hostname||"";var L=this.hostname[0]==="["&&this.hostname[this.hostname.length-1]==="]";if(!L){var C=this.hostname.split(/\./);for(var U=0,R=C.length;U<R;U++){var P=C[U];if(!P)continue;if(!P.match(m)){var F="";for(var O=0,D=P.length;O<D;O++){if(P.charCodeAt(O)>127){F+="x"}else{F+=P[O]}}if(!F.match(m)){var M=C.slice(0,U);var N=C.slice(U+1);var z=P.match(g);if(z){M.push(z[1]);N.unshift(z[2])}if(N.length){w="/"+N.join(".")+w}this.hostname=M.join(".");break}}}}if(this.hostname.length>p){this.hostname=""}else{this.hostname=this.hostname.toLowerCase()}if(!L){this.hostname=n.toASCII(this.hostname)}var j=this.port?":"+this.port:"";var H=this.hostname||"";this.host=H+j;this.href+=this.host;if(L){this.hostname=this.hostname.substr(1,this.hostname.length-2);if(w[0]!=="/"){w="/"+w}}}if(!v[k]){for(var U=0,R=l.length;U<R;U++){var q=l[U];if(w.indexOf(q)===-1)continue;var G=encodeURIComponent(q);if(G===q){G=escape(q)}w=w.split(q).join(G)}}var W=w.indexOf("#");if(W!==-1){this.hash=w.substr(W);w=w.slice(0,W)}var Y=w.indexOf("?");if(Y!==-1){this.search=w.substr(Y);this.query=w.substr(Y+1);if(t){this.query=b.parse(this.query)}w=w.slice(0,Y)}else if(t){this.search="";this.query={}}if(w)this.pathname=w;if(_[k]&&this.hostname&&!this.pathname){this.pathname="/"}if(this.pathname||this.search){var j=this.pathname||"";var V=this.search||"";this.path=j+V}this.href=this.format();return this};function S(e){if(i.isString(e))e=w(e);if(!(e instanceof s))return s.prototype.format.call(e);return e.format()}s.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||"",s=false,o="";if(this.host){s=e+this.host}else if(this.hostname){s=e+(this.hostname.indexOf(":")===-1?this.hostname:"["+this.hostname+"]");if(this.port){s+=":"+this.port}}if(this.query&&i.isObject(this.query)&&Object.keys(this.query).length){o=b.stringify(this.query)}var a=this.search||o&&"?"+o||"";if(t&&t.substr(-1)!==":")t+=":";if(this.slashes||(!t||_[t])&&s!==false){s="//"+(s||"");if(r&&r.charAt(0)!=="/")r="/"+r}else if(!s){s=""}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+s+r+a+n};function x(e,t){return w(e,false,true).resolve(t)}s.prototype.resolve=function(e){return this.resolveObject(w(e,false,true)).format()};function k(e,t){if(!e)return t;return w(e,false,true).resolveObject(t)}s.prototype.resolveObject=function(e){if(i.isString(e)){var t=new s;t.parse(e,false,true);e=t}var r=new s;var n=Object.keys(this);for(var o=0;o<n.length;o++){var a=n[o];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 h=f[u];if(h!=="protocol")r[h]=e[h]}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 c=0;c<l.length;c++){var d=l[c];r[d]=e[d]}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 g=r.search||"";r.path=m+g}r.slashes=r.slashes||e.slashes;r.href=r.format();return r}var v=r.pathname&&r.pathname.charAt(0)==="/",b=e.host||e.pathname&&e.pathname.charAt(0)==="/",w=b||v||r.host&&e.pathname,S=w,x=r.pathname&&r.pathname.split("/")||[],p=e.pathname&&e.pathname.split("/")||[],k=r.protocol&&!_[r.protocol];if(k){r.hostname="";r.port=null;if(r.host){if(x[0]==="")x[0]=r.host;else x.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]===""||x[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;x=p}else if(p.length){if(!x)x=[];x.pop();x=x.concat(p);r.search=e.search;r.query=e.query}else if(!i.isNullOrUndefined(e.search)){if(k){r.hostname=r.host=x.shift();var E=r.host&&r.host.indexOf("@")>0?r.host.split("@"):false;if(E){r.auth=E.shift();r.host=r.hostname=E.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(!x.length){r.pathname=null;if(r.search){r.path="/"+r.search}else{r.path=null}r.href=r.format();return r}var A=x.slice(-1)[0];var U=(r.host||e.host||x.length>1)&&(A==="."||A==="..")||A==="";var I=0;for(var T=x.length;T>=0;T--){A=x[T];if(A==="."){x.splice(T,1)}else if(A===".."){x.splice(T,1);I++}else if(I){x.splice(T,1);I--}}if(!w&&!S){for(;I--;I){x.unshift("..")}}if(w&&x[0]!==""&&(!x[0]||x[0].charAt(0)!=="/")){x.unshift("")}if(U&&x.join("/").substr(-1)!=="/"){x.push("")}var B=x[0]===""||x[0]&&x[0].charAt(0)==="/";if(k){r.hostname=r.host=B?"":x.length?x.shift():"";var E=r.host&&r.host.indexOf("@")>0?r.host.split("@"):false;if(E){r.auth=E.shift();r.host=r.hostname=E.shift()}}w=w||r.host&&x.length;if(w&&!B){x.unshift("")}if(!x.length){r.pathname=null;r.path=null}else{r.pathname=x.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};s.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":67,punycode:42,querystring:45}],67:[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}}},{}],68:[function(e,t,r){(function(r){var n=e("inherits");var i=e("readable-stream").Transform;var s=e("defined");t.exports=o;n(o,i);function o(e,t){if(!(this instanceof o))return new o(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=s(t.zeroPadding,true);this._buffered=[];this._bufferedBytes=0}o.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()};o.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:32,defined:69,inherits:122,"readable-stream":80}],69:[function(e,t,r){t.exports=function(){for(var e=0;e<arguments.length;e++){if(arguments[e]!==undefined)return arguments[e]}}},{}],70:[function(e,t,r){arguments[4][47][0].apply(r,arguments)},{"./_stream_readable":72,"./_stream_writable":74,"core-util-is":75,dup:47,inherits:122,"process-nextick-args":77}],71:[function(e,t,r){arguments[4][48][0].apply(r,arguments)},{"./_stream_transform":73,"core-util-is":75,dup:48,inherits:122}],72:[function(e,t,r){arguments[4][49][0].apply(r,arguments)},{"./_stream_duplex":70,_process:41,buffer:32,"core-util-is":75,dup:49,events:36,inherits:122,isarray:76,"process-nextick-args":77,"string_decoder/":78,util:31}],73:[function(e,t,r){arguments[4][50][0].apply(r,arguments)},{"./_stream_duplex":70,"core-util-is":75,dup:50,inherits:122}],74:[function(e,t,r){arguments[4][51][0].apply(r,arguments)},{"./_stream_duplex":70,buffer:32,"core-util-is":75,dup:51,events:36,inherits:122,"process-nextick-args":77,"util-deprecate":79}],75:[function(e,t,r){(function(e){function t(e){if(Array.isArray){return Array.isArray(e)}return g(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 s(e){return e==null}r.isNullOrUndefined=s;function o(e){return typeof e==="number"}r.isNumber=o;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 h(e){return g(e)==="[object RegExp]"}r.isRegExp=h;function l(e){return typeof e==="object"&&e!==null}r.isObject=l;function c(e){return g(e)==="[object Date]"}r.isDate=c;function d(e){return g(e)==="[object Error]"||e instanceof Error}r.isError=d;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 g(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":38}],76:[function(e,t,r){arguments[4][39][0].apply(r,arguments)},{dup:39}],77:[function(e,t,r){arguments[4][53][0].apply(r,arguments)},{_process:41,dup:53}],78:[function(e,t,r){arguments[4][65][0].apply(r,arguments)},{buffer:32,dup:65}],79:[function(e,t,r){arguments[4][54][0].apply(r,arguments)},{dup:54}],80:[function(e,t,r){arguments[4][56][0].apply(r,arguments)},{"./lib/_stream_duplex.js":70,"./lib/_stream_passthrough.js":71,"./lib/_stream_readable.js":72,"./lib/_stream_transform.js":73,"./lib/_stream_writable.js":74,dup:56}],81:[function(e,t,r){t.exports=o;var n=e("block-stream2");var i=e("inherits");var s=e("stream");i(o,s.Writable);function o(e,t,r){var i=this;if(!(i instanceof o)){return new o(e,t,r)}s.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()})}o.prototype._write=function(e,t,r){this._blockstream.write(e,t,r)};o.prototype.destroy=function(e){if(this.destroyed)return;this.destroyed=true;if(e)this.emit("error",e);this.emit("close")}},{"block-stream2":68,inherits:122,stream:59}],82:[function(e,t,r){(function(r,n){t.exports=_;t.exports.parseInput=b;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"]];var i=e("bencode");var s=e("block-stream2");var o=e("piece-length");var a=e("path");var f=e("dezalgo");var u=e("filestream/read");var h=e("flatten");var l=e("fs");var c=e("is-file");var d=e("junk");var p=e("multistream");var m=e("once");var g=e("run-parallel");var v=e("simple-sha1");var y=e("stream");
-function _(e,t,r){if(typeof t==="function"){r=t;t={}}if(!t)t={};b(e,t,function(e,n,i){if(e)return r(e);t.singleFileTorrent=i;A(n,t,r)})}function b(e,t,r){if(typeof t==="function"){r=t;t={}}if(!t)t={};r=f(r);if(Array.isArray(e)&&e.length===0)throw new Error("invalid input type");if(T(e))e=Array.prototype.slice.call(e);if(!Array.isArray(e))e=[e];if(e.length===1&&typeof e[0]!=="string"&&!e[0].name)e[0].name=t.name;var i=null;e.forEach(function(e,t){if(typeof e==="string")return;var r=e.fullPath||e.name;if(!r)throw new Error("missing required `fullPath` or `name` property on input");e.path=r.split("/");if(!e.path[0])e.path.shift();if(e.path.length<2){i=null}else if(t===0){i=e.path[0]}else if(e.path[0]!==i){i=null}});e=e.filter(function(e){if(typeof e==="string")return true;var t=e.path[e.path.length-1];return k(t)&&d.not(t)});if(i){e.forEach(function(e){if(typeof e==="string")return;e.path.shift()})}if(!t.name&&i)t.name=i;if(!t.name&&e[0]&&e[0].name)t.name=e[0].name;if(!t.name&&typeof e[0]==="string")t.name=a.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 o=e.length===1;if(e.length===1&&typeof e[0]==="string"){if(typeof l.stat!=="function"){throw new Error("filesystem paths do not work in the browser")}c(e[0],function(e,t){if(e)return r(e);o=t;u()})}else{u()}function u(){g(e.map(function(e){return function(r){var i={};if(I(e)){i.getStream=L(e);i.length=e.size}else if(n.isBuffer(e)){i.getStream=C(e);i.length=e.length}else if(B(e)){if(!t.pieceLength){throw new Error("must specify `pieceLength` option if input is Stream")}i.getStream=P(e,i);i.length=0}else if(typeof e==="string"){if(typeof l.stat!=="function"){throw new Error("filesystem paths do not work in the browser")}var a=s>1||o;w(e,a,r);return}else{throw new Error("invalid input type")}i.path=e.path;r(null,i)}}),function(e,t){if(e)return r(e);t=h(t);r(null,t,o)})}}function w(e,t,r){x(e,S,function(n,i){if(n)return r(n);if(Array.isArray(i))i=h(i);else i=[i];e=a.normalize(e);if(t){e=e.slice(0,e.lastIndexOf(a.sep)+1)}if(e[e.length-1]!==a.sep)e+=a.sep;i.forEach(function(t){t.getStream=R(t.path);t.path=t.path.replace(e,"").split(a.sep)});r(null,i)})}function S(e,t){t=m(t);l.stat(e,function(r,n){if(r)return t(r);var i={length:n.size,path:e};t(null,i)})}function x(e,t,r){l.readdir(e,function(n,i){if(n&&n.code==="ENOTDIR"){t(e,r)}else if(n){r(n)}else{g(i.filter(k).filter(d.not).map(function(r){return function(n){x(a.join(e,r),t,n)}}),r)}})}function k(e){return e[0]!=="."}function E(e,t,r){r=m(r);var i=[];var o=0;var a=e.map(function(e){return e.getStream});var f=0;var u=0;var h=false;var l=new p(a);var c=new s(t,{zeroPadding:false});l.on("error",y);l.pipe(c).on("data",d).on("end",g).on("error",y);function d(e){o+=e.length;var t=u;v(e,function(e){i[t]=e;f-=1;b()});f+=1;u+=1}function g(){h=true;b()}function y(e){_();r(e)}function _(){l.removeListener("error",y);c.removeListener("data",d);c.removeListener("end",g);c.removeListener("error",y)}function b(){if(h&&f===0){_();r(null,new n(i.join(""),"hex"),o)}}}function A(e,n,s){var a=n.announceList;if(!a){if(typeof n.announce==="string")a=[[n.announce]];else if(Array.isArray(n.announce)){a=n.announce.map(function(e){return[e]})}}if(!a)a=[];if(r.WEBTORRENT_ANNOUNCE){if(typeof r.WEBTORRENT_ANNOUNCE==="string"){a.push([[r.WEBTORRENT_ANNOUNCE]])}else if(Array.isArray(r.WEBTORRENT_ANNOUNCE)){a=a.concat(r.WEBTORRENT_ANNOUNCE.map(function(e){return[e]}))}}if(n.announce===undefined&&n.announceList===undefined){a=a.concat(t.exports.announceList)}if(typeof n.urlList==="string")n.urlList=[n.urlList];var f={info:{name:n.name},"creation date":Number(n.creationDate)||Date.now(),encoding:"UTF-8"};if(a.length!==0){f.announce=a[0][0];f["announce-list"]=a}if(n.comment!==undefined)f.comment=n.comment;if(n.createdBy!==undefined)f["created by"]=n.createdBy;if(n.private!==undefined)f.info.private=Number(n.private);if(n.sslCert!==undefined)f.info["ssl-cert"]=n.sslCert;if(n.urlList!==undefined)f["url-list"]=n.urlList;var u=n.pieceLength||o(e.reduce(U,0));f.info["piece length"]=u;E(e,u,function(t,r,o){if(t)return s(t);f.info.pieces=r;e.forEach(function(e){delete e.getStream});if(n.singleFileTorrent){f.info.length=o}else{f.info.files=e}s(null,i.encode(f))})}function U(e,t){return e+t.length}function I(e){return typeof Blob!=="undefined"&&e instanceof Blob}function T(e){return typeof FileList==="function"&&e instanceof FileList}function B(e){return typeof e==="object"&&typeof e.pipe==="function"}function L(e){return function(){return new u(e)}}function C(e){return function(){var t=new y.PassThrough;t.end(e);return t}}function R(e){return function(){return l.createReadStream(e)}}function P(e,t){return function(){var r=new y.Transform;r._transform=function(e,r,n){t.length+=e.length;this.push(e);n()};e.pipe(r);return r}}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{},e("buffer").Buffer)},{bencode:83,"block-stream2":87,buffer:32,dezalgo:100,"filestream/read":106,flatten:107,fs:30,"is-file":108,junk:109,multistream:125,once:111,path:40,"piece-length":112,"run-parallel":143,"simple-sha1":147,stream:59}],83:[function(e,t,r){arguments[4][13][0].apply(r,arguments)},{"./lib/decode":84,"./lib/encode":86,dup:13}],84:[function(e,t,r){arguments[4][14][0].apply(r,arguments)},{"./dict":85,buffer:32,dup:14}],85:[function(e,t,r){arguments[4][15][0].apply(r,arguments)},{dup:15}],86:[function(e,t,r){arguments[4][16][0].apply(r,arguments)},{buffer:32,dup:16}],87:[function(e,t,r){arguments[4][68][0].apply(r,arguments)},{buffer:32,defined:88,dup:68,inherits:122,"readable-stream":99}],88:[function(e,t,r){arguments[4][69][0].apply(r,arguments)},{dup:69}],89:[function(e,t,r){arguments[4][47][0].apply(r,arguments)},{"./_stream_readable":91,"./_stream_writable":93,"core-util-is":94,dup:47,inherits:122,"process-nextick-args":96}],90:[function(e,t,r){arguments[4][48][0].apply(r,arguments)},{"./_stream_transform":92,"core-util-is":94,dup:48,inherits:122}],91:[function(e,t,r){arguments[4][49][0].apply(r,arguments)},{"./_stream_duplex":89,_process:41,buffer:32,"core-util-is":94,dup:49,events:36,inherits:122,isarray:95,"process-nextick-args":96,"string_decoder/":97,util:31}],92:[function(e,t,r){arguments[4][50][0].apply(r,arguments)},{"./_stream_duplex":89,"core-util-is":94,dup:50,inherits:122}],93:[function(e,t,r){arguments[4][51][0].apply(r,arguments)},{"./_stream_duplex":89,buffer:32,"core-util-is":94,dup:51,events:36,inherits:122,"process-nextick-args":96,"util-deprecate":98}],94:[function(e,t,r){arguments[4][75][0].apply(r,arguments)},{"../../../../../../../../browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js":38,dup:75}],95:[function(e,t,r){arguments[4][39][0].apply(r,arguments)},{dup:39}],96:[function(e,t,r){arguments[4][53][0].apply(r,arguments)},{_process:41,dup:53}],97:[function(e,t,r){arguments[4][65][0].apply(r,arguments)},{buffer:32,dup:65}],98:[function(e,t,r){arguments[4][54][0].apply(r,arguments)},{dup:54}],99:[function(e,t,r){arguments[4][56][0].apply(r,arguments)},{"./lib/_stream_duplex.js":89,"./lib/_stream_passthrough.js":90,"./lib/_stream_readable.js":91,"./lib/_stream_transform.js":92,"./lib/_stream_writable.js":93,dup:56}],100:[function(e,t,r){var n=e("wrappy");t.exports=n(s);var i=e("asap");function s(e){var t=true;i(function(){t=false});return function r(){var r=arguments;var n=this;if(t)i(function(){e.apply(n,r)});else e.apply(n,r)}}},{asap:101,wrappy:103}],101:[function(e,t,r){"use strict";var n=e("./raw");var i=[];var s=[];var o=n.makeRequestCallFromTimer(a);function a(){if(s.length){throw s.shift()}}t.exports=f;function f(e){var t;if(i.length){t=i.pop()}else{t=new u}t.task=e;n(t)}function u(){this.task=null}u.prototype.call=function(){try{this.task.call()}catch(e){if(f.onerror){f.onerror(e)}else{s.push(e);o()}}finally{this.task=null;i[i.length]=this}}},{"./raw":102}],102:[function(e,t,r){(function(e){"use strict";t.exports=r;function r(e){if(!n.length){s();i=true}n[n.length]=e}var n=[];var i=false;var s;var o=0;var a=1024;function f(){while(o<n.length){var e=o;o=o+1;n[e].call();if(o>a){for(var t=0,r=n.length-o;t<r;t++){n[t]=n[t+o]}n.length-=o;o=0}}n.length=0;o=0;i=false}var u=e.MutationObserver||e.WebKitMutationObserver;if(typeof u==="function"){s=h(f)}else{s=l(f)}r.requestFlush=s;function h(e){var t=1;var r=new u(e);var n=document.createTextNode("");r.observe(n,{characterData:true});return function i(){t=-t;n.data=t}}function l(e){return function t(){var t=setTimeout(n,0);var r=setInterval(n,50);function n(){clearTimeout(t);clearInterval(r);e()}}}r.makeRequestCallFromTimer=l}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],103:[function(e,t,r){arguments[4][21][0].apply(r,arguments)},{dup:21}],104:[function(e,t,r){arguments[4][26][0].apply(r,arguments)},{buffer:32,dup:26,"is-typedarray":105}],105:[function(e,t,r){arguments[4][25][0].apply(r,arguments)},{dup:25}],106:[function(e,t,r){var n=e("stream").Readable;var i=e("inherits");var s=/^.*\.(\w+)$/;var o=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(o(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:122,stream:59,"typedarray-to-buffer":104}],107:[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)}},[])}}},{}],108:[function(e,t,r){"use strict";var n=e("fs");t.exports=function s(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:30}],109:[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)}},{}],110:[function(e,t,r){arguments[4][21][0].apply(r,arguments)},{dup:21}],111:[function(e,t,r){arguments[4][22][0].apply(r,arguments)},{dup:22,wrappy:110}],112:[function(e,t,r){var n=e("closest-to");var i=[];for(var s=14;s<=22;s++){i.push(Math.pow(2,s))}t.exports=function(e){return n(e/Math.pow(2,10),i)}},{"closest-to":113}],113:[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 s=0,o=t.length;s<o;s++){n=Math.abs(e-t[s]);if(n>=r){break}r=n;i=t[s]}return i}},{}],114:[function(e,t,r){r=t.exports=e("./debug");r.log=s;r.formatArgs=i;r.save=o;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 s=0;e[0].replace(/%[a-z%]/g,function(e){if("%%"===e)return;i++;if("%c"===e){s=i}});e.splice(s,0,n);return e}function s(){return"object"===typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function o(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":115}],115:[function(e,t,r){r=t.exports=o;r.coerce=h;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 s(){return r.colors[n++%r.colors.length]}function o(e){function t(){}t.enabled=false;function n(){var e=n;var t=+new Date;var o=t-(i||t);e.diff=o;e.prev=i;e.curr=t;i=t;if(null==e.useColors)e.useColors=r.useColors();if(null==e.color&&e.useColors)e.color=s();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 s=a[f];t=i.call(e,s);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 o=r.enabled(e)?n:t;o.namespace=e;return o}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 h(e){if(e instanceof Error)return e.stack||e.message;return e}},{ms:116}],116:[function(e,t,r){var n=1e3;var i=n*60;var s=i*60;var o=s*24;var a=o*365.25;t.exports=function(e,t){t=t||{};if("string"==typeof e)return f(e);return t.long?h(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*o;case"hours":case"hour":case"hrs":case"hr":case"h":return r*s;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>=o)return Math.round(e/o)+"d";if(e>=s)return Math.round(e/s)+"h";if(e>=i)return Math.round(e/i)+"m";if(e>=n)return Math.round(e/n)+"s";return e+"ms"}function h(e){return l(e,o,"day")||l(e,s,"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"}},{}],117:[function(e,t,r){var n=e("once");var i=function(){};var s=function(e){return e.setHeader&&typeof e.abort==="function"};var o=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 h=t.readable||t.readable!==false&&e.readable;var l=t.writable||t.writable!==false&&e.writable;var c=function(){if(!e.writable)d()};var d=function(){l=false;if(!h)r()};var p=function(){h=false;if(!l)r()};var m=function(e){r(e?new Error("exited with error code: "+e):null)};var g=function(){if(h&&!(u&&u.ended))return r(new Error("premature close"));if(l&&!(f&&f.ended))return r(new Error("premature close"))};var v=function(){e.req.on("finish",d)};if(s(e)){e.on("complete",d);e.on("abort",g);if(e.req)v();else e.on("request",v)}else if(l&&!f){e.on("end",c);e.on("close",c)}if(o(e))e.on("exit",m);e.on("end",p);e.on("finish",d);if(t.error!==false)e.on("error",r);e.on("close",g);return function(){e.removeListener("complete",d);e.removeListener("abort",g);e.removeListener("request",v);if(e.req)e.req.removeListener("finish",d);e.removeListener("end",c);e.removeListener("close",c);e.removeListener("finish",d);e.removeListener("exit",m);e.removeListener("end",p);e.removeListener("error",r);e.removeListener("close",g)}};t.exports=a},{once:119}],118:[function(e,t,r){arguments[4][21][0].apply(r,arguments)},{dup:21}],119:[function(e,t,r){arguments[4][22][0].apply(r,arguments)},{dup:22,wrappy:118}],120:[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 s=r-Math.floor(r);var o="";for(var i=0;i<Math.floor(r);i++){var a=Math.floor(Math.random()*t).toString(t);o=a+o}if(s){var f=Math.pow(t,s);var a=Math.floor(Math.random()*f).toString(t);o=a+o}var u=parseInt(o,t);if(u!==Infinity&&u>=Math.pow(2,e)){return n(e,t)}else return o};n.rack=function(e,t,r){var i=function(i){var o=0;do{if(o++>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(s,a));s[a]=i;return a};var s=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}},{}],121:[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 s=t&&t.length&&i+t.length;var o=this.mem[e];if(o)return n(r,null,t?o.slice(i,s):o);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:41}],122:[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}}},{}],123:[function(e,t,r){t.exports=o;var n=e("inherits");var i=e("stream");var s=typeof window!=="undefined"&&window.MediaSource;n(o,i.Writable);function o(e,t){var r=this;if(!(r instanceof o))return new o(e,t);i.Writable.call(r,t);if(!s)throw new Error("web browser lacks MediaSource support");if(!t)t={};r._elem=e;r._mediaSource=new s;r._sourceBuffer=null;r._cb=null;r._type=t.type||a(t.extname);if(!r._type)throw new Error("missing `opts.type` or `opts.extname` options");r._elem.src=window.URL.createObjectURL(r._mediaSource);r._mediaSource.addEventListener("sourceopen",function(){if(s.isTypeSupported(r._type)){r._sourceBuffer=r._mediaSource.addSourceBuffer(r._type);r._sourceBuffer.addEventListener("updateend",r._flow.bind(r));r._flow()}else{r._mediaSource.endOfStream("decode")}});r.on("finish",function(){r._mediaSource.endOfStream()})}o.prototype._write=function(e,t,r){var n=this;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"))}n._sourceBuffer.appendBuffer(e);n._cb=r};o.prototype._flow=function(){var e=this;if(e._cb){e._cb(null)}};function a(e){if(!e)return null;if(e[0]!==".")e="."+e;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"'}[e]}},{inherits:122,stream:59}],124:[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 s=t.offset||0;var o=t.length||i.length-s;n(r,null,i.slice(s,o+s))};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:41}],125:[function(e,t,r){t.exports=s;var n=e("inherits");var i=e("stream");n(s,i.Readable);function s(e,t){if(!(this instanceof s))return new s(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(o);this._next()}s.obj=function(e){return new s(e,{objectMode:true,highWaterMark:16})};s.prototype._read=function(){this._drained=true;this._forward()};s.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};s.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")};s.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(o(r))})}else{var t=e._queue.shift();if(typeof t==="function")t=o(t());e._gotNextStream(t)}};s.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",s);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",s);e.removeListener("close",n);t._next()}function s(e){t.destroy(e)}};function o(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:122,stream:59}],126:[function(e,t,r){(function(r,n){t.exports=u;t.exports.remote=h;var i=e("blob-to-buffer");var s=e("fs");var o=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 h(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 o==="function"&&/^https?:/.test(e)){o.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 s.readFile==="function"&&typeof e==="string"){s.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":38,_process:41,"blob-to-buffer":127,fs:30,"magnet-uri":130,"parse-torrent-file":133,"simple-get":144}],127:[function(e,t,r){var n=e("typedarray-to-buffer");t.exports=function i(e,t){if(typeof Blob==="undefined"||!(e instanceof Blob)){throw new Error("first argument must be a Blob")}if(typeof t!=="function"){throw new Error("second argument must be a function")}var r=new FileReader;function i(e){r.removeEventListener("loadend",i,false);if(e.error)t(e.error);else t(null,n(r.result))}r.addEventListener("loadend",i,false);r.readAsArrayBuffer(e)}},{"typedarray-to-buffer":128}],128:[function(e,t,r){arguments[4][26][0].apply(r,arguments)},{buffer:32,dup:26,"is-typedarray":129}],129:[function(e,t,r){arguments[4][25][0].apply(r,arguments)},{dup:25}],130:[function(e,t,r){(function(r){t.exports=o;t.exports.decode=o;t.exports.encode=a;var n=e("thirty-two");var i=e("xtend");var s=e("uniq");function o(e){var t={};var i=e.split("magnet:?")[1];var o=i&&i.length>=0?i.split("&"):[];o.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 s=t[n];t[n]=[s,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=[];s(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)}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:32,"thirty-two":131,uniq:152,xtend:165}],131:[function(e,t,r){var n=e("./thirty-two");r.encode=n.encode;r.decode=n.decode},{"./thirty-two":132}],132:[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 s=0;var o=0;var a=0;var f=new e(i(r)*8);while(n<r.length){var u=r[n];if(o>3){a=u&255>>o;o=(o+5)%8;a=a<<o|(n+1<r.length?r[n+1]:0)>>8-o;n++}else{a=u>>8-(o+5)&31;o=(o+5)%8;if(o==0)n++}f[s]=t.charCodeAt(a);s++}for(n=s;n<f.length;n++)f[n]=61;return f};r.decode=function(t){var r=0;var i=0;var s;var o=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){s|=i;a[o]=s;o++;s=0}else{s|=255&i<<8-r}}else{r=(r+5)%8;s|=255&i>>>r;a[o]=s;o++;s=255&i<<8-r}}else{throw new Error("Invalid input - it is not base32 encoded string")}}return a.slice(0,o)}}).call(this,e("buffer").Buffer)},{buffer:32}],133:[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 s=e("simple-sha1");var o=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=s.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())}o(t.announce);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()});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=h(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 h(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:134,buffer:32,path:40,"simple-sha1":147,uniq:152}],134:[function(e,t,r){arguments[4][13][0].apply(r,arguments)},{"./lib/decode":135,
-"./lib/encode":137,dup:13}],135:[function(e,t,r){arguments[4][14][0].apply(r,arguments)},{"./dict":136,buffer:32,dup:14}],136:[function(e,t,r){arguments[4][15][0].apply(r,arguments)},{dup:15}],137:[function(e,t,r){arguments[4][16][0].apply(r,arguments)},{buffer:32,dup:16}],138:[function(e,t,r){var n=e("once");var i=e("end-of-stream");var s=e("fs");var o=function(){};var a=function(e){return typeof e==="function"};var f=function(e){return(e instanceof(s.ReadStream||o)||e instanceof(s.WriteStream||o))&&a(e.close)};var u=function(e){return e.setHeader&&a(e.abort)};var h=function(e,t,r,s){s=n(s);var o=false;e.on("close",function(){o=true});i(e,{readable:t,writable:r},function(e){if(e)return s(e);o=true;s()});var h=false;return function(t){if(o)return;if(h)return;h=true;if(f(e))return e.close();if(u(e))return e.abort();if(a(e.destroy))return e.destroy();s(t||new Error("stream was destroyed"))}};var l=function(e){e()};var c=function(e,t){return e.pipe(t)};var d=function(){var e=Array.prototype.slice.call(arguments);var t=a(e[e.length-1]||o)&&e.pop()||o;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,s){var o=s<e.length-1;var a=s>0;return h(i,o,a,function(e){if(!r)r=e;if(e)n.forEach(l);if(o)return;n.forEach(l);t(r)})});return e.reduce(c)};t.exports=d},{"end-of-stream":117,fs:30,once:140}],139:[function(e,t,r){arguments[4][21][0].apply(r,arguments)},{dup:21}],140:[function(e,t,r){arguments[4][22][0].apply(r,arguments)},{dup:22,wrappy:139}],141:[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 s=e[t];e[t]=i;e[t+n]=s;t++;return i}};t.exports=n},{}],142:[function(e,t,r){t.exports=i;t.exports.filter=s;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 s(e,t){var r=new n;i(e,r,t);return r}},{events:36}],143:[function(e,t,r){(function(e){t.exports=function(t,r){var n,i,s;var o=true;if(Array.isArray(t)){n=[];i=t.length}else{s=Object.keys(t);n={};i=s.length}function a(t){function i(){if(r)r(t,n);r=null}if(o)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(s){s.forEach(function(e){t[e](f.bind(undefined,e))})}else{t.forEach(function(e,t){e(f.bind(undefined,t))})}o=false}}).call(this,e("_process"))},{_process:41}],144:[function(e,t,r){(function(r){t.exports=u;var n=e("xtend");var i=e("http");var s=e("https");var o=e("once");var a=e("unzip-response");var f=e("url");function u(e,t){e=typeof e==="string"?{url:e}:n(e);t=o(t);if(e.url)h(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:"?s:i;var c=l.request(e,function(r){if(r.statusCode>=300&&r.statusCode<400&&"location"in r.headers){e.url=r.headers.location;h(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)});c.on("error",t);c.end(r);return c}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 h(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:32,http:60,https:37,once:146,"unzip-response":31,url:66,xtend:165}],145:[function(e,t,r){arguments[4][21][0].apply(r,arguments)},{dup:21}],146:[function(e,t,r){arguments[4][22][0].apply(r,arguments)},{dup:22,wrappy:145}],147:[function(e,t,r){var n=e("rusha");var i=new n;var s=window.crypto||window.msCrypto||{};var o=s.subtle||s.webkitSubtle;var a=i.digest.bind(i);try{o.digest({name:"sha-1"},new Uint8Array).catch(function(){o=false})}catch(f){o=false}function u(e,t){if(!o){setTimeout(t,0,a(e));return}if(typeof e==="string"){e=h(e)}o.digest({name:"sha-1"},e).then(function r(e){t(l(new Uint8Array(e)))},function n(r){t(a(e))})}function h(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:148}],148:[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 s=function(e){for(e+=9;e%64>0;e+=1);return e};var o=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 s=this,o,a=i%4,f=n%4,u=n-f;if(u>0){switch(a){case 0:e[i+3|0]=s.charCodeAt(r);case 1:e[i+2|0]=s.charCodeAt(r+1);case 2:e[i+1|0]=s.charCodeAt(r+2);case 3:e[i|0]=s.charCodeAt(r+3)}}for(o=a;o<u;o=o+4|0){t[i+o>>2]=s.charCodeAt(r+o)<<24|s.charCodeAt(r+o+1)<<16|s.charCodeAt(r+o+2)<<8|s.charCodeAt(r+o+3)}switch(f){case 3:e[i+u+1|0]=s.charCodeAt(r+u+2);case 2:e[i+u+2|0]=s.charCodeAt(r+u+1);case 1:e[i+u+3|0]=s.charCodeAt(r+u)}};var u=function(e,t,r,n,i){var s=this,o,a=i%4,f=n%4,u=n-f;if(u>0){switch(a){case 0:e[i+3|0]=s[r];case 1:e[i+2|0]=s[r+1];case 2:e[i+1|0]=s[r+2];case 3:e[i|0]=s[r+3]}}for(o=4-a;o<u;o=o+=4|0){t[i+o>>2]=s[r+o]<<24|s[r+o+1]<<16|s[r+o+2]<<8|s[r+o+3]}switch(f){case 3:e[i+u+1|0]=s[r+u+2];case 2:e[i+u+2|0]=s[r+u+1];case 1:e[i+u+3|0]=s[r+u]}};var h=function(e,t,r,n,s){var o=this,a,f=s%4,u=n%4,h=n-u;var l=new Uint8Array(i.readAsArrayBuffer(o.slice(r,r+n)));if(h>0){switch(f){case 0:e[s+3|0]=l[0];case 1:e[s+2|0]=l[1];case 2:e[s+1|0]=l[2];case 3:e[s|0]=l[3]}}for(a=4-f;a<h;a=a+=4|0){t[s+a>>2]=l[a]<<24|l[a+1]<<16|l[a+2]<<8|l[a+3]}switch(u){case 3:e[s+h+1|0]=l[h+2];case 2:e[s+h+2|0]=l[h+1];case 1:e[s+h+3|0]=l[h]}};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 h.bind(e)}};var c=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 d=function(e){var t,r,n="0123456789abcdef",i=[],s=new Uint8Array(e);for(t=0;t<s.length;t++){r=s[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=s(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 g=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 v=function(e,r){var n=s(e);var i=new Int32Array(t.heap,0,n>>2);o(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,s){var o=n;if(s){o=v(n,i)}y(e,r,n);t.core.hash(o,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;g(t.heap,t.padMaxChunkLen);var n=0,i=t.maxChunkLen,s;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 d(w(e).buffer)}}n._core=function o(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,s=0,o=0,a=0,f=0,u=0,h=0,l=0,c=0,d=0,p=0,m=0,g=0;s=n[t+320>>2]|0;a=n[t+324>>2]|0;u=n[t+328>>2]|0;l=n[t+332>>2]|0;d=n[t+336>>2]|0;for(r=0;(r|0)<(e|0);r=r+64|0){o=s;f=a;h=u;c=l;p=d;for(i=0;(i|0)<64;i=i+4|0){g=n[r+i>>2]|0;m=((s<<5|s>>>27)+(a&u|~a&l)|0)+((g+d|0)+1518500249|0)|0;d=l;l=u;u=a<<30|a>>>2;a=s;s=m;n[e+i>>2]=g}for(i=e+64|0;(i|0)<(e+80|0);i=i+4|0){g=(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=((s<<5|s>>>27)+(a&u|~a&l)|0)+((g+d|0)+1518500249|0)|0;d=l;l=u;u=a<<30|a>>>2;a=s;s=m;n[i>>2]=g}for(i=e+80|0;(i|0)<(e+160|0);i=i+4|0){g=(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=((s<<5|s>>>27)+(a^u^l)|0)+((g+d|0)+1859775393|0)|0;d=l;l=u;u=a<<30|a>>>2;a=s;s=m;n[i>>2]=g}for(i=e+160|0;(i|0)<(e+240|0);i=i+4|0){g=(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=((s<<5|s>>>27)+(a&u|a&l|u&l)|0)+((g+d|0)-1894007588|0)|0;d=l;l=u;u=a<<30|a>>>2;a=s;s=m;n[i>>2]=g}for(i=e+240|0;(i|0)<(e+320|0);i=i+4|0){g=(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=((s<<5|s>>>27)+(a^u^l)|0)+((g+d|0)-899497514|0)|0;d=l;l=u;u=a<<30|a>>>2;a=s;s=m;n[i>>2]=g}s=s+o|0;a=a+f|0;u=u+h|0;l=l+c|0;d=d+p|0}n[t+320>>2]=s;n[t+324>>2]=a;n[t+328>>2]=u;n[t+332>>2]=l;n[t+336>>2]=d}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,s=new n(4*1024*1024);self.onmessage=function a(e){var t,r=e.data.data;try{t=s.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:{})},{}],149:[function(e,t,r){var n=1;var i=65535;var s=4;var o=function(){n=n+1&i};var a=setInterval(o,1e3/s|0);if(a.unref)a.unref();t.exports=function(e){var t=s*(e||5);var r=[0];var o=1;var a=n-1&i;return function(e){var f=n-a&i;if(f>t)f=t;a=n;while(f--){if(o===t)o=0;r[o]=r[o===0?t-1:o-1];o++}if(e)r[o-1]+=e;var u=r[o-1];var h=r.length<t?0:r[o===t?0:o];return r.length<s?u:(u-h)*s/r.length}}},{}],150:[function(e,t,r){(function(r,n){t.exports=c;var i=e("debug")("torrent-discovery");var s=e("bittorrent-dht/client");var o=e("events").EventEmitter;var a=e("xtend/mutable");var f=e("inherits");var u=e("run-parallel");var h=e("re-emitter");var l=e("bittorrent-tracker/client");f(c,o);function c(e){var t=this;if(!(t instanceof c))return new c(e);o.call(t);a(t,{announce:[],dht:typeof s==="function",rtcConfig:null,peerId:null,port:0,tracker:true,wrtc:null},e);t.infoHash=null;t.infoHashBuffer=null;t.torrent=null;t._externalDHT=typeof t.dht==="object";t._performedDHTLookup=false;if(!t.peerId)throw new Error("peerId required");if(!r.browser&&!t.port)throw new Error("port required");if(t.dht)t._createDHT(t.dhtPort)}c.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()}if(t.dht){if(t.dht.ready)t._dhtLookupAndAnnounce();else t.dht.on("ready",t._dhtLookupAndAnnounce.bind(t))}};c.prototype.updatePort=function(e){var t=this;if(e===t.port)return;t.port=e;if(t.dht&&t.infoHash){t._performedDHTLookup=false;t._dhtLookupAndAnnounce()}if(t.tracker&&t.tracker!==true){t.tracker.stop();t.tracker.destroy(function(){t._createTracker()})}};c.prototype.stop=function(e){var t=this;var r=[];if(t.tracker&&t.tracker!==true){t.tracker.stop();r.push(function(e){t.tracker.destroy(e)})}if(!t._externalDHT&&t.dht&&t.dht!==true){r.push(function(e){t.dht.destroy(e)})}u(r,e)};c.prototype._createDHT=function(e){var t=this;if(!t._externalDHT)t.dht=new s;h(t.dht,t,["error","warning"]);t.dht.on("peer",function(e,r){if(r===t.infoHash)t.emit("peer",e)});if(!t._externalDHT)t.dht.listen(e)};c.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);h(e.tracker,e,["peer","warning","error"]);e.tracker.on("update",function(t){e.emit("trackerAnnounce",t)});e.tracker.start()};c.prototype._dhtLookupAndAnnounce=function(){var e=this;if(e._performedDHTLookup)return;e._performedDHTLookup=true;i("dht lookup");e.dht.lookup(e.infoHash,function(t){if(t||!e.port)return;i("dht announce");e.dht.announce(e.infoHash,e.port,function(){i("dht announce complete");e.emit("dhtAnnounce")})})}}).call(this,e("_process"),e("buffer").Buffer)},{_process:41,"bittorrent-dht/client":31,"bittorrent-tracker/client":17,buffer:32,debug:114,events:36,inherits:122,"re-emitter":142,"run-parallel":143,"xtend/mutable":166}],151:[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:32}],152:[function(e,t,r){"use strict";function n(e,t){var r=1,n=e.length,i=e[0],s=e[0];for(var o=1;o<n;++o){s=i;i=e[o];if(t(i,s)){if(o===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 s=1;s<r;++s,i=n){i=n;n=e[s];if(n!==i){if(s===t){t++;continue}e[t++]=n}}e.length=t;return e}function s(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=s},{}],153:[function(e,t,r){(function(r){var n=e("bencode");var i=e("bitfield");var s=e("events").EventEmitter;var o=e("inherits");var a=e("simple-sha1");var f=1e7;var u=1e3;var h=16*1024;t.exports=function(e){o(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:u});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>f){return this.emit("warning",new Error("Peer gave maliciously large metadata size"))}this._metadataSize=e.metadata_size;this._numPieces=Math.ceil(this._metadataSize/h);this._remainingRejects=this._numPieces*2;if(this._fetching){this._requestPieces()}};t.prototype.onMessage=function(e){var t,r;try{var i=e.toString();var s=i.indexOf("ee")+2;t=n.decode(i.substring(0,s));r=e.slice(s)}catch(o){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;try{var t=n.decode(e).info;if(t){e=n.encode(t)}}catch(r){}if(this._infoHash&&this._infoHash!==a.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*h;var r=t+h;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>h){return}t.copy(this.metadata,e*h);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:u});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:154,bitfield:8,buffer:32,events:36,inherits:122,"simple-sha1":147}],154:[function(e,t,r){arguments[4][13][0].apply(r,arguments)},{"./lib/decode":155,"./lib/encode":157,dup:13}],155:[function(e,t,r){arguments[4][14][0].apply(r,arguments)},{"./dict":156,buffer:32,dup:14}],156:[function(e,t,r){arguments[4][15][0].apply(r,arguments)},{dup:15}],157:[function(e,t,r){arguments[4][16][0].apply(r,arguments)},{buffer:32,dup:16}],158:[function(e,t,r){var n=function(e,t,r){this._byteOffset=t||0;if(e instanceof ArrayBuffer){this.buffer=e}else if(typeof e=="object"){this.dataView=e;if(t){this._byteOffset+=t}}else{this.buffer=new ArrayBuffer(e||0)}this.position=0;this.endianness=r==null?n.LITTLE_ENDIAN:r};t.exports=n;n.prototype={};n.prototype.save=function(e){var t=new Blob([this.buffer]);var r=window.webkitURL||window.URL;if(r&&r.createObjectURL){var n=r.createObjectURL(t);var i=document.createElement("a");i.setAttribute("href",n);i.setAttribute("download",e);i.click();r.revokeObjectURL(n)}else{throw"DataStream.save: Can't create object URL."}};n.BIG_ENDIAN=false;n.LITTLE_ENDIAN=true;n.prototype._dynamicSize=true;Object.defineProperty(n.prototype,"dynamicSize",{get:function(){return this._dynamicSize},set:function(e){if(!e){this._trimAlloc()}this._dynamicSize=e}});n.prototype._byteLength=0;Object.defineProperty(n.prototype,"byteLength",{get:function(){return this._byteLength-this._byteOffset}});Object.defineProperty(n.prototype,"buffer",{get:function(){this._trimAlloc();return this._buffer},set:function(e){this._buffer=e;this._dataView=new DataView(this._buffer,this._byteOffset);this._byteLength=this._buffer.byteLength}});Object.defineProperty(n.prototype,"byteOffset",{get:function(){return this._byteOffset},set:function(e){this._byteOffset=e;this._dataView=new DataView(this._buffer,this._byteOffset);this._byteLength=this._buffer.byteLength}});Object.defineProperty(n.prototype,"dataView",{get:function(){return this._dataView},set:function(e){this._byteOffset=e.byteOffset;this._buffer=e.buffer;this._dataView=new DataView(this._buffer,this._byteOffset);this._byteLength=this._byteOffset+e.byteLength}});n.prototype._realloc=function(e){if(!this._dynamicSize){return}var t=this._byteOffset+this.position+e;var r=this._buffer.byteLength;if(t<=r){if(t>this._byteLength){this._byteLength=t}return}if(r<1){r=1}while(t>r){r*=2}var n=new ArrayBuffer(r);var i=new Uint8Array(this._buffer);var s=new Uint8Array(n,0,i.length);s.set(i);this.buffer=n;this._byteLength=t};n.prototype._trimAlloc=function(){if(this._byteLength==this._buffer.byteLength){return}var e=new ArrayBuffer(this._byteLength);var t=new Uint8Array(e);var r=new Uint8Array(this._buffer,0,t.length);t.set(r);this.buffer=e};n.prototype.shift=function(e){var t=new ArrayBuffer(this._byteLength-e);var r=new Uint8Array(t);var n=new Uint8Array(this._buffer,e,r.length);r.set(n);this.buffer=t;this.position-=e};n.prototype.seek=function(e){var t=Math.max(0,Math.min(this.byteLength,e));this.position=isNaN(t)||!isFinite(t)?0:t};n.prototype.isEof=function(){return this.position>=this._byteLength};n.prototype.mapInt32Array=function(e,t){this._realloc(e*4);var r=new Int32Array(this._buffer,this.byteOffset+this.position,e);n.arrayToNative(r,t==null?this.endianness:t);this.position+=e*4;return r};n.prototype.mapInt16Array=function(e,t){this._realloc(e*2);var r=new Int16Array(this._buffer,this.byteOffset+this.position,e);n.arrayToNative(r,t==null?this.endianness:t);this.position+=e*2;return r};n.prototype.mapInt8Array=function(e){this._realloc(e*1);var t=new Int8Array(this._buffer,this.byteOffset+this.position,e);this.position+=e*1;return t};n.prototype.mapUint32Array=function(e,t){this._realloc(e*4);var r=new Uint32Array(this._buffer,this.byteOffset+this.position,e);n.arrayToNative(r,t==null?this.endianness:t);this.position+=e*4;return r};n.prototype.mapUint16Array=function(e,t){this._realloc(e*2);var r=new Uint16Array(this._buffer,this.byteOffset+this.position,e);n.arrayToNative(r,t==null?this.endianness:t);this.position+=e*2;return r};n.prototype.mapUint8Array=function(e){this._realloc(e*1);var t=new Uint8Array(this._buffer,this.byteOffset+this.position,e);this.position+=e*1;return t};n.prototype.mapFloat64Array=function(e,t){this._realloc(e*8);var r=new Float64Array(this._buffer,this.byteOffset+this.position,e);n.arrayToNative(r,t==null?this.endianness:t);this.position+=e*8;return r};n.prototype.mapFloat32Array=function(e,t){this._realloc(e*4);var r=new Float32Array(this._buffer,this.byteOffset+this.position,e);n.arrayToNative(r,t==null?this.endianness:t);this.position+=e*4;return r};n.prototype.readInt32Array=function(e,t){e=e==null?this.byteLength-this.position/4:e;var r=new Int32Array(e);n.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT);n.arrayToNative(r,t==null?this.endianness:t);this.position+=r.byteLength;return r};n.prototype.readInt16Array=function(e,t){e=e==null?this.byteLength-this.position/2:e;var r=new Int16Array(e);n.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT);n.arrayToNative(r,t==null?this.endianness:t);this.position+=r.byteLength;return r};n.prototype.readInt8Array=function(e){e=e==null?this.byteLength-this.position:e;var t=new Int8Array(e);n.memcpy(t.buffer,0,this.buffer,this.byteOffset+this.position,e*t.BYTES_PER_ELEMENT);this.position+=t.byteLength;return t};n.prototype.readUint32Array=function(e,t){e=e==null?this.byteLength-this.position/4:e;var r=new Uint32Array(e);n.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT);n.arrayToNative(r,t==null?this.endianness:t);this.position+=r.byteLength;return r};n.prototype.readUint16Array=function(e,t){e=e==null?this.byteLength-this.position/2:e;var r=new Uint16Array(e);n.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT);n.arrayToNative(r,t==null?this.endianness:t);this.position+=r.byteLength;return r};n.prototype.readUint8Array=function(e){e=e==null?this.byteLength-this.position:e;var t=new Uint8Array(e);n.memcpy(t.buffer,0,this.buffer,this.byteOffset+this.position,e*t.BYTES_PER_ELEMENT);this.position+=t.byteLength;return t};n.prototype.readFloat64Array=function(e,t){e=e==null?this.byteLength-this.position/8:e;var r=new Float64Array(e);n.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT);n.arrayToNative(r,t==null?this.endianness:t);this.position+=r.byteLength;return r};n.prototype.readFloat32Array=function(e,t){e=e==null?this.byteLength-this.position/4:e;var r=new Float32Array(e);n.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT);n.arrayToNative(r,t==null?this.endianness:t);this.position+=r.byteLength;return r};n.prototype.writeInt32Array=function(e,t){this._realloc(e.length*4);if(e instanceof Int32Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapInt32Array(e.length,t)}else{for(var r=0;r<e.length;r++){this.writeInt32(e[r],t)}}};n.prototype.writeInt16Array=function(e,t){this._realloc(e.length*2);if(e instanceof Int16Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapInt16Array(e.length,t)}else{for(var r=0;r<e.length;r++){this.writeInt16(e[r],t)}}};n.prototype.writeInt8Array=function(e){this._realloc(e.length*1);if(e instanceof Int8Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapInt8Array(e.length)}else{for(var t=0;t<e.length;t++){this.writeInt8(e[t])}}};n.prototype.writeUint32Array=function(e,t){this._realloc(e.length*4);if(e instanceof Uint32Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapUint32Array(e.length,t)}else{for(var r=0;r<e.length;r++){this.writeUint32(e[r],t)}}};n.prototype.writeUint16Array=function(e,t){this._realloc(e.length*2);if(e instanceof Uint16Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapUint16Array(e.length,t)}else{for(var r=0;r<e.length;r++){this.writeUint16(e[r],t)}}};n.prototype.writeUint8Array=function(e){this._realloc(e.length*1);if(e instanceof Uint8Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapUint8Array(e.length)}else{for(var t=0;t<e.length;t++){this.writeUint8(e[t])}}};n.prototype.writeFloat64Array=function(e,t){this._realloc(e.length*8);if(e instanceof Float64Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapFloat64Array(e.length,t)}else{for(var r=0;r<e.length;r++){this.writeFloat64(e[r],t)}}};n.prototype.writeFloat32Array=function(e,t){this._realloc(e.length*4);if(e instanceof Float32Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapFloat32Array(e.length,t)}else{for(var r=0;r<e.length;r++){this.writeFloat32(e[r],t)}}};n.prototype.readInt32=function(e){var t=this._dataView.getInt32(this.position,e==null?this.endianness:e);this.position+=4;return t};n.prototype.readInt16=function(e){var t=this._dataView.getInt16(this.position,e==null?this.endianness:e);this.position+=2;return t};n.prototype.readInt8=function(){var e=this._dataView.getInt8(this.position);this.position+=1;return e};n.prototype.readUint32=function(e){var t=this._dataView.getUint32(this.position,e==null?this.endianness:e);this.position+=4;return t};n.prototype.readUint16=function(e){var t=this._dataView.getUint16(this.position,e==null?this.endianness:e);this.position+=2;return t};n.prototype.readUint8=function(){var e=this._dataView.getUint8(this.position);this.position+=1;return e};n.prototype.readFloat32=function(e){var t=this._dataView.getFloat32(this.position,e==null?this.endianness:e);this.position+=4;return t};n.prototype.readFloat64=function(e){var t=this._dataView.getFloat64(this.position,e==null?this.endianness:e);this.position+=8;return t};n.prototype.writeInt32=function(e,t){this._realloc(4);this._dataView.setInt32(this.position,e,t==null?this.endianness:t);this.position+=4};n.prototype.writeInt16=function(e,t){this._realloc(2);this._dataView.setInt16(this.position,e,t==null?this.endianness:t);this.position+=2};n.prototype.writeInt8=function(e){this._realloc(1);this._dataView.setInt8(this.position,e);this.position+=1};n.prototype.writeUint32=function(e,t){this._realloc(4);this._dataView.setUint32(this.position,e,t==null?this.endianness:t);this.position+=4};n.prototype.writeUint16=function(e,t){this._realloc(2);this._dataView.setUint16(this.position,e,t==null?this.endianness:t);this.position+=2};n.prototype.writeUint8=function(e){this._realloc(1);this._dataView.setUint8(this.position,e);this.position+=1};n.prototype.writeFloat32=function(e,t){this._realloc(4);this._dataView.setFloat32(this.position,e,t==null?this.endianness:t);this.position+=4};n.prototype.writeFloat64=function(e,t){this._realloc(8);this._dataView.setFloat64(this.position,e,t==null?this.endianness:t);this.position+=8};n.endianness=new Int8Array(new Int16Array([1]).buffer)[0]>0;n.memcpy=function(e,t,r,n,i){var s=new Uint8Array(e,t,i);var o=new Uint8Array(r,n,i);s.set(o)};n.arrayToNative=function(e,t){if(t==this.endianness){return e}else{return this.flipArrayEndianness(e)}};n.nativeToEndian=function(e,t){if(this.endianness==t){return e}else{return this.flipArrayEndianness(e)}};n.flipArrayEndianness=function(e){var t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);for(var r=0;r<e.byteLength;r+=e.BYTES_PER_ELEMENT){for(var n=r+e.BYTES_PER_ELEMENT-1,i=r;n>i;n--,i++){var s=t[i];t[i]=t[n];t[n]=s}}return e};n.prototype.failurePosition=0;n.prototype.readStruct=function(e){var t={},r,n,i;var s=this.position;for(var o=0;o<e.length;o+=2){r=e[o+1];n=this.readType(r,t);if(n==null){if(this.failurePosition===0){this.failurePosition=this.position}this.position=s;return null}t[e[o]]=n}return t};n.prototype.readUCS2String=function(e,t){return String.fromCharCode.apply(null,this.readUint16Array(e,t))};n.prototype.writeUCS2String=function(e,t,r){if(r==null){r=e.length}for(var n=0;n<e.length&&n<r;n++){this.writeUint16(e.charCodeAt(n),t)}for(;n<r;n++){this.writeUint16(0)}};n.prototype.readString=function(e,t){if(t==null||t=="ASCII"){return String.fromCharCode.apply(null,this.mapUint8Array(e==null?this.byteLength-this.position:e));
-}else{return new TextDecoder(t).decode(this.mapUint8Array(e))}};n.prototype.writeString=function(e,t,r){var n=0;if(t==null||t=="ASCII"){if(r!=null){var i=Math.min(e.length,r);for(n=0;n<i;n++){this.writeUint8(e.charCodeAt(n))}for(;n<r;n++){this.writeUint8(0)}}else{for(n=0;n<e.length;n++){this.writeUint8(e.charCodeAt(n))}}}else{this.writeUint8Array(new TextEncoder(t).encode(e.substring(0,r)))}};n.prototype.readCString=function(e){var t=this.byteLength-this.position;var r=new Uint8Array(this._buffer,this._byteOffset+this.position);var n=t;if(e!=null){n=Math.min(e,t)}for(var i=0;i<n&&r[i]!==0;i++);var s=String.fromCharCode.apply(null,this.mapUint8Array(i));if(e!=null){this.position+=n-i}else if(i!=t){this.position+=1}return s};n.prototype.writeCString=function(e,t){var r=0;if(t!=null){var n=Math.min(e.length,t);for(r=0;r<n;r++){this.writeUint8(e.charCodeAt(r))}for(;r<t;r++){this.writeUint8(0)}}else{for(r=0;r<e.length;r++){this.writeUint8(e.charCodeAt(r))}this.writeUint8(0)}};n.prototype.readType=function(e,t){if(typeof e=="function"){return e(this,t)}else if(typeof e=="object"&&!(e instanceof Array)){return e.get(this,t)}else if(e instanceof Array&&e.length!=3){return this.readStruct(e,t)}var r=null;var i=null;var s="ASCII";var o=this.position;var a;var f;var u;if(typeof e=="string"&&/:/.test(e)){a=e.split(":");e=a[0];i=parseInt(a[1])}if(typeof e=="string"&&/,/.test(e)){a=e.split(",");e=a[0];s=parseInt(a[1])}switch(e){case"uint8":r=this.readUint8();break;case"int8":r=this.readInt8();break;case"uint16":r=this.readUint16(this.endianness);break;case"int16":r=this.readInt16(this.endianness);break;case"uint32":r=this.readUint32(this.endianness);break;case"int32":r=this.readInt32(this.endianness);break;case"float32":r=this.readFloat32(this.endianness);break;case"float64":r=this.readFloat64(this.endianness);break;case"uint16be":r=this.readUint16(n.BIG_ENDIAN);break;case"int16be":r=this.readInt16(n.BIG_ENDIAN);break;case"uint32be":r=this.readUint32(n.BIG_ENDIAN);break;case"int32be":r=this.readInt32(n.BIG_ENDIAN);break;case"float32be":r=this.readFloat32(n.BIG_ENDIAN);break;case"float64be":r=this.readFloat64(n.BIG_ENDIAN);break;case"uint16le":r=this.readUint16(n.LITTLE_ENDIAN);break;case"int16le":r=this.readInt16(n.LITTLE_ENDIAN);break;case"uint32le":r=this.readUint32(n.LITTLE_ENDIAN);break;case"int32le":r=this.readInt32(n.LITTLE_ENDIAN);break;case"float32le":r=this.readFloat32(n.LITTLE_ENDIAN);break;case"float64le":r=this.readFloat64(n.LITTLE_ENDIAN);break;case"cstring":r=this.readCString(i);break;case"string":r=this.readString(i,s);break;case"u16string":r=this.readUCS2String(i,this.endianness);break;case"u16stringle":r=this.readUCS2String(i,n.LITTLE_ENDIAN);break;case"u16stringbe":r=this.readUCS2String(i,n.BIG_ENDIAN);break;default:if(e.length==3){var h=e[1];var l=e[2];var c=0;if(typeof l=="function"){c=l(t,this,e)}else if(typeof l=="string"&&t[l]!=null){c=parseInt(t[l])}else{c=parseInt(l)}if(typeof h=="string"){var d=h.replace(/(le|be)$/,"");var p=null;if(/le$/.test(h)){p=n.LITTLE_ENDIAN}else if(/be$/.test(h)){p=n.BIG_ENDIAN}if(l=="*"){c=null}switch(d){case"uint8":r=this.readUint8Array(c);break;case"uint16":r=this.readUint16Array(c,p);break;case"uint32":r=this.readUint32Array(c,p);break;case"int8":r=this.readInt8Array(c);break;case"int16":r=this.readInt16Array(c,p);break;case"int32":r=this.readInt32Array(c,p);break;case"float32":r=this.readFloat32Array(c,p);break;case"float64":r=this.readFloat64Array(c,p);break;case"cstring":case"utf16string":case"string":if(c==null){r=[];while(!this.isEof()){u=this.readType(h,t);if(u==null)break;r.push(u)}}else{r=new Array(c);for(f=0;f<c;f++){r[f]=this.readType(h,t)}}break}}else{if(l=="*"){r=[];var m=this.buffer;while(true){var g=this.position;try{var v=this.readType(h,t);if(v==null){this.position=g;break}r.push(v)}catch(y){this.position=g;break}}}else{r=new Array(c);for(f=0;f<c;f++){u=this.readType(h,t);if(u==null)return null;r[f]=u}}}break}}if(i!=null){this.position=o+i}return r};n.prototype.writeStruct=function(e,t){for(var r=0;r<e.length;r+=2){var n=e[r+1];this.writeType(n,t[e[r]],t)}};n.prototype.writeType=function(e,t,r){var i;if(typeof e=="function"){return e(this,t)}else if(typeof e=="object"&&!(e instanceof Array)){return e.set(this,t,r)}var s=null;var o="ASCII";var a=this.position;if(typeof e=="string"&&/:/.test(e)){i=e.split(":");e=i[0];s=parseInt(i[1])}if(typeof e=="string"&&/,/.test(e)){i=e.split(",");e=i[0];o=parseInt(i[1])}switch(e){case"uint8":this.writeUint8(t);break;case"int8":this.writeInt8(t);break;case"uint16":this.writeUint16(t,this.endianness);break;case"int16":this.writeInt16(t,this.endianness);break;case"uint32":this.writeUint32(t,this.endianness);break;case"int32":this.writeInt32(t,this.endianness);break;case"float32":this.writeFloat32(t,this.endianness);break;case"float64":this.writeFloat64(t,this.endianness);break;case"uint16be":this.writeUint16(t,n.BIG_ENDIAN);break;case"int16be":this.writeInt16(t,n.BIG_ENDIAN);break;case"uint32be":this.writeUint32(t,n.BIG_ENDIAN);break;case"int32be":this.writeInt32(t,n.BIG_ENDIAN);break;case"float32be":this.writeFloat32(t,n.BIG_ENDIAN);break;case"float64be":this.writeFloat64(t,n.BIG_ENDIAN);break;case"uint16le":this.writeUint16(t,n.LITTLE_ENDIAN);break;case"int16le":this.writeInt16(t,n.LITTLE_ENDIAN);break;case"uint32le":this.writeUint32(t,n.LITTLE_ENDIAN);break;case"int32le":this.writeInt32(t,n.LITTLE_ENDIAN);break;case"float32le":this.writeFloat32(t,n.LITTLE_ENDIAN);break;case"float64le":this.writeFloat64(t,n.LITTLE_ENDIAN);break;case"cstring":this.writeCString(t,s);break;case"string":this.writeString(t,o,s);break;case"u16string":this.writeUCS2String(t,this.endianness,s);break;case"u16stringle":this.writeUCS2String(t,n.LITTLE_ENDIAN,s);break;case"u16stringbe":this.writeUCS2String(t,n.BIG_ENDIAN,s);break;default:if(e.length==3){var f=e[1];for(var u=0;u<t.length;u++){this.writeType(f,t[u])}break}else{this.writeStruct(e,t);break}}if(s!=null){this.position=a;this._realloc(s);this.position=a+s}};var i=Math.pow(2,32);r.MAX_SIZE=i;n.prototype.readUint64=function(){return this.readUint32()*i+this.readUint32()};n.prototype.writeUint64=function(e){var t=Math.floor(e/i);this.writeUint32(t);this.writeUint32(e&4294967295)};n.prototype.readUint24=function(){return(this.readUint8()<<16)+(this.readUint8()<<8)+this.readUint8()};n.prototype.writeUint24=function(e){this.writeUint8((e&16711680)>>16);this.writeUint8((e&65280)>>8);this.writeUint8(e&255)};n.prototype.adjustUint32=function(e,t){var r=this.position;this.seek(e);this.writeUint32(t);this.seek(r)}},{}],159:[function(e,t,r){var n=e("./DataStream");var s=e("./descriptor");var o=e("./log");var a={ERR_NOT_ENOUGH_DATA:0,OK:1,boxCodes:["mdat","avcC","hvcC","ftyp","payl","vmhd","smhd","hmhd","dref","elst"],fullBoxCodes:["mvhd","tkhd","mdhd","hdlr","smhd","hmhd","nhmd","url ","urn ","ctts","cslg","stco","co64","stsc","stss","stsz","stz2","stts","stsh","mehd","trex","mfhd","tfhd","trun","tfdt","esds","subs","txtC"],containerBoxCodes:[["moov",["trak"]],["trak"],["edts"],["mdia"],["minf"],["dinf"],["stbl"],["mvex",["trex"]],["moof",["traf"]],["traf",["trun"]],["vttc"],["tref"]],sampleEntryCodes:[{prefix:"Visual",types:["mp4v","avc1","avc2","avc3","avc4","avcp","drac","encv","mjp2","mvc1","mvc2","resv","s263","svc1","vc-1","hvc1","hev1"]},{prefix:"Audio",types:["mp4a","ac-3","alac","dra1","dtsc","dtse",,"dtsh","dtsl","ec-3","enca","g719","g726","m4ae","mlpa","raw ","samr","sawb","sawp","sevc","sqcp","ssmv","twos"]},{prefix:"Hint",types:["fdp ","m2ts","pm2t","prtp","rm2t","rrtp","rsrp","rtp ","sm2t","srtp"]},{prefix:"Metadata",types:["metx","mett","urim"]},{prefix:"Subtitle",types:["stpp","wvtt","sbtt","tx3g","stxt"]}],trackReferenceTypes:["scal"],initialize:function(){var e,t;var r;a.FullBox.prototype=new a.Box;a.ContainerBox.prototype=new a.Box;a.stsdBox.prototype=new a.FullBox;a.SampleEntry.prototype=new a.FullBox;a.TrackReferenceTypeBox.prototype=new a.Box;r=a.boxCodes.length;for(e=0;e<r;e++){a[a.boxCodes[e]+"Box"]=function(e){return function(t){a.Box.call(this,a.boxCodes[e],t)}}(e);a[a.boxCodes[e]+"Box"].prototype=new a.Box}r=a.fullBoxCodes.length;for(e=0;e<r;e++){a[a.fullBoxCodes[e]+"Box"]=function(e){return function(t){a.FullBox.call(this,a.fullBoxCodes[e],t)}}(e);a[a.fullBoxCodes[e]+"Box"].prototype=new a.FullBox}r=a.containerBoxCodes.length;for(e=0;e<r;e++){a[a.containerBoxCodes[e][0]+"Box"]=function(e,t){return function(r){a.ContainerBox.call(this,a.containerBoxCodes[e][0],r);if(t){this.subBoxNames=t;var n=t.length;for(var i=0;i<n;i++){this[t[i]+"s"]=[]}}}}(e,a.containerBoxCodes[e][1]);a[a.containerBoxCodes[e][0]+"Box"].prototype=new a.ContainerBox}r=a.sampleEntryCodes.length;for(t=0;t<r;t++){var n=a.sampleEntryCodes[t].prefix;var i=a.sampleEntryCodes[t].types;var s=i.length;a[n+"SampleEntry"]=function(e,t){a.SampleEntry.call(this,e,t)};a[n+"SampleEntry"].prototype=new a.SampleEntry;for(e=0;e<s;e++){a[i[e]+"Box"]=function(e,t){return function(r){a[a.sampleEntryCodes[e].prefix+"SampleEntry"].call(this,a.sampleEntryCodes[e].types[t],r)}}(t,e);a[i[e]+"Box"].prototype=new a[n+"SampleEntry"]}}r=a.trackReferenceTypes.length;for(e=0;e<r;e++){a[a.trackReferenceTypes[e]+"Box"]=function(e){return function(t){a.TrackReferenceTypeBox.call(this,a.trackReferenceTypes[e],t)}}(e);a[a.trackReferenceTypes[e]+"Box"].prototype=new a.Box}},Box:function(e,t){this.type=e;this.size=t},FullBox:function(e,t){a.Box.call(this,e,t);this.flags=0;this.version=0},ContainerBox:function(e,t){a.Box.call(this,e,t);this.boxes=[]},SampleEntry:function(e,t){a.Box.call(this,e,t);this.boxes=[]},TrackReferenceTypeBox:function(e,t){a.Box.call(this,e,t);this.track_ids=[]},stsdBox:function(e){a.FullBox.call(this,"stsd",e);this.entries=[]},parseOneBox:function(e,t){var r;var n=e.position;var i=0;if(e.byteLength-e.position<8){o.d("BoxParser","Not enough data in stream to parse the type and size of the box");return{code:a.ERR_NOT_ENOUGH_DATA}}var s=e.readUint32();var f=e.readString(4);o.d("BoxParser","Found box of type "+f+" and size "+s+" at position "+n+" in the current buffer ("+(e.buffer.fileStart+n)+" in the file)");i=8;if(s==1){if(e.byteLength-e.position<8){e.seek(n);o.w("BoxParser",'Not enough data in stream to parse the extended size of the "'+f+'" box');return{code:a.ERR_NOT_ENOUGH_DATA}}s=e.readUint64();i+=8}else if(s===0){throw"Unlimited box size not supported"}if(n+s>e.byteLength){e.seek(n);o.w("BoxParser",'Not enough data in stream to parse the entire "'+f+'" box');return{code:a.ERR_NOT_ENOUGH_DATA,type:f,size:s,hdr_size:i}}if(a[f+"Box"]){r=new a[f+"Box"](s-i)}else{if(t){r=new a.SampleEntry(f,s-i)}else{r=new a.Box(f,s-i)}}r.hdr_size=i;r.start=n;r.fileStart=n+e.buffer.fileStart;r.parse(e);e.seek(n+s);return{code:a.OK,box:r,size:s}}};t.exports=a;a.initialize();a.Box.prototype.parse=function(e){if(this.type!="mdat"){this.data=e.readUint8Array(this.size)}else{e.seek(this.start+this.size+this.hdr_size)}};a.FullBox.prototype.parseFullHeader=function(e){this.version=e.readUint8();this.flags=e.readUint24();this.size-=4};a.ContainerBox.prototype.parse=function(e){var t;var r;var n;n=e.position;while(e.position<n+this.size){t=a.parseOneBox(e);r=t.box;this.boxes.push(r);if(this.subBoxNames&&this.subBoxNames.indexOf(r.type)!=-1){this[this.subBoxNames+"s"].push(r)}else{this[r.type]=r}}};a.SampleEntry.prototype.isVideo=function(){return false};a.SampleEntry.prototype.isAudio=function(){return false};a.SampleEntry.prototype.isSubtitle=function(){return false};a.SampleEntry.prototype.isMetadata=function(){return false};a.SampleEntry.prototype.isHint=function(){return false};a.SampleEntry.prototype.getCodec=function(){return this.type};a.SampleEntry.prototype.getWidth=function(){return""};a.SampleEntry.prototype.getHeight=function(){return""};a.SampleEntry.prototype.getChannelCount=function(){return""};a.SampleEntry.prototype.getSampleRate=function(){return""};a.SampleEntry.prototype.getSampleSize=function(){return""};a.SampleEntry.prototype.parseHeader=function(e){this.start=e.position;e.readUint8Array(6);this.data_reference_index=e.readUint16()};a.SampleEntry.prototype.parse=function(e){this.parseHeader(e);e.seek(this.start+this.size)};a.SampleEntry.prototype.parseFooter=function(e){var t;var r;while(e.position<this.start+this.size){t=a.parseOneBox(e,false);r=t.box;this.boxes.push(r);this[r.type]=r}};a.VisualSampleEntry.prototype.parse=function(e){this.parseHeader(e);e.readUint16();e.readUint16();e.readUint32Array(3);this.width=e.readUint16();this.height=e.readUint16();this.horizresolution=e.readUint32();this.vertresolution=e.readUint32();e.readUint32();this.frame_count=e.readUint16();this.compressorname=e.readString(32);this.depth=e.readUint16();e.readUint16();this.parseFooter(e)};a.VisualSampleEntry.prototype.isVideo=function(){return true};a.VisualSampleEntry.prototype.getWidth=function(){return this.width};a.VisualSampleEntry.prototype.getHeight=function(){return this.height};a.AudioSampleEntry.prototype.parse=function(e){this.parseHeader(e);e.readUint32Array(2);this.channel_count=e.readUint16();this.samplesize=e.readUint16();e.readUint16();e.readUint16();this.samplerate=e.readUint32()/(1<<16);this.parseFooter(e)};a.AudioSampleEntry.prototype.isAudio=function(){return true};a.AudioSampleEntry.prototype.getChannelCount=function(){return this.channel_count};a.AudioSampleEntry.prototype.getSampleRate=function(){return this.samplerate};a.AudioSampleEntry.prototype.getSampleSize=function(){return this.samplesize};a.SubtitleSampleEntry.prototype.parse=function(e){this.parseHeader(e);this.parseFooter(e)};a.SubtitleSampleEntry.prototype.isSubtitle=function(){return true};a.MetadataSampleEntry.prototype.parse=function(e){this.parseHeader(e);this.parseFooter(e)};a.MetadataSampleEntry.prototype.isMetadata=function(){return true};a.TrackReferenceTypeBox.prototype.parse=function(e){this.track_ids=e.readUint8Array(this.size)};a.metxBox.prototype.parse=function(e){this.parseHeader(e);this.content_encoding=e.readCString();this.namespace=e.readCString();this.schema_location=e.readCString();this.parseFooter(e)};a.mettBox.prototype.parse=function(e){this.parseHeader(e);this.content_encoding=e.readCString();this.mime_format=e.readCString();this.parseFooter(e)};a.sbttBox.prototype.parse=function(e){this.parseHeader(e);this.content_encoding=e.readCString();this.mime_format=e.readCString();this.parseFooter(e)};a.stxtBox.prototype.parse=function(e){this.parseHeader(e);this.content_encoding=e.readCString();this.mime_format=e.readCString();this.parseFooter(e)};a.stppBox.prototype.parse=function(e){this.parseHeader(e);this.namespace=e.readCString();this.schema_location=e.readCString();this.auxiliary_mime_types=e.readCString();this.parseFooter(e)};a.tx3gBox.prototype.parse=function(e){this.parseHeader(e);this.displayFlags=e.readUint32();this.horizontal_justification=e.readInt8();this.vertical_justification=e.readInt8();this.bg_color_rgba=e.readUint8Array(4);this.box_record=e.readInt16Array(4);this.style_record=e.readUint8Array(12);this.parseFooter(e)};a.ftypBox.prototype.parse=function(e){this.major_brand=e.readString(4);this.minor_version=e.readUint32();this.size-=8;this.compatible_brands=[];var t=0;while(this.size>=4){this.compatible_brands[t]=e.readString(4);this.size-=4;t++}};a.mvhdBox.prototype.parse=function(e){this.flags=0;this.parseFullHeader(e);if(this.version==1){this.creation_time=e.readUint64();this.modification_time=e.readUint64();this.timescale=e.readUint32();this.duration=e.readUint64()}else{this.creation_time=e.readUint32();this.modification_time=e.readUint32();this.timescale=e.readUint32();this.duration=e.readUint32()}this.rate=e.readUint32();this.volume=e.readUint16()>>8;e.readUint16();e.readUint32Array(2);this.matrix=e.readUint32Array(9);e.readUint32Array(6);this.next_track_id=e.readUint32()};a.TKHD_FLAG_ENABLED=1;a.TKHD_FLAG_IN_MOVIE=2;a.TKHD_FLAG_IN_PREVIEW=4;a.tkhdBox.prototype.parse=function(e){this.parseFullHeader(e);if(this.version==1){this.creation_time=e.readUint64();this.modification_time=e.readUint64();this.track_id=e.readUint32();e.readUint32();this.duration=e.readUint64()}else{this.creation_time=e.readUint32();this.modification_time=e.readUint32();this.track_id=e.readUint32();e.readUint32();this.duration=e.readUint32()}e.readUint32Array(2);this.layer=e.readInt16();this.alternate_group=e.readInt16();this.volume=e.readInt16()>>8;e.readUint16();this.matrix=e.readInt32Array(9);this.width=e.readUint32();this.height=e.readUint32()};a.mdhdBox.prototype.parse=function(e){this.parseFullHeader(e);if(this.version==1){this.creation_time=e.readUint64();this.modification_time=e.readUint64();this.timescale=e.readUint32();this.duration=e.readUint64()}else{this.creation_time=e.readUint32();this.modification_time=e.readUint32();this.timescale=e.readUint32();this.duration=e.readUint32()}this.language=e.readUint16();var t=[];t[0]=this.language>>10&31;t[1]=this.language>>5&31;t[2]=this.language&31;this.languageString=String.fromCharCode(t[0]+96,t[1]+96,t[2]+96);e.readUint16()};a.hdlrBox.prototype.parse=function(e){this.parseFullHeader(e);if(this.version===0){e.readUint32();this.handler=e.readString(4);e.readUint32Array(3);this.name=e.readCString()}else{this.data=e.readUint8Array(size)}};a.stsdBox.prototype.parse=function(e){var t;var r;this.parseFullHeader(e);r=e.readUint32();for(i=1;i<=r;i++){t=a.parseOneBox(e,true);this.entries.push(t.box)}};a.avcCBox.prototype.parse=function(e){var t;var r;var n;this.configurationVersion=e.readUint8();this.AVCProfileIndication=e.readUint8();this.profile_compatibility=e.readUint8();this.AVCLevelIndication=e.readUint8();this.lengthSizeMinusOne=e.readUint8()&3;r=e.readUint8()&31;this.size-=6;this.SPS=new Array(r);for(t=0;t<r;t++){n=e.readUint16();this.SPS[t]=e.readUint8Array(n);this.size-=2+n}r=e.readUint8();this.size--;this.PPS=new Array(r);for(t=0;t<r;t++){n=e.readUint16();this.PPS[t]=e.readUint8Array(n);this.size-=2+n}if(this.size>0){this.ext=e.readUint8Array(this.size)}};a.hvcCBox.prototype.parse=function(e){var t;var r;var n;var i;this.configurationVersion=e.readUint8();i=e.readUint8();this.general_profile_space=i>>6;this.general_tier_flag=(i&32)>>5;this.general_profile_idc=i&31;this.general_profile_compatibility=e.readUint32();this.general_constraint_indicator=e.readUint8Array(6);this.general_level_idc=e.readUint8();this.min_spatial_segmentation_idc=e.readUint16()&4095;this.parallelismType=e.readUint8()&3;this.chromaFormat=e.readUint8()&3;this.bitDepthLumaMinus8=e.readUint8()&7;this.bitDepthChromaMinus8=e.readUint8()&7;this.avgFrameRate=e.readUint16();i=e.readUint8();this.constantFrameRate=i>>6;this.numTemporalLayers=(i&13)>>3;this.temporalIdNested=(i&4)>>2;this.lengthSizeMinusOne=i&3;this.nalu_arrays=[];numOfArrays=e.readUint8();for(t=0;t<numOfArrays;t++){var s=[];this.nalu_arrays.push(s);i=e.readUint8();s.completeness=(i&128)>>7;s.nalu_type=i&63;numNalus=e.readUint16();for(j=0;j<numNalus;j++){var o={};s.push(o);n=e.readUint16();o.data=e.readUint8Array(n)}}};function f(e,t){var r=Number(e).toString(16);t=typeof t==="undefined"||t===null?t=2:t;while(r.length<t){r="0"+r}return r}a.avc1Box.prototype.getCodec=function(){var e=a.SampleEntry.prototype.getCodec.call(this);if(this.avcC){return e+"."+f(this.avcC.AVCProfileIndication)+""+f(this.avcC.profile_compatibility)+""+f(this.avcC.AVCLevelIndication)}else{return e}};a.hvc1Box.prototype.getCodec=function(){var e;var t=a.SampleEntry.prototype.getCodec.call(this);if(this.hvcC){t+=".";switch(this.hvcC.general_profile_space){case 0:t+="";break;case 1:t+="A";break;case 2:t+="B";break;case 3:t+="C";break}t+=this.hvcC.general_profile_idc;t+=".";var r=this.hvcC.general_profile_compatibility;var n=0;for(e=0;e<32;e++){n|=r&1;if(e==31)break;n<<=1;r>>=1}t+=f(n,0);t+=".";if(this.hvcC.general_tier_flag===0){t+="L"}else{t+="H"}t+=this.hvcC.general_level_idc;var i=false;var s="";for(e=5;e>=0;e--){if(this.hvcC.general_constraint_indicator[e]||i){s="."+f(this.hvcC.general_constraint_indicator[e],0)+s;i=true}}t+=s}return t};a.mp4aBox.prototype.getCodec=function(){var e=a.SampleEntry.prototype.getCodec.call(this);if(this.esds&&this.esds.esd){var t=this.esds.esd.getOTI();var r=this.esds.esd.getAudioConfig();return e+"."+f(t)+(r?"."+r:"")}else{return e}};a.esdsBox.prototype.parse=function(e){this.parseFullHeader(e);this.data=e.readUint8Array(this.size);this.size=0;var t=new s;this.esd=t.parseOneDescriptor(new n(this.data.buffer,0,n.BIG_ENDIAN))};a.txtCBox.prototype.parse=function(e){this.parseFullHeader(e);this.config=e.readCString()};a.cttsBox.prototype.parse=function(e){var t;var r;this.parseFullHeader(e);t=e.readUint32();this.sample_counts=[];this.sample_offsets=[];if(this.version===0){for(r=0;r<t;r++){this.sample_counts.push(e.readUint32());this.sample_offsets.push(e.readInt32())}}else if(this.version==1){for(r=0;r<t;r++){this.sample_counts.push(e.readUint32());this.sample_offsets.push(e.readInt32())}}else{this.data=e.readUint8Array(this.size-4)}};a.cttsBox.prototype.unpack=function(e){var t,r,n;n=0;for(t=0;t<this.sample_counts.length;t++){for(r=0;r<this.sample_counts[t];r++){e[n].pts=e[n].dts+this.sample_offsets[t];n++}}};a.cslgBox.prototype.parse=function(e){var t;this.parseFullHeader(e);if(this.version===0){this.compositionToDTSShift=e.readInt32();this.leastDecodeToDisplayDelta=e.readInt32();this.greatestDecodeToDisplayDelta=e.readInt32();this.compositionStartTime=e.readInt32();this.compositionEndTime=e.readInt32()}else{this.data=e.readUint8Array(this.size-4)}};a.sttsBox.prototype.parse=function(e){var t;var r;this.parseFullHeader(e);t=e.readUint32();this.sample_counts=[];this.sample_deltas=[];if(this.version===0){for(r=0;r<t;r++){this.sample_counts.push(e.readUint32());this.sample_deltas.push(e.readUint32())}}else{this.data=e.readUint8Array(this.size-4)}};a.sttsBox.prototype.unpack=function(e){var t,r,n;n=0;for(t=0;t<this.sample_counts.length;t++){for(r=0;r<this.sample_counts[t];r++){if(n===0){e[n].dts=0}else{e[n].dts=e[n-1].dts+this.sample_deltas[t]}n++}}};a.stssBox.prototype.parse=function(e){var t;this.parseFullHeader(e);t=e.readUint32();if(this.version===0){this.sample_numbers=e.readUint32Array(t)}else{this.data=e.readUint8Array(this.size-4)}};a.stshBox.prototype.parse=function(e){var t;var r;this.parseFullHeader(e);t=e.readUint32();this.shadowed_sample_numbers=[];this.sync_sample_numbers=[];if(this.version===0){for(r=0;r<t;r++){this.shadowed_sample_numbers.push(e.readUint32());this.sync_sample_numbers.push(e.readUint32())}}else{this.data=e.readUint8Array(this.size-4)}};a.stcoBox.prototype.parse=function(e){var t;this.parseFullHeader(e);t=e.readUint32();if(this.version===0){this.chunk_offsets=e.readUint32Array(t)}else{this.data=e.readUint8Array(this.size-4)}};a.stcoBox.prototype.unpack=function(e){var t;for(t=0;t<this.chunk_offsets.length;t++){e[t].offset=this.chunk_offsets[t]}};a.co64Box.prototype.parse=function(e){var t;var r;this.parseFullHeader(e);t=e.readUint32();this.chunk_offsets=[];if(this.version===0){for(r=0;r<t;r++){this.chunk_offsets.push(e.readUint64())}}else{this.data=e.readUint8Array(this.size-4)}};a.stscBox.prototype.parse=function(e){var t;var r;this.parseFullHeader(e);t=e.readUint32();this.first_chunk=[];this.samples_per_chunk=[];this.sample_description_index=[];if(this.version===0){for(r=0;r<t;r++){this.first_chunk.push(e.readUint32());this.samples_per_chunk.push(e.readUint32());this.sample_description_index.push(e.readUint32())}}else{this.data=e.readUint8Array(this.size-4)}};a.stscBox.prototype.unpack=function(e){var t,r,n,i,s;i=0;s=0;for(t=0;t<this.first_chunk.length;t++){for(r=0;r<(t+1<this.first_chunk.length?this.first_chunk[t+1]:Infinity);r++){s++;for(n=0;n<this.samples_per_chunk[t];n++){if(e[i]){e[i].description_index=this.sample_description_index[t];e[i].chunk_index=s}else{return}i++}}}};a.stszBox.prototype.parse=function(e){var t;var r;var n;this.parseFullHeader(e);this.sample_sizes=[];if(this.version===0){r=e.readUint32();n=e.readUint32();if(r===0){this.sample_sizes=e.readUint32Array(n)}else{this.sample_sizes=[];for(t=0;t<n;t++){this.sample_sizes[t]=r}}}else{this.data=e.readUint8Array(this.size)}};a.stszBox.prototype.unpack=function(e){var t;for(t=0;t<this.sample_sizes.length;t++){e[t].size=this.sample_sizes[t]}};a.mehdBox.prototype.parse=function(e){this.parseFullHeader(e);if(this.version==1){this.fragment_duration=e.readUint64()}else{this.fragment_duration=e.readUint32()}};a.trexBox.prototype.parse=function(e){this.parseFullHeader(e);this.track_id=e.readUint32();this.default_sample_description_index=e.readUint32();this.default_sample_duration=e.readUint32();this.default_sample_size=e.readUint32();this.default_sample_flags=e.readUint32()};a.mfhdBox.prototype.parse=function(e){this.parseFullHeader(e);this.sequence_number=e.readUint32()};a.TFHD_FLAG_BASE_DATA_OFFSET=1;a.TFHD_FLAG_SAMPLE_DESC=2;a.TFHD_FLAG_SAMPLE_DUR=8;a.TFHD_FLAG_SAMPLE_SIZE=16;a.TFHD_FLAG_SAMPLE_FLAGS=32;a.TFHD_FLAG_DUR_EMPTY=65536;a.TFHD_FLAG_DEFAULT_BASE_IS_MOOF=131072;a.tfhdBox.prototype.parse=function(e){var t=0;this.parseFullHeader(e);this.track_id=e.readUint32();if(this.size>t&&this.flags&a.TFHD_FLAG_BASE_DATA_OFFSET){this.base_data_offset=e.readUint64();t+=8}else{this.base_data_offset=0}if(this.size>t&&this.flags&a.TFHD_FLAG_SAMPLE_DESC){this.default_sample_description_index=e.readUint32();t+=4}else{this.default_sample_description_index=0}if(this.size>t&&this.flags&a.TFHD_FLAG_SAMPLE_DUR){this.default_sample_duration=e.readUint32();t+=4}else{this.default_sample_duration=0}if(this.size>t&&this.flags&a.TFHD_FLAG_SAMPLE_SIZE){this.default_sample_size=e.readUint32();t+=4}else{this.default_sample_size=0}if(this.size>t&&this.flags&a.TFHD_FLAG_SAMPLE_FLAGS){this.default_sample_flags=e.readUint32();t+=4}else{this.default_sample_flags=0}};a.TRUN_FLAGS_DATA_OFFSET=1;a.TRUN_FLAGS_FIRST_FLAG=4;a.TRUN_FLAGS_DURATION=256;a.TRUN_FLAGS_SIZE=512;a.TRUN_FLAGS_FLAGS=1024;a.TRUN_FLAGS_CTS_OFFSET=2048;a.trunBox.prototype.parse=function(e){var t=0;this.parseFullHeader(e);this.sample_count=e.readUint32();t+=4;if(this.size>t&&this.flags&a.TRUN_FLAGS_DATA_OFFSET){this.data_offset=e.readInt32();t+=4}else{this.data_offset=0}if(this.size>t&&this.flags&a.TRUN_FLAGS_FIRST_FLAG){this.first_sample_flags=e.readUint32();t+=4}else{this.first_sample_flags=0}this.sample_duration=[];this.sample_size=[];this.sample_flags=[];this.sample_composition_time_offset=[];if(this.size>t){for(var r=0;r<this.sample_count;r++){if(this.flags&a.TRUN_FLAGS_DURATION){this.sample_duration[r]=e.readUint32()}if(this.flags&a.TRUN_FLAGS_SIZE){this.sample_size[r]=e.readUint32()}if(this.flags&a.TRUN_FLAGS_FLAGS){this.sample_flags[r]=e.readUint32()}if(this.flags&a.TRUN_FLAGS_CTS_OFFSET){if(this.version===0){this.sample_composition_time_offset[r]=e.readUint32()}else{this.sample_composition_time_offset[r]=e.readInt32()}}}}};a.tfdtBox.prototype.parse=function(e){this.parseFullHeader(e);if(this.version==1){this.baseMediaDecodeTime=e.readUint64()}else{this.baseMediaDecodeTime=e.readUint32()}};a.paylBox.prototype.parse=function(e){this.text=e.readString(this.size)};a.subsBox.prototype.parse=function(e){var t,r;var n;var i;this.parseFullHeader(e);n=e.readUint32();this.samples=[];for(t=0;t<n;t++){var s={};this.samples[t]=s;s.sample_delta=e.readUint32();s.subsamples=[];i=e.readUint16();if(i>0){for(r=0;r<i;r++){var o={};s.subsamples.push(o);if(this.version==1){o.size=e.readUint32()}else{o.size=e.readUint16()}o.priority=e.readUint8();o.discardable=e.readUint8();o.reserved=e.readUint32()}}}};a.Box.prototype.writeHeader=function(e,t){this.size+=8;if(this.size>n.MAX_SIZE){this.size+=8}o.d("BoxWriter","Writing box "+this.type+" of size: "+this.size+" at position "+e.position+(t||""));if(this.size>n.MAX_SIZE){e.writeUint32(1)}else{this.sizePosition=e.position;e.writeUint32(this.size)}e.writeString(this.type,null,4);if(this.size>n.MAX_SIZE){e.writeUint64(this.size)}};a.FullBox.prototype.writeHeader=function(e){this.size+=4;a.Box.prototype.writeHeader.call(this,e," v="+this.version+" f="+this.flags);e.writeUint8(this.version);e.writeUint24(this.flags)};a.Box.prototype.write=function(e){if(this.type==="mdat"){if(this.data){this.size=this.data.length;this.writeHeader(e);e.writeUint8Array(this.data)}}else{this.size=this.data.length;this.writeHeader(e);e.writeUint8Array(this.data)}};a.ContainerBox.prototype.write=function(e){this.size=0;this.writeHeader(e);for(var t=0;t<this.boxes.length;t++){if(this.boxes[t]){this.boxes[t].write(e);this.size+=this.boxes[t].size}}o.d("BoxWriter","Adjusting box "+this.type+" with new size "+this.size);e.adjustUint32(this.sizePosition,this.size)};a.TrackReferenceTypeBox.prototype.write=function(e){this.size=this.track_ids.length*4;this.writeHeader(e);e.writeUint32Array(this.track_ids)};a.ftypBox.prototype.write=function(e){this.size=8+4*this.compatible_brands.length;this.writeHeader(e);e.writeString(this.major_brand,null,4);e.writeUint32(this.minor_version);for(var t=0;t<this.compatible_brands.length;t++){e.writeString(this.compatible_brands[t],null,4)}};a.mvhdBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=23*4+2*2;this.writeHeader(e);e.writeUint32(this.creation_time);e.writeUint32(this.modification_time);e.writeUint32(this.timescale);e.writeUint32(this.duration);e.writeUint32(this.rate);e.writeUint16(this.volume<<8);e.writeUint16(0);e.writeUint32(0);e.writeUint32(0);e.writeUint32Array(this.matrix);e.writeUint32(0);e.writeUint32(0);e.writeUint32(0);e.writeUint32(0);e.writeUint32(0);e.writeUint32(0);e.writeUint32(this.next_track_id)};a.tkhdBox.prototype.write=function(e){this.version=0;this.size=4*18+2*4;this.writeHeader(e);e.writeUint32(this.creation_time);e.writeUint32(this.modification_time);e.writeUint32(this.track_id);e.writeUint32(0);e.writeUint32(this.duration);e.writeUint32(0);e.writeUint32(0);e.writeInt16(this.layer);e.writeInt16(this.alternate_group);e.writeInt16(this.volume<<8);e.writeUint16(0);e.writeInt32Array(this.matrix);e.writeUint32(this.width);e.writeUint32(this.height)};a.mdhdBox.prototype.write=function(e){this.size=4*4+2*2;this.flags=0;this.version=0;this.writeHeader(e);e.writeUint32(this.creation_time);e.writeUint32(this.modification_time);e.writeUint32(this.timescale);e.writeUint32(this.duration);e.writeUint16(this.language);e.writeUint16(0)};a.hdlrBox.prototype.write=function(e){this.size=5*4+this.name.length+1;this.version=0;this.flags=0;this.writeHeader(e);e.writeUint32(0);e.writeString(this.handler,null,4);e.writeUint32(0);e.writeUint32(0);e.writeUint32(0);e.writeCString(this.name)};a.stsdBox.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=0;this.writeHeader(e);e.writeUint32(this.entries.length);this.size+=4;for(t=0;t<this.entries.length;t++){this.entries[t].write(e);this.size+=this.entries[t].size}o.d("BoxWriter","Adjusting box "+this.type+" with new size "+this.size);e.adjustUint32(this.sizePosition,this.size)};a.SampleEntry.prototype.writeHeader=function(e){this.size=8;a.Box.prototype.writeHeader.call(this,e);e.writeUint8(0);e.writeUint8(0);e.writeUint8(0);e.writeUint8(0);e.writeUint8(0);e.writeUint8(0);e.writeUint16(this.data_reference_index)};a.SampleEntry.prototype.writeFooter=function(e){for(var t=0;t<this.boxes.length;t++){this.boxes[t].write(e);this.size+=this.boxes[t].size}o.d("BoxWriter","Adjusting box "+this.type+" with new size "+this.size);e.adjustUint32(this.sizePosition,this.size)};a.SampleEntry.prototype.write=function(e){this.writeHeader(e);this.writeFooter(e)};a.VisualSampleEntry.prototype.write=function(e){this.writeHeader(e);this.size+=2*7+6*4+32;e.writeUint16(0);e.writeUint16(0);e.writeUint32(0);e.writeUint32(0);e.writeUint32(0);e.writeUint16(this.width-this.width%2);e.writeUint16(this.height-this.height%2);e.writeUint32(this.horizresolution);e.writeUint32(this.vertresolution);e.writeUint32(0);e.writeUint16(this.frame_count);e.writeString(this.compressorname,null,32);e.writeUint16(this.depth);e.writeInt16(-1);this.writeFooter(e)};a.AudioSampleEntry.prototype.write=function(e){this.writeHeader(e);this.size+=2*4+3*4;e.writeUint32(0);e.writeUint32(0);e.writeUint16(this.channel_count);e.writeUint16(this.samplesize);
-e.writeUint16(0);e.writeUint16(0);e.writeUint32(this.samplerate<<16);this.writeFooter(e)};a.avcCBox.prototype.write=function(e){var t;this.size=7;for(t=0;t<this.SPS.length;t++){this.size+=2+this.SPS[t].length}for(t=0;t<this.PPS.length;t++){this.size+=2+this.PPS[t].length}if(this.ext){this.size+=this.ext.length}this.writeHeader(e);e.writeUint8(this.configurationVersion);e.writeUint8(this.AVCProfileIndication);e.writeUint8(this.profile_compatibility);e.writeUint8(this.AVCLevelIndication);e.writeUint8(this.lengthSizeMinusOne+(63<<2));e.writeUint8(this.SPS.length+(7<<5));for(t=0;t<this.SPS.length;t++){e.writeUint16(this.SPS[t].length);e.writeUint8Array(this.SPS[t])}e.writeUint8(this.PPS.length);for(t=0;t<this.PPS.length;t++){e.writeUint16(this.PPS[t].length);e.writeUint8Array(this.PPS[t])}if(this.ext){e.writeUint8Array(this.ext)}};a.cttsBox.prototype.write=function(e){var t;this.version=1;this.flags=0;this.size=4+8*this.sample_counts.length;this.writeHeader(e);e.writeUint32(this.sample_counts.length);for(t=0;t<this.sample_counts.length;t++){e.writeUint32(this.sample_counts[t]);e.writeInt32(this.sample_offsets[t])}};a.cslgBox.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=4*5;this.writeHeader(e);e.writeInt32(this.compositionToDTSShift);e.writeInt32(this.leastDecodeToDisplayDelta);e.writeInt32(this.greatestDecodeToDisplayDelta);e.writeInt32(this.compositionStartTime);e.writeInt32(this.compositionEndTime)};a.sttsBox.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=4+8*this.sample_counts.length;this.writeHeader(e);e.writeUint32(this.sample_counts.length);for(t=0;t<this.sample_counts.length;t++){e.writeUint32(this.sample_counts[t]);e.writeUint32(this.sample_deltas[t])}};a.stssBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=4+4*this.sample_numbers.length;this.writeHeader(e);e.writeUint32(this.sample_numbers.length);e.writeUint32Array(this.sample_numbers)};a.stshBox.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=4+8*this.shadowed_sample_numbers.length;this.writeHeader(e);e.writeUint32(this.shadowed_sample_numbers.length);for(t=0;t<this.shadowed_sample_numbers.length;t++){e.writeUint32(this.shadowed_sample_numbers[t]);e.writeUint32(this.sync_sample_numbers[t])}};a.stcoBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=4+4*this.chunk_offsets.length;this.writeHeader(e);e.writeUint32(this.chunk_offsets.length);e.writeUint32Array(this.chunk_offsets)};a.co64Box.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=4+8*this.chunk_offsets.length;this.writeHeader(e);e.writeUint32(this.chunk_offsets.length);for(t=0;t<this.chunk_offsets.length;t++){e.writeUint64(this.chunk_offsets[t])}};a.stscBox.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=4+12*this.first_chunk.length;this.writeHeader(e);e.writeUint32(this.first_chunk.length);for(t=0;t<this.first_chunk.length;t++){e.writeUint32(this.first_chunk[t]);e.writeUint32(this.samples_per_chunk[t]);e.writeUint32(this.sample_description_index[t])}};a.stszBox.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=8+12*this.sample_sizes.length;this.writeHeader(e);e.writeUint32(0);e.writeUint32(this.sample_sizes.length);e.writeUint32Array(this.sample_sizes)};a.mehdBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=4;this.writeHeader(e);e.writeUint32(this.fragment_duration)};a.trexBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=4*5;this.writeHeader(e);e.writeUint32(this.track_id);e.writeUint32(this.default_sample_description_index);e.writeUint32(this.default_sample_duration);e.writeUint32(this.default_sample_size);e.writeUint32(this.default_sample_flags)};a.mfhdBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=4;this.writeHeader(e);e.writeUint32(this.sequence_number)};a.tfhdBox.prototype.write=function(e){this.version=0;this.size=4;if(this.flags&a.TFHD_FLAG_BASE_OFFSET){this.size+=8}if(this.flags&a.TFHD_FLAG_SAMPLE_DESC){this.size+=4}if(this.flags&a.TFHD_FLAG_SAMPLE_DUR){this.size+=4}if(this.flags&a.TFHD_FLAG_SAMPLE_SIZE){this.size+=4}if(this.flags&a.TFHD_FLAG_SAMPLE_FLAGS){this.size+=4}this.writeHeader(e);e.writeUint32(this.track_id);if(this.flags&a.TFHD_FLAG_BASE_OFFSET){e.writeUint64(this.base_data_offset)}if(this.flags&a.TFHD_FLAG_SAMPLE_DESC){e.writeUint32(this.default_sample_description_index)}if(this.flags&a.TFHD_FLAG_SAMPLE_DUR){e.writeUint32(this.default_sample_duration)}if(this.flags&a.TFHD_FLAG_SAMPLE_SIZE){e.writeUint32(this.default_sample_size)}if(this.flags&a.TFHD_FLAG_SAMPLE_FLAGS){e.writeUint32(this.default_sample_flags)}};a.trunBox.prototype.write=function(e){this.version=0;this.size=4;if(this.flags&a.TRUN_FLAGS_DATA_OFFSET){this.size+=4}if(this.flags&a.TRUN_FLAGS_FIRST_FLAG){this.size+=4}if(this.flags&a.TRUN_FLAGS_DURATION){this.size+=4*this.sample_duration.length}if(this.flags&a.TRUN_FLAGS_SIZE){this.size+=4*this.sample_size.length}if(this.flags&a.TRUN_FLAGS_FLAGS){this.size+=4*this.sample_flags.length}if(this.flags&a.TRUN_FLAGS_CTS_OFFSET){this.size+=4*this.sample_composition_time_offset.length}this.writeHeader(e);e.writeUint32(this.sample_count);if(this.flags&a.TRUN_FLAGS_DATA_OFFSET){this.data_offset_position=e.position;e.writeInt32(this.data_offset)}if(this.flags&a.TRUN_FLAGS_FIRST_FLAG){e.writeUint32(this.first_sample_flags)}for(var t=0;t<this.sample_count;t++){if(this.flags&a.TRUN_FLAGS_DURATION){e.writeUint32(this.sample_duration[t])}if(this.flags&a.TRUN_FLAGS_SIZE){e.writeUint32(this.sample_size[t])}if(this.flags&a.TRUN_FLAGS_FLAGS){e.writeUint32(this.sample_flags[t])}if(this.flags&a.TRUN_FLAGS_CTS_OFFSET){if(this.version===0){e.writeUint32(this.sample_composition_time_offset[t])}else{e.writeInt32(this.sample_composition_time_offset[t])}}}};a.tfdtBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=4;this.writeHeader(e);if(this.version==1){e.writeUint64(this.baseMediaDecodeTime)}else{e.writeUint32(this.baseMediaDecodeTime)}}},{"./DataStream":158,"./descriptor":160,"./log":162}],160:[function(e,t,r){var n=e("./log");var i=function(){var e=3;var t=4;var r=5;var i=6;var s=[];s[e]="ES_Descriptor";s[t]="DecoderConfigDescriptor";s[r]="DecoderSpecificInfo";s[i]="SLConfigDescriptor";var o=this;var a={};this.parseOneDescriptor=function(e){var t=0;var r=0;var i;var o;var f;i=e.readUint8();t++;f=e.readUint8();t++;while(f&128){r=(f&127)<<7;f=e.readUint8();t++}r+=f&127;n.d("MPEG4DescriptorParser","Found "+(s[i]|"Descriptor "+i)+", size "+r+" at position "+e.position);if(s[i]){o=new a[s[i]](r)}else{o=new a.Descriptor(r)}o.parse(e);return o};a.Descriptor=function(e,t){this.tag=e;this.size=t;this.descs=[]};a.Descriptor.prototype.parse=function(e){this.data=e.readUint8Array(this.size)};a.Descriptor.prototype.findDescriptor=function(e){for(var t=0;t<this.descs.length;t++){if(this.descs[t].tag==e){return this.descs[t]}}return null};a.Descriptor.prototype.parseRemainingDescriptors=function(e){var t=e.position;while(e.position<t+this.size){var r=o.parseOneDescriptor(e);this.descs.push(r)}};a.ES_Descriptor=function(t){a.Descriptor.call(this,e,t)};a.ES_Descriptor.prototype=new a.Descriptor;a.ES_Descriptor.prototype.parse=function(e){this.ES_ID=e.readUint16();this.flags=e.readUint8();this.size-=3;if(this.flags&128){this.dependsOn_ES_ID=e.readUint16();this.size-=2}else{this.dependsOn_ES_ID=0}if(this.flags&64){var t=e.readUint8();this.URL=e.readString(t);this.size-=t+1}else{this.URL=null}if(this.flags&32){this.OCR_ES_ID=e.readUint16();this.size-=2}else{this.OCR_ES_ID=0}this.parseRemainingDescriptors(e)};a.ES_Descriptor.prototype.getOTI=function(e){var r=this.findDescriptor(t);if(r){return r.oti}else{return 0}};a.ES_Descriptor.prototype.getAudioConfig=function(e){var n=this.findDescriptor(t);if(!n)return null;var i=n.findDescriptor(r);if(i&&i.data){return(i.data[0]&248)>>3}else{return null}};a.DecoderConfigDescriptor=function(e){a.Descriptor.call(this,t,e)};a.DecoderConfigDescriptor.prototype=new a.Descriptor;a.DecoderConfigDescriptor.prototype.parse=function(e){this.oti=e.readUint8();this.streamType=e.readUint8();this.bufferSize=e.readUint24();this.maxBitrate=e.readUint32();this.avgBitrate=e.readUint32();this.size-=13;this.parseRemainingDescriptors(e)};a.DecoderSpecificInfo=function(e){a.Descriptor.call(this,r,e)};a.DecoderSpecificInfo.prototype=new a.Descriptor;a.SLConfigDescriptor=function(e){a.Descriptor.call(this,i,e)};a.SLConfigDescriptor.prototype=new a.Descriptor;return this};t.exports=i},{"./log":162}],161:[function(e,t,r){var n=e("./box");var i=e("./DataStream");var s=e("./log");var o=function(e){this.stream=e;this.boxes=[];this.mdats=[];this.moofs=[];this.isProgressive=false;this.lastMoofIndex=0;this.lastBoxStartPosition=0;this.parsingMdat=null;this.moovStartFound=false;this.samplesDataSize=0;this.nextParsePosition=0};t.exports=o;o.prototype.mergeNextBuffer=function(){var e;if(this.stream.bufferIndex+1<this.stream.nextBuffers.length){e=this.stream.nextBuffers[this.stream.bufferIndex+1];if(e.fileStart===this.stream.buffer.fileStart+this.stream.buffer.byteLength){var t=this.stream.buffer.byteLength;var r=this.stream.buffer.usedBytes;var n=this.stream.buffer.fileStart;this.stream.nextBuffers[this.stream.bufferIndex]=ArrayBuffer.concat(this.stream.buffer,e);this.stream.buffer=this.stream.nextBuffers[this.stream.bufferIndex];this.stream.nextBuffers.splice(this.stream.bufferIndex+1,1);this.stream.buffer.usedBytes=r;this.stream.buffer.fileStart=n;s.d("ISOFile","Concatenating buffer for box parsing (length: "+t+"->"+this.stream.buffer.byteLength+")");return true}else{return false}}else{return false}};o.prototype.parse=function(){var e;var t;var r;s.d("ISOFile","Starting parsing with buffer #"+this.stream.bufferIndex+" (fileStart: "+this.stream.buffer.fileStart+" - Length: "+this.stream.buffer.byteLength+") from position "+this.lastBoxStartPosition+" ("+(this.stream.buffer.fileStart+this.lastBoxStartPosition)+" in the file)");this.stream.seek(this.lastBoxStartPosition);while(true){if(this.parsingMdat!==null){r=this.parsingMdat;e=this.reposition(false,r.fileStart+r.hdr_size+r.size);if(e){s.d("ISOFile","Found 'mdat' end in buffer #"+this.stream.bufferIndex);this.parsingMdat=null;continue}else{this.nextParsePosition=this.findEndContiguousBuf(this.stream.bufferIndex);return}}else{this.lastBoxStartPosition=this.stream.position;t=n.parseOneBox(this.stream);if(t.code===n.ERR_NOT_ENOUGH_DATA){if(t.type==="mdat"){r=new n[t.type+"Box"](t.size-t.hdr_size);this.parsingMdat=r;this.mdats.push(r);r.fileStart=this.stream.buffer.fileStart+this.stream.position;r.hdr_size=t.hdr_size;this.stream.buffer.usedBytes+=t.hdr_size;e=this.reposition(false,r.fileStart+r.hdr_size+r.size);if(e){this.parsingMdat=null;continue}else{if(!this.moovStartFound){this.nextParsePosition=r.fileStart+r.size+r.hdr_size}else{this.nextParsePosition=this.findEndContiguousBuf(this.stream.bufferIndex)}return}}else{if(t.type==="moov"){this.moovStartFound=true;if(this.mdats.length===0){this.isProgressive=true}}else if(t.type==="free"){e=this.reposition(false,this.stream.buffer.fileStart+this.stream.position+t.size);if(e){continue}else{this.nextParsePosition=this.stream.buffer.fileStart+this.stream.position+t.size;return}}merged=this.mergeNextBuffer();if(merged){this.nextParsePosition=this.stream.buffer.fileStart+this.stream.buffer.byteLength;continue}else{if(!t.type){this.nextParsePosition=this.stream.buffer.fileStart+this.stream.buffer.byteLength}else{if(this.moovStartFound){this.nextParsePosition=this.stream.buffer.fileStart+this.stream.buffer.byteLength}else{this.nextParsePosition=this.stream.buffer.fileStart+this.stream.position+t.size}}return}}}else{r=t.box;this.boxes.push(r);switch(r.type){case"mdat":this.mdats.push(r);r.fileStart=this.stream.buffer.fileStart+r.start;break;case"moof":this.moofs.push(r);break;case"moov":this.moovStartFound=true;if(this.mdats.length===0){this.isProgressive=true}default:if(this[r.type]!==undefined){s.w("ISOFile","Duplicate Box of type: "+r.type+", overriding previous occurrence")}this[r.type]=r;break}if(r.type==="mdat"){this.stream.buffer.usedBytes+=r.hdr_size}else{this.stream.buffer.usedBytes+=t.size}}}}};o.prototype.reposition=function(e,t){var r;r=this.findPosition(e,t);if(r!==-1){this.stream.buffer=this.stream.nextBuffers[r];this.stream.bufferIndex=r;this.stream.position=t-this.stream.buffer.fileStart;s.d("ISOFile","Repositioning parser at buffer position: "+this.stream.position);return true}else{return false}};o.prototype.findPosition=function(e,t){var r;var n=null;var i=-1;if(e===true){r=0}else{r=this.stream.bufferIndex}while(r<this.stream.nextBuffers.length){n=this.stream.nextBuffers[r];if(n.fileStart<=t){i=r}else{break}r++}if(i!==-1){n=this.stream.nextBuffers[i];if(n.fileStart+n.byteLength>=t){s.d("ISOFile","Found position in existing buffer #"+i);return i}else{return-1}}else{return-1}};o.prototype.findEndContiguousBuf=function(e){var t;var r;var n;r=this.stream.nextBuffers[e];if(this.stream.nextBuffers.length>e+1){for(t=e+1;t<this.stream.nextBuffers.length;t++){n=this.stream.nextBuffers[t];if(n.fileStart===r.fileStart+r.byteLength){r=n}else{break}}}return r.fileStart+r.byteLength};o.prototype.write=function(e){for(var t=0;t<this.boxes.length;t++){this.boxes[t].write(e)}};o.prototype.writeInitializationSegment=function(e){var t;var r;var i;var o;var a;s.d("ISOFile","Generating initialization segment");this.ftyp.write(e);if(this.moov.mvex){this.initial_duration=this.moov.mvex.mehd.fragment_duration;r=-1;for(t=0;t<this.moov.boxes.length;t++){a=this.moov.boxes[t];if(a===this.moov.mvex){r=t}}if(r>-1){this.moov.boxes.splice(r,1)}this.moov.mvex=null}this.moov.mvex=new n.mvexBox;this.moov.boxes.push(this.moov.mvex);this.moov.mvex.mehd=new n.mehdBox;this.moov.mvex.boxes.push(this.moov.mvex.mehd);this.moov.mvex.mehd.fragment_duration=this.initial_duration;for(t=0;t<this.moov.traks.length;t++){if(this.moov.traks[t].ignore)continue;o=new n.trexBox;this.moov.mvex.boxes.push(o);o.track_id=this.moov.traks[t].tkhd.track_id;o.default_sample_description_index=1;o.default_sample_duration=this.moov.traks[t].samples.length>0?this.moov.traks[t].samples[0].duration:0;o.default_sample_size=0;o.default_sample_flags=1<<16}this.moov.write(e)};o.prototype.resetTables=function(){var e;var t,r,n,i,s,o,a,f;this.initial_duration=this.moov.mvhd.duration;this.moov.mvhd.duration=0;for(e=0;e<this.moov.traks.length;e++){t=this.moov.traks[e];t.tkhd.duration=0;t.mdia.mdhd.duration=0;r=t.mdia.minf.stbl.stco||t.mdia.minf.stbl.co64;r.chunk_offsets=[];n=t.mdia.minf.stbl.stsc;n.first_chunk=[];n.samples_per_chunk=[];n.sample_description_index=[];i=t.mdia.minf.stbl.stsz;i.sample_sizes=[];s=t.mdia.minf.stbl.stts;s.sample_counts=[];s.sample_deltas=[];o=t.mdia.minf.stbl.ctts;if(o){o.sample_counts=[];o.sample_offsets=[]}a=t.mdia.minf.stbl.stss;if(a){a.sample_numbers=new Uint32Array(0)}f=t.mdia.minf.stbl.sdtp;var u=t.mdia.minf.stbl.boxes.indexOf(f);if(u!=-1)t.mdia.minf.stbl.boxes[u]=null}};o.prototype.buildSampleLists=function(){var e,t,r;var n,i,s,o,a,f,u,h,l;var c,d,p,m,g;var v,y,_,b,w,S;this.originalMvex=this.moov.mvex;for(e=0;e<this.moov.traks.length;e++){n=this.moov.traks[e];n.samples=[];i=n.mdia.minf.stbl.stco||n.mdia.minf.stbl.co64;s=n.mdia.minf.stbl.stsc;o=n.mdia.minf.stbl.stsz;a=n.mdia.minf.stbl.stts;f=n.mdia.minf.stbl.ctts;u=n.mdia.minf.stbl.stss;h=n.mdia.minf.stbl.stsd;l=n.mdia.minf.stbl.subs;v=-1;y=-1;_=-1;b=-1;w=0;subs_entry_index=0;last_subs_sample_index=0;for(t=0;t<o.sample_sizes.length;t++){var x={};x.number=t;x.track_id=n.tkhd.track_id;x.timescale=n.mdia.mdhd.timescale;n.samples[t]=x;x.size=o.sample_sizes[t];if(t===0){d=1;c=0;x.chunk_index=d;x.chunk_run_index=c;g=s.samples_per_chunk[c];m=0;if(c+1<s.first_chunk.length){p=s.first_chunk[c+1]-1}else{p=Infinity}}else{if(t<g){x.chunk_index=d;x.chunk_run_index=c}else{d++;x.chunk_index=d;m=0;if(d<=p){}else{c++;if(c+1<s.first_chunk.length){p=s.first_chunk[c+1]-1}else{p=Infinity}}x.chunk_run_index=c;g+=s.samples_per_chunk[c]}}x.description=h.entries[s.sample_description_index[x.chunk_run_index]-1];x.offset=i.chunk_offsets[x.chunk_index-1]+m;m+=x.size;if(t>v){y++;if(v<0){v=0}v+=a.sample_counts[y]}if(t>0){n.samples[t-1].duration=a.sample_deltas[y];x.dts=n.samples[t-1].dts+n.samples[t-1].duration}else{x.dts=0}if(f){if(t>_){b++;_+=f.sample_counts[b]}x.cts=n.samples[t].dts+f.sample_offsets[b]}else{x.cts=x.dts}if(u){if(t==u.sample_numbers[w]-1){x.is_rap=true;w++}else{x.is_rap=false}}else{x.is_rap=true}if(l){if(l.samples[subs_entry_index].sample_delta+last_subs_sample_index==t){x.subsamples=l.samples[subs_entry_index].subsamples;last_subs_sample_index+=l.samples[subs_entry_index].sample_delta}}}if(t>0)n.samples[t-1].duration=n.mdia.mdhd.duration-n.samples[t-1].dts}};o.prototype.updateSampleLists=function(){var e,t,r;var i,s,o,a;var f;var u,h,l,c,d;var p;while(this.lastMoofIndex<this.moofs.length){u=this.moofs[this.lastMoofIndex];this.lastMoofIndex++;if(u.type=="moof"){h=u;for(e=0;e<h.trafs.length;e++){l=h.trafs[e];c=this.getTrackById(l.tfhd.track_id);d=this.getTrexById(l.tfhd.track_id);if(l.tfhd.flags&n.TFHD_FLAG_SAMPLE_DESC){i=l.tfhd.default_sample_description_index}else{i=d.default_sample_description_index}if(l.tfhd.flags&n.TFHD_FLAG_SAMPLE_DUR){s=l.tfhd.default_sample_duration}else{s=d.default_sample_duration}if(l.tfhd.flags&n.TFHD_FLAG_SAMPLE_SIZE){o=l.tfhd.default_sample_size}else{o=d.default_sample_size}if(l.tfhd.flags&n.TFHD_FLAG_SAMPLE_FLAGS){a=l.tfhd.default_sample_flags}else{a=d.default_sample_flags}for(t=0;t<l.truns.length;t++){var m=l.truns[t];for(r=0;r<m.sample_count;r++){p={};l.first_sample_index=c.samples.length;c.samples.push(p);p.track_id=c.tkhd.track_id;p.timescale=c.mdia.mdhd.timescale;p.description=c.mdia.minf.stbl.stsd.entries[i-1];p.size=o;if(m.flags&n.TRUN_FLAGS_SIZE){p.size=m.sample_size[r]}p.duration=s;if(m.flags&n.TRUN_FLAGS_DURATION){p.duration=m.sample_duration[r]}if(c.first_traf_merged||r>0){p.dts=c.samples[c.samples.length-2].dts+c.samples[c.samples.length-2].duration}else{if(l.tfdt){p.dts=l.tfdt.baseMediaDecodeTime}else{p.dts=0}c.first_traf_merged=true}p.cts=p.dts;if(m.flags&n.TRUN_FLAGS_CTS_OFFSET){p.cts=p.dts+m.sample_composition_time_offset[r]}sample_flags=a;if(m.flags&n.TRUN_FLAGS_FLAGS){sample_flags=m.sample_flags[r]}else if(r===0&&m.flags&n.TRUN_FLAGS_FIRST_FLAG){sample_flags=m.first_sample_flags}p.is_rap=sample_flags>>16&1?false:true;var g=l.tfhd.flags&n.TFHD_FLAG_BASE_DATA_OFFSET?true:false;var v=l.tfhd.flags&n.TFHD_FLAG_DEFAULT_BASE_IS_MOOF?true:false;var y=m.flags&n.TRUN_FLAGS_DATA_OFFSET?true:false;var _=0;if(!g){if(!v){if(t===0){_=h.fileStart}else{_=f}}else{_=h.fileStart}}else{_=l.tfhd.base_data_offset}if(t===0&&r===0){if(y){p.offset=_+m.data_offset}else{p.offset=_}}else{p.offset=f}f=p.offset+p.size}}if(l.subs){var b=l.first_sample_index;for(t=0;t<l.subs.samples.length;t++){b+=l.subs.samples[t].sample_delta;p=c.samples[b-1];p.subsamples=l.subs.samples[t].subsamples}}}}}};o.prototype.getCodecs=function(){var e;var t="";for(e=0;e<this.moov.traks.length;e++){var r=this.moov.traks[e];if(e>0){t+=","}t+=r.mdia.minf.stbl.stsd.entries[0].getCodec()}return t};o.prototype.getTrexById=function(e){var t;if(!this.originalMvex)return null;for(t=0;t<this.originalMvex.trexs.length;t++){var r=this.originalMvex.trexs[t];if(r.track_id==e)return r}return null};o.prototype.getTrackById=function(e){for(var t=0;t<this.moov.traks.length;t++){var r=this.moov.traks[t];if(r.tkhd.track_id==e)return r}return null};o.prototype.getSample=function(e,t){var r;var n;var o=e.samples[t];if(!this.moov){return null}if(!o.data){o.data=new Uint8Array(o.size);o.alreadyRead=0;this.samplesDataSize+=o.size;s.d("ISOFile","Allocating sample #"+t+" on track #"+e.tkhd.track_id+" of size "+o.size+" (total: "+this.samplesDataSize+")")}else if(o.alreadyRead==o.size){return o}for(n=0;n<this.stream.nextBuffers.length;n++){r=this.stream.nextBuffers[n];if(o.offset+o.alreadyRead>=r.fileStart&&o.offset+o.alreadyRead<r.fileStart+r.byteLength){var a=r.byteLength-(o.offset+o.alreadyRead-r.fileStart);if(o.size-o.alreadyRead<=a){s.d("ISOFile","Getting sample #"+t+" data (alreadyRead: "+o.alreadyRead+" offset: "+(o.offset+o.alreadyRead-r.fileStart)+" size: "+(o.size-o.alreadyRead)+")");i.memcpy(o.data.buffer,o.alreadyRead,r,o.offset+o.alreadyRead-r.fileStart,o.size-o.alreadyRead);o.alreadyRead=o.size;r.usedBytes+=o.size-o.alreadyRead;if(r.usedBytes===r.byteLength){this.stream.nextBuffers.splice(n,1);n--}return o}else{s.d("ISOFile","Getting sample data (alreadyRead: "+o.alreadyRead+" offset: "+(o.offset+o.alreadyRead-r.fileStart)+" size: "+a+")");i.memcpy(o.data.buffer,o.alreadyRead,r,o.offset+o.alreadyRead-r.fileStart,a);o.alreadyRead+=a;r.usedBytes+=a;if(r.usedBytes===r.byteLength){this.stream.nextBuffers.splice(n,1);n--}}}}return null};o.prototype.releaseSample=function(e,t){var r=e.samples[t];r.data=null;this.samplesDataSize-=r.size;return r.size}},{"./DataStream":158,"./box":159,"./log":162}],162:[function(e,t,r){var n=function(){var e=new Date;var t=4;var r=3;var i=2;var s=1;var o=t;var a={setLogLevel:function(e){if(e==this.d)o=s;else if(e==this.i)o=i;else if(e==this.w)o=r;else if(e==this.e)o=t;else o=t},d:function(t,r){if(s>=o){console.debug("["+n.getDurationString(new Date-e,1e3)+"]","["+t+"]",r)}},i:function(t,r){if(i>=o){console.info("["+n.getDurationString(new Date-e,1e3)+"]","["+t+"]",r)}},w:function(t,i){if(r>=o){console.warn("["+n.getDurationString(new Date-e,1e3)+"]","["+t+"]",i)}},e:function(r,i){if(t>=o){console.error("["+n.getDurationString(new Date-e,1e3)+"]","["+r+"]",i)}}};return a}();t.exports=n;n.getDurationString=function(e,t){function r(e,t){var r=""+e;var n=r.split(".");while(n[0].length<t){n[0]="0"+n[0]}return n.join(".")}var n=t||1;var i=e/n;var s=Math.floor(i/3600);i-=s*3600;var o=Math.floor(i/60);i-=o*60;var a=i*1e3;i=Math.floor(i);a-=i*1e3;a=Math.floor(a);return""+s+":"+r(o,2)+":"+r(i,2)+"."+r(a,3)};n.printRanges=function(e){var t=e.length;if(t>0){var r="";for(var i=0;i<t;i++){if(i>0)r+=",";r+="["+n.getDurationString(e.start(i))+","+n.getDurationString(e.end(i))+"]"}return r}else{return"(empty)"}}},{}],163:[function(e,t,r){var n=e("./box");var s=e("./DataStream");var o=e("./isofile");var a=e("./log");var f=function(){this.inputStream=null;this.nextBuffers=[];this.inputIsoFile=null;this.onMoovStart=null;this.moovStartSent=false;this.onReady=null;this.readySent=false;this.onSegment=null;this.onSamples=null;this.onError=null;this.sampleListBuilt=false;this.fragmentedTracks=[];this.extractedTracks=[];this.isFragmentationStarted=false;this.nextMoofNumber=0};t.exports=f;f.prototype.setSegmentOptions=function(e,t,r){var n=this.inputIsoFile.getTrackById(e);if(n){var i={};this.fragmentedTracks.push(i);i.id=e;i.user=t;i.trak=n;n.nextSample=0;i.segmentStream=null;i.nb_samples=1e3;i.rapAlignement=true;if(r){if(r.nbSamples)i.nb_samples=r.nbSamples;if(r.rapAlignement)i.rapAlignement=r.rapAlignement}}};f.prototype.unsetSegmentOptions=function(e){var t=-1;for(var r=0;r<this.fragmentedTracks.length;r++){var n=this.fragmentedTracks[r];if(n.id==e){t=r}}if(t>-1){this.fragmentedTracks.splice(t,1)}};f.prototype.setExtractionOptions=function(e,t,r){var n=this.inputIsoFile.getTrackById(e);if(n){var i={};this.extractedTracks.push(i);i.id=e;i.user=t;i.trak=n;n.nextSample=0;i.nb_samples=1e3;i.samples=[];if(r){if(r.nbSamples)i.nb_samples=r.nbSamples}}};f.prototype.unsetExtractionOptions=function(e){var t=-1;for(var r=0;r<this.extractedTracks.length;r++){var n=this.extractedTracks[r];if(n.id==e){t=r}}if(t>-1){this.extractedTracks.splice(t,1)}};f.prototype.createSingleSampleMoof=function(e){var t=new n.moofBox;var r=new n.mfhdBox;r.sequence_number=this.nextMoofNumber;this.nextMoofNumber++;t.boxes.push(r);var i=new n.trafBox;t.boxes.push(i);var s=new n.tfhdBox;i.boxes.push(s);s.track_id=e.track_id;s.flags=n.TFHD_FLAG_DEFAULT_BASE_IS_MOOF;var o=new n.tfdtBox;i.boxes.push(o);o.baseMediaDecodeTime=e.dts;var a=new n.trunBox;i.boxes.push(a);t.trun=a;a.flags=n.TRUN_FLAGS_DATA_OFFSET|n.TRUN_FLAGS_DURATION|n.TRUN_FLAGS_SIZE|n.TRUN_FLAGS_FLAGS|n.TRUN_FLAGS_CTS_OFFSET;a.data_offset=0;a.first_sample_flags=0;a.sample_count=1;a.sample_duration=[];a.sample_duration[0]=e.duration;a.sample_size=[];a.sample_size[0]=e.size;a.sample_flags=[];a.sample_flags[0]=0;a.sample_composition_time_offset=[];a.sample_composition_time_offset[0]=e.cts-e.dts;return t};f.prototype.createFragment=function(e,t,r,i){var o=this.inputIsoFile.getTrackById(t);var f=this.inputIsoFile.getSample(o,r);if(f==null){if(this.nextSeekPosition){this.nextSeekPosition=Math.min(o.samples[r].offset,this.nextSeekPosition)}else{this.nextSeekPosition=o.samples[r].offset}return null}var u=i||new s;u.endianness=s.BIG_ENDIAN;var h=this.createSingleSampleMoof(f);h.write(u);h.trun.data_offset=h.size+8;a.d("BoxWriter","Adjusting data_offset with new value "+h.trun.data_offset);u.adjustUint32(h.trun.data_offset_position,h.trun.data_offset);var l=new n.mdatBox;l.data=f.data;l.write(u);return u};ArrayBuffer.concat=function(e,t){a.d("ArrayBuffer","Trying to create a new buffer of size: "+(e.byteLength+t.byteLength));var r=new Uint8Array(e.byteLength+t.byteLength);r.set(new Uint8Array(e),0);r.set(new Uint8Array(t),e.byteLength);return r.buffer};f.prototype.reduceBuffer=function(e,t,r){var n;n=new Uint8Array(r);n.set(new Uint8Array(e,t,r));n.buffer.fileStart=e.fileStart+t;n.buffer.usedBytes=0;return n.buffer};f.prototype.insertBuffer=function(e){var t=true;for(var r=0;r<this.nextBuffers.length;r++){var n=this.nextBuffers[r];if(e.fileStart<=n.fileStart){if(e.fileStart===n.fileStart){if(e.byteLength>n.byteLength){this.nextBuffers.splice(r,1);r--;continue}else{a.w("MP4Box","Buffer (fileStart: "+e.fileStart+" - Length: "+e.byteLength+") already appended, ignoring")}}else{if(e.fileStart+e.byteLength<=n.fileStart){}else{e=this.reduceBuffer(e,0,n.fileStart-e.fileStart)}a.d("MP4Box","Appending new buffer (fileStart: "+e.fileStart+" - Length: "+e.byteLength+")");this.nextBuffers.splice(r,0,e);if(r===0&&this.inputStream!==null){this.inputStream.buffer=e}}t=false;break}else if(e.fileStart<n.fileStart+n.byteLength){var i=n.fileStart+n.byteLength-e.fileStart;var s=e.byteLength-i;if(s>0){e=this.reduceBuffer(e,i,s)}else{t=false;break}}}if(t){a.d("MP4Box","Appending new buffer (fileStart: "+e.fileStart+" - Length: "+e.byteLength+")");this.nextBuffers.push(e);if(r===0&&this.inputStream!==null){this.inputStream.buffer=e}}};f.prototype.processSamples=function(){var e;var t;if(this.isFragmentationStarted&&this.onSegment!==null){for(e=0;e<this.fragmentedTracks.length;e++){var r=this.fragmentedTracks[e];t=r.trak;while(t.nextSample<t.samples.length){a.d("MP4Box","Creating media fragment on track #"+r.id+" for sample "+t.nextSample);var n=this.createFragment(this.inputIsoFile,r.id,t.nextSample,r.segmentStream);if(n){r.segmentStream=n;t.nextSample++}else{break}if(t.nextSample%r.nb_samples===0||t.nextSample>=t.samples.length){a.i("MP4Box","Sending fragmented data on track #"+r.id+" for samples ["+(t.nextSample-r.nb_samples)+","+(t.nextSample-1)+"]");if(this.onSegment){this.onSegment(r.id,r.user,r.segmentStream.buffer,t.nextSample)}r.segmentStream=null;if(r!==this.fragmentedTracks[e]){break}}}}}if(this.onSamples!==null){for(e=0;e<this.extractedTracks.length;e++){var i=this.extractedTracks[e];t=i.trak;while(t.nextSample<t.samples.length){a.d("MP4Box","Exporting on track #"+i.id+" sample #"+t.nextSample);var s=this.inputIsoFile.getSample(t,t.nextSample);if(s){t.nextSample++;i.samples.push(s)}else{return}if(t.nextSample%i.nb_samples===0||t.nextSample>=t.samples.length){a.d("MP4Box","Sending samples on track #"+i.id+" for sample "+t.nextSample);if(this.onSamples){this.onSamples(i.id,i.user,i.samples)}i.samples=[];if(i!==this.extractedTracks[e]){break}}}}}};f.prototype.appendBuffer=function(e){var t;var r;if(e===null||e===undefined){throw"Buffer must be defined and non empty"}if(e.fileStart===undefined){throw"Buffer must have a fileStart property"}if(e.byteLength===0){a.w("MP4Box","Ignoring empty buffer (fileStart: "+e.fileStart+")");return}e.usedBytes=0;this.insertBuffer(e);if(!this.inputStream){if(this.nextBuffers.length>0){r=this.nextBuffers[0];if(r.fileStart===0){this.inputStream=new s(r,0,s.BIG_ENDIAN);this.inputStream.nextBuffers=this.nextBuffers;this.inputStream.bufferIndex=0}else{a.w("MP4Box","The first buffer should have a fileStart of 0");return}}else{a.w("MP4Box","No buffer to start parsing from");return}}if(!this.inputIsoFile){this.inputIsoFile=new o(this.inputStream)}this.inputIsoFile.parse();if(this.inputIsoFile.moovStartFound&&!this.moovStartSent){this.moovStartSent=true;if(this.onMoovStart)this.onMoovStart()}if(this.inputIsoFile.moov){if(!this.sampleListBuilt){this.inputIsoFile.buildSampleLists();this.sampleListBuilt=true}this.inputIsoFile.updateSampleLists();if(this.onReady&&!this.readySent){var n=this.getInfo();this.readySent=true;this.onReady(n)}this.processSamples();if(this.nextSeekPosition){t=this.nextSeekPosition;this.nextSeekPosition=undefined}else{t=this.inputIsoFile.nextParsePosition}var i=this.inputIsoFile.findPosition(true,t);if(i!==-1){t=this.inputIsoFile.findEndContiguousBuf(i)}a.i("MP4Box","Next buffer to fetch should have a fileStart position of "+t);return t}else{if(this.inputIsoFile!==null){return this.inputIsoFile.nextParsePosition}else{return 0}}};f.prototype.getInfo=function(){var e={};var t;var r;var n;var s=new Date(4,0,1,0,0,0,0).getTime();e.duration=this.inputIsoFile.moov.mvhd.duration;e.timescale=this.inputIsoFile.moov.mvhd.timescale;e.isFragmented=this.inputIsoFile.moov.mvex!=null;if(e.isFragmented&&this.inputIsoFile.moov.mvex.mehd){e.fragment_duration=this.inputIsoFile.moov.mvex.mehd.fragment_duration}else{e.fragment_duration=0}e.isProgressive=this.inputIsoFile.isProgressive;e.hasIOD=this.inputIsoFile.moov.iods!=null;e.brands=[];e.brands.push(this.inputIsoFile.ftyp.major_brand);e.brands=e.brands.concat(this.inputIsoFile.ftyp.compatible_brands);e.created=new Date(s+this.inputIsoFile.moov.mvhd.creation_time*1e3);e.modified=new Date(s+this.inputIsoFile.moov.mvhd.modification_time*1e3);e.tracks=[];e.audioTracks=[];e.videoTracks=[];e.subtitleTracks=[];e.metadataTracks=[];e.hintTracks=[];e.otherTracks=[];for(i=0;i<this.inputIsoFile.moov.traks.length;i++){t=this.inputIsoFile.moov.traks[i];n=t.mdia.minf.stbl.stsd.entries[0];r={};e.tracks.push(r);r.id=t.tkhd.track_id;r.references=[];if(t.tref){for(j=0;j<t.tref.boxes.length;j++){ref={};r.references.push(ref);ref.type=t.tref.boxes[j].type;ref.track_ids=t.tref.boxes[j].track_ids}}r.created=new Date(s+t.tkhd.creation_time*1e3);r.modified=new Date(s+t.tkhd.modification_time*1e3);r.movie_duration=t.tkhd.duration;r.layer=t.tkhd.layer;r.alternate_group=t.tkhd.alternate_group;r.volume=t.tkhd.volume;r.matrix=t.tkhd.matrix;r.track_width=t.tkhd.width/(1<<16);r.track_height=t.tkhd.height/(1<<16);r.timescale=t.mdia.mdhd.timescale;r.duration=t.mdia.mdhd.duration;r.codec=n.getCodec();r.language=t.mdia.mdhd.languageString;r.nb_samples=t.samples.length;r.size=0;for(j=0;j<r.nb_samples;j++){r.size+=t.samples[j].size}r.bitrate=r.size*8*r.timescale/r.duration;if(n.isAudio()){e.audioTracks.push(r);r.audio={};r.audio.sample_rate=n.getSampleRate();r.audio.channel_count=n.getChannelCount();r.audio.sample_size=n.getSampleSize()}else if(n.isVideo()){e.videoTracks.push(r);r.video={};r.video.width=n.getWidth();r.video.height=n.getHeight()}else if(n.isSubtitle()){e.subtitleTracks.push(r)}else if(n.isHint()){e.hintTracks.push(r)}else if(n.isMetadata()){e.metadataTracks.push(r)}else{e.otherTracks.push(r)}}return e};f.prototype.getInitializationSegment=function(){var e=new s;e.endianness=s.BIG_ENDIAN;this.inputIsoFile.writeInitializationSegment(e);return e.buffer};f.prototype.writeFile=function(){var e=new s;e.endianness=s.BIG_ENDIAN;this.inputIsoFile.write(e);return e.buffer};f.prototype.initializeSegmentation=function(){var e;var t;var r;var n;var i;if(this.onSegment===null){a.w("MP4Box","No segmentation callback set!")}if(!this.isFragmentationStarted){this.isFragmentationStarted=true;this.nextMoofNumber=0;
-this.inputIsoFile.resetTables()}n=[];for(e=0;e<this.fragmentedTracks.length;e++){for(t=0;t<this.inputIsoFile.moov.boxes.length;t++){r=this.inputIsoFile.moov.boxes[t];if(r&&r.type==="trak"){this.inputIsoFile.moov.boxes[t].ignore=true;this.inputIsoFile.moov.boxes[t]=null}}i=this.inputIsoFile.getTrackById(this.fragmentedTracks[e].id);delete i.ignore;for(t=0;t<this.inputIsoFile.moov.boxes.length;t++){r=this.inputIsoFile.moov.boxes[t];if(r==null){this.inputIsoFile.moov.boxes[t]=i;break}}seg={};seg.id=i.tkhd.track_id;seg.user=this.fragmentedTracks[e].user;seg.buffer=this.getInitializationSegment();n.push(seg)}return n};f.prototype.releaseUsedSamples=function(e,t){var r=0;var n=this.inputIsoFile.getTrackById(e);if(!n.lastValidSample)n.lastValidSample=0;for(var i=n.lastValidSample;i<t;i++){r+=this.inputIsoFile.releaseSample(n,i)}a.d("MP4Box","Track #"+e+" released samples up to "+t+" (total size: "+r+", remaining: "+this.inputIsoFile.samplesDataSize+")");n.lastValidSample=t};f.prototype.flush=function(){a.i("MP4Box","Flushing remaining samples");this.inputIsoFile.updateSampleLists();this.processSamples()};f.prototype.seekTrack=function(e,t,r){var n;var i;var s=Infinity;var o=0;var f=Infinity;var u=0;var h=0;var l;for(n=0;n<r.samples.length;n++){i=r.samples[n];if(n===0){f=i.offset;h=0;l=i.timescale}else if(i.cts>e*i.timescale){f=r.samples[n-1].offset;h=n-1;break}if(t&&i.is_rap){s=i.offset;o=i.cts;u=n}}if(t){r.nextSample=u;a.i("MP4Box","Seeking to RAP sample #"+r.nextSample+" on track "+r.tkhd.track_id+", time "+a.getDurationString(o,l)+" and offset: "+s);return{offset:s,time:o/l}}else{r.nextSample=h;a.i("MP4Box","Seeking to non-RAP sample #"+r.nextSample+" on track "+r.tkhd.track_id+", time "+a.getDurationString(e)+" and offset: "+s);return{offset:f,time:e}}};f.prototype.seek=function(e,t){var r=this.inputIsoFile.moov;var n;var i;var s;var o={offset:Infinity,time:Infinity};if(!this.inputIsoFile.moov){throw"Cannot seek: moov not received!"}else{for(s=0;s<r.traks.length;s++){n=r.traks[s];i=this.seekTrack(e,t,n);if(i.offset<o.offset){o.offset=i.offset}if(i.time<o.time){o.time=i.time}}if(o.offset===Infinity){o={offset:this.inputIsoFile.nextParsePosition,time:0}}else{var f=this.inputIsoFile.findPosition(true,o.offset);if(f!==-1){o.offset=this.inputIsoFile.findEndContiguousBuf(f)}}a.i("MP4Box","Seeking at time "+a.getDurationString(o.time,1)+" needs a buffer with a fileStart position of "+o.offset);return o}}},{"./DataStream":158,"./box":159,"./isofile":161,"./log":162}],164:[function(e,t,r){var n=e("debug")("videostream");var i=e("mp4box");var s=.01;var o=60;t.exports=function(e,t,r){r=r||{};var f=r.debugTrack||-1;var u=[];function h(){t.addEventListener("waiting",S);t.addEventListener("timeupdate",E)}h();var l=false;function c(e){l=true;t.removeEventListener("waiting",S);t.removeEventListener("timeupdate",E);if(p.readyState==="open")p.endOfStream(e)}function d(e){var r=e.buffer.buffered;var i=t.currentTime;var a=-1;for(var f=0;f<r.length;f++){var u=r.start(f);var h=r.end(f)+s;if(u>i){break}else if(a>=0||i<=h){a=h}}var l=a-i;if(l<0)l=0;n("Buffer length: %f",l);return l<=o}var p=new MediaSource;p.addEventListener("sourceopen",function(){w(0)});t.src=window.URL.createObjectURL(p);var m=new i;m.onError=function(e){n("MP4Box error: %s",e.message);if(b){b()}if(p.readyState==="open"){c("decode")}};var g=false;var v={};m.onReady=function(e){n("MP4 info: %o",e);e.tracks.forEach(function(e){var t;if(e.video){t="video/mp4"}else if(e.audio){t="audio/mp4"}else{return}t+='; codecs="'+e.codec+'"';if(MediaSource.isTypeSupported(t)){var r=p.addSourceBuffer(t);var n={buffer:r,arrayBuffers:[],meta:e,ended:false};r.addEventListener("updateend",A.bind(null,n));m.setSegmentOptions(e.id,null,{nbSamples:e.video?1:100});v[e.id]=n}});if(Object.keys(v).length===0){c("decode");return}var t=m.initializeSegmentation();t.forEach(function(e){k(v[e.id],e.buffer);if(e.id===f){a("init-track-"+f+".mp4",[e.buffer]);u.push(e.buffer)}});g=true};m.onSegment=function(e,t,r,n){var i=v[e];k(i,r,n===i.meta.nb_samples);if(e===f&&u){u.push(r);if(n>1e3){a("track-"+f+".mp4",u);u=null}}};var y;var _=null;var b=null;function w(t){if(t===e.length){m.flush();return}if(_&&t===y){var r=_;setTimeout(function(){if(_===r)_.resume()});return}if(_){_.destroy();b()}y=t;var i={start:y,end:e.length-1};_=e.createReadStream(i);function s(e){_.pause();var t=e.toArrayBuffer();t.fileStart=y;y+=t.byteLength;var r;try{r=m.appendBuffer(t)}catch(i){n("MP4Box threw exception: %s",i.message);if(p.readyState==="open"){c("decode")}_.destroy();b();return}w(r)}_.on("data",s);function o(){b();w(y)}_.on("end",o);function a(e){n("Stream error: %s",e.message);if(p.readyState==="open"){c("network")}}_.on("error",a);b=function(){_.removeListener("data",s);_.removeListener("end",o);_.removeListener("error",a);_=null;b=null}}function S(){if(g){x(t.currentTime)}}function x(e){if(l)h();var t=m.seek(e,true);n("Seeking to time: %d",e);n("Seeked file offset: %d",t.offset);w(t.offset)}function k(e,t,r){e.arrayBuffers.push({buffer:t,ended:r||false});A(e)}function E(){Object.keys(v).forEach(function(e){var t=v[e];if(t.blocked){A(t)}})}function A(e){if(e.buffer.updating)return;e.blocked=!d(e);if(e.blocked)return;if(e.arrayBuffers.length===0)return;var t=e.arrayBuffers.shift();var r=false;try{e.buffer.appendBuffer(t.buffer);e.ended=t.ended;r=true}catch(i){n("SourceBuffer error: %s",i.message);c("decode");return}if(r){U()}}function U(){if(p.readyState!=="open"){return}var e=Object.keys(v).every(function(e){var t=v[e];return t.ended&&!t.buffer.updating});if(e){c()}}};function a(e,t){var r=new Blob(t);var n=URL.createObjectURL(r);var i=document.createElement("a");i.setAttribute("href",n);i.setAttribute("download",e);i.click()}},{debug:114,mp4box:163}],165:[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}},{}],166:[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}},{}],167:[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+""}},{}],168:[function(e,t,r){t.exports={name:"webtorrent",description:"Streaming torrent client",version:"0.64.0",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":"^5.0.0","bittorrent-swarm":"^6.0.0","chunk-store-stream":"^2.0.0",clivas:"^0.2.0","create-torrent":"^3.4.0","cross-spawn-async":"^2.0.0",debug:"^2.1.0","end-of-stream":"^1.0.0",executable:"^2.1.0","fs-chunk-store":"^1.3.4",hat:"0.0.3","immediate-chunk-store":"^1.0.7",inherits:"^2.0.1",inquirer:"^0.11.0","load-ip-set":"^1.0.3",mediasource:"^1.0.0","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":"^2.0.1",pump:"^1.0.0","random-iterate":"^1.0.1","range-parser":"^1.0.2","re-emitter":"^1.0.0","run-parallel":"^1.0.0","simple-sha1":"^2.0.0",speedometer:"^1.0.0",thunky:"^0.1.0","torrent-discovery":"^4.0.0","torrent-piece":"^1.0.0",uniq:"^1.0.1",ut_metadata:"^3.0.1",ut_pex:"^1.0.1",videostream:"^1.1.4","windows-no-runnable":"0.0.6",xtend:"^4.0.0","zero-fill":"^2.2.0"},devDependencies:{"bittorrent-tracker":"^6.0.0",brfs:"^1.2.0",browserify:"^12.0.1",finalhandler:"^0.4.0","run-auto":"^1.0.0","serve-static":"^1.9.3","simple-get":"^1.0.0",standard:"^5.1.0",tape:"^4.0.0","uglify-js":"^2.4.15",zuul:"^3.0.0"},homepage:"http://webtorrent.io",keywords:["torrent","bittorrent","bittorrent client","streaming","download","webrtc","webrtc data","webtorrent","mad science"],license:"MIT",main:"index.js",optionalDependencies:{"airplay-js":"^0.2.3",chromecasts:"^1.5.3",nodebmc:"0.0.5"},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/basic.js","test-browser-local":"zuul --local -- test/basic.js","test-node":"tape test/*.js"}}},{}],169:[function(e,t,r){(function(r,n,i){t.exports=S;var s=e("create-torrent");var o=e("debug")("webtorrent");var a=e("bittorrent-dht/client");var f=e("events").EventEmitter;var u=e("xtend");var h=e("hat");var l=e("inherits");var c=e("load-ip-set");var d=e("run-parallel");var p=e("parse-torrent");var m=e("path");var g=e("speedometer");var v=e("zero-fill");var y=e("./lib/torrent");l(S,f);var _=e("./package.json").version;var b=_.match(/([0-9]+)/g).slice(0,2).map(v(2)).join("");var w="-WW"+b+"-";function S(e){var t=this;if(!(t instanceof S))return new S(e);f.call(t);if(!e)e={};if(!o.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.peerId=typeof e.peerId==="string"?e.peerId:(e.peerId||new i(w+h(48))).toString("hex");t.peerIdBuffer=new i(t.peerId,"hex");t.nodeId=typeof e.nodeId==="string"?e.nodeId:e.nodeId&&e.nodeId.toString("hex")||h(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)}o("new webtorrent (peerId %s, nodeId %s)",t.peerId,t.nodeId);if(typeof c==="function"){c(e.blocklist,{headers:{"user-agent":"WebTorrent/"+_+" (http://webtorrent.io)"}},function(e,r){if(e)return t.error("Failed to load blocklist: "+e.message);t.blocked=r;s()})}else r.nextTick(s);function s(){if(t.destroyed)return;t.ready=true;t.emit("ready")}}Object.defineProperty(S.prototype,"ratio",{get:function(){var e=this;var t=e.torrents.reduce(function(e,t){return e+t.uploaded},0);var r=e.torrents.reduce(function(e,t){return e+t.downloaded},0)||1;return t/r}});S.prototype.get=function(e){var t=this;if(e instanceof y)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,s=t.torrents.length;i<s;i++){var o=t.torrents[i];if(o.infoHash===r.infoHash)return o}return null};S.prototype.add=S.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);o("add");if(!t)t={};else t=u(t);t.client=i;var s=i.get(e);function a(){if(typeof n==="function")n(s)}if(s){if(s.ready)r.nextTick(a);else s.on("ready",a)}else{s=new y(e,t);i.torrents.push(s);s.on("error",function(e){i.emit("error",e,s);i.remove(s)});s.on("listening",function(e){i.emit("listening",e,s)});s.on("ready",function(){a();i.emit("torrent",s)})}return s};S.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);o("seed");if(!t)t={};else t=u(t);if(typeof e==="string")t.path=m.dirname(e);if(!t.createdBy)t.createdBy="WebTorrent/"+b;if(!n.tracker)t.announce=[];var i;var a=n.add(undefined,t,function(e){var t=[function(t){e.load(i,t)}];if(n.dht){t.push(function(t){e.on("dhtAnnounce",t)})}d(t,function(t){if(t)return n.emit("error",t);f();n.emit("seed",e)})});s.parseInput(e,t,function(r,o){if(r)return n.emit("error",r);i=o.map(function(e){return e.getStream});s(e,t,function(e,t){if(e)return n.emit("error",e);if(n.destroyed)return;var r=n.get(t);if(r){a.destroy();f();return}else{a._onTorrentId(t)}})});function f(){o("on seed");if(typeof r==="function")r(a)}return a};S.prototype.remove=function(e,t){var r=this;o("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)};S.prototype.address=function(){var e=this;return{address:"0.0.0.0",family:"IPv4",port:e.torrentPort}};S.prototype.destroy=function(e){var t=this;if(t.destroyed)throw new Error("client already destroyed");t.destroyed=true;o("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)});d(r,e)}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{},e("buffer").Buffer)},{"./lib/torrent":6,"./package.json":168,_process:41,"bittorrent-dht/client":31,buffer:32,"create-torrent":82,debug:114,events:36,hat:120,inherits:122,"load-ip-set":31,"parse-torrent":126,path:40,"run-parallel":143,speedometer:149,xtend:165,"zero-fill":167}]},{},[169])(169)});
+(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(o,a){if(!t[o]){if(!e[o]){var f=typeof require=="function"&&require;if(!a&&f)return f(o,!0);if(s)return s(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var h=t[o]={exports:{}};e[o][0].call(h.exports,function(t){var r=e[o][1][t];return i(r?r:t)},h,h.exports,n,e,t,r)}return t[o].exports}var s=typeof require=="function"&&require;for(var o=0;o<r.length;o++)i(r[o]);return i}({1:[function(e,t,r){var n=e("./render");t.exports=function i(e,t,r){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.")}n(e,function(e){if(e==="video"||e==="audio")return i(e);else return s(e)},function(e,t){if(e&&t)t.remove();r(e,t)});function i(e){var r=s(e);r.controls=true;r.autoplay=true;r.play();t.appendChild(r);return r}function s(e){var r=document.createElement(e);t.appendChild(r);return r}}},{"./render":7}],2:[function(e,t,r){t.exports=o;var n=e("debug")("webtorrent:file-stream");var i=e("inherits");var s=e("stream");i(o,s.Readable);function o(e,t){s.Readable.call(this,t);this.destroyed=false;this._torrent=e._torrent;var r=t&&t.start||0;var n=t&&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)}o.prototype._read=function(){if(this._reading)return;this._reading=true;this._notify()};o.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};o.prototype.destroy=function(){if(this.destroyed)return;this.destroyed=true;this._torrent.deselect(this._startPiece,this._endPiece,true)}},{debug:116,inherits:124,stream:61}],3:[function(e,t,r){(function(r,n){t.exports=d;var i=e("./append-to");var s=e("./render-to");var o=e("end-of-stream");var a=e("events").EventEmitter;var f=e("./file-stream");var u=e("inherits");var h=e("./mime.json");var l=e("path");var c=e("stream");u(d,a);function d(e,t){a.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(){if(this.length===0)return;this._torrent.select(this._startPiece,this._endPiece,false)};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 n=new c.PassThrough;r.nextTick(function(){n.end()});return n}var i=new f(t,e);t._torrent.select(i._startPiece,i._endPiece,true,function(){i._notify()});o(i,function(){t._torrent.deselect(i._startPiece,i._endPiece,true)});return i};d.prototype.getBuffer=function(e){var t=new n(this.length);var r=0;this.createReadStream().on("data",function(e){e.copy(t,r);r+=e.length}).on("end",function(){e(null,t)}).on("error",e)};d.prototype.getBlobURL=function(e){var t=this;if(typeof window==="undefined")throw new Error("browser-only method");t.getBuffer(function(r,n){if(r)return e(r);var i=l.extname(t.name).toLowerCase();var s=h[i];var o=s?new window.Blob([n],{type:s}):new window.Blob([n]);var a=window.URL.createObjectURL(o);e(null,a)})};d.prototype.appendTo=function(e,t){if(typeof window==="undefined")throw new Error("browser-only method");if(typeof e==="string")e=document.querySelector(e);i(this,e,t)};d.prototype.renderTo=function(e,t){if(typeof window==="undefined")throw new Error("browser-only method");if(typeof e==="string")e=document.querySelector(e);s(this,e,t)}}).call(this,e("_process"),e("buffer").Buffer)},{"./append-to":1,"./file-stream":2,"./mime.json":4,"./render-to":6,_process:43,buffer:34,"end-of-stream":119,events:38,inherits:124,path:42,stream:61}],4:[function(e,t,r){t.exports={".aac":"audio/aac",".css":"text/css",".html":"text/html",".js":"application/javascript",".m4a":"audio/mp4",".md":"text/x-markdown",".mp3":"audio/mpeg",".mp4":"video/mp4",".oga":"audio/ogg",".ogg":"audio/ogg",".pdf":"application/pdf",".txt":"text/plain",".wav":"audio/wav",".webm":"video/webm"}},{}],5:[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 s=t.pieces[i];if(s===n){r.push(i)}else if(s<n){r=[i];n=s}}if(r.length>0){return r[Math.random()*r.length|0]}else{return-1}}},{}],6:[function(e,t,r){var n=e("path");var i=e("./render");t.exports=function s(e,t,r){i(e,function(r){if(t.nodeName!==r.toUpperCase()){var i=n.extname(e.name).toLowerCase();throw new Error('Cannot render "'+i+'" inside a "'+t.nodeName.toLowerCase()+'" element, expected "'+r+'"')}return t},r)}},{"./render":7,path:42}],7:[function(e,t,r){(function(r){var n=e("debug")("webtorrent:render");var i=e("mediasource");var s=e("path");var o=e("videostream");var a=[".mp4",".m4v",".m4a"];var f=[".mp4",".m4v",".webm"];var u=[".m4a",".mp3"];var h=f.concat(u);var l=[".wav",".aac",".ogg",".oga"];var c=[".jpg",".jpeg",".png",".gif",".bmp"];var d=[".css",".html",".js",".md",".pdf",".txt"];var p=typeof window!=="undefined"&&window.MediaSource;t.exports=function g(e,t,r){if(!r)r=m;var u;var g=s.extname(e.name).toLowerCase();var y=0;if(h.indexOf(g)>=0)_();else if(l.indexOf(g)>=0)w();else if(c.indexOf(g)>=0)S();else if(d.indexOf(g)>=0)x();else v(r,new Error('Unsupported file type "'+g+'": Cannot append to DOM'));function _(){if(!p){return v(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 s=f.indexOf(g)>=0?"video":"audio";if(a.indexOf(g)>=0)h();else l();function h(){n("Use `videostream` package for "+e.name);_();u.addEventListener("error",d);u.addEventListener("playing",b);o(e,u)}function l(){n("Use MediaSource API for "+e.name);_();u.addEventListener("error",m);u.addEventListener("playing",b);e.createReadStream().pipe(new i(u,{extname:g}));if(y)u.currentTime=y}function c(){n("Use Blob URL for "+e.name);_();u.addEventListener("error",k);u.addEventListener("playing",b);e.getBlobURL(function(e,t){if(e)return k(e);u.src=t;if(y)u.currentTime=y})}function d(e){n("videostream error: fallback to MediaSource API: %o",e.message||e);u.removeEventListener("error",d);u.removeEventListener("playing",b);l()}function m(e){n("MediaSource API error: fallback to Blob URL: %o",e.message||e);u.removeEventListener("error",m);u.removeEventListener("playing",b);c()}function _(){if(!u){u=t(s);u.addEventListener("progress",function(){y=u.currentTime})}}}function b(){u.removeEventListener("playing",b);r(null,u)}function w(){u=t("audio");e.getBlobURL(function(e,t){if(e)return k(e);u.addEventListener("error",k);u.addEventListener("playing",b);u.src=t})}function S(){u=t("img");e.getBlobURL(function(t,n){if(t)return k(t);u.src=n;u.alt=e.name;r(null,u)})}function x(){u=t("iframe");e.getBlobURL(function(e,t){if(e)return k(e);u.src=t;if(g!==".pdf")u.sandbox="allow-forms allow-scripts";r(null,u)})}function k(t){t.message='Error rendering file "'+e.name+'": '+t.message;n(t.message);if(r)r(t)}};function m(){}function v(e,t,n){r.nextTick(function(){if(e)e(t,n)})}}).call(this,e("_process"))},{_process:43,debug:116,mediasource:125,path:42,videostream:166}],8:[function(e,t,r){(function(r,n){t.exports=H;var i=e("addr-to-ip-port");var s=e("bitfield");var o=e("chunk-store-stream/write");var a=e("create-torrent");var f=e("debug")("webtorrent:torrent");var u=e("torrent-discovery");var h=e("events").EventEmitter;var l=e("xtend/mutable");var c=e("fs-chunk-store");var d=e("immediate-chunk-store");var p=e("inherits");var m=e("multistream");var v=e("os");var g=e("run-parallel");var y=e("parse-torrent");var _=e("path");var b=e("path-exists");var w=e("torrent-piece");var S=e("pump");var x=e("random-iterate");var k=e("re-emitter");var E=e("simple-sha1");var A=e("bittorrent-swarm");var U=e("uniq");var I=e("ut_metadata");var T=e("ut_pex");var B=e("./file");var L=e("./rarity-map");var C=e("./server");var R=128*1024;var P=3e4;var F=5e3;var O=3*w.BLOCK_LENGTH;var D=.5;var M=1;var N=1e4;var z=2;var j=typeof b.sync==="function"?_.join(b.sync("/tmp")?"/tmp":v.tmpDir(),"webtorrent"):"/tmp/webtorrent";p(H,h);function H(e,t){h.call(this);if(!f.enabled)this.setMaxListeners(0);f("new torrent");this.client=t.client;this.announce=t.announce;this.urlList=t.urlList;this.path=t.path;this._store=t.store||c;this.strategy=t.strategy||"sequential";this._rechokeNumSlots=t.uploads===false||t.uploads===0?0:+t.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)this._onTorrentId(e)}Object.defineProperty(H.prototype,"timeRemaining",{get:function(){if(this.done)return 0;if(this.swarm.downloadSpeed()===0)return Infinity;else return(this.length-this.downloaded)/this.swarm.downloadSpeed()*1e3}});Object.defineProperty(H.prototype,"downloaded",{get:function(){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(H.prototype,"received",{get:function(){return this.swarm?this.swarm.downloaded:0}});Object.defineProperty(H.prototype,"uploaded",{get:function(){return this.swarm?this.swarm.uploaded:0}});Object.defineProperty(H.prototype,"progress",{get:function(){return this.length?this.downloaded/this.length:0}});Object.defineProperty(H.prototype,"ratio",{get:function(){return this.uploaded/(this.downloaded||1)}});Object.defineProperty(H.prototype,"numPeers",{get:function(){return this.swarm?this.swarm.numPeers:0}});Object.defineProperty(H.prototype,"torrentFileURL",{get:function(){if(typeof window==="undefined")throw new Error("browser-only property");if(!this.torrentFile)return null;return window.URL.createObjectURL(new window.Blob([this.torrentFile],{type:"application/x-bittorrent"}))}});H.prototype.downloadSpeed=function(){return this.swarm?this.swarm.downloadSpeed():0};H.prototype.uploadSpeed=function(){return this.swarm?this.swarm.uploadSpeed():0};H.prototype._onTorrentId=function(e){var t=this;if(t.destroyed)return;y.remote(e,function(e,r){if(t.destroyed)return;if(e)return t._onError(e);t._onParsedTorrent(r)})};H.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=_.join(j,t.infoHash);t.swarm=new A(t.infoHash,t.client.peerId,{handshake:{dht:t.private?false:!!t.client.dht}});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));r.nextTick(function(){if(t.destroyed)return;t.emit("infoHash",t.infoHash)})};H.prototype._processParsedTorrent=function(e){if(this.announce){e.announce=e.announce.concat(this.announce)}if(this.client.tracker&&n.WEBTORRENT_ANNOUNCE){e.announce=e.announce.concat(n.WEBTORRENT_ANNOUNCE)}if(this.client.tracker&&e.announce.length===0){e.announce=a.announceList.map(function(e){return e[0]})}if(this.urlList){e.urlList=e.urlList.concat(this.urlList)}U(e.announce);U(e.urlList);l(this,e);this.magnetURI=y.toMagnetURI(e);this.torrentFile=y.toTorrentFile(e)};H.prototype._onSwarmListening=function(){var e=this;if(e.destroyed)return;if(e.swarm.server)e.client.torrentPort=e.swarm.address().port;e.discovery=new u({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.setTorrent(e.infoHash);e.discovery.on("peer",e.addPeer.bind(e));k(e.discovery,e,["trackerAnnounce","dhtAnnounce","warning"]);if(e.info)e._onMetadata(e);e.emit("listening",e.client.torrentPort)};H.prototype._onMetadata=function(e){var t=this;if(t.metadata||t.destroyed)return;f("got metadata");var r;if(e&&e.infoHash){r=e}else{try{r=y(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 L(t.swarm,t.pieces.length);t.store=new d(new t._store(t.pieceLength,{files:t.files.map(function(e){return{path:_.join(t.path,e.path),length:e.length,offset:e.offset}}),length:t.length}));t.files=t.files.map(function(e){return new B(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 w(n)});t._reservations=t.pieces.map(function(){return[]});t.bitfield=new s(t.pieces.length);t.swarm.wires.forEach(function(e){if(e.ut_metadata)e.ut_metadata.setMetadata(t.metadata);t._onWireWithMetadata(e)});f("verifying existing torrent data");g(t.pieces.map(function(e,r){return function(e){t.store.get(r,function(n,i){if(n)return e(null);E(i,function(n){if(n===t._hashes[r]){if(!t.pieces[r])return;f("piece verified %s",r);t.pieces[r]=null;t._reservations[r]=null;t.bitfield.set(r,true)}else{f("piece invalid %s",r)}e(null)})})}}),function(e){if(e)return t._onError(e);f("done verifying");t._onStore()});t.emit("metadata")};H.prototype._onStore=function(){var e=this;if(e.destroyed)return;f("on store");e.select(0,e.pieces.length-1,false);e._rechokeIntervalId=setInterval(e._rechoke.bind(e),N);if(e._rechokeIntervalId.unref)e._rechokeIntervalId.unref();e.ready=true;e.emit("ready");e._checkDone()};H.prototype.destroy=function(e){var t=this;if(t.destroyed)return;t.destroyed=true;f("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)});g(r,e)};H.prototype.addPeer=function(e){var t=this;function r(){t.swarm.addPeer(e);t.emit("peer",e)}if(typeof e==="string"&&t.client.blocked&&t.client.blocked.contains(i(e)[0])){t.numBlockedPeers+=1;t.emit("blockedPeer",e);return false}else{if(t.swarm)r();else t.once("listening",r);return true}};H.prototype.addWebSeed=function(e){var t=this;f("add web seed %s",e);t.swarm.addWebSeed(e,t)};H.prototype.select=function(e,t,r,n){var i=this;if(e>t||e<0||t>=i.pieces.length){throw new Error("invalid selection ",e,":",t)}r=Number(r)||0;f("select %s-%s (priority %s)",e,t,r);i._selections.push({from:e,to:t,offset:0,priority:r,notify:n||W});i._selections.sort(function(e,t){return t.priority-e.priority});i._updateSelections()};H.prototype.deselect=function(e,t,r){var n=this;r=Number(r)||0;f("deselect %s-%s (priority %s)",e,t,r);for(var i=0;i<n._selections.length;++i){var s=n._selections[i];if(s.from===e&&s.to===t&&s.priority===r){n._selections.splice(i--,1);break}}n._updateSelections()};H.prototype.critical=function(e,t){var r=this;f("critical %s-%s",e,t);for(var n=e;n<=t;++n){r._critical[n]=true}r._updateSelections()};H.prototype._onWire=function(e,t){var r=this;f("got wire (%s)",t||"Unknown");if(t){var n=i(t);e.remoteAddress=n[0];e.remotePort=n[1]}if(e.peerExtensions.dht&&r.client.dht&&r.client.dht.listening){e.on("port",function(t){if(!e.remoteAddress){f("ignoring port from peer with no address");return}f("port: %s (from %s)",t,e.remoteAddress+":"+e.remotePort);r.client.dht.addNode(e.remoteAddress+":"+t)});e.port(r.client.dht.address().port)}e.on("timeout",function(){f("wire timeout (%s)",t);e.destroy()});e.setTimeout(P,true);e.setKeepAlive(true);e.use(I(r.metadata));if(!r.metadata){e.ut_metadata.on("metadata",function(e){f("got metadata via ut_metadata");r._onMetadata(e)});e.ut_metadata.fetch()}if(typeof T==="function"&&!r.private){e.use(T());e.ut_pex.on("peer",function(e){f("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];if(n&&!n.connected){f("ut_pex: dropped peer: %s (from %s)",e,t);r.swarm.removePeer(e)}})}r.emit("wire",e,t);if(r.metadata){r._onWireWithMetadata(e)}};H.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,F);if(r.unref)r.unref()}}var i=0;function s(){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(){s();t._update()});e.on("have",function(){s();t._update()});e.once("interested",function(){e.unchoke()});e.on("close",function(){clearTimeout(r)});e.on("choke",function(){clearTimeout(r);r=setTimeout(n,F);if(r.unref)r.unref()});e.on("unchoke",function(){clearTimeout(r);t._update()});e.on("request",function(r,n,i,s){if(i>R){return e.destroy()}if(t.pieces[r])return;t.store.get(r,{offset:n,length:i},s)});e.bitfield(t.bitfield);e.interested();r=setTimeout(n,F);if(r.unref)r.unref();e.isSeeder=false;s()};H.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()};H.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")};H.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")};H.prototype._update=function(){var e=this;if(e.destroyed)return;var t=x(e.swarm.wires);var r;while(r=t()){e._updateWire(r)}};H.prototype._updateWire=function(e){var t=this;if(e.peerChoking)return;if(!e.downloaded)return s();var r=q(e,D);if(e.requests.length>=r)return;var n=q(e,M);f(false)||f(true);function i(t,r,n,i){return function(s){return s>=t&&s<=r&&!(s in n)&&e.peerPieces.get(s)&&(!i||i(s))}}function s(){if(e.requests.length)return;var r=t._selections.length;while(r--){var n=t._selections[r];var s;if(t.strategy==="rarest"){var o=n.from+n.offset;var a=n.to;var f=a-o+1;var u={};var h=0;var l=i(o,a,u);while(h<f){s=t.rarityMap.getRarestPiece(l);if(s<0)break;if(t._request(e,s,false))return;u[s]=true;h+=1}}else{for(s=n.to;s>=n.from+n.offset;--s){if(!e.peerPieces.get(s))continue;if(t._request(e,s,false))return}}}}function o(){var r=e.downloadSpeed()||1;if(r>O)return function(){return true};var n=Math.max(1,e.requests.length)*w.BLOCK_LENGTH/r;var i=10;var s=0;return function(e){if(!i||t.bitfield.get(e))return true;var o=t.pieces[e].missing;for(;s<t.swarm.wires.length;s++){var a=t.swarm.wires[s];var f=a.downloadSpeed();if(f<O)continue;if(f<=r)continue;if(!a.peerPieces.get(e))continue;if((o-=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 s=o();for(var f=0;f<t._selections.length;f++){var u=t._selections[f];var h;if(t.strategy==="rarest"){var l=u.from+u.offset;var c=u.to;var d=c-l+1;var p={};var m=0;var v=i(l,c,p,s);while(m<d){h=t.rarityMap.getRarestPiece(v);if(h<0)break;while(t._request(e,h,t._critical[h]||r)){}if(e.requests.length<n){p[h]=true;m++;continue}if(u.priority)a(f);return true}}else{for(h=u.from+u.offset;h<=u.to;h++){if(!e.peerPieces.get(h)||!s(h))continue;while(t._request(e,h,t._critical[h]||r)){}if(e.requests.length<n)continue;if(u.priority)a(f);return true}}}return false}};H.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(o);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 s=i[G(i.length)];if(s){s.isChoked=false;e._rechokeOptimisticWire=s.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 o(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}};H.prototype._hotswap=function(e,t){var r=this;var n=e.downloadSpeed();if(n<w.BLOCK_LENGTH)return false;if(!r._reservations[t])return false;var i=r._reservations[t];if(!i){return false}var s=Infinity;var o;var a;for(a=0;a<i.length;a++){var f=i[a];if(!f||f===e)continue;var u=f.downloadSpeed();if(u>=O)continue;if(2*u>n||u>s)continue;o=f;s=u}if(!o)return false;for(a=0;a<i.length;a++){if(i[a]===o)i[a]=null}for(a=0;a<o.requests.length;a++){var h=o.requests[a];if(h.piece!==t)continue;r.pieces[t].cancel(h.offset/w.BLOCK_SIZE|0)}r.emit("hotswap",o,e,t);return true};H.prototype._request=function(e,t,n){var i=this;var s=e.requests.length;if(i.bitfield.get(t))return false;var o=q(e,M);if(s>=o)return false;var a=i.pieces[t];var u=a.reserve();if(u===-1&&n&&i._hotswap(e,t)){u=a.reserve()}if(u===-1)return false;var h=i._reservations[t];if(!h)h=i._reservations[t]=[];var l=h.indexOf(null);if(l===-1)l=h.length;h[l]=e;var c=a.chunkOffset(u);var d=a.chunkLength(u);e.request(t,c,d,function m(r,n){if(!i.ready)return i.once("ready",function(){m(r,n)});if(h[l]===e)h[l]=null;if(a!==i.pieces[t])return p();if(r){f("error getting piece %s (offset: %s length: %s) from %s: %s",t,c,d,e.remoteAddress+":"+e.remotePort,r.message);a.cancel(u);p();return}f("got piece %s (offset: %s length: %s) from %s",t,c,d,e.remoteAddress+":"+e.remotePort);if(!a.set(u,n,e))return p();var s=a.flush();E(s,function(e){if(e===i._hashes[t]){if(!i.pieces[t])return;f("piece verified %s",t);i.pieces[t]=null;i._reservations[t]=null;i.bitfield.set(t,true);i.store.put(t,s);i.swarm.wires.forEach(function(e){e.have(t)});i._checkDone()}else{i.pieces[t]=new w(a.length);i.emit("warning",new Error("Piece "+t+" failed verification"))}p()})});function p(){r.nextTick(function(){i._update()})}return true};H.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");f("file done: "+t.name)});if(e.files.every(function(e){return e.done})){e.done=true;e.emit("done");f("torrent done: "+e.infoHash);if(e.discovery.tracker)e.discovery.tracker.complete()}e._gcSelections()};H.prototype.load=function(e,t){var r=this;if(!Array.isArray(e))e=[e];if(!t)t=W;var n=new m(e);var i=new o(r.store,r.pieceLength);S(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)})};H.prototype.createServer=function(e){var t=this;if(typeof C!=="function")throw new Error("node.js-only method");var r=new C(t,e);t._servers.push(r);return r};H.prototype._onError=function(e){var t=this;f("torrent error: %s",e.message||e);t.emit("error",e);t.destroy()};function q(e,t){return Math.ceil(2+t*e.downloadSpeed()/w.BLOCK_LENGTH)}function G(e){return Math.random()*e|0}function W(){}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./file":3,"./rarity-map":5,"./server":33,_process:43,"addr-to-ip-port":9,bitfield:10,"bittorrent-swarm":11,"chunk-store-stream/write":83,"create-torrent":84,debug:116,events:38,"fs-chunk-store":126,"immediate-chunk-store":123,inherits:124,multistream:127,os:33,"parse-torrent":128,path:42,"path-exists":33,pump:140,"random-iterate":143,"re-emitter":144,"run-parallel":145,"simple-sha1":149,"torrent-discovery":152,"torrent-piece":153,uniq:154,ut_metadata:155,ut_pex:33,"xtend/mutable":168}],9:[function(e,t,r){var n=/^\[?([^\]]+)\]?:(\d+)$/;var i={};var s=0;t.exports=function o(e){if(s===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])];s+=1}return i[e]};t.exports.reset=function a(){i={};s=0}},{}],10:[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:34}],11:[function(e,t,r){(function(r,n){t.exports=p;var i=e("addr-to-ip-port");var s=e("debug")("bittorrent-swarm");var o=e("events").EventEmitter;var a=e("inherits");var f=e("net");var u=e("speedometer");var h=e("./lib/peer");var l=e("./lib/tcp-pool");var c=55;var d=[1e3,5e3,15e3];a(p,o);function p(e,t,r){var i=this;if(!(i instanceof p))return new p(e,t,r);o.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={};s("new swarm (i %s p %s)",i.infoHash,i.peerId);i.handshakeOpts=r.handshake;i.maxConns=r.maxConns!==undefined?r.maxConns:c;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)){s("ignoring invalid peer %s (from swarm.addPeer)",e);return null}var r=e&&e.id||e;if(t._peers[r])return;s("addPeer %s",r);var n;if(typeof e==="string"){n=h.createOutgoingTCPPeer(e,t)}else{if(t.paused){e.destroy(new Error("swarm paused"));return null}n=h.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)){s("ignoring invalid web seed %s (from swarm.addWebSeed)",e);return}if(r._peers[e])return;s("addWebSeed %s",e);var n=h.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)"))}s("_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;s("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;s("pause");e.paused=true};p.prototype.resume=function(){var e=this;if(e.destroyed)return;s("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;s("listen %s",e);var o=l.addSwarm(i);i.server=o.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);s("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;s("_drain numConns %s maxConns %s",e.numConns,e.maxConns);if(typeof f.connect!=="function"||e.destroyed||e.paused||e.numConns>=e.maxConns){
+return}s("drain (%s queued, %s/%s peers)",e.numQueued,e.numPeers,e.maxConns);var t=e._queue.shift();if(!t)return;s("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 o=t.conn=f.connect(n);o.once("connect",function(){t.onConnect()});o.once("error",function(e){t.destroy(e)});t.setConnectTimeout();o.on("close",function(){if(e.destroyed)return;if(t.retries>=d.length){s("conn %s closed: will not re-add (max %s attempts)",t.addr,d.length);return}var r=d[t.retries];s("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 s=r[1];return s>0&&s<65535&&!(n==="127.0.0.1"&&s===t._port)}}).call(this,e("_process"),e("buffer").Buffer)},{"./lib/peer":12,"./lib/tcp-pool":33,_process:43,"addr-to-ip-port":33,buffer:34,debug:116,events:38,inherits:124,net:33,speedometer:151}],12:[function(e,t,r){var n=e("debug")("bittorrent-swarm:peer");var i=e("./webconn");var s=e("bittorrent-protocol");var o=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 s;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)});if(!r.sentHandshake)r.handshake();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)};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"))},o);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 s=t.wire;t.conn=null;t.swarm=null;t.wire=null;if(r&&s){var o=r.wires.indexOf(s);if(o>=0)r.wires.splice(o,1)}if(i)i.destroy();if(s)s.destroy();if(r)r.removePeer(t.id)}},{"./webconn":13,"bittorrent-protocol":14,debug:116}],13:[function(e,t,r){t.exports=u;var n=e("bitfield");var i=e("debug")("bittorrent-swarm:webconn");var s=e("simple-get");var o=e("inherits");var a=e("simple-sha1");var f=e("bittorrent-protocol");o(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 s=new n(i);for(var o=0;o<=i;o++){s.set(o,true)}r.bitfield(s)});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,s){i("request pieceIndex=%d offset=%d length=%d",e,t,n);r.httpRequest(e,t,n,s)})}u.prototype.httpRequest=function(e,t,r,n){var o=this;var a=e*o.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 h={url:o.url,method:"GET",headers:{"user-agent":"WebTorrent (http://webtorrent.io)",range:"bytes="+f+"-"+u}};s.concat(h,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:10,"bittorrent-protocol":14,debug:116,inherits:124,"simple-get":146,"simple-sha1":149}],14:[function(e,t,r){(function(r){t.exports=w;var n=e("bencode");var i=e("bitfield");var s=e("debug")("bittorrent-protocol");var o=e("xtend");var a=e("hat");var f=e("inherits");var u=e("speedometer");var h=e("stream");var l=4e5;var c=new r("BitTorrent protocol");var d=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,h.Duplex);function w(){if(!(this instanceof w))return new w;h.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();h.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(d)};w.prototype.handshake=function(e,t,n){var i,s;if(typeof e==="string"){i=new r(e,"hex")}else{i=e;e=i.toString("hex")}if(typeof t==="string"){s=new r(t,"hex")}else{s=t;t=s.toString("hex")}if(i.length!==20||s.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 o=new r(y);o[5]|=16;if(n&&n.dht)o[7]|=1;this._push(r.concat([c,o,i,s]));this._handshakeSent=true;if(this.peerExtensions.extended){this._sendExtendedHandshake()}};w.prototype._sendExtendedHandshake=function(){var e=o(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))};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(S(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 s=r.isBuffer(t)?t:n.encode(t);this._message(20,[],r.concat([i,s]))}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 s;for(s in this._ext){this._ext[s].onHandshake(n,i,r)}if(r.extended&&this._handshakeSent){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,s){if(i!==S(this.peerRequests,e,t,r))return;if(n)return;this.piece(e,t,s)}.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(S(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);S(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 s;if(typeof r.m==="object"){for(s in r.m){this.peerExtendedMapping[s]=Number(r.m[s].toString())}}for(s in this._ext){if(this.peerExtendedMapping[s]){this._ext[s].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 s=new r(5+4*t.length);s.writeUInt32BE(s.length+i-4,0);s[4]=e;for(var o=0;o<t.length;o++){s.writeUInt32BE(t[o],5+4*o)}this._push(s);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];s.apply(null,e)};function S(e,t,r,n){for(var i=0;i<e.length;i++){var s=e[i];if(s.piece!==t||s.offset!==r||s.length!==n)continue;if(i===0)e.shift();else e.splice(i,1);return s}return null}}).call(this,e("buffer").Buffer)},{bencode:15,bitfield:10,buffer:34,debug:116,hat:122,inherits:124,speedometer:151,stream:61,xtend:167}],15:[function(e,t,r){t.exports={encode:e("./lib/encode"),decode:e("./lib/decode")}},{"./lib/decode":16,"./lib/encode":18}],16:[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":17,buffer:34}],17:[function(e,t,r){var n=t.exports=function i(){Object.defineProperty(this,"_keys",{enumerable:false,value:[]})};n.prototype.binaryKeys=function s(){return this._keys.slice()};n.prototype.binarySet=function o(e,t){this._keys.push(e);this[e]=t}},{}],18:[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"),s=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 s=n/i<<0;var o=n%i<<0;var a=s*i+o;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 s=0;var o;var a=Object.keys(t).sort();var f=a.length;for(;s<f;s++){o=a[s];r.bytes(e,o);r._encode(e,t[o])}e.push(n)};r.list=function(e,t){var i=0,o=1;var a=t.length;e.push(s);for(;i<a;i++){r._encode(e,t[i])}e.push(n)};t.exports=r}).call(this,e("buffer").Buffer)},{buffer:34}],19:[function(e,t,r){(function(r,n){t.exports=m;var i=e("events").EventEmitter;var s=e("debug")("bittorrent-tracker");var o=e("inherits");var a=e("once");var f=e("run-parallel");var u=e("uniq");var h=e("url");var l=e("./lib/common");var c=e("./lib/client/http-tracker");var d=e("./lib/client/udp-tracker");var p=e("./lib/client/websocket-tracker");o(m,i);function m(e,t,o,a){var f=this;if(!(f instanceof m))return new m(e,t,o,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 o.infoHash==="string"?o.infoHash:o.infoHash.toString("hex");f.infoHashBuffer=new n(f.infoHash,"hex");f._infoHashBinary=f.infoHashBuffer.toString("binary");f.torrentLength=o.length;f.destroyed=false;f._port=t;f._rtcConfig=a.rtcConfig;f._wrtc=a.wrtc;s("new client %s",f.infoHash);var l=!!f._wrtc||typeof window!=="undefined";var v=typeof o.announce==="string"?[o.announce]:o.announce==null?[]:o.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=h.parse(e).protocol;if((t==="http:"||t==="https:")&&typeof c==="function"){return new c(f,e)}else if(t==="udp:"&&typeof d==="function"){return new d(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 s=6881;var o={infoHash:Array.isArray(t)?t[0]:t,announce:[e]};var f=new m(i,s,o);f.once("error",r);var u=Array.isArray(t)?t.length:1;var h={};f.on("scrape",function(e){u-=1;h[e.infoHash]=e;if(u===0){f.destroy();var t=Object.keys(h);if(t.length===1){r(null,h[t[0]])}else{r(null,h)}}});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;s("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;s("send `stop`");e=t._defaultAnnounceOpts(e);e.event="stopped";t._announce(e)};m.prototype.complete=function(e){var t=this;s("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;s("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;s("send `scrape`");if(!e)e={};t._trackers.forEach(function(t){t.scrape(e)})};m.prototype.setInterval=function(e){var t=this;s("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;s("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":33,"./lib/client/udp-tracker":33,"./lib/client/websocket-tracker":21,"./lib/common":22,_process:43,buffer:34,debug:116,events:38,inherits:124,once:24,"run-parallel":145,uniq:154,url:68}],20:[function(e,t,r){t.exports=s;var n=e("events").EventEmitter;var i=e("inherits");i(s,n);function s(e,t){var r=this;n.call(r);r.client=e;r.announceUrl=t;r.interval=null;r.destroyed=false}s.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:38,inherits:124}],21:[function(e,t,r){t.exports=p;var n=e("debug")("bittorrent-tracker:websocket-tracker");var i=e("hat");var s=e("inherits");var o=e("simple-peer");var a=e("simple-websocket");var f=e("../common");var u=e("./tracker");var h={};var l=30*1e3;var c=5*1e3;var d=50*1e3;s(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);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",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=h[e.announceUrl];if(!e.socket){e.socket=h[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 s=e.interval||e["min interval"];if(s)t.setInterval(s*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 o({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 h=f.binaryToHex(e.offer_id);u=t.peers[h];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[h]=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)+c;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 s=[];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 o({initiator:true,trickle:false,config:r.client._rtcConfig,wrtc:r.client._wrtc});t.once("signal",function(t){s.push({offer:t,offer_id:f.hexToBinary(e)});h()});t.trackerTimeout=setTimeout(function(){n("tracker timeout: destroying peer");t.trackerTimeout=null;r.peers[e]=null;t.destroy()},d)}function h(){if(s.length===e){n("generated %s offers",e);t(s)}}};function m(){}},{"../common":22,"./tracker":20,debug:116,hat:122,inherits:124,"simple-peer":25,"simple-websocket":29}],22:[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":33,buffer:34,"xtend/mutable":168}],23:[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}}},{}],24:[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:23}],25:[function(e,t,r){(function(r){t.exports=l;var n=e("debug")("simple-peer");var i=e("get-browser-rtc");var s=e("hat");var o=e("inherits");var a=e("is-typedarray");var f=e("once");var u=e("stream");var h=e("typedarray-to-buffer");o(l,u.Duplex);function l(e){var t=this;if(!(t instanceof l))return new l(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||l.channelConfig;t.channelName=e.channelName||s(160);if(!e.initiator)t.channelName=null;t.config=e.config||l.config;t.constraints=e.constraints||l.constraints;t.reconnectTimer=e.reconnectTimer||0;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._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)})}})}l.WEBRTC_SUPPORT=!!i();l.config={iceServers:[{url:"stun:23.21.150.121",urls:"stun:23.21.150.121"}]};l.constraints={};l.channelConfig={};Object.defineProperty(l.prototype,"bufferSize",{get:function(){var e=this;return e._channel&&e._channel.bufferedAmount||0}});l.prototype.address=function(){var e=this;return{port:e.localPort,family:"IPv4",address:e.localAddress}};l.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),c,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"))}};l.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)&&!a.strict(e)){e=new Uint8Array(e)}var n=e.length||e.byteLength||e.size;t._channel.send(e);t._debug("write: %d bytes",n)};l.prototype.destroy=function(e){var t=this;t._destroy(null,e)};l.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")};l.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)};l.prototype._read=function(){};l.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}};l.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,c,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)};l.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,c,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)};l.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==="closed"){e._destroy()}};l.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"){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")}};l.prototype._onSignalingStateChange=function(){var e=this;if(e.destroyed)return;e._debug("signalingStateChange %s",e._pc.signalingState);e.emit("signalingStateChange",e._pc.signalingState)};l.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")}};l.prototype._onChannelMessage=function(e){var t=this;if(t.destroyed)return;var r=e.data;t._debug("read: %d bytes",r.byteLength||r.length);if(r instanceof ArrayBuffer){r=h(new Uint8Array(r));t.push(r)}else{try{r=JSON.parse(r)}catch(n){}t.emit("data",r)}};l.prototype._onChannelOpen=function(){var e=this;if(e.connected||e.destroyed)return;e._debug("on channel open");e._channelReady=true;e._maybeReady()};l.prototype._onChannelClose=function(){var e=this;if(e.destroyed)return;e._debug("on channel close");e._destroy()};l.prototype._onAddStream=function(e){var t=this;if(t.destroyed)return;t._debug("on add stream");t.emit("stream",e.stream)};l.prototype._onError=function(e){var t=this;if(t.destroyed)return;t._debug("error %s",e.message||e);t._destroy(e)};l.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 c(){}}).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":40,debug:116,"get-browser-rtc":26,hat:122,inherits:124,"is-typedarray":27,once:24,stream:61,"typedarray-to-buffer":28}],26:[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}},{}],27:[function(e,t,r){t.exports=s;s.strict=o;s.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 s(e){return o(e)||a(e)}function o(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)]}},{}],28:[function(e,t,r){(function(r){var n=e("is-typedarray").strict;t.exports=function(e){var t=r.TYPED_ARRAY_SUPPORT?r._augment:function(e){return new r(e)};if(e instanceof Uint8Array){return t(e)}else if(e instanceof ArrayBuffer){return t(new Uint8Array(e))}else if(n(e)){return t(new Uint8Array(e.buffer,e.byteOffset,e.byteLength))}else{return new r(e)}}}).call(this,e("buffer").Buffer)},{buffer:34,"is-typedarray":27}],29:[function(e,t,r){(function(r){t.exports=h;var n=e("debug")("simple-websocket");var i=e("inherits");var s=e("is-typedarray");var o=e("stream");var a=e("typedarray-to-buffer");var f=e("ws");var u=typeof window!=="undefined"?window.WebSocket:f;i(h,o.Duplex);function h(e,t){var r=this;if(!(r instanceof h))return new h(e,t);if(!t)t={};n("new websocket: %s %o",e,t);t.allowHalfOpen=false;if(t.highWaterMark==null)t.highWaterMark=1024*1024;o.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 u(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)})}})}h.WEBSOCKET_SUPPORT=!!u;h.prototype.send=function(e){var t=this;if(!s.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)};h.prototype.destroy=function(e){var t=this;t._destroy(null,e)};h.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 s=function(){i.onclose=null;r.emit("close")};if(i.readyState===u.CLOSED){s()}else{try{i.onclose=s;i.close()}catch(e){s()}}i.onopen=null;i.onmessage=null;i.onerror=null}r._ws=null;if(e)r.emit("error",e)};h.prototype._read=function(){};h.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(s){return i._onError(s)}if(typeof f!=="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}};h.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=a(new Uint8Array(i));t.push(i)}else if(r.isBuffer(i)){t.push(i)}else{try{i=JSON.parse(i)}catch(s){}t.emit("data",i)}};h.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 f!=="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")};h.prototype._onClose=function(){var e=this;if(e.destroyed)return;n("on close");e._destroy()};h.prototype._onError=function(e){var t=this;if(t.destroyed)return;n("error: %s",e.message||e);t._destroy(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":40,debug:116,inherits:124,"is-typedarray":30,stream:61,"typedarray-to-buffer":31,ws:33}],30:[function(e,t,r){arguments[4][27][0].apply(r,arguments)},{dup:27}],31:[function(e,t,r){arguments[4][28][0].apply(r,arguments)},{buffer:34,dup:28,"is-typedarray":30}],32:[function(e,t,r){},{}],33:[function(e,t,r){arguments[4][32][0].apply(r,arguments)},{dup:32}],34:[function(e,t,r){(function(t){"use strict";var n=e("base64-js");var i=e("ieee754");var s=e("isarray");r.Buffer=u;r.SlowBuffer=w;r.INSPECT_MAX_BYTES=50;u.poolSize=8192;var o={};u.TYPED_ARRAY_SUPPORT=t.TYPED_ARRAY_SUPPORT!==undefined?t.TYPED_ARRAY_SUPPORT:a();function a(){function e(){}try{var t=new Uint8Array(1);t.foo=function(){return 42};t.constructor=e;return t.foo()===42&&t.constructor===e&&typeof t.subarray==="function"&&t.subarray(1,1).byteLength===0}catch(r){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 h(this,e)}if(typeof e==="string"){return l(this,e,arguments.length>1?arguments[1]:"utf8")}return c(this,e)}function h(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=S(t,r)|0;e=_(e,n);e.write(t,r);return e}function c(e,t){if(u.isBuffer(t))return d(e,t);if(s(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 d(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){if(u.TYPED_ARRAY_SUPPORT){t.byteLength;e=u._augment(new Uint8Array(t))}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"&&s(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=u._augment(new Uint8Array(t));e.__proto__=u.prototype}else{e.length=t;e._isBuffer=true}var r=t!==0&&t<=u.poolSize>>>1;if(r)e.parent=o;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 te(e){return!!(e!=null&&e._isBuffer)};u.compare=function re(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 s=Math.min(r,n);while(i<s){if(e[i]!==t[i])break;++i}if(i!==s){r=e[i];n=t[i]}if(r<n)return-1;if(n<r)return 1;return 0};u.isEncoding=function ne(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 ie(e,t){if(!s(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 o=e[r];o.copy(n,i);i+=o.length}return n};function S(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 Z(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Q(e).length;default:if(n)return Z(e).length;t=(""+t).toLowerCase();n=true}}}u.byteLength=S;function x(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 O(this,t,r);case"utf8":case"utf-8":return L(this,t,r);case"ascii":return P(this,t,r);case"binary":return F(this,t,r);case"base64":return B(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return D(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase();n=true}}}u.prototype.toString=function se(){var e=this.length|0;if(e===0)return"";if(arguments.length===0)return L(this,0,e);return x.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 ae(){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 fe(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 ue(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")};u.prototype.get=function he(e){console.log(".get() is deprecated. Access using array indexes instead.");return this.readUInt8(e)};u.prototype.set=function le(e,t){console.log(".set() is deprecated. Access using array indexes instead.");return this.writeUInt8(e,t)};function k(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 s=t.length;if(s%2!==0)throw new Error("Invalid hex string");if(n>s/2){n=s/2}for(var o=0;o<n;o++){var a=parseInt(t.substr(o*2,2),16);if(isNaN(a))throw new Error("Invalid hex string");e[r+o]=a}return o}function E(e,t,r,n){return ee(Z(t,e.length-r),e,r,n)}function A(e,t,r,n){return ee(X(t),e,r,n)}function U(e,t,r,n){return A(e,t,r,n)}function I(e,t,r,n){return ee(Q(t),e,r,n)}function T(e,t,r,n){return ee(J(t,e.length-r),e,r,n)}u.prototype.write=function ce(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 s=this.length-t;if(r===undefined||r>s)r=s;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 o=false;for(;;){switch(n){case"hex":return k(this,e,t,r);case"utf8":case"utf-8":return E(this,e,t,r);case"ascii":return A(this,e,t,r);case"binary":return U(this,e,t,r);case"base64":return I(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase();o=true}}};u.prototype.toJSON=function de(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function B(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 s=e[i];var o=null;var a=s>239?4:s>223?3:s>191?2:1;if(i+a<=r){var f,u,h,l;switch(a){case 1:if(s<128){o=s}break;case 2:f=e[i+1];if((f&192)===128){l=(s&31)<<6|f&63;if(l>127){o=l}}break;case 3:f=e[i+1];u=e[i+2];if((f&192)===128&&(u&192)===128){l=(s&15)<<12|(f&63)<<6|u&63;if(l>2047&&(l<55296||l>57343)){o=l}}break;case 4:f=e[i+1];u=e[i+2];h=e[i+3];if((f&192)===128&&(u&192)===128&&(h&192)===128){l=(s&15)<<18|(f&63)<<12|(u&63)<<6|h&63;if(l>65535&&l<1114112){o=l}}}}if(o===null){o=65533;a=1}else if(o>65535){o-=65536;n.push(o>>>10&1023|55296);o=56320|o&1023}n.push(o);i+=a}return R(n)}var C=4096;function R(e){var t=e.length;if(t<=C){return String.fromCharCode.apply(String,e)}var r="";var n=0;while(n<t){r+=String.fromCharCode.apply(String,e.slice(n,n+=C))}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 F(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 O(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 s=t;s<r;s++){i+=$(e[s])}return i}function D(e,t,r){var n=e.slice(t,r);var i="";for(var s=0;s<n.length;s+=2){i+=String.fromCharCode(n[s]+n[s+1]*256)}return i}u.prototype.slice=function pe(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=u._augment(this.subarray(e,t))}else{var i=t-e;n=new u(i,undefined);for(var s=0;s<i;s++){n[s]=this[s+e]}}if(n.length)n.parent=this.parent||this;return n};function M(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 me(e,t,r){e=e|0;t=t|0;if(!r)M(e,t,this.length);var n=this[e];var i=1;var s=0;while(++s<t&&(i*=256)){n+=this[e+s]*i}return n};u.prototype.readUIntBE=function ve(e,t,r){e=e|0;t=t|0;if(!r){M(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 ge(e,t){if(!t)M(e,1,this.length);return this[e]};u.prototype.readUInt16LE=function ye(e,t){if(!t)M(e,2,this.length);return this[e]|this[e+1]<<8};u.prototype.readUInt16BE=function _e(e,t){if(!t)M(e,2,this.length);return this[e]<<8|this[e+1]};u.prototype.readUInt32LE=function be(e,t){if(!t)M(e,4,this.length);return(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};u.prototype.readUInt32BE=function we(e,t){if(!t)M(e,4,this.length);return this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};u.prototype.readIntLE=function Se(e,t,r){e=e|0;t=t|0;if(!r)M(e,t,this.length);var n=this[e];var i=1;var s=0;while(++s<t&&(i*=256)){n+=this[e+s]*i}i*=128;if(n>=i)n-=Math.pow(2,8*t);return n};u.prototype.readIntBE=function xe(e,t,r){e=e|0;t=t|0;if(!r)M(e,t,this.length);var n=t;var i=1;var s=this[e+--n];while(n>0&&(i*=256)){s+=this[e+--n]*i}i*=128;if(s>=i)s-=Math.pow(2,8*t);return s};u.prototype.readInt8=function ke(e,t){if(!t)M(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)M(e,2,this.length);var r=this[e]|this[e+1]<<8;return r&32768?r|4294901760:r};u.prototype.readInt16BE=function Ae(e,t){if(!t)M(e,2,this.length);var r=this[e+1]|this[e]<<8;return r&32768?r|4294901760:r};u.prototype.readInt32LE=function Ue(e,t){if(!t)M(e,4,this.length);return this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};u.prototype.readInt32BE=function Ie(e,t){if(!t)M(e,4,this.length);return this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};u.prototype.readFloatLE=function Te(e,t){if(!t)M(e,4,this.length);return i.read(this,e,true,23,4)};u.prototype.readFloatBE=function Be(e,t){if(!t)M(e,4,this.length);return i.read(this,e,false,23,4)};u.prototype.readDoubleLE=function Le(e,t){if(!t)M(e,8,this.length);return i.read(this,e,true,52,8)};u.prototype.readDoubleBE=function Ce(e,t){if(!t)M(e,8,this.length);return i.read(this,e,false,52,8)};function N(e,t,r,n,i,s){if(!u.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");if(t>i||t<s)throw new RangeError("value is out of bounds");if(r+n>e.length)throw new RangeError("index out of range")}u.prototype.writeUIntLE=function Re(e,t,r,n){e=+e;t=t|0;r=r|0;if(!n)N(this,e,t,r,Math.pow(2,8*r),0);var i=1;var s=0;this[t]=e&255;while(++s<r&&(i*=256)){this[t+s]=e/i&255}return t+r};u.prototype.writeUIntBE=function Pe(e,t,r,n){e=+e;t=t|0;r=r|0;if(!n)N(this,e,t,r,Math.pow(2,8*r),0);var i=r-1;var s=1;this[t+i]=e&255;while(--i>=0&&(s*=256)){this[t+i]=e/s&255}return t+r};u.prototype.writeUInt8=function Fe(e,t,r){e=+e;t=t|0;if(!r)N(this,e,t,1,255,0);if(!u.TYPED_ARRAY_SUPPORT)e=Math.floor(e);this[t]=e&255;return t+1};function z(e,t,r,n){if(t<0)t=65535+t+1;for(var i=0,s=Math.min(e.length-r,2);i<s;i++){e[r+i]=(t&255<<8*(n?i:1-i))>>>(n?i:1-i)*8}}u.prototype.writeUInt16LE=function Oe(e,t,r){e=+e;t=t|0;if(!r)N(this,e,t,2,65535,0);if(u.TYPED_ARRAY_SUPPORT){this[t]=e&255;this[t+1]=e>>>8}else{z(this,e,t,true)}return t+2};u.prototype.writeUInt16BE=function De(e,t,r){e=+e;t=t|0;if(!r)N(this,e,t,2,65535,0);if(u.TYPED_ARRAY_SUPPORT){this[t]=e>>>8;this[t+1]=e&255}else{z(this,e,t,false)}return t+2};function j(e,t,r,n){if(t<0)t=4294967295+t+1;for(var i=0,s=Math.min(e.length-r,4);i<s;i++){e[r+i]=t>>>(n?i:3-i)*8&255}}u.prototype.writeUInt32LE=function Me(e,t,r){e=+e;t=t|0;if(!r)N(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{j(this,e,t,true)}return t+4};u.prototype.writeUInt32BE=function Ne(e,t,r){e=+e;t=t|0;if(!r)N(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{j(this,e,t,false)}return t+4};u.prototype.writeIntLE=function ze(e,t,r,n){e=+e;t=t|0;if(!n){var i=Math.pow(2,8*r-1);N(this,e,t,r,i-1,-i)}var s=0;var o=1;var a=e<0?1:0;this[t]=e&255;while(++s<r&&(o*=256)){this[t+s]=(e/o>>0)-a&255}return t+r};u.prototype.writeIntBE=function je(e,t,r,n){e=+e;t=t|0;if(!n){var i=Math.pow(2,8*r-1);N(this,e,t,r,i-1,-i)}var s=r-1;var o=1;var a=e<0?1:0;this[t+s]=e&255;while(--s>=0&&(o*=256)){this[t+s]=(e/o>>0)-a&255}return t+r};u.prototype.writeInt8=function He(e,t,r){e=+e;t=t|0;if(!r)N(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 qe(e,t,r){e=+e;t=t|0;if(!r)N(this,e,t,2,32767,-32768);if(u.TYPED_ARRAY_SUPPORT){this[t]=e&255;this[t+1]=e>>>8}else{z(this,e,t,true)}return t+2};u.prototype.writeInt16BE=function Ge(e,t,r){e=+e;t=t|0;if(!r)N(this,e,t,2,32767,-32768);if(u.TYPED_ARRAY_SUPPORT){this[t]=e>>>8;this[t+1]=e&255}else{z(this,e,t,false)}return t+2};u.prototype.writeInt32LE=function We(e,t,r){e=+e;t=t|0;if(!r)N(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{j(this,e,t,true)}return t+4};u.prototype.writeInt32BE=function Ye(e,t,r){e=+e;t=t|0;if(!r)N(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{j(this,e,t,false)}return t+4};function H(e,t,r,n,i,s){if(t>i||t<s)throw new RangeError("value is out of bounds");if(r+n>e.length)throw new RangeError("index out of range");if(r<0)throw new RangeError("index out of range")}function q(e,t,r,n,s){if(!s){H(e,t,r,4,3.4028234663852886e38,-3.4028234663852886e38)}i.write(e,t,r,n,23,4);return r+4}u.prototype.writeFloatLE=function Ve(e,t,r){return q(this,e,t,true,r)};u.prototype.writeFloatBE=function Ke(e,t,r){return q(this,e,t,false,r)};function G(e,t,r,n,s){if(!s){H(e,t,r,8,1.7976931348623157e308,-1.7976931348623157e308)}i.write(e,t,r,n,52,8);return r+8}u.prototype.writeDoubleLE=function $e(e,t,r){return G(this,e,t,true,r)};u.prototype.writeDoubleBE=function Ze(e,t,r){return G(this,e,t,false,r)};u.prototype.copy=function Xe(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 s;if(this===e&&r<t&&t<n){for(s=i-1;s>=0;s--){e[s+t]=this[s+r]}}else if(i<1e3||!u.TYPED_ARRAY_SUPPORT){for(s=0;s<i;s++){e[s+t]=this[s+r]}}else{e._set(this.subarray(r,r+i),t)}return i};u.prototype.fill=function Je(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=Z(e.toString());var s=i.length;for(n=t;n<r;n++){this[n]=i[n%s]}}return this};u.prototype.toArrayBuffer=function Qe(){if(typeof Uint8Array!=="undefined"){if(u.TYPED_ARRAY_SUPPORT){return new u(this).buffer}else{var e=new Uint8Array(this.length);for(var t=0,r=e.length;t<r;t+=1){e[t]=this[t]}return e.buffer}}else{throw new TypeError("Buffer.toArrayBuffer not supported in this browser")}};var W=u.prototype;u._augment=function et(e){e.constructor=u;e._isBuffer=true;e._set=e.set;e.get=W.get;e.set=W.set;e.write=W.write;e.toString=W.toString;e.toLocaleString=W.toString;e.toJSON=W.toJSON;e.equals=W.equals;e.compare=W.compare;e.indexOf=W.indexOf;e.copy=W.copy;e.slice=W.slice;e.readUIntLE=W.readUIntLE;e.readUIntBE=W.readUIntBE;e.readUInt8=W.readUInt8;e.readUInt16LE=W.readUInt16LE;e.readUInt16BE=W.readUInt16BE;e.readUInt32LE=W.readUInt32LE;e.readUInt32BE=W.readUInt32BE;e.readIntLE=W.readIntLE;e.readIntBE=W.readIntBE;e.readInt8=W.readInt8;e.readInt16LE=W.readInt16LE;e.readInt16BE=W.readInt16BE;e.readInt32LE=W.readInt32LE;e.readInt32BE=W.readInt32BE;e.readFloatLE=W.readFloatLE;e.readFloatBE=W.readFloatBE;e.readDoubleLE=W.readDoubleLE;e.readDoubleBE=W.readDoubleBE;e.writeUInt8=W.writeUInt8;e.writeUIntLE=W.writeUIntLE;e.writeUIntBE=W.writeUIntBE;e.writeUInt16LE=W.writeUInt16LE;e.writeUInt16BE=W.writeUInt16BE;e.writeUInt32LE=W.writeUInt32LE;e.writeUInt32BE=W.writeUInt32BE;e.writeIntLE=W.writeIntLE;e.writeIntBE=W.writeIntBE;e.writeInt8=W.writeInt8;e.writeInt16LE=W.writeInt16LE;e.writeInt16BE=W.writeInt16BE;e.writeInt32LE=W.writeInt32LE;e.writeInt32BE=W.writeInt32BE;e.writeFloatLE=W.writeFloatLE;e.writeFloatBE=W.writeFloatBE;e.writeDoubleLE=W.writeDoubleLE;e.writeDoubleBE=W.writeDoubleBE;e.fill=W.fill;e.inspect=W.inspect;e.toArrayBuffer=W.toArrayBuffer;return e};var Y=/[^+\/0-9A-Za-z-_]/g;function V(e){e=K(e).replace(Y,"");if(e.length<2)return"";while(e.length%4!==0){e=e+"="}return e}function K(e){if(e.trim)return e.trim();return e.replace(/^\s+|\s+$/g,"")}function $(e){if(e<16)return"0"+e.toString(16);return e.toString(16)}function Z(e,t){t=t||Infinity;var r;var n=e.length;var i=null;var s=[];for(var o=0;o<n;o++){r=e.charCodeAt(o);if(r>55295&&r<57344){
+if(!i){if(r>56319){if((t-=3)>-1)s.push(239,191,189);continue}else if(o+1===n){if((t-=3)>-1)s.push(239,191,189);continue}i=r;continue}if(r<56320){if((t-=3)>-1)s.push(239,191,189);i=r;continue}r=(i-55296<<10|r-56320)+65536}else if(i){if((t-=3)>-1)s.push(239,191,189)}i=null;if(r<128){if((t-=1)<0)break;s.push(r)}else if(r<2048){if((t-=2)<0)break;s.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;s.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else{throw new Error("Invalid code point")}}return s}function X(e){var t=[];for(var r=0;r<e.length;r++){t.push(e.charCodeAt(r)&255)}return t}function J(e,t){var r,n,i;var s=[];for(var o=0;o<e.length;o++){if((t-=2)<0)break;r=e.charCodeAt(o);n=r>>8;i=r%256;s.push(i);s.push(n)}return s}function Q(e){return n.toByteArray(V(e))}function ee(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":35,ieee754:36,isarray:37}],35:[function(e,t,r){var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";(function(e){"use strict";var t=typeof Uint8Array!=="undefined"?Uint8Array:Array;var r="+".charCodeAt(0);var i="/".charCodeAt(0);var s="0".charCodeAt(0);var o="a".charCodeAt(0);var a="A".charCodeAt(0);var f="-".charCodeAt(0);var u="_".charCodeAt(0);function h(e){var t=e.charCodeAt(0);if(t===r||t===f)return 62;if(t===i||t===u)return 63;if(t<s)return-1;if(t<s+10)return t-s+26+26;if(t<a+26)return t-a;if(t<o+26)return t-o+26}function l(e){var r,n,i,s,o,a;if(e.length%4>0){throw new Error("Invalid string. Length must be a multiple of 4")}var f=e.length;o="="===e.charAt(f-2)?2:"="===e.charAt(f-1)?1:0;a=new t(e.length*3/4-o);i=o>0?e.length-4:e.length;var u=0;function l(e){a[u++]=e}for(r=0,n=0;r<i;r+=4,n+=3){s=h(e.charAt(r))<<18|h(e.charAt(r+1))<<12|h(e.charAt(r+2))<<6|h(e.charAt(r+3));l((s&16711680)>>16);l((s&65280)>>8);l(s&255)}if(o===2){s=h(e.charAt(r))<<2|h(e.charAt(r+1))>>4;l(s&255)}else if(o===1){s=h(e.charAt(r))<<10|h(e.charAt(r+1))<<4|h(e.charAt(r+2))>>2;l(s>>8&255);l(s&255)}return a}function c(e){var t,r=e.length%3,i="",s,o;function a(e){return n.charAt(e)}function f(e){return a(e>>18&63)+a(e>>12&63)+a(e>>6&63)+a(e&63)}for(t=0,o=e.length-r;t<o;t+=3){s=(e[t]<<16)+(e[t+1]<<8)+e[t+2];i+=f(s)}switch(r){case 1:s=e[e.length-1];i+=a(s>>2);i+=a(s<<4&63);i+="==";break;case 2:s=(e[e.length-2]<<8)+e[e.length-1];i+=a(s>>10);i+=a(s>>4&63);i+=a(s<<2&63);i+="=";break}return i}e.toByteArray=l;e.fromByteArray=c})(typeof r==="undefined"?this.base64js={}:r)},{}],36:[function(e,t,r){r.read=function(e,t,r,n,i){var s,o;var a=i*8-n-1;var f=(1<<a)-1;var u=f>>1;var h=-7;var l=r?i-1:0;var c=r?-1:1;var d=e[t+l];l+=c;s=d&(1<<-h)-1;d>>=-h;h+=a;for(;h>0;s=s*256+e[t+l],l+=c,h-=8){}o=s&(1<<-h)-1;s>>=-h;h+=n;for(;h>0;o=o*256+e[t+l],l+=c,h-=8){}if(s===0){s=1-u}else if(s===f){return o?NaN:(d?-1:1)*Infinity}else{o=o+Math.pow(2,n);s=s-u}return(d?-1:1)*o*Math.pow(2,s-n)};r.write=function(e,t,r,n,i,s){var o,a,f;var u=s*8-i-1;var h=(1<<u)-1;var l=h>>1;var c=i===23?Math.pow(2,-24)-Math.pow(2,-77):0;var d=n?0:s-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;o=h}else{o=Math.floor(Math.log(t)/Math.LN2);if(t*(f=Math.pow(2,-o))<1){o--;f*=2}if(o+l>=1){t+=c/f}else{t+=c*Math.pow(2,1-l)}if(t*f>=2){o++;f/=2}if(o+l>=h){a=0;o=h}else if(o+l>=1){a=(t*f-1)*Math.pow(2,i);o=o+l}else{a=t*Math.pow(2,l-1)*Math.pow(2,i);o=0}}for(;i>=8;e[r+d]=a&255,d+=p,a/=256,i-=8){}o=o<<i|a;u+=i;for(;u>0;e[r+d]=o&255,d+=p,o/=256,u-=8){}e[r+d-p]|=m*128}},{}],37:[function(e,t,r){var n={}.toString;t.exports=Array.isArray||function(e){return n.call(e)=="[object Array]"}},{}],38:[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(!s(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,s,f,u;if(!this._events)this._events={};if(e==="error"){if(!this._events.error||o(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:s=Array.prototype.slice.call(arguments,1);r.apply(this,s)}}else if(o(r)){s=Array.prototype.slice.call(arguments,1);u=r.slice();n=u.length;for(f=0;f<n;f++)u[f].apply(this,s)}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(o(this._events[e]))this._events[e].push(t);else this._events[e]=[this._events[e],t];if(o(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,s,a;if(!i(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;r=this._events[e];s=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(o(r)){for(a=s;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 s(e){return typeof e==="number"}function o(e){return typeof e==="object"&&e!==null}function a(e){return e===void 0}},{}],39:[function(e,t,r){var n=e("http");var i=t.exports;for(var s in n){if(n.hasOwnProperty(s))i[s]=n[s]}i.request=function(e,t){if(!e)e={};e.scheme="https";e.protocol="https:";return n.request.call(this,e,t)}},{http:62}],40:[function(e,t,r){t.exports=function(e){return!!(e!=null&&(e._isBuffer||e.constructor&&typeof e.constructor.isBuffer==="function"&&e.constructor.isBuffer(e)))}},{}],41:[function(e,t,r){t.exports=Array.isArray||function(e){return Object.prototype.toString.call(e)=="[object Array]"}},{}],42:[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 o=i>=0?arguments[i]:e.cwd();if(typeof o!=="string"){throw new TypeError("Arguments to path.resolve must be strings")}else if(!o){continue}r=o+"/"+r;n=o.charAt(0)==="/"}r=t(s(r.split("/"),function(e){return!!e}),!n).join("/");return(n?"/":"")+r||"."};r.normalize=function(e){var n=r.isAbsolute(e),i=o(e,-1)==="/";e=t(s(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(s(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 s=n(t.split("/"));var o=Math.min(i.length,s.length);var a=o;for(var f=0;f<o;f++){if(i[f]!==s[f]){a=f;break}}var u=[];for(var f=a;f<i.length;f++){u.push("..")}u=u.concat(s.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 s(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 o="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:43}],43:[function(e,t,r){var n=t.exports={};var i=[];var s=false;var o;var a=-1;function f(){s=false;if(o.length){i=o.concat(i)}else{a=-1}if(i.length){u()}}function u(){if(s){return}var e=setTimeout(f);s=true;var t=i.length;while(t){o=i;i=[];while(++a<t){if(o){o[a].run()}}a=-1;t=i.length}o=null;s=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 h(e,t));if(i.length===1&&!s){setTimeout(u,0)}};function h(e,t){this.fun=e;this.array=t}h.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}},{}],44:[function(t,r,n){(function(t){(function(i){var s=typeof n=="object"&&n&&!n.nodeType&&n;var o=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,h=36,l=1,c=26,d=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"},S=h-l,x=Math.floor,k=String.fromCharCode,E;function A(e){throw new RangeError(w[e])}function U(e,t){var r=e.length;var n=[];while(r--){n[r]=t(e[r])}return n}function I(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 s=U(i,t).join(".");return n+s}function T(e){var t=[],r=0,n=e.length,i,s;while(r<n){i=e.charCodeAt(r++);if(i>=55296&&i<=56319&&r<n){s=e.charCodeAt(r++);if((s&64512)==56320){t.push(((i&1023)<<10)+(s&1023)+65536)}else{t.push(i);r--}}else{t.push(i)}}return t}function B(e){return U(e,function(e){var t="";if(e>65535){e-=65536;t+=k(e>>>10&1023|55296);e=56320|e&1023}t+=k(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 h}function C(e,t){return e+22+75*(e<26)-((t!=0)<<5)}function R(e,t,r){var n=0;e=r?x(e/p):e>>1;e+=x(e/t);for(;e>S*c>>1;n+=h){e=x(e/S)}return x(n+(S+1)*e/(e+d))}function P(e){var t=[],r=e.length,n,i=0,s=v,o=m,a,f,d,p,y,_,b,w,S;a=e.lastIndexOf(g);if(a<0){a=0}for(f=0;f<a;++f){if(e.charCodeAt(f)>=128){A("not-basic")}t.push(e.charCodeAt(f))}for(d=a>0?a+1:0;d<r;){for(p=i,y=1,_=h;;_+=h){if(d>=r){A("invalid-input")}b=L(e.charCodeAt(d++));if(b>=h||b>x((u-i)/y)){A("overflow")}i+=b*y;w=_<=o?l:_>=o+c?c:_-o;if(b<w){break}S=h-w;if(y>x(u/S)){A("overflow")}y*=S}n=t.length+1;o=R(i-p,n,p==0);if(x(i/n)>u-s){A("overflow")}s+=x(i/n);i%=n;t.splice(i++,0,s)}return B(t)}function F(e){var t,r,n,i,s,o,a,f,d,p,y,_=[],b,w,S,E;e=T(e);b=e.length;t=v;r=0;s=m;for(o=0;o<b;++o){y=e[o];if(y<128){_.push(k(y))}}n=i=_.length;if(i){_.push(g)}while(n<b){for(a=u,o=0;o<b;++o){y=e[o];if(y>=t&&y<a){a=y}}w=n+1;if(a-t>x((u-r)/w)){A("overflow")}r+=(a-t)*w;t=a;for(o=0;o<b;++o){y=e[o];if(y<t&&++r>u){A("overflow")}if(y==t){for(f=r,d=h;;d+=h){p=d<=s?l:d>=s+c?c:d-s;if(f<p){break}E=f-p;S=h-p;_.push(k(C(p+E%S,0)));f=x(E/S)}_.push(k(C(f,0)));s=R(r,w,n==i);r=0;++n}}++r;++t}return _.join("")}function O(e){return I(e,function(e){return y.test(e)?P(e.slice(4).toLowerCase()):e})}function D(e){return I(e,function(e){return _.test(e)?"xn--"+F(e):e})}f={version:"1.3.2",ucs2:{decode:T,encode:B},decode:P,encode:F,toASCII:D,toUnicode:O};if(typeof e=="function"&&typeof e.amd=="object"&&e.amd){e("punycode",function(){return f})}else if(s&&o){if(r.exports==s){o.exports=f}else{for(E in f){f.hasOwnProperty(E)&&(s[E]=f[E])}}}else{i.punycode=f}})(this)}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],45:[function(e,t,r){"use strict";function n(e,t){return Object.prototype.hasOwnProperty.call(e,t)}t.exports=function(e,t,r,s){t=t||"&";r=r||"=";var o={};if(typeof e!=="string"||e.length===0){return o}var a=/\+/g;e=e.split(t);var f=1e3;if(s&&typeof s.maxKeys==="number"){f=s.maxKeys}var u=e.length;if(f>0&&u>f){u=f}for(var h=0;h<u;++h){var l=e[h].replace(a,"%20"),c=l.indexOf(r),d,p,m,v;if(c>=0){d=l.substr(0,c);p=l.substr(c+1)}else{d=l;p=""}m=decodeURIComponent(d);v=decodeURIComponent(p);if(!n(o,m)){o[m]=v}else if(i(o[m])){o[m].push(v)}else{o[m]=[o[m],v]}}return o};var i=Array.isArray||function(e){return Object.prototype.toString.call(e)==="[object Array]"}},{}],46:[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 s(o(e),function(o){var a=encodeURIComponent(n(o))+r;if(i(e[o])){return s(e[o],function(e){return a+encodeURIComponent(n(e))}).join(t)}else{return a+encodeURIComponent(n(e[o]))}}).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 s(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 o=Object.keys||function(e){var t=[];for(var r in e){if(Object.prototype.hasOwnProperty.call(e,r))t.push(r)}return t}},{}],47:[function(e,t,r){"use strict";r.decode=r.parse=e("./decode");r.encode=r.stringify=e("./encode")},{"./decode":45,"./encode":46}],48:[function(e,t,r){t.exports=e("./lib/_stream_duplex.js")},{"./lib/_stream_duplex.js":49}],49:[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 s=e("core-util-is");s.inherits=e("inherits");var o=e("./_stream_readable");var a=e("./_stream_writable");s.inherits(l,o);var f=n(a.prototype);for(var u=0;u<f.length;u++){var h=f[u];if(!l.prototype[h])l.prototype[h]=a.prototype[h]}function l(e){if(!(this instanceof l))return new l(e);o.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",c)}function c(){if(this.allowHalfOpen||this._writableState.ended)return;i(d,this)}function d(e){e.end()}function p(e,t){for(var r=0,n=e.length;r<n;r++){t(e[r],r)}}},{"./_stream_readable":51,"./_stream_writable":53,"core-util-is":54,inherits:124,"process-nextick-args":55}],50:[function(e,t,r){"use strict";t.exports=s;var n=e("./_stream_transform");var i=e("core-util-is");i.inherits=e("inherits");i.inherits(s,n);function s(e){if(!(this instanceof s))return new s(e);n.call(this,e)}s.prototype._transform=function(e,t,r){r(null,e)}},{"./_stream_transform":52,"core-util-is":54,inherits:124}],51:[function(e,t,r){(function(r){"use strict";t.exports=m;var n=e("process-nextick-args");var i=e("isarray");var s=e("buffer").Buffer;m.ReadableState=p;var o=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 s=e("buffer").Buffer;var u=e("core-util-is");u.inherits=e("inherits");var h=e("util");var l;if(h&&h.debuglog){l=h.debuglog("stream")}else{l=function(){}}var c;u.inherits(m,f);var d;function p(t,r){d=d||e("./_stream_duplex");t=t||{};this.objectMode=!!t.objectMode;if(r instanceof d)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(!c)c=e("string_decoder/").StringDecoder;this.decoder=new c(t.encoding);this.encoding=t.encoding}}var d;function m(t){d=d||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 s(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 s=w(t,r);if(s){e.emit("error",s)}else if(r===null){t.reading=false;S(e,t)}else if(t.objectMode||r&&r.length>0){if(t.ended&&!i){var o=new Error("stream.push() after EOF");e.emit("error",o)}else if(t.endEmitted&&i){var o=new Error("stream.unshift() after end event");e.emit("error",o)}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)x(e)}E(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(!c)c=e("string_decoder/").StringDecoder;this._readableState.decoder=new c(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)R(this);else x(this);return null}e=b(e,t);if(e===0&&t.ended){if(t.length===0)R(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=C(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)R(this);if(i!==null)this.emit("data",i);return i};function w(e,t){var r=null;if(!s.isBuffer(t)&&typeof t!=="string"&&t!==null&&t!==undefined&&!e.objectMode){r=new TypeError("Invalid non-string/buffer chunk")}return r}function S(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;x(e)}function x(e){var t=e._readableState;t.needReadable=false;if(!t.emittedReadable){l("emitReadable",t.flowing);t.emittedReadable=true;if(t.sync)n(k,e);else k(e)}}function k(e){l("emit readable");e.emit("readable");L(e)}function E(e,t){if(!t.readingMore){t.readingMore=true;n(A,e,t)}}function A(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 s=this;var o=this._readableState;switch(o.pipesCount){case 0:o.pipes=e;break;case 1:o.pipes=[o.pipes,e];break;default:o.pipes.push(e);break}o.pipesCount+=1;l("pipe count=%d opts=%j",o.pipesCount,t);var f=(!t||t.end!==false)&&e!==r.stdout&&e!==r.stderr;var u=f?c:m;if(o.endEmitted)n(u);else s.once("end",u);e.on("unpipe",h);function h(e){l("onunpipe");if(e===s){m()}}function c(){l("onend");e.end()}var d=U(s);e.on("drain",d);var p=false;function m(){l("cleanup");e.removeListener("close",y);e.removeListener("finish",_);e.removeListener("drain",d);e.removeListener("error",g);e.removeListener("unpipe",h);s.removeListener("end",c);s.removeListener("end",m);s.removeListener("data",v);p=true;if(o.awaitDrain&&(!e._writableState||e._writableState.needDrain))d()}s.on("data",v);function v(t){l("ondata");var r=e.write(t);if(false===r){if(o.pipesCount===1&&o.pipes[0]===e&&s.listenerCount("data")===1&&!p){l("false write response, pause",s._readableState.awaitDrain);s._readableState.awaitDrain++}s.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");s.unpipe(e)}e.emit("pipe",s);if(!o.flowing){l("pipe resume");s.resume()}return e};function U(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=O(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(I,this)}else if(i.length){x(this,i)}}}return r};m.prototype.addListener=m.prototype.on;function I(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;T(this,e)}return this};function T(e,t){if(!t.resumeScheduled){t.resumeScheduled=true;n(B,e,t)}}function B(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 s=n.push(i);if(!s){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 s=["error","close","destroy","pause","resume"];F(s,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=C;function C(e,t){var r=t.buffer;var n=t.length;var i=!!t.decoder;var o=!!t.objectMode;var a;if(r.length===0)return null;if(n===0)a=null;else if(o)a=r.shift();else if(!e||e>=n){if(i)a=r.join("");else if(r.length===1)a=r[0];else a=s.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 s(e);var u=0;for(var h=0,l=r.length;h<l&&u<e;h++){var f=r[0];var c=Math.min(e-u,f.length);if(i)a+=f.slice(0,c);else f.copy(a,u,0,c);if(c<f.length)r[0]=f.slice(c);else r.shift();u+=c}}}return a}function R(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 F(e,t){for(var r=0,n=e.length;r<n;r++){t(e[r],r)}}function O(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":49,_process:43,buffer:34,"core-util-is":54,events:38,inherits:124,isarray:41,"process-nextick-args":55,"string_decoder/":67,util:33}],52:[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 s(e){this.afterTransform=function(t,r){return o(e,t,r)};this.needTransform=false;this.transforming=false;this.writecb=null;this.writechunk=null}function o(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 s=e._readableState;s.reading=false;if(s.needReadable||s.length<s.highWaterMark){e._read(s.highWaterMark)}}function a(e){if(!(this instanceof a))return new a(e);n.call(this,e);this._transformState=new s(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":49,"core-util-is":54,inherits:124}],53:[function(e,t,r){"use strict";t.exports=c;var n=e("process-nextick-args");var i=e("buffer").Buffer;c.WritableState=l;var s=e("core-util-is");s.inherits=e("inherits");var o={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;s.inherits(c,a);function f(){}function u(e,t,r){this.chunk=e;this.encoding=t;this.callback=r;this.next=null}var h;function l(t,r){h=h||e("./_stream_duplex");t=t||{};this.objectMode=!!t.objectMode;if(r instanceof h)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 s=t.decodeStrings===false;this.decodeStrings=!s;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 I(){var e=this.bufferedRequest;var t=[];while(e){t.push(e);e=e.next}return t};(function(){try{Object.defineProperty(l.prototype,"buffer",{get:o.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer "+"instead.")})}catch(e){}})();var h;function c(t){h=h||e("./_stream_duplex");if(!(this instanceof c)&&!(this instanceof h))return new c(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)}c.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe. Not readable."))};function d(e,t){var r=new Error("write after end");e.emit("error",r);n(t,r)}function p(e,t,r,s){var o=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(s,a);o=false}return o}c.prototype.write=function(e,t,r){var n=this._writableState;var s=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)d(this,r);else if(p(this,n,e,r)){n.pendingcb++;s=v(this,n,e,t,r)}return s};c.prototype.cork=function(){var e=this._writableState;e.corked++};c.prototype.uncork=function(){var e=this._writableState;if(e.corked){e.corked--;if(!e.writing&&!e.corked&&!e.finished&&!e.bufferProcessing&&e.bufferedRequest)x(this,e)}};c.prototype.setDefaultEncoding=function T(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,s){r=m(t,r,n);if(i.isBuffer(r))n="buffer";var o=t.objectMode?1:r.length;t.length+=o;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,s);if(f){f.next=t.lastBufferedRequest}else{t.bufferedRequest=t.lastBufferedRequest}}else{g(e,t,false,o,r,n,s)}return a}function g(e,t,r,n,i,s,o){t.writelen=n;t.writecb=o;t.writing=true;t.sync=true;if(r)e._writev(i,t.onwrite);else e._write(i,s,t.onwrite);t.sync=false}function y(e,t,r,i,s){--t.pendingcb;if(r)n(s,i);else s(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 s=r.writecb;_(r);if(t)y(e,r,i,t,s);else{var o=k(r);if(!o&&!r.corked&&!r.bufferProcessing&&r.bufferedRequest){x(e,r)}if(i){n(w,e,r,o,s)}else{w(e,r,o,s)}}}function w(e,t,r,n){if(!r)S(e,t);t.pendingcb--;n();A(e,t)}function S(e,t){if(t.length===0&&t.needDrain){t.needDrain=false;e.emit("drain")}}function x(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 s=r.chunk;var o=r.encoding;var a=r.callback;var f=t.objectMode?1:s.length;g(e,t,false,f,s,o,a);r=r.next;if(t.writing){break}}if(r===null)t.lastBufferedRequest=null}t.bufferedRequest=r;t.bufferProcessing=false}c.prototype._write=function(e,t,r){r(new Error("not implemented"))};c.prototype._writev=null;c.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)U(this,n,r)};function k(e){return e.ending&&e.length===0&&e.bufferedRequest===null&&!e.finished&&!e.writing}function E(e,t){if(!t.prefinished){t.prefinished=true;e.emit("prefinish")}}function A(e,t){var r=k(t);if(r){if(t.pendingcb===0){E(e,t);t.finished=true;e.emit("finish")}else{E(e,t)}}return r}function U(e,t,r){t.ending=true;A(e,t);if(r){if(t.finished)n(r);else e.once("finish",r)}t.ended=true}},{"./_stream_duplex":49,buffer:34,"core-util-is":54,events:38,inherits:124,"process-nextick-args":55,"util-deprecate":56}],54:[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 s(e){return e==null}r.isNullOrUndefined=s;function o(e){return typeof e==="number"}r.isNumber=o;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 h(e){return v(e)==="[object RegExp]"}r.isRegExp=h;function l(e){return typeof e==="object"&&e!==null}r.isObject=l;function c(e){return v(e)==="[object Date]"}r.isDate=c;function d(e){return v(e)==="[object Error]"||e instanceof Error}r.isError=d;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("../../../../insert-module-globals/node_modules/is-buffer/index.js")})},{"../../../../insert-module-globals/node_modules/is-buffer/index.js":40}],55:[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:43}],56:[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:{})},{}],57:[function(e,t,r){t.exports=e("./lib/_stream_passthrough.js")},{"./lib/_stream_passthrough.js":50}],58:[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":49,"./lib/_stream_passthrough.js":50,"./lib/_stream_readable.js":51,"./lib/_stream_transform.js":52,"./lib/_stream_writable.js":53}],59:[function(e,t,r){t.exports=e("./lib/_stream_transform.js")},{"./lib/_stream_transform.js":52}],60:[function(e,t,r){t.exports=e("./lib/_stream_writable.js")},{"./lib/_stream_writable.js":53}],61:[function(e,t,r){t.exports=s;var n=e("events").EventEmitter;var i=e("inherits");i(s,n);s.Readable=e("readable-stream/readable.js");s.Writable=e("readable-stream/writable.js");s.Duplex=e("readable-stream/duplex.js");s.Transform=e("readable-stream/transform.js");s.PassThrough=e("readable-stream/passthrough.js");s.Stream=s;function s(){n.call(this)}s.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 s(){if(r.readable&&r.resume){r.resume()}}e.on("drain",s);if(!e._isStdio&&(!t||t.end!==false)){r.on("end",a);r.on("close",f)}var o=false;function a(){if(o)return;o=true;e.end()}function f(){if(o)return;o=true;if(typeof e.destroy==="function")e.destroy()}function u(e){h();if(n.listenerCount(this,"error")===0){throw e}}r.on("error",u);e.on("error",u);function h(){r.removeListener("data",i);e.removeListener("drain",s);r.removeListener("end",a);r.removeListener("close",f);r.removeListener("error",u);e.removeListener("error",u);r.removeListener("end",h);r.removeListener("close",h);e.removeListener("close",h)}r.on("end",h);r.on("close",h);e.on("close",h);e.emit("pipe",r);return e}},{events:38,inherits:124,"readable-stream/duplex.js":48,"readable-stream/passthrough.js":57,"readable-stream/readable.js":58,"readable-stream/transform.js":59,"readable-stream/writable.js":60}],62:[function(e,t,r){var n=e("./lib/request");var i=e("xtend");var s=e("builtin-status-codes");var o=e("url");var a=r;a.request=function(e,t){if(typeof e==="string")e=o.parse(e);else e=i(e);var r=e.protocol||"";var s=e.hostname||e.host;var a=e.port;var f=e.path||"/";if(s&&s.indexOf(":")!==-1)s="["+s+"]";e.url=(s?r+"//"+s:"")+(a?":"+a:"")+f;e.method=(e.method||"GET").toUpperCase();e.headers=e.headers||{};var u=new n(e);if(t)u.on("response",t);return u};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=s;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"]},{"./lib/request":64,"builtin-status-codes":66,url:68,xtend:167}],63:[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 s=typeof e.ArrayBuffer!=="undefined";var o=s&&a(e.ArrayBuffer.prototype.slice);r.arraybuffer=s&&i("arraybuffer");r.msstream=!r.fetch&&o&&i("ms-stream");r.mozchunkedarraybuffer=!r.fetch&&s&&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:{})},{}],64:[function(e,t,r){(function(r,n,i){var s=e("./capability");var o=e("inherits");var a=e("./response");var f=e("stream");var u=a.IncomingMessage;var h=a.readyStates;function l(e){if(s.fetch){return"fetch"}else if(s.mozchunkedarraybuffer){return"moz-chunked-arraybuffer"}else if(s.msstream){return"ms-stream"}else if(s.arraybuffer&&e){return"arraybuffer"}else if(s.vbArray&&e){return"text:vbarray"}else{return"text"}}var c=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=!s.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=l(r);t.on("finish",function(){t._onFinish()})};o(c,f.Writable);c.prototype.setHeader=function(e,t){var r=this;var n=e.toLowerCase();if(p.indexOf(n)!==-1)return;r._headers[n]={name:e,value:t}};c.prototype.getHeader=function(e){var t=this;return t._headers[e.toLowerCase()].value};c.prototype.removeHeader=function(e){var t=this;delete t._headers[e.toLowerCase()]};c.prototype._onFinish=function(){var e=this;if(e._destroyed)return;var t=e._opts;var o=e._headers;var a;if(t.method==="POST"||t.method==="PUT"||t.method==="PATCH"){if(s.blobConstructor){a=new n.Blob(e._body.map(function(e){return e.toArrayBuffer()}),{type:(o["content-type"]||{}).value||""})}else{a=i.concat(e._body).toString()}}if(e._mode==="fetch"){var f=Object.keys(o).map(function(e){return[o[e].name,o[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 u=e._xhr=new n.XMLHttpRequest;try{u.open(e._opts.method,e._opts.url,true)}catch(l){r.nextTick(function(){e.emit("error",l)});return}if("responseType"in u)u.responseType=e._mode.split(":")[0];if("withCredentials"in u)u.withCredentials=!!t.withCredentials;if(e._mode==="text"&&"overrideMimeType"in u)u.overrideMimeType("text/plain; charset=x-user-defined");Object.keys(o).forEach(function(e){u.setRequestHeader(o[e].name,o[e].value)});e._response=null;u.onreadystatechange=function(){switch(u.readyState){case h.LOADING:case h.DONE:e._onXHRProgress();break}};if(e._mode==="moz-chunked-arraybuffer"){u.onprogress=function(){e._onXHRProgress()}}u.onerror=function(){if(e._destroyed)return;e.emit("error",new Error("XHR error"))};try{u.send(a)}catch(l){r.nextTick(function(){e.emit("error",l)});return}}};function d(e){try{return e.status!==null}catch(t){return false}}c.prototype._onXHRProgress=function(){var e=this;if(!d(e._xhr)||e._destroyed)return;if(!e._response)e._connect();e._response._onXHRProgress()};c.prototype._connect=function(){var e=this;if(e._destroyed)return;e._response=new u(e._xhr,e._fetchResponse,e._mode);e.emit("response",e._response)};c.prototype._write=function(e,t,r){var n=this;n._body.push(e);r()};c.prototype.abort=c.prototype.destroy=function(){var e=this;e._destroyed=true;if(e._response)e._response._destroyed=true;if(e._xhr)e._xhr.abort()};c.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)};c.prototype.flushHeaders=function(){};c.prototype.setTimeout=function(){};c.prototype.setNoDelay=function(){};c.prototype.setSocketKeepAlive=function(){};var p=["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":63,"./response":65,_process:43,buffer:34,inherits:124,stream:61}],65:[function(e,t,r){(function(t,n,i){var s=e("./capability");var o=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 o=this;a.Readable.call(o);o._mode=n;o.headers={};o.rawHeaders=[];o.trailers={};o.rawTrailers=[];o.on("end",function(){t.nextTick(function(){o.emit("close")})});if(n==="fetch"){o._fetchResponse=r;o.statusCode=r.status;o.statusMessage=r.statusText;for(var f,u,h=r.headers[Symbol.iterator]();f=(u=h.next()).value,!u.done;){o.headers[f[0].toLowerCase()]=f[1];o.rawHeaders.push(f[0],f[1])}var l=r.body.getReader();function c(){l.read().then(function(e){if(o._destroyed)return;if(e.done){o.push(null);return}o.push(new i(e.value));c()})}c()}else{o._xhr=e;o._pos=0;o.statusCode=e.status;o.statusMessage=e.statusText;var d=e.getAllResponseHeaders().split(/\r?\n/);d.forEach(function(e){var t=e.match(/^([^:]+):\s*(.*)/);if(t){var r=t[1].toLowerCase();if(o.headers[r]!==undefined)o.headers[r]+=", "+t[2];else o.headers[r]=t[2];o.rawHeaders.push(t[1],t[2])}});o._charset="x-user-defined";if(!s.overrideMimeType){var p=o.rawHeaders["mime-type"];if(p){var m=p.match(/;\s*charset=([^;])(;|$)/);if(m){o._charset=m[1].toLowerCase()}}if(!o._charset)o._charset="utf-8"}}};o(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(s){}if(r!==null){e.push(new i(r));break}case"text":try{r=t.responseText}catch(s){e._mode="text:vbarray";break}if(r.length>e._pos){var o=r.substr(e._pos);if(e._charset==="x-user-defined"){var a=new i(o.length);for(var u=0;u<o.length;u++)a[u]=o.charCodeAt(u)&255;e.push(a)}else{e.push(o,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 h=new n.MSStreamReader;h.onprogress=function(){if(h.result.byteLength>e._pos){e.push(new i(new Uint8Array(h.result.slice(e._pos))));e._pos=h.result.byteLength}};h.onload=function(){e.push(null)};h.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":63,_process:43,buffer:34,inherits:124,stream:61}],66:[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"}},{}],67:[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 s(e){if(e&&!i(e)){throw new Error("Unknown encoding: "+e)}}var o=r.StringDecoder=function(e){this.encoding=(e||"utf8").toLowerCase().replace(/[-_]/,"");s(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};o.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 s=this.surrogateSize;this.charLength+=s;this.charReceived+=s;this.charBuffer.copy(this.charBuffer,s,0,s);e.copy(this.charBuffer,0,0,s);return t.substring(0,i)}return t};o.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};o.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:34}],68:[function(e,t,r){"use strict";var n=e("punycode");var i=e("./util");r.parse=w;r.resolve=x;r.resolveObject=k;r.format=S;r.Url=s;function s(){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 o=/^([a-z0-9.+-]+:)/i,a=/:[0-9]*$/,f=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,u=["<",">",'"',"`"," ","\r","\n"," "],h=["{","}","|","\\","^","`"].concat(u),l=["'"].concat(h),c=["%","/","?",";","#"].concat(l),d=["/","?","#"],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 s)return e;var n=new s;n.parse(e,t,r);return n}s.prototype.parse=function(e,t,r){if(!i.isString(e)){throw new TypeError("Parameter 'url' must be a string, not "+typeof e)}var s=e.indexOf("?"),a=s!==-1&&s<e.indexOf("#")?"?":"#",u=e.split(a),h=/\\/g;u[0]=u[0].replace(h,"/");e=u.join(a);var w=e;w=w.trim();if(!r&&e.split("#").length===1){var S=f.exec(w);if(S){this.path=w;this.href=w;this.pathname=S[1];if(S[2]){this.search=S[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 x=o.exec(w);if(x){x=x[0];var k=x.toLowerCase();this.protocol=k;w=w.substr(x.length)}if(r||x||w.match(/^\/\/[^@\/]+@[^@\/]+/)){var E=w.substr(0,2)==="//";if(E&&!(x&&y[x])){w=w.substr(2);this.slashes=true}}if(!y[x]&&(E||x&&!_[x])){var A=-1;for(var U=0;U<d.length;U++){var I=w.indexOf(d[U]);if(I!==-1&&(A===-1||I<A))A=I}var T,B;if(A===-1){B=w.lastIndexOf("@")}else{B=w.lastIndexOf("@",A)}if(B!==-1){T=w.slice(0,B);w=w.slice(B+1);this.auth=decodeURIComponent(T)}A=-1;for(var U=0;U<c.length;U++){var I=w.indexOf(c[U]);if(I!==-1&&(A===-1||I<A))A=I}if(A===-1)A=w.length;this.host=w.slice(0,A);w=w.slice(A);this.parseHost();this.hostname=this.hostname||"";var L=this.hostname[0]==="["&&this.hostname[this.hostname.length-1]==="]";if(!L){var C=this.hostname.split(/\./);for(var U=0,R=C.length;U<R;U++){var P=C[U];if(!P)continue;if(!P.match(m)){var F="";for(var O=0,D=P.length;O<D;O++){if(P.charCodeAt(O)>127){F+="x"}else{F+=P[O]}}if(!F.match(m)){var M=C.slice(0,U);var N=C.slice(U+1);var z=P.match(v);if(z){M.push(z[1]);N.unshift(z[2])}if(N.length){w="/"+N.join(".")+w}this.hostname=M.join(".");break}}}}if(this.hostname.length>p){this.hostname=""}else{this.hostname=this.hostname.toLowerCase()}if(!L){this.hostname=n.toASCII(this.hostname)}var j=this.port?":"+this.port:"";var H=this.hostname||"";this.host=H+j;this.href+=this.host;if(L){this.hostname=this.hostname.substr(1,this.hostname.length-2);if(w[0]!=="/"){w="/"+w}}}if(!g[k]){for(var U=0,R=l.length;U<R;U++){var q=l[U];if(w.indexOf(q)===-1)continue;var G=encodeURIComponent(q);if(G===q){G=escape(q)}w=w.split(q).join(G)}}var W=w.indexOf("#");if(W!==-1){this.hash=w.substr(W);w=w.slice(0,W)}var Y=w.indexOf("?");if(Y!==-1){this.search=w.substr(Y);this.query=w.substr(Y+1);if(t){this.query=b.parse(this.query)}w=w.slice(0,Y)}else if(t){this.search="";this.query={}}if(w)this.pathname=w;if(_[k]&&this.hostname&&!this.pathname){this.pathname="/"}if(this.pathname||this.search){var j=this.pathname||"";var V=this.search||"";this.path=j+V}this.href=this.format();return this};function S(e){if(i.isString(e))e=w(e);if(!(e instanceof s))return s.prototype.format.call(e);return e.format()}s.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||"",s=false,o="";if(this.host){s=e+this.host}else if(this.hostname){s=e+(this.hostname.indexOf(":")===-1?this.hostname:"["+this.hostname+"]");if(this.port){s+=":"+this.port}}if(this.query&&i.isObject(this.query)&&Object.keys(this.query).length){o=b.stringify(this.query)}var a=this.search||o&&"?"+o||"";if(t&&t.substr(-1)!==":")t+=":";if(this.slashes||(!t||_[t])&&s!==false){s="//"+(s||"");if(r&&r.charAt(0)!=="/")r="/"+r}else if(!s){s=""}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+s+r+a+n};function x(e,t){return w(e,false,true).resolve(t)}s.prototype.resolve=function(e){return this.resolveObject(w(e,false,true)).format()};function k(e,t){if(!e)return t;return w(e,false,true).resolveObject(t)}s.prototype.resolveObject=function(e){if(i.isString(e)){var t=new s;t.parse(e,false,true);e=t}var r=new s;var n=Object.keys(this);for(var o=0;o<n.length;o++){var a=n[o];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 h=f[u];if(h!=="protocol")r[h]=e[h]}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 c=0;c<l.length;c++){var d=l[c];r[d]=e[d]}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,S=w,x=r.pathname&&r.pathname.split("/")||[],p=e.pathname&&e.pathname.split("/")||[],k=r.protocol&&!_[r.protocol];if(k){r.hostname="";r.port=null;if(r.host){if(x[0]==="")x[0]=r.host;else x.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]===""||x[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;x=p}else if(p.length){if(!x)x=[];x.pop();x=x.concat(p);r.search=e.search;r.query=e.query}else if(!i.isNullOrUndefined(e.search)){if(k){r.hostname=r.host=x.shift();var E=r.host&&r.host.indexOf("@")>0?r.host.split("@"):false;if(E){r.auth=E.shift();r.host=r.hostname=E.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(!x.length){r.pathname=null;if(r.search){r.path="/"+r.search}else{r.path=null}r.href=r.format();return r}var A=x.slice(-1)[0];var U=(r.host||e.host||x.length>1)&&(A==="."||A==="..")||A==="";var I=0;for(var T=x.length;T>=0;T--){A=x[T];if(A==="."){x.splice(T,1)}else if(A===".."){x.splice(T,1);I++}else if(I){x.splice(T,1);I--}}if(!w&&!S){for(;I--;I){x.unshift("..")}}if(w&&x[0]!==""&&(!x[0]||x[0].charAt(0)!=="/")){x.unshift("")}if(U&&x.join("/").substr(-1)!=="/"){x.push("")}var B=x[0]===""||x[0]&&x[0].charAt(0)==="/";if(k){r.hostname=r.host=B?"":x.length?x.shift():"";var E=r.host&&r.host.indexOf("@")>0?r.host.split("@"):false;if(E){r.auth=E.shift();r.host=r.hostname=E.shift()}}w=w||r.host&&x.length;if(w&&!B){x.unshift("")}if(!x.length){r.pathname=null;r.path=null}else{r.pathname=x.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};s.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":69,punycode:44,querystring:47}],69:[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}}},{}],70:[function(e,t,r){(function(r){var n=e("inherits");var i=e("readable-stream").Transform;var s=e("defined");t.exports=o;n(o,i);function o(e,t){if(!(this instanceof o))return new o(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=s(t.zeroPadding,true);this._buffered=[];this._bufferedBytes=0}o.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()};o.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:34,defined:71,inherits:124,"readable-stream":82}],71:[function(e,t,r){t.exports=function(){for(var e=0;e<arguments.length;e++){if(arguments[e]!==undefined)return arguments[e]}}},{}],72:[function(e,t,r){arguments[4][49][0].apply(r,arguments)},{"./_stream_readable":74,"./_stream_writable":76,"core-util-is":77,dup:49,inherits:124,"process-nextick-args":79}],73:[function(e,t,r){arguments[4][50][0].apply(r,arguments)},{"./_stream_transform":75,"core-util-is":77,dup:50,inherits:124}],74:[function(e,t,r){arguments[4][51][0].apply(r,arguments)},{"./_stream_duplex":72,_process:43,buffer:34,"core-util-is":77,dup:51,events:38,inherits:124,isarray:78,"process-nextick-args":79,"string_decoder/":80,util:33}],75:[function(e,t,r){arguments[4][52][0].apply(r,arguments)},{"./_stream_duplex":72,"core-util-is":77,dup:52,inherits:124}],76:[function(e,t,r){arguments[4][53][0].apply(r,arguments)},{"./_stream_duplex":72,buffer:34,"core-util-is":77,dup:53,events:38,inherits:124,"process-nextick-args":79,"util-deprecate":81}],77:[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 s(e){return e==null}r.isNullOrUndefined=s;function o(e){return typeof e==="number"}r.isNumber=o;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 h(e){return v(e)==="[object RegExp]"}r.isRegExp=h;function l(e){return typeof e==="object"&&e!==null}r.isObject=l;function c(e){return v(e)==="[object Date]"}r.isDate=c;function d(e){return v(e)==="[object Error]"||e instanceof Error}r.isError=d;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":40}],78:[function(e,t,r){arguments[4][41][0].apply(r,arguments)},{dup:41}],79:[function(e,t,r){arguments[4][55][0].apply(r,arguments)},{_process:43,dup:55}],80:[function(e,t,r){arguments[4][67][0].apply(r,arguments)},{buffer:34,dup:67}],81:[function(e,t,r){arguments[4][56][0].apply(r,arguments)},{dup:56}],82:[function(e,t,r){arguments[4][58][0].apply(r,arguments)},{"./lib/_stream_duplex.js":72,"./lib/_stream_passthrough.js":73,"./lib/_stream_readable.js":74,"./lib/_stream_transform.js":75,"./lib/_stream_writable.js":76,dup:58}],83:[function(e,t,r){t.exports=o;var n=e("block-stream2");var i=e("inherits");var s=e("stream");i(o,s.Writable);function o(e,t,r){var i=this;if(!(i instanceof o)){return new o(e,t,r)}s.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()})}o.prototype._write=function(e,t,r){this._blockstream.write(e,t,r)};o.prototype.destroy=function(e){if(this.destroyed)return;this.destroyed=true;if(e)this.emit("error",e);this.emit("close")}},{"block-stream2":70,inherits:124,stream:61
+}],84:[function(e,t,r){(function(r,n){t.exports=_;t.exports.parseInput=b;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"]];var i=e("bencode");var s=e("block-stream2");var o=e("piece-length");var a=e("path");var f=e("dezalgo");var u=e("filestream/read");var h=e("flatten");var l=e("fs");var c=e("is-file");var d=e("junk");var p=e("multistream");var m=e("once");var v=e("run-parallel");var g=e("simple-sha1");var y=e("stream");function _(e,t,r){if(typeof t==="function"){r=t;t={}}if(!t)t={};b(e,t,function(e,n,i){if(e)return r(e);t.singleFileTorrent=i;A(n,t,r)})}function b(e,t,r){if(typeof t==="function"){r=t;t={}}if(!t)t={};r=f(r);if(Array.isArray(e)&&e.length===0)throw new Error("invalid input type");if(T(e))e=Array.prototype.slice.call(e);if(!Array.isArray(e))e=[e];if(e.length===1&&typeof e[0]!=="string"&&!e[0].name)e[0].name=t.name;var i=null;e.forEach(function(e,t){if(typeof e==="string")return;var r=e.fullPath||e.name;if(!r)throw new Error("missing required `fullPath` or `name` property on input");e.path=r.split("/");if(!e.path[0])e.path.shift();if(e.path.length<2){i=null}else if(t===0){i=e.path[0]}else if(e.path[0]!==i){i=null}});e=e.filter(function(e){if(typeof e==="string")return true;var t=e.path[e.path.length-1];return k(t)&&d.not(t)});if(i){e.forEach(function(e){if(typeof e==="string")return;e.path.shift()})}if(!t.name&&i)t.name=i;if(!t.name&&e[0]&&e[0].name)t.name=e[0].name;if(!t.name&&typeof e[0]==="string")t.name=a.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 o=e.length===1;if(e.length===1&&typeof e[0]==="string"){if(typeof l.stat!=="function"){throw new Error("filesystem paths do not work in the browser")}c(e[0],function(e,t){if(e)return r(e);o=t;u()})}else{u()}function u(){v(e.map(function(e){return function(r){var i={};if(I(e)){i.getStream=L(e);i.length=e.size}else if(n.isBuffer(e)){i.getStream=C(e);i.length=e.length}else if(B(e)){if(!t.pieceLength){throw new Error("must specify `pieceLength` option if input is Stream")}i.getStream=P(e,i);i.length=0}else if(typeof e==="string"){if(typeof l.stat!=="function"){throw new Error("filesystem paths do not work in the browser")}var a=s>1||o;w(e,a,r);return}else{throw new Error("invalid input type")}i.path=e.path;r(null,i)}}),function(e,t){if(e)return r(e);t=h(t);r(null,t,o)})}}function w(e,t,r){x(e,S,function(n,i){if(n)return r(n);if(Array.isArray(i))i=h(i);else i=[i];e=a.normalize(e);if(t){e=e.slice(0,e.lastIndexOf(a.sep)+1)}if(e[e.length-1]!==a.sep)e+=a.sep;i.forEach(function(t){t.getStream=R(t.path);t.path=t.path.replace(e,"").split(a.sep)});r(null,i)})}function S(e,t){t=m(t);l.stat(e,function(r,n){if(r)return t(r);var i={length:n.size,path:e};t(null,i)})}function x(e,t,r){l.readdir(e,function(n,i){if(n&&n.code==="ENOTDIR"){t(e,r)}else if(n){r(n)}else{v(i.filter(k).filter(d.not).map(function(r){return function(n){x(a.join(e,r),t,n)}}),r)}})}function k(e){return e[0]!=="."}function E(e,t,r){r=m(r);var i=[];var o=0;var a=e.map(function(e){return e.getStream});var f=0;var u=0;var h=false;var l=new p(a);var c=new s(t,{zeroPadding:false});l.on("error",y);l.pipe(c).on("data",d).on("end",v).on("error",y);function d(e){o+=e.length;var t=u;g(e,function(e){i[t]=e;f-=1;b()});f+=1;u+=1}function v(){h=true;b()}function y(e){_();r(e)}function _(){l.removeListener("error",y);c.removeListener("data",d);c.removeListener("end",v);c.removeListener("error",y)}function b(){if(h&&f===0){_();r(null,new n(i.join(""),"hex"),o)}}}function A(e,n,s){var a=n.announceList;if(!a){if(typeof n.announce==="string")a=[[n.announce]];else if(Array.isArray(n.announce)){a=n.announce.map(function(e){return[e]})}}if(!a)a=[];if(r.WEBTORRENT_ANNOUNCE){if(typeof r.WEBTORRENT_ANNOUNCE==="string"){a.push([[r.WEBTORRENT_ANNOUNCE]])}else if(Array.isArray(r.WEBTORRENT_ANNOUNCE)){a=a.concat(r.WEBTORRENT_ANNOUNCE.map(function(e){return[e]}))}}if(n.announce===undefined&&n.announceList===undefined){a=a.concat(t.exports.announceList)}if(typeof n.urlList==="string")n.urlList=[n.urlList];var f={info:{name:n.name},"creation date":Number(n.creationDate)||Date.now(),encoding:"UTF-8"};if(a.length!==0){f.announce=a[0][0];f["announce-list"]=a}if(n.comment!==undefined)f.comment=n.comment;if(n.createdBy!==undefined)f["created by"]=n.createdBy;if(n.private!==undefined)f.info.private=Number(n.private);if(n.sslCert!==undefined)f.info["ssl-cert"]=n.sslCert;if(n.urlList!==undefined)f["url-list"]=n.urlList;var u=n.pieceLength||o(e.reduce(U,0));f.info["piece length"]=u;E(e,u,function(t,r,o){if(t)return s(t);f.info.pieces=r;e.forEach(function(e){delete e.getStream});if(n.singleFileTorrent){f.info.length=o}else{f.info.files=e}s(null,i.encode(f))})}function U(e,t){return e+t.length}function I(e){return typeof Blob!=="undefined"&&e instanceof Blob}function T(e){return typeof FileList==="function"&&e instanceof FileList}function B(e){return typeof e==="object"&&typeof e.pipe==="function"}function L(e){return function(){return new u(e)}}function C(e){return function(){var t=new y.PassThrough;t.end(e);return t}}function R(e){return function(){return l.createReadStream(e)}}function P(e,t){return function(){var r=new y.Transform;r._transform=function(e,r,n){t.length+=e.length;this.push(e);n()};e.pipe(r);return r}}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{},e("buffer").Buffer)},{bencode:85,"block-stream2":89,buffer:34,dezalgo:102,"filestream/read":108,flatten:109,fs:32,"is-file":110,junk:111,multistream:127,once:113,path:42,"piece-length":114,"run-parallel":145,"simple-sha1":149,stream:61}],85:[function(e,t,r){arguments[4][15][0].apply(r,arguments)},{"./lib/decode":86,"./lib/encode":88,dup:15}],86:[function(e,t,r){arguments[4][16][0].apply(r,arguments)},{"./dict":87,buffer:34,dup:16}],87:[function(e,t,r){arguments[4][17][0].apply(r,arguments)},{dup:17}],88:[function(e,t,r){arguments[4][18][0].apply(r,arguments)},{buffer:34,dup:18}],89:[function(e,t,r){arguments[4][70][0].apply(r,arguments)},{buffer:34,defined:90,dup:70,inherits:124,"readable-stream":101}],90:[function(e,t,r){arguments[4][71][0].apply(r,arguments)},{dup:71}],91:[function(e,t,r){arguments[4][49][0].apply(r,arguments)},{"./_stream_readable":93,"./_stream_writable":95,"core-util-is":96,dup:49,inherits:124,"process-nextick-args":98}],92:[function(e,t,r){arguments[4][50][0].apply(r,arguments)},{"./_stream_transform":94,"core-util-is":96,dup:50,inherits:124}],93:[function(e,t,r){arguments[4][51][0].apply(r,arguments)},{"./_stream_duplex":91,_process:43,buffer:34,"core-util-is":96,dup:51,events:38,inherits:124,isarray:97,"process-nextick-args":98,"string_decoder/":99,util:33}],94:[function(e,t,r){arguments[4][52][0].apply(r,arguments)},{"./_stream_duplex":91,"core-util-is":96,dup:52,inherits:124}],95:[function(e,t,r){arguments[4][53][0].apply(r,arguments)},{"./_stream_duplex":91,buffer:34,"core-util-is":96,dup:53,events:38,inherits:124,"process-nextick-args":98,"util-deprecate":100}],96:[function(e,t,r){arguments[4][77][0].apply(r,arguments)},{"../../../../../../../../browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js":40,dup:77}],97:[function(e,t,r){arguments[4][41][0].apply(r,arguments)},{dup:41}],98:[function(e,t,r){arguments[4][55][0].apply(r,arguments)},{_process:43,dup:55}],99:[function(e,t,r){arguments[4][67][0].apply(r,arguments)},{buffer:34,dup:67}],100:[function(e,t,r){arguments[4][56][0].apply(r,arguments)},{dup:56}],101:[function(e,t,r){arguments[4][58][0].apply(r,arguments)},{"./lib/_stream_duplex.js":91,"./lib/_stream_passthrough.js":92,"./lib/_stream_readable.js":93,"./lib/_stream_transform.js":94,"./lib/_stream_writable.js":95,dup:58}],102:[function(e,t,r){var n=e("wrappy");t.exports=n(s);var i=e("asap");function s(e){var t=true;i(function(){t=false});return function r(){var r=arguments;var n=this;if(t)i(function(){e.apply(n,r)});else e.apply(n,r)}}},{asap:103,wrappy:105}],103:[function(e,t,r){"use strict";var n=e("./raw");var i=[];var s=[];var o=n.makeRequestCallFromTimer(a);function a(){if(s.length){throw s.shift()}}t.exports=f;function f(e){var t;if(i.length){t=i.pop()}else{t=new u}t.task=e;n(t)}function u(){this.task=null}u.prototype.call=function(){try{this.task.call()}catch(e){if(f.onerror){f.onerror(e)}else{s.push(e);o()}}finally{this.task=null;i[i.length]=this}}},{"./raw":104}],104:[function(e,t,r){(function(e){"use strict";t.exports=r;function r(e){if(!n.length){s();i=true}n[n.length]=e}var n=[];var i=false;var s;var o=0;var a=1024;function f(){while(o<n.length){var e=o;o=o+1;n[e].call();if(o>a){for(var t=0,r=n.length-o;t<r;t++){n[t]=n[t+o]}n.length-=o;o=0}}n.length=0;o=0;i=false}var u=e.MutationObserver||e.WebKitMutationObserver;if(typeof u==="function"){s=h(f)}else{s=l(f)}r.requestFlush=s;function h(e){var t=1;var r=new u(e);var n=document.createTextNode("");r.observe(n,{characterData:true});return function i(){t=-t;n.data=t}}function l(e){return function t(){var t=setTimeout(n,0);var r=setInterval(n,50);function n(){clearTimeout(t);clearInterval(r);e()}}}r.makeRequestCallFromTimer=l}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],105:[function(e,t,r){arguments[4][23][0].apply(r,arguments)},{dup:23}],106:[function(e,t,r){arguments[4][28][0].apply(r,arguments)},{buffer:34,dup:28,"is-typedarray":107}],107:[function(e,t,r){arguments[4][27][0].apply(r,arguments)},{dup:27}],108:[function(e,t,r){var n=e("stream").Readable;var i=e("inherits");var s=/^.*\.(\w+)$/;var o=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(o(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:124,stream:61,"typedarray-to-buffer":106}],109:[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)}},[])}}},{}],110:[function(e,t,r){"use strict";var n=e("fs");t.exports=function s(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:32}],111:[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)}},{}],112:[function(e,t,r){arguments[4][23][0].apply(r,arguments)},{dup:23}],113:[function(e,t,r){arguments[4][24][0].apply(r,arguments)},{dup:24,wrappy:112}],114:[function(e,t,r){var n=e("closest-to");var i=[];for(var s=14;s<=22;s++){i.push(Math.pow(2,s))}t.exports=function(e){return n(e/Math.pow(2,10),i)}},{"closest-to":115}],115:[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 s=0,o=t.length;s<o;s++){n=Math.abs(e-t[s]);if(n>=r){break}r=n;i=t[s]}return i}},{}],116:[function(e,t,r){r=t.exports=e("./debug");r.log=s;r.formatArgs=i;r.save=o;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 s=0;e[0].replace(/%[a-z%]/g,function(e){if("%%"===e)return;i++;if("%c"===e){s=i}});e.splice(s,0,n);return e}function s(){return"object"===typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function o(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":117}],117:[function(e,t,r){r=t.exports=o;r.coerce=h;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 s(){return r.colors[n++%r.colors.length]}function o(e){function t(){}t.enabled=false;function n(){var e=n;var t=+new Date;var o=t-(i||t);e.diff=o;e.prev=i;e.curr=t;i=t;if(null==e.useColors)e.useColors=r.useColors();if(null==e.color&&e.useColors)e.color=s();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 s=a[f];t=i.call(e,s);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 o=r.enabled(e)?n:t;o.namespace=e;return o}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 h(e){if(e instanceof Error)return e.stack||e.message;return e}},{ms:118}],118:[function(e,t,r){var n=1e3;var i=n*60;var s=i*60;var o=s*24;var a=o*365.25;t.exports=function(e,t){t=t||{};if("string"==typeof e)return f(e);return t.long?h(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*o;case"hours":case"hour":case"hrs":case"hr":case"h":return r*s;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>=o)return Math.round(e/o)+"d";if(e>=s)return Math.round(e/s)+"h";if(e>=i)return Math.round(e/i)+"m";if(e>=n)return Math.round(e/n)+"s";return e+"ms"}function h(e){return l(e,o,"day")||l(e,s,"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"}},{}],119:[function(e,t,r){var n=e("once");var i=function(){};var s=function(e){return e.setHeader&&typeof e.abort==="function"};var o=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 h=t.readable||t.readable!==false&&e.readable;var l=t.writable||t.writable!==false&&e.writable;var c=function(){if(!e.writable)d()};var d=function(){l=false;if(!h)r()};var p=function(){h=false;if(!l)r()};var m=function(e){r(e?new Error("exited with error code: "+e):null)};var v=function(){if(h&&!(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",d)};if(s(e)){e.on("complete",d);e.on("abort",v);if(e.req)g();else e.on("request",g)}else if(l&&!f){e.on("end",c);e.on("close",c)}if(o(e))e.on("exit",m);e.on("end",p);e.on("finish",d);if(t.error!==false)e.on("error",r);e.on("close",v);return function(){e.removeListener("complete",d);e.removeListener("abort",v);e.removeListener("request",g);if(e.req)e.req.removeListener("finish",d);e.removeListener("end",c);e.removeListener("close",c);e.removeListener("finish",d);e.removeListener("exit",m);e.removeListener("end",p);e.removeListener("error",r);e.removeListener("close",v)}};t.exports=a},{once:121}],120:[function(e,t,r){arguments[4][23][0].apply(r,arguments)},{dup:23}],121:[function(e,t,r){arguments[4][24][0].apply(r,arguments)},{dup:24,wrappy:120}],122:[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 s=r-Math.floor(r);var o="";for(var i=0;i<Math.floor(r);i++){var a=Math.floor(Math.random()*t).toString(t);o=a+o}if(s){var f=Math.pow(t,s);var a=Math.floor(Math.random()*f).toString(t);o=a+o}var u=parseInt(o,t);if(u!==Infinity&&u>=Math.pow(2,e)){return n(e,t)}else return o};n.rack=function(e,t,r){var i=function(i){var o=0;do{if(o++>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(s,a));s[a]=i;return a};var s=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}},{}],123:[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 s=t&&t.length&&i+t.length;var o=this.mem[e];if(o)return n(r,null,t?o.slice(i,s):o);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:43}],124:[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}}},{}],125:[function(e,t,r){t.exports=o;var n=e("inherits");var i=e("stream");var s=typeof window!=="undefined"&&window.MediaSource;n(o,i.Writable);function o(e,t){var r=this;if(!(r instanceof o))return new o(e,t);i.Writable.call(r,t);if(!s)throw new Error("web browser lacks MediaSource support");if(!t)t={};r._elem=e;r._mediaSource=new s;r._sourceBuffer=null;r._cb=null;r._type=t.type||a(t.extname);if(!r._type)throw new Error("missing `opts.type` or `opts.extname` options");r._elem.src=window.URL.createObjectURL(r._mediaSource);r._mediaSource.addEventListener("sourceopen",function(){if(s.isTypeSupported(r._type)){r._sourceBuffer=r._mediaSource.addSourceBuffer(r._type);r._sourceBuffer.addEventListener("updateend",r._flow.bind(r));r._flow()}else{r._mediaSource.endOfStream("decode")}});r.on("finish",function(){r._mediaSource.endOfStream()})}o.prototype._write=function(e,t,r){var n=this;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"))}n._sourceBuffer.appendBuffer(e);n._cb=r};o.prototype._flow=function(){var e=this;if(e._cb){e._cb(null)}};function a(e){if(!e)return null;if(e[0]!==".")e="."+e;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"'}[e]}},{inherits:124,stream:61}],126:[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 s=t.offset||0;var o=t.length||i.length-s;n(r,null,i.slice(s,o+s))};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:43}],127:[function(e,t,r){t.exports=s;var n=e("inherits");var i=e("stream");n(s,i.Readable);function s(e,t){if(!(this instanceof s))return new s(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(o);this._next()}s.obj=function(e){return new s(e,{objectMode:true,highWaterMark:16})};s.prototype._read=function(){this._drained=true;this._forward()};s.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};s.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")};s.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(o(r))})}else{var t=e._queue.shift();if(typeof t==="function")t=o(t());e._gotNextStream(t)}};s.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",s);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",s);e.removeListener("close",n);t._next()}function s(e){t.destroy(e)}};function o(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:124,stream:61}],128:[function(e,t,r){(function(r,n){t.exports=u;t.exports.remote=h;var i=e("blob-to-buffer");var s=e("fs");var o=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 h(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 o==="function"&&/^https?:/.test(e)){o.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 s.readFile==="function"&&typeof e==="string"){s.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":40,_process:43,"blob-to-buffer":129,fs:32,"magnet-uri":132,"parse-torrent-file":135,"simple-get":146}],129:[function(e,t,r){var n=e("typedarray-to-buffer");t.exports=function i(e,t){if(typeof Blob==="undefined"||!(e instanceof Blob)){throw new Error("first argument must be a Blob")}if(typeof t!=="function"){throw new Error("second argument must be a function")}var r=new FileReader;function i(e){r.removeEventListener("loadend",i,false);if(e.error)t(e.error);else t(null,n(r.result))}r.addEventListener("loadend",i,false);r.readAsArrayBuffer(e)}},{"typedarray-to-buffer":130}],130:[function(e,t,r){arguments[4][28][0].apply(r,arguments)},{buffer:34,dup:28,"is-typedarray":131}],131:[function(e,t,r){arguments[4][27][0].apply(r,arguments)},{dup:27}],132:[function(e,t,r){(function(r){t.exports=o;t.exports.decode=o;t.exports.encode=a;var n=e("thirty-two");var i=e("xtend");var s=e("uniq");function o(e){var t={};var i=e.split("magnet:?")[1];var o=i&&i.length>=0?i.split("&"):[];o.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 s=t[n];t[n]=[s,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=[];s(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)}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:34,"thirty-two":133,uniq:154,xtend:167}],133:[function(e,t,r){var n=e("./thirty-two");r.encode=n.encode;r.decode=n.decode},{"./thirty-two":134}],134:[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 s=0;var o=0;var a=0;var f=new e(i(r)*8);while(n<r.length){var u=r[n];if(o>3){a=u&255>>o;o=(o+5)%8;a=a<<o|(n+1<r.length?r[n+1]:0)>>8-o;n++}else{a=u>>8-(o+5)&31;o=(o+5)%8;if(o==0)n++}f[s]=t.charCodeAt(a);s++}for(n=s;n<f.length;n++)f[n]=61;return f};r.decode=function(t){var r=0;var i=0;var s;var o=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){s|=i;a[o]=s;o++;s=0}else{s|=255&i<<8-r}}else{r=(r+5)%8;s|=255&i>>>r;a[o]=s;o++;s=255&i<<8-r}}else{throw new Error("Invalid input - it is not base32 encoded string")}}return a.slice(0,o)}}).call(this,e("buffer").Buffer)},{buffer:34}],135:[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 s=e("simple-sha1");var o=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=s.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())}o(t.announce);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()});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=h(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 h(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:136,buffer:34,path:42,"simple-sha1":149,uniq:154}],136:[function(e,t,r){arguments[4][15][0].apply(r,arguments)},{"./lib/decode":137,"./lib/encode":139,dup:15}],137:[function(e,t,r){arguments[4][16][0].apply(r,arguments)},{"./dict":138,buffer:34,dup:16}],138:[function(e,t,r){arguments[4][17][0].apply(r,arguments)},{dup:17}],139:[function(e,t,r){arguments[4][18][0].apply(r,arguments)},{buffer:34,dup:18}],140:[function(e,t,r){var n=e("once");var i=e("end-of-stream");var s=e("fs");var o=function(){};var a=function(e){return typeof e==="function"};var f=function(e){return(e instanceof(s.ReadStream||o)||e instanceof(s.WriteStream||o))&&a(e.close)};var u=function(e){return e.setHeader&&a(e.abort)};var h=function(e,t,r,s){s=n(s);var o=false;e.on("close",function(){o=true});i(e,{readable:t,writable:r},function(e){if(e)return s(e);o=true;s()});var h=false;return function(t){if(o)return;if(h)return;h=true;if(f(e))return e.close();if(u(e))return e.abort();if(a(e.destroy))return e.destroy();s(t||new Error("stream was destroyed"))}};var l=function(e){e()};var c=function(e,t){return e.pipe(t)};var d=function(){var e=Array.prototype.slice.call(arguments);var t=a(e[e.length-1]||o)&&e.pop()||o;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,s){var o=s<e.length-1;var a=s>0;return h(i,o,a,function(e){if(!r)r=e;if(e)n.forEach(l);if(o)return;n.forEach(l);t(r)})});return e.reduce(c)};t.exports=d},{"end-of-stream":119,fs:32,once:142}],141:[function(e,t,r){arguments[4][23][0].apply(r,arguments)},{dup:23}],142:[function(e,t,r){arguments[4][24][0].apply(r,arguments)},{dup:24,wrappy:141}],143:[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 s=e[t];e[t]=i;e[t+n]=s;t++;return i}};t.exports=n},{}],144:[function(e,t,r){t.exports=i;t.exports.filter=s;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 s(e,t){var r=new n;i(e,r,t);return r}},{events:38}],145:[function(e,t,r){(function(e){t.exports=function(t,r){var n,i,s;var o=true;if(Array.isArray(t)){n=[];i=t.length}else{s=Object.keys(t);n={};i=s.length}function a(t){function i(){if(r)r(t,n);r=null}if(o)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(s){s.forEach(function(e){t[e](f.bind(undefined,e))})}else{t.forEach(function(e,t){e(f.bind(undefined,t))})}o=false}}).call(this,e("_process"))},{_process:43}],146:[function(e,t,r){(function(r){t.exports=u;var n=e("xtend");var i=e("http");var s=e("https");var o=e("once");var a=e("unzip-response");var f=e("url");function u(e,t){e=typeof e==="string"?{url:e}:n(e);t=o(t);if(e.url)h(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:"?s:i;var c=l.request(e,function(r){if(r.statusCode>=300&&r.statusCode<400&&"location"in r.headers){e.url=r.headers.location;h(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)});c.on("error",t);c.end(r);return c}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 h(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:34,http:62,https:39,once:148,"unzip-response":33,url:68,xtend:167}],147:[function(e,t,r){arguments[4][23][0].apply(r,arguments)},{dup:23}],148:[function(e,t,r){arguments[4][24][0].apply(r,arguments)},{dup:24,wrappy:147}],149:[function(e,t,r){var n=e("rusha");var i=new n;var s=window.crypto||window.msCrypto||{};var o=s.subtle||s.webkitSubtle;var a=i.digest.bind(i);try{o.digest({name:"sha-1"},new Uint8Array).catch(function(){o=false})}catch(f){o=false}function u(e,t){if(!o){setTimeout(t,0,a(e));return}if(typeof e==="string"){e=h(e)}o.digest({name:"sha-1"},e).then(function r(e){t(l(new Uint8Array(e)))},function n(r){t(a(e))})}function h(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:150}],150:[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 s=function(e){for(e+=9;e%64>0;e+=1);return e};var o=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 s=this,o,a=i%4,f=n%4,u=n-f;if(u>0){switch(a){case 0:e[i+3|0]=s.charCodeAt(r);case 1:e[i+2|0]=s.charCodeAt(r+1);case 2:e[i+1|0]=s.charCodeAt(r+2);case 3:e[i|0]=s.charCodeAt(r+3)}}for(o=a;o<u;o=o+4|0){t[i+o>>2]=s.charCodeAt(r+o)<<24|s.charCodeAt(r+o+1)<<16|s.charCodeAt(r+o+2)<<8|s.charCodeAt(r+o+3)}switch(f){case 3:e[i+u+1|0]=s.charCodeAt(r+u+2);case 2:e[i+u+2|0]=s.charCodeAt(r+u+1);case 1:e[i+u+3|0]=s.charCodeAt(r+u)}};var u=function(e,t,r,n,i){var s=this,o,a=i%4,f=n%4,u=n-f;if(u>0){switch(a){case 0:e[i+3|0]=s[r];case 1:e[i+2|0]=s[r+1];case 2:e[i+1|0]=s[r+2];case 3:e[i|0]=s[r+3]}}for(o=4-a;o<u;o=o+=4|0){t[i+o>>2]=s[r+o]<<24|s[r+o+1]<<16|s[r+o+2]<<8|s[r+o+3]}switch(f){case 3:e[i+u+1|0]=s[r+u+2];case 2:e[i+u+2|0]=s[r+u+1];case 1:e[i+u+3|0]=s[r+u]}};var h=function(e,t,r,n,s){var o=this,a,f=s%4,u=n%4,h=n-u;var l=new Uint8Array(i.readAsArrayBuffer(o.slice(r,r+n)));if(h>0){switch(f){case 0:e[s+3|0]=l[0];case 1:e[s+2|0]=l[1];case 2:e[s+1|0]=l[2];case 3:e[s|0]=l[3]}}for(a=4-f;a<h;a=a+=4|0){t[s+a>>2]=l[a]<<24|l[a+1]<<16|l[a+2]<<8|l[a+3]}switch(u){case 3:e[s+h+1|0]=l[h+2];case 2:e[s+h+2|0]=l[h+1];case 1:e[s+h+3|0]=l[h]}};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 h.bind(e)}};var c=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 d=function(e){var t,r,n="0123456789abcdef",i=[],s=new Uint8Array(e);for(t=0;t<s.length;t++){r=s[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=s(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=s(e);var i=new Int32Array(t.heap,0,n>>2);o(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,s){var o=n;if(s){o=g(n,i)}y(e,r,n);t.core.hash(o,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,s;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 d(w(e).buffer)}}n._core=function o(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,s=0,o=0,a=0,f=0,u=0,h=0,l=0,c=0,d=0,p=0,m=0,v=0;s=n[t+320>>2]|0;a=n[t+324>>2]|0;u=n[t+328>>2]|0;l=n[t+332>>2]|0;d=n[t+336>>2]|0;for(r=0;(r|0)<(e|0);r=r+64|0){o=s;f=a;h=u;c=l;p=d;for(i=0;(i|0)<64;i=i+4|0){v=n[r+i>>2]|0;m=((s<<5|s>>>27)+(a&u|~a&l)|0)+((v+d|0)+1518500249|0)|0;d=l;l=u;u=a<<30|a>>>2;a=s;s=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=((s<<5|s>>>27)+(a&u|~a&l)|0)+((v+d|0)+1518500249|0)|0;d=l;l=u;u=a<<30|a>>>2;a=s;s=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=((s<<5|s>>>27)+(a^u^l)|0)+((v+d|0)+1859775393|0)|0;d=l;l=u;u=a<<30|a>>>2;a=s;s=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=((s<<5|s>>>27)+(a&u|a&l|u&l)|0)+((v+d|0)-1894007588|0)|0;d=l;l=u;u=a<<30|a>>>2;a=s;s=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=((s<<5|s>>>27)+(a^u^l)|0)+((v+d|0)-899497514|0)|0;d=l;l=u;u=a<<30|a>>>2;a=s;s=m;n[i>>2]=v}s=s+o|0;a=a+f|0;u=u+h|0;l=l+c|0;d=d+p|0}n[t+320>>2]=s;n[t+324>>2]=a;n[t+328>>2]=u;n[t+332>>2]=l;n[t+336>>2]=d}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,s=new n(4*1024*1024);self.onmessage=function a(e){var t,r=e.data.data;try{t=s.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:{})},{}],151:[function(e,t,r){var n=1;var i=65535;var s=4;var o=function(){n=n+1&i};var a=setInterval(o,1e3/s|0);if(a.unref)a.unref();t.exports=function(e){var t=s*(e||5);var r=[0];var o=1;var a=n-1&i;return function(e){var f=n-a&i;if(f>t)f=t;a=n;while(f--){if(o===t)o=0;r[o]=r[o===0?t-1:o-1];o++}if(e)r[o-1]+=e;var u=r[o-1];var h=r.length<t?0:r[o===t?0:o];return r.length<s?u:(u-h)*s/r.length}}},{}],152:[function(e,t,r){(function(r,n){t.exports=c;var i=e("debug")("torrent-discovery");var s=e("bittorrent-dht/client");var o=e("events").EventEmitter;var a=e("xtend/mutable");var f=e("inherits");var u=e("run-parallel");var h=e("re-emitter");var l=e("bittorrent-tracker/client");f(c,o);function c(e){var t=this;if(!(t instanceof c))return new c(e);o.call(t);a(t,{announce:[],dht:typeof s==="function",rtcConfig:null,peerId:null,port:0,tracker:true,wrtc:null},e);t.infoHash=null;t.infoHashBuffer=null;t.torrent=null;t._externalDHT=typeof t.dht==="object";t._performedDHTLookup=false;if(!t.peerId)throw new Error("peerId required");if(!r.browser&&!t.port)throw new Error("port required");if(t.dht)t._createDHT(t.dhtPort)}c.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()}if(t.dht){if(t.dht.ready)t._dhtLookupAndAnnounce();else t.dht.on("ready",t._dhtLookupAndAnnounce.bind(t))}};c.prototype.updatePort=function(e){var t=this;if(e===t.port)return;t.port=e;if(t.dht&&t.infoHash){t._performedDHTLookup=false;t._dhtLookupAndAnnounce()}if(t.tracker&&t.tracker!==true){t.tracker.stop();t.tracker.destroy(function(){t._createTracker()})}};c.prototype.stop=function(e){var t=this;var r=[];if(t.tracker&&t.tracker!==true){t.tracker.stop();r.push(function(e){t.tracker.destroy(e)})}if(!t._externalDHT&&t.dht&&t.dht!==true){r.push(function(e){t.dht.destroy(e)})}u(r,e)};c.prototype._createDHT=function(e){var t=this;if(!t._externalDHT)t.dht=new s;h(t.dht,t,["error","warning"]);t.dht.on("peer",function(e,r){if(r===t.infoHash)t.emit("peer",e)});if(!t._externalDHT)t.dht.listen(e)};c.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);h(e.tracker,e,["peer","warning","error"]);e.tracker.on("update",function(t){e.emit("trackerAnnounce",t)});e.tracker.start()};c.prototype._dhtLookupAndAnnounce=function(){var e=this;if(e._performedDHTLookup)return;e._performedDHTLookup=true;i("dht lookup");e.dht.lookup(e.infoHash,function(t){if(t||!e.port)return;i("dht announce");e.dht.announce(e.infoHash,e.port,function(){i("dht announce complete");e.emit("dhtAnnounce")})})}}).call(this,e("_process"),e("buffer").Buffer)},{_process:43,"bittorrent-dht/client":33,"bittorrent-tracker/client":19,buffer:34,debug:116,events:38,inherits:124,"re-emitter":144,"run-parallel":145,"xtend/mutable":168}],153:[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:34}],154:[function(e,t,r){"use strict";function n(e,t){var r=1,n=e.length,i=e[0],s=e[0];for(var o=1;o<n;++o){s=i;i=e[o];if(t(i,s)){if(o===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 s=1;s<r;++s,i=n){i=n;n=e[s];if(n!==i){if(s===t){t++;continue}e[t++]=n}}e.length=t;return e}function s(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=s},{}],155:[function(e,t,r){(function(r){var n=e("bencode");var i=e("bitfield");var s=e("events").EventEmitter;var o=e("inherits");var a=e("simple-sha1");var f=1e7;var u=1e3;var h=16*1024;t.exports=function(e){o(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:u});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>f){return this.emit("warning",new Error("Peer gave maliciously large metadata size"))}this._metadataSize=e.metadata_size;this._numPieces=Math.ceil(this._metadataSize/h);this._remainingRejects=this._numPieces*2;if(this._fetching){this._requestPieces()}};t.prototype.onMessage=function(e){var t,r;try{var i=e.toString();var s=i.indexOf("ee")+2;t=n.decode(i.substring(0,s));r=e.slice(s)}catch(o){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;try{var t=n.decode(e).info;if(t){e=n.encode(t)}}catch(r){}if(this._infoHash&&this._infoHash!==a.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*h;var r=t+h;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>h){return}t.copy(this.metadata,e*h);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:u});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:156,bitfield:10,buffer:34,events:38,inherits:124,"simple-sha1":149}],156:[function(e,t,r){arguments[4][15][0].apply(r,arguments)},{"./lib/decode":157,"./lib/encode":159,dup:15}],157:[function(e,t,r){arguments[4][16][0].apply(r,arguments)},{"./dict":158,buffer:34,dup:16}],158:[function(e,t,r){arguments[4][17][0].apply(r,arguments)},{dup:17}],159:[function(e,t,r){arguments[4][18][0].apply(r,arguments)},{buffer:34,dup:18}],160:[function(e,t,r){var n=function(e,t,r){this._byteOffset=t||0;if(e instanceof ArrayBuffer){this.buffer=e}else if(typeof e=="object"){this.dataView=e;if(t){this._byteOffset+=t}}else{this.buffer=new ArrayBuffer(e||0)}this.position=0;this.endianness=r==null?n.LITTLE_ENDIAN:r};t.exports=n;n.prototype={};n.prototype.save=function(e){var t=new Blob([this.buffer]);var r=window.webkitURL||window.URL;if(r&&r.createObjectURL){var n=r.createObjectURL(t);var i=document.createElement("a");i.setAttribute("href",n);i.setAttribute("download",e);i.click();r.revokeObjectURL(n)}else{throw"DataStream.save: Can't create object URL."}};n.BIG_ENDIAN=false;n.LITTLE_ENDIAN=true;n.prototype._dynamicSize=true;Object.defineProperty(n.prototype,"dynamicSize",{get:function(){return this._dynamicSize},set:function(e){if(!e){this._trimAlloc()}this._dynamicSize=e}});n.prototype._byteLength=0;Object.defineProperty(n.prototype,"byteLength",{get:function(){return this._byteLength-this._byteOffset}});Object.defineProperty(n.prototype,"buffer",{get:function(){this._trimAlloc();return this._buffer},set:function(e){this._buffer=e;this._dataView=new DataView(this._buffer,this._byteOffset);this._byteLength=this._buffer.byteLength}});Object.defineProperty(n.prototype,"byteOffset",{get:function(){return this._byteOffset},set:function(e){this._byteOffset=e;this._dataView=new DataView(this._buffer,this._byteOffset);this._byteLength=this._buffer.byteLength}});Object.defineProperty(n.prototype,"dataView",{get:function(){return this._dataView},set:function(e){this._byteOffset=e.byteOffset;this._buffer=e.buffer;this._dataView=new DataView(this._buffer,this._byteOffset);this._byteLength=this._byteOffset+e.byteLength}});n.prototype._realloc=function(e){if(!this._dynamicSize){return}var t=this._byteOffset+this.position+e;var r=this._buffer.byteLength;if(t<=r){if(t>this._byteLength){this._byteLength=t}return}if(r<1){r=1}while(t>r){r*=2}var n=new ArrayBuffer(r);var i=new Uint8Array(this._buffer);var s=new Uint8Array(n,0,i.length);s.set(i);this.buffer=n;this._byteLength=t};n.prototype._trimAlloc=function(){if(this._byteLength==this._buffer.byteLength){return}var e=new ArrayBuffer(this._byteLength);var t=new Uint8Array(e);var r=new Uint8Array(this._buffer,0,t.length);t.set(r);this.buffer=e};n.prototype.shift=function(e){var t=new ArrayBuffer(this._byteLength-e);var r=new Uint8Array(t);var n=new Uint8Array(this._buffer,e,r.length);r.set(n);this.buffer=t;this.position-=e};n.prototype.seek=function(e){var t=Math.max(0,Math.min(this.byteLength,e));this.position=isNaN(t)||!isFinite(t)?0:t};n.prototype.isEof=function(){return this.position>=this._byteLength};n.prototype.mapInt32Array=function(e,t){this._realloc(e*4);var r=new Int32Array(this._buffer,this.byteOffset+this.position,e);n.arrayToNative(r,t==null?this.endianness:t);this.position+=e*4;return r};n.prototype.mapInt16Array=function(e,t){this._realloc(e*2);var r=new Int16Array(this._buffer,this.byteOffset+this.position,e);n.arrayToNative(r,t==null?this.endianness:t);this.position+=e*2;return r};n.prototype.mapInt8Array=function(e){this._realloc(e*1);var t=new Int8Array(this._buffer,this.byteOffset+this.position,e);this.position+=e*1;return t};n.prototype.mapUint32Array=function(e,t){this._realloc(e*4);var r=new Uint32Array(this._buffer,this.byteOffset+this.position,e);n.arrayToNative(r,t==null?this.endianness:t);this.position+=e*4;return r};n.prototype.mapUint16Array=function(e,t){this._realloc(e*2);var r=new Uint16Array(this._buffer,this.byteOffset+this.position,e);n.arrayToNative(r,t==null?this.endianness:t);this.position+=e*2;return r};n.prototype.mapUint8Array=function(e){this._realloc(e*1);var t=new Uint8Array(this._buffer,this.byteOffset+this.position,e);this.position+=e*1;return t};n.prototype.mapFloat64Array=function(e,t){this._realloc(e*8);var r=new Float64Array(this._buffer,this.byteOffset+this.position,e);n.arrayToNative(r,t==null?this.endianness:t);this.position+=e*8;return r};n.prototype.mapFloat32Array=function(e,t){this._realloc(e*4);var r=new Float32Array(this._buffer,this.byteOffset+this.position,e);n.arrayToNative(r,t==null?this.endianness:t);this.position+=e*4;return r};n.prototype.readInt32Array=function(e,t){e=e==null?this.byteLength-this.position/4:e;var r=new Int32Array(e);n.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT);n.arrayToNative(r,t==null?this.endianness:t);this.position+=r.byteLength;return r};n.prototype.readInt16Array=function(e,t){e=e==null?this.byteLength-this.position/2:e;var r=new Int16Array(e);n.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT);n.arrayToNative(r,t==null?this.endianness:t);this.position+=r.byteLength;return r};n.prototype.readInt8Array=function(e){e=e==null?this.byteLength-this.position:e;var t=new Int8Array(e);n.memcpy(t.buffer,0,this.buffer,this.byteOffset+this.position,e*t.BYTES_PER_ELEMENT);this.position+=t.byteLength;return t};n.prototype.readUint32Array=function(e,t){e=e==null?this.byteLength-this.position/4:e;var r=new Uint32Array(e);n.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT);n.arrayToNative(r,t==null?this.endianness:t);this.position+=r.byteLength;return r};n.prototype.readUint16Array=function(e,t){e=e==null?this.byteLength-this.position/2:e;var r=new Uint16Array(e);n.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT);n.arrayToNative(r,t==null?this.endianness:t);this.position+=r.byteLength;return r};n.prototype.readUint8Array=function(e){e=e==null?this.byteLength-this.position:e;var t=new Uint8Array(e);n.memcpy(t.buffer,0,this.buffer,this.byteOffset+this.position,e*t.BYTES_PER_ELEMENT);this.position+=t.byteLength;return t};n.prototype.readFloat64Array=function(e,t){e=e==null?this.byteLength-this.position/8:e;var r=new Float64Array(e);n.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT);n.arrayToNative(r,t==null?this.endianness:t);this.position+=r.byteLength;return r};n.prototype.readFloat32Array=function(e,t){e=e==null?this.byteLength-this.position/4:e;var r=new Float32Array(e);n.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT);n.arrayToNative(r,t==null?this.endianness:t);this.position+=r.byteLength;return r};n.prototype.writeInt32Array=function(e,t){this._realloc(e.length*4);if(e instanceof Int32Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapInt32Array(e.length,t)}else{for(var r=0;r<e.length;r++){this.writeInt32(e[r],t)}}};n.prototype.writeInt16Array=function(e,t){this._realloc(e.length*2);if(e instanceof Int16Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapInt16Array(e.length,t)}else{for(var r=0;r<e.length;r++){this.writeInt16(e[r],t)}}};n.prototype.writeInt8Array=function(e){this._realloc(e.length*1);if(e instanceof Int8Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapInt8Array(e.length)}else{for(var t=0;t<e.length;t++){this.writeInt8(e[t])}}};n.prototype.writeUint32Array=function(e,t){this._realloc(e.length*4);if(e instanceof Uint32Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapUint32Array(e.length,t)}else{for(var r=0;r<e.length;r++){this.writeUint32(e[r],t)}}};n.prototype.writeUint16Array=function(e,t){this._realloc(e.length*2);if(e instanceof Uint16Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapUint16Array(e.length,t)}else{for(var r=0;r<e.length;r++){this.writeUint16(e[r],t)}}};n.prototype.writeUint8Array=function(e){this._realloc(e.length*1);if(e instanceof Uint8Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapUint8Array(e.length)}else{for(var t=0;t<e.length;t++){this.writeUint8(e[t])}}};n.prototype.writeFloat64Array=function(e,t){this._realloc(e.length*8);if(e instanceof Float64Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapFloat64Array(e.length,t)}else{for(var r=0;r<e.length;r++){this.writeFloat64(e[r],t)}}};n.prototype.writeFloat32Array=function(e,t){this._realloc(e.length*4);if(e instanceof Float32Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapFloat32Array(e.length,t)}else{for(var r=0;r<e.length;r++){this.writeFloat32(e[r],t)}}};n.prototype.readInt32=function(e){var t=this._dataView.getInt32(this.position,e==null?this.endianness:e);this.position+=4;return t};n.prototype.readInt16=function(e){var t=this._dataView.getInt16(this.position,e==null?this.endianness:e);this.position+=2;return t};n.prototype.readInt8=function(){var e=this._dataView.getInt8(this.position);this.position+=1;return e};n.prototype.readUint32=function(e){var t=this._dataView.getUint32(this.position,e==null?this.endianness:e);this.position+=4;return t};n.prototype.readUint16=function(e){var t=this._dataView.getUint16(this.position,e==null?this.endianness:e);this.position+=2;return t};n.prototype.readUint8=function(){var e=this._dataView.getUint8(this.position);this.position+=1;return e};n.prototype.readFloat32=function(e){var t=this._dataView.getFloat32(this.position,e==null?this.endianness:e);this.position+=4;return t};n.prototype.readFloat64=function(e){var t=this._dataView.getFloat64(this.position,e==null?this.endianness:e);this.position+=8;return t};n.prototype.writeInt32=function(e,t){this._realloc(4);this._dataView.setInt32(this.position,e,t==null?this.endianness:t);this.position+=4};n.prototype.writeInt16=function(e,t){this._realloc(2);this._dataView.setInt16(this.position,e,t==null?this.endianness:t);this.position+=2};n.prototype.writeInt8=function(e){this._realloc(1);this._dataView.setInt8(this.position,e);this.position+=1};n.prototype.writeUint32=function(e,t){this._realloc(4);this._dataView.setUint32(this.position,e,t==null?this.endianness:t);this.position+=4};n.prototype.writeUint16=function(e,t){this._realloc(2);this._dataView.setUint16(this.position,e,t==null?this.endianness:t);this.position+=2};n.prototype.writeUint8=function(e){this._realloc(1);this._dataView.setUint8(this.position,e);this.position+=1};n.prototype.writeFloat32=function(e,t){this._realloc(4);this._dataView.setFloat32(this.position,e,t==null?this.endianness:t);this.position+=4};n.prototype.writeFloat64=function(e,t){this._realloc(8);this._dataView.setFloat64(this.position,e,t==null?this.endianness:t);this.position+=8};n.endianness=new Int8Array(new Int16Array([1]).buffer)[0]>0;n.memcpy=function(e,t,r,n,i){var s=new Uint8Array(e,t,i);var o=new Uint8Array(r,n,i);s.set(o)};n.arrayToNative=function(e,t){if(t==this.endianness){return e}else{return this.flipArrayEndianness(e)}};n.nativeToEndian=function(e,t){if(this.endianness==t){return e}else{return this.flipArrayEndianness(e)}};n.flipArrayEndianness=function(e){var t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);for(var r=0;r<e.byteLength;r+=e.BYTES_PER_ELEMENT){for(var n=r+e.BYTES_PER_ELEMENT-1,i=r;n>i;n--,i++){var s=t[i];t[i]=t[n];t[n]=s}}return e};n.prototype.failurePosition=0;
+n.prototype.readStruct=function(e){var t={},r,n,i;var s=this.position;for(var o=0;o<e.length;o+=2){r=e[o+1];n=this.readType(r,t);if(n==null){if(this.failurePosition===0){this.failurePosition=this.position}this.position=s;return null}t[e[o]]=n}return t};n.prototype.readUCS2String=function(e,t){return String.fromCharCode.apply(null,this.readUint16Array(e,t))};n.prototype.writeUCS2String=function(e,t,r){if(r==null){r=e.length}for(var n=0;n<e.length&&n<r;n++){this.writeUint16(e.charCodeAt(n),t)}for(;n<r;n++){this.writeUint16(0)}};n.prototype.readString=function(e,t){if(t==null||t=="ASCII"){return String.fromCharCode.apply(null,this.mapUint8Array(e==null?this.byteLength-this.position:e))}else{return new TextDecoder(t).decode(this.mapUint8Array(e))}};n.prototype.writeString=function(e,t,r){var n=0;if(t==null||t=="ASCII"){if(r!=null){var i=Math.min(e.length,r);for(n=0;n<i;n++){this.writeUint8(e.charCodeAt(n))}for(;n<r;n++){this.writeUint8(0)}}else{for(n=0;n<e.length;n++){this.writeUint8(e.charCodeAt(n))}}}else{this.writeUint8Array(new TextEncoder(t).encode(e.substring(0,r)))}};n.prototype.readCString=function(e){var t=this.byteLength-this.position;var r=new Uint8Array(this._buffer,this._byteOffset+this.position);var n=t;if(e!=null){n=Math.min(e,t)}for(var i=0;i<n&&r[i]!==0;i++);var s=String.fromCharCode.apply(null,this.mapUint8Array(i));if(e!=null){this.position+=n-i}else if(i!=t){this.position+=1}return s};n.prototype.writeCString=function(e,t){var r=0;if(t!=null){var n=Math.min(e.length,t);for(r=0;r<n;r++){this.writeUint8(e.charCodeAt(r))}for(;r<t;r++){this.writeUint8(0)}}else{for(r=0;r<e.length;r++){this.writeUint8(e.charCodeAt(r))}this.writeUint8(0)}};n.prototype.readType=function(e,t){if(typeof e=="function"){return e(this,t)}else if(typeof e=="object"&&!(e instanceof Array)){return e.get(this,t)}else if(e instanceof Array&&e.length!=3){return this.readStruct(e,t)}var r=null;var i=null;var s="ASCII";var o=this.position;var a;var f;var u;if(typeof e=="string"&&/:/.test(e)){a=e.split(":");e=a[0];i=parseInt(a[1])}if(typeof e=="string"&&/,/.test(e)){a=e.split(",");e=a[0];s=parseInt(a[1])}switch(e){case"uint8":r=this.readUint8();break;case"int8":r=this.readInt8();break;case"uint16":r=this.readUint16(this.endianness);break;case"int16":r=this.readInt16(this.endianness);break;case"uint32":r=this.readUint32(this.endianness);break;case"int32":r=this.readInt32(this.endianness);break;case"float32":r=this.readFloat32(this.endianness);break;case"float64":r=this.readFloat64(this.endianness);break;case"uint16be":r=this.readUint16(n.BIG_ENDIAN);break;case"int16be":r=this.readInt16(n.BIG_ENDIAN);break;case"uint32be":r=this.readUint32(n.BIG_ENDIAN);break;case"int32be":r=this.readInt32(n.BIG_ENDIAN);break;case"float32be":r=this.readFloat32(n.BIG_ENDIAN);break;case"float64be":r=this.readFloat64(n.BIG_ENDIAN);break;case"uint16le":r=this.readUint16(n.LITTLE_ENDIAN);break;case"int16le":r=this.readInt16(n.LITTLE_ENDIAN);break;case"uint32le":r=this.readUint32(n.LITTLE_ENDIAN);break;case"int32le":r=this.readInt32(n.LITTLE_ENDIAN);break;case"float32le":r=this.readFloat32(n.LITTLE_ENDIAN);break;case"float64le":r=this.readFloat64(n.LITTLE_ENDIAN);break;case"cstring":r=this.readCString(i);break;case"string":r=this.readString(i,s);break;case"u16string":r=this.readUCS2String(i,this.endianness);break;case"u16stringle":r=this.readUCS2String(i,n.LITTLE_ENDIAN);break;case"u16stringbe":r=this.readUCS2String(i,n.BIG_ENDIAN);break;default:if(e.length==3){var h=e[1];var l=e[2];var c=0;if(typeof l=="function"){c=l(t,this,e)}else if(typeof l=="string"&&t[l]!=null){c=parseInt(t[l])}else{c=parseInt(l)}if(typeof h=="string"){var d=h.replace(/(le|be)$/,"");var p=null;if(/le$/.test(h)){p=n.LITTLE_ENDIAN}else if(/be$/.test(h)){p=n.BIG_ENDIAN}if(l=="*"){c=null}switch(d){case"uint8":r=this.readUint8Array(c);break;case"uint16":r=this.readUint16Array(c,p);break;case"uint32":r=this.readUint32Array(c,p);break;case"int8":r=this.readInt8Array(c);break;case"int16":r=this.readInt16Array(c,p);break;case"int32":r=this.readInt32Array(c,p);break;case"float32":r=this.readFloat32Array(c,p);break;case"float64":r=this.readFloat64Array(c,p);break;case"cstring":case"utf16string":case"string":if(c==null){r=[];while(!this.isEof()){u=this.readType(h,t);if(u==null)break;r.push(u)}}else{r=new Array(c);for(f=0;f<c;f++){r[f]=this.readType(h,t)}}break}}else{if(l=="*"){r=[];var m=this.buffer;while(true){var v=this.position;try{var g=this.readType(h,t);if(g==null){this.position=v;break}r.push(g)}catch(y){this.position=v;break}}}else{r=new Array(c);for(f=0;f<c;f++){u=this.readType(h,t);if(u==null)return null;r[f]=u}}}break}}if(i!=null){this.position=o+i}return r};n.prototype.writeStruct=function(e,t){for(var r=0;r<e.length;r+=2){var n=e[r+1];this.writeType(n,t[e[r]],t)}};n.prototype.writeType=function(e,t,r){var i;if(typeof e=="function"){return e(this,t)}else if(typeof e=="object"&&!(e instanceof Array)){return e.set(this,t,r)}var s=null;var o="ASCII";var a=this.position;if(typeof e=="string"&&/:/.test(e)){i=e.split(":");e=i[0];s=parseInt(i[1])}if(typeof e=="string"&&/,/.test(e)){i=e.split(",");e=i[0];o=parseInt(i[1])}switch(e){case"uint8":this.writeUint8(t);break;case"int8":this.writeInt8(t);break;case"uint16":this.writeUint16(t,this.endianness);break;case"int16":this.writeInt16(t,this.endianness);break;case"uint32":this.writeUint32(t,this.endianness);break;case"int32":this.writeInt32(t,this.endianness);break;case"float32":this.writeFloat32(t,this.endianness);break;case"float64":this.writeFloat64(t,this.endianness);break;case"uint16be":this.writeUint16(t,n.BIG_ENDIAN);break;case"int16be":this.writeInt16(t,n.BIG_ENDIAN);break;case"uint32be":this.writeUint32(t,n.BIG_ENDIAN);break;case"int32be":this.writeInt32(t,n.BIG_ENDIAN);break;case"float32be":this.writeFloat32(t,n.BIG_ENDIAN);break;case"float64be":this.writeFloat64(t,n.BIG_ENDIAN);break;case"uint16le":this.writeUint16(t,n.LITTLE_ENDIAN);break;case"int16le":this.writeInt16(t,n.LITTLE_ENDIAN);break;case"uint32le":this.writeUint32(t,n.LITTLE_ENDIAN);break;case"int32le":this.writeInt32(t,n.LITTLE_ENDIAN);break;case"float32le":this.writeFloat32(t,n.LITTLE_ENDIAN);break;case"float64le":this.writeFloat64(t,n.LITTLE_ENDIAN);break;case"cstring":this.writeCString(t,s);break;case"string":this.writeString(t,o,s);break;case"u16string":this.writeUCS2String(t,this.endianness,s);break;case"u16stringle":this.writeUCS2String(t,n.LITTLE_ENDIAN,s);break;case"u16stringbe":this.writeUCS2String(t,n.BIG_ENDIAN,s);break;default:if(e.length==3){var f=e[1];for(var u=0;u<t.length;u++){this.writeType(f,t[u])}break}else{this.writeStruct(e,t);break}}if(s!=null){this.position=a;this._realloc(s);this.position=a+s}};var i=Math.pow(2,32);r.MAX_SIZE=i;n.prototype.readUint64=function(){return this.readUint32()*i+this.readUint32()};n.prototype.writeUint64=function(e){var t=Math.floor(e/i);this.writeUint32(t);this.writeUint32(e&4294967295)};n.prototype.readUint24=function(){return(this.readUint8()<<16)+(this.readUint8()<<8)+this.readUint8()};n.prototype.writeUint24=function(e){this.writeUint8((e&16711680)>>16);this.writeUint8((e&65280)>>8);this.writeUint8(e&255)};n.prototype.adjustUint32=function(e,t){var r=this.position;this.seek(e);this.writeUint32(t);this.seek(r)}},{}],161:[function(e,t,r){var n=e("./DataStream");var s=e("./descriptor");var o=e("./log");var a={ERR_NOT_ENOUGH_DATA:0,OK:1,boxCodes:["mdat","avcC","hvcC","ftyp","payl","vmhd","smhd","hmhd","dref","elst"],fullBoxCodes:["mvhd","tkhd","mdhd","hdlr","smhd","hmhd","nhmd","url ","urn ","ctts","cslg","stco","co64","stsc","stss","stsz","stz2","stts","stsh","mehd","trex","mfhd","tfhd","trun","tfdt","esds","subs","txtC"],containerBoxCodes:[["moov",["trak"]],["trak"],["edts"],["mdia"],["minf"],["dinf"],["stbl"],["mvex",["trex"]],["moof",["traf"]],["traf",["trun"]],["vttc"],["tref"]],sampleEntryCodes:[{prefix:"Visual",types:["mp4v","avc1","avc2","avc3","avc4","avcp","drac","encv","mjp2","mvc1","mvc2","resv","s263","svc1","vc-1","hvc1","hev1"]},{prefix:"Audio",types:["mp4a","ac-3","alac","dra1","dtsc","dtse",,"dtsh","dtsl","ec-3","enca","g719","g726","m4ae","mlpa","raw ","samr","sawb","sawp","sevc","sqcp","ssmv","twos"]},{prefix:"Hint",types:["fdp ","m2ts","pm2t","prtp","rm2t","rrtp","rsrp","rtp ","sm2t","srtp"]},{prefix:"Metadata",types:["metx","mett","urim"]},{prefix:"Subtitle",types:["stpp","wvtt","sbtt","tx3g","stxt"]}],trackReferenceTypes:["scal"],initialize:function(){var e,t;var r;a.FullBox.prototype=new a.Box;a.ContainerBox.prototype=new a.Box;a.stsdBox.prototype=new a.FullBox;a.SampleEntry.prototype=new a.FullBox;a.TrackReferenceTypeBox.prototype=new a.Box;r=a.boxCodes.length;for(e=0;e<r;e++){a[a.boxCodes[e]+"Box"]=function(e){return function(t){a.Box.call(this,a.boxCodes[e],t)}}(e);a[a.boxCodes[e]+"Box"].prototype=new a.Box}r=a.fullBoxCodes.length;for(e=0;e<r;e++){a[a.fullBoxCodes[e]+"Box"]=function(e){return function(t){a.FullBox.call(this,a.fullBoxCodes[e],t)}}(e);a[a.fullBoxCodes[e]+"Box"].prototype=new a.FullBox}r=a.containerBoxCodes.length;for(e=0;e<r;e++){a[a.containerBoxCodes[e][0]+"Box"]=function(e,t){return function(r){a.ContainerBox.call(this,a.containerBoxCodes[e][0],r);if(t){this.subBoxNames=t;var n=t.length;for(var i=0;i<n;i++){this[t[i]+"s"]=[]}}}}(e,a.containerBoxCodes[e][1]);a[a.containerBoxCodes[e][0]+"Box"].prototype=new a.ContainerBox}r=a.sampleEntryCodes.length;for(t=0;t<r;t++){var n=a.sampleEntryCodes[t].prefix;var i=a.sampleEntryCodes[t].types;var s=i.length;a[n+"SampleEntry"]=function(e,t){a.SampleEntry.call(this,e,t)};a[n+"SampleEntry"].prototype=new a.SampleEntry;for(e=0;e<s;e++){a[i[e]+"Box"]=function(e,t){return function(r){a[a.sampleEntryCodes[e].prefix+"SampleEntry"].call(this,a.sampleEntryCodes[e].types[t],r)}}(t,e);a[i[e]+"Box"].prototype=new a[n+"SampleEntry"]}}r=a.trackReferenceTypes.length;for(e=0;e<r;e++){a[a.trackReferenceTypes[e]+"Box"]=function(e){return function(t){a.TrackReferenceTypeBox.call(this,a.trackReferenceTypes[e],t)}}(e);a[a.trackReferenceTypes[e]+"Box"].prototype=new a.Box}},Box:function(e,t){this.type=e;this.size=t},FullBox:function(e,t){a.Box.call(this,e,t);this.flags=0;this.version=0},ContainerBox:function(e,t){a.Box.call(this,e,t);this.boxes=[]},SampleEntry:function(e,t){a.Box.call(this,e,t);this.boxes=[]},TrackReferenceTypeBox:function(e,t){a.Box.call(this,e,t);this.track_ids=[]},stsdBox:function(e){a.FullBox.call(this,"stsd",e);this.entries=[]},parseOneBox:function(e,t){var r;var n=e.position;var i=0;if(e.byteLength-e.position<8){o.d("BoxParser","Not enough data in stream to parse the type and size of the box");return{code:a.ERR_NOT_ENOUGH_DATA}}var s=e.readUint32();var f=e.readString(4);o.d("BoxParser","Found box of type "+f+" and size "+s+" at position "+n+" in the current buffer ("+(e.buffer.fileStart+n)+" in the file)");i=8;if(s==1){if(e.byteLength-e.position<8){e.seek(n);o.w("BoxParser",'Not enough data in stream to parse the extended size of the "'+f+'" box');return{code:a.ERR_NOT_ENOUGH_DATA}}s=e.readUint64();i+=8}else if(s===0){throw"Unlimited box size not supported"}if(n+s>e.byteLength){e.seek(n);o.w("BoxParser",'Not enough data in stream to parse the entire "'+f+'" box');return{code:a.ERR_NOT_ENOUGH_DATA,type:f,size:s,hdr_size:i}}if(a[f+"Box"]){r=new a[f+"Box"](s-i)}else{if(t){r=new a.SampleEntry(f,s-i)}else{r=new a.Box(f,s-i)}}r.hdr_size=i;r.start=n;r.fileStart=n+e.buffer.fileStart;r.parse(e);e.seek(n+s);return{code:a.OK,box:r,size:s}}};t.exports=a;a.initialize();a.Box.prototype.parse=function(e){if(this.type!="mdat"){this.data=e.readUint8Array(this.size)}else{e.seek(this.start+this.size+this.hdr_size)}};a.FullBox.prototype.parseFullHeader=function(e){this.version=e.readUint8();this.flags=e.readUint24();this.size-=4};a.ContainerBox.prototype.parse=function(e){var t;var r;var n;n=e.position;while(e.position<n+this.size){t=a.parseOneBox(e);r=t.box;this.boxes.push(r);if(this.subBoxNames&&this.subBoxNames.indexOf(r.type)!=-1){this[this.subBoxNames+"s"].push(r)}else{this[r.type]=r}}};a.SampleEntry.prototype.isVideo=function(){return false};a.SampleEntry.prototype.isAudio=function(){return false};a.SampleEntry.prototype.isSubtitle=function(){return false};a.SampleEntry.prototype.isMetadata=function(){return false};a.SampleEntry.prototype.isHint=function(){return false};a.SampleEntry.prototype.getCodec=function(){return this.type};a.SampleEntry.prototype.getWidth=function(){return""};a.SampleEntry.prototype.getHeight=function(){return""};a.SampleEntry.prototype.getChannelCount=function(){return""};a.SampleEntry.prototype.getSampleRate=function(){return""};a.SampleEntry.prototype.getSampleSize=function(){return""};a.SampleEntry.prototype.parseHeader=function(e){this.start=e.position;e.readUint8Array(6);this.data_reference_index=e.readUint16()};a.SampleEntry.prototype.parse=function(e){this.parseHeader(e);e.seek(this.start+this.size)};a.SampleEntry.prototype.parseFooter=function(e){var t;var r;while(e.position<this.start+this.size){t=a.parseOneBox(e,false);r=t.box;this.boxes.push(r);this[r.type]=r}};a.VisualSampleEntry.prototype.parse=function(e){this.parseHeader(e);e.readUint16();e.readUint16();e.readUint32Array(3);this.width=e.readUint16();this.height=e.readUint16();this.horizresolution=e.readUint32();this.vertresolution=e.readUint32();e.readUint32();this.frame_count=e.readUint16();this.compressorname=e.readString(32);this.depth=e.readUint16();e.readUint16();this.parseFooter(e)};a.VisualSampleEntry.prototype.isVideo=function(){return true};a.VisualSampleEntry.prototype.getWidth=function(){return this.width};a.VisualSampleEntry.prototype.getHeight=function(){return this.height};a.AudioSampleEntry.prototype.parse=function(e){this.parseHeader(e);e.readUint32Array(2);this.channel_count=e.readUint16();this.samplesize=e.readUint16();e.readUint16();e.readUint16();this.samplerate=e.readUint32()/(1<<16);this.parseFooter(e)};a.AudioSampleEntry.prototype.isAudio=function(){return true};a.AudioSampleEntry.prototype.getChannelCount=function(){return this.channel_count};a.AudioSampleEntry.prototype.getSampleRate=function(){return this.samplerate};a.AudioSampleEntry.prototype.getSampleSize=function(){return this.samplesize};a.SubtitleSampleEntry.prototype.parse=function(e){this.parseHeader(e);this.parseFooter(e)};a.SubtitleSampleEntry.prototype.isSubtitle=function(){return true};a.MetadataSampleEntry.prototype.parse=function(e){this.parseHeader(e);this.parseFooter(e)};a.MetadataSampleEntry.prototype.isMetadata=function(){return true};a.TrackReferenceTypeBox.prototype.parse=function(e){this.track_ids=e.readUint8Array(this.size)};a.metxBox.prototype.parse=function(e){this.parseHeader(e);this.content_encoding=e.readCString();this.namespace=e.readCString();this.schema_location=e.readCString();this.parseFooter(e)};a.mettBox.prototype.parse=function(e){this.parseHeader(e);this.content_encoding=e.readCString();this.mime_format=e.readCString();this.parseFooter(e)};a.sbttBox.prototype.parse=function(e){this.parseHeader(e);this.content_encoding=e.readCString();this.mime_format=e.readCString();this.parseFooter(e)};a.stxtBox.prototype.parse=function(e){this.parseHeader(e);this.content_encoding=e.readCString();this.mime_format=e.readCString();this.parseFooter(e)};a.stppBox.prototype.parse=function(e){this.parseHeader(e);this.namespace=e.readCString();this.schema_location=e.readCString();this.auxiliary_mime_types=e.readCString();this.parseFooter(e)};a.tx3gBox.prototype.parse=function(e){this.parseHeader(e);this.displayFlags=e.readUint32();this.horizontal_justification=e.readInt8();this.vertical_justification=e.readInt8();this.bg_color_rgba=e.readUint8Array(4);this.box_record=e.readInt16Array(4);this.style_record=e.readUint8Array(12);this.parseFooter(e)};a.ftypBox.prototype.parse=function(e){this.major_brand=e.readString(4);this.minor_version=e.readUint32();this.size-=8;this.compatible_brands=[];var t=0;while(this.size>=4){this.compatible_brands[t]=e.readString(4);this.size-=4;t++}};a.mvhdBox.prototype.parse=function(e){this.flags=0;this.parseFullHeader(e);if(this.version==1){this.creation_time=e.readUint64();this.modification_time=e.readUint64();this.timescale=e.readUint32();this.duration=e.readUint64()}else{this.creation_time=e.readUint32();this.modification_time=e.readUint32();this.timescale=e.readUint32();this.duration=e.readUint32()}this.rate=e.readUint32();this.volume=e.readUint16()>>8;e.readUint16();e.readUint32Array(2);this.matrix=e.readUint32Array(9);e.readUint32Array(6);this.next_track_id=e.readUint32()};a.TKHD_FLAG_ENABLED=1;a.TKHD_FLAG_IN_MOVIE=2;a.TKHD_FLAG_IN_PREVIEW=4;a.tkhdBox.prototype.parse=function(e){this.parseFullHeader(e);if(this.version==1){this.creation_time=e.readUint64();this.modification_time=e.readUint64();this.track_id=e.readUint32();e.readUint32();this.duration=e.readUint64()}else{this.creation_time=e.readUint32();this.modification_time=e.readUint32();this.track_id=e.readUint32();e.readUint32();this.duration=e.readUint32()}e.readUint32Array(2);this.layer=e.readInt16();this.alternate_group=e.readInt16();this.volume=e.readInt16()>>8;e.readUint16();this.matrix=e.readInt32Array(9);this.width=e.readUint32();this.height=e.readUint32()};a.mdhdBox.prototype.parse=function(e){this.parseFullHeader(e);if(this.version==1){this.creation_time=e.readUint64();this.modification_time=e.readUint64();this.timescale=e.readUint32();this.duration=e.readUint64()}else{this.creation_time=e.readUint32();this.modification_time=e.readUint32();this.timescale=e.readUint32();this.duration=e.readUint32()}this.language=e.readUint16();var t=[];t[0]=this.language>>10&31;t[1]=this.language>>5&31;t[2]=this.language&31;this.languageString=String.fromCharCode(t[0]+96,t[1]+96,t[2]+96);e.readUint16()};a.hdlrBox.prototype.parse=function(e){this.parseFullHeader(e);if(this.version===0){e.readUint32();this.handler=e.readString(4);e.readUint32Array(3);this.name=e.readCString()}else{this.data=e.readUint8Array(size)}};a.stsdBox.prototype.parse=function(e){var t;var r;this.parseFullHeader(e);r=e.readUint32();for(i=1;i<=r;i++){t=a.parseOneBox(e,true);this.entries.push(t.box)}};a.avcCBox.prototype.parse=function(e){var t;var r;var n;this.configurationVersion=e.readUint8();this.AVCProfileIndication=e.readUint8();this.profile_compatibility=e.readUint8();this.AVCLevelIndication=e.readUint8();this.lengthSizeMinusOne=e.readUint8()&3;r=e.readUint8()&31;this.size-=6;this.SPS=new Array(r);for(t=0;t<r;t++){n=e.readUint16();this.SPS[t]=e.readUint8Array(n);this.size-=2+n}r=e.readUint8();this.size--;this.PPS=new Array(r);for(t=0;t<r;t++){n=e.readUint16();this.PPS[t]=e.readUint8Array(n);this.size-=2+n}if(this.size>0){this.ext=e.readUint8Array(this.size)}};a.hvcCBox.prototype.parse=function(e){var t;var r;var n;var i;this.configurationVersion=e.readUint8();i=e.readUint8();this.general_profile_space=i>>6;this.general_tier_flag=(i&32)>>5;this.general_profile_idc=i&31;this.general_profile_compatibility=e.readUint32();this.general_constraint_indicator=e.readUint8Array(6);this.general_level_idc=e.readUint8();this.min_spatial_segmentation_idc=e.readUint16()&4095;this.parallelismType=e.readUint8()&3;this.chromaFormat=e.readUint8()&3;this.bitDepthLumaMinus8=e.readUint8()&7;this.bitDepthChromaMinus8=e.readUint8()&7;this.avgFrameRate=e.readUint16();i=e.readUint8();this.constantFrameRate=i>>6;this.numTemporalLayers=(i&13)>>3;this.temporalIdNested=(i&4)>>2;this.lengthSizeMinusOne=i&3;this.nalu_arrays=[];numOfArrays=e.readUint8();for(t=0;t<numOfArrays;t++){var s=[];this.nalu_arrays.push(s);i=e.readUint8();s.completeness=(i&128)>>7;s.nalu_type=i&63;numNalus=e.readUint16();for(j=0;j<numNalus;j++){var o={};s.push(o);n=e.readUint16();o.data=e.readUint8Array(n)}}};function f(e,t){var r=Number(e).toString(16);t=typeof t==="undefined"||t===null?t=2:t;while(r.length<t){r="0"+r}return r}a.avc1Box.prototype.getCodec=function(){var e=a.SampleEntry.prototype.getCodec.call(this);if(this.avcC){return e+"."+f(this.avcC.AVCProfileIndication)+""+f(this.avcC.profile_compatibility)+""+f(this.avcC.AVCLevelIndication)}else{return e}};a.hvc1Box.prototype.getCodec=function(){var e;var t=a.SampleEntry.prototype.getCodec.call(this);if(this.hvcC){t+=".";switch(this.hvcC.general_profile_space){case 0:t+="";break;case 1:t+="A";break;case 2:t+="B";break;case 3:t+="C";break}t+=this.hvcC.general_profile_idc;t+=".";var r=this.hvcC.general_profile_compatibility;var n=0;for(e=0;e<32;e++){n|=r&1;if(e==31)break;n<<=1;r>>=1}t+=f(n,0);t+=".";if(this.hvcC.general_tier_flag===0){t+="L"}else{t+="H"}t+=this.hvcC.general_level_idc;var i=false;var s="";for(e=5;e>=0;e--){if(this.hvcC.general_constraint_indicator[e]||i){s="."+f(this.hvcC.general_constraint_indicator[e],0)+s;i=true}}t+=s}return t};a.mp4aBox.prototype.getCodec=function(){var e=a.SampleEntry.prototype.getCodec.call(this);if(this.esds&&this.esds.esd){var t=this.esds.esd.getOTI();var r=this.esds.esd.getAudioConfig();return e+"."+f(t)+(r?"."+r:"")}else{return e}};a.esdsBox.prototype.parse=function(e){this.parseFullHeader(e);this.data=e.readUint8Array(this.size);this.size=0;var t=new s;this.esd=t.parseOneDescriptor(new n(this.data.buffer,0,n.BIG_ENDIAN))};a.txtCBox.prototype.parse=function(e){this.parseFullHeader(e);this.config=e.readCString()};a.cttsBox.prototype.parse=function(e){var t;var r;this.parseFullHeader(e);t=e.readUint32();this.sample_counts=[];this.sample_offsets=[];if(this.version===0){for(r=0;r<t;r++){this.sample_counts.push(e.readUint32());this.sample_offsets.push(e.readInt32())}}else if(this.version==1){for(r=0;r<t;r++){this.sample_counts.push(e.readUint32());this.sample_offsets.push(e.readInt32())}}else{this.data=e.readUint8Array(this.size-4)}};a.cttsBox.prototype.unpack=function(e){var t,r,n;n=0;for(t=0;t<this.sample_counts.length;t++){for(r=0;r<this.sample_counts[t];r++){e[n].pts=e[n].dts+this.sample_offsets[t];n++}}};a.cslgBox.prototype.parse=function(e){var t;this.parseFullHeader(e);if(this.version===0){this.compositionToDTSShift=e.readInt32();this.leastDecodeToDisplayDelta=e.readInt32();this.greatestDecodeToDisplayDelta=e.readInt32();this.compositionStartTime=e.readInt32();this.compositionEndTime=e.readInt32()}else{this.data=e.readUint8Array(this.size-4)}};a.sttsBox.prototype.parse=function(e){var t;var r;this.parseFullHeader(e);t=e.readUint32();this.sample_counts=[];this.sample_deltas=[];if(this.version===0){for(r=0;r<t;r++){this.sample_counts.push(e.readUint32());this.sample_deltas.push(e.readUint32())}}else{this.data=e.readUint8Array(this.size-4)}};a.sttsBox.prototype.unpack=function(e){var t,r,n;n=0;for(t=0;t<this.sample_counts.length;t++){for(r=0;r<this.sample_counts[t];r++){if(n===0){e[n].dts=0}else{e[n].dts=e[n-1].dts+this.sample_deltas[t]}n++}}};a.stssBox.prototype.parse=function(e){var t;this.parseFullHeader(e);t=e.readUint32();if(this.version===0){this.sample_numbers=e.readUint32Array(t)}else{this.data=e.readUint8Array(this.size-4)}};a.stshBox.prototype.parse=function(e){var t;var r;this.parseFullHeader(e);t=e.readUint32();this.shadowed_sample_numbers=[];this.sync_sample_numbers=[];if(this.version===0){for(r=0;r<t;r++){this.shadowed_sample_numbers.push(e.readUint32());this.sync_sample_numbers.push(e.readUint32())}}else{this.data=e.readUint8Array(this.size-4)}};a.stcoBox.prototype.parse=function(e){var t;this.parseFullHeader(e);t=e.readUint32();if(this.version===0){this.chunk_offsets=e.readUint32Array(t)}else{this.data=e.readUint8Array(this.size-4)}};a.stcoBox.prototype.unpack=function(e){var t;for(t=0;t<this.chunk_offsets.length;t++){e[t].offset=this.chunk_offsets[t]}};a.co64Box.prototype.parse=function(e){var t;var r;this.parseFullHeader(e);t=e.readUint32();this.chunk_offsets=[];if(this.version===0){for(r=0;r<t;r++){this.chunk_offsets.push(e.readUint64())}}else{this.data=e.readUint8Array(this.size-4)}};a.stscBox.prototype.parse=function(e){var t;var r;this.parseFullHeader(e);t=e.readUint32();this.first_chunk=[];this.samples_per_chunk=[];this.sample_description_index=[];if(this.version===0){for(r=0;r<t;r++){this.first_chunk.push(e.readUint32());this.samples_per_chunk.push(e.readUint32());this.sample_description_index.push(e.readUint32())}}else{this.data=e.readUint8Array(this.size-4)}};a.stscBox.prototype.unpack=function(e){var t,r,n,i,s;i=0;s=0;for(t=0;t<this.first_chunk.length;t++){for(r=0;r<(t+1<this.first_chunk.length?this.first_chunk[t+1]:Infinity);r++){s++;for(n=0;n<this.samples_per_chunk[t];n++){if(e[i]){e[i].description_index=this.sample_description_index[t];e[i].chunk_index=s}else{return}i++}}}};a.stszBox.prototype.parse=function(e){var t;var r;var n;this.parseFullHeader(e);this.sample_sizes=[];if(this.version===0){r=e.readUint32();n=e.readUint32();if(r===0){this.sample_sizes=e.readUint32Array(n)}else{this.sample_sizes=[];for(t=0;t<n;t++){this.sample_sizes[t]=r}}}else{this.data=e.readUint8Array(this.size)}};a.stszBox.prototype.unpack=function(e){var t;for(t=0;t<this.sample_sizes.length;t++){e[t].size=this.sample_sizes[t]}};a.mehdBox.prototype.parse=function(e){this.parseFullHeader(e);if(this.version==1){this.fragment_duration=e.readUint64()}else{this.fragment_duration=e.readUint32()}};a.trexBox.prototype.parse=function(e){this.parseFullHeader(e);this.track_id=e.readUint32();this.default_sample_description_index=e.readUint32();this.default_sample_duration=e.readUint32();this.default_sample_size=e.readUint32();this.default_sample_flags=e.readUint32()};a.mfhdBox.prototype.parse=function(e){this.parseFullHeader(e);this.sequence_number=e.readUint32()};a.TFHD_FLAG_BASE_DATA_OFFSET=1;a.TFHD_FLAG_SAMPLE_DESC=2;a.TFHD_FLAG_SAMPLE_DUR=8;a.TFHD_FLAG_SAMPLE_SIZE=16;a.TFHD_FLAG_SAMPLE_FLAGS=32;a.TFHD_FLAG_DUR_EMPTY=65536;a.TFHD_FLAG_DEFAULT_BASE_IS_MOOF=131072;a.tfhdBox.prototype.parse=function(e){var t=0;this.parseFullHeader(e);this.track_id=e.readUint32();if(this.size>t&&this.flags&a.TFHD_FLAG_BASE_DATA_OFFSET){this.base_data_offset=e.readUint64();t+=8}else{this.base_data_offset=0}if(this.size>t&&this.flags&a.TFHD_FLAG_SAMPLE_DESC){this.default_sample_description_index=e.readUint32();t+=4}else{this.default_sample_description_index=0}if(this.size>t&&this.flags&a.TFHD_FLAG_SAMPLE_DUR){this.default_sample_duration=e.readUint32();t+=4}else{this.default_sample_duration=0}if(this.size>t&&this.flags&a.TFHD_FLAG_SAMPLE_SIZE){this.default_sample_size=e.readUint32();t+=4}else{this.default_sample_size=0}if(this.size>t&&this.flags&a.TFHD_FLAG_SAMPLE_FLAGS){this.default_sample_flags=e.readUint32();t+=4}else{this.default_sample_flags=0}};a.TRUN_FLAGS_DATA_OFFSET=1;a.TRUN_FLAGS_FIRST_FLAG=4;a.TRUN_FLAGS_DURATION=256;a.TRUN_FLAGS_SIZE=512;a.TRUN_FLAGS_FLAGS=1024;a.TRUN_FLAGS_CTS_OFFSET=2048;a.trunBox.prototype.parse=function(e){var t=0;this.parseFullHeader(e);this.sample_count=e.readUint32();t+=4;if(this.size>t&&this.flags&a.TRUN_FLAGS_DATA_OFFSET){this.data_offset=e.readInt32();t+=4}else{this.data_offset=0}if(this.size>t&&this.flags&a.TRUN_FLAGS_FIRST_FLAG){this.first_sample_flags=e.readUint32();t+=4}else{this.first_sample_flags=0}this.sample_duration=[];this.sample_size=[];this.sample_flags=[];this.sample_composition_time_offset=[];if(this.size>t){for(var r=0;r<this.sample_count;r++){if(this.flags&a.TRUN_FLAGS_DURATION){this.sample_duration[r]=e.readUint32()}if(this.flags&a.TRUN_FLAGS_SIZE){this.sample_size[r]=e.readUint32()}if(this.flags&a.TRUN_FLAGS_FLAGS){this.sample_flags[r]=e.readUint32()}if(this.flags&a.TRUN_FLAGS_CTS_OFFSET){if(this.version===0){this.sample_composition_time_offset[r]=e.readUint32()}else{this.sample_composition_time_offset[r]=e.readInt32()}}}}};a.tfdtBox.prototype.parse=function(e){this.parseFullHeader(e);if(this.version==1){this.baseMediaDecodeTime=e.readUint64()}else{this.baseMediaDecodeTime=e.readUint32()}};a.paylBox.prototype.parse=function(e){this.text=e.readString(this.size)};a.subsBox.prototype.parse=function(e){var t,r;var n;var i;this.parseFullHeader(e);n=e.readUint32();this.samples=[];for(t=0;t<n;t++){var s={};this.samples[t]=s;s.sample_delta=e.readUint32();s.subsamples=[];i=e.readUint16();if(i>0){for(r=0;r<i;r++){var o={};s.subsamples.push(o);if(this.version==1){o.size=e.readUint32()}else{o.size=e.readUint16()}o.priority=e.readUint8();o.discardable=e.readUint8();o.reserved=e.readUint32()}}}};a.Box.prototype.writeHeader=function(e,t){this.size+=8;if(this.size>n.MAX_SIZE){this.size+=8}o.d("BoxWriter","Writing box "+this.type+" of size: "+this.size+" at position "+e.position+(t||""));if(this.size>n.MAX_SIZE){e.writeUint32(1)}else{this.sizePosition=e.position;e.writeUint32(this.size)}e.writeString(this.type,null,4);if(this.size>n.MAX_SIZE){e.writeUint64(this.size)}};a.FullBox.prototype.writeHeader=function(e){this.size+=4;a.Box.prototype.writeHeader.call(this,e," v="+this.version+" f="+this.flags);e.writeUint8(this.version);e.writeUint24(this.flags)};a.Box.prototype.write=function(e){if(this.type==="mdat"){if(this.data){this.size=this.data.length;this.writeHeader(e);e.writeUint8Array(this.data)}}else{this.size=this.data.length;this.writeHeader(e);e.writeUint8Array(this.data)}};a.ContainerBox.prototype.write=function(e){this.size=0;this.writeHeader(e);for(var t=0;t<this.boxes.length;t++){if(this.boxes[t]){this.boxes[t].write(e);this.size+=this.boxes[t].size}}o.d("BoxWriter","Adjusting box "+this.type+" with new size "+this.size);e.adjustUint32(this.sizePosition,this.size)};a.TrackReferenceTypeBox.prototype.write=function(e){this.size=this.track_ids.length*4;this.writeHeader(e);e.writeUint32Array(this.track_ids)};a.ftypBox.prototype.write=function(e){this.size=8+4*this.compatible_brands.length;this.writeHeader(e);e.writeString(this.major_brand,null,4);e.writeUint32(this.minor_version);for(var t=0;t<this.compatible_brands.length;t++){e.writeString(this.compatible_brands[t],null,4)}};a.mvhdBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=23*4+2*2;this.writeHeader(e);e.writeUint32(this.creation_time);e.writeUint32(this.modification_time);e.writeUint32(this.timescale);e.writeUint32(this.duration);e.writeUint32(this.rate);e.writeUint16(this.volume<<8);e.writeUint16(0);e.writeUint32(0);e.writeUint32(0);e.writeUint32Array(this.matrix);e.writeUint32(0);e.writeUint32(0);e.writeUint32(0);e.writeUint32(0);e.writeUint32(0);e.writeUint32(0);e.writeUint32(this.next_track_id)};a.tkhdBox.prototype.write=function(e){this.version=0;this.size=4*18+2*4;this.writeHeader(e);e.writeUint32(this.creation_time);e.writeUint32(this.modification_time);e.writeUint32(this.track_id);e.writeUint32(0);e.writeUint32(this.duration);e.writeUint32(0);e.writeUint32(0);e.writeInt16(this.layer);e.writeInt16(this.alternate_group);e.writeInt16(this.volume<<8);e.writeUint16(0);e.writeInt32Array(this.matrix);e.writeUint32(this.width);e.writeUint32(this.height)};a.mdhdBox.prototype.write=function(e){this.size=4*4+2*2;this.flags=0;this.version=0;this.writeHeader(e);e.writeUint32(this.creation_time);e.writeUint32(this.modification_time);e.writeUint32(this.timescale);e.writeUint32(this.duration);e.writeUint16(this.language);e.writeUint16(0)};a.hdlrBox.prototype.write=function(e){this.size=5*4+this.name.length+1;this.version=0;this.flags=0;this.writeHeader(e);e.writeUint32(0);e.writeString(this.handler,null,4);e.writeUint32(0);e.writeUint32(0);e.writeUint32(0);e.writeCString(this.name)};a.stsdBox.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=0;this.writeHeader(e);e.writeUint32(this.entries.length);this.size+=4;for(t=0;t<this.entries.length;t++){this.entries[t].write(e);this.size+=this.entries[t].size}o.d("BoxWriter","Adjusting box "+this.type+" with new size "+this.size);e.adjustUint32(this.sizePosition,this.size)};a.SampleEntry.prototype.writeHeader=function(e){this.size=8;a.Box.prototype.writeHeader.call(this,e);e.writeUint8(0);e.writeUint8(0);e.writeUint8(0);e.writeUint8(0);e.writeUint8(0);e.writeUint8(0);e.writeUint16(this.data_reference_index)};a.SampleEntry.prototype.writeFooter=function(e){for(var t=0;t<this.boxes.length;t++){this.boxes[t].write(e);this.size+=this.boxes[t].size}o.d("BoxWriter","Adjusting box "+this.type+" with new size "+this.size);e.adjustUint32(this.sizePosition,this.size)};a.SampleEntry.prototype.write=function(e){this.writeHeader(e);
+this.writeFooter(e)};a.VisualSampleEntry.prototype.write=function(e){this.writeHeader(e);this.size+=2*7+6*4+32;e.writeUint16(0);e.writeUint16(0);e.writeUint32(0);e.writeUint32(0);e.writeUint32(0);e.writeUint16(this.width-this.width%2);e.writeUint16(this.height-this.height%2);e.writeUint32(this.horizresolution);e.writeUint32(this.vertresolution);e.writeUint32(0);e.writeUint16(this.frame_count);e.writeString(this.compressorname,null,32);e.writeUint16(this.depth);e.writeInt16(-1);this.writeFooter(e)};a.AudioSampleEntry.prototype.write=function(e){this.writeHeader(e);this.size+=2*4+3*4;e.writeUint32(0);e.writeUint32(0);e.writeUint16(this.channel_count);e.writeUint16(this.samplesize);e.writeUint16(0);e.writeUint16(0);e.writeUint32(this.samplerate<<16);this.writeFooter(e)};a.avcCBox.prototype.write=function(e){var t;this.size=7;for(t=0;t<this.SPS.length;t++){this.size+=2+this.SPS[t].length}for(t=0;t<this.PPS.length;t++){this.size+=2+this.PPS[t].length}if(this.ext){this.size+=this.ext.length}this.writeHeader(e);e.writeUint8(this.configurationVersion);e.writeUint8(this.AVCProfileIndication);e.writeUint8(this.profile_compatibility);e.writeUint8(this.AVCLevelIndication);e.writeUint8(this.lengthSizeMinusOne+(63<<2));e.writeUint8(this.SPS.length+(7<<5));for(t=0;t<this.SPS.length;t++){e.writeUint16(this.SPS[t].length);e.writeUint8Array(this.SPS[t])}e.writeUint8(this.PPS.length);for(t=0;t<this.PPS.length;t++){e.writeUint16(this.PPS[t].length);e.writeUint8Array(this.PPS[t])}if(this.ext){e.writeUint8Array(this.ext)}};a.cttsBox.prototype.write=function(e){var t;this.version=1;this.flags=0;this.size=4+8*this.sample_counts.length;this.writeHeader(e);e.writeUint32(this.sample_counts.length);for(t=0;t<this.sample_counts.length;t++){e.writeUint32(this.sample_counts[t]);e.writeInt32(this.sample_offsets[t])}};a.cslgBox.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=4*5;this.writeHeader(e);e.writeInt32(this.compositionToDTSShift);e.writeInt32(this.leastDecodeToDisplayDelta);e.writeInt32(this.greatestDecodeToDisplayDelta);e.writeInt32(this.compositionStartTime);e.writeInt32(this.compositionEndTime)};a.sttsBox.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=4+8*this.sample_counts.length;this.writeHeader(e);e.writeUint32(this.sample_counts.length);for(t=0;t<this.sample_counts.length;t++){e.writeUint32(this.sample_counts[t]);e.writeUint32(this.sample_deltas[t])}};a.stssBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=4+4*this.sample_numbers.length;this.writeHeader(e);e.writeUint32(this.sample_numbers.length);e.writeUint32Array(this.sample_numbers)};a.stshBox.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=4+8*this.shadowed_sample_numbers.length;this.writeHeader(e);e.writeUint32(this.shadowed_sample_numbers.length);for(t=0;t<this.shadowed_sample_numbers.length;t++){e.writeUint32(this.shadowed_sample_numbers[t]);e.writeUint32(this.sync_sample_numbers[t])}};a.stcoBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=4+4*this.chunk_offsets.length;this.writeHeader(e);e.writeUint32(this.chunk_offsets.length);e.writeUint32Array(this.chunk_offsets)};a.co64Box.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=4+8*this.chunk_offsets.length;this.writeHeader(e);e.writeUint32(this.chunk_offsets.length);for(t=0;t<this.chunk_offsets.length;t++){e.writeUint64(this.chunk_offsets[t])}};a.stscBox.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=4+12*this.first_chunk.length;this.writeHeader(e);e.writeUint32(this.first_chunk.length);for(t=0;t<this.first_chunk.length;t++){e.writeUint32(this.first_chunk[t]);e.writeUint32(this.samples_per_chunk[t]);e.writeUint32(this.sample_description_index[t])}};a.stszBox.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=8+12*this.sample_sizes.length;this.writeHeader(e);e.writeUint32(0);e.writeUint32(this.sample_sizes.length);e.writeUint32Array(this.sample_sizes)};a.mehdBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=4;this.writeHeader(e);e.writeUint32(this.fragment_duration)};a.trexBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=4*5;this.writeHeader(e);e.writeUint32(this.track_id);e.writeUint32(this.default_sample_description_index);e.writeUint32(this.default_sample_duration);e.writeUint32(this.default_sample_size);e.writeUint32(this.default_sample_flags)};a.mfhdBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=4;this.writeHeader(e);e.writeUint32(this.sequence_number)};a.tfhdBox.prototype.write=function(e){this.version=0;this.size=4;if(this.flags&a.TFHD_FLAG_BASE_OFFSET){this.size+=8}if(this.flags&a.TFHD_FLAG_SAMPLE_DESC){this.size+=4}if(this.flags&a.TFHD_FLAG_SAMPLE_DUR){this.size+=4}if(this.flags&a.TFHD_FLAG_SAMPLE_SIZE){this.size+=4}if(this.flags&a.TFHD_FLAG_SAMPLE_FLAGS){this.size+=4}this.writeHeader(e);e.writeUint32(this.track_id);if(this.flags&a.TFHD_FLAG_BASE_OFFSET){e.writeUint64(this.base_data_offset)}if(this.flags&a.TFHD_FLAG_SAMPLE_DESC){e.writeUint32(this.default_sample_description_index)}if(this.flags&a.TFHD_FLAG_SAMPLE_DUR){e.writeUint32(this.default_sample_duration)}if(this.flags&a.TFHD_FLAG_SAMPLE_SIZE){e.writeUint32(this.default_sample_size)}if(this.flags&a.TFHD_FLAG_SAMPLE_FLAGS){e.writeUint32(this.default_sample_flags)}};a.trunBox.prototype.write=function(e){this.version=0;this.size=4;if(this.flags&a.TRUN_FLAGS_DATA_OFFSET){this.size+=4}if(this.flags&a.TRUN_FLAGS_FIRST_FLAG){this.size+=4}if(this.flags&a.TRUN_FLAGS_DURATION){this.size+=4*this.sample_duration.length}if(this.flags&a.TRUN_FLAGS_SIZE){this.size+=4*this.sample_size.length}if(this.flags&a.TRUN_FLAGS_FLAGS){this.size+=4*this.sample_flags.length}if(this.flags&a.TRUN_FLAGS_CTS_OFFSET){this.size+=4*this.sample_composition_time_offset.length}this.writeHeader(e);e.writeUint32(this.sample_count);if(this.flags&a.TRUN_FLAGS_DATA_OFFSET){this.data_offset_position=e.position;e.writeInt32(this.data_offset)}if(this.flags&a.TRUN_FLAGS_FIRST_FLAG){e.writeUint32(this.first_sample_flags)}for(var t=0;t<this.sample_count;t++){if(this.flags&a.TRUN_FLAGS_DURATION){e.writeUint32(this.sample_duration[t])}if(this.flags&a.TRUN_FLAGS_SIZE){e.writeUint32(this.sample_size[t])}if(this.flags&a.TRUN_FLAGS_FLAGS){e.writeUint32(this.sample_flags[t])}if(this.flags&a.TRUN_FLAGS_CTS_OFFSET){if(this.version===0){e.writeUint32(this.sample_composition_time_offset[t])}else{e.writeInt32(this.sample_composition_time_offset[t])}}}};a.tfdtBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=4;this.writeHeader(e);if(this.version==1){e.writeUint64(this.baseMediaDecodeTime)}else{e.writeUint32(this.baseMediaDecodeTime)}}},{"./DataStream":160,"./descriptor":162,"./log":164}],162:[function(e,t,r){var n=e("./log");var i=function(){var e=3;var t=4;var r=5;var i=6;var s=[];s[e]="ES_Descriptor";s[t]="DecoderConfigDescriptor";s[r]="DecoderSpecificInfo";s[i]="SLConfigDescriptor";var o=this;var a={};this.parseOneDescriptor=function(e){var t=0;var r=0;var i;var o;var f;i=e.readUint8();t++;f=e.readUint8();t++;while(f&128){r=(f&127)<<7;f=e.readUint8();t++}r+=f&127;n.d("MPEG4DescriptorParser","Found "+(s[i]|"Descriptor "+i)+", size "+r+" at position "+e.position);if(s[i]){o=new a[s[i]](r)}else{o=new a.Descriptor(r)}o.parse(e);return o};a.Descriptor=function(e,t){this.tag=e;this.size=t;this.descs=[]};a.Descriptor.prototype.parse=function(e){this.data=e.readUint8Array(this.size)};a.Descriptor.prototype.findDescriptor=function(e){for(var t=0;t<this.descs.length;t++){if(this.descs[t].tag==e){return this.descs[t]}}return null};a.Descriptor.prototype.parseRemainingDescriptors=function(e){var t=e.position;while(e.position<t+this.size){var r=o.parseOneDescriptor(e);this.descs.push(r)}};a.ES_Descriptor=function(t){a.Descriptor.call(this,e,t)};a.ES_Descriptor.prototype=new a.Descriptor;a.ES_Descriptor.prototype.parse=function(e){this.ES_ID=e.readUint16();this.flags=e.readUint8();this.size-=3;if(this.flags&128){this.dependsOn_ES_ID=e.readUint16();this.size-=2}else{this.dependsOn_ES_ID=0}if(this.flags&64){var t=e.readUint8();this.URL=e.readString(t);this.size-=t+1}else{this.URL=null}if(this.flags&32){this.OCR_ES_ID=e.readUint16();this.size-=2}else{this.OCR_ES_ID=0}this.parseRemainingDescriptors(e)};a.ES_Descriptor.prototype.getOTI=function(e){var r=this.findDescriptor(t);if(r){return r.oti}else{return 0}};a.ES_Descriptor.prototype.getAudioConfig=function(e){var n=this.findDescriptor(t);if(!n)return null;var i=n.findDescriptor(r);if(i&&i.data){return(i.data[0]&248)>>3}else{return null}};a.DecoderConfigDescriptor=function(e){a.Descriptor.call(this,t,e)};a.DecoderConfigDescriptor.prototype=new a.Descriptor;a.DecoderConfigDescriptor.prototype.parse=function(e){this.oti=e.readUint8();this.streamType=e.readUint8();this.bufferSize=e.readUint24();this.maxBitrate=e.readUint32();this.avgBitrate=e.readUint32();this.size-=13;this.parseRemainingDescriptors(e)};a.DecoderSpecificInfo=function(e){a.Descriptor.call(this,r,e)};a.DecoderSpecificInfo.prototype=new a.Descriptor;a.SLConfigDescriptor=function(e){a.Descriptor.call(this,i,e)};a.SLConfigDescriptor.prototype=new a.Descriptor;return this};t.exports=i},{"./log":164}],163:[function(e,t,r){var n=e("./box");var i=e("./DataStream");var s=e("./log");var o=function(e){this.stream=e;this.boxes=[];this.mdats=[];this.moofs=[];this.isProgressive=false;this.lastMoofIndex=0;this.lastBoxStartPosition=0;this.parsingMdat=null;this.moovStartFound=false;this.samplesDataSize=0;this.nextParsePosition=0};t.exports=o;o.prototype.mergeNextBuffer=function(){var e;if(this.stream.bufferIndex+1<this.stream.nextBuffers.length){e=this.stream.nextBuffers[this.stream.bufferIndex+1];if(e.fileStart===this.stream.buffer.fileStart+this.stream.buffer.byteLength){var t=this.stream.buffer.byteLength;var r=this.stream.buffer.usedBytes;var n=this.stream.buffer.fileStart;this.stream.nextBuffers[this.stream.bufferIndex]=ArrayBuffer.concat(this.stream.buffer,e);this.stream.buffer=this.stream.nextBuffers[this.stream.bufferIndex];this.stream.nextBuffers.splice(this.stream.bufferIndex+1,1);this.stream.buffer.usedBytes=r;this.stream.buffer.fileStart=n;s.d("ISOFile","Concatenating buffer for box parsing (length: "+t+"->"+this.stream.buffer.byteLength+")");return true}else{return false}}else{return false}};o.prototype.parse=function(){var e;var t;var r;s.d("ISOFile","Starting parsing with buffer #"+this.stream.bufferIndex+" (fileStart: "+this.stream.buffer.fileStart+" - Length: "+this.stream.buffer.byteLength+") from position "+this.lastBoxStartPosition+" ("+(this.stream.buffer.fileStart+this.lastBoxStartPosition)+" in the file)");this.stream.seek(this.lastBoxStartPosition);while(true){if(this.parsingMdat!==null){r=this.parsingMdat;e=this.reposition(false,r.fileStart+r.hdr_size+r.size);if(e){s.d("ISOFile","Found 'mdat' end in buffer #"+this.stream.bufferIndex);this.parsingMdat=null;continue}else{this.nextParsePosition=this.findEndContiguousBuf(this.stream.bufferIndex);return}}else{this.lastBoxStartPosition=this.stream.position;t=n.parseOneBox(this.stream);if(t.code===n.ERR_NOT_ENOUGH_DATA){if(t.type==="mdat"){r=new n[t.type+"Box"](t.size-t.hdr_size);this.parsingMdat=r;this.mdats.push(r);r.fileStart=this.stream.buffer.fileStart+this.stream.position;r.hdr_size=t.hdr_size;this.stream.buffer.usedBytes+=t.hdr_size;e=this.reposition(false,r.fileStart+r.hdr_size+r.size);if(e){this.parsingMdat=null;continue}else{if(!this.moovStartFound){this.nextParsePosition=r.fileStart+r.size+r.hdr_size}else{this.nextParsePosition=this.findEndContiguousBuf(this.stream.bufferIndex)}return}}else{if(t.type==="moov"){this.moovStartFound=true;if(this.mdats.length===0){this.isProgressive=true}}else if(t.type==="free"){e=this.reposition(false,this.stream.buffer.fileStart+this.stream.position+t.size);if(e){continue}else{this.nextParsePosition=this.stream.buffer.fileStart+this.stream.position+t.size;return}}merged=this.mergeNextBuffer();if(merged){this.nextParsePosition=this.stream.buffer.fileStart+this.stream.buffer.byteLength;continue}else{if(!t.type){this.nextParsePosition=this.stream.buffer.fileStart+this.stream.buffer.byteLength}else{if(this.moovStartFound){this.nextParsePosition=this.stream.buffer.fileStart+this.stream.buffer.byteLength}else{this.nextParsePosition=this.stream.buffer.fileStart+this.stream.position+t.size}}return}}}else{r=t.box;this.boxes.push(r);switch(r.type){case"mdat":this.mdats.push(r);r.fileStart=this.stream.buffer.fileStart+r.start;break;case"moof":this.moofs.push(r);break;case"moov":this.moovStartFound=true;if(this.mdats.length===0){this.isProgressive=true}default:if(this[r.type]!==undefined){s.w("ISOFile","Duplicate Box of type: "+r.type+", overriding previous occurrence")}this[r.type]=r;break}if(r.type==="mdat"){this.stream.buffer.usedBytes+=r.hdr_size}else{this.stream.buffer.usedBytes+=t.size}}}}};o.prototype.reposition=function(e,t){var r;r=this.findPosition(e,t);if(r!==-1){this.stream.buffer=this.stream.nextBuffers[r];this.stream.bufferIndex=r;this.stream.position=t-this.stream.buffer.fileStart;s.d("ISOFile","Repositioning parser at buffer position: "+this.stream.position);return true}else{return false}};o.prototype.findPosition=function(e,t){var r;var n=null;var i=-1;if(e===true){r=0}else{r=this.stream.bufferIndex}while(r<this.stream.nextBuffers.length){n=this.stream.nextBuffers[r];if(n.fileStart<=t){i=r}else{break}r++}if(i!==-1){n=this.stream.nextBuffers[i];if(n.fileStart+n.byteLength>=t){s.d("ISOFile","Found position in existing buffer #"+i);return i}else{return-1}}else{return-1}};o.prototype.findEndContiguousBuf=function(e){var t;var r;var n;r=this.stream.nextBuffers[e];if(this.stream.nextBuffers.length>e+1){for(t=e+1;t<this.stream.nextBuffers.length;t++){n=this.stream.nextBuffers[t];if(n.fileStart===r.fileStart+r.byteLength){r=n}else{break}}}return r.fileStart+r.byteLength};o.prototype.write=function(e){for(var t=0;t<this.boxes.length;t++){this.boxes[t].write(e)}};o.prototype.writeInitializationSegment=function(e){var t;var r;var i;var o;var a;s.d("ISOFile","Generating initialization segment");this.ftyp.write(e);if(this.moov.mvex){this.initial_duration=this.moov.mvex.mehd.fragment_duration;r=-1;for(t=0;t<this.moov.boxes.length;t++){a=this.moov.boxes[t];if(a===this.moov.mvex){r=t}}if(r>-1){this.moov.boxes.splice(r,1)}this.moov.mvex=null}this.moov.mvex=new n.mvexBox;this.moov.boxes.push(this.moov.mvex);this.moov.mvex.mehd=new n.mehdBox;this.moov.mvex.boxes.push(this.moov.mvex.mehd);this.moov.mvex.mehd.fragment_duration=this.initial_duration;for(t=0;t<this.moov.traks.length;t++){if(this.moov.traks[t].ignore)continue;o=new n.trexBox;this.moov.mvex.boxes.push(o);o.track_id=this.moov.traks[t].tkhd.track_id;o.default_sample_description_index=1;o.default_sample_duration=this.moov.traks[t].samples.length>0?this.moov.traks[t].samples[0].duration:0;o.default_sample_size=0;o.default_sample_flags=1<<16}this.moov.write(e)};o.prototype.resetTables=function(){var e;var t,r,n,i,s,o,a,f;this.initial_duration=this.moov.mvhd.duration;this.moov.mvhd.duration=0;for(e=0;e<this.moov.traks.length;e++){t=this.moov.traks[e];t.tkhd.duration=0;t.mdia.mdhd.duration=0;r=t.mdia.minf.stbl.stco||t.mdia.minf.stbl.co64;r.chunk_offsets=[];n=t.mdia.minf.stbl.stsc;n.first_chunk=[];n.samples_per_chunk=[];n.sample_description_index=[];i=t.mdia.minf.stbl.stsz;i.sample_sizes=[];s=t.mdia.minf.stbl.stts;s.sample_counts=[];s.sample_deltas=[];o=t.mdia.minf.stbl.ctts;if(o){o.sample_counts=[];o.sample_offsets=[]}a=t.mdia.minf.stbl.stss;if(a){a.sample_numbers=new Uint32Array(0)}f=t.mdia.minf.stbl.sdtp;var u=t.mdia.minf.stbl.boxes.indexOf(f);if(u!=-1)t.mdia.minf.stbl.boxes[u]=null}};o.prototype.buildSampleLists=function(){var e,t,r;var n,i,s,o,a,f,u,h,l;var c,d,p,m,v;var g,y,_,b,w,S;this.originalMvex=this.moov.mvex;for(e=0;e<this.moov.traks.length;e++){n=this.moov.traks[e];n.samples=[];i=n.mdia.minf.stbl.stco||n.mdia.minf.stbl.co64;s=n.mdia.minf.stbl.stsc;o=n.mdia.minf.stbl.stsz;a=n.mdia.minf.stbl.stts;f=n.mdia.minf.stbl.ctts;u=n.mdia.minf.stbl.stss;h=n.mdia.minf.stbl.stsd;l=n.mdia.minf.stbl.subs;g=-1;y=-1;_=-1;b=-1;w=0;subs_entry_index=0;last_subs_sample_index=0;for(t=0;t<o.sample_sizes.length;t++){var x={};x.number=t;x.track_id=n.tkhd.track_id;x.timescale=n.mdia.mdhd.timescale;n.samples[t]=x;x.size=o.sample_sizes[t];if(t===0){d=1;c=0;x.chunk_index=d;x.chunk_run_index=c;v=s.samples_per_chunk[c];m=0;if(c+1<s.first_chunk.length){p=s.first_chunk[c+1]-1}else{p=Infinity}}else{if(t<v){x.chunk_index=d;x.chunk_run_index=c}else{d++;x.chunk_index=d;m=0;if(d<=p){}else{c++;if(c+1<s.first_chunk.length){p=s.first_chunk[c+1]-1}else{p=Infinity}}x.chunk_run_index=c;v+=s.samples_per_chunk[c]}}x.description=h.entries[s.sample_description_index[x.chunk_run_index]-1];x.offset=i.chunk_offsets[x.chunk_index-1]+m;m+=x.size;if(t>g){y++;if(g<0){g=0}g+=a.sample_counts[y]}if(t>0){n.samples[t-1].duration=a.sample_deltas[y];x.dts=n.samples[t-1].dts+n.samples[t-1].duration}else{x.dts=0}if(f){if(t>_){b++;_+=f.sample_counts[b]}x.cts=n.samples[t].dts+f.sample_offsets[b]}else{x.cts=x.dts}if(u){if(t==u.sample_numbers[w]-1){x.is_rap=true;w++}else{x.is_rap=false}}else{x.is_rap=true}if(l){if(l.samples[subs_entry_index].sample_delta+last_subs_sample_index==t){x.subsamples=l.samples[subs_entry_index].subsamples;last_subs_sample_index+=l.samples[subs_entry_index].sample_delta}}}if(t>0)n.samples[t-1].duration=n.mdia.mdhd.duration-n.samples[t-1].dts}};o.prototype.updateSampleLists=function(){var e,t,r;var i,s,o,a;var f;var u,h,l,c,d;var p;while(this.lastMoofIndex<this.moofs.length){u=this.moofs[this.lastMoofIndex];this.lastMoofIndex++;if(u.type=="moof"){h=u;for(e=0;e<h.trafs.length;e++){l=h.trafs[e];c=this.getTrackById(l.tfhd.track_id);d=this.getTrexById(l.tfhd.track_id);if(l.tfhd.flags&n.TFHD_FLAG_SAMPLE_DESC){i=l.tfhd.default_sample_description_index}else{i=d.default_sample_description_index}if(l.tfhd.flags&n.TFHD_FLAG_SAMPLE_DUR){s=l.tfhd.default_sample_duration}else{s=d.default_sample_duration}if(l.tfhd.flags&n.TFHD_FLAG_SAMPLE_SIZE){o=l.tfhd.default_sample_size}else{o=d.default_sample_size}if(l.tfhd.flags&n.TFHD_FLAG_SAMPLE_FLAGS){a=l.tfhd.default_sample_flags}else{a=d.default_sample_flags}for(t=0;t<l.truns.length;t++){var m=l.truns[t];for(r=0;r<m.sample_count;r++){p={};l.first_sample_index=c.samples.length;c.samples.push(p);p.track_id=c.tkhd.track_id;p.timescale=c.mdia.mdhd.timescale;p.description=c.mdia.minf.stbl.stsd.entries[i-1];p.size=o;if(m.flags&n.TRUN_FLAGS_SIZE){p.size=m.sample_size[r]}p.duration=s;if(m.flags&n.TRUN_FLAGS_DURATION){p.duration=m.sample_duration[r]}if(c.first_traf_merged||r>0){p.dts=c.samples[c.samples.length-2].dts+c.samples[c.samples.length-2].duration}else{if(l.tfdt){p.dts=l.tfdt.baseMediaDecodeTime}else{p.dts=0}c.first_traf_merged=true}p.cts=p.dts;if(m.flags&n.TRUN_FLAGS_CTS_OFFSET){p.cts=p.dts+m.sample_composition_time_offset[r]}sample_flags=a;if(m.flags&n.TRUN_FLAGS_FLAGS){sample_flags=m.sample_flags[r]}else if(r===0&&m.flags&n.TRUN_FLAGS_FIRST_FLAG){sample_flags=m.first_sample_flags}p.is_rap=sample_flags>>16&1?false:true;var v=l.tfhd.flags&n.TFHD_FLAG_BASE_DATA_OFFSET?true:false;var g=l.tfhd.flags&n.TFHD_FLAG_DEFAULT_BASE_IS_MOOF?true:false;var y=m.flags&n.TRUN_FLAGS_DATA_OFFSET?true:false;var _=0;if(!v){if(!g){if(t===0){_=h.fileStart}else{_=f}}else{_=h.fileStart}}else{_=l.tfhd.base_data_offset}if(t===0&&r===0){if(y){p.offset=_+m.data_offset}else{p.offset=_}}else{p.offset=f}f=p.offset+p.size}}if(l.subs){var b=l.first_sample_index;for(t=0;t<l.subs.samples.length;t++){b+=l.subs.samples[t].sample_delta;p=c.samples[b-1];p.subsamples=l.subs.samples[t].subsamples}}}}}};o.prototype.getCodecs=function(){var e;var t="";for(e=0;e<this.moov.traks.length;e++){var r=this.moov.traks[e];if(e>0){t+=","}t+=r.mdia.minf.stbl.stsd.entries[0].getCodec()}return t};o.prototype.getTrexById=function(e){var t;if(!this.originalMvex)return null;for(t=0;t<this.originalMvex.trexs.length;t++){var r=this.originalMvex.trexs[t];if(r.track_id==e)return r}return null};o.prototype.getTrackById=function(e){for(var t=0;t<this.moov.traks.length;t++){var r=this.moov.traks[t];if(r.tkhd.track_id==e)return r}return null};o.prototype.getSample=function(e,t){var r;var n;var o=e.samples[t];if(!this.moov){return null}if(!o.data){o.data=new Uint8Array(o.size);o.alreadyRead=0;this.samplesDataSize+=o.size;s.d("ISOFile","Allocating sample #"+t+" on track #"+e.tkhd.track_id+" of size "+o.size+" (total: "+this.samplesDataSize+")")}else if(o.alreadyRead==o.size){return o}for(n=0;n<this.stream.nextBuffers.length;n++){r=this.stream.nextBuffers[n];if(o.offset+o.alreadyRead>=r.fileStart&&o.offset+o.alreadyRead<r.fileStart+r.byteLength){var a=r.byteLength-(o.offset+o.alreadyRead-r.fileStart);if(o.size-o.alreadyRead<=a){s.d("ISOFile","Getting sample #"+t+" data (alreadyRead: "+o.alreadyRead+" offset: "+(o.offset+o.alreadyRead-r.fileStart)+" size: "+(o.size-o.alreadyRead)+")");i.memcpy(o.data.buffer,o.alreadyRead,r,o.offset+o.alreadyRead-r.fileStart,o.size-o.alreadyRead);o.alreadyRead=o.size;r.usedBytes+=o.size-o.alreadyRead;if(r.usedBytes===r.byteLength){this.stream.nextBuffers.splice(n,1);n--}return o}else{s.d("ISOFile","Getting sample data (alreadyRead: "+o.alreadyRead+" offset: "+(o.offset+o.alreadyRead-r.fileStart)+" size: "+a+")");i.memcpy(o.data.buffer,o.alreadyRead,r,o.offset+o.alreadyRead-r.fileStart,a);o.alreadyRead+=a;r.usedBytes+=a;if(r.usedBytes===r.byteLength){this.stream.nextBuffers.splice(n,1);n--}}}}return null};o.prototype.releaseSample=function(e,t){var r=e.samples[t];r.data=null;this.samplesDataSize-=r.size;return r.size}},{"./DataStream":160,"./box":161,"./log":164}],164:[function(e,t,r){var n=function(){var e=new Date;var t=4;var r=3;var i=2;var s=1;var o=t;var a={setLogLevel:function(e){if(e==this.d)o=s;else if(e==this.i)o=i;else if(e==this.w)o=r;else if(e==this.e)o=t;else o=t},d:function(t,r){if(s>=o){console.debug("["+n.getDurationString(new Date-e,1e3)+"]","["+t+"]",r)}},i:function(t,r){if(i>=o){console.info("["+n.getDurationString(new Date-e,1e3)+"]","["+t+"]",r)}},w:function(t,i){if(r>=o){console.warn("["+n.getDurationString(new Date-e,1e3)+"]","["+t+"]",i)}},e:function(r,i){if(t>=o){console.error("["+n.getDurationString(new Date-e,1e3)+"]","["+r+"]",i)}}};return a}();t.exports=n;n.getDurationString=function(e,t){function r(e,t){var r=""+e;var n=r.split(".");while(n[0].length<t){n[0]="0"+n[0]}return n.join(".")}var n=t||1;var i=e/n;var s=Math.floor(i/3600);i-=s*3600;var o=Math.floor(i/60);i-=o*60;var a=i*1e3;i=Math.floor(i);a-=i*1e3;a=Math.floor(a);return""+s+":"+r(o,2)+":"+r(i,2)+"."+r(a,3)};n.printRanges=function(e){var t=e.length;if(t>0){var r="";for(var i=0;i<t;i++){if(i>0)r+=",";r+="["+n.getDurationString(e.start(i))+","+n.getDurationString(e.end(i))+"]"}return r}else{return"(empty)"}}},{}],165:[function(e,t,r){var n=e("./box");var s=e("./DataStream");var o=e("./isofile");var a=e("./log");var f=function(){this.inputStream=null;this.nextBuffers=[];this.inputIsoFile=null;this.onMoovStart=null;this.moovStartSent=false;this.onReady=null;this.readySent=false;this.onSegment=null;this.onSamples=null;this.onError=null;this.sampleListBuilt=false;this.fragmentedTracks=[];this.extractedTracks=[];this.isFragmentationStarted=false;this.nextMoofNumber=0};t.exports=f;f.prototype.setSegmentOptions=function(e,t,r){var n=this.inputIsoFile.getTrackById(e);if(n){var i={};this.fragmentedTracks.push(i);i.id=e;i.user=t;i.trak=n;n.nextSample=0;i.segmentStream=null;i.nb_samples=1e3;i.rapAlignement=true;if(r){if(r.nbSamples)i.nb_samples=r.nbSamples;if(r.rapAlignement)i.rapAlignement=r.rapAlignement}}};f.prototype.unsetSegmentOptions=function(e){var t=-1;for(var r=0;r<this.fragmentedTracks.length;r++){var n=this.fragmentedTracks[r];if(n.id==e){t=r}}if(t>-1){this.fragmentedTracks.splice(t,1)}};f.prototype.setExtractionOptions=function(e,t,r){var n=this.inputIsoFile.getTrackById(e);if(n){var i={};this.extractedTracks.push(i);i.id=e;i.user=t;i.trak=n;n.nextSample=0;i.nb_samples=1e3;i.samples=[];if(r){if(r.nbSamples)i.nb_samples=r.nbSamples}}};f.prototype.unsetExtractionOptions=function(e){var t=-1;for(var r=0;r<this.extractedTracks.length;r++){var n=this.extractedTracks[r];if(n.id==e){t=r}}if(t>-1){this.extractedTracks.splice(t,1)}};f.prototype.createSingleSampleMoof=function(e){var t=new n.moofBox;var r=new n.mfhdBox;r.sequence_number=this.nextMoofNumber;this.nextMoofNumber++;t.boxes.push(r);var i=new n.trafBox;t.boxes.push(i);var s=new n.tfhdBox;i.boxes.push(s);s.track_id=e.track_id;s.flags=n.TFHD_FLAG_DEFAULT_BASE_IS_MOOF;var o=new n.tfdtBox;i.boxes.push(o);o.baseMediaDecodeTime=e.dts;var a=new n.trunBox;i.boxes.push(a);t.trun=a;a.flags=n.TRUN_FLAGS_DATA_OFFSET|n.TRUN_FLAGS_DURATION|n.TRUN_FLAGS_SIZE|n.TRUN_FLAGS_FLAGS|n.TRUN_FLAGS_CTS_OFFSET;a.data_offset=0;a.first_sample_flags=0;a.sample_count=1;a.sample_duration=[];a.sample_duration[0]=e.duration;a.sample_size=[];a.sample_size[0]=e.size;a.sample_flags=[];a.sample_flags[0]=0;a.sample_composition_time_offset=[];a.sample_composition_time_offset[0]=e.cts-e.dts;return t};f.prototype.createFragment=function(e,t,r,i){var o=this.inputIsoFile.getTrackById(t);var f=this.inputIsoFile.getSample(o,r);if(f==null){if(this.nextSeekPosition){this.nextSeekPosition=Math.min(o.samples[r].offset,this.nextSeekPosition)}else{this.nextSeekPosition=o.samples[r].offset}return null}var u=i||new s;u.endianness=s.BIG_ENDIAN;var h=this.createSingleSampleMoof(f);h.write(u);h.trun.data_offset=h.size+8;a.d("BoxWriter","Adjusting data_offset with new value "+h.trun.data_offset);u.adjustUint32(h.trun.data_offset_position,h.trun.data_offset);var l=new n.mdatBox;l.data=f.data;l.write(u);return u};ArrayBuffer.concat=function(e,t){a.d("ArrayBuffer","Trying to create a new buffer of size: "+(e.byteLength+t.byteLength));var r=new Uint8Array(e.byteLength+t.byteLength);r.set(new Uint8Array(e),0);r.set(new Uint8Array(t),e.byteLength);return r.buffer};f.prototype.reduceBuffer=function(e,t,r){var n;n=new Uint8Array(r);n.set(new Uint8Array(e,t,r));n.buffer.fileStart=e.fileStart+t;n.buffer.usedBytes=0;return n.buffer};f.prototype.insertBuffer=function(e){var t=true;for(var r=0;r<this.nextBuffers.length;r++){var n=this.nextBuffers[r];if(e.fileStart<=n.fileStart){if(e.fileStart===n.fileStart){if(e.byteLength>n.byteLength){this.nextBuffers.splice(r,1);r--;continue}else{a.w("MP4Box","Buffer (fileStart: "+e.fileStart+" - Length: "+e.byteLength+") already appended, ignoring")}}else{if(e.fileStart+e.byteLength<=n.fileStart){}else{e=this.reduceBuffer(e,0,n.fileStart-e.fileStart)}a.d("MP4Box","Appending new buffer (fileStart: "+e.fileStart+" - Length: "+e.byteLength+")");this.nextBuffers.splice(r,0,e);if(r===0&&this.inputStream!==null){this.inputStream.buffer=e}}t=false;break}else if(e.fileStart<n.fileStart+n.byteLength){var i=n.fileStart+n.byteLength-e.fileStart;var s=e.byteLength-i;if(s>0){e=this.reduceBuffer(e,i,s)}else{t=false;break}}}if(t){a.d("MP4Box","Appending new buffer (fileStart: "+e.fileStart+" - Length: "+e.byteLength+")");this.nextBuffers.push(e);if(r===0&&this.inputStream!==null){this.inputStream.buffer=e}}};f.prototype.processSamples=function(){var e;var t;if(this.isFragmentationStarted&&this.onSegment!==null){for(e=0;e<this.fragmentedTracks.length;e++){var r=this.fragmentedTracks[e];t=r.trak;while(t.nextSample<t.samples.length){a.d("MP4Box","Creating media fragment on track #"+r.id+" for sample "+t.nextSample);var n=this.createFragment(this.inputIsoFile,r.id,t.nextSample,r.segmentStream);if(n){r.segmentStream=n;t.nextSample++}else{break}if(t.nextSample%r.nb_samples===0||t.nextSample>=t.samples.length){a.i("MP4Box","Sending fragmented data on track #"+r.id+" for samples ["+(t.nextSample-r.nb_samples)+","+(t.nextSample-1)+"]");if(this.onSegment){this.onSegment(r.id,r.user,r.segmentStream.buffer,t.nextSample)}r.segmentStream=null;if(r!==this.fragmentedTracks[e]){break}}}}}if(this.onSamples!==null){for(e=0;e<this.extractedTracks.length;e++){var i=this.extractedTracks[e];t=i.trak;while(t.nextSample<t.samples.length){a.d("MP4Box","Exporting on track #"+i.id+" sample #"+t.nextSample);var s=this.inputIsoFile.getSample(t,t.nextSample);if(s){t.nextSample++;i.samples.push(s)}else{return}if(t.nextSample%i.nb_samples===0||t.nextSample>=t.samples.length){a.d("MP4Box","Sending samples on track #"+i.id+" for sample "+t.nextSample);if(this.onSamples){this.onSamples(i.id,i.user,i.samples)}i.samples=[];if(i!==this.extractedTracks[e]){break}}}}}};f.prototype.appendBuffer=function(e){var t;var r;if(e===null||e===undefined){throw"Buffer must be defined and non empty"}if(e.fileStart===undefined){throw"Buffer must have a fileStart property"}if(e.byteLength===0){a.w("MP4Box","Ignoring empty buffer (fileStart: "+e.fileStart+")");return}e.usedBytes=0;this.insertBuffer(e);if(!this.inputStream){if(this.nextBuffers.length>0){r=this.nextBuffers[0];if(r.fileStart===0){this.inputStream=new s(r,0,s.BIG_ENDIAN);this.inputStream.nextBuffers=this.nextBuffers;this.inputStream.bufferIndex=0}else{a.w("MP4Box","The first buffer should have a fileStart of 0");return}}else{a.w("MP4Box","No buffer to start parsing from");return}}if(!this.inputIsoFile){this.inputIsoFile=new o(this.inputStream)}this.inputIsoFile.parse();if(this.inputIsoFile.moovStartFound&&!this.moovStartSent){this.moovStartSent=true;if(this.onMoovStart)this.onMoovStart()}if(this.inputIsoFile.moov){if(!this.sampleListBuilt){this.inputIsoFile.buildSampleLists();this.sampleListBuilt=true}this.inputIsoFile.updateSampleLists();if(this.onReady&&!this.readySent){var n=this.getInfo();this.readySent=true;this.onReady(n)}this.processSamples();if(this.nextSeekPosition){t=this.nextSeekPosition;this.nextSeekPosition=undefined}else{t=this.inputIsoFile.nextParsePosition}var i=this.inputIsoFile.findPosition(true,t);if(i!==-1){t=this.inputIsoFile.findEndContiguousBuf(i)}a.i("MP4Box","Next buffer to fetch should have a fileStart position of "+t);return t}else{if(this.inputIsoFile!==null){return this.inputIsoFile.nextParsePosition}else{return 0}}};f.prototype.getInfo=function(){var e={};var t;var r;var n;var s=new Date(4,0,1,0,0,0,0).getTime();e.duration=this.inputIsoFile.moov.mvhd.duration;e.timescale=this.inputIsoFile.moov.mvhd.timescale;e.isFragmented=this.inputIsoFile.moov.mvex!=null;if(e.isFragmented&&this.inputIsoFile.moov.mvex.mehd){e.fragment_duration=this.inputIsoFile.moov.mvex.mehd.fragment_duration}else{e.fragment_duration=0}e.isProgressive=this.inputIsoFile.isProgressive;e.hasIOD=this.inputIsoFile.moov.iods!=null;e.brands=[];e.brands.push(this.inputIsoFile.ftyp.major_brand);e.brands=e.brands.concat(this.inputIsoFile.ftyp.compatible_brands);e.created=new Date(s+this.inputIsoFile.moov.mvhd.creation_time*1e3);e.modified=new Date(s+this.inputIsoFile.moov.mvhd.modification_time*1e3);e.tracks=[];e.audioTracks=[];e.videoTracks=[];e.subtitleTracks=[];e.metadataTracks=[];e.hintTracks=[];e.otherTracks=[];for(i=0;i<this.inputIsoFile.moov.traks.length;i++){t=this.inputIsoFile.moov.traks[i];n=t.mdia.minf.stbl.stsd.entries[0];r={};e.tracks.push(r);r.id=t.tkhd.track_id;r.references=[];if(t.tref){for(j=0;j<t.tref.boxes.length;j++){ref={};r.references.push(ref);ref.type=t.tref.boxes[j].type;ref.track_ids=t.tref.boxes[j].track_ids}}r.created=new Date(s+t.tkhd.creation_time*1e3);r.modified=new Date(s+t.tkhd.modification_time*1e3);r.movie_duration=t.tkhd.duration;r.layer=t.tkhd.layer;r.alternate_group=t.tkhd.alternate_group;r.volume=t.tkhd.volume;r.matrix=t.tkhd.matrix;r.track_width=t.tkhd.width/(1<<16);r.track_height=t.tkhd.height/(1<<16);r.timescale=t.mdia.mdhd.timescale;r.duration=t.mdia.mdhd.duration;r.codec=n.getCodec();r.language=t.mdia.mdhd.languageString;r.nb_samples=t.samples.length;r.size=0;for(j=0;j<r.nb_samples;j++){r.size+=t.samples[j].size}r.bitrate=r.size*8*r.timescale/r.duration;if(n.isAudio()){e.audioTracks.push(r);r.audio={};r.audio.sample_rate=n.getSampleRate();r.audio.channel_count=n.getChannelCount();r.audio.sample_size=n.getSampleSize()}else if(n.isVideo()){e.videoTracks.push(r);r.video={};r.video.width=n.getWidth();r.video.height=n.getHeight();
+}else if(n.isSubtitle()){e.subtitleTracks.push(r)}else if(n.isHint()){e.hintTracks.push(r)}else if(n.isMetadata()){e.metadataTracks.push(r)}else{e.otherTracks.push(r)}}return e};f.prototype.getInitializationSegment=function(){var e=new s;e.endianness=s.BIG_ENDIAN;this.inputIsoFile.writeInitializationSegment(e);return e.buffer};f.prototype.writeFile=function(){var e=new s;e.endianness=s.BIG_ENDIAN;this.inputIsoFile.write(e);return e.buffer};f.prototype.initializeSegmentation=function(){var e;var t;var r;var n;var i;if(this.onSegment===null){a.w("MP4Box","No segmentation callback set!")}if(!this.isFragmentationStarted){this.isFragmentationStarted=true;this.nextMoofNumber=0;this.inputIsoFile.resetTables()}n=[];for(e=0;e<this.fragmentedTracks.length;e++){for(t=0;t<this.inputIsoFile.moov.boxes.length;t++){r=this.inputIsoFile.moov.boxes[t];if(r&&r.type==="trak"){this.inputIsoFile.moov.boxes[t].ignore=true;this.inputIsoFile.moov.boxes[t]=null}}i=this.inputIsoFile.getTrackById(this.fragmentedTracks[e].id);delete i.ignore;for(t=0;t<this.inputIsoFile.moov.boxes.length;t++){r=this.inputIsoFile.moov.boxes[t];if(r==null){this.inputIsoFile.moov.boxes[t]=i;break}}seg={};seg.id=i.tkhd.track_id;seg.user=this.fragmentedTracks[e].user;seg.buffer=this.getInitializationSegment();n.push(seg)}return n};f.prototype.releaseUsedSamples=function(e,t){var r=0;var n=this.inputIsoFile.getTrackById(e);if(!n.lastValidSample)n.lastValidSample=0;for(var i=n.lastValidSample;i<t;i++){r+=this.inputIsoFile.releaseSample(n,i)}a.d("MP4Box","Track #"+e+" released samples up to "+t+" (total size: "+r+", remaining: "+this.inputIsoFile.samplesDataSize+")");n.lastValidSample=t};f.prototype.flush=function(){a.i("MP4Box","Flushing remaining samples");this.inputIsoFile.updateSampleLists();this.processSamples()};f.prototype.seekTrack=function(e,t,r){var n;var i;var s=Infinity;var o=0;var f=Infinity;var u=0;var h=0;var l;for(n=0;n<r.samples.length;n++){i=r.samples[n];if(n===0){f=i.offset;h=0;l=i.timescale}else if(i.cts>e*i.timescale){f=r.samples[n-1].offset;h=n-1;break}if(t&&i.is_rap){s=i.offset;o=i.cts;u=n}}if(t){r.nextSample=u;a.i("MP4Box","Seeking to RAP sample #"+r.nextSample+" on track "+r.tkhd.track_id+", time "+a.getDurationString(o,l)+" and offset: "+s);return{offset:s,time:o/l}}else{r.nextSample=h;a.i("MP4Box","Seeking to non-RAP sample #"+r.nextSample+" on track "+r.tkhd.track_id+", time "+a.getDurationString(e)+" and offset: "+s);return{offset:f,time:e}}};f.prototype.seek=function(e,t){var r=this.inputIsoFile.moov;var n;var i;var s;var o={offset:Infinity,time:Infinity};if(!this.inputIsoFile.moov){throw"Cannot seek: moov not received!"}else{for(s=0;s<r.traks.length;s++){n=r.traks[s];i=this.seekTrack(e,t,n);if(i.offset<o.offset){o.offset=i.offset}if(i.time<o.time){o.time=i.time}}if(o.offset===Infinity){o={offset:this.inputIsoFile.nextParsePosition,time:0}}else{var f=this.inputIsoFile.findPosition(true,o.offset);if(f!==-1){o.offset=this.inputIsoFile.findEndContiguousBuf(f)}}a.i("MP4Box","Seeking at time "+a.getDurationString(o.time,1)+" needs a buffer with a fileStart position of "+o.offset);return o}}},{"./DataStream":160,"./box":161,"./isofile":163,"./log":164}],166:[function(e,t,r){var n=e("debug")("videostream");var i=e("mp4box");var s=.01;var o=60;t.exports=function(e,t,r){r=r||{};var f=r.debugTrack||-1;var u=[];function h(){t.addEventListener("waiting",S);t.addEventListener("timeupdate",E)}h();var l=false;function c(e){l=true;t.removeEventListener("waiting",S);t.removeEventListener("timeupdate",E);if(p.readyState==="open")p.endOfStream(e)}function d(e){var r=e.buffer.buffered;var i=t.currentTime;var a=-1;for(var f=0;f<r.length;f++){var u=r.start(f);var h=r.end(f)+s;if(u>i){break}else if(a>=0||i<=h){a=h}}var l=a-i;if(l<0)l=0;n("Buffer length: %f",l);return l<=o}var p=new MediaSource;p.addEventListener("sourceopen",function(){w(0)});t.src=window.URL.createObjectURL(p);var m=new i;m.onError=function(e){n("MP4Box error: %s",e.message);if(b){b()}if(p.readyState==="open"){c("decode")}};var v=false;var g={};m.onReady=function(e){n("MP4 info: %o",e);e.tracks.forEach(function(e){var t;if(e.video){t="video/mp4"}else if(e.audio){t="audio/mp4"}else{return}t+='; codecs="'+e.codec+'"';if(MediaSource.isTypeSupported(t)){var r=p.addSourceBuffer(t);var n={buffer:r,arrayBuffers:[],meta:e,ended:false};r.addEventListener("updateend",A.bind(null,n));m.setSegmentOptions(e.id,null,{nbSamples:e.video?1:100});g[e.id]=n}});if(Object.keys(g).length===0){c("decode");return}var t=m.initializeSegmentation();t.forEach(function(e){k(g[e.id],e.buffer);if(e.id===f){a("init-track-"+f+".mp4",[e.buffer]);u.push(e.buffer)}});v=true};m.onSegment=function(e,t,r,n){var i=g[e];k(i,r,n===i.meta.nb_samples);if(e===f&&u){u.push(r);if(n>1e3){a("track-"+f+".mp4",u);u=null}}};var y;var _=null;var b=null;function w(t){if(t===e.length){m.flush();return}if(_&&t===y){var r=_;setTimeout(function(){if(_===r)_.resume()});return}if(_){_.destroy();b()}y=t;var i={start:y,end:e.length-1};_=e.createReadStream(i);function s(e){_.pause();var t=e.toArrayBuffer();t.fileStart=y;y+=t.byteLength;var r;try{r=m.appendBuffer(t)}catch(i){n("MP4Box threw exception: %s",i.message);if(p.readyState==="open"){c("decode")}_.destroy();b();return}w(r)}_.on("data",s);function o(){b();w(y)}_.on("end",o);function a(e){n("Stream error: %s",e.message);if(p.readyState==="open"){c("network")}}_.on("error",a);b=function(){_.removeListener("data",s);_.removeListener("end",o);_.removeListener("error",a);_=null;b=null}}function S(){if(v){x(t.currentTime)}}function x(e){if(l)h();var t=m.seek(e,true);n("Seeking to time: %d",e);n("Seeked file offset: %d",t.offset);w(t.offset)}function k(e,t,r){e.arrayBuffers.push({buffer:t,ended:r||false});A(e)}function E(){Object.keys(g).forEach(function(e){var t=g[e];if(t.blocked){A(t)}})}function A(e){if(e.buffer.updating)return;e.blocked=!d(e);if(e.blocked)return;if(e.arrayBuffers.length===0)return;var t=e.arrayBuffers.shift();var r=false;try{e.buffer.appendBuffer(t.buffer);e.ended=t.ended;r=true}catch(i){n("SourceBuffer error: %s",i.message);c("decode");return}if(r){U()}}function U(){if(p.readyState!=="open"){return}var e=Object.keys(g).every(function(e){var t=g[e];return t.ended&&!t.buffer.updating});if(e){c()}}};function a(e,t){var r=new Blob(t);var n=URL.createObjectURL(r);var i=document.createElement("a");i.setAttribute("href",n);i.setAttribute("download",e);i.click()}},{debug:116,mp4box:165}],167:[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}},{}],168:[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}},{}],169:[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+""}},{}],170:[function(e,t,r){t.exports={name:"webtorrent",description:"Streaming torrent client",version:"0.65.0",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":"^5.0.0","bittorrent-swarm":"^6.0.0","chunk-store-stream":"^2.0.0",clivas:"^0.2.0","create-torrent":"^3.4.0","cross-spawn-async":"^2.0.0",debug:"^2.1.0","end-of-stream":"^1.0.0",executable:"^2.1.0","fs-chunk-store":"^1.3.4",hat:"0.0.3","immediate-chunk-store":"^1.0.7",inherits:"^2.0.1",inquirer:"^0.11.0","load-ip-set":"^1.0.3",mediasource:"^1.0.0","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":"^2.0.1",pump:"^1.0.0","random-iterate":"^1.0.1","range-parser":"^1.0.2","re-emitter":"^1.0.0","run-parallel":"^1.0.0","simple-sha1":"^2.0.0",speedometer:"^1.0.0",thunky:"^0.1.0","torrent-discovery":"^4.0.0","torrent-piece":"^1.0.0",uniq:"^1.0.1",ut_metadata:"^3.0.1",ut_pex:"^1.0.1",videostream:"^1.1.4","windows-no-runnable":"0.0.6",xtend:"^4.0.0","zero-fill":"^2.2.0"},devDependencies:{"bittorrent-tracker":"^6.0.0",brfs:"^1.2.0",browserify:"^12.0.1",finalhandler:"^0.4.0","run-series":"^1.0.2","serve-static":"^1.9.3","simple-get":"^1.0.0",standard:"^5.1.0",tape:"^4.0.0","uglify-js":"^2.4.15",zuul:"^3.0.0"},homepage:"http://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.5"},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/basic.js","test-browser-local":"zuul --local -- test/basic.js","test-node":"tape test/*.js"}}},{}],171:[function(e,t,r){(function(r,n,i){t.exports=S;var s=e("create-torrent");var o=e("debug")("webtorrent");var a=e("bittorrent-dht/client");var f=e("events").EventEmitter;var u=e("xtend");var h=e("hat");var l=e("inherits");var c=e("load-ip-set");var d=e("run-parallel");var p=e("parse-torrent");var m=e("path");var v=e("speedometer");var g=e("zero-fill");var y=e("./lib/torrent");l(S,f);var _=e("./package.json").version;var b=_.match(/([0-9]+)/g).slice(0,2).map(g(2)).join("");var w="-WW"+b+"-";function S(e){var t=this;if(!(t instanceof S))return new S(e);f.call(t);if(!e)e={};if(!o.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=v();t.uploadSpeed=v();t.peerId=typeof e.peerId==="string"?e.peerId:(e.peerId||new i(w+h(48))).toString("hex");t.peerIdBuffer=new i(t.peerId,"hex");t.nodeId=typeof e.nodeId==="string"?e.nodeId:e.nodeId&&e.nodeId.toString("hex")||h(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)}o("new webtorrent (peerId %s, nodeId %s)",t.peerId,t.nodeId);if(typeof c==="function"){c(e.blocklist,{headers:{"user-agent":"WebTorrent/"+_+" (http://webtorrent.io)"}},function(e,r){if(e)return t.error("Failed to load blocklist: "+e.message);t.blocked=r;s()})}else r.nextTick(s);function s(){if(t.destroyed)return;t.ready=true;t.emit("ready")}}Object.defineProperty(S.prototype,"ratio",{get:function(){var e=this;var t=e.torrents.reduce(function(e,t){return e+t.uploaded},0);var r=e.torrents.reduce(function(e,t){return e+t.downloaded},0)||1;return t/r}});S.prototype.get=function(e){var t=this;if(e instanceof y)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,s=t.torrents.length;i<s;i++){var o=t.torrents[i];if(o.infoHash===r.infoHash)return o}return null};S.prototype.add=S.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);o("add");if(!t)t={};else t=u(t);t.client=i;var s=i.get(e);function a(){if(typeof n==="function")n(s)}if(s){if(s.ready)r.nextTick(a);else s.on("ready",a)}else{s=new y(e,t);i.torrents.push(s);s.on("error",function(e){i.emit("error",e,s);i.remove(s)});s.on("listening",function(e){i.emit("listening",e,s)});s.on("ready",function(){a();i.emit("torrent",s)})}return s};S.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);o("seed");if(!t)t={};else t=u(t);if(typeof e==="string")t.path=m.dirname(e);if(!t.createdBy)t.createdBy="WebTorrent/"+b;if(!n.tracker)t.announce=[];var i;var a=n.add(undefined,t,function(e){var t=[function(t){e.load(i,t)}];if(n.dht){t.push(function(t){e.on("dhtAnnounce",t)})}d(t,function(t){if(t)return n.emit("error",t);f();n.emit("seed",e)})});s.parseInput(e,t,function(r,o){if(r)return n.emit("error",r);i=o.map(function(e){return e.getStream});s(e,t,function(e,t){if(e)return n.emit("error",e);if(n.destroyed)return;var r=n.get(t);if(r){a.destroy();f();return}else{a._onTorrentId(t)}})});function f(){o("on seed");if(typeof r==="function")r(a)}return a};S.prototype.remove=function(e,t){var r=this;o("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)};S.prototype.address=function(){var e=this;return{address:"0.0.0.0",family:"IPv4",port:e.torrentPort}};S.prototype.destroy=function(e){var t=this;if(t.destroyed)throw new Error("client already destroyed");t.destroyed=true;o("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)});d(r,e)}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{},e("buffer").Buffer)},{"./lib/torrent":8,"./package.json":170,_process:43,"bittorrent-dht/client":33,buffer:34,"create-torrent":84,debug:116,events:38,hat:122,inherits:124,"load-ip-set":33,"parse-torrent":128,path:42,"run-parallel":145,speedometer:151,xtend:167,"zero-fill":169}]},{},[171])(171)});