diff --git a/conversejs/builtin.ts b/conversejs/builtin.ts index 57a1a495..f5b93c3d 100644 --- a/conversejs/builtin.ts +++ b/conversejs/builtin.ts @@ -168,6 +168,16 @@ async function initConverse ( if (tryOIDC && !isAuthenticated) { params.livechat_external_auth_oidc_button_label = initConverseParams.externalAuthOIDC?.buttonLabel params.livechat_external_auth_oidc_url = initConverseParams.externalAuthOIDC?.url + + switch (chatIncludeMode) { + case 'peertube-video': + params.livechat_external_auth_reconnect_mode = 'button-close-open' + break + case 'peertube-fullpage': + case 'chat-only': + default: + params.livechat_external_auth_reconnect_mode = 'reload' + } } if (chatIncludeMode === 'peertube-video') { diff --git a/conversejs/custom/templates/livechat-external-login-modal.js b/conversejs/custom/templates/livechat-external-login-modal.js index b7211539..d55516bb 100644 --- a/conversejs/custom/templates/livechat-external-login-modal.js +++ b/conversejs/custom/templates/livechat-external-login-modal.js @@ -1,4 +1,4 @@ -import { api } from '@converse/headless/core' +import { _converse, api } from '@converse/headless/core' import { __ } from 'i18n' import { html } from 'lit' @@ -50,8 +50,32 @@ export const tplExternalLoginModal = (el, o) => { // Storing the token in sessionStorage. window.sessionStorage.setItem('peertube-plugin-livechat-oidc-token', data.token) - // FIXME: do better. - window.location.reload() + const reconnectMode = api.settings.get('livechat_external_auth_reconnect_mode') + if (reconnectMode === 'button-close-open') { + // Here, we click on the close button, then on the open button. + // FIXME: there is maybe a better way to do this. + try { + // But first, close the modal. + document.getElementsByClassName('livechat-external-login-modal')[0] + .closest('.modal-dialog') + .querySelector('button.close') + .click() + + // As soon as disconnected, re-open: + _converse.api.listen.once('disconnected', () => { + document.getElementsByClassName('peertube-plugin-livechat-button-open')[0].click() + }) + + // And we close! + document.getElementsByClassName('peertube-plugin-livechat-button-close')[0].click() + } catch (err) { + // fallback... reloading window :/ + console.error(err) + window.location.reload() + } + } else { // reload and other use cases... + window.location.reload() + } } return false diff --git a/conversejs/lib/plugins/livechat-specific.ts b/conversejs/lib/plugins/livechat-specific.ts index 5ff95bbb..e6dc0399 100644 --- a/conversejs/lib/plugins/livechat-specific.ts +++ b/conversejs/lib/plugins/livechat-specific.ts @@ -38,6 +38,7 @@ export const livechatSpecificsPlugin = { 'hide_muc_participants', 'livechat_enable_viewer_mode', 'livechat_external_auth_oidc_button_label', 'livechat_external_auth_oidc_url', + 'livechat_external_auth_reconnect_mode', 'livechat_mini_muc_head' ]) { _converse.api.settings.set(k, params[k]) diff --git a/conversejs/lib/plugins/livechat-viewer-mode.ts b/conversejs/lib/plugins/livechat-viewer-mode.ts index 5d89977b..b9884fe8 100644 --- a/conversejs/lib/plugins/livechat-viewer-mode.ts +++ b/conversejs/lib/plugins/livechat-viewer-mode.ts @@ -10,7 +10,8 @@ export const livechatViewerModePlugin = { livechat_peertube_video_original_url: undefined, livechat_peertube_video_uuid: undefined, livechat_external_auth_oidc_button_label: undefined, - livechat_external_auth_oidc_url: undefined + livechat_external_auth_oidc_url: undefined, + livechat_external_auth_reconnect_mode: undefined }) const originalGetDefaultMUCNickname = _converse.getDefaultMUCNickname