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 input?: GainNode;
|
||||||
private recorder?: WebAudioRecorderClass;
|
private recorder?: WebAudioRecorderClass;
|
||||||
private source?: MediaStreamAudioSourceNode;
|
private source?: MediaStreamAudioSourceNode;
|
||||||
|
private stream?: MediaStream;
|
||||||
private blob?: Blob;
|
private blob?: Blob;
|
||||||
private resolve?: (blob: Blob) => void;
|
private resolve?: (blob: Blob) => void;
|
||||||
|
|
||||||
|
@ -33,6 +34,7 @@ export class RecorderClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.input = undefined;
|
this.input = undefined;
|
||||||
|
this.stream = undefined;
|
||||||
|
|
||||||
if (this.context) {
|
if (this.context) {
|
||||||
this.context.close();
|
this.context.close();
|
||||||
|
@ -67,6 +69,7 @@ export class RecorderClass {
|
||||||
}
|
}
|
||||||
this.source = this.context.createMediaStreamSource(stream);
|
this.source = this.context.createMediaStreamSource(stream);
|
||||||
this.source.connect(this.input);
|
this.source.connect(this.input);
|
||||||
|
this.stream = stream;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.error(
|
log.error(
|
||||||
'Recorder.onGetUserMediaError:',
|
'Recorder.onGetUserMediaError:',
|
||||||
|
@ -87,6 +90,10 @@ export class RecorderClass {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.stream) {
|
||||||
|
this.stream.getTracks().forEach(track => track.stop());
|
||||||
|
}
|
||||||
|
|
||||||
if (this.blob) {
|
if (this.blob) {
|
||||||
return this.blob;
|
return this.blob;
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,12 +148,20 @@ function completeRecording(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancelRecording(): CancelRecordingAction {
|
function cancelRecording(): ThunkAction<
|
||||||
recorder.clear();
|
void,
|
||||||
|
RootStateType,
|
||||||
|
unknown,
|
||||||
|
CancelRecordingAction
|
||||||
|
> {
|
||||||
|
return async dispatch => {
|
||||||
|
await recorder.stop();
|
||||||
|
recorder.clear();
|
||||||
|
|
||||||
return {
|
dispatch({
|
||||||
type: CANCEL_RECORDING,
|
type: CANCEL_RECORDING,
|
||||||
payload: undefined,
|
payload: undefined,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +208,6 @@ export function reducer(
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
errorDialogAudioRecorderType: action.payload,
|
errorDialogAudioRecorderType: action.payload,
|
||||||
isRecording: false,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue