Builtin ConverseJS on external XMPP server: new placeholders for the room name: CHANNEL_ID, CHANNEL_NAME.
This commit is contained in:
parent
98a9515a50
commit
a3579abb81
@ -1,5 +1,11 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## ???
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Builtin ConverseJS on external XMPP server: new placeholders for the room name: CHANNEL_ID, CHANNEL_NAME.
|
||||||
|
|
||||||
## v3.2.0
|
## v3.2.0
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
@ -24,10 +24,18 @@ The ```peertube.im``` is part of the example, you have to replace the entire val
|
|||||||
#### XMPP room template (mandatory)
|
#### XMPP room template (mandatory)
|
||||||
|
|
||||||
The room to join on your XMPP server.
|
The room to join on your XMPP server.
|
||||||
You can have a single room for all webchats, or you can use the placeholder ```{{{VIDEO_UUID}}}``` to insert the video UUID and have a custom room for each video.
|
You can have a single room for all webchats, or you can use any of there placeholders:
|
||||||
|
|
||||||
|
- ```{{{VIDEO_UUID}}}``` to insert the video UUID and have a custom room for each video.
|
||||||
|
- ```{{{CHANNEL_ID}}}``` to insert the channel numerical ID and have a custom room for each channel.
|
||||||
|
- ```{{{CHANNEL_NAME}}}``` to insert the channel name (see the Peertube's documentation for possible characters) and have a custom room for each channel.
|
||||||
|
|
||||||
|
You can mix several placeholder.
|
||||||
|
|
||||||
Example: ```room_{{VIDEO_UUID}}@room.peertube.im.your_domain```
|
Example: ```room_{{VIDEO_UUID}}@room.peertube.im.your_domain```
|
||||||
|
|
||||||
|
NB: when using CHANNEL_ID or CHANNEL_NAME with remote videos, you can have unexpected results. You should consider disabling webchat for remote videos.
|
||||||
|
|
||||||
#### BOSH uri OR Websocket uri
|
#### BOSH uri OR Websocket uri
|
||||||
|
|
||||||
You have to provide at least one of these two settings.
|
You have to provide at least one of these two settings.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "peertube-plugin-livechat",
|
"name": "peertube-plugin-livechat",
|
||||||
"description": "PeerTube plugin livechat",
|
"description": "PeerTube plugin livechat",
|
||||||
"version": "3.2.0",
|
"version": "3.3.0",
|
||||||
"author": "John Livingston",
|
"author": "John Livingston",
|
||||||
"bugs": "https://github.com/JohnXLivingston/peertube-plugin-livechat/issues",
|
"bugs": "https://github.com/JohnXLivingston/peertube-plugin-livechat/issues",
|
||||||
"clientScripts": [
|
"clientScripts": [
|
||||||
|
26
server/lib/database/channel.ts
Normal file
26
server/lib/database/channel.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
async function getChannelNameById (options: RegisterServerOptions, channelId: number): Promise<string | null> {
|
||||||
|
if (!channelId) {
|
||||||
|
throw new Error('Missing channelId')
|
||||||
|
}
|
||||||
|
if (!Number.isInteger(channelId)) {
|
||||||
|
throw new Error('Invalid channelId: not an integer')
|
||||||
|
}
|
||||||
|
const [results] = await options.peertubeHelpers.database.query(
|
||||||
|
'SELECT "actor"."preferredUsername"' +
|
||||||
|
' FROM "videoChannel"' +
|
||||||
|
' RIGHT JOIN "actor" ON "actor"."id" = "videoChannel"."actorId"' +
|
||||||
|
' WHERE "videoChannel"."id" = ' + channelId.toString()
|
||||||
|
)
|
||||||
|
if (!Array.isArray(results)) {
|
||||||
|
throw new Error('getChannelNameById: query result is not an array.')
|
||||||
|
}
|
||||||
|
if (!results[0]) {
|
||||||
|
options.peertubeHelpers.logger.debug(`getChannelNameById: channel ${channelId} not found.`)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return (results[0].preferredUsername ?? null) as string
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
getChannelNameById
|
||||||
|
}
|
@ -32,7 +32,7 @@ export async function diagConverse (test: string, { settingsManager }: RegisterS
|
|||||||
result.messages.push('Missing chat room configuration')
|
result.messages.push('Missing chat room configuration')
|
||||||
isBuiltinError = true
|
isBuiltinError = true
|
||||||
} else if (
|
} else if (
|
||||||
!/^(\w|{{VIDEO_UUID}})+@([a-z0-9.]+)+[a-z0-9]+$/
|
!/^(\w|{{(VIDEO_UUID|CHANNEL_ID|CHANNEL_NAME)}})+@([a-z0-9.]+)+[a-z0-9]+$/
|
||||||
.test(chatRoom)
|
.test(chatRoom)
|
||||||
) {
|
) {
|
||||||
result.messages.push(
|
result.messages.push(
|
||||||
|
@ -5,6 +5,7 @@ import { getBaseRouterRoute, getBaseStaticRoute, isUserAdmin } from '../helpers'
|
|||||||
import { asyncMiddleware } from '../middlewares/async'
|
import { asyncMiddleware } from '../middlewares/async'
|
||||||
import { getProsodyDomain } from '../prosody/config/domain'
|
import { getProsodyDomain } from '../prosody/config/domain'
|
||||||
import { getAPIKey } from '../apikey'
|
import { getAPIKey } from '../apikey'
|
||||||
|
import { getChannelNameById } from '../database/channel'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
const bodyParser = require('body-parser')
|
const bodyParser = require('body-parser')
|
||||||
const got = require('got')
|
const got = require('got')
|
||||||
@ -84,7 +85,22 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise<Route
|
|||||||
const baseStaticUrl = getBaseStaticRoute(options)
|
const baseStaticUrl = getBaseStaticRoute(options)
|
||||||
page = page.replace(/{{BASE_STATIC_URL}}/g, baseStaticUrl)
|
page = page.replace(/{{BASE_STATIC_URL}}/g, baseStaticUrl)
|
||||||
page = page.replace(/{{JID}}/g, server)
|
page = page.replace(/{{JID}}/g, server)
|
||||||
|
// Computing the room name...
|
||||||
room = room.replace(/{{VIDEO_UUID}}/g, video.uuid)
|
room = room.replace(/{{VIDEO_UUID}}/g, video.uuid)
|
||||||
|
room = room.replace(/{{CHANNEL_ID}}/g, `${video.channelId}`)
|
||||||
|
if (room.includes('CHANNEL_NAME')) {
|
||||||
|
const channelName = await getChannelNameById(options, video.channelId)
|
||||||
|
if (channelName === null) {
|
||||||
|
throw new Error('Channel not found')
|
||||||
|
}
|
||||||
|
if (!/^[a-zA-Z0-9_.]+$/.test(channelName)) {
|
||||||
|
// FIXME: see if there is a response here https://github.com/Chocobozzz/PeerTube/issues/4301 for allowed chars
|
||||||
|
peertubeHelpers.logger.error(`Invalid channel name, contains unauthorized chars: '${channelName}'`)
|
||||||
|
throw new Error('Invalid channel name, contains unauthorized chars')
|
||||||
|
}
|
||||||
|
room = room.replace(/{{CHANNEL_NAME}}/g, channelName)
|
||||||
|
}
|
||||||
|
// ... then inject it in the page.
|
||||||
page = page.replace(/{{ROOM}}/g, room)
|
page = page.replace(/{{ROOM}}/g, room)
|
||||||
page = page.replace(/{{BOSH_SERVICE_URL}}/g, boshUri)
|
page = page.replace(/{{BOSH_SERVICE_URL}}/g, boshUri)
|
||||||
page = page.replace(/{{WS_SERVICE_URL}}/g, wsUri)
|
page = page.replace(/{{WS_SERVICE_URL}}/g, wsUri)
|
||||||
|
@ -124,8 +124,13 @@ You can close this port on your firewall, it will not be accessed from the outer
|
|||||||
type: 'input',
|
type: 'input',
|
||||||
default: '',
|
default: '',
|
||||||
descriptionHTML:
|
descriptionHTML:
|
||||||
`Your XMPP room. You can use the placeholder {{VIDEO_UUID}} to add the video UUID.
|
`Your XMPP room. You can use following placeholders to inject video metadata in the room name:
|
||||||
Without this placeholder, all videos will point to the same chat room.<br>
|
<ul>
|
||||||
|
<li>{{VIDEO_UUID}} to add the video UUID.</li>
|
||||||
|
<li>{{CHANNEL_ID}} to add the CHANNEL numerical ID.</li>
|
||||||
|
<li>{{CHANNEL_NAME}} to add the channel name (see the Peertube's documentation for possible characters).</li>
|
||||||
|
</ul>
|
||||||
|
Without any placeholder, all videos will point to the same chat room.<br>
|
||||||
Example: public@room.peertube.im.your_domain<br>
|
Example: public@room.peertube.im.your_domain<br>
|
||||||
Example: public_{{VIDEO_UUID}}@room.peertube.im.your_domain`,
|
Example: public_{{VIDEO_UUID}}@room.peertube.im.your_domain`,
|
||||||
private: true
|
private: true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user