From 349a183af34efd7c3783257f8c2e14061a9e4972 Mon Sep 17 00:00:00 2001 From: nizar Date: Sat, 8 Jun 2024 10:18:24 -0700 Subject: [PATCH] Update record.ts - Add mediaRecorderTimeslice option to RecordPluginOptions to which is passed to mediaRecorder.start(). - Add 'record-data-available' event which returns the blob that is delivered by the mediaRecorder and only that blob --- src/plugins/record.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/record.ts b/src/plugins/record.ts index eca9f6409..8634e2585 100644 --- a/src/plugins/record.ts +++ b/src/plugins/record.ts @@ -16,6 +16,8 @@ export type RecordPluginOptions = { scrollingWaveform?: boolean /** The duration of the scrolling waveform window, defaults to 5 seconds */ scrollingWaveformWindow?: number + /** The timeslice to use for the media recorder */ + mediaRecorderTimeslice?: number } export type RecordPluginDeviceOptions = { @@ -30,6 +32,7 @@ export type RecordPluginEvents = BasePluginEvents & { 'record-end': [blob: Blob] /** Fires continuously while recording */ 'record-progress': [duration: number] + 'record-data-available': [blob: Blob] } type MicStream = { @@ -62,6 +65,7 @@ class RecordPlugin extends BasePlugin { scrollingWaveform: options.scrollingWaveform ?? false, scrollingWaveformWindow: options.scrollingWaveformWindow ?? DEFAULT_SCROLLING_WAVEFORM_WINDOW, renderRecordedAudio: options.renderRecordedAudio ?? true, + mediaRecorderTimeslice: options.mediaRecorderTimeslice ?? undefined, }) this.timer = new Timer() @@ -193,6 +197,7 @@ class RecordPlugin extends BasePlugin { if (event.data.size > 0) { recordedChunks.push(event.data) } + this.emit('record-data-available', event.data) } const emitWithBlob = (ev: 'record-pause' | 'record-end') => { @@ -208,7 +213,7 @@ class RecordPlugin extends BasePlugin { mediaRecorder.onstop = () => emitWithBlob('record-end') - mediaRecorder.start() + mediaRecorder.start(this.options.mediaRecorderTimeslice) this.lastStartTime = performance.now() this.lastDuration = 0 this.duration = 0