Skip to content

Commit 8ef2ad1

Browse files
committed
(fix) prevent recording errors
1 parent 950a2c3 commit 8ef2ad1

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

src/ChatWindow/Room/Room.vue

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@
159159

160160
<div
161161
class="vac-svg-button vac-icon-audio-confirm"
162-
@click="toggleRecorder"
162+
@click="toggleRecorder(false)"
163163
>
164164
<slot name="audio-stop-icon">
165165
<svg-icon name="checkmark" />
166166
</slot>
167167
</div>
168168
</template>
169169

170-
<div v-else class="vac-svg-button" @click="toggleRecorder">
170+
<div v-else class="vac-svg-button" @click="toggleRecorder(true)">
171171
<slot name="microphone-icon">
172172
<svg-icon name="microphone" class="vac-icon-microphone" />
173173
</slot>
@@ -853,34 +853,42 @@ export default {
853853
format: this.format
854854
})
855855
},
856-
toggleRecorder() {
857-
this.isRecording = !this.isRecording
856+
toggleRecorder(recording) {
857+
this.isRecording = recording
858858
859859
if (!this.recorder.isRecording) {
860860
setTimeout(() => this.recorder.start(), 200)
861861
} else {
862-
this.recorder.stop()
863-
864-
const record = this.recorder.records[0]
865-
866-
this.file = {
867-
blob: record.blob,
868-
name: `audio.${this.format}`,
869-
size: record.blob.size,
870-
duration: record.duration,
871-
type: record.blob.type,
872-
audio: true,
873-
localUrl: URL.createObjectURL(record.blob)
874-
}
862+
try {
863+
this.recorder.stop()
864+
865+
const record = this.recorder.records[0]
866+
867+
this.file = {
868+
blob: record.blob,
869+
name: `audio.${this.format}`,
870+
size: record.blob.size,
871+
duration: record.duration,
872+
type: record.blob.type,
873+
audio: true,
874+
localUrl: URL.createObjectURL(record.blob)
875+
}
875876
876-
this.recorder = this.initRecorder()
877-
this.sendMessage()
877+
this.recorder = this.initRecorder()
878+
this.sendMessage()
879+
} catch {
880+
setTimeout(() => this.stopRecorder(), 100)
881+
}
878882
}
879883
},
880884
stopRecorder() {
881885
if (this.recorder.isRecording) {
882-
this.recorder.stop()
883-
this.recorder = this.initRecorder()
886+
try {
887+
this.recorder.stop()
888+
this.recorder = this.initRecorder()
889+
} catch {
890+
setTimeout(() => this.stopRecorder(), 100)
891+
}
884892
}
885893
},
886894
openFile({ message, action }) {

0 commit comments

Comments
 (0)