@haxtheweb/haxcms-nodejs
Version:
HAXcms single and multisite nodejs server, api, and administration
1 lines • 22.8 kB
JavaScript
function MediaStreamRecorder(e){if(!e)throw"MediaStream is mandatory.";var t;this.start=function(a){var i;"undefined"!=typeof MediaRecorder?i=MediaRecorderWrapper:(n||o||r)&&(-1!==this.mimeType.indexOf("video")?i=WhammyRecorder:-1!==this.mimeType.indexOf("audio")&&(i=StereoAudioRecorder)),"image/gif"===this.mimeType&&(i=GifRecorder),("audio/wav"===this.mimeType||"audio/pcm"===this.mimeType)&&(i=StereoAudioRecorder),this.recorderType&&(i=this.recorderType),(t=new i(e)).blobs=[];var d=this;t.ondataavailable=function(e){t.blobs.push(e),d.ondataavailable(e)},t.onstop=this.onstop,t.onStartedDrawingNonBlankFrames=this.onStartedDrawingNonBlankFrames,(t=function mergeProps(e,t){for(var a in t)"function"!=typeof t[a]&&(e[a]=t[a]);return e}(t,this)).start(a)},this.onStartedDrawingNonBlankFrames=function(){},this.clearOldRecordedFrames=function(){t&&t.clearOldRecordedFrames()},this.stop=function(){t&&t.stop()},this.ondataavailable=function(e){console.log("ondataavailable..",e)},this.onstop=function(e){console.warn("stopped..",e)},this.save=function(e,a){if(e)invokeSaveAsDialog(e,a);else{if(!t)return;ConcatenateBlobs(t.blobs,t.blobs[0].type,(function(e){invokeSaveAsDialog(e)}))}},this.pause=function(){t&&(t.pause(),console.log("Paused recording.",this.mimeType||t.mimeType))},this.resume=function(){t&&(t.resume(),console.log("Resumed recording.",this.mimeType||t.mimeType))},this.recorderType=null,this.mimeType="video/webm",this.disableLogs=!1}function invokeSaveAsDialog(e,t){if(!e)throw"Blob object is required.";if(!e.type)try{e.type="video/webm"}catch(e){}var a=(e.type||"video/webm").split("/")[1];if(t&&-1!==t.indexOf(".")){var r=t.split(".");t=r[0],a=r[1]}var o=(t||Math.round(9999999999*Math.random())+888888888)+"."+a;if(void 0!==navigator.msSaveOrOpenBlob)return navigator.msSaveOrOpenBlob(e,o);if(void 0!==navigator.msSaveBlob)return navigator.msSaveBlob(e,o);var n=document.createElement("a");n.href=i.createObjectURL(e),n.target="_blank",n.download=o,navigator.mozGetUserMedia&&(n.onclick=function(){(document.body||document.documentElement).removeChild(n)},(document.body||document.documentElement).appendChild(n));var d=new MouseEvent("click",{view:window,bubbles:!0,cancelable:!0});n.dispatchEvent(d),navigator.mozGetUserMedia||i.revokeObjectURL(n.href)}function bytesToSize(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 isMediaRecorderCompatible(){var e=!!window.opera||navigator.userAgent.indexOf(" OPR/")>=0,t=!!window.chrome&&!e;if(void 0!==window.InstallTrigger)return!0;if(!t)return!1;var a,i,r=(navigator.appVersion,navigator.userAgent),o=""+parseFloat(navigator.appVersion),n=parseInt(navigator.appVersion,10);return t&&(a=r.indexOf("Chrome"),o=r.substring(a+7)),-1!==(i=o.indexOf(";"))&&(o=o.substring(0,i)),-1!==(i=o.indexOf(" "))&&(o=o.substring(0,i)),n=parseInt(""+o,10),isNaN(n)&&(o=""+parseFloat(navigator.appVersion),n=parseInt(navigator.appVersion,10)),n>=49}function MediaRecorderWrapper(e){var t,a=this;this.start=function(i,r){var o;(a.mimeType||(a.mimeType="video/webm"),-1!==a.mimeType.indexOf("audio")&&e.getVideoTracks().length&&e.getAudioTracks().length)&&(navigator.mozGetUserMedia?(o=new d).addTrack(e.getAudioTracks()[0]):o=new d(e.getAudioTracks()),e=o);-1!==a.mimeType.indexOf("audio")&&(a.mimeType=n?"audio/webm":"audio/ogg"),a.dontFireOnDataAvailableEvent=!1;var s={mimeType:a.mimeType};a.disableLogs||r||console.log("Passing following params over MediaRecorder API.",s),t&&(t=null),n&&!isMediaRecorderCompatible()&&(s="video/vp8");try{t=new MediaRecorder(e,s)}catch(a){t=new MediaRecorder(e)}"canRecordMimeType"in t&&!1===t.canRecordMimeType(a.mimeType)&&(a.disableLogs||console.warn("MediaRecorder API seems unable to record mimeType:",a.mimeType)),t.ignoreMutedMedia=a.ignoreMutedMedia||!1;var u=!1;t.ondataavailable=function(e){if(!a.dontFireOnDataAvailableEvent&&e.data&&e.data.size&&!(e.data.size<26800)&&!u){u=!0;var r=a.getNativeBlob?e.data:new Blob([e.data],{type:a.mimeType||"video/webm"});a.ondataavailable(r),a.dontFireOnDataAvailableEvent=!0,t&&(t.stop(),t=null),a.start(i,"__disableLogs")}},t.onerror=function(e){a.disableLogs||("InvalidState"===e.name?console.error("The MediaRecorder is not in a state in which the proposed operation is allowed to be executed."):"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."):"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."):"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."):"GenericError"===e.name?console.error("The UA cannot provide the codec or recording option that has been requested.",e):console.error("MediaRecorder Error",e)),t&&"inactive"!==t.state&&"stopped"!==t.state&&t.stop()};try{t.start(36e5)}catch(e){t=null}setTimeout((function(){t&&"recording"===t.state&&t.requestData()}),i)},this.stop=function(e){t&&"recording"===t.state&&(t.requestData(),setTimeout((function(){a.dontFireOnDataAvailableEvent=!0,t&&"recording"===t.state&&t.stop(),t=null}),2e3))},this.pause=function(){t&&"recording"===t.state&&t.pause()},this.ondataavailable=function(e){console.log("recorded-blob",e)},this.resume=function(){if(this.dontFireOnDataAvailableEvent){this.dontFireOnDataAvailableEvent=!1;var e=a.disableLogs;return a.disableLogs=!0,this.record(),void(a.disableLogs=e)}t&&"paused"===t.state&&t.resume()},this.clearRecordedData=function(){t&&(this.pause(),this.dontFireOnDataAvailableEvent=!0,this.stop())},function looper(){return t?!1===function isMediaStreamActive(){if("active"in e){if(!e.active)return!1}else if("ended"in e&&e.ended)return!1;return!0}()?void a.stop():void setTimeout(looper,1e3):void 0}()}function StereoAudioRecorder(e){var t,a;this.start=function(i){i=i||1e3,(t=new StereoAudioRecorderHelper(e,this)).record(),a=setInterval((function(){t.requestData()}),i)},this.stop=function(){t&&(t.stop(),clearTimeout(a))},this.pause=function(){t&&t.pause()},this.resume=function(){t&&t.resume()},this.ondataavailable=function(){}}function StereoAudioRecorderHelper(e,t){function mergeBuffers(e,t){for(var a=new Float32Array(t),i=0,r=e.length,o=0;r>o;o++){var n=e[o];a.set(n,i),i+=n.length}return a}function writeUTFBytes(e,t,a){for(var i=a.length,r=0;i>r;r++)e.setUint8(t+r,a.charCodeAt(r))}function convertoFloat32ToInt16(e){for(var t=e.length,a=new Int16Array(t);t--;)a[t]=65535*e[t];return a.buffer}var a;s.AudioContextConstructor||(s.AudioContextConstructor=new s.AudioContext),a=s.AudioContextConstructor.sampleRate;var i,r=[],o=[],n=!1,d=0,u=t.sampleRate||a,c=(t.mimeType||"audio/wav").indexOf("audio/pcm")>-1,h=t.audioChannels||2;this.record=function(){n=!0,r.length=o.length=0,d=0},this.requestData=function(){if(!g){if(0===d)return void(v=!1);v=!0;var e=r.slice(0),a=o.slice(0),i=d;r.length=o.length=[],d=0,v=!1;var n=mergeBuffers(e,i),s=n;if(2===h)s=function interleave(e,t){for(var a=e.length+t.length,i=new Float32Array(a),r=0,o=0;a>o;)i[o++]=e[r],i[o++]=t[r],r++;return i}(n,mergeBuffers(a,i));if(c){var l=new Blob([convertoFloat32ToInt16(s)],{type:"audio/pcm"});return console.debug("audio recorded blob size:",bytesToSize(l.size)),void t.ondataavailable(l)}var f=new ArrayBuffer(44+2*s.length),m=new DataView(f);writeUTFBytes(m,0,"RIFF"),m.setUint32(4,44+2*s.length-8,!0),writeUTFBytes(m,8,"WAVE"),writeUTFBytes(m,12,"fmt "),m.setUint32(16,16,!0),m.setUint16(20,1,!0),m.setUint16(22,h,!0),m.setUint32(24,u,!0),m.setUint32(28,u*h*2,!0),m.setUint16(32,2*h,!0),m.setUint16(34,16,!0),writeUTFBytes(m,36,"data"),m.setUint32(40,2*s.length,!0);for(var p=s.length,w=44,b=0;p>b;b++)m.setInt16(w,32767*s[b],!0),w+=2;l=new Blob([m],{type:"audio/wav"});console.debug("audio recorded blob size:",bytesToSize(l.size)),t.ondataavailable(l)}},this.stop=function(){n=!1,this.requestData(),f.disconnect()};var l=s.AudioContextConstructor;s.VolumeGainNode=l.createGain();var f,m=s.VolumeGainNode;s.AudioInput=l.createMediaStreamSource(e),(f=s.AudioInput).connect(m);var p=t.bufferSize||2048;if(0===t.bufferSize&&(p=0),l.createJavaScriptNode)i=l.createJavaScriptNode(p,h,h);else{if(!l.createScriptProcessor)throw"WebAudio API has no support on this browser.";i=l.createScriptProcessor(p,h,h)}p=i.bufferSize,console.debug("using audio buffer-size:",p);var v=!1;window.scriptprocessornode=i,1===h&&console.debug("All right-channels are skipped.");var g=!1;this.pause=function(){g=!0},this.resume=function(){g=!1},i.onaudioprocess=function(e){if(n&&!v&&!g){var t=e.inputBuffer.getChannelData(0);if(r.push(new Float32Array(t)),2===h){var a=e.inputBuffer.getChannelData(1);o.push(new Float32Array(a))}d+=p}},m.connect(i),i.connect(l.destination)}function WhammyRecorder(e){var t,a;this.start=function(i){for(var r in i=i||1e3,t=new WhammyRecorderHelper(e,this),this)"function"!=typeof this[r]&&(t[r]=this[r]);t.record(),a=setInterval((function(){t.requestData()}),i)},this.stop=function(){t&&(t.stop(),clearTimeout(a))},this.clearOldRecordedFrames=function(){t&&t.clearOldRecordedFrames()},this.pause=function(){t&&t.pause()},this.resume=function(){t&&t.resume()},this.ondataavailable=function(){}}function WhammyRecorderHelper(e,t){function drawFrames(){if(f)return d=(new Date).getTime(),void setTimeout(drawFrames,500);if(!o){if(a)return setTimeout(drawFrames,100);var e=(new Date).getTime()-d;if(!e)return drawFrames();d=(new Date).getTime(),!l.isHTMLObject&&n.paused&&n.play(),h.drawImage(n,0,0,c.width,c.height),o||s.frames.push({duration:e,image:c.toDataURL("image/webp")}),r||function isBlankFrame(e,t,a){var i=document.createElement("canvas");i.width=c.width,i.height=c.height;var r,o,n,d=i.getContext("2d"),s={r:0,g:0,b:0},u=Math.sqrt(Math.pow(255,2)+Math.pow(255,2)+Math.pow(255,2)),h=t&&t>=0&&1>=t?t:0,l=a&&a>=0&&1>=a?a:0,f=new Image;f.src=e.image,d.drawImage(f,0,0,c.width,c.height);var m=d.getImageData(0,0,c.width,c.height);r=0,o=m.data.length,n=m.data.length/4;for(var p=0;o>p;p+=4){var v={r:m.data[p],g:m.data[p+1],b:m.data[p+2]};u*h>=Math.sqrt(Math.pow(v.r-s.r,2)+Math.pow(v.g-s.g,2)+Math.pow(v.b-s.b,2))&&r++}return!(n*l>=n-r)}(s.frames[s.frames.length-1])||(r=!0,t.onStartedDrawingNonBlankFrames()),setTimeout(drawFrames,10)}}this.record=function(a){this.width||(this.width=320),this.height||(this.height=240),this.video&&this.video instanceof HTMLVideoElement&&(this.width||(this.width=n.videoWidth||n.clientWidth||320),this.height||(this.height=n.videoHeight||n.clientHeight||240)),this.video||(this.video={width:this.width,height:this.height}),this.canvas&&this.canvas.width&&this.canvas.height||(this.canvas={width:this.width,height:this.height}),c.width=this.canvas.width,c.height=this.canvas.height,this.video&&this.video instanceof HTMLVideoElement?(this.isHTMLObject=!0,n=this.video.cloneNode()):((n=document.createElement("video")).src=i.createObjectURL(e),n.width=this.video.width,n.height=this.video.height),n.muted=!0,n.play(),d=(new Date).getTime(),s=new u.Video(t.speed,t.quality),console.log("canvas resolutions",c.width,"*",c.height),console.log("video width/height",n.width||c.width,"*",n.height||c.height),drawFrames()},this.clearOldRecordedFrames=function(){s.frames=[]};var a=!1;this.requestData=function(){if(!f){if(!s.frames.length)return void(a=!1);a=!0;var e=s.frames.slice(0);s.frames=function dropBlackFrames(e,t,a,i){var r=document.createElement("canvas");r.width=c.width,r.height=c.height;for(var o=r.getContext("2d"),n=[],d=-1===t,s=t&&t>0&&t<=e.length?t:e.length,u={r:0,g:0,b:0},h=Math.sqrt(Math.pow(255,2)+Math.pow(255,2)+Math.pow(255,2)),l=a&&a>=0&&1>=a?a:0,f=i&&i>=0&&1>=i?i:0,m=!1,p=0;s>p;p++){var v,g,w;if(!m){var b=new Image;b.src=e[p].image,o.drawImage(b,0,0,c.width,c.height);var y=o.getImageData(0,0,c.width,c.height);v=0,g=y.data.length,w=y.data.length/4;for(var A=0;g>A;A+=4){var M={r:y.data[A],g:y.data[A+1],b:y.data[A+2]};h*l>=Math.sqrt(Math.pow(M.r-u.r,2)+Math.pow(M.g-u.g,2)+Math.pow(M.b-u.b,2))&&v++}}!m&&w*f>=w-v||(d&&(m=!0),n.push(e[p]))}return(n=n.concat(e.slice(s))).length<=0&&n.push(e[e.length-1]),n}(e,-1),s.compile((function(e){t.ondataavailable(e),console.debug("video recorded blob size:",bytesToSize(e.size))})),s.frames=[],a=!1}};var r=!1,o=!1;this.stop=function(){o=!0,this.requestData()};var n,d,s,c=document.createElement("canvas"),h=c.getContext("2d"),l=this,f=!1;this.pause=function(){f=!0},this.resume=function(){f=!1}}function GifRecorder(e){function doneRecording(){Date.now();var e=new Blob([new Uint8Array(s.stream().bin)],{type:"image/gif"});a.ondataavailable(e),s.stream().bin=[]}if("undefined"==typeof GIFEncoder)throw"Please link: https://cdn.webrtc-experiment.com/gif-recorder.js";this.start=function(e){e=e||1e3;var a=this.videoWidth||320,i=this.videoHeight||240;r.width=n.width=a,r.height=n.height=i,(s=new GIFEncoder).setRepeat(0),s.setDelay(this.frameRate||this.speed||200),s.setQuality(this.quality||1),s.start(),Date.now(),c=requestAnimationFrame((function drawVideoFrame(e){return t?void setTimeout(drawVideoFrame,500,e):(c=requestAnimationFrame(drawVideoFrame),void 0===typeof d&&(d=e),void(90>e-d||(n.paused&&n.play(),o.drawImage(n,0,0,a,i),s.addFrame(o),d=e)))})),u=setTimeout(doneRecording,e)},this.stop=function(){c&&(cancelAnimationFrame(c),clearTimeout(u),doneRecording())};var t=!1;this.pause=function(){t=!0},this.resume=function(){t=!1},this.ondataavailable=function(){},this.onstop=function(){};var a=this,r=document.createElement("canvas"),o=r.getContext("2d"),n=document.createElement("video");n.muted=!0,n.autoplay=!0,n.src=i.createObjectURL(e),n.play();var d,s,u,c=null}MediaStreamRecorder.MultiStreamRecorder=function MultiStreamRecorder(e){if(!e)throw"MediaStream is mandatory.";var t=this,a=isMediaRecorderCompatible();this.stream=e,this.start=function(d){function fireOnDataAvailableEvent(e){n++,t.ondataavailable(e)}for(var s in i=new MediaStreamRecorder(e),r=new MediaStreamRecorder(e),i.mimeType="audio/ogg",r.mimeType="video/webm",this)"function"!=typeof this[s]&&(i[s]=r[s]=this[s]);i.ondataavailable=function(e){o[n]||(o[n]={}),o[n].audio=e,o[n].video&&!o[n].onDataAvailableEventFired&&(o[n].onDataAvailableEventFired=!0,fireOnDataAvailableEvent(o[n]))},r.ondataavailable=function(e){return a?t.ondataavailable({video:e,audio:e}):(o[n]||(o[n]={}),o[n].video=e,void(o[n].audio&&!o[n].onDataAvailableEventFired&&(o[n].onDataAvailableEventFired=!0,fireOnDataAvailableEvent(o[n]))))},r.onstop=i.onstop=function(e){t.onstop(e)},a||(r.onStartedDrawingNonBlankFrames=function(){r.clearOldRecordedFrames(),i.start(d)}),r.start(d)},this.stop=function(){i&&i.stop(),r&&r.stop()},this.ondataavailable=function(e){console.log("ondataavailable..",e)},this.onstop=function(e){console.warn("stopped..",e)},this.pause=function(){i&&i.pause(),r&&r.pause()},this.resume=function(){i&&i.resume(),r&&r.resume()};var i,r,o={},n=0};var e,t,a="Fake/5.0 (FakeOS) AppleWebKit/123 (KHTML, like Gecko) Fake/12.3.4567.89 Fake/123.45";e="undefined"!=typeof global?global:window,"undefined"==typeof window&&("undefined"==typeof window&&"undefined"!=typeof global&&(global.navigator={userAgent:a,getUserMedia:function(){}},e.window=global),"undefined"==typeof document&&(e.document={},document.createElement=document.captureStream=document.mozCaptureStream=function(){return{}}),"undefined"==typeof location&&(e.location={protocol:"file:",href:"",hash:""}),"undefined"==typeof screen&&(e.screen={width:0,height:0})),void 0===(t=window.AudioContext)&&("undefined"!=typeof webkitAudioContext&&(t=webkitAudioContext),"undefined"!=typeof mozAudioContext&&(t=mozAudioContext)),"undefined"==typeof window&&(window={}),void 0===(t=window.AudioContext)&&("undefined"!=typeof webkitAudioContext&&(t=webkitAudioContext),"undefined"!=typeof mozAudioContext&&(t=mozAudioContext));var i=window.URL;void 0===i&&"undefined"!=typeof webkitURL&&(i=webkitURL),"undefined"!=typeof navigator?(void 0!==navigator.webkitGetUserMedia&&(navigator.getUserMedia=navigator.webkitGetUserMedia),void 0!==navigator.mozGetUserMedia&&(navigator.getUserMedia=navigator.mozGetUserMedia)):navigator={getUserMedia:function(){},userAgent:a};var r=!(-1===navigator.userAgent.indexOf("Edge")||!navigator.msSaveBlob&&!navigator.msSaveOrOpenBlob),o=!1;"undefined"!=typeof opera&&navigator.userAgent&&-1!==navigator.userAgent.indexOf("OPR/")&&(o=!0);var n=!r&&!r&&!!navigator.webkitGetUserMedia,d=window.MediaStream;void 0===d&&"undefined"!=typeof webkitMediaStream&&(d=webkitMediaStream),void 0!==d&&("getVideoTracks"in d.prototype||(d.prototype.getVideoTracks=function(){if(!this.getTracks)return[];var e=[];return this.getTracks.forEach((function(t){-1!==t.kind.toString().indexOf("video")&&e.push(t)})),e},d.prototype.getAudioTracks=function(){if(!this.getTracks)return[];var e=[];return this.getTracks.forEach((function(t){-1!==t.kind.toString().indexOf("audio")&&e.push(t)})),e}),"stop"in d.prototype||(d.prototype.stop=function(){this.getAudioTracks().forEach((function(e){e.stop&&e.stop()})),this.getVideoTracks().forEach((function(e){e.stop&&e.stop()}))})),"undefined"!=typeof location&&0===location.href.indexOf("file:")&&console.error("Please load this HTML file on HTTP or HTTPS.");var s={AudioContext:t};s={AudioContext:window.AudioContext||window.webkitAudioContext};MediaStreamRecorder.MediaRecorderWrapper=MediaRecorderWrapper,MediaStreamRecorder.StereoAudioRecorder=StereoAudioRecorder,MediaStreamRecorder.StereoAudioRecorderHelper=StereoAudioRecorderHelper,MediaStreamRecorder.WhammyRecorder=WhammyRecorder,MediaStreamRecorder.WhammyRecorderHelper=WhammyRecorderHelper,MediaStreamRecorder.GifRecorder=GifRecorder;var u=function(){function WhammyVideo(e,t){this.frames=[],e||(e=1),this.duration=1e3/e,this.quality=t||.8}function whammyInWebWorker(e){function getClusterData(e,t,a){return[{data:e,id:231}].concat(a.map((function(e){var a=function makeSimpleBlock(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:a,id:163}})))}function numToBuffer(e){for(var t=[];e>0;)t.push(255&e),e>>=8;return new Uint8Array(t.reverse())}function bitsToBuffer(e){var t=[];e=(e.length%8?new Array(9-e.length%8).join("0"):"")+e;for(var a=0;a<e.length;a+=8)t.push(parseInt(e.substr(a,8),2));return new Uint8Array(t)}function generateEBML(e){for(var t=[],a=0;a<e.length;a++){var i=e[a].data;"object"==typeof i&&(i=generateEBML(i)),"number"==typeof i&&(i=bitsToBuffer(i.toString(2))),"string"==typeof i&&(i=new Uint8Array(i.split("").map((function(e){return e.charCodeAt(0)}))));var r=i.size||i.byteLength||i.length,o=Math.ceil(Math.ceil(Math.log(r)/Math.log(2))/8),n=r.toString(2),d=new Array(7*o+7+1-n.length).join("0")+n,s=new Array(o).join("0")+"1"+d;t.push(numToBuffer(e[a].id)),t.push(bitsToBuffer(s)),t.push(i)}return new Blob(t,{type:"video/webm"})}function getStrLength(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 parseRIFF(e){for(var t=0,a={};t<e.length;){var i=e.substr(t,4),r=getStrLength(e,t),o=e.substr(t+4+4,r);t+=8+r,a[i]=a[i]||[],"RIFF"===i||"LIST"===i?a[i].push(parseRIFF(o)):a[i].push(o)}return a}var t=new function ArrayToWebM(e){var t,a=function checkFrames(e){if(!e[0])return void postMessage({error:"Something went wrong. Maybe WebP format is not supported in the current browser."});for(var t=e[0].width,a=e[0].height,i=e[0].duration,r=1;r<e.length;r++)i+=e[r].duration;return{duration:i,width:t,height:a}}(e);if(!a)return[];for(var i=[{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:(t=a.duration,[].slice.call(new Uint8Array(new Float64Array([t]).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:a.width,id:176},{data:a.height,id:186}]}]}]}]}],r=0,o=0;r<e.length;){var n=[],d=0;do{n.push(e[r]),d+=e[r].duration,r++}while(r<e.length&&3e4>d);var s={id:524531317,data:getClusterData(o,0,n)};i[1].data.push(s),o+=d}return generateEBML(i)}(e.map((function(e){var t=function parseWebP(e){for(var t=e.RIFF[0].WEBP[0],a=t.indexOf("*"),i=0,r=[];4>i;i++)r[i]=t.charCodeAt(a+3+i);return{width:16383&(r[1]<<8|r[0]),height:16383&(r[3]<<8|r[2]),data:t,riff:e}}(parseRIFF(atob(e.image.slice(23))));return t.duration=e.duration,t})));postMessage(t)}return WhammyVideo.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})},WhammyVideo.prototype.compile=function(e){var t=function processInWebWorker(e){var t=i.createObjectURL(new Blob([e.toString(),"this.onmessage = function (e) {"+e.name+"(e.data);}"],{type:"application/javascript"})),a=new Worker(t);return i.revokeObjectURL(t),a}(whammyInWebWorker);t.onmessage=function(t){return t.data.error?void console.error(t.data.error):void e(t.data)},t.postMessage(this.frames)},{Video:WhammyVideo}}();MediaStreamRecorder.Whammy=u,window.ConcatenateBlobs=function(e,t,a){var i=[],r=0;!function readAsArrayBuffer(){if(!e[r])return function concatenateBuffers(){var e=0;i.forEach((function(t){e+=t.byteLength}));var r=new Uint16Array(e),o=0;i.forEach((function(e){var t=e.byteLength;t%2!=0&&(e=e.slice(0,t-1)),r.set(new Uint16Array(e),o),o+=t}));var n=new Blob([r.buffer],{type:t});a(n)}();var o=new FileReader;o.onload=function(e){i.push(e.target.result),r++,readAsArrayBuffer()},o.readAsArrayBuffer(e[r])}()},"undefined"!=typeof module&&(module.exports=MediaStreamRecorder),"function"==typeof define&&define.amd&&define("MediaStreamRecorder",[],(function(){return MediaStreamRecorder}));