Release microphone immediately when cancelling recording
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user