(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var t;if(typeof window!=="undefined"){t=window}else if(typeof global!=="undefined"){t=global}else if(typeof self!=="undefined"){t=self}else{t=this}t.WebTorrent=e()}})(function(){var e,t,r;return function n(e,t,r){function i(s,a){if(!t[s]){if(!e[s]){var f=typeof require=="function"&&require;if(!a&&f)return f(s,!0);if(o)return o(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var c=t[s]={exports:{}};e[s][0].call(c.exports,function(t){var r=e[s][1][t];return i(r?r:t)},c,c.exports,n,e,t,r)}return t[s].exports}var o=typeof require=="function"&&require;for(var s=0;s0){return r[Math.random()*r.length|0]}else{return-1}}},{}],4:[function(e,t,r){(function(r,n){t.exports=F;var i=e("addr-to-ip-port");var o=e("bitfield");var s=e("chunk-store-stream/write");var a=e("cpus");var f=e("create-torrent");var u=e("debug")("webtorrent:torrent");var c=e("torrent-discovery");var l=e("events").EventEmitter;var d=e("xtend/mutable");var h=e("fs-chunk-store");var p=e("immediate-chunk-store");var m=e("inherits");var v=e("multistream");var g=e("os");var y=e("run-parallel");var _=e("run-parallel-limit");var b=e("parse-torrent");var w=e("path");var E=e("path-exists");var x=e("torrent-piece");var k=e("pump");var S=e("random-iterate");var B=e("re-emitter");var I=e("simple-sha1");var A=e("bittorrent-swarm");var C=e("uniq");var T=e("ut_metadata");var L=e("ut_pex");var R=e("./file");var U=e("./rarity-map");var P=e("./server");var j=128*1024;var O=3e4;var M=5e3;var D=3*x.BLOCK_LENGTH;var N=.5;var H=1;var q=1e4;var z=2;var W=typeof E.sync==="function"?w.join(E.sync("/tmp")?"/tmp":g.tmpDir(),"webtorrent"):"/tmp/webtorrent";m(F,l);function F(e,t){l.call(this);if(!u.enabled)this.setMaxListeners(0);u("new torrent");this.client=t.client;this.announce=t.announce;this.urlList=t.urlList;this.path=t.path;this._store=t.store||h;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!=null)this._onTorrentId(e)}Object.defineProperty(F.prototype,"timeRemaining",{get:function(){if(this.done)return 0;if(!this.swarm||this.swarm.downloadSpeed()===0)return Infinity;return(this.length-this.downloaded)/this.swarm.downloadSpeed()*1e3}});Object.defineProperty(F.prototype,"downloaded",{get:function(){if(!this.bitfield)return 0;var e=0;for(var t=0,r=this.pieces.length;tt||e<0||t>=i.pieces.length){throw new Error("invalid selection ",e,":",t)}r=Number(r)||0;u("select %s-%s (priority %s)",e,t,r);i._selections.push({from:e,to:t,offset:0,priority:r,notify:n||$});i._selections.sort(function(e,t){return t.priority-e.priority});i._updateSelections()};F.prototype.deselect=function(e,t,r){var n=this;if(n.destroyed)throw new Error("torrent is destroyed");r=Number(r)||0;u("deselect %s-%s (priority %s)",e,t,r);for(var i=0;i65536)return u("ignoring invalid PORT from peer");u("port: %s (from %s)",t,e.remoteAddress+":"+e.remotePort);r.client.dht.addNode({host:e.remoteAddress,port:t})});e.port(r.client.dht.address().port)}e.on("timeout",function(){u("wire timeout (%s)",t);e.destroy()});e.setTimeout(O,true);e.setKeepAlive(true);e.use(T(r.metadata));e.ut_metadata.on("warning",function(e){u("ut_metadata warning: %s",e.message)});if(!r.metadata){e.ut_metadata.on("metadata",function(e){u("got metadata via ut_metadata");r._onMetadata(e)});e.ut_metadata.fetch()}if(typeof L==="function"&&!r.private){e.use(L());e.ut_pex.on("peer",function(e){u("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){u("ut_pex: dropped peer: %s (from %s)",e,t);r.swarm.removePeer(e)}})}r.emit("wire",e,t);if(r.metadata){r._onWireWithMetadata(e)}};F.prototype._onWireWithMetadata=function(e){var t=this;var r=null;function n(){if(t.destroyed||e.destroyed)return;if(t.swarm.numQueued>2*(t.swarm.numConns-t.swarm.numPeers)&&e.amInterested){e.destroy()}else{r=setTimeout(n,M);if(r.unref)r.unref()}}var i=0;function o(){if(e.peerPieces.length!==t.pieces.length)return;for(;ij){return e.destroy()}if(t.pieces[r])return;t.store.get(r,{offset:n,length:i},o)});e.bitfield(t.bitfield);e.interested();r=setTimeout(n,M);if(r.unref)r.unref();e.isSeeder=false;o()};F.prototype._updateSelections=function(){var e=this;if(!e.swarm||e.destroyed)return;if(!e.metadata)return e.once("metadata",e._updateSelections.bind(e));r.nextTick(e._gcSelections.bind(e));e._updateInterest();e._update()};F.prototype._gcSelections=function(){var e=this;for(var t=0;t=r)return;var n=Y(e,H);f(false)||f(true);function i(t,r,n,i){return function(o){return o>=t&&o<=r&&!(o in n)&&e.peerPieces.get(o)&&(!i||i(o))}}function o(){if(e.requests.length)return;var r=t._selections.length;while(r--){var n=t._selections[r];var o;if(t.strategy==="rarest"){var s=n.from+n.offset;var a=n.to;var f=a-s+1;var u={};var c=0;var l=i(s,a,u);while(c=n.from+n.offset;--o){if(!e.peerPieces.get(o))continue;if(t._request(e,o,false))return}}}}function s(){var r=e.downloadSpeed()||1;if(r>D)return function(){return true};var n=Math.max(1,e.requests.length)*x.BLOCK_LENGTH/r;var i=10;var o=0;return function(e){if(!i||t.bitfield.get(e))return true;var s=t.pieces[e].missing;for(;o0)continue;i--;return false}return true}}function a(e){var r=e;for(var n=e;n=n)return true;var o=s();for(var f=0;f0)e._rechokeOptimisticTime-=1;else e._rechokeOptimisticWire=null;var t=[];e.swarm.wires.forEach(function(r){if(!r.isSeeder&&r!==e._rechokeOptimisticWire){t.push({wire:r,downloadSpeed:r.downloadSpeed(),uploadSpeed:r.uploadSpeed(),salt:Math.random(),isChoked:true})}});t.sort(s);var r=0;var n=0;for(;n=D)continue;if(2*u>n||u>o)continue;s=f;o=u}if(!s)return false;for(a=0;a=s)return false;var a=i.pieces[t];var f=a.reserve();if(f===-1&&n&&i._hotswap(e,t)){f=a.reserve()}if(f===-1)return false;var c=i._reservations[t];if(!c)c=i._reservations[t]=[];var l=c.indexOf(null);if(l===-1)l=c.length;c[l]=e;var d=a.chunkOffset(f);var h=a.chunkLength(f);e.request(t,d,h,function m(r,n){if(!i.ready)return i.once("ready",function(){m(r,n)});if(c[l]===e)c[l]=null;if(a!==i.pieces[t])return p();if(r){u("error getting piece %s (offset: %s length: %s) from %s: %s",t,d,h,e.remoteAddress+":"+e.remotePort,r.message);a.cancel(f);p();return}u("got piece %s (offset: %s length: %s) from %s",t,d,h,e.remoteAddress+":"+e.remotePort);if(!a.set(f,n,e))return p();var o=a.flush();I(o,function(e){if(e===i._hashes[t]){if(!i.pieces[t])return;u("piece verified %s",t);i.pieces[t]=null;i._reservations[t]=null;i.bitfield.set(t,true);i.store.put(t,o);i.swarm.wires.forEach(function(e){e.have(t)});i._checkDone()}else{i.pieces[t]=new x(a.length);i.emit("warning",new Error("Piece "+t+" failed verification"))}p()})});function p(){r.nextTick(function(){i._update()})}return true};F.prototype._checkDone=function(){var e=this;if(e.destroyed)return;e.files.forEach(function(t){if(t.done)return;for(var r=t._startPiece;r<=t._endPiece;++r){if(!e.bitfield.get(r))return}t.done=true;t.emit("done");u("file done: "+t.name)});var t=true;for(var r=0;r>3;if(e%8!==0)t++;return t}n.prototype.get=function(e){var t=e>>3;return t>e%8)};n.prototype.set=function(e,t){var r=e>>3;if(t||arguments.length===1){if(this.buffer.length>e%8}else if(r>e%8)}};n.prototype._grow=function(e){if(this.buffer.length=e.maxConns){return}o("drain (%s queued, %s/%s peers)",e.numQueued,e.numPeers,e.maxConns);var t=e._queue.shift();if(!t)return;o("tcp connect attempt to %s",t.addr);var r=i(t.addr);var n={host:r[0],port:r[1]};if(e._hostname)n.localAddress=e._hostname;var s=t.conn=f.connect(n);s.once("connect",function(){t.onConnect()});s.once("error",function(e){t.destroy(e)});t.setConnectTimeout();s.on("close",function(){if(e.destroyed)return;if(t.retries>=h.length){o("conn %s closed: will not re-add (max %s attempts)",t.addr,h.length);return}var r=h[t.retries];o("conn %s closed: will re-add to queue in %sms (attempt %s)",t.addr,r,t.retries+1);var n=setTimeout(function i(){var r=e._addPeer(t.addr);if(r)r.retries=t.retries+1},r);if(n.unref)n.unref()})};p.prototype._onError=function(e){var t=this;t.emit("error",e);t.destroy()};p.prototype._validAddr=function(e){var t=this;var r=i(e);var n=r[0];var o=r[1];return o>0&&o<65535&&!(n==="127.0.0.1"&&o===t._port)}}).call(this,e("_process"),e("buffer").Buffer)},{"./lib/peer":8,"./lib/tcp-pool":24,_process:34,"addr-to-ip-port":24,buffer:25,debug:107,events:29,inherits:115,net:24,speedometer:195}],8:[function(e,t,r){var n=e("debug")("bittorrent-swarm:peer");var i=e("./webconn");var o=e("bittorrent-protocol");var s=25e3;var a=25e3;r.createWebRTCPeer=function(e,t){var r=new f(e.id);r.conn=e;r.swarm=t;if(r.conn.connected){r.onConnect()}else{r.conn.once("connect",function(){r.onConnect()});r.conn.once("error",function(e){r.destroy(e)});r.setConnectTimeout()}return r};r.createIncomingTCPPeer=function(e){var t=e.remoteAddress+":"+e.remotePort;var r=new f(t);r.conn=e;r.addr=t;r.onConnect();return r};r.createOutgoingTCPPeer=function(e,t){var r=new f(e);r.addr=e;r.swarm=t;return r};r.createWebPeer=function(e,t,r){var n=new f(e);n.swarm=r;n.conn=new i(e,t);n.onConnect();return n};function f(e){var t=this;t.id=e;n("new Peer %s",e);t.addr=null;t.conn=null;t.swarm=null;t.wire=null;t.connected=false;t.destroyed=false;t.timeout=null;t.retries=0;t.sentHandshake=false}f.prototype.onConnect=function(){var e=this;if(e.destroyed)return;e.connected=true;n("Peer %s connected",e.id);clearTimeout(e.connectTimeout);var t=e.conn;t.once("end",function(){e.destroy()});t.once("close",function(){e.destroy()});t.once("finish",function(){e.destroy()});t.once("error",function(t){e.destroy(t)});var r=e.wire=new o;r.once("end",function(){e.destroy()});r.once("close",function(){e.destroy()});r.once("finish",function(){e.destroy()});r.once("error",function(t){e.destroy(t)});r.once("handshake",function(t,r){e.onHandshake(t,r)});e.setHandshakeTimeout();t.pipe(r).pipe(t);if(e.swarm&&!e.sentHandshake)e.handshake()};f.prototype.onHandshake=function(e,t){var r=this;if(!r.swarm)return;if(r.swarm.destroyed)return r.destroy(new Error("swarm already destroyed"));if(e!==r.swarm.infoHash){return r.destroy(new Error("unexpected handshake info hash for this swarm"))}if(t===r.swarm.peerId){ return r.destroy(new Error("refusing to handshake with self"))}n("Peer %s got handshake %s",r.id,e);clearTimeout(r.handshakeTimeout);r.retries=0;r.wire.on("download",function(e){if(r.destroyed)return;r.swarm.downloaded+=e;r.swarm.downloadSpeed(e);r.swarm.emit("download",e)});r.wire.on("upload",function(e){if(r.destroyed)return;r.swarm.uploaded+=e;r.swarm.uploadSpeed(e);r.swarm.emit("upload",e)});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"))},s);if(e.connectTimeout.unref)e.connectTimeout.unref()};f.prototype.setHandshakeTimeout=function(){var e=this;clearTimeout(e.handshakeTimeout);e.handshakeTimeout=setTimeout(function(){e.destroy(new Error("handshake timeout"))},a);if(e.handshakeTimeout.unref)e.handshakeTimeout.unref()};f.prototype.destroy=function(e){var t=this;if(t.destroyed)return;t.destroyed=true;t.connected=false;n("destroy %s (error: %s)",t.id,e&&(e.message||e));clearTimeout(t.connectTimeout);clearTimeout(t.handshakeTimeout);var r=t.swarm;var i=t.conn;var o=t.wire;t.conn=null;t.swarm=null;t.wire=null;if(r&&o){var s=r.wires.indexOf(o);if(s>=0)r.wires.splice(s,1)}if(i)i.destroy();if(o)o.destroy();if(r)r.removePeer(t.id)}},{"./webconn":9,"bittorrent-protocol":10,debug:107}],9:[function(e,t,r){t.exports=u;var n=e("bitfield");var i=e("debug")("bittorrent-swarm:webconn");var o=e("simple-get");var s=e("inherits");var a=e("simple-sha1");var f=e("bittorrent-protocol");s(u,f);function u(e,t){var r=this;f.call(this);r.url=e;r.webPeerId=a.sync(e);r.parsedTorrent=t;r.setKeepAlive(true);r.on("handshake",function(e,t){r.handshake(e,r.webPeerId);var i=r.parsedTorrent.pieces.length;var o=new n(i);for(var s=0;s<=i;s++){o.set(s,true)}r.bitfield(o)});r.on("choke",function(){i("choke")});r.on("unchoke",function(){i("unchoke")});r.once("interested",function(){i("interested");r.unchoke()});r.on("uninterested",function(){i("uninterested")});r.on("bitfield",function(){i("bitfield")});r.on("request",function(e,t,n,o){i("request pieceIndex=%d offset=%d length=%d",e,t,n);r.httpRequest(e,t,n,o)})}u.prototype.httpRequest=function(e,t,r,n){var s=this;var a=e*s.parsedTorrent.pieceLength;var f=a+t;var u=f+r-1;i("Requesting pieceIndex=%d offset=%d length=%d start=%d end=%d",e,t,r,f,u);var c={url:s.url,method:"GET",headers:{"user-agent":"WebTorrent (http://webtorrent.io)",range:"bytes="+f+"-"+u}};o.concat(c,function(e,t,r){if(e)return n(e);if(r.statusCode<200||r.statusCode>=300){return n(new Error("Unexpected HTTP status code "+r.statusCode))}i("Got data of length %d",t.length);n(null,t)})}},{bitfield:6,"bittorrent-protocol":10,debug:107,inherits:115,"simple-get":185,"simple-sha1":193}],10:[function(e,t,r){(function(r){t.exports=w;var n=e("bencode");var i=e("bitfield");var o=e("debug")("bittorrent-protocol");var s=e("xtend");var a=e("hat");var f=e("inherits");var u=e("speedometer");var c=e("stream");var l=4e5;var d=new r("BitTorrent protocol");var h=new r([0,0,0,0]);var p=new r([0,0,0,1,0]);var m=new r([0,0,0,1,1]);var v=new r([0,0,0,1,2]);var g=new r([0,0,0,1,3]);var y=[0,0,0,0,0,0,0,0];var _=[0,0,0,3,9,0,0];function b(e,t,r,n){this.piece=e;this.offset=t;this.length=r;this.callback=n}f(w,c.Duplex);function w(){if(!(this instanceof w))return new w;c.Duplex.call(this);this._debugId=a(32);this._debug("new wire");this.peerId=null;this.peerIdBuffer=null;this.amChoking=true;this.amInterested=false;this.peerChoking=true;this.peerInterested=false;this.peerPieces=new i(0,{grow:l});this.peerExtensions={};this.requests=[];this.peerRequests=[];this.extendedMapping={};this.peerExtendedMapping={};this.extendedHandshake={};this.peerExtendedHandshake={};this._ext={};this._nextExt=1;this.uploaded=0;this.downloaded=0;this.uploadSpeed=u();this.downloadSpeed=u();this._keepAliveInterval=null;this._timeout=null;this._timeoutMs=0;this.destroyed=false;this._finished=false;this._buffer=[];this._bufferSize=0;this._parser=null;this._parserSize=0;this.on("finish",this._onfinish);this._parseHandshake()}w.prototype.setKeepAlive=function(e){this._debug("setKeepAlive %s",e);clearInterval(this._keepAliveInterval);if(e===false)return;this._keepAliveInterval=setInterval(this.keepAlive.bind(this),6e4)};w.prototype.setTimeout=function(e,t){this._debug("setTimeout ms=%d unref=%s",e,t);this._clearTimeout();this._timeoutMs=e;this._timeoutUnref=!!t;this._updateTimeout()};w.prototype.destroy=function(){if(this.destroyed)return;this.destroyed=true;this._debug("destroy");this.emit("close");this.end()};w.prototype.end=function(){this._debug("end");this._onUninterested();this._onChoke();c.Duplex.prototype.end.apply(this,arguments)};w.prototype.use=function(e){var t=e.prototype.name;if(!t){throw new Error('Extension class requires a "name" property on the prototype')}this._debug("use extension.name=%s",t);var r=this._nextExt;var n=new e(this);function i(){}if(typeof n.onHandshake!=="function"){n.onHandshake=i}if(typeof n.onExtendedHandshake!=="function"){n.onExtendedHandshake=i}if(typeof n.onMessage!=="function"){n.onMessage=i}this.extendedMapping[r]=t;this._ext[t]=n;this[t]=n;this._nextExt+=1};w.prototype.keepAlive=function(){this._debug("keep-alive");this._push(h)};w.prototype.handshake=function(e,t,n){var i,o;if(typeof e==="string"){i=new r(e,"hex")}else{i=e;e=i.toString("hex")}if(typeof t==="string"){o=new r(t,"hex")}else{o=t;t=o.toString("hex")}if(i.length!==20||o.length!==20){throw new Error("infoHash and peerId MUST have length 20")}this._debug("handshake i=%s p=%s exts=%o",e,t,n);var s=new r(y);s[5]|=16;if(n&&n.dht)s[7]|=1;this._push(r.concat([d,s,i,o]));this._handshakeSent=true;if(this.peerExtensions.extended){this._sendExtendedHandshake()}};w.prototype._sendExtendedHandshake=function(){var e=s(this.extendedHandshake);e.m={};for(var t in this.extendedMapping){var r=this.extendedMapping[t];e.m[r]=Number(t)}this.extended(0,n.encode(e))};w.prototype.choke=function(){if(this.amChoking)return;this.amChoking=true;this._debug("choke");this.peerRequests.splice(0,this.peerRequests.length);this._push(p)};w.prototype.unchoke=function(){if(!this.amChoking)return;this.amChoking=false;this._debug("unchoke");this._push(m)};w.prototype.interested=function(){if(this.amInterested)return;this.amInterested=true;this._debug("interested");this._push(v)};w.prototype.uninterested=function(){if(!this.amInterested)return;this.amInterested=false;this._debug("uninterested");this._push(g)};w.prototype.have=function(e){this._debug("have %d",e);this._message(4,[e],null)};w.prototype.bitfield=function(e){this._debug("bitfield");if(!r.isBuffer(e))e=e.buffer;this._message(5,[],e)};w.prototype.request=function(e,t,r,n){if(!n)n=function(){};if(this._finished)return n(new Error("wire is closed"));if(this.peerChoking)return n(new Error("peer is choking"));this._debug("request index=%d offset=%d length=%d",e,t,r);this.requests.push(new b(e,t,r,n));this._updateTimeout();this._message(6,[e,t,r],null)};w.prototype.piece=function(e,t,r){this._debug("piece index=%d offset=%d",e,t);this.uploaded+=r.length;this.uploadSpeed(r.length);this.emit("upload",r.length);this._message(7,[e,t],r)};w.prototype.cancel=function(e,t,r){this._debug("cancel index=%d offset=%d length=%d",e,t,r);this._callback(E(this.requests,e,t,r),new Error("request was cancelled"),null);this._message(8,[e,t,r],null)};w.prototype.port=function(e){this._debug("port %d",e);var t=new r(_);t.writeUInt16BE(e,5);this._push(t)};w.prototype.extended=function(e,t){this._debug("extended ext=%s",e);if(typeof e==="string"&&this.peerExtendedMapping[e]){e=this.peerExtendedMapping[e]}if(typeof e==="number"){var i=new r([e]);var o=r.isBuffer(t)?t:n.encode(t);this._message(20,[],r.concat([i,o]))}else{throw new Error("Unrecognized extension: "+e)}};w.prototype._onKeepAlive=function(){this._debug("got keep-alive");this.emit("keep-alive")};w.prototype._onHandshake=function(e,t,r){var n=e.toString("hex");var i=t.toString("hex");this._debug("got handshake i=%s p=%s exts=%o",n,i,r);this.peerId=i;this.peerIdBuffer=t;this.peerExtensions=r;this.emit("handshake",n,i,r);var o;for(o in this._ext){this._ext[o].onHandshake(n,i,r)}if(r.extended&&this._handshakeSent){this._sendExtendedHandshake()}};w.prototype._onChoke=function(){this.peerChoking=true;this._debug("got choke");this.emit("choke");while(this.requests.length){this._callback(this.requests.shift(),new Error("peer is choking"),null)}};w.prototype._onUnchoke=function(){this.peerChoking=false;this._debug("got unchoke");this.emit("unchoke")};w.prototype._onInterested=function(){this.peerInterested=true;this._debug("got interested");this.emit("interested")};w.prototype._onUninterested=function(){this.peerInterested=false;this._debug("got uninterested");this.emit("uninterested")};w.prototype._onHave=function(e){if(this.peerPieces.get(e))return;this._debug("got have %d",e);this.peerPieces.set(e,true);this.emit("have",e)};w.prototype._onBitField=function(e){this.peerPieces=new i(e);this._debug("got bitfield");this.emit("bitfield",this.peerPieces)};w.prototype._onRequest=function(e,t,r){if(this.amChoking)return;this._debug("got request index=%d offset=%d length=%d",e,t,r);var n=function(n,o){if(i!==E(this.peerRequests,e,t,r))return;if(n)return;this.piece(e,t,o)}.bind(this);var i=new b(e,t,r,n);this.peerRequests.push(i);this.emit("request",e,t,r,n)};w.prototype._onPiece=function(e,t,r){this._debug("got piece index=%d offset=%d",e,t);this._callback(E(this.requests,e,t,r.length),null,r);this.downloaded+=r.length;this.downloadSpeed(r.length);this.emit("download",r.length);this.emit("piece",e,t,r)};w.prototype._onCancel=function(e,t,r){this._debug("got cancel index=%d offset=%d length=%d",e,t,r);E(this.peerRequests,e,t,r);this.emit("cancel",e,t,r)};w.prototype._onPort=function(e){this._debug("got port %d",e);this.emit("port",e)};w.prototype._onExtended=function(e,t){if(e===0){var r;try{r=n.decode(t)}catch(i){this._debug("ignoring invalid extended handshake: %s",i.message||i)}if(!r)return;this.peerExtendedHandshake=r;var o;if(typeof r.m==="object"){for(o in r.m){this.peerExtendedMapping[o]=Number(r.m[o].toString())}}for(o in this._ext){if(this.peerExtendedMapping[o]){this._ext[o].onExtendedHandshake(this.peerExtendedHandshake)}}this._debug("got extended handshake");this.emit("extended","handshake",this.peerExtendedHandshake)}else{if(this.extendedMapping[e]){e=this.extendedMapping[e];if(this._ext[e]){this._ext[e].onMessage(t)}}this._debug("got extended message ext=%s",e);this.emit("extended",e,t)}};w.prototype._onTimeout=function(){this._debug("request timed out");this._callback(this.requests.shift(),new Error("request has timed out"),null);this.emit("timeout")};w.prototype._push=function(e){if(this._finished)return;return this.push(e)};w.prototype._write=function(e,t,n){this._bufferSize+=e.length;this._buffer.push(e);while(this._bufferSize>=this._parserSize){var i=this._buffer.length===1?this._buffer[0]:r.concat(this._buffer);this._bufferSize-=this._parserSize;this._buffer=this._bufferSize?[i.slice(this._parserSize)]:[];this._parser(i.slice(0,this._parserSize))}n(null)};w.prototype._read=function(){};w.prototype._callback=function(e,t,r){if(!e)return;this._clearTimeout();if(!this.peerChoking&&!this._finished)this._updateTimeout();e.callback(t,r)};w.prototype._clearTimeout=function(){if(!this._timeout)return;clearTimeout(this._timeout);this._timeout=null};w.prototype._updateTimeout=function(){if(!this._timeoutMs||!this.requests.length||this._timeout)return;this._timeout=setTimeout(this._onTimeout.bind(this),this._timeoutMs);if(this._timeoutUnref&&this._timeout.unref)this._timeout.unref()};w.prototype._parse=function(e,t){this._parserSize=e;this._parser=t};w.prototype._message=function(e,t,n){var i=n?n.length:0;var o=new r(5+4*t.length);o.writeUInt32BE(o.length+i-4,0);o[4]=e;for(var s=0;s0){this._parse(t,this._onmessage)}else{this._onKeepAlive();this._parse(4,this._onmessagelength)}};w.prototype._onmessage=function(e){this._parse(4,this._onmessagelength);switch(e[0]){case 0:return this._onChoke();case 1:return this._onUnchoke();case 2:return this._onInterested();case 3:return this._onUninterested();case 4:return this._onHave(e.readUInt32BE(1));case 5:return this._onBitField(e.slice(1));case 6:return this._onRequest(e.readUInt32BE(1),e.readUInt32BE(5),e.readUInt32BE(9));case 7:return this._onPiece(e.readUInt32BE(1),e.readUInt32BE(5),e.slice(9));case 8:return this._onCancel(e.readUInt32BE(1),e.readUInt32BE(5),e.readUInt32BE(9));case 9:return this._onPort(e.readUInt16BE(1));case 20:return this._onExtended(e.readUInt8(1),e.slice(2));default:this._debug("got unknown message");return this.emit("unknownmessage",e)}};w.prototype._parseHandshake=function(){this._parse(1,function(e){var t=e.readUInt8(0);this._parse(t+48,function(e){var r=e.slice(0,t);if(r.toString()!=="BitTorrent protocol"){this._debug("Error: wire not speaking BitTorrent protocol (%s)",r.toString());this.end();return}e=e.slice(t);this._onHandshake(e.slice(8,28),e.slice(28,48),{dht:!!(e[7]&1),extended:!!(e[5]&16)});this._parse(4,this._onmessagelength)}.bind(this))}.bind(this))};w.prototype._onfinish=function(){this._finished=true;this.push(null);while(this.read()){}clearInterval(this._keepAliveInterval);this._parse(Number.MAX_VALUE,function(){});this.peerRequests=[];while(this.requests.length){this._callback(this.requests.shift(),new Error("wire was closed"),null)}};w.prototype._debug=function(){var e=[].slice.call(arguments);e[0]="["+this._debugId+"] "+e[0];o.apply(null,e)};function E(e,t,r,n){for(var i=0;ii._maxBufferedAmount){n("start backpressure: bufferedAmount %d",i._ws.bufferedAmount);i._cb=r}else{r(null)}}else{n("write before connect");i._chunk=e;i._cb=r}};u.prototype._onMessage=function(e){var t=this;if(t.destroyed)return;var i=e.data;n("read: %d bytes",i.byteLength||i.length);if(i instanceof ArrayBuffer){i=new r(i);t.push(i)}else if(r.isBuffer(i)){t.push(i)}else{try{i=JSON.parse(i)}catch(o){}t.emit("data",i)}};u.prototype._onOpen=function(){var e=this;if(e.connected||e.destroyed)return;e.connected=true;if(e._chunk){try{e.send(e._chunk)}catch(t){return e._onError(t)}e._chunk=null;n('sent chunk from "write before connect"');var r=e._cb;e._cb=null;r(null)}if(typeof a!=="function"){e._interval=setInterval(function(){if(!e._cb||!e._ws||e._ws.bufferedAmount>e._maxBufferedAmount){return}n("ending backpressure: bufferedAmount %d",e._ws.bufferedAmount);var t=e._cb;e._cb=null;t(null)},150);if(e._interval.unref)e._interval.unref()}n("connect");e.emit("connect")};u.prototype._onClose=function(){var e=this;if(e.destroyed)return;n("on close");e._destroy()};u.prototype._onError=function(e){var t=this;if(t.destroyed)return;n("error: %s",e.message||e);t._destroy(e)}}).call(this,e("buffer").Buffer)},{buffer:25,debug:107,inherits:115,"is-typedarray":22,stream:52,ws:24}],22:[function(e,t,r){t.exports=o;o.strict=s;o.loose=a;var n=Object.prototype.toString;var i={"[object Int8Array]":true,"[object Int16Array]":true,"[object Int32Array]":true,"[object Uint8Array]":true,"[object Uint8ClampedArray]":true,"[object Uint16Array]":true,"[object Uint32Array]":true,"[object Float32Array]":true,"[object Float64Array]":true};function o(e){return s(e)||a(e)}function s(e){return e instanceof Int8Array||e instanceof Int16Array||e instanceof Int32Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Uint16Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array}function a(e){return i[n.call(e)]}},{}],23:[function(e,t,r){},{}],24:[function(e,t,r){arguments[4][23][0].apply(r,arguments)},{dup:23}],25:[function(e,t,r){(function(t){"use strict";var n=e("base64-js");var i=e("ieee754");var o=e("isarray");r.Buffer=u;r.SlowBuffer=w;r.INSPECT_MAX_BYTES=50;u.poolSize=8192;var s={};u.TYPED_ARRAY_SUPPORT=t.TYPED_ARRAY_SUPPORT!==undefined?t.TYPED_ARRAY_SUPPORT:a();function a(){try{var e=new Uint8Array(1);e.foo=function(){return 42};return e.foo()===42&&typeof e.subarray==="function"&&e.subarray(1,1).byteLength===0}catch(t){return false}}function f(){return u.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function u(e){if(!(this instanceof u)){if(arguments.length>1)return new u(e,arguments[1]); return new u(e)}if(!u.TYPED_ARRAY_SUPPORT){this.length=0;this.parent=undefined}if(typeof e==="number"){return c(this,e)}if(typeof e==="string"){return l(this,e,arguments.length>1?arguments[1]:"utf8")}return d(this,e)}u._augment=function(e){e.__proto__=u.prototype;return e};function c(e,t){e=_(e,t<0?0:b(t)|0);if(!u.TYPED_ARRAY_SUPPORT){for(var r=0;r>>1;if(r)e.parent=s;return e}function b(e){if(e>=f()){throw new RangeError("Attempt to allocate Buffer larger than maximum "+"size: 0x"+f().toString(16)+" bytes")}return e|0}function w(e,t){if(!(this instanceof w))return new w(e,t);var r=new u(e,t);delete r.parent;return r}u.isBuffer=function ee(e){return!!(e!=null&&e._isBuffer)};u.compare=function te(e,t){if(!u.isBuffer(e)||!u.isBuffer(t)){throw new TypeError("Arguments must be Buffers")}if(e===t)return 0;var r=e.length;var n=t.length;var i=0;var o=Math.min(r,n);while(i>>1;case"base64":return Z(e).length;default:if(n)return K(e).length;t=(""+t).toLowerCase();n=true}}}u.byteLength=E;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 j(this,t,r);case"base64":return T(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return M(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase();n=true}}}u.prototype._isBuffer=true;u.prototype.toString=function ie(){var e=this.length|0;if(e===0)return"";if(arguments.length===0)return L(this,0,e);return 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 se(){var e="";var t=r.INSPECT_MAX_BYTES;if(this.length>0){e=this.toString("hex",0,t).match(/.{2}/g).join(" ");if(this.length>t)e+=" ... "}return""};u.prototype.compare=function ae(e){if(!u.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(this===e)return 0;return u.compare(this,e)};u.prototype.indexOf=function fe(e,t){if(t>2147483647)t=2147483647;else if(t<-2147483648)t=-2147483648;t>>=0;if(this.length===0)return-1;if(t>=this.length)return-1;if(t<0)t=Math.max(this.length+t,0);if(typeof e==="string"){if(e.length===0)return-1;return String.prototype.indexOf.call(this,e,t)}if(u.isBuffer(e)){return r(this,e,t)}if(typeof e==="number"){if(u.TYPED_ARRAY_SUPPORT&&Uint8Array.prototype.indexOf==="function"){return Uint8Array.prototype.indexOf.call(this,e,t)}return r(this,[e],t)}function r(e,t,r){var n=-1;for(var i=0;r+ii){n=i}}var o=t.length;if(o%2!==0)throw new Error("Invalid hex string");if(n>o/2){n=o/2}for(var s=0;so)r=o;if(e.length>0&&(r<0||t<0)||t>this.length){throw new RangeError("attempt to write outside buffer bounds")}if(!n)n="utf8";var s=false;for(;;){switch(n){case"hex":return k(this,e,t,r);case"utf8":case"utf-8":return S(this,e,t,r);case"ascii":return B(this,e,t,r);case"binary":return I(this,e,t,r);case"base64":return A(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,e,t,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase();s=true}}};u.prototype.toJSON=function ce(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function T(e,t,r){if(t===0&&r===e.length){return n.fromByteArray(e)}else{return n.fromByteArray(e.slice(t,r))}}function L(e,t,r){r=Math.min(e.length,r);var n=[];var i=t;while(i239?4:o>223?3:o>191?2:1;if(i+a<=r){var f,u,c,l;switch(a){case 1:if(o<128){s=o}break;case 2:f=e[i+1];if((f&192)===128){l=(o&31)<<6|f&63;if(l>127){s=l}}break;case 3:f=e[i+1];u=e[i+2];if((f&192)===128&&(u&192)===128){l=(o&15)<<12|(f&63)<<6|u&63;if(l>2047&&(l<55296||l>57343)){s=l}}break;case 4:f=e[i+1];u=e[i+2];c=e[i+3];if((f&192)===128&&(u&192)===128&&(c&192)===128){l=(o&15)<<18|(f&63)<<12|(u&63)<<6|c&63;if(l>65535&&l<1114112){s=l}}}}if(s===null){s=65533;a=1}else if(s>65535){s-=65536;n.push(s>>>10&1023|55296);s=56320|s&1023}n.push(s);i+=a}return U(n)}var R=4096;function U(e){var t=e.length;if(t<=R){return String.fromCharCode.apply(String,e)}var r="";var n=0;while(nn)r=n;var i="";for(var o=t;or){e=r}if(t<0){t+=r;if(t<0)t=0}else if(t>r){t=r}if(tr)throw new RangeError("Trying to access beyond buffer length")}u.prototype.readUIntLE=function de(e,t,r){e=e|0;t=t|0;if(!r)D(e,t,this.length);var n=this[e];var i=1;var o=0;while(++o0&&(i*=256)){n+=this[e+--t]*i}return n};u.prototype.readUInt8=function pe(e,t){if(!t)D(e,1,this.length);return this[e]};u.prototype.readUInt16LE=function me(e,t){if(!t)D(e,2,this.length);return this[e]|this[e+1]<<8};u.prototype.readUInt16BE=function ve(e,t){if(!t)D(e,2,this.length);return this[e]<<8|this[e+1]};u.prototype.readUInt32LE=function ge(e,t){if(!t)D(e,4,this.length);return(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};u.prototype.readUInt32BE=function ye(e,t){if(!t)D(e,4,this.length);return this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};u.prototype.readIntLE=function _e(e,t,r){e=e|0;t=t|0;if(!r)D(e,t,this.length);var n=this[e];var i=1;var o=0;while(++o=i)n-=Math.pow(2,8*t);return n};u.prototype.readIntBE=function be(e,t,r){e=e|0;t=t|0;if(!r)D(e,t,this.length);var n=t;var i=1;var o=this[e+--n];while(n>0&&(i*=256)){o+=this[e+--n]*i}i*=128;if(o>=i)o-=Math.pow(2,8*t);return o};u.prototype.readInt8=function we(e,t){if(!t)D(e,1,this.length);if(!(this[e]&128))return this[e];return(255-this[e]+1)*-1};u.prototype.readInt16LE=function Ee(e,t){if(!t)D(e,2,this.length);var r=this[e]|this[e+1]<<8;return r&32768?r|4294901760:r};u.prototype.readInt16BE=function xe(e,t){if(!t)D(e,2,this.length);var r=this[e+1]|this[e]<<8;return r&32768?r|4294901760:r};u.prototype.readInt32LE=function ke(e,t){if(!t)D(e,4,this.length);return this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};u.prototype.readInt32BE=function Se(e,t){if(!t)D(e,4,this.length);return this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};u.prototype.readFloatLE=function Be(e,t){if(!t)D(e,4,this.length);return i.read(this,e,true,23,4)};u.prototype.readFloatBE=function Ie(e,t){if(!t)D(e,4,this.length);return i.read(this,e,false,23,4)};u.prototype.readDoubleLE=function Ae(e,t){if(!t)D(e,8,this.length);return i.read(this,e,true,52,8)};u.prototype.readDoubleBE=function Ce(e,t){if(!t)D(e,8,this.length);return i.read(this,e,false,52,8)};function N(e,t,r,n,i,o){if(!u.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");if(t>i||te.length)throw new RangeError("index out of range")}u.prototype.writeUIntLE=function Te(e,t,r,n){e=+e;t=t|0;r=r|0;if(!n)N(this,e,t,r,Math.pow(2,8*r),0);var i=1;var o=0;this[t]=e&255;while(++o=0&&(o*=256)){this[t+i]=e/o&255}return t+r};u.prototype.writeUInt8=function Re(e,t,r){e=+e;t=t|0;if(!r)N(this,e,t,1,255,0);if(!u.TYPED_ARRAY_SUPPORT)e=Math.floor(e);this[t]=e&255;return t+1};function H(e,t,r,n){if(t<0)t=65535+t+1;for(var i=0,o=Math.min(e.length-r,2);i>>(n?i:1-i)*8}}u.prototype.writeUInt16LE=function Ue(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{H(this,e,t,true)}return t+2};u.prototype.writeUInt16BE=function Pe(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{H(this,e,t,false)}return t+2};function q(e,t,r,n){if(t<0)t=4294967295+t+1;for(var i=0,o=Math.min(e.length-r,4);i>>(n?i:3-i)*8&255}}u.prototype.writeUInt32LE=function je(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{q(this,e,t,true)}return t+4};u.prototype.writeUInt32BE=function Oe(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{q(this,e,t,false)}return t+4};u.prototype.writeIntLE=function Me(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 o=0;var s=1;var a=e<0?1:0;this[t]=e&255;while(++o>0)-a&255}return t+r};u.prototype.writeIntBE=function De(e,t,r,n){e=+e;t=t|0;if(!n){var i=Math.pow(2,8*r-1);N(this,e,t,r,i-1,-i)}var o=r-1;var s=1;var a=e<0?1:0;this[t+o]=e&255;while(--o>=0&&(s*=256)){this[t+o]=(e/s>>0)-a&255}return t+r};u.prototype.writeInt8=function Ne(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 He(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{H(this,e,t,true)}return t+2};u.prototype.writeInt16BE=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>>>8;this[t+1]=e&255}else{H(this,e,t,false)}return t+2};u.prototype.writeInt32LE=function ze(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{q(this,e,t,true)}return t+4};u.prototype.writeInt32BE=function We(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{q(this,e,t,false)}return t+4};function z(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("index out of range");if(r<0)throw new RangeError("index out of range")}function W(e,t,r,n,o){if(!o){z(e,t,r,4,3.4028234663852886e38,-3.4028234663852886e38)}i.write(e,t,r,n,23,4);return r+4}u.prototype.writeFloatLE=function Fe(e,t,r){return W(this,e,t,true,r)};u.prototype.writeFloatBE=function Ye(e,t,r){return W(this,e,t,false,r)};function F(e,t,r,n,o){if(!o){z(e,t,r,8,1.7976931348623157e308,-1.7976931348623157e308)}i.write(e,t,r,n,52,8);return r+8}u.prototype.writeDoubleLE=function Ve(e,t,r){return F(this,e,t,true,r)};u.prototype.writeDoubleBE=function $e(e,t,r){return F(this,e,t,false,r)};u.prototype.copy=function Ge(e,t,r,n){if(!r)r=0;if(!n&&n!==0)n=this.length;if(t>=e.length)t=e.length;if(!t)t=0;if(n>0&&n=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=0;o--){e[o+t]=this[o+r]}}else if(i<1e3||!u.TYPED_ARRAY_SUPPORT){for(o=0;o=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;n55295&&r<57344){if(!i){if(r>56319){if((t-=3)>-1)o.push(239,191,189);continue}else if(s+1===n){if((t-=3)>-1)o.push(239,191,189);continue}i=r;continue}if(r<56320){if((t-=3)>-1)o.push(239,191,189);i=r;continue}r=(i-55296<<10|r-56320)+65536}else if(i){if((t-=3)>-1)o.push(239,191,189)}i=null;if(r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else{throw new Error("Invalid code point")}}return o}function J(e){var t=[];for(var r=0;r>8;i=r%256;o.push(i);o.push(n)}return o}function Z(e){return n.toByteArray(V(e))}function Q(e,t,r,n){for(var i=0;i=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":26,ieee754:27,isarray:28}],26:[function(e,t,r){(function(e){"use strict";var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var r=typeof Uint8Array!=="undefined"?Uint8Array:Array;var n="+".charCodeAt(0);var i="/".charCodeAt(0);var o="0".charCodeAt(0);var s="a".charCodeAt(0);var a="A".charCodeAt(0);var f="-".charCodeAt(0);var u="_".charCodeAt(0);function c(e){var t=e.charCodeAt(0);if(t===n||t===f)return 62;if(t===i||t===u)return 63;if(t0){throw new Error("Invalid string. Length must be a multiple of 4")}var f=e.length;s=e.charAt(f-2)==="="?2:e.charAt(f-1)==="="?1:0;a=new r(e.length*3/4-s);i=s>0?e.length-4:e.length;var u=0;function l(e){a[u++]=e}for(t=0,n=0;t>16);l((o&65280)>>8);l(o&255)}if(s===2){o=c(e.charAt(t))<<2|c(e.charAt(t+1))>>4;l(o&255)}else if(s===1){o=c(e.charAt(t))<<10|c(e.charAt(t+1))<<4|c(e.charAt(t+2))>>2;l(o>>8&255);l(o&255)}return a}function d(e){var r;var n=e.length%3;var i="";var o,s;function a(e){return t.charAt(e)}function f(e){return a(e>>18&63)+a(e>>12&63)+a(e>>6&63)+a(e&63)}for(r=0,s=e.length-n;r>2);i+=a(o<<4&63);i+="==";break;case 2:o=(e[e.length-2]<<8)+e[e.length-1];i+=a(o>>10);i+=a(o>>4&63);i+=a(o<<2&63);i+="=";break;default:break}return i}e.toByteArray=l;e.fromByteArray=d})(typeof r==="undefined"?this.base64js={}:r)},{}],27:[function(e,t,r){r.read=function(e,t,r,n,i){var o,s;var a=i*8-n-1;var f=(1<>1;var c=-7;var l=r?i-1:0;var d=r?-1:1;var h=e[t+l];l+=d;o=h&(1<<-c)-1;h>>=-c;c+=a;for(;c>0;o=o*256+e[t+l],l+=d,c-=8){}s=o&(1<<-c)-1;o>>=-c;c+=n;for(;c>0;s=s*256+e[t+l],l+=d,c-=8){}if(o===0){o=1-u}else if(o===f){return s?NaN:(h?-1:1)*Infinity}else{s=s+Math.pow(2,n);o=o-u}return(h?-1:1)*s*Math.pow(2,o-n)};r.write=function(e,t,r,n,i,o){var s,a,f;var u=o*8-i-1;var c=(1<>1;var d=i===23?Math.pow(2,-24)-Math.pow(2,-77):0;var h=n?0:o-1;var p=n?1:-1;var m=t<0||t===0&&1/t<0?1:0;t=Math.abs(t);if(isNaN(t)||t===Infinity){a=isNaN(t)?1:0;s=c}else{s=Math.floor(Math.log(t)/Math.LN2);if(t*(f=Math.pow(2,-s))<1){s--;f*=2}if(s+l>=1){t+=d/f}else{t+=d*Math.pow(2,1-l)}if(t*f>=2){s++;f/=2}if(s+l>=c){a=0;s=c}else if(s+l>=1){a=(t*f-1)*Math.pow(2,i);s=s+l}else{a=t*Math.pow(2,l-1)*Math.pow(2,i);s=0}}for(;i>=8;e[r+h]=a&255,h+=p,a/=256,i-=8){}s=s<0;e[r+h]=s&255,h+=p,s/=256,u-=8){}e[r+h-p]|=m*128}},{}],28:[function(e,t,r){var n={}.toString;t.exports=Array.isArray||function(e){return n.call(e)=="[object Array]"}},{}],29:[function(e,t,r){function n(){this._events=this._events||{};this._maxListeners=this._maxListeners||undefined}t.exports=n;n.EventEmitter=n;n.prototype._events=undefined;n.prototype._maxListeners=undefined;n.defaultMaxListeners=10;n.prototype.setMaxListeners=function(e){if(!o(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");this._maxListeners=e;return this};n.prototype.emit=function(e){var t,r,n,o,f,u;if(!this._events)this._events={};if(e==="error"){if(!this._events.error||s(this._events.error)&&!this._events.error.length){t=arguments[1];if(t instanceof Error){throw t}throw TypeError('Uncaught, unspecified "error" event.')}}r=this._events[e];if(a(r))return false;if(i(r)){switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:o=Array.prototype.slice.call(arguments,1);r.apply(this,o)}}else if(s(r)){o=Array.prototype.slice.call(arguments,1);u=r.slice();n=u.length;for(f=0;f0&&this._events[e].length>r){this._events[e].warned=true;console.error("(node) warning: possible EventEmitter memory "+"leak detected. %d listeners added. "+"Use emitter.setMaxListeners() to increase limit.",this._events[e].length);if(typeof console.trace==="function"){console.trace()}}}return this};n.prototype.on=n.prototype.addListener;n.prototype.once=function(e,t){if(!i(t))throw TypeError("listener must be a function");var r=false;function n(){this.removeListener(e,n);if(!r){r=true;t.apply(this,arguments)}}n.listener=t;this.on(e,n);return this};n.prototype.removeListener=function(e,t){var r,n,o,a;if(!i(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;r=this._events[e];o=r.length;n=-1;if(r===t||i(r.listener)&&r.listener===t){delete this._events[e];if(this._events.removeListener)this.emit("removeListener",e,t)}else if(s(r)){for(a=o;a-- >0;){if(r[a]===t||r[a].listener&&r[a].listener===t){n=a;break}}if(n<0)return this;if(r.length===1){r.length=0;delete this._events[e]}else{r.splice(n,1)}if(this._events.removeListener)this.emit("removeListener",e,t)}return this};n.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener){if(arguments.length===0)this._events={};else if(this._events[e])delete this._events[e];return this}if(arguments.length===0){for(t in this._events){if(t==="removeListener")continue;this.removeAllListeners(t)}this.removeAllListeners("removeListener");this._events={};return this}r=this._events[e];if(i(r)){this.removeListener(e,r)}else if(r){while(r.length)this.removeListener(e,r[r.length-1])}delete this._events[e];return this};n.prototype.listeners=function(e){var t;if(!this._events||!this._events[e])t=[];else if(i(this._events[e]))t=[this._events[e]];else t=this._events[e].slice();return t};n.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(i(t))return 1;else if(t)return t.length}return 0};n.listenerCount=function(e,t){return e.listenerCount(t)};function i(e){return typeof e==="function"}function o(e){return typeof e==="number"}function s(e){return typeof e==="object"&&e!==null}function a(e){return e===void 0}},{}],30:[function(e,t,r){var n=e("http");var i=t.exports;for(var o in n){if(n.hasOwnProperty(o))i[o]=n[o]}i.request=function(e,t){if(!e)e={};e.scheme="https";e.protocol="https:";return n.request.call(this,e,t)}},{http:53}],31:[function(e,t,r){t.exports=function(e){return!!(e!=null&&(e._isBuffer||e.constructor&&typeof e.constructor.isBuffer==="function"&&e.constructor.isBuffer(e)))}},{}],32:[function(e,t,r){t.exports=Array.isArray||function(e){return Object.prototype.toString.call(e)=="[object Array]"}},{}],33:[function(e,t,r){(function(e){function t(e,t){var r=0;for(var n=e.length-1;n>=0;n--){var i=e[n];if(i==="."){e.splice(n,1)}else if(i===".."){e.splice(n,1);r++}else if(r){e.splice(n,1);r--}}if(t){for(;r--;r){e.unshift("..")}}return e}var n=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;var i=function(e){return n.exec(e).slice(1)};r.resolve=function(){var r="",n=false;for(var i=arguments.length-1;i>=-1&&!n;i--){var s=i>=0?arguments[i]:e.cwd();if(typeof s!=="string"){throw new TypeError("Arguments to path.resolve must be strings")}else if(!s){continue}r=s+"/"+r;n=s.charAt(0)==="/"}r=t(o(r.split("/"),function(e){return!!e}),!n).join("/");return(n?"/":"")+r||"."};r.normalize=function(e){var n=r.isAbsolute(e),i=s(e,-1)==="/";e=t(o(e.split("/"),function(e){return!!e}),!n).join("/");if(!e&&!n){e="."}if(e&&i){e+="/"}return(n?"/":"")+e};r.isAbsolute=function(e){return e.charAt(0)==="/"};r.join=function(){var e=Array.prototype.slice.call(arguments,0);return r.normalize(o(e,function(e,t){if(typeof e!=="string"){throw new TypeError("Arguments to path.join must be strings")}return e}).join("/"))};r.relative=function(e,t){e=r.resolve(e).substr(1);t=r.resolve(t).substr(1);function n(e){var t=0;for(;t=0;r--){if(e[r]!=="")break}if(t>r)return[];return e.slice(t,r-t+1)}var i=n(e.split("/"));var o=n(t.split("/"));var s=Math.min(i.length,o.length);var a=s;for(var f=0;f1){for(var r=1;r= 0x80 (not a basic code point)","invalid-input":"Invalid input"},E=c-l,x=Math.floor,k=String.fromCharCode,S;function B(e){throw new RangeError(w[e])}function I(e,t){var r=e.length;var n=[];while(r--){n[r]=t(e[r])}return n}function A(e,t){var r=e.split("@");var n="";if(r.length>1){n=r[0]+"@";e=r[1]}e=e.replace(b,".");var i=e.split(".");var o=I(i,t).join(".");return n+o}function C(e){var t=[],r=0,n=e.length,i,o;while(r=55296&&i<=56319&&r65535){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 c}function R(e,t){return e+22+75*(e<26)-((t!=0)<<5)}function U(e,t,r){var n=0;e=r?x(e/p):e>>1;e+=x(e/t);for(;e>E*d>>1;n+=c){e=x(e/E)}return x(n+(E+1)*e/(e+h))}function P(e){var t=[],r=e.length,n,i=0,o=v,s=m,a,f,h,p,y,_,b,w,E;a=e.lastIndexOf(g);if(a<0){a=0}for(f=0;f=128){B("not-basic")}t.push(e.charCodeAt(f))}for(h=a>0?a+1:0;h=r){B("invalid-input")}b=L(e.charCodeAt(h++));if(b>=c||b>x((u-i)/y)){B("overflow")}i+=b*y;w=_<=s?l:_>=s+d?d:_-s;if(bx(u/E)){B("overflow")}y*=E}n=t.length+1;s=U(i-p,n,p==0);if(x(i/n)>u-o){B("overflow")}o+=x(i/n);i%=n;t.splice(i++,0,o)}return T(t)}function j(e){var t,r,n,i,o,s,a,f,h,p,y,_=[],b,w,E,S;e=C(e);b=e.length;t=v;r=0;o=m;for(s=0;s=t&&yx((u-r)/w)){B("overflow")}r+=(a-t)*w;t=a;for(s=0;su){B("overflow")}if(y==t){for(f=r,h=c;;h+=c){p=h<=o?l:h>=o+d?d:h-o;if(f0&&u>f){u=f}for(var c=0;c=0){h=l.substr(0,d);p=l.substr(d+1)}else{h=l;p=""}m=decodeURIComponent(h);v=decodeURIComponent(p);if(!n(s,m)){s[m]=v}else if(i(s[m])){s[m].push(v)}else{s[m]=[s[m],v]}}return s};var i=Array.isArray||function(e){return Object.prototype.toString.call(e)==="[object Array]"}},{}],37:[function(e,t,r){"use strict";var n=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};t.exports=function(e,t,r,a){t=t||"&";r=r||"=";if(e===null){e=undefined}if(typeof e==="object"){return o(s(e),function(s){var a=encodeURIComponent(n(s))+r;if(i(e[s])){return o(e[s],function(e){return a+encodeURIComponent(n(e))}).join(t)}else{return a+encodeURIComponent(n(e[s]))}}).join(t)}if(!a)return"";return encodeURIComponent(n(a))+r+encodeURIComponent(n(e))};var i=Array.isArray||function(e){return Object.prototype.toString.call(e)==="[object Array]"};function o(e,t){if(e.map)return e.map(t);var r=[];for(var n=0;n0){if(t.ended&&!i){var s=new Error("stream.push() after EOF");e.emit("error",s)}else if(t.endEmitted&&i){var s=new Error("stream.unshift() after end event");e.emit("error",s)}else{if(t.decoder&&!i&&!n)r=t.decoder.write(r);if(!i)t.reading=false;if(t.flowing&&t.length===0&&!t.sync){e.emit("data",r);e.read(0)}else{t.length+=t.objectMode?1:r.length;if(i)t.buffer.unshift(r);else t.buffer.push(r);if(t.needReadable)x(e)}S(e,t)}}else if(!i){t.reading=false}return g(t)}function g(e){return!e.ended&&(e.needReadable||e.length=y){e=y}else{e--;e|=e>>>1;e|=e>>>2;e|=e>>>4;e|=e>>>8;e|=e>>>16;e++}return e}function b(e,t){if(t.length===0&&t.ended)return 0;if(t.objectMode)return e===0?0:1;if(e===null||isNaN(e)){if(t.flowing&&t.buffer.length)return t.buffer[0].length;else return t.length}if(e<=0)return 0;if(e>t.highWaterMark)t.highWaterMark=_(e);if(e>t.length){if(!t.ended){t.needReadable=true;return 0}else{return t.length}}return e}m.prototype.read=function(e){l("read",e);var t=this._readableState;var r=e;if(typeof e!=="number"||e>0)t.emittedReadable=false;if(e===0&&t.needReadable&&(t.length>=t.highWaterMark||t.ended)){l("read: emitReadable",t.length,t.ended);if(t.length===0&&t.ended)U(this);else x(this);return null}e=b(e,t);if(e===0&&t.ended){if(t.length===0)U(this);return null}var n=t.needReadable;l("need readable",n);if(t.length===0||t.length-e0)i=R(e,t);else i=null;if(i===null){t.needReadable=true;e=0}t.length-=e;if(t.length===0&&!t.ended)t.needReadable=true;if(r!==e&&t.ended&&t.length===0)U(this);if(i!==null)this.emit("data",i);return i};function w(e,t){var r=null;if(!o.isBuffer(t)&&typeof t!=="string"&&t!==null&&t!==undefined&&!e.objectMode){r=new TypeError("Invalid non-string/buffer chunk")}return r}function E(e,t){if(t.ended)return;if(t.decoder){var r=t.decoder.end();if(r&&r.length){t.buffer.push(r);t.length+=t.objectMode?1:r.length}}t.ended=true;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 S(e,t){if(!t.readingMore){t.readingMore=true;n(B,e,t)}}function B(e,t){var r=t.length;while(!t.reading&&!t.flowing&&!t.ended&&t.length=n){if(i)a=r.join("");else if(r.length===1)a=r[0];else a=o.concat(r,n);r.length=0}else{if(e0)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 j(e,t){for(var r=0,n=e.length;r-1))throw new TypeError("Unknown encoding: "+e);this._writableState.defaultEncoding=e};function m(e,t,r){if(!e.objectMode&&e.decodeStrings!==false&&typeof t==="string"){t=new i(t,r)}return t}function v(e,t,r,n,o){r=m(t,r,n);if(i.isBuffer(r))n="buffer";var s=t.objectMode?1:r.length;t.length+=s;var a=t.lengthe._pos){var s=r.substr(e._pos);if(e._charset==="x-user-defined"){var a=new i(s.length);for(var u=0;ue._pos){e.push(new i(new Uint8Array(c.result.slice(e._pos))));e._pos=c.result.byteLength}};c.onload=function(){e.push(null)};c.readAsArrayBuffer(r);break}if(e._xhr.readyState===f.DONE&&e._mode!=="ms-stream"){e.push(null)}}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{},e("buffer").Buffer)},{"./capability":54,_process:34,buffer:25,inherits:115,stream:52}],57:[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"}},{}],58:[function(e,t,r){var n=e("buffer").Buffer;t.exports=function(e){if(e instanceof Uint8Array){if(e.byteOffset===0&&e.byteLength===e.buffer.byteLength){return e.buffer}else if(typeof e.buffer.slice==="function"){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}}if(n.isBuffer(e)){var t=new Uint8Array(e.length);var r=e.length;for(var i=0;i=this.charLength-this.charReceived?this.charLength-this.charReceived:e.length;e.copy(this.charBuffer,this.charReceived,0,r);this.charReceived+=r;if(this.charReceived=55296&&n<=56319){this.charLength+=this.surrogateSize;t="";continue}this.charReceived=this.charLength=0;if(e.length===0){return t}break}this.detectIncompleteChar(e);var i=e.length;if(this.charLength){e.copy(this.charBuffer,0,e.length-this.charReceived,i);i-=this.charReceived}t+=e.toString(this.encoding,0,i);var i=t.length-1;var n=t.charCodeAt(i);if(n>=55296&&n<=56319){var o=this.surrogateSize;this.charLength+=o;this.charReceived+=o;this.charBuffer.copy(this.charBuffer,o,0,o);e.copy(this.charBuffer,0,0,o);return t.substring(0,i)}return t};s.prototype.detectIncompleteChar=function(e){var t=e.length>=3?3:e.length;for(;t>0;t--){var r=e[e.length-t];if(t==1&&r>>5==6){this.charLength=2;break}if(t<=2&&r>>4==14){this.charLength=3;break}if(t<=3&&r>>3==30){this.charLength=4;break}}this.charReceived=t};s.prototype.end=function(e){var t="";if(e&&e.length)t=this.write(e);if(this.charReceived){var r=this.charReceived;var n=this.charBuffer;var i=this.encoding;t+=n.slice(0,r).toString(i)}return t};function a(e){return e.toString(this.encoding)}function f(e){this.charReceived=e.length%2;this.charLength=this.charReceived?2:0}function u(e){this.charReceived=e.length%3;this.charLength=this.charReceived?3:0}},{buffer:25}],60:[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=E;r.Url=o;function o(){this.protocol=null;this.slashes=null;this.auth=null;this.host=null;this.port=null;this.hostname=null;this.hash=null;this.search=null;this.query=null;this.pathname=null;this.path=null;this.href=null}var s=/^([a-z0-9.+-]+:)/i,a=/:[0-9]*$/,f=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,u=["<",">",'"',"`"," ","\r","\n"," "],c=["{","}","|","\\","^","`"].concat(u),l=["'"].concat(c),d=["%","/","?",";","#"].concat(l),h=["/","?","#"],p=255,m=/^[+a-z0-9A-Z_-]{0,63}$/,v=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,g={javascript:true,"javascript:":true},y={javascript:true,"javascript:":true},_={http:true,https:true,ftp:true,gopher:true,file:true,"http:":true,"https:":true,"ftp:":true,"gopher:":true,"file:":true},b=e("querystring");function w(e,t,r){if(e&&i.isObject(e)&&e instanceof o)return e;var n=new o;n.parse(e,t,r);return n}o.prototype.parse=function(e,t,r){if(!i.isString(e)){throw new TypeError("Parameter 'url' must be a string, not "+typeof e)}var o=e.indexOf("?"),a=o!==-1&&o127){j+="x"}else{j+=P[O]}}if(!j.match(m)){var D=R.slice(0,I);var N=R.slice(I+1);var H=P.match(v);if(H){D.push(H[1]);N.unshift(H[2])}if(N.length){w="/"+N.join(".")+w}this.hostname=D.join(".");break}}}}if(this.hostname.length>p){this.hostname=""}else{this.hostname=this.hostname.toLowerCase()}if(!L){this.hostname=n.toASCII(this.hostname)}var q=this.port?":"+this.port:"";var z=this.hostname||"";this.host=z+q;this.href+=this.host;if(L){this.hostname=this.hostname.substr(1,this.hostname.length-2);if(w[0]!=="/"){w="/"+w}}}if(!g[k]){for(var I=0,U=l.length;I0?r.host.split("@"):false;if(S){r.auth=S.shift();r.host=r.hostname=S.shift()}}r.search=e.search;r.query=e.query;if(!i.isNull(r.pathname)||!i.isNull(r.search)){r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")}r.href=r.format();return r}if(!x.length){r.pathname=null;if(r.search){r.path="/"+r.search}else{r.path=null}r.href=r.format();return r}var B=x.slice(-1)[0];var I=(r.host||e.host||x.length>1)&&(B==="."||B==="..")||B==="";var A=0;for(var C=x.length;C>=0;C--){B=x[C];if(B==="."){x.splice(C,1)}else if(B===".."){x.splice(C,1);A++}else if(A){x.splice(C,1);A--}}if(!w&&!E){for(;A--;A){x.unshift("..")}}if(w&&x[0]!==""&&(!x[0]||x[0].charAt(0)!=="/")){x.unshift("")}if(I&&x.join("/").substr(-1)!=="/"){x.push("")}var T=x[0]===""||x[0]&&x[0].charAt(0)==="/";if(k){r.hostname=r.host=T?"":x.length?x.shift():"";var S=r.host&&r.host.indexOf("@")>0?r.host.split("@"):false;if(S){r.auth=S.shift();r.host=r.hostname=S.shift()}}w=w||r.host&&x.length;if(w&&!T){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};o.prototype.parseHost=function(){var e=this.host;var t=a.exec(e);if(t){t=t[0];if(t!==":"){this.port=t.substr(1)}e=e.substr(0,e.length-t.length)}if(e)this.hostname=e}},{"./util":61,punycode:35,querystring:38}],61:[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}}},{}],62:[function(e,t,r){t.exports=function n(e){return e&&typeof e==="object"&&typeof e.copy==="function"&&typeof e.fill==="function"&&typeof e.readUInt8==="function"}},{}],63:[function(e,t,r){(function(t,n){var i=/%[sdj%]/g;r.format=function(e){if(!E(e)){var t=[];for(var r=0;r=o)return e;switch(e){case"%s":return String(n[r++]);case"%d":return Number(n[r++]);case"%j":try{return JSON.stringify(n[r++])}catch(t){return"[Circular]"}default:return e}});for(var f=n[r];r=3)n.depth=arguments[2];if(arguments.length>=4)n.colors=arguments[3];if(y(t)){n.showHidden=t}else if(t){r._extend(n,t)}if(k(n.showHidden))n.showHidden=false;if(k(n.depth))n.depth=2;if(k(n.colors))n.colors=false;if(k(n.customInspect))n.customInspect=true;if(n.colors)n.stylize=f;return l(n,e,n.depth)}r.inspect=a;a.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]};a.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"};function f(e,t){var r=a.styles[t];if(r){return"["+a.colors[r][0]+"m"+e+"["+a.colors[r][1]+"m"}else{return e}}function u(e,t){return e}function c(e){var t={};e.forEach(function(e,r){t[e]=true});return t}function l(e,t,n){if(e.customInspect&&t&&C(t.inspect)&&t.inspect!==r.inspect&&!(t.constructor&&t.constructor.prototype===t)){var i=t.inspect(n,e);if(!E(i)){i=l(e,i,n)}return i}var o=d(e,t);if(o){return o}var s=Object.keys(t);var a=c(s);if(e.showHidden){s=Object.getOwnPropertyNames(t)}if(A(t)&&(s.indexOf("message")>=0||s.indexOf("description")>=0)){return h(t)}if(s.length===0){if(C(t)){var f=t.name?": "+t.name:"";return e.stylize("[Function"+f+"]","special")}if(S(t)){return e.stylize(RegExp.prototype.toString.call(t),"regexp")}if(I(t)){return e.stylize(Date.prototype.toString.call(t),"date")}if(A(t)){return h(t)}}var u="",y=false,_=["{","}"];if(g(t)){y=true;_=["[","]"]}if(C(t)){var b=t.name?": "+t.name:"";u=" [Function"+b+"]"}if(S(t)){u=" "+RegExp.prototype.toString.call(t)}if(I(t)){u=" "+Date.prototype.toUTCString.call(t)}if(A(t)){u=" "+h(t)}if(s.length===0&&(!y||t.length==0)){return _[0]+u+_[1]}if(n<0){if(S(t)){return e.stylize(RegExp.prototype.toString.call(t),"regexp")}else{return e.stylize("[Object]","special")}}e.seen.push(t);var w;if(y){w=p(e,t,n,a,s)}else{w=s.map(function(r){return m(e,t,n,a,r,y)})}e.seen.pop();return v(w,u,_)}function d(e,t){if(k(t))return e.stylize("undefined","undefined");if(E(t)){var r="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(r,"string")}if(w(t))return e.stylize(""+t,"number");if(y(t))return e.stylize(""+t,"boolean");if(_(t))return e.stylize("null","null")}function h(e){return"["+Error.prototype.toString.call(e)+"]"}function p(e,t,r,n,i){var o=[];for(var s=0,a=t.length;s-1){if(o){a=a.split("\n").map(function(e){return" "+e}).join("\n").substr(2)}else{a="\n"+a.split("\n").map(function(e){return" "+e}).join("\n")}}}else{a=e.stylize("[Circular]","special")}}if(k(s)){if(o&&i.match(/^\d+$/)){return a}s=JSON.stringify(""+i);if(s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)){s=s.substr(1,s.length-2);s=e.stylize(s,"name")}else{s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'");s=e.stylize(s,"string")}}return s+": "+a}function v(e,t,r){var n=0;var i=e.reduce(function(e,t){n++;if(t.indexOf("\n")>=0)n++;return e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0);if(i>60){return r[0]+(t===""?"":t+"\n ")+" "+e.join(",\n ")+" "+r[1]}return r[0]+t+" "+e.join(", ")+" "+r[1]}function g(e){return Array.isArray(e)}r.isArray=g;function y(e){return typeof e==="boolean"}r.isBoolean=y;function _(e){return e===null}r.isNull=_;function b(e){return e==null}r.isNullOrUndefined=b;function w(e){return typeof e==="number"}r.isNumber=w;function E(e){return typeof e==="string"}r.isString=E;function x(e){return typeof e==="symbol"}r.isSymbol=x;function k(e){return e===void 0}r.isUndefined=k;function S(e){return B(e)&&L(e)==="[object RegExp]"}r.isRegExp=S;function B(e){return typeof e==="object"&&e!==null}r.isObject=B;function I(e){return B(e)&&L(e)==="[object Date]"}r.isDate=I;function A(e){return B(e)&&(L(e)==="[object Error]"||e instanceof Error)}r.isError=A;function C(e){return typeof e==="function"}r.isFunction=C;function T(e){return e===null||typeof e==="boolean"||typeof e==="number"||typeof e==="string"||typeof e==="symbol"||typeof e==="undefined"}r.isPrimitive=T;r.isBuffer=e("./support/isBuffer");function L(e){return Object.prototype.toString.call(e)}function R(e){return e<10?"0"+e.toString(10):e.toString(10)}var U=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function P(){var e=new Date;var t=[R(e.getHours()),R(e.getMinutes()),R(e.getSeconds())].join(":");return[e.getDate(),U[e.getMonth()],t].join(" ")}r.log=function(){console.log("%s - %s",P(),r.format.apply(r,arguments))};r.inherits=e("inherits");r._extend=function(e,t){if(!t||!B(t))return e;var r=Object.keys(t);var n=r.length;while(n--){e[r[n]]=t[r[n]]}return e};function j(e,t){return Object.prototype.hasOwnProperty.call(e,t)}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./support/isBuffer":62,_process:34,inherits:115}],64:[function(e,t,r){(function(r){var n=e("inherits");var i=e("readable-stream").Transform;var o=e("defined");t.exports=s;n(s,i);function s(e,t){if(!(this instanceof s))return new s(e,t);i.call(this);if(!t)t={};if(typeof e==="object"){t=e;e=t.size}this.size=e||512;if(t.nopad)this._zeroPadding=false;else this._zeroPadding=o(t.zeroPadding,true);this._buffered=[];this._bufferedBytes=0}s.prototype._transform=function(e,t,n){this._bufferedBytes+=e.length;this._buffered.push(e);while(this._bufferedBytes>=this.size){var i=r.concat(this._buffered);this._bufferedBytes-=this.size;this.push(i.slice(0,this.size));this._buffered=[i.slice(this.size,i.length)]}n()};s.prototype._flush=function(){if(this._bufferedBytes&&this._zeroPadding){var e=new r(this.size-this._bufferedBytes);e.fill(0);this._buffered.push(e);this.push(r.concat(this._buffered));this._buffered=null}else if(this._bufferedBytes){this.push(r.concat(this._buffered));this._buffered=null}this.push(null)}}).call(this,e("buffer").Buffer)},{buffer:25,defined:65,inherits:115,"readable-stream":76}],65:[function(e,t,r){t.exports=function(){for(var e=0;e1){o=t.path[0]}else if(t.path[0]!==o){o=null}});e=e.filter(function(e){if(typeof e==="string")return true;var t=e.path[e.path.length-1];return B(t)&&p.not(t)});if(o){e.forEach(function(e){if(typeof e==="string")return;e.path.shift()})}if(!t.name&&o)t.name=o;if(!t.name&&e[0]&&e[0].name)t.name=e[0].name;if(!t.name&&typeof e[0]==="string")t.name=f.basename(e[0]);if(t.name===undefined){throw new Error("missing option 'name' and unable to infer it from input[0].name")}var s=e.reduce(function(e,t){return e+Number(typeof t==="string")},0);var a=e.length===1;if(e.length===1&&typeof e[0]==="string"){if(typeof d.stat!=="function"){throw new Error("filesystem paths do not work in the browser")}h(e[0],function(e,t){if(e)return n(e);a=t;u()})}else{r.nextTick(function(){u()})}function u(){g(e.map(function(e){return function(r){var n={};if(T(e)){n.getStream=U(e);n.length=e.size}else if(i.isBuffer(e)){n.getStream=P(e);n.length=e.length}else if(R(e)){if(!t.pieceLength){throw new Error("must specify `pieceLength` option if input is Stream")}n.getStream=O(e,n);n.length=0}else if(typeof e==="string"){if(typeof d.stat!=="function"){throw new Error("filesystem paths do not work in the browser")}var o=s>1||a;x(e,o,r);return}else{throw new Error("invalid input type")}n.path=e.path;r(null,n)}}),function(e,t){if(e)return n(e);t=l(t);n(null,t,a)})}}function x(e,t,r){S(e,k,function(n,i){if(n)return r(n);if(Array.isArray(i))i=l(i);else i=[i];e=f.normalize(e);if(t){e=e.slice(0,e.lastIndexOf(f.sep)+1)}if(e[e.length-1]!==f.sep)e+=f.sep;i.forEach(function(t){t.getStream=j(t.path);t.path=t.path.replace(e,"").split(f.sep)});r(null,i)})}function k(e,t){t=v(t);d.stat(e,function(r,n){if(r)return t(r);var i={length:n.size,path:e};t(null,i)})}function S(e,t,r){d.readdir(e,function(n,i){if(n&&n.code==="ENOTDIR"){t(e,r)}else if(n){r(n)}else{g(i.filter(B).filter(p.not).map(function(r){return function(n){S(f.join(e,r),t,n)}}),r)}})}function B(e){return e[0]!=="."}function I(e,t,r){r=v(r);var n=[];var o=0;var a=e.map(function(e){return e.getStream});var f=0;var u=0;var c=false;var l=new m(a);var d=new s(t,{zeroPadding:false});l.on("error",g);l.pipe(d).on("data",h).on("end",p).on("error",g);function h(e){o+=e.length;var t=u;y(e,function(e){n[t]=e;f-=1;b()});f+=1;u+=1}function p(){c=true;b()}function g(e){_();r(e)}function _(){l.removeListener("error",g);d.removeListener("data",h);d.removeListener("end",p);d.removeListener("error",g)}function b(){if(c&&f===0){_();r(null,new i(n.join(""),"hex"),o)}}}function A(e,r,i){var s=r.announceList;if(!s){if(typeof r.announce==="string")s=[[r.announce]];else if(Array.isArray(r.announce)){s=r.announce.map(function(e){return[e]})}}if(!s)s=[];if(n.WEBTORRENT_ANNOUNCE){if(typeof n.WEBTORRENT_ANNOUNCE==="string"){s.push([[n.WEBTORRENT_ANNOUNCE]])}else if(Array.isArray(n.WEBTORRENT_ANNOUNCE)){s=s.concat(n.WEBTORRENT_ANNOUNCE.map(function(e){return[e]}))}}if(r.announce===undefined&&r.announceList===undefined){s=s.concat(t.exports.announceList)}if(typeof r.urlList==="string")r.urlList=[r.urlList];var f={info:{name:r.name},"creation date":Number(r.creationDate)||Date.now(),encoding:"UTF-8"};if(s.length!==0){f.announce=s[0][0];f["announce-list"]=s}if(r.comment!==undefined)f.comment=r.comment;if(r.createdBy!==undefined)f["created by"]=r.createdBy;if(r.private!==undefined)f.info.private=Number(r.private);if(r.sslCert!==undefined)f.info["ssl-cert"]=r.sslCert;if(r.urlList!==undefined)f["url-list"]=r.urlList;var u=r.pieceLength||a(e.reduce(C,0));f.info["piece length"]=u;I(e,u,function(t,n,s){if(t)return i(t);f.info.pieces=n;e.forEach(function(e){delete e.getStream});if(r.singleFileTorrent){f.info.length=s}else{f.info.files=e}i(null,o.encode(f))})}function C(e,t){return e+t.length}function T(e){return typeof Blob!=="undefined"&&e instanceof Blob}function L(e){return typeof FileList==="function"&&e instanceof FileList}function R(e){return typeof e==="object"&&e!=null&&typeof e.pipe==="function"}function U(e){return function(){return new c(e)}}function P(e){return function(){var t=new _.PassThrough;t.end(e);return t}}function j(e){return function(){return d.createReadStream(e)}}function O(e,t){return function(){var r=new _.Transform;r._transform=function(e,r,n){t.length+=e.length;this.push(e);n()};e.pipe(r);return r}}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{},e("buffer").Buffer)},{_process:34,bencode:80,"block-stream2":84,buffer:25,"filestream/read":99,flatten:100,fs:23,"is-file":101,junk:102,multistream:117,once:104,path:33,"piece-length":105,"run-parallel":184,"simple-sha1":193,stream:52,xtend:210}],80:[function(e,t,r){arguments[4][11][0].apply(r,arguments)},{"./lib/decode":81,"./lib/encode":83,dup:11}],81:[function(e,t,r){arguments[4][12][0].apply(r,arguments)},{"./dict":82,buffer:25,dup:12}],82:[function(e,t,r){arguments[4][13][0].apply(r,arguments)},{dup:13}],83:[function(e,t,r){arguments[4][14][0].apply(r,arguments)},{buffer:25,dup:14}],84:[function(e,t,r){arguments[4][64][0].apply(r,arguments)},{buffer:25,defined:85,dup:64,inherits:115,"readable-stream":96}],85:[function(e,t,r){arguments[4][65][0].apply(r,arguments)},{dup:65}],86:[function(e,t,r){arguments[4][40][0].apply(r,arguments)},{"./_stream_readable":88,"./_stream_writable":90,"core-util-is":91,dup:40,inherits:115,"process-nextick-args":93}],87:[function(e,t,r){arguments[4][41][0].apply(r,arguments)},{"./_stream_transform":89,"core-util-is":91,dup:41,inherits:115}],88:[function(e,t,r){arguments[4][42][0].apply(r,arguments)},{"./_stream_duplex":86,_process:34,buffer:25,"core-util-is":91,dup:42,events:29,inherits:115,isarray:92,"process-nextick-args":93,"string_decoder/":94,util:24}],89:[function(e,t,r){arguments[4][43][0].apply(r,arguments)},{"./_stream_duplex":86,"core-util-is":91,dup:43,inherits:115}],90:[function(e,t,r){arguments[4][44][0].apply(r,arguments)},{"./_stream_duplex":86,buffer:25,"core-util-is":91,dup:44,events:29,inherits:115,"process-nextick-args":93,"util-deprecate":95}],91:[function(e,t,r){arguments[4][71][0].apply(r,arguments)},{"../../../../../../../../browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js":31,dup:71}],92:[function(e,t,r){arguments[4][32][0].apply(r,arguments)},{dup:32}],93:[function(e,t,r){arguments[4][46][0].apply(r,arguments)},{_process:34,dup:46}],94:[function(e,t,r){arguments[4][59][0].apply(r,arguments)},{buffer:25,dup:59}],95:[function(e,t,r){arguments[4][47][0].apply(r,arguments)},{dup:47}],96:[function(e,t,r){arguments[4][49][0].apply(r,arguments)},{"./lib/_stream_duplex.js":86,"./lib/_stream_passthrough.js":87,"./lib/_stream_readable.js":88,"./lib/_stream_transform.js":89,"./lib/_stream_writable.js":90,dup:49}],97:[function(e,t,r){ (function(r){var n=e("is-typedarray").strict;t.exports=function i(e){if(n(e)){var t=new r(e.buffer);if(e.byteLength!==e.buffer.byteLength){t=t.slice(e.byteOffset,e.byteOffset+e.byteLength)}return t}else{return new r(e)}}}).call(this,e("buffer").Buffer)},{buffer:25,"is-typedarray":98}],98:[function(e,t,r){arguments[4][22][0].apply(r,arguments)},{dup:22}],99:[function(e,t,r){var n=e("stream").Readable;var i=e("inherits");var o=/^.*\.(\w+)$/;var s=e("typedarray-to-buffer");function a(e,t){var r=this;if(!(this instanceof a)){return new a(e,t)}t=t||{};n.call(this,t);this._offset=0;this._ready=false;this._file=e;this._size=e.size;this._chunkSize=t.chunkSize||Math.max(this._size/1e3,200*1024);this.reader=new FileReader;this._generateHeaderBlocks(e,t,function(e,t){if(e){return r.emit("error",e)}if(Array.isArray(t)){t.forEach(function(e){r.push(e)})}r._ready=true;r.emit("_ready")})}i(a,n);t.exports=a;a.prototype._generateHeaderBlocks=function(e,t,r){r(null,[])};a.prototype._read=function(){if(!this._ready){this.once("_ready",this._read.bind(this));return}var e=this;var t=this.reader;var r=this._offset;var n=this._offset+this._chunkSize;if(n>this._size)n=this._size;if(r===this._size){this.destroy();this.push(null);return}t.onload=function(){e._offset=n;e.push(s(t.result))};t.onerror=function(){e.emit("error",t.error)};t.readAsArrayBuffer(this._file.slice(r,n))};a.prototype.destroy=function(){this._file=null;if(this.reader){this.reader.onload=null;this.reader.onerror=null;try{this.reader.abort()}catch(e){}}this.reader=null}},{inherits:115,stream:52,"typedarray-to-buffer":97}],100:[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=r){break}r=n;i=t[o]}return i}},{}],107:[function(e,t,r){r=t.exports=e("./debug");r.log=o;r.formatArgs=i;r.save=s;r.load=a;r.useColors=n;r.storage="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:f();r.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"];function n(){return"WebkitAppearance"in document.documentElement.style||window.console&&(console.firebug||console.exception&&console.table)||navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31}r.formatters.j=function(e){return JSON.stringify(e)};function i(){var e=arguments;var t=this.useColors;e[0]=(t?"%c":"")+this.namespace+(t?" %c":" ")+e[0]+(t?"%c ":" ")+"+"+r.humanize(this.diff);if(!t)return e;var n="color: "+this.color;e=[e[0],n,"color: inherit"].concat(Array.prototype.slice.call(e,1));var i=0;var o=0;e[0].replace(/%[a-z%]/g,function(e){if("%%"===e)return;i++;if("%c"===e){o=i}});e.splice(o,0,n);return e}function o(){return"object"===typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function s(e){try{if(null==e){r.storage.removeItem("debug")}else{r.storage.debug=e}}catch(t){}}function a(){var e;try{e=r.storage.debug}catch(t){}return e}r.enable(a());function f(){try{return window.localStorage}catch(e){}}},{"./debug":108}],108:[function(e,t,r){r=t.exports=s;r.coerce=c;r.disable=f;r.enable=a;r.enabled=u;r.humanize=e("ms");r.names=[];r.skips=[];r.formatters={};var n=0;var i;function o(){return r.colors[n++%r.colors.length]}function s(e){function t(){}t.enabled=false;function n(){var e=n;var t=+new Date;var s=t-(i||t);e.diff=s;e.prev=i;e.curr=t;i=t;if(null==e.useColors)e.useColors=r.useColors();if(null==e.color&&e.useColors)e.color=o();var a=Array.prototype.slice.call(arguments);a[0]=r.coerce(a[0]);if("string"!==typeof a[0]){a=["%o"].concat(a)}var f=0;a[0]=a[0].replace(/%([a-z%])/g,function(t,n){if(t==="%%")return t;f++;var i=r.formatters[n];if("function"===typeof i){var o=a[f];t=i.call(e,o);a.splice(f,1);f--}return t});if("function"===typeof r.formatArgs){a=r.formatArgs.apply(e,a)}var u=n.log||r.log||console.log.bind(console);u.apply(e,a)}n.enabled=true;var s=r.enabled(e)?n:t;s.namespace=e;return s}function a(e){r.save(e);var t=(e||"").split(/[\s,]+/);var n=t.length;for(var i=0;i1e4)return;var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(!t)return;var r=parseFloat(t[1]);var f=(t[2]||"ms").toLowerCase();switch(f){case"years":case"year":case"yrs":case"yr":case"y":return r*a;case"days":case"day":case"d":return r*s;case"hours":case"hour":case"hrs":case"hr":case"h":return r*o;case"minutes":case"minute":case"mins":case"min":case"m":return r*i;case"seconds":case"second":case"secs":case"sec":case"s":return r*n;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r}}function u(e){if(e>=s)return Math.round(e/s)+"d";if(e>=o)return Math.round(e/o)+"h";if(e>=i)return Math.round(e/i)+"m";if(e>=n)return Math.round(e/n)+"s";return e+"ms"}function c(e){return l(e,s,"day")||l(e,o,"hour")||l(e,i,"minute")||l(e,n,"second")||e+" ms"}function l(e,t,r){if(e=Math.pow(2,e)){return n(e,t)}else return s};n.rack=function(e,t,r){var i=function(i){var s=0;do{if(s++>10){if(r)e+=r;else throw new Error("too many ID collisions, use more bits")}var a=n(e,t)}while(Object.hasOwnProperty.call(o,a));o[a]=i;return a};var o=i.hats={};i.get=function(e){return i.hats[e]};i.set=function(e,t){i.hats[e]=t;return i};i.bits=e||128;i.base=t||16;return i}},{}],114:[function(e,t,r){(function(e){t.exports=r;function r(e){if(!(this instanceof r))return new r(e);this.store=e;if(!this.store||!this.store.get||!this.store.put){throw new Error("First argument must be abstract-chunk-store compliant")}this.mem=[]}r.prototype.put=function(e,t,r){var n=this;n.mem[e]=t;n.store.put(e,t,function(t){n.mem[e]=null;if(r)r(t)})};r.prototype.get=function(e,t,r){if(typeof t==="function")return this.get(e,null,t);var i=t&&t.offset||0;var o=t&&t.length&&i+t.length;var s=this.mem[e];if(s)return n(r,null,t?s.slice(i,o):s);this.store.get(e,t,r)};r.prototype.close=function(e){this.store.close(e)};r.prototype.destroy=function(e){this.store.destroy(e)};function n(t,r,n){e.nextTick(function(){if(t)t(r,n)})}}).call(this,e("_process"))},{_process:34}],115:[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}}},{}],116:[function(e,t,r){(function(e){t.exports=r;function r(e,t){if(!(this instanceof r))return new r(e,t);if(!t)t={};this.chunkLength=Number(e);if(!this.chunkLength)throw new Error("First argument must be a chunk length");this.chunks=[];this.closed=false;this.length=Number(t.length)||Infinity;if(this.length!==Infinity){this.lastChunkLength=this.length%this.chunkLength||this.chunkLength;this.lastChunkIndex=Math.ceil(this.length/this.chunkLength)-1}}r.prototype.put=function(e,t,r){if(this.closed)return n(r,new Error("Storage is closed"));var i=e===this.lastChunkIndex;if(i&&t.length!==this.lastChunkLength){return n(r,new Error("Last chunk length must be "+this.lastChunkLength))}if(!i&&t.length!==this.chunkLength){return n(r,new Error("Chunk length must be "+this.chunkLength))}this.chunks[e]=t;n(r,null)};r.prototype.get=function(e,t,r){if(typeof t==="function")return this.get(e,null,t);if(this.closed)return n(r,new Error("Storage is closed"));var i=this.chunks[e];if(!i)return n(r,new Error("Chunk not found"));if(!t)return n(r,null,i);var o=t.offset||0;var s=t.length||i.length-o;n(r,null,i.slice(o,s+o))};r.prototype.close=r.prototype.destroy=function(e){if(this.closed)return n(e,new Error("Storage is closed"));this.closed=true;this.chunks=null;n(e,null)};function n(t,r,n){e.nextTick(function(){if(t)t(r,n)})}}).call(this,e("_process"))},{_process:34}],117:[function(e,t,r){t.exports=o;var n=e("inherits");var i=e("stream");n(o,i.Readable);function o(e,t){if(!(this instanceof o))return new o(e,t);i.Readable.call(this,t);this.destroyed=false;this._drained=false;this._forwarding=false;this._current=null;this._queue=typeof e==="function"?e:e.map(s);this._next()}o.obj=function(e){return new o(e,{objectMode:true,highWaterMark:16})};o.prototype._read=function(){this._drained=true;this._forward()};o.prototype._forward=function(){if(this._forwarding||!this._drained||!this._current)return;this._forwarding=true;var e;while((e=this._current.read())!==null){this._drained=this.push(e)}this._forwarding=false};o.prototype.destroy=function(e){if(this.destroyed)return;this.destroyed=true;if(this._current&&this._current.destroy)this._current.destroy();if(typeof this._queue!=="function"){this._queue.forEach(function(e){if(e.destroy)e.destroy()})}if(e)this.emit("error",e);this.emit("close")};o.prototype._next=function(){var e=this;e._current=null;if(typeof e._queue==="function"){e._queue(function(t,r){if(t)return e.destroy(t);e._gotNextStream(s(r))})}else{var t=e._queue.shift();if(typeof t==="function")t=s(t());e._gotNextStream(t)}};o.prototype._gotNextStream=function(e){var t=this;if(!e){t.push(null);t.destroy();return}t._current=e;t._forward();e.on("readable",r);e.on("end",i);e.on("error",o);e.on("close",n);function r(){t._forward()}function n(){if(!e._readableState.ended){t.destroy()}}function i(){t._current=null;e.removeListener("readable",r);e.removeListener("end",i);e.removeListener("error",o);e.removeListener("close",n);t._next()}function o(e){t.destroy(e)}};function s(e){if(!e||typeof e==="function"||e._readableState)return e;var t=(new i.Readable).wrap(e);if(e.destroy){t.destroy=e.destroy.bind(e)}return t}},{inherits:115,stream:52}],118:[function(e,t,r){(function(r,n){t.exports=u;t.exports.remote=c;var i=e("blob-to-buffer");var o=e("fs");var s=e("simple-get");var a=e("magnet-uri");var f=e("parse-torrent-file");t.exports.toMagnetURI=a.encode;t.exports.toTorrentFile=f.encode;function u(e){if(typeof e==="string"&&/magnet:/.test(e)){return a(e)}else if(typeof e==="string"&&(/^[a-f0-9]{40}$/i.test(e)||/^[a-z2-7]{32}$/i.test(e))){return a("magnet:?xt=urn:btih:"+e)}else if(r.isBuffer(e)&&e.length===20){return a("magnet:?xt=urn:btih:"+e.toString("hex"))}else if(r.isBuffer(e)){return f(e)}else if(e&&e.infoHash){if(!e.announce)e.announce=[];if(typeof e.announce==="string"){e.announce=[e.announce]}if(!e.urlList)e.urlList=[];return e}else{throw new Error("Invalid torrent identifier")}}function c(e,t){var r;if(typeof t!=="function")throw new Error("second argument must be a Function");try{r=u(e)}catch(a){}if(r&&r.infoHash){n.nextTick(function(){t(null,r)})}else if(l(e)){i(e,function(e,r){if(e)return t(new Error("Error converting Blob: "+e.message));f(r)})}else if(typeof s==="function"&&/^https?:/.test(e)){s.concat({url:e,headers:{"user-agent":"WebTorrent (http://webtorrent.io)"}},function(e,r){if(e)return t(new Error("Error downloading torrent: "+e.message));f(r)})}else if(typeof o.readFile==="function"&&typeof e==="string"){o.readFile(e,function(e,r){if(e)return t(new Error("Invalid torrent identifier"));f(r)})}else{n.nextTick(function(){t(new Error("Invalid torrent identifier"))})}function f(e){try{r=u(e)}catch(n){return t(n)}if(r&&r.infoHash)t(null,r);else t(new Error("Invalid torrent identifier"))}}function l(e){return typeof Blob!=="undefined"&&e instanceof Blob}}).call(this,{isBuffer:e("../browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js")},e("_process"))},{"../browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js":31,_process:34,"blob-to-buffer":119,fs:23,"magnet-uri":120,"parse-torrent-file":123,"simple-get":185}],119:[function(e,t,r){(function(e){t.exports=function r(t,n){if(typeof Blob==="undefined"||!(t instanceof Blob)){throw new Error("first argument must be a Blob")}if(typeof n!=="function"){throw new Error("second argument must be a function")}var i=new FileReader;function o(t){i.removeEventListener("loadend",o,false);if(t.error)n(t.error);else n(null,new e(i.result))}i.addEventListener("loadend",o,false);i.readAsArrayBuffer(t)}}).call(this,e("buffer").Buffer)},{buffer:25}],120:[function(e,t,r){(function(r){t.exports=s;t.exports.decode=s;t.exports.encode=a;var n=e("thirty-two");var i=e("xtend");var o=e("uniq");function s(e){var t={};var i=e.split("magnet:?")[1];var s=i&&i.length>=0?i.split("&"):[];s.forEach(function(e){var r=e.split("=");if(r.length!==2)return;var n=r[0];var i=r[1];if(n==="dn")i=decodeURIComponent(i).replace(/\+/g," ");if(n==="tr"||n==="xs"||n==="as"||n==="ws"){i=decodeURIComponent(i)}if(n==="kt")i=decodeURIComponent(i).split("+");if(t[n]){if(Array.isArray(t[n])){t[n].push(i)}else{var o=t[n];t[n]=[o,i]}}else{t[n]=i}});var a;if(t.xt){var f=Array.isArray(t.xt)?t.xt:[t.xt];f.forEach(function(e){if(a=e.match(/^urn:btih:(.{40})/)){t.infoHash=a[1].toLowerCase()}else if(a=e.match(/^urn:btih:(.{32})/)){var i=n.decode(a[1]);t.infoHash=new r(i,"binary").toString("hex")}})}if(t.infoHash)t.infoHashBuffer=new r(t.infoHash,"hex");if(t.dn)t.name=t.dn;if(t.kt)t.keywords=t.kt;if(typeof t.tr==="string")t.announce=[t.tr];else if(Array.isArray(t.tr))t.announce=t.tr;else t.announce=[];t.urlList=[];if(typeof t.as==="string"||Array.isArray(t.as)){t.urlList=t.urlList.concat(t.as)}if(typeof t.ws==="string"||Array.isArray(t.ws)){t.urlList=t.urlList.concat(t.ws)}o(t.announce);o(t.urlList);return t}function a(e){e=i(e);if(e.infoHashBuffer)e.xt="urn:btih:"+e.infoHashBuffer.toString("hex");if(e.infoHash)e.xt="urn:btih:"+e.infoHash;if(e.name)e.dn=e.name;if(e.keywords)e.kt=e.keywords;if(e.announce)e.tr=e.announce;if(e.urlList){e.ws=e.urlList;delete e.as}var t="magnet:?";Object.keys(e).filter(function(e){return e.length===2}).forEach(function(r,n){var i=Array.isArray(e[r])?e[r]:[e[r]];i.forEach(function(e,i){if((n>0||i>0)&&(r!=="kt"||i===0))t+="&";if(r==="dn")e=encodeURIComponent(e).replace(/%20/g,"+");if(r==="tr"||r==="xs"||r==="as"||r==="ws"){e=encodeURIComponent(e)}if(r==="kt")e=encodeURIComponent(e);if(r==="kt"&&i>0)t+="+"+e;else t+=r+"="+e})});return t}}).call(this,e("buffer").Buffer)},{buffer:25,"thirty-two":121,uniq:204,xtend:210}],121:[function(e,t,r){var n=e("./thirty-two");r.encode=n.encode;r.decode=n.decode},{"./thirty-two":122}],122:[function(e,t,r){(function(e){var t="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";var n=[255,255,26,27,28,29,30,31,255,255,255,255,255,255,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,255,255,255,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,255,255,255,255,255];function i(e){var t=Math.floor(e.length/5);return e.length%5==0?t:t+1}r.encode=function(r){if(!e.isBuffer(r)){r=new e(r)}var n=0;var o=0;var s=0;var a=0;var f=new e(i(r)*8);while(n3){a=u&255>>s;s=(s+5)%8;a=a<>8-s;n++}else{a=u>>8-(s+5)&31;s=(s+5)%8;if(s==0)n++}f[o]=t.charCodeAt(a);o++}for(n=o;n>>r;a[s]=o;s++;o=255&i<<8-r}}else{throw new Error("Invalid input - it is not base32 encoded string")}}return a.slice(0,s)}}).call(this,e("buffer").Buffer)},{buffer:25}],123:[function(e,t,r){(function(r){t.exports=a;t.exports.decode=a;t.exports.encode=f;var n=e("bencode");var i=e("path");var o=e("simple-sha1");var s=e("uniq");function a(e){if(r.isBuffer(e)){e=n.decode(e)}l(e.info,"info");l(e.info["name.utf-8"]||e.info.name,"info.name");l(e.info["piece length"],"info['piece length']");l(e.info.pieces,"info.pieces");if(e.info.files){e.info.files.forEach(function(e){l(typeof e.length==="number","info.files[0].length");l(e["path.utf-8"]||e.path,"info.files[0].path")})}else{l(typeof e.info.length==="number","info.length")}var t={};t.info=e.info;t.infoBuffer=n.encode(e.info);t.infoHash=o.sync(t.infoBuffer);t.infoHashBuffer=new r(t.infoHash,"hex");t.name=(e.info["name.utf-8"]||e.info.name).toString();if(e.info.private!==undefined)t.private=!!e.info.private;if(e["creation date"])t.created=new Date(e["creation date"]*1e3);if(e["created by"])t.createdBy=e["created by"].toString();if(r.isBuffer(e.comment))t.comment=e.comment.toString();t.announce=[];if(e["announce-list"]&&e["announce-list"].length){e["announce-list"].forEach(function(e){e.forEach(function(e){t.announce.push(e.toString())})})}else if(e.announce){t.announce.push(e.announce.toString())}if(r.isBuffer(e["url-list"])){e["url-list"]=e["url-list"].length>0?[e["url-list"]]:[]}t.urlList=(e["url-list"]||[]).map(function(e){return e.toString()});s(t.announce);s(t.urlList);var a=e.info.files||[e.info];t.files=a.map(function(e,r){var n=[].concat(t.name,e["path.utf-8"]||e.path||[]).map(function(e){return e.toString()});return{path:i.join.apply(null,[i.sep].concat(n)).slice(1),name:n[n.length-1],length:e.length,offset:a.slice(0,r).reduce(u,0)}});t.length=a.reduce(u,0);var f=t.files[t.files.length-1];t.pieceLength=e.info["piece length"];t.lastPieceLength=(f.offset+f.length)%t.pieceLength||t.pieceLength;t.pieces=c(e.info.pieces);return t}function f(e){var t={info:e.info};t["announce-list"]=e.announce.map(function(e){if(!t.announce)t.announce=e;e=new r(e,"utf8");return[e]});if(e.created){t["creation date"]=e.created.getTime()/1e3|0}if(e.urlList){t["url-list"]=e.urlList}return n.encode(t)}function u(e,t){return e+t.length}function c(e){var t=[];for(var r=0;r0;return c(i,s,a,function(e){if(!r)r=e;if(e)n.forEach(l);if(s)return;n.forEach(l);t(r)})});return e.reduce(d)};t.exports=h},{"end-of-stream":110,fs:23,once:130}],129:[function(e,t,r){arguments[4][19][0].apply(r,arguments)},{dup:19}],130:[function(e,t,r){arguments[4][20][0].apply(r,arguments)},{dup:20,wrappy:129}],131:[function(e,t,r){var n=function(e){var t=0;return function(){if(t===e.length)return null;var r=e.length-t;var n=Math.random()*r|0;var i=e[t+n];var o=e[t];e[t]=i;e[t+n]=o;t++;return i}};t.exports=n},{}],132:[function(e,t,r){t.exports=i;t.exports.filter=o;var n=e("events").EventEmitter;function i(e,t,r){if(!Array.isArray(r))r=[r];var n=[];r.forEach(function(r){var i=function(){var e=[].slice.call(arguments);e.unshift(r);t.emit.apply(t,e)};n.push(i);e.on(r,i)});return function i(){r.forEach(function(t,r){e.removeListener(t,n[r])})}}function o(e,t){var r=new n;i(e,r,t);return r}},{events:29}],133:[function(e,t,r){arguments[4][40][0].apply(r,arguments)},{"./_stream_readable":135,"./_stream_writable":137,"core-util-is":138,dup:40,inherits:115,"process-nextick-args":140}],134:[function(e,t,r){arguments[4][41][0].apply(r,arguments)},{"./_stream_transform":136,"core-util-is":138,dup:41,inherits:115}],135:[function(e,t,r){arguments[4][42][0].apply(r,arguments)},{"./_stream_duplex":133,_process:34,buffer:25,"core-util-is":138,dup:42,events:29,inherits:115,isarray:139,"process-nextick-args":140,"string_decoder/":141,util:24}],136:[function(e,t,r){arguments[4][43][0].apply(r,arguments)},{"./_stream_duplex":133,"core-util-is":138,dup:43,inherits:115}],137:[function(e,t,r){arguments[4][44][0].apply(r,arguments)},{"./_stream_duplex":133,buffer:25,"core-util-is":138,dup:44,events:29,inherits:115,"process-nextick-args":140,"util-deprecate":142}],138:[function(e,t,r){(function(e){function t(e){if(Array.isArray){return Array.isArray(e)}return v(e)==="[object Array]"}r.isArray=t;function n(e){return typeof e==="boolean"}r.isBoolean=n;function i(e){return e===null}r.isNull=i;function o(e){return e==null}r.isNullOrUndefined=o;function s(e){return typeof e==="number"}r.isNumber=s;function a(e){return typeof e==="string"}r.isString=a;function f(e){return typeof e==="symbol"}r.isSymbol=f;function u(e){return e===void 0}r.isUndefined=u;function c(e){return v(e)==="[object RegExp]"}r.isRegExp=c;function l(e){return typeof e==="object"&&e!==null}r.isObject=l;function d(e){return v(e)==="[object Date]"}r.isDate=d;function h(e){return v(e)==="[object Error]"||e instanceof Error}r.isError=h;function p(e){return typeof e==="function"}r.isFunction=p;function m(e){return e===null||typeof e==="boolean"||typeof e==="number"||typeof e==="string"||typeof e==="symbol"||typeof e==="undefined"}r.isPrimitive=m;r.isBuffer=e.isBuffer;function v(e){return Object.prototype.toString.call(e)}}).call(this,{isBuffer:e("../../../../browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js")})},{"../../../../browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js":31}],139:[function(e,t,r){arguments[4][32][0].apply(r,arguments)},{dup:32}],140:[function(e,t,r){arguments[4][46][0].apply(r,arguments)},{_process:34,dup:46}],141:[function(e,t,r){arguments[4][59][0].apply(r,arguments)},{buffer:25,dup:59}],142:[function(e,t,r){arguments[4][47][0].apply(r,arguments)},{dup:47}],143:[function(e,t,r){arguments[4][49][0].apply(r,arguments)},{"./lib/_stream_duplex.js":133,"./lib/_stream_passthrough.js":134,"./lib/_stream_readable.js":135,"./lib/_stream_transform.js":136,"./lib/_stream_writable.js":137,dup:49}],144:[function(e,t,r){(function(t){r.render=y;r.append=_;var n=r.mime=e("./lib/mime.json");var i=e("debug")("render-media");var o=e("is-ascii");var s=e("mediasource");var a=e("path");var f=e("stream-to-blob-url");var u=e("videostream");var c=[".mp4",".m4v",".m4a"];var l=[".mp4",".m4v",".webm"];var d=[".m4a",".mp3"];var h=l.concat(d);var p=[".wav",".aac",".ogg",".oga"];var m=[".jpg",".jpeg",".png",".gif",".bmp"];var v=[".css",".html",".js",".md",".pdf",".txt"];var g=typeof window!=="undefined"&&window.MediaSource;function y(e,t,r){x(e);if(typeof t==="string")t=document.querySelector(t);b(e,function(r){if(t.nodeName!==r.toUpperCase()){var n=a.extname(e.name).toLowerCase();throw new Error('Cannot render "'+n+'" inside a "'+t.nodeName.toLowerCase()+'" element, expected "'+r+'"')}return t},r)}function _(e,t,r){if(!r)r=function(){};x(e);if(typeof t==="string")t=document.querySelector(t);if(t&&(t.nodeName==="VIDEO"||t.nodeName==="AUDIO")){throw new Error("Invalid video/audio node argument. Argument must be root element that "+"video/audio tag will be appended to.")}b(e,function(e){if(e==="video"||e==="audio")return n(e);else return i(e)},function(e,t){if(e&&t)t.remove();r(e,t)});function n(e){var r=i(e);r.controls=true;r.autoplay=true;r.play();t.appendChild(r);return r}function i(e){var r=document.createElement(e);t.appendChild(r);return r}}function b(e,t,r){if(!r)r=function(){};var n=a.extname(e.name).toLowerCase();var f=0;var d;if(h.indexOf(n)>=0){y()}else if(p.indexOf(n)>=0){b()}else if(m.indexOf(n)>=0){x()}else if(v.indexOf(n)>=0){S()}else{B()}function y(){if(!g){return w(r,new Error("Video/audio streaming is not supported in your browser. You can still share "+"or download "+e.name+" (once it's fully downloaded). Use Chrome for "+"MediaSource support."))}var o=l.indexOf(n)>=0?"video":"audio";if(c.indexOf(n)>=0)a();else h();function a(){i("Use `videostream` package for "+e.name);y();d.addEventListener("error",m);d.addEventListener("playing",_);u(e,d)}function h(){i("Use MediaSource API for "+e.name);y();d.addEventListener("error",v);d.addEventListener("playing",_);var t=new s(d);var r=t.createWriteStream(k(e.name));e.createReadStream().pipe(r);if(f)d.currentTime=f}function p(){i("Use Blob URL for "+e.name);y();d.addEventListener("error",I);d.addEventListener("playing",_);E(e,function(e,t){if(e)return I(e);d.src=t;if(f)d.currentTime=f})}function m(e){i("videostream error: fallback to MediaSource API: %o",e.message||e);d.removeEventListener("error",m);d.removeEventListener("playing",_);h()}function v(e){i("MediaSource API error: fallback to Blob URL: %o",e.message||e);d.removeEventListener("error",v);d.removeEventListener("playing",_);p()}function y(){if(!d){d=t(o);d.addEventListener("progress",function(){f=d.currentTime})}}}function _(){d.removeEventListener("playing",_);r(null,d)}function b(){d=t("audio");E(e,function(e,t){if(e)return I(e);d.addEventListener("error",I);d.addEventListener("playing",_);d.src=t})}function x(){d=t("img");E(e,function(t,n){if(t)return I(t);d.src=n;d.alt=e.name;r(null,d)})}function S(){d=t("iframe");E(e,function(e,t){if(e)return I(e);d.src=t;if(n!==".pdf")d.sandbox="allow-forms allow-scripts";r(null,d)})}function B(){i('Unknown file extension "%s" - will attempt to render into iframe',n);var t="";e.createReadStream({start:0,end:1e3}).setEncoding("utf8").on("data",function(e){t+=e}).on("end",s).on("error",r);function s(){if(o(t)){i('File extension "%s" appears ascii, so will render.',n);S()}else{i('File extension "%s" appears non-ascii, will not render.',n);r(new Error('Unsupported file type "'+n+'": Cannot append to DOM'))}}}function I(t){t.message='Error rendering file "'+e.name+'": '+t.message;i(t.message);r(t)}}function w(e,r,n){t.nextTick(function(){e(r,n)})}function E(e,t){var r=a.extname(e.name).toLowerCase();f(e.createReadStream(),n[r],t)}function x(e){if(e==null){throw new Error("file cannot be null or undefined")}if(typeof e.name!=="string"){throw new Error("missing or invalid file.name property")}if(typeof e.createReadStream!=="function"){throw new Error("missing or invalid file.createReadStream property")}}function k(e){var t=a.extname(e).toLowerCase();return{".m4a":'audio/mp4; codecs="mp4a.40.5"',".m4v":'video/mp4; codecs="avc1.640029, mp4a.40.5"',".mp3":"audio/mpeg",".mp4":'video/mp4; codecs="avc1.640029, mp4a.40.5"',".webm":'video/webm; codecs="vorbis, vp8"'}[t]}}).call(this,e("_process"))},{"./lib/mime.json":145,_process:34,debug:107,"is-ascii":146,mediasource:147,path:33,"stream-to-blob-url":196,videostream:182}],145:[function(e,t,r){t.exports={".3gp":"video/3gpp",".aac":"audio/aac",".aif":"audio/x-aiff",".aiff":"audio/x-aiff",".atom":"application/atom+xml",".avi":"video/x-msvideo",".bmp":"image/bmp",".bz2":"application/x-bzip2",".conf":"text/plain",".css":"text/css",".csv":"text/csv",".diff":"text/x-diff",".doc":"application/msword",".flv":"video/x-flv",".gif":"image/gif",".gz":"application/x-gzip",".htm":"text/html",".html":"text/html",".ico":"image/vnd.microsoft.icon",".ics":"text/calendar",".iso":"application/octet-stream",".jar":"application/java-archive",".jpeg":"image/jpeg",".jpg":"image/jpeg",".js":"application/javascript",".json":"application/json",".less":"text/css",".log":"text/plain",".m3u":"audio/x-mpegurl",".m4a":"audio/mp4",".m4v":"video/mp4",".manifest":"text/cache-manifest",".markdown":"text/x-markdown",".mathml":"application/mathml+xml",".md":"text/x-markdown",".mid":"audio/midi",".midi":"audio/midi",".mov":"video/quicktime",".mp3":"audio/mpeg",".mp4":"video/mp4",".mp4v":"video/mp4",".mpeg":"video/mpeg",".mpg":"video/mpeg", ".odp":"application/vnd.oasis.opendocument.presentation",".ods":"application/vnd.oasis.opendocument.spreadsheet",".odt":"application/vnd.oasis.opendocument.text",".oga":"audio/ogg",".ogg":"application/ogg",".pdf":"application/pdf",".png":"image/png",".pps":"application/vnd.ms-powerpoint",".ppt":"application/vnd.ms-powerpoint",".ps":"application/postscript",".psd":"image/vnd.adobe.photoshop",".qt":"video/quicktime",".rar":"application/x-rar-compressed",".rdf":"application/rdf+xml",".rss":"application/rss+xml",".rtf":"application/rtf",".svg":"image/svg+xml",".svgz":"image/svg+xml",".swf":"application/x-shockwave-flash",".tar":"application/x-tar",".tbz":"application/x-bzip-compressed-tar",".text":"text/plain",".tif":"image/tiff",".tiff":"image/tiff",".torrent":"application/x-bittorrent",".ttf":"application/x-font-ttf",".txt":"text/plain",".wav":"audio/wav",".webm":"video/webm",".wma":"audio/x-ms-wma",".wmv":"video/x-ms-wmv",".xls":"application/vnd.ms-excel",".xml":"application/xml",".yaml":"text/yaml",".yml":"text/yaml",".zip":"application/zip"}},{}],146:[function(e,t,r){var n=127;t.exports=function i(e){for(var t=0,r=e.length;tn)return false}return true}},{}],147:[function(e,t,r){t.exports=f;var n=e("inherits");var i=e("readable-stream");var o=e("to-arraybuffer");var s=typeof window!=="undefined"&&window.MediaSource;var a=60;function f(e,t){var r=this;if(!(r instanceof f))return new f(e,t);if(!s)throw new Error("web browser lacks MediaSource support");if(!t)t={};r._bufferDuration=t.bufferDuration||a;r._elem=e;r._mediaSource=new s;r._streams=[];r.detailedError=null;r._errorHandler=function(){r._elem.removeEventListener("error",r._errorHandler);var e=r._streams.slice();e.forEach(function(e){e.destroy(r._elem.error)})};r._elem.addEventListener("error",r._errorHandler);r._elem.src=window.URL.createObjectURL(r._mediaSource)}f.prototype.createWriteStream=function(e){var t=this;return new u(t,e)};f.prototype.error=function(e){var t=this;if(!t.detailedError){t.detailedError=e}try{t._mediaSource.endOfStream("decode")}catch(e){}};n(u,i.Writable);function u(e,t){var r=this;i.Writable.call(r);r._wrapper=e;r._elem=e._elem;r._mediaSource=e._mediaSource;r._allStreams=e._streams;r._allStreams.push(r);r._bufferDuration=e._bufferDuration;r._openHandler=r._onSourceOpen.bind(r,t);r._flowHandler=r._flow.bind(r);if(typeof t==="string"){if(r._mediaSource.readyState==="open"){r._createSourceBuffer(t)}else{r._mediaSource.addEventListener("sourceopen",r._openHandler)}}else if(t._sourceBuffer){t.destroy();r._sourceBuffer=t._sourceBuffer;r._sourceBuffer.addEventListener("updateend",r._flowHandler)}else{throw new Error("The argument to MediaElementWrapper.createWriteStream must be a string or a previous stream returned from that function")}r._elem.addEventListener("timeupdate",r._flowHandler);r.on("error",r._wrapper.error.bind(r._wrapper));r.on("finish",function(){if(r.destroyed)return;r._finished=true;if(r._allStreams.every(function(e){return e._finished})){try{r._mediaSource.endOfStream()}catch(e){}}})}u.prototype._onSourceOpen=function(e){var t=this;if(t.destroyed)return;t._mediaSource.removeEventListener("sourceopen",t._openHandler);t._createSourceBuffer(e)};u.prototype.destroy=function(e){var t=this;if(t.destroyed)return;t.destroyed=true;t._allStreams.splice(t._allStreams.indexOf(t),1);t._mediaSource.removeEventListener("sourceopen",t._openHandler);t._elem.removeEventListener("timeupdate",t._flowHandler);if(t._sourceBuffer){t._sourceBuffer.removeEventListener("updateend",t._flowHandler);if(t._mediaSource.readyState==="open"){t._sourceBuffer.abort()}}if(e)t.emit("error",e);t.emit("close")};u.prototype._createSourceBuffer=function(e){var t=this;if(t.destroyed)return;if(s.isTypeSupported(e)){t._sourceBuffer=t._mediaSource.addSourceBuffer(e);t._sourceBuffer.addEventListener("updateend",t._flowHandler);if(t._cb){var r=t._cb;t._cb=null;r()}}else{t.destroy(new Error("The provided type is not supported"))}};u.prototype._write=function(e,t,r){var n=this;if(n.destroyed)return;if(!n._sourceBuffer){n._cb=function(i){if(i)return r(i);n._write(e,t,r)};return}if(n._sourceBuffer.updating){return r(new Error("Cannot append buffer while source buffer updating"))}try{n._sourceBuffer.appendBuffer(o(e))}catch(i){n.destroy(i);return}n._cb=r};u.prototype._flow=function(){var e=this;if(e.destroyed||!e._sourceBuffer||e._sourceBuffer.updating){return}if(e._mediaSource.readyState==="open"){if(e._getBufferDuration()>e._bufferDuration){return}}if(e._cb){var t=e._cb;e._cb=null;t()}};var c=0;u.prototype._getBufferDuration=function(){var e=this;var t=e._sourceBuffer.buffered;var r=e._elem.currentTime;var n=-1;for(var i=0;ir){break}else if(n>=0||r<=s){n=s}}var a=n-r;if(a<0){a=0}return a}},{inherits:115,"readable-stream":158,"to-arraybuffer":159}],148:[function(e,t,r){arguments[4][40][0].apply(r,arguments)},{"./_stream_readable":150,"./_stream_writable":152,"core-util-is":153,dup:40,inherits:115,"process-nextick-args":155}],149:[function(e,t,r){arguments[4][41][0].apply(r,arguments)},{"./_stream_transform":151,"core-util-is":153,dup:41,inherits:115}],150:[function(e,t,r){arguments[4][42][0].apply(r,arguments)},{"./_stream_duplex":148,_process:34,buffer:25,"core-util-is":153,dup:42,events:29,inherits:115,isarray:154,"process-nextick-args":155,"string_decoder/":156,util:24}],151:[function(e,t,r){arguments[4][43][0].apply(r,arguments)},{"./_stream_duplex":148,"core-util-is":153,dup:43,inherits:115}],152:[function(e,t,r){arguments[4][44][0].apply(r,arguments)},{"./_stream_duplex":148,buffer:25,"core-util-is":153,dup:44,events:29,inherits:115,"process-nextick-args":155,"util-deprecate":157}],153:[function(e,t,r){arguments[4][71][0].apply(r,arguments)},{"../../../../../../../../browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js":31,dup:71}],154:[function(e,t,r){arguments[4][32][0].apply(r,arguments)},{dup:32}],155:[function(e,t,r){arguments[4][46][0].apply(r,arguments)},{_process:34,dup:46}],156:[function(e,t,r){arguments[4][59][0].apply(r,arguments)},{buffer:25,dup:59}],157:[function(e,t,r){arguments[4][47][0].apply(r,arguments)},{dup:47}],158:[function(e,t,r){arguments[4][49][0].apply(r,arguments)},{"./lib/_stream_duplex.js":148,"./lib/_stream_passthrough.js":149,"./lib/_stream_readable.js":150,"./lib/_stream_transform.js":151,"./lib/_stream_writable.js":152,dup:49}],159:[function(e,t,r){arguments[4][58][0].apply(r,arguments)},{buffer:25,dup:58}],160:[function(e,t,r){var n=e("binary-search");var i=e("events");var o=e("inherits");var s=e("mp4-stream");var a=e("mp4-box-encoding");var f=e("range-slice-stream");t.exports=u;function u(e){var t=this;i.call(t);t._tracks=[];t._fragmentSequence=1;t._file=e;t._decoder=null;t._findMoov(0)}o(u,i);u.prototype._findMoov=function(e){var t=this;if(t._decoder){t._decoder.destroy()}t._decoder=s.decode();var r=t._file.createReadStream({start:e});r.pipe(t._decoder);t._decoder.once("box",function(n){if(n.type==="moov"){t._decoder.decode(function(e){r.destroy();t._processMoov(e)})}else{r.destroy();t._findMoov(e+n.length)}})};function c(e,t){var r=this;r._entries=e;r._countName=t||"count";r._index=0;r._offset=0;r.value=r._entries[0]}c.prototype.inc=function(){var e=this;e._offset++;if(e._offset>=e._entries[e._index][e._countName]){e._index++;e._offset=0}e.value=e._entries[e._index]};u.prototype._processMoov=function(e){var t=this;var r=e.traks;t._tracks=[];var n=null;var i=null;t._hasVideo=false;t._hasAudio=false;for(var o=0;o=a.stsz.entries.length){break}v++;y+=S;if(v>=k.samplesPerChunk){v=0;y=0;g++;var C=a.stsc.entries[_+1];if(C&&g+1>=C.firstChunk){_++}}b+=B;w.inc();E&&E.inc();if(A){x++}}s.mdia.mdhd.duration=0;s.tkhd.duration=0;var T=k.sampleDescriptionId;var L={type:"moov",mvhd:e.mvhd,traks:[{tkhd:s.tkhd,mdia:{mdhd:s.mdia.mdhd,hdlr:s.mdia.hdlr,elng:s.mdia.elng,minf:{vmhd:s.mdia.minf.vmhd,smhd:s.mdia.minf.smhd,dinf:s.mdia.minf.dinf,stbl:{stsd:a.stsd,stts:l(),ctts:l(),stsc:l(),stsz:l(),stco:l(),stss:l()}}}}],mvex:{mehd:{fragmentDuration:e.mvhd.duration},trexs:[{trackId:s.tkhd.trackId,defaultSampleDescriptionIndex:T,defaultSampleDuration:0,defaultSampleSize:0,defaultSampleFlags:0}]}};t._tracks.push({trackId:s.tkhd.trackId,timeScale:s.mdia.mdhd.timeScale,samples:p,currSample:null,currTime:null,moov:L,mime:h})}e.mvhd.duration=0;t._ftyp={type:"ftyp",brand:"iso5",brandVersion:0,compatibleBrands:["iso5"]};var R=t._tracks.map(function(e){return{mime:e.mime}});t.emit("ready",R)};function l(){return{version:0,flags:0,entries:[]}}u.prototype.seek=function(e,t){var r=this;if(!r._tracks){throw new Error("Not ready yet; wait for 'ready' event")}if(r._fileStream){r._fileStream.destroy();r._fileStream=null}var n=-1;r._tracks.map(function(i,o){if(i.outStream){i.outStream.destroy()}if(i.inStream){i.inStream.destroy();i.inStream=null}var a=i.outStream=s.encode();var f=r._generateFragment(o,e);if(!f){return a.finalize()}if(n===-1||f.ranges[0].start=0){var i=r._fileStream=r._file.createReadStream({start:n});r._tracks.forEach(function(e){e.inStream=new f(n);i.pipe(e.inStream)})}return r._tracks.map(function(e){return e.outStream})};u.prototype._findSampleBefore=function(e,t){var r=this;var i=r._tracks[e];var o=Math.floor(i.timeScale*t);var s=n(i.samples,o,function(e,t){var r=e.dts+e.presentationOffset;return r-t});if(s===-1){s=0}else if(s<0){s=-s-2}while(!i.samples[s].sync){s--}return s};var d=1;u.prototype._generateFragment=function(e,t){var r=this;var n=r._tracks[e];var i;if(t!==undefined){i=r._findSampleBefore(e,t)}else{i=n.currSample}if(i>=n.samples.length)return null;var o=n.samples[i].offset;var s=n.samples[i].dts;var a=0;var f=[];for(var u=i;u=n.timeScale*d){break}a+=c.size;var l=f.length-1;if(l<0||f[l].end!==c.offset){f.push({start:c.offset,end:c.offset+c.size})}else{f[l].end+=c.size}}n.currSample=u;return{moof:r._generateMoof(e,i,u),ranges:f,length:a}};u.prototype._generateMoof=function(e,t,r){var n=this;var i=n._tracks[e];var o=[];for(var s=t;s=e.length)throw new RangeError("invalid lower bound")}if(i===undefined)i=e.length-1;else{i=i|0;if(i=e.length)throw new RangeError("invalid upper bound")}while(n<=i){o=n+(i-n>>1);s=+r(e[o],t);if(s<0)n=o+1;else if(s>0)i=o-1;else return o}return~n}},{}],162:[function(e,t,r){(function(t){var n=e("./index");var i=e("./descriptor");var o=20828448e5;r.fullBoxes={};var s=["mvhd","tkhd","mdhd","vmhd","smhd","stsd","esds","stsz","stco","stss","stts","ctts","stsc","dref","elst","hdlr","mehd","trex","mfhd","tfhd","tfdt","trun"];s.forEach(function(e){r.fullBoxes[e]=true});r.ftyp={};r.ftyp.encode=function(e,n,i){n=n?n.slice(i):new t(r.ftyp.encodingLength(e));var o=e.compatibleBrands||[];n.write(e.brand,0,4,"ascii");n.writeUInt32BE(e.brandVersion,4);for(var s=0;s=8){var f=n.decode(e,a,i);s.children.push(f);s[f.type]=f;a+=f.length}return s};r.VisualSampleEntry.encodingLength=function(e){var t=78;var r=e.children||[];r.forEach(function(e){t+=n.encodingLength(e)});return t};r.avcC={};r.avcC.encode=function(e,n,i){n=n?n.slice(i):t(e.buffer.length);e.buffer.copy(n);r.avcC.encode.bytes=e.buffer.length};r.avcC.decode=function(e,r,n){e=e.slice(r,n);return{mimeCodec:e.toString("hex",1,4),buffer:new t(e)}};r.avcC.encodingLength=function(e){return e.buffer.length};r.mp4a=r.AudioSampleEntry={};r.AudioSampleEntry.encode=function(e,i,o){i=i?i.slice(o):new t(r.AudioSampleEntry.encodingLength(e));a(i,0,6);i.writeUInt16BE(e.dataReferenceIndex||0,6);a(i,8,16);i.writeUInt16BE(e.channelCount||2,16);i.writeUInt16BE(e.sampleSize||16,18);a(i,20,24);i.writeUInt32BE(e.sampleRate||0,24);var s=28;var f=e.children||[];f.forEach(function(e){n.encode(e,i,s);s+=n.encode.bytes});r.AudioSampleEntry.encode.bytes=s};r.AudioSampleEntry.decode=function(e,t,r){e=e.slice(t,r);var i=r-t;var o={dataReferenceIndex:e.readUInt16BE(6),channelCount:e.readUInt16BE(16),sampleSize:e.readUInt16BE(18),sampleRate:e.readUInt32BE(24),children:[]};var s=28;while(i-s>=8){var a=n.decode(e,s,i);o.children.push(a);o[a.type]=a;s+=a.length}return o};r.AudioSampleEntry.encodingLength=function(e){var t=28;var r=e.children||[];r.forEach(function(e){t+=n.encodingLength(e)});return t};r.esds={};r.esds.encode=function(e,n,i){n=n?n.slice(i):t(e.buffer.length);e.buffer.copy(n,0);r.esds.encode.bytes=e.buffer.length};r.esds.decode=function(e,r,n){e=e.slice(r,n);var o=i.Descriptor.decode(e,0,e.length);var s=o.tagName==="ESDescriptor"?o:{};var a=s.DecoderConfigDescriptor||{};var f=a.oti||0;var u=a.DecoderSpecificInfo||{};var c=u?(u.buffer.readUInt8(0)&248)>>3:0;var l=null;if(f){l=f.toString(16);if(c){l+="."+c}}return{mimeCodec:l,buffer:new t(e.slice(0))}};r.esds.encodingLength=function(e){return e.buffer.length};r.stsz={};r.stsz.encode=function(e,n,i){var o=e.entries||[];n=n?n.slice(i):t(r.stsz.encodingLength(e));n.writeUInt32BE(0,0);n.writeUInt32BE(o.length,4);for(var s=0;so){u=1}t.writeUInt32BE(u,r);t.write(e.type,r+4,4,"ascii");var c=r+8;if(u===1){n.encode(e.length,t,c);c+=8}if(i.fullBoxes[f]){t.writeUInt32BE(e.flags||0,c);t.writeUInt8(e.version||0,c);c+=4}if(a[f]){var l=a[f];l.forEach(function(r){if(r.length===5){var n=e[r]||[];r=r.substr(0,4);n.forEach(function(e){s._encode(e,t,c);c+=s.encode.bytes})}else if(e[r]){s._encode(e[r],t,c);c+=s.encode.bytes}});if(e.otherBoxes){e.otherBoxes.forEach(function(e){s._encode(e,t,c);c+=s.encode.bytes})}}else if(i[f]){var d=i[f].encode;d(e,t,c);c+=d.bytes}else if(e.buffer){var h=e.buffer;h.copy(t,c);c+=e.buffer.length}else{throw new Error("Either `type` must be set to a known type (not'"+f+"') or `buffer` must be set")}s.encode.bytes=c-r;return t};s.readHeaders=function(e,t,r){t=t||0;r=r||e.length;if(r-t<8){return 8}var o=e.readUInt32BE(t);var s=e.toString("ascii",t+4,t+8);var a=t+8;if(o===1){if(r-t<16){return 16}o=n.decode(e,a);a+=8}var f;var u;if(i.fullBoxes[s]){f=e.readUInt8(a);u=e.readUInt32BE(a)&16777215;a+=4}return{length:o,headersLen:a-t,contentLen:o-(a-t),type:s,version:f,flags:u}};s.decode=function(e,t,r){t=t||0;r=r||e.length;var n=s.readHeaders(e,t,r);if(!n||n.length>r-t){throw new Error("Data too short")}return s.decodeWithoutHeaders(n,e,t+n.headersLen,t+n.length)};s.decodeWithoutHeaders=function(e,r,n,o){n=n||0;o=o||r.length;var f=e.type;var u={};if(a[f]){u.otherBoxes=[];var c=a[f];var l=n;while(o-l>=8){var d=s.decode(r,l,o);l+=d.length;if(c.indexOf(d.type)>=0){u[d.type]=d}else if(c.indexOf(d.type+"s")>=0){var h=d.type+"s";var p=u[h]=u[h]||[];p.push(d)}else{u.otherBoxes.push(d)}}}else if(i[f]){var m=i[f].decode;u=m(r,n,o)}else{u.buffer=new t(r.slice(n,o))}u.length=e.length;u.contentLen=e.contentLen;u.type=e.type;u.version=e.version;u.flags=e.flags;return u};s.encodingLength=function(e){var t=e.type;var r=8;if(i.fullBoxes[t]){r+=4}if(a[t]){var n=a[t];n.forEach(function(t){if(t.length===5){var n=e[t]||[];t=t.substr(0,4);n.forEach(function(e){e.type=t;r+=s.encodingLength(e)})}else if(e[t]){var i=e[t];i.type=t;r+=s.encodingLength(i)}});if(e.otherBoxes){e.otherBoxes.forEach(function(e){r+=s.encodingLength(e)})}}else if(i[t]){r+=i[t].encodingLength(e)}else if(e.buffer){r+=e.buffer.length}else{throw new Error("Either `type` must be set to a known type (not'"+t+"') or `buffer` must be set")}if(r>o){r+=8}e.length=r;return r}}).call(this,e("buffer").Buffer)},{"./boxes":162,buffer:25,uint64be:165}],165:[function(e,t,r){(function(e){var t=4294967295;r.encodingLength=function(){return 8};r.encode=function(r,n,i){if(!n)n=new e(8);if(!i)i=0;var o=Math.floor(r/t);var s=r-o*t;n.writeUInt32BE(o,i);n.writeUInt32BE(s,i+4);return n};r.decode=function(r,n){if(!n)n=0;if(!r)r=new e(4);if(!n)n=0;var i=r.readUInt32BE(n);var o=r.readUInt32BE(n+4);return i*t+o; };r.encode.bytes=8;r.decode.bytes=8}).call(this,e("buffer").Buffer)},{buffer:25}],166:[function(e,t,r){(function(r){var n=e("readable-stream");var i=e("util");var o=e("next-event");var s=e("mp4-box-encoding");var a=new r(0);t.exports=f;function f(){if(!(this instanceof f))return new f;n.Writable.call(this);this.destroyed=false;this._pending=0;this._missing=0;this._buf=null;this._str=null;this._cb=null;this._ondrain=null;this._writeBuffer=null;this._writeCb=null;this._ondrain=null;this._kick()}i.inherits(f,n.Writable);f.prototype.destroy=function(e){if(this.destroyed)return;this.destroyed=true;if(e)this.emit("error",e);this.emit("close")};f.prototype._write=function(e,t,r){if(this.destroyed)return;var n=!this._str||!this._str._writableState.needDrain;while(e.length&&!this.destroyed){if(!this._missing){this._writeBuffer=e;this._writeCb=r;return}var i=e.length=e.length){n._position+=e.length;return r(null)}var f;if(a>e.length){n._position+=e.length;if(s===0){f=e}else{f=e.slice(s)}i=o.stream.write(f)&&i;break}n._position+=a;if(s===0&&a===e.length){f=e}else{f=e.slice(s,a)}i=o.stream.write(f)&&i;if(o.last){o.stream.end()}e=e.slice(a);n._queue.shift()}if(i){r(null)}else{o.stream.once("drain",r.bind(null,null))}};o.prototype.slice=function(e){var t=this;if(t.destroyed)return null;if(!(e instanceof Array)){e=[e]}var r=new i.PassThrough;e.forEach(function(n,i){t._queue.push({start:n.start,end:n.end,stream:r,last:i===e.length-1})});if(t._buffer){t._write(t._buffer,null,t._cb)}return r};o.prototype.destroy=function(e){var t=this;if(t.destroyed)return;t.destroyed=true;if(e)t.emit("error",e)}},{inherits:115,stream:52}],182:[function(e,t,r){var n=e("events");var i=e("inherits");var o=e("mediasource");var s=e("pump");var a=e("./mp4-remuxer");t.exports=f;function f(e,t,r){var i=this;if(!(this instanceof f))return new f(e,t,r);r=r||{};n.call(i);i._elem=t;i._elemWrapper=new o(t);i._muxer=new a(e);i._tracks=null;i._onWaiting=function(){if(i._tracks){var e=i._muxer.seek(i._elem.currentTime);i._tracks.forEach(function(t,r){t.muxed.destroy();t.muxed=e[r];t.mediaSource=i._elemWrapper.createWriteStream(t.mediaSource)});i._pump()}};i._elem.addEventListener("waiting",i._onWaiting);i._muxer.on("ready",function(e){var t=i._muxer.seek(0,true);i._tracks=e.map(function(e,r){return{muxed:t[r],mediaSource:i._elemWrapper.createWriteStream(e.mime)}});i._pump()});i._muxer.on("error",i.emit.bind(i,"error"))}i(f,n);f.prototype._pump=function(){var e=this;e._tracks.forEach(function(t){s(t.muxed,t.mediaSource,function(t){if(t&&t.message!=="premature close"){e.emit("error",t)}})})};f.prototype.destroy=function(e){var t=this;if(t.destroyed){return}t.destroyed=true;t._elem.removeEventListener("waiting",t._onWaiting);if(t._tracks){t._tracks.forEach(function(e){e.muxed.destroy()})}t._elem.src="";if(e)t.emit("error",e)}},{"./mp4-remuxer":160,events:29,inherits:115,mediasource:147,pump:128}],183:[function(e,t,r){(function(e){t.exports=function(t,r,n){if(typeof r!=="number")throw new Error("second argument must be a Number");var i,o,s,a,f;var u=true;if(Array.isArray(t)){i=[];s=o=t.length}else{a=Object.keys(t);i={};s=o=a.length}function c(t){function r(){if(n)n(t,i);n=null}if(u)e.nextTick(r);else r()}function l(e,r,n){i[e]=n;if(r)f=true;if(--s===0||r){c(r)}else if(!f&&d=300&&r.statusCode<400&&"location"in r.headers){e.url=r.headers.location;c(e);r.resume();e.maxRedirects-=1;if(e.maxRedirects>0)u(e,t);else t(new Error("too many redirects"));return}t(null,typeof a==="function"?a(r):r)});d.on("error",t);d.end(r);return d}t.exports.concat=function(e,t){return u(e,function(e,n){if(e)return t(e);var i=[];n.on("data",function(e){i.push(e)});n.on("end",function(){t(null,r.concat(i),n)})})};["get","post","put","patch","head","delete"].forEach(function(e){t.exports[e]=function(t,r){if(typeof t==="string")t={url:t};t.method=e.toUpperCase();return u(t,r)}});function c(e){var t=f.parse(e.url);if(t.hostname)e.hostname=t.hostname;if(t.port)e.port=t.port;if(t.protocol)e.protocol=t.protocol;e.path=t.path;delete e.url}}).call(this,e("buffer").Buffer)},{buffer:25,http:53,https:30,once:187,"unzip-response":24,url:60,xtend:210}],186:[function(e,t,r){arguments[4][19][0].apply(r,arguments)},{dup:19}],187:[function(e,t,r){arguments[4][20][0].apply(r,arguments)},{dup:20,wrappy:186}],188:[function(e,t,r){(function(r){t.exports=c;var n=e("debug")("simple-peer");var i=e("get-browser-rtc");var o=e("hat");var s=e("inherits");var a=e("is-typedarray");var f=e("once");var u=e("stream");s(c,u.Duplex);function c(e){var t=this;if(!(t instanceof c))return new c(e);t._debug("new peer %o",e);if(!e)e={};e.allowHalfOpen=false;if(e.highWaterMark==null)e.highWaterMark=1024*1024;u.Duplex.call(t,e);t.initiator=e.initiator||false;t.channelConfig=e.channelConfig||c.channelConfig;t.channelName=e.initiator?e.channelName||o(160):null;t.config=e.config||c.config;t.constraints=e.constraints||c.constraints;t.offerConstraints=e.offerConstraints;t.answerConstraints=e.answerConstraints;t.reconnectTimer=e.reconnectTimer||false;t.sdpTransform=e.sdpTransform||function(e){return e};t.stream=e.stream||false;t.trickle=e.trickle!==undefined?e.trickle:true;t.destroyed=false;t.connected=false;t.remoteAddress=undefined;t.remoteFamily=undefined;t.remotePort=undefined;t.localAddress=undefined;t.localPort=undefined;t._isWrtc=!!e.wrtc;t._wrtc=e.wrtc||i();if(!t._wrtc){if(typeof window==="undefined"){throw new Error("No WebRTC support: Specify `opts.wrtc` option in this environment")}else{throw new Error("No WebRTC support: Not a supported browser")}}t._maxBufferedAmount=e.highWaterMark;t._pcReady=false;t._channelReady=false;t._iceComplete=false;t._channel=null;t._pendingCandidates=[];t._chunk=null;t._cb=null;t._interval=null;t._reconnectTimeout=null;t._pc=new t._wrtc.RTCPeerConnection(t.config,t.constraints);t._pc.oniceconnectionstatechange=t._onIceConnectionStateChange.bind(t);t._pc.onsignalingstatechange=t._onSignalingStateChange.bind(t);t._pc.onicecandidate=t._onIceCandidate.bind(t);if(t.stream)t._pc.addStream(t.stream);t._pc.onaddstream=t._onAddStream.bind(t);if(t.initiator){t._setupData({channel:t._pc.createDataChannel(t.channelName,t.channelConfig)});t._pc.onnegotiationneeded=f(t._createOffer.bind(t));if(typeof window==="undefined"||!window.webkitRTCPeerConnection){t._pc.onnegotiationneeded()}}else{t._pc.ondatachannel=t._setupData.bind(t)}t.on("finish",function(){if(t.connected){setTimeout(function(){t._destroy()},100)}else{t.once("connect",function(){setTimeout(function(){t._destroy()},100)})}})}c.WEBRTC_SUPPORT=!!i();c.config={iceServers:[{url:"stun:23.21.150.121",urls:"stun:23.21.150.121"}]};c.constraints={};c.channelConfig={};Object.defineProperty(c.prototype,"bufferSize",{get:function(){var e=this;return e._channel&&e._channel.bufferedAmount||0}});c.prototype.address=function(){var e=this;return{port:e.localPort,family:"IPv4",address:e.localAddress}};c.prototype.signal=function(e){var t=this;if(t.destroyed)throw new Error("cannot signal after peer is destroyed");if(typeof e==="string"){try{e=JSON.parse(e)}catch(r){e={}}}t._debug("signal()");function n(e){try{t._pc.addIceCandidate(new t._wrtc.RTCIceCandidate(e),l,t._onError.bind(t))}catch(r){t._destroy(new Error("error adding candidate: "+r.message))}}if(e.sdp){t._pc.setRemoteDescription(new t._wrtc.RTCSessionDescription(e),function(){if(t.destroyed)return;if(t._pc.remoteDescription.type==="offer")t._createAnswer();t._pendingCandidates.forEach(n);t._pendingCandidates=[]},t._onError.bind(t))}if(e.candidate){if(t._pc.remoteDescription)n(e.candidate);else t._pendingCandidates.push(e.candidate)}if(!e.sdp&&!e.candidate){t._destroy(new Error("signal() called with invalid signal data"))}};c.prototype.send=function(e){var t=this;if(!a.strict(e)&&!(e instanceof ArrayBuffer)&&!r.isBuffer(e)&&typeof e!=="string"&&(typeof Blob==="undefined"||!(e instanceof Blob))){e=JSON.stringify(e)}if(r.isBuffer(e)&&t._isWrtc){e=new Uint8Array(e)}var n=e.length||e.byteLength||e.size;t._channel.send(e);t._debug("write: %d bytes",n)};c.prototype.destroy=function(e){var t=this;t._destroy(null,e)};c.prototype._destroy=function(e,t){var r=this;if(r.destroyed)return;if(t)r.once("close",t);r._debug("destroy (error: %s)",e&&e.message);r.readable=r.writable=false;if(!r._readableState.ended)r.push(null);if(!r._writableState.finished)r.end();r.destroyed=true;r.connected=false;r._pcReady=false;r._channelReady=false;r._chunk=null;r._cb=null;clearInterval(r._interval);clearTimeout(r._reconnectTimeout);if(r._pc){try{r._pc.close()}catch(e){}r._pc.oniceconnectionstatechange=null;r._pc.onsignalingstatechange=null;r._pc.onicecandidate=null}if(r._channel){try{r._channel.close()}catch(e){}r._channel.onmessage=null;r._channel.onopen=null;r._channel.onclose=null}r._pc=null;r._channel=null;if(e)r.emit("error",e);r.emit("close")};c.prototype._setupData=function(e){var t=this;t._channel=e.channel;t.channelName=t._channel.label;t._channel.binaryType="arraybuffer";t._channel.onmessage=t._onChannelMessage.bind(t);t._channel.onopen=t._onChannelOpen.bind(t);t._channel.onclose=t._onChannelClose.bind(t)};c.prototype._read=function(){};c.prototype._write=function(e,t,r){var n=this;if(n.destroyed)return r(new Error("cannot write after peer is destroyed"));if(n.connected){try{n.send(e)}catch(i){return n._onError(i)}if(n._channel.bufferedAmount>n._maxBufferedAmount){n._debug("start backpressure: bufferedAmount %d",n._channel.bufferedAmount);n._cb=r}else{r(null)}}else{n._debug("write before connect");n._chunk=e;n._cb=r}};c.prototype._createOffer=function(){var e=this;if(e.destroyed)return;e._pc.createOffer(function(t){if(e.destroyed)return;t.sdp=e.sdpTransform(t.sdp);e._pc.setLocalDescription(t,l,e._onError.bind(e));var r=function(){var r=e._pc.localDescription||t;e._debug("signal");e.emit("signal",{type:r.type,sdp:r.sdp})};if(e.trickle||e._iceComplete)r();else e.once("_iceComplete",r)},e._onError.bind(e),e.offerConstraints)};c.prototype._createAnswer=function(){var e=this;if(e.destroyed)return;e._pc.createAnswer(function(t){if(e.destroyed)return;t.sdp=e.sdpTransform(t.sdp);e._pc.setLocalDescription(t,l,e._onError.bind(e));var r=function(){var r=e._pc.localDescription||t;e._debug("signal");e.emit("signal",{type:r.type,sdp:r.sdp})};if(e.trickle||e._iceComplete)r();else e.once("_iceComplete",r)},e._onError.bind(e),e.answerConstraints)};c.prototype._onIceConnectionStateChange=function(){var e=this;if(e.destroyed)return;var t=e._pc.iceGatheringState;var r=e._pc.iceConnectionState;e._debug("iceConnectionStateChange %s %s",t,r);e.emit("iceConnectionStateChange",t,r);if(r==="connected"||r==="completed"){clearTimeout(e._reconnectTimeout);e._pcReady=true;e._maybeReady()}if(r==="disconnected"){if(e.reconnectTimer){clearTimeout(e._reconnectTimeout);e._reconnectTimeout=setTimeout(function(){e._destroy()},e.reconnectTimer)}else{e._destroy()}}if(r==="failed"){e._destroy()}if(r==="closed"){e._destroy()}};c.prototype._maybeReady=function(){var e=this;e._debug("maybeReady pc %s channel %s",e._pcReady,e._channelReady);if(e.connected||e._connecting||!e._pcReady||!e._channelReady)return;e._connecting=true;if(!e._pc.getStats){t([])}else if(typeof window!=="undefined"&&!!window.mozRTCPeerConnection){e._pc.getStats(null,function(e){var r=[];e.forEach(function(e){r.push(e)});t(r)},e._onError.bind(e))}else{e._pc.getStats(function(e){var r=[];e.result().forEach(function(e){var t={};e.names().forEach(function(r){t[r]=e.stat(r)});t.id=e.id;t.type=e.type;t.timestamp=e.timestamp;r.push(t)});t(r)})}function t(t){t.forEach(function(t){if(t.type==="remotecandidate"&&t.candidateType==="host"){e.remoteAddress=t.ipAddress;e.remotePort=Number(t.portNumber);e.remoteFamily="IPv4";e._debug("connect remote: %s:%s (%s)",e.remoteAddress,e.remotePort,e.remoteFamily)}else if(t.type==="localcandidate"&&t.candidateType==="host"){e.localAddress=t.ipAddress;e.localPort=Number(t.portNumber);e._debug("connect local: %s:%s",e.localAddress,e.localPort)}});e._connecting=false;e.connected=true;if(e._chunk){try{e.send(e._chunk)}catch(r){return e._onError(r)}e._chunk=null;e._debug('sent chunk from "write before connect"');var n=e._cb;e._cb=null;n(null)}e._interval=setInterval(function(){if(!e._cb||!e._channel||e._channel.bufferedAmount>e._maxBufferedAmount)return;e._debug("ending backpressure: bufferedAmount %d",e._channel.bufferedAmount);var t=e._cb;e._cb=null;t(null)},150);if(e._interval.unref)e._interval.unref();e._debug("connect");e.emit("connect")}};c.prototype._onSignalingStateChange=function(){var e=this;if(e.destroyed)return;e._debug("signalingStateChange %s",e._pc.signalingState);e.emit("signalingStateChange",e._pc.signalingState)};c.prototype._onIceCandidate=function(e){var t=this;if(t.destroyed)return;if(e.candidate&&t.trickle){t.emit("signal",{candidate:{candidate:e.candidate.candidate,sdpMLineIndex:e.candidate.sdpMLineIndex,sdpMid:e.candidate.sdpMid}})}else if(!e.candidate){t._iceComplete=true;t.emit("_iceComplete")}};c.prototype._onChannelMessage=function(e){var t=this;if(t.destroyed)return;var n=e.data;t._debug("read: %d bytes",n.byteLength||n.length);if(n instanceof ArrayBuffer){n=new r(n);t.push(n)}else{try{n=JSON.parse(n)}catch(i){}t.emit("data",n)}};c.prototype._onChannelOpen=function(){var e=this;if(e.connected||e.destroyed)return;e._debug("on channel open");e._channelReady=true;e._maybeReady()};c.prototype._onChannelClose=function(){var e=this;if(e.destroyed)return;e._debug("on channel close");e._destroy()};c.prototype._onAddStream=function(e){var t=this;if(t.destroyed)return;t._debug("on add stream");t.emit("stream",e.stream)};c.prototype._onError=function(e){var t=this;if(t.destroyed)return;t._debug("error %s",e.message||e);t._destroy(e)};c.prototype._debug=function(){var e=this;var t=[].slice.call(arguments);var r=e.channelName&&e.channelName.substring(0,7);t[0]="["+r+"] "+t[0];n.apply(null,t)};function l(){}}).call(this,e("buffer").Buffer)},{buffer:25,debug:107,"get-browser-rtc":189,hat:113,inherits:115,"is-typedarray":190,once:192,stream:52}],189:[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}},{}],190:[function(e,t,r){arguments[4][22][0].apply(r,arguments)},{dup:22}],191:[function(e,t,r){arguments[4][19][0].apply(r,arguments)},{dup:19}],192:[function(e,t,r){arguments[4][20][0].apply(r,arguments)},{dup:20,wrappy:191}],193:[function(e,t,r){var n=e("rusha");var i=new n;var o=window.crypto||window.msCrypto||{};var s=o.subtle||o.webkitSubtle;var a=i.digest.bind(i);try{s.digest({name:"sha-1"},new Uint8Array).catch(function(){s=false})}catch(f){s=false}function u(e,t){if(!s){setTimeout(t,0,a(e));return}if(typeof e==="string"){e=c(e)}s.digest({name:"sha-1"},e).then(function r(e){t(l(new Uint8Array(e)))},function n(r){t(a(e))})}function c(e){var t=e.length;var r=new Uint8Array(t);for(var n=0;n>>4).toString(16));r.push((i&15).toString(16))}return r.join("")}t.exports=u;t.exports.sync=a},{rusha:194}],194:[function(e,t,r){(function(e){(function(){var r={getDataType:function(t){if(typeof t==="string"){return"string"}if(t instanceof Array){return"array"}if(typeof e!=="undefined"&&e.Buffer&&e.Buffer.isBuffer(t)){return"buffer"}if(t instanceof ArrayBuffer){return"arraybuffer"}if(t.buffer instanceof ArrayBuffer){return"view"}if(t instanceof Blob){return"blob"}throw new Error("Unsupported data type.")}};function n(e){"use strict";var t={fill:0};var o=function(e){for(e+=9;e%64>0;e+=1);return e};var s=function(e,t){for(var r=t>>2;r>2]|=128<<24-(t%4<<3);e[((t>>2)+2&~15)+14]=r>>29;e[((t>>2)+2&~15)+15]=r<<3};var f=function(e,t,r,n,i){var o=this,s,a=i%4,f=n%4,u=n-f;if(u>0){switch(a){case 0:e[i+3|0]=o.charCodeAt(r);case 1:e[i+2|0]=o.charCodeAt(r+1);case 2:e[i+1|0]=o.charCodeAt(r+2);case 3:e[i|0]=o.charCodeAt(r+3)}}for(s=a;s>2]=o.charCodeAt(r+s)<<24|o.charCodeAt(r+s+1)<<16|o.charCodeAt(r+s+2)<<8|o.charCodeAt(r+s+3)}switch(f){case 3:e[i+u+1|0]=o.charCodeAt(r+u+2);case 2:e[i+u+2|0]=o.charCodeAt(r+u+1);case 1:e[i+u+3|0]=o.charCodeAt(r+u)}};var u=function(e,t,r,n,i){var o=this,s,a=i%4,f=n%4,u=n-f;if(u>0){switch(a){case 0:e[i+3|0]=o[r];case 1:e[i+2|0]=o[r+1];case 2:e[i+1|0]=o[r+2];case 3:e[i|0]=o[r+3]}}for(s=4-a;s>2]=o[r+s]<<24|o[r+s+1]<<16|o[r+s+2]<<8|o[r+s+3]}switch(f){case 3:e[i+u+1|0]=o[r+u+2];case 2:e[i+u+2|0]=o[r+u+1];case 1:e[i+u+3|0]=o[r+u]}};var c=function(e,t,r,n,o){var s=this,a,f=o%4,u=n%4,c=n-u;var l=new Uint8Array(i.readAsArrayBuffer(s.slice(r,r+n)));if(c>0){switch(f){case 0:e[o+3|0]=l[0];case 1:e[o+2|0]=l[1];case 2:e[o+1|0]=l[2];case 3:e[o|0]=l[3]}}for(a=4-f;a>2]=l[a]<<24|l[a+1]<<16|l[a+2]<<8|l[a+3]}switch(u){case 3:e[o+c+1|0]=l[c+2];case 2:e[o+c+2|0]=l[c+1];case 1:e[o+c+3|0]=l[c]}};var l=function(e){switch(r.getDataType(e)){case"string":return f.bind(e);case"array":return u.bind(e);case"buffer":return u.bind(e);case"arraybuffer":return u.bind(new Uint8Array(e));case"view":return u.bind(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));case"blob":return c.bind(e)}};var d=function(e,t){switch(r.getDataType(e)){case"string":return e.slice(t);case"array":return e.slice(t);case"buffer":return e.slice(t);case"arraybuffer":return e.slice(t);case"view":return e.buffer.slice(t)}};var h=function(e){var t,r,n="0123456789abcdef",i=[],o=new Uint8Array(e);for(t=0;t>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;t0){throw new Error("Chunk size must be a multiple of 128 bit")}t.maxChunkLen=e;t.padMaxChunkLen=o(e);t.heap=new ArrayBuffer(p(t.padMaxChunkLen+320+20));t.h32=new Int32Array(t.heap);t.h8=new Int8Array(t.heap);t.core=new n._core({Int32Array:Int32Array,DataView:DataView},{},t.heap);t.buffer=null};m(e||64*1024);var v=function(e,t){var r=new Int32Array(e,t+320,5);r[0]=1732584193;r[1]=-271733879;r[2]=-1732584194;r[3]=271733878;r[4]=-1009589776};var g=function(e,r){var n=o(e);var i=new Int32Array(t.heap,0,n>>2);s(i,e);a(i,e,r);return n};var y=function(e,r,n){l(e)(t.h8,t.h32,r,n,0)};var _=function(e,r,n,i,o){var s=n;if(o){s=g(n,i)}y(e,r,n);t.core.hash(s,t.padMaxChunkLen)};var b=function(e,t){var r=new Int32Array(e,t+320,5);var n=new Int32Array(5);var i=new DataView(n.buffer);i.setInt32(0,r[0],false);i.setInt32(4,r[1],false);i.setInt32(8,r[2],false);i.setInt32(12,r[3],false);i.setInt32(16,r[4],false);return n};var w=this.rawDigest=function(e){var r=e.byteLength||e.length||e.size||0;v(t.heap,t.padMaxChunkLen);var n=0,i=t.maxChunkLen,o;for(n=0;r>n+i;n+=i){_(e,n,i,r,false)}_(e,n,r-n,r,true);return b(t.heap,t.padMaxChunkLen)};this.digest=this.digestFromString=this.digestFromBuffer=this.digestFromArrayBuffer=function(e){return h(w(e).buffer)}}n._core=function s(e,t,r){"use asm";var n=new e.Int32Array(r);function i(e,t){e=e|0;t=t|0;var r=0,i=0,o=0,s=0,a=0,f=0,u=0,c=0,l=0,d=0,h=0,p=0,m=0,v=0;o=n[t+320>>2]|0;a=n[t+324>>2]|0;u=n[t+328>>2]|0;l=n[t+332>>2]|0;h=n[t+336>>2]|0;for(r=0;(r|0)<(e|0);r=r+64|0){s=o;f=a;c=u;d=l;p=h;for(i=0;(i|0)<64;i=i+4|0){v=n[r+i>>2]|0;m=((o<<5|o>>>27)+(a&u|~a&l)|0)+((v+h|0)+1518500249|0)|0;h=l;l=u;u=a<<30|a>>>2;a=o;o=m;n[e+i>>2]=v}for(i=e+64|0;(i|0)<(e+80|0);i=i+4|0){v=(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])<<1|(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])>>>31;m=((o<<5|o>>>27)+(a&u|~a&l)|0)+((v+h|0)+1518500249|0)|0;h=l;l=u;u=a<<30|a>>>2;a=o;o=m;n[i>>2]=v}for(i=e+80|0;(i|0)<(e+160|0);i=i+4|0){v=(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])<<1|(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])>>>31;m=((o<<5|o>>>27)+(a^u^l)|0)+((v+h|0)+1859775393|0)|0;h=l;l=u;u=a<<30|a>>>2;a=o;o=m;n[i>>2]=v}for(i=e+160|0;(i|0)<(e+240|0);i=i+4|0){v=(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])<<1|(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])>>>31;m=((o<<5|o>>>27)+(a&u|a&l|u&l)|0)+((v+h|0)-1894007588|0)|0;h=l;l=u;u=a<<30|a>>>2;a=o;o=m;n[i>>2]=v}for(i=e+240|0;(i|0)<(e+320|0);i=i+4|0){v=(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])<<1|(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])>>>31;m=((o<<5|o>>>27)+(a^u^l)|0)+((v+h|0)-899497514|0)|0;h=l;l=u;u=a<<30|a>>>2;a=o;o=m;n[i>>2]=v}o=o+s|0;a=a+f|0;u=u+c|0;l=l+d|0;h=h+p|0}n[t+320>>2]=o;n[t+324>>2]=a;n[t+328>>2]=u;n[t+332>>2]=l;n[t+336>>2]=h}return{hash:i}};if(typeof t!=="undefined"){t.exports=n}else if(typeof window!=="undefined"){window.Rusha=n}if(typeof FileReaderSync!=="undefined"){var i=new FileReaderSync,o=new n(4*1024*1024);self.onmessage=function a(e){var t,r=e.data.data;try{t=o.digest(r);self.postMessage({id:e.data.id,hash:t})}catch(n){self.postMessage({id:e.data.id,error:n.name})}}}})()}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],195:[function(e,t,r){var n=1;var i=65535;var o=4;var s=function(){n=n+1&i};var a=setInterval(s,1e3/o|0);if(a.unref)a.unref();t.exports=function(e){var t=o*(e||5);var r=[0];var s=1;var a=n-1&i;return function(e){var f=n-a&i;if(f>t)f=t;a=n;while(f--){if(s===t)s=0;r[s]=r[s===0?t-1:s-1];s++}if(e)r[s-1]+=e;var u=r[s-1];var c=r.lengthf){return this.emit("warning",new Error("Peer gave maliciously large metadata size"))}this._metadataSize=e.metadata_size;this._numPieces=Math.ceil(this._metadataSize/c);this._remainingRejects=this._numPieces*2;if(this._fetching){this._requestPieces()}};t.prototype.onMessage=function(e){var t,r;try{var i=e.toString();var o=i.indexOf("ee")+2;t=n.decode(i.substring(0,o));r=e.slice(o)}catch(s){return}switch(t.msg_type){case 0:this._onRequest(t.piece);break;case 1:this._onData(t.piece,r,t.total_size);break;case 2:this._onReject(t.piece);break}};t.prototype.fetch=function(){if(this._metadataComplete){return}this._fetching=true;if(this._metadataSize){this._requestPieces()}};t.prototype.cancel=function(){this._fetching=false};t.prototype.setMetadata=function(e){if(this._metadataComplete)return true;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*c;var r=t+c;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>c){return}t.copy(this.metadata,e*c);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;e0){this._requestPieces()}else{this.emit("warning",new Error("Peer sent invalid metadata"))}};return t}}).call(this,e("buffer").Buffer)},{bencode:206,bitfield:6,buffer:25,events:29,inherits:115,"simple-sha1":193}],206:[function(e,t,r){arguments[4][11][0].apply(r,arguments)},{"./lib/decode":207,"./lib/encode":209,dup:11}],207:[function(e,t,r){arguments[4][12][0].apply(r,arguments)},{"./dict":208,buffer:25,dup:12}],208:[function(e,t,r){arguments[4][13][0].apply(r,arguments)},{dup:13}],209:[function(e,t,r){arguments[4][14][0].apply(r,arguments)},{buffer:25,dup:14}],210:[function(e,t,r){t.exports=i;var n=Object.prototype.hasOwnProperty;function i(){var e={};for(var t=0;t0)return new Array(e+(/\./.test(t)?2:1)).join(r)+t;return t+""}},{}],213:[function(e,t,r){t.exports={name:"webtorrent",description:"Streaming torrent client",version:"0.73.1",author:{name:"Feross Aboukhadijeh",email:"feross@feross.org",url:"http://feross.org/"},bin:{webtorrent:"./bin/cmd.js"},browser:{"./lib/server.js":false,"bittorrent-dht/client":false,"fs-chunk-store":"memory-chunk-store","load-ip-set":false,os:false,"path-exists":false,ut_pex:false},bugs:{url:"https://github.com/feross/webtorrent/issues"},dependencies:{"addr-to-ip-port":"^1.0.1",bitfield:"^1.0.2","bittorrent-dht":"^6.0.1","bittorrent-swarm":"^6.0.0","chunk-store-stream":"^2.0.0",clivas:"^0.2.0",cpus:"^1.0.0","create-torrent":"^3.4.0",debug:"^2.1.0","end-of-stream":"^1.0.0",executable:"^3.0.0","fs-chunk-store":"^1.3.4",hat:"0.0.3","immediate-chunk-store":"^1.0.7",inherits:"^2.0.1",inquirer:"^0.11.0","load-ip-set":"^1.0.3","memory-chunk-store":"^1.2.0",mime:"^1.2.11",minimist:"^1.1.0",moment:"^2.8.3",multistream:"^2.0.2","network-address":"^1.0.0","parse-torrent":"^5.1.0","path-exists":"^2.1.0","pretty-bytes":"^3.0.0",pump:"^1.0.0","random-iterate":"^1.0.1","range-parser":"^1.0.2","re-emitter":"^1.0.0","readable-stream":"^2.0.5","render-media":"^2.0.0","run-parallel":"^1.0.0","run-parallel-limit":"^1.0.2","simple-peer":"^5.11.6","simple-sha1":"^2.0.0",speedometer:"^1.0.0","stream-to-blob-url":"^2.0.0","stream-with-known-length-to-buffer":"^1.0.0","torrent-discovery":"^5.1.0","torrent-piece":"^1.0.0",uniq:"^1.0.1",ut_metadata:"^3.0.1",ut_pex:"^1.0.1",winreg:"0.0.16",xtend:"^4.0.0","zero-fill":"^2.2.0"},devDependencies:{"bittorrent-tracker":"^7.0.0",brfs:"^1.2.0",browserify:"^13.0.0","cross-spawn-async":"^2.0.0",finalhandler:"^0.4.0","run-series":"^1.0.2","serve-static":"^1.9.3","simple-get":"^1.0.0",standard:"^6.0.1",tape:"^4.0.0","uglify-js":"^2.4.15",zuul:"^3.0.0"},homepage:"https://webtorrent.io",keywords:["bittorrent","bittorrent client","download","mad science","streaming","torrent","webrtc","webrtc data","webtorrent"],license:"MIT",main:"index.js",optionalDependencies:{"airplay-js":"^0.2.3",chromecasts:"^1.5.3",nodebmc:"0.0.6"},repository:{type:"git",url:"git://github.com/feross/webtorrent.git"},scripts:{build:"browserify -s WebTorrent -e ./ | uglifyjs -m > webtorrent.min.js","build-debug":"browserify -s WebTorrent -e ./ > webtorrent.debug.js",size:"npm run build && cat webtorrent.min.js | gzip | wc -c",test:"standard && node ./bin/test.js","test-browser":"zuul -- test/*.js test/browser/*.js","test-browser-local":"zuul --local -- test/*.js test/browser/*.js","test-node":"tape test/*.js test/node/*.js"}}},{}],214:[function(e,t,r){(function(r,n,i){t.exports=x;var o=e("create-torrent");var s=e("debug")("webtorrent");var a=e("bittorrent-dht/client");var f=e("events").EventEmitter;var u=e("xtend");var c=e("hat");var l=e("inherits");var d=e("load-ip-set");var h=e("run-parallel");var p=e("parse-torrent");var m=e("path");var v=e("simple-peer");var g=e("speedometer");var y=e("zero-fill");var _=e("./lib/torrent");t.exports.WEBRTC_SUPPORT=v.WEBRTC_SUPPORT;var b=e("./package.json").version;var w=b.match(/([0-9]+)/g).slice(0,2).map(y(2)).join("");var E="-WW"+w+"-";l(x,f);function x(e){var t=this;if(!(t instanceof x))return new x(e);f.call(t);if(!e)e={};if(!s.enabled)t.setMaxListeners(0);t.destroyed=false;t.torrentPort=e.torrentPort||0;t.tracker=e.tracker!==undefined?e.tracker:true;t._rtcConfig=e.rtcConfig;t._wrtc=e.wrtc||n.WRTC;t.torrents=[];t._downloadSpeed=g();t._uploadSpeed=g();t.maxConns=e.maxConns;t.peerId=typeof e.peerId==="string"?e.peerId:(e.peerId||new i(E+c(48))).toString("hex");t.peerIdBuffer=new i(t.peerId,"hex");t.nodeId=typeof e.nodeId==="string"?e.nodeId:e.nodeId&&e.nodeId.toString("hex")||c(160);t.nodeIdBuffer=new i(t.nodeId,"hex");if(e.dht!==false&&typeof a==="function"){t.dht=new a(u({nodeId:t.nodeId},e.dht));t.dht.listen(e.dhtPort)}s("new webtorrent (peerId %s, nodeId %s)",t.peerId,t.nodeId);if(typeof d==="function"){d(e.blocklist,{headers:{"user-agent":"WebTorrent/"+b+" (http://webtorrent.io)"}},function(e,r){if(e)return t.error("Failed to load blocklist: "+e.message);t.blocked=r;o()})}else r.nextTick(o);function o(){if(t.destroyed)return;t.ready=true;t.emit("ready")}}Object.defineProperty(x.prototype,"ratio",{get:function(){var e=this.torrents.reduce(function(e,t){return e+t.uploaded},0);var t=this.torrents.reduce(function(e,t){return e+t.downloaded},0)||1;return e/t}});Object.defineProperty(x.prototype,"downloadSpeed",{get:function(){return this._downloadSpeed()}});Object.defineProperty(x.prototype,"uploadSpeed",{get:function(){return this._uploadSpeed()}});x.prototype.get=function(e){var t=this;if(e instanceof _)return e;var r;try{r=p(e)}catch(n){}if(!r)return null;if(!r.infoHash)throw new Error("Invalid torrent identifier");for(var i=0,o=t.torrents.length;i