diff --git a/client/videowatch-client-plugin.ts b/client/videowatch-client-plugin.ts index 87e83352..6e6df72a 100644 --- a/client/videowatch-client-plugin.ts +++ b/client/videowatch-client-plugin.ts @@ -41,14 +41,7 @@ function register ({ registerHook, peertubeHelpers }: RegisterOptions): void { return null } let iframeUri = '' - if (!settings['chat-use-builtin']) { - iframeUri = settings['chat-uri'] || '' - iframeUri = iframeUri.replace(/{{VIDEO_UUID}}/g, uuid) - if (!/^https?:\/\//.test(iframeUri)) { - logger.error('The webchaturi must begin with https://') - return null - } - } else { + if (settings['chat-use-prosody'] || settings['chat-use-builtin']) { // Using the builtin converseJS // FIXME: with Peertube 3.0.1 there is no loadByIdOrUUID method, // we need to pass the complete url. @@ -57,6 +50,16 @@ function register ({ registerHook, peertubeHelpers }: RegisterOptions): void { const url: string = video.originInstanceUrl + '/videos/watch/' + uuid iframeUri = getBaseRoute() + '/webchat?url=' + encodeURIComponent(url) } + } else if (!settings['chat-use-builtin']) { + iframeUri = settings['chat-uri'] || '' + iframeUri = iframeUri.replace(/{{VIDEO_UUID}}/g, uuid) + if (!/^https?:\/\//.test(iframeUri)) { + logger.error('The webchaturi must begin with https://') + return null + } + } else { + logger.error('Dont known which url use for the iframe.') + return null } if (iframeUri === '') { logger.error('No iframe uri') diff --git a/server/lib/routers/webchat.ts b/server/lib/routers/webchat.ts index e7a9ed62..edb3e4da 100644 --- a/server/lib/routers/webchat.ts +++ b/server/lib/routers/webchat.ts @@ -1,4 +1,5 @@ import type { Router, Request, Response, NextFunction } from 'express' +import { getBaseRouter } from '../helpers' import * as path from 'path' const fs = require('fs').promises @@ -13,22 +14,36 @@ async function initWebchatRouter ({ router.get('/', async (req: Request, res: Response, next: NextFunction) => { try { const settings = await settingsManager.getSettings([ - 'chat-use-builtin', 'chat-room', 'chat-server', + 'chat-use-prosody', 'chat-use-builtin', 'chat-room', 'chat-server', 'chat-bosh-uri', 'chat-ws-uri' ]) - if (!settings['chat-use-builtin']) { + let server: string + let room: string + let boshUri: string + let wsUri: string + if (settings['chat-use-prosody']) { + server = 'localhost' + room = '{{VIDEO_UUID}}@room.localhost' + boshUri = getBaseRouter() + 'http-bind' + wsUri = '' + } else if (settings['chat-use-builtin']) { + if (!settings['chat-server']) { + throw new Error('Missing chat-server settings.') + } + if (!settings['chat-room']) { + throw new Error('Missing chat-room settings.') + } + if (!settings['chat-bosh-uri'] && !settings['chat-ws-uri']) { + throw new Error('Missing BOSH or Websocket uri.') + } + server = settings['chat-server'] as string + room = settings['chat-room'] as string + boshUri = settings['chat-bosh-uri'] as string + wsUri = settings['chat-ws-uri'] as string + } else { throw new Error('Builtin chat disabled.') } - if (!settings['chat-server']) { - throw new Error('Missing chat-server settings.') - } - if (!settings['chat-room']) { - throw new Error('Missing chat-room settings.') - } - if (!settings['chat-bosh-uri'] && !settings['chat-ws-uri']) { - throw new Error('Missing BOSH or Websocket uri.') - } // FIXME: with Peertube 3.0.1 the following method is not available... // When loadByIdOrUUID is available, change the entry point to @@ -54,11 +69,11 @@ async function initWebchatRouter ({ // FIXME: Peertube should provide the static folder path. For now: const staticRelative = '../static' page = page.replace(/{{BASE_STATIC_URL}}/g, staticRelative) - page = page.replace(/{{JID}}/g, settings['chat-server'] as string) - const room = (settings['chat-room'] as string).replace(/{{VIDEO_UUID}}/g, video.uuid) + page = page.replace(/{{JID}}/g, server) + room = room.replace(/{{VIDEO_UUID}}/g, video.uuid) page = page.replace(/{{ROOM}}/g, room) - page = page.replace(/{{BOSH_SERVICE_URL}}/g, settings['chat-bosh-uri'] as string) - page = page.replace(/{{WS_SERVICE_URL}}/g, settings['chat-ws-uri'] as string) + page = page.replace(/{{BOSH_SERVICE_URL}}/g, boshUri) + page = page.replace(/{{WS_SERVICE_URL}}/g, wsUri) res.status(200) res.type('html')