Skip to content

Commit

Permalink
fix: stop all stream tracks when leaving inbox-form-recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriansaliou committed Jan 4, 2024
1 parent 94417a0 commit 9bca00c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/components/inbox/InboxFormRecorder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ export default {

// --> STATE <--

stream: null as null | MediaStream,
recorder: null as null | MediaRecorder,

audioChunks: [] as Array<Blob>,

emitAudioProcessing: false,
Expand Down Expand Up @@ -228,10 +230,10 @@ export default {
}

// Capture media stream
const stream = await this.captureMediaStream();
this.stream = await this.captureMediaStream();

// Create media recorder
this.recorder = this.createMediaRecorder(stream);
this.recorder = this.createMediaRecorder(this.stream);

// Start recording
this.recorder.start();
Expand Down Expand Up @@ -313,6 +315,7 @@ export default {
},

destroyMediaRecorder() {
// Stop recorder? (if any)
if (this.recorder !== null) {
try {
// Stop recording (forced)
Expand All @@ -322,8 +325,23 @@ export default {
}
}

// Forcibly unset recorder instance
// Stop associated stream tracks? (if any)
if (this.stream !== null) {
try {
this.stream.getTracks().forEach(track => {
track.stop();
});
} catch (error) {
logger.warn(
"Failed stopping stream tracks associated to media recorder",
error
);
}
}

// Forcibly unset recorder instances
this.recorder = null;
this.stream = null;
this.audioChunks = [];
this.emitAudioOnStop = false;
},
Expand Down

0 comments on commit 9bca00c

Please sign in to comment.