From 69745bbd40069439b6765aff0e2219ac6566e455 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 4 Sep 2020 21:55:50 -0600 Subject: [PATCH] Switch to using the Widget API SDK for Jitsi widgets --- src/vector/jitsi/index.ts | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/vector/jitsi/index.ts b/src/vector/jitsi/index.ts index 081246c0a9..3ebbc7d3b4 100644 --- a/src/vector/jitsi/index.ts +++ b/src/vector/jitsi/index.ts @@ -18,7 +18,12 @@ limitations under the License. require("./index.scss"); import * as qs from 'querystring'; -import { Capability, WidgetApi } from "matrix-react-sdk/src/widgets/WidgetApi"; +import { + IWidgetApiRequest, + IWidgetApiRequestEmptyData, + VideoConferenceCapabilities, + WidgetApi +} from "matrix-widget-api"; // Dev note: we use raw JS without many dependencies to reduce bundle size. // We do not need all of React to render a Jitsi conference. @@ -56,11 +61,19 @@ let widgetApi: WidgetApi; const widgetId = qsParam('widgetId', true); // Set this up as early as possible because Element will be hitting it almost immediately. + let readyPromise: Promise<[void, void]>; if (parentUrl && widgetId) { - widgetApi = new WidgetApi(qsParam('parentUrl'), qsParam('widgetId'), [ - Capability.AlwaysOnScreen, + const parentOrigin = new URL(qsParam('parentUrl')).origin; + widgetApi = new WidgetApi(qsParam("widgetId"), parentOrigin); + widgetApi.requestCapabilities(VideoConferenceCapabilities); + readyPromise = Promise.all([ + widgetApi.waitFor>("im.vector.ready") + .then(ev => widgetApi.transport.reply(ev.detail, {})), + widgetApi.waitFor("ready"), ]); - widgetApi.expectingExplicitReady = true; + widgetApi.start(); + } else { + throw new Error("No parent URL or no widget ID"); } // Populate the Jitsi params now @@ -70,10 +83,8 @@ let widgetApi: WidgetApi; avatarUrl = qsParam('avatarUrl', true); // http not mxc userId = qsParam('userId'); - if (widgetApi) { - await widgetApi.waitReady(); - await widgetApi.setAlwaysOnScreen(false); // start off as detachable from the screen - } + await readyPromise; + 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)