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

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2016-01-08 05:59:18 +0300
committerFeross Aboukhadijeh <feross@feross.org>2016-01-08 05:59:18 +0300
commit213fadc7e2927b274e11398eddb63be13a8fb9ed (patch)
tree81c5958c33913ff5dec9d5f989d9108f9caa8391 /webtorrent.min.js
parentb2625e7b1e667913d9c1fc627cd749c61ea00644 (diff)
build
Diffstat (limited to 'webtorrent.min.js')
-rw-r--r--webtorrent.min.js2
1 files changed, 1 insertions, 1 deletions
diff --git a/webtorrent.min.js b/webtorrent.min.js
index 67918b3..0471281 100644
--- a/webtorrent.min.js
+++ b/webtorrent.min.js
@@ -7,4 +7,4 @@ t.enabled=false;function n(){var e=n;var t=+new Date;var o=t-(i||t);e.diff=o;e.p
if(t._pc.remoteDescription.type==="offer")t._createAnswer();t._pendingCandidates.forEach(n);t._pendingCandidates=[]},t._onError.bind(t))}if(e.candidate){if(t._pc.remoteDescription)n(e.candidate);else t._pendingCandidates.push(e.candidate)}if(!e.sdp&&!e.candidate){t._destroy(new Error("signal() called with invalid signal data"))}};l.prototype.send=function(e){var t=this;if(!a.strict(e)&&!(e instanceof ArrayBuffer)&&!r.isBuffer(e)&&typeof e!=="string"&&(typeof Blob==="undefined"||!(e instanceof Blob))){e=JSON.stringify(e)}if(r.isBuffer(e)&&!a.strict(e)){e=new Uint8Array(e)}var n=e.length||e.byteLength||e.size;t._channel.send(e);t._debug("write: %d bytes",n)};l.prototype.destroy=function(e){var t=this;t._destroy(null,e)};l.prototype._destroy=function(e,t){var r=this;if(r.destroyed)return;if(t)r.once("close",t);r._debug("destroy (error: %s)",e&&e.message);r.readable=r.writable=false;if(!r._readableState.ended)r.push(null);if(!r._writableState.finished)r.end();r.destroyed=true;r.connected=false;r._pcReady=false;r._channelReady=false;r._chunk=null;r._cb=null;clearInterval(r._interval);clearTimeout(r._reconnectTimeout);if(r._pc){try{r._pc.close()}catch(e){}r._pc.oniceconnectionstatechange=null;r._pc.onsignalingstatechange=null;r._pc.onicecandidate=null}if(r._channel){try{r._channel.close()}catch(e){}r._channel.onmessage=null;r._channel.onopen=null;r._channel.onclose=null}r._pc=null;r._channel=null;if(e)r.emit("error",e);r.emit("close")};l.prototype._setupData=function(e){var t=this;t._channel=e.channel;t.channelName=t._channel.label;t._channel.binaryType="arraybuffer";t._channel.onmessage=t._onChannelMessage.bind(t);t._channel.onopen=t._onChannelOpen.bind(t);t._channel.onclose=t._onChannelClose.bind(t)};l.prototype._read=function(){};l.prototype._write=function(e,t,r){var n=this;if(n.destroyed)return r(new Error("cannot write after peer is destroyed"));if(n.connected){try{n.send(e)}catch(i){return n._onError(i)}if(n._channel.bufferedAmount>n._maxBufferedAmount){n._debug("start backpressure: bufferedAmount %d",n._channel.bufferedAmount);n._cb=r}else{r(null)}}else{n._debug("write before connect");n._chunk=e;n._cb=r}};l.prototype._createOffer=function(){var e=this;if(e.destroyed)return;e._pc.createOffer(function(t){if(e.destroyed)return;t.sdp=e.sdpTransform(t.sdp);e._pc.setLocalDescription(t,c,e._onError.bind(e));var r=function(){var r=e._pc.localDescription||t;e._debug("signal");e.emit("signal",{type:r.type,sdp:r.sdp})};if(e.trickle||e._iceComplete)r();else e.once("_iceComplete",r)},e._onError.bind(e),e.offerConstraints)};l.prototype._createAnswer=function(){var e=this;if(e.destroyed)return;e._pc.createAnswer(function(t){if(e.destroyed)return;t.sdp=e.sdpTransform(t.sdp);e._pc.setLocalDescription(t,c,e._onError.bind(e));var r=function(){var r=e._pc.localDescription||t;e._debug("signal");e.emit("signal",{type:r.type,sdp:r.sdp})};if(e.trickle||e._iceComplete)r();else e.once("_iceComplete",r)},e._onError.bind(e),e.answerConstraints)};l.prototype._onIceConnectionStateChange=function(){var e=this;if(e.destroyed)return;var t=e._pc.iceGatheringState;var r=e._pc.iceConnectionState;e._debug("iceConnectionStateChange %s %s",t,r);e.emit("iceConnectionStateChange",t,r);if(r==="connected"||r==="completed"){clearTimeout(e._reconnectTimeout);e._pcReady=true;e._maybeReady()}if(r==="disconnected"){if(e.reconnectTimer){clearTimeout(e._reconnectTimeout);e._reconnectTimeout=setTimeout(function(){e._destroy()},e.reconnectTimer)}else{e._destroy()}}if(r==="closed"){e._destroy()}};l.prototype._maybeReady=function(){var e=this;e._debug("maybeReady pc %s channel %s",e._pcReady,e._channelReady);if(e.connected||e._connecting||!e._pcReady||!e._channelReady)return;e._connecting=true;if(!e._pc.getStats){t([])}else if(typeof window!=="undefined"&&!!window.mozRTCPeerConnection){e._pc.getStats(null,function(e){var r=[];e.forEach(function(e){r.push(e)});t(r)},e._onError.bind(e))}else{e._pc.getStats(function(e){var r=[];e.result().forEach(function(e){var t={};e.names().forEach(function(r){t[r]=e.stat(r)});t.id=e.id;t.type=e.type;t.timestamp=e.timestamp;r.push(t)});t(r)})}function t(t){t.forEach(function(t){if(t.type==="remotecandidate"){e.remoteAddress=t.ipAddress;e.remotePort=Number(t.portNumber);e.remoteFamily="IPv4";e._debug("connect remote: %s:%s (%s)",e.remoteAddress,e.remotePort,e.remoteFamily)}else if(t.type==="localcandidate"&&t.candidateType==="host"){e.localAddress=t.ipAddress;e.localPort=Number(t.portNumber);e._debug("connect local: %s:%s",e.localAddress,e.localPort)}});e._connecting=false;e.connected=true;if(e._chunk){try{e.send(e._chunk)}catch(r){return e._onError(r)}e._chunk=null;e._debug('sent chunk from "write before connect"');var n=e._cb;e._cb=null;n(null)}e._interval=setInterval(function(){if(!e._cb||!e._channel||e._channel.bufferedAmount>e._maxBufferedAmount)return;e._debug("ending backpressure: bufferedAmount %d",e._channel.bufferedAmount);var t=e._cb;e._cb=null;t(null)},150);if(e._interval.unref)e._interval.unref();e._debug("connect");e.emit("connect")}};l.prototype._onSignalingStateChange=function(){var e=this;if(e.destroyed)return;e._debug("signalingStateChange %s",e._pc.signalingState);e.emit("signalingStateChange",e._pc.signalingState)};l.prototype._onIceCandidate=function(e){var t=this;if(t.destroyed)return;if(e.candidate&&t.trickle){t.emit("signal",{candidate:{candidate:e.candidate.candidate,sdpMLineIndex:e.candidate.sdpMLineIndex,sdpMid:e.candidate.sdpMid}})}else if(!e.candidate){t._iceComplete=true;t.emit("_iceComplete")}};l.prototype._onChannelMessage=function(e){var t=this;if(t.destroyed)return;var r=e.data;t._debug("read: %d bytes",r.byteLength||r.length);if(r instanceof ArrayBuffer){r=h(new Uint8Array(r));t.push(r)}else{try{r=JSON.parse(r)}catch(n){}t.emit("data",r)}};l.prototype._onChannelOpen=function(){var e=this;if(e.connected||e.destroyed)return;e._debug("on channel open");e._channelReady=true;e._maybeReady()};l.prototype._onChannelClose=function(){var e=this;if(e.destroyed)return;e._debug("on channel close");e._destroy()};l.prototype._onAddStream=function(e){var t=this;if(t.destroyed)return;t._debug("on add stream");t.emit("stream",e.stream)};l.prototype._onError=function(e){var t=this;if(t.destroyed)return;t._debug("error %s",e.message||e);t._destroy(e)};l.prototype._debug=function(){var e=this;var t=[].slice.call(arguments);var r=e.channelName&&e.channelName.substring(0,7);t[0]="["+r+"] "+t[0];n.apply(null,t)};function c(){}}).call(this,{isBuffer:e("../browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js")})},{"../browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js":31,debug:107,"get-browser-rtc":143,hat:113,inherits:115,"is-typedarray":144,once:146,stream:52,"typedarray-to-buffer":147}],143:[function(e,t,r){t.exports=function n(){if(typeof window==="undefined")return null;var e={RTCPeerConnection:window.mozRTCPeerConnection||window.RTCPeerConnection||window.webkitRTCPeerConnection,RTCSessionDescription:window.mozRTCSessionDescription||window.RTCSessionDescription||window.webkitRTCSessionDescription,RTCIceCandidate:window.mozRTCIceCandidate||window.RTCIceCandidate||window.webkitRTCIceCandidate};if(!e.RTCPeerConnection)return null;return e}},{}],144:[function(e,t,r){arguments[4][22][0].apply(r,arguments)},{dup:22}],145:[function(e,t,r){arguments[4][19][0].apply(r,arguments)},{dup:19}],146:[function(e,t,r){arguments[4][20][0].apply(r,arguments)},{dup:20,wrappy:145}],147:[function(e,t,r){arguments[4][97][0].apply(r,arguments)},{buffer:25,dup:97,"is-typedarray":144}],148:[function(e,t,r){var n=e("rusha");var i=new n;var s=window.crypto||window.msCrypto||{};var o=s.subtle||s.webkitSubtle;var a=i.digest.bind(i);try{o.digest({name:"sha-1"},new Uint8Array).catch(function(){o=false})}catch(f){o=false}function u(e,t){if(!o){setTimeout(t,0,a(e));return}if(typeof e==="string"){e=h(e)}o.digest({name:"sha-1"},e).then(function r(e){t(l(new Uint8Array(e)))},function n(r){t(a(e))})}function h(e){var t=e.length;var r=new Uint8Array(t);for(var n=0;n<t;n++){r[n]=e.charCodeAt(n)}return r}function l(e){var t=e.length;var r=[];for(var n=0;n<t;n++){var i=e[n];r.push((i>>>4).toString(16));r.push((i&15).toString(16))}return r.join("")}t.exports=u;t.exports.sync=a},{rusha:149}],149:[function(e,t,r){(function(e){(function(){var r={getDataType:function(t){if(typeof t==="string"){return"string"}if(t instanceof Array){return"array"}if(typeof e!=="undefined"&&e.Buffer&&e.Buffer.isBuffer(t)){return"buffer"}if(t instanceof ArrayBuffer){return"arraybuffer"}if(t.buffer instanceof ArrayBuffer){return"view"}if(t instanceof Blob){return"blob"}throw new Error("Unsupported data type.")}};function n(e){"use strict";var t={fill:0};var s=function(e){for(e+=9;e%64>0;e+=1);return e};var o=function(e,t){for(var r=t>>2;r<e.length;r++)e[r]=0};var a=function(e,t,r){e[t>>2]|=128<<24-(t%4<<3);e[((t>>2)+2&~15)+14]=r>>29;e[((t>>2)+2&~15)+15]=r<<3};var f=function(e,t,r,n,i){var s=this,o,a=i%4,f=n%4,u=n-f;if(u>0){switch(a){case 0:e[i+3|0]=s.charCodeAt(r);case 1:e[i+2|0]=s.charCodeAt(r+1);case 2:e[i+1|0]=s.charCodeAt(r+2);case 3:e[i|0]=s.charCodeAt(r+3)}}for(o=a;o<u;o=o+4|0){t[i+o>>2]=s.charCodeAt(r+o)<<24|s.charCodeAt(r+o+1)<<16|s.charCodeAt(r+o+2)<<8|s.charCodeAt(r+o+3)}switch(f){case 3:e[i+u+1|0]=s.charCodeAt(r+u+2);case 2:e[i+u+2|0]=s.charCodeAt(r+u+1);case 1:e[i+u+3|0]=s.charCodeAt(r+u)}};var u=function(e,t,r,n,i){var s=this,o,a=i%4,f=n%4,u=n-f;if(u>0){switch(a){case 0:e[i+3|0]=s[r];case 1:e[i+2|0]=s[r+1];case 2:e[i+1|0]=s[r+2];case 3:e[i|0]=s[r+3]}}for(o=4-a;o<u;o=o+=4|0){t[i+o>>2]=s[r+o]<<24|s[r+o+1]<<16|s[r+o+2]<<8|s[r+o+3]}switch(f){case 3:e[i+u+1|0]=s[r+u+2];case 2:e[i+u+2|0]=s[r+u+1];case 1:e[i+u+3|0]=s[r+u]}};var h=function(e,t,r,n,s){var o=this,a,f=s%4,u=n%4,h=n-u;var l=new Uint8Array(i.readAsArrayBuffer(o.slice(r,r+n)));if(h>0){switch(f){case 0:e[s+3|0]=l[0];case 1:e[s+2|0]=l[1];case 2:e[s+1|0]=l[2];case 3:e[s|0]=l[3]}}for(a=4-f;a<h;a=a+=4|0){t[s+a>>2]=l[a]<<24|l[a+1]<<16|l[a+2]<<8|l[a+3]}switch(u){case 3:e[s+h+1|0]=l[h+2];case 2:e[s+h+2|0]=l[h+1];case 1:e[s+h+3|0]=l[h]}};var l=function(e){switch(r.getDataType(e)){case"string":return f.bind(e);case"array":return u.bind(e);case"buffer":return u.bind(e);case"arraybuffer":return u.bind(new Uint8Array(e));case"view":return u.bind(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));case"blob":return h.bind(e)}};var c=function(e,t){switch(r.getDataType(e)){case"string":return e.slice(t);case"array":return e.slice(t);case"buffer":return e.slice(t);case"arraybuffer":return e.slice(t);case"view":return e.buffer.slice(t)}};var d=function(e){var t,r,n="0123456789abcdef",i=[],s=new Uint8Array(e);for(t=0;t<s.length;t++){r=s[t];i[t]=n.charAt(r>>4&15)+n.charAt(r>>0&15)}return i.join("")};var p=function(e){var t;if(e<=65536)return 65536;if(e<16777216){for(t=1;t<e;t=t<<1);}else{for(t=16777216;t<e;t+=16777216);}return t};var m=function(e){if(e%64>0){throw new Error("Chunk size must be a multiple of 128 bit")}t.maxChunkLen=e;t.padMaxChunkLen=s(e);t.heap=new ArrayBuffer(p(t.padMaxChunkLen+320+20));t.h32=new Int32Array(t.heap);t.h8=new Int8Array(t.heap);t.core=new n._core({Int32Array:Int32Array,DataView:DataView},{},t.heap);t.buffer=null};m(e||64*1024);var g=function(e,t){var r=new Int32Array(e,t+320,5);r[0]=1732584193;r[1]=-271733879;r[2]=-1732584194;r[3]=271733878;r[4]=-1009589776};var v=function(e,r){var n=s(e);var i=new Int32Array(t.heap,0,n>>2);o(i,e);a(i,e,r);return n};var y=function(e,r,n){l(e)(t.h8,t.h32,r,n,0)};var _=function(e,r,n,i,s){var o=n;if(s){o=v(n,i)}y(e,r,n);t.core.hash(o,t.padMaxChunkLen)};var b=function(e,t){var r=new Int32Array(e,t+320,5);var n=new Int32Array(5);var i=new DataView(n.buffer);i.setInt32(0,r[0],false);i.setInt32(4,r[1],false);i.setInt32(8,r[2],false);i.setInt32(12,r[3],false);i.setInt32(16,r[4],false);return n};var w=this.rawDigest=function(e){var r=e.byteLength||e.length||e.size||0;g(t.heap,t.padMaxChunkLen);var n=0,i=t.maxChunkLen,s;for(n=0;r>n+i;n+=i){_(e,n,i,r,false)}_(e,n,r-n,r,true);return b(t.heap,t.padMaxChunkLen)};this.digest=this.digestFromString=this.digestFromBuffer=this.digestFromArrayBuffer=function(e){return d(w(e).buffer)}}n._core=function o(e,t,r){"use asm";var n=new e.Int32Array(r);function i(e,t){e=e|0;t=t|0;var r=0,i=0,s=0,o=0,a=0,f=0,u=0,h=0,l=0,c=0,d=0,p=0,m=0,g=0;s=n[t+320>>2]|0;a=n[t+324>>2]|0;u=n[t+328>>2]|0;l=n[t+332>>2]|0;d=n[t+336>>2]|0;for(r=0;(r|0)<(e|0);r=r+64|0){o=s;f=a;h=u;c=l;p=d;for(i=0;(i|0)<64;i=i+4|0){g=n[r+i>>2]|0;m=((s<<5|s>>>27)+(a&u|~a&l)|0)+((g+d|0)+1518500249|0)|0;d=l;l=u;u=a<<30|a>>>2;a=s;s=m;n[e+i>>2]=g}for(i=e+64|0;(i|0)<(e+80|0);i=i+4|0){g=(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])<<1|(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])>>>31;m=((s<<5|s>>>27)+(a&u|~a&l)|0)+((g+d|0)+1518500249|0)|0;d=l;l=u;u=a<<30|a>>>2;a=s;s=m;n[i>>2]=g}for(i=e+80|0;(i|0)<(e+160|0);i=i+4|0){g=(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])<<1|(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])>>>31;m=((s<<5|s>>>27)+(a^u^l)|0)+((g+d|0)+1859775393|0)|0;d=l;l=u;u=a<<30|a>>>2;a=s;s=m;n[i>>2]=g}for(i=e+160|0;(i|0)<(e+240|0);i=i+4|0){g=(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])<<1|(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])>>>31;m=((s<<5|s>>>27)+(a&u|a&l|u&l)|0)+((g+d|0)-1894007588|0)|0;d=l;l=u;u=a<<30|a>>>2;a=s;s=m;n[i>>2]=g}for(i=e+240|0;(i|0)<(e+320|0);i=i+4|0){g=(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])<<1|(n[i-12>>2]^n[i-32>>2]^n[i-56>>2]^n[i-64>>2])>>>31;m=((s<<5|s>>>27)+(a^u^l)|0)+((g+d|0)-899497514|0)|0;d=l;l=u;u=a<<30|a>>>2;a=s;s=m;n[i>>2]=g}s=s+o|0;a=a+f|0;u=u+h|0;l=l+c|0;d=d+p|0}n[t+320>>2]=s;n[t+324>>2]=a;n[t+328>>2]=u;n[t+332>>2]=l;n[t+336>>2]=d}return{hash:i}};if(typeof t!=="undefined"){t.exports=n}else if(typeof window!=="undefined"){window.Rusha=n}if(typeof FileReaderSync!=="undefined"){var i=new FileReaderSync,s=new n(4*1024*1024);self.onmessage=function a(e){var t,r=e.data.data;try{t=s.digest(r);self.postMessage({id:e.data.id,hash:t})}catch(n){self.postMessage({id:e.data.id,error:n.name})}}}})()}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],150:[function(e,t,r){var n=1;var i=65535;var s=4;var o=function(){n=n+1&i};var a=setInterval(o,1e3/s|0);if(a.unref)a.unref();t.exports=function(e){var t=s*(e||5);var r=[0];var o=1;var a=n-1&i;return function(e){var f=n-a&i;if(f>t)f=t;a=n;while(f--){if(o===t)o=0;r[o]=r[o===0?t-1:o-1];o++}if(e)r[o-1]+=e;var u=r[o-1];var h=r.length<t?0:r[o===t?0:o];return r.length<s?u:(u-h)*s/r.length}}},{}],151:[function(e,t,r){var n=e("stream-with-known-length-to-buffer");t.exports=function i(e,t,r,s){n(e,t,function(e,t){if(e)return s(e);var n=r?new Blob([t],{type:r}):new Blob([t]);var i=URL.createObjectURL(n);s(null,i)})}},{"stream-with-known-length-to-buffer":152}],152:[function(e,t,r){(function(r){var n=e("once");t.exports=function i(e,t,s){s=n(s);var o=new r(t);var a=0;e.on("data",function(e){e.copy(o,a);a+=e.length}).on("end",function(){s(null,o)}).on("error",s)}}).call(this,e("buffer").Buffer)},{buffer:25,once:154}],153:[function(e,t,r){arguments[4][19][0].apply(r,arguments)},{dup:19}],154:[function(e,t,r){arguments[4][20][0].apply(r,arguments)},{dup:20,wrappy:153}],155:[function(e,t,r){(function(r,n){t.exports=c;var i=e("debug")("torrent-discovery");var s=e("bittorrent-dht/client");var o=e("events").EventEmitter;var a=e("xtend");var f=e("inherits");var u=e("run-parallel");var h=e("re-emitter");var l=e("bittorrent-tracker/client");f(c,o);function c(e){var t=this;if(!(t instanceof c))return new c(e);o.call(t);t.announce=e.announce||[];t.rtcConfig=e.rtcConfig;t.peerId=e.peerId;t.port=e.port||0;t.tracker=e.tracker!==false;t.wrtc=e.wrtc;t.intervalMs=e.intervalMs||15*60*1e3;if(!t.peerId)throw new Error("peerId required");if(!r.browser&&!t.port)throw new Error("port required");t.infoHash=null;t.infoHashBuffer=null;t.torrent=null;t._dhtAnnouncing=false;t._dhtTimeout=false;t._internalDHT=false;t.dht=e.dht===false?false:e.dht||n();if(t.dht){h(t.dht,t,["error","warning"]);t.dht.on("peer",i)}function n(){if(typeof s!=="function")return false;t._internalDHT=true;var r=new s;r.listen(e.dhtPort);return r}function i(e,r){if(r.toString("hex")!==t.infoHash)return;t.emit("peer",e.host+":"+e.port)}}c.prototype.setTorrent=function(e){var t=this;if(!t.infoHash&&(typeof e==="string"||n.isBuffer(e))){t.infoHash=typeof e==="string"?e:e.toString("hex")}else if(!t.torrent&&e&&e.infoHash){t.torrent=e;t.infoHash=typeof e.infoHash==="string"?e.infoHash:e.infoHash.toString("hex")}else{return}t.infoHashBuffer=new n(t.infoHash,"hex");i("setTorrent %s",t.infoHash);if(t.tracker&&t.tracker!==true){t.tracker.torrentLength=e.length}else{t._createTracker()}t._dhtAnnounce()};c.prototype.updatePort=function(e){var t=this;if(e===t.port)return;t.port=e;t._dhtAnnounce();if(t.tracker&&t.tracker!==true){t.tracker.stop();t.tracker.destroy(function(){t._createTracker()})}};c.prototype.stop=function(e){var t=this;var r=[];if(t.tracker&&t.tracker!==true){t.tracker.stop();r.push(function(e){t.tracker.destroy(e)})}if(t._internalDHT){r.push(function(e){t.dht.destroy(e)})}u(r,e)};c.prototype._createTracker=function(){var e=this;if(!e.tracker)return;var t=e.torrent?a({announce:[]},e.torrent):{infoHash:e.infoHash,announce:[]};if(e.announce)t.announce=t.announce.concat(e.announce);var r={rtcConfig:e.rtcConfig,wrtc:e.wrtc};e.tracker=new l(e.peerId,e.port,t,r);h(e.tracker,e,["peer","warning","error"]);e.tracker.setInterval(e.intervalMs);e.tracker.on("update",n);e.tracker.start();function n(t){e.emit("trackerAnnounce",t)}};c.prototype._dhtAnnounce=function(){var e=this;if(!e.port||!e.infoHash||!e.dht||e._dhtAnnouncing)return;e._dhtAnnouncing=true;e.dht.announce(e.infoHash,e.port,function(r){if(r)e.emit("warning",r);e._dhtAnnouncing=false;i("dht announce complete");e.emit("dhtAnnounce");clearTimeout(e._dhtTimeout);e._dhtTimeout=setTimeout(function(){e._dhtAnnounce()},t());e._dhtTimeout.unref()});function t(){return e.intervalMs+Math.floor(Math.random()*e.intervalMs/5)}}}).call(this,e("_process"),e("buffer").Buffer)},{_process:34,"bittorrent-dht/client":24,"bittorrent-tracker/client":15,buffer:25,debug:107,events:29,inherits:115,"re-emitter":135,"run-parallel":138,xtend:170}],156:[function(e,t,r){(function(e){t.exports=n;var r=1<<14;function n(e){if(!(this instanceof n))return new n(e);this.length=e;this.missing=e;this.sources=null;this._chunks=Math.ceil(e/r);this._remainder=e%r||r;this._buffered=0;this._buffer=null;this._cancellations=null;this._reservations=0;this._flushed=false}n.BLOCK_LENGTH=r;n.prototype.chunkLength=function(e){return e===this._chunks-1?this._remainder:r};n.prototype.chunkOffset=function(e){return e*r};n.prototype.reserve=function(){if(!this.init())return-1;if(this._cancellations.length)return this._cancellations.pop();if(this._reservations<this._chunks)return this._reservations++;return-1};n.prototype.cancel=function(e){if(!this.init())return;this._cancellations.push(e)};n.prototype.get=function(e){if(!this.init())return null;return this._buffer[e]};n.prototype.set=function(e,t,r){if(!this.init())return false;if(!this._buffer[e]){this._buffered++;this._buffer[e]=t;this.missing-=t.length;if(this.sources.indexOf(r)===-1){this.sources.push(r)}}return this._buffered===this._chunks};n.prototype.flush=function(){if(!this._buffer||this._chunks!==this._buffered)return null;var t=e.concat(this._buffer,this.length);this._buffer=null;this._cancellations=null;this.sources=null;this._flushed=true;return t};n.prototype.init=function(){if(this._flushed)return false;if(this._buffer)return true;this._buffer=new Array(this._chunks);this._cancellations=[];this.sources=[];return true}}).call(this,e("buffer").Buffer)},{buffer:25}],157:[function(e,t,r){"use strict";function n(e,t){var r=1,n=e.length,i=e[0],s=e[0];for(var o=1;o<n;++o){s=i;i=e[o];if(t(i,s)){if(o===r){r++;continue}e[r++]=i}}e.length=r;return e}function i(e){var t=1,r=e.length,n=e[0],i=e[0];for(var s=1;s<r;++s,i=n){i=n;n=e[s];if(n!==i){if(s===t){t++;continue}e[t++]=n}}e.length=t;return e}function s(e,t,r){if(e.length===0){return e}if(t){if(!r){e.sort(t)}return n(e,t)}if(!r){e.sort()}return i(e)}t.exports=s},{}],158:[function(e,t,r){(function(r){var n=e("bencode");var i=e("bitfield");var s=e("events").EventEmitter;var o=e("inherits");var a=e("simple-sha1");var f=1e7;var u=1e3;var h=16*1024;t.exports=function(e){o(t,s);function t(t){s.call(this);this._wire=t;this._metadataComplete=false;this._metadataSize=null;this._remainingRejects=null;this._fetching=false;this._bitfield=new i(0,{grow:u});if(r.isBuffer(e)){this.setMetadata(e)}}t.prototype.name="ut_metadata";t.prototype.onHandshake=function(e,t,r){this._infoHash=e};t.prototype.onExtendedHandshake=function(e){if(!e.m||!e.m.ut_metadata){return this.emit("warning",new Error("Peer does not support ut_metadata"))}if(!e.metadata_size){return this.emit("warning",new Error("Peer does not have metadata"))}if(e.metadata_size>f){return this.emit("warning",new Error("Peer gave maliciously large metadata size"))}this._metadataSize=e.metadata_size;this._numPieces=Math.ceil(this._metadataSize/h);this._remainingRejects=this._numPieces*2;if(this._fetching){this._requestPieces()}};t.prototype.onMessage=function(e){var t,r;try{var i=e.toString();var s=i.indexOf("ee")+2;t=n.decode(i.substring(0,s));r=e.slice(s)}catch(o){return}switch(t.msg_type){case 0:this._onRequest(t.piece);break;case 1:this._onData(t.piece,r,t.total_size);break;case 2:this._onReject(t.piece);break}};t.prototype.fetch=function(){if(this._metadataComplete){return}this._fetching=true;if(this._metadataSize){this._requestPieces()}};t.prototype.cancel=function(){this._fetching=false};t.prototype.setMetadata=function(e){if(this._metadataComplete)return true;try{var t=n.decode(e).info;if(t){e=n.encode(t)}}catch(r){}if(this._infoHash&&this._infoHash!==a.sync(e)){return false}this.cancel();this.metadata=e;this._metadataComplete=true;this._metadataSize=this.metadata.length;this._wire.extendedHandshake.metadata_size=this._metadataSize;this.emit("metadata",n.encode({info:n.decode(this.metadata)}));return true};t.prototype._send=function(e,t){var i=n.encode(e);if(r.isBuffer(t)){i=r.concat([i,t])}this._wire.extended("ut_metadata",i)};t.prototype._request=function(e){this._send({msg_type:0,piece:e})};t.prototype._data=function(e,t,r){var n={msg_type:1,piece:e};if(typeof r==="number"){n.total_size=r}this._send(n,t)};t.prototype._reject=function(e){this._send({msg_type:2,piece:e})};t.prototype._onRequest=function(e){if(!this._metadataComplete){this._reject(e);return}var t=e*h;var r=t+h;if(r>this._metadataSize){r=this._metadataSize}var n=this.metadata.slice(t,r);this._data(e,n,this._metadataSize)};t.prototype._onData=function(e,t,r){if(t.length>h){return}t.copy(this.metadata,e*h);this._bitfield.set(e);this._checkDone()};t.prototype._onReject=function(e){if(this._remainingRejects>0&&this._fetching){this._request(e);this._remainingRejects-=1}else{this.emit("warning",new Error('Peer sent "reject" too much'))}};t.prototype._requestPieces=function(){this.metadata=new r(this._metadataSize);for(var e=0;e<this._numPieces;e++){this._request(e)}};t.prototype._checkDone=function(){var e=true;for(var t=0;t<this._numPieces;t++){if(!this._bitfield.get(t)){e=false;break}}if(!e)return;var r=this.setMetadata(this.metadata);if(!r){this._failedMetadata()}};t.prototype._failedMetadata=function(){this._bitfield=new i(0,{grow:u});this._remainingRejects-=this._numPieces;if(this._remainingRejects>0){this._requestPieces()}else{this.emit("warning",new Error("Peer sent invalid metadata"))}};return t}}).call(this,e("buffer").Buffer)},{bencode:159,bitfield:6,buffer:25,events:29,inherits:115,"simple-sha1":148}],159:[function(e,t,r){arguments[4][11][0].apply(r,arguments)},{"./lib/decode":160,"./lib/encode":162,dup:11}],160:[function(e,t,r){arguments[4][12][0].apply(r,arguments)},{"./dict":161,buffer:25,dup:12}],161:[function(e,t,r){arguments[4][13][0].apply(r,arguments)},{dup:13}],162:[function(e,t,r){arguments[4][14][0].apply(r,arguments)},{buffer:25,dup:14}],163:[function(e,t,r){var n=function(e,t,r){this._byteOffset=t||0;if(e instanceof ArrayBuffer){this.buffer=e}else if(typeof e=="object"){this.dataView=e;if(t){this._byteOffset+=t}}else{this.buffer=new ArrayBuffer(e||0)}this.position=0;this.endianness=r==null?n.LITTLE_ENDIAN:r};t.exports=n;n.prototype={};n.prototype.save=function(e){var t=new Blob([this.buffer]);var r=window.webkitURL||window.URL;if(r&&r.createObjectURL){var n=r.createObjectURL(t);var i=document.createElement("a");i.setAttribute("href",n);i.setAttribute("download",e);i.click();r.revokeObjectURL(n)}else{throw"DataStream.save: Can't create object URL."}};n.BIG_ENDIAN=false;n.LITTLE_ENDIAN=true;n.prototype._dynamicSize=true;Object.defineProperty(n.prototype,"dynamicSize",{get:function(){return this._dynamicSize},set:function(e){if(!e){this._trimAlloc()}this._dynamicSize=e}});n.prototype._byteLength=0;Object.defineProperty(n.prototype,"byteLength",{get:function(){return this._byteLength-this._byteOffset}});Object.defineProperty(n.prototype,"buffer",{get:function(){this._trimAlloc();return this._buffer},set:function(e){this._buffer=e;this._dataView=new DataView(this._buffer,this._byteOffset);this._byteLength=this._buffer.byteLength}});Object.defineProperty(n.prototype,"byteOffset",{get:function(){return this._byteOffset},set:function(e){this._byteOffset=e;this._dataView=new DataView(this._buffer,this._byteOffset);this._byteLength=this._buffer.byteLength}});Object.defineProperty(n.prototype,"dataView",{get:function(){return this._dataView},set:function(e){this._byteOffset=e.byteOffset;this._buffer=e.buffer;this._dataView=new DataView(this._buffer,this._byteOffset);this._byteLength=this._byteOffset+e.byteLength}});n.prototype._realloc=function(e){if(!this._dynamicSize){return}var t=this._byteOffset+this.position+e;var r=this._buffer.byteLength;if(t<=r){if(t>this._byteLength){this._byteLength=t}return}if(r<1){r=1}while(t>r){r*=2}var n=new ArrayBuffer(r);var i=new Uint8Array(this._buffer);var s=new Uint8Array(n,0,i.length);s.set(i);this.buffer=n;this._byteLength=t};n.prototype._trimAlloc=function(){if(this._byteLength==this._buffer.byteLength){return}var e=new ArrayBuffer(this._byteLength);var t=new Uint8Array(e);var r=new Uint8Array(this._buffer,0,t.length);t.set(r);this.buffer=e};n.prototype.shift=function(e){var t=new ArrayBuffer(this._byteLength-e);var r=new Uint8Array(t);var n=new Uint8Array(this._buffer,e,r.length);r.set(n);this.buffer=t;this.position-=e};n.prototype.seek=function(e){var t=Math.max(0,Math.min(this.byteLength,e));this.position=isNaN(t)||!isFinite(t)?0:t};n.prototype.isEof=function(){return this.position>=this._byteLength};n.prototype.mapInt32Array=function(e,t){this._realloc(e*4);var r=new Int32Array(this._buffer,this.byteOffset+this.position,e);n.arrayToNative(r,t==null?this.endianness:t);this.position+=e*4;return r};n.prototype.mapInt16Array=function(e,t){this._realloc(e*2);var r=new Int16Array(this._buffer,this.byteOffset+this.position,e);n.arrayToNative(r,t==null?this.endianness:t);this.position+=e*2;return r};n.prototype.mapInt8Array=function(e){this._realloc(e*1);var t=new Int8Array(this._buffer,this.byteOffset+this.position,e);this.position+=e*1;return t};n.prototype.mapUint32Array=function(e,t){this._realloc(e*4);var r=new Uint32Array(this._buffer,this.byteOffset+this.position,e);n.arrayToNative(r,t==null?this.endianness:t);this.position+=e*4;return r};n.prototype.mapUint16Array=function(e,t){this._realloc(e*2);var r=new Uint16Array(this._buffer,this.byteOffset+this.position,e);n.arrayToNative(r,t==null?this.endianness:t);this.position+=e*2;return r};n.prototype.mapUint8Array=function(e){this._realloc(e*1);var t=new Uint8Array(this._buffer,this.byteOffset+this.position,e);this.position+=e*1;return t};n.prototype.mapFloat64Array=function(e,t){this._realloc(e*8);var r=new Float64Array(this._buffer,this.byteOffset+this.position,e);n.arrayToNative(r,t==null?this.endianness:t);this.position+=e*8;return r};n.prototype.mapFloat32Array=function(e,t){this._realloc(e*4);var r=new Float32Array(this._buffer,this.byteOffset+this.position,e);n.arrayToNative(r,t==null?this.endianness:t);this.position+=e*4;return r};n.prototype.readInt32Array=function(e,t){e=e==null?this.byteLength-this.position/4:e;var r=new Int32Array(e);n.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT);n.arrayToNative(r,t==null?this.endianness:t);this.position+=r.byteLength;return r};n.prototype.readInt16Array=function(e,t){e=e==null?this.byteLength-this.position/2:e;var r=new Int16Array(e);n.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT);n.arrayToNative(r,t==null?this.endianness:t);this.position+=r.byteLength;return r};n.prototype.readInt8Array=function(e){e=e==null?this.byteLength-this.position:e;var t=new Int8Array(e);n.memcpy(t.buffer,0,this.buffer,this.byteOffset+this.position,e*t.BYTES_PER_ELEMENT);this.position+=t.byteLength;return t};n.prototype.readUint32Array=function(e,t){e=e==null?this.byteLength-this.position/4:e;var r=new Uint32Array(e);n.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT);n.arrayToNative(r,t==null?this.endianness:t);this.position+=r.byteLength;return r};n.prototype.readUint16Array=function(e,t){e=e==null?this.byteLength-this.position/2:e;var r=new Uint16Array(e);n.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT);n.arrayToNative(r,t==null?this.endianness:t);this.position+=r.byteLength;return r};n.prototype.readUint8Array=function(e){e=e==null?this.byteLength-this.position:e;var t=new Uint8Array(e);n.memcpy(t.buffer,0,this.buffer,this.byteOffset+this.position,e*t.BYTES_PER_ELEMENT);this.position+=t.byteLength;return t};n.prototype.readFloat64Array=function(e,t){e=e==null?this.byteLength-this.position/8:e;var r=new Float64Array(e);n.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT);n.arrayToNative(r,t==null?this.endianness:t);this.position+=r.byteLength;return r};n.prototype.readFloat32Array=function(e,t){e=e==null?this.byteLength-this.position/4:e;var r=new Float32Array(e);n.memcpy(r.buffer,0,this.buffer,this.byteOffset+this.position,e*r.BYTES_PER_ELEMENT);n.arrayToNative(r,t==null?this.endianness:t);this.position+=r.byteLength;return r};n.prototype.writeInt32Array=function(e,t){this._realloc(e.length*4);if(e instanceof Int32Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapInt32Array(e.length,t)}else{for(var r=0;r<e.length;r++){this.writeInt32(e[r],t)}}};n.prototype.writeInt16Array=function(e,t){this._realloc(e.length*2);if(e instanceof Int16Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapInt16Array(e.length,t)}else{for(var r=0;r<e.length;r++){this.writeInt16(e[r],t)}}};n.prototype.writeInt8Array=function(e){this._realloc(e.length*1);if(e instanceof Int8Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapInt8Array(e.length)}else{for(var t=0;t<e.length;t++){this.writeInt8(e[t])}}};n.prototype.writeUint32Array=function(e,t){this._realloc(e.length*4);if(e instanceof Uint32Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapUint32Array(e.length,t)}else{for(var r=0;r<e.length;r++){this.writeUint32(e[r],t)}}};n.prototype.writeUint16Array=function(e,t){this._realloc(e.length*2);if(e instanceof Uint16Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapUint16Array(e.length,t)}else{for(var r=0;r<e.length;r++){this.writeUint16(e[r],t)}}};n.prototype.writeUint8Array=function(e){this._realloc(e.length*1);if(e instanceof Uint8Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){
n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapUint8Array(e.length)}else{for(var t=0;t<e.length;t++){this.writeUint8(e[t])}}};n.prototype.writeFloat64Array=function(e,t){this._realloc(e.length*8);if(e instanceof Float64Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapFloat64Array(e.length,t)}else{for(var r=0;r<e.length;r++){this.writeFloat64(e[r],t)}}};n.prototype.writeFloat32Array=function(e,t){this._realloc(e.length*4);if(e instanceof Float32Array&&this.byteOffset+this.position%e.BYTES_PER_ELEMENT===0){n.memcpy(this._buffer,this.byteOffset+this.position,e.buffer,0,e.byteLength);this.mapFloat32Array(e.length,t)}else{for(var r=0;r<e.length;r++){this.writeFloat32(e[r],t)}}};n.prototype.readInt32=function(e){var t=this._dataView.getInt32(this.position,e==null?this.endianness:e);this.position+=4;return t};n.prototype.readInt16=function(e){var t=this._dataView.getInt16(this.position,e==null?this.endianness:e);this.position+=2;return t};n.prototype.readInt8=function(){var e=this._dataView.getInt8(this.position);this.position+=1;return e};n.prototype.readUint32=function(e){var t=this._dataView.getUint32(this.position,e==null?this.endianness:e);this.position+=4;return t};n.prototype.readUint16=function(e){var t=this._dataView.getUint16(this.position,e==null?this.endianness:e);this.position+=2;return t};n.prototype.readUint8=function(){var e=this._dataView.getUint8(this.position);this.position+=1;return e};n.prototype.readFloat32=function(e){var t=this._dataView.getFloat32(this.position,e==null?this.endianness:e);this.position+=4;return t};n.prototype.readFloat64=function(e){var t=this._dataView.getFloat64(this.position,e==null?this.endianness:e);this.position+=8;return t};n.prototype.writeInt32=function(e,t){this._realloc(4);this._dataView.setInt32(this.position,e,t==null?this.endianness:t);this.position+=4};n.prototype.writeInt16=function(e,t){this._realloc(2);this._dataView.setInt16(this.position,e,t==null?this.endianness:t);this.position+=2};n.prototype.writeInt8=function(e){this._realloc(1);this._dataView.setInt8(this.position,e);this.position+=1};n.prototype.writeUint32=function(e,t){this._realloc(4);this._dataView.setUint32(this.position,e,t==null?this.endianness:t);this.position+=4};n.prototype.writeUint16=function(e,t){this._realloc(2);this._dataView.setUint16(this.position,e,t==null?this.endianness:t);this.position+=2};n.prototype.writeUint8=function(e){this._realloc(1);this._dataView.setUint8(this.position,e);this.position+=1};n.prototype.writeFloat32=function(e,t){this._realloc(4);this._dataView.setFloat32(this.position,e,t==null?this.endianness:t);this.position+=4};n.prototype.writeFloat64=function(e,t){this._realloc(8);this._dataView.setFloat64(this.position,e,t==null?this.endianness:t);this.position+=8};n.endianness=new Int8Array(new Int16Array([1]).buffer)[0]>0;n.memcpy=function(e,t,r,n,i){var s=new Uint8Array(e,t,i);var o=new Uint8Array(r,n,i);s.set(o)};n.arrayToNative=function(e,t){if(t==this.endianness){return e}else{return this.flipArrayEndianness(e)}};n.nativeToEndian=function(e,t){if(this.endianness==t){return e}else{return this.flipArrayEndianness(e)}};n.flipArrayEndianness=function(e){var t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);for(var r=0;r<e.byteLength;r+=e.BYTES_PER_ELEMENT){for(var n=r+e.BYTES_PER_ELEMENT-1,i=r;n>i;n--,i++){var s=t[i];t[i]=t[n];t[n]=s}}return e};n.prototype.failurePosition=0;n.prototype.readStruct=function(e){var t={},r,n,i;var s=this.position;for(var o=0;o<e.length;o+=2){r=e[o+1];n=this.readType(r,t);if(n==null){if(this.failurePosition===0){this.failurePosition=this.position}this.position=s;return null}t[e[o]]=n}return t};n.prototype.readUCS2String=function(e,t){return String.fromCharCode.apply(null,this.readUint16Array(e,t))};n.prototype.writeUCS2String=function(e,t,r){if(r==null){r=e.length}for(var n=0;n<e.length&&n<r;n++){this.writeUint16(e.charCodeAt(n),t)}for(;n<r;n++){this.writeUint16(0)}};n.prototype.readString=function(e,t){if(t==null||t=="ASCII"){return String.fromCharCode.apply(null,this.mapUint8Array(e==null?this.byteLength-this.position:e))}else{return new TextDecoder(t).decode(this.mapUint8Array(e))}};n.prototype.writeString=function(e,t,r){var n=0;if(t==null||t=="ASCII"){if(r!=null){var i=Math.min(e.length,r);for(n=0;n<i;n++){this.writeUint8(e.charCodeAt(n))}for(;n<r;n++){this.writeUint8(0)}}else{for(n=0;n<e.length;n++){this.writeUint8(e.charCodeAt(n))}}}else{this.writeUint8Array(new TextEncoder(t).encode(e.substring(0,r)))}};n.prototype.readCString=function(e){var t=this.byteLength-this.position;var r=new Uint8Array(this._buffer,this._byteOffset+this.position);var n=t;if(e!=null){n=Math.min(e,t)}for(var i=0;i<n&&r[i]!==0;i++);var s=String.fromCharCode.apply(null,this.mapUint8Array(i));if(e!=null){this.position+=n-i}else if(i!=t){this.position+=1}return s};n.prototype.writeCString=function(e,t){var r=0;if(t!=null){var n=Math.min(e.length,t);for(r=0;r<n;r++){this.writeUint8(e.charCodeAt(r))}for(;r<t;r++){this.writeUint8(0)}}else{for(r=0;r<e.length;r++){this.writeUint8(e.charCodeAt(r))}this.writeUint8(0)}};n.prototype.readType=function(e,t){if(typeof e=="function"){return e(this,t)}else if(typeof e=="object"&&!(e instanceof Array)){return e.get(this,t)}else if(e instanceof Array&&e.length!=3){return this.readStruct(e,t)}var r=null;var i=null;var s="ASCII";var o=this.position;var a;var f;var u;if(typeof e=="string"&&/:/.test(e)){a=e.split(":");e=a[0];i=parseInt(a[1])}if(typeof e=="string"&&/,/.test(e)){a=e.split(",");e=a[0];s=parseInt(a[1])}switch(e){case"uint8":r=this.readUint8();break;case"int8":r=this.readInt8();break;case"uint16":r=this.readUint16(this.endianness);break;case"int16":r=this.readInt16(this.endianness);break;case"uint32":r=this.readUint32(this.endianness);break;case"int32":r=this.readInt32(this.endianness);break;case"float32":r=this.readFloat32(this.endianness);break;case"float64":r=this.readFloat64(this.endianness);break;case"uint16be":r=this.readUint16(n.BIG_ENDIAN);break;case"int16be":r=this.readInt16(n.BIG_ENDIAN);break;case"uint32be":r=this.readUint32(n.BIG_ENDIAN);break;case"int32be":r=this.readInt32(n.BIG_ENDIAN);break;case"float32be":r=this.readFloat32(n.BIG_ENDIAN);break;case"float64be":r=this.readFloat64(n.BIG_ENDIAN);break;case"uint16le":r=this.readUint16(n.LITTLE_ENDIAN);break;case"int16le":r=this.readInt16(n.LITTLE_ENDIAN);break;case"uint32le":r=this.readUint32(n.LITTLE_ENDIAN);break;case"int32le":r=this.readInt32(n.LITTLE_ENDIAN);break;case"float32le":r=this.readFloat32(n.LITTLE_ENDIAN);break;case"float64le":r=this.readFloat64(n.LITTLE_ENDIAN);break;case"cstring":r=this.readCString(i);break;case"string":r=this.readString(i,s);break;case"u16string":r=this.readUCS2String(i,this.endianness);break;case"u16stringle":r=this.readUCS2String(i,n.LITTLE_ENDIAN);break;case"u16stringbe":r=this.readUCS2String(i,n.BIG_ENDIAN);break;default:if(e.length==3){var h=e[1];var l=e[2];var c=0;if(typeof l=="function"){c=l(t,this,e)}else if(typeof l=="string"&&t[l]!=null){c=parseInt(t[l])}else{c=parseInt(l)}if(typeof h=="string"){var d=h.replace(/(le|be)$/,"");var p=null;if(/le$/.test(h)){p=n.LITTLE_ENDIAN}else if(/be$/.test(h)){p=n.BIG_ENDIAN}if(l=="*"){c=null}switch(d){case"uint8":r=this.readUint8Array(c);break;case"uint16":r=this.readUint16Array(c,p);break;case"uint32":r=this.readUint32Array(c,p);break;case"int8":r=this.readInt8Array(c);break;case"int16":r=this.readInt16Array(c,p);break;case"int32":r=this.readInt32Array(c,p);break;case"float32":r=this.readFloat32Array(c,p);break;case"float64":r=this.readFloat64Array(c,p);break;case"cstring":case"utf16string":case"string":if(c==null){r=[];while(!this.isEof()){u=this.readType(h,t);if(u==null)break;r.push(u)}}else{r=new Array(c);for(f=0;f<c;f++){r[f]=this.readType(h,t)}}break}}else{if(l=="*"){r=[];var m=this.buffer;while(true){var g=this.position;try{var v=this.readType(h,t);if(v==null){this.position=g;break}r.push(v)}catch(y){this.position=g;break}}}else{r=new Array(c);for(f=0;f<c;f++){u=this.readType(h,t);if(u==null)return null;r[f]=u}}}break}}if(i!=null){this.position=o+i}return r};n.prototype.writeStruct=function(e,t){for(var r=0;r<e.length;r+=2){var n=e[r+1];this.writeType(n,t[e[r]],t)}};n.prototype.writeType=function(e,t,r){var i;if(typeof e=="function"){return e(this,t)}else if(typeof e=="object"&&!(e instanceof Array)){return e.set(this,t,r)}var s=null;var o="ASCII";var a=this.position;if(typeof e=="string"&&/:/.test(e)){i=e.split(":");e=i[0];s=parseInt(i[1])}if(typeof e=="string"&&/,/.test(e)){i=e.split(",");e=i[0];o=parseInt(i[1])}switch(e){case"uint8":this.writeUint8(t);break;case"int8":this.writeInt8(t);break;case"uint16":this.writeUint16(t,this.endianness);break;case"int16":this.writeInt16(t,this.endianness);break;case"uint32":this.writeUint32(t,this.endianness);break;case"int32":this.writeInt32(t,this.endianness);break;case"float32":this.writeFloat32(t,this.endianness);break;case"float64":this.writeFloat64(t,this.endianness);break;case"uint16be":this.writeUint16(t,n.BIG_ENDIAN);break;case"int16be":this.writeInt16(t,n.BIG_ENDIAN);break;case"uint32be":this.writeUint32(t,n.BIG_ENDIAN);break;case"int32be":this.writeInt32(t,n.BIG_ENDIAN);break;case"float32be":this.writeFloat32(t,n.BIG_ENDIAN);break;case"float64be":this.writeFloat64(t,n.BIG_ENDIAN);break;case"uint16le":this.writeUint16(t,n.LITTLE_ENDIAN);break;case"int16le":this.writeInt16(t,n.LITTLE_ENDIAN);break;case"uint32le":this.writeUint32(t,n.LITTLE_ENDIAN);break;case"int32le":this.writeInt32(t,n.LITTLE_ENDIAN);break;case"float32le":this.writeFloat32(t,n.LITTLE_ENDIAN);break;case"float64le":this.writeFloat64(t,n.LITTLE_ENDIAN);break;case"cstring":this.writeCString(t,s);break;case"string":this.writeString(t,o,s);break;case"u16string":this.writeUCS2String(t,this.endianness,s);break;case"u16stringle":this.writeUCS2String(t,n.LITTLE_ENDIAN,s);break;case"u16stringbe":this.writeUCS2String(t,n.BIG_ENDIAN,s);break;default:if(e.length==3){var f=e[1];for(var u=0;u<t.length;u++){this.writeType(f,t[u])}break}else{this.writeStruct(e,t);break}}if(s!=null){this.position=a;this._realloc(s);this.position=a+s}};var i=Math.pow(2,32);r.MAX_SIZE=i;n.prototype.readUint64=function(){return this.readUint32()*i+this.readUint32()};n.prototype.writeUint64=function(e){var t=Math.floor(e/i);this.writeUint32(t);this.writeUint32(e&4294967295)};n.prototype.readUint24=function(){return(this.readUint8()<<16)+(this.readUint8()<<8)+this.readUint8()};n.prototype.writeUint24=function(e){this.writeUint8((e&16711680)>>16);this.writeUint8((e&65280)>>8);this.writeUint8(e&255)};n.prototype.adjustUint32=function(e,t){var r=this.position;this.seek(e);this.writeUint32(t);this.seek(r)}},{}],164:[function(e,t,r){var n=e("./DataStream");var s=e("./descriptor");var o=e("./log");var a={ERR_NOT_ENOUGH_DATA:0,OK:1,boxCodes:["mdat","avcC","hvcC","ftyp","payl","vmhd","smhd","hmhd","dref","elst"],fullBoxCodes:["mvhd","tkhd","mdhd","hdlr","smhd","hmhd","nhmd","url ","urn ","ctts","cslg","stco","co64","stsc","stss","stsz","stz2","stts","stsh","mehd","trex","mfhd","tfhd","trun","tfdt","esds","subs","txtC"],containerBoxCodes:[["moov",["trak"]],["trak"],["edts"],["mdia"],["minf"],["dinf"],["stbl"],["mvex",["trex"]],["moof",["traf"]],["traf",["trun"]],["vttc"],["tref"]],sampleEntryCodes:[{prefix:"Visual",types:["mp4v","avc1","avc2","avc3","avc4","avcp","drac","encv","mjp2","mvc1","mvc2","resv","s263","svc1","vc-1","hvc1","hev1"]},{prefix:"Audio",types:["mp4a","ac-3","alac","dra1","dtsc","dtse",,"dtsh","dtsl","ec-3","enca","g719","g726","m4ae","mlpa","raw ","samr","sawb","sawp","sevc","sqcp","ssmv","twos"]},{prefix:"Hint",types:["fdp ","m2ts","pm2t","prtp","rm2t","rrtp","rsrp","rtp ","sm2t","srtp"]},{prefix:"Metadata",types:["metx","mett","urim"]},{prefix:"Subtitle",types:["stpp","wvtt","sbtt","tx3g","stxt"]}],trackReferenceTypes:["scal"],initialize:function(){var e,t;var r;a.FullBox.prototype=new a.Box;a.ContainerBox.prototype=new a.Box;a.stsdBox.prototype=new a.FullBox;a.SampleEntry.prototype=new a.FullBox;a.TrackReferenceTypeBox.prototype=new a.Box;r=a.boxCodes.length;for(e=0;e<r;e++){a[a.boxCodes[e]+"Box"]=function(e){return function(t){a.Box.call(this,a.boxCodes[e],t)}}(e);a[a.boxCodes[e]+"Box"].prototype=new a.Box}r=a.fullBoxCodes.length;for(e=0;e<r;e++){a[a.fullBoxCodes[e]+"Box"]=function(e){return function(t){a.FullBox.call(this,a.fullBoxCodes[e],t)}}(e);a[a.fullBoxCodes[e]+"Box"].prototype=new a.FullBox}r=a.containerBoxCodes.length;for(e=0;e<r;e++){a[a.containerBoxCodes[e][0]+"Box"]=function(e,t){return function(r){a.ContainerBox.call(this,a.containerBoxCodes[e][0],r);if(t){this.subBoxNames=t;var n=t.length;for(var i=0;i<n;i++){this[t[i]+"s"]=[]}}}}(e,a.containerBoxCodes[e][1]);a[a.containerBoxCodes[e][0]+"Box"].prototype=new a.ContainerBox}r=a.sampleEntryCodes.length;for(t=0;t<r;t++){var n=a.sampleEntryCodes[t].prefix;var i=a.sampleEntryCodes[t].types;var s=i.length;a[n+"SampleEntry"]=function(e,t){a.SampleEntry.call(this,e,t)};a[n+"SampleEntry"].prototype=new a.SampleEntry;for(e=0;e<s;e++){a[i[e]+"Box"]=function(e,t){return function(r){a[a.sampleEntryCodes[e].prefix+"SampleEntry"].call(this,a.sampleEntryCodes[e].types[t],r)}}(t,e);a[i[e]+"Box"].prototype=new a[n+"SampleEntry"]}}r=a.trackReferenceTypes.length;for(e=0;e<r;e++){a[a.trackReferenceTypes[e]+"Box"]=function(e){return function(t){a.TrackReferenceTypeBox.call(this,a.trackReferenceTypes[e],t)}}(e);a[a.trackReferenceTypes[e]+"Box"].prototype=new a.Box}},Box:function(e,t){this.type=e;this.size=t},FullBox:function(e,t){a.Box.call(this,e,t);this.flags=0;this.version=0},ContainerBox:function(e,t){a.Box.call(this,e,t);this.boxes=[]},SampleEntry:function(e,t){a.Box.call(this,e,t);this.boxes=[]},TrackReferenceTypeBox:function(e,t){a.Box.call(this,e,t);this.track_ids=[]},stsdBox:function(e){a.FullBox.call(this,"stsd",e);this.entries=[]},parseOneBox:function(e,t){var r;var n=e.position;var i=0;if(e.byteLength-e.position<8){o.d("BoxParser","Not enough data in stream to parse the type and size of the box");return{code:a.ERR_NOT_ENOUGH_DATA}}var s=e.readUint32();var f=e.readString(4);o.d("BoxParser","Found box of type "+f+" and size "+s+" at position "+n+" in the current buffer ("+(e.buffer.fileStart+n)+" in the file)");i=8;if(s==1){if(e.byteLength-e.position<8){e.seek(n);o.w("BoxParser",'Not enough data in stream to parse the extended size of the "'+f+'" box');return{code:a.ERR_NOT_ENOUGH_DATA}}s=e.readUint64();i+=8}else if(s===0){throw"Unlimited box size not supported"}if(n+s>e.byteLength){e.seek(n);o.w("BoxParser",'Not enough data in stream to parse the entire "'+f+'" box');return{code:a.ERR_NOT_ENOUGH_DATA,type:f,size:s,hdr_size:i}}if(a[f+"Box"]){r=new a[f+"Box"](s-i)}else{if(t){r=new a.SampleEntry(f,s-i)}else{r=new a.Box(f,s-i)}}r.hdr_size=i;r.start=n;r.fileStart=n+e.buffer.fileStart;r.parse(e);e.seek(n+s);return{code:a.OK,box:r,size:s}}};t.exports=a;a.initialize();a.Box.prototype.parse=function(e){if(this.type!="mdat"){this.data=e.readUint8Array(this.size)}else{e.seek(this.start+this.size+this.hdr_size)}};a.FullBox.prototype.parseFullHeader=function(e){this.version=e.readUint8();this.flags=e.readUint24();this.size-=4};a.ContainerBox.prototype.parse=function(e){var t;var r;var n;n=e.position;while(e.position<n+this.size){t=a.parseOneBox(e);r=t.box;this.boxes.push(r);if(this.subBoxNames&&this.subBoxNames.indexOf(r.type)!=-1){this[this.subBoxNames+"s"].push(r)}else{this[r.type]=r}}};a.SampleEntry.prototype.isVideo=function(){return false};a.SampleEntry.prototype.isAudio=function(){return false};a.SampleEntry.prototype.isSubtitle=function(){return false};a.SampleEntry.prototype.isMetadata=function(){return false};a.SampleEntry.prototype.isHint=function(){return false};a.SampleEntry.prototype.getCodec=function(){return this.type};a.SampleEntry.prototype.getWidth=function(){return""};a.SampleEntry.prototype.getHeight=function(){return""};a.SampleEntry.prototype.getChannelCount=function(){return""};a.SampleEntry.prototype.getSampleRate=function(){return""};a.SampleEntry.prototype.getSampleSize=function(){return""};a.SampleEntry.prototype.parseHeader=function(e){this.start=e.position;e.readUint8Array(6);this.data_reference_index=e.readUint16()};a.SampleEntry.prototype.parse=function(e){this.parseHeader(e);e.seek(this.start+this.size)};a.SampleEntry.prototype.parseFooter=function(e){var t;var r;while(e.position<this.start+this.size){t=a.parseOneBox(e,false);r=t.box;this.boxes.push(r);this[r.type]=r}};a.VisualSampleEntry.prototype.parse=function(e){this.parseHeader(e);e.readUint16();e.readUint16();e.readUint32Array(3);this.width=e.readUint16();this.height=e.readUint16();this.horizresolution=e.readUint32();this.vertresolution=e.readUint32();e.readUint32();this.frame_count=e.readUint16();this.compressorname=e.readString(32);this.depth=e.readUint16();e.readUint16();this.parseFooter(e)};a.VisualSampleEntry.prototype.isVideo=function(){return true};a.VisualSampleEntry.prototype.getWidth=function(){return this.width};a.VisualSampleEntry.prototype.getHeight=function(){return this.height};a.AudioSampleEntry.prototype.parse=function(e){this.parseHeader(e);e.readUint32Array(2);this.channel_count=e.readUint16();this.samplesize=e.readUint16();e.readUint16();e.readUint16();this.samplerate=e.readUint32()/(1<<16);this.parseFooter(e)};a.AudioSampleEntry.prototype.isAudio=function(){return true};a.AudioSampleEntry.prototype.getChannelCount=function(){return this.channel_count};a.AudioSampleEntry.prototype.getSampleRate=function(){return this.samplerate};a.AudioSampleEntry.prototype.getSampleSize=function(){return this.samplesize};a.SubtitleSampleEntry.prototype.parse=function(e){this.parseHeader(e);this.parseFooter(e)};a.SubtitleSampleEntry.prototype.isSubtitle=function(){return true};a.MetadataSampleEntry.prototype.parse=function(e){this.parseHeader(e);this.parseFooter(e)};a.MetadataSampleEntry.prototype.isMetadata=function(){return true};a.TrackReferenceTypeBox.prototype.parse=function(e){this.track_ids=e.readUint8Array(this.size)};a.metxBox.prototype.parse=function(e){this.parseHeader(e);this.content_encoding=e.readCString();this.namespace=e.readCString();this.schema_location=e.readCString();this.parseFooter(e)};a.mettBox.prototype.parse=function(e){this.parseHeader(e);this.content_encoding=e.readCString();this.mime_format=e.readCString();this.parseFooter(e)};a.sbttBox.prototype.parse=function(e){this.parseHeader(e);this.content_encoding=e.readCString();this.mime_format=e.readCString();this.parseFooter(e)};a.stxtBox.prototype.parse=function(e){this.parseHeader(e);this.content_encoding=e.readCString();this.mime_format=e.readCString();this.parseFooter(e)};a.stppBox.prototype.parse=function(e){this.parseHeader(e);this.namespace=e.readCString();this.schema_location=e.readCString();this.auxiliary_mime_types=e.readCString();this.parseFooter(e)};a.tx3gBox.prototype.parse=function(e){this.parseHeader(e);this.displayFlags=e.readUint32();this.horizontal_justification=e.readInt8();this.vertical_justification=e.readInt8();this.bg_color_rgba=e.readUint8Array(4);this.box_record=e.readInt16Array(4);this.style_record=e.readUint8Array(12);this.parseFooter(e)};a.ftypBox.prototype.parse=function(e){this.major_brand=e.readString(4);this.minor_version=e.readUint32();this.size-=8;this.compatible_brands=[];var t=0;while(this.size>=4){this.compatible_brands[t]=e.readString(4);this.size-=4;t++}};a.mvhdBox.prototype.parse=function(e){this.flags=0;this.parseFullHeader(e);if(this.version==1){this.creation_time=e.readUint64();this.modification_time=e.readUint64();this.timescale=e.readUint32();this.duration=e.readUint64()}else{this.creation_time=e.readUint32();this.modification_time=e.readUint32();this.timescale=e.readUint32();this.duration=e.readUint32()}this.rate=e.readUint32();this.volume=e.readUint16()>>8;e.readUint16();e.readUint32Array(2);this.matrix=e.readUint32Array(9);e.readUint32Array(6);this.next_track_id=e.readUint32()};a.TKHD_FLAG_ENABLED=1;a.TKHD_FLAG_IN_MOVIE=2;a.TKHD_FLAG_IN_PREVIEW=4;a.tkhdBox.prototype.parse=function(e){this.parseFullHeader(e);if(this.version==1){this.creation_time=e.readUint64();this.modification_time=e.readUint64();this.track_id=e.readUint32();e.readUint32();this.duration=e.readUint64()}else{this.creation_time=e.readUint32();this.modification_time=e.readUint32();this.track_id=e.readUint32();e.readUint32();this.duration=e.readUint32()}e.readUint32Array(2);this.layer=e.readInt16();this.alternate_group=e.readInt16();this.volume=e.readInt16()>>8;e.readUint16();this.matrix=e.readInt32Array(9);this.width=e.readUint32();this.height=e.readUint32()};a.mdhdBox.prototype.parse=function(e){this.parseFullHeader(e);if(this.version==1){this.creation_time=e.readUint64();this.modification_time=e.readUint64();this.timescale=e.readUint32();this.duration=e.readUint64()}else{this.creation_time=e.readUint32();this.modification_time=e.readUint32();this.timescale=e.readUint32();this.duration=e.readUint32()}this.language=e.readUint16();var t=[];t[0]=this.language>>10&31;t[1]=this.language>>5&31;t[2]=this.language&31;this.languageString=String.fromCharCode(t[0]+96,t[1]+96,t[2]+96);e.readUint16()};a.hdlrBox.prototype.parse=function(e){this.parseFullHeader(e);if(this.version===0){e.readUint32();this.handler=e.readString(4);e.readUint32Array(3);this.name=e.readCString()}else{this.data=e.readUint8Array(size)}};a.stsdBox.prototype.parse=function(e){var t;var r;this.parseFullHeader(e);r=e.readUint32();for(i=1;i<=r;i++){t=a.parseOneBox(e,true);this.entries.push(t.box)}};a.avcCBox.prototype.parse=function(e){var t;var r;var n;this.configurationVersion=e.readUint8();this.AVCProfileIndication=e.readUint8();this.profile_compatibility=e.readUint8();this.AVCLevelIndication=e.readUint8();this.lengthSizeMinusOne=e.readUint8()&3;r=e.readUint8()&31;this.size-=6;this.SPS=new Array(r);for(t=0;t<r;t++){n=e.readUint16();this.SPS[t]=e.readUint8Array(n);this.size-=2+n}r=e.readUint8();this.size--;this.PPS=new Array(r);for(t=0;t<r;t++){n=e.readUint16();this.PPS[t]=e.readUint8Array(n);this.size-=2+n}if(this.size>0){this.ext=e.readUint8Array(this.size)}};a.hvcCBox.prototype.parse=function(e){var t;var r;var n;var i;this.configurationVersion=e.readUint8();i=e.readUint8();this.general_profile_space=i>>6;this.general_tier_flag=(i&32)>>5;this.general_profile_idc=i&31;this.general_profile_compatibility=e.readUint32();this.general_constraint_indicator=e.readUint8Array(6);this.general_level_idc=e.readUint8();this.min_spatial_segmentation_idc=e.readUint16()&4095;this.parallelismType=e.readUint8()&3;this.chromaFormat=e.readUint8()&3;this.bitDepthLumaMinus8=e.readUint8()&7;this.bitDepthChromaMinus8=e.readUint8()&7;this.avgFrameRate=e.readUint16();i=e.readUint8();this.constantFrameRate=i>>6;this.numTemporalLayers=(i&13)>>3;this.temporalIdNested=(i&4)>>2;this.lengthSizeMinusOne=i&3;this.nalu_arrays=[];numOfArrays=e.readUint8();for(t=0;t<numOfArrays;t++){var s=[];this.nalu_arrays.push(s);i=e.readUint8();s.completeness=(i&128)>>7;s.nalu_type=i&63;numNalus=e.readUint16();for(j=0;j<numNalus;j++){var o={};s.push(o);n=e.readUint16();o.data=e.readUint8Array(n)}}};function f(e,t){var r=Number(e).toString(16);t=typeof t==="undefined"||t===null?t=2:t;while(r.length<t){r="0"+r}return r}a.avc1Box.prototype.getCodec=function(){var e=a.SampleEntry.prototype.getCodec.call(this);if(this.avcC){return e+"."+f(this.avcC.AVCProfileIndication)+""+f(this.avcC.profile_compatibility)+""+f(this.avcC.AVCLevelIndication)}else{return e}};a.hvc1Box.prototype.getCodec=function(){var e;var t=a.SampleEntry.prototype.getCodec.call(this);if(this.hvcC){t+=".";switch(this.hvcC.general_profile_space){case 0:t+="";break;case 1:t+="A";break;case 2:t+="B";break;case 3:t+="C";break}t+=this.hvcC.general_profile_idc;t+=".";var r=this.hvcC.general_profile_compatibility;var n=0;for(e=0;e<32;e++){n|=r&1;if(e==31)break;n<<=1;r>>=1}t+=f(n,0);t+=".";if(this.hvcC.general_tier_flag===0){t+="L"}else{t+="H"}t+=this.hvcC.general_level_idc;var i=false;var s="";for(e=5;e>=0;e--){if(this.hvcC.general_constraint_indicator[e]||i){s="."+f(this.hvcC.general_constraint_indicator[e],0)+s;i=true}}t+=s}return t};a.mp4aBox.prototype.getCodec=function(){var e=a.SampleEntry.prototype.getCodec.call(this);if(this.esds&&this.esds.esd){var t=this.esds.esd.getOTI();var r=this.esds.esd.getAudioConfig();return e+"."+f(t)+(r?"."+r:"")}else{return e}};a.esdsBox.prototype.parse=function(e){this.parseFullHeader(e);this.data=e.readUint8Array(this.size);this.size=0;var t=new s;this.esd=t.parseOneDescriptor(new n(this.data.buffer,0,n.BIG_ENDIAN))};a.txtCBox.prototype.parse=function(e){this.parseFullHeader(e);this.config=e.readCString()};a.cttsBox.prototype.parse=function(e){var t;var r;this.parseFullHeader(e);t=e.readUint32();this.sample_counts=[];this.sample_offsets=[];if(this.version===0){for(r=0;r<t;r++){this.sample_counts.push(e.readUint32());this.sample_offsets.push(e.readInt32())}}else if(this.version==1){for(r=0;r<t;r++){this.sample_counts.push(e.readUint32());this.sample_offsets.push(e.readInt32())}}else{this.data=e.readUint8Array(this.size-4)}};a.cttsBox.prototype.unpack=function(e){var t,r,n;n=0;for(t=0;t<this.sample_counts.length;t++){for(r=0;r<this.sample_counts[t];r++){e[n].pts=e[n].dts+this.sample_offsets[t];n++}}};a.cslgBox.prototype.parse=function(e){var t;this.parseFullHeader(e);if(this.version===0){this.compositionToDTSShift=e.readInt32();this.leastDecodeToDisplayDelta=e.readInt32();this.greatestDecodeToDisplayDelta=e.readInt32();this.compositionStartTime=e.readInt32();this.compositionEndTime=e.readInt32()}else{this.data=e.readUint8Array(this.size-4)}};a.sttsBox.prototype.parse=function(e){var t;var r;this.parseFullHeader(e);t=e.readUint32();this.sample_counts=[];this.sample_deltas=[];if(this.version===0){for(r=0;r<t;r++){this.sample_counts.push(e.readUint32());this.sample_deltas.push(e.readUint32())}}else{this.data=e.readUint8Array(this.size-4)}};a.sttsBox.prototype.unpack=function(e){var t,r,n;n=0;for(t=0;t<this.sample_counts.length;t++){for(r=0;r<this.sample_counts[t];r++){if(n===0){e[n].dts=0}else{e[n].dts=e[n-1].dts+this.sample_deltas[t]}n++}}};a.stssBox.prototype.parse=function(e){var t;this.parseFullHeader(e);t=e.readUint32();if(this.version===0){this.sample_numbers=e.readUint32Array(t)}else{this.data=e.readUint8Array(this.size-4)}};a.stshBox.prototype.parse=function(e){var t;var r;this.parseFullHeader(e);t=e.readUint32();this.shadowed_sample_numbers=[];this.sync_sample_numbers=[];if(this.version===0){for(r=0;r<t;r++){this.shadowed_sample_numbers.push(e.readUint32());this.sync_sample_numbers.push(e.readUint32())}}else{this.data=e.readUint8Array(this.size-4)}};a.stcoBox.prototype.parse=function(e){var t;this.parseFullHeader(e);t=e.readUint32();if(this.version===0){this.chunk_offsets=e.readUint32Array(t)}else{this.data=e.readUint8Array(this.size-4)}};a.stcoBox.prototype.unpack=function(e){var t;for(t=0;t<this.chunk_offsets.length;t++){e[t].offset=this.chunk_offsets[t]}};a.co64Box.prototype.parse=function(e){var t;var r;this.parseFullHeader(e);t=e.readUint32();this.chunk_offsets=[];if(this.version===0){for(r=0;r<t;r++){this.chunk_offsets.push(e.readUint64())}}else{this.data=e.readUint8Array(this.size-4)}};a.stscBox.prototype.parse=function(e){var t;var r;this.parseFullHeader(e);t=e.readUint32();this.first_chunk=[];this.samples_per_chunk=[];this.sample_description_index=[];if(this.version===0){for(r=0;r<t;r++){this.first_chunk.push(e.readUint32());this.samples_per_chunk.push(e.readUint32());this.sample_description_index.push(e.readUint32())}}else{this.data=e.readUint8Array(this.size-4)}};a.stscBox.prototype.unpack=function(e){var t,r,n,i,s;i=0;s=0;for(t=0;t<this.first_chunk.length;t++){for(r=0;r<(t+1<this.first_chunk.length?this.first_chunk[t+1]:Infinity);r++){s++;for(n=0;n<this.samples_per_chunk[t];n++){if(e[i]){e[i].description_index=this.sample_description_index[t];e[i].chunk_index=s}else{return}i++}}}};a.stszBox.prototype.parse=function(e){var t;var r;var n;this.parseFullHeader(e);this.sample_sizes=[];if(this.version===0){r=e.readUint32();n=e.readUint32();if(r===0){this.sample_sizes=e.readUint32Array(n)}else{this.sample_sizes=[];for(t=0;t<n;t++){this.sample_sizes[t]=r}}}else{this.data=e.readUint8Array(this.size)}};a.stszBox.prototype.unpack=function(e){var t;for(t=0;t<this.sample_sizes.length;t++){e[t].size=this.sample_sizes[t]}};a.mehdBox.prototype.parse=function(e){this.parseFullHeader(e);if(this.version==1){this.fragment_duration=e.readUint64()}else{this.fragment_duration=e.readUint32()}};a.trexBox.prototype.parse=function(e){this.parseFullHeader(e);this.track_id=e.readUint32();this.default_sample_description_index=e.readUint32();this.default_sample_duration=e.readUint32();this.default_sample_size=e.readUint32();this.default_sample_flags=e.readUint32()};a.mfhdBox.prototype.parse=function(e){this.parseFullHeader(e);this.sequence_number=e.readUint32()};a.TFHD_FLAG_BASE_DATA_OFFSET=1;a.TFHD_FLAG_SAMPLE_DESC=2;a.TFHD_FLAG_SAMPLE_DUR=8;a.TFHD_FLAG_SAMPLE_SIZE=16;a.TFHD_FLAG_SAMPLE_FLAGS=32;a.TFHD_FLAG_DUR_EMPTY=65536;a.TFHD_FLAG_DEFAULT_BASE_IS_MOOF=131072;a.tfhdBox.prototype.parse=function(e){var t=0;this.parseFullHeader(e);this.track_id=e.readUint32();if(this.size>t&&this.flags&a.TFHD_FLAG_BASE_DATA_OFFSET){this.base_data_offset=e.readUint64();t+=8}else{this.base_data_offset=0}if(this.size>t&&this.flags&a.TFHD_FLAG_SAMPLE_DESC){this.default_sample_description_index=e.readUint32();t+=4}else{this.default_sample_description_index=0}if(this.size>t&&this.flags&a.TFHD_FLAG_SAMPLE_DUR){this.default_sample_duration=e.readUint32();t+=4}else{this.default_sample_duration=0}if(this.size>t&&this.flags&a.TFHD_FLAG_SAMPLE_SIZE){this.default_sample_size=e.readUint32();t+=4}else{this.default_sample_size=0}if(this.size>t&&this.flags&a.TFHD_FLAG_SAMPLE_FLAGS){this.default_sample_flags=e.readUint32();t+=4}else{this.default_sample_flags=0}};a.TRUN_FLAGS_DATA_OFFSET=1;a.TRUN_FLAGS_FIRST_FLAG=4;a.TRUN_FLAGS_DURATION=256;a.TRUN_FLAGS_SIZE=512;a.TRUN_FLAGS_FLAGS=1024;a.TRUN_FLAGS_CTS_OFFSET=2048;a.trunBox.prototype.parse=function(e){var t=0;this.parseFullHeader(e);this.sample_count=e.readUint32();t+=4;if(this.size>t&&this.flags&a.TRUN_FLAGS_DATA_OFFSET){this.data_offset=e.readInt32();t+=4}else{this.data_offset=0}if(this.size>t&&this.flags&a.TRUN_FLAGS_FIRST_FLAG){this.first_sample_flags=e.readUint32();t+=4}else{this.first_sample_flags=0}this.sample_duration=[];this.sample_size=[];this.sample_flags=[];this.sample_composition_time_offset=[];if(this.size>t){for(var r=0;r<this.sample_count;r++){if(this.flags&a.TRUN_FLAGS_DURATION){this.sample_duration[r]=e.readUint32()}if(this.flags&a.TRUN_FLAGS_SIZE){this.sample_size[r]=e.readUint32()}if(this.flags&a.TRUN_FLAGS_FLAGS){this.sample_flags[r]=e.readUint32()}if(this.flags&a.TRUN_FLAGS_CTS_OFFSET){if(this.version===0){this.sample_composition_time_offset[r]=e.readUint32()}else{this.sample_composition_time_offset[r]=e.readInt32()}}}}};a.tfdtBox.prototype.parse=function(e){this.parseFullHeader(e);if(this.version==1){this.baseMediaDecodeTime=e.readUint64()}else{this.baseMediaDecodeTime=e.readUint32()}};a.paylBox.prototype.parse=function(e){this.text=e.readString(this.size)};a.subsBox.prototype.parse=function(e){var t,r;var n;var i;this.parseFullHeader(e);n=e.readUint32();this.samples=[];for(t=0;t<n;t++){var s={};this.samples[t]=s;s.sample_delta=e.readUint32();s.subsamples=[];i=e.readUint16();if(i>0){for(r=0;r<i;r++){var o={};s.subsamples.push(o);if(this.version==1){o.size=e.readUint32()}else{o.size=e.readUint16()}o.priority=e.readUint8();o.discardable=e.readUint8();o.reserved=e.readUint32()}}}};a.Box.prototype.writeHeader=function(e,t){this.size+=8;if(this.size>n.MAX_SIZE){this.size+=8}o.d("BoxWriter","Writing box "+this.type+" of size: "+this.size+" at position "+e.position+(t||""));if(this.size>n.MAX_SIZE){e.writeUint32(1)}else{this.sizePosition=e.position;e.writeUint32(this.size)}e.writeString(this.type,null,4);if(this.size>n.MAX_SIZE){e.writeUint64(this.size)}};a.FullBox.prototype.writeHeader=function(e){
this.size+=4;a.Box.prototype.writeHeader.call(this,e," v="+this.version+" f="+this.flags);e.writeUint8(this.version);e.writeUint24(this.flags)};a.Box.prototype.write=function(e){if(this.type==="mdat"){if(this.data){this.size=this.data.length;this.writeHeader(e);e.writeUint8Array(this.data)}}else{this.size=this.data.length;this.writeHeader(e);e.writeUint8Array(this.data)}};a.ContainerBox.prototype.write=function(e){this.size=0;this.writeHeader(e);for(var t=0;t<this.boxes.length;t++){if(this.boxes[t]){this.boxes[t].write(e);this.size+=this.boxes[t].size}}o.d("BoxWriter","Adjusting box "+this.type+" with new size "+this.size);e.adjustUint32(this.sizePosition,this.size)};a.TrackReferenceTypeBox.prototype.write=function(e){this.size=this.track_ids.length*4;this.writeHeader(e);e.writeUint32Array(this.track_ids)};a.ftypBox.prototype.write=function(e){this.size=8+4*this.compatible_brands.length;this.writeHeader(e);e.writeString(this.major_brand,null,4);e.writeUint32(this.minor_version);for(var t=0;t<this.compatible_brands.length;t++){e.writeString(this.compatible_brands[t],null,4)}};a.mvhdBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=23*4+2*2;this.writeHeader(e);e.writeUint32(this.creation_time);e.writeUint32(this.modification_time);e.writeUint32(this.timescale);e.writeUint32(this.duration);e.writeUint32(this.rate);e.writeUint16(this.volume<<8);e.writeUint16(0);e.writeUint32(0);e.writeUint32(0);e.writeUint32Array(this.matrix);e.writeUint32(0);e.writeUint32(0);e.writeUint32(0);e.writeUint32(0);e.writeUint32(0);e.writeUint32(0);e.writeUint32(this.next_track_id)};a.tkhdBox.prototype.write=function(e){this.version=0;this.size=4*18+2*4;this.writeHeader(e);e.writeUint32(this.creation_time);e.writeUint32(this.modification_time);e.writeUint32(this.track_id);e.writeUint32(0);e.writeUint32(this.duration);e.writeUint32(0);e.writeUint32(0);e.writeInt16(this.layer);e.writeInt16(this.alternate_group);e.writeInt16(this.volume<<8);e.writeUint16(0);e.writeInt32Array(this.matrix);e.writeUint32(this.width);e.writeUint32(this.height)};a.mdhdBox.prototype.write=function(e){this.size=4*4+2*2;this.flags=0;this.version=0;this.writeHeader(e);e.writeUint32(this.creation_time);e.writeUint32(this.modification_time);e.writeUint32(this.timescale);e.writeUint32(this.duration);e.writeUint16(this.language);e.writeUint16(0)};a.hdlrBox.prototype.write=function(e){this.size=5*4+this.name.length+1;this.version=0;this.flags=0;this.writeHeader(e);e.writeUint32(0);e.writeString(this.handler,null,4);e.writeUint32(0);e.writeUint32(0);e.writeUint32(0);e.writeCString(this.name)};a.stsdBox.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=0;this.writeHeader(e);e.writeUint32(this.entries.length);this.size+=4;for(t=0;t<this.entries.length;t++){this.entries[t].write(e);this.size+=this.entries[t].size}o.d("BoxWriter","Adjusting box "+this.type+" with new size "+this.size);e.adjustUint32(this.sizePosition,this.size)};a.SampleEntry.prototype.writeHeader=function(e){this.size=8;a.Box.prototype.writeHeader.call(this,e);e.writeUint8(0);e.writeUint8(0);e.writeUint8(0);e.writeUint8(0);e.writeUint8(0);e.writeUint8(0);e.writeUint16(this.data_reference_index)};a.SampleEntry.prototype.writeFooter=function(e){for(var t=0;t<this.boxes.length;t++){this.boxes[t].write(e);this.size+=this.boxes[t].size}o.d("BoxWriter","Adjusting box "+this.type+" with new size "+this.size);e.adjustUint32(this.sizePosition,this.size)};a.SampleEntry.prototype.write=function(e){this.writeHeader(e);this.writeFooter(e)};a.VisualSampleEntry.prototype.write=function(e){this.writeHeader(e);this.size+=2*7+6*4+32;e.writeUint16(0);e.writeUint16(0);e.writeUint32(0);e.writeUint32(0);e.writeUint32(0);e.writeUint16(this.width-this.width%2);e.writeUint16(this.height-this.height%2);e.writeUint32(this.horizresolution);e.writeUint32(this.vertresolution);e.writeUint32(0);e.writeUint16(this.frame_count);e.writeString(this.compressorname,null,32);e.writeUint16(this.depth);e.writeInt16(-1);this.writeFooter(e)};a.AudioSampleEntry.prototype.write=function(e){this.writeHeader(e);this.size+=2*4+3*4;e.writeUint32(0);e.writeUint32(0);e.writeUint16(this.channel_count);e.writeUint16(this.samplesize);e.writeUint16(0);e.writeUint16(0);e.writeUint32(this.samplerate<<16);this.writeFooter(e)};a.avcCBox.prototype.write=function(e){var t;this.size=7;for(t=0;t<this.SPS.length;t++){this.size+=2+this.SPS[t].length}for(t=0;t<this.PPS.length;t++){this.size+=2+this.PPS[t].length}if(this.ext){this.size+=this.ext.length}this.writeHeader(e);e.writeUint8(this.configurationVersion);e.writeUint8(this.AVCProfileIndication);e.writeUint8(this.profile_compatibility);e.writeUint8(this.AVCLevelIndication);e.writeUint8(this.lengthSizeMinusOne+(63<<2));e.writeUint8(this.SPS.length+(7<<5));for(t=0;t<this.SPS.length;t++){e.writeUint16(this.SPS[t].length);e.writeUint8Array(this.SPS[t])}e.writeUint8(this.PPS.length);for(t=0;t<this.PPS.length;t++){e.writeUint16(this.PPS[t].length);e.writeUint8Array(this.PPS[t])}if(this.ext){e.writeUint8Array(this.ext)}};a.cttsBox.prototype.write=function(e){var t;this.version=1;this.flags=0;this.size=4+8*this.sample_counts.length;this.writeHeader(e);e.writeUint32(this.sample_counts.length);for(t=0;t<this.sample_counts.length;t++){e.writeUint32(this.sample_counts[t]);e.writeInt32(this.sample_offsets[t])}};a.cslgBox.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=4*5;this.writeHeader(e);e.writeInt32(this.compositionToDTSShift);e.writeInt32(this.leastDecodeToDisplayDelta);e.writeInt32(this.greatestDecodeToDisplayDelta);e.writeInt32(this.compositionStartTime);e.writeInt32(this.compositionEndTime)};a.sttsBox.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=4+8*this.sample_counts.length;this.writeHeader(e);e.writeUint32(this.sample_counts.length);for(t=0;t<this.sample_counts.length;t++){e.writeUint32(this.sample_counts[t]);e.writeUint32(this.sample_deltas[t])}};a.stssBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=4+4*this.sample_numbers.length;this.writeHeader(e);e.writeUint32(this.sample_numbers.length);e.writeUint32Array(this.sample_numbers)};a.stshBox.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=4+8*this.shadowed_sample_numbers.length;this.writeHeader(e);e.writeUint32(this.shadowed_sample_numbers.length);for(t=0;t<this.shadowed_sample_numbers.length;t++){e.writeUint32(this.shadowed_sample_numbers[t]);e.writeUint32(this.sync_sample_numbers[t])}};a.stcoBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=4+4*this.chunk_offsets.length;this.writeHeader(e);e.writeUint32(this.chunk_offsets.length);e.writeUint32Array(this.chunk_offsets)};a.co64Box.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=4+8*this.chunk_offsets.length;this.writeHeader(e);e.writeUint32(this.chunk_offsets.length);for(t=0;t<this.chunk_offsets.length;t++){e.writeUint64(this.chunk_offsets[t])}};a.stscBox.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=4+12*this.first_chunk.length;this.writeHeader(e);e.writeUint32(this.first_chunk.length);for(t=0;t<this.first_chunk.length;t++){e.writeUint32(this.first_chunk[t]);e.writeUint32(this.samples_per_chunk[t]);e.writeUint32(this.sample_description_index[t])}};a.stszBox.prototype.write=function(e){var t;this.version=0;this.flags=0;this.size=8+12*this.sample_sizes.length;this.writeHeader(e);e.writeUint32(0);e.writeUint32(this.sample_sizes.length);e.writeUint32Array(this.sample_sizes)};a.mehdBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=4;this.writeHeader(e);e.writeUint32(this.fragment_duration)};a.trexBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=4*5;this.writeHeader(e);e.writeUint32(this.track_id);e.writeUint32(this.default_sample_description_index);e.writeUint32(this.default_sample_duration);e.writeUint32(this.default_sample_size);e.writeUint32(this.default_sample_flags)};a.mfhdBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=4;this.writeHeader(e);e.writeUint32(this.sequence_number)};a.tfhdBox.prototype.write=function(e){this.version=0;this.size=4;if(this.flags&a.TFHD_FLAG_BASE_OFFSET){this.size+=8}if(this.flags&a.TFHD_FLAG_SAMPLE_DESC){this.size+=4}if(this.flags&a.TFHD_FLAG_SAMPLE_DUR){this.size+=4}if(this.flags&a.TFHD_FLAG_SAMPLE_SIZE){this.size+=4}if(this.flags&a.TFHD_FLAG_SAMPLE_FLAGS){this.size+=4}this.writeHeader(e);e.writeUint32(this.track_id);if(this.flags&a.TFHD_FLAG_BASE_OFFSET){e.writeUint64(this.base_data_offset)}if(this.flags&a.TFHD_FLAG_SAMPLE_DESC){e.writeUint32(this.default_sample_description_index)}if(this.flags&a.TFHD_FLAG_SAMPLE_DUR){e.writeUint32(this.default_sample_duration)}if(this.flags&a.TFHD_FLAG_SAMPLE_SIZE){e.writeUint32(this.default_sample_size)}if(this.flags&a.TFHD_FLAG_SAMPLE_FLAGS){e.writeUint32(this.default_sample_flags)}};a.trunBox.prototype.write=function(e){this.version=0;this.size=4;if(this.flags&a.TRUN_FLAGS_DATA_OFFSET){this.size+=4}if(this.flags&a.TRUN_FLAGS_FIRST_FLAG){this.size+=4}if(this.flags&a.TRUN_FLAGS_DURATION){this.size+=4*this.sample_duration.length}if(this.flags&a.TRUN_FLAGS_SIZE){this.size+=4*this.sample_size.length}if(this.flags&a.TRUN_FLAGS_FLAGS){this.size+=4*this.sample_flags.length}if(this.flags&a.TRUN_FLAGS_CTS_OFFSET){this.size+=4*this.sample_composition_time_offset.length}this.writeHeader(e);e.writeUint32(this.sample_count);if(this.flags&a.TRUN_FLAGS_DATA_OFFSET){this.data_offset_position=e.position;e.writeInt32(this.data_offset)}if(this.flags&a.TRUN_FLAGS_FIRST_FLAG){e.writeUint32(this.first_sample_flags)}for(var t=0;t<this.sample_count;t++){if(this.flags&a.TRUN_FLAGS_DURATION){e.writeUint32(this.sample_duration[t])}if(this.flags&a.TRUN_FLAGS_SIZE){e.writeUint32(this.sample_size[t])}if(this.flags&a.TRUN_FLAGS_FLAGS){e.writeUint32(this.sample_flags[t])}if(this.flags&a.TRUN_FLAGS_CTS_OFFSET){if(this.version===0){e.writeUint32(this.sample_composition_time_offset[t])}else{e.writeInt32(this.sample_composition_time_offset[t])}}}};a.tfdtBox.prototype.write=function(e){this.version=0;this.flags=0;this.size=4;this.writeHeader(e);if(this.version==1){e.writeUint64(this.baseMediaDecodeTime)}else{e.writeUint32(this.baseMediaDecodeTime)}}},{"./DataStream":163,"./descriptor":165,"./log":167}],165:[function(e,t,r){var n=e("./log");var i=function(){var e=3;var t=4;var r=5;var i=6;var s=[];s[e]="ES_Descriptor";s[t]="DecoderConfigDescriptor";s[r]="DecoderSpecificInfo";s[i]="SLConfigDescriptor";var o=this;var a={};this.parseOneDescriptor=function(e){var t=0;var r=0;var i;var o;var f;i=e.readUint8();t++;f=e.readUint8();t++;while(f&128){r=(f&127)<<7;f=e.readUint8();t++}r+=f&127;n.d("MPEG4DescriptorParser","Found "+(s[i]|"Descriptor "+i)+", size "+r+" at position "+e.position);if(s[i]){o=new a[s[i]](r)}else{o=new a.Descriptor(r)}o.parse(e);return o};a.Descriptor=function(e,t){this.tag=e;this.size=t;this.descs=[]};a.Descriptor.prototype.parse=function(e){this.data=e.readUint8Array(this.size)};a.Descriptor.prototype.findDescriptor=function(e){for(var t=0;t<this.descs.length;t++){if(this.descs[t].tag==e){return this.descs[t]}}return null};a.Descriptor.prototype.parseRemainingDescriptors=function(e){var t=e.position;while(e.position<t+this.size){var r=o.parseOneDescriptor(e);this.descs.push(r)}};a.ES_Descriptor=function(t){a.Descriptor.call(this,e,t)};a.ES_Descriptor.prototype=new a.Descriptor;a.ES_Descriptor.prototype.parse=function(e){this.ES_ID=e.readUint16();this.flags=e.readUint8();this.size-=3;if(this.flags&128){this.dependsOn_ES_ID=e.readUint16();this.size-=2}else{this.dependsOn_ES_ID=0}if(this.flags&64){var t=e.readUint8();this.URL=e.readString(t);this.size-=t+1}else{this.URL=null}if(this.flags&32){this.OCR_ES_ID=e.readUint16();this.size-=2}else{this.OCR_ES_ID=0}this.parseRemainingDescriptors(e)};a.ES_Descriptor.prototype.getOTI=function(e){var r=this.findDescriptor(t);if(r){return r.oti}else{return 0}};a.ES_Descriptor.prototype.getAudioConfig=function(e){var n=this.findDescriptor(t);if(!n)return null;var i=n.findDescriptor(r);if(i&&i.data){return(i.data[0]&248)>>3}else{return null}};a.DecoderConfigDescriptor=function(e){a.Descriptor.call(this,t,e)};a.DecoderConfigDescriptor.prototype=new a.Descriptor;a.DecoderConfigDescriptor.prototype.parse=function(e){this.oti=e.readUint8();this.streamType=e.readUint8();this.bufferSize=e.readUint24();this.maxBitrate=e.readUint32();this.avgBitrate=e.readUint32();this.size-=13;this.parseRemainingDescriptors(e)};a.DecoderSpecificInfo=function(e){a.Descriptor.call(this,r,e)};a.DecoderSpecificInfo.prototype=new a.Descriptor;a.SLConfigDescriptor=function(e){a.Descriptor.call(this,i,e)};a.SLConfigDescriptor.prototype=new a.Descriptor;return this};t.exports=i},{"./log":167}],166:[function(e,t,r){var n=e("./box");var i=e("./DataStream");var s=e("./log");var o=function(e){this.stream=e;this.boxes=[];this.mdats=[];this.moofs=[];this.isProgressive=false;this.lastMoofIndex=0;this.lastBoxStartPosition=0;this.parsingMdat=null;this.moovStartFound=false;this.samplesDataSize=0;this.nextParsePosition=0};t.exports=o;o.prototype.mergeNextBuffer=function(){var e;if(this.stream.bufferIndex+1<this.stream.nextBuffers.length){e=this.stream.nextBuffers[this.stream.bufferIndex+1];if(e.fileStart===this.stream.buffer.fileStart+this.stream.buffer.byteLength){var t=this.stream.buffer.byteLength;var r=this.stream.buffer.usedBytes;var n=this.stream.buffer.fileStart;this.stream.nextBuffers[this.stream.bufferIndex]=ArrayBuffer.concat(this.stream.buffer,e);this.stream.buffer=this.stream.nextBuffers[this.stream.bufferIndex];this.stream.nextBuffers.splice(this.stream.bufferIndex+1,1);this.stream.buffer.usedBytes=r;this.stream.buffer.fileStart=n;s.d("ISOFile","Concatenating buffer for box parsing (length: "+t+"->"+this.stream.buffer.byteLength+")");return true}else{return false}}else{return false}};o.prototype.parse=function(){var e;var t;var r;s.d("ISOFile","Starting parsing with buffer #"+this.stream.bufferIndex+" (fileStart: "+this.stream.buffer.fileStart+" - Length: "+this.stream.buffer.byteLength+") from position "+this.lastBoxStartPosition+" ("+(this.stream.buffer.fileStart+this.lastBoxStartPosition)+" in the file)");this.stream.seek(this.lastBoxStartPosition);while(true){if(this.parsingMdat!==null){r=this.parsingMdat;e=this.reposition(false,r.fileStart+r.hdr_size+r.size);if(e){s.d("ISOFile","Found 'mdat' end in buffer #"+this.stream.bufferIndex);this.parsingMdat=null;continue}else{this.nextParsePosition=this.findEndContiguousBuf(this.stream.bufferIndex);return}}else{this.lastBoxStartPosition=this.stream.position;t=n.parseOneBox(this.stream);if(t.code===n.ERR_NOT_ENOUGH_DATA){if(t.type==="mdat"){r=new n[t.type+"Box"](t.size-t.hdr_size);this.parsingMdat=r;this.mdats.push(r);r.fileStart=this.stream.buffer.fileStart+this.stream.position;r.hdr_size=t.hdr_size;this.stream.buffer.usedBytes+=t.hdr_size;e=this.reposition(false,r.fileStart+r.hdr_size+r.size);if(e){this.parsingMdat=null;continue}else{if(!this.moovStartFound){this.nextParsePosition=r.fileStart+r.size+r.hdr_size}else{this.nextParsePosition=this.findEndContiguousBuf(this.stream.bufferIndex)}return}}else{if(t.type==="moov"){this.moovStartFound=true;if(this.mdats.length===0){this.isProgressive=true}}else if(t.type==="free"){e=this.reposition(false,this.stream.buffer.fileStart+this.stream.position+t.size);if(e){continue}else{this.nextParsePosition=this.stream.buffer.fileStart+this.stream.position+t.size;return}}merged=this.mergeNextBuffer();if(merged){this.nextParsePosition=this.stream.buffer.fileStart+this.stream.buffer.byteLength;continue}else{if(!t.type){this.nextParsePosition=this.stream.buffer.fileStart+this.stream.buffer.byteLength}else{if(this.moovStartFound){this.nextParsePosition=this.stream.buffer.fileStart+this.stream.buffer.byteLength}else{this.nextParsePosition=this.stream.buffer.fileStart+this.stream.position+t.size}}return}}}else{r=t.box;this.boxes.push(r);switch(r.type){case"mdat":this.mdats.push(r);r.fileStart=this.stream.buffer.fileStart+r.start;break;case"moof":this.moofs.push(r);break;case"moov":this.moovStartFound=true;if(this.mdats.length===0){this.isProgressive=true}default:if(this[r.type]!==undefined){s.w("ISOFile","Duplicate Box of type: "+r.type+", overriding previous occurrence")}this[r.type]=r;break}if(r.type==="mdat"){this.stream.buffer.usedBytes+=r.hdr_size}else{this.stream.buffer.usedBytes+=t.size}}}}};o.prototype.reposition=function(e,t){var r;r=this.findPosition(e,t);if(r!==-1){this.stream.buffer=this.stream.nextBuffers[r];this.stream.bufferIndex=r;this.stream.position=t-this.stream.buffer.fileStart;s.d("ISOFile","Repositioning parser at buffer position: "+this.stream.position);return true}else{return false}};o.prototype.findPosition=function(e,t){var r;var n=null;var i=-1;if(e===true){r=0}else{r=this.stream.bufferIndex}while(r<this.stream.nextBuffers.length){n=this.stream.nextBuffers[r];if(n.fileStart<=t){i=r}else{break}r++}if(i!==-1){n=this.stream.nextBuffers[i];if(n.fileStart+n.byteLength>=t){s.d("ISOFile","Found position in existing buffer #"+i);return i}else{return-1}}else{return-1}};o.prototype.findEndContiguousBuf=function(e){var t;var r;var n;r=this.stream.nextBuffers[e];if(this.stream.nextBuffers.length>e+1){for(t=e+1;t<this.stream.nextBuffers.length;t++){n=this.stream.nextBuffers[t];if(n.fileStart===r.fileStart+r.byteLength){r=n}else{break}}}return r.fileStart+r.byteLength};o.prototype.write=function(e){for(var t=0;t<this.boxes.length;t++){this.boxes[t].write(e)}};o.prototype.writeInitializationSegment=function(e){var t;var r;var i;var o;var a;s.d("ISOFile","Generating initialization segment");this.ftyp.write(e);if(this.moov.mvex){this.initial_duration=this.moov.mvex.mehd.fragment_duration;r=-1;for(t=0;t<this.moov.boxes.length;t++){a=this.moov.boxes[t];if(a===this.moov.mvex){r=t}}if(r>-1){this.moov.boxes.splice(r,1)}this.moov.mvex=null}this.moov.mvex=new n.mvexBox;this.moov.boxes.push(this.moov.mvex);this.moov.mvex.mehd=new n.mehdBox;this.moov.mvex.boxes.push(this.moov.mvex.mehd);this.moov.mvex.mehd.fragment_duration=this.initial_duration;for(t=0;t<this.moov.traks.length;t++){if(this.moov.traks[t].ignore)continue;o=new n.trexBox;this.moov.mvex.boxes.push(o);o.track_id=this.moov.traks[t].tkhd.track_id;o.default_sample_description_index=1;o.default_sample_duration=this.moov.traks[t].samples.length>0?this.moov.traks[t].samples[0].duration:0;o.default_sample_size=0;o.default_sample_flags=1<<16}this.moov.write(e)};o.prototype.resetTables=function(){var e;var t,r,n,i,s,o,a,f;this.initial_duration=this.moov.mvhd.duration;this.moov.mvhd.duration=0;for(e=0;e<this.moov.traks.length;e++){t=this.moov.traks[e];t.tkhd.duration=0;t.mdia.mdhd.duration=0;r=t.mdia.minf.stbl.stco||t.mdia.minf.stbl.co64;r.chunk_offsets=[];n=t.mdia.minf.stbl.stsc;n.first_chunk=[];n.samples_per_chunk=[];n.sample_description_index=[];i=t.mdia.minf.stbl.stsz;i.sample_sizes=[];s=t.mdia.minf.stbl.stts;s.sample_counts=[];s.sample_deltas=[];o=t.mdia.minf.stbl.ctts;if(o){o.sample_counts=[];o.sample_offsets=[]}a=t.mdia.minf.stbl.stss;if(a){a.sample_numbers=new Uint32Array(0)}f=t.mdia.minf.stbl.sdtp;var u=t.mdia.minf.stbl.boxes.indexOf(f);if(u!=-1)t.mdia.minf.stbl.boxes[u]=null}};o.prototype.buildSampleLists=function(){var e,t,r;var n,i,s,o,a,f,u,h,l;var c,d,p,m,g;var v,y,_,b,w,x;this.originalMvex=this.moov.mvex;for(e=0;e<this.moov.traks.length;e++){n=this.moov.traks[e];n.samples=[];i=n.mdia.minf.stbl.stco||n.mdia.minf.stbl.co64;s=n.mdia.minf.stbl.stsc;o=n.mdia.minf.stbl.stsz;a=n.mdia.minf.stbl.stts;f=n.mdia.minf.stbl.ctts;u=n.mdia.minf.stbl.stss;h=n.mdia.minf.stbl.stsd;l=n.mdia.minf.stbl.subs;v=-1;y=-1;_=-1;b=-1;w=0;subs_entry_index=0;last_subs_sample_index=0;for(t=0;t<o.sample_sizes.length;t++){var S={};S.number=t;S.track_id=n.tkhd.track_id;S.timescale=n.mdia.mdhd.timescale;n.samples[t]=S;S.size=o.sample_sizes[t];if(t===0){d=1;c=0;S.chunk_index=d;S.chunk_run_index=c;g=s.samples_per_chunk[c];m=0;if(c+1<s.first_chunk.length){p=s.first_chunk[c+1]-1}else{p=Infinity}}else{if(t<g){S.chunk_index=d;S.chunk_run_index=c}else{d++;S.chunk_index=d;m=0;if(d<=p){}else{c++;if(c+1<s.first_chunk.length){p=s.first_chunk[c+1]-1}else{p=Infinity}}S.chunk_run_index=c;g+=s.samples_per_chunk[c]}}S.description=h.entries[s.sample_description_index[S.chunk_run_index]-1];S.offset=i.chunk_offsets[S.chunk_index-1]+m;m+=S.size;if(t>v){y++;if(v<0){v=0}v+=a.sample_counts[y]}if(t>0){n.samples[t-1].duration=a.sample_deltas[y];S.dts=n.samples[t-1].dts+n.samples[t-1].duration}else{S.dts=0}if(f){if(t>_){b++;_+=f.sample_counts[b]}S.cts=n.samples[t].dts+f.sample_offsets[b]}else{S.cts=S.dts}if(u){if(t==u.sample_numbers[w]-1){S.is_rap=true;w++}else{S.is_rap=false}}else{S.is_rap=true}if(l){if(l.samples[subs_entry_index].sample_delta+last_subs_sample_index==t){S.subsamples=l.samples[subs_entry_index].subsamples;last_subs_sample_index+=l.samples[subs_entry_index].sample_delta}}}if(t>0)n.samples[t-1].duration=n.mdia.mdhd.duration-n.samples[t-1].dts}};o.prototype.updateSampleLists=function(){var e,t,r;var i,s,o,a;var f;var u,h,l,c,d;var p;while(this.lastMoofIndex<this.moofs.length){u=this.moofs[this.lastMoofIndex];this.lastMoofIndex++;if(u.type=="moof"){h=u;for(e=0;e<h.trafs.length;e++){l=h.trafs[e];c=this.getTrackById(l.tfhd.track_id);d=this.getTrexById(l.tfhd.track_id);if(l.tfhd.flags&n.TFHD_FLAG_SAMPLE_DESC){i=l.tfhd.default_sample_description_index}else{i=d.default_sample_description_index}if(l.tfhd.flags&n.TFHD_FLAG_SAMPLE_DUR){s=l.tfhd.default_sample_duration}else{s=d.default_sample_duration}if(l.tfhd.flags&n.TFHD_FLAG_SAMPLE_SIZE){o=l.tfhd.default_sample_size}else{o=d.default_sample_size}if(l.tfhd.flags&n.TFHD_FLAG_SAMPLE_FLAGS){a=l.tfhd.default_sample_flags}else{a=d.default_sample_flags}for(t=0;t<l.truns.length;t++){var m=l.truns[t];for(r=0;r<m.sample_count;r++){p={};l.first_sample_index=c.samples.length;c.samples.push(p);p.track_id=c.tkhd.track_id;p.timescale=c.mdia.mdhd.timescale;p.description=c.mdia.minf.stbl.stsd.entries[i-1];p.size=o;if(m.flags&n.TRUN_FLAGS_SIZE){p.size=m.sample_size[r]}p.duration=s;if(m.flags&n.TRUN_FLAGS_DURATION){p.duration=m.sample_duration[r]}if(c.first_traf_merged||r>0){p.dts=c.samples[c.samples.length-2].dts+c.samples[c.samples.length-2].duration}else{if(l.tfdt){p.dts=l.tfdt.baseMediaDecodeTime}else{p.dts=0}c.first_traf_merged=true}p.cts=p.dts;if(m.flags&n.TRUN_FLAGS_CTS_OFFSET){p.cts=p.dts+m.sample_composition_time_offset[r]}sample_flags=a;if(m.flags&n.TRUN_FLAGS_FLAGS){sample_flags=m.sample_flags[r]}else if(r===0&&m.flags&n.TRUN_FLAGS_FIRST_FLAG){sample_flags=m.first_sample_flags}p.is_rap=sample_flags>>16&1?false:true;var g=l.tfhd.flags&n.TFHD_FLAG_BASE_DATA_OFFSET?true:false;var v=l.tfhd.flags&n.TFHD_FLAG_DEFAULT_BASE_IS_MOOF?true:false;var y=m.flags&n.TRUN_FLAGS_DATA_OFFSET?true:false;var _=0;if(!g){if(!v){if(t===0){_=h.fileStart}else{_=f}}else{_=h.fileStart}}else{_=l.tfhd.base_data_offset}if(t===0&&r===0){if(y){p.offset=_+m.data_offset}else{p.offset=_}}else{p.offset=f}f=p.offset+p.size}}if(l.subs){var b=l.first_sample_index;for(t=0;t<l.subs.samples.length;t++){b+=l.subs.samples[t].sample_delta;p=c.samples[b-1];p.subsamples=l.subs.samples[t].subsamples}}}}}};o.prototype.getCodecs=function(){var e;var t="";for(e=0;e<this.moov.traks.length;e++){var r=this.moov.traks[e];if(e>0){t+=","}t+=r.mdia.minf.stbl.stsd.entries[0].getCodec()}return t};o.prototype.getTrexById=function(e){var t;if(!this.originalMvex)return null;for(t=0;t<this.originalMvex.trexs.length;t++){var r=this.originalMvex.trexs[t];if(r.track_id==e)return r}return null};o.prototype.getTrackById=function(e){for(var t=0;t<this.moov.traks.length;t++){var r=this.moov.traks[t];if(r.tkhd.track_id==e)return r}return null};o.prototype.getSample=function(e,t){var r;var n;var o=e.samples[t];if(!this.moov){return null}if(!o.data){o.data=new Uint8Array(o.size);o.alreadyRead=0;this.samplesDataSize+=o.size;s.d("ISOFile","Allocating sample #"+t+" on track #"+e.tkhd.track_id+" of size "+o.size+" (total: "+this.samplesDataSize+")")}else if(o.alreadyRead==o.size){return o}for(n=0;n<this.stream.nextBuffers.length;n++){r=this.stream.nextBuffers[n];if(o.offset+o.alreadyRead>=r.fileStart&&o.offset+o.alreadyRead<r.fileStart+r.byteLength){var a=r.byteLength-(o.offset+o.alreadyRead-r.fileStart);if(o.size-o.alreadyRead<=a){s.d("ISOFile","Getting sample #"+t+" data (alreadyRead: "+o.alreadyRead+" offset: "+(o.offset+o.alreadyRead-r.fileStart)+" size: "+(o.size-o.alreadyRead)+")");i.memcpy(o.data.buffer,o.alreadyRead,r,o.offset+o.alreadyRead-r.fileStart,o.size-o.alreadyRead);o.alreadyRead=o.size;r.usedBytes+=o.size-o.alreadyRead;if(r.usedBytes===r.byteLength){this.stream.nextBuffers.splice(n,1);n--}return o}else{s.d("ISOFile","Getting sample data (alreadyRead: "+o.alreadyRead+" offset: "+(o.offset+o.alreadyRead-r.fileStart)+" size: "+a+")");i.memcpy(o.data.buffer,o.alreadyRead,r,o.offset+o.alreadyRead-r.fileStart,a);o.alreadyRead+=a;r.usedBytes+=a;if(r.usedBytes===r.byteLength){this.stream.nextBuffers.splice(n,1);n--}}}}return null};o.prototype.releaseSample=function(e,t){var r=e.samples[t];r.data=null;this.samplesDataSize-=r.size;return r.size}},{"./DataStream":163,"./box":164,"./log":167}],167:[function(e,t,r){var n=function(){var e=new Date;var t=4;var r=3;var i=2;var s=1;var o=t;var a={setLogLevel:function(e){if(e==this.d)o=s;else if(e==this.i)o=i;else if(e==this.w)o=r;else if(e==this.e)o=t;else o=t},d:function(t,r){if(s>=o){console.debug("["+n.getDurationString(new Date-e,1e3)+"]","["+t+"]",r)}},i:function(t,r){if(i>=o){console.info("["+n.getDurationString(new Date-e,1e3)+"]","["+t+"]",r)}},w:function(t,i){if(r>=o){console.warn("["+n.getDurationString(new Date-e,1e3)+"]","["+t+"]",i)}},e:function(r,i){if(t>=o){console.error("["+n.getDurationString(new Date-e,1e3)+"]","["+r+"]",i)}}};return a}();t.exports=n;n.getDurationString=function(e,t){function r(e,t){var r=""+e;var n=r.split(".");while(n[0].length<t){n[0]="0"+n[0]}return n.join(".")}var n=t||1;var i=e/n;var s=Math.floor(i/3600);i-=s*3600;var o=Math.floor(i/60);i-=o*60;var a=i*1e3;i=Math.floor(i);a-=i*1e3;a=Math.floor(a);return""+s+":"+r(o,2)+":"+r(i,2)+"."+r(a,3)};n.printRanges=function(e){var t=e.length;if(t>0){var r="";for(var i=0;i<t;i++){if(i>0)r+=",";r+="["+n.getDurationString(e.start(i))+","+n.getDurationString(e.end(i))+"]"}return r}else{return"(empty)"}}},{}],168:[function(e,t,r){var n=e("./box");var s=e("./DataStream");var o=e("./isofile");var a=e("./log");var f=function(){this.inputStream=null;this.nextBuffers=[];this.inputIsoFile=null;this.onMoovStart=null;this.moovStartSent=false;this.onReady=null;this.readySent=false;this.onSegment=null;this.onSamples=null;this.onError=null;this.sampleListBuilt=false;this.fragmentedTracks=[];this.extractedTracks=[];this.isFragmentationStarted=false;this.nextMoofNumber=0};t.exports=f;f.prototype.setSegmentOptions=function(e,t,r){var n=this.inputIsoFile.getTrackById(e);if(n){var i={};this.fragmentedTracks.push(i);i.id=e;i.user=t;i.trak=n;n.nextSample=0;i.segmentStream=null;i.nb_samples=1e3;i.rapAlignement=true;if(r){if(r.nbSamples)i.nb_samples=r.nbSamples;if(r.rapAlignement)i.rapAlignement=r.rapAlignement}}};f.prototype.unsetSegmentOptions=function(e){var t=-1;for(var r=0;r<this.fragmentedTracks.length;r++){var n=this.fragmentedTracks[r];if(n.id==e){t=r}}if(t>-1){this.fragmentedTracks.splice(t,1)}};f.prototype.setExtractionOptions=function(e,t,r){var n=this.inputIsoFile.getTrackById(e);if(n){var i={};this.extractedTracks.push(i);i.id=e;i.user=t;i.trak=n;n.nextSample=0;i.nb_samples=1e3;i.samples=[];if(r){if(r.nbSamples)i.nb_samples=r.nbSamples}}};f.prototype.unsetExtractionOptions=function(e){var t=-1;for(var r=0;r<this.extractedTracks.length;r++){var n=this.extractedTracks[r];if(n.id==e){t=r}}if(t>-1){this.extractedTracks.splice(t,1)}};f.prototype.createSingleSampleMoof=function(e){var t=new n.moofBox;var r=new n.mfhdBox;r.sequence_number=this.nextMoofNumber;this.nextMoofNumber++;t.boxes.push(r);var i=new n.trafBox;t.boxes.push(i);var s=new n.tfhdBox;i.boxes.push(s);s.track_id=e.track_id;s.flags=n.TFHD_FLAG_DEFAULT_BASE_IS_MOOF;var o=new n.tfdtBox;i.boxes.push(o);o.baseMediaDecodeTime=e.dts;var a=new n.trunBox;i.boxes.push(a);t.trun=a;a.flags=n.TRUN_FLAGS_DATA_OFFSET|n.TRUN_FLAGS_DURATION|n.TRUN_FLAGS_SIZE|n.TRUN_FLAGS_FLAGS|n.TRUN_FLAGS_CTS_OFFSET;a.data_offset=0;a.first_sample_flags=0;a.sample_count=1;a.sample_duration=[];a.sample_duration[0]=e.duration;a.sample_size=[];a.sample_size[0]=e.size;a.sample_flags=[];a.sample_flags[0]=0;a.sample_composition_time_offset=[];a.sample_composition_time_offset[0]=e.cts-e.dts;return t};f.prototype.createFragment=function(e,t,r,i){var o=this.inputIsoFile.getTrackById(t);var f=this.inputIsoFile.getSample(o,r);if(f==null){if(this.nextSeekPosition){this.nextSeekPosition=Math.min(o.samples[r].offset,this.nextSeekPosition)}else{this.nextSeekPosition=o.samples[r].offset}return null}var u=i||new s;u.endianness=s.BIG_ENDIAN;var h=this.createSingleSampleMoof(f);h.write(u);h.trun.data_offset=h.size+8;a.d("BoxWriter","Adjusting data_offset with new value "+h.trun.data_offset);u.adjustUint32(h.trun.data_offset_position,h.trun.data_offset);var l=new n.mdatBox;l.data=f.data;l.write(u);return u};ArrayBuffer.concat=function(e,t){a.d("ArrayBuffer","Trying to create a new buffer of size: "+(e.byteLength+t.byteLength));var r=new Uint8Array(e.byteLength+t.byteLength);r.set(new Uint8Array(e),0);r.set(new Uint8Array(t),e.byteLength);return r.buffer};f.prototype.reduceBuffer=function(e,t,r){var n;n=new Uint8Array(r);n.set(new Uint8Array(e,t,r));n.buffer.fileStart=e.fileStart+t;n.buffer.usedBytes=0;return n.buffer};f.prototype.insertBuffer=function(e){var t=true;for(var r=0;r<this.nextBuffers.length;r++){var n=this.nextBuffers[r];if(e.fileStart<=n.fileStart){if(e.fileStart===n.fileStart){if(e.byteLength>n.byteLength){this.nextBuffers.splice(r,1);r--;continue}else{a.w("MP4Box","Buffer (fileStart: "+e.fileStart+" - Length: "+e.byteLength+") already appended, ignoring")}}else{if(e.fileStart+e.byteLength<=n.fileStart){}else{e=this.reduceBuffer(e,0,n.fileStart-e.fileStart)}a.d("MP4Box","Appending new buffer (fileStart: "+e.fileStart+" - Length: "+e.byteLength+")");this.nextBuffers.splice(r,0,e);if(r===0&&this.inputStream!==null){this.inputStream.buffer=e}}t=false;break}else if(e.fileStart<n.fileStart+n.byteLength){var i=n.fileStart+n.byteLength-e.fileStart;var s=e.byteLength-i;if(s>0){e=this.reduceBuffer(e,i,s)}else{t=false;break}}}if(t){a.d("MP4Box","Appending new buffer (fileStart: "+e.fileStart+" - Length: "+e.byteLength+")");this.nextBuffers.push(e);if(r===0&&this.inputStream!==null){this.inputStream.buffer=e}}};f.prototype.processSamples=function(){var e;var t;if(this.isFragmentationStarted&&this.onSegment!==null){for(e=0;e<this.fragmentedTracks.length;e++){var r=this.fragmentedTracks[e];t=r.trak;while(t.nextSample<t.samples.length){a.d("MP4Box","Creating media fragment on track #"+r.id+" for sample "+t.nextSample);var n=this.createFragment(this.inputIsoFile,r.id,t.nextSample,r.segmentStream);if(n){r.segmentStream=n;t.nextSample++}else{break}if(t.nextSample%r.nb_samples===0||t.nextSample>=t.samples.length){a.i("MP4Box","Sending fragmented data on track #"+r.id+" for samples ["+(t.nextSample-r.nb_samples)+","+(t.nextSample-1)+"]");if(this.onSegment){this.onSegment(r.id,r.user,r.segmentStream.buffer,t.nextSample)}r.segmentStream=null;if(r!==this.fragmentedTracks[e]){break}}}}}if(this.onSamples!==null){for(e=0;e<this.extractedTracks.length;e++){var i=this.extractedTracks[e];t=i.trak;while(t.nextSample<t.samples.length){a.d("MP4Box","Exporting on track #"+i.id+" sample #"+t.nextSample);var s=this.inputIsoFile.getSample(t,t.nextSample);if(s){t.nextSample++;i.samples.push(s)}else{return}if(t.nextSample%i.nb_samples===0||t.nextSample>=t.samples.length){a.d("MP4Box","Sending samples on track #"+i.id+" for sample "+t.nextSample);if(this.onSamples){this.onSamples(i.id,i.user,i.samples)}i.samples=[];if(i!==this.extractedTracks[e]){break}}}}}};f.prototype.appendBuffer=function(e){var t;var r;if(e===null||e===undefined){
-throw"Buffer must be defined and non empty"}if(e.fileStart===undefined){throw"Buffer must have a fileStart property"}if(e.byteLength===0){a.w("MP4Box","Ignoring empty buffer (fileStart: "+e.fileStart+")");return}e.usedBytes=0;this.insertBuffer(e);if(!this.inputStream){if(this.nextBuffers.length>0){r=this.nextBuffers[0];if(r.fileStart===0){this.inputStream=new s(r,0,s.BIG_ENDIAN);this.inputStream.nextBuffers=this.nextBuffers;this.inputStream.bufferIndex=0}else{a.w("MP4Box","The first buffer should have a fileStart of 0");return}}else{a.w("MP4Box","No buffer to start parsing from");return}}if(!this.inputIsoFile){this.inputIsoFile=new o(this.inputStream)}this.inputIsoFile.parse();if(this.inputIsoFile.moovStartFound&&!this.moovStartSent){this.moovStartSent=true;if(this.onMoovStart)this.onMoovStart()}if(this.inputIsoFile.moov){if(!this.sampleListBuilt){this.inputIsoFile.buildSampleLists();this.sampleListBuilt=true}this.inputIsoFile.updateSampleLists();if(this.onReady&&!this.readySent){var n=this.getInfo();this.readySent=true;this.onReady(n)}this.processSamples();if(this.nextSeekPosition){t=this.nextSeekPosition;this.nextSeekPosition=undefined}else{t=this.inputIsoFile.nextParsePosition}var i=this.inputIsoFile.findPosition(true,t);if(i!==-1){t=this.inputIsoFile.findEndContiguousBuf(i)}a.i("MP4Box","Next buffer to fetch should have a fileStart position of "+t);return t}else{if(this.inputIsoFile!==null){return this.inputIsoFile.nextParsePosition}else{return 0}}};f.prototype.getInfo=function(){var e={};var t;var r;var n;var s=new Date(4,0,1,0,0,0,0).getTime();e.duration=this.inputIsoFile.moov.mvhd.duration;e.timescale=this.inputIsoFile.moov.mvhd.timescale;e.isFragmented=this.inputIsoFile.moov.mvex!=null;if(e.isFragmented&&this.inputIsoFile.moov.mvex.mehd){e.fragment_duration=this.inputIsoFile.moov.mvex.mehd.fragment_duration}else{e.fragment_duration=0}e.isProgressive=this.inputIsoFile.isProgressive;e.hasIOD=this.inputIsoFile.moov.iods!=null;e.brands=[];e.brands.push(this.inputIsoFile.ftyp.major_brand);e.brands=e.brands.concat(this.inputIsoFile.ftyp.compatible_brands);e.created=new Date(s+this.inputIsoFile.moov.mvhd.creation_time*1e3);e.modified=new Date(s+this.inputIsoFile.moov.mvhd.modification_time*1e3);e.tracks=[];e.audioTracks=[];e.videoTracks=[];e.subtitleTracks=[];e.metadataTracks=[];e.hintTracks=[];e.otherTracks=[];for(i=0;i<this.inputIsoFile.moov.traks.length;i++){t=this.inputIsoFile.moov.traks[i];n=t.mdia.minf.stbl.stsd.entries[0];r={};e.tracks.push(r);r.id=t.tkhd.track_id;r.references=[];if(t.tref){for(j=0;j<t.tref.boxes.length;j++){ref={};r.references.push(ref);ref.type=t.tref.boxes[j].type;ref.track_ids=t.tref.boxes[j].track_ids}}r.created=new Date(s+t.tkhd.creation_time*1e3);r.modified=new Date(s+t.tkhd.modification_time*1e3);r.movie_duration=t.tkhd.duration;r.layer=t.tkhd.layer;r.alternate_group=t.tkhd.alternate_group;r.volume=t.tkhd.volume;r.matrix=t.tkhd.matrix;r.track_width=t.tkhd.width/(1<<16);r.track_height=t.tkhd.height/(1<<16);r.timescale=t.mdia.mdhd.timescale;r.duration=t.mdia.mdhd.duration;r.codec=n.getCodec();r.language=t.mdia.mdhd.languageString;r.nb_samples=t.samples.length;r.size=0;for(j=0;j<r.nb_samples;j++){r.size+=t.samples[j].size}r.bitrate=r.size*8*r.timescale/r.duration;if(n.isAudio()){e.audioTracks.push(r);r.audio={};r.audio.sample_rate=n.getSampleRate();r.audio.channel_count=n.getChannelCount();r.audio.sample_size=n.getSampleSize()}else if(n.isVideo()){e.videoTracks.push(r);r.video={};r.video.width=n.getWidth();r.video.height=n.getHeight()}else if(n.isSubtitle()){e.subtitleTracks.push(r)}else if(n.isHint()){e.hintTracks.push(r)}else if(n.isMetadata()){e.metadataTracks.push(r)}else{e.otherTracks.push(r)}}return e};f.prototype.getInitializationSegment=function(){var e=new s;e.endianness=s.BIG_ENDIAN;this.inputIsoFile.writeInitializationSegment(e);return e.buffer};f.prototype.writeFile=function(){var e=new s;e.endianness=s.BIG_ENDIAN;this.inputIsoFile.write(e);return e.buffer};f.prototype.initializeSegmentation=function(){var e;var t;var r;var n;var i;if(this.onSegment===null){a.w("MP4Box","No segmentation callback set!")}if(!this.isFragmentationStarted){this.isFragmentationStarted=true;this.nextMoofNumber=0;this.inputIsoFile.resetTables()}n=[];for(e=0;e<this.fragmentedTracks.length;e++){for(t=0;t<this.inputIsoFile.moov.boxes.length;t++){r=this.inputIsoFile.moov.boxes[t];if(r&&r.type==="trak"){this.inputIsoFile.moov.boxes[t].ignore=true;this.inputIsoFile.moov.boxes[t]=null}}i=this.inputIsoFile.getTrackById(this.fragmentedTracks[e].id);delete i.ignore;for(t=0;t<this.inputIsoFile.moov.boxes.length;t++){r=this.inputIsoFile.moov.boxes[t];if(r==null){this.inputIsoFile.moov.boxes[t]=i;break}}seg={};seg.id=i.tkhd.track_id;seg.user=this.fragmentedTracks[e].user;seg.buffer=this.getInitializationSegment();n.push(seg)}return n};f.prototype.releaseUsedSamples=function(e,t){var r=0;var n=this.inputIsoFile.getTrackById(e);if(!n.lastValidSample)n.lastValidSample=0;for(var i=n.lastValidSample;i<t;i++){r+=this.inputIsoFile.releaseSample(n,i)}a.d("MP4Box","Track #"+e+" released samples up to "+t+" (total size: "+r+", remaining: "+this.inputIsoFile.samplesDataSize+")");n.lastValidSample=t};f.prototype.flush=function(){a.i("MP4Box","Flushing remaining samples");this.inputIsoFile.updateSampleLists();this.processSamples()};f.prototype.seekTrack=function(e,t,r){var n;var i;var s=Infinity;var o=0;var f=Infinity;var u=0;var h=0;var l;for(n=0;n<r.samples.length;n++){i=r.samples[n];if(n===0){f=i.offset;h=0;l=i.timescale}else if(i.cts>e*i.timescale){f=r.samples[n-1].offset;h=n-1;break}if(t&&i.is_rap){s=i.offset;o=i.cts;u=n}}if(t){r.nextSample=u;a.i("MP4Box","Seeking to RAP sample #"+r.nextSample+" on track "+r.tkhd.track_id+", time "+a.getDurationString(o,l)+" and offset: "+s);return{offset:s,time:o/l}}else{r.nextSample=h;a.i("MP4Box","Seeking to non-RAP sample #"+r.nextSample+" on track "+r.tkhd.track_id+", time "+a.getDurationString(e)+" and offset: "+s);return{offset:f,time:e}}};f.prototype.seek=function(e,t){var r=this.inputIsoFile.moov;var n;var i;var s;var o={offset:Infinity,time:Infinity};if(!this.inputIsoFile.moov){throw"Cannot seek: moov not received!"}else{for(s=0;s<r.traks.length;s++){n=r.traks[s];i=this.seekTrack(e,t,n);if(i.offset<o.offset){o.offset=i.offset}if(i.time<o.time){o.time=i.time}}if(o.offset===Infinity){o={offset:this.inputIsoFile.nextParsePosition,time:0}}else{var f=this.inputIsoFile.findPosition(true,o.offset);if(f!==-1){o.offset=this.inputIsoFile.findEndContiguousBuf(f)}}a.i("MP4Box","Seeking at time "+a.getDurationString(o.time,1)+" needs a buffer with a fileStart position of "+o.offset);return o}}},{"./DataStream":163,"./box":164,"./isofile":166,"./log":167}],169:[function(e,t,r){(function(r){var n=e("debug")("videostream");var i=e("videostream-mp4box");var s=.01;var o=60;t.exports=function(e,t,f){f=f||{};var u=f.debugTrack||-1;var h=[];function l(){t.addEventListener("waiting",S);t.addEventListener("timeupdate",A)}l();var c=false;function d(e){c=true;t.removeEventListener("waiting",S);t.removeEventListener("timeupdate",A);if(m.readyState==="open")m.endOfStream(e)}function p(e){var r=e.buffer.buffered;var i=t.currentTime;var a=-1;for(var f=0;f<r.length;f++){var u=r.start(f);var h=r.end(f)+s;if(u>i){break}else if(a>=0||i<=h){a=h}}var l=a-i;if(l<0)l=0;n("Buffer length: %f",l);return l<=o}var m=new MediaSource;m.addEventListener("sourceopen",function(){x(0)});t.src=window.URL.createObjectURL(m);var g=new i;g.onError=function(e){n("MP4Box error: %s",e.message);if(w){w()}if(m.readyState==="open"){d("decode")}};var v=false;var y={};g.onReady=function(e){n("MP4 info: %o",e);e.tracks.forEach(function(e){var t;if(e.video){t="video/mp4"}else if(e.audio){t="audio/mp4"}else{return}t+='; codecs="'+e.codec+'"';if(MediaSource.isTypeSupported(t)){var r=m.addSourceBuffer(t);var n={buffer:r,arrayBuffers:[],meta:e,ended:false};r.addEventListener("updateend",U.bind(null,n));g.setSegmentOptions(e.id,null,{nbSamples:e.video?1:100});y[e.id]=n}});if(Object.keys(y).length===0){d("decode");return}var t=g.initializeSegmentation();t.forEach(function(e){E(y[e.id],e.buffer);if(e.id===u){a("init-track-"+u+".mp4",[e.buffer]);h.push(e.buffer)}});v=true};g.onSegment=function(e,t,r,n){var i=y[e];E(i,r,n===i.meta.nb_samples);if(e===u&&h){h.push(r);if(n>1e3){a("track-"+u+".mp4",h);h=null}}};var _;var b=null;var w=null;function x(t){if(t===e.length){g.flush();return}if(b&&t===_){var i=b;setTimeout(function(){if(b===i)b.resume()});return}if(b){b.destroy();w()}_=t;var s={start:_,end:e.length-1};b=e.createReadStream(s);function o(e){b.pause();var t=new r(e).buffer;t.fileStart=_;_+=t.byteLength;var i;try{i=g.appendBuffer(t)}catch(s){n("MP4Box threw exception: %s",s.message);if(m.readyState==="open"){d("decode")}b.destroy();w();return}x(i)}b.on("data",o);function a(){w();x(_)}b.on("end",a);function f(e){n("Stream error: %s",e.message);if(m.readyState==="open"){d("network")}}b.on("error",f);w=function(){b.removeListener("data",o);b.removeListener("end",a);b.removeListener("error",f);b=null;w=null}}function S(){if(v){k(t.currentTime)}}function k(e){if(c)l();var t=g.seek(e,true);n("Seeking to time: %d",e);n("Seeked file offset: %d",t.offset);x(t.offset)}function E(e,t,r){e.arrayBuffers.push({buffer:t,ended:r||false});U(e)}function A(){Object.keys(y).forEach(function(e){var t=y[e];if(t.blocked){U(t)}})}function U(e){if(e.buffer.updating)return;e.blocked=!p(e);if(e.blocked)return;if(e.arrayBuffers.length===0)return;var t=e.arrayBuffers.shift();var r=false;try{e.buffer.appendBuffer(t.buffer);e.ended=t.ended;r=true}catch(i){n("SourceBuffer error: %s",i.message);d("decode");return}if(r){I()}}function I(){if(m.readyState!=="open"){return}var e=Object.keys(y).every(function(e){var t=y[e];return t.ended&&!t.buffer.updating});if(e){d()}}};function a(e,t){var r=new Blob(t);var n=URL.createObjectURL(r);var i=document.createElement("a");i.setAttribute("href",n);i.setAttribute("download",e);i.click()}}).call(this,e("buffer").Buffer)},{buffer:25,debug:107,"videostream-mp4box":168}],170:[function(e,t,r){t.exports=i;var n=Object.prototype.hasOwnProperty;function i(){var e={};for(var t=0;t<arguments.length;t++){var r=arguments[t];for(var i in r){if(n.call(r,i)){e[i]=r[i]}}}return e}},{}],171:[function(e,t,r){t.exports=i;var n=Object.prototype.hasOwnProperty;function i(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r){if(n.call(r,i)){e[i]=r[i]}}}return e}},{}],172:[function(e,t,r){t.exports=function n(e,t,r){if(t===undefined){return function(t,r){return n(e,t,r)}}if(r===undefined)r="0";e-=t.toString().length;if(e>0)return new Array(e+(/\./.test(t)?2:1)).join(r)+t;return t+""}},{}],173:[function(e,t,r){t.exports={name:"webtorrent",description:"Streaming torrent client",version:"0.71.2",author:{name:"Feross Aboukhadijeh",email:"feross@feross.org",url:"http://feross.org/"},bin:{webtorrent:"./bin/cmd.js"},browser:{"./lib/server.js":false,"bittorrent-dht/client":false,"fs-chunk-store":"memory-chunk-store","load-ip-set":false,os:false,"path-exists":false,ut_pex:false},bugs:{url:"https://github.com/feross/webtorrent/issues"},dependencies:{"addr-to-ip-port":"^1.0.1",bitfield:"^1.0.2","bittorrent-dht":"^6.0.1","bittorrent-swarm":"^6.0.0","chunk-store-stream":"^2.0.0",clivas:"^0.2.0","create-torrent":"^3.4.0","cross-spawn-async":"^2.0.0",debug:"^2.1.0","end-of-stream":"^1.0.0",executable:"^3.0.0","fs-chunk-store":"^1.3.4",hat:"0.0.3","immediate-chunk-store":"^1.0.7",inherits:"^2.0.1",inquirer:"^0.11.0","load-ip-set":"^1.0.3",mediasource:"^1.0.0","memory-chunk-store":"^1.2.0",mime:"^1.2.11",minimist:"^1.1.0",moment:"^2.8.3",multistream:"^2.0.2","network-address":"^1.0.0","parse-torrent":"^5.1.0","path-exists":"^2.1.0","pretty-bytes":"^3.0.0",pump:"^1.0.0","random-iterate":"^1.0.1","range-parser":"^1.0.2","re-emitter":"^1.0.0","render-media":"^2.0.0","run-parallel":"^1.0.0","simple-peer":"^5.11.6","simple-sha1":"^2.0.0",speedometer:"^1.0.0","stream-to-blob-url":"^1.0.0","stream-with-known-length-to-buffer":"^1.0.0",thunky:"^0.1.0","torrent-discovery":"^5.1.0","torrent-piece":"^1.0.0",uniq:"^1.0.1",ut_metadata:"^3.0.1",ut_pex:"^1.0.1",videostream:"^1.1.4","windows-no-runnable":"0.0.6",xtend:"^4.0.0","zero-fill":"^2.2.0"},devDependencies:{"bittorrent-tracker":"^7.0.0",brfs:"^1.2.0",browserify:"^12.0.1",finalhandler:"^0.4.0","run-series":"^1.0.2","serve-static":"^1.9.3","simple-get":"^1.0.0",standard:"^5.1.0",tape:"^4.0.0","uglify-js":"^2.4.15",zuul:"^3.0.0"},homepage:"https://webtorrent.io",keywords:["bittorrent","bittorrent client","download","mad science","streaming","torrent","webrtc","webrtc data","webtorrent"],license:"MIT",main:"index.js",optionalDependencies:{"airplay-js":"^0.2.3",chromecasts:"^1.5.3",nodebmc:"0.0.5"},repository:{type:"git",url:"git://github.com/feross/webtorrent.git"},scripts:{build:"browserify -s WebTorrent -e ./ | uglifyjs -m > webtorrent.min.js","build-debug":"browserify -s WebTorrent -e ./ > webtorrent.debug.js",size:"npm run build && cat webtorrent.min.js | gzip | wc -c",test:"standard && node ./bin/test.js","test-browser":"zuul -- test/*.js test/browser/*.js","test-browser-local":"zuul --local -- test/*.js test/browser/*.js","test-node":"tape test/*.js test/node/*.js"}}},{}],174:[function(e,t,r){(function(r,n,i){t.exports=S;var s=e("create-torrent");var o=e("debug")("webtorrent");var a=e("bittorrent-dht/client");var f=e("events").EventEmitter;var u=e("xtend");var h=e("hat");var l=e("inherits");var c=e("load-ip-set");var d=e("run-parallel");var p=e("parse-torrent");var m=e("path");var g=e("simple-peer");var v=e("speedometer");var y=e("zero-fill");var _=e("./lib/torrent");t.exports.WEBRTC_SUPPORT=g.WEBRTC_SUPPORT;var b=e("./package.json").version;var w=b.match(/([0-9]+)/g).slice(0,2).map(y(2)).join("");var x="-WW"+w+"-";l(S,f);function S(e){var t=this;if(!(t instanceof S))return new S(e);f.call(t);if(!e)e={};if(!o.enabled)t.setMaxListeners(0);t.destroyed=false;t.torrentPort=e.torrentPort||0;t.tracker=e.tracker!==undefined?e.tracker:true;t._rtcConfig=e.rtcConfig;t._wrtc=e.wrtc||n.WRTC;t.torrents=[];t.downloadSpeed=v();t.uploadSpeed=v();t.maxConns=e.maxConns;t.peerId=typeof e.peerId==="string"?e.peerId:(e.peerId||new i(x+h(48))).toString("hex");t.peerIdBuffer=new i(t.peerId,"hex");t.nodeId=typeof e.nodeId==="string"?e.nodeId:e.nodeId&&e.nodeId.toString("hex")||h(160);t.nodeIdBuffer=new i(t.nodeId,"hex");if(e.dht!==false&&typeof a==="function"){t.dht=new a(u({nodeId:t.nodeId},e.dht));t.dht.listen(e.dhtPort)}o("new webtorrent (peerId %s, nodeId %s)",t.peerId,t.nodeId);if(typeof c==="function"){c(e.blocklist,{headers:{"user-agent":"WebTorrent/"+b+" (http://webtorrent.io)"}},function(e,r){if(e)return t.error("Failed to load blocklist: "+e.message);t.blocked=r;s()})}else r.nextTick(s);function s(){if(t.destroyed)return;t.ready=true;t.emit("ready")}}Object.defineProperty(S.prototype,"ratio",{get:function(){var e=this;var t=e.torrents.reduce(function(e,t){return e+t.uploaded},0);var r=e.torrents.reduce(function(e,t){return e+t.downloaded},0)||1;return t/r}});S.prototype.get=function(e){var t=this;if(e instanceof _)return e;var r;try{r=p(e)}catch(n){}if(!r)return null;if(!r.infoHash)throw new Error("Invalid torrent identifier");for(var i=0,s=t.torrents.length;i<s;i++){var o=t.torrents[i];if(o.infoHash===r.infoHash)return o}return null};S.prototype.add=S.prototype.download=function(e,t,n){var i=this;if(i.destroyed)throw new Error("client is destroyed");if(typeof t==="function")return i.add(e,null,t);o("add");if(!t)t={};else t=u(t);t.client=i;var s=i.get(e);function a(){if(typeof n==="function")n(s)}if(s){if(s.ready)r.nextTick(a);else s.on("ready",a)}else{s=new _(e,t);i.torrents.push(s);s.on("error",function(e){i.emit("error",e,s);i.remove(s)});s.on("listening",function(e){i.emit("listening",e,s)});s.on("ready",function(){a();i.emit("torrent",s)})}return s};S.prototype.seed=function(e,t,r){var n=this;if(n.destroyed)throw new Error("client is destroyed");if(typeof t==="function")return n.seed(e,null,t);o("seed");if(!t)t={};else t=u(t);if(typeof e==="string")t.path=m.dirname(e);if(!t.createdBy)t.createdBy="WebTorrent/"+w;if(!n.tracker)t.announce=[];var i;var a=n.add(undefined,t,function(e){var t=[function(t){e.load(i,t)}];if(n.dht){t.push(function(t){e.on("dhtAnnounce",t)})}d(t,function(t){if(t)return n.emit("error",t);f();n.emit("seed",e)})});s.parseInput(e,t,function(r,o){if(r)return n.emit("error",r);i=o.map(function(e){return e.getStream});s(e,t,function(e,t){if(e)return n.emit("error",e);if(n.destroyed)return;var r=n.get(t);if(r){a.destroy();f();return}else{a._onTorrentId(t)}})});function f(){o("on seed");if(typeof r==="function")r(a)}return a};S.prototype.remove=function(e,t){var r=this;o("remove");var n=r.get(e);if(!n)throw new Error("No torrent with id "+e);r.torrents.splice(r.torrents.indexOf(n),1);n.destroy(t)};S.prototype.address=function(){var e=this;return{address:"0.0.0.0",family:"IPv4",port:e.torrentPort}};S.prototype.destroy=function(e){var t=this;if(t.destroyed)throw new Error("client already destroyed");t.destroyed=true;o("destroy");var r=t.torrents.map(function(e){return function(r){t.remove(e,r)}});if(t.dht)r.push(function(e){t.dht.destroy(e)});d(r,e)}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{},e("buffer").Buffer)},{"./lib/torrent":4,"./package.json":173,_process:34,"bittorrent-dht/client":24,buffer:25,"create-torrent":75,debug:107,events:29,hat:113,inherits:115,"load-ip-set":24,"parse-torrent":119,path:33,"run-parallel":138,"simple-peer":142,speedometer:150,xtend:170,"zero-fill":172}]},{},[174])(174)});
+throw"Buffer must be defined and non empty"}if(e.fileStart===undefined){throw"Buffer must have a fileStart property"}if(e.byteLength===0){a.w("MP4Box","Ignoring empty buffer (fileStart: "+e.fileStart+")");return}e.usedBytes=0;this.insertBuffer(e);if(!this.inputStream){if(this.nextBuffers.length>0){r=this.nextBuffers[0];if(r.fileStart===0){this.inputStream=new s(r,0,s.BIG_ENDIAN);this.inputStream.nextBuffers=this.nextBuffers;this.inputStream.bufferIndex=0}else{a.w("MP4Box","The first buffer should have a fileStart of 0");return}}else{a.w("MP4Box","No buffer to start parsing from");return}}if(!this.inputIsoFile){this.inputIsoFile=new o(this.inputStream)}this.inputIsoFile.parse();if(this.inputIsoFile.moovStartFound&&!this.moovStartSent){this.moovStartSent=true;if(this.onMoovStart)this.onMoovStart()}if(this.inputIsoFile.moov){if(!this.sampleListBuilt){this.inputIsoFile.buildSampleLists();this.sampleListBuilt=true}this.inputIsoFile.updateSampleLists();if(this.onReady&&!this.readySent){var n=this.getInfo();this.readySent=true;this.onReady(n)}this.processSamples();if(this.nextSeekPosition){t=this.nextSeekPosition;this.nextSeekPosition=undefined}else{t=this.inputIsoFile.nextParsePosition}var i=this.inputIsoFile.findPosition(true,t);if(i!==-1){t=this.inputIsoFile.findEndContiguousBuf(i)}a.i("MP4Box","Next buffer to fetch should have a fileStart position of "+t);return t}else{if(this.inputIsoFile!==null){return this.inputIsoFile.nextParsePosition}else{return 0}}};f.prototype.getInfo=function(){var e={};var t;var r;var n;var s=new Date(4,0,1,0,0,0,0).getTime();e.duration=this.inputIsoFile.moov.mvhd.duration;e.timescale=this.inputIsoFile.moov.mvhd.timescale;e.isFragmented=this.inputIsoFile.moov.mvex!=null;if(e.isFragmented&&this.inputIsoFile.moov.mvex.mehd){e.fragment_duration=this.inputIsoFile.moov.mvex.mehd.fragment_duration}else{e.fragment_duration=0}e.isProgressive=this.inputIsoFile.isProgressive;e.hasIOD=this.inputIsoFile.moov.iods!=null;e.brands=[];e.brands.push(this.inputIsoFile.ftyp.major_brand);e.brands=e.brands.concat(this.inputIsoFile.ftyp.compatible_brands);e.created=new Date(s+this.inputIsoFile.moov.mvhd.creation_time*1e3);e.modified=new Date(s+this.inputIsoFile.moov.mvhd.modification_time*1e3);e.tracks=[];e.audioTracks=[];e.videoTracks=[];e.subtitleTracks=[];e.metadataTracks=[];e.hintTracks=[];e.otherTracks=[];for(i=0;i<this.inputIsoFile.moov.traks.length;i++){t=this.inputIsoFile.moov.traks[i];n=t.mdia.minf.stbl.stsd.entries[0];r={};e.tracks.push(r);r.id=t.tkhd.track_id;r.references=[];if(t.tref){for(j=0;j<t.tref.boxes.length;j++){ref={};r.references.push(ref);ref.type=t.tref.boxes[j].type;ref.track_ids=t.tref.boxes[j].track_ids}}r.created=new Date(s+t.tkhd.creation_time*1e3);r.modified=new Date(s+t.tkhd.modification_time*1e3);r.movie_duration=t.tkhd.duration;r.layer=t.tkhd.layer;r.alternate_group=t.tkhd.alternate_group;r.volume=t.tkhd.volume;r.matrix=t.tkhd.matrix;r.track_width=t.tkhd.width/(1<<16);r.track_height=t.tkhd.height/(1<<16);r.timescale=t.mdia.mdhd.timescale;r.duration=t.mdia.mdhd.duration;r.codec=n.getCodec();r.language=t.mdia.mdhd.languageString;r.nb_samples=t.samples.length;r.size=0;for(j=0;j<r.nb_samples;j++){r.size+=t.samples[j].size}r.bitrate=r.size*8*r.timescale/r.duration;if(n.isAudio()){e.audioTracks.push(r);r.audio={};r.audio.sample_rate=n.getSampleRate();r.audio.channel_count=n.getChannelCount();r.audio.sample_size=n.getSampleSize()}else if(n.isVideo()){e.videoTracks.push(r);r.video={};r.video.width=n.getWidth();r.video.height=n.getHeight()}else if(n.isSubtitle()){e.subtitleTracks.push(r)}else if(n.isHint()){e.hintTracks.push(r)}else if(n.isMetadata()){e.metadataTracks.push(r)}else{e.otherTracks.push(r)}}return e};f.prototype.getInitializationSegment=function(){var e=new s;e.endianness=s.BIG_ENDIAN;this.inputIsoFile.writeInitializationSegment(e);return e.buffer};f.prototype.writeFile=function(){var e=new s;e.endianness=s.BIG_ENDIAN;this.inputIsoFile.write(e);return e.buffer};f.prototype.initializeSegmentation=function(){var e;var t;var r;var n;var i;if(this.onSegment===null){a.w("MP4Box","No segmentation callback set!")}if(!this.isFragmentationStarted){this.isFragmentationStarted=true;this.nextMoofNumber=0;this.inputIsoFile.resetTables()}n=[];for(e=0;e<this.fragmentedTracks.length;e++){for(t=0;t<this.inputIsoFile.moov.boxes.length;t++){r=this.inputIsoFile.moov.boxes[t];if(r&&r.type==="trak"){this.inputIsoFile.moov.boxes[t].ignore=true;this.inputIsoFile.moov.boxes[t]=null}}i=this.inputIsoFile.getTrackById(this.fragmentedTracks[e].id);delete i.ignore;for(t=0;t<this.inputIsoFile.moov.boxes.length;t++){r=this.inputIsoFile.moov.boxes[t];if(r==null){this.inputIsoFile.moov.boxes[t]=i;break}}seg={};seg.id=i.tkhd.track_id;seg.user=this.fragmentedTracks[e].user;seg.buffer=this.getInitializationSegment();n.push(seg)}return n};f.prototype.releaseUsedSamples=function(e,t){var r=0;var n=this.inputIsoFile.getTrackById(e);if(!n.lastValidSample)n.lastValidSample=0;for(var i=n.lastValidSample;i<t;i++){r+=this.inputIsoFile.releaseSample(n,i)}a.d("MP4Box","Track #"+e+" released samples up to "+t+" (total size: "+r+", remaining: "+this.inputIsoFile.samplesDataSize+")");n.lastValidSample=t};f.prototype.flush=function(){a.i("MP4Box","Flushing remaining samples");this.inputIsoFile.updateSampleLists();this.processSamples()};f.prototype.seekTrack=function(e,t,r){var n;var i;var s=Infinity;var o=0;var f=Infinity;var u=0;var h=0;var l;for(n=0;n<r.samples.length;n++){i=r.samples[n];if(n===0){f=i.offset;h=0;l=i.timescale}else if(i.cts>e*i.timescale){f=r.samples[n-1].offset;h=n-1;break}if(t&&i.is_rap){s=i.offset;o=i.cts;u=n}}if(t){r.nextSample=u;a.i("MP4Box","Seeking to RAP sample #"+r.nextSample+" on track "+r.tkhd.track_id+", time "+a.getDurationString(o,l)+" and offset: "+s);return{offset:s,time:o/l}}else{r.nextSample=h;a.i("MP4Box","Seeking to non-RAP sample #"+r.nextSample+" on track "+r.tkhd.track_id+", time "+a.getDurationString(e)+" and offset: "+s);return{offset:f,time:e}}};f.prototype.seek=function(e,t){var r=this.inputIsoFile.moov;var n;var i;var s;var o={offset:Infinity,time:Infinity};if(!this.inputIsoFile.moov){throw"Cannot seek: moov not received!"}else{for(s=0;s<r.traks.length;s++){n=r.traks[s];i=this.seekTrack(e,t,n);if(i.offset<o.offset){o.offset=i.offset}if(i.time<o.time){o.time=i.time}}if(o.offset===Infinity){o={offset:this.inputIsoFile.nextParsePosition,time:0}}else{var f=this.inputIsoFile.findPosition(true,o.offset);if(f!==-1){o.offset=this.inputIsoFile.findEndContiguousBuf(f)}}a.i("MP4Box","Seeking at time "+a.getDurationString(o.time,1)+" needs a buffer with a fileStart position of "+o.offset);return o}}},{"./DataStream":163,"./box":164,"./isofile":166,"./log":167}],169:[function(e,t,r){(function(r){var n=e("debug")("videostream");var i=e("videostream-mp4box");var s=.01;var o=60;t.exports=function(e,t,f){f=f||{};var u=f.debugTrack||-1;var h=[];function l(){t.addEventListener("waiting",S);t.addEventListener("timeupdate",A)}l();var c=false;function d(e){c=true;t.removeEventListener("waiting",S);t.removeEventListener("timeupdate",A);if(m.readyState==="open")m.endOfStream(e)}function p(e){var r=e.buffer.buffered;var i=t.currentTime;var a=-1;for(var f=0;f<r.length;f++){var u=r.start(f);var h=r.end(f)+s;if(u>i){break}else if(a>=0||i<=h){a=h}}var l=a-i;if(l<0)l=0;n("Buffer length: %f",l);return l<=o}var m=new MediaSource;m.addEventListener("sourceopen",function(){x(0)});t.src=window.URL.createObjectURL(m);var g=new i;g.onError=function(e){n("MP4Box error: %s",e.message);if(w){w()}if(m.readyState==="open"){d("decode")}};var v=false;var y={};g.onReady=function(e){n("MP4 info: %o",e);e.tracks.forEach(function(e){var t;if(e.video){t="video/mp4"}else if(e.audio){t="audio/mp4"}else{return}t+='; codecs="'+e.codec+'"';if(MediaSource.isTypeSupported(t)){var r=m.addSourceBuffer(t);var n={buffer:r,arrayBuffers:[],meta:e,ended:false};r.addEventListener("updateend",U.bind(null,n));g.setSegmentOptions(e.id,null,{nbSamples:e.video?1:100});y[e.id]=n}});if(Object.keys(y).length===0){d("decode");return}var t=g.initializeSegmentation();t.forEach(function(e){E(y[e.id],e.buffer);if(e.id===u){a("init-track-"+u+".mp4",[e.buffer]);h.push(e.buffer)}});v=true};g.onSegment=function(e,t,r,n){var i=y[e];E(i,r,n===i.meta.nb_samples);if(e===u&&h){h.push(r);if(n>1e3){a("track-"+u+".mp4",h);h=null}}};var _;var b=null;var w=null;function x(t){if(t===e.length){g.flush();return}if(b&&t===_){var i=b;setTimeout(function(){if(b===i)b.resume()});return}if(b){b.destroy();w()}_=t;var s={start:_,end:e.length-1};b=e.createReadStream(s);function o(e){b.pause();var t=new r(e).buffer;t.fileStart=_;_+=t.byteLength;var i;try{i=g.appendBuffer(t)}catch(s){n("MP4Box threw exception: %s",s.message);if(m.readyState==="open"){d("decode")}b.destroy();w();return}x(i)}b.on("data",o);function a(){w();x(_)}b.on("end",a);function f(e){n("Stream error: %s",e.message);if(m.readyState==="open"){d("network")}}b.on("error",f);w=function(){b.removeListener("data",o);b.removeListener("end",a);b.removeListener("error",f);b=null;w=null}}function S(){if(v){k(t.currentTime)}}function k(e){if(c)l();var t=g.seek(e,true);n("Seeking to time: %d",e);n("Seeked file offset: %d",t.offset);x(t.offset)}function E(e,t,r){e.arrayBuffers.push({buffer:t,ended:r||false});U(e)}function A(){Object.keys(y).forEach(function(e){var t=y[e];if(t.blocked){U(t)}})}function U(e){if(e.buffer.updating)return;e.blocked=!p(e);if(e.blocked)return;if(e.arrayBuffers.length===0)return;var t=e.arrayBuffers.shift();var r=false;try{e.buffer.appendBuffer(t.buffer);e.ended=t.ended;r=true}catch(i){n("SourceBuffer error: %s",i.message);d("decode");return}if(r){I()}}function I(){if(m.readyState!=="open"){return}var e=Object.keys(y).every(function(e){var t=y[e];return t.ended&&!t.buffer.updating});if(e){d()}}};function a(e,t){var r=new Blob(t);var n=URL.createObjectURL(r);var i=document.createElement("a");i.setAttribute("href",n);i.setAttribute("download",e);i.click()}}).call(this,e("buffer").Buffer)},{buffer:25,debug:107,"videostream-mp4box":168}],170:[function(e,t,r){t.exports=i;var n=Object.prototype.hasOwnProperty;function i(){var e={};for(var t=0;t<arguments.length;t++){var r=arguments[t];for(var i in r){if(n.call(r,i)){e[i]=r[i]}}}return e}},{}],171:[function(e,t,r){t.exports=i;var n=Object.prototype.hasOwnProperty;function i(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r){if(n.call(r,i)){e[i]=r[i]}}}return e}},{}],172:[function(e,t,r){t.exports=function n(e,t,r){if(t===undefined){return function(t,r){return n(e,t,r)}}if(r===undefined)r="0";e-=t.toString().length;if(e>0)return new Array(e+(/\./.test(t)?2:1)).join(r)+t;return t+""}},{}],173:[function(e,t,r){t.exports={name:"webtorrent",description:"Streaming torrent client",version:"0.71.3",author:{name:"Feross Aboukhadijeh",email:"feross@feross.org",url:"http://feross.org/"},bin:{webtorrent:"./bin/cmd.js"},browser:{"./lib/server.js":false,"bittorrent-dht/client":false,"fs-chunk-store":"memory-chunk-store","load-ip-set":false,os:false,"path-exists":false,ut_pex:false},bugs:{url:"https://github.com/feross/webtorrent/issues"},dependencies:{"addr-to-ip-port":"^1.0.1",bitfield:"^1.0.2","bittorrent-dht":"^6.0.1","bittorrent-swarm":"^6.0.0","chunk-store-stream":"^2.0.0",clivas:"^0.2.0","create-torrent":"^3.4.0","cross-spawn-async":"^2.0.0",debug:"^2.1.0","end-of-stream":"^1.0.0",executable:"^3.0.0","fs-chunk-store":"^1.3.4",hat:"0.0.3","immediate-chunk-store":"^1.0.7",inherits:"^2.0.1",inquirer:"^0.11.0","load-ip-set":"^1.0.3",mediasource:"^1.0.0","memory-chunk-store":"^1.2.0",mime:"^1.2.11",minimist:"^1.1.0",moment:"^2.8.3",multistream:"^2.0.2","network-address":"^1.0.0","parse-torrent":"^5.1.0","path-exists":"^2.1.0","pretty-bytes":"^3.0.0",pump:"^1.0.0","random-iterate":"^1.0.1","range-parser":"^1.0.2","re-emitter":"^1.0.0","render-media":"^2.0.0","run-parallel":"^1.0.0","simple-peer":"^5.11.6","simple-sha1":"^2.0.0",speedometer:"^1.0.0","stream-to-blob-url":"^1.0.0","stream-with-known-length-to-buffer":"^1.0.0",thunky:"^0.1.0","torrent-discovery":"^5.1.0","torrent-piece":"^1.0.0",uniq:"^1.0.1",ut_metadata:"^3.0.1",ut_pex:"^1.0.1",videostream:"^1.1.4","windows-no-runnable":"0.0.6",xtend:"^4.0.0","zero-fill":"^2.2.0"},devDependencies:{"bittorrent-tracker":"^7.0.0",brfs:"^1.2.0",browserify:"^12.0.1",finalhandler:"^0.4.0","run-series":"^1.0.2","serve-static":"^1.9.3","simple-get":"^1.0.0",standard:"^5.1.0",tape:"^4.0.0","uglify-js":"^2.4.15",zuul:"^3.0.0"},homepage:"https://webtorrent.io",keywords:["bittorrent","bittorrent client","download","mad science","streaming","torrent","webrtc","webrtc data","webtorrent"],license:"MIT",main:"index.js",optionalDependencies:{"airplay-js":"^0.2.3",chromecasts:"^1.5.3",nodebmc:"0.0.5"},repository:{type:"git",url:"git://github.com/feross/webtorrent.git"},scripts:{build:"browserify -s WebTorrent -e ./ | uglifyjs -m > webtorrent.min.js","build-debug":"browserify -s WebTorrent -e ./ > webtorrent.debug.js",size:"npm run build && cat webtorrent.min.js | gzip | wc -c",test:"standard && node ./bin/test.js","test-browser":"zuul -- test/*.js test/browser/*.js","test-browser-local":"zuul --local -- test/*.js test/browser/*.js","test-node":"tape test/*.js test/node/*.js"}}},{}],174:[function(e,t,r){(function(r,n,i){t.exports=S;var s=e("create-torrent");var o=e("debug")("webtorrent");var a=e("bittorrent-dht/client");var f=e("events").EventEmitter;var u=e("xtend");var h=e("hat");var l=e("inherits");var c=e("load-ip-set");var d=e("run-parallel");var p=e("parse-torrent");var m=e("path");var g=e("simple-peer");var v=e("speedometer");var y=e("zero-fill");var _=e("./lib/torrent");t.exports.WEBRTC_SUPPORT=g.WEBRTC_SUPPORT;var b=e("./package.json").version;var w=b.match(/([0-9]+)/g).slice(0,2).map(y(2)).join("");var x="-WW"+w+"-";l(S,f);function S(e){var t=this;if(!(t instanceof S))return new S(e);f.call(t);if(!e)e={};if(!o.enabled)t.setMaxListeners(0);t.destroyed=false;t.torrentPort=e.torrentPort||0;t.tracker=e.tracker!==undefined?e.tracker:true;t._rtcConfig=e.rtcConfig;t._wrtc=e.wrtc||n.WRTC;t.torrents=[];t.downloadSpeed=v();t.uploadSpeed=v();t.maxConns=e.maxConns;t.peerId=typeof e.peerId==="string"?e.peerId:(e.peerId||new i(x+h(48))).toString("hex");t.peerIdBuffer=new i(t.peerId,"hex");t.nodeId=typeof e.nodeId==="string"?e.nodeId:e.nodeId&&e.nodeId.toString("hex")||h(160);t.nodeIdBuffer=new i(t.nodeId,"hex");if(e.dht!==false&&typeof a==="function"){t.dht=new a(u({nodeId:t.nodeId},e.dht));t.dht.listen(e.dhtPort)}o("new webtorrent (peerId %s, nodeId %s)",t.peerId,t.nodeId);if(typeof c==="function"){c(e.blocklist,{headers:{"user-agent":"WebTorrent/"+b+" (http://webtorrent.io)"}},function(e,r){if(e)return t.error("Failed to load blocklist: "+e.message);t.blocked=r;s()})}else r.nextTick(s);function s(){if(t.destroyed)return;t.ready=true;t.emit("ready")}}Object.defineProperty(S.prototype,"ratio",{get:function(){var e=this;var t=e.torrents.reduce(function(e,t){return e+t.uploaded},0);var r=e.torrents.reduce(function(e,t){return e+t.downloaded},0)||1;return t/r}});S.prototype.get=function(e){var t=this;if(e instanceof _)return e;var r;try{r=p(e)}catch(n){}if(!r)return null;if(!r.infoHash)throw new Error("Invalid torrent identifier");for(var i=0,s=t.torrents.length;i<s;i++){var o=t.torrents[i];if(o.infoHash===r.infoHash)return o}return null};S.prototype.add=S.prototype.download=function(e,t,n){var i=this;if(i.destroyed)throw new Error("client is destroyed");if(typeof t==="function")return i.add(e,null,t);o("add");if(!t)t={};else t=u(t);t.client=i;var s=i.get(e);function a(){if(typeof n==="function")n(s)}if(s){if(s.ready)r.nextTick(a);else s.on("ready",a)}else{s=new _(e,t);i.torrents.push(s);s.on("error",function(e){i.emit("error",e,s);i.remove(s)});s.on("listening",function(e){i.emit("listening",e,s)});s.on("ready",function(){a();i.emit("torrent",s)})}return s};S.prototype.seed=function(e,t,r){var n=this;if(n.destroyed)throw new Error("client is destroyed");if(typeof t==="function")return n.seed(e,null,t);o("seed");if(!t)t={};else t=u(t);if(typeof e==="string")t.path=m.dirname(e);if(!t.createdBy)t.createdBy="WebTorrent/"+w;if(!n.tracker)t.announce=[];var i;var a=n.add(undefined,t,function(e){var t=[function(t){e.load(i,t)}];if(n.dht){t.push(function(t){e.on("dhtAnnounce",t)})}d(t,function(t){if(t)return n.emit("error",t);f();n.emit("seed",e)})});s.parseInput(e,t,function(r,o){if(r)return n.emit("error",r);i=o.map(function(e){return e.getStream});s(e,t,function(e,t){if(e)return n.emit("error",e);if(n.destroyed)return;var r=n.get(t);if(r){a.destroy();f();return}else{a._onTorrentId(t)}})});function f(){o("on seed");if(typeof r==="function")r(a)}return a};S.prototype.remove=function(e,t){var r=this;o("remove");var n=r.get(e);if(!n)throw new Error("No torrent with id "+e);r.torrents.splice(r.torrents.indexOf(n),1);n.destroy(t)};S.prototype.address=function(){var e=this;return{address:"0.0.0.0",family:"IPv4",port:e.torrentPort}};S.prototype.destroy=function(e){var t=this;if(t.destroyed)throw new Error("client already destroyed");t.destroyed=true;o("destroy");var r=t.torrents.map(function(e){return function(r){t.remove(e,r)}});if(t.dht)r.push(function(e){t.dht.destroy(e)});d(r,e)}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{},e("buffer").Buffer)},{"./lib/torrent":4,"./package.json":173,_process:34,"bittorrent-dht/client":24,buffer:25,"create-torrent":75,debug:107,events:29,hat:113,inherits:115,"load-ip-set":24,"parse-torrent":119,path:33,"run-parallel":138,"simple-peer":142,speedometer:150,xtend:170,"zero-fill":172}]},{},[174])(174)});