diff --git a/src/vector/jitsi/index.ts b/src/vector/jitsi/index.ts index 055d4aff4f..c801d2ad03 100644 --- a/src/vector/jitsi/index.ts +++ b/src/vector/jitsi/index.ts @@ -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, {});