Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mediaRecorderTimeslice option to RecordPluginOptions #3760

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/plugins/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand Down Expand Up @@ -62,6 +65,7 @@ class RecordPlugin extends BasePlugin<RecordPluginEvents, RecordPluginOptions> {
scrollingWaveform: options.scrollingWaveform ?? false,
scrollingWaveformWindow: options.scrollingWaveformWindow ?? DEFAULT_SCROLLING_WAVEFORM_WINDOW,
renderRecordedAudio: options.renderRecordedAudio ?? true,
mediaRecorderTimeslice: options.mediaRecorderTimeslice ?? undefined,
})

this.timer = new Timer()
Expand Down Expand Up @@ -193,6 +197,7 @@ class RecordPlugin extends BasePlugin<RecordPluginEvents, RecordPluginOptions> {
if (event.data.size > 0) {
recordedChunks.push(event.data)
}
this.emit('record-data-available', event.data)
}

const emitWithBlob = (ev: 'record-pause' | 'record-end') => {
Expand All @@ -208,7 +213,7 @@ class RecordPlugin extends BasePlugin<RecordPluginEvents, RecordPluginOptions> {

mediaRecorder.onstop = () => emitWithBlob('record-end')

mediaRecorder.start()
mediaRecorder.start(this.options.mediaRecorderTimeslice)
this.lastStartTime = performance.now()
this.lastDuration = 0
this.duration = 0
Expand Down
Loading