This commit is contained in:
Timothy J. Baek 2024-09-21 04:53:44 +02:00
parent d3ef9d980b
commit 2f028b45fe

View File

@ -220,7 +220,9 @@
}; };
const startRecording = async () => { const startRecording = async () => {
audioStream = await navigator.mediaDevices.getUserMedia({ audio: true }); if (!audioStream) {
audioStream = await navigator.mediaDevices.getUserMedia({ audio: true });
}
mediaRecorder = new MediaRecorder(audioStream); mediaRecorder = new MediaRecorder(audioStream);
mediaRecorder.onstart = () => { mediaRecorder.onstart = () => {
@ -236,7 +238,7 @@
}; };
mediaRecorder.onstop = (e) => { mediaRecorder.onstop = (e) => {
console.log('Recording stopped', e); console.log('Recording stopped', audioStream, e);
stopRecordingCallback(); stopRecordingCallback();
}; };
@ -244,10 +246,11 @@
}; };
const stopAudioStream = async () => { const stopAudioStream = async () => {
if (audioStream) { if (!audioStream) return;
const tracks = audioStream.getTracks();
tracks.forEach((track) => track.stop()); audioStream.getAudioTracks().forEach(function (track) {
} track.stop();
});
audioStream = null; audioStream = null;
}; };
@ -617,6 +620,10 @@
eventTarget.addEventListener('chat:finish', chatFinishHandler); eventTarget.addEventListener('chat:finish', chatFinishHandler);
return async () => { return async () => {
await stopAllAudio();
stopAudioStream();
eventTarget.removeEventListener('chat:start', chatStartHandler); eventTarget.removeEventListener('chat:start', chatStartHandler);
eventTarget.removeEventListener('chat', chatEventHandler); eventTarget.removeEventListener('chat', chatEventHandler);
eventTarget.removeEventListener('chat:finish', chatFinishHandler); eventTarget.removeEventListener('chat:finish', chatFinishHandler);
@ -632,6 +639,9 @@
}); });
onDestroy(async () => { onDestroy(async () => {
await stopAllAudio();
stopAudioStream();
eventTarget.removeEventListener('chat:start', chatStartHandler); eventTarget.removeEventListener('chat:start', chatStartHandler);
eventTarget.removeEventListener('chat', chatEventHandler); eventTarget.removeEventListener('chat', chatEventHandler);
eventTarget.removeEventListener('chat:finish', chatFinishHandler); eventTarget.removeEventListener('chat:finish', chatFinishHandler);
@ -932,6 +942,10 @@
on:click={async () => { on:click={async () => {
await stopAudioStream(); await stopAudioStream();
await stopVideoStream(); await stopVideoStream();
console.log(audioStream);
console.log(cameraStream);
showCallOverlay.set(false); showCallOverlay.set(false);
dispatch('close'); dispatch('close');
}} }}