* Chat should be displayed for waiting and ended lives
* Chat and chat buttons must be cleaned out of the dom on navigation
This commit is contained in:
John Livingston 2021-02-20 15:41:00 +01:00
parent db13377d81
commit b071489e5b
5 changed files with 97 additions and 50 deletions

View File

@ -9,6 +9,8 @@
### Fix ### Fix
* Fix dom positionning * Fix dom positionning
* Chat should be displayed for waiting and ended lives
* Chat and chat buttons must be cleaned out of the dom on navigation
## v0.0.5 ## v0.0.5

View File

@ -0,0 +1,16 @@
'use strict'
function register ({ registerHook, _peertubeHelpers }) {
registerHook({
target: 'action:router.navigation-end',
handler: () => {
document.querySelectorAll('.peertube-plugin-livechat-stuff')
.forEach(dom => dom.remove())
}
})
}
export {
register
}

View File

@ -44,7 +44,10 @@ function getIframeUri (uuid) {
function displayButton (buttons, name, label, callback) { function displayButton (buttons, name, label, callback) {
const button = document.createElement('button') const button = document.createElement('button')
button.setAttribute('class', 'action-button peertube-plugin-livechat-button-' + name) button.setAttribute(
'class',
'action-button peertube-plugin-livechat-stuff peertube-plugin-livechat-button-' + name
)
button.setAttribute('type', 'button') button.setAttribute('type', 'button')
button.textContent = label button.textContent = label
button.onclick = callback button.onclick = callback
@ -108,13 +111,16 @@ function openChat () {
// Adding a class=row element // Adding a class=row element
const row = document.createElement('div') const row = document.createElement('div')
row.setAttribute('class', 'row peertube-plugin-livechat-stuff') row.setAttribute('class', 'row peertube-plugin-livechat-stuff peertube-plugin-livechat-iframe-stuff')
videoWrapper.after(row) videoWrapper.after(row)
// Creating the iframe... // Creating the iframe...
const iframe = document.createElement('iframe') const iframe = document.createElement('iframe')
iframe.setAttribute('src', iframeUri) iframe.setAttribute('src', iframeUri)
iframe.setAttribute('class', 'peertube-plugin-livechat peertube-plugin-livechat-stuff') iframe.setAttribute(
'class',
'peertube-plugin-livechat peertube-plugin-livechat-stuff peertube-plugin-livechat-iframe-stuff'
)
iframe.setAttribute('sandbox', 'allow-same-origin allow-scripts allow-popups allow-forms') iframe.setAttribute('sandbox', 'allow-same-origin allow-scripts allow-popups allow-forms')
iframe.setAttribute('frameborder', '0') iframe.setAttribute('frameborder', '0')
if (additionalStyles) { if (additionalStyles) {
@ -131,27 +137,21 @@ function openChat () {
} }
function closeChat () { function closeChat () {
document.querySelectorAll('.peertube-plugin-livechat-stuff') document.querySelectorAll('.peertube-plugin-livechat-iframe-stuff')
.forEach(dom => dom.remove()) .forEach(dom => dom.remove())
// showing/hiding buttons... // showing/hiding buttons...
toggleShowHideButtons(false) toggleShowHideButtons(false)
} }
function register ({ registerHook, peertubeHelpers }) { function initChat (peertubeHelpers) {
registerHook({ if (document.querySelector('TODO')) {
target: 'filter:api.video-watch.video.get.result', logger.log('The chat seems already initialized...')
handler: (video) => { return
// For now, hooks for action:video-watch... did not receive the video object
// So we store video objects in videoCache
videoCache[video.uuid] = video
lastUUID = video.uuid
return video
} }
}) // Adding a custom class in the dom, so we know initChat was already called.
registerHook({ // TODO
target: 'action:video-watch.video.loaded',
handler: () => {
peertubeHelpers.getSettings().then(s => { peertubeHelpers.getSettings().then(s => {
settings = s settings = s
const liveOn = !!settings['chat-all-lives'] const liveOn = !!settings['chat-all-lives']
@ -193,8 +193,30 @@ function register ({ registerHook, peertubeHelpers }) {
} }
}) })
}) })
}
function register ({ registerHook, peertubeHelpers }) {
registerHook({
target: 'filter:api.video-watch.video.get.result',
handler: (video) => {
// For now, hooks for action:video-watch... did not receive the video object
// So we store video objects in videoCache
videoCache[video.uuid] = video
lastUUID = video.uuid
// FIXME: this should be made in action:video-watch.video.loaded.
// But with Peertube 3.0.1, this hook is not called for lives
// in WAITING_FOR_LIVE and LIVE_ENDED states.
initChat(peertubeHelpers)
return video
} }
}) })
// FIXME: this should be the correct hook for initChat...
// registerHook({
// target: 'action:video-watch.video.loaded',
// handler: () => {
// initChat(peertubeHelpers)
// }
// })
} }
export { export {

View File

@ -10,6 +10,12 @@
"scopes": [ "scopes": [
"video-watch" "video-watch"
] ]
},
{
"script": "dist/common-client-plugin.js",
"scopes": [
"common"
]
} }
], ],
"css": [ "css": [

View File

@ -3,6 +3,7 @@ const path = require("path")
const EsmWebpackPlugin = require("@purtuga/esm-webpack-plugin") const EsmWebpackPlugin = require("@purtuga/esm-webpack-plugin")
const clientFiles = [ const clientFiles = [
'common-client-plugin.js',
'videowatch-client-plugin.js' 'videowatch-client-plugin.js'
] ]