!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;(t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Wfs=e()}}(function(){return(function(){function e(t,n,r){function i(a,s){if(!n[a]){if(!t[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(o)return o(a,!0);var c=Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var l=n[a]={exports:{}};t[a][0].call(l.exports,function(e){return i(t[a][1][e]||e)},l,l.exports,e,t,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;a0&&a.length>i&&!a.warned){a.warned=!0;var i,o,a,s,u=Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=a.length,s=u,console&&console.warn&&console.warn(s)}return e}function d(){if(!this.fired)return(this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length)?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function h(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=d.bind(r);return i.listener=n,r.wrapFn=i,i}function p(e,t,n){var r=e._events;if(void 0===r)return[];var i=r[t];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function e(t){for(var n=Array(t.length),r=0;r0&&(s=n[0]),s instanceof Error)throw s;var s,u=Error("Unhandled error."+(s?" ("+s.message+")":""));throw u.context=s,u}var c=a[t];if(void 0===c)return!1;if("function"==typeof c)o(c,this,n);else for(var l=c.length,f=v(c,l),r=0;r=0;a--)if(r[a]===n||r[a].listener===n){s=r[a].listener,o=a;break}if(o<0)return this;0===o?r.shift():function e(t,n){for(;n+1=0;i--)this.removeListener(t,n[i]);return this},s.prototype.listeners=function e(t){return p(this,t,!0)},s.prototype.rawListeners=function e(t){return p(this,t,!1)},s.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):$.call(e,t)},s.prototype.listenerCount=$,s.prototype.eventNames=function e(){return this._eventsCount>0?r(this._events):[]}},{}],2:[function(e,t,n){var r,i,o,a=t.exports={};function s(){throw Error("setTimeout has not been defined")}function u(){throw Error("clearTimeout has not been defined")}function c(e){if(r===setTimeout)return setTimeout(e,0);if((r===s||!r)&&setTimeout)return r=setTimeout,setTimeout(e,0);try{return r(e,0)}catch(t){try{return r.call(null,e,0)}catch(n){return r.call(this,e,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:s}catch(e){r=s}try{i="function"==typeof clearTimeout?clearTimeout:u}catch(t){i=u}}();var l=[],f=!1,d=-1;function h(){f&&o&&(f=!1,o.length?l=o.concat(l):d=-1,l.length&&p())}function p(){if(!f){var e=c(h);f=!0;for(var t=l.length;t;){for(o=l,l=[];++d1)for(var n=1;n=0;--o){var a=this.tryEntries[o],s=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),c=n.call(a,"finallyLoc");if(u&&c){if(this.prev=0;--i){var o=this.tryEntries[i];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--n){var r=this.tryEntries[n];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),k(r),h}},catch:function e(t){for(var n=this.tryEntries.length-1;n>=0;--n){var r=this.tryEntries[n];if(r.tryLoc===t){var i=r.completion;if("throw"===i.type){var o=i.arg;k(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function e(t,n,r){return this.delegate={iterator:S(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},e}function l(e,t){for(var n=0;n10){clearInterval(t.rec_timer),t.rec_timer=void 0;var e=new Date,n=1900+e.getYear()+"-"+t.pad2(e.getMonth()+1)+"-"+t.pad2(e.getDate())+"_"+t.pad2(e.getHours())+"-"+t.pad2(e.getMinutes())+"-"+t.pad2(e.getSeconds());t.rec_file="ax_"+n+".mp4",console.log("MediaRecorder started: "+t.rec_file),t.mediaSize=0,t.recording=!0,t.rec_result_cb&&t.rec_result_cb(!0)}else t.count++;t.count>=10&&(clearInterval(t.rec_timer),t.rec_timer=void 0,t.rec_result_cb&&t.rec_result_cb(!1))},1e3)}},{key:"onRecordingStart",value:function e(t){if(this.recording){console.log("recording is in progress");return}void 0!=t&&(this.rec_threshold_single=t.rec_file_threshold,this.rec_result_cb=t.result_cb,this.rec_state_cb=t.state_cb);var n=this;navigator.webkitPersistentStorage.queryUsageAndQuota(function(e,t){""==t?n.requestFs():window.webkitRequestFileSystem(window.PERSISTENT,n.rec_threshold_total,function(e){n._fs=e,e.root.getDirectory("ax_video",{create:!0},function(e){console.log("Directory: "+e.name+" fs requested"),n.onRecordingProc()},n.errorHandler)})},this.errorHandler)}},{key:"onRecordingStop",value:function e(){this.rec_timer&&(clearInterval(this.rec_timer),this.rec_timer=void 0,console.log("Media Recorder stopped2"));var t=this;t.recording=!1,t.saveToMP4Blob(t.h264Frames,this.track_info),t.h264Frames=[]}},{key:"errorHandler",value:function e(t){console.log("An error occured(errcd): "+t.code)}},{key:"requestFs",value:function e(){var t=this;navigator.webkitPersistentStorage.requestQuota(this.rec_threshold_total,function(e){console.log("grantedBytes: "+e),e>0?window.webkitRequestFileSystem(window.PERSISTENT,e,function(e){t._fs=e,e.root.getDirectory("ax_video",{create:!0},function(e){console.log("Directory: "+e.name+" exists or just created."),t.onRecordingProc()},t.errorHandler)}):t.rec_result_cb&&t.rec_result_cb(!1)})}},{key:"onMediaAttaching",value:function e(t){var n=this.mediaElement=t.media;if(this.mediaType=t.mediaType,this.websocketName=t.websocketName,this.channelName=t.channelName,n){var r=this.mediaSource=new MediaSource;this.onmso=this.onMediaSourceOpen.bind(this),this.onmse=this.onMediaSourceEnded.bind(this),this.onmsc=this.onMediaSourceClose.bind(this),r.addEventListener("sourceopen",this.onmso),r.addEventListener("sourceended",this.onmse),r.addEventListener("sourceclose",this.onmsc),n.src=URL.createObjectURL(r)}}},{key:"onMediaDetaching",value:function e(){}},{key:"onH264DataAppending",value:function e(t){if(this.recording&&t.data){var n=this,r=t.data;n.h264Frames.push(t.data),n.mediaSize+=r.length,n.mediaSize>=n.rec_threshold_single&&(n.rec_state_cb&&n.rec_state_cb(!1),n.onRecordingStop(),n.onRecordingStart(),n.rec_state_cb&&n.rec_state_cb(!0))}}},{key:"saveToMP4Blob",value:function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t.length>0){var r=n.width,i=n.height,o=$.createEncoder({width:r,height:i,hevc:!1});t.forEach(function(e){o.addNalu(e)});var a=new Blob([o.end()]);this.writeMP4Data(a)}}},{key:"writeMP4Data",value:function e(t){var n=this;n._fs.root.getFile("ax_video/"+n.rec_file,{create:!0},function(e){e.createWriter(function(e){e.onwriteend=function(e){},e.onerror=function(e){console.log("Write rec data failed: "+e.toString())},e.seek(e.length),e.write(t)},n.errorHandler)},n.errorHandler)}},{key:"onBufferAppending",value:function e(t){this.segments.push(t),this.doAppending()}},{key:"onMediaSourceClose",value:function e(){console.log("media source closed")}},{key:"onMediaSourceEnded",value:function e(){console.log("media source ended")}},{key:"onSBUpdateEnd",value:function e(t){this.appending=!1,this.doAppending()}},{key:"onMediaSourceOpen",value:function e(){console.log("media source open");var t=this.mediaSource;t&&t.removeEventListener("sourceopen",this.onmso),this.wfs.trigger(o.default.MEDIA_ATTACHED,{media:this.media,channelName:this.channelName,mediaType:this.mediaType,websocketName:this.websocketName})}},{key:"onBufferReset",value:function e(t){"H264Raw"===this.mediaType&&this.createSourceBuffers({tracks:"video",mimeType:t.mimeType}),this.track_info.width=t.width,this.track_info.height=t.height}},{key:"createSourceBuffers",value:function e(t){var n,r=this.sourceBuffers,i=this.mediaSource;n=""===t.mimeType?"video/mp4;codecs=avc1.420028":"video/mp4;codecs="+t.mimeType;try{(r.video=i.addSourceBuffer(n)).addEventListener("updateend",this.onsbue)}catch(a){}this.wfs.trigger(o.default.BUFFER_CREATED,{tracks:t}),this.mediaElement.play()}},{key:"onPlayerSeekNow",value:function e(){var t=this.mediaElement.buffered.end(0);this.mediaElement.currentTime=t}},{key:"doAppending",value:function e(){var t=this.wfs,n=this.sourceBuffers,r=this.segments;if(Object.keys(n).length){if(this.mediaElement.error){if(this.segments=[],this.mediaErrorCount++,this.mediaErrorCount<100)console.log("doAppending although a media error occured, error code:",this.media.error.code);else{var a={type:i.ErrorTypes.MEDIA_ERROR};a.details=i.ErrorDetails.BUFFER_APPEND_ERROR,a.frag=this.fragCurrent,a.fatal=!0,this.wfs.trigger(o.default.ERROR,a)}return}if(this.mediaErrorCount=0,this.appending)return;if(r&&r.length){var s=r.shift();try{n[s.type]&&(this.parent=s.parent,n[s.type].appendBuffer(s.data),this.appendError=0,this.appended++,this.appending=!0)}catch(u){r.unshift(s);var c={type:i.ErrorTypes.MEDIA_ERROR};22!==u.code?(this.appendError?this.appendError++:this.appendError=1,c.details=i.ErrorDetails.BUFFER_APPEND_ERROR,c.frag=this.fragCurrent,this.appendError>t.config.appendErrorMaxRetry?(r=[],c.fatal=!0):c.fatal=!1):(this.segments=[],c.details=i.ErrorDetails.BUFFER_FULL_ERROR,c.fatal=!0),this.wfs.trigger(o.default.ERROR,c)}}}}}],l(s.prototype,u),c&&l(s,c),Object.defineProperty(s,"prototype",{writable:!1}),y}(a.default);n.default=y},{"../errors":7,"../event-handler":8,"../events":9,"../utils/mp4-encoder":17}],4:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var i=a(e("../events")),o=a(e("../event-handler"));function a(e){return e&&e.__esModule?e:{default:e}}function s(e,t){for(var n=0;nt?(this.word<<=t,this.bitsAvailable-=t):(t-=this.bitsAvailable,n=t>>3,t-=n>>3,this.bytesAvailable-=n,this.loadWord(),this.word<<=t,this.bitsAvailable-=t)}},{key:"readBits",value:function e(t){var n=Math.min(this.bitsAvailable,t),i=this.word>>>32-n;return(t>32&&r.logger.error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=n,this.bitsAvailable>0?this.word<<=n:this.bytesAvailable>0&&this.loadWord(),(n=t-n)>0)?i<>>t))return this.word<<=t,this.bitsAvailable-=t,t;return this.loadWord(),t+this.skipLZ()}},{key:"skipUEG",value:function e(){this.skipBits(1+this.skipLZ())}},{key:"skipEG",value:function e(){this.skipBits(1+this.skipLZ())}},{key:"readUEG",value:function e(){var t=this.skipLZ();return this.readBits(t+1)-1}},{key:"readEG",value:function e(){var t=this.readUEG();return 1&t?1+t>>>1:-1*(t>>>1)}},{key:"readBoolean",value:function e(){return 1===this.readBits(1)}},{key:"readUByte",value:function e(){return this.readBits(8)}},{key:"readUShort",value:function e(){return this.readBits(16)}},{key:"readUInt",value:function e(){return this.readBits(32)}},{key:"skipScalingList",value:function e(t){var n,r,i=8,o=8;for(n=0;n1&&void 0!==arguments[1]?arguments[1]:null;return!function e(t,n){if(!(t instanceof n))throw TypeError("Cannot call a class as a function")}(this,$),(t=p.call(this,e,i.default.H264_DATA_PARSING)).config=t.wfs.config||n,t.wfs=e,t.id="main",MediaSource.isTypeSupported("video/mp4"),t.remuxer=new s.default(t.wfs,t.id,t.config),t.contiguous=!0,t.timeOffset=1,t.sn=0,t.TIMESCALE=9e4,t.timestamp=0,t.scaleFactor=t.TIMESCALE/1e3,t.H264_TIMEBASE=t.config.mp4Duration,t._avcTrack={container:"video/mp4",type:"video",id:1,sequenceNumber:0,samples:[],len:0,nbNalu:0,dropped:0,count:0},t.browserType=0,-1!==navigator.userAgent.toLowerCase().indexOf("firefox")&&(t.browserType=1),t}return u=$,d=[{key:"destroy",value:function e(){a.default.prototype.destroy.call(this)}},{key:"getTimestampM",value:function e(){return this.timestamp+=this.H264_TIMEBASE,this.timestamp}},{key:"onH264DataParsing",value:function e(t){this._parseAVCTrack(t.data),this.browserType,this.remuxer.pushVideo(0,this.sn,this._avcTrack,this.timeOffset,this.contiguous),this.sn+=1}},{key:"_parseAVCTrack",value:function e(t){var n,r,a,s,u=this,c=this._avcTrack,l=c.samples,f=this._parseAVCNALu(t),d=[],h=!1,p=0,$="",v=(function(){if(d.length){if(!this.config.forceKeyFrameOnDiscontinuity||!0===h||c.sps&&(l.length||this.contiguous)){var e=this.getTimestampM();r={units:{units:d,length:p},pts:e,dts:e,key:h},l.push(r),c.len+=p,c.nbNalu+=d.length}else c.dropped++;d=[],p=0}}).bind(this);f.forEach(function(e){switch(e.type){case 1:a=!0;break;case 5:a=!0,h=!0;break;case 6:e.data=u.discardEPB(e.data),(n=new o.default(e.data)).readUByte();break;case 7:if(a=!1,!c.sps){var t=(n=new o.default(e.data)).readSPS();c.width=t.width,c.height=t.height,c.sps=[e.data],c.duration=0;var r=e.data.subarray(1,4),l="avc1.";for(s=0;s<3;s++){var f=r[s].toString(16);f.length<2&&(f="0"+f),l+=f}c.codec=l,u.wfs.trigger(i.default.BUFFER_RESET,{mimeType:c.codec,width:c.width,height:c.height}),a=!0}break;case 8:a=!1,c.pps||(c.pps=[e.data],a=!0);break;case 9:a=!1,v();break;default:a=!1,$+="unknown NAL "+e.type+" "}a&&(d.push(e),p+=e.data.byteLength)}),$.length&&logger.log($),v()}},{key:"_parseAVCNALu",value:function e(t){for(var n,r,i,o,a,s=0,u=t.byteLength,c=0,l=[];s1?t-1:0),r=1;r0){var e=performance.now()-t.lastRecvDataTime;if(e>t.wfs.config.wsMinPacketInterval&&console.log("Websocket: did not recv data over "+e+" ms"),e>t.wfs.config.wsMaxPacketInterval&&!t.isForceClosed){t.unload(),console.log("Websocket data not received in "+t.wfs.config.wsMaxPacketInterval/1e3+"s, open again...");var n={type:i.ErrorTypes.NETWORK_ERROR};n.details=i.ErrorDetails.NETWORK_RECV_DATA_TIMEOUT,n.fatal=!0,t.wfs.trigger(o.default.ERROR,n)}}else t.lastRecvDataTime=performance.now()},this.wfs.config.wsMinPacketInterval)}},{key:"kill_timer",value:function e(){this.timer&&(console.log("Websocket close: clear timer"),clearInterval(this.timer),this.timer=void 0)}},{key:"destroy",value:function e(){this.kill_timer(),this.isForceClosed=!0,this.client&&this.client.close(),a.default.prototype.destroy.call(this)}},{key:"onWebsocketAttaching",value:function e(t){(this.kill_timer(),this.create_timer(),"MJPEG"===t.mediaType)?(this.mediaCode=1,this.ctx=t.media.getContext("2d")):this.mediaCode=0,this.websocketName=t.websocketName,this.media=t.media,this.mediaType=t.mediaType,this.channelName=t.channelName,this.extraData=t.extraData,t.websocket instanceof WebSocket&&(this.client=t.websocket,this.client.onopen=this.initSocketClient.bind(this),this.client.onclose=this.closeSocketClient.bind(this),this.client.onerror=this.errorSocketClient.bind(this))}},{key:"errorSocketClient",value:function e(t){this.unload(),console.log("WebSocket error: ",t)}},{key:"closeSocketClient",value:function e(t){this.unload(),console.log("Websocket closed: ",t)}},{key:"initSocketClient",value:function e(t){this.load()}},{key:"receiveSocketMessage",value:function e(t){var n=this;if(this.isLoaded){if(this.lastRecvDataTime=performance.now(),0===this.mediaCode){this.buf=new Uint8Array(t.data);var r=new Uint8Array(this.buf),i=new Uint8Array(this.buf);this.wfs.trigger(o.default.H264_DATA_PARSING,{data:r}),this.wfs.trigger(o.default.H264_DATA_APPENDING,{data:i})}else if(1===this.mediaCode){if(this.extraData){if(!this.extraData.isDrawImg||void 0==this.media||!this.media)return;var a=new FileReader;a.onload=function(e){if(e.target.readyState===FileReader.DONE){var t=n.ctx,r=new Image,i=n.extraData.mjpeg_w,o=n.extraData.mjpeg_h,a=n.extraData.sizeOptionInd,s=n.extraData.getObjectFitSize;r.onload=function(){if(t.clearRect(0,0,i,o),1===a){var e=s(a,i,o,this.width,this.height),n=e.sx,u=e.sy,c=e.swidth,l=e.sheight,f=e.x,d=e.y,h=e.width,p=e.height;t.drawImage(r,n,u,c,l,f,d,h,p)}else t.drawImage(r,0,0,i,o)},r.src=e.target.result}},a.readAsDataURL(t.data)}else console.log("extraData is undefined"),this.extraData=this.wfs.extraData}}}},{key:"onWebsocketDataUploading",value:function e(t){this.client.send(t.data)}},{key:"onWebsocketMessageSending",value:function e(t){this.client.send(JSON.stringify({t:t.commandType,c:t.channelName,v:t.commandValue}))}},{key:"load",value:function e(){0===this.mediaCode&&(this.client.binaryType="arraybuffer"),this.client.onmessage=this.receiveSocketMessage.bind(this),this.wfs.trigger(o.default.WEBSOCKET_MESSAGE_SENDING,{commandType:"open",channelName:this.channelName,commandValue:"NA"}),this.isLoaded=!0}},{key:"unload",value:function e(){this.isLoaded=!1,1===this.mediaCode&&this.ctx.clearRect(0,0,this.extraData.mjpeg_w,this.extraData.mjpeg_h)}}],c(u.prototype,d),h&&c(u,h),Object.defineProperty(u,"prototype",{writable:!1}),$}(a.default);n.default=d},{"../demux/h264-demuxer":6,"../errors":7,"../event-handler":8,"../events":9}],14:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n>24&255,n[1]=i>>16&255,n[2]=i>>8&255,n[3]=255&i,n.set(t,4),o=0,i=8;o>24&255,t>>16&255,t>>8&255,255&t,r>>24,r>>16&255,r>>8&255,255&r,85,196,0,0]))}},{key:"mdia",value:function e(t){return n.box(n.types.mdia,n.mdhd(t.timescale,t.duration),n.hdlr(t.type),n.minf(t))}},{key:"mfhd",value:function e(t){return n.box(n.types.mfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))}},{key:"minf",value:function e(t){return"audio"===t.type?n.box(n.types.minf,n.box(n.types.smhd,n.SMHD),n.DINF,n.stbl(t)):n.box(n.types.minf,n.box(n.types.vmhd,n.VMHD),n.DINF,n.stbl(t))}},{key:"moof",value:function e(t,r,i){return n.box(n.types.moof,n.mfhd(t),n.traf(i,r))}},{key:"moov",value:function e(t){for(var r=t.length,i=[];r--;)i[r]=n.trak(t[r]);return n.box.apply(null,[n.types.moov,n.mvhd(t[0].timescale,t[0].duration)].concat(i).concat(n.mvex(t)))}},{key:"mvex",value:function e(t){for(var r=t.length,i=[];r--;)i[r]=n.trex(t[r]);return n.box.apply(null,[n.types.mvex].concat(i))}},{key:"mvhd",value:function e(t,r){r=0;var i=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,2,t>>24&255,t>>16&255,t>>8&255,255&t,r>>24&255,r>>16&255,r>>8&255,255&r,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255]);return n.box(n.types.mvhd,i)}},{key:"sdtp",value:function e(t){var r,i,o=t.samples||[],a=new Uint8Array(4+o.length);for(i=0;i>>8&255),a.push(255&o),a=a.concat(Array.prototype.slice.call(i));for(r=0;r>>8&255),s.push(255&o),s=s.concat(Array.prototype.slice.call(i));var u=n.box(n.types.avcC,new Uint8Array([1,a[3],a[4],a[5],255,224|t.sps.length].concat(a).concat([t.pps.length]).concat(s))),c=t.width,l=t.height;return n.box(n.types.avc1,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,c>>8&255,255&c,l>>8&255,255&l,0,72,0,0,0,72,0,0,0,0,0,0,0,1,18,106,101,102,102,45,121,97,110,47,47,47,103,119,102,115,46,106,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),u,n.box(n.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])))}},{key:"esds",value:function e(t){var n=t.config.length;return new Uint8Array([0,0,0,0,3,23+n,0,1,0,4,15+n,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([n]).concat(t.config).concat([6,1,2]))}},{key:"mp4a",value:function e(t){var r=t.audiosamplerate;return n.box(n.types.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,r>>8&255,255&r,0,0]),n.box(n.types.esds,n.esds(t)))}},{key:"stsd",value:function e(t){return"audio"===t.type?n.box(n.types.stsd,n.STSD,n.mp4a(t)):n.box(n.types.stsd,n.STSD,n.avc1(t))}},{key:"tkhd",value:function e(t){var r=t.id,i=t.duration*t.timescale,o=t.width,a=t.height;return n.box(n.types.tkhd,new Uint8Array([0,0,0,7,0,0,0,0,0,0,0,0,r>>24&255,r>>16&255,r>>8&255,255&r,0,0,0,0,i>>24,i>>16&255,i>>8&255,255&i,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,o>>8&255,255&o,0,0,a>>8&255,255&a,0,0]))}},{key:"traf",value:function e(t,r){var i=n.sdtp(t),o=t.id;return n.box(n.types.traf,n.box(n.types.tfhd,new Uint8Array([0,0,0,0,o>>24,o>>16&255,o>>8&255,255&o])),n.box(n.types.tfdt,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r])),n.trun(t,i.length+16+16+8+16+8+8),i)}},{key:"trak",value:function e(t){return t.duration=t.duration||4294967295,n.box(n.types.trak,n.tkhd(t),n.mdia(t))}},{key:"trex",value:function e(t){var r=t.id;return n.box(n.types.trex,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))}},{key:"trun",value:function e(t,r){var i,o,a,s,u,c,l=t.samples||[],f=l.length,d=12+16*f,h=new Uint8Array(d);for(r+=8+d,h.set([0,0,15,1,f>>>24&255,f>>>16&255,f>>>8&255,255&f,r>>>24&255,r>>>16&255,r>>>8&255,255&r],0),i=0;i>>24&255,a>>>16&255,a>>>8&255,255&a,s>>>24&255,s>>>16&255,s>>>8&255,255&s,u.isLeading<<2|u.dependsOn,u.isDependedOn<<6|u.hasRedundancy<<4|u.paddingValue<<1|u.isNonSync,61440&u.degradPrio,15&u.degradPrio,c>>>24&255,c>>>16&255,c>>>8&255,255&c],12+16*i);return n.box(n.types.trun,h)}},{key:"initSegment",value:function e(t){n.types||n.init();var r,i=n.moov(t);return(r=new Uint8Array(n.FTYP.byteLength+i.byteLength)).set(n.FTYP),r.set(i,n.FTYP.byteLength),r}}],t&&r(e,t),Object.defineProperty(e,"prototype",{writable:!1}),n}();n.default=i},{}],15:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var r=u(e("../helper/aac")),i=u(e("../events")),o=e("../utils/logger"),a=u(e("../remux/mp4-generator")),s=e("../errors");function u(e){return e&&e.__esModule?e:{default:e}}function c(e,t){for(var n=0;nMath.abs(T=Math.round(E-k))&&T&&(T>1?o.logger.log("AVC:".concat(T," ms hole between fragments detected,filling it")):T<-1&&o.logger.log("AVC:".concat(-T," ms overlapping between fragments detected")),b=Math.max(b-T,E=k),o.logger.log("Video/PTS/DTS adjusted: ".concat(b,"/").concat(E,",delta:").concat(T))),this.firstPTS=Math.max(0,b),this.firstDTS=Math.max(0,E),p=.03}d.push({size:y,duration:this.H264_TIMEBASE,cts:0,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:v.key?2:1,isNonSync:v.key?0:1}}),w=E}var A=0;if(d.length>=2&&(A=d[d.length-2].duration,d[0].duration=A),this.nextAvcDts=E+A,t.len=0,t.nbNalu=0,t.dropped=0,d.length&&navigator.userAgent.toLowerCase().indexOf("chrome")>-1){var S=d[0].flags;S.dependsOn=2,S.isNonSync=0}t.samples=d,c=a.default.moof(t.sequenceNumber++,E,t),t.samples=[];var R={data1:c,data2:u,type:"video"};return this.observer.trigger(i.default.FRAG_PARSING_DATA,R),R}},{key:"generateVideoIS",value:function e(t,n){var r,o,u=this.observer,c=t.samples,l=(this.PES_TIMESCALE,{}),f={id:this.id,level:this.level,sn:this.sn,tracks:l,unique:!1},d=void 0===this._initPTS;d&&(r=o=1/0),t.sps&&t.pps&&c.length&&(t.timescale=9e4,l.video={container:"video/mp4",codec:t.codec,initSegment:a.default.initSegment([t]),metadata:{width:t.width,height:t.height}},d&&(r=Math.min(r,c[0].pts-this.H264_TIMEBASE),o=Math.min(o,c[0].dts-this.H264_TIMEBASE))),Object.keys(l).length?(u.trigger(i.default.FRAG_PARSING_INIT_SEGMENT,f),this.ISGenerated=!0,this.genISFailCount=0,d&&(this._initPTS=r,this._initDTS=o)):(this.genISFailCount++,this.genISFailCount>60&&console.log("generateVideoIS ERROR: ",s.ErrorTypes.MEDIA_ERROR))}},{key:"remux",value:function e(t,n,r,o,a,s,u,c){if(this.level=t,this.sn=n,this.ISGenerated||this.generateIS(r,o,u),this.ISGenerated){if(r.samples.length){var l,f,d=this.remuxAudio(r,u,c);o.samples.length&&(d&&(f=d.endPTS-d.startPTS),this.remuxVideo(o,u,c,f))}else o.samples.length&&(l=this.remuxVideo(o,u,c)),l&&r.codec&&this.remuxEmptyAudio(r,u,c,l)}a.samples.length&&this.remuxID3(a,u),s.samples.length&&this.remuxText(s,u),this.observer.trigger(i.default.FRAG_PARSED,{id:this.id,level:this.level,sn:this.sn})}},{key:"generateIS",value:function e(t,n,r){var u,c,l=this.observer,f=t.samples,d=n.samples,h=this.PES_TIMESCALE,p={},$={id:this.id,level:this.level,sn:this.sn,tracks:p,unique:!1},v=void 0===this._initPTS;v&&(u=c=1/0),t.config&&f.length&&(t.timescale=t.audiosamplerate,t.timescale*t.duration>4294967296&&(t.timescale=t.audiosamplerate/function e(t,n){return n?e(n,t%n):t}(t.audiosamplerate,1024)),o.logger.log("audio mp4 timescale :"+t.timescale),p.audio={container:"audio/mp4",codec:t.codec,initSegment:a.default.initSegment([t]),metadata:{channelCount:t.channelCount}},v&&(u=c=f[0].pts-h*r)),n.sps&&n.pps&&d.length&&(n.timescale=this.MP4_TIMESCALE,p.video={container:"video/mp4",codec:n.codec,initSegment:a.default.initSegment([n]),metadata:{width:n.width,height:n.height}},v&&(u=Math.min(u,d[0].pts-h*r),c=Math.min(c,d[0].dts-h*r))),Object.keys(p).length?(l.trigger(i.default.FRAG_PARSING_INIT_SEGMENT,$),this.ISGenerated=!0,v&&(this._initPTS=u,this._initDTS=c)):l.trigger(i.default.ERROR,{type:s.ErrorTypes.MEDIA_ERROR,id:this.id,details:s.ErrorDetails.FRAG_PARSING_ERROR,fatal:!1,reason:"no audio/video samples found"})}},{key:"remuxAudio",value:function e(t,n,s){var u,c,l,f,d,h,p,$,v,y,g,m,_,b=this.PES_TIMESCALE,E=b/t.timescale,w=1024*t.timescale/t.audiosamplerate,T=8,k=[],A=[];t.samples.sort(function(e,t){return e.pts-t.pts}),A=t.samples;for(var S=s?this.nextAacPts:n*b,R=this._PTSNormalize(A[0].pts-this._initPTS,S),P=w*E,D=R+P,L=1;L.5*P){var I=Math.round(O/P);o.logger.log("Injecting ".concat(I," frame").concat(I>1?"s":""," of missing audio due to ").concat(Math.round(O/90)," ms gap."));for(var N=0;N.1*P&&o.logger.log("Invalid frame delta ".concat(C-D+P," at PTS ").concat(Math.round(C/90)," (should be ").concat(P,").")),D+=P,x.pts=A[L-1].pts+P,L+=1}for(;A.length;){if(f=(c=A.shift()).unit,y=c.pts-this._initDTS,g=c.dts-this._initDTS,void 0!==v)m=this._PTSNormalize(y,v),_=this._PTSNormalize(g,v),l.duration=(_-v)/E;else{m=this._PTSNormalize(y,S),_=this._PTSNormalize(g,S);var G=Math.round(1e3*(m-S)/b);if(s&&G){if(G>0)o.logger.log("".concat(G," ms hole between AAC samples detected,filling it"));else if(G<-12){o.logger.log("".concat(-G," ms overlapping between AAC samples detected, drop frame")),t.len-=f.byteLength;continue}m=_=S}if(p=Math.max(0,m),$=Math.max(0,_),!(t.len>0))return;d=new Uint8Array(t.len+8),(u=new DataView(d.buffer)).setUint32(0,d.byteLength),d.set(a.default.types.mdat,4)}d.set(f,T),T+=f.byteLength,l={size:f.byteLength,cts:0,duration:0,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:1}},k.push(l),v=_}var B=0,U=k.length;if(U>=2&&(B=k[U-2].duration,l.duration=B),U){this.nextAacPts=m+E*B,t.len=0,t.samples=k,h=a.default.moof(t.sequenceNumber++,$/E,t),t.samples=[];var H={id:this.id,level:this.level,sn:this.sn,data1:h,data2:d,startPTS:p/b,endPTS:this.nextAacPts/b,startDTS:$/b,endDTS:(_+E*B)/b,type:"audio",nb:U};return this.observer.trigger(i.default.FRAG_PARSING_DATA,H),H}return null}},{key:"remuxEmptyAudio",value:function e(t,n,i,a){var s=this.PES_TIMESCALE,u=t.timescale?t.timescale:t.audiosamplerate,c=a.startDTS*s+this._initDTS,l=a.endDTS*s+this._initDTS,f=s/u*1024,d=Math.ceil((l-c)/f),h=r.default.getSilentFrame(t.channelCount);if(!h){o.logger.trace("Unable to remuxEmptyAudio since we were unable to get a silent frame for given audio codec!");return}for(var p=[],$=0;$4294967296;)t+=r;return t}}],c(e.prototype,t),n&&c(e,n),Object.defineProperty(e,"prototype",{writable:!1}),u}();n.default=l},{"../errors":7,"../events":9,"../helper/aac":10,"../remux/mp4-generator":14,"../utils/logger":16,"../utils/polyfill":18}],16:[function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(){}Object.defineProperty(n,"__esModule",{value:!0}),n.logger=n.enableLogs=void 0;var o={trace:i,debug:i,log:i,warn:i,info:i,error:i},a=o,s=function e(t){if(!0===t||"object"===r(t)){!function e(t){for(var n=arguments.length,r=Array(n>1?n-1:0),o=1;o "+(t=o[0]))),r.apply(window.console,o)}:i)})}(t,"debug","log","info","warn","error");try{a.log()}catch(n){a=o}}else a=o};n.enableLogs=s;var u=a;n.logger=u},{}],17:[function(e,t,n){(function(e){(function(){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}Object.defineProperty(n,"__esModule",{value:!0}),n.createEncoderWithModule=a,n.createFile=o,n.default=void 0;var r,i=(r="undefined"!=typeof document&&document.currentScript?document.currentScript.src:void 0,function(n){var i,o,s,u,c,l,f,d,h,p,$,v,y,g,m,_,b,E,w,T,k,A,n=void 0!==(n=n||{})?n:{};n.ready=new Promise(function(e,t){o=e,s=t}),n.createEncoder=function e(t){return a(n,t)};var S=Object.assign({},n),R=[],P="./this.program",D=function e(t,n){throw n},L=("undefined"==typeof window?"undefined":t(window))=="object",x="function"==typeof importScripts;(void 0===e?"undefined":t(e))=="object"&&"object"==t(e.versions)&&e.versions.node;var C="";(L||x)&&(x?C=self.location.href:"undefined"!=typeof document&&document.currentScript&&(C=document.currentScript.src),r&&(C=r),C=0!==C.indexOf("blob:")?C.substr(0,C.replace(/[?#].*/,"").lastIndexOf("/")+1):"",u=function e(t){var n=new XMLHttpRequest;return n.open("GET",t,!1),n.send(null),n.responseText},x&&(l=function e(t){var n=new XMLHttpRequest;return n.open("GET",t,!1),n.responseType="arraybuffer",n.send(null),new Uint8Array(n.response)}),c=function e(t,n,r){var i=new XMLHttpRequest;i.open("GET",t,!0),i.responseType="arraybuffer",i.onload=function(){if(200==i.status||0==i.status&&i.response){n(i.response);return}r()},i.onerror=r,i.send(null)},f=function e(t){return document.title=t}),n.print||console.log.bind(console);var O=n.printErr||console.warn.bind(console);Object.assign(n,S),S=null,n.arguments&&(R=n.arguments),n.thisProgram&&(P=n.thisProgram),n.quit&&(D=n.quit),n.wasmBinary&&(d=n.wasmBinary),n.noExitRuntime,("undefined"==typeof WebAssembly?"undefined":t(WebAssembly))!="object"&&q("no native wasm support detected");var I=!1;function N(e,t){return e?function e(t,n,r){for(var i=n+r,o="";!(n>=i);){var a=t[n++];if(!a)break;if(!(128&a)){o+=String.fromCharCode(a);continue}var s=63&t[n++];if((224&a)==192){o+=String.fromCharCode((31&a)<<6|s);continue}var u=63&t[n++];if((a=(240&a)==224?(15&a)<<12|s<<6|u:(7&a)<<18|s<<12|u<<6|63&t[n++])<65536)o+=String.fromCharCode(a);else{var c=a-65536;o+=String.fromCharCode(55296|c>>10,56320|1023&c)}}return o}(y,e,t):""}function F(e){$=e,n.HEAP8=v=new Int8Array(e),n.HEAP16=g=new Int16Array(e),n.HEAP32=_=new Int32Array(e),n.HEAPU8=y=new Uint8Array(e),n.HEAPU16=m=new Uint16Array(e),n.HEAPU32=b=new Uint32Array(e),n.HEAPF32=E=new Float32Array(e),n.HEAPF64=w=new Float64Array(e)}n.INITIAL_MEMORY;var M=[],G=[],B=[],U=!1;function H(e){M.unshift(e)}function W(e){B.unshift(e)}var V=0,j=null,z=null;function q(e){n.onAbort&&n.onAbort(e),O(e="Aborted("+e+")"),I=!0,p=1,e+=". Build with -sASSERTIONS for more info.";var t=new WebAssembly.RuntimeError(e);throw s(t),t}function K(e){return e.startsWith("data:application/octet-stream;base64,")}function Y(e){try{if(e==k&&d)return new Uint8Array(d);if(l)return l(e);throw"both async and sync fetching of the wasm failed"}catch(t){q(t)}}function Z(e){for(;e.length>0;)e.shift()(n)}function J(e){switch(e){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw TypeError("Unknown type size: "+e)}}!K(k="mp4-encoder.wasm")&&(k=(i=k,n.locateFile?n.locateFile(i,C):C+i));var Q=void 0;function X(e){for(var t="",n=e;y[n];)t+=Q[y[n++]];return t}var ee={},et={},en={};function er(e){if(void 0===e)return"_unknown";var t=(e=e.replace(/[^a-zA-Z0-9_]/g,"$")).charCodeAt(0);return t>=48&&t<=57?"_"+e:e}function ei(e,t){return Function("body","return function "+(e=er(e))+'() {\n "use strict"; return body.apply(this, arguments);\n};\n')(t)}function eo(e,t){var n=ei(t,function(e){this.name=t,this.message=e;var n=Error(e).stack;void 0!==n&&(this.stack=this.toString()+"\n"+n.replace(/^Error(:[^\n]*)?\n/,""))});return n.prototype=Object.create(e.prototype),n.prototype.constructor=n,n.prototype.toString=function(){return void 0===this.message?this.name:this.name+": "+this.message},n}var ea=void 0;function es(e){throw new ea(e)}var eu=void 0;function ec(e){throw new eu(e)}function el(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!("argPackAdvance"in t))throw TypeError("registerType registeredInstance requires argPackAdvance");var r=t.name;if(e||es('type "'+r+'" must have a positive integer typeid pointer'),et.hasOwnProperty(e)){if(n.ignoreDuplicateRegistrations)return;es("Cannot register type '"+r+"' twice")}if(et[e]=t,delete en[e],ee.hasOwnProperty(e)){var i=ee[e];delete ee[e],i.forEach(function(e){return e()})}}var ef=[],ed=[{},{value:void 0},{value:null},{value:!0},{value:!1}];function eh(e){e>4&&0==--ed[e].refcount&&(ed[e]=void 0,ef.push(e))}var ep={toValue:function e(t){return t||es("Cannot use deleted val. handle = "+t),ed[t].value},toHandle:function e(t){switch(t){case void 0:return 1;case null:return 2;case!0:return 3;case!1:return 4;default:var n=ef.length?ef.pop():ed.length;return ed[n]={refcount:1,value:t},n}}};function e$(e){return this.fromWireType(_[e>>2])}function ev(e){for(;e.length;){var t=e.pop();e.pop()(t)}}var ey=[];function eg(e){var t=ey[e];return t||(e>=ey.length&&(ey.length=e+1),ey[e]=t=T.get(e)),t}var em=void 0;function e_(e){var t=eL(e),n=X(t);return eD(t),n}function eb(e,t){for(var n="",r=0;!(r>=t/2);++r){var i=g[e+2*r>>1];if(0==i)break;n+=String.fromCharCode(i)}return n}function e8(e,t,n){if(void 0===n&&(n=2147483647),n<2)return 0;for(var r=t,i=(n-=2)<2*e.length?n/2:e.length,o=0;o>1]=a,t+=2}return g[t>>1]=0,t-r}function eE(e){return 2*e.length}function ew(e,t){for(var n=0,r="";!(n>=t/4);){var i=_[e+4*n>>2];if(0==i)break;if(++n,i>=65536){var o=i-65536;r+=String.fromCharCode(55296|o>>10,56320|1023&o)}else r+=String.fromCharCode(i)}return r}function e0(e,t,n){if(void 0===n&&(n=2147483647),n<4)return 0;for(var r=t,i=r+n-4,o=0;o=55296&&a<=57343&&(a=65536+((1023&a)<<10)|1023&e.charCodeAt(++o)),_[t>>2]=a,(t+=4)+4>i)break}return _[t>>2]=0,t-r}function eT(e){for(var t=0,n=0;n=55296&&r<=57343&&++n,t+=4}return t}function ek(e,t){var n=et[e];return void 0===n&&es(t+" has unknown type "+e_(e)),n}var eA={};function eS(e){try{return h.grow(e-$.byteLength+65535>>>16),F(h.buffer),1}catch(t){}}(function e(){for(var t=Array(256),n=0;n<256;++n)t[n]=String.fromCharCode(n);Q=t})(),ea=n.BindingError=eo(Error,"BindingError"),eu=n.InternalError=eo(Error,"InternalError"),n.count_emval_handles=function e(){for(var t=0,n=5;n>a])},destructorFunction:null})},t:function e(t,n){n=X(n),el(t,{name:n,fromWireType:function e(t){var n=ep.toValue(t);return eh(t),n},toWireType:function e(t,n){return ep.toHandle(n)},argPackAdvance:8,readValueFromPointer:e$,destructorFunction:null})},o:function e(t,n,r){var i=J(r);n=X(n),el(t,{name:n,fromWireType:function e(t){return t},toWireType:function e(t,n){return n},argPackAdvance:8,readValueFromPointer:function e(t,n){switch(n){case 2:return function(e){return this.fromWireType(E[e>>2])};case 3:return function(e){return this.fromWireType(w[e>>3])};default:throw TypeError("Unknown float type: "+t)}}(n,i),destructorFunction:null})},h:function e(r,i,o,a,s,u){var c,l,f,d,h,p,$=function e(t,n){for(var r=[],i=0;i>2]);return r}(i,o);r=X(r),s=(c=a,l=s,c=X(c),"function"!=typeof(f=function e(){if(c.includes("j")){var t,r,i;return t=c,r=l,i=[],function(){var e,o,a,s,u,c,l;return i.length=0,Object.assign(i,arguments),e=t,o=r,a=i,e.includes("j")?(s=e,u=o,c=a,l=n["dynCall_"+s],c&&c.length?l.apply(null,[u].concat(c)):l.call(null,u)):eg(o).apply(null,a)}}return eg(l)}())&&es("unknown function pointer with signature "+c+": "+l),f),d=r,h=function(){!function e(t,n){var r=[],i={};function o(e){if(!i[e]&&!et[e]){if(en[e]){en[e].forEach(o);return}r.push(e),i[e]=!0}}throw n.forEach(o),new em(t+": "+r.map(e_).join([", "]))}("Cannot call "+r+" due to unbound types",$)},p=i-1,n.hasOwnProperty(d)?((void 0===p||void 0!==n[d].overloadTable&&void 0!==n[d].overloadTable[p])&&es("Cannot register public name '"+d+"' twice"),function e(t,n,r){if(void 0===t[n].overloadTable){var i=t[n];t[n]=function(){return t[n].overloadTable.hasOwnProperty(arguments.length)||es("Function '"+r+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+t[n].overloadTable+")!"),t[n].overloadTable[arguments.length].apply(this,arguments)},t[n].overloadTable=[],t[n].overloadTable[i.argCount]=i}}(n,d,d),n.hasOwnProperty(p)&&es("Cannot register multiple overloads of a function with the same number of arguments ("+p+")!"),n[d].overloadTable[p]=h):(n[d]=h,void 0!==p&&(n[d].numArguments=p)),function e(t,n,r){function i(e){var n=r(e);n.length!==t.length&&ec("Mismatched type converter count");for(var i=0;i0?", ":"")+h),p+=(f?"var rv = ":"")+"invoker(fn"+(h.length>0?", ":"")+h+");\n",c)p+="runDestructors(destructors);\n";else for(var l=u?1:2;l>>c}}var l=n.includes("unsigned"),f=function e(t,n){};a=l?function e(t,n){return f(n,this.name),n>>>0}:function e(t,n){return f(n,this.name),n},el(t,{name:n,fromWireType:u,toWireType:a,argPackAdvance:8,readValueFromPointer:function e(t,n,r){switch(n){case 0:return r?function e(t){return v[t]}:function e(t){return y[t]};case 1:return r?function e(t){return g[t>>1]}:function e(t){return m[t>>1]};case 2:return r?function e(t){return _[t>>2]}:function e(t){return b[t>>2]};default:throw TypeError("Unknown integer type: "+t)}}(n,s,0!==i),destructorFunction:null})},c:function e(t,n,r){var i=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array][n];function o(e){var t=b,n=t[e>>=2],r=t[e+1];return new i($,r,n)}r=X(r),el(t,{name:r,fromWireType:o,argPackAdvance:8,readValueFromPointer:o},{ignoreDuplicateRegistrations:!0})},n:function e(t,n){var r="std::string"===(n=X(n));el(t,{name:n,fromWireType:function e(t){var n,i=b[t>>2],o=t+4;if(r)for(var a=o,s=0;s<=i;++s){var u=o+s;if(s==i||0==y[u]){var c=u-a,l=N(a,c);void 0===n?n=l:(n+="\0",n+=l),a=u+1}}else{for(var f=Array(i),s=0;s=55296&&i<=57343?(n+=4,++r):n+=3}return n}(n):n.length)+1),l=c+4;if(b[c>>2]=s,r&&u)i=n,o=l,function e(t,n,r,i){if(!(i>0))return 0;for(var o=r,a=r+i-1,s=0;s=55296&&u<=57343&&(u=65536+((1023&u)<<10)|1023&t.charCodeAt(++s)),u<=127){if(r>=a)break;n[r++]=u}else if(u<=2047){if(r+1>=a)break;n[r++]=192|u>>6,n[r++]=128|63&u}else if(u<=65535){if(r+2>=a)break;n[r++]=224|u>>12,n[r++]=128|u>>6&63,n[r++]=128|63&u}else{if(r+3>=a)break;n[r++]=240|u>>18,n[r++]=128|u>>12&63,n[r++]=128|u>>6&63,n[r++]=128|63&u}}return n[r]=0,r-o}(i,y,o,a=s+1);else if(u)for(var f=0;f255&&(eD(l),es("String has UTF-16 code units that do not fit in 8 bits")),y[l+f]=d}else for(var f=0;f>2],s=a(),c=t+4,l=0;l<=o;++l){var f=t+4+l*n;if(l==o||0==s[f>>u]){var d=f-c,h=i(c,d);void 0===r?r=h:(r+="\0",r+=h),c=f+n}}return eD(t),r},toWireType:function e(t,i){"string"!=typeof i&&es("Cannot pass non-string to C++ string type "+r);var a=s(i),c=e3(4+a+n);return b[c>>2]=a>>u,o(i,c+4,a+n),null!==t&&t.push(eD,c),c},argPackAdvance:8,readValueFromPointer:e$,destructorFunction:function e(t){eD(t)}})},v:function e(t,n){n=X(n),el(t,{isVoid:!0,name:n,argPackAdvance:0,fromWireType:function e(){},toWireType:function e(t,n){}})},k:function e(t,n,r){t=ep.toValue(t),n=ek(n,"emval::as");var i=[],o=ep.toHandle(i);return b[r>>2]=o,n.toWireType(i,t)},w:function e(t,n,r,i){t=ep.toValue(t);for(var o=function e(t,n){for(var r=Array(t),i=0;i>2],"parameter "+i);return r}(n,r),a=Array(n),s=0;s4&&(ed[t].refcount+=1)},p:function e(t){return"number"==typeof(t=ep.toValue(t))},f:function e(t){var n,r;return ep.toHandle(void 0===(r=eA[n=t])?X(n):r)},j:function e(t){ev(ep.toValue(t)),eh(t)},i:function e(t,n){var r=(t=ek(t,"_emval_take_value")).readValueFromPointer(n);return ep.toHandle(r)},m:function e(){q("")},s:function e(t,n,r){y.copyWithin(t,n,n+r)},r:function e(t){var n=y.length;if((t>>>=0)>2147483648)return!1;for(var r=1;r<=4;r*=2){var i,o,a=n*(1+.2/r);if(a=Math.min(a,t+100663296),eS(Math.min(2147483648,(i=Math.max(t,a))+(65536-i%65536)%65536)))return!0}return!1}};(function e(){var t={a:eR};function r(e,t){var r,i=e.exports;n.asm=i,F((h=n.asm.x).buffer),T=n.asm.B,r=n.asm.y,G.unshift(r),function e(t){if(V--,n.monitorRunDependencies&&n.monitorRunDependencies(V),0==V&&(null!==j&&(clearInterval(j),j=null),z)){var r=z;z=null,r()}}("wasm-instantiate")}function i(e){r(e.instance)}function o(e){return(!d&&(L||x)&&"function"==typeof fetch?fetch(k,{credentials:"same-origin"}).then(function(e){if(!e.ok)throw"failed to load wasm binary file at '"+k+"'";return e.arrayBuffer()}).catch(function(){return Y(k)}):Promise.resolve().then(function(){return Y(k)})).then(function(e){return WebAssembly.instantiate(e,t)}).then(function(e){return e}).then(e,function(e){O("failed to asynchronously prepare wasm: "+e),q(e)})}if(V++,n.monitorRunDependencies&&n.monitorRunDependencies(V),n.instantiateWasm)try{return n.instantiateWasm(t,r)}catch(a){O("Module.instantiateWasm callback failed with error: "+a),s(a)}return(d||"function"!=typeof WebAssembly.instantiateStreaming||K(k)||"function"!=typeof fetch?o(i):fetch(k,{credentials:"same-origin"}).then(function(e){return WebAssembly.instantiateStreaming(e,t).then(i,function(e){return O("wasm streaming compile failed: "+e),O("falling back to ArrayBuffer instantiation"),o(i)})})).catch(s),{}})();var eP=n.___wasm_call_ctors=function(){return(eP=n.___wasm_call_ctors=n.asm.y).apply(null,arguments)},e3=n._malloc=function(){return(e3=n._malloc=n.asm.z).apply(null,arguments)},eD=n._free=function(){return(eD=n._free=n.asm.A).apply(null,arguments)},eL=n.___getTypeName=function(){return(eL=n.___getTypeName=n.asm.C).apply(null,arguments)},ex=n.__embind_initialize_bindings=function(){return(ex=n.__embind_initialize_bindings=n.asm.D).apply(null,arguments)},e2=n.dynCall_ijiii=function(){return(e2=n.dynCall_ijiii=n.asm.E).apply(null,arguments)};function eC(e){if(e=e||R,!(V>0))(function e(){if(n.preRun)for("function"==typeof n.preRun&&(n.preRun=[n.preRun]);n.preRun.length;)H(n.preRun.shift());Z(M)})(),!(V>0)&&(n.setStatus?(n.setStatus("Running..."),setTimeout(function(){setTimeout(function(){n.setStatus("")},1),t()},1)):t());function t(){!A&&(A=!0,n.calledRun=!0,I||(U=!0,Z(G),o(n),n.onRuntimeInitialized&&n.onRuntimeInitialized(),function e(){if(n.postRun)for("function"==typeof n.postRun&&(n.postRun=[n.postRun]);n.postRun.length;)W(n.postRun.shift());Z(B)}()))}}if(z=function e(){A||eC(),A||(z=e)},n.preInit)for("function"==typeof n.preInit&&(n.preInit=[n.preInit]);n.preInit.length>0;)n.preInit.pop()();return eC(),n.ready});function o(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:256,t=0,n=0,r=new Uint8Array(e);return{contents:function e(){return r.slice(0,n)},seek:function e(n){t=n},write:function e(i){var o=i.byteLength;return function e(t){var i=r.length;if(!(i>=t)){t=Math.max(t,i*(i<1048576?2:1.125)>>>0),0!=i&&(t=Math.max(t,256));var o=r;r=new Uint8Array(t),n>0&&r.set(o.subarray(0,n),0)}}(t+o),r.set(i,t),t+=o,n=Math.max(n,t),o}}}function a(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.width,r=t.height,i=t.fps,a=t.fragmentation,s=t.sequential,u=t.hevc;if("number"!=typeof n||"number"!=typeof r)throw Error("Must specify { width, height } options");if(!isFinite(n)||n<0||!isFinite(r)||r<0)throw Error("{ width, height } options must be positive integers");var c=o(),l=e.create_muxer({width:n,height:r,fps:void 0===i?30:i,fragmentation:void 0!==a&&a,sequential:void 0!==s&&s,hevc:void 0!==u&&u},function t(n,r,i){c.seek(i);var o=e.HEAPU8.subarray(n,n+r);return c.write(o)!==o.byteLength});return{end:function t(){return e.finalize_muxer(l),c.contents()},addNalu:function t(n){var r=e._malloc(n.byteLength);e.HEAPU8.set(n,r),e.mux_nal(l,r,n.byteLength),e._free(r)}}}n.default=i,i.createFile=o}).call(this)}).call(this,e("_process"))},{_process:2}],18:[function(e,t,n){"use strict";"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||(ArrayBuffer.prototype.slice=function(e,t){var n=new Uint8Array(this);void 0===t&&(t=n.length);for(var r=new ArrayBuffer(t-e),i=new Uint8Array(r),o=0;o=200&&r<300){i.tload=Math.max(i.tfirst,performance.now()),u="arraybuffer"===o.responseType?(s=n.response).byteLength:(s=n.responseText).length,i.loaded=i.total=u;var s,u,c={url:n.responseURL,data:s};this.callbacks.onSuccess(c,i,o)}else i.retry>=a.maxRetry||r>=400&&r<499?this.callbacks.onError({code:r,text:n.statusText},o):(this.destroy(),this.retryTimeout=window.setTimeout(this.loadInternal.bind(this),this.retryDelay),this.retryDelay=Math.min(2*this.retryDelay,a.maxRetryDelay),i.retry++)}}},{key:"loadtimeout",value:function e(){this.callbacks.onTimeout(this.stats,this.context)}},{key:"loadprogress",value:function e(t){var n=this.stats;0===n.tfirst&&(n.tfirst=Math.max(performance.now(),n.trequest)),n.loaded=t.loaded,t.lengthComputable&&(n.total=t.total);var r=this.callbacks.onProgress;r&&r(n,this.context,null)}}],r(e.prototype,t),n&&r(e,n),Object.defineProperty(e,"prototype",{writable:!1}),i}();n.default=i},{}],20:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var r=e("./errors"),i=l(e("./events")),o=l(e("./controller/flow-controller")),a=l(e("./controller/buffer-controller")),s=l(e("events")),u=l(e("./utils/xhr-loader"));l(e("./loader/file-loader"));var c=l(e("./loader/websocket-loader"));function l(e){return e&&e.__esModule?e:{default:e}}function f(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:{};!function e(t,n){if(!(t instanceof n))throw TypeError("Cannot call a class as a function")}(this,l);var t=l.DefaultConfig;for(var n in t)!(n in e)&&(e[n]=t[n]);this.config=e;var r=this.observer=new s.default;r.trigger=function e(t){for(var n=arguments.length,i=Array(n>1?n-1:0),o=1;o1?n-1:0),o=1;o1&&void 0!==arguments[1]?arguments[1]:"chX",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"H264Raw",o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"play2",a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:void 0;this.mediaType=r,this.media=t,this.extraData=a;var s=void 0;s="MJPEG"===r?i.default.MEDIA_ATTACHED:i.default.MEDIA_ATTACHING,this.trigger(s,{media:t,channelName:n,mediaType:r,websocketName:o,extraData:this.extraData})}},{key:"attachWebsocket",value:function e(t,n,r){this.trigger(i.default.WEBSOCKET_ATTACHING,{websocket:t,websocketName:n,media:this.media,mediaType:this.mediaType,channelName:r,extraData:this.extraData})}},{key:"start_recording",value:function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1073741824,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this.trigger(i.default.RECORDING_START,{rec_file_threshold:t,result_cb:n,state_cb:r})}},{key:"playerSeekNow",value:function e(){this.trigger(i.default.PLAYER_SEEK_NOW)}},{key:"stop_recording",value:function e(){this.trigger(i.default.RECORDING_STOP)}}],n=[{key:"version",get:function e(){return"v.0.0.0.1"}},{key:"isSupported",value:function e(){return window.MediaSource&&"function"==typeof window.MediaSource.isTypeSupported&&window.MediaSource.isTypeSupported('video/mp4; codecs="avc1.42c01f,mp4a.40.2"')}},{key:"Events",get:function e(){return i.default}},{key:"ErrorTypes",get:function e(){return r.ErrorTypes}},{key:"ErrorDetails",get:function e(){return r.ErrorDetails}},{key:"DefaultConfig",get:function e(){return l.defaultConfig||(l.defaultConfig={autoStartLoad:!0,startPosition:-1,debug:!1,fLoader:void 0,loader:u.default,fmp4FileUrl:"xxxx.mp4",fragLoadingTimeOut:2e4,fragLoadingMaxRetry:6,fragLoadingRetryDelay:1e3,fragLoadingMaxRetryTimeout:64e3,fragLoadingLoopThreshold:3,forceKeyFrameOnDiscontinuity:!0,appendErrorMaxRetry:3,wsMinPacketInterval:3e3,wsMaxPacketInterval:3e4,mp4Duration:1e3}),l.defaultConfig},set:function e(t){l.defaultConfig=t}}],t&&f(e.prototype,t),n&&f(e,n),Object.defineProperty(e,"prototype",{writable:!1}),l}();n.default=d},{"./controller/buffer-controller":3,"./controller/flow-controller":4,"./errors":7,"./events":9,"./loader/file-loader":12,"./loader/websocket-loader":13,"./utils/xhr-loader":19,events:1}]},{},[11])(11)});