!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function r(e,r){return e(r={exports:{}},r.exports),r.exports}var t=e(r((function(e){e.exports=function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")},e.exports.__esModule=!0,e.exports.default=e.exports}))),o=r((function(e){function r(t){return e.exports=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.exports.__esModule=!0,e.exports.default=e.exports,r(t)}e.exports=r,e.exports.__esModule=!0,e.exports.default=e.exports})),n=e(o),i=r((function(e){var r=o.default;e.exports=function(e,t){if("object"!==r(e)||null===e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var n=o.call(e,t||"default");if("object"!==r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)},e.exports.__esModule=!0,e.exports.default=e.exports}));e(i);var u=r((function(e){var r=o.default;e.exports=function(e){var t=i(e,"string");return"symbol"===r(t)?t:String(t)},e.exports.__esModule=!0,e.exports.default=e.exports}));e(u);var d=e(r((function(e){function r(e,r){for(var t=0;t1?t-1:0),n=1;n1?n-1:0),u=1;u1?n-1:0),u=1;u1?n-1:0),u=1;u0&&void 0!==arguments[0]?arguments[0]:{};t(this,o),(e=r.call(this))._opt={},Object.keys(n).forEach((function(e){if(void 0===n[e])throw new Error('JbProMp4Recorder option "'.concat(e,'" can not be undefined'))})),e.originalOptions=n;var i=U(),u=Object.assign({},i,n);return e._opt=u,e.isRecording=!1,e.debug=new B(s(e)),e.worker=null,e.startTimestamp=null,e.TAG_NAME="Recorder",e.debug.log(e.TAG_NAME,"init",JSON.stringify(e._opt)),e}return d(o,[{key:"destroy",value:function(){this._reset(),this._destroyWorker()}},{key:"_reset",value:function(){this.isRecording=!1,this.startTimestamp=null}},{key:"_destroyWorker",value:function(){this.worker&&(this.worker.destroy(),this.worker=null)}},{key:"startRecord",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return new Promise((function(t,o){e.debug.log(e.TAG_NAME,"startRecord",JSON.stringify(r));var n=!!r.audio,i=!!r.video;if(L(i)&&L(n))return e.debug.error(e.TAG_NAME,"video and audio can not be false at the same time"),void o("video and audio can not be false at the same time");if(n){if(F(r.audio.type))return e.debug.error(e.TAG_NAME,"audio type can not be undefined"),void o("audio type can not be undefined");if(F(r.audio.extraData))return e.debug.error(e.TAG_NAME,"audio extraData can not be undefined"),void o("audio extraData can not be undefined");if(F(r.audio.sampleRate))return e.debug.error(e.TAG_NAME,"audio extraData can not be undefined"),void o("audio extraData can not be undefined");if(F(r.audio.channels))return e.debug.error(e.TAG_NAME,"audio channels can not be undefined"),void o("audio channels can not be undefined");if(F(r.audio.depth))return e.debug.error(e.TAG_NAME,"audio depth can not be undefined"),void o("audio depth can not be undefined")}if(i){if(F(r.video.type))return e.debug.error(e.TAG_NAME,"video type can not be undefined"),void o("video type can not be undefined");if(F(r.video.extraData))return e.debug.error(e.TAG_NAME,"video extraData can not be undefined"),void o("video extraData can not be undefined");if(F(r.video.width))return e.debug.error(e.TAG_NAME,"video width can not be undefined"),void o("video width can not be undefined");if(F(r.video.height))return e.debug.error(e.TAG_NAME,"video height can not be undefined"),void o("video height can not be undefined")}e.worker?e._startRecord(r,t,o):(e.worker=new I(e),e.worker.once(G,(function(){e._startRecord(r,t,o),e.startTimestamp=Date.now()})),e.worker.once(W,(function(e){o(e)})),e.worker.on(J,(function(r){e.emit(J,r)})))}))}},{key:"_startRecord",value:function(){var e=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0,o=arguments.length>2?arguments[2]:void 0;this.worker.startRecord(r),this.worker.once(P,(function(r){e.debug.error(e.TAG_NAME,"startRecordError",r),o(r)})),this.worker.once(j,(function(){e.isRecording=!0,e.debug.log(e.TAG_NAME,"startRecordSuccess"),t()}))}},{key:"stopRecord",value:function(){var e=this;return new Promise((function(r,t){e.debug.log(e.TAG_NAME,"stopRecord"),L(e.isRecording)&&(e._destroyWorker(),e.debug.error(e.TAG_NAME,"isRecording is false"),t("isRecording is false")),e.isRecording=!1,e.worker.stopRecord(),e.worker.once(S,(function(r){e._destroyWorker(),e.debug.error(e.TAG_NAME,"stopRecordError",r),t(r)})),e.worker.once(D,(function(t){e._destroyWorker(),e.debug.log(e.TAG_NAME,"recordEnd");var o=new Blob([t.buffer],{type:"video/mp4"});r(o)}))}))}},{key:"sendVideoFrame",value:function(e,r,t,o){if(this.isRecording&&this.worker){if(Date.now()-this.startTimestamp>6e5)return;var n=t+o;this.worker.sendVideoFrame(e,r,t,n)}}},{key:"sendAudioFrame",value:function(e,r){if(this.isRecording&&this.worker){if(Date.now()-this.startTimestamp>6e5)return;this.worker.sendAudioFrame(e,r)}}}]),o}(v);window.JessibucaProMp4Recorder=q}));