Reconnect livechat in embedded mode.
This commit is contained in:
parent
1ba1e08d69
commit
ba52d4e3d8
@ -25,19 +25,6 @@ async function registerConfiguration (clientOptions: RegisterClientOptions): Pro
|
|||||||
throw new Error('missing room parameter')
|
throw new Error('missing room parameter')
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(
|
|
||||||
getBaseRoute(clientOptions) + '/api/configuration/room/' + encodeURIComponent(roomKey),
|
|
||||||
{
|
|
||||||
method: 'GET',
|
|
||||||
headers: peertubeHelpers.getAuthHeader()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Can\'t get channel configuration options.')
|
|
||||||
}
|
|
||||||
|
|
||||||
const converseJSParams: InitConverseJSParams = await (response).json()
|
|
||||||
|
|
||||||
const container = document.createElement('div')
|
const container = document.createElement('div')
|
||||||
container.classList.add('livechat-embed-fullpage')
|
container.classList.add('livechat-embed-fullpage')
|
||||||
rootEl.append(container)
|
rootEl.append(container)
|
||||||
@ -55,10 +42,23 @@ async function registerConfiguration (clientOptions: RegisterClientOptions): Pro
|
|||||||
|
|
||||||
const authHeader = peertubeHelpers.getAuthHeader()
|
const authHeader = peertubeHelpers.getAuthHeader()
|
||||||
|
|
||||||
|
const response = await fetch(
|
||||||
|
getBaseRoute(clientOptions) + '/api/configuration/room/' + encodeURIComponent(roomKey),
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
headers: peertubeHelpers.getAuthHeader()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Can\'t get channel configuration options.')
|
||||||
|
}
|
||||||
|
const converseJSParams: InitConverseJSParams = await (response).json()
|
||||||
|
|
||||||
await loadConverseJS(converseJSParams)
|
await loadConverseJS(converseJSParams)
|
||||||
window.initConverse(converseJSParams, 'peertube-fullpage', authHeader ?? null)
|
window.initConverse(converseJSParams, 'peertube-fullpage', authHeader ?? null)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[peertube-plugin-livechat] ' + (err as string))
|
console.error('[peertube-plugin-livechat] ' + (err as string))
|
||||||
|
// FIXME: do a better error page.
|
||||||
rootEl.innerText = await peertubeHelpers.translate(LOC_NOT_FOUND)
|
rootEl.innerText = await peertubeHelpers.translate(LOC_NOT_FOUND)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ declare global {
|
|||||||
}
|
}
|
||||||
initConversePlugins: typeof initConversePlugins
|
initConversePlugins: typeof initConversePlugins
|
||||||
initConverse: typeof initConverse
|
initConverse: typeof initConverse
|
||||||
|
reconnectConverse?: (room: string) => void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +143,11 @@ async function initConverse (
|
|||||||
params.blacklisted_plugins.push('livechatViewerModePlugin')
|
params.blacklisted_plugins.push('livechatViewerModePlugin')
|
||||||
}
|
}
|
||||||
|
|
||||||
converse.initialize(params)
|
if (window.reconnectConverse) { // this is set in the livechatSpecificsPlugin
|
||||||
|
window.reconnectConverse(params)
|
||||||
|
} else {
|
||||||
|
converse.initialize(params)
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed initializing converseJS', error)
|
console.error('Failed initializing converseJS', error)
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,32 @@ export const livechatSpecificsPlugin = {
|
|||||||
window.converse.livechatDisconnect = undefined // will be set again on next initialize.
|
window.converse.livechatDisconnect = undefined // will be set again on next initialize.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// To reconnect ConverseJS when joining another room (or the same one),
|
||||||
|
// we store the relevant closure function:
|
||||||
|
window.reconnectConverse = function reconnectConverse (params: any): void {
|
||||||
|
console.log('[livechatSpecificsPlugin] reconnecting converseJS...')
|
||||||
|
|
||||||
|
// The new room to join:
|
||||||
|
_converse.api.settings.set('auto_join_rooms', params.auto_join_rooms)
|
||||||
|
_converse.api.settings.set('notify_all_room_messages', params.notify_all_room_messages)
|
||||||
|
|
||||||
|
// update connection parameters (in case the user logged in after the first chat)
|
||||||
|
for (const k of [
|
||||||
|
'bosh_service_url', 'websocket_url',
|
||||||
|
'authentication', 'nickname', 'muc_nickname_from_jid', 'auto_login', 'jid', 'password', 'keepalive'
|
||||||
|
]) {
|
||||||
|
_converse.api.settings.set(k, params[k])
|
||||||
|
}
|
||||||
|
|
||||||
|
// update other settings
|
||||||
|
for (const k of ['hide_muc_participants', 'blacklisted_plugins']) {
|
||||||
|
_converse.api.settings.set(k, params[k])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then login.
|
||||||
|
_converse.api.user.login()
|
||||||
|
}
|
||||||
|
|
||||||
if (window.location.protocol === 'http:') {
|
if (window.location.protocol === 'http:') {
|
||||||
// We are probably on a dev instance, so we will add _converse in window:
|
// We are probably on a dev instance, so we will add _converse in window:
|
||||||
(window as any)._livechatConverse = _converse
|
(window as any)._livechatConverse = _converse
|
||||||
|
Loading…
Reference in New Issue
Block a user