43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
|
|
import { displayConverseJS } from '../../utils/conversejs'
|
|
|
|
/**
|
|
* Registers stuff related to "room" page.
|
|
* @param clientOptions Peertube client options
|
|
*/
|
|
async function registerRoom (clientOptions: RegisterClientOptions): Promise<void> {
|
|
const { peertubeHelpers, registerClientRoute } = clientOptions
|
|
|
|
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 forceType = urlParams.get('forcetype') === '1'
|
|
|
|
const container = document.createElement('div')
|
|
container.classList.add('livechat-embed-fullpage')
|
|
rootEl.append(container)
|
|
|
|
await displayConverseJS(clientOptions, container, roomKey, 'peertube-fullpage', forceType)
|
|
} catch (err) {
|
|
console.error('[peertube-plugin-livechat] ' + (err as string))
|
|
// Displaying an error page.
|
|
rootEl.innerHTML = ''
|
|
const message = document.createElement('div')
|
|
message.classList.add('peertube-plugin-livechat-error-message')
|
|
message.innerText = await peertubeHelpers.translate(LOC_CHATROOM_NOT_ACCESSIBLE)
|
|
rootEl.append(message)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
export {
|
|
registerRoom
|
|
}
|