From f7bf0d013c54111c903468010b878994f118a13e Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Mon, 23 Mar 2020 10:17:45 -0600 Subject: [PATCH] Support sending and receiving v1 Jitsi widgets Fixes https://github.com/vector-im/riot-web/issues/12816 Fixes https://github.com/vector-im/riot-web/issues/12814 --- src/CallHandler.js | 8 +++++++- src/utils/WidgetUtils.js | 21 ++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/CallHandler.js b/src/CallHandler.js index b21f07ad4f..362db939a3 100644 --- a/src/CallHandler.js +++ b/src/CallHandler.js @@ -433,7 +433,13 @@ async function _startCallApp(roomId, type) { const confId = `JitsiConference_${generateHumanReadableId()}`; const jitsiDomain = SdkConfig.get()['jitsi']['preferredDomain']; - const widgetUrl = WidgetUtils.getLocalJitsiWrapperUrl(); + let widgetUrl = WidgetUtils.getLocalJitsiWrapperUrl(); + + // TODO: Remove URL hacks when the mobile clients eventually support v2 widgets + const parsedUrl = new URL(widgetUrl); + parsedUrl.search = ''; // set to empty string to make the URL class use searchParams instead + parsedUrl.searchParams.set('confId', confId); + widgetUrl = parsedUrl.toString(); const widgetData = { conferenceId: confId, diff --git a/src/utils/WidgetUtils.js b/src/utils/WidgetUtils.js index 45ca7602bd..74e5f82c35 100644 --- a/src/utils/WidgetUtils.js +++ b/src/utils/WidgetUtils.js @@ -422,6 +422,22 @@ export default class WidgetUtils { app.eventId = eventId; app.name = app.name || app.type; + if (app.type === 'jitsi') { + console.log("Replacing Jitsi widget URL with local wrapper"); + if (!app.data || !app.data.conferenceId) { + // Assumed to be a v1 widget: add a data object for visibility on the wrapper + // TODO: Remove this once mobile supports v2 widgets + console.log("Replacing v1 Jitsi widget with v2 equivalent"); + const parsed = new URL(app.url); + app.data = { + conferenceId: parsed.searchParams.get("confId"), + domain: "jitsi.riot.im", // v1 widgets have this hardcoded + }; + } + + app.url = WidgetUtils.getLocalJitsiWrapperUrl({forLocalRender: true}); + } + if (app.data) { Object.keys(app.data).forEach((key) => { params['$' + key] = app.data[key]; @@ -430,11 +446,6 @@ export default class WidgetUtils { app.waitForIframeLoad = (app.data.waitForIframeLoad === 'false' ? false : true); } - if (app.type === 'jitsi') { - console.log("Replacing Jitsi widget URL with local wrapper"); - app.url = WidgetUtils.getLocalJitsiWrapperUrl({forLocalRender: true}); - } - app.url = encodeUri(app.url, params); return app;