From 24fe98a78cb9bf58d151673fc62422b11c042a30 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 1 Apr 2020 11:08:53 +0100 Subject: [PATCH] Make widget API use optional So we can work when popped out into a browser --- src/vector/jitsi/index.ts | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/vector/jitsi/index.ts b/src/vector/jitsi/index.ts index 1108e70c..8150a399 100644 --- a/src/vector/jitsi/index.ts +++ b/src/vector/jitsi/index.ts @@ -49,11 +49,19 @@ let widgetApi: WidgetApi; return query[name]; }; + // If we have these params, expect a widget API to be available (ie. to be in an iframe + // inside a matrix client). Otherwise, assume we're on our own, eg. have been popped + // out into a browser. + const parentUrl = qsParam('parentUrl', true); + const widgetId = qsParam('widgetId', true); + // Set this up as early as possible because Riot will be hitting it almost immediately. - widgetApi = new WidgetApi(qsParam('parentUrl'), qsParam('widgetId'), [ - Capability.AlwaysOnScreen, - ]); - widgetApi.expectingExplicitReady = true; + if (parentUrl && widgetId) { + widgetApi = new WidgetApi(qsParam('parentUrl'), qsParam('widgetId'), [ + Capability.AlwaysOnScreen, + ]); + widgetApi.expectingExplicitReady = true; + } // Populate the Jitsi params now jitsiDomain = qsParam('conferenceDomain'); @@ -62,8 +70,10 @@ let widgetApi: WidgetApi; avatarUrl = qsParam('avatarUrl', true); // http not mxc userId = qsParam('userId'); - await widgetApi.waitReady(); - await widgetApi.setAlwaysOnScreen(false); // start off as detachable from the screen + if (widgetApi) { + await widgetApi.waitReady(); + await widgetApi.setAlwaysOnScreen(false); // start off as detachable from the screen + } // TODO: register widgetApi listeners for PTT controls (https://github.com/vector-im/riot-web/issues/12795) @@ -85,7 +95,7 @@ function joinConference() { // event handler bound in HTML switchVisibleContainers(); // noinspection JSIgnoredPromiseFromCall - widgetApi.setAlwaysOnScreen(true); // ignored promise because we don't care if it works + if (widgetApi) widgetApi.setAlwaysOnScreen(true); // ignored promise because we don't care if it works const meetApi = new JitsiMeetExternalAPI(jitsiDomain, { width: "100%", @@ -107,7 +117,7 @@ function joinConference() { // event handler bound in HTML switchVisibleContainers(); // noinspection JSIgnoredPromiseFromCall - widgetApi.setAlwaysOnScreen(false); // ignored promise because we don't care if it works + if (widgetApi) widgetApi.setAlwaysOnScreen(false); // ignored promise because we don't care if it works document.getElementById("jitsiContainer").innerHTML = ""; });