Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Audio recording doesn't stop in direct messages on channel switch #22880

Merged
merged 3 commits into from
Aug 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions app/ui-message/client/messageBox/messageBoxAudioMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ const stopRecording = () => new Promise((resolve) => AudioRecorder.stop(resolve)
const recordingInterval = new ReactiveVar(null);
const recordingRoomId = new ReactiveVar(null);

const cancelRecording = (instance) => new Promise(async () => {
if (recordingInterval.get()) {
clearInterval(recordingInterval.get());
recordingInterval.set(null);
recordingRoomId.set(null);
}

instance.time.set('00:00');

await stopRecording();

instance.state.set(null);
});

Template.messageBoxAudioMessage.onCreated(async function() {
this.state = new ReactiveVar(null);
this.time = new ReactiveVar('00:00');
Expand Down Expand Up @@ -47,6 +61,12 @@ Template.messageBoxAudioMessage.onCreated(async function() {
}
});

Template.messageBoxAudioMessage.onDestroyed(async function() {
if (this.state.get() === 'recording') {
await cancelRecording(this);
}
});

Template.messageBoxAudioMessage.helpers({
isAllowed() {
return AudioRecorder.isSupported()
Expand Down Expand Up @@ -105,17 +125,7 @@ Template.messageBoxAudioMessage.events({
async 'click .js-audio-message-cancel'(event, instance) {
event.preventDefault();

if (recordingInterval.get()) {
clearInterval(recordingInterval.get());
recordingInterval.set(null);
recordingRoomId.set(null);
}

instance.time.set('00:00');

await stopRecording();

instance.state.set(null);
await cancelRecording(instance);
},

async 'click .js-audio-message-done'(event, instance) {
Expand Down