2022-01-11 00:29:33 +00:00
|
|
|
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
|
|
|
|
import type { RegisterClientFormFieldOptions } from '@peertube/peertube-types'
|
2023-09-06 13:23:39 +00:00
|
|
|
import { registerConfiguration } from './common/configuration/register'
|
2024-04-03 10:13:44 +00:00
|
|
|
import { registerRoom } from './common/room/register'
|
2023-08-08 15:15:05 +00:00
|
|
|
|
|
|
|
async function register (clientOptions: RegisterClientOptions): Promise<void> {
|
|
|
|
const { peertubeHelpers, registerHook, registerVideoField } = clientOptions
|
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) {
|
2021-12-08 18:33:28 +00:00
|
|
|
const url = container.getAttribute('peertube-plugin-livechat-current-url')
|
|
|
|
if (url && url === window.location.href) {
|
|
|
|
console.warn(
|
|
|
|
'[peertube-plugin-livechat navigation-end] ' +
|
|
|
|
'It seems that action:router.navigation-end was called after action:video-watch.video.loaded. ' +
|
2024-03-28 14:06:15 +00:00
|
|
|
'Not removing the chat from the DOM.'
|
2021-12-08 18:33:28 +00:00
|
|
|
)
|
|
|
|
return
|
|
|
|
}
|
2021-03-01 17:38:39 +00:00
|
|
|
container.remove()
|
2021-02-20 15:03:44 +00:00
|
|
|
}
|
2024-03-27 15:26:32 +00:00
|
|
|
|
|
|
|
if (window.converse?.livechatDisconnect) {
|
|
|
|
window.converse.livechatDisconnect()
|
|
|
|
}
|
2021-02-20 14:41:00 +00:00
|
|
|
}
|
|
|
|
})
|
2021-06-08 16:08:58 +00:00
|
|
|
|
|
|
|
const [label, description, settings] = await Promise.all([
|
2023-06-12 17:26:28 +00:00
|
|
|
peertubeHelpers.translate(LOC_USE_CHAT),
|
|
|
|
peertubeHelpers.translate(LOC_USE_CHAT_HELP),
|
2021-06-08 16:08:58 +00:00
|
|
|
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' })
|
2023-08-08 15:15:05 +00:00
|
|
|
|
2024-04-03 10:13:44 +00:00
|
|
|
await Promise.all([
|
|
|
|
registerRoom(clientOptions),
|
|
|
|
registerConfiguration(clientOptions)
|
|
|
|
])
|
2021-02-20 14:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
register
|
|
|
|
}
|