Release microphone immediately when cancelling recording
This commit is contained in:
parent
9dc5214db7
commit
ab1c31b64f
2 changed files with 20 additions and 6 deletions
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue