2021-02-20 14:41:00 +00:00
|
|
|
|
2021-06-08 16:08:58 +00:00
|
|
|
async function register ({ peertubeHelpers, registerHook, registerVideoField }: RegisterOptions): Promise<void> {
|
2021-02-20 14:41:00 +00:00
|
|
|
registerHook({
|
|
|
|
target: 'action:router.navigation-end',
|
|
|
|
handler: () => {
|
2021-03-01 17:38:39 +00:00
|
|
|
const container = document.querySelector('#peertube-plugin-livechat-container')
|
|
|
|
if (container) {
|
|
|
|
container.remove()
|
2021-02-20 15:03:44 +00:00
|
|
|
}
|
2021-02-20 14:41:00 +00:00
|
|
|
}
|
|
|
|
})
|
2021-06-08 16:08:58 +00:00
|
|
|
|
|
|
|
const [label, description, settings] = await Promise.all([
|
|
|
|
peertubeHelpers.translate('Use chat'),
|
|
|
|
peertubeHelpers.translate('If enabled, there will be a chat next to the video.'),
|
|
|
|
peertubeHelpers.getSettings()
|
|
|
|
])
|
|
|
|
const webchatFieldOptions: RegisterClientFormFieldOptions = {
|
|
|
|
name: 'livechat-active',
|
|
|
|
label: label,
|
|
|
|
descriptionHTML: description,
|
|
|
|
type: 'input-checkbox',
|
|
|
|
default: true,
|
|
|
|
hidden: ({ liveVideo }) => {
|
|
|
|
if (!liveVideo) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if (!settings['chat-per-live-video']) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if (settings['chat-all-lives']) {
|
|
|
|
// No need to add this field if live is active for all live videos
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
registerVideoField(webchatFieldOptions, { type: 'update' })
|
|
|
|
registerVideoField(webchatFieldOptions, { type: 'go-live' })
|
2021-02-20 14:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
register
|
|
|
|
}
|