2022-01-11 00:29:33 +00:00
|
|
|
import type { RegisterServerOptions } from '@peertube/peertube-types'
|
2022-10-10 16:08:20 +00:00
|
|
|
import { ensureProsodyRunning } from './prosody/ctl'
|
|
|
|
import type { ConverseJSTheme } from '../../shared/lib/types'
|
2023-02-15 10:54:48 +00:00
|
|
|
import { existsSync, promises as fsPromises } from 'fs'
|
|
|
|
import { resolve } from 'path'
|
2021-06-02 17:16:27 +00:00
|
|
|
|
2023-02-15 10:54:48 +00:00
|
|
|
const locContent: Map<string, string> = new Map<string, string>()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Currently, the Peertube plugin system assumes that settings strings
|
|
|
|
* are localized in english, and will be translated on front-end.
|
|
|
|
* This system make it hard to have complex strings (with html, newlines, ...).
|
|
|
|
* See https://github.com/Chocobozzz/PeerTube/issues/4523
|
|
|
|
*
|
|
|
|
* Waiting for a better solution, we implemented a custom solution:
|
|
|
|
* - We are using keys to identify setting strings
|
|
|
|
* - the `loc` function gets the english segment for the key
|
|
|
|
* - the build-languages.js script builds all needed files.
|
|
|
|
* @param key The key to translate
|
|
|
|
*/
|
|
|
|
function loc (key: string): string {
|
|
|
|
return locContent.get(key) ?? key
|
|
|
|
}
|
|
|
|
|
|
|
|
async function loadLoc (): Promise<void> {
|
|
|
|
const filePath = resolve(__dirname, '..', '..', 'languages', 'settings.reference.json')
|
|
|
|
if (!existsSync(filePath)) {
|
|
|
|
throw new Error(`File ${filePath} missing, can't load plugin settings`)
|
|
|
|
}
|
|
|
|
const content = await fsPromises.readFile(filePath, 'utf8')
|
|
|
|
const json = JSON.parse(content ?? '{}')
|
|
|
|
if (typeof json !== 'object') {
|
|
|
|
throw new Error(`File ${filePath} invalid, can't load plugin settings`)
|
|
|
|
}
|
|
|
|
for (const k in json) {
|
|
|
|
const v = json[k]
|
|
|
|
if (typeof v === 'string') {
|
|
|
|
locContent.set(k, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function initSettings (options: RegisterServerOptions): Promise<void> {
|
2021-04-13 15:13:41 +00:00
|
|
|
const { peertubeHelpers, registerSetting, settingsManager } = options
|
2021-04-08 00:43:13 +00:00
|
|
|
|
2023-02-15 10:54:48 +00:00
|
|
|
await loadLoc()
|
|
|
|
|
2021-06-03 10:20:19 +00:00
|
|
|
// ********** IMPORTANT NOTES
|
2021-04-12 14:31:48 +00:00
|
|
|
registerSetting({
|
2021-06-03 10:20:19 +00:00
|
|
|
type: 'html',
|
|
|
|
private: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('important_note_title')
|
2021-06-03 10:20:19 +00:00
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
type: 'html',
|
|
|
|
private: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('important_note_text')
|
2021-06-03 10:20:19 +00:00
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
type: 'html',
|
|
|
|
private: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('diagnostic')
|
2021-04-12 14:31:48 +00:00
|
|
|
})
|
2021-06-03 10:20:19 +00:00
|
|
|
|
2022-12-12 18:17:43 +00:00
|
|
|
if (process.arch !== 'x64' && process.arch !== 'x86_64') {
|
|
|
|
registerSetting({
|
|
|
|
name: 'prosody-arch-warning',
|
|
|
|
type: 'html',
|
|
|
|
private: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
// Note: the following text as a variable in it.
|
|
|
|
// Not translating it: it should be very rare.
|
2022-12-12 18:17:43 +00:00
|
|
|
descriptionHTML: `<span class="peertube-plugin-livechat-warning">
|
|
|
|
It seems that your are using a ${process.arch} CPU,
|
|
|
|
which is not compatible with the plugin.
|
2023-02-13 17:03:23 +00:00
|
|
|
Please read
|
2022-12-12 18:17:43 +00:00
|
|
|
<a
|
2023-02-13 17:03:23 +00:00
|
|
|
href="https://johnxlivingston.github.io/peertube-plugin-livechat/fr/documentation/installation/cpu_compatibility/"
|
2022-12-12 18:17:43 +00:00
|
|
|
target="_blank"
|
|
|
|
>
|
2023-02-13 17:03:23 +00:00
|
|
|
this page
|
2022-12-12 18:17:43 +00:00
|
|
|
</a> for a workaround.
|
|
|
|
</span>`
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-11-15 16:19:49 +00:00
|
|
|
// ********** Chat
|
2021-06-03 10:20:19 +00:00
|
|
|
registerSetting({
|
|
|
|
type: 'html',
|
|
|
|
private: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('chat_title')
|
2021-06-03 10:20:19 +00:00
|
|
|
})
|
2021-06-11 23:16:57 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'prosody-list-rooms',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('list_rooms_label'),
|
2021-06-11 23:16:57 +00:00
|
|
|
type: 'html',
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('list_rooms_description'),
|
2021-06-11 23:16:57 +00:00
|
|
|
private: true
|
|
|
|
})
|
2021-08-05 13:41:49 +00:00
|
|
|
|
2022-11-15 16:19:49 +00:00
|
|
|
// ********** Chat behaviour
|
|
|
|
registerSetting({
|
|
|
|
type: 'html',
|
|
|
|
private: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('chat_behaviour_description')
|
2022-11-15 16:19:49 +00:00
|
|
|
})
|
2021-08-05 13:41:49 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'prosody-room-type',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('room_type_label'),
|
2021-08-05 13:41:49 +00:00
|
|
|
type: 'select',
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('room_type_description'),
|
2021-08-05 13:41:49 +00:00
|
|
|
private: false,
|
|
|
|
default: 'video',
|
|
|
|
options: [
|
2023-02-15 10:54:48 +00:00
|
|
|
{ value: 'video', label: loc('room_type_option_video') },
|
|
|
|
{ value: 'channel', label: loc('room_type_option_channel') }
|
2021-08-05 13:41:49 +00:00
|
|
|
]
|
|
|
|
})
|
2021-06-03 10:24:09 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'chat-auto-display',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('auto_display_label'),
|
|
|
|
descriptionHTML: loc('auto_display_description'),
|
2021-06-03 10:24:09 +00:00
|
|
|
type: 'input-checkbox',
|
|
|
|
default: true,
|
|
|
|
private: false
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-open-blank',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('open_blank_label'),
|
|
|
|
descriptionHTML: loc('open_blank_description'),
|
2021-06-03 10:24:09 +00:00
|
|
|
private: false,
|
|
|
|
type: 'input-checkbox',
|
|
|
|
default: true
|
|
|
|
})
|
2022-11-15 16:19:49 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'chat-share-url',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('share_url_label'),
|
|
|
|
descriptionHTML: loc('share_url_description'),
|
2022-11-15 16:19:49 +00:00
|
|
|
private: false,
|
|
|
|
type: 'select',
|
|
|
|
default: 'owner',
|
|
|
|
options: [
|
2023-02-15 10:54:48 +00:00
|
|
|
{ value: 'nobody', label: loc('share_url_option_nobody') },
|
|
|
|
{ value: 'everyone', label: loc('share_url_option_everyone') },
|
|
|
|
{ value: 'owner', label: loc('share_url_option_owner') },
|
|
|
|
{ value: 'owner+moderators', label: loc('share_url_option_owner_moderators') }
|
2022-11-15 16:19:49 +00:00
|
|
|
]
|
|
|
|
})
|
2021-06-08 16:08:58 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'chat-per-live-video',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('per_live_video_label'),
|
2021-06-08 16:08:58 +00:00
|
|
|
type: 'input-checkbox',
|
|
|
|
default: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('per_live_video_description'),
|
2021-06-08 16:08:58 +00:00
|
|
|
private: false
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-per-live-video-warning',
|
|
|
|
type: 'html',
|
|
|
|
private: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('per_live_video_warning_description')
|
2021-06-03 10:24:09 +00:00
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-all-lives',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('all_lives_label'),
|
2021-06-03 10:24:09 +00:00
|
|
|
type: 'input-checkbox',
|
2021-06-08 16:08:58 +00:00
|
|
|
default: false,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('all_lives_description'),
|
2021-06-03 10:24:09 +00:00
|
|
|
private: false
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-all-non-lives',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('all_non_lives_label'),
|
2021-06-03 10:24:09 +00:00
|
|
|
type: 'input-checkbox',
|
|
|
|
default: false,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('all_non_lives_description'),
|
2021-06-03 10:24:09 +00:00
|
|
|
private: false
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-videos-list',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('videos_list_label'),
|
2021-06-03 10:24:09 +00:00
|
|
|
type: 'input-textarea',
|
|
|
|
default: '',
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('videos_list_description'),
|
2021-06-03 10:24:09 +00:00
|
|
|
private: false
|
|
|
|
})
|
2022-04-11 16:12:12 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'chat-no-anonymous',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('no_anonymous_label'),
|
2022-04-11 16:12:12 +00:00
|
|
|
type: 'input-checkbox',
|
|
|
|
default: false,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('no_anonymous_description'),
|
2022-04-11 16:12:12 +00:00
|
|
|
private: false
|
|
|
|
})
|
2021-06-03 10:24:09 +00:00
|
|
|
|
2022-11-15 16:19:49 +00:00
|
|
|
// ********** Theming
|
2021-04-08 00:43:13 +00:00
|
|
|
registerSetting({
|
2022-11-15 16:19:49 +00:00
|
|
|
name: 'theming-advanced',
|
2021-11-18 10:08:12 +00:00
|
|
|
type: 'html',
|
|
|
|
private: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('theming_advanced_description')
|
2021-11-18 10:08:12 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
registerSetting({
|
|
|
|
name: 'converse-theme',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('converse_theme_label'),
|
2021-11-18 10:08:12 +00:00
|
|
|
type: 'select',
|
|
|
|
default: 'peertube' as ConverseJSTheme,
|
2021-11-19 15:45:10 +00:00
|
|
|
private: false,
|
2021-11-18 10:08:12 +00:00
|
|
|
options: [
|
2023-02-15 10:54:48 +00:00
|
|
|
{ value: 'peertube', label: loc('peertube') },
|
|
|
|
{ value: 'default', label: loc('default') },
|
|
|
|
{ value: 'concord', label: loc('concord') }
|
2021-11-18 10:08:12 +00:00
|
|
|
] as Array<{value: ConverseJSTheme, label: string}>,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('converse_theme_description')
|
2021-11-18 10:08:12 +00:00
|
|
|
})
|
|
|
|
|
2021-11-19 15:45:10 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'converse-autocolors',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('autocolors_label'),
|
2021-11-19 15:45:10 +00:00
|
|
|
type: 'input-checkbox',
|
|
|
|
default: true,
|
|
|
|
private: false,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('autocolors_description')
|
2021-11-19 15:45:10 +00:00
|
|
|
})
|
|
|
|
|
2022-11-15 16:19:49 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'chat-style',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('chat_style_label'),
|
2022-11-15 16:19:49 +00:00
|
|
|
type: 'input-textarea',
|
|
|
|
default: '',
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('chat_style_description'),
|
2022-11-15 16:19:49 +00:00
|
|
|
private: false
|
|
|
|
})
|
|
|
|
|
|
|
|
// ********** Chat server advanced settings
|
2021-07-13 15:40:29 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'prosody-advanced',
|
|
|
|
type: 'html',
|
|
|
|
private: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('prosody_advanced_description')
|
2021-07-13 15:40:29 +00:00
|
|
|
})
|
|
|
|
|
2021-12-21 18:54:37 +00:00
|
|
|
registerSetting({
|
2022-11-15 16:19:49 +00:00
|
|
|
name: 'chat-help-builtin-prosody',
|
|
|
|
type: 'html',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('help_builtin_prosody_label'),
|
|
|
|
descriptionHTML: loc('help_builtin_prosody_description'),
|
2022-11-15 16:19:49 +00:00
|
|
|
private: true
|
|
|
|
})
|
|
|
|
|
|
|
|
registerSetting({
|
|
|
|
name: 'use-system-prosody',
|
|
|
|
type: 'input-checkbox',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('system_prosody_label'),
|
|
|
|
descriptionHTML: loc('system_prosody_description'),
|
2022-11-15 16:19:49 +00:00
|
|
|
private: true,
|
|
|
|
default: false
|
2021-12-21 18:54:37 +00:00
|
|
|
})
|
2022-11-15 16:19:49 +00:00
|
|
|
|
2022-12-08 10:25:57 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'disable-websocket',
|
|
|
|
type: 'input-checkbox',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('disable_websocket_label'),
|
|
|
|
descriptionHTML: loc('disable_websocket_description'),
|
2022-12-08 10:25:57 +00:00
|
|
|
private: true,
|
|
|
|
default: false
|
|
|
|
})
|
|
|
|
|
2022-11-15 16:19:49 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'prosody-port',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('prosody_port_label'),
|
2022-11-15 16:19:49 +00:00
|
|
|
type: 'input',
|
|
|
|
default: '52800',
|
|
|
|
private: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('prosody_port_description')
|
2022-11-15 16:19:49 +00:00
|
|
|
})
|
|
|
|
|
2021-07-14 17:22:25 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'prosody-peertube-uri',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('prosody_peertube_uri_label'),
|
2021-07-14 17:22:25 +00:00
|
|
|
type: 'input',
|
|
|
|
default: '',
|
|
|
|
private: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('prosody_peertube_uri_description')
|
2021-07-14 17:22:25 +00:00
|
|
|
})
|
|
|
|
|
2021-12-01 11:57:15 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'prosody-muc-log-by-default',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('prosody_muc_log_by_default_label'),
|
2021-12-01 11:57:15 +00:00
|
|
|
type: 'input-checkbox',
|
|
|
|
default: true,
|
|
|
|
private: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('prosody_muc_log_by_default_description')
|
2021-12-01 11:57:15 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
registerSetting({
|
|
|
|
name: 'prosody-muc-expiration',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('prosody_muc_expiration_label'),
|
2021-12-01 11:57:15 +00:00
|
|
|
type: 'input',
|
|
|
|
default: '1w',
|
|
|
|
private: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('prosody_muc_expiration_description')
|
2021-12-01 11:57:15 +00:00
|
|
|
})
|
|
|
|
|
2021-07-13 15:40:29 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'prosody-c2s',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('prosody_c2s_label'),
|
2021-07-13 15:40:29 +00:00
|
|
|
type: 'input-checkbox',
|
|
|
|
default: false,
|
|
|
|
private: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('prosody_c2s_description')
|
2021-07-13 15:40:29 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
registerSetting({
|
|
|
|
name: 'prosody-c2s-port',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('prosody_c2s_port_label'),
|
2021-07-13 15:40:29 +00:00
|
|
|
type: 'input',
|
|
|
|
default: '52822',
|
|
|
|
private: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('prosody_c2s_port_description')
|
2021-12-11 18:09:01 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
registerSetting({
|
|
|
|
name: 'prosody-components',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('prosody_components_label'),
|
2021-12-11 18:09:01 +00:00
|
|
|
type: 'input-checkbox',
|
|
|
|
default: false,
|
|
|
|
private: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('prosody_components_description')
|
2021-12-11 18:09:01 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
registerSetting({
|
|
|
|
name: 'prosody-components-port',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('prosody_components_port_label'),
|
2021-12-11 18:09:01 +00:00
|
|
|
type: 'input',
|
|
|
|
default: '53470',
|
|
|
|
private: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('prosody_components_port_description')
|
2021-12-11 18:09:01 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
registerSetting({
|
|
|
|
name: 'prosody-components-list',
|
2023-02-15 10:54:48 +00:00
|
|
|
label: loc('prosody_components_list_label'),
|
2021-12-11 18:09:01 +00:00
|
|
|
type: 'input-textarea',
|
|
|
|
default: '',
|
|
|
|
private: true,
|
2023-02-15 10:54:48 +00:00
|
|
|
descriptionHTML: loc('prosody_components_list_description')
|
2021-07-13 15:40:29 +00:00
|
|
|
})
|
|
|
|
|
2021-06-03 10:24:09 +00:00
|
|
|
// ********** settings changes management
|
2022-10-10 16:08:20 +00:00
|
|
|
settingsManager.onSettingsChange(async (_settings: any) => {
|
|
|
|
peertubeHelpers.logger.info('Saving settings, ensuring prosody is running')
|
|
|
|
await ensureProsodyRunning(options)
|
2021-04-13 15:13:41 +00:00
|
|
|
})
|
2021-04-08 00:43:13 +00:00
|
|
|
}
|
2021-06-02 17:16:27 +00:00
|
|
|
|
|
|
|
export {
|
|
|
|
initSettings
|
|
|
|
}
|