2021-04-13 15:13:41 +00:00
|
|
|
import { ensureProsodyRunning, ensureProsodyNotRunning } from './prosody/ctl'
|
2021-06-02 17:54:04 +00:00
|
|
|
import type { ChatType } from '../../shared/lib/types'
|
2021-06-02 17:16:27 +00:00
|
|
|
|
|
|
|
function initSettings (options: RegisterServerOptions): void {
|
2021-04-13 15:13:41 +00:00
|
|
|
const { peertubeHelpers, registerSetting, settingsManager } = options
|
2021-04-08 00:43:13 +00:00
|
|
|
|
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,
|
|
|
|
descriptionHTML: '<h3>Important notes</h3>'
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
type: 'html',
|
|
|
|
private: true,
|
|
|
|
descriptionHTML: `Please read the
|
2021-04-16 15:55:48 +00:00
|
|
|
<a href="https://github.com/JohnXLivingston/peertube-plugin-livechat/blob/main/README.md" target="_blank">
|
|
|
|
documentation
|
2021-06-11 12:30:46 +00:00
|
|
|
</a> first.`
|
2021-06-03 10:20:19 +00:00
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
type: 'html',
|
|
|
|
private: true,
|
|
|
|
descriptionHTML: `Before asking for help, please use the diagnostic tool:
|
2021-06-11 12:30:46 +00:00
|
|
|
<a class="peertube-plugin-livechat-launch-diagnostic">Launch diagnostic</a>`
|
2021-04-12 14:31:48 +00:00
|
|
|
})
|
2021-06-03 10:20:19 +00:00
|
|
|
|
|
|
|
// ********** Chat Mode
|
|
|
|
registerSetting({
|
|
|
|
type: 'html',
|
|
|
|
private: true,
|
|
|
|
descriptionHTML: '<h3>Chat mode</h3>'
|
|
|
|
})
|
2021-06-02 17:54:04 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'chat-type',
|
2021-06-11 12:45:18 +00:00
|
|
|
label: 'Chat mode',
|
2021-06-02 17:54:04 +00:00
|
|
|
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' },
|
2021-06-11 12:45:18 +00:00
|
|
|
{ value: 'external-uri', label: 'Use an external web chat tool' }
|
2021-06-02 17:54:04 +00:00
|
|
|
] as Array<{value: ChatType, label: string}>,
|
|
|
|
descriptionHTML: 'Please choose the webchat mode you want to use.'
|
|
|
|
})
|
|
|
|
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-type-help-disabled',
|
|
|
|
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)',
|
2021-06-11 12:45:18 +00:00
|
|
|
descriptionHTML: `With this mode, the Peertube server will control a local Prosody XMPP server.<br>
|
|
|
|
Note: you have to install the Prosody XMPP server.
|
|
|
|
Please read the <a
|
|
|
|
href="https://github.com/JohnXLivingston/peertube-plugin-livechat/blob/main/documentation/prosody.md"
|
|
|
|
target="_blank"
|
|
|
|
>documentation</a>.`,
|
2021-06-02 17:54:04 +00:00
|
|
|
private: true
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-type-help-builtin-converse',
|
|
|
|
type: 'html',
|
|
|
|
label: 'Connect to an existing XMPP server with ConverseJS',
|
2021-06-11 12:45:18 +00:00
|
|
|
descriptionHTML:
|
|
|
|
`With this mode, you can connect to an existing XMPP server, that allow anonymous authentication and room creation.
|
|
|
|
Please read the
|
|
|
|
<a
|
|
|
|
href="https://github.com/JohnXLivingston/peertube-plugin-livechat/blob/main/documentation/conversejs.md"
|
|
|
|
target="_blank"
|
|
|
|
>documentation</a>.`,
|
2021-06-02 17:54:04 +00:00
|
|
|
private: true
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-type-help-external-uri',
|
|
|
|
type: 'html',
|
|
|
|
label: 'Use an external webchat',
|
2021-06-11 12:45:18 +00:00
|
|
|
descriptionHTML:
|
|
|
|
`With this mode, you can use any external web chat that can be included in an iframe.
|
|
|
|
Please read the
|
|
|
|
<a
|
|
|
|
href="https://github.com/JohnXLivingston/peertube-plugin-livechat/blob/main/documentation/external.md"
|
|
|
|
target="_blank"
|
|
|
|
>documentation</a>.`,
|
2021-06-02 17:54:04 +00:00
|
|
|
private: true
|
|
|
|
})
|
|
|
|
|
2021-04-16 13:13:46 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'prosody-port',
|
2021-06-03 09:46:11 +00:00
|
|
|
label: 'Prosody port',
|
2021-04-16 13:13:46 +00:00
|
|
|
type: 'input',
|
|
|
|
default: '52800',
|
|
|
|
private: true,
|
2021-06-11 12:45:18 +00:00
|
|
|
descriptionHTML:
|
|
|
|
`The port that will be used by the builtin Prosody server.<br>
|
|
|
|
Change it if this port is already in use on your server.<br>
|
|
|
|
You can close this port on your firewall, it will not be accessed from the outer world.`
|
2021-04-16 13:13:46 +00:00
|
|
|
})
|
|
|
|
|
2021-04-08 00:43:13 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'chat-server',
|
2021-06-03 09:46:11 +00:00
|
|
|
label: 'XMPP service server',
|
2021-04-08 00:43:13 +00:00
|
|
|
type: 'input',
|
|
|
|
default: '',
|
2021-06-03 09:46:11 +00:00
|
|
|
descriptionHTML: 'Your XMPP server. Without any scheme. Example : peertube.im.your_domain.',
|
2021-04-08 00:43:13 +00:00
|
|
|
private: true
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-room',
|
2021-06-03 09:46:11 +00:00
|
|
|
label: 'XMPP room template',
|
2021-04-08 00:43:13 +00:00
|
|
|
type: 'input',
|
|
|
|
default: '',
|
2021-06-11 12:45:18 +00:00
|
|
|
descriptionHTML:
|
|
|
|
`Your XMPP room. You can use the placeholder {{VIDEO_UUID}} to add the video UUID.
|
|
|
|
Without this placeholder, all videos will point to the same chat room.<br>
|
|
|
|
Example: public@room.peertube.im.your_domain<br>
|
|
|
|
Example: public_{{VIDEO_UUID}}@room.peertube.im.your_domain`,
|
2021-04-08 00:43:13 +00:00
|
|
|
private: true
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-bosh-uri',
|
2021-06-03 09:46:11 +00:00
|
|
|
label: 'BOSH uri',
|
2021-04-08 00:43:13 +00:00
|
|
|
type: 'input',
|
|
|
|
default: '',
|
2021-06-11 12:45:18 +00:00
|
|
|
descriptionHTML:
|
|
|
|
`URI of the external BOSH server.
|
|
|
|
Please make sure it accept cross origin request from your domain.<br>
|
|
|
|
You must at least have a BOSH or a Websocket uri.`,
|
2021-04-08 00:43:13 +00:00
|
|
|
private: true
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-ws-uri',
|
2021-06-03 09:46:11 +00:00
|
|
|
label: 'Websocket uri',
|
2021-04-08 00:43:13 +00:00
|
|
|
type: 'input',
|
|
|
|
default: '',
|
2021-06-11 12:45:18 +00:00
|
|
|
descriptionHTML: `
|
|
|
|
URI of the external WS server.
|
|
|
|
Please make sure it accept cross origin request from your domain.<br>
|
|
|
|
You must at least have a BOSH or a Websocket uri.`,
|
2021-04-08 00:43:13 +00:00
|
|
|
private: true
|
|
|
|
})
|
|
|
|
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-uri',
|
|
|
|
label: 'Webchat url',
|
|
|
|
type: 'input',
|
|
|
|
default: '',
|
2021-06-11 12:45:18 +00:00
|
|
|
descriptionHTML:
|
|
|
|
`Put here your webchat url. An iframe will be created pointing to this url.
|
|
|
|
The placeholder {{VIDEO_UUID}} will be replace by the video UUID if present.
|
|
|
|
Example : https://my_domain/conversejs.html?room=video_{{VIDEO_UUID}}.<br>
|
|
|
|
If this field is empty, it will use the builtin ConverseJS webchat.`,
|
2021-04-08 00:43:13 +00:00
|
|
|
private: false
|
|
|
|
})
|
|
|
|
|
2021-06-03 10:24:09 +00:00
|
|
|
// ********** Chat behaviour
|
|
|
|
registerSetting({
|
|
|
|
type: 'html',
|
|
|
|
private: true,
|
|
|
|
descriptionHTML: '<h3>Chat behaviour</h3>'
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-auto-display',
|
|
|
|
label: 'Automatically open the chat',
|
|
|
|
descriptionHTML: 'When watching a video, the chatbox will automatically open',
|
|
|
|
type: 'input-checkbox',
|
|
|
|
default: true,
|
|
|
|
private: false
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-open-blank',
|
|
|
|
label: 'Show the «open in new window» button',
|
2021-06-11 12:45:18 +00:00
|
|
|
descriptionHTML: 'There will be a button for opening the web chat in a new window.',
|
2021-06-03 10:24:09 +00:00
|
|
|
private: false,
|
|
|
|
type: 'input-checkbox',
|
|
|
|
default: true
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-only-locals',
|
|
|
|
label: 'Chats are only available for local videos.',
|
|
|
|
descriptionHTML: 'If you uncheck this settings, the chat will also be enabled on remote videos.',
|
|
|
|
type: 'input-checkbox',
|
|
|
|
default: true,
|
|
|
|
private: false
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-only-locals-warning',
|
|
|
|
type: 'html',
|
|
|
|
private: true,
|
2021-06-11 12:45:18 +00:00
|
|
|
descriptionHTML:
|
|
|
|
`<span class="peertube-plugin-livechat-warning">
|
2021-06-03 10:24:09 +00:00
|
|
|
The plugin is not compatible with video federation yet.
|
|
|
|
The webchat will only be accessible for people watching videos on your server.
|
2021-06-08 16:08:58 +00:00
|
|
|
</span>`
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-per-live-video',
|
|
|
|
label: 'Users can activate the chat for their lives',
|
|
|
|
type: 'input-checkbox',
|
|
|
|
default: true,
|
2021-06-11 12:45:18 +00:00
|
|
|
descriptionHTML: 'If checked, all live videos will have a checkbox in their properties for enabling the web chat.',
|
2021-06-08 16:08:58 +00:00
|
|
|
private: false
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-per-live-video-warning',
|
|
|
|
type: 'html',
|
|
|
|
private: true,
|
2021-06-11 12:45:18 +00:00
|
|
|
descriptionHTML:
|
|
|
|
`<span class="peertube-plugin-livechat-warning">
|
2021-06-08 16:08:58 +00:00
|
|
|
You have enabled the setting «Users can activate the chat for their lives».
|
|
|
|
It is redundant with the «Activate chat for all lives» setting.
|
2021-06-03 10:24:09 +00:00
|
|
|
</span>`
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-all-lives',
|
|
|
|
label: 'Activate chat for all lives',
|
|
|
|
type: 'input-checkbox',
|
2021-06-08 16:08:58 +00:00
|
|
|
default: false,
|
2021-06-03 10:24:09 +00:00
|
|
|
descriptionHTML: 'If checked, the chat will be enabled for all lives.',
|
|
|
|
private: false
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-all-non-lives',
|
|
|
|
label: 'Activate chat for all non-lives',
|
|
|
|
type: 'input-checkbox',
|
|
|
|
default: false,
|
|
|
|
descriptionHTML: 'If checked, the chat will be enable for all video that are not lives.',
|
|
|
|
private: false
|
|
|
|
})
|
|
|
|
registerSetting({
|
|
|
|
name: 'chat-videos-list',
|
2021-06-11 12:45:18 +00:00
|
|
|
label: 'Activate chat for these videos',
|
2021-06-03 10:24:09 +00:00
|
|
|
type: 'input-textarea',
|
|
|
|
default: '',
|
2021-06-11 12:45:18 +00:00
|
|
|
descriptionHTML:
|
|
|
|
`Videos UUIDs for which we want a web chat.
|
|
|
|
Can be non-live videos. One per line. <br />
|
|
|
|
You can add comments: everything after the # character will be stripped off, and empty lines ignored.<br />
|
|
|
|
Don't add private videos, the UUIDs will be send to frontend.`,
|
2021-06-03 10:24:09 +00:00
|
|
|
private: false
|
|
|
|
})
|
|
|
|
|
2021-04-08 00:43:13 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'chat-style',
|
|
|
|
label: 'Webchat iframe style attribute',
|
|
|
|
type: 'input-textarea',
|
|
|
|
default: '',
|
2021-06-11 12:45:18 +00:00
|
|
|
descriptionHTML:
|
|
|
|
`Additional styles to be added on the iframe style attribute. <br>
|
|
|
|
Example: height:400px;`,
|
2021-04-08 00:43:13 +00:00
|
|
|
private: false
|
|
|
|
})
|
2021-04-13 15:13:41 +00:00
|
|
|
|
2021-06-03 10:24:09 +00:00
|
|
|
// ********** settings changes management
|
2021-04-13 15:13:41 +00:00
|
|
|
settingsManager.onSettingsChange(async (settings: any) => {
|
2021-06-03 09:46:11 +00:00
|
|
|
if ('chat-type' in settings) {
|
|
|
|
const chatType: ChatType = settings['chat-type'] ?? 'disabled'
|
|
|
|
if (chatType === 'builtin-prosody') {
|
2021-04-13 15:13:41 +00:00
|
|
|
peertubeHelpers.logger.info('Saving settings, ensuring prosody is running')
|
|
|
|
await ensureProsodyRunning(options)
|
2021-06-03 09:46:11 +00:00
|
|
|
} else {
|
2021-04-13 15:13:41 +00:00
|
|
|
peertubeHelpers.logger.info('Saving settings, ensuring prosody is not running')
|
|
|
|
await ensureProsodyNotRunning(options)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2021-04-08 00:43:13 +00:00
|
|
|
}
|
2021-06-02 17:16:27 +00:00
|
|
|
|
|
|
|
export {
|
|
|
|
initSettings
|
|
|
|
}
|