recordrtc-ponyfill
Version:
RecordRTC is a server-less (entire client-side) JavaScript library that can be used to record WebRTC audio/video media streams. It supports cross-browser audio/video recording.
1 lines • 55.4 kB
JavaScript
"use strict";var{ReadableStream:ReadableStream,WritableStream:WritableStream}=require("web-streams-polyfill/ponyfill");function RecordRTC(e,t){if(!e)throw"First parameter is required.";t=new RecordRTCConfiguration(e,t=t||{type:"video"});var o=this;function i(o){o&&(t.initCallback=function(){o(),o=t.initCallback=null});var i=new GetRecorderType(e,t);(c=new i(e,t)).record(),s("recording"),t.disableLogs||console.log("Initialized recorderType:",c.constructor.name,"for output-type:",t.type)}function r(e){if(e=e||function(){},c){if("paused"===o.state)return o.resumeRecording(),void setTimeout(function(){r(e)},1);"recording"===o.state||t.disableLogs||console.warn('Recording state should be: "recording", however current state is: ',o.state),t.disableLogs||console.log("Stopped recording "+t.type+" stream."),"gif"!==t.type?c.stop(i):(c.stop(),i()),s("stopped")}else l();function i(i){if(c){Object.keys(c).forEach(function(e){"function"!=typeof c[e]&&(o[e]=c[e])});var r=c.blob;if(!r){if(!i)throw"Recording failed.";c.blob=r=i}if(r&&!t.disableLogs&&console.log(r.type,"->",bytesToSize(r.size)),e){var n;try{n=URL.createObjectURL(r)}catch(e){}"function"==typeof e.call?e.call(o,n):e(n)}t.autoWriteToDisk&&a(function(e){var o={};o[t.type+"Blob"]=e,DiskStorage.Store(o)})}else"function"==typeof e.call?e.call(o,""):e("")}}function n(e){postMessage((new FileReaderSync).readAsDataURL(e))}function a(e,o){if(!e)throw"Pass a callback function over getDataURL.";var i=o?o.blob:(c||{}).blob;if(!i)return t.disableLogs||console.warn("Blob encoder did not finish its job yet."),void setTimeout(function(){a(e,o)},1e3);if("undefined"==typeof Worker||navigator.mozGetUserMedia){var r=new FileReader;r.readAsDataURL(i),r.onload=function(t){e(t.target.result)}}else{var d=function(e){try{var t=URL.createObjectURL(new Blob([e.toString(),"this.onmessage = function (eee) {"+e.name+"(eee.data);}"],{type:"application/javascript"})),o=new Worker(t);return URL.revokeObjectURL(t),o}catch(e){}}(n);d.onmessage=function(t){e(t.data)},d.postMessage(i)}}function d(e){e=e||0,"paused"!==o.state?"stopped"!==o.state&&(e>=o.recordingDuration?r(o.onRecordingStopped):(e+=1e3,setTimeout(function(){d(e)},1e3))):setTimeout(function(){d(e)},1e3)}function s(e){o&&(o.state=e,"function"==typeof o.onStateChanged.call?o.onStateChanged.call(o,e):o.onStateChanged(e))}var c,u='It seems that recorder is destroyed or "startRecording" is not invoked for '+t.type+" recorder.";function l(){!0!==t.disableLogs&&console.warn(u)}var f={startRecording:function(r){return t.disableLogs||console.log("RecordRTC version: ",o.version),r&&(t=new RecordRTCConfiguration(e,r)),t.disableLogs||console.log("started recording "+t.type+" stream."),c?(c.clearRecordedData(),c.record(),s("recording"),o.recordingDuration&&d(),o):(i(function(){o.recordingDuration&&d()}),o)},stopRecording:r,pauseRecording:function(){c?"recording"===o.state?(s("paused"),c.pause(),t.disableLogs||console.log("Paused recording.")):t.disableLogs||console.warn("Unable to pause the recording. Recording state: ",o.state):l()},resumeRecording:function(){c?"paused"===o.state?(s("recording"),c.resume(),t.disableLogs||console.log("Resumed recording.")):t.disableLogs||console.warn("Unable to resume the recording. Recording state: ",o.state):l()},initRecorder:i,setRecordingDuration:function(e,t){if(void 0===e)throw"recordingDuration is required.";if("number"!=typeof e)throw"recordingDuration must be a number.";return o.recordingDuration=e,o.onRecordingStopped=t||function(){},{onRecordingStopped:function(e){o.onRecordingStopped=e}}},clearRecordedData:function(){c?(c.clearRecordedData(),t.disableLogs||console.log("Cleared old recorded data.")):l()},getBlob:function(){if(c)return c.blob;l()},getDataURL:a,toURL:function(){if(c)return URL.createObjectURL(c.blob);l()},getInternalRecorder:function(){return c},save:function(e){c?invokeSaveAsDialog(c.blob,e):l()},getFromDisk:function(e){c?RecordRTC.getFromDisk(t.type,e):l()},setAdvertisementArray:function(e){t.advertisement=[];for(var o=e.length,i=0;i<o;i++)t.advertisement.push({duration:i,image:e[i]})},blob:null,bufferSize:0,sampleRate:0,buffer:null,reset:function(){"recording"!==o.state||t.disableLogs||console.warn("Stop an active recorder."),c&&"function"==typeof c.clearRecordedData&&c.clearRecordedData(),c=null,s("inactive"),o.blob=null},onStateChanged:function(e){t.disableLogs||console.log("Recorder state changed:",e)},state:"inactive",getState:function(){return o.state},destroy:function(){var e=t.disableLogs;t={disableLogs:!0},o.reset(),s("destroyed"),f=o=null,Storage.AudioContextConstructor&&(Storage.AudioContextConstructor.close(),Storage.AudioContextConstructor=null),t.disableLogs=e,t.disableLogs||console.log("RecordRTC is destroyed.")},version:"5.6.1"};if(!this)return o=f,f;for(var m in f)this[m]=f[m];return o=this,f}function RecordRTCConfiguration(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===WhammyRecorder||t.recorderType===CanvasRecorder||void 0!==WebAssemblyRecorder&&t.recorderType===WebAssemblyRecorder?t.type="video":t.recorderType===GifRecorder?t.type="gif":t.recorderType===StereoAudioRecorder?t.type="audio":t.recorderType===MediaStreamRecorder&&(getTracks(e,"audio").length&&getTracks(e,"video").length?t.type="video":!getTracks(e,"audio").length&&getTracks(e,"video").length?t.type="video":getTracks(e,"audio").length&&!getTracks(e,"video").length&&(t.type="audio"))),void 0!==MediaStreamRecorder&&"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 GetRecorderType(e,t){var o;return(isChrome||isEdge||isOpera)&&(o=StereoAudioRecorder),"undefined"!=typeof MediaRecorder&&"requestData"in MediaRecorder.prototype&&!isChrome&&(o=MediaStreamRecorder),"video"===t.type&&(isChrome||isOpera)&&(o=WhammyRecorder,void 0!==WebAssemblyRecorder&&void 0!==ReadableStream&&(o=WebAssemblyRecorder)),"gif"===t.type&&(o=GifRecorder),"canvas"===t.type&&(o=CanvasRecorder),isMediaRecorderCompatible()&&o!==CanvasRecorder&&o!==GifRecorder&&"undefined"!=typeof MediaRecorder&&"requestData"in MediaRecorder.prototype&&(getTracks(e,"video").length||getTracks(e,"audio").length)&&("audio"===t.type?"function"==typeof MediaRecorder.isTypeSupported&&MediaRecorder.isTypeSupported("audio/webm")&&(o=MediaStreamRecorder):"function"==typeof MediaRecorder.isTypeSupported&&MediaRecorder.isTypeSupported("video/webm")&&(o=MediaStreamRecorder)),e instanceof Array&&e.length&&(o=MultiStreamRecorder),t.recorderType&&(o=t.recorderType),!t.disableLogs&&o&&o.name&&console.log("Using recorderType:",o.name||o.constructor.name),!o&&isSafari&&(o=MediaStreamRecorder),o}function MRecordRTC(e){this.addStream=function(t){t&&(e=t)},this.mediaType={audio:!0,video:!0},this.startRecording=function(){var t,o=this.mediaType,i=this.mimeType||{audio:null,video:null,gif:null};if("function"!=typeof o.audio&&isMediaRecorderCompatible()&&!getTracks(e,"audio").length&&(o.audio=!1),"function"!=typeof o.video&&isMediaRecorderCompatible()&&!getTracks(e,"video").length&&(o.video=!1),"function"!=typeof o.gif&&isMediaRecorderCompatible()&&!getTracks(e,"video").length&&(o.gif=!1),!o.audio&&!o.video&&!o.gif)throw"MediaStream must have either audio or video tracks.";if(o.audio&&(t=null,"function"==typeof o.audio&&(t=o.audio),this.audioRecorder=new RecordRTC(e,{type:"audio",bufferSize:this.bufferSize,sampleRate:this.sampleRate,numberOfAudioChannels:this.numberOfAudioChannels||2,disableLogs:this.disableLogs,recorderType:t,mimeType:i.audio,timeSlice:this.timeSlice,onTimeStamp:this.onTimeStamp}),o.video||this.audioRecorder.startRecording()),o.video){t=null,"function"==typeof o.video&&(t=o.video);var r=e;if(isMediaRecorderCompatible()&&o.audio&&"function"==typeof o.audio){var n=getTracks(e,"video")[0];isFirefox?((r=new MediaStream).addTrack(n),t&&t===WhammyRecorder&&(t=MediaStreamRecorder)):(r=new MediaStream).addTrack(n)}this.videoRecorder=new RecordRTC(r,{type:"video",video:this.video,canvas:this.canvas,frameInterval:this.frameInterval||10,disableLogs:this.disableLogs,recorderType:t,mimeType:i.video,timeSlice:this.timeSlice,onTimeStamp:this.onTimeStamp,workerPath:this.workerPath,webAssemblyPath:this.webAssemblyPath,frameRate:this.frameRate,bitrate:this.bitrate}),o.audio||this.videoRecorder.startRecording()}if(o.audio&&o.video){var a=this,d=!0===isMediaRecorderCompatible();o.audio instanceof StereoAudioRecorder&&o.video?d=!1:!0!==o.audio&&!0!==o.video&&o.audio!==o.video&&(d=!1),!0===d?(a.audioRecorder=null,a.videoRecorder.startRecording()):a.videoRecorder.initRecorder(function(){a.audioRecorder.initRecorder(function(){a.videoRecorder.startRecording(),a.audioRecorder.startRecording()})})}o.gif&&(t=null,"function"==typeof o.gif&&(t=o.gif),this.gifRecorder=new RecordRTC(e,{type:"gif",frameRate:this.frameRate||200,quality:this.quality||10,disableLogs:this.disableLogs,recorderType:t,mimeType:i.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 o=function(e){var t,o=URL.createObjectURL(new Blob([e.toString(),"this.onmessage = function (eee) {"+e.name+"(eee.data);}"],{type:"application/javascript"})),i=new Worker(o);if(void 0!==URL)t=URL;else{if("undefined"==typeof webkitURL)throw"Neither URL nor webkitURL detected.";t=webkitURL}return t.revokeObjectURL(o),i}(function(e){postMessage((new FileReaderSync).readAsDataURL(e))});o.onmessage=function(e){t(e.data)},o.postMessage(e)}else{var i=new FileReader;i.readAsDataURL(e),i.onload=function(e){t(e.target.result)}}}this.getBlob(function(o){o.audio&&o.video?t(o.audio,function(i){t(o.video,function(t){e({audio:i,video:t})})}):o.audio?t(o.audio,function(t){e({audio:t})}):o.video&&t(o.video,function(t){e({video:t})})})},this.writeToDisk=function(){RecordRTC.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:"")}}RecordRTC.version="5.6.1","undefined"!=typeof module&&(module.exports=RecordRTC),"function"==typeof define&&define.amd&&define("RecordRTC",[],function(){return RecordRTC}),RecordRTC.getFromDisk=function(e,t){if(!t)throw"callback is mandatory.";console.log("Getting recorded "+("all"===e?"blobs":e+" blob ")+" from disk!"),DiskStorage.Fetch(function(o,i){"all"!==e&&i===e+"Blob"&&t&&t(o),"all"===e&&t&&t(o,i.replace("Blob",""))})},RecordRTC.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(o){e.gif.getDataURL(function(e){DiskStorage.Store({audioBlob:t,videoBlob:o,gifBlob:e})})})}):e.audio&&e.video?e.audio.getDataURL(function(t){e.video.getDataURL(function(e){DiskStorage.Store({audioBlob:t,videoBlob:e})})}):e.audio&&e.gif?e.audio.getDataURL(function(t){e.gif.getDataURL(function(e){DiskStorage.Store({audioBlob:t,gifBlob:e})})}):e.video&&e.gif?e.video.getDataURL(function(t){e.gif.getDataURL(function(e){DiskStorage.Store({videoBlob:t,gifBlob:e})})}):e.audio?e.audio.getDataURL(function(e){DiskStorage.Store({audioBlob:e})}):e.video?e.video.getDataURL(function(e){DiskStorage.Store({videoBlob:e})}):e.gif&&e.gif.getDataURL(function(e){DiskStorage.Store({gifBlob:e})})},MRecordRTC.getFromDisk=RecordRTC.getFromDisk,MRecordRTC.writeToDisk=RecordRTC.writeToDisk,void 0!==RecordRTC&&(RecordRTC.MRecordRTC=MRecordRTC);var browserFakeUserAgent="Fake/5.0 (FakeOS) AppleWebKit/123 (KHTML, like Gecko) Fake/12.3.4567.89 Fake/123.45";!function(e){e&&"undefined"==typeof window&&"undefined"!=typeof global&&(global.navigator={userAgent:browserFakeUserAgent,getUserMedia:function(){}},global.console||(global.console={}),void 0!==global.console.log&&void 0!==global.console.error||(global.console.error=global.console.log=global.console.log||function(){console.log(arguments)}),"undefined"==typeof document&&(e.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},e.HTMLVideoElement=function(){}),"undefined"==typeof location&&(e.location={protocol:"file:",href:"",hash:""}),"undefined"==typeof screen&&(e.screen={width:0,height:0}),void 0===URL&&(e.URL={createObjectURL:function(){return""},revokeObjectURL:function(){return""}}),e.window=global)}("undefined"!=typeof global?global:null);var requestAnimationFrame=window.requestAnimationFrame;if(void 0===requestAnimationFrame)if("undefined"!=typeof webkitRequestAnimationFrame)requestAnimationFrame=webkitRequestAnimationFrame;else if("undefined"!=typeof mozRequestAnimationFrame)requestAnimationFrame=mozRequestAnimationFrame;else if("undefined"!=typeof msRequestAnimationFrame)requestAnimationFrame=msRequestAnimationFrame;else if(void 0===requestAnimationFrame){var lastTime=0;requestAnimationFrame=function(e,t){var o=(new Date).getTime(),i=Math.max(0,16-(o-lastTime)),r=setTimeout(function(){e(o+i)},i);return lastTime=o+i,r}}var cancelAnimationFrame=window.cancelAnimationFrame;void 0===cancelAnimationFrame&&("undefined"!=typeof webkitCancelAnimationFrame?cancelAnimationFrame=webkitCancelAnimationFrame:"undefined"!=typeof mozCancelAnimationFrame?cancelAnimationFrame=mozCancelAnimationFrame:"undefined"!=typeof msCancelAnimationFrame?cancelAnimationFrame=msCancelAnimationFrame:void 0===cancelAnimationFrame&&(cancelAnimationFrame=function(e){clearTimeout(e)}));var AudioContext=window.AudioContext;void 0===AudioContext&&("undefined"!=typeof webkitAudioContext&&(AudioContext=webkitAudioContext),"undefined"!=typeof mozAudioContext&&(AudioContext=mozAudioContext));var URL=window.URL;void 0===URL&&"undefined"!=typeof webkitURL&&(URL=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 isEdge=!(-1===navigator.userAgent.indexOf("Edge")||!navigator.msSaveBlob&&!navigator.msSaveOrOpenBlob),isOpera=!!window.opera||-1!==navigator.userAgent.indexOf("OPR/"),isFirefox=navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&"netscape"in window&&/ rv:/.test(navigator.userAgent),isChrome=!isOpera&&!isEdge&&!!navigator.webkitGetUserMedia||isElectron()||-1!==navigator.userAgent.toLowerCase().indexOf("chrome/"),isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);isSafari&&!isChrome&&-1!==navigator.userAgent.indexOf("CriOS")&&(isSafari=!1,isChrome=!0);var MediaStream=window.MediaStream;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 invokeSaveAsDialog(e,t){if(!e)throw"Blob object is required.";if(!e.type)try{e.type="video/webm"}catch(e){}var o=(e.type||"video/webm").split("/")[1];if(t&&-1!==t.indexOf(".")){var i=t.split(".");t=i[0],o=i[1]}var r=(t||Math.round(9999999999*Math.random())+888888888)+"."+o;if(void 0!==navigator.msSaveOrOpenBlob)return navigator.msSaveOrOpenBlob(e,r);if(void 0!==navigator.msSaveBlob)return navigator.msSaveBlob(e,r);var n=document.createElement("a");n.href=URL.createObjectURL(e),n.download=r,n.style="display:none;opacity:0;color:transparent;",(document.body||document.documentElement).appendChild(n),"function"==typeof n.click?n.click():(n.target="_blank",n.dispatchEvent(new MouseEvent("click",{view:window,bubbles:!0,cancelable:!0}))),URL.revokeObjectURL(n.href)}function isElectron(){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 getTracks(e,t){return e&&e.getTracks?e.getTracks().filter(function(e){return e.kind===(t||"audio")}):[]}function setSrcObject(e,t){"srcObject"in t?t.srcObject=e:"mozSrcObject"in t?t.mozSrcObject=e:t.srcObject=e}function getSeekableBlob(e,t){if("undefined"==typeof EBML)throw new Error("Please link: https://www.webrtc-experiment.com/EBML.js");var o=new EBML.Reader,i=new EBML.Decoder,r=EBML.tools,n=new FileReader;n.onload=function(e){i.decode(this.result).forEach(function(e){o.read(e)}),o.stop();var n=r.makeMetadataSeekable(o.metadatas,o.duration,o.cues),a=this.result.slice(o.metadataSize),d=new Blob([n,a],{type:"video/webm"});t(d)},n.readAsArrayBuffer(e)}void 0===MediaStream&&"undefined"!=typeof webkitMediaStream&&(MediaStream=webkitMediaStream),void 0!==MediaStream&&void 0===MediaStream.prototype.stop&&(MediaStream.prototype.stop=function(){this.getTracks().forEach(function(e){e.stop()})}),void 0!==RecordRTC&&(RecordRTC.invokeSaveAsDialog=invokeSaveAsDialog,RecordRTC.getTracks=getTracks,RecordRTC.getSeekableBlob=getSeekableBlob,RecordRTC.bytesToSize=bytesToSize,RecordRTC.isElectron=isElectron);var Storage={};function isMediaRecorderCompatible(){if(isFirefox||isSafari||isEdge)return!0;navigator.appVersion;var e,t,o=navigator.userAgent,i=""+parseFloat(navigator.appVersion),r=parseInt(navigator.appVersion,10);return(isChrome||isOpera)&&(e=o.indexOf("Chrome"),i=o.substring(e+7)),-1!==(t=i.indexOf(";"))&&(i=i.substring(0,t)),-1!==(t=i.indexOf(" "))&&(i=i.substring(0,t)),r=parseInt(""+i,10),isNaN(r)&&(i=""+parseFloat(navigator.appVersion),r=parseInt(navigator.appVersion,10)),r>=49}function MediaStreamRecorder(e,t){var o=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.";if("audio"===(t=t||{mimeType:"video/webm"}).type){var i;if(getTracks(e,"video").length&&getTracks(e,"audio").length)navigator.mozGetUserMedia?(i=new MediaStream).addTrack(getTracks(e,"audio")[0]):i=new MediaStream(getTracks(e,"audio")),e=i;t.mimeType&&-1!==t.mimeType.toString().toLowerCase().indexOf("audio")||(t.mimeType=isChrome?"audio/webm":"audio/ogg"),t.mimeType&&"audio/ogg"!==t.mimeType.toString().toLowerCase()&&navigator.mozGetUserMedia&&(t.mimeType="audio/ogg")}var r,n=[];function a(){o.timestamps.push((new Date).getTime()),"function"==typeof t.onTimeStamp&&t.onTimeStamp(o.timestamps[o.timestamps.length-1],o.timestamps)}function d(e){return r&&r.mimeType?r.mimeType:e.mimeType||"video/webm"}function s(){n=[],r=null,o.timestamps=[]}this.getArrayOfBlobs=function(){return n},this.record=function(){o.blob=null,o.clearRecordedData(),o.timestamps=[],c=[],n=[];var i=t;t.disableLogs||console.log("Passing following config over MediaRecorder API.",i),r&&(r=null),isChrome&&!isMediaRecorderCompatible()&&(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{r=new MediaRecorder(e,i),t.mimeType=i.mimeType}catch(t){r=new MediaRecorder(e)}i.mimeType&&!MediaRecorder.isTypeSupported&&"canRecordMimeType"in r&&!1===r.canRecordMimeType(i.mimeType)&&(t.disableLogs||console.warn("MediaRecorder API seems unable to record mimeType:",i.mimeType)),r.ondataavailable=function(e){if(e.data&&c.push("ondataavailable: "+bytesToSize(e.data.size)),"number"!=typeof t.timeSlice)!e.data||!e.data.size||e.data.size<100||o.blob?o.recordingCallback&&(o.recordingCallback(new Blob([],{type:d(i)})),o.recordingCallback=null):(o.blob=t.getNativeBlob?e.data:new Blob([e.data],{type:d(i)}),o.recordingCallback&&(o.recordingCallback(o.blob),o.recordingCallback=null));else if(e.data&&e.data.size&&e.data.size>100&&(n.push(e.data),a(),"function"==typeof t.ondataavailable)){var r=t.getNativeBlob?e.data:new Blob([e.data],{type:d(i)});t.ondataavailable(r)}},r.onstart=function(){c.push("started")},r.onpause=function(){c.push("paused")},r.onresume=function(){c.push("resumed")},r.onstop=function(){c.push("stopped")},r.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(!o.manuallyStopped&&r&&"inactive"===r.state)return delete t.timeslice,void r.start(6e5);setTimeout(void 0,1e3)}(),"inactive"!==r.state&&"stopped"!==r.state&&r.stop())},"number"==typeof t.timeSlice?(a(),r.start(t.timeSlice)):r.start(36e5),t.initCallback&&t.initCallback()},this.timestamps=[],this.stop=function(e){e=e||function(){},o.manuallyStopped=!0,r&&(this.recordingCallback=e,"recording"===r.state&&r.stop(),"number"==typeof t.timeSlice&&setTimeout(function(){o.blob=new Blob(n,{type:d(t)}),o.recordingCallback(o.blob)},100))},this.pause=function(){r&&"recording"===r.state&&r.pause()},this.resume=function(){r&&"paused"===r.state&&r.resume()},this.clearRecordedData=function(){r&&"recording"===r.state&&o.stop(s),s()},this.getInternalRecorder=function(){return r},this.blob=null,this.getState=function(){return r&&r.state||"inactive"};var c=[];this.getAllStates=function(){return c},void 0===t.checkForInactiveTracks&&(t.checkForInactiveTracks=!1);o=this;!function i(){if(r&&!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 o.stop()):void setTimeout(i,1e3)}(),this.name="MediaStreamRecorder",this.toString=function(){return this.name}}function StereoAudioRecorder(e,t){if(!getTracks(e,"audio").length)throw"Your stream has no audio tracks.";var o,i=this,r=[],n=[],a=!1,d=0,s=2,c=(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 l(e,t){function o(e,t){var o,i=e.numberOfAudioChannels,r=e.leftBuffers.slice(0),n=e.rightBuffers.slice(0),a=e.sampleRate,d=e.internalInterleavedLength,s=e.desiredSampRate;function c(e,t,o){var i=Math.round(e.length*(t/o)),r=[],n=Number((e.length-1)/(i-1));r[0]=e[0];for(var a=1;a<i-1;a++){var d=a*n,s=Number(Math.floor(d)).toFixed(),c=Number(Math.ceil(d)).toFixed(),l=d-s;r[a]=u(e[s],e[c],l)}return r[i-1]=e[e.length-1],r}function u(e,t,o){return e+(t-e)*o}function l(e,t){for(var o=new Float64Array(t),i=0,r=e.length,n=0;n<r;n++){var a=e[n];o.set(a,i),i+=a.length}return o}function f(e,t,o){for(var i=o.length,r=0;r<i;r++)e.setUint8(t+r,o.charCodeAt(r))}2===i&&(r=l(r,d),n=l(n,d),s&&(r=c(r,s,a),n=c(n,s,a))),1===i&&(r=l(r,d),s&&(r=c(r,s,a))),s&&(a=s),2===i&&(o=function(e,t){for(var o=e.length+t.length,i=new Float64Array(o),r=0,n=0;n<o;)i[n++]=e[r],i[n++]=t[r],r++;return i}(r,n)),1===i&&(o=r);var m=o.length,h=new ArrayBuffer(44+2*m),g=new DataView(h);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,i,!0),g.setUint32(24,a,!0),g.setUint32(28,2*a,!0),g.setUint16(32,2*i,!0),g.setUint16(34,16,!0),f(g,36,"data"),g.setUint32(40,2*m,!0);for(var p=m,v=44,b=0;b<p;b++)g.setInt16(v,32767*o[b],!0),v+=2;if(t)return t({buffer:h,view:g});postMessage({buffer:h,view:g})}if(e.noWorker)o(e,function(e){t(e.buffer,e.view)});else{var i,r,n,a=(i=o,r=URL.createObjectURL(new Blob([i.toString(),";this.onmessage = function (eee) {"+i.name+"(eee.data);}"],{type:"application/javascript"})),(n=new Worker(r)).workerURL=r,n);a.onmessage=function(e){t(e.data.buffer,e.data.view),URL.revokeObjectURL(a.workerURL),a.terminate()},a.postMessage(e)}}!0===t.leftChannel&&(s=1),1===t.numberOfAudioChannels&&(s=1),(!s||s<1)&&(s=2),t.disableLogs||console.log("StereoAudioRecorder is set to record number of channels: "+s),void 0===t.checkForInactiveTracks&&(t.checkForInactiveTracks=!0),this.record=function(){if(!1===u())throw"Please make sure MediaStream is active.";b(),w=v=!1,a=!0,void 0!==t.timeSlice&&S()},this.stop=function(e){e=e||function(){},a=!1,l({desiredSampRate:c,sampleRate:p,numberOfAudioChannels:s,internalInterleavedLength:d,leftBuffers:r,rightBuffers:1===s?[]:n,noWorker:t.noWorker},function(t,o){i.blob=new Blob([o],{type:"audio/wav"}),i.buffer=new ArrayBuffer(o.buffer.byteLength),i.view=o,i.sampleRate=c||p,i.bufferSize=g,i.length=d,w=!1,e&&e(i.blob)})},void 0===RecordRTC.Storage&&(RecordRTC.Storage={AudioContextConstructor:null,AudioContext:window.AudioContext||window.webkitAudioContext}),RecordRTC.Storage.AudioContextConstructor&&"closed"!==RecordRTC.Storage.AudioContextConstructor.state||(RecordRTC.Storage.AudioContextConstructor=new RecordRTC.Storage.AudioContext);var f=RecordRTC.Storage.AudioContextConstructor,m=f.createMediaStreamSource(e),h=[0,256,512,1024,2048,4096,8192,16384],g=void 0===t.bufferSize?4096:t.bufferSize;if(-1===h.indexOf(g)&&(t.disableLogs||console.log("Legal values for buffer-size are "+JSON.stringify(h,null,"\t"))),f.createJavaScriptNode)o=f.createJavaScriptNode(g,s,s);else{if(!f.createScriptProcessor)throw"WebAudio API has no support on this browser.";o=f.createScriptProcessor(g,s,s)}m.connect(o),t.bufferSize||(g=o.bufferSize);var p=void 0!==t.sampleRate?t.sampleRate:f.sampleRate||44100;(p<22050||p>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 v=!1;function b(){r=[],n=[],d=0,w=!1,a=!1,v=!1,f=null,i.leftchannel=r,i.rightchannel=n,i.numberOfAudioChannels=s,i.desiredSampRate=c,i.sampleRate=p,i.recordingLength=d,y={left:[],right:[],recordingLength:0}}function R(){o&&(o.onaudioprocess=null,o.disconnect(),o=null),m&&(m.disconnect(),m=null),b()}this.pause=function(){v=!0},this.resume=function(){if(!1===u())throw"Please make sure MediaStream is active.";if(!a)return t.disableLogs||console.log("Seems recording has been restarted."),void this.record();v=!1},this.clearRecordedData=function(){t.checkForInactiveTracks=!1,a&&this.stop(R),R()},this.name="StereoAudioRecorder",this.toString=function(){return this.name};var w=!1;o.onaudioprocess=function(e){if(!v)if(!1===u()&&(t.disableLogs||console.log("MediaStream seems stopped."),o.disconnect(),a=!1),a){w||(w=!0,t.onAudioProcessStarted&&t.onAudioProcessStarted(),t.initCallback&&t.initCallback());var c=e.inputBuffer.getChannelData(0),l=new Float32Array(c);if(r.push(l),2===s){var f=e.inputBuffer.getChannelData(1),h=new Float32Array(f);n.push(h)}d+=g,i.recordingLength=d,void 0!==t.timeSlice&&(y.recordingLength+=g,y.left.push(l),2===s&&y.right.push(h))}else m&&(m.disconnect(),m=null)},f.createMediaStreamDestination?o.connect(f.createMediaStreamDestination()):o.connect(f.destination),this.leftchannel=r,this.rightchannel=n,this.numberOfAudioChannels=s,this.desiredSampRate=c,this.sampleRate=p,i.recordingLength=d;var y={left:[],right:[],recordingLength:0};function S(){a&&"function"==typeof t.ondataavailable&&void 0!==t.timeSlice&&(y.left.length?(l({desiredSampRate:c,sampleRate:p,numberOfAudioChannels:s,internalInterleavedLength:y.recordingLength,leftBuffers:y.left,rightBuffers:1===s?[]:y.right},function(e,o){var i=new Blob([o],{type:"audio/wav"});t.ondataavailable(i),setTimeout(S,t.timeSlice)}),y={left:[],right:[],recordingLength:0}):setTimeout(S,t.timeSlice))}}function CanvasRecorder(e,t){if("undefined"==typeof html2canvas)throw"Please link: https://www.webrtc-experiment.com/screenshot.js";(t=t||{}).frameInterval||(t.frameInterval=10);var o=!1;["captureStream","mozCaptureStream","webkitCaptureStream"].forEach(function(e){e in document.createElement("canvas")&&(o=!0)});var i,r,n,a=!(!window.webkitRTCPeerConnection&&!window.webkitGetUserMedia||!window.chrome),d=50,s=navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);if(a&&s&&s[2]&&(d=parseInt(s[2],10)),a&&d<52&&(o=!1),t.useWhammyRecorder&&(o=!1),o)if(t.disableLogs||console.log("Your browser supports both MediRecorder API and canvas.captureStream!"),e instanceof HTMLCanvasElement)i=e;else{if(!(e instanceof CanvasRenderingContext2D))throw"Please pass either HTMLCanvasElement or CanvasRenderingContext2D.";i=e.canvas}else navigator.mozGetUserMedia&&(t.disableLogs||console.error("Canvas recording is NOT supported in Firefox."));this.record=function(){if(n=!0,o&&!t.useWhammyRecorder){var e;"captureStream"in i?e=i.captureStream(25):"mozCaptureStream"in i?e=i.mozCaptureStream(25):"webkitCaptureStream"in i&&(e=i.webkitCaptureStream(25));try{var a=new MediaStream;a.addTrack(getTracks(e,"video")[0]),e=a}catch(e){}if(!e)throw"captureStream API are NOT available.";(r=new MediaStreamRecorder(e,{mimeType:t.mimeType||"video/webm"})).record()}else m.frames=[],f=(new Date).getTime(),l();t.initCallback&&t.initCallback()},this.getWebPImages=function(o){if("canvas"===e.nodeName.toLowerCase()){var i=m.frames.length;m.frames.forEach(function(e,o){var r=i-o;t.disableLogs||console.log(r+"/"+i+" frames remaining"),t.onEncodingCallback&&t.onEncodingCallback(r,i);var n=e.image.toDataURL("image/webp",1);m.frames[o].image=n}),t.disableLogs||console.log("Generating WebM"),o()}else o()},this.stop=function(e){n=!1;var i=this;o&&r?r.stop(e):this.getWebPImages(function(){m.compile(function(o){t.disableLogs||console.log("Recording finished!"),i.blob=o,i.blob.forEach&&(i.blob=new Blob([],{type:"video/webm"})),e&&e(i.blob),m.frames=[]})})};var c=!1;function u(){m.frames=[],n=!1,c=!1}function l(){if(c)return f=(new Date).getTime(),setTimeout(l,500);if("canvas"===e.nodeName.toLowerCase()){var o=(new Date).getTime()-f;return f=(new Date).getTime(),m.frames.push({image:(i=document.createElement("canvas"),r=i.getContext("2d"),i.width=e.width,i.height=e.height,r.drawImage(e,0,0),i),duration:o}),void(n&&setTimeout(l,t.frameInterval))}var i,r;html2canvas(e,{grabMouse:void 0===t.showMousePointer||t.showMousePointer,onrendered:function(e){var o=(new Date).getTime()-f;if(!o)return setTimeout(l,t.frameInterval);f=(new Date).getTime(),m.frames.push({image:e.toDataURL("image/webp",1),duration:o}),n&&setTimeout(l,t.frameInterval)}})}this.pause=function(){c=!0,r instanceof MediaStreamRecorder&&r.pause()},this.resume=function(){c=!1,r instanceof MediaStreamRecorder?r.resume():n||this.record()},this.clearRecordedData=function(){n&&this.stop(u),u()},this.name="CanvasRecorder",this.toString=function(){return this.name};var f=(new Date).getTime(),m=new Whammy.Video(100)}function WhammyRecorder(e,t){function o(e){e=void 0!==e?e:10;var t=(new Date).getTime()-s;return t?n?(s=(new Date).getTime(),setTimeout(o,100)):(s=(new Date).getTime(),d.paused&&d.play(),l.drawImage(d,0,0,u.width,u.height),c.frames.push({duration:t,image:u.toDataURL("image/webp")}),void(r||setTimeout(o,e,e))):setTimeout(o,e,e)}function i(e,t,o,i,r){var n=document.createElement("canvas");n.width=u.width,n.height=u.height;var a,d,s,c=n.getContext("2d"),l=[],f=-1===t,m=t&&t>0&&t<=e.length?t:e.length,h=0,g=0,p=0,v=Math.sqrt(Math.pow(255,2)+Math.pow(255,2)+Math.pow(255,2)),b=o&&o>=0&&o<=1?o:0,R=i&&i>=0&&i<=1?i:0,w=!1;d=-1,s=(a={length:m,functionToLoop:function(t,o){var i,r,n,a=function(){!w&&n-i<=n*R||(f&&(w=!0),l.push(e[o])),t()};if(w)a();else{var d=new Image;d.onload=function(){c.drawImage(d,0,0,u.width,u.height);var e=c.getImageData(0,0,u.width,u.height);i=0,r=e.data.length,n=e.data.length/4;for(var t=0;t<r;t+=4){var o={r:e.data[t],g:e.data[t+1],b:e.data[t+2]};Math.sqrt(Math.pow(o.r-h,2)+Math.pow(o.g-g,2)+Math.pow(o.b-p,2))<=v*b&&i++}a()},d.src=e[o].image}},callback:function(){(l=l.concat(e.slice(m))).length<=0&&l.push(e[e.length-1]),r(l)}}).length,function e(){++d!==s?setTimeout(function(){a.functionToLoop(e,d)},1):a.callback()}()}(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}),u.width=t.canvas.width||320,u.height=t.canvas.height||240,l=u.getContext("2d"),t.video&&t.video instanceof HTMLVideoElement?(d=t.video.cloneNode(),t.initCallback&&t.initCallback()):(d=document.createElement("video"),setSrcObject(e,d),d.onloadedmetadata=function(){t.initCallback&&t.initCallback()},d.width=t.video.width,d.height=t.video.height),d.muted=!0,d.play(),s=(new Date).getTime(),c=new Whammy.Video,t.disableLogs||(console.log("canvas resolutions",u.width,"*",u.height),console.log("video width/height",d.width||u.width,"*",d.height||u.height)),o(t.frameInterval)};var r=!1;this.stop=function(e){e=e||function(){},r=!0;var o=this;setTimeout(function(){i(c.frames,-1,null,null,function(i){c.frames=i,t.advertisement&&t.advertisement.length&&(c.frames=t.advertisement.concat(c.frames)),c.compile(function(t){o.blob=t,o.blob.forEach&&(o.blob=new Blob([],{type:"video/webm"})),e&&e(o.blob)})})},10)};var n=!1;function a(){c.frames=[],r=!0,n=!1}this.pause=function(){n=!0},this.resume=function(){n=!1,r&&this.record()},this.clearRecordedData=function(){r||this.stop(a),a()},this.name="WhammyRecorder",this.toString=function(){return this.name};var d,s,c,u=document.createElement("canvas"),l=u.getContext("2d")}void 0!==AudioContext?Storage.AudioContext=AudioContext:"undefined"!=typeof webkitAudioContext&&(Storage.AudioContext=webkitAudioContext),void 0!==RecordRTC&&(RecordRTC.Storage=Storage),void 0!==RecordRTC&&(RecordRTC.MediaStreamRecorder=MediaStreamRecorder),void 0!==RecordRTC&&(RecordRTC.StereoAudioRecorder=StereoAudioRecorder),void 0!==RecordRTC&&(RecordRTC.CanvasRecorder=CanvasRecorder),void 0!==RecordRTC&&(RecordRTC.WhammyRecorder=WhammyRecorder);var Whammy=function(){function e(e){this.frames=[],this.duration=e||1,this.quality=.8}function t(e){function t(e,t,o){return[{data:e,id:231}].concat(o.map(function(e){var o=function(e){var t=0;e.keyframe&&(t|=128);e.invisible&&(t|=8);e.lacing&&(t|=e.lacing<<1);e.discardable&&(t|=1);if(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:o,id:163}}))}function o(e){for(var t=[];e>0;)t.push(255&e),e>>=8;return new Uint8Array(t.reverse())}function i(e){var t=[];e=(e.length%8?new Array(9-e.length%8).join("0"):"")+e;for(var o=0;o<e.length;o+=8)t.push(parseInt(e.substr(o,8),2));return new Uint8Array(t)}function r(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)}var n=new function(e){var r=function(e){if(e[0]){for(var t=e[0].width,o=e[0].height,i=e[0].duration,r=1;r<e.length;r++)i+=e[r].duration;return{duration:i,width:t,height:o}}postMessage({error:"Something went wrong. Maybe WebP format is not supported in the current browser."})}(e);if(!r)return[];for(var n,a=[{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=r.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:r.width,id:176},{data:r.height,id:186}]}]}]}]}],d=0,s=0;d<e.length;){var c=[],u=0;do{c.push(e[d]),u+=e[d].duration,d++}while(d<e.length&&u<3e4);var l={id:524531317,data:t(s,0,c)};a[1].data.push(l),s+=u}return function e(t){for(var r=[],n=0;n<t.length;n++){var a=t[n].data;"object"==typeof a&&(a=e(a)),"number"==typeof a&&(a=i(a.toString(2))),"string"==typeof a&&(a=new Uint8Array(a.split("").map(function(e){return e.charCodeAt(0)})));var d=a.size||a.byteLength||a.length,s=Math.ceil(Math.ceil(Math.log(d)/Math.log(2))/8),c=d.toString(2),u=new Array(7*s+7+1-c.length).join("0")+c,l=new Array(s).join("0")+"1"+u;r.push(o(t[n].id)),r.push(i(l)),r.push(a)}return new Blob(r,{type:"video/webm"})}(a)}(e.map(function(e){var t=function(e){for(var t=e.RIFF[0].WEBP[0],o=t.indexOf("*"),i=0,r=[];i<4;i++)r[i]=t.charCodeAt(o+3+i);return{width:16383&(r[1]<<8|r[0]),height:16383&(r[3]<<8|r[2]),data:t,riff:e}}(function e(t){for(var o=0,i={};o<t.length;){var n=t.substr(o,4),a=r(t,o),d=t.substr(o+4+4,a);o+=8+a,i[n]=i[n]||[],"RIFF"===n||"LIST"===n?i[n].push(e(d)):i[n].push(d)}return i}(atob(e.image.slice(23))));return t.duration=e.duration,t}));postMessage(n)}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 o,i,r,n=(o=t,i=URL.createObjectURL(new Blob([o.toString(),"this.onmessage = function (eee) {"+o.name+"(eee.data);}"],{type:"application/javascript"})),r=new Worker(i),URL.revokeObjectURL(i),r);n.onmessage=function(t){t.data.error?console.error(t.data.error):e(t.data)},n.postMessage(this.frames)},{Video:e}}();void 0!==RecordRTC&&(RecordRTC.Whammy=Whammy);var DiskStorage={init:function(){var e=this;if("undefined"!=typeof indexedDB&&void 0!==indexedDB.open){var t,o=this.dbName||location.href.replace(/\/|:|#|%|\.|\[|\]/g,""),i=indexedDB.open(o,1);i.onerror=e.onError,i.onsuccess=function(){((t=i.result).onerror=e.onError,t.setVersion)?1!==t.version?t.setVersion(1).onsuccess=function(){r(t),n()}:n():n()},i.onupgradeneeded=function(e){r(e.target.result)}}else console.error("IndexedDB API are not available in this browser.");function r(t){t.createObjectStore(e.dataStoreName)}function n(){var o=t.transaction([e.dataStoreName],"readwrite");function i(t){o.objectStore(e.dataStoreName).get(t).onsuccess=function(o){e.callback&&e.callback(o.target.result,t)}}e.videoBlob&&o.objectStore(e.dataStoreName).put(e.videoBlob,"videoBlob"),e.gifBlob&&o.objectStore(e.dataStoreName).put(e.gifBlob,"gifBlob"),e.audioBlob&&o.objectStore(e.dataStoreName).put(e.audioBlob,"audioBlob"),i("audioBlob"),i("videoBlob"),i("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 GifRecorder(e,t){if("undefined"==typeof GIFEncoder){var o=document.createElement("script");o.src="https://www.webrtc-experiment.com/gif-recorder.js",(document.body||document.documentElement).appendChild(o)}t=t||{};var i=e instanceof CanvasRenderingContext2D||e instanceof HTMLCanvasElement;this.record=function(){"undefined"!=typeof GIFEncoder&&d?(i||(t.width||(t.width=s.offsetWidth||320),t.height||(t.height=s.offsetHeight||240),t.video||(t.video={width:t.width,height:t.height}),t.canvas||(t.canvas={width:t.width,height:t.height}),n.width=t.canvas.width||320,n.height=t.canvas.height||240,s.width=t.video.width||320,s.height=t.video.height||240),(u=new GIFEncoder).setRepeat(0),u.setDelay(t.frameRate||200),u.setQuality(t.quality||10),u.start(),"function"==typeof t.onGifRecordingStarted&&t.onGifRecordingStarted(),Date.now(),l=requestAnimationFrame(function e(o){if(!0!==f.clearedRecordedData){if(r)return setTimeout(function(){e(o)},100);l=requestAnimationFrame(e),void 0===typeof c&&(c=o),o-c<90||(!i&&s.paused&&s.play(),i||a.drawImage(s,0,0,n.width,n.height),t.onGifPreview&&t.onGifPreview(n.toDataURL("image/png")),u.addFrame(a),c=o)}}),t.initCallback&&t.initCallback()):setTimeout(f.record,1e3)},this.stop=function(e){e=e||function(){},l&&cancelAnimationFrame(l),Date.now(),this.blob=new Blob([new Uint8Array(u.stream().bin)],{type:"image/gif"}),e(this.blob),u.stream().bin=[]};var r=!1;this.pause=function(){r=!0},this.resume=function(){r=!1},this.clearRecordedData=function(){f.clearedRecordedData=!0,u&&(u.stream().bin=[])},this.name="GifRecorder",this.toString=function(){return this.name};var n=document.createElement("canvas"),a=n.getContext("2d");i&&(e instanceof CanvasRenderingContext2D?n=(a=e).canvas:e instanceof HTMLCanvasElement&&(a=e.getContext("2d"),n=e));var d=!0;if(!i){var s=document.createElement("video");s.muted=!0,s.autoplay=!0,s.playsInline=!0,d=!1,s.onloadedmetadata=function(){d=!0},setSrcObject(e,s),s.play()}var c,u,l=null,f=this}function MultiStreamsMixer(e,t){var o;o="undefined"!=typeof global?global:null,void 0===RecordRTC&&o&&"undefined"==typeof window&&"undefined"!=typeof global&&(global.navigator={userAgent:"Fake/5.0 (FakeOS) AppleWebKit/123 (KHTML, like Gecko) Fake/12.3.4567.89 Fake/123.45",getUserMedia:function(){}},global.console||(global.console={}),void 0!==global.console.log&&void 0!==global.console.error||(global.console.error=global.console.log=global.console.log||function(){console.log(arguments)}),"undefined"==typeof document&&(o.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},o.HTMLVideoElement=function(){}),"undefined"==typeof location&&(o.location={protocol:"file:",href:"",hash:""}),"undefined"==typeof screen&&(o.screen={width:0,height:0}),void 0===c&&(o.URL={createObjectURL:function(){return""},revokeObjectURL:function(){return""}}),o.window=global),t=t||"multi-streams-mixer";var i=[],r=!1,n=document.createElement("canvas"),a=n.getContext("2d");n.style.opacity=0,n.style.position="absolute",n.style.zIndex=-1,n.style.top="-1000em",n.style.left="-1000em",n.className=t,(document.body||document.documentElement).appendChild(n),this.disableLogs=!1,this.frameInterval=10,this.width=360,this.height=240,this.useGainNode=!0;var d=this,s=window.AudioContext;void 0===s&&("undefined"!=typeof webkitAudioContext&&(s=webkitAudioContext),"undefined"!=typeof mozAudioContext&&(s=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 u=window.MediaStream;void 0===u&&"undefined"!=typeof webkitMediaStream&&(u=webkitMediaStream),void 0!==u&&void 0===u.prototype.stop&&(u.prototype.stop=function(){this.getTracks().forEach(function(e){e.stop()})});var l={};function f(){if(!r){var e=i.length,t=!1,o=[];if(i.forEach(function(e){e.stream||(e.stream={}),e.stream.fullcanvas?t=e:o.push(e)}),t)n.width=t.stream.width,n.height=t.stream.height;else if(o.length){n.width=e>1?2*o[0].width:o[0].width;var a=1;3!==e&&4!==e||(a=2),5!==e&&6!==e||(a=3),7!==e&&8!==e||(a=4),9!==e&&10!==e||(a=5),n.height=o[0].height*a}else n.width=d.width||360,n.height=d.height||240;t&&t instanceof HTMLVideoElement&&m(t),o.forEach(function(e,t){m(e,t)}),setTimeout(f,d.frameInterval)}}function m(e,t){if(!r){var o=0,i=0,n=e.width,d=e.height;1===t&&(o=e.width),2===t&&(i=e.height),3===t&&(o=e.width,i=e.height),4===t&&(i=2*e.height),5===t&&(o=e.width,i=2*e.height),6===t&&(i=3*e.height),7===t&&(o=e.width,i=3*e.height),void 0!==e.stream.left&&(o=e.stream.left),void 0!==e.stream.top&&(i=e.stream.top),void 0!==e.stream.width&&(n=e.stream.width),void 0!==e.stream.height&&(d=e.stream.height),a.drawImage(e,o,i,n,d),"function"==typeof e.stream.onRender&&e.stream.onRender(a,o,i,n,d,t)}}function h(e){var o=document.createElement("video");return function(e,t){"srcObject"in t?t.srcObject=e:"mozSrcObject"in t?t.mozSrcObject=e:t.srcObject=e}(e,o),o.className=t,o.muted=!0,o.volume=0,o.width=e.width||d.width||360,o.height=e.height||d.height||240,o.play(),o}function g(t){i=[],(t=t||e).forEach(function(e){if(e.getTracks().filter(function(e){return"video"===e.kind}).length){var t=h(e);t.stream=e,i.push(t)}})}void 0!==s?l.AudioContext=s:"undefined"!=typeof webkitAudioContext&&(l.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 o=new u;if(t.getTracks().filter(function(e){return"video"===e.kind}).length){var r=h(t);r.stream=t,i.push(r),o.addTrack(t.getTracks().filter(function(e){return"video"===e.kind})[0])}if(t.getTracks().filter(function(e){return"audio"===e.kind}).length){var n=d.audioContext.createMediaStreamSource(t);d.audioDestination=d.audioContext.createMediaStreamDestination(),n.connect(d.audioDestination),o.addTrack(d.audioDestination.stream.getTracks().filter(function(e){return"audio"===e.kind})[0])}e.push(o)})},this.releaseStreams=function(){i=[],r=!0,d.gainNode&&(d.gainNode.disconnect(),d.gainNode=null),d.audioSources.length&&(d.audioSources.forEach(function(e){e.disconnect()}),d.audioSources=[]),d.audioDestination&&(d.audioDestination.disconnect(),d.audioDestination=null),d.audioContext&&d.audioContext.close(),d.audioContext=null,a.clearRect(0,0,n.width,n.height),n.stream&&(n.stream.stop(),n.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(){r=!1;var t=function(){var e;g(),"captureStream"in n?e=n.captureStream():"mozCaptureStream"in n?e=n.mozCaptureStream():d.disableLogs||console.error("Upgrade to latest Chrome or otherwise enable this flag: chrome://flags/#enable-experimental-web-platform-features");var t=new u;return e.getTracks().filter(function(e){return"video"===e.kind}).forEach(function(e){t.addTrack(e)}),n.stream=t,t}(),o=function(){l.AudioContextConstructor||(l.AudioContextConstructor=new l.AudioContext),d.audioContext=l.AudioContextConstructor,d.audioSources=[],!0===d.useGainNode&&(d.gainNode=d.audioContext.createGain(),d.gainNode.connect(d.audioContext.destination),d.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 o=d.audioContext.createMediaStreamSource(e);!0===d.useGainNode&&o.connect(d.gainNode),d.audioSources.push(o)}}),t)return d.audioDestination=d.audioContext.createMediaStreamDestination(),d.audioSources.forEach(function(e){e.connect(d.audioDestination)}),d.audioDestination.stream}();return o&&o.getTracks().filter(function(e){return"audio"===e.kind}).forEach(function(e){t.addTrack(e)}),e.forEach(function(e){e.fullcanvas}),t}}function MultiStreamRecorder(e,t){e=e||[];var o,i,r=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 r;o=new MultiStreamsMixer(e,t.elementClass||"multi-streams-mixer"),(r=[],e.forEach(function(e){getTracks(e,"video")