Release microphone immediately when cancelling recording

This commit is contained in:
Josh Perez 2021-10-15 14:51:33 -04:00 committed by GitHub
parent 9dc5214db7
commit ab1c31b64f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View File

@ -9,6 +9,7 @@ export class RecorderClass {
private input?: GainNode;
private recorder?: WebAudioRecorderClass;
private source?: MediaStreamAudioSourceNode;
private stream?: MediaStream;
private blob?: Blob;
private resolve?: (blob: Blob) => void;
@ -33,6 +34,7 @@ export class RecorderClass {
}
this.input = undefined;
this.stream = undefined;
if (this.context) {
this.context.close();
@ -67,6 +69,7 @@ export class RecorderClass {
}
this.source = this.context.createMediaStreamSource(stream);
this.source.connect(this.input);
this.stream = stream;
} catch (err) {
log.error(
'Recorder.onGetUserMediaError:',
@ -87,6 +90,10 @@ export class RecorderClass {
return;
}
if (this.stream) {
this.stream.getTracks().forEach(track => track.stop());
}
if (this.blob) {
return this.blob;
}

View File

@ -148,12 +148,20 @@ function completeRecording(
};
}
function cancelRecording(): CancelRecordingAction {
recorder.clear();
function cancelRecording(): ThunkAction<
void,
RootStateType,
unknown,
CancelRecordingAction
> {
return async dispatch => {
await recorder.stop();
recorder.clear();
return {
type: CANCEL_RECORDING,
payload: undefined,
dispatch({
type: CANCEL_RECORDING,
payload: undefined,
});
};
}
@ -200,7 +208,6 @@ export function reducer(
return {
...state,
errorDialogAudioRecorderType: action.payload,
isRecording: false,
};
}