Using builtin prosody when enabled.
This commit is contained in:
parent
d536625f7b
commit
817cf28e2a
@ -41,14 +41,7 @@ function register ({ registerHook, peertubeHelpers }: RegisterOptions): void {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
let iframeUri = ''
|
let iframeUri = ''
|
||||||
if (!settings['chat-use-builtin']) {
|
if (settings['chat-use-prosody'] || 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 {
|
|
||||||
// Using the builtin converseJS
|
// Using the builtin converseJS
|
||||||
// FIXME: with Peertube 3.0.1 there is no loadByIdOrUUID method,
|
// FIXME: with Peertube 3.0.1 there is no loadByIdOrUUID method,
|
||||||
// we need to pass the complete url.
|
// 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
|
const url: string = video.originInstanceUrl + '/videos/watch/' + uuid
|
||||||
iframeUri = getBaseRoute() + '/webchat?url=' + encodeURIComponent(url)
|
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 === '') {
|
if (iframeUri === '') {
|
||||||
logger.error('No iframe uri')
|
logger.error('No iframe uri')
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import type { Router, Request, Response, NextFunction } from 'express'
|
import type { Router, Request, Response, NextFunction } from 'express'
|
||||||
|
import { getBaseRouter } from '../helpers'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
const fs = require('fs').promises
|
const fs = require('fs').promises
|
||||||
|
|
||||||
@ -13,22 +14,36 @@ async function initWebchatRouter ({
|
|||||||
router.get('/', async (req: Request, res: Response, next: NextFunction) => {
|
router.get('/', async (req: Request, res: Response, next: NextFunction) => {
|
||||||
try {
|
try {
|
||||||
const settings = await settingsManager.getSettings([
|
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'
|
'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.')
|
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...
|
// FIXME: with Peertube 3.0.1 the following method is not available...
|
||||||
// When loadByIdOrUUID is available, change the entry point to
|
// 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:
|
// FIXME: Peertube should provide the static folder path. For now:
|
||||||
const staticRelative = '../static'
|
const staticRelative = '../static'
|
||||||
page = page.replace(/{{BASE_STATIC_URL}}/g, staticRelative)
|
page = page.replace(/{{BASE_STATIC_URL}}/g, staticRelative)
|
||||||
page = page.replace(/{{JID}}/g, settings['chat-server'] as string)
|
page = page.replace(/{{JID}}/g, server)
|
||||||
const room = (settings['chat-room'] as string).replace(/{{VIDEO_UUID}}/g, video.uuid)
|
room = room.replace(/{{VIDEO_UUID}}/g, video.uuid)
|
||||||
page = page.replace(/{{ROOM}}/g, room)
|
page = page.replace(/{{ROOM}}/g, room)
|
||||||
page = page.replace(/{{BOSH_SERVICE_URL}}/g, settings['chat-bosh-uri'] as string)
|
page = page.replace(/{{BOSH_SERVICE_URL}}/g, boshUri)
|
||||||
page = page.replace(/{{WS_SERVICE_URL}}/g, settings['chat-ws-uri'] as string)
|
page = page.replace(/{{WS_SERVICE_URL}}/g, wsUri)
|
||||||
|
|
||||||
res.status(200)
|
res.status(200)
|
||||||
res.type('html')
|
res.type('html')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user