From 3309b2ec552bc463e7a7197ce7c44bc8b6aec0b9 Mon Sep 17 00:00:00 2001 From: Jason Robinson Date: Tue, 8 Sep 2020 11:37:50 +0300 Subject: [PATCH] Block on matrix-org/matrix-react-sdk#5172 And shuffle code around a bit. --- src/vector/jitsi/index.ts | 86 +++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 45 deletions(-) diff --git a/src/vector/jitsi/index.ts b/src/vector/jitsi/index.ts index fa9e7759fb..8392e1e530 100644 --- a/src/vector/jitsi/index.ts +++ b/src/vector/jitsi/index.ts @@ -41,51 +41,6 @@ let openIDToken: string; let widgetApi: WidgetApi; -function processOpenIDMessage(msg) { - const data = (msg.action === 'get_openid') ? msg.response : msg.data; - // TODO: just use data.state once https://github.com/matrix-org/matrix-react-sdk/pull/5172 is out - const result = (data.state !== undefined) ? data.state : - (data.success === true) ? 'allowed' : 'blocked'; - - switch (result) { - case 'allowed': - console.info('Successfully got OpenID credentials.'); - openIDToken = data.access_token; - // Send a response if this was not a response - if (msg.action === 'openid_credentials') { - const request = objectClone(msg); - request.response = {}; - window.parent.postMessage(request, '*'); - } - enableJoinButton(); - break; - case 'blocked': - console.warn('OpenID credentials request was blocked by user.'); - document.getElementById("widgetActionContainer").innerText = "Failed to load Jitsi widget"; - break; - default: - // nothing to do - } -} - -/** - * Implements processing OpenID token requests as per MSC1960 - */ -function onWidgetMessage(msg) { - const data = msg.data; - if (!data) { - return; - } - switch (data.action) { - case 'get_openid': - case 'openid_credentials': - processOpenIDMessage(data); - break; - default: - // Nothing to do - } -} - (async function() { try { // The widget's options are encoded into the fragment to avoid leaking info to the server. The widget @@ -147,6 +102,47 @@ function onWidgetMessage(msg) { } })(); +function processOpenIDMessage(msg) { + const data = (msg.action === 'get_openid') ? msg.response : msg.data; + + switch (data.state) { + case 'allowed': + console.info('Successfully got OpenID credentials.'); + openIDToken = data.access_token; + // Send a response if this was not a response + if (msg.action === 'openid_credentials') { + const request = objectClone(msg); + request.response = {}; + window.parent.postMessage(request, '*'); + } + enableJoinButton(); + break; + case 'blocked': + console.warn('OpenID credentials request was blocked by user.'); + document.getElementById("widgetActionContainer").innerText = "Failed to load Jitsi widget"; + break; + default: + // nothing to do + } +} + +/** + * Implements processing OpenID token requests as per MSC1960 + */ +function onWidgetMessage(msg) { + const data = msg.data; + if (!data) { + return; + } + switch (data.action) { + case 'get_openid': + case 'openid_credentials': + processOpenIDMessage(data); + break; + default: + // Nothing to do + } +} function enableJoinButton() { document.getElementById("joinButton").onclick = () => joinConference();