Handle forced disconnects from Jitsi (#21697)

pull/21707/head
Robin 2022-04-06 13:08:58 -04:00 committed by GitHub
parent ecf1c41f7c
commit ef1d90ad41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 10 deletions

View File

@ -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) {
@ -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;
@ -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, {});