diff --git a/README.md b/README.md index 1a767457..b0fd8e16 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,12 @@ -# PeerTube plugin livechat +# PeerTube plugin livechat * ALPHA VERSION * Work In Progress + +Plugin that allows to integrated an iframe with an external webchat application. + +This is under development. It is not functional yet. + +For now, there is no documentation for how you can setup the webchat. +It has to be setup by your own. For example with a XMPP Server and the ConverseJS Javascript. + +Next step: document how you can setup the XMPP server. diff --git a/assets/style.css b/assets/style.css index e69de29b..84d62abb 100644 --- a/assets/style.css +++ b/assets/style.css @@ -0,0 +1,5 @@ +iframe.peertube-plugin-livechat { + width: 100%; + height: 300px; + resize: vertical; +} diff --git a/client/common-client-plugin.js b/client/common-client-plugin.js deleted file mode 100644 index 50df4e76..00000000 --- a/client/common-client-plugin.js +++ /dev/null @@ -1,7 +0,0 @@ -function register ({ registerHook, peertubeHelpers }) { - -} - -export { - register -} diff --git a/client/videowatch-client-plugin.js b/client/videowatch-client-plugin.js new file mode 100644 index 00000000..1054888d --- /dev/null +++ b/client/videowatch-client-plugin.js @@ -0,0 +1,49 @@ +function register ({ registerHook, peertubeHelpers }) { + registerHook({ + target: 'action:video-watch.player.loaded', + handler: ({player, videojs, video}) => { + peertubeHelpers.getSettings().then(s => { + const liveOn = !!s['chat-all-lives'] + const nonLiveOn = !!s['chat-all-non-lives'] + const uuids = s['chat-videos-list'] ? s['chat-videos-list'].split('\n') : [] + const iframeUri = s['chat-uri'] || '' + if ( iframeUri === '' ) { + console.log('[peertube-plugin-livechat] no uri, can\'t add chat.') + return + } + if (!uuids.length && !liveOn && !nonLiveOn) { + console.log('[peertube-plugin-livechat] not activated.') + return + } + + console.log('[peertube-plugin-livechat] Checking if this video should have a chat...') + const uuid = video.uuid + if (uuids.indexOf(uuid) >= 0) { + console.log('[peertube-plugin-livechat] This video is in the list for chats.') + } else if (video.isLive && liveOn) { + console.log('[peertube-plugin-livechat] This video is live and we want all lives.') + } else if (!video.isLive && nonLiveOn) { + console.log('[peertube-plugin-livechat] This video is not live and we want all non-lives.') + } else { + console.log('[peertube-plugin-livechat] This video will not have a chat.') + return + } + console.info('[peertube-plugin-livechat] Trying to load the chat for video ' + uuid + '.') + const chatUrl = iframeUri.replace('{{VIDEO_UUID}}', uuid) + if (!/^https?:\/\//.test(chatUrl)) { + console.error('[peertube-plugin-livechat] The webchaturi must begin with https://') + return + } + const parent = document.querySelector('.video-info') + const iframe = document.createElement('iframe') + iframe.setAttribute('src', chatUrl) + iframe.setAttribute('class', 'peertube-plugin-livechat') + parent.prepend(iframe) + }) + } + }) +} + +export { + register +} diff --git a/main.js b/main.js index 498da0a2..17d212a7 100644 --- a/main.js +++ b/main.js @@ -7,7 +7,35 @@ async function register ({ videoLicenceManager, videoLanguageManager }) { - + registerSetting({ + name: 'chat-all-lives', + label: 'Activate chat for all lives', + type: 'input-checkbox', + default: false, + descriptionHTML: 'If checked, a chat will be added to all lives.' + }) + registerSetting({ + name: 'chat-all-non-lives', + label: 'Activate chat for all non-lives', + type: 'input-checkbox', + default: false, + descriptionHTML: 'If checked, a chat will be added to all video that are not lives.' + }) + registerSetting({ + name: 'chat-videos-list', + label: 'Activate chat for specific videos', + type: 'input-textarea', + default: '', + descriptionHTML: 'Videos UUIDs for which we want a chat. Can be non-live videos. One per line. Don\'t add private videos, the UUIDs will be send to frontend.' + }) + registerSetting({ + name: 'chat-uri', + label: 'Webchat url', + type: 'input', + default: '', + descriptionHTML: 'The 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}}.' + }) + } async function unregister () { diff --git a/package.json b/package.json index d2771671..583a6e4c 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,9 @@ "bugs": "https://github.com/JohnXLivingston/peertube-plugin-livechat/issues", "clientScripts": [ { - "script": "dist/common-client-plugin.js", + "script": "dist/videowatch-client-plugin.js", "scopes": [ - "common" + "video-watch" ] } ], diff --git a/webpack.config.js b/webpack.config.js index c73f5926..20b57fa3 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -3,7 +3,7 @@ const path = require("path") const EsmWebpackPlugin = require("@purtuga/esm-webpack-plugin") const clientFiles = [ - 'common-client-plugin.js' + 'videowatch-client-plugin.js' ] let config = clientFiles.map(f => ({