text: !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.P2PEngine=t():e.P2PEngine=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=21)}([function(e,t){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function r(e){return"function"==typeof e}function i(e){return"number"==typeof e}function o(e){return"object"==typeof e&&null!==e}function a(e){return void 0===e}e.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,n,i,s,u,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||o(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var l=new Error('Uncaught, unspecified "error" event. ('+t+")");throw l.context=t,l}if(n=this._events[e],a(n))return!1;if(r(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:s=Array.prototype.slice.call(arguments,1),n.apply(this,s)}else if(o(n))for(s=Array.prototype.slice.call(arguments,1),c=n.slice(),i=c.length,u=0;u<i;u++)c[u].apply(this,s);return!0},n.prototype.addListener=function(e,t){var i;if(!r(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,r(t.listener)?t.listener:t),this._events[e]?o(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,o(this._events[e])&&!this._events[e].warned&&(i=a(this._maxListeners)?n.defaultMaxListeners:this._maxListeners)&&i>0&&this._events[e].length>i&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function n(){this.removeListener(e,n),i||(i=!0,t.apply(this,arguments))}if(!r(t))throw TypeError("listener must be a function");var i=!1;return n.listener=t,this.on(e,n),this},n.prototype.removeListener=function(e,t){var n,i,a,s;if(!r(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],a=n.length,i=-1,n===t||r(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(o(n)){for(s=a;s-- >0;)if(n[s]===t||n[s].listener&&n[s].listener===t){i=s;break}if(i<0)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(i,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],r(n))this.removeListener(e,n);else if(n)for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){return this._events&&this._events[e]?r(this._events[e])?[this._events[e]]:this._events[e].slice():[]},n.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(r(t))return 1;if(t)return t.length}return 0},n.listenerCount=function(e,t){return e.listenerCount(t)}},function(e,t){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";(function(e){function r(){return o.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function i(e,t){if(r()<t)throw new RangeError("Invalid typed array length");return o.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t),e.__proto__=o.prototype):(null===e&&(e=new o(t)),e.length=t),e}function o(e,t,n){if(!(o.TYPED_ARRAY_SUPPORT||this instanceof o))return new o(e,t,n);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return c(this,e)}return a(this,e,t,n)}function a(e,t,n,r){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?d(e,t,n,r):"string"==typeof t?l(e,t,n):h(e,t)}function s(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function u(e,t,n,r){return s(t),t<=0?i(e,t):void 0!==n?"string"==typeof r?i(e,t).fill(n,r):i(e,t).fill(n):i(e,t)}function c(e,t){if(s(t),e=i(e,t<0?0:0|p(t)),!o.TYPED_ARRAY_SUPPORT)for(var n=0;n<t;++n)e[n]=0;return e}function l(e,t,n){if("string"==typeof n&&""!==n||(n="utf8"),!o.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|y(t,n);e=i(e,r);var a=e.write(t,n);return a!==r&&(e=e.slice(0,a)),e}function f(e,t){var n=t.length<0?0:0|p(t.length);e=i(e,n);for(var r=0;r<n;r+=1)e[r]=255&t[r];return e}function d(e,t,n,r){if(t.byteLength,n<0||t.byteLength<n)throw new RangeError("'offset' is out of bounds");if(t.byteLength<n+(r||0))throw new RangeError("'length' is out of bounds");return t=void 0===n&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,n):new Uint8Array(t,n,r),o.TYPED_ARRAY_SUPPORT?(e=t,e.__proto__=o.prototype):e=f(e,t),e}function h(e,t){if(o.isBuffer(t)){var n=0|p(t.length);return e=i(e,n),0===e.length?e:(t.copy(e,0,0,n),e)}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||Q(t.length)?i(e,0):f(e,t);if("Buffer"===t.type&&X(t.data))return f(e,t.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function p(e){if(e>=r())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+r().toString(16)+" bytes");return 0|e}function g(e){return+e!=e&&(e=0),o.alloc(+e)}function y(e,t){if(o.isBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var n=e.length;if(0===n)return 0;for(var r=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return Y(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return J(e).length;default:if(r)return Y(e).length;t=(""+t).toLowerCase(),r=!0}}function v(e,t,n){var r=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if(n>>>=0,t>>>=0,n<=t)return"";for(e||(e="utf8");;)switch(e){case"hex":return I(this,t,n);case"utf8":case"utf-8":return k(this,t,n);case"ascii":return O(this,t,n);case"latin1":case"binary":return L(this,t,n);case"base64":return R(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return D(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}function b(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function m(e,t,n,r,i){if(0===e.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=i?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(i)return-1;n=e.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof t&&(t=o.from(t,r)),o.isBuffer(t))return 0===t.length?-1:_(e,t,n,r,i);if("number"==typeof t)return t&=255,o.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):_(e,[t],n,r,i);throw new TypeError("val must be string, number or Buffer")}function _(e,t,n,r,i){function o(e,t){return 1===a?e[t]:e.readUInt16BE(t*a)}var a=1,s=e.length,u=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return-1;a=2,s/=2,u/=2,n/=2}var c;if(i){var l=-1;for(c=n;c<s;c++)if(o(e,c)===o(t,-1===l?0:c-l)){if(-1===l&&(l=c),c-l+1===u)return l*a}else-1!==l&&(c-=c-l),l=-1}else for(n+u>s&&(n=s-u),c=n;c>=0;c--){for(var f=!0,d=0;d<u;d++)if(o(e,c+d)!==o(t,d)){f=!1;break}if(f)return c}return-1}function w(e,t,n,r){n=Number(n)||0;var i=e.length-n;r?(r=Number(r))>i&&(r=i):r=i;var o=t.length;if(o%2!=0)throw new TypeError("Invalid hex string");r>o/2&&(r=o/2);for(var a=0;a<r;++a){var s=parseInt(t.substr(2*a,2),16);if(isNaN(s))return a;e[n+a]=s}return a}function C(e,t,n,r){return V(Y(t,e.length-n),e,n,r)}function S(e,t,n,r){return V(H(t),e,n,r)}function E(e,t,n,r){return S(e,t,n,r)}function T(e,t,n,r){return V(J(t),e,n,r)}function P(e,t,n,r){return V(G(t,e.length-n),e,n,r)}function R(e,t,n){return 0===t&&n===e.length?K.fromByteArray(e):K.fromByteArray(e.slice(t,n))}function k(e,t,n){n=Math.min(e.length,n);for(var r=[],i=t;i<n;){var o=e[i],a=null,s=o>239?4:o>223?3:o>191?2:1;if(i+s<=n){var u,c,l,f;switch(s){case 1:o<128&&(a=o);break;case 2:u=e[i+1],128==(192&u)&&(f=(31&o)<<6|63&u)>127&&(a=f);break;case 3:u=e[i+1],c=e[i+2],128==(192&u)&&128==(192&c)&&(f=(15&o)<<12|(63&u)<<6|63&c)>2047&&(f<55296||f>57343)&&(a=f);break;case 4:u=e[i+1],c=e[i+2],l=e[i+3],128==(192&u)&&128==(192&c)&&128==(192&l)&&(f=(15&o)<<18|(63&u)<<12|(63&c)<<6|63&l)>65535&&f<1114112&&(a=f)}}null===a?(a=65533,s=1):a>65535&&(a-=65536,r.push(a>>>10&1023|55296),a=56320|1023&a),r.push(a),i+=s}return A(r)}function A(e){var t=e.length;if(t<=Z)return String.fromCharCode.apply(String,e);for(var n="",r=0;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=Z));return n}function O(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;i<n;++i)r+=String.fromCharCode(127&e[i]);return r}function L(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;i<n;++i)r+=String.fromCharCode(e[i]);return r}function I(e,t,n){var r=e.length;(!t||t<0)&&(t=0),(!n||n<0||n>r)&&(n=r);for(var i="",o=t;o<n;++o)i+=W(e[o]);return i}function D(e,t,n){for(var r=e.slice(t,n),i="",o=0;o<r.length;o+=2)i+=String.fromCharCode(r[o]+256*r[o+1]);return i}function M(e,t,n){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>n)throw new RangeError("Trying to access beyond buffer length")}function x(e,t,n,r,i,a){if(!o.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<a)throw new RangeError('"value" argument is out of bounds');if(n+r>e.length)throw new RangeError("Index out of range")}function B(e,t,n,r){t<0&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-n,2);i<o;++i)e[n+i]=(t&255<<8*(r?i:1-i))>>>8*(r?i:1-i)}function U(e,t,n,r){t<0&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-n,4);i<o;++i)e[n+i]=t>>>8*(r?i:3-i)&255}function j(e,t,n,r,i,o){if(n+r>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function N(e,t,n,r,i){return i||j(e,t,n,4,3.4028234663852886e38,-3.4028234663852886e38),$.write(e,t,n,r,23,4),n+4}function F(e,t,n,r,i){return i||j(e,t,n,8,1.7976931348623157e308,-1.7976931348623157e308),$.write(e,t,n,r,52,8),n+8}function q(e){if(e=z(e).replace(ee,""),e.length<2)return"";for(;e.length%4!=0;)e+="=";return e}function z(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function W(e){return e<16?"0"+e.toString(16):e.toString(16)}function Y(e,t){t=t||1/0;for(var n,r=e.length,i=null,o=[],a=0;a<r;++a){if((n=e.charCodeAt(a))>55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(a+1===r){(t-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(n<56320){(t-=3)>-1&&o.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,n<128){if((t-=1)<0)break;o.push(n)}else if(n<2048){if((t-=2)<0)break;o.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;o.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return o}function H(e){for(var t=[],n=0;n<e.length;++n)t.push(255&e.charCodeAt(n));return t}function G(e,t){for(var n,r,i,o=[],a=0;a<e.length&&!((t-=2)<0);++a)n=e.charCodeAt(a),r=n>>8,i=n%256,o.push(i),o.push(r);return o}function J(e){return K.toByteArray(q(e))}function V(e,t,n,r){for(var i=0;i<r&&!(i+n>=t.length||i>=e.length);++i)t[i+n]=e[i];return i}function Q(e){return e!==e}var K=n(27),$=n(28),X=n(29);t.Buffer=o,t.SlowBuffer=g,t.INSPECT_MAX_BYTES=50,o.TYPED_ARRAY_SUPPORT=void 0!==e.TYPED_ARRAY_SUPPORT?e.TYPED_ARRAY_SUPPORT:function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()&&"function"==typeof e.subarray&&0===e.subarray(1,1).byteLength}catch(e){return!1}}(),t.kMaxLength=r(),o.poolSize=8192,o._augment=function(e){return e.__proto__=o.prototype,e},o.from=function(e,t,n){return a(null,e,t,n)},o.TYPED_ARRAY_SUPPORT&&(o.prototype.__proto__=Uint8Array.prototype,o.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&o[Symbol.species]===o&&Object.defineProperty(o,Symbol.species,{value:null,configurable:!0})),o.alloc=function(e,t,n){return u(null,e,t,n)},o.allocUnsafe=function(e){return c(null,e)},o.allocUnsafeSlow=function(e){return c(null,e)},o.isBuffer=function(e){return!(null==e||!e._isBuffer)},o.compare=function(e,t){if(!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var n=e.length,r=t.length,i=0,a=Math.min(n,r);i<a;++i)if(e[i]!==t[i]){n=e[i],r=t[i];break}return n<r?-1:r<n?1:0},o.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(e,t){if(!X(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return o.alloc(0);var n;if(void 0===t)for(t=0,n=0;n<e.length;++n)t+=e[n].length;var r=o.allocUnsafe(t),i=0;for(n=0;n<e.length;++n){var a=e[n];if(!o.isBuffer(a))throw new TypeError('"list" argument must be an Array of Buffers');a.copy(r,i),i+=a.length}return r},o.byteLength=y,o.prototype._isBuffer=!0,o.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)b(this,t,t+1);return this},o.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)b(this,t,t+3),b(this,t+1,t+2);return this},o.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)b(this,t,t+7),b(this,t+1,t+6),b(this,t+2,t+5),b(this,t+3,t+4);return this},o.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?k(this,0,e):v.apply(this,arguments)},o.prototype.equals=function(e){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===o.compare(this,e)},o.prototype.inspect=function(){var e="",n=t.INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(e+=" ... ")),"<Buffer "+e+">"},o.prototype.compare=function(e,t,n,r,i){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===n&&(n=e?e.length:0),void 0===r&&(r=0),void 0===i&&(i=this.length),t<0||n>e.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&t>=n)return 0;if(r>=i)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,r>>>=0,i>>>=0,this===e)return 0;for(var a=i-r,s=n-t,u=Math.min(a,s),c=this.slice(r,i),l=e.slice(t,n),f=0;f<u;++f)if(c[f]!==l[f]){a=c[f],s=l[f];break}return a<s?-1:s<a?1:0},o.prototype.includes=function(e,t,n){return-1!==this.indexOf(e,t,n)},o.prototype.indexOf=function(e,t,n){return m(this,e,t,n,!0)},o.prototype.lastIndexOf=function(e,t,n){return m(this,e,t,n,!1)},o.prototype.write=function(e,t,n,r){if(void 0===t)r="utf8",n=this.length,t=0;else if(void 0===n&&"string"==typeof t)r=t,n=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var i=this.length-t;if((void 0===n||n>i)&&(n=i),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var o=!1;;)switch(r){case"hex":return w(this,e,t,n);case"utf8":case"utf-8":return C(this,e,t,n);case"ascii":return S(this,e,t,n);case"latin1":case"binary":return E(this,e,t,n);case"base64":return T(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return P(this,e,t,n);default:if(o)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),o=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var Z=4096;o.prototype.slice=function(e,t){var n=this.length;e=~~e,t=void 0===t?n:~~t,e<0?(e+=n)<0&&(e=0):e>n&&(e=n),t<0?(t+=n)<0&&(t=0):t>n&&(t=n),t<e&&(t=e);var r;if(o.TYPED_ARRAY_SUPPORT)r=this.subarray(e,t),r.__proto__=o.prototype;else{var i=t-e;r=new o(i,void 0);for(var a=0;a<i;++a)r[a]=this[a+e]}return r},o.prototype.readUIntLE=function(e,t,n){e|=0,t|=0,n||M(e,t,this.length);for(var r=this[e],i=1,o=0;++o<t&&(i*=256);)r+=this[e+o]*i;return r},o.prototype.readUIntBE=function(e,t,n){e|=0,t|=0,n||M(e,t,this.length);for(var r=this[e+--t],i=1;t>0&&(i*=256);)r+=this[e+--t]*i;return r},o.prototype.readUInt8=function(e,t){return t||M(e,1,this.length),this[e]},o.prototype.readUInt16LE=function(e,t){return t||M(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUInt16BE=function(e,t){return t||M(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUInt32LE=function(e,t){return t||M(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},o.prototype.readUInt32BE=function(e,t){return t||M(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readIntLE=function(e,t,n){e|=0,t|=0,n||M(e,t,this.length);for(var r=this[e],i=1,o=0;++o<t&&(i*=256);)r+=this[e+o]*i;return i*=128,r>=i&&(r-=Math.pow(2,8*t)),r},o.prototype.readIntBE=function(e,t,n){e|=0,t|=0,n||M(e,t,this.length);for(var r=t,i=1,o=this[e+--r];r>0&&(i*=256);)o+=this[e+--r]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*t)),o},o.prototype.readInt8=function(e,t){return t||M(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},o.prototype.readInt16LE=function(e,t){t||M(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt16BE=function(e,t){t||M(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt32LE=function(e,t){return t||M(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},o.prototype.readInt32BE=function(e,t){return t||M(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readFloatLE=function(e,t){return t||M(e,4,this.length),$.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return t||M(e,4,this.length),$.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return t||M(e,8,this.length),$.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return t||M(e,8,this.length),$.read(this,e,!1,52,8)},o.prototype.writeUIntLE=function(e,t,n,r){if(e=+e,t|=0,n|=0,!r){x(this,e,t,n,Math.pow(2,8*n)-1,0)}var i=1,o=0;for(this[t]=255&e;++o<n&&(i*=256);)this[t+o]=e/i&255;return t+n},o.prototype.writeUIntBE=function(e,t,n,r){if(e=+e,t|=0,n|=0,!r){x(this,e,t,n,Math.pow(2,8*n)-1,0)}var i=n-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+n},o.prototype.writeUInt8=function(e,t,n){return e=+e,t|=0,n||x(this,e,t,1,255,0),o.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},o.prototype.writeUInt16LE=function(e,t,n){return e=+e,t|=0,n||x(this,e,t,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):B(this,e,t,!0),t+2},o.prototype.writeUInt16BE=function(e,t,n){return e=+e,t|=0,n||x(this,e,t,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):B(this,e,t,!1),t+2},o.prototype.writeUInt32LE=function(e,t,n){return e=+e,t|=0,n||x(this,e,t,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):U(this,e,t,!0),t+4},o.prototype.writeUInt32BE=function(e,t,n){return e=+e,t|=0,n||x(this,e,t,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):U(this,e,t,!1),t+4},o.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t|=0,!r){var i=Math.pow(2,8*n-1);x(this,e,t,n,i-1,-i)}var o=0,a=1,s=0;for(this[t]=255&e;++o<n&&(a*=256);)e<0&&0===s&&0!==this[t+o-1]&&(s=1),this[t+o]=(e/a>>0)-s&255;return t+n},o.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t|=0,!r){var i=Math.pow(2,8*n-1);x(this,e,t,n,i-1,-i)}var o=n-1,a=1,s=0;for(this[t+o]=255&e;--o>=0&&(a*=256);)e<0&&0===s&&0!==this[t+o+1]&&(s=1),this[t+o]=(e/a>>0)-s&255;return t+n},o.prototype.writeInt8=function(e,t,n){return e=+e,t|=0,n||x(this,e,t,1,127,-128),o.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},o.prototype.writeInt16LE=function(e,t,n){return e=+e,t|=0,n||x(this,e,t,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):B(this,e,t,!0),t+2},o.prototype.writeInt16BE=function(e,t,n){return e=+e,t|=0,n||x(this,e,t,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):B(this,e,t,!1),t+2},o.prototype.writeInt32LE=function(e,t,n){return e=+e,t|=0,n||x(this,e,t,4,2147483647,-2147483648),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):U(this,e,t,!0),t+4},o.prototype.writeInt32BE=function(e,t,n){return e=+e,t|=0,n||x(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):U(this,e,t,!1),t+4},o.prototype.writeFloatLE=function(e,t,n){return N(this,e,t,!0,n)},o.prototype.writeFloatBE=function(e,t,n){return N(this,e,t,!1,n)},o.prototype.writeDoubleLE=function(e,t,n){return F(this,e,t,!0,n)},o.prototype.writeDoubleBE=function(e,t,n){return F(this,e,t,!1,n)},o.prototype.copy=function(e,t,n,r){if(n||(n=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);var i,a=r-n;if(this===e&&n<t&&t<r)for(i=a-1;i>=0;--i)e[i+t]=this[i+n];else if(a<1e3||!o.TYPED_ARRAY_SUPPORT)for(i=0;i<a;++i)e[i+t]=this[i+n];else Uint8Array.prototype.set.call(e,this.subarray(n,n+a),t);return a},o.prototype.fill=function(e,t,n,r){if("string"==typeof e){if("string"==typeof t?(r=t,t=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===e.length){var i=e.charCodeAt(0);i<256&&(e=i)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!o.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;t>>>=0,n=void 0===n?this.length:n>>>0,e||(e=0);var a;if("number"==typeof e)for(a=t;a<n;++a)this[a]=e;else{var s=o.isBuffer(e)?e:Y(new o(e,r).toString()),u=s.length;for(a=0;a<n-t;++a)this[a+t]=s[a%u]}return this};var ee=/[^+\/0-9A-Za-z-_]/g}).call(t,n(1))},function(e,t){function n(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function i(e){if(l===setTimeout)return setTimeout(e,0);if((l===n||!l)&&setTimeout)return l=setTimeout,setTimeout(e,0);try{return l(e,0)}catch(t){try{return l.call(null,e,0)}catch(t){return l.call(this,e,0)}}}function o(e){if(f===clearTimeout)return clearTimeout(e);if((f===r||!f)&&clearTimeout)return f=clearTimeout,clearTimeout(e);try{return f(e)}catch(t){try{return f.call(null,e)}catch(t){return f.call(this,e)}}}function a(){g&&h&&(g=!1,h.length?p=h.concat(p):y=-1,p.length&&s())}function s(){if(!g){var e=i(a);g=!0;for(var t=p.length;t;){for(h=p,p=[];++y<t;)h&&h[y].run();y=-1,t=p.length}h=null,g=!1,o(e)}}function u(e,t){this.fun=e,this.array=t}function c(){}var l,f,d=e.exports={};!function(){try{l="function"==typeof setTimeout?setTimeout:n}catch(e){l=n}try{f="function"==typeof clearTimeout?clearTimeout:r}catch(e){f=r}}();var h,p=[],g=!1,y=-1;d.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];p.push(new u(e,t)),1!==p.length||g||i(s)},u.prototype.run=function(){this.fun.apply(null,this.array)},d.title="browser",d.browser=!0,d.env={},d.argv=[],d.version="",d.versions={},d.on=c,d.addListener=c,d.once=c,d.off=c,d.removeListener=c,d.removeAllListeners=c,d.emit=c,d.prependListener=c,d.prependOnceListener=c,d.listeners=function(e){return[]},d.binding=function(e){throw new Error("process.binding is not supported")},d.cwd=function(){return"/"},d.chdir=function(e){throw new Error("process.chdir is not supported")},d.umask=function(){return 0}},function(e,t,n){"use strict";"function"==typeof Object.create?e.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:e.exports=function(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}},function(e,t,n){"use strict";function r(e){if(!(this instanceof r))return new r(e);c.call(this,e),l.call(this,e),e&&!1===e.readable&&(this.readable=!1),e&&!1===e.writable&&(this.writable=!1),this.allowHalfOpen=!0,e&&!1===e.allowHalfOpen&&(this.allowHalfOpen=!1),this.once("end",i)}function i(){this.allowHalfOpen||this._writableState.ended||a.nextTick(o,this)}function o(e){e.end()}var a=n(9),s=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};e.exports=r;var u=n(6);u.inherits=n(4);var c=n(12),l=n(15);u.inherits(r,c);for(var f=s(l.prototype),d=0;d<f.length;d++){var h=f[d];r.prototype[h]||(r.prototype[h]=l.prototype[h])}Object.defineProperty(r.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(r.prototype,"destroyed",{get:function(){return void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed&&this._writableState.destroyed)},set:function(e){void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed=e,this._writableState.destroyed=e)}}),r.prototype._destroy=function(e,t){this.push(null),this.end(),a.nextTick(t,e)}},function(e,t,n){"use strict";(function(e){function n(e){return Array.isArray?Array.isArray(e):"[object Array]"===y(e)}function r(e){return"boolean"==typeof e}function i(e){return null===e}function o(e){return null==e}function a(e){return"number"==typeof e}function s(e){return"string"==typeof e}function u(e){return"symbol"===(void 0===e?"undefined":v(e))}function c(e){return void 0===e}function l(e){return"[object RegExp]"===y(e)}function f(e){return"object"===(void 0===e?"undefined":v(e))&&null!==e}function d(e){return"[object Date]"===y(e)}function h(e){return"[object Error]"===y(e)||e instanceof Error}function p(e){return"function"==typeof e}function g(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"===(void 0===e?"undefined":v(e))||void 0===e}function y(e){return Object.prototype.toString.call(e)}var v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t.isArray=n,t.isBoolean=r,t.isNull=i,t.isNullOrUndefined=o,t.isNumber=a,t.isString=s,t.isSymbol=u,t.isUndefined=c,t.isRegExp=l,t.isObject=f,t.isDate=d,t.isError=h,t.isFunction=p,t.isPrimitive=g,t.isBuffer=e.isBuffer}).call(t,n(2).Buffer)},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.getBrowserRTC=t.Buffer=t.Fetcher=t.Events=t.DataChannel=void 0;var i=n(25),o=r(i),a=n(18),s=r(a),u=n(45),c=r(u),l=n(47),f=r(l),d=n(2).Buffer;t.DataChannel=o.default,t.Events=s.default,t.Fetcher=c.default,t.Buffer=d,t.getBrowserRTC=f.default},function(e,t,n){"use strict";function r(e,t){for(var n in e)t[n]=e[n]}function i(e,t,n){return a(e,t,n)}var o=n(2),a=o.Buffer;a.from&&a.alloc&&a.allocUnsafe&&a.allocUnsafeSlow?e.exports=o:(r(o,t),t.Buffer=i),r(a,i),i.from=function(e,t,n){if("number"==typeof e)throw new TypeError("Argument must not be a number");return a(e,t,n)},i.alloc=function(e,t,n){if("number"!=typeof e)throw new TypeError("Argument must be a number");var r=a(e);return void 0!==t?"string"==typeof n?r.fill(t,n):r.fill(t):r.fill(0),r},i.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return a(e)},i.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return o.SlowBuffer(e)}},function(e,t,n){"use strict";(function(t){function n(e,n,r,i){if("function"!=typeof e)throw new TypeError('"callback" argument must be a function');var o,a,s=arguments.length;switch(s){case 0:case 1:return t.nextTick(e);case 2:return t.nextTick(function(){e.call(null,n)});case 3:return t.nextTick(function(){e.call(null,n,r)});case 4:return t.nextTick(function(){e.call(null,n,r,i)});default:for(o=new Array(s-1),a=0;a<o.length;)o[a++]=arguments[a];return t.nextTick(function(){e.apply(null,o)})}}!t.version||0===t.version.indexOf("v0.")||0===t.version.indexOf("v1.")&&0!==t.version.indexOf("v1.8.")?e.exports={nextTick:n}:e.exports=t}).call(t,n(3))},function(e,t,n){"use strict";function r(e){return arguments.length>1&&void 0!==arguments[1]&&arguments[1]?e:e.split("?")[0]}function i(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:30,r=!1;return function(){r||(r=!0,setTimeout(function(){e.call(t),r=!1},1e3*n))}}function o(e,t){arguments.length>2&&void 0!==arguments[2]&&arguments[2];return s.default.parseURL(e).path.split(".")[0]+"["+t+"]"}Object.defineProperty(t,"__esModule",{value:!0}),t.handleTSUrl=r,t.throttle=i,t.defaultChannelId=o;var a=n(19),s=function(e){return e&&e.__esModule?e:{default:e}}(a)},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.config=t.FragLoader=t.Tracker=void 0;var i=n(23),o=r(i),a=n(49),s=r(a),u={announce:"https://api.cdnbye.com/v1",urgentOffset:3};t.Tracker=o.default,t.FragLoader=s.default,t.config=u},function(e,t,n){"use strict";(function(t,r){function i(e){return U.from(e)}function o(e){return U.isBuffer(e)||e instanceof j}function a(e,t,n){if("function"==typeof e.prependListener)return e.prependListener(t,n);e._events&&e._events[t]?M(e._events[t])?e._events[t].unshift(n):e._events[t]=[n,e._events[t]]:e.on(t,n)}function s(e,t){D=D||n(5),e=e||{};var r=t instanceof D;this.objectMode=!!e.objectMode,r&&(this.objectMode=this.objectMode||!!e.readableObjectMode);var i=e.highWaterMark,o=e.readableHighWaterMark,a=this.objectMode?16:16384;this.highWaterMark=i||0===i?i:r&&(o||0===o)?o:a,this.highWaterMark=Math.floor(this.highWaterMark),this.buffer=new W,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.destroyed=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(z||(z=n(16).StringDecoder),this.decoder=new z(e.encoding),this.encoding=e.encoding)}function u(e){if(D=D||n(5),!(this instanceof u))return new u(e);this._readableState=new s(e,this),this.readable=!0,e&&("function"==typeof e.read&&(this._read=e.read),"function"==typeof e.destroy&&(this._destroy=e.destroy)),B.call(this)}function c(e,t,n,r,o){var a=e._readableState;if(null===t)a.reading=!1,g(e,a);else{var s;o||(s=f(a,t)),s?e.emit("error",s):a.objectMode||t&&t.length>0?("string"==typeof t||a.objectMode||Object.getPrototypeOf(t)===U.prototype||(t=i(t)),r?a.endEmitted?e.emit("error",new Error("stream.unshift() after end event")):l(e,a,t,!0):a.ended?e.emit("error",new Error("stream.push() after EOF")):(a.reading=!1,a.decoder&&!n?(t=a.decoder.write(t),a.objectMode||0!==t.length?l(e,a,t,!1):b(e,a)):l(e,a,t,!1))):r||(a.reading=!1)}return d(a)}function l(e,t,n,r){t.flowing&&0===t.length&&!t.sync?(e.emit("data",n),e.read(0)):(t.length+=t.objectMode?1:n.length,r?t.buffer.unshift(n):t.buffer.push(n),t.needReadable&&y(e)),b(e,t)}function f(e,t){var n;return o(t)||"string"==typeof t||void 0===t||e.objectMode||(n=new TypeError("Invalid non-string/buffer chunk")),n}function d(e){return!e.ended&&(e.needReadable||e.length<e.highWaterMark||0===e.length)}function h(e){return e>=G?e=G:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function p(e,t){return e<=0||0===t.length&&t.ended?0:t.objectMode?1:e!==e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=h(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function g(e,t){if(!t.ended){if(t.decoder){var n=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.ended=!0,y(e)}}function y(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(q("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?I.nextTick(v,e):v(e))}function v(e){q("emit readable"),e.emit("readable"),E(e)}function b(e,t){t.readingMore||(t.readingMore=!0,I.nextTick(m,e,t))}function m(e,t){for(var n=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length<t.highWaterMark&&(q("maybeReadMore read 0"),e.read(0),n!==t.length);)n=t.length;t.readingMore=!1}function _(e){return function(){var t=e._readableState;q("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&x(e,"data")&&(t.flowing=!0,E(e))}}function w(e){q("readable nexttick read 0"),e.read(0)}function C(e,t){t.resumeScheduled||(t.resumeScheduled=!0,I.nextTick(S,e,t))}function S(e,t){t.reading||(q("resume read 0"),e.read(0)),t.resumeScheduled=!1,t.awaitDrain=0,e.emit("resume"),E(e),t.flowing&&!t.reading&&e.read(0)}function E(e){var t=e._readableState;for(q("flow",t.flowing);t.flowing&&null!==e.read(););}function T(e,t){if(0===t.length)return null;var n;return t.objectMode?n=t.buffer.shift():!e||e>=t.length?(n=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.head.data:t.buffer.concat(t.length),t.buffer.clear()):n=P(e,t.buffer,t.decoder),n}function P(e,t,n){var r;return e<t.head.data.length?(r=t.head.data.slice(0,e),t.head.data=t.head.data.slice(e)):r=e===t.head.data.length?t.shift():n?R(e,t):k(e,t),r}function R(e,t){var n=t.head,r=1,i=n.data;for(e-=i.length;n=n.next;){var o=n.data,a=e>o.length?o.length:e;if(a===o.length?i+=o:i+=o.slice(0,e),0===(e-=a)){a===o.length?(++r,n.next?t.head=n.next:t.head=t.tail=null):(t.head=n,n.data=o.slice(a));break}++r}return t.length-=r,i}function k(e,t){var n=U.allocUnsafe(e),r=t.head,i=1;for(r.data.copy(n),e-=r.data.length;r=r.next;){var o=r.data,a=e>o.length?o.length:e;if(o.copy(n,n.length-e,0,a),0===(e-=a)){a===o.length?(++i,r.next?t.head=r.next:t.head=t.tail=null):(t.head=r,r.data=o.slice(a));break}++i}return t.length-=i,n}function A(e){var t=e._readableState;if(t.length>0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,I.nextTick(O,t,e))}function O(e,t){e.endEmitted||0!==e.length||(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function L(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1}var I=n(9);e.exports=u;var D,M=n(36);u.ReadableState=s;var x=(n(0).EventEmitter,function(e,t){return e.listeners(t).length}),B=n(13),U=n(8).Buffer,j=t.Uint8Array||function(){},N=n(6);N.inherits=n(4);var F=n(37),q=void 0;q=F&&F.debuglog?F.debuglog("stream"):function(){};var z,W=n(38),Y=n(14);N.inherits(u,B);var H=["error","close","destroy","pause","resume"];Object.defineProperty(u.prototype,"destroyed",{get:function(){return void 0!==this._readableState&&this._readableState.destroyed},set:function(e){this._readableState&&(this._readableState.destroyed=e)}}),u.prototype.destroy=Y.destroy,u.prototype._undestroy=Y.undestroy,u.prototype._destroy=function(e,t){this.push(null),t(e)},u.prototype.push=function(e,t){var n,r=this._readableState;return r.objectMode?n=!0:"string"==typeof e&&(t=t||r.defaultEncoding,t!==r.encoding&&(e=U.from(e,t),t=""),n=!0),c(this,e,t,!1,n)},u.prototype.unshift=function(e){return c(this,e,null,!0,!1)},u.prototype.isPaused=function(){return!1===this._readableState.flowing},u.prototype.setEncoding=function(e){return z||(z=n(16).StringDecoder),this._readableState.decoder=new z(e),this._readableState.encoding=e,this};var G=8388608;u.prototype.read=function(e){q("read",e),e=parseInt(e,10);var t=this._readableState,n=e;if(0!==e&&(t.emittedReadable=!1),0===e&&t.needReadable&&(t.length>=t.highWaterMark||t.ended))return q("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?A(this):y(this),null;if(0===(e=p(e,t))&&t.ended)return 0===t.length&&A(this),null;var r=t.needReadable;q("need readable",r),(0===t.length||t.length-e<t.highWaterMark)&&(r=!0,q("length less than watermark",r)),t.ended||t.reading?(r=!1,q("reading or ended",r)):r&&(q("do read"),t.reading=!0,t.sync=!0,0===t.length&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=p(n,t)));var i;return i=e>0?T(e,t):null,null===i?(t.needReadable=!0,e=0):t.length-=e,0===t.length&&(t.ended||(t.needReadable=!0),n!==e&&t.ended&&A(this)),null!==i&&this.emit("data",i),i},u.prototype._read=function(e){this.emit("error",new Error("_read() is not implemented"))},u.prototype.pipe=function(e,t){function n(e,t){q("onunpipe"),e===d&&t&&!1===t.hasUnpiped&&(t.hasUnpiped=!0,o())}function i(){q("onend"),e.end()}function o(){q("cleanup"),e.removeListener("close",c),e.removeListener("finish",l),e.removeListener("drain",y),e.removeListener("error",u),e.removeListener("unpipe",n),d.removeListener("end",i),d.removeListener("end",f),d.removeListener("data",s),v=!0,!h.awaitDrain||e._writableState&&!e._writableState.needDrain||y()}function s(t){q("ondata"),b=!1,!1!==e.write(t)||b||((1===h.pipesCount&&h.pipes===e||h.pipesCount>1&&-1!==L(h.pipes,e))&&!v&&(q("false write response, pause",d._readableState.awaitDrain),d._readableState.awaitDrain++,b=!0),d.pause())}function u(t){q("onerror",t),f(),e.removeListener("error",u),0===x(e,"error")&&e.emit("error",t)}function c(){e.removeListener("finish",l),f()}function l(){q("onfinish"),e.removeListener("close",c),f()}function f(){q("unpipe"),d.unpipe(e)}var d=this,h=this._readableState;switch(h.pipesCount){case 0:h.pipes=e;break;case 1:h.pipes=[h.pipes,e];break;default:h.pipes.push(e)}h.pipesCount+=1,q("pipe count=%d opts=%j",h.pipesCount,t);var p=(!t||!1!==t.end)&&e!==r.stdout&&e!==r.stderr,g=p?i:f;h.endEmitted?I.nextTick(g):d.once("end",g),e.on("unpipe",n);var y=_(d);e.on("drain",y);var v=!1,b=!1;return d.on("data",s),a(e,"error",u),e.once("close",c),e.once("finish",l),e.emit("pipe",d),h.flowing||(q("pipe resume"),d.resume()),e},u.prototype.unpipe=function(e){var t=this._readableState,n={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,n),this);if(!e){var r=t.pipes,i=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var o=0;o<i;o++)r[o].emit("unpipe",this,n);return this}var a=L(t.pipes,e);return-1===a?this:(t.pipes.splice(a,1),t.pipesCount-=1,1===t.pipesCount&&(t.pipes=t.pipes[0]),e.emit("unpipe",this,n),this)},u.prototype.on=function(e,t){var n=B.prototype.on.call(this,e,t);if("data"===e)!1!==this._readableState.flowing&&this.resume();else if("readable"===e){var r=this._readableState;r.endEmitted||r.readableListening||(r.readableListening=r.needReadable=!0,r.emittedReadable=!1,r.reading?r.length&&y(this):I.nextTick(w,this))}return n},u.prototype.addListener=u.prototype.on,u.prototype.resume=function(){var e=this._readableState;return e.flowing||(q("resume"),e.flowing=!0,C(this,e)),this},u.prototype.pause=function(){return q("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(q("pause"),this._readableState.flowing=!1,this.emit("pause")),this},u.prototype.wrap=function(e){var t=this,n=this._readableState,r=!1;e.on("end",function(){if(q("wrapped end"),n.decoder&&!n.ended){var e=n.decoder.end();e&&e.length&&t.push(e)}t.push(null)}),e.on("data",function(i){if(q("wrapped data"),n.decoder&&(i=n.decoder.write(i)),(!n.objectMode||null!==i&&void 0!==i)&&(n.objectMode||i&&i.length)){t.push(i)||(r=!0,e.pause())}});for(var i in e)void 0===this[i]&&"function"==typeof e[i]&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));for(var o=0;o<H.length;o++)e.on(H[o],this.emit.bind(this,H[o]));return this._read=function(t){q("wrapped _read",t),r&&(r=!1,e.resume())},this},Object.defineProperty(u.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),u._fromList=T}).call(t,n(1),n(3))},function(e,t,n){"use strict";e.exports=n(0).EventEmitter},function(e,t,n){"use strict";function r(e,t){var n=this,r=this._readableState&&this._readableState.destroyed,i=this._writableState&&this._writableState.destroyed;return r||i?(t?t(e):!e||this._writableState&&this._writableState.errorEmitted||a.nextTick(o,this,e),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,function(e){!t&&e?(a.nextTick(o,n,e),n._writableState&&(n._writableState.errorEmitted=!0)):t&&t(e)}),this)}function i(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}function o(e,t){e.emit("error",t)}var a=n(9);e.exports={destroy:r,undestroy:i}},function(e,t,n){"use strict";(function(t,r,i){function o(e){var t=this;this.next=null,this.entry=null,this.finish=function(){R(t,e)}}function a(e){return M.from(e)}function s(e){return M.isBuffer(e)||e instanceof x}function u(){}function c(e,t){A=A||n(5),e=e||{};var r=t instanceof A;this.objectMode=!!e.objectMode,r&&(this.objectMode=this.objectMode||!!e.writableObjectMode);var i=e.highWaterMark,a=e.writableHighWaterMark,s=this.objectMode?16:16384;this.highWaterMark=i||0===i?i:r&&(a||0===a)?a:s,this.highWaterMark=Math.floor(this.highWaterMark),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var u=!1===e.decodeStrings;this.decodeStrings=!u,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(e){b(t,e)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.bufferedRequestCount=0,this.corkedRequestsFree=new o(this)}function l(e){if(A=A||n(5),!(U.call(l,this)||this instanceof A))return new l(e);this._writableState=new c(e,this),this.writable=!0,e&&("function"==typeof e.write&&(this._write=e.write),"function"==typeof e.writev&&(this._writev=e.writev),"function"==typeof e.destroy&&(this._destroy=e.destroy),"function"==typeof e.final&&(this._final=e.final)),D.call(this)}function f(e,t){var n=new Error("write after end");e.emit("error",n),k.nextTick(t,n)}function d(e,t,n,r){var i=!0,o=!1;return null===n?o=new TypeError("May not write null values to stream"):"string"==typeof n||void 0===n||t.objectMode||(o=new TypeError("Invalid non-string/buffer chunk")),o&&(e.emit("error",o),k.nextTick(r,o),i=!1),i}function h(e,t,n){return e.objectMode||!1===e.decodeStrings||"string"!=typeof t||(t=M.from(t,n)),t}function p(e,t,n,r,i,o){if(!n){var a=h(t,r,i);r!==a&&(n=!0,i="buffer",r=a)}var s=t.objectMode?1:r.length;t.length+=s;var u=t.length<t.highWaterMark;if(u||(t.needDrain=!0),t.writing||t.corked){var c=t.lastBufferedRequest;t.lastBufferedRequest={chunk:r,encoding:i,isBuf:n,callback:o,next:null},c?c.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else g(e,t,!1,s,r,i,o);return u}function g(e,t,n,r,i,o,a){t.writelen=r,t.writecb=a,t.writing=!0,t.sync=!0,n?e._writev(i,t.onwrite):e._write(i,o,t.onwrite),t.sync=!1}function y(e,t,n,r,i){--t.pendingcb,n?(k.nextTick(i,r),k.nextTick(T,e,t),e._writableState.errorEmitted=!0,e.emit("error",r)):(i(r),e._writableState.errorEmitted=!0,e.emit("error",r),T(e,t))}function v(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}function b(e,t){var n=e._writableState,r=n.sync,i=n.writecb;if(v(n),t)y(e,n,r,t,i);else{var o=C(n);o||n.corked||n.bufferProcessing||!n.bufferedRequest||w(e,n),r?O(m,e,n,o,i):m(e,n,o,i)}}function m(e,t,n,r){n||_(e,t),t.pendingcb--,r(),T(e,t)}function _(e,t){0===t.length&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}function w(e,t){t.bufferProcessing=!0;var n=t.bufferedRequest;if(e._writev&&n&&n.next){var r=t.bufferedRequestCount,i=new Array(r),a=t.corkedRequestsFree;a.entry=n;for(var s=0,u=!0;n;)i[s]=n,n.isBuf||(u=!1),n=n.next,s+=1;i.allBuffers=u,g(e,t,!0,t.length,i,"",a.finish),t.pendingcb++,t.lastBufferedRequest=null,a.next?(t.corkedRequestsFree=a.next,a.next=null):t.corkedRequestsFree=new o(t),t.bufferedRequestCount=0}else{for(;n;){var c=n.chunk,l=n.encoding,f=n.callback;if(g(e,t,!1,t.objectMode?1:c.length,c,l,f),n=n.next,t.bufferedRequestCount--,t.writing)break}null===n&&(t.lastBufferedRequest=null)}t.bufferedRequest=n,t.bufferProcessing=!1}function C(e){return e.ending&&0===e.length&&null===e.bufferedRequest&&!e.finished&&!e.writing}function S(e,t){e._final(function(n){t.pendingcb--,n&&e.emit("error",n),t.prefinished=!0,e.emit("prefinish"),T(e,t)})}function E(e,t){t.prefinished||t.finalCalled||("function"==typeof e._final?(t.pendingcb++,t.finalCalled=!0,k.nextTick(S,e,t)):(t.prefinished=!0,e.emit("prefinish")))}function T(e,t){var n=C(t);return n&&(E(e,t),0===t.pendingcb&&(t.finished=!0,e.emit("finish"))),n}function P(e,t,n){t.ending=!0,T(e,t),n&&(t.finished?k.nextTick(n):e.once("finish",n)),t.ended=!0,e.writable=!1}function R(e,t,n){var r=e.entry;for(e.entry=null;r;){var i=r.callback;t.pendingcb--,i(n),r=r.next}t.corkedRequestsFree?t.corkedRequestsFree.next=e:t.corkedRequestsFree=e}var k=n(9);e.exports=l;var A,O=!t.browser&&["v0.10","v0.9."].indexOf(t.version.slice(0,5))>-1?r:k.nextTick;l.WritableState=c;var L=n(6);L.inherits=n(4);var I={deprecate:n(42)},D=n(13),M=n(8).Buffer,x=i.Uint8Array||function(){},B=n(14);L.inherits(l,D),c.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(c.prototype,"buffer",{get:I.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(e){}}();var U;"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(U=Function.prototype[Symbol.hasInstance],Object.defineProperty(l,Symbol.hasInstance,{value:function(e){return!!U.call(this,e)||this===l&&(e&&e._writableState instanceof c)}})):U=function(e){return e instanceof this},l.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))},l.prototype.write=function(e,t,n){var r=this._writableState,i=!1,o=!r.objectMode&&s(e);return o&&!M.isBuffer(e)&&(e=a(e)),"function"==typeof t&&(n=t,t=null),o?t="buffer":t||(t=r.defaultEncoding),"function"!=typeof n&&(n=u),r.ended?f(this,n):(o||d(this,r,e,n))&&(r.pendingcb++,i=p(this,r,o,e,t,n)),i},l.prototype.cork=function(){this._writableState.corked++},l.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.finished||e.bufferProcessing||!e.bufferedRequest||w(this,e))},l.prototype.setDefaultEncoding=function(e){if("string"==typeof e&&(e=e.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((e+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(l.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),l.prototype._write=function(e,t,n){n(new Error("_write() is not implemented"))},l.prototype._writev=null,l.prototype.end=function(e,t,n){var r=this._writableState;"function"==typeof e?(n=e,e=null,t=null):"function"==typeof t&&(n=t,t=null),null!==e&&void 0!==e&&this.write(e,t),r.corked&&(r.corked=1,this.uncork()),r.ending||r.finished||P(this,r,n)},Object.defineProperty(l.prototype,"destroyed",{get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),l.prototype.destroy=B.destroy,l.prototype._undestroy=B.undestroy,l.prototype._destroy=function(e,t){this.end(),t(e)}}).call(t,n(3),n(40).setImmediate,n(1))},function(e,t,n){"use strict";function r(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}function i(e){var t=r(e);if("string"!=typeof t&&(b.isEncoding===m||!m(e)))throw new Error("Unknown encoding: "+e);return t||e}function o(e){this.encoding=i(e);var t;switch(this.encoding){case"utf16le":this.text=d,this.end=h,t=4;break;case"utf8":this.fillLast=c,t=4;break;case"base64":this.text=p,this.end=g,t=3;break;default:return this.write=y,void(this.end=v)}this.lastNeed=0,this.lastTotal=0,this.lastChar=b.allocUnsafe(t)}function a(e){return e<=127?0:e>>5==6?2:e>>4==14?3:e>>3==30?4:e>>6==2?-1:-2}function s(e,t,n){var r=t.length-1;if(r<n)return 0;var i=a(t[r]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--r<n||-2===i?0:(i=a(t[r]))>=0?(i>0&&(e.lastNeed=i-2),i):--r<n||-2===i?0:(i=a(t[r]),i>=0?(i>0&&(2===i?i=0:e.lastNeed=i-3),i):0)}function u(e,t,n){if(128!=(192&t[0]))return e.lastNeed=0,"�";if(e.lastNeed>1&&t.length>1){if(128!=(192&t[1]))return e.lastNeed=1,"�";if(e.lastNeed>2&&t.length>2&&128!=(192&t[2]))return e.lastNeed=2,"�"}}function c(e){var t=this.lastTotal-this.lastNeed,n=u(this,e,t);return void 0!==n?n:this.lastNeed<=e.length?(e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(e.copy(this.lastChar,t,0,e.length),void(this.lastNeed-=e.length))}function l(e,t){var n=s(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=n;var r=e.length-(n-this.lastNeed);return e.copy(this.lastChar,0,r),e.toString("utf8",t,r)}function f(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t}function d(e,t){if((e.length-t)%2==0){var n=e.toString("utf16le",t);if(n){var r=n.charCodeAt(n.length-1);if(r>=55296&&r<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function h(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,n)}return t}function p(e,t){var n=(e.length-t)%3;return 0===n?e.toString("base64",t):(this.lastNeed=3-n,this.lastTotal=3,1===n?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-n))}function g(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function y(e){return e.toString(this.encoding)}function v(e){return e&&e.length?this.write(e):""}var b=n(43).Buffer,m=b.isEncoding||function(e){switch((e=""+e)&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};t.StringDecoder=o,o.prototype.write=function(e){if(0===e.length)return"";var t,n;if(this.lastNeed){if(void 0===(t=this.fillLast(e)))return"";n=this.lastNeed,this.lastNeed=0}else n=0;return n<e.length?t?t+this.text(e,n):this.text(e,n):t||""},o.prototype.end=f,o.prototype.text=l,o.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length}},function(e,t,n){"use strict";function r(e,t){var n=this._transformState;n.transforming=!1;var r=n.writecb;if(!r)return this.emit("error",new Error("write callback called multiple times"));n.writechunk=null,n.writecb=null,null!=t&&this.push(t),r(e);var i=this._readableState;i.reading=!1,(i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}function i(e){if(!(this instanceof i))return new i(e);s.call(this,e),this._transformState={afterTransform:r.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,e&&("function"==typeof e.transform&&(this._transform=e.transform),"function"==typeof e.flush&&(this._flush=e.flush)),this.on("prefinish",o)}function o(){var e=this;"function"==typeof this._flush?this._flush(function(t,n){a(e,t,n)}):a(this,null,null)}function a(e,t,n){if(t)return e.emit("error",t);if(null!=n&&e.push(n),e._writableState.length)throw new Error("Calling transform done when ws.length != 0");if(e._transformState.transforming)throw new Error("Calling transform done when still transforming");return e.push(null)}e.exports=i;var s=n(5),u=n(6);u.inherits=n(4),u.inherits(i,s),i.prototype.push=function(e,t){return this._transformState.needTransform=!1,s.prototype.push.call(this,e,t)},i.prototype._transform=function(e,t,n){throw new Error("_transform() is not implemented")},i.prototype._write=function(e,t,n){var r=this._transformState;if(r.writecb=n,r.writechunk=e,r.writeencoding=t,!r.transforming){var i=this._readableState;(r.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}},i.prototype._read=function(e){var t=this._transformState;null!==t.writechunk&&t.writecb&&!t.transforming?(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform)):t.needTransform=!0},i.prototype._destroy=function(e,t){var n=this;s.prototype._destroy.call(this,e,function(e){t(e),n.emit("close")})}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default={DC_PING:"PING",DC_PONG:"PONG",DC_SIGNAL:"SIGNAL",DC_OPEN:"OPEN",DC_REQUEST:"REQUEST",DC_PIECE_NOT_FOUND:"PIECE_NOT_FOUND",DC_CLOSE:"CLOSE",DC_RESPONSE:"RESPONSE",DC_ERROR:"ERROR",DC_PIECE:"PIECE",DC_TIMEOUT:"TIMEOUT",DC_PIECE_ACK:"PIECE_ACK",DC_BITFIELD:"BITFIELD",DC_CHOKE:"CHOKE",DC_UNCHOKE:"UNCHOKE",DC_INTERESTED:"INTERESTED",DC_NOTINTERESTED:"NOT_INTERESTED",DC_HAVE:"HAVE",DC_LOST:"LOST",BM_LOST:"lost"},e.exports=t.default},function(e,t,n){!function(t){var n=/^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/\;?#]*)?(.*?)??(;.*?)?(\?.*?)?(#.*?)?$/,r=/^([^\/;?#]*)(.*)$/,i=/(?:\/|^)\.(?=\/)/g,o=/(?:\/|^)\.\.\/(?!\.\.\/).*?(?=\/)/g,a={buildAbsoluteURL:function(e,t,n){if(n=n||{},e=e.trim(),!(t=t.trim())){if(!n.alwaysNormalize)return e;var i=a.parseURL(e);if(!i)throw new Error("Error trying to parse base URL.");return i.path=a.normalizePath(i.path),a.buildURLFromParts(i)}var o=a.parseURL(t);if(!o)throw new Error("Error trying to parse relative URL.");if(o.scheme)return n.alwaysNormalize?(o.path=a.normalizePath(o.path),a.buildURLFromParts(o)):t;var s=a.parseURL(e);if(!s)throw new Error("Error trying to parse base URL.");if(!s.netLoc&&s.path&&"/"!==s.path[0]){var u=r.exec(s.path);s.netLoc=u[1],s.path=u[2]}s.netLoc&&!s.path&&(s.path="/");var c={scheme:s.scheme,netLoc:o.netLoc,path:null,params:o.params,query:o.query,fragment:o.fragment};if(!o.netLoc&&(c.netLoc=s.netLoc,"/"!==o.path[0]))if(o.path){var l=s.path,f=l.substring(0,l.lastIndexOf("/")+1)+o.path;c.path=a.normalizePath(f)}else c.path=s.path,o.params||(c.params=s.params,o.query||(c.query=s.query));return null===c.path&&(c.path=n.alwaysNormalize?a.normalizePath(o.path):o.path),a.buildURLFromParts(c)},parseURL:function(e){var t=n.exec(e);return t?{scheme:t[1]||"",netLoc:t[2]||"",path:t[3]||"",params:t[4]||"",query:t[5]||"",fragment:t[6]||""}:null},normalizePath:function(e){for(e=e.split("").reverse().join("").replace(i,"");e.length!==(e=e.replace(o,"")).length;);return e.split("").reverse().join("")},buildURLFromParts:function(e){return e.scheme+e.netLoc+e.path+e.params+e.query+e.fragment}};e.exports=a}()},function(e,t,n){"use strict";var r=function(e){return e&&2===e.CLOSING},i=function(){return"undefined"!=typeof WebSocket&&r(WebSocket)},o=function(){return{constructor:i()?WebSocket:null,maxReconnectionDelay:1e4,minReconnectionDelay:1500,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,debug:!1}},a=function(e,t,n){Object.defineProperty(t,n,{get:function(){return e[n]},set:function(t){e[n]=t},enumerable:!0,configurable:!0})},s=function(e){return e.minReconnectionDelay+Math.random()*e.minReconnectionDelay},u=function(e,t){var n=t*e.reconnectionDelayGrowFactor;return n>e.maxReconnectionDelay?e.maxReconnectionDelay:n},c=["onopen","onclose","onmessage","onerror"],l=function(e,t,n){Object.keys(n).forEach(function(t){n[t].forEach(function(n){var r=n[0],i=n[1];e.addEventListener(t,r,i)})}),t&&c.forEach(function(n){e[n]=t[n]})},f=function(e,t,n){var i=this;void 0===n&&(n={});var c,d,h=0,p=0,g=!0,y=null,v={};if(!(this instanceof f))throw new TypeError("Failed to construct 'ReconnectingWebSocket': Please use the 'new' operator");var b=o();if(Object.keys(b).filter(function(e){return n.hasOwnProperty(e)}).forEach(function(e){return b[e]=n[e]}),!r(b.constructor))throw new TypeError("Invalid WebSocket constructor. Set `options.constructor`");var m=b.debug?function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return console.log.apply(console,["RWS:"].concat(e))}:function(){},_=function(e,t){return setTimeout(function(){var n=new Error(t);n.code=e,Array.isArray(v.error)&&v.error.forEach(function(e){return(0,e[0])(n)}),c.onerror&&c.onerror(n)},0)},w=function(){if(m("handleClose",{shouldRetry:g}),p++,m("retries count:",p),p>b.maxRetries)return void _("EHOSTDOWN","Too many failed connection attempts");h=h?u(b,h):s(b),m("handleClose - reconnectDelay:",h),g&&setTimeout(C,h)},C=function(){if(g){m("connect");var n=c,r="function"==typeof e?e():e;c=new b.constructor(r,t),d=setTimeout(function(){m("timeout"),c.close(),_("ETIMEDOUT","Connection timeout")},b.connectionTimeout),m("bypass properties");for(var o in c)["addEventListener","removeEventListener","close","send"].indexOf(o)<0&&a(c,i,o);c.addEventListener("open",function(){clearTimeout(d),m("open"),h=s(b),m("reconnectDelay:",h),p=0}),c.addEventListener("close",w),l(c,n,v),c.onclose=c.onclose||y,y=null}};m("init"),C(),this.close=function(e,t,n){void 0===e&&(e=1e3),void 0===t&&(t="");var r=void 0===n?{}:n,i=r.keepClosed,o=void 0!==i&&i,a=r.fastClose,s=void 0===a||a,u=r.delay,l=void 0===u?0:u;if(m("close - params:",{reason:t,keepClosed:o,fastClose:s,delay:l,retriesCount:p,maxRetries:b.maxRetries}),g=!o&&p<=b.maxRetries,l&&(h=l),c.close(e,t),s){var f={code:e,reason:t,wasClean:!0};w(),c.removeEventListener("close",w),Array.isArray(v.close)&&v.close.forEach(function(e){var t=e[0],n=e[1];t(f),c.removeEventListener("close",t,n)}),c.onclose&&(y=c.onclose,c.onclose(f),c.onclose=null)}},this.send=function(e){c.send(e)},this.addEventListener=function(e,t,n){Array.isArray(v[e])?v[e].some(function(e){return e[0]===t})||v[e].push([t,n]):v[e]=[[t,n]],c.addEventListener(e,t,n)},this.removeEventListener=function(e,t,n){Array.isArray(v[e])&&(v[e]=v[e].filter(function(e){return e[0]!==t})),c.removeEventListener(e,t,n)}};e.exports=f},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),u=n(0),c=r(u),l=n(22),f=r(l),d=n(11),h=n(50),p=r(h),g=n(7),y=n(51),v=r(y),b=n(52),m=r(b),_=n(10),w=function(e){function t(e,n){i(this,t);var r=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));r.config=Object.assign({},f.default,n),r.config.channelId&&"function"==typeof r.config.channelId||(r.config.channelId=_.defaultChannelId),r.hlsjs=e,r.p2pEnabled=!1!==r.config.disableP2P,e.config.currLoaded=e.config.currPlay=0;var a=function n(i,o){var a=o.details.live;r.config.live=a;var s={device:m.default.getPlatform(),netType:m.default.getNetType(),host:window.location.host,version:t.version,tag:r.config.tag||r.hlsjs.constructor.version},u=r.config.channelId(e.url,g.DataChannel.VERSION,s),c=new v.default(r.config,u);r.hlsjs.config.logger=r.logger=c,c.info("channel "+u),r._init(u,s),e.off(e.constructor.Events.LEVEL_LOADED,n)};return e.on(e.constructor.Events.LEVEL_LOADED,a),console.log("CDNBye v"+t.version+" -- A Free and Infinitely Scalable Video P2P Engine. (https://github.com/cdnbye/hlsjs-p2p-engine)"),r}return a(t,e),s(t,null,[{key:"Events",get:function(){return g.Events}}]),s(t,[{key:"_init",value:function(e,t){var n=this,r=this.logger;this.hlsjs.config.p2pEnabled=this.p2pEnabled,this.bufMgr=new p.default(this,this.config),this.hlsjs.config.bufMgr=this.bufMgr;var i=new g.Fetcher(this,"free",window.encodeURIComponent(e),this.config.announce,t);this.fetcher=i,this.signaler=new d.Tracker(this,i,this.config),this.signaler.scheduler.bufferManager=this.bufMgr,this.hlsjs.config.fLoader=d.FragLoader,this.hlsjs.config.scheduler=this.signaler.scheduler,this.hlsjs.config.fetcher=i,this.hlsjs.on(this.hlsjs.constructor.Events.FRAG_LOADING,function(e,t){r.debug("loading frag "+t.frag.sn),n.signaler.currentLoadingSN=t.frag.sn}),this.signalTried=!1,this.hlsjs.on(this.hlsjs.constructor.Events.FRAG_LOADED,function(e,t){var i=t.frag.sn;n.hlsjs.config.currLoaded=i,n.signaler.currentLoadedSN=i,n.hlsjs.config.currLoadedDuration=t.frag.duration;var o=Math.round(8*t.frag.loaded/t.frag.duration);n.signalTried||n.signaler.connected||!n.config.p2pEnabled||(n.signaler.scheduler.bitrate=o,r.info("bitrate "+o),n.signaler.resumeP2P(),n.signalTried=!0),t.frag.loadByHTTP||(t.frag.loadByP2P=!1,t.frag.loadByHTTP=!0)}),this.hlsjs.on(this.hlsjs.constructor.Events.FRAG_CHANGED,function(e,t){r.debug("frag changed: "+t.frag.sn);var i=t.frag.sn;n.hlsjs.config.currPlay=i,n.signaler.currentPlaySN=i}),this.hlsjs.on(this.hlsjs.constructor.Events.ERROR,function(e,t){r.error("errorType "+t.type+" details "+t.details+" errorFatal "+t.fatal);var i=n.hlsjs.constructor.ErrorDetails;switch(t.details){case i.FRAG_LOAD_ERROR:case i.FRAG_LOAD_TIMEOUT:n.fetcher.errsFragLoad++;break;case i.BUFFER_STALLED_ERROR:n.fetcher.errsBufStalled++;break;case i.INTERNAL_EXCEPTION:n.fetcher.errsInternalExpt++}}),this.hlsjs.on(this.hlsjs.constructor.Events.DESTROYING,function(){n.signaler.destroy(),n.signaler=null})}},{key:"disableP2P",value:function(){this.logger.warn("disable P2P"),this.p2pEnabled&&(this.p2pEnabled=!1,this.config.p2pEnabled=this.hlsjs.config.p2pEnabled=this.p2pEnabled,this.signaler&&this.signaler.stopP2P())}},{key:"enableP2P",value:function(){this.logger.warn("enable P2P"),this.p2pEnabled||(this.p2pEnabled=!0,this.config.p2pEnabled=this.hlsjs.config.p2pEnabled=this.p2pEnabled,this.signaler&&this.signaler.resumeP2P())}},{key:"version",get:function(){return t.version}}]),t}(c.default);w.WEBRTC_SUPPORT=!!(0,g.getBrowserRTC)(),w.version="0.2.2",t.default=w,e.exports=t.default},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i=n(11),o=r({wsSignalerAddr:"wss://signal.cdnbye.com/wss",wsMaxRetries:3,wsReconnectInterval:5,p2pEnabled:!0,dcRequestTimeout:3,dcUploadTimeout:3,dcPings:5,dcTolerance:4,packetSize:65536,maxBufSize:52428800,loadTimeout:3,tsStrictMatched:!1,enableLogUpload:!1,logUploadAddr:"wss://api.cdnbye.com/trace",logUploadLevel:"warn",logLevel:"none",tag:"",channelId:null},i.config);t.default=o,e.exports=t.default},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var u=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),c=n(0),l=r(c),f=n(24),d=r(f),h=n(48),p=r(h),g=n(7),y=n(10),v=function(e){function t(e,n,r){o(this,t);var i=a(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return i.engine=e,i.config=r,i.connected=!1,i.scheduler=new d.default(e,r),i.DCMap=new Map,i.failedDCSet=new Set,i.signalerWs=null,i.fetcher=n,i.peers=[],i.requestMorePeers=(0,y.throttle)(i._requestMorePeers,i),i._setupScheduler(i.scheduler),i}return s(t,e),u(t,[{key:"resumeP2P",value:function(){var e=this,t=this.engine.logger;this.fetcher.btAnnounce().then(function(n){t.info("announce request response "+JSON.stringify(n)),e.engine.peerId=e.peerId=n.id,t.identifier=e.peerId,e.signalerWs=e._initSignalerWs(),e._handlePeers(n.peers),e.engine.emit("peerId",e.peerId)}).catch(function(e){console.warn(e)})}},{key:"stopP2P",value:function(){this.engine.logger.warn("未实现")}},{key:"destroy",value:function(){}},{key:"_handlePeers",value:function(e){var t=this,n=!0,r=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(n=(a=s.next()).done);n=!0){var u=a.value;this.peers.push({id:u.id})}}catch(e){r=!0,o=e}finally{try{!n&&s.return&&s.return()}finally{if(r)throw o}}this.peers=this.peers.filter(function(e){for(var n=[].concat(i(t.DCMap.keys()),i(t.failedDCSet.keys())),r=0;r<n.length;r++){var o=n[r];if(e.id===o)return!1}return!0})}},{key:"_tryConnectToPeer",value:function(){var e=this.engine.logger;if(0!==this.peers.length){var t=this.peers.pop().id;e.info("try connect to Peer "+t);var n=new g.DataChannel(this.engine,this.peerId,t,!0,this.config);this.DCMap.set(t,n),this._setupDC(n)}}},{key:"_tryConnectToAllPeers",value:function(){var e=this,t=this.engine.logger;0!==this.peers.length&&(t.info("try connect to "+this.peers.length+" peers"),this.peers.forEach(function(t){var n=new g.DataChannel(e.engine,e.peerId,t.id,!0,e.config);e.DCMap.set(t.id,n),e._setupDC(n)}),this.peers=[])}},{key:"_setupDC",value:function(e){var t=this,n=this.engine.logger;e.on(g.Events.DC_SIGNAL,function(n){var r=e.remotePeerId;t.signalerWs.sendSignal(r,n)}).once(g.Events.DC_ERROR,function(){n.warn("datachannel connect "+e.channelId+" failed"),t.scheduler.deletePeer(e),t.DCMap.delete(e.remotePeerId),t.failedDCSet.add(e.remotePeerId),e.destroy(),t.requestMorePeers(),e.isInitiator&&(e.connected?t.fetcher.decreConns():t.fetcher.increFailConns())}).once(g.Events.DC_CLOSE,function(){n.warn("datachannel "+e.channelId+" closed"),t.scheduler.deletePeer(e),t.DCMap.delete(e.remotePeerId),t.failedDCSet.add(e.remotePeerId),e.destroy(),t.requestMorePeers(),t.fetcher.decreConns()}).once(g.Events.DC_OPEN,function(){t.scheduler.handshakePeer(e),t.requestMorePeers(),t.fetcher.increConns()})}},{key:"_initSignalerWs",value:function(){var e=this,t=this.engine.logger,n=new p.default(this.engine,this.peerId,this.config);return n.onopen=function(){e.connected=!0,e._tryConnectToAllPeers()},n.onmessage=function(n){var r=JSON.parse(n.data),i=r.action;switch(i){case"signal":if(e.failedDCSet.has(r.from_peer_id))return;t.debug("handle signal of "+r.from_peer_id),r.data?e._handleSignal(r.from_peer_id,r.data):(e.DCMap.delete(r.from_peer_id),e.failedDCSet.add(r.from_peer_id),t.info("signaling "+r.from_peer_id+" not found"));break;case"reject":e.stopP2P();break;default:t.warn("Signaler websocket unknown action "+i)}},n.onclose=function(){e.connected=!1,e.destroy()},n}},{key:"_handleSignal",value:function(e,t){var n=this.engine.logger,r=this.DCMap.get(e);if(r&&r.connected)return void n.info("datachannel had connected, signal ignored");if(!r){if(n.debug("receive node "+e+" connection request"),this.failedDCSet.has(e))return;r=new g.DataChannel(this.engine,this.peerId,e,!1,this.config),this.DCMap.set(e,r),this._setupDC(r)}r.receiveSignal(t)}},{key:"_setupScheduler",value:function(e){}},{key:"_requestMorePeers",value:function(){var e=this,t=this.engine.logger;this.scheduler.peerMap.size<=3&&this.fetcher.btGetPeers().then(function(n){t.info("request more peers "+JSON.stringify(n)),e._handlePeers(n.peers),e._tryConnectToAllPeers()})}},{key:"currentPlaySN",set:function(e){this.scheduler.updatePlaySN(e)}},{key:"currentLoadingSN",set:function(e){this.scheduler.updateLoadingSN(e)}},{key:"currentLoadedSN",set:function(e){this.scheduler.updateLoadedSN(e)}}]),t}(l.default);t.default=v,e.exports=t.default},function(e,t,n){"use strict";function r(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),u=n(0),c=function(e){return e&&e.__esModule?e:{default:e}}(u),l=n(7),f=n(10),d=function(e){function t(e,n){i(this,t);var r=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return r.engine=e,r.config=n,r.bufMgr=null,r.peerMap=new Map,r.bitset=new Set,r.bitCounts=new Map,r.targetPeer=null,r}return a(t,e),s(t,[{key:"updateLoadedSN",value:function(e){if(this.bitset.add(e),this.bitCounts.has(e)&&this.bitCounts.delete(e),this.peerMap.size>0){var t={event:l.Events.DC_HAVE,sn:e};this._broadcastToPeers(t)}}},{key:"updateLoadingSN",value:function(e){this.loadingSN=e}},{key:"updatePlaySN",value:function(e){var t=this.engine.logger;if(!this.config.live&&this.hasPeers)for(var n=[],r=e+1;r<=e+this.config.urgentOffset+1;r++)if(!this.bitset.has(r)&&r!==this.loadingSN&&this.bitCounts.has(r)){var i=!0,o=!1,a=void 0;try{for(var s,u=this.peerMap.values()[Symbol.iterator]();!(i=(s=u.next()).done);i=!0){var c=s.value;if(c.isAvailable&&c.bitset.has(r)){c.requestDataBySN(r,!0),t.debug("request urgent "+r+" from peer "+c.remotePeerId),n.push(r);break}}}catch(e){o=!0,a=e}finally{try{!i&&u.return&&u.return()}finally{if(o)throw a}}}}},{key:"deletePeer",value:function(e){var t=this;this.peerMap.has(e.remotePeerId)&&(e.bitset.forEach(function(e){t._decreBitCounts(e)}),this.peerMap.delete(e.remotePeerId)),this.engine.emit("peers",[].concat(r(this.peerMap.keys())))}},{key:"handshakePeer",value:function(e){this._setupDC(e),e.sendBitField(Array.from(this.bitset))}},{key:"addPeer",value:function(e){this.engine.logger.info("add peer "+e.remotePeerId),this.peerMap.set(e.remotePeerId,e),this.engine.emit("peers",[].concat(r(this.peerMap.keys())))}},{key:"peersHasSN",value:function(e){return this.bitCounts.has(e)}},{key:"hasAndSetTargetPeer",value:function(e){var t=this.engine.logger;if(!this.hasIdlePeers||!this.peersHasSN(e))return!1;var n=!0,r=!1,i=void 0;try{for(var o,a=this.peerMap.values()[Symbol.iterator]();!(n=(o=a.next()).done);n=!0){var s=o.value;if(s.isAvailable&&s.bitset.has(e))return t.info("found sn "+e+" from peer "+s.remotePeerId),this.targetPeer=s,!0}}catch(e){r=!0,i=e}finally{try{!n&&a.return&&a.return()}finally{if(r)throw i}}return t.warn("idle peers has not sn "+e),!1}},{key:"load",value:function(e,t,n){var r=this.engine.logger;this.context=e;var i=e.frag,o=(0,f.handleTSUrl)(i.relurl,this.config.tsStrictMatched);this.callbacks=n,this.stats={trequest:performance.now(),retry:0,tfirst:0,tload:0,loaded:0},this.criticalSeg={sn:i.sn,relurl:o},this.targetPeer.requestDataByURL(o,!0),r.info("request criticalSeg url "+i.relurl+" at "+i.sn),this.criticaltimeouter=window.setTimeout(this._criticaltimeout.bind(this),1e3*this.config.loadTimeout)}},{key:"_setupDC",value:function(e){var t=this,n=this.engine.logger;e.on(l.Events.DC_BITFIELD,function(n){if(n.field){var r=new Set(n.field);e.bitset=r,n.field.forEach(function(e){t.bitset.has(e)||t._increBitCounts(e)}),t.addPeer(e)}}).on(l.Events.DC_HAVE,function(n){if(n.sn&&e.bitset){var r=n.sn;e.bitset.add(r),t.bitset.has(r)||t._increBitCounts(r)}}).on(l.Events.DC_LOST,function(n){if(n.sn&&e.bitset){var r=n.sn;e.bitset.delete(r),t._decreBitCounts(r)}}).on(l.Events.DC_PIECE_ACK,function(e){e.size&&t.engine.fetcher.reportUploaded(e.size)}).on(l.Events.DC_PIECE,function(e){t.criticalSeg&&t.criticalSeg.relurl===e.url&&(t.stats.tfirst=Math.max(performance.now(),t.stats.trequest))}).on(l.Events.DC_PIECE_NOT_FOUND,function(e){t.criticalSeg&&t.criticalSeg.relurl===e.url&&(window.clearTimeout(t.criticaltimeouter),n.info("DC_PIECE_NOT_FOUND"),t._criticaltimeout())}).on(l.Events.DC_RESPONSE,function(r){if(t.criticalSeg&&t.criticalSeg.relurl===r.url&&t.criticaltimeouter){n.info("receive criticalSeg url "+r.url),window.clearTimeout(t.criticaltimeouter),t.criticaltimeouter=null;var i=t.stats;i.tload=Math.max(i.tfirst,performance.now()),i.loaded=i.total=r.data.byteLength,t.criticalSeg=null,t.context.frag.fromPeerId=e.remotePeerId,t.callbacks.onSuccess(r,i,t.context)}else t.bufMgr.addBuffer(r.sn,r.url,r.data,e.remotePeerId);t.updateLoadedSN(r.sn)}).on(l.Events.DC_REQUEST,function(n){var r="";if((r=n.url?n.url:t.bufMgr.getURLbySN(n.sn))&&t.bufMgr.hasSegOfURL(r)){var i=t.bufMgr.getSegByURL(r);e.sendBuffer(n.sn,i.relurl,i.data)}else e.sendJson({event:l.Events.DC_PIECE_NOT_FOUND,url:r,sn:n.sn})}).on(l.Events.DC_TIMEOUT,function(){n.warn("DC_TIMEOUT"),t.criticaltimeouter&&(window.clearTimeout(t.criticaltimeouter),t._criticaltimeout())})}},{key:"_broadcastToPeers",value:function(e){var t=!0,n=!1,r=void 0;try{for(var i,o=this.peerMap.values()[Symbol.iterator]();!(t=(i=o.next()).done);t=!0){i.value.sendJson(e)}}catch(e){n=!0,r=e}finally{try{!t&&o.return&&o.return()}finally{if(n)throw r}}}},{key:"_getIdlePeer",value:function(){return[].concat(r(this.peerMap.values())).filter(function(e){return e.isAvailable})}},{key:"_decreBitCounts",value:function(e){if(this.bitCounts.has(e)){var t=this.bitCounts.get(e);1===t?this.bitCounts.delete(e):this.bitCounts.set(e,t-1)}}},{key:"_increBitCounts",value:function(e){if(this.bitCounts.has(e)){var t=this.bitCounts.get(e);this.bitCounts.set(e,t+1)}else this.bitCounts.set(e,1)}},{key:"_criticaltimeout",value:function(){this.engine.logger.warn("critical request timeout"),this.criticalSeg=null,this.criticaltimeouter=null,this.callbacks.onTimeout(this.stats,this.context,null)}},{key:"hasPeers",get:function(){return this.peerMap.size>0}},{key:"hasIdlePeers",get:function(){var e=this.engine.logger,t=this._getIdlePeer().length;return e.info("peers: "+this.peerMap.size+" idle peers: "+t),t>0}},{key:"bufferManager",set:function(e){var t=this;this.bufMgr=e,e.on(l.Events.BM_LOST,function(e){t._broadcastToPeers({event:l.Events.DC_LOST,sn:e}),t.bitset.delete(e)})}}]),t}(c.default);t.default=d,e.exports=t.default},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function s(e,t,n,r){var i=[];if(r){for(var o=void 0,a=0;a<n-1;a++)o=e.slice(a*t,(a+1)*t),i.push(o);o=e.slice(e.byteLength-r,e.byteLength),i.push(o)}else for(var s=void 0,u=0;u<n;u++)s=e.slice(u*t,(u+1)*t),i.push(s);return i}function u(e){for(var t=0,n=0;n<e.length-1;n++)t+=e.charCodeAt(n);return e[e.length-1]===(t%16).toString(16)}Object.defineProperty(t,"__esModule",{value:!0});var c=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),l=n(26),f=r(l),d=n(0),h=r(d),p=n(18),g=r(p),y=n(2).Buffer,v=function(e){function t(e,n,r,a,s){i(this,t);var c=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return c.engine=e,c.config=s,c.remotePeerId=r,c.channelId=a?n+"-"+r:r+"-"+n,c.connected=!1,c.msgQueue=[],c.miss=0,c.rcvdReqQueue=[],c.downloading=!1,c.uploading=!1,c.choked=!u(r),c.delays=[],c._datachannel=new f.default({initiator:a,objectMode:!0}),c.isInitiator=a,c._init(c._datachannel),c.streamingRate=0,c.recordSended=c._adjustStreamingRate(10),c}return a(t,e),c(t,null,[{key:"VERSION",get:function(){return"v1"}}]),c(t,[{key:"_init",value:function(e){var t=this,n=this.engine.logger;e.on("error",function(e){t.emit(g.default.DC_ERROR)}),e.on("signal",function(e){t.emit(g.default.DC_SIGNAL,e)});var r=function(){for(n.info("datachannel CONNECTED to "+t.remotePeerId),t.connected=!0,t.emit(g.default.DC_OPEN),t._sendPing();t.msgQueue.length>0;){var e=t.msgQueue.shift();t.emit(e.event,e)}};e.once("connect",r),e.on("data",function(e){if("string"==typeof e){var n=JSON.parse(e);if(!t.connected)return void t.msgQueue.push(n);switch(n.event){case g.default.DC_PONG:t._handlePongMsg();break;case g.default.DC_PING:t.sendJson({event:g.default.DC_PONG});break;case g.default.DC_PIECE:t._prepareForBinary(n.attachments,n.url,n.sn,n.size),t.emit(n.event,n);break;case g.default.DC_PIECE_NOT_FOUND:window.clearTimeout(t.requestTimeout),t.requestTimeout=null,t.emit(n.event,n);break;case g.default.DC_REQUEST:t._handleRequestMsg(n);break;case g.default.DC_PIECE_ACK:t._handlePieceAck(),t.emit(n.event,n);break;default:t.emit(n.event,n)}}else t.bufArr.push(e),0===--t.remainAttachments&&(window.clearTimeout(t.requestTimeout),t.requestTimeout=null,t.sendJson({event:g.default.DC_PIECE_ACK,sn:t.bufSN,url:t.bufUrl,size:t.expectedSize}),t._handleBinaryData())}),e.once("close",function(){t.emit(g.default.DC_CLOSE)})}},{key:"sendJson",value:function(e){this.send(JSON.stringify(e))}},{key:"send",value:function(e){this._datachannel&&this._datachannel.connected&&this._datachannel.send(e)}},{key:"sendBitField",value:function(e){this.sendJson({event:g.default.DC_BITFIELD,field:e})}},{key:"sendBuffer",value:function(e,t,n){this.uploading=!0,this.uploadTimeout=window.setTimeout(this._uploadtimeout.bind(this),1e3*this.config.dcUploadTimeout);var r=n.byteLength,i=this.config.packetSize,o=0,a=0;r%i==0?a=r/i:(a=Math.floor(r/i)+1,o=r%i);var u={event:g.default.DC_PIECE,attachments:a,url:t,sn:e,size:r};this.sendJson(u);for(var c=s(n,i,a,o),l=0;l<c.length;l++)this.send(c[l]);this.recordSended(r)}},{key:"requestDataByURL",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n={event:g.default.DC_REQUEST,url:e,urgent:t};this.downloading=!0,this.sendJson(n),t&&(this.requestTimeout=window.setTimeout(this._loadtimeout.bind(this),1e3*this.config.dcRequestTimeout))}},{key:"requestDataBySN",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n={event:g.default.DC_REQUEST,sn:e,urgent:t};this.downloading=!0,this.sendJson(n),t&&(this.requestTimeout=window.setTimeout(this._loadtimeout.bind(this),1e3*this.config.dcRequestTimeout))}},{key:"close",value:function(){this.destroy()}},{key:"receiveSignal",value:function(e){this._datachannel.signal(e)}},{key:"destroy",value:function(){window.clearInterval(this.adjustSRInterval),window.clearInterval(this.pinger),this._datachannel.removeAllListeners(),this.removeAllListeners(),this._datachannel.destroy()}},{key:"_handleRequestMsg",value:function(e){this.rcvdReqQueue.length>0?e.urgent?this.rcvdReqQueue.push(e.sn):this.rcvdReqQueue.unshift(e.sn):this.emit(g.default.DC_REQUEST,e)}},{key:"_handlePieceAck",value:function(){if(this.uploading=!1,window.clearTimeout(this.uploadTimeout),this.uploadTimeout=null,this.rcvdReqQueue.length>0){var e=this.rcvdReqQueue.pop();this.emit(g.default.DC_REQUEST,{sn:e})}}},{key:"_prepareForBinary",value:function(e,t,n,r){this.bufArr=[],this.remainAttachments=e,this.bufUrl=t,this.bufSN=n,this.expectedSize=r}},{key:"_handleBinaryData",value:function(){var e=y.concat(this.bufArr);e.byteLength==this.expectedSize&&this.emit(g.default.DC_RESPONSE,{url:this.bufUrl,sn:this.bufSN,data:e}),this.bufUrl="",this.bufArr=[],this.expectedSize=-1,this.downloading=!1}},{key:"_adjustStreamingRate",value:function(e){var t=this,n=0;return this.adjustSRInterval=window.setInterval(function(){t.streamingRate=Math.round(8*n/e),n=0},1e3*e),function(e){n+=e}}},{key:"_loadtimeout",value:function(){var e=this.engine.logger;if(e.warn("datachannel timeout while downloading from "+this.remotePeerId),this.emit(g.default.DC_TIMEOUT),this.requestTimeout=null,this.downloading=!1,++this.miss>=this.config.dcTolerance){var t={event:g.default.DC_CLOSE};this.sendJson(t),e.warn("datachannel download miss reach dcTolerance, close "+this.remotePeerId),this.emit(g.default.DC_ERROR)}}},{key:"_uploadtimeout",value:function(){this.engine.logger.warn("datachannel timeout while uploading to "+this.remotePeerId),this.uploading=!1,this.rcvdReqQueue=[]}},{key:"_sendPing",value:function(){var e=this;this.ping=performance.now();for(var t=0;t<this.config.dcPings;t++)this.sendJson({event:g.default.DC_PING});window.setTimeout(function(){if(e.delays.length>0){var t=0,n=!0,r=!1,i=void 0;try{for(var o,a=e.delays[Symbol.iterator]();!(n=(o=a.next()).done);n=!0){t+=o.value}}catch(e){r=!0,i=e}finally{try{!n&&a.return&&a.return()}finally{if(r)throw i}}e.delay=t/e.delays.length,e.delays=[]}},100)}},{key:"_handlePongMsg",value:function(){var e=performance.now()-this.ping;this.delays.push(e)}},{key:"setupStats",value:function(){var e=this,t=this.engine.logger;setInterval(function(){e._datachannel.getStats(function(e,n){t.warn("reports: "+JSON.stringify(n,null,1))})},1e4)}},{key:"isAvailable",get:function(){return!1===this.downloading&&!1===this.choked}}]),t}(h.default);t.default=v,e.exports=t.default},function(e,t,n){"use strict";(function(t){function r(e){var t=this;if(!(t instanceof r))return new r(e);if(t._id=c(4).toString("hex").slice(0,7),t._debug("new peer %o",e),e=Object.assign({allowHalfOpen:!1},e),l.Duplex.call(t,e),t.channelName=e.initiator?e.channelName||c(20).toString("hex"):null,t._isChromium="undefined"!=typeof window&&!!window.webkitRTCPeerConnection,t.initiator=e.initiator||!1,t.channelConfig=e.channelConfig||r.channelConfig,t.config=e.config||r.config,t.constraints=t._transformConstraints(e.constraints||r.constraints),t.offerConstraints=t._transformConstraints(e.offerConstraints||{}),t.answerConstraints=t._transformConstraints(e.answerConstraints||{}),t.reconnectTimer=e.reconnectTimer||!1,t.sdpTransform=e.sdpTransform||function(e){return e},t.stream=e.stream||!1,t.trickle=void 0===e.trickle||e.trickle,t.destroyed=!1,t.connected=!1,t.remoteAddress=void 0,t.remoteFamily=void 0,t.remotePort=void 0,t.localAddress=void 0,t.localPort=void 0,t._wrtc=e.wrtc&&"object"===o(e.wrtc)?e.wrtc:s(),!t._wrtc)throw"undefined"==typeof window?new Error("No WebRTC support: Specify `opts.wrtc` option in this environment"):new Error("No WebRTC support: Not a supported browser");if(t._pcReady=!1,t._channelReady=!1,t._iceComplete=!1,t._channel=null,t._pendingCandidates=[],t._previousStreams=[],t._chunk=null,t._cb=null,t._interval=null,t._reconnectTimeout=null,t._pc=new t._wrtc.RTCPeerConnection(t.config,t.constraints),t._isWrtc=Array.isArray(t._pc.RTCIceConnectionStates),t._isReactNativeWebrtc="number"==typeof t._pc._peerConnectionId,t._pc.oniceconnectionstatechange=function(){t._onIceStateChange()},t._pc.onicegatheringstatechange=function(){t._onIceStateChange()},t._pc.onsignalingstatechange=function(){t._onSignalingStateChange()},t._pc.onicecandidate=function(e){t._onIceCandidate(e)},t.initiator){var n=!1;t._pc.onnegotiationneeded=function(){n||t._createOffer(),n=!0},t._setupData({channel:t._pc.createDataChannel(t.channelName,t.channelConfig)})}else t._pc.ondatachannel=function(e){t._setupData(e)};"addTrack"in t._pc?(t.stream&&t.stream.getTracks().forEach(function(e){t._pc.addTrack(e,t.stream)}),t._pc.ontrack=function(e){t._onTrack(e)}):(t.stream&&t._pc.addStream(t.stream),t._pc.onaddstream=function(e){t._onAddStream(e)}),t.initiator&&t._isWrtc&&t._pc.onnegotiationneeded(),t._onFinishBound=function(){t._onFinish()},t.once("finish",t._onFinishBound)}function i(){}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};e.exports=r;var a=n(30)("simple-channel"),s=n(33),u=n(4),c=n(34),l=n(35);u(r,l.Duplex),r.WEBRTC_SUPPORT=!!s(),r.config={iceServers:[{urls:"stun:stun.l.google.com:19302"},{urls:"stun:global.stun.twilio.com:3478?transport=udp"}]},r.constraints={},r.channelConfig={},Object.defineProperty(r.prototype,"bufferSize",{get:function(){var e=this;return e._channel&&e._channel.bufferedAmount||0}}),r.prototype.address=function(){var e=this;return{port:e.localPort,family:"IPv4",address:e.localAddress}},r.prototype.signal=function(e){var t=this;if(t.destroyed)throw new Error("cannot signal after peer is destroyed");if("string"==typeof e)try{e=JSON.parse(e)}catch(t){e={}}t._debug("signal()"),e.candidate&&(t._pc.remoteDescription&&t._pc.remoteDescription.type?t._addIceCandidate(e.candidate):t._pendingCandidates.push(e.candidate)),e.sdp&&t._pc.setRemoteDescription(new t._wrtc.RTCSessionDescription(e),function(){t.destroyed||(t._pendingCandidates.forEach(function(e){t._addIceCandidate(e)}),t._pendingCandidates=[],"offer"===t._pc.remoteDescription.type&&t._createAnswer())},function(e){t.destroy(e)}),e.sdp||e.candidate||t.destroy(new Error("signal() called with invalid signal data"))},r.prototype._addIceCandidate=function(e){var t=this;try{t._pc.addIceCandidate(new t._wrtc.RTCIceCandidate(e),i,function(e){t.destroy(e)})}catch(e){t.destroy(new Error("error adding candidate: "+e.message))}},r.prototype.send=function(e){this._channel.send(e)},r.prototype.destroy=function(e){this._destroy(e,function(){})},r.prototype._destroy=function(e,t){var n=this;if(!n.destroyed){if(n._debug("destroy (error: %s)",e&&(e.message||e)),n.readable=n.writable=!1,n._readableState.ended||n.push(null),n._writableState.finished||n.end(),n.destroyed=!0,n.connected=!1,n._pcReady=!1,n._channelReady=!1,n._previousStreams=null,clearInterval(n._interval),clearTimeout(n._reconnectTimeout),n._interval=null,n._reconnectTimeout=null,n._chunk=null,n._cb=null,n._onFinishBound&&n.removeListener("finish",n._onFinishBound),n._onFinishBound=null,n._pc){try{n._pc.close()}catch(e){}n._pc.oniceconnectionstatechange=null,n._pc.onicegatheringstatechange=null,n._pc.onsignalingstatechange=null,n._pc.onicecandidate=null,"addTrack"in n._pc?n._pc.ontrack=null:n._pc.onaddstream=null,n._pc.onnegotiationneeded=null,n._pc.ondatachannel=null}if(n._channel){try{n._channel.close()}catch(e){}n._channel.onmessage=null,n._channel.onopen=null,n._channel.onclose=null,n._channel.onerror=null}n._pc=null,n._channel=null,e&&n.emit("error",e),n.emit("close"),t()}},r.prototype._setupData=function(e){var t=this;if(!e.channel)return t.destroy(new Error("Data channel event is missing `channel` property"));t._channel=e.channel,t._channel.binaryType="arraybuffer","number"==typeof t._channel.bufferedAmountLowThreshold&&(t._channel.bufferedAmountLowThreshold=65536),t.channelName=t._channel.label,t._channel.onmessage=function(e){t._onChannelMessage(e)},t._channel.onbufferedamountlow=function(){t._onChannelBufferedAmountLow()},t._channel.onopen=function(){t._onChannelOpen()},t._channel.onclose=function(){t._onChannelClose()},t._channel.onerror=function(e){t.destroy(e)}},r.prototype._read=function(){},r.prototype._write=function(e,t,n){var r=this;if(r.destroyed)return n(new Error("cannot write after peer is destroyed"));if(r.connected){try{r.send(e)}catch(e){return r.destroy(e)}r._channel.bufferedAmount>65536?(r._debug("start backpressure: bufferedAmount %d",r._channel.bufferedAmount),r._cb=n):n(null)}else r._debug("write before connect"),r._chunk=e,r._cb=n},r.prototype._onFinish=function(){function e(){setTimeout(function(){t.destroy()},1e3)}var t=this;t.destroyed||(t.connected?e():t.once("connect",e))},r.prototype._createOffer=function(){var e=this;e.destroyed||e._pc.createOffer(function(t){function n(){e.destroyed||(e.trickle||e._iceComplete?i():e.once("_iceComplete",i))}function r(t){e.destroy(t)}function i(){var n=e._pc.localDescription||t;e._debug("signal"),e.emit("signal",{type:n.type,sdp:n.sdp})}e.destroyed||(t.sdp=e.sdpTransform(t.sdp),e._pc.setLocalDescription(t,n,r))},function(t){e.destroy(t)},e.offerConstraints)},r.prototype._createAnswer=function(){var e=this;e.destroyed||e._pc.createAnswer(function(t){function n(){e.destroyed||(e.trickle||e._iceComplete?i():e.once("_iceComplete",i))}function r(t){e.destroy(t)}function i(){var n=e._pc.localDescription||t;e._debug("signal"),e.emit("signal",{type:n.type,sdp:n.sdp})}e.destroyed||(t.sdp=e.sdpTransform(t.sdp),e._pc.setLocalDescription(t,n,r))},function(t){e.destroy(t)},e.answerConstraints)},r.prototype._onIceStateChange=function(){var e=this;if(!e.destroyed){var t=e._pc.iceConnectionState,n=e._pc.iceGatheringState;e._debug("iceStateChange (connection: %s) (gathering: %s)",t,n),e.emit("iceStateChange",t,n),"connected"!==t&&"completed"!==t||(clearTimeout(e._reconnectTimeout),e._pcReady=!0,e._maybeReady()),"disconnected"===t&&(e.reconnectTimer?(clearTimeout(e._reconnectTimeout),e._reconnectTimeout=setTimeout(function(){e.destroy()},e.reconnectTimer)):e.destroy()),"failed"===t&&e.destroy(new Error("Ice connection failed.")),"closed"===t&&e.destroy()}},r.prototype.getStats=function(e){var t=this;0===t._pc.getStats.length?t._pc.getStats().then(function(t){var n=[];t.forEach(function(e){n.push(e)}),e(null,n)},function(t){e(t)}):t._isReactNativeWebrtc?t._pc.getStats(null,function(t){var n=[];t.forEach(function(e){n.push(e)}),e(null,n)},function(t){e(t)}):t._pc.getStats.length>0?t._pc.getStats(function(n){if(!t.destroyed){var r=[];n.result().forEach(function(e){var t={};e.names().forEach(function(n){t[n]=e.stat(n)}),t.id=e.id,t.type=e.type,t.timestamp=e.timestamp,r.push(t)}),e(null,r)}},function(t){e(t)}):e(null,[])},r.prototype._maybeReady=function(){function e(){t.destroyed||t.getStats(function(n,r){function i(e){u=!0;var n=a[e.localCandidateId];n&&n.ip?(t.localAddress=n.ip,t.localPort=Number(n.port)):n&&n.ipAddress?(t.localAddress=n.ipAddress,t.localPort=Number(n.portNumber)):"string"==typeof e.googLocalAddress&&(n=e.googLocalAddress.split(":"),t.localAddress=n[0],t.localPort=Number(n[1]));var r=o[e.remoteCandidateId];r&&r.ip?(t.remoteAddress=r.ip,t.remotePort=Number(r.port)):r&&r.ipAddress?(t.remoteAddress=r.ipAddress,t.remotePort=Number(r.portNumber)):"string"==typeof e.googRemoteAddress&&(r=e.googRemoteAddress.split(":"),t.remoteAddress=r[0],t.remotePort=Number(r[1])),t.remoteFamily="IPv4",t._debug("connect local: %s:%s remote: %s:%s",t.localAddress,t.localPort,t.remoteAddress,t.remotePort)}if(!t.destroyed){n&&(r=[]);var o={},a={},s={},u=!1;if(r.forEach(function(e){"remotecandidate"!==e.type&&"remote-candidate"!==e.type||(o[e.id]=e),"localcandidate"!==e.type&&"local-candidate"!==e.type||(a[e.id]=e),"candidatepair"!==e.type&&"candidate-pair"!==e.type||(s[e.id]=e)}),r.forEach(function(e){"transport"===e.type&&i(s[e.selectedCandidatePairId]),("googCandidatePair"===e.type&&"true"===e.googActiveConnection||("candidatepair"===e.type||"candidate-pair"===e.type)&&e.selected)&&i(e)}),!(u||Object.keys(s).length&&!Object.keys(a).length))return void setTimeout(e,100);if(t._connecting=!1,t.connected=!0,t._chunk){try{t.send(t._chunk)}catch(n){return t.destroy(n)}t._chunk=null,t._debug('sent chunk from "write before connect"');var c=t._cb;t._cb=null,c(null)}"number"!=typeof t._channel.bufferedAmountLowThreshold&&(t._interval=setInterval(function(){t._onInterval()},150),t._interval.unref&&t._interval.unref()),t._debug("connect"),t.emit("connect")}})}var t=this;t._debug("maybeReady pc %s channel %s",t._pcReady,t._channelReady),!t.connected&&!t._connecting&&t._pcReady&&t._channelReady&&(t._connecting=!0,e())},r.prototype._onInterval=function(){var e=this;!e._cb||!e._channel||e._channel.bufferedAmount>65536||e._onChannelBufferedAmountLow()},r.prototype._onSignalingStateChange=function(){var e=this;e.destroyed||(e._debug("signalingStateChange %s",e._pc.signalingState),e.emit("signalingStateChange",e._pc.signalingState))},r.prototype._onIceCandidate=function(e){var t=this;t.destroyed||(e.candidate&&t.trickle?t.emit("signal",{candidate:{candidate:e.candidate.candidate,sdpMLineIndex:e.candidate.sdpMLineIndex,sdpMid:e.candidate.sdpMid}}):e.candidate||(t._iceComplete=!0,t.emit("_iceComplete")))},r.prototype._onChannelMessage=function(e){var n=this;if(!n.destroyed){var r=e.data;r instanceof ArrayBuffer&&(r=t.from(r)),n.push(r)}},r.prototype._onChannelBufferedAmountLow=function(){var e=this;if(!e.destroyed&&e._cb){e._debug("ending backpressure: bufferedAmount %d",e._channel.bufferedAmount);var t=e._cb;e._cb=null,t(null)}},r.prototype._onChannelOpen=function(){var e=this;e.connected||e.destroyed||(e._debug("on channel open"),e._channelReady=!0,e._maybeReady())},r.prototype._onChannelClose=function(){var e=this;e.destroyed||(e._debug("on channel close"),e.destroy())},r.prototype._onAddStream=function(e){var t=this;t.destroyed||(t._debug("on add stream"),t.emit("stream",e.stream))},r.prototype._onTrack=function(e){var t=this;if(!t.destroyed){t._debug("on track");var n=e.streams[0].id;-1===t._previousStreams.indexOf(n)&&(t._previousStreams.push(n),t.emit("stream",e.streams[0]))}},r.prototype._debug=function(){var e=this,t=[].slice.call(arguments);t[0]="["+e._id+"] "+t[0],a.apply(null,t)},r.prototype._transformConstraints=function(e){var t=this;if(0===Object.keys(e).length)return e;if((e.mandatory||e.optional)&&!t._isChromium){var n=Object.assign({},e.optional,e.mandatory);return void 0!==n.OfferToReceiveVideo&&(n.offerToReceiveVideo=n.OfferToReceiveVideo,delete n.OfferToReceiveVideo),void 0!==n.OfferToReceiveAudio&&(n.offerToReceiveAudio=n.OfferToReceiveAudio,delete n.OfferToReceiveAudio),n}return e.mandatory||e.optional||!t._isChromium?e:(void 0!==e.offerToReceiveVideo&&(e.OfferToReceiveVideo=e.offerToReceiveVideo,delete e.offerToReceiveVideo),void 0!==e.offerToReceiveAudio&&(e.OfferToReceiveAudio=e.offerToReceiveAudio,delete e.offerToReceiveAudio),{mandatory:e})}}).call(t,n(2).Buffer)},function(e,t,n){"use strict";function r(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===e[t-2]?2:"="===e[t-1]?1:0}function i(e){return 3*e.length/4-r(e)}function o(e){var t,n,i,o,a,s=e.length;o=r(e),a=new f(3*s/4-o),n=o>0?s-4:s;var u=0;for(t=0;t<n;t+=4)i=l[e.charCodeAt(t)]<<18|l[e.charCodeAt(t+1)]<<12|l[e.charCodeAt(t+2)]<<6|l[e.charCodeAt(t+3)],a[u++]=i>>16&255,a[u++]=i>>8&255,a[u++]=255&i;return 2===o?(i=l[e.charCodeAt(t)]<<2|l[e.charCodeAt(t+1)]>>4,a[u++]=255&i):1===o&&(i=l[e.charCodeAt(t)]<<10|l[e.charCodeAt(t+1)]<<4|l[e.charCodeAt(t+2)]>>2,a[u++]=i>>8&255,a[u++]=255&i),a}function a(e){return c[e>>18&63]+c[e>>12&63]+c[e>>6&63]+c[63&e]}function s(e,t,n){for(var r,i=[],o=t;o<n;o+=3)r=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]),i.push(a(r));return i.join("")}function u(e){for(var t,n=e.length,r=n%3,i="",o=[],a=0,u=n-r;a<u;a+=16383)o.push(s(e,a,a+16383>u?u:a+16383));return 1===r?(t=e[n-1],i+=c[t>>2],i+=c[t<<4&63],i+="=="):2===r&&(t=(e[n-2]<<8)+e[n-1],i+=c[t>>10],i+=c[t>>4&63],i+=c[t<<2&63],i+="="),o.push(i),o.join("")}t.byteLength=i,t.toByteArray=o,t.fromByteArray=u;for(var c=[],l=[],f="undefined"!=typeof Uint8Array?Uint8Array:Array,d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",h=0,p=d.length;h<p;++h)c[h]=d[h],l[d.charCodeAt(h)]=h;l["-".charCodeAt(0)]=62,l["_".charCodeAt(0)]=63},function(e,t){t.read=function(e,t,n,r,i){var o,a,s=8*i-r-1,u=(1<<s)-1,c=u>>1,l=-7,f=n?i-1:0,d=n?-1:1,h=e[t+f];for(f+=d,o=h&(1<<-l)-1,h>>=-l,l+=s;l>0;o=256*o+e[t+f],f+=d,l-=8);for(a=o&(1<<-l)-1,o>>=-l,l+=r;l>0;a=256*a+e[t+f],f+=d,l-=8);if(0===o)o=1-c;else{if(o===u)return a?NaN:1/0*(h?-1:1);a+=Math.pow(2,r),o-=c}return(h?-1:1)*a*Math.pow(2,o-r)},t.write=function(e,t,n,r,i,o){var a,s,u,c=8*o-i-1,l=(1<<c)-1,f=l>>1,d=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,h=r?0:o-1,p=r?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(s=isNaN(t)?1:0,a=l):(a=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-a))<1&&(a--,u*=2),t+=a+f>=1?d/u:d*Math.pow(2,1-f),t*u>=2&&(a++,u/=2),a+f>=l?(s=0,a=l):a+f>=1?(s=(t*u-1)*Math.pow(2,i),a+=f):(s=t*Math.pow(2,f-1)*Math.pow(2,i),a=0));i>=8;e[n+h]=255&s,h+=p,s/=256,i-=8);for(a=a<<i|s,c+=i;c>0;e[n+h]=255&a,h+=p,a/=256,c-=8);e[n+h-p]|=128*g}},function(e,t){var n={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==n.call(e)}},function(e,t,n){"use strict";(function(r){function i(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))}function o(e){var n=this.useColors;if(e[0]=(n?"%c":"")+this.namespace+(n?" %c":" ")+e[0]+(n?"%c ":" ")+"+"+t.humanize(this.diff),n){var r="color: "+this.color;e.splice(1,0,r,"color: inherit");var i=0,o=0;e[0].replace(/%[a-zA-Z%]/g,function(e){"%%"!==e&&(i++,"%c"===e&&(o=i))}),e.splice(o,0,r)}}function a(){return"object"===("undefined"==typeof console?"undefined":c(console))&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function s(e){try{null==e?t.storage.removeItem("debug"):t.storage.debug=e}catch(e){}}function u(){var e;try{e=t.storage.debug}catch(e){}return!e&&void 0!==r&&"env"in r&&(e=r.env.DEBUG),e}var c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t=e.exports=n(31),t.log=a,t.formatArgs=o,t.save=s,t.load=u,t.useColors=i,t.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(e){}}(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}},t.enable(u())}).call(t,n(3))},function(e,t,n){"use strict";function r(e){var n,r=0;for(n in e)r=(r<<5)-r+e.charCodeAt(n),r|=0;return t.colors[Math.abs(r)%t.colors.length]}function i(e){function n(){if(n.enabled){var e=n,r=+new Date,o=r-(i||r);e.diff=o,e.prev=i,e.curr=r,i=r;for(var a=new Array(arguments.length),s=0;s<a.length;s++)a[s]=arguments[s];a[0]=t.coerce(a[0]),"string"!=typeof a[0]&&a.unshift("%O");var u=0;a[0]=a[0].replace(/%([a-zA-Z%])/g,function(n,r){if("%%"===n)return n;u++;var i=t.formatters[r];if("function"==typeof i){var o=a[u];n=i.call(e,o),a.splice(u,1),u--}return n}),t.formatArgs.call(e,a);(n.log||t.log||console.log.bind(console)).apply(e,a)}}var i;return n.namespace=e,n.enabled=t.enabled(e),n.useColors=t.useColors(),n.color=r(e),n.destroy=o,"function"==typeof t.init&&t.init(n),t.instances.push(n),n}function o(){var e=t.instances.indexOf(this);return-1!==e&&(t.instances.splice(e,1),!0)}function a(e){t.save(e),t.names=[],t.skips=[];var n,r=("string"==typeof e?e:"").split(/[\s,]+/),i=r.length;for(n=0;n<i;n++)r[n]&&(e=r[n].replace(/\*/g,".*?"),"-"===e[0]?t.skips.push(new RegExp("^"+e.substr(1)+"$")):t.names.push(new RegExp("^"+e+"$")));for(n=0;n<t.instances.length;n++){var o=t.instances[n];o.enabled=t.enabled(o.namespace)}}function s(){t.enable("")}function u(e){if("*"===e[e.length-1])return!0;var n,r;for(n=0,r=t.skips.length;n<r;n++)if(t.skips[n].test(e))return!1;for(n=0,r=t.names.length;n<r;n++)if(t.names[n].test(e))return!0;return!1}function c(e){return e instanceof Error?e.stack||e.message:e}t=e.exports=i.debug=i.default=i,t.coerce=c,t.disable=s,t.enable=a,t.enabled=u,t.humanize=n(32),t.instances=[],t.names=[],t.skips=[],t.formatters={}},function(e,t,n){"use strict";function r(e){if(e=String(e),!(e.length>100)){var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(t){var n=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return n*d;case"days":case"day":case"d":return n*f;case"hours":case"hour":case"hrs":case"hr":case"h":return n*l;case"minutes":case"minute":case"mins":case"min":case"m":return n*c;case"seconds":case"second":case"secs":case"sec":case"s":return n*u;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}}}function i(e){return e>=f?Math.round(e/f)+"d":e>=l?Math.round(e/l)+"h":e>=c?Math.round(e/c)+"m":e>=u?Math.round(e/u)+"s":e+"ms"}function o(e){return a(e,f,"day")||a(e,l,"hour")||a(e,c,"minute")||a(e,u,"second")||e+" ms"}function a(e,t,n){if(!(e<t))return e<1.5*t?Math.floor(e/t)+" "+n:Math.ceil(e/t)+" "+n+"s"}var s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},u=1e3,c=60*u,l=60*c,f=24*l,d=365.25*f;e.exports=function(e,t){t=t||{};var n=void 0===e?"undefined":s(e);if("string"===n&&e.length>0)return r(e);if("number"===n&&!1===isNaN(e))return t.long?o(e):i(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},function(e,t,n){"use strict";e.exports=function(){if("undefined"==typeof window)return null;var e={RTCPeerConnection:window.RTCPeerConnection||window.mozRTCPeerConnection||window.webkitRTCPeerConnection,RTCSessionDescription:window.RTCSessionDescription||window.mozRTCSessionDescription||window.webkitRTCSessionDescription,RTCIceCandidate:window.RTCIceCandidate||window.mozRTCIceCandidate||window.webkitRTCIceCandidate};return e.RTCPeerConnection?e:null}},function(e,t,n){"use strict";(function(t,r){function i(){throw new Error("Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11")}function o(e,n){if(e>65536)throw new Error("requested too many random bytes");var i=new t.Uint8Array(e);e>0&&s.getRandomValues(i);var o=a.from(i.buffer);return"function"==typeof n?r.nextTick(function(){n(null,o)}):o}var a=n(8).Buffer,s=t.crypto||t.msCrypto;s&&s.getRandomValues?e.exports=o:e.exports=i}).call(t,n(1),n(3))},function(e,t,n){"use strict";t=e.exports=n(12),t.Stream=t,t.Readable=t,t.Writable=n(15),t.Duplex=n(5),t.Transform=n(17),t.PassThrough=n(44)},function(e,t,n){"use strict";var r={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==r.call(e)}},function(e,t){},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t,n){e.copy(t,n)}var o=n(8).Buffer,a=n(39);e.exports=function(){function e(){r(this,e),this.head=null,this.tail=null,this.length=0}return e.prototype.push=function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length},e.prototype.unshift=function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length},e.prototype.shift=function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}},e.prototype.clear=function(){this.head=this.tail=null,this.length=0},e.prototype.join=function(e){if(0===this.length)return"";for(var t=this.head,n=""+t.data;t=t.next;)n+=e+t.data;return n},e.prototype.concat=function(e){if(0===this.length)return o.alloc(0);if(1===this.length)return this.head.data;for(var t=o.allocUnsafe(e>>>0),n=this.head,r=0;n;)i(n.data,t,r),r+=n.data.length,n=n.next;return t},e}(),a&&a.inspect&&a.inspect.custom&&(e.exports.prototype[a.inspect.custom]=function(){var e=a.inspect({length:this.length});return this.constructor.name+" "+e})},function(e,t){},function(e,t,n){(function(e){function r(e,t){this._id=e,this._clearFn=t}var i=Function.prototype.apply;t.setTimeout=function(){return new r(i.call(setTimeout,window,arguments),clearTimeout)},t.setInterval=function(){return new r(i.call(setInterval,window,arguments),clearInterval)},t.clearTimeout=t.clearInterval=function(e){e&&e.close()},r.prototype.unref=r.prototype.ref=function(){},r.prototype.close=function(){this._clearFn.call(window,this._id)},t.enroll=function(e,t){clearTimeout(e._idleTimeoutId),e._idleTimeout=t},t.unenroll=function(e){clearTimeout(e._idleTimeoutId),e._idleTimeout=-1},t._unrefActive=t.active=function(e){clearTimeout(e._idleTimeoutId);var t=e._idleTimeout;t>=0&&(e._idleTimeoutId=setTimeout(function(){e._onTimeout&&e._onTimeout()},t))},n(41),t.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==e&&e.setImmediate||this&&this.setImmediate,t.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==e&&e.clearImmediate||this&&this.clearImmediate}).call(t,n(1))},function(e,t,n){(function(e,t){!function(e,n){"use strict";function r(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),n=0;n<t.length;n++)t[n]=arguments[n+1];var r={callback:e,args:t};return c[u]=r,s(u),u++}function i(e){delete c[e]}function o(e){var t=e.callback,r=e.args;switch(r.length){case 0:t();break;case 1:t(r[0]);break;case 2:t(r[0],r[1]);break;case 3:t(r[0],r[1],r[2]);break;default:t.apply(n,r)}}function a(e){if(l)setTimeout(a,0,e);else{var t=c[e];if(t){l=!0;try{o(t)}finally{i(e),l=!1}}}}if(!e.setImmediate){var s,u=1,c={},l=!1,f=e.document,d=Object.getPrototypeOf&&Object.getPrototypeOf(e);d=d&&d.setTimeout?d:e,"[object process]"==={}.toString.call(e.process)?function(){s=function(e){t.nextTick(function(){a(e)})}}():function(){if(e.postMessage&&!e.importScripts){var t=!0,n=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=n,t}}()?function(){var t="setImmediate$"+Math.random()+"$",n=function(n){n.source===e&&"string"==typeof n.data&&0===n.data.indexOf(t)&&a(+n.data.slice(t.length))};e.addEventListener?e.addEventListener("message",n,!1):e.attachEvent("onmessage",n),s=function(n){e.postMessage(t+n,"*")}}():e.MessageChannel?function(){var e=new MessageChannel;e.port1.onmessage=function(e){a(e.data)},s=function(t){e.port2.postMessage(t)}}():f&&"onreadystatechange"in f.createElement("script")?function(){var e=f.documentElement;s=function(t){var n=f.createElement("script");n.onreadystatechange=function(){a(t),n.onreadystatechange=null,e.removeChild(n),n=null},e.appendChild(n)}}():function(){s=function(e){setTimeout(a,0,e)}}(),d.setImmediate=r,d.clearImmediate=i}}("undefined"==typeof self?void 0===e?this:e:self)}).call(t,n(1),n(3))},function(e,t,n){"use strict";(function(t){function n(e,t){function n(){if(!i){if(r("throwDeprecation"))throw new Error(t);r("traceDeprecation")?console.trace(t):console.warn(t),i=!0}return e.apply(this,arguments)}if(r("noDeprecation"))return e;var i=!1;return n}function r(e){try{if(!t.localStorage)return!1}catch(e){return!1}var n=t.localStorage[e];return null!=n&&"true"===String(n).toLowerCase()}e.exports=n}).call(t,n(1))},function(e,t,n){function r(e,t){for(var n in e)t[n]=e[n]}function i(e,t,n){return a(e,t,n)}var o=n(2),a=o.Buffer;a.from&&a.alloc&&a.allocUnsafe&&a.allocUnsafeSlow?e.exports=o:(r(o,t),t.Buffer=i),r(a,i),i.from=function(e,t,n){if("number"==typeof e)throw new TypeError("Argument must not be a number");return a(e,t,n)},i.alloc=function(e,t,n){if("number"!=typeof e)throw new TypeError("Argument must be a number");var r=a(e);return void 0!==t?"string"==typeof n?r.fill(t,n):r.fill(t):r.fill(0),r},i.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return a(e)},i.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return o.SlowBuffer(e)}},function(e,t,n){"use strict";function r(e){if(!(this instanceof r))return new r(e);i.call(this,e)}e.exports=r;var i=n(17),o=n(6);o.inherits=n(4),o.inherits(r,i),r.prototype._transform=function(e,t,n){n(null,e)}},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},o=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=n(46),s=function(){function e(t,n,o,s,u){r(this,e),this.engine=t,this.key=n,this.baseUrl=s,this.channelId=a.Base64.encode(o),this.announceInfo=i({},u,{channel:this.channelId}),this.announceURL=s+"/channel",this.key=n,this.limit=10240,this.conns=0,this.failConns=0,this.totalHTTPDownloaded=0,this.totalP2PDownloaded=0,this.totalP2PUploaded=0,this.httpDownloaded=0,this.p2pDownloaded=0,this.errsFragLoad=0,this.errsBufStalled=0,this.errsInternalExpt=0}return o(e,[{key:"btAnnounce",value:function(){var e=this,t=this.engine.logger;return new Promise(function(n,r){fetch(e.announceURL,{headers:e._requestHeader,method:"POST",body:JSON.stringify(e.announceInfo)}).then(function(e){return e.json()}).then(function(t){if(-1===t.ret)r(t.data.msg);else{var i=t.data;e.peerId=i.id,e.btStats(i.report_interval),e.getPeersURL=e.baseUrl+"/channel/"+e.channelId+"/node/"+e.peerId+"/peers",e.statsURL=e.baseUrl+"/channel/"+e.channelId+"/node/"+e.peerId+"/stats",n(t.data)}}).catch(function(e){t.error("btAnnounce error "+e),r(e)})})}},{key:"btStats",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10,n=this.engine.logger;this.heartbeater=window.setInterval(function(){fetch(e.statsURL,{headers:e._requestHeader,method:"POST",body:JSON.stringify(e._makeStatsBody())}).then(function(t){t.ok&&(n.info("sucessfully report stats"),e.httpDownloaded=0,e.p2pDownloaded=0,e.conns=0,e.failConns=0,e.errsFragLoad=0,e.errsBufStalled=0,e.errsInternalExpt=0)}).catch(function(e){n.error("btStats error "+e)})},1e3*t)}},{key:"btGetPeers",value:function(){var e=this,t=this.engine.logger;return new Promise(function(n,r){fetch(e.getPeersURL,{headers:e._requestHeader,method:"POST"}).then(function(e){return e.json()}).then(function(e){-1===e.ret?r(e.data.msg):n(e.data)}).catch(function(e){t.error("btGetPeers error "+e),r(e)})})}},{key:"increConns",value:function(){this.conns++}},{key:"decreConns",value:function(){this.conns--}},{key:"increFailConns",value:function(){this.failConns++}},{key:"reportFlow",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=Math.round(e.total/1024);t?(this.p2pDownloaded+=n,this.totalP2PDownloaded+=n):(this.httpDownloaded+=n,this.totalHTTPDownloaded+=n),this._emitStats()}},{key:"reportUploaded",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.totalP2PUploaded+=Math.round(e/1024),this._emitStats()}},{key:"destroy",value:function(){window.clearInterval(this.heartbeater)}},{key:"_emitStats",value:function(){this.engine.emit("stats",{totalHTTPDownloaded:this.totalHTTPDownloaded,totalP2PDownloaded:this.totalP2PDownloaded,totalP2PUploaded:this.totalP2PUploaded})}},{key:"_makeStatsBody",value:function(){return{conns:this.conns,failConns:this.failConns,errsFragLoad:this.errsFragLoad,errsBufStalled:this.errsBufStalled,errsInternalExpt:this.errsInternalExpt,http:Math.round(this.httpDownloaded),p2p:Math.round(this.p2pDownloaded)}}},{key:"_requestHeader",get:function(){return{}}}]),e}();t.default=s,e.exports=t.default},function(e,t,n){"use strict";(function(r){var i,o,a,o,s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};!function(r,a){"object"===s(t)&&void 0!==e?e.exports=a(r):(i=a,void 0!==(o="function"==typeof i?i.call(t,n,t,e):i)&&(e.exports=o))}("undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==r?r:void 0,function(r){var i,s=r.Base64;if(void 0!==e&&e.exports)if("undefined"!=typeof navigator&&"ReactNative"==navigator.product);else try{i=n(2).Buffer}catch(e){}var u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",c=function(e){for(var t={},n=0,r=e.length;n<r;n++)t[e.charAt(n)]=n;return t}(u),l=String.fromCharCode,f=function(e){if(e.length<2){var t=e.charCodeAt(0);return t<128?e:t<2048?l(192|t>>>6)+l(128|63&t):l(224|t>>>12&15)+l(128|t>>>6&63)+l(128|63&t)}var t=65536+1024*(e.charCodeAt(0)-55296)+(e.charCodeAt(1)-56320);return l(240|t>>>18&7)+l(128|t>>>12&63)+l(128|t>>>6&63)+l(128|63&t)},d=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,h=function(e){return e.replace(d,f)},p=function(e){var t=[0,2,1][e.length%3],n=e.charCodeAt(0)<<16|(e.length>1?e.charCodeAt(1):0)<<8|(e.length>2?e.charCodeAt(2):0);return[u.charAt(n>>>18),u.charAt(n>>>12&63),t>=2?"=":u.charAt(n>>>6&63),t>=1?"=":u.charAt(63&n)].join("")},g=r.btoa?function(e){return r.btoa(e)}:function(e){return e.replace(/[\s\S]{1,3}/g,p)},y=i?i.from&&Uint8Array&&i.from!==Uint8Array.from?function(e){return(e.constructor===i.constructor?e:i.from(e)).toString("base64")}:function(e){return(e.constructor===i.constructor?e:new i(e)).toString("base64")}:function(e){return g(h(e))},v=function(e,t){return t?y(String(e)).replace(/[+\/]/g,function(e){return"+"==e?"-":"_"}).replace(/=/g,""):y(String(e))},b=function(e){return v(e,!0)},m=new RegExp(["[À-ß][-¿]","[à-ï][-¿]{2}","[ð-÷][-¿]{3}"].join("|"),"g"),_=function(e){switch(e.length){case 4:var t=(7&e.charCodeAt(0))<<18|(63&e.charCodeAt(1))<<12|(63&e.charCodeAt(2))<<6|63&e.charCodeAt(3),n=t-65536;return l(55296+(n>>>10))+l(56320+(1023&n));case 3:return l((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return l((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}},w=function(e){return e.replace(m,_)},C=function(e){var t=e.length,n=t%4,r=(t>0?c[e.charAt(0)]<<18:0)|(t>1?c[e.charAt(1)]<<12:0)|(t>2?c[e.charAt(2)]<<6:0)|(t>3?c[e.charAt(3)]:0),i=[l(r>>>16),l(r>>>8&255),l(255&r)];return i.length-=[0,0,2,1][n],i.join("")},S=r.atob?function(e){return r.atob(e)}:function(e){return e.replace(/[\s\S]{1,4}/g,C)},E=i?i.from&&Uint8Array&&i.from!==Uint8Array.from?function(e){return(e.constructor===i.constructor?e:i.from(e,"base64")).toString()}:function(e){return(e.constructor===i.constructor?e:new i(e,"base64")).toString()}:function(e){return w(S(e))},T=function(e){return E(String(e).replace(/[-_]/g,function(e){return"-"==e?"+":"/"}).replace(/[^A-Za-z0-9\+\/]/g,""))},P=function(){var e=r.Base64;return r.Base64=s,e};if(r.Base64={VERSION:"2.4.8",atob:S,btoa:g,fromBase64:T,toBase64:v,utob:h,encode:v,encodeURI:b,btou:w,decode:T,noConflict:P},"function"==typeof Object.defineProperty){var R=function(e){return{value:e,enumerable:!1,writable:!0,configurable:!0}};r.Base64.extendString=function(){Object.defineProperty(String.prototype,"fromBase64",R(function(){return T(this)})),Object.defineProperty(String.prototype,"toBase64",R(function(e){return v(this,e)})),Object.defineProperty(String.prototype,"toBase64URI",R(function(){return v(this,!0)}))}}return r.Meteor&&(Base64=r.Base64),void 0!==e&&e.exports?e.exports.Base64=r.Base64:(a=[],void 0!==(o=function(){return r.Base64}.apply(t,a))&&(e.exports=o)),{Base64:r.Base64}})}).call(t,n(1))},function(e,t){e.exports=function(){if("undefined"==typeof window)return null;var e={RTCPeerConnection:window.RTCPeerConnection||window.mozRTCPeerConnection||window.webkitRTCPeerConnection,RTCSessionDescription:window.RTCSessionDescription||window.mozRTCSessionDescription||window.webkitRTCSessionDescription,RTCIceCandidate:window.RTCIceCandidate||window.mozRTCIceCandidate||window.webkitRTCIceCandidate};return e.RTCPeerConnection?e:null}},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),u=n(0),c=r(u),l=n(20),f=r(l),d=function(e){function t(e,n,r){i(this,t);var a=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return a.engine=e,a.peerId=n,a.config=r,a.connected=!1,a._ws=a._init(n),a}return a(t,e),s(t,[{key:"_init",value:function(e){var t=this,n=this.engine.logger,r={maxRetries:this.config.wsMaxRetries,minReconnectionDelay:1e3*this.config.wsReconnectInterval},i="?id="+e,o=new f.default(this.config.wsSignalerAddr+i,void 0,r);return o.onopen=function(){n.info("Signaler websocket connection opened"),t.connected=!0,t.onopen&&t.onopen()},o.push=o.send,o.send=function(t){var n=JSON.stringify(Object.assign({peer_id:e},t));o.push(n)},o.onmessage=function(e){t.onmessage&&t.onmessage(e)},o.onclose=function(){n.warn("Signaler websocket closed"),t.onclose&&t.onclose(),t.connected=!1},o}},{key:"sendSignal",value:function(e,t){var n={action:"signal",peer_id:this.peerId,to_peer_id:e,data:t};this.send(n)}},{key:"send",value:function(e){this._ws.send(e)}},{key:"close",value:function(){this._ws.close(),this._ws=null}}]),t}(c.default);t.default=d,e.exports=t.default},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),u=n(0),c=r(u),l=n(19),f=r(l),d=function(e){function t(e){i(this,t);var n=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return n.logger=e.logger,n.currLoaded=e.currLoaded,n.currLoadedDuration=e.currLoadedDuration,n.currPlay=e.currPlay,n.bufMgr=e.bufMgr,n.xhrLoader=new e.loader(e),n.p2pEnabled=e.p2pEnabled,n.scheduler=e.scheduler,n.fetcher=e.fetcher,n}return a(t,e),s(t,[{key:"destroy",value:function(){this.abort()}},{key:"abort",value:function(){this.xhrLoader.abort()}},{key:"load",value:function(e,t,n){var r=this,i=this.logger,o=e.frag,a=f.default.parseURL(o.url);if(o.relurl=a.path+a.query,o.loadByP2P=!1,o.loadByHTTP=!1,this.bufMgr.hasSegOfURL(o.relurl)){i.debug("bufMgr found seg sn "+o.sn+" url "+o.relurl);var s=this.bufMgr.getSegByURL(o.relurl),u={url:e.url,data:s.data},c=void 0,l=void 0,d=void 0,h=void 0,p=void 0;c=performance.now(),l=d=c+50,h=p=o.loaded=s.size;var g={trequest:c,tfirst:l,tload:d,loaded:h,total:p,retry:0};o.loadByP2P=!0,e.frag.fromPeerId=s.fromPeerId,i.debug("bufMgr loaded "+o.relurl+" at "+o.sn),window.setTimeout(function(){r.fetcher.reportFlow(g,!0),n.onSuccess(u,g,e)},50)}else if(this.scheduler.hasAndSetTargetPeer(o.sn)){e.frag.loadByP2P=!0,this.scheduler.load(e,t,n),n.onTimeout=function(e,a){i.debug("P2P timeout switched to HTTP load "+o.relurl+" at "+o.sn),o.loadByP2P=!1,o.loadByHTTP=!0,r.xhrLoader.load(a,t,n)};var y=n.onSuccess;n.onSuccess=function(e,t,n){r.bufMgr.hasSegOfURL(o.relurl)||r.bufMgr.copyAndAddBuffer(e.data,o.relurl,o.sn,o.fromPeerId||r.fetcher.peerId),r.fetcher.reportFlow(t,o.loadByP2P),o.loaded=t.loaded,i.debug((o.loadByP2P?"P2P":"HTTP")+" loaded "+o.relurl+" at "+o.sn),y(e,t,n)}}else{i.debug("HTTP load "+o.relurl+" at "+o.sn),e.frag.loadByHTTP=!0,this.xhrLoader.load(e,t,n);var v=n.onSuccess;n.onSuccess=function(e,t,n){r.bufMgr.hasSegOfURL(o.relurl)||r.bufMgr.copyAndAddBuffer(e.data,o.relurl,o.sn,r.fetcher.peerId),r.fetcher.reportFlow(t,!1),i.info("HTTP load time "+(t.tload-t.trequest)+"ms"),r.scheduler.loadTimeSample=t.tload-t.trequest,v(e,t,n)}}}}]),t}(c.default);t.default=d,e.exports=t.default},function(e,t,n){"use strict";function r(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),u=n(0),c=function(e){return e&&e.__esModule?e:{default:e}}(u),l=n(7),f=n(10),d=function(e){function t(e,n){i(this,t);var r=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return r.engine=e,r.config=n,r._segPool=new Map,r._currBufSize=0,r.sn2Url=new Map,r.overflowed=!1,r}return a(t,e),s(t,[{key:"hasSegOfURL",value:function(e){return this._segPool.has(e)}},{key:"copyAndAddBuffer",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",i=(0,f.handleTSUrl)(t,this.config.tsStrictMatched),o=l.Buffer.from(e),a=o.byteLength,s=new l.Buffer(a);o.copy(s);var u={sn:n,relurl:i,data:s,size:a,fromPeerId:r};this.addSeg(u),this.sn2Url.set(n,i)}},{key:"addBuffer",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",i=(0,f.handleTSUrl)(t,this.config.tsStrictMatched),o={sn:e,relurl:i,data:n,size:n.byteLength,fromPeerId:r};this.addSeg(o),this.sn2Url.set(e,i)}},{key:"addSeg",value:function(e){var t=this.engine.logger;for(this._segPool.set(e.relurl,e),this._currBufSize+=parseInt(e.size);this._currBufSize>this.config.maxBufSize;){var n=[].concat(r(this._segPool.values())).shift();t.info("pop seg "+n.relurl+" at "+n.sn),this._segPool.delete(n.relurl),this.sn2Url.delete(n.sn),this._currBufSize-=parseInt(n.size),this.overflowed||(this.overflowed=!0),this.emit(l.Events.BM_LOST,n.sn)}}},{key:"getSegByURL",value:function(e){return this._segPool.get(e)}},{key:"getURLbySN",value:function(e){return this.sn2Url.get(e)}},{key:"clear",value:function(){this._segPool.clear(),this.sn2Url.clear(),this._currBufSize=0}},{key:"currBufSize",get:function(){return this._currBufSize}}]),t}(c.default);t.default=d,e.exports=t.default},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(){}Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=n(20),s=function(e){return e&&e.__esModule?e:{default:e}}(a),u={debug:0,info:1,warn:2,error:3,none:4},c=["_debugP","_infoP","_warnP","_errorP"],l=["_debugU","_infoU","_warnU","_errorU"],f=function(){function e(t,n){if(r(this,e),this.config=t,this.connected=!1,t.enableLogUpload)try{this._ws=this._initWs(n)}catch(e){this._ws=null}!0===t.logLevel?t.logLevel="debug":t.logLevel in u&&!1!==t.logLevel||(t.logLevel="none"),t.logUploadLevel in u||(t.logUploadLevel="none");for(var o=0;o<u[t.logLevel];o++)this[c[o]]=i;for(var a=0;a<u[t.logUploadLevel];a++)this[l[a]]=i;this.identifier=""}return o(e,[{key:"debug",value:function(e){this._debugP(e),this._debugU(e)}},{key:"info",value:function(e){this._infoP(e),this._infoU(e)}},{key:"warn",value:function(e){this._warnP(e),this._warnU(e)}},{key:"error",value:function(e){this._errorP(e),this._errorU(e)}},{key:"_debugP",value:function(e){console.log(e)}},{key:"_infoP",value:function(e){console.info(e)}},{key:"_warnP",value:function(e){console.warn(e)}},{key:"_errorP",value:function(e){console.error(e)}},{key:"_debugU",value:function(e){e="["+this.identifier+" debug] > "+e,this._uploadLog(e)}},{key:"_infoU",value:function(e){e="["+this.identifier+" info] > "+e,this._uploadLog(e)}},{key:"_warnU",value:function(e){e="["+this.identifier+" warn] > "+e,this._uploadLog(e)}},{key:"_errorU",value:function(e){e="["+this.identifier+" error] > "+e,this._uploadLog(e)}},{key:"_uploadLog",value:function(e){this.connected&&this._ws.send(e)}},{key:"_initWs",value:function(e){var t=this,n={maxRetries:this.config.wsMaxRetries,minReconnectionDelay:1e3*this.config.wsReconnectInterval},r=new s.default(this.config.logUploadAddr+"?info_hash="+window.encodeURIComponent(e),void 0,n);return r.onopen=function(){t.debug("Log websocket connection opened"),t.connected=!0},r.onclose=function(){t.warn("Log websocket closed"),t.connected=!1},r}}]),e}();t.default=f,e.exports=t.default},function(e,t,n){"use strict";function r(){return navigator.userAgent.toLowerCase()}function i(e){return""+(new RegExp(e+"(\\d+((\\.|_)\\d+)*)").exec(r())||[,0])[1]||void 0}function o(e){return parseFloat((e||"").replace(/\_/g,"."))||0}var a={getNetType:function(){return(new RegExp("nettype\\/(\\w*)").exec(r())||[,""])[1].toLowerCase()},getPlatform:function(){return a.isAndroid()?"android":a.isIOS()?"iOS":"PC"},isX5:function(){return this.isAndroid()&&/\s(TBS|X5Core)\/[\w\.\-]+/i.test(r())},isPC:function(){return!o(i("os "))&&!o(i("android[/ ]"))},isIOS:function(){return o(i("os "))},isAndroid:function(){return o(i("android[/ ]"))},isSafari:function(){return this.isIOS()&&/^((?!chrome|android).)*safari/i.test(r())}};e.exports=a}])});