From 8cd2372f53c05fd1e3e85bb5af0a72b2c338f859 Mon Sep 17 00:00:00 2001 From: C0ffeeCode Date: Thu, 6 Jan 2022 15:42:10 +0100 Subject: [PATCH] fixed bug: If recording is paused before restarting it will cause the "Recording paused" not to be edited --- .../room/AttachmentUis/VoiceMailRecorder.jsx | 16 +++++++++------- src/app/organisms/room/RoomViewInput.jsx | 1 - 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/app/organisms/room/AttachmentUis/VoiceMailRecorder.jsx b/src/app/organisms/room/AttachmentUis/VoiceMailRecorder.jsx index 5f98ff51..dd0cedf0 100644 --- a/src/app/organisms/room/AttachmentUis/VoiceMailRecorder.jsx +++ b/src/app/organisms/room/AttachmentUis/VoiceMailRecorder.jsx @@ -60,16 +60,17 @@ function startOrResumeRec() { timer.resume(); } -function restartRec() { +async function restartRec() { // TODO: BUG: If recording is paused before restarting // it will cause the "Recording paused" not to be edited - if (_mediaRecorder.state !== 'recording') _mediaRecorder.pause(); - if (_mediaRecorder.state !== 'inactive') _mediaRecorder.stop(); + // Needed, otherwise the browser indicator would remain after closing UI + if (_mediaRecorder.state !== 'inactive') _mediaRecorder.stop(); + _stream.getTracks().forEach((track) => track.stop()); _mediaRecorder = null; timer = new Timer(); - init() - .then(startOrResumeRec); + await init(); + startOrResumeRec(); } function VoiceMailRecorder({ fnHowToSubmit }) { @@ -109,7 +110,6 @@ function VoiceMailRecorder({ fnHowToSubmit }) { const audioFile = new File([audioBlob], 'voicemail.webm', opts); fnHowToSubmit(audioFile); - // BUG: This will cause the recorder to add the file although it was to be cancelled }, 300); // TODO: Fix this hack, stop does not mean dataavailable but its going to happen soon } } @@ -151,7 +151,9 @@ function VoiceMailRecorder({ fnHowToSubmit }) { {(_mediaRecorder && _mediaRecorder.state === 'recording') ? (Pause) : (Start)} - Reset + restartRec().then(() => setState('Recording...'))} src={ArrowIC} tooltip="Start over"> + Reset + stopAndSubmit()} src={ChevronBottomIC} tooltip="Add as attachment" type="submit">Submit diff --git a/src/app/organisms/room/RoomViewInput.jsx b/src/app/organisms/room/RoomViewInput.jsx index f37e9def..4d1d2f7e 100644 --- a/src/app/organisms/room/RoomViewInput.jsx +++ b/src/app/organisms/room/RoomViewInput.jsx @@ -180,7 +180,6 @@ function RoomViewInput({ if (msgBody.trim() === '' && attachmentOrUi === null) return; sendIsTyping(false); - // TODO: Notify user about their mistake if (typeof attachmentOrUi === 'string') return; // Attachment UI is not finished roomsInput.setMessage(roomId, msgBody); if (attachmentOrUi !== null && typeof attachmentOrUi === 'object') {