From c95dd1f71317f95daacdd53073d6600f23f52163 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Tue, 21 Dec 2021 19:54:37 +0100 Subject: [PATCH] chat-share-url --- client/@types/peertube.d.ts | 1 + client/admin-plugin-client-plugin.ts | 1 + client/videowatch-client-plugin.ts | 62 +++++++++++++++++++++++++++- client/videowatch/share.ts | 2 - documentation/prosody.md | 23 ++++++++++- server/lib/settings.ts | 14 +++++++ 6 files changed, 98 insertions(+), 5 deletions(-) diff --git a/client/@types/peertube.d.ts b/client/@types/peertube.d.ts index 36cd1004..ac6dbc27 100644 --- a/client/@types/peertube.d.ts +++ b/client/@types/peertube.d.ts @@ -68,6 +68,7 @@ interface Video { originInstanceUrl: string uuid: string channel: Channel + byAccount: string } interface Channel { diff --git a/client/admin-plugin-client-plugin.ts b/client/admin-plugin-client-plugin.ts index 47d45904..b77e7ef6 100644 --- a/client/admin-plugin-client-plugin.ts +++ b/client/admin-plugin-client-plugin.ts @@ -212,6 +212,7 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re 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 !( diff --git a/client/videowatch-client-plugin.ts b/client/videowatch-client-plugin.ts index 9958c5c0..e9861c31 100644 --- a/client/videowatch-client-plugin.ts +++ b/client/videowatch-client-plugin.ts @@ -11,6 +11,54 @@ interface VideoWatchLoadedHookOptions { playlist?: any } +function guessIsMine (registerOptions: RegisterOptions, video: Video): boolean { + // Note: this is not safe, but it is not a problem: + // this function is used for non critical functions + try { + if (!video) { + return false + } + if (!video.isLocal) { + return false + } + if (!window.localStorage) { + return false + } + const username = window.localStorage.getItem('username') ?? '' + if (!username) { + return false + } + if (username !== video.byAccount) { + return false + } + return true + } catch (err) { + logger.error(err as string) + return false + } +} + +function guessIamIModerator (_registerOptions: RegisterOptions): boolean { + // Note: this is not safe, but it is not a problem: + // this function is used for non critical functions + try { + if (!window.localStorage) { + return false + } + const role = window.localStorage.getItem('role') ?? '' + if (!role) { + return false + } + if (role !== '0' && role !== '1') { + return false + } + return true + } catch (err) { + logger.error(err as string) + return false + } +} + function register (registerOptions: RegisterOptions): void { const { registerHook, peertubeHelpers } = registerOptions let settings: any = {} @@ -196,8 +244,18 @@ function register (registerOptions: RegisterOptions): void { let showShareUrlButton: boolean = false if (settings['chat-type'] === 'builtin-prosody') { - // FIXME: showShareUrlButton should only be true for video owner and instance moderators. - showShareUrlButton = true + // 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) + } } insertChatDom(container as HTMLElement, video, !!settings['chat-open-blank'], showShareUrlButton).then(() => { if (settings['chat-auto-display']) { diff --git a/client/videowatch/share.ts b/client/videowatch/share.ts index f39c8839..6554ad5f 100644 --- a/client/videowatch/share.ts +++ b/client/videowatch/share.ts @@ -130,8 +130,6 @@ async function shareChatUrl (registerOptions: RegisterOptions, settings: any, vi // Saving the form state, to restore each time the modal is opened. save(form) - // TODO: check when the feature should be available - const uriOptions: UriOptions = { ignoreAutoColors: form.autoColors ? !form.autoColors.checked : true, permanent: true diff --git a/documentation/prosody.md b/documentation/prosody.md index 547dff85..72aa0d85 100644 --- a/documentation/prosody.md +++ b/documentation/prosody.md @@ -67,6 +67,15 @@ Here is the documentation: [common settings](./common.md). ### Prosody advanced settings +#### Show the «share chat link» button + +This feature enable a «share chat link» modal. With this modal, you can generate urls to join the chat. +The chat can be customized (readonly mode, use the current theme, ...). + +You can for example generate a readonly url and use it in OBS to integrate the chat in your live stream! + +This settings allows you to choose who can access this modal. + #### Peertube url for API calls In some rare cases, Prosody can't call Peertube's API from its public URI. @@ -128,6 +137,18 @@ When you open the chat room in full screen, there will also be a menu with dedic ## Advanced usages -### OBS Overlay using Matterbridge +### OBS Overlay + +#### Using readonly chat url + +You can use the «share chat link» feature (see above) to generate an url to your chat. +Check the «readonly» checkbox in the modal. +Then use this link as a «web browser source» in OBS. + +Note: you can customize colors. This is undocumented yet, but you can try this: +in the modal, check «use curent theme colors», then you can try to manually change color values in the url. +You must use valid CSS color values, and they must be properly url encoded. + +#### Using Matterbridge Here is a tutorial to use Matterbridge with the plugin: diff --git a/server/lib/settings.ts b/server/lib/settings.ts index dd692980..871e51ff 100644 --- a/server/lib/settings.ts +++ b/server/lib/settings.ts @@ -315,6 +315,20 @@ You can report the bug on the official descriptionHTML: '

Prosody advanced settings

' }) + registerSetting({ + name: 'chat-share-url', + label: 'Show the «share chat link» button', + descriptionHTML: 'There will be a button for sharing a chat url (could be used to intregrated in OBS for example).', + private: false, + type: 'select', + default: 'owner', + options: [ + { label: 'Show for nobody', value: 'nobody' }, + { label: 'Show for everyone', value: 'everyone' }, + { label: 'Show for the video owner', value: 'owner' }, + { label: 'Show for the video owner and instance\'s moderators', value: 'owner+moderators' } + ] + }) registerSetting({ name: 'prosody-peertube-uri', label: 'Peertube url for API calls',