From 7906ddf625e5f6bf4d14461ee2355e0796697c0d Mon Sep 17 00:00:00 2001 From: John Livingston Date: Mon, 10 Oct 2022 18:08:20 +0200 Subject: [PATCH] Prosody mode only: Removing old modes (ConverseJS and External URI). Work in progress. --- CHANGELOG.md | 25 +++++ client/admin-plugin-client-plugin.ts | 51 +-------- client/videowatch-client-plugin.ts | 21 ++-- client/videowatch/share.ts | 2 +- client/videowatch/uri.ts | 33 +----- package-lock.json | 8 +- package.json | 2 +- server/lib/diagnostic/chat-type.ts | 30 ------ server/lib/diagnostic/converse.ts | 77 -------------- server/lib/diagnostic/index.ts | 9 -- server/lib/diagnostic/uri.ts | 17 --- server/lib/diagnostic/utils.ts | 2 +- server/lib/diagnostic/video.ts | 2 +- server/lib/migration/settings.ts | 80 +------------- server/lib/prosody/ctl.ts | 10 +- server/lib/routers/api.ts | 29 ----- server/lib/routers/webchat.ts | 111 +++++++------------ server/lib/settings.ts | 152 ++------------------------- shared/lib/autocolors.ts | 7 +- shared/lib/types.ts | 2 - 20 files changed, 98 insertions(+), 572 deletions(-) delete mode 100644 server/lib/diagnostic/chat-type.ts delete mode 100644 server/lib/diagnostic/converse.ts delete mode 100644 server/lib/diagnostic/uri.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 9856c45d..fa7d5fbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,30 @@ # Changelog +## 6.0.0 (Not Released Yet) + +### Breaking changes + +Following modes are removed: + +* Connect to an existing XMPP server with ConverseJS +* Use an external web chat tool + +The only remaining mode is the recommanded one: «Prosody server controlled by Peertube». + +These modes were here for historical reasons (backward compatibility, etc.). +But they became difficult to maintain, and impossible to document (adding a lot of confusion). + +Moreover, it seems that they weren't really used. + +**Note:** If you were using one of the 2 removed modes, or if you disabled the plugin in the settings, +the server will try to use the new mode after updating the plugin. +If you don't want the chat server to be active, just uninstall the plugin +(settings won't be lost, you just have to download it again). + +### New Features + +* + ## 5.7.1 * Adding an easy way to customize background transparency in OBS and co. diff --git a/client/admin-plugin-client-plugin.ts b/client/admin-plugin-client-plugin.ts index cb9aa4a7..e74cc51d 100644 --- a/client/admin-plugin-client-plugin.ts +++ b/client/admin-plugin-client-plugin.ts @@ -1,6 +1,6 @@ import type { RegisterClientOptions } from '@peertube/peertube-types/client' import type { Video } from '@peertube/peertube-types' -import type { ChatType, ProsodyListRoomsResult } from 'shared/lib/types' +import type { ProsodyListRoomsResult } from 'shared/lib/types' interface ActionPluginSettingsParams { npmName: string @@ -202,56 +202,13 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re isSettingHidden: options => { const name = options.setting.name switch (name) { - case 'chat-type-help-disabled': - return options.formValues['chat-type'] !== ('disabled' as ChatType) - case 'prosody-room-type': - case 'prosody-port': - case 'prosody-peertube-uri': - case 'chat-type-help-builtin-prosody': - case 'prosody-list-rooms': - case 'prosody-advanced': - case 'prosody-muc-log-by-default': - case 'prosody-muc-expiration': - case 'prosody-c2s': - case 'prosody-components': - case 'chat-share-url': - return options.formValues['chat-type'] !== ('builtin-prosody' as ChatType) case 'prosody-c2s-port': - return !( - options.formValues['chat-type'] === ('builtin-prosody' as ChatType) && - options.formValues['prosody-c2s'] === true - ) + return options.formValues['prosody-c2s'] !== true case 'prosody-components-port': case 'prosody-components-list': - return !( - options.formValues['chat-type'] === ('builtin-prosody' as ChatType) && - options.formValues['prosody-components'] === true - ) - case 'chat-server': - case 'chat-room': - case 'chat-bosh-uri': - case 'chat-ws-uri': - case 'chat-type-help-builtin-converse': - return options.formValues['chat-type'] !== ('builtin-converse' as ChatType) - case 'converse-advanced': - case 'converse-theme': - return !( - options.formValues['chat-type'] === ('builtin-converse' as ChatType) || - options.formValues['chat-type'] === ('builtin-prosody' as ChatType) - ) + return options.formValues['prosody-components'] !== true case 'converse-autocolors': - return !( - ( - options.formValues['chat-type'] === ('builtin-converse' as ChatType) || - options.formValues['chat-type'] === ('builtin-prosody' as ChatType) - ) && - options.formValues['converse-theme'] === 'peertube' - ) - case 'chat-uri': - case 'chat-type-help-external-uri': - return options.formValues['chat-type'] !== ('external-uri' as ChatType) - case 'chat-style': - return options.formValues['chat-type'] === 'disabled' + return options.formValues['converse-theme'] !== 'peertube' case 'chat-per-live-video-warning': return !(options.formValues['chat-all-lives'] === true && options.formValues['chat-per-live-video'] === true) } diff --git a/client/videowatch-client-plugin.ts b/client/videowatch-client-plugin.ts index fc7dfb81..69aa6e98 100644 --- a/client/videowatch-client-plugin.ts +++ b/client/videowatch-client-plugin.ts @@ -253,20 +253,15 @@ function register (registerOptions: RegisterClientOptions): void { } let showShareUrlButton: boolean = false - if (settings['chat-type'] === 'builtin-prosody') { - // The share url functionality should be technically possible for other modes - // than builtin-prosody. But it is too difficult to maintain. - // So I choose to enable it only for builtin-prosody. - - const chatShareUrl = settings['chat-share-url'] ?? '' - if (chatShareUrl === 'everyone') { - showShareUrlButton = true - } else if (chatShareUrl === 'owner') { - showShareUrlButton = guessIsMine(registerOptions, video) - } else if (chatShareUrl === 'owner+moderators') { - showShareUrlButton = guessIsMine(registerOptions, video) || guessIamIModerator(registerOptions) - } + const chatShareUrl = settings['chat-share-url'] ?? '' + if (chatShareUrl === 'everyone') { + showShareUrlButton = true + } else if (chatShareUrl === 'owner') { + showShareUrlButton = guessIsMine(registerOptions, video) + } else if (chatShareUrl === 'owner+moderators') { + showShareUrlButton = guessIsMine(registerOptions, video) || guessIamIModerator(registerOptions) } + insertChatDom(container as HTMLElement, video, !!settings['chat-open-blank'], showShareUrlButton).then(() => { if (settings['chat-auto-display']) { openChat(video) diff --git a/client/videowatch/share.ts b/client/videowatch/share.ts index cdd12e25..d6e1b251 100644 --- a/client/videowatch/share.ts +++ b/client/videowatch/share.ts @@ -106,7 +106,7 @@ async function shareChatUrl (registerOptions: RegisterClientOptions, settings: a readonlyOptions.append(transparentLabelEl) let autoColors - if (isAutoColorsAvailable(settings['chat-type'], settings['converse-theme'])) { + if (isAutoColorsAvailable(settings['converse-theme'])) { const label = document.createElement('label') label.innerText = labelAutocolors autoColors = document.createElement('input') diff --git a/client/videowatch/uri.ts b/client/videowatch/uri.ts index ed32d6e2..29b404ae 100644 --- a/client/videowatch/uri.ts +++ b/client/videowatch/uri.ts @@ -1,6 +1,5 @@ import type { RegisterClientOptions } from '@peertube/peertube-types/client' import type { Video } from '@peertube/peertube-types' -import type { ChatType } from 'shared/lib/types' import { AutoColors, isAutoColorsAvailable } from 'shared/lib/autocolors' import { logger } from './logger' import { computeAutoColors } from './colors' @@ -32,41 +31,15 @@ function getIframeUri ( logger.error('Settings are not initialized, too soon to compute the iframeUri') return null } - let iframeUriStr = '' - const chatType: ChatType = (settings['chat-type'] ?? 'disabled') as ChatType - if (chatType === 'builtin-prosody' || chatType === 'builtin-converse') { - // Using the builtin converseJS - iframeUriStr = getBaseRoute(registerOptions, uriOptions.permanent) - iframeUriStr += '/webchat/room/' + encodeURIComponent(video.uuid) - } else if (chatType === 'external-uri') { - iframeUriStr = settings['chat-uri'] || '' - iframeUriStr = iframeUriStr.replace(/{{VIDEO_UUID}}/g, encodeURIComponent(video.uuid)) - if (iframeUriStr.includes('{{CHANNEL_ID}}')) { - if (!video.channel || !video.channel.id) { - logger.error('Missing channel info in video object.') - return null - } - iframeUriStr = iframeUriStr.replace(/{{CHANNEL_ID}}/g, encodeURIComponent(video.channel.id)) - } - if (!/^https?:\/\//.test(iframeUriStr)) { - logger.error('The webchaturi must begin with https://') - return null - } - } else { - logger.error('Chat disabled.') - return null - } - if (iframeUriStr === '') { - logger.error('No iframe uri') - return null - } + let iframeUriStr = getBaseRoute(registerOptions, uriOptions.permanent) + iframeUriStr += '/webchat/room/' + encodeURIComponent(video.uuid) const iFrameUri = new URL(iframeUriStr, window.location.origin) if ( !uriOptions.ignoreAutoColors && settings['converse-autocolors'] && - isAutoColorsAvailable(settings['chat-type'] as ChatType, settings['converse-theme']) + isAutoColorsAvailable(settings['converse-theme']) ) { logger.info('We have to try to compute autocolors.') try { diff --git a/package-lock.json b/package-lock.json index 612c19de..d2f373ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "peertube-plugin-livechat", "version": "5.7.1", "license": "AGPL-3.0", "dependencies": { @@ -46,6 +47,9 @@ "typescript": "^4.3.5", "webpack": "^4.46.0", "webpack-cli": "^3.3.12" + }, + "engines": { + "npm": ">=7 <8" } }, "node_modules/@aws-crypto/crc32": { @@ -3712,7 +3716,6 @@ "dependencies": { "anymatch": "~3.1.2", "braces": "~3.0.2", - "fsevents": "~2.3.2", "glob-parent": "~5.1.2", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", @@ -12189,8 +12192,7 @@ "dependencies": { "chokidar": "^3.4.1", "graceful-fs": "^4.1.2", - "neo-async": "^2.5.0", - "watchpack-chokidar2": "^2.0.1" + "neo-async": "^2.5.0" }, "optionalDependencies": { "watchpack-chokidar2": "^2.0.1" diff --git a/package.json b/package.json index e0b4d461..66dd329e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "peertube-plugin-livechat", "description": "PeerTube plugin livechat: offers a way to embed a chat system into Peertube.", - "version": "5.7.1", + "version": "6.0.0", "license": "AGPL-3.0", "author": { "name": "John Livingston", diff --git a/server/lib/diagnostic/chat-type.ts b/server/lib/diagnostic/chat-type.ts deleted file mode 100644 index 75a99b9c..00000000 --- a/server/lib/diagnostic/chat-type.ts +++ /dev/null @@ -1,30 +0,0 @@ -import type { RegisterServerOptions } from '@peertube/peertube-types' -import { newResult, TestResult } from './utils' -import type { ChatType } from '../../../shared/lib/types' - -export async function diagChatType (test: string, { settingsManager }: RegisterServerOptions): Promise { - const result = newResult(test) - const typeSettings = await settingsManager.getSettings([ - 'chat-type' - ]) - result.label = 'Webchat type' - const chatType: ChatType = (typeSettings['chat-type'] ?? 'disabled') as ChatType - if (chatType === 'builtin-prosody') { - result.messages.push('Using builtin Prosody') - result.ok = true - result.next = 'prosody' - } else if (chatType === 'builtin-converse') { - result.messages.push('Using builtin ConverseJS to connect to an external XMPP server') - result.ok = true - result.next = 'converse' - } else if (chatType === 'external-uri') { - result.messages.push('Using an external uri') - result.ok = true - result.next = 'use-uri' - } else if (chatType === 'disabled') { - result.messages.push('Webchat disabled') - } else { - result.messages.push('Unknown chat type value: ' + (chatType as string)) - } - return result -} diff --git a/server/lib/diagnostic/converse.ts b/server/lib/diagnostic/converse.ts deleted file mode 100644 index 509546df..00000000 --- a/server/lib/diagnostic/converse.ts +++ /dev/null @@ -1,77 +0,0 @@ -import type { RegisterServerOptions } from '@peertube/peertube-types' -import { newResult, TestResult } from './utils' - -export async function diagConverse (test: string, { settingsManager }: RegisterServerOptions): Promise { - const result = newResult(test) - result.label = 'Builtin ConverseJS on XMPP service' - const builtinSettings = await settingsManager.getSettings([ - 'chat-server', - 'chat-room', - 'chat-bosh-uri', - 'chat-ws-uri' - ]) - - let isBuiltinError = false - - const chatServer: string = (builtinSettings['chat-server'] as string) || '' - if (chatServer === '') { - result.messages.push('Missing chat server configuration') - isBuiltinError = true - } else if (!/^([a-z0-9.]+)+[a-z0-9]+$/.test(chatServer)) { - result.messages.push( - 'Invalid value for the webchat server: "' + - chatServer + - '"' - ) - isBuiltinError = true - } else { - result.messages.push('Chat server is correct') - } - - const chatRoom: string = (builtinSettings['chat-room'] as string) || '' - if (chatRoom === '') { - result.messages.push('Missing chat room configuration') - isBuiltinError = true - } else if ( - !/^(\w|{{(VIDEO_UUID|CHANNEL_ID|CHANNEL_NAME)}})+@([a-z0-9.]+)+[a-z0-9]+$/ - .test(chatRoom) - ) { - result.messages.push( - 'Invalid value for the webchat room: "' + - chatRoom + - '"' - ) - isBuiltinError = true - } else { - result.messages.push('Chat room is correct and will be: ' + chatRoom) - } - - const chatBoshUri: string = (builtinSettings['chat-bosh-uri'] as string) || '' - const chatWsUri: string = (builtinSettings['chat-ws-uri'] as string) || '' - if (chatBoshUri === '' && chatWsUri === '') { - result.messages.push('Missing BOSH or Websocket uri') - isBuiltinError = true - } - if (chatBoshUri !== '') { - if (!/^https?:\/\//.test(chatBoshUri)) { - result.messages.push('Invalid BOSH Uri, should begin with https://') - isBuiltinError = true - } else { - result.messages.push('Valid Bosh Uri') - } - } - if (chatWsUri !== '') { - if (!/^wss?:\/\//.test(chatWsUri)) { - result.messages.push('Invalid Websocket Uri, should begin with wss://') - isBuiltinError = true - } else { - result.messages.push('Valid Websocket Uri') - } - } - - if (!isBuiltinError) { - result.messages.push('Builtin converse is correctly configured') - result.ok = true - } - return result -} diff --git a/server/lib/diagnostic/index.ts b/server/lib/diagnostic/index.ts index c5708a64..60fe3bf1 100644 --- a/server/lib/diagnostic/index.ts +++ b/server/lib/diagnostic/index.ts @@ -1,10 +1,7 @@ import type { RegisterServerOptions } from '@peertube/peertube-types' import { diagBackend } from './backend' -import { diagConverse } from './converse' -import { diagChatType } from './chat-type' import { TestResult, newResult } from './utils' import { diagProsody } from './prosody' -import { diagUri } from './uri' import { diagVideo } from './video' export async function diag (test: string, options: RegisterServerOptions): Promise { @@ -14,14 +11,8 @@ export async function diag (test: string, options: RegisterServerOptions): Promi result = await diagBackend(test, options) } else if (test === 'webchat-video') { result = await diagVideo(test, options) - } else if (test === 'webchat-type') { - result = await diagChatType(test, options) } else if (test === 'prosody') { result = await diagProsody(test, options) - } else if (test === 'converse') { - result = await diagConverse(test, options) - } else if (test === 'use-uri') { - result = await diagUri(test, options) } else { result = newResult(test) result.messages.push('Unknown test') diff --git a/server/lib/diagnostic/uri.ts b/server/lib/diagnostic/uri.ts deleted file mode 100644 index 744f2ecc..00000000 --- a/server/lib/diagnostic/uri.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { RegisterServerOptions } from '@peertube/peertube-types' -import { newResult, TestResult } from './utils' - -export async function diagUri (test: string, { settingsManager }: RegisterServerOptions): Promise { - const result = newResult(test) - result.label = 'External Webchat using an iframe' - const settings = await settingsManager.getSettings([ - 'chat-uri' - ]) - if (/^https:\/\//.test(settings['chat-uri'] as string)) { - result.ok = true - result.messages.push('Chat url will be: ' + (settings['chat-uri'] as string)) - } else { - result.messages.push('Incorrect value for the uri (it does not start with https://)') - } - return result -} diff --git a/server/lib/diagnostic/utils.ts b/server/lib/diagnostic/utils.ts index a8d7a350..105de414 100644 --- a/server/lib/diagnostic/utils.ts +++ b/server/lib/diagnostic/utils.ts @@ -1,4 +1,4 @@ -type nextValue = 'backend' | 'webchat-video' | 'webchat-type' | 'prosody' | 'converse' | 'use-uri' +type nextValue = 'backend' | 'webchat-video' | 'prosody' interface MessageWithLevel { level: 'info' | 'warning' | 'error' diff --git a/server/lib/diagnostic/video.ts b/server/lib/diagnostic/video.ts index 249b7ed6..9c591470 100644 --- a/server/lib/diagnostic/video.ts +++ b/server/lib/diagnostic/video.ts @@ -46,7 +46,7 @@ export async function diagVideo (test: string, { settingsManager }: RegisterServ } if (atLeastOne) { result.ok = true - result.next = 'webchat-type' + result.next = 'prosody' } else { result.ok = false result.messages.push('Chat is activate for no video.') diff --git a/server/lib/migration/settings.ts b/server/lib/migration/settings.ts index ad9cbbd5..5c5d7a6c 100644 --- a/server/lib/migration/settings.ts +++ b/server/lib/migration/settings.ts @@ -1,87 +1,9 @@ import type { RegisterServerOptions } from '@peertube/peertube-types' -import { pluginShortName } from '../helpers' -import type { ChatType } from '../../../shared/lib/types' - -async function _migrateChatTypeSetting (options: RegisterServerOptions): Promise { - const peertubeHelpers = options.peertubeHelpers - const logger = peertubeHelpers.logger - // Previous to plugin v3.0.0, there was multiple checkbox and input-text for settings the plugin mode. - // With Peertube v2.3.0, we can replace all these settings with a single select. - // This function migrates old values if needed. - // NB: we cant use safely settingsManager.getSetting, because settings are not registered yet. - logger.info('Checking if we need to migrate chat-type') - if (!/^[-a-z]+$/.test(pluginShortName)) { - // to prevent sql injection... be sure there is no special char here. - throw new Error(`Wrong pluginShortName '${pluginShortName}'`) - } - const [results] = await peertubeHelpers.database.query( - 'SELECT "settings" FROM "plugin"' + - ' WHERE "plugin"."name" = :pluginShortName', - { - replacements: { - pluginShortName - } - } - ) - if (!Array.isArray(results)) { - throw new Error('_migrateChatTypeSetting: query result is not an array.') - } - if (results.length === 0) { - logger.error('Plugin not found in database') - return - } - if (results.length > 1) { - logger.error('Multiple lines for plugin in database, dont know which one to migrate... Aborting.') - return - } - const settings = results[0].settings - if (!settings) { - logger.info('Plugin settings are empty in database, no migration needed.') - return - } - if (typeof settings !== 'object') { - logger.error('Plugin settings in database seems to be invalid json') - return - } - if ('chat-type' in settings) { - logger.info('The setting chat-type is already here, no need to migrate.') - return - } - - logger.info('The setting chat-type is not here, checking if we have to migrate from previous settings...') - let chatType: ChatType | undefined - if (settings['chat-use-prosody'] === true) { - chatType = 'builtin-prosody' - } else if (settings['chat-use-builtin'] === true) { - chatType = 'builtin-converse' - } else if (((settings['chat-uri'] || '') as string) !== '') { - chatType = 'external-uri' - } else { - logger.info('It seems there was no previous active chat configuration.') - return - } - - logger.info(`We have to set chat-type to value '${chatType}'.`) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - await peertubeHelpers.database.query( - 'UPDATE "plugin" ' + - ' SET "settings" = "settings" || :value ' + - ' WHERE "name" = :pluginShortName', - { - replacements: { - pluginShortName, - value: JSON.stringify({ - 'chat-type': chatType - }) - } - } - ) -} async function migrateSettings (options: RegisterServerOptions): Promise { const logger = options.peertubeHelpers.logger logger.info('Checking if there is a migration script to launch...') - await _migrateChatTypeSetting(options) + // 2022-10-10: as we removed the «chat-type» settings, there is no migration needed for now. } export { diff --git a/server/lib/prosody/ctl.ts b/server/lib/prosody/ctl.ts index a5b6ee99..7fc109a6 100644 --- a/server/lib/prosody/ctl.ts +++ b/server/lib/prosody/ctl.ts @@ -2,7 +2,6 @@ import type { RegisterServerOptions } from '@peertube/peertube-types' import { getProsodyConfig, getProsodyFilePaths, writeProsodyConfig } from './config' import { startProsodyLogRotate, stopProsodyLogRotate } from './logrotate' import { changeHttpBindRoute } from '../routers/webchat' -import type { ChatType } from '../../../shared/lib/types' import * as fs from 'fs' import * as child_process from 'child_process' @@ -139,17 +138,10 @@ async function testProsodyCorrectlyRunning (options: RegisterServerOptions): Pro } async function ensureProsodyRunning (options: RegisterServerOptions): Promise { - const { peertubeHelpers, settingsManager } = options + const { peertubeHelpers } = options const logger = peertubeHelpers.logger logger.debug('Calling ensureProsodyRunning') - logger.debug('Checking if prosody should be active') - const setting = await settingsManager.getSetting('chat-type') - if (setting !== ('builtin-prosody' as ChatType)) { - logger.info('Chat type is not set to builtin-prosody, we wont launch it') - return - } - const r = await testProsodyCorrectlyRunning(options) if (r.ok) { r.messages.forEach(m => logger.debug(m)) diff --git a/server/lib/routers/api.ts b/server/lib/routers/api.ts index e113d3ad..4937e883 100644 --- a/server/lib/routers/api.ts +++ b/server/lib/routers/api.ts @@ -7,7 +7,6 @@ import { prosodyCheckUserPassword, prosodyRegisterUser, prosodyUserRegistered } import { getUserNickname } from '../helpers' import { Affiliations, getVideoAffiliations, getChannelAffiliations } from '../prosody/config/affiliations' import { getProsodyDomain } from '../prosody/config/domain' -import type { ChatType } from '../../../shared/lib/types' import { fillVideoCustomFields } from '../custom-fields' import { getChannelInfosById } from '../database/channel' @@ -51,14 +50,8 @@ async function initApiRouter (options: RegisterServerOptions): Promise { logger.info(`Requesting room information for room '${jid}'.`) const settings = await options.settingsManager.getSettings([ - 'chat-type', 'prosody-room-type' ]) - if (settings['chat-type'] !== ('builtin-prosody' as ChatType)) { - logger.warn('Prosody chat is not active') - res.sendStatus(403) - return - } // Now, we have two different room type: per video or per channel. if (settings['prosody-room-type'] === 'channel') { const matches = jid.match(/^channel\.(\d+)$/) @@ -106,17 +99,11 @@ async function initApiRouter (options: RegisterServerOptions): Promise { // check settings (chat enabled for this video?) const settings = await options.settingsManager.getSettings([ - 'chat-type', 'chat-per-live-video', 'chat-all-lives', 'chat-all-non-lives', 'chat-videos-list' ]) - if (settings['chat-type'] !== ('builtin-prosody' as ChatType)) { - logger.warn('Prosody chat is not active') - res.sendStatus(403) - return - } if (!videoHasWebchat({ 'chat-per-live-video': !!settings['chat-per-live-video'], 'chat-all-lives': !!settings['chat-all-lives'], @@ -186,14 +173,6 @@ async function initApiRouter (options: RegisterServerOptions): Promise { router.get('/user/check_password', asyncMiddleware( async (req: Request, res: Response, _next: NextFunction) => { - const settings = await options.settingsManager.getSettings([ - 'chat-type' - ]) - if (settings['chat-type'] !== ('builtin-prosody' as ChatType)) { - logger.warn('Prosody chat is not active') - res.status(200).send('false') - return - } const prosodyDomain = await getProsodyDomain(options) const user = req.query.user const server = req.query.server @@ -213,14 +192,6 @@ async function initApiRouter (options: RegisterServerOptions): Promise { router.get('/user/user_exists', asyncMiddleware( async (req: Request, res: Response, _next: NextFunction) => { - const settings = await options.settingsManager.getSettings([ - 'chat-type' - ]) - if (settings['chat-type'] !== ('builtin-prosody' as ChatType)) { - logger.warn('Prosody chat is not active') - res.status(200).send('false') - return - } const prosodyDomain = await getProsodyDomain(options) const user = req.query.user const server = req.query.server diff --git a/server/lib/routers/webchat.ts b/server/lib/routers/webchat.ts index 7553486b..23363b52 100644 --- a/server/lib/routers/webchat.ts +++ b/server/lib/routers/webchat.ts @@ -2,7 +2,7 @@ import type { RegisterServerOptions, MVideoThumbnail } from '@peertube/peertube- import type { Router, RequestHandler, Request, Response, NextFunction } from 'express' import type { ProxyOptions } from 'express-http-proxy' import type { - ChatType, ProsodyListRoomsResult, ProsodyListRoomsResultRoom + ProsodyListRoomsResult, ProsodyListRoomsResultRoom } from '../../../shared/lib/types' import { getBaseRouterRoute, getBaseStaticRoute, isUserAdmin } from '../helpers' import { asyncMiddleware } from '../middlewares/async' @@ -41,17 +41,11 @@ async function initWebchatRouter (options: RegisterServerOptions): PromiseChat mode' }) registerSetting({ - name: 'chat-type', - label: 'Chat mode', - type: 'select', - default: 'disabled' as ChatType, - private: false, - options: [ - { value: 'disabled', label: 'Disabled' }, - { value: 'builtin-prosody', label: 'Prosody server controlled by Peertube (recommended)' }, - { value: 'builtin-converse', label: 'Connect to an existing XMPP server with ConverseJS' }, - { value: 'external-uri', label: 'Use an external web chat tool' } - ] as Array<{value: ChatType, label: string}>, - descriptionHTML: 'Please choose the webchat mode you want to use.' - }) - - registerSetting({ - name: 'chat-type-help-disabled', + name: 'chat-help-builtin-prosody', type: 'html', - descriptionHTML: 'The chat is disabled.', - private: true - }) - registerSetting({ - name: 'chat-type-help-builtin-prosody', - type: 'html', - label: 'Prosody server controlled by Peertube (recommended)', - descriptionHTML: `With this mode, the Peertube server will control a local Prosody XMPP server.
-Note: you have to install the Prosody XMPP server. + label: 'Prosody server', + descriptionHTML: `This plugin uses the Prosody XMPP server to handle chat rooms.
+The Peertube server will control this Prosody server.
+Important Note: you have to install Prosody on your server. Please read the documentation.`, private: true }) - registerSetting({ - name: 'chat-type-help-builtin-converse', - type: 'html', - label: 'Connect to an existing XMPP server with ConverseJS', - descriptionHTML: -`
- This mode is deprecated and will be removed in version 6.0.0. - More information in the - - CHANGELOG - . -
-With this mode, you can connect to an existing XMPP server, that allow anonymous authentication and room creation. -Please read the -documentation.`, - private: true - }) - registerSetting({ - name: 'chat-type-help-external-uri', - type: 'html', - label: 'Use an external webchat', - descriptionHTML: -`
-This mode is deprecated and will be removed in version 6.0.0. -More information in the - - CHANGELOG -. -
-With this mode, you can use any external web chat that can be included in an iframe. -Please read the -documentation.`, - private: true - }) registerSetting({ name: 'prosody-list-rooms', @@ -140,70 +80,6 @@ Change it if this port is already in use on your server.
You can close this port on your firewall, it will not be accessed from the outer world.` }) - registerSetting({ - name: 'chat-server', - label: 'XMPP service server', - type: 'input', - default: '', - descriptionHTML: 'Your XMPP server. Without any scheme. Example : peertube.im.your_domain.', - private: true - }) - registerSetting({ - name: 'chat-room', - label: 'XMPP room template', - type: 'input', - default: '', - descriptionHTML: -`Your XMPP room. You can use following placeholders to inject video metadata in the room name: -
    -
  • {{VIDEO_UUID}} to add the video UUID.
  • -
  • {{CHANNEL_ID}} to add the CHANNEL numerical ID.
  • -
  • {{CHANNEL_NAME}} to add the channel name (see the Peertube's documentation for possible characters).
  • -
-Without any placeholder, all videos will point to the same chat room.
-Example: public@room.peertube.im.your_domain
-Example: public_{{VIDEO_UUID}}@room.peertube.im.your_domain`, - private: true - }) - registerSetting({ - name: 'chat-bosh-uri', - label: 'BOSH uri', - type: 'input', - default: '', - descriptionHTML: -`URI of the external BOSH server. -Please make sure it accept cross origin request from your domain.
-You must at least have a BOSH or a Websocket uri.`, - private: true - }) - registerSetting({ - name: 'chat-ws-uri', - label: 'Websocket uri', - type: 'input', - default: '', - descriptionHTML: ` -URI of the external WS server. -Please make sure it accept cross origin request from your domain.
-You must at least have a BOSH or a Websocket uri.`, - private: true - }) - - registerSetting({ - name: 'chat-uri', - label: 'Webchat url', - type: 'input', - default: '', - descriptionHTML: -`Put here your webchat url. An iframe will be created pointing to this url. -You can use following placeholders to inject video metadata in the url: -
    -
  • {{VIDEO_UUID}} to add the video UUID.
  • -
  • {{CHANNEL_ID}} to add the CHANNEL numerical ID.
  • -
-Example : https://my_domain/conversejs.html?room=video_{{VIDEO_UUID}}.`, - private: false - }) - // ********** Chat behaviour registerSetting({ type: 'html', @@ -467,17 +343,9 @@ You can keep this port closed on your firewall for now, it will not be accessed }) // ********** settings changes management - settingsManager.onSettingsChange(async (settings: any) => { - if ('chat-type' in settings) { - const chatType: ChatType = settings['chat-type'] ?? 'disabled' - if (chatType === 'builtin-prosody') { - peertubeHelpers.logger.info('Saving settings, ensuring prosody is running') - await ensureProsodyRunning(options) - } else { - peertubeHelpers.logger.info('Saving settings, ensuring prosody is not running') - await ensureProsodyNotRunning(options) - } - } + settingsManager.onSettingsChange(async (_settings: any) => { + peertubeHelpers.logger.info('Saving settings, ensuring prosody is running') + await ensureProsodyRunning(options) }) } diff --git a/shared/lib/autocolors.ts b/shared/lib/autocolors.ts index b3dc5afb..45976d03 100644 --- a/shared/lib/autocolors.ts +++ b/shared/lib/autocolors.ts @@ -1,4 +1,3 @@ -import type { ChatType } from './types' const validateColor = require('validate-color').default type AutoColorValue = string @@ -19,14 +18,10 @@ interface AutoColors { } /** - * @param chatType value of the settings 'chat-type' * @param theme value of the settings 'converse-theme' * @returns true if the theme can use autocolors */ -function isAutoColorsAvailable (chatType: ChatType, theme: string): boolean { - if (chatType !== 'builtin-prosody' && chatType !== 'builtin-converse') { - return false - } +function isAutoColorsAvailable (theme: string): boolean { return theme === 'peertube' // currently the only theme that can handle autocolors. } diff --git a/shared/lib/types.ts b/shared/lib/types.ts index a1c08b4e..43ef5551 100644 --- a/shared/lib/types.ts +++ b/shared/lib/types.ts @@ -1,4 +1,3 @@ -type ChatType = 'disabled' | 'builtin-prosody' | 'builtin-converse' | 'external-uri' type ConverseJSTheme = 'peertube' | 'default' | 'concord' interface ProsodyListRoomsResultError { @@ -28,7 +27,6 @@ interface ProsodyListRoomsResultSuccess { type ProsodyListRoomsResult = ProsodyListRoomsResultError | ProsodyListRoomsResultSuccess export { - ChatType, ConverseJSTheme, ProsodyListRoomsResult, ProsodyListRoomsResultRoom