Skip to content

Commit

Permalink
More robust exiting from the video
Browse files Browse the repository at this point in the history
  • Loading branch information
nkonev committed Dec 24, 2024
1 parent 015027e commit d78b50c
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions frontend/src/ChatVideo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ export default {
presenterVideoMute: false,
presenterAudioMute: true,
showControls: true,
localTrackDrawn: false,
localTrackCreatedAndPublished: false,
connectedToRoom: false,
}
},
methods: {
Expand Down Expand Up @@ -218,10 +222,15 @@ export default {
return
} finally {
if (localVideoProperties) {
this.chatStore.initializingVideoCall = false;
this.localTrackDrawn = true;
this.updateInitializingVideoCall();
}
}
},
updateInitializingVideoCall() {
// because of possibly 2 local tracks (audio + video) we wait for localTrackCreatedAndPublished too
this.chatStore.initializingVideoCall = !(this.localTrackDrawn && this.localTrackCreatedAndPublished && this.connectedToRoom);
},
getPresenterPriority(pub, isSpeaking) {
if (!pub) {
return -1
Expand Down Expand Up @@ -427,11 +436,14 @@ export default {
}
},
async tryRestartVideoDevice() {
this.inRestarting = true;
async stopLocalTracks() {
for (const publication of this.room.localParticipant.getTrackPublications().values()) {
await this.room.localParticipant.unpublishTrack(publication.track, true);
}
},
async tryRestartVideoDevice() {
this.inRestarting = true;
await this.stopLocalTracks();
await this.createLocalMediaTracks(getStoredCallVideoDeviceId(), getStoredCallAudioDeviceId());
bus.emit(VIDEO_PARAMETERS_CHANGED);
this.inRestarting = false;
Expand Down Expand Up @@ -520,6 +532,15 @@ export default {
autoSubscribe: true,
});
console.log('Connected to room', this.room.name);
// after a several attempts (Firefox + ssh tunnel)
// it turns into true
// and the spinner on red tube button disappears
// so we can leave the call, and we won't get an error "this.room is null in createLocalMediaTracks()"
// because of this retry
this.connectedToRoom = true;
this.updateInitializingVideoCall();
} else {
console.warn("Didn't connect to room because it's null. It is ok when user leaves very fast.");
}
Expand Down Expand Up @@ -645,6 +666,9 @@ export default {
}
console.info("Published track sid=", track.sid, " kind=", track.kind);
}
this.localTrackCreatedAndPublished = true;
this.updateInitializingVideoCall();
return Promise.resolve(true);
} catch (e) {
this.setError(e, "Error during publishing local tracks");
this.chatStore.initializingVideoCall = false;
Expand Down Expand Up @@ -975,7 +999,7 @@ export default {
this.startRoom(enterResponse.data.token);
},
beforeUnmount() {
async beforeUnmount() {
axios.put(`/api/video/${this.chatId}/dial/exit`, null, {
params: {
tokenId: this.chatStore.videoTokenId
Expand All @@ -984,14 +1008,18 @@ export default {
this.detachPresenter();
this.stopRoom().then(()=>{
console.log("Cleaning videoContainerDiv");
this.videoContainerDiv = null;
this.inRestarting = false;
});
await this.stopLocalTracks();
await this.stopRoom();
console.log("Cleaning videoContainerDiv");
this.videoContainerDiv = null;
this.inRestarting = false;
this.chatStore.canShowMicrophoneButton = false;
this.localTrackDrawn = false;
this.localTrackCreatedAndPublished = false;
this.connectedToRoom = false;
if (!this.isMobile()) {
this.chatStore.showDrawer = this.chatStore.showDrawerPrevious;
this.chatStore.showDrawerPrevious = false;
Expand Down

0 comments on commit d78b50c

Please sign in to comment.