Room list: using new chat page
This commit is contained in:
parent
624f053d02
commit
e5e6c6f953
@ -160,8 +160,7 @@ function register (clientOptions: RegisterClientOptions): void {
|
|||||||
// Here we have a channel chat room
|
// Here we have a channel chat room
|
||||||
// The backend should have added informations here
|
// The backend should have added informations here
|
||||||
// (because the Peertube API can't work with channelId...)
|
// (because the Peertube API can't work with channelId...)
|
||||||
const href = getBaseRoute(clientOptions) +
|
const href = '/p/livechat/room?room=' + encodeURIComponent(localpart) + '&forcetype=1'
|
||||||
'/webchat/room/' + encodeURIComponent(localpart) + '?forcetype=1'
|
|
||||||
if (room.channel?.name) {
|
if (room.channel?.name) {
|
||||||
aEl.href = href // here we know that the channel still exists, so we can open the webchat.
|
aEl.href = href // here we know that the channel still exists, so we can open the webchat.
|
||||||
const aVideoEl = document.createElement('a')
|
const aVideoEl = document.createElement('a')
|
||||||
@ -176,8 +175,7 @@ function register (clientOptions: RegisterClientOptions): void {
|
|||||||
} else if (/^[a-zA-A0-9-]+$/.test(localpart)) {
|
} else if (/^[a-zA-A0-9-]+$/.test(localpart)) {
|
||||||
// localpart must be a video uuid.
|
// localpart must be a video uuid.
|
||||||
const uuid = localpart
|
const uuid = localpart
|
||||||
const href = getBaseRoute(clientOptions) +
|
const href = '/p/livechat/room?room=' + encodeURIComponent(uuid) + '&forcetype=1'
|
||||||
'/webchat/room/' + encodeURIComponent(uuid) + '?forcetype=1'
|
|
||||||
const p = fetch('/api/v1/videos/' + uuid, {
|
const p = fetch('/api/v1/videos/' + uuid, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: peertubeHelpers.getAuthHeader()
|
headers: peertubeHelpers.getAuthHeader()
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
|
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
|
||||||
import type { RegisterClientFormFieldOptions } from '@peertube/peertube-types'
|
import type { RegisterClientFormFieldOptions } from '@peertube/peertube-types'
|
||||||
import { registerConfiguration } from './common/configuration/register'
|
import { registerConfiguration } from './common/configuration/register'
|
||||||
|
import { registerRoom } from './common/room/register'
|
||||||
|
|
||||||
async function register (clientOptions: RegisterClientOptions): Promise<void> {
|
async function register (clientOptions: RegisterClientOptions): Promise<void> {
|
||||||
const { peertubeHelpers, registerHook, registerVideoField } = clientOptions
|
const { peertubeHelpers, registerHook, registerVideoField } = clientOptions
|
||||||
@ -56,7 +57,10 @@ async function register (clientOptions: RegisterClientOptions): Promise<void> {
|
|||||||
registerVideoField(webchatFieldOptions, { type: 'update' })
|
registerVideoField(webchatFieldOptions, { type: 'update' })
|
||||||
registerVideoField(webchatFieldOptions, { type: 'go-live' })
|
registerVideoField(webchatFieldOptions, { type: 'go-live' })
|
||||||
|
|
||||||
await registerConfiguration(clientOptions)
|
await Promise.all([
|
||||||
|
registerRoom(clientOptions),
|
||||||
|
registerConfiguration(clientOptions)
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
|
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
|
||||||
import { renderConfigurationHome } from './templates/home'
|
import { renderConfigurationHome } from './templates/home'
|
||||||
import { renderConfigurationChannel } from './templates/channel'
|
import { renderConfigurationChannel } from './templates/channel'
|
||||||
import { displayConverseJS } from '../../utils/conversejs'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers stuff related to the user's configuration pages.
|
* Registers stuff related to the user's configuration pages.
|
||||||
@ -13,29 +12,6 @@ async function registerConfiguration (clientOptions: RegisterClientOptions): Pro
|
|||||||
const settings = await peertubeHelpers.getSettings()
|
const settings = await peertubeHelpers.getSettings()
|
||||||
if (settings['disable-channel-configuration']) { return }
|
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 container = document.createElement('div')
|
|
||||||
container.classList.add('livechat-embed-fullpage')
|
|
||||||
rootEl.append(container)
|
|
||||||
|
|
||||||
await displayConverseJS(clientOptions, container, roomKey, 'peertube-fullpage')
|
|
||||||
} catch (err) {
|
|
||||||
console.error('[peertube-plugin-livechat] ' + (err as string))
|
|
||||||
// FIXME: do a better error page.
|
|
||||||
rootEl.innerText = await peertubeHelpers.translate(LOC_NOT_FOUND)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
registerClientRoute({
|
registerClientRoute({
|
||||||
route: 'livechat/configuration',
|
route: 'livechat/configuration',
|
||||||
onMount: async ({ rootEl }) => {
|
onMount: async ({ rootEl }) => {
|
||||||
|
38
client/common/room/register.ts
Normal file
38
client/common/room/register.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
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))
|
||||||
|
// FIXME: do a better error page.
|
||||||
|
rootEl.innerText = await peertubeHelpers.translate(LOC_NOT_FOUND)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
registerRoom
|
||||||
|
}
|
@ -116,12 +116,14 @@ async function loadConverseJS (converseJSParams: InitConverseJSParams): Promise<
|
|||||||
* @param container the dom element where to insert the chat
|
* @param container the dom element where to insert the chat
|
||||||
* @param roomKey the room to join
|
* @param roomKey the room to join
|
||||||
* @param chatIncludeMode the include mode
|
* @param chatIncludeMode the include mode
|
||||||
|
* @param forceType only usable for admins/moderators, to enter rooms that have not the current type (channel/video)
|
||||||
*/
|
*/
|
||||||
async function displayConverseJS (
|
async function displayConverseJS (
|
||||||
clientOptions: RegisterClientOptions,
|
clientOptions: RegisterClientOptions,
|
||||||
container: HTMLElement,
|
container: HTMLElement,
|
||||||
roomKey: string,
|
roomKey: string,
|
||||||
chatIncludeMode: ChatPeertubeIncludeMode
|
chatIncludeMode: ChatPeertubeIncludeMode,
|
||||||
|
forceType: boolean
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const peertubeHelpers = clientOptions.peertubeHelpers
|
const peertubeHelpers = clientOptions.peertubeHelpers
|
||||||
|
|
||||||
@ -139,7 +141,9 @@ async function displayConverseJS (
|
|||||||
const authHeader = peertubeHelpers.getAuthHeader()
|
const authHeader = peertubeHelpers.getAuthHeader()
|
||||||
|
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
getBaseRoute(clientOptions) + '/api/configuration/room/' + encodeURIComponent(roomKey),
|
getBaseRoute(clientOptions) + '/api/configuration/room/' +
|
||||||
|
encodeURIComponent(roomKey) +
|
||||||
|
(forceType ? '?forcetype=1' : ''),
|
||||||
{
|
{
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: peertubeHelpers.getAuthHeader()
|
headers: peertubeHelpers.getAuthHeader()
|
||||||
|
@ -204,7 +204,7 @@ function register (registerOptions: RegisterClientOptions): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Loading converseJS...
|
// Loading converseJS...
|
||||||
await displayConverseJS(registerOptions, container, roomkey, 'peertube-video')
|
await displayConverseJS(registerOptions, container, roomkey, 'peertube-video', false)
|
||||||
|
|
||||||
if (additionalStyles) {
|
if (additionalStyles) {
|
||||||
container.setAttribute('style', additionalStyles)
|
container.setAttribute('style', additionalStyles)
|
||||||
|
@ -18,7 +18,9 @@ async function initConfigurationApiRouter (options: RegisterServerOptions, route
|
|||||||
router.get('/configuration/room/:roomKey', asyncMiddleware(
|
router.get('/configuration/room/:roomKey', asyncMiddleware(
|
||||||
async (req: Request, res: Response, _next: NextFunction): Promise<void> => {
|
async (req: Request, res: Response, _next: NextFunction): Promise<void> => {
|
||||||
const roomKey = req.params.roomKey
|
const roomKey = req.params.roomKey
|
||||||
const initConverseJSParam = await getConverseJSParams(options, roomKey, {})
|
const initConverseJSParam = await getConverseJSParams(options, roomKey, {
|
||||||
|
forcetype: req.query.forcetype === '1'
|
||||||
|
})
|
||||||
if (('isError' in initConverseJSParam) && initConverseJSParam.isError) {
|
if (('isError' in initConverseJSParam) && initConverseJSParam.isError) {
|
||||||
res.sendStatus(initConverseJSParam.code)
|
res.sendStatus(initConverseJSParam.code)
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user