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

Handle forced disconnects from Jitsi #21697

Merged
merged 1 commit into from
Apr 6, 2022
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
31 changes: 21 additions & 10 deletions src/vector/jitsi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,18 @@ function createJWTToken() {
);
}

async function notifyHangup() {
if (widgetApi) {
// We send the hangup event before setAlwaysOnScreen, because the latter
// can cause the receiving side to instantly stop listening.
try {
await widgetApi.transport.send(ElementWidgetActions.HangupCall, {});
} finally {
await widgetApi.setAlwaysOnScreen(false);
}
}
}

function joinConference() { // event handler bound in HTML
let jwt;
if (jitsiAuth === JITSI_OPENIDTOKEN_JWT_AUTH) {
Expand Down Expand Up @@ -353,16 +365,7 @@ function joinConference() { // event handler bound in HTML

meetApi.on("readyToClose", () => {
switchVisibleContainers();

if (widgetApi) {
// We send the hangup event before setAlwaysOnScreen, because the latter
// can cause the receiving side to instantly stop listening.
// ignored promise because we don't care if it works
// noinspection JSIgnoredPromiseFromCall
widgetApi.transport.send(ElementWidgetActions.HangupCall, {}).finally(() =>
widgetApi.setAlwaysOnScreen(false),
);
}
notifyHangup();

document.getElementById("jitsiContainer").innerHTML = "";
meetApi = null;
Expand All @@ -372,6 +375,14 @@ function joinConference() { // event handler bound in HTML
}
});

meetApi.on("errorOccurred", ({ error }) => {
if (error.isFatal) {
// We got disconnected. Since Jitsi Meet might send us back to the
// prejoin screen, we're forced to act as if we hung up entirely.
notifyHangup();
}
});

meetApi.on("audioMuteStatusChanged", ({ muted }) => {
const action = muted ? ElementWidgetActions.MuteAudio : ElementWidgetActions.UnmuteAudio;
widgetApi.transport.send(action, {});
Expand Down