Code refactoring WIP:
Cleaning the way ConverseJS parameters are given to the full page.
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import type { InitConverseParams } from './lib/types'
|
||||
import type { InitConverseJSParams } from 'shared/lib/types'
|
||||
import { inIframe } from './lib/utils'
|
||||
import { initDom } from './lib/dom'
|
||||
import {
|
||||
@ -19,11 +19,11 @@ declare global {
|
||||
add: (name: string, plugin: any) => void
|
||||
}
|
||||
}
|
||||
initConverse: (args: InitConverseParams) => Promise<void>
|
||||
initConverse: (args: InitConverseJSParams) => Promise<void>
|
||||
}
|
||||
}
|
||||
|
||||
window.initConverse = async function initConverse (initConverseParams: InitConverseParams): Promise<void> {
|
||||
window.initConverse = async function initConverse (initConverseParams: InitConverseJSParams): Promise<void> {
|
||||
// First, fixing relative websocket urls.
|
||||
if (initConverseParams.localWebsocketServiceUrl?.startsWith('/')) {
|
||||
initConverseParams.localWebsocketServiceUrl = new URL(
|
||||
|
@ -14,24 +14,9 @@
|
||||
<noscript>You need to enable JavaScript to run the Converse.js chat app.</noscript>
|
||||
<div id="conversejs-bg" class="theme-peertube"></div>
|
||||
<script type="text/javascript">
|
||||
initConverse({
|
||||
isRemoteChat: '{{IS_REMOTE_CHAT}}' === 'true',
|
||||
localAnonymousJID: '{{LOCAL_ANONYMOUS_JID}}',
|
||||
remoteAnonymousJID: '{{REMOTE_ANONYMOUS_JID}}' === '' ? null : '{{REMOTE_ANONYMOUS_JID}}',
|
||||
remoteAnonymousXMPPServer: '{{REMOTE_ANONYMOUS_XMPP_SERVER}}' === 'true',
|
||||
remoteAuthenticatedXMPPServer: '{{REMOTE_AUTHENTICATED_XMPP_SERVER}}' === 'true',
|
||||
assetsPath : '{{BASE_STATIC_URL}}conversejs/',
|
||||
room: '{{ROOM}}',
|
||||
localBoshServiceUrl: '{{LOCAL_BOSH_SERVICE_URL}}' === '' ? null : '{{LOCAL_BOSH_SERVICE_URL}}',
|
||||
localWebsocketServiceUrl: '{{LOCAL_WS_SERVICE_URL}}' === '' ? null : '{{LOCAL_WS_SERVICE_URL}}',
|
||||
remoteBoshServiceUrl: '{{REMOTE_BOSH_SERVICE_URL}}' === '' ? null : '{{REMOTE_BOSH_SERVICE_URL}}',
|
||||
remoteWebsocketServiceUrl: '{{REMOTE_WS_SERVICE_URL}}' === '' ? null : '{{REMOTE_WS_SERVICE_URL}}',
|
||||
authenticationUrl: '{{AUTHENTICATION_URL}}',
|
||||
autoViewerMode: '{{AUTOVIEWERMODE}}' === 'true',
|
||||
theme: '{{CONVERSEJS_THEME}}',
|
||||
forceReadonly: '{{FORCEREADONLY}}' === 'noscroll' ? '{{FORCEREADONLY}}' : '{{FORCEREADONLY}}' === 'true',
|
||||
transparent: '{{TRANSPARENT}}' === 'true'
|
||||
})
|
||||
initConverse(
|
||||
{INIT_CONVERSE_PARAMS}
|
||||
)
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,4 +1,4 @@
|
||||
import type { InitConverseParams } from './types'
|
||||
import type { InitConverseJSParams } from 'shared/lib/types'
|
||||
import type { AuthentInfos } from './auth'
|
||||
|
||||
/**
|
||||
@ -9,7 +9,7 @@ import type { AuthentInfos } from './auth'
|
||||
* @returns default parameters to provide to ConverseJS.
|
||||
*/
|
||||
function defaultConverseParams (
|
||||
{ forceReadonly, theme, assetsPath, room }: InitConverseParams,
|
||||
{ forceReadonly, theme, assetsPath, room }: InitConverseJSParams,
|
||||
isInIframe: boolean
|
||||
): any {
|
||||
const mucShowInfoMessages = forceReadonly
|
||||
@ -96,7 +96,10 @@ function defaultConverseParams (
|
||||
* @param auth authent infos.
|
||||
* @param params ConverseJS parameters to fill
|
||||
*/
|
||||
function localRoomAuthenticatedParams (initConverseParams: InitConverseParams, auth: AuthentInfos, params: any): void {
|
||||
function localRoomAuthenticatedParams (
|
||||
initConverseParams: InitConverseJSParams,
|
||||
auth: AuthentInfos, params: any
|
||||
): void {
|
||||
_fillAuthenticatedParams(initConverseParams, auth, params)
|
||||
_fillLocalProtocols(initConverseParams, params)
|
||||
}
|
||||
@ -106,7 +109,7 @@ function localRoomAuthenticatedParams (initConverseParams: InitConverseParams, a
|
||||
* @param initConverseParams global parameters
|
||||
* @param params ConverseJS parameters to fill
|
||||
*/
|
||||
function localRoomAnonymousParams (initConverseParams: InitConverseParams, params: any): void {
|
||||
function localRoomAnonymousParams (initConverseParams: InitConverseJSParams, params: any): void {
|
||||
params.jid = initConverseParams.localAnonymousJID
|
||||
_fillLocalProtocols(initConverseParams, params)
|
||||
}
|
||||
@ -117,7 +120,10 @@ function localRoomAnonymousParams (initConverseParams: InitConverseParams, param
|
||||
* @param auth authent infos.
|
||||
* @param params ConverseJS parameters to fill
|
||||
*/
|
||||
function remoteRoomAuthenticatedParams (initConverseParams: InitConverseParams, auth: AuthentInfos, params: any): void {
|
||||
function remoteRoomAuthenticatedParams (
|
||||
initConverseParams: InitConverseJSParams,
|
||||
auth: AuthentInfos, params: any
|
||||
): void {
|
||||
_fillAuthenticatedParams(initConverseParams, auth, params)
|
||||
_fillLocalProtocols(initConverseParams, params)
|
||||
}
|
||||
@ -129,7 +135,7 @@ function remoteRoomAuthenticatedParams (initConverseParams: InitConverseParams,
|
||||
* @param params ConverseJS parameters to fill
|
||||
*/
|
||||
function remoteRoomAnonymousParams (
|
||||
initConverseParams: InitConverseParams,
|
||||
initConverseParams: InitConverseJSParams,
|
||||
auth: AuthentInfos | null,
|
||||
params: any
|
||||
): void {
|
||||
@ -140,7 +146,7 @@ function remoteRoomAnonymousParams (
|
||||
_fillRemoteProtocols(initConverseParams, params)
|
||||
}
|
||||
|
||||
function _fillAuthenticatedParams (initConverseParams: InitConverseParams, auth: AuthentInfos, params: any): void {
|
||||
function _fillAuthenticatedParams (initConverseParams: InitConverseJSParams, auth: AuthentInfos, params: any): void {
|
||||
params.authentication = 'login'
|
||||
params.auto_login = true
|
||||
params.jid = auth.jid
|
||||
@ -155,12 +161,12 @@ function _fillAuthenticatedParams (initConverseParams: InitConverseParams, auth:
|
||||
// FIXME: use params.oauth_providers?
|
||||
}
|
||||
|
||||
function _fillLocalProtocols (initConverseParams: InitConverseParams, params: any): void {
|
||||
function _fillLocalProtocols (initConverseParams: InitConverseJSParams, params: any): void {
|
||||
params.bosh_service_url = initConverseParams.localBoshServiceUrl
|
||||
params.websocket_url = initConverseParams.localWebsocketServiceUrl
|
||||
}
|
||||
|
||||
function _fillRemoteProtocols (initConverseParams: InitConverseParams, params: any): void {
|
||||
function _fillRemoteProtocols (initConverseParams: InitConverseJSParams, params: any): void {
|
||||
params.bosh_service_url = initConverseParams.remoteBoshServiceUrl
|
||||
params.websocket_url = initConverseParams.remoteWebsocketServiceUrl
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import type { InitConverseParams } from './types'
|
||||
import type { InitConverseJSParams } from 'shared/lib/types'
|
||||
|
||||
function initDom ({ forceReadonly, transparent }: InitConverseParams, isInIframe: boolean): void {
|
||||
function initDom ({ forceReadonly, transparent }: InitConverseJSParams, isInIframe: boolean): void {
|
||||
const body = document.querySelector('body')
|
||||
if (isInIframe) {
|
||||
if (body) {
|
||||
|
@ -1,23 +0,0 @@
|
||||
interface InitConverseParams {
|
||||
isRemoteChat: boolean
|
||||
localAnonymousJID: string
|
||||
remoteAnonymousJID: string | null
|
||||
remoteAnonymousXMPPServer: boolean
|
||||
remoteAuthenticatedXMPPServer: boolean
|
||||
assetsPath: string
|
||||
room: string
|
||||
localBoshServiceUrl: string | null
|
||||
localWebsocketServiceUrl: string | null
|
||||
remoteBoshServiceUrl: string | null
|
||||
remoteWebsocketServiceUrl: string | null
|
||||
authenticationUrl: string
|
||||
autoViewerMode: boolean
|
||||
forceReadonly: boolean | 'noscroll'
|
||||
noScroll: boolean
|
||||
theme: string
|
||||
transparent: boolean
|
||||
}
|
||||
|
||||
export {
|
||||
InitConverseParams
|
||||
}
|
Reference in New Issue
Block a user