New fullscreen chat WIP:

* Fullscreen chat: now uses a custom page (in other words: when opening the chat in a new tab, you will have the Peertube menu). WIP
* some code refactoring (getBaseRoute moved to util/uri, ...)
This commit is contained in:
John Livingston
2023-12-27 12:48:45 +01:00
parent 17bd8a0716
commit bd695bdb27
10 changed files with 151 additions and 37 deletions

View File

@ -1,6 +1,9 @@
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
import type { InitConverseJSParams } from 'shared/lib/types'
import { renderConfigurationHome } from './templates/home'
import { renderConfigurationChannel } from './templates/channel'
import { getBaseRoute } from '../../utils/uri'
import { loadConverseJS } from '../../utils/conversejs'
/**
* Registers stuff related to the user's configuration pages.
@ -12,6 +15,42 @@ async function registerConfiguration (clientOptions: RegisterClientOptions): Pro
const settings = await peertubeHelpers.getSettings()
if (settings['disable-channel-configuration']) { return }
registerClientRoute({
route: 'livechat/room',
onMount: async ({ rootEl }) => {
try {
const urlParams = new URLSearchParams(window.location.search)
const roomKey = urlParams.get('room')
if (!roomKey) {
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()
await loadConverseJS(converseJSParams)
rootEl.innerHTML = `<div class="converse-fullscreen theme-peertube">
<div id="conversejs-bg" class="theme-peertube">
</div>`
window.initConverse(converseJSParams)
} catch (err) {
console.error('[peertube-plugin-livechat] ' + (err as string))
rootEl.innerText = await peertubeHelpers.translate(LOC_NOT_FOUND)
}
}
})
registerClientRoute({
route: 'livechat/configuration',
onMount: async ({ rootEl }) => {