New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

wavesurfer.js

Package Overview
Dependencies
Maintainers
1
Versions
302
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wavesurfer.js - npm Package Compare versions

Comparing version 7.8.3 to 7.8.4-beta.0

2

dist/plugins/record.esm.js

@@ -1,1 +0,1 @@

function i(i,t,e,s){return new(e||(e=Promise))((function(o,r){function n(i){try{d(s.next(i))}catch(i){r(i)}}function a(i){try{d(s.throw(i))}catch(i){r(i)}}function d(i){var t;i.done?o(i.value):(t=i.value,t instanceof e?t:new e((function(i){i(t)}))).then(n,a)}d((s=s.apply(i,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class t{constructor(){this.listeners={}}on(i,t,e){if(this.listeners[i]||(this.listeners[i]=new Set),this.listeners[i].add(t),null==e?void 0:e.once){const e=()=>{this.un(i,e),this.un(i,t)};return this.on(i,e),e}return()=>this.un(i,t)}un(i,t){var e;null===(e=this.listeners[i])||void 0===e||e.delete(t)}once(i,t){return this.on(i,t,{once:!0})}unAll(){this.listeners={}}emit(i,...t){this.listeners[i]&&this.listeners[i].forEach((i=>i(...t)))}}class e extends t{constructor(i){super(),this.subscriptions=[],this.options=i}onInit(){}_init(i){this.wavesurfer=i,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((i=>i()))}}class s extends t{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",(()=>{requestAnimationFrame((()=>{this.emit("tick")}))})),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}const o=["audio/webm","audio/wav","audio/mpeg","audio/mp4","audio/mp3"];class r extends e{constructor(i){var t,e,o,r,n,a;super(Object.assign(Object.assign({},i),{audioBitsPerSecond:null!==(t=i.audioBitsPerSecond)&&void 0!==t?t:128e3,scrollingWaveform:null!==(e=i.scrollingWaveform)&&void 0!==e&&e,scrollingWaveformWindow:null!==(o=i.scrollingWaveformWindow)&&void 0!==o?o:5,continuousWaveform:null!==(r=i.continuousWaveform)&&void 0!==r&&r,renderRecordedAudio:null===(n=i.renderRecordedAudio)||void 0===n||n,mediaRecorderTimeslice:null!==(a=i.mediaRecorderTimeslice)&&void 0!==a?a:void 0})),this.stream=null,this.mediaRecorder=null,this.dataWindow=null,this.isWaveformPaused=!1,this.lastStartTime=0,this.lastDuration=0,this.duration=0,this.timer=new s,this.subscriptions.push(this.timer.on("tick",(()=>{const i=performance.now()-this.lastStartTime;this.duration=this.isPaused()?this.duration:this.lastDuration+i,this.emit("record-progress",this.duration)})))}static create(i){return new r(i||{})}renderMicStream(i){var t;const e=new AudioContext,s=e.createMediaStreamSource(i),o=e.createAnalyser();s.connect(o);const r=o.frequencyBinCount,n=new Float32Array(r);let a,d=0;this.wavesurfer&&(null!==(t=this.originalOptions)&&void 0!==t||(this.originalOptions=Object.assign({},this.wavesurfer.options)),this.wavesurfer.options.interact=!1,this.options.scrollingWaveform&&(this.wavesurfer.options.cursorWidth=0));const h=()=>{var i,t,s,u;if(this.isWaveformPaused)a=requestAnimationFrame(h);else{if(o.getFloatTimeDomainData(n),this.options.scrollingWaveform){const i=Math.floor((this.options.scrollingWaveformWindow||0)*e.sampleRate),t=Math.min(i,this.dataWindow?this.dataWindow.length+r:r),s=new Float32Array(i);if(this.dataWindow){const e=Math.max(0,i-this.dataWindow.length);s.set(this.dataWindow.slice(-t+r),e)}s.set(n,i-r),this.dataWindow=s}else if(this.options.continuousWaveform){if(!this.dataWindow){const e=this.options.continuousWaveformDuration?Math.round(60*this.options.continuousWaveformDuration):(null!==(t=null===(i=this.wavesurfer)||void 0===i?void 0:i.getWidth())&&void 0!==t?t:0)*window.devicePixelRatio;this.dataWindow=new Float32Array(e)}const e=Math.max(...n);if(d+1>this.dataWindow.length){const i=new Float32Array(2*this.dataWindow.length);i.set(this.dataWindow,0),this.dataWindow=i}this.dataWindow.set([e],d),d++}else this.dataWindow=n;if(this.wavesurfer){const i=(null!==(u=null===(s=this.dataWindow)||void 0===s?void 0:s.length)&&void 0!==u?u:0)/60;let t=d/this.dataWindow.length;this.wavesurfer.options.barWidth&&(t+=this.wavesurfer.options.barWidth/this.wavesurfer.getWidth()),this.wavesurfer.load("",[this.dataWindow],this.options.scrollingWaveform?this.options.scrollingWaveformWindow:i).then((()=>{this.wavesurfer&&this.options.continuousWaveform&&(this.wavesurfer.seekTo(t),this.wavesurfer.options.minPxPerSec||this.wavesurfer.setOptions({minPxPerSec:this.wavesurfer.getWidth()/this.wavesurfer.getDuration()}))})).catch((i=>{console.error("Error rendering real-time recording data:",i)}))}a=requestAnimationFrame(h)}};return h(),{onDestroy:()=>{cancelAnimationFrame(a),null==s||s.disconnect(),null==e||e.close()},onEnd:()=>{this.isWaveformPaused=!0,cancelAnimationFrame(a),this.stopMic()}}}startMic(t){return i(this,void 0,void 0,(function*(){let i;try{i=yield navigator.mediaDevices.getUserMedia({audio:!(null==t?void 0:t.deviceId)||{deviceId:t.deviceId}})}catch(i){throw new Error("Error accessing the microphone: "+i.message)}const{onDestroy:e,onEnd:s}=this.renderMicStream(i);return this.subscriptions.push(this.once("destroy",e)),this.subscriptions.push(this.once("record-end",s)),this.stream=i,i}))}stopMic(){this.stream&&(this.stream.getTracks().forEach((i=>i.stop())),this.stream=null,this.mediaRecorder=null)}startRecording(t){return i(this,void 0,void 0,(function*(){const i=this.stream||(yield this.startMic(t));this.dataWindow=null;const e=this.mediaRecorder||new MediaRecorder(i,{mimeType:this.options.mimeType||o.find((i=>MediaRecorder.isTypeSupported(i))),audioBitsPerSecond:this.options.audioBitsPerSecond});this.mediaRecorder=e,this.stopRecording();const s=[];e.ondataavailable=i=>{i.data.size>0&&s.push(i.data),this.emit("record-data-available",i.data)};const r=i=>{var t;const o=new Blob(s,{type:e.mimeType});this.emit(i,o),this.options.renderRecordedAudio&&(this.applyOriginalOptionsIfNeeded(),null===(t=this.wavesurfer)||void 0===t||t.load(URL.createObjectURL(o)))};e.onpause=()=>r("record-pause"),e.onstop=()=>r("record-end"),e.start(this.options.mediaRecorderTimeslice),this.lastStartTime=performance.now(),this.lastDuration=0,this.duration=0,this.isWaveformPaused=!1,this.timer.start(),this.emit("record-start")}))}getDuration(){return this.duration}isRecording(){var i;return"recording"===(null===(i=this.mediaRecorder)||void 0===i?void 0:i.state)}isPaused(){var i;return"paused"===(null===(i=this.mediaRecorder)||void 0===i?void 0:i.state)}isActive(){var i;return"inactive"!==(null===(i=this.mediaRecorder)||void 0===i?void 0:i.state)}stopRecording(){var i;this.isActive()&&(null===(i=this.mediaRecorder)||void 0===i||i.stop(),this.timer.stop())}pauseRecording(){var i,t;this.isRecording()&&(this.isWaveformPaused=!0,null===(i=this.mediaRecorder)||void 0===i||i.requestData(),null===(t=this.mediaRecorder)||void 0===t||t.pause(),this.timer.stop(),this.lastDuration=this.duration)}resumeRecording(){var i;this.isPaused()&&(this.isWaveformPaused=!1,null===(i=this.mediaRecorder)||void 0===i||i.resume(),this.timer.start(),this.lastStartTime=performance.now(),this.emit("record-resume"))}static getAvailableAudioDevices(){return i(this,void 0,void 0,(function*(){return navigator.mediaDevices.enumerateDevices().then((i=>i.filter((i=>"audioinput"===i.kind))))}))}destroy(){this.applyOriginalOptionsIfNeeded(),super.destroy(),this.stopRecording(),this.stopMic()}applyOriginalOptionsIfNeeded(){this.wavesurfer&&this.originalOptions&&(this.wavesurfer.setOptions(this.originalOptions),delete this.originalOptions)}}export{r as default};
function i(i,t,e,s){return new(e||(e=Promise))((function(o,r){function n(i){try{d(s.next(i))}catch(i){r(i)}}function a(i){try{d(s.throw(i))}catch(i){r(i)}}function d(i){var t;i.done?o(i.value):(t=i.value,t instanceof e?t:new e((function(i){i(t)}))).then(n,a)}d((s=s.apply(i,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class t{constructor(){this.listeners={}}on(i,t,e){if(this.listeners[i]||(this.listeners[i]=new Set),this.listeners[i].add(t),null==e?void 0:e.once){const e=()=>{this.un(i,e),this.un(i,t)};return this.on(i,e),e}return()=>this.un(i,t)}un(i,t){var e;null===(e=this.listeners[i])||void 0===e||e.delete(t)}once(i,t){return this.on(i,t,{once:!0})}unAll(){this.listeners={}}emit(i,...t){this.listeners[i]&&this.listeners[i].forEach((i=>i(...t)))}}class e extends t{constructor(i){super(),this.subscriptions=[],this.options=i}onInit(){}_init(i){this.wavesurfer=i,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((i=>i()))}}class s extends t{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",(()=>{requestAnimationFrame((()=>{this.emit("tick")}))})),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}const o=["audio/webm","audio/wav","audio/mpeg","audio/mp4","audio/mp3"];class r extends e{constructor(i){var t,e,o,r,n,a;super(Object.assign(Object.assign({},i),{audioBitsPerSecond:null!==(t=i.audioBitsPerSecond)&&void 0!==t?t:128e3,scrollingWaveform:null!==(e=i.scrollingWaveform)&&void 0!==e&&e,scrollingWaveformWindow:null!==(o=i.scrollingWaveformWindow)&&void 0!==o?o:5,continuousWaveform:null!==(r=i.continuousWaveform)&&void 0!==r&&r,renderRecordedAudio:null===(n=i.renderRecordedAudio)||void 0===n||n,mediaRecorderTimeslice:null!==(a=i.mediaRecorderTimeslice)&&void 0!==a?a:void 0})),this.stream=null,this.mediaRecorder=null,this.dataWindow=null,this.isWaveformPaused=!1,this.lastStartTime=0,this.lastDuration=0,this.duration=0,this.timer=new s,this.subscriptions.push(this.timer.on("tick",(()=>{const i=performance.now()-this.lastStartTime;this.duration=this.isPaused()?this.duration:this.lastDuration+i,this.emit("record-progress",this.duration)})))}static create(i){return new r(i||{})}renderMicStream(i){var t;const e=new AudioContext,s=e.createMediaStreamSource(i),o=e.createAnalyser();s.connect(o);const r=o.frequencyBinCount,n=new Float32Array(r);let a,d=0;this.wavesurfer&&(null!==(t=this.originalOptions)&&void 0!==t||(this.originalOptions=Object.assign({},this.wavesurfer.options)),this.wavesurfer.options.interact=!1,this.options.scrollingWaveform&&(this.wavesurfer.options.cursorWidth=0));const c=()=>{var i,t,s,u;if(this.isWaveformPaused)a=requestAnimationFrame(c);else{if(o.getFloatTimeDomainData(n),this.options.scrollingWaveform){const i=Math.floor((this.options.scrollingWaveformWindow||0)*e.sampleRate),t=Math.min(i,this.dataWindow?this.dataWindow.length+r:r),s=new Float32Array(i);if(this.dataWindow){const e=Math.max(0,i-this.dataWindow.length);s.set(this.dataWindow.slice(-t+r),e)}s.set(n,i-r),this.dataWindow=s}else if(this.options.continuousWaveform){if(!this.dataWindow){const e=this.options.continuousWaveformDuration?Math.round(60*this.options.continuousWaveformDuration):(null!==(t=null===(i=this.wavesurfer)||void 0===i?void 0:i.getWidth())&&void 0!==t?t:0)*window.devicePixelRatio;this.dataWindow=new Float32Array(e)}const e=Math.max(...n);if(d+1>this.dataWindow.length){const i=new Float32Array(2*this.dataWindow.length);i.set(this.dataWindow,0),this.dataWindow=i}this.dataWindow.set([e],d),d++}else this.dataWindow=n;if(this.wavesurfer){const i=(null!==(u=null===(s=this.dataWindow)||void 0===s?void 0:s.length)&&void 0!==u?u:0)/60;this.wavesurfer.load("",[this.dataWindow],this.options.scrollingWaveform?this.options.scrollingWaveformWindow:i).then((()=>{this.wavesurfer&&this.options.continuousWaveform&&(this.wavesurfer.setTime(this.getDuration()/1e3),this.wavesurfer.options.minPxPerSec||this.wavesurfer.setOptions({minPxPerSec:this.wavesurfer.getWidth()/this.wavesurfer.getDuration()}))})).catch((i=>{console.error("Error rendering real-time recording data:",i)}))}a=requestAnimationFrame(c)}};return c(),{onDestroy:()=>{cancelAnimationFrame(a),null==s||s.disconnect(),null==e||e.close()},onEnd:()=>{this.isWaveformPaused=!0,cancelAnimationFrame(a),this.stopMic()}}}startMic(t){return i(this,void 0,void 0,(function*(){let i;try{i=yield navigator.mediaDevices.getUserMedia({audio:!(null==t?void 0:t.deviceId)||{deviceId:t.deviceId}})}catch(i){throw new Error("Error accessing the microphone: "+i.message)}const{onDestroy:e,onEnd:s}=this.renderMicStream(i);return this.subscriptions.push(this.once("destroy",e)),this.subscriptions.push(this.once("record-end",s)),this.stream=i,i}))}stopMic(){this.stream&&(this.stream.getTracks().forEach((i=>i.stop())),this.stream=null,this.mediaRecorder=null)}startRecording(t){return i(this,void 0,void 0,(function*(){const i=this.stream||(yield this.startMic(t));this.dataWindow=null;const e=this.mediaRecorder||new MediaRecorder(i,{mimeType:this.options.mimeType||o.find((i=>MediaRecorder.isTypeSupported(i))),audioBitsPerSecond:this.options.audioBitsPerSecond});this.mediaRecorder=e,this.stopRecording();const s=[];e.ondataavailable=i=>{i.data.size>0&&s.push(i.data),this.emit("record-data-available",i.data)};const r=i=>{var t;const o=new Blob(s,{type:e.mimeType});this.emit(i,o),this.options.renderRecordedAudio&&(this.applyOriginalOptionsIfNeeded(),null===(t=this.wavesurfer)||void 0===t||t.load(URL.createObjectURL(o)))};e.onpause=()=>r("record-pause"),e.onstop=()=>r("record-end"),e.start(this.options.mediaRecorderTimeslice),this.lastStartTime=performance.now(),this.lastDuration=0,this.duration=0,this.isWaveformPaused=!1,this.timer.start(),this.emit("record-start")}))}getDuration(){return this.duration}isRecording(){var i;return"recording"===(null===(i=this.mediaRecorder)||void 0===i?void 0:i.state)}isPaused(){var i;return"paused"===(null===(i=this.mediaRecorder)||void 0===i?void 0:i.state)}isActive(){var i;return"inactive"!==(null===(i=this.mediaRecorder)||void 0===i?void 0:i.state)}stopRecording(){var i;this.isActive()&&(null===(i=this.mediaRecorder)||void 0===i||i.stop(),this.timer.stop())}pauseRecording(){var i,t;this.isRecording()&&(this.isWaveformPaused=!0,null===(i=this.mediaRecorder)||void 0===i||i.requestData(),null===(t=this.mediaRecorder)||void 0===t||t.pause(),this.timer.stop(),this.lastDuration=this.duration)}resumeRecording(){var i;this.isPaused()&&(this.isWaveformPaused=!1,null===(i=this.mediaRecorder)||void 0===i||i.resume(),this.timer.start(),this.lastStartTime=performance.now(),this.emit("record-resume"))}static getAvailableAudioDevices(){return i(this,void 0,void 0,(function*(){return navigator.mediaDevices.enumerateDevices().then((i=>i.filter((i=>"audioinput"===i.kind))))}))}destroy(){this.applyOriginalOptionsIfNeeded(),super.destroy(),this.stopRecording(),this.stopMic()}applyOriginalOptionsIfNeeded(){this.wavesurfer&&this.originalOptions&&(this.wavesurfer.setOptions(this.originalOptions),delete this.originalOptions)}}export{r as default};

@@ -1,1 +0,1 @@

function i(i,t,e,s){return new(e||(e=Promise))((function(o,r){function n(i){try{d(s.next(i))}catch(i){r(i)}}function a(i){try{d(s.throw(i))}catch(i){r(i)}}function d(i){var t;i.done?o(i.value):(t=i.value,t instanceof e?t:new e((function(i){i(t)}))).then(n,a)}d((s=s.apply(i,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class t{constructor(){this.listeners={}}on(i,t,e){if(this.listeners[i]||(this.listeners[i]=new Set),this.listeners[i].add(t),null==e?void 0:e.once){const e=()=>{this.un(i,e),this.un(i,t)};return this.on(i,e),e}return()=>this.un(i,t)}un(i,t){var e;null===(e=this.listeners[i])||void 0===e||e.delete(t)}once(i,t){return this.on(i,t,{once:!0})}unAll(){this.listeners={}}emit(i,...t){this.listeners[i]&&this.listeners[i].forEach((i=>i(...t)))}}class e extends t{constructor(i){super(),this.subscriptions=[],this.options=i}onInit(){}_init(i){this.wavesurfer=i,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((i=>i()))}}class s extends t{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",(()=>{requestAnimationFrame((()=>{this.emit("tick")}))})),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}const o=["audio/webm","audio/wav","audio/mpeg","audio/mp4","audio/mp3"];class r extends e{constructor(i){var t,e,o,r,n,a;super(Object.assign(Object.assign({},i),{audioBitsPerSecond:null!==(t=i.audioBitsPerSecond)&&void 0!==t?t:128e3,scrollingWaveform:null!==(e=i.scrollingWaveform)&&void 0!==e&&e,scrollingWaveformWindow:null!==(o=i.scrollingWaveformWindow)&&void 0!==o?o:5,continuousWaveform:null!==(r=i.continuousWaveform)&&void 0!==r&&r,renderRecordedAudio:null===(n=i.renderRecordedAudio)||void 0===n||n,mediaRecorderTimeslice:null!==(a=i.mediaRecorderTimeslice)&&void 0!==a?a:void 0})),this.stream=null,this.mediaRecorder=null,this.dataWindow=null,this.isWaveformPaused=!1,this.lastStartTime=0,this.lastDuration=0,this.duration=0,this.timer=new s,this.subscriptions.push(this.timer.on("tick",(()=>{const i=performance.now()-this.lastStartTime;this.duration=this.isPaused()?this.duration:this.lastDuration+i,this.emit("record-progress",this.duration)})))}static create(i){return new r(i||{})}renderMicStream(i){var t;const e=new AudioContext,s=e.createMediaStreamSource(i),o=e.createAnalyser();s.connect(o);const r=o.frequencyBinCount,n=new Float32Array(r);let a,d=0;this.wavesurfer&&(null!==(t=this.originalOptions)&&void 0!==t||(this.originalOptions=Object.assign({},this.wavesurfer.options)),this.wavesurfer.options.interact=!1,this.options.scrollingWaveform&&(this.wavesurfer.options.cursorWidth=0));const h=()=>{var i,t,s,u;if(this.isWaveformPaused)a=requestAnimationFrame(h);else{if(o.getFloatTimeDomainData(n),this.options.scrollingWaveform){const i=Math.floor((this.options.scrollingWaveformWindow||0)*e.sampleRate),t=Math.min(i,this.dataWindow?this.dataWindow.length+r:r),s=new Float32Array(i);if(this.dataWindow){const e=Math.max(0,i-this.dataWindow.length);s.set(this.dataWindow.slice(-t+r),e)}s.set(n,i-r),this.dataWindow=s}else if(this.options.continuousWaveform){if(!this.dataWindow){const e=this.options.continuousWaveformDuration?Math.round(60*this.options.continuousWaveformDuration):(null!==(t=null===(i=this.wavesurfer)||void 0===i?void 0:i.getWidth())&&void 0!==t?t:0)*window.devicePixelRatio;this.dataWindow=new Float32Array(e)}const e=Math.max(...n);if(d+1>this.dataWindow.length){const i=new Float32Array(2*this.dataWindow.length);i.set(this.dataWindow,0),this.dataWindow=i}this.dataWindow.set([e],d),d++}else this.dataWindow=n;if(this.wavesurfer){const i=(null!==(u=null===(s=this.dataWindow)||void 0===s?void 0:s.length)&&void 0!==u?u:0)/60;let t=d/this.dataWindow.length;this.wavesurfer.options.barWidth&&(t+=this.wavesurfer.options.barWidth/this.wavesurfer.getWidth()),this.wavesurfer.load("",[this.dataWindow],this.options.scrollingWaveform?this.options.scrollingWaveformWindow:i).then((()=>{this.wavesurfer&&this.options.continuousWaveform&&(this.wavesurfer.seekTo(t),this.wavesurfer.options.minPxPerSec||this.wavesurfer.setOptions({minPxPerSec:this.wavesurfer.getWidth()/this.wavesurfer.getDuration()}))})).catch((i=>{console.error("Error rendering real-time recording data:",i)}))}a=requestAnimationFrame(h)}};return h(),{onDestroy:()=>{cancelAnimationFrame(a),null==s||s.disconnect(),null==e||e.close()},onEnd:()=>{this.isWaveformPaused=!0,cancelAnimationFrame(a),this.stopMic()}}}startMic(t){return i(this,void 0,void 0,(function*(){let i;try{i=yield navigator.mediaDevices.getUserMedia({audio:!(null==t?void 0:t.deviceId)||{deviceId:t.deviceId}})}catch(i){throw new Error("Error accessing the microphone: "+i.message)}const{onDestroy:e,onEnd:s}=this.renderMicStream(i);return this.subscriptions.push(this.once("destroy",e)),this.subscriptions.push(this.once("record-end",s)),this.stream=i,i}))}stopMic(){this.stream&&(this.stream.getTracks().forEach((i=>i.stop())),this.stream=null,this.mediaRecorder=null)}startRecording(t){return i(this,void 0,void 0,(function*(){const i=this.stream||(yield this.startMic(t));this.dataWindow=null;const e=this.mediaRecorder||new MediaRecorder(i,{mimeType:this.options.mimeType||o.find((i=>MediaRecorder.isTypeSupported(i))),audioBitsPerSecond:this.options.audioBitsPerSecond});this.mediaRecorder=e,this.stopRecording();const s=[];e.ondataavailable=i=>{i.data.size>0&&s.push(i.data),this.emit("record-data-available",i.data)};const r=i=>{var t;const o=new Blob(s,{type:e.mimeType});this.emit(i,o),this.options.renderRecordedAudio&&(this.applyOriginalOptionsIfNeeded(),null===(t=this.wavesurfer)||void 0===t||t.load(URL.createObjectURL(o)))};e.onpause=()=>r("record-pause"),e.onstop=()=>r("record-end"),e.start(this.options.mediaRecorderTimeslice),this.lastStartTime=performance.now(),this.lastDuration=0,this.duration=0,this.isWaveformPaused=!1,this.timer.start(),this.emit("record-start")}))}getDuration(){return this.duration}isRecording(){var i;return"recording"===(null===(i=this.mediaRecorder)||void 0===i?void 0:i.state)}isPaused(){var i;return"paused"===(null===(i=this.mediaRecorder)||void 0===i?void 0:i.state)}isActive(){var i;return"inactive"!==(null===(i=this.mediaRecorder)||void 0===i?void 0:i.state)}stopRecording(){var i;this.isActive()&&(null===(i=this.mediaRecorder)||void 0===i||i.stop(),this.timer.stop())}pauseRecording(){var i,t;this.isRecording()&&(this.isWaveformPaused=!0,null===(i=this.mediaRecorder)||void 0===i||i.requestData(),null===(t=this.mediaRecorder)||void 0===t||t.pause(),this.timer.stop(),this.lastDuration=this.duration)}resumeRecording(){var i;this.isPaused()&&(this.isWaveformPaused=!1,null===(i=this.mediaRecorder)||void 0===i||i.resume(),this.timer.start(),this.lastStartTime=performance.now(),this.emit("record-resume"))}static getAvailableAudioDevices(){return i(this,void 0,void 0,(function*(){return navigator.mediaDevices.enumerateDevices().then((i=>i.filter((i=>"audioinput"===i.kind))))}))}destroy(){this.applyOriginalOptionsIfNeeded(),super.destroy(),this.stopRecording(),this.stopMic()}applyOriginalOptionsIfNeeded(){this.wavesurfer&&this.originalOptions&&(this.wavesurfer.setOptions(this.originalOptions),delete this.originalOptions)}}export{r as default};
function i(i,t,e,s){return new(e||(e=Promise))((function(o,r){function n(i){try{d(s.next(i))}catch(i){r(i)}}function a(i){try{d(s.throw(i))}catch(i){r(i)}}function d(i){var t;i.done?o(i.value):(t=i.value,t instanceof e?t:new e((function(i){i(t)}))).then(n,a)}d((s=s.apply(i,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class t{constructor(){this.listeners={}}on(i,t,e){if(this.listeners[i]||(this.listeners[i]=new Set),this.listeners[i].add(t),null==e?void 0:e.once){const e=()=>{this.un(i,e),this.un(i,t)};return this.on(i,e),e}return()=>this.un(i,t)}un(i,t){var e;null===(e=this.listeners[i])||void 0===e||e.delete(t)}once(i,t){return this.on(i,t,{once:!0})}unAll(){this.listeners={}}emit(i,...t){this.listeners[i]&&this.listeners[i].forEach((i=>i(...t)))}}class e extends t{constructor(i){super(),this.subscriptions=[],this.options=i}onInit(){}_init(i){this.wavesurfer=i,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((i=>i()))}}class s extends t{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",(()=>{requestAnimationFrame((()=>{this.emit("tick")}))})),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}const o=["audio/webm","audio/wav","audio/mpeg","audio/mp4","audio/mp3"];class r extends e{constructor(i){var t,e,o,r,n,a;super(Object.assign(Object.assign({},i),{audioBitsPerSecond:null!==(t=i.audioBitsPerSecond)&&void 0!==t?t:128e3,scrollingWaveform:null!==(e=i.scrollingWaveform)&&void 0!==e&&e,scrollingWaveformWindow:null!==(o=i.scrollingWaveformWindow)&&void 0!==o?o:5,continuousWaveform:null!==(r=i.continuousWaveform)&&void 0!==r&&r,renderRecordedAudio:null===(n=i.renderRecordedAudio)||void 0===n||n,mediaRecorderTimeslice:null!==(a=i.mediaRecorderTimeslice)&&void 0!==a?a:void 0})),this.stream=null,this.mediaRecorder=null,this.dataWindow=null,this.isWaveformPaused=!1,this.lastStartTime=0,this.lastDuration=0,this.duration=0,this.timer=new s,this.subscriptions.push(this.timer.on("tick",(()=>{const i=performance.now()-this.lastStartTime;this.duration=this.isPaused()?this.duration:this.lastDuration+i,this.emit("record-progress",this.duration)})))}static create(i){return new r(i||{})}renderMicStream(i){var t;const e=new AudioContext,s=e.createMediaStreamSource(i),o=e.createAnalyser();s.connect(o);const r=o.frequencyBinCount,n=new Float32Array(r);let a,d=0;this.wavesurfer&&(null!==(t=this.originalOptions)&&void 0!==t||(this.originalOptions=Object.assign({},this.wavesurfer.options)),this.wavesurfer.options.interact=!1,this.options.scrollingWaveform&&(this.wavesurfer.options.cursorWidth=0));const c=()=>{var i,t,s,u;if(this.isWaveformPaused)a=requestAnimationFrame(c);else{if(o.getFloatTimeDomainData(n),this.options.scrollingWaveform){const i=Math.floor((this.options.scrollingWaveformWindow||0)*e.sampleRate),t=Math.min(i,this.dataWindow?this.dataWindow.length+r:r),s=new Float32Array(i);if(this.dataWindow){const e=Math.max(0,i-this.dataWindow.length);s.set(this.dataWindow.slice(-t+r),e)}s.set(n,i-r),this.dataWindow=s}else if(this.options.continuousWaveform){if(!this.dataWindow){const e=this.options.continuousWaveformDuration?Math.round(60*this.options.continuousWaveformDuration):(null!==(t=null===(i=this.wavesurfer)||void 0===i?void 0:i.getWidth())&&void 0!==t?t:0)*window.devicePixelRatio;this.dataWindow=new Float32Array(e)}const e=Math.max(...n);if(d+1>this.dataWindow.length){const i=new Float32Array(2*this.dataWindow.length);i.set(this.dataWindow,0),this.dataWindow=i}this.dataWindow.set([e],d),d++}else this.dataWindow=n;if(this.wavesurfer){const i=(null!==(u=null===(s=this.dataWindow)||void 0===s?void 0:s.length)&&void 0!==u?u:0)/60;this.wavesurfer.load("",[this.dataWindow],this.options.scrollingWaveform?this.options.scrollingWaveformWindow:i).then((()=>{this.wavesurfer&&this.options.continuousWaveform&&(this.wavesurfer.setTime(this.getDuration()/1e3),this.wavesurfer.options.minPxPerSec||this.wavesurfer.setOptions({minPxPerSec:this.wavesurfer.getWidth()/this.wavesurfer.getDuration()}))})).catch((i=>{console.error("Error rendering real-time recording data:",i)}))}a=requestAnimationFrame(c)}};return c(),{onDestroy:()=>{cancelAnimationFrame(a),null==s||s.disconnect(),null==e||e.close()},onEnd:()=>{this.isWaveformPaused=!0,cancelAnimationFrame(a),this.stopMic()}}}startMic(t){return i(this,void 0,void 0,(function*(){let i;try{i=yield navigator.mediaDevices.getUserMedia({audio:!(null==t?void 0:t.deviceId)||{deviceId:t.deviceId}})}catch(i){throw new Error("Error accessing the microphone: "+i.message)}const{onDestroy:e,onEnd:s}=this.renderMicStream(i);return this.subscriptions.push(this.once("destroy",e)),this.subscriptions.push(this.once("record-end",s)),this.stream=i,i}))}stopMic(){this.stream&&(this.stream.getTracks().forEach((i=>i.stop())),this.stream=null,this.mediaRecorder=null)}startRecording(t){return i(this,void 0,void 0,(function*(){const i=this.stream||(yield this.startMic(t));this.dataWindow=null;const e=this.mediaRecorder||new MediaRecorder(i,{mimeType:this.options.mimeType||o.find((i=>MediaRecorder.isTypeSupported(i))),audioBitsPerSecond:this.options.audioBitsPerSecond});this.mediaRecorder=e,this.stopRecording();const s=[];e.ondataavailable=i=>{i.data.size>0&&s.push(i.data),this.emit("record-data-available",i.data)};const r=i=>{var t;const o=new Blob(s,{type:e.mimeType});this.emit(i,o),this.options.renderRecordedAudio&&(this.applyOriginalOptionsIfNeeded(),null===(t=this.wavesurfer)||void 0===t||t.load(URL.createObjectURL(o)))};e.onpause=()=>r("record-pause"),e.onstop=()=>r("record-end"),e.start(this.options.mediaRecorderTimeslice),this.lastStartTime=performance.now(),this.lastDuration=0,this.duration=0,this.isWaveformPaused=!1,this.timer.start(),this.emit("record-start")}))}getDuration(){return this.duration}isRecording(){var i;return"recording"===(null===(i=this.mediaRecorder)||void 0===i?void 0:i.state)}isPaused(){var i;return"paused"===(null===(i=this.mediaRecorder)||void 0===i?void 0:i.state)}isActive(){var i;return"inactive"!==(null===(i=this.mediaRecorder)||void 0===i?void 0:i.state)}stopRecording(){var i;this.isActive()&&(null===(i=this.mediaRecorder)||void 0===i||i.stop(),this.timer.stop())}pauseRecording(){var i,t;this.isRecording()&&(this.isWaveformPaused=!0,null===(i=this.mediaRecorder)||void 0===i||i.requestData(),null===(t=this.mediaRecorder)||void 0===t||t.pause(),this.timer.stop(),this.lastDuration=this.duration)}resumeRecording(){var i;this.isPaused()&&(this.isWaveformPaused=!1,null===(i=this.mediaRecorder)||void 0===i||i.resume(),this.timer.start(),this.lastStartTime=performance.now(),this.emit("record-resume"))}static getAvailableAudioDevices(){return i(this,void 0,void 0,(function*(){return navigator.mediaDevices.enumerateDevices().then((i=>i.filter((i=>"audioinput"===i.kind))))}))}destroy(){this.applyOriginalOptionsIfNeeded(),super.destroy(),this.stopRecording(),this.stopMic()}applyOriginalOptionsIfNeeded(){this.wavesurfer&&this.originalOptions&&(this.wavesurfer.setOptions(this.originalOptions),delete this.originalOptions)}}export{r as default};

@@ -1,1 +0,1 @@

!function(i,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((i="undefined"!=typeof globalThis?globalThis:i||self).WaveSurfer=i.WaveSurfer||{},i.WaveSurfer.Record=t())}(this,(function(){"use strict";function i(i,t,e,s){return new(e||(e=Promise))((function(o,r){function n(i){try{d(s.next(i))}catch(i){r(i)}}function a(i){try{d(s.throw(i))}catch(i){r(i)}}function d(i){var t;i.done?o(i.value):(t=i.value,t instanceof e?t:new e((function(i){i(t)}))).then(n,a)}d((s=s.apply(i,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class t{constructor(){this.listeners={}}on(i,t,e){if(this.listeners[i]||(this.listeners[i]=new Set),this.listeners[i].add(t),null==e?void 0:e.once){const e=()=>{this.un(i,e),this.un(i,t)};return this.on(i,e),e}return()=>this.un(i,t)}un(i,t){var e;null===(e=this.listeners[i])||void 0===e||e.delete(t)}once(i,t){return this.on(i,t,{once:!0})}unAll(){this.listeners={}}emit(i,...t){this.listeners[i]&&this.listeners[i].forEach((i=>i(...t)))}}class e extends t{constructor(i){super(),this.subscriptions=[],this.options=i}onInit(){}_init(i){this.wavesurfer=i,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((i=>i()))}}class s extends t{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",(()=>{requestAnimationFrame((()=>{this.emit("tick")}))})),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}const o=["audio/webm","audio/wav","audio/mpeg","audio/mp4","audio/mp3"];class r extends e{constructor(i){var t,e,o,r,n,a;super(Object.assign(Object.assign({},i),{audioBitsPerSecond:null!==(t=i.audioBitsPerSecond)&&void 0!==t?t:128e3,scrollingWaveform:null!==(e=i.scrollingWaveform)&&void 0!==e&&e,scrollingWaveformWindow:null!==(o=i.scrollingWaveformWindow)&&void 0!==o?o:5,continuousWaveform:null!==(r=i.continuousWaveform)&&void 0!==r&&r,renderRecordedAudio:null===(n=i.renderRecordedAudio)||void 0===n||n,mediaRecorderTimeslice:null!==(a=i.mediaRecorderTimeslice)&&void 0!==a?a:void 0})),this.stream=null,this.mediaRecorder=null,this.dataWindow=null,this.isWaveformPaused=!1,this.lastStartTime=0,this.lastDuration=0,this.duration=0,this.timer=new s,this.subscriptions.push(this.timer.on("tick",(()=>{const i=performance.now()-this.lastStartTime;this.duration=this.isPaused()?this.duration:this.lastDuration+i,this.emit("record-progress",this.duration)})))}static create(i){return new r(i||{})}renderMicStream(i){var t;const e=new AudioContext,s=e.createMediaStreamSource(i),o=e.createAnalyser();s.connect(o);const r=o.frequencyBinCount,n=new Float32Array(r);let a,d=0;this.wavesurfer&&(null!==(t=this.originalOptions)&&void 0!==t||(this.originalOptions=Object.assign({},this.wavesurfer.options)),this.wavesurfer.options.interact=!1,this.options.scrollingWaveform&&(this.wavesurfer.options.cursorWidth=0));const u=()=>{var i,t,s,h;if(this.isWaveformPaused)a=requestAnimationFrame(u);else{if(o.getFloatTimeDomainData(n),this.options.scrollingWaveform){const i=Math.floor((this.options.scrollingWaveformWindow||0)*e.sampleRate),t=Math.min(i,this.dataWindow?this.dataWindow.length+r:r),s=new Float32Array(i);if(this.dataWindow){const e=Math.max(0,i-this.dataWindow.length);s.set(this.dataWindow.slice(-t+r),e)}s.set(n,i-r),this.dataWindow=s}else if(this.options.continuousWaveform){if(!this.dataWindow){const e=this.options.continuousWaveformDuration?Math.round(60*this.options.continuousWaveformDuration):(null!==(t=null===(i=this.wavesurfer)||void 0===i?void 0:i.getWidth())&&void 0!==t?t:0)*window.devicePixelRatio;this.dataWindow=new Float32Array(e)}const e=Math.max(...n);if(d+1>this.dataWindow.length){const i=new Float32Array(2*this.dataWindow.length);i.set(this.dataWindow,0),this.dataWindow=i}this.dataWindow.set([e],d),d++}else this.dataWindow=n;if(this.wavesurfer){const i=(null!==(h=null===(s=this.dataWindow)||void 0===s?void 0:s.length)&&void 0!==h?h:0)/60;let t=d/this.dataWindow.length;this.wavesurfer.options.barWidth&&(t+=this.wavesurfer.options.barWidth/this.wavesurfer.getWidth()),this.wavesurfer.load("",[this.dataWindow],this.options.scrollingWaveform?this.options.scrollingWaveformWindow:i).then((()=>{this.wavesurfer&&this.options.continuousWaveform&&(this.wavesurfer.seekTo(t),this.wavesurfer.options.minPxPerSec||this.wavesurfer.setOptions({minPxPerSec:this.wavesurfer.getWidth()/this.wavesurfer.getDuration()}))})).catch((i=>{console.error("Error rendering real-time recording data:",i)}))}a=requestAnimationFrame(u)}};return u(),{onDestroy:()=>{cancelAnimationFrame(a),null==s||s.disconnect(),null==e||e.close()},onEnd:()=>{this.isWaveformPaused=!0,cancelAnimationFrame(a),this.stopMic()}}}startMic(t){return i(this,void 0,void 0,(function*(){let i;try{i=yield navigator.mediaDevices.getUserMedia({audio:!(null==t?void 0:t.deviceId)||{deviceId:t.deviceId}})}catch(i){throw new Error("Error accessing the microphone: "+i.message)}const{onDestroy:e,onEnd:s}=this.renderMicStream(i);return this.subscriptions.push(this.once("destroy",e)),this.subscriptions.push(this.once("record-end",s)),this.stream=i,i}))}stopMic(){this.stream&&(this.stream.getTracks().forEach((i=>i.stop())),this.stream=null,this.mediaRecorder=null)}startRecording(t){return i(this,void 0,void 0,(function*(){const i=this.stream||(yield this.startMic(t));this.dataWindow=null;const e=this.mediaRecorder||new MediaRecorder(i,{mimeType:this.options.mimeType||o.find((i=>MediaRecorder.isTypeSupported(i))),audioBitsPerSecond:this.options.audioBitsPerSecond});this.mediaRecorder=e,this.stopRecording();const s=[];e.ondataavailable=i=>{i.data.size>0&&s.push(i.data),this.emit("record-data-available",i.data)};const r=i=>{var t;const o=new Blob(s,{type:e.mimeType});this.emit(i,o),this.options.renderRecordedAudio&&(this.applyOriginalOptionsIfNeeded(),null===(t=this.wavesurfer)||void 0===t||t.load(URL.createObjectURL(o)))};e.onpause=()=>r("record-pause"),e.onstop=()=>r("record-end"),e.start(this.options.mediaRecorderTimeslice),this.lastStartTime=performance.now(),this.lastDuration=0,this.duration=0,this.isWaveformPaused=!1,this.timer.start(),this.emit("record-start")}))}getDuration(){return this.duration}isRecording(){var i;return"recording"===(null===(i=this.mediaRecorder)||void 0===i?void 0:i.state)}isPaused(){var i;return"paused"===(null===(i=this.mediaRecorder)||void 0===i?void 0:i.state)}isActive(){var i;return"inactive"!==(null===(i=this.mediaRecorder)||void 0===i?void 0:i.state)}stopRecording(){var i;this.isActive()&&(null===(i=this.mediaRecorder)||void 0===i||i.stop(),this.timer.stop())}pauseRecording(){var i,t;this.isRecording()&&(this.isWaveformPaused=!0,null===(i=this.mediaRecorder)||void 0===i||i.requestData(),null===(t=this.mediaRecorder)||void 0===t||t.pause(),this.timer.stop(),this.lastDuration=this.duration)}resumeRecording(){var i;this.isPaused()&&(this.isWaveformPaused=!1,null===(i=this.mediaRecorder)||void 0===i||i.resume(),this.timer.start(),this.lastStartTime=performance.now(),this.emit("record-resume"))}static getAvailableAudioDevices(){return i(this,void 0,void 0,(function*(){return navigator.mediaDevices.enumerateDevices().then((i=>i.filter((i=>"audioinput"===i.kind))))}))}destroy(){this.applyOriginalOptionsIfNeeded(),super.destroy(),this.stopRecording(),this.stopMic()}applyOriginalOptionsIfNeeded(){this.wavesurfer&&this.originalOptions&&(this.wavesurfer.setOptions(this.originalOptions),delete this.originalOptions)}}return r}));
!function(i,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((i="undefined"!=typeof globalThis?globalThis:i||self).WaveSurfer=i.WaveSurfer||{},i.WaveSurfer.Record=t())}(this,(function(){"use strict";function i(i,t,e,s){return new(e||(e=Promise))((function(o,r){function n(i){try{d(s.next(i))}catch(i){r(i)}}function a(i){try{d(s.throw(i))}catch(i){r(i)}}function d(i){var t;i.done?o(i.value):(t=i.value,t instanceof e?t:new e((function(i){i(t)}))).then(n,a)}d((s=s.apply(i,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class t{constructor(){this.listeners={}}on(i,t,e){if(this.listeners[i]||(this.listeners[i]=new Set),this.listeners[i].add(t),null==e?void 0:e.once){const e=()=>{this.un(i,e),this.un(i,t)};return this.on(i,e),e}return()=>this.un(i,t)}un(i,t){var e;null===(e=this.listeners[i])||void 0===e||e.delete(t)}once(i,t){return this.on(i,t,{once:!0})}unAll(){this.listeners={}}emit(i,...t){this.listeners[i]&&this.listeners[i].forEach((i=>i(...t)))}}class e extends t{constructor(i){super(),this.subscriptions=[],this.options=i}onInit(){}_init(i){this.wavesurfer=i,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((i=>i()))}}class s extends t{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",(()=>{requestAnimationFrame((()=>{this.emit("tick")}))})),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}const o=["audio/webm","audio/wav","audio/mpeg","audio/mp4","audio/mp3"];class r extends e{constructor(i){var t,e,o,r,n,a;super(Object.assign(Object.assign({},i),{audioBitsPerSecond:null!==(t=i.audioBitsPerSecond)&&void 0!==t?t:128e3,scrollingWaveform:null!==(e=i.scrollingWaveform)&&void 0!==e&&e,scrollingWaveformWindow:null!==(o=i.scrollingWaveformWindow)&&void 0!==o?o:5,continuousWaveform:null!==(r=i.continuousWaveform)&&void 0!==r&&r,renderRecordedAudio:null===(n=i.renderRecordedAudio)||void 0===n||n,mediaRecorderTimeslice:null!==(a=i.mediaRecorderTimeslice)&&void 0!==a?a:void 0})),this.stream=null,this.mediaRecorder=null,this.dataWindow=null,this.isWaveformPaused=!1,this.lastStartTime=0,this.lastDuration=0,this.duration=0,this.timer=new s,this.subscriptions.push(this.timer.on("tick",(()=>{const i=performance.now()-this.lastStartTime;this.duration=this.isPaused()?this.duration:this.lastDuration+i,this.emit("record-progress",this.duration)})))}static create(i){return new r(i||{})}renderMicStream(i){var t;const e=new AudioContext,s=e.createMediaStreamSource(i),o=e.createAnalyser();s.connect(o);const r=o.frequencyBinCount,n=new Float32Array(r);let a,d=0;this.wavesurfer&&(null!==(t=this.originalOptions)&&void 0!==t||(this.originalOptions=Object.assign({},this.wavesurfer.options)),this.wavesurfer.options.interact=!1,this.options.scrollingWaveform&&(this.wavesurfer.options.cursorWidth=0));const u=()=>{var i,t,s,c;if(this.isWaveformPaused)a=requestAnimationFrame(u);else{if(o.getFloatTimeDomainData(n),this.options.scrollingWaveform){const i=Math.floor((this.options.scrollingWaveformWindow||0)*e.sampleRate),t=Math.min(i,this.dataWindow?this.dataWindow.length+r:r),s=new Float32Array(i);if(this.dataWindow){const e=Math.max(0,i-this.dataWindow.length);s.set(this.dataWindow.slice(-t+r),e)}s.set(n,i-r),this.dataWindow=s}else if(this.options.continuousWaveform){if(!this.dataWindow){const e=this.options.continuousWaveformDuration?Math.round(60*this.options.continuousWaveformDuration):(null!==(t=null===(i=this.wavesurfer)||void 0===i?void 0:i.getWidth())&&void 0!==t?t:0)*window.devicePixelRatio;this.dataWindow=new Float32Array(e)}const e=Math.max(...n);if(d+1>this.dataWindow.length){const i=new Float32Array(2*this.dataWindow.length);i.set(this.dataWindow,0),this.dataWindow=i}this.dataWindow.set([e],d),d++}else this.dataWindow=n;if(this.wavesurfer){const i=(null!==(c=null===(s=this.dataWindow)||void 0===s?void 0:s.length)&&void 0!==c?c:0)/60;this.wavesurfer.load("",[this.dataWindow],this.options.scrollingWaveform?this.options.scrollingWaveformWindow:i).then((()=>{this.wavesurfer&&this.options.continuousWaveform&&(this.wavesurfer.setTime(this.getDuration()/1e3),this.wavesurfer.options.minPxPerSec||this.wavesurfer.setOptions({minPxPerSec:this.wavesurfer.getWidth()/this.wavesurfer.getDuration()}))})).catch((i=>{console.error("Error rendering real-time recording data:",i)}))}a=requestAnimationFrame(u)}};return u(),{onDestroy:()=>{cancelAnimationFrame(a),null==s||s.disconnect(),null==e||e.close()},onEnd:()=>{this.isWaveformPaused=!0,cancelAnimationFrame(a),this.stopMic()}}}startMic(t){return i(this,void 0,void 0,(function*(){let i;try{i=yield navigator.mediaDevices.getUserMedia({audio:!(null==t?void 0:t.deviceId)||{deviceId:t.deviceId}})}catch(i){throw new Error("Error accessing the microphone: "+i.message)}const{onDestroy:e,onEnd:s}=this.renderMicStream(i);return this.subscriptions.push(this.once("destroy",e)),this.subscriptions.push(this.once("record-end",s)),this.stream=i,i}))}stopMic(){this.stream&&(this.stream.getTracks().forEach((i=>i.stop())),this.stream=null,this.mediaRecorder=null)}startRecording(t){return i(this,void 0,void 0,(function*(){const i=this.stream||(yield this.startMic(t));this.dataWindow=null;const e=this.mediaRecorder||new MediaRecorder(i,{mimeType:this.options.mimeType||o.find((i=>MediaRecorder.isTypeSupported(i))),audioBitsPerSecond:this.options.audioBitsPerSecond});this.mediaRecorder=e,this.stopRecording();const s=[];e.ondataavailable=i=>{i.data.size>0&&s.push(i.data),this.emit("record-data-available",i.data)};const r=i=>{var t;const o=new Blob(s,{type:e.mimeType});this.emit(i,o),this.options.renderRecordedAudio&&(this.applyOriginalOptionsIfNeeded(),null===(t=this.wavesurfer)||void 0===t||t.load(URL.createObjectURL(o)))};e.onpause=()=>r("record-pause"),e.onstop=()=>r("record-end"),e.start(this.options.mediaRecorderTimeslice),this.lastStartTime=performance.now(),this.lastDuration=0,this.duration=0,this.isWaveformPaused=!1,this.timer.start(),this.emit("record-start")}))}getDuration(){return this.duration}isRecording(){var i;return"recording"===(null===(i=this.mediaRecorder)||void 0===i?void 0:i.state)}isPaused(){var i;return"paused"===(null===(i=this.mediaRecorder)||void 0===i?void 0:i.state)}isActive(){var i;return"inactive"!==(null===(i=this.mediaRecorder)||void 0===i?void 0:i.state)}stopRecording(){var i;this.isActive()&&(null===(i=this.mediaRecorder)||void 0===i||i.stop(),this.timer.stop())}pauseRecording(){var i,t;this.isRecording()&&(this.isWaveformPaused=!0,null===(i=this.mediaRecorder)||void 0===i||i.requestData(),null===(t=this.mediaRecorder)||void 0===t||t.pause(),this.timer.stop(),this.lastDuration=this.duration)}resumeRecording(){var i;this.isPaused()&&(this.isWaveformPaused=!1,null===(i=this.mediaRecorder)||void 0===i||i.resume(),this.timer.start(),this.lastStartTime=performance.now(),this.emit("record-resume"))}static getAvailableAudioDevices(){return i(this,void 0,void 0,(function*(){return navigator.mediaDevices.enumerateDevices().then((i=>i.filter((i=>"audioinput"===i.kind))))}))}destroy(){this.applyOriginalOptionsIfNeeded(),super.destroy(),this.stopRecording(),this.stopMic()}applyOriginalOptionsIfNeeded(){this.wavesurfer&&this.originalOptions&&(this.wavesurfer.setOptions(this.originalOptions),delete this.originalOptions)}}return r}));
{
"name": "wavesurfer.js",
"version": "7.8.3",
"version": "7.8.4-beta.0",
"license": "BSD-3-Clause",

@@ -5,0 +5,0 @@ "author": "katspaugh",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc