surveyjs-widgets
Version:
Custom widgets for the SurveyJS library
2 lines • 98.7 kB
JavaScript
/*! For license information please see surveyjs-widgets.min.js.LICENSE.txt */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("inputmask"),require("nouislider"),require("sortablejs"),require("bootstrap-slider")):"function"==typeof define&&define.amd?define("surveyjs-widgets",["inputmask","nouislider","sortablejs","bootstrap-slider"],t):"object"==typeof exports?exports["surveyjs-widgets"]=t(require("inputmask"),require("nouislider"),require("sortablejs"),require("bootstrap-slider")):e["surveyjs-widgets"]=t(e.Inputmask,e.noUiSlider,e.Sortable,e.Slider)}(self,((e,t,i,n)=>(()=>{var a={212:(e,t,i)=>{"use strict";var n,a;function o(e,t){if(!e)throw"First parameter is required.";t=new r(e,t=t||{type:"video"});var i=this;function n(i){i&&(t.initCallback=function(){i(),i=t.initCallback=null});var n=new s(e,t);(f=new n(e,t)).record(),u("recording"),t.disableLogs||console.log("Initialized recorderType:",f.constructor.name,"for output-type:",t.type)}function a(e){if(e=e||function(){},f){if("paused"===i.state)return i.resumeRecording(),void setTimeout((function(){a(e)}),1);"recording"===i.state||t.disableLogs||console.warn('Recording state should be: "recording", however current state is: ',i.state),t.disableLogs||console.log("Stopped recording "+t.type+" stream."),"gif"!==t.type?f.stop(n):(f.stop(),n()),u("stopped")}else g();function n(n){if(f){Object.keys(f).forEach((function(e){"function"!=typeof f[e]&&(i[e]=f[e])}));var a=f.blob;if(!a){if(!n)throw"Recording failed.";f.blob=a=n}if(a&&!t.disableLogs&&console.log(a.type,"->",w(a.size)),e){var o;try{o=m.createObjectURL(a)}catch(e){}"function"==typeof e.call?e.call(i,o):e(o)}t.autoWriteToDisk&&c((function(e){var i={};i[t.type+"Blob"]=e,I.Store(i)}))}else"function"==typeof e.call?e.call(i,""):e("")}}function d(e){postMessage((new FileReaderSync).readAsDataURL(e))}function c(e,i){if(!e)throw"Pass a callback function over getDataURL.";var n=i?i.blob:(f||{}).blob;if(!n)return t.disableLogs||console.warn("Blob encoder did not finish its job yet."),void setTimeout((function(){c(e,i)}),1e3);if("undefined"==typeof Worker||navigator.mozGetUserMedia){var a=new FileReader;a.readAsDataURL(n),a.onload=function(t){e(t.target.result)}}else{var o=function(e){try{var t=m.createObjectURL(new Blob([e.toString(),"this.onmessage = function (eee) {"+e.name+"(eee.data);}"],{type:"application/javascript"})),i=new Worker(t);return m.revokeObjectURL(t),i}catch(e){}}(d);o.onmessage=function(t){e(t.data)},o.postMessage(n)}}function l(e){e=e||0,"paused"!==i.state?"stopped"!==i.state&&(e>=i.recordingDuration?a(i.onRecordingStopped):(e+=1e3,setTimeout((function(){l(e)}),1e3))):setTimeout((function(){l(e)}),1e3)}function u(e){i&&(i.state=e,"function"==typeof i.onStateChanged.call?i.onStateChanged.call(i,e):i.onStateChanged(e))}var f,p='It seems that recorder is destroyed or "startRecording" is not invoked for '+t.type+" recorder.";function g(){!0!==t.disableLogs&&console.warn(p)}var h={startRecording:function(a){return t.disableLogs||console.log("RecordRTC version: ",i.version),a&&(t=new r(e,a)),t.disableLogs||console.log("started recording "+t.type+" stream."),f?(f.clearRecordedData(),f.record(),u("recording"),i.recordingDuration&&l(),i):(n((function(){i.recordingDuration&&l()})),i)},stopRecording:a,pauseRecording:function(){f?"recording"===i.state?(u("paused"),f.pause(),t.disableLogs||console.log("Paused recording.")):t.disableLogs||console.warn("Unable to pause the recording. Recording state: ",i.state):g()},resumeRecording:function(){f?"paused"===i.state?(u("recording"),f.resume(),t.disableLogs||console.log("Resumed recording.")):t.disableLogs||console.warn("Unable to resume the recording. Recording state: ",i.state):g()},initRecorder:n,setRecordingDuration:function(e,t){if(void 0===e)throw"recordingDuration is required.";if("number"!=typeof e)throw"recordingDuration must be a number.";return i.recordingDuration=e,i.onRecordingStopped=t||function(){},{onRecordingStopped:function(e){i.onRecordingStopped=e}}},clearRecordedData:function(){f?(f.clearRecordedData(),t.disableLogs||console.log("Cleared old recorded data.")):g()},getBlob:function(){if(f)return f.blob;g()},getDataURL:c,toURL:function(){if(f)return m.createObjectURL(f.blob);g()},getInternalRecorder:function(){return f},save:function(e){f?C(f.blob,e):g()},getFromDisk:function(e){f?o.getFromDisk(t.type,e):g()},setAdvertisementArray:function(e){t.advertisement=[];for(var i=e.length,n=0;n<i;n++)t.advertisement.push({duration:n,image:e[n]})},blob:null,bufferSize:0,sampleRate:0,buffer:null,reset:function(){"recording"!==i.state||t.disableLogs||console.warn("Stop an active recorder."),f&&"function"==typeof f.clearRecordedData&&f.clearRecordedData(),f=null,u("inactive"),i.blob=null},onStateChanged:function(e){t.disableLogs||console.log("Recorder state changed:",e)},state:"inactive",getState:function(){return i.state},destroy:function(){var e=t.disableLogs;t={disableLogs:!0},i.reset(),u("destroyed"),h=i=null,x.AudioContextConstructor&&(x.AudioContextConstructor.close(),x.AudioContextConstructor=null),t.disableLogs=e,t.disableLogs||console.log("RecordRTC is destroyed.")},version:"5.6.2"};if(!this)return i=h,h;for(var v in h)this[v]=h[v];return i=this,h}function r(e,t){return t.recorderType||t.type||(t.audio&&t.video?t.type="video":t.audio&&!t.video&&(t.type="audio")),t.recorderType&&!t.type&&(t.recorderType===O||t.recorderType===D||t.recorderType===F?t.type="video":t.recorderType===E?t.type="gif":t.recorderType===A?t.type="audio":t.recorderType===M&&(R(e,"audio").length&&R(e,"video").length||!R(e,"audio").length&&R(e,"video").length?t.type="video":R(e,"audio").length&&!R(e,"video").length&&(t.type="audio"))),"undefined"!=typeof MediaRecorder&&"requestData"in MediaRecorder.prototype&&(t.mimeType||(t.mimeType="video/webm"),t.type||(t.type=t.mimeType.split("/")[0]),t.bitsPerSecond),t.type||(t.mimeType&&(t.type=t.mimeType.split("/")[0]),t.type||(t.type="audio")),t}function s(e,t){var i;return(v||p||g)&&(i=A),"undefined"!=typeof MediaRecorder&&"requestData"in MediaRecorder.prototype&&!v&&(i=M),"video"===t.type&&(v||g)&&(i=O,"undefined"!=typeof ReadableStream&&(i=F)),"gif"===t.type&&(i=E),"canvas"===t.type&&(i=D),T()&&i!==D&&i!==E&&"undefined"!=typeof MediaRecorder&&"requestData"in MediaRecorder.prototype&&(R(e,"video").length||R(e,"audio").length)&&("audio"===t.type?"function"==typeof MediaRecorder.isTypeSupported&&MediaRecorder.isTypeSupported("audio/webm")&&(i=M):"function"==typeof MediaRecorder.isTypeSupported&&MediaRecorder.isTypeSupported("video/webm")&&(i=M)),e instanceof Array&&e.length&&(i=U),t.recorderType&&(i=t.recorderType),!t.disableLogs&&i&&i.name&&console.log("Using recorderType:",i.name||i.constructor.name),!i&&y&&(i=M),i}function d(e){this.addStream=function(t){t&&(e=t)},this.mediaType={audio:!0,video:!0},this.startRecording=function(){var t,i=this.mediaType,n=this.mimeType||{audio:null,video:null,gif:null};if("function"!=typeof i.audio&&T()&&!R(e,"audio").length&&(i.audio=!1),"function"!=typeof i.video&&T()&&!R(e,"video").length&&(i.video=!1),"function"!=typeof i.gif&&T()&&!R(e,"video").length&&(i.gif=!1),!i.audio&&!i.video&&!i.gif)throw"MediaStream must have either audio or video tracks.";if(i.audio&&(t=null,"function"==typeof i.audio&&(t=i.audio),this.audioRecorder=new o(e,{type:"audio",bufferSize:this.bufferSize,sampleRate:this.sampleRate,numberOfAudioChannels:this.numberOfAudioChannels||2,disableLogs:this.disableLogs,recorderType:t,mimeType:n.audio,timeSlice:this.timeSlice,onTimeStamp:this.onTimeStamp}),i.video||this.audioRecorder.startRecording()),i.video){t=null,"function"==typeof i.video&&(t=i.video);var a=e;if(T()&&i.audio&&"function"==typeof i.audio){var r=R(e,"video")[0];h?((a=new b).addTrack(r),t&&t===O&&(t=M)):(a=new b).addTrack(r)}this.videoRecorder=new o(a,{type:"video",video:this.video,canvas:this.canvas,frameInterval:this.frameInterval||10,disableLogs:this.disableLogs,recorderType:t,mimeType:n.video,timeSlice:this.timeSlice,onTimeStamp:this.onTimeStamp,workerPath:this.workerPath,webAssemblyPath:this.webAssemblyPath,frameRate:this.frameRate,bitrate:this.bitrate}),i.audio||this.videoRecorder.startRecording()}if(i.audio&&i.video){var s=this,d=!0===T();(i.audio instanceof A&&i.video||!0!==i.audio&&!0!==i.video&&i.audio!==i.video)&&(d=!1),!0===d?(s.audioRecorder=null,s.videoRecorder.startRecording()):s.videoRecorder.initRecorder((function(){s.audioRecorder.initRecorder((function(){s.videoRecorder.startRecording(),s.audioRecorder.startRecording()}))}))}i.gif&&(t=null,"function"==typeof i.gif&&(t=i.gif),this.gifRecorder=new o(e,{type:"gif",frameRate:this.frameRate||200,quality:this.quality||10,disableLogs:this.disableLogs,recorderType:t,mimeType:n.gif}),this.gifRecorder.startRecording())},this.stopRecording=function(e){e=e||function(){},this.audioRecorder&&this.audioRecorder.stopRecording((function(t){e(t,"audio")})),this.videoRecorder&&this.videoRecorder.stopRecording((function(t){e(t,"video")})),this.gifRecorder&&this.gifRecorder.stopRecording((function(t){e(t,"gif")}))},this.pauseRecording=function(){this.audioRecorder&&this.audioRecorder.pauseRecording(),this.videoRecorder&&this.videoRecorder.pauseRecording(),this.gifRecorder&&this.gifRecorder.pauseRecording()},this.resumeRecording=function(){this.audioRecorder&&this.audioRecorder.resumeRecording(),this.videoRecorder&&this.videoRecorder.resumeRecording(),this.gifRecorder&&this.gifRecorder.resumeRecording()},this.getBlob=function(e){var t={};return this.audioRecorder&&(t.audio=this.audioRecorder.getBlob()),this.videoRecorder&&(t.video=this.videoRecorder.getBlob()),this.gifRecorder&&(t.gif=this.gifRecorder.getBlob()),e&&e(t),t},this.destroy=function(){this.audioRecorder&&(this.audioRecorder.destroy(),this.audioRecorder=null),this.videoRecorder&&(this.videoRecorder.destroy(),this.videoRecorder=null),this.gifRecorder&&(this.gifRecorder.destroy(),this.gifRecorder=null)},this.getDataURL=function(e){function t(e,t){if("undefined"!=typeof Worker){var i=function(e){var t,i=m.createObjectURL(new Blob([e.toString(),"this.onmessage = function (eee) {"+e.name+"(eee.data);}"],{type:"application/javascript"})),n=new Worker(i);if(void 0!==m)t=m;else{if("undefined"==typeof webkitURL)throw"Neither URL nor webkitURL detected.";t=webkitURL}return t.revokeObjectURL(i),n}((function(e){postMessage((new FileReaderSync).readAsDataURL(e))}));i.onmessage=function(e){t(e.data)},i.postMessage(e)}else{var n=new FileReader;n.readAsDataURL(e),n.onload=function(e){t(e.target.result)}}}this.getBlob((function(i){i.audio&&i.video?t(i.audio,(function(n){t(i.video,(function(t){e({audio:n,video:t})}))})):i.audio?t(i.audio,(function(t){e({audio:t})})):i.video&&t(i.video,(function(t){e({video:t})}))}))},this.writeToDisk=function(){o.writeToDisk({audio:this.audioRecorder,video:this.videoRecorder,gif:this.gifRecorder})},this.save=function(e){(e=e||{audio:!0,video:!0,gif:!0}).audio&&this.audioRecorder&&this.audioRecorder.save("string"==typeof e.audio?e.audio:""),e.video&&this.videoRecorder&&this.videoRecorder.save("string"==typeof e.video?e.video:""),e.gif&&this.gifRecorder&&this.gifRecorder.save("string"==typeof e.gif?e.gif:"")}}o.version="5.6.2",e.exports=o,void 0===(n=function(){return o}.apply(t,[]))||(e.exports=n),o.getFromDisk=function(e,t){if(!t)throw"callback is mandatory.";console.log("Getting recorded "+("all"===e?"blobs":e+" blob ")+" from disk!"),I.Fetch((function(i,n){"all"!==e&&n===e+"Blob"&&t&&t(i),"all"===e&&t&&t(i,n.replace("Blob",""))}))},o.writeToDisk=function(e){console.log("Writing recorded blob(s) to disk!"),(e=e||{}).audio&&e.video&&e.gif?e.audio.getDataURL((function(t){e.video.getDataURL((function(i){e.gif.getDataURL((function(e){I.Store({audioBlob:t,videoBlob:i,gifBlob:e})}))}))})):e.audio&&e.video?e.audio.getDataURL((function(t){e.video.getDataURL((function(e){I.Store({audioBlob:t,videoBlob:e})}))})):e.audio&&e.gif?e.audio.getDataURL((function(t){e.gif.getDataURL((function(e){I.Store({audioBlob:t,gifBlob:e})}))})):e.video&&e.gif?e.video.getDataURL((function(t){e.gif.getDataURL((function(e){I.Store({videoBlob:t,gifBlob:e})}))})):e.audio?e.audio.getDataURL((function(e){I.Store({audioBlob:e})})):e.video?e.video.getDataURL((function(e){I.Store({videoBlob:e})})):e.gif&&e.gif.getDataURL((function(e){I.Store({gifBlob:e})}))},d.getFromDisk=o.getFromDisk,d.writeToDisk=o.writeToDisk,o.MRecordRTC=d,(a=void 0!==i.g?i.g:null)&&"undefined"==typeof window&&void 0!==i.g&&(i.g.navigator={userAgent:"Fake/5.0 (FakeOS) AppleWebKit/123 (KHTML, like Gecko) Fake/12.3.4567.89 Fake/123.45",getUserMedia:function(){}},i.g.console||(i.g.console={}),void 0!==i.g.console.log&&void 0!==i.g.console.error||(i.g.console.error=i.g.console.log=i.g.console.log||function(){console.log(arguments)}),"undefined"==typeof document&&(a.document={documentElement:{appendChild:function(){return""}}},document.createElement=document.captureStream=document.mozCaptureStream=function(){var e={getContext:function(){return e},play:function(){},pause:function(){},drawImage:function(){},toDataURL:function(){return""},style:{}};return e},a.HTMLVideoElement=function(){}),"undefined"==typeof location&&(a.location={protocol:"file:",href:"",hash:""}),"undefined"==typeof screen&&(a.screen={width:0,height:0}),void 0===m&&(a.URL={createObjectURL:function(){return""},revokeObjectURL:function(){return""}}),a.window=i.g);var c=window.requestAnimationFrame;if(void 0===c)if("undefined"!=typeof webkitRequestAnimationFrame)c=webkitRequestAnimationFrame;else if("undefined"!=typeof mozRequestAnimationFrame)c=mozRequestAnimationFrame;else if("undefined"!=typeof msRequestAnimationFrame)c=msRequestAnimationFrame;else if(void 0===c){var l=0;c=function(e,t){var i=(new Date).getTime(),n=Math.max(0,16-(i-l)),a=setTimeout((function(){e(i+n)}),n);return l=i+n,a}}var u=window.cancelAnimationFrame;void 0===u&&("undefined"!=typeof webkitCancelAnimationFrame?u=webkitCancelAnimationFrame:"undefined"!=typeof mozCancelAnimationFrame?u=mozCancelAnimationFrame:"undefined"!=typeof msCancelAnimationFrame?u=msCancelAnimationFrame:void 0===u&&(u=function(e){clearTimeout(e)}));var f=window.AudioContext;void 0===f&&("undefined"!=typeof webkitAudioContext&&(f=webkitAudioContext),"undefined"!=typeof mozAudioContext&&(f=mozAudioContext));var m=window.URL;void 0===m&&"undefined"!=typeof webkitURL&&(m=webkitURL),"undefined"!=typeof navigator&&void 0===navigator.getUserMedia&&(void 0!==navigator.webkitGetUserMedia&&(navigator.getUserMedia=navigator.webkitGetUserMedia),void 0!==navigator.mozGetUserMedia&&(navigator.getUserMedia=navigator.mozGetUserMedia));var p=!(-1===navigator.userAgent.indexOf("Edge")||!navigator.msSaveBlob&&!navigator.msSaveOrOpenBlob),g=!!window.opera||-1!==navigator.userAgent.indexOf("OPR/"),h=navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&"netscape"in window&&/ rv:/.test(navigator.userAgent),v=!g&&!p&&!!navigator.webkitGetUserMedia||S()||-1!==navigator.userAgent.toLowerCase().indexOf("chrome/"),y=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);y&&!v&&-1!==navigator.userAgent.indexOf("CriOS")&&(y=!1,v=!0);var b=window.MediaStream;function w(e){if(0===e)return"0 Bytes";var t=parseInt(Math.floor(Math.log(e)/Math.log(1e3)),10);return(e/Math.pow(1e3,t)).toPrecision(3)+" "+["Bytes","KB","MB","GB","TB"][t]}function C(e,t){if(!e)throw"Blob object is required.";if(!e.type)try{e.type="video/webm"}catch(e){}var i=(e.type||"video/webm").split("/")[1];if(-1!==i.indexOf(";")&&(i=i.split(";")[0]),t&&-1!==t.indexOf(".")){var n=t.split(".");t=n[0],i=n[1]}var a=(t||Math.round(9999999999*Math.random())+888888888)+"."+i;if(void 0!==navigator.msSaveOrOpenBlob)return navigator.msSaveOrOpenBlob(e,a);if(void 0!==navigator.msSaveBlob)return navigator.msSaveBlob(e,a);var o=document.createElement("a");o.href=m.createObjectURL(e),o.download=a,o.style="display:none;opacity:0;color:transparent;",(document.body||document.documentElement).appendChild(o),"function"==typeof o.click?o.click():(o.target="_blank",o.dispatchEvent(new MouseEvent("click",{view:window,bubbles:!0,cancelable:!0}))),m.revokeObjectURL(o.href)}function S(){return"undefined"!=typeof window&&"object"==typeof window.process&&"renderer"===window.process.type||!("undefined"==typeof process||"object"!=typeof process.versions||!process.versions.electron)||"object"==typeof navigator&&"string"==typeof navigator.userAgent&&navigator.userAgent.indexOf("Electron")>=0}function R(e,t){return e&&e.getTracks?e.getTracks().filter((function(e){return e.kind===(t||"audio")})):[]}function k(e,t){"srcObject"in t?t.srcObject=e:"mozSrcObject"in t?t.mozSrcObject=e:t.srcObject=e}void 0===b&&"undefined"!=typeof webkitMediaStream&&(b=webkitMediaStream),void 0!==b&&void 0===b.prototype.stop&&(b.prototype.stop=function(){this.getTracks().forEach((function(e){e.stop()}))}),o.invokeSaveAsDialog=C,o.getTracks=R,o.getSeekableBlob=function(e,t){if("undefined"==typeof EBML)throw new Error("Please link: https://www.webrtc-experiment.com/EBML.js");var i=new EBML.Reader,n=new EBML.Decoder,a=EBML.tools,o=new FileReader;o.onload=function(e){n.decode(this.result).forEach((function(e){i.read(e)})),i.stop();var o=a.makeMetadataSeekable(i.metadatas,i.duration,i.cues),r=this.result.slice(i.metadataSize),s=new Blob([o,r],{type:"video/webm"});t(s)},o.readAsArrayBuffer(e)},o.bytesToSize=w,o.isElectron=S;var x={};function T(){if(h||y||p)return!0;navigator.appVersion;var e,t,i=navigator.userAgent,n=""+parseFloat(navigator.appVersion),a=parseInt(navigator.appVersion,10);return(v||g)&&(e=i.indexOf("Chrome"),n=i.substring(e+7)),-1!==(t=n.indexOf(";"))&&(n=n.substring(0,t)),-1!==(t=n.indexOf(" "))&&(n=n.substring(0,t)),a=parseInt(""+n,10),isNaN(a)&&(n=""+parseFloat(navigator.appVersion),a=parseInt(navigator.appVersion,10)),a>=49}function M(e,t){var i,n=this;if(void 0===e)throw'First argument "MediaStream" is required.';if("undefined"==typeof MediaRecorder)throw"Your browser does not support the Media Recorder API. Please try other modules e.g. WhammyRecorder or StereoAudioRecorder.";"audio"===(t=t||{mimeType:"video/webm"}).type&&(R(e,"video").length&&R(e,"audio").length&&(navigator.mozGetUserMedia?(i=new b).addTrack(R(e,"audio")[0]):i=new b(R(e,"audio")),e=i),t.mimeType&&-1!==t.mimeType.toString().toLowerCase().indexOf("audio")||(t.mimeType=v?"audio/webm":"audio/ogg"),t.mimeType&&"audio/ogg"!==t.mimeType.toString().toLowerCase()&&navigator.mozGetUserMedia&&(t.mimeType="audio/ogg"));var a,o=[];function r(){n.timestamps.push((new Date).getTime()),"function"==typeof t.onTimeStamp&&t.onTimeStamp(n.timestamps[n.timestamps.length-1],n.timestamps)}function s(e){return a&&a.mimeType?a.mimeType:e.mimeType||"video/webm"}function d(){o=[],a=null,n.timestamps=[]}this.getArrayOfBlobs=function(){return o},this.record=function(){n.blob=null,n.clearRecordedData(),n.timestamps=[],c=[],o=[];var i=t;t.disableLogs||console.log("Passing following config over MediaRecorder API.",i),a&&(a=null),v&&!T()&&(i="video/vp8"),"function"==typeof MediaRecorder.isTypeSupported&&i.mimeType&&(MediaRecorder.isTypeSupported(i.mimeType)||(t.disableLogs||console.warn("MediaRecorder API seems unable to record mimeType:",i.mimeType),i.mimeType="audio"===t.type?"audio/webm":"video/webm"));try{a=new MediaRecorder(e,i),t.mimeType=i.mimeType}catch(t){a=new MediaRecorder(e)}i.mimeType&&!MediaRecorder.isTypeSupported&&"canRecordMimeType"in a&&!1===a.canRecordMimeType(i.mimeType)&&(t.disableLogs||console.warn("MediaRecorder API seems unable to record mimeType:",i.mimeType)),a.ondataavailable=function(e){if(e.data&&c.push("ondataavailable: "+w(e.data.size)),"number"!=typeof t.timeSlice)!e.data||!e.data.size||e.data.size<100||n.blob?n.recordingCallback&&(n.recordingCallback(new Blob([],{type:s(i)})),n.recordingCallback=null):(n.blob=t.getNativeBlob?e.data:new Blob([e.data],{type:s(i)}),n.recordingCallback&&(n.recordingCallback(n.blob),n.recordingCallback=null));else if(e.data&&e.data.size&&(o.push(e.data),r(),"function"==typeof t.ondataavailable)){var a=t.getNativeBlob?e.data:new Blob([e.data],{type:s(i)});t.ondataavailable(a)}},a.onstart=function(){c.push("started")},a.onpause=function(){c.push("paused")},a.onresume=function(){c.push("resumed")},a.onstop=function(){c.push("stopped")},a.onerror=function(e){e&&(e.name||(e.name="UnknownError"),c.push("error: "+e),t.disableLogs||(-1!==e.name.toString().toLowerCase().indexOf("invalidstate")?console.error("The MediaRecorder is not in a state in which the proposed operation is allowed to be executed.",e):-1!==e.name.toString().toLowerCase().indexOf("notsupported")?console.error("MIME type (",i.mimeType,") is not supported.",e):-1!==e.name.toString().toLowerCase().indexOf("security")?console.error("MediaRecorder security error",e):"OutOfMemory"===e.name?console.error("The UA has exhaused the available memory. User agents SHOULD provide as much additional information as possible in the message attribute.",e):"IllegalStreamModification"===e.name?console.error("A modification to the stream has occurred that makes it impossible to continue recording. An example would be the addition of a Track while recording is occurring. User agents SHOULD provide as much additional information as possible in the message attribute.",e):"OtherRecordingError"===e.name?console.error("Used for an fatal error other than those listed above. User agents SHOULD provide as much additional information as possible in the message attribute.",e):"GenericError"===e.name?console.error("The UA cannot provide the codec or recording option that has been requested.",e):console.error("MediaRecorder Error",e)),function(e){if(!n.manuallyStopped&&a&&"inactive"===a.state)return delete t.timeslice,void a.start(6e5);setTimeout(void 0,1e3)}(),"inactive"!==a.state&&"stopped"!==a.state&&a.stop())},"number"==typeof t.timeSlice?(r(),a.start(t.timeSlice)):a.start(36e5),t.initCallback&&t.initCallback()},this.timestamps=[],this.stop=function(e){e=e||function(){},n.manuallyStopped=!0,a&&(this.recordingCallback=e,"recording"===a.state&&a.stop(),"number"==typeof t.timeSlice&&setTimeout((function(){n.blob=new Blob(o,{type:s(t)}),n.recordingCallback(n.blob)}),100))},this.pause=function(){a&&"recording"===a.state&&a.pause()},this.resume=function(){a&&"paused"===a.state&&a.resume()},this.clearRecordedData=function(){a&&"recording"===a.state&&n.stop(d),d()},this.getInternalRecorder=function(){return a},this.blob=null,this.getState=function(){return a&&a.state||"inactive"};var c=[];this.getAllStates=function(){return c},void 0===t.checkForInactiveTracks&&(t.checkForInactiveTracks=!1),n=this,function i(){if(a&&!1!==t.checkForInactiveTracks)return!1===function(){if("active"in e){if(!e.active)return!1}else if("ended"in e&&e.ended)return!1;return!0}()?(t.disableLogs||console.log("MediaStream seems stopped."),void n.stop()):void setTimeout(i,1e3)}(),this.name="MediaStreamRecorder",this.toString=function(){return this.name}}function A(e,t){if(!R(e,"audio").length)throw"Your stream has no audio tracks.";var i,n=this,a=[],r=[],s=!1,d=0,c=2,l=(t=t||{}).desiredSampRate;function u(){if(!1===t.checkForInactiveTracks)return!0;if("active"in e){if(!e.active)return!1}else if("ended"in e&&e.ended)return!1;return!0}function f(e,t){function i(e,t){var i,n=e.numberOfAudioChannels,a=e.leftBuffers.slice(0),o=e.rightBuffers.slice(0),r=e.sampleRate,s=e.internalInterleavedLength,d=e.desiredSampRate;function c(e,t,i){var n=Math.round(e.length*(t/i)),a=[],o=Number((e.length-1)/(n-1));a[0]=e[0];for(var r=1;r<n-1;r++){var s=r*o,d=Number(Math.floor(s)).toFixed(),c=Number(Math.ceil(s)).toFixed(),u=s-d;a[r]=l(e[d],e[c],u)}return a[n-1]=e[e.length-1],a}function l(e,t,i){return e+(t-e)*i}function u(e,t){for(var i=new Float64Array(t),n=0,a=e.length,o=0;o<a;o++){var r=e[o];i.set(r,n),n+=r.length}return i}function f(e,t,i){for(var n=i.length,a=0;a<n;a++)e.setUint8(t+a,i.charCodeAt(a))}2===n&&(a=u(a,s),o=u(o,s),d&&(a=c(a,d,r),o=c(o,d,r))),1===n&&(a=u(a,s),d&&(a=c(a,d,r))),d&&(r=d),2===n&&(i=function(e,t){for(var i=e.length+t.length,n=new Float64Array(i),a=0,o=0;o<i;)n[o++]=e[a],n[o++]=t[a],a++;return n}(a,o)),1===n&&(i=a);var m=i.length,p=new ArrayBuffer(44+2*m),g=new DataView(p);f(g,0,"RIFF"),g.setUint32(4,36+2*m,!0),f(g,8,"WAVE"),f(g,12,"fmt "),g.setUint32(16,16,!0),g.setUint16(20,1,!0),g.setUint16(22,n,!0),g.setUint32(24,r,!0),g.setUint32(28,r*n*2,!0),g.setUint16(32,2*n,!0),g.setUint16(34,16,!0),f(g,36,"data"),g.setUint32(40,2*m,!0);for(var h=m,v=44,y=0;y<h;y++)g.setInt16(v,32767*i[y],!0),v+=2;if(t)return t({buffer:p,view:g});postMessage({buffer:p,view:g})}if(e.noWorker)i(e,(function(e){t(e.buffer,e.view)}));else{var n,a,o,r=(n=i,a=m.createObjectURL(new Blob([n.toString(),";this.onmessage = function (eee) {"+n.name+"(eee.data);}"],{type:"application/javascript"})),(o=new Worker(a)).workerURL=a,o);r.onmessage=function(e){t(e.data.buffer,e.data.view),m.revokeObjectURL(r.workerURL),r.terminate()},r.postMessage(e)}}!0===t.leftChannel&&(c=1),1===t.numberOfAudioChannels&&(c=1),(!c||c<1)&&(c=2),t.disableLogs||console.log("StereoAudioRecorder is set to record number of channels: "+c),void 0===t.checkForInactiveTracks&&(t.checkForInactiveTracks=!0),this.record=function(){if(!1===u())throw"Please make sure MediaStream is active.";w(),S=b=!1,s=!0,void 0!==t.timeSlice&&x()},this.stop=function(e){e=e||function(){},s=!1,f({desiredSampRate:l,sampleRate:y,numberOfAudioChannels:c,internalInterleavedLength:d,leftBuffers:a,rightBuffers:1===c?[]:r,noWorker:t.noWorker},(function(t,i){n.blob=new Blob([i],{type:"audio/wav"}),n.buffer=new ArrayBuffer(i.buffer.byteLength),n.view=i,n.sampleRate=l||y,n.bufferSize=v,n.length=d,S=!1,e&&e(n.blob)}))},void 0===o.Storage&&(o.Storage={AudioContextConstructor:null,AudioContext:window.AudioContext||window.webkitAudioContext}),o.Storage.AudioContextConstructor&&"closed"!==o.Storage.AudioContextConstructor.state||(o.Storage.AudioContextConstructor=new o.Storage.AudioContext);var p=o.Storage.AudioContextConstructor,g=p.createMediaStreamSource(e),h=[0,256,512,1024,2048,4096,8192,16384],v=void 0===t.bufferSize?4096:t.bufferSize;if(-1===h.indexOf(v)&&(t.disableLogs||console.log("Legal values for buffer-size are "+JSON.stringify(h,null,"\t"))),p.createJavaScriptNode)i=p.createJavaScriptNode(v,c,c);else{if(!p.createScriptProcessor)throw"WebAudio API has no support on this browser.";i=p.createScriptProcessor(v,c,c)}g.connect(i),t.bufferSize||(v=i.bufferSize);var y=void 0!==t.sampleRate?t.sampleRate:p.sampleRate||44100;(y<22050||y>96e3)&&(t.disableLogs||console.log("sample-rate must be under range 22050 and 96000.")),t.disableLogs||t.desiredSampRate&&console.log("Desired sample-rate: "+t.desiredSampRate);var b=!1;function w(){a=[],r=[],d=0,S=!1,s=!1,b=!1,p=null,n.leftchannel=a,n.rightchannel=r,n.numberOfAudioChannels=c,n.desiredSampRate=l,n.sampleRate=y,n.recordingLength=d,k={left:[],right:[],recordingLength:0}}function C(){i&&(i.onaudioprocess=null,i.disconnect(),i=null),g&&(g.disconnect(),g=null),w()}this.pause=function(){b=!0},this.resume=function(){if(!1===u())throw"Please make sure MediaStream is active.";if(!s)return t.disableLogs||console.log("Seems recording has been restarted."),void this.record();b=!1},this.clearRecordedData=function(){t.checkForInactiveTracks=!1,s&&this.stop(C),C()},this.name="StereoAudioRecorder",this.toString=function(){return this.name};var S=!1;i.onaudioprocess=function(e){if(!b)if(!1===u()&&(t.disableLogs||console.log("MediaStream seems stopped."),i.disconnect(),s=!1),s){S||(S=!0,t.onAudioProcessStarted&&t.onAudioProcessStarted(),t.initCallback&&t.initCallback());var o=e.inputBuffer.getChannelData(0),l=new Float32Array(o);if(a.push(l),2===c){var f=e.inputBuffer.getChannelData(1),m=new Float32Array(f);r.push(m)}d+=v,n.recordingLength=d,void 0!==t.timeSlice&&(k.recordingLength+=v,k.left.push(l),2===c&&k.right.push(m))}else g&&(g.disconnect(),g=null)},p.createMediaStreamDestination?i.connect(p.createMediaStreamDestination()):i.connect(p.destination),this.leftchannel=a,this.rightchannel=r,this.numberOfAudioChannels=c,this.desiredSampRate=l,this.sampleRate=y,n.recordingLength=d;var k={left:[],right:[],recordingLength:0};function x(){s&&"function"==typeof t.ondataavailable&&void 0!==t.timeSlice&&(k.left.length?(f({desiredSampRate:l,sampleRate:y,numberOfAudioChannels:c,internalInterleavedLength:k.recordingLength,leftBuffers:k.left,rightBuffers:1===c?[]:k.right},(function(e,i){var n=new Blob([i],{type:"audio/wav"});t.ondataavailable(n),setTimeout(x,t.timeSlice)})),k={left:[],right:[],recordingLength:0}):setTimeout(x,t.timeSlice))}}function D(e,t){if("undefined"==typeof html2canvas)throw"Please link: https://www.webrtc-experiment.com/screenshot.js";(t=t||{}).frameInterval||(t.frameInterval=10);var i=!1;["captureStream","mozCaptureStream","webkitCaptureStream"].forEach((function(e){e in document.createElement("canvas")&&(i=!0)}));var n,a,o,r=!(!window.webkitRTCPeerConnection&&!window.webkitGetUserMedia||!window.chrome),s=50,d=navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);if(r&&d&&d[2]&&(s=parseInt(d[2],10)),r&&s<52&&(i=!1),t.useWhammyRecorder&&(i=!1),i)if(t.disableLogs||console.log("Your browser supports both MediRecorder API and canvas.captureStream!"),e instanceof HTMLCanvasElement)n=e;else{if(!(e instanceof CanvasRenderingContext2D))throw"Please pass either HTMLCanvasElement or CanvasRenderingContext2D.";n=e.canvas}else navigator.mozGetUserMedia&&(t.disableLogs||console.error("Canvas recording is NOT supported in Firefox."));this.record=function(){if(o=!0,i&&!t.useWhammyRecorder){var e;"captureStream"in n?e=n.captureStream(25):"mozCaptureStream"in n?e=n.mozCaptureStream(25):"webkitCaptureStream"in n&&(e=n.webkitCaptureStream(25));try{var r=new b;r.addTrack(R(e,"video")[0]),e=r}catch(e){}if(!e)throw"captureStream API are NOT available.";(a=new M(e,{mimeType:t.mimeType||"video/webm"})).record()}else m.frames=[],f=(new Date).getTime(),u();t.initCallback&&t.initCallback()},this.getWebPImages=function(i){if("canvas"===e.nodeName.toLowerCase()){var n=m.frames.length;m.frames.forEach((function(e,i){var a=n-i;t.disableLogs||console.log(a+"/"+n+" frames remaining"),t.onEncodingCallback&&t.onEncodingCallback(a,n);var o=e.image.toDataURL("image/webp",1);m.frames[i].image=o})),t.disableLogs||console.log("Generating WebM"),i()}else i()},this.stop=function(e){o=!1;var n=this;i&&a?a.stop(e):this.getWebPImages((function(){m.compile((function(i){t.disableLogs||console.log("Recording finished!"),n.blob=i,n.blob.forEach&&(n.blob=new Blob([],{type:"video/webm"})),e&&e(n.blob),m.frames=[]}))}))};var c=!1;function l(){m.frames=[],o=!1,c=!1}function u(){if(c)return f=(new Date).getTime(),setTimeout(u,500);if("canvas"===e.nodeName.toLowerCase()){var i=(new Date).getTime()-f;return f=(new Date).getTime(),m.frames.push({image:(n=document.createElement("canvas"),a=n.getContext("2d"),n.width=e.width,n.height=e.height,a.drawImage(e,0,0),n),duration:i}),void(o&&setTimeout(u,t.frameInterval))}var n,a;html2canvas(e,{grabMouse:void 0===t.showMousePointer||t.showMousePointer,onrendered:function(e){var i=(new Date).getTime()-f;if(!i)return setTimeout(u,t.frameInterval);f=(new Date).getTime(),m.frames.push({image:e.toDataURL("image/webp",1),duration:i}),o&&setTimeout(u,t.frameInterval)}})}this.pause=function(){c=!0,a instanceof M&&a.pause()},this.resume=function(){c=!1,a instanceof M?a.resume():o||this.record()},this.clearRecordedData=function(){o&&this.stop(l),l()},this.name="CanvasRecorder",this.toString=function(){return this.name};var f=(new Date).getTime(),m=new L.Video(100)}function O(e,t){function i(e){e=void 0!==e?e:10;var t=(new Date).getTime()-s;return t?a?(s=(new Date).getTime(),setTimeout(i,100)):(s=(new Date).getTime(),r.paused&&r.play(),l.drawImage(r,0,0,c.width,c.height),d.frames.push({duration:t,image:c.toDataURL("image/webp")}),void(n||setTimeout(i,e,e))):setTimeout(i,e,e)}(t=t||{}).frameInterval||(t.frameInterval=10),t.disableLogs||console.log("Using frames-interval:",t.frameInterval),this.record=function(){t.width||(t.width=320),t.height||(t.height=240),t.video||(t.video={width:t.width,height:t.height}),t.canvas||(t.canvas={width:t.width,height:t.height}),c.width=t.canvas.width||320,c.height=t.canvas.height||240,l=c.getContext("2d"),t.video&&t.video instanceof HTMLVideoElement?(r=t.video.cloneNode(),t.initCallback&&t.initCallback()):(r=document.createElement("video"),k(e,r),r.onloadedmetadata=function(){t.initCallback&&t.initCallback()},r.width=t.video.width,r.height=t.video.height),r.muted=!0,r.play(),s=(new Date).getTime(),d=new L.Video,t.disableLogs||(console.log("canvas resolutions",c.width,"*",c.height),console.log("video width/height",r.width||c.width,"*",r.height||c.height)),i(t.frameInterval)};var n=!1;this.stop=function(e){e=e||function(){},n=!0;var i=this;setTimeout((function(){!function(e,t,i,n,a){var o=document.createElement("canvas");o.width=c.width,o.height=c.height;var r,s,d,l=o.getContext("2d"),u=[],f=-1===t,m=t&&t>0&&t<=e.length?t:e.length,p=Math.sqrt(Math.pow(255,2)+Math.pow(255,2)+Math.pow(255,2)),g=i&&i>=0&&i<=1?i:0,h=n&&n>=0&&n<=1?n:0,v=!1;s=-1,d=(r={length:m,functionToLoop:function(t,i){var n,a,o,r=function(){!v&&o-n<=o*h||(f&&(v=!0),u.push(e[i])),t()};if(v)r();else{var s=new Image;s.onload=function(){l.drawImage(s,0,0,c.width,c.height);var e=l.getImageData(0,0,c.width,c.height);n=0,a=e.data.length,o=e.data.length/4;for(var t=0;t<a;t+=4){var i={r:e.data[t],g:e.data[t+1],b:e.data[t+2]};Math.sqrt(Math.pow(i.r-0,2)+Math.pow(i.g-0,2)+Math.pow(i.b-0,2))<=p*g&&n++}r()},s.src=e[i].image}},callback:function(){(u=u.concat(e.slice(m))).length<=0&&u.push(e[e.length-1]),a(u)}}).length,function e(){++s!==d?setTimeout((function(){r.functionToLoop(e,s)}),1):r.callback()}()}(d.frames,-1,null,null,(function(n){d.frames=n,t.advertisement&&t.advertisement.length&&(d.frames=t.advertisement.concat(d.frames)),d.compile((function(t){i.blob=t,i.blob.forEach&&(i.blob=new Blob([],{type:"video/webm"})),e&&e(i.blob)}))}))}),10)};var a=!1;function o(){d.frames=[],n=!0,a=!1}this.pause=function(){a=!0},this.resume=function(){a=!1,n&&this.record()},this.clearRecordedData=function(){n||this.stop(o),o()},this.name="WhammyRecorder",this.toString=function(){return this.name};var r,s,d,c=document.createElement("canvas"),l=c.getContext("2d")}void 0!==f?x.AudioContext=f:"undefined"!=typeof webkitAudioContext&&(x.AudioContext=webkitAudioContext),o.Storage=x,o.MediaStreamRecorder=M,o.StereoAudioRecorder=A,o.CanvasRecorder=D,o.WhammyRecorder=O;var L=function(){function e(e){this.frames=[],this.duration=e||1,this.quality=.8}function t(e){function t(e,t,i){return[{data:e,id:231}].concat(i.map((function(e){var i=function(e){var t=0;if(e.keyframe&&(t|=128),e.invisible&&(t|=8),e.lacing&&(t|=e.lacing<<1),e.discardable&&(t|=1),e.trackNum>127)throw"TrackNumber > 127 not supported";return[128|e.trackNum,e.timecode>>8,255&e.timecode,t].map((function(e){return String.fromCharCode(e)})).join("")+e.frame}({discardable:0,frame:e.data.slice(4),invisible:0,keyframe:1,lacing:0,trackNum:1,timecode:Math.round(t)});return t+=e.duration,{data:i,id:163}})))}function i(e){for(var t=[];e>0;)t.push(255&e),e>>=8;return new Uint8Array(t.reverse())}function n(e){var t=[];e=(e.length%8?new Array(9-e.length%8).join("0"):"")+e;for(var i=0;i<e.length;i+=8)t.push(parseInt(e.substr(i,8),2));return new Uint8Array(t)}function a(e){for(var t=[],o=0;o<e.length;o++){var r=e[o].data;"object"==typeof r&&(r=a(r)),"number"==typeof r&&(r=n(r.toString(2))),"string"==typeof r&&(r=new Uint8Array(r.split("").map((function(e){return e.charCodeAt(0)}))));var s=r.size||r.byteLength||r.length,d=Math.ceil(Math.ceil(Math.log(s)/Math.log(2))/8),c=s.toString(2),l=new Array(7*d+7+1-c.length).join("0")+c,u=new Array(d).join("0")+"1"+l;t.push(i(e[o].id)),t.push(n(u)),t.push(r)}return new Blob(t,{type:"video/webm"})}function o(e,t){return parseInt(e.substr(t+4,4).split("").map((function(e){var t=e.charCodeAt(0).toString(2);return new Array(8-t.length+1).join("0")+t})).join(""),2)}function r(e){for(var t=0,i={};t<e.length;){var n=e.substr(t,4),a=o(e,t),s=e.substr(t+4+4,a);t+=8+a,i[n]=i[n]||[],"RIFF"===n||"LIST"===n?i[n].push(r(s)):i[n].push(s)}return i}var s=new function(e){var i=function(e){if(e[0]){for(var t=e[0].width,i=e[0].height,n=e[0].duration,a=1;a<e.length;a++)n+=e[a].duration;return{duration:n,width:t,height:i}}postMessage({error:"Something went wrong. Maybe WebP format is not supported in the current browser."})}(e);if(!i)return[];for(var n,o=[{id:440786851,data:[{data:1,id:17030},{data:1,id:17143},{data:4,id:17138},{data:8,id:17139},{data:"webm",id:17026},{data:2,id:17031},{data:2,id:17029}]},{id:408125543,data:[{id:357149030,data:[{data:1e6,id:2807729},{data:"whammy",id:19840},{data:"whammy",id:22337},{data:(n=i.duration,[].slice.call(new Uint8Array(new Float64Array([n]).buffer),0).map((function(e){return String.fromCharCode(e)})).reverse().join("")),id:17545}]},{id:374648427,data:[{id:174,data:[{data:1,id:215},{data:1,id:29637},{data:0,id:156},{data:"und",id:2274716},{data:"V_VP8",id:134},{data:"VP8",id:2459272},{data:1,id:131},{id:224,data:[{data:i.width,id:176},{data:i.height,id:186}]}]}]}]}],r=0,s=0;r<e.length;){var d=[],c=0;do{d.push(e[r]),c+=e[r].duration,r++}while(r<e.length&&c<3e4);var l={id:524531317,data:t(s,0,d)};o[1].data.push(l),s+=c}return a(o)}(e.map((function(e){var t=function(e){for(var t=e.RIFF[0].WEBP[0],i=t.indexOf("*"),n=0,a=[];n<4;n++)a[n]=t.charCodeAt(i+3+n);return{width:16383&(a[1]<<8|a[0]),height:16383&(a[3]<<8|a[2]),data:t,riff:e}}(r(atob(e.image.slice(23))));return t.duration=e.duration,t})));postMessage(s)}return e.prototype.add=function(e,t){if("canvas"in e&&(e=e.canvas),"toDataURL"in e&&(e=e.toDataURL("image/webp",this.quality)),!/^data:image\/webp;base64,/gi.test(e))throw"Input must be formatted properly as a base64 encoded DataURI of type image/webp";this.frames.push({image:e,duration:t||this.duration})},e.prototype.compile=function(e){var i,n,a,o=(i=t,n=m.createObjectURL(new Blob([i.toString(),"this.onmessage = function (eee) {"+i.name+"(eee.data);}"],{type:"application/javascript"})),a=new Worker(n),m.revokeObjectURL(n),a);o.onmessage=function(t){t.data.error?console.error(t.data.error):e(t.data)},o.postMessage(this.frames)},{Video:e}}();o.Whammy=L;var I={init:function(){var e=this;if("undefined"!=typeof indexedDB&&void 0!==indexedDB.open){var t,i=this.dbName||location.href.replace(/\/|:|#|%|\.|\[|\]/g,""),n=indexedDB.open(i,1);n.onerror=e.onError,n.onsuccess=function(){(t=n.result).onerror=e.onError,t.setVersion&&1!==t.version?t.setVersion(1).onsuccess=function(){a(t),o()}:o()},n.onupgradeneeded=function(e){a(e.target.result)}}else console.error("IndexedDB API are not available in this browser.");function a(t){t.createObjectStore(e.dataStoreName)}function o(){var i=t.transaction([e.dataStoreName],"readwrite");function n(t){i.objectStore(e.dataStoreName).get(t).onsuccess=function(i){e.callback&&e.callback(i.target.result,t)}}e.videoBlob&&i.objectStore(e.dataStoreName).put(e.videoBlob,"videoBlob"),e.gifBlob&&i.objectStore(e.dataStoreName).put(e.gifBlob,"gifBlob"),e.audioBlob&&i.objectStore(e.dataStoreName).put(e.audioBlob,"audioBlob"),n("audioBlob"),n("videoBlob"),n("gifBlob")}},Fetch:function(e){return this.callback=e,this.init(),this},Store:function(e){return this.audioBlob=e.audioBlob,this.videoBlob=e.videoBlob,this.gifBlob=e.gifBlob,this.init(),this},onError:function(e){console.error(JSON.stringify(e,null,"\t"))},dataStoreName:"recordRTC",dbName:null};function E(e,t){if("undefined"==typeof GIFEncoder){var i=document.createElement("script");i.src="https://www.webrtc-experiment.com/gif-recorder.js",(document.body||document.documentElement).appendChild(i)}t=t||{};var n=e instanceof CanvasRenderingContext2D||e instanceof HTMLCanvasElement;this.record=function(){"undefined"!=typeof GIFEncoder&&s?(n||(t.width||(t.width=d.offsetWidth||320),t.height||(t.height=d.offsetHeight||240),t.video||(t.video={width:t.width,height:t.height}),t.canvas||(t.canvas={width:t.width,height:t.height}),o.width=t.canvas.width||320,o.height=t.canvas.height||240,d.width=t.video.width||320,d.height=t.video.height||240),(f=new GIFEncoder).setRepeat(0),f.setDelay(t.frameRate||200),f.setQuality(t.quality||10),f.start(),"function"==typeof t.onGifRecordingStarted&&t.onGifRecordingStarted(),Date.now(),m=c((function e(i){if(!0!==p.clearedRecordedData){if(a)return setTimeout((function(){e(i)}),100);m=c(e),void 0===typeof l&&(l=i),i-l<90||(!n&&d.paused&&d.play(),n||r.drawImage(d,0,0,o.width,o.height),t.onGifPreview&&t.onGifPreview(o.toDataURL("image/png")),f.addFrame(r),l=i)}})),t.initCallback&&t.initCallback()):setTimeout(p.record,1e3)},this.stop=function(e){e=e||function(){},m&&u(m),Date.now(),this.blob=new Blob([new Uint8Array(f.stream().bin)],{type:"image/gif"}),e(this.blob),f.stream().bin=[]};var a=!1;this.pause=function(){a=!0},this.resume=function(){a=!1},this.clearRecordedData=function(){p.clearedRecordedData=!0,f&&(f.stream().bin=[])},this.name="GifRecorder",this.toString=function(){return this.name};var o=document.createElement("canvas"),r=o.getContext("2d");n&&(e instanceof CanvasRenderingContext2D?o=(r=e).canvas:e instanceof HTMLCanvasElement&&(r=e.getContext("2d"),o=e));var s=!0;if(!n){var d=document.createElement("video");d.muted=!0,d.autoplay=!0,d.playsInline=!0,s=!1,d.onloadedmetadata=function(){s=!0},k(e,d),d.play()}var l,f,m=null,p=this}function B(e,t){void 0!==i.g&&i.g,t=t||"multi-streams-mixer";var n=[],a=!1,o=document.createElement("canvas"),r=o.getContext("2d");o.style.opacity=0,o.style.position="absolute",o.style.zIndex=-1,o.style.top="-1000em",o.style.left="-1000em",o.className=t,(document.body||document.documentElement).appendChild(o),this.disableLogs=!1,this.frameInterval=10,this.width=360,this.height=240,this.useGainNode=!0;var s=this,d=window.AudioContext;void 0===d&&("undefined"!=typeof webkitAudioContext&&(d=webkitAudioContext),"undefined"!=typeof mozAudioContext&&(d=mozAudioContext));var c=window.URL;void 0===c&&"undefined"!=typeof webkitURL&&(c=webkitURL),"undefined"!=typeof navigator&&void 0===navigator.getUserMedia&&(void 0!==navigator.webkitGetUserMedia&&(navigator.getUserMedia=navigator.webkitGetUserMedia),void 0!==navigator.mozGetUserMedia&&(navigator.getUserMedia=navigator.mozGetUserMedia));var l=window.MediaStream;void 0===l&&"undefined"!=typeof webkitMediaStream&&(l=webkitMediaStream),void 0!==l&&void 0===l.prototype.stop&&(l.prototype.stop=function(){this.getTracks().forEach((function(e){e.stop()}))});var u={};function f(){if(!a){var e=n.length,t=!1,i=[];if(n.forEach((function(e){e.stream||(e.stream={}),e.stream.fullcanvas?t=e:i.push(e)})),t)o.width=t.stream.width,o.height=t.stream.height;else if(i.length){o.width=e>1?2*i[0].width:i[0].width;var r=1;3!==e&&4!==e||(r=2),5!==e&&6!==e||(r=3),7!==e&&8!==e||(r=4),9!==e&&10!==e||(r=5),o.height=i[0].height*r}else o.width=s.width||360,o.height=s.height||240;t&&t instanceof HTMLVideoElement&&m(t),i.forEach((function(e,t){m(e,t)})),setTimeout(f,s.frameInterval)}}function m(e,t){if(!a){var i=0,n=0,o=e.width,s=e.height;1===t&&(i=e.width),2===t&&(n=e.height),3===t&&(i=e.width,n=e.height),4===t&&(n=2*e.height),5===t&&(i=e.width,n=2*e.height),6===t&&(n=3*e.height),7===t&&(i=e.width,n=3*e.height),void 0!==e.stream.left&&(i=e.stream.left),void 0!==e.stream.top&&(n=e.stream.top),void 0!==e.stream.width&&(o=e.stream.width),void 0!==e.stream.height&&(s=e.stream.height),r.drawImage(e,i,n,o,s),"function"==typeof e.stream.onRender&&e.stream.onRender(r,i,n,o,s,t)}}function p(e){var i=document.createElement("video");return function(e,t){"srcObject"in t?t.srcObject=e:"mozSrcObject"in t?t.mozSrcObject=e:t.srcObject=e}(e,i),i.className=t,i.muted=!0,i.volume=0,i.width=e.width||s.width||360,i.height=e.height||s.height||240,i.play(),i}function g(t){n=[],(t=t||e).forEach((function(e){if(e.getTracks().filter((function(e){return"video"===e.kind})).length){var t=p(e);t.stream=e,n.push(t)}}))}void 0!==d?u.AudioContext=d:"undefined"!=typeof webkitAudioContext&&(u.AudioContext=webkitAudioContext),this.startDrawingFrames=function(){f()},this.appendStreams=function(t){if(!t)throw"First parameter is required.";t instanceof Array||(t=[t]),t.forEach((function(t){var i=new l;if(t.getTracks().filter((function(e){return"video"===e.kind})).length){var a=p(t);a.stream=t,n.push(a),i.addTrack(t.getTracks().filter((function(e){return"video"===e.kind}))[0])}if(t.getTracks().filter((function(e){return"audio"===e.kind})).length){var o=s.audioContext.createMediaStreamSource(t);s.audioDestination=s.audioContext.createMediaStreamDestination(),o.connect(s.audioDestination),i.addTrack(s.audioDestination.stream.getTracks().filter((function(e){return"audio"===e.kind}))[0])}e.push(i)}))},this.releaseStreams=function(){n=[],a=!0,s.gainNode&&(s.gainNode.disconnect(),s.gainNode=null),s.audioSources.length&&(s.audioSources.forEach((function(e){e.disconnect()})),s.audioSources=[]),s.audioDestination&&(s.audioDestination.disconnect(),s.audioDestination=null),s.audioContext&&s.audioContext.close(),s.audioContext=null,r.clearRect(0,0,o.width,o.height),o.stream&&(o.stream.stop(),o.stream=null)},this.resetVideoStreams=function(e){!e||e instanceof Array||(e=[e]),g(e)},this.name="MultiStreamsMixer",this.toString=function(){return this.name},this.getMixedStream=function(){a=!1;var t=function(){var e;g(),"captureStream"in o?e=o.captureStream():"mozCaptureStream"in o?e=o.mozCaptureStream():s.disableLogs||console.error("Upgrade to latest Chrome or otherwise enable this flag: chrome://flags/#enable-experimental-web-platform-features");var t=new l;return e.getTracks().filter((function(e){return"video"===e.kind})).forEach((function(e){t.addTrack(e)})),o.stream=t,t}(),i=function(){u.AudioContextConstructor||(u.AudioContextConstructor=new u.AudioContext),s.audioContext=u.AudioContextConstructor,s.audioSources=[],!0===s.useGainNode&&(s.gainNode=s.audioContext.createGain(),s.gainNode.connect(s.audioContext.destination),s.gainNode.gain.value=0);var t=0;if(e.forEach((function(e){if(e.getTracks().filter((function(e){return"audio"===e.kind})).length){t++;var i=s.audioContext.createMediaStreamSource(e);!0===s.useGainNode&&i.connect(s.gainNode),s.audioSources.push(i)}})),t)return s.audioDestination=s.audioContext.createMediaStreamDestination(),s.audioSources.forEach((function(e){e.connect(s.audioDestination)})),s.audioDestination.stream}();return i&&i.getTracks().filter((function(e){return"audio"===e.kind})).forEach((function(e){t.addTrack(e)})),e.forEach((function(e){e.fullcanvas})),t}}function U(e,t){e=e||[];var i,n,a=this;(t=t||{elementClass:"multi-streams-mixer",mimeType:"video/webm",video:{width:360,height:240}}).frameInterval||(t.frameInterval=10),t.video||(t.video={}),t.video.width||(t.video.width=360),t.video.height||(t.video.height=240),this.record=function(){var a;i=new B(e,t.elementClass||"multi-streams-mixer"),(a=[],e.forEach((function(e){R(e,"video").forEach((function(e){a.push(e)}))})),a).length&&(i.frameInterval=t.frameInterval||10,i.width=t.video.width||360,i.height=t.video.height||240,i.startDrawingFrames()),t.previewStream&&"function"==typeof t.previewStream&&t.previewStream(i.getMixedStream()),(n=new M(i.getMixedStream(),t)).record()},this.stop=function(e){n&&n.stop((function(t){a.blob=t,e(t),a.clearRecordedData()}))},this.pause=function(){n&&n.pause()},this.resume=function(){n&&n.resume()},this.clearRecordedData=function(){n&&(n.clearRecordedData(),n=null),i&&(i.releaseStreams(),i=null)},this.addStreams=function(a){if(!a)throw"First parameter is required.";a instanceof Array||(a=[a]),e.concat(a),n&&i&&(i.appendStreams(a),t.previewStream&&"function"==typeof t.previewStream&&t.previewStream(i.getMixedStream()))},this.resetVideoStreams=function(e){i&&(!e||e instanceof Array||(e=[e]),i.resetVideoStreams(e))},this.getMixer=function(){return i},this.name="MultiStreamRecorder",this.toString=function(){return this.name}}function F(e,t){var i,n,a;function o(){return new ReadableStream({start:function(n){var a=document.createElement("canvas"),o=document.createElement("video"),r=!0;o.srcObject=e,o.muted=!0,o.height=t.height,o.width=t.width,o.volume=0,o.onplaying=function(){a.width=t.width,a.height=t.height;var e=a.getContext("2d"),s=1e3/t.frameRate,d=setInterval((function(){if(i&&(clearInterval(d),n.close()),r&&(r=!1,t.onVideoProcessStarted&&t.onVideoProcessStarted()),e.drawImage(o,0,0),"closed"!==n._controlledReadableStream.state)try{n.enqueue(e.getImageData(0,0,t.width,t.height))}catch(e){}}),s)},o.play()}})}function r(e,d){if(!t.workerPath&&!d)return i=!1,void fetch("https://unpkg.com/webm-wasm@latest/dist/webm-worker.js").then((function(t){t.arrayBuffer().then((function(t){r(e,t)}))}));if(!t.workerPath&&d instanceof ArrayBuffer){var c=new Blob([d],{type:"text/javascript"});t.workerPath=m.createObjectURL(c)}t.workerPath||console.error("workerPath parameter is missing."),(n=new Worker(t.workerPath)).postMessage(t.webAssemblyPath||"https://unpkg.com/webm-wasm@latest/dist/webm-wasm.wasm"),n.addEventListener("message",(function(e){"READY"===e.data?(n.postMessage({width:t.width,height:t.height,bitrate:t.bitrate||1200,timebaseDen:t.frameRate||30,realtime:t.realtime}),o().pipeTo(new WritableStream({write:function(e){i?console.error("Got image, but recorder is finished!"):n.postMessage(e.data.buffer,[e.data.buffer])}}))):e.data&&(a||s.push(e.data))}))}"undefined"!=typeof ReadableStream&&"undefined"!=typeof WritableStream||console.error("Following polyfill is strongly recommended: https://unpkg.com/@mattiasbuelens/web-streams-polyfill/dist/polyfill.min.js"),(t=t||{}).width=t.width||640,t.height=t.height||480,t.frameRate=t.frameRate||30,t.bitrate=t.bitrate||1200,t.realtime=t.realtime||!0,this.record=function(){s=[],a=!1,this.blob=null,r(e),"function"==typeof t.initCallback&&t.initCallback()},this.pause=function(){a=!0},this.resume=function(){a=!1};var s=[];this.stop=function(e){i=!0;var t=this;!function(e){n?(n.addEventListener("message",(function(t){null===t.data&&(n.terminate(),n=null,e&&e())})),n.postMessage(null)):e&&e()}((function(){t.blob=new Blob(s,{type:"video/webm"}),e(t.blob