Fix:
* 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:
parent
db13377d81
commit
b071489e5b
@ -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
|
||||||
|
|
||||||
|
16
client/common-client-plugin.js
Normal file
16
client/common-client-plugin.js
Normal 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
|
||||||
|
}
|
@ -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,13 +137,64 @@ 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 initChat (peertubeHelpers) {
|
||||||
|
if (document.querySelector('TODO')) {
|
||||||
|
logger.log('The chat seems already initialized...')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Adding a custom class in the dom, so we know initChat was already called.
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
peertubeHelpers.getSettings().then(s => {
|
||||||
|
settings = s
|
||||||
|
const liveOn = !!settings['chat-all-lives']
|
||||||
|
const nonLiveOn = !!settings['chat-all-non-lives']
|
||||||
|
const uuids = parseUUIDs(settings['chat-videos-list'])
|
||||||
|
const iframeUri = settings['chat-uri'] || ''
|
||||||
|
if (iframeUri === '') {
|
||||||
|
logger.log('no uri, can\'t add chat.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!uuids.length && !liveOn && !nonLiveOn) {
|
||||||
|
logger.log('not activated.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.log('Checking if this video should have a chat...')
|
||||||
|
const uuid = lastUUID
|
||||||
|
const video = videoCache[uuid]
|
||||||
|
if (!video) {
|
||||||
|
logger.error('Can\'t find the video ' + uuid + ' in the videoCache')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (uuids.indexOf(uuid) >= 0) {
|
||||||
|
logger.log('This video is in the list for chats.')
|
||||||
|
} else if (video.isLive && liveOn) {
|
||||||
|
logger.log('This video is live and we want all lives.')
|
||||||
|
} else if (!video.isLive && nonLiveOn) {
|
||||||
|
logger.log('This video is not live and we want all non-lives.')
|
||||||
|
} else {
|
||||||
|
logger.log('This video will not have a chat.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
displayChatButtons(peertubeHelpers, uuid).then(() => {
|
||||||
|
if (settings['chat-auto-display']) {
|
||||||
|
openChat()
|
||||||
|
} else {
|
||||||
|
toggleShowHideButtons(false)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function register ({ registerHook, peertubeHelpers }) {
|
function register ({ registerHook, peertubeHelpers }) {
|
||||||
registerHook({
|
registerHook({
|
||||||
target: 'filter:api.video-watch.video.get.result',
|
target: 'filter:api.video-watch.video.get.result',
|
||||||
@ -146,55 +203,20 @@ function register ({ registerHook, peertubeHelpers }) {
|
|||||||
// So we store video objects in videoCache
|
// So we store video objects in videoCache
|
||||||
videoCache[video.uuid] = video
|
videoCache[video.uuid] = video
|
||||||
lastUUID = video.uuid
|
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
|
return video
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
registerHook({
|
// FIXME: this should be the correct hook for initChat...
|
||||||
target: 'action:video-watch.video.loaded',
|
// registerHook({
|
||||||
handler: () => {
|
// target: 'action:video-watch.video.loaded',
|
||||||
peertubeHelpers.getSettings().then(s => {
|
// handler: () => {
|
||||||
settings = s
|
// initChat(peertubeHelpers)
|
||||||
const liveOn = !!settings['chat-all-lives']
|
// }
|
||||||
const nonLiveOn = !!settings['chat-all-non-lives']
|
// })
|
||||||
const uuids = parseUUIDs(settings['chat-videos-list'])
|
|
||||||
const iframeUri = settings['chat-uri'] || ''
|
|
||||||
if (iframeUri === '') {
|
|
||||||
logger.log('no uri, can\'t add chat.')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!uuids.length && !liveOn && !nonLiveOn) {
|
|
||||||
logger.log('not activated.')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.log('Checking if this video should have a chat...')
|
|
||||||
const uuid = lastUUID
|
|
||||||
const video = videoCache[uuid]
|
|
||||||
if (!video) {
|
|
||||||
logger.error('Can\'t find the video ' + uuid + ' in the videoCache')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (uuids.indexOf(uuid) >= 0) {
|
|
||||||
logger.log('This video is in the list for chats.')
|
|
||||||
} else if (video.isLive && liveOn) {
|
|
||||||
logger.log('This video is live and we want all lives.')
|
|
||||||
} else if (!video.isLive && nonLiveOn) {
|
|
||||||
logger.log('This video is not live and we want all non-lives.')
|
|
||||||
} else {
|
|
||||||
logger.log('This video will not have a chat.')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
displayChatButtons(peertubeHelpers, uuid).then(() => {
|
|
||||||
if (settings['chat-auto-display']) {
|
|
||||||
openChat()
|
|
||||||
} else {
|
|
||||||
toggleShowHideButtons(false)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -10,6 +10,12 @@
|
|||||||
"scopes": [
|
"scopes": [
|
||||||
"video-watch"
|
"video-watch"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"script": "dist/common-client-plugin.js",
|
||||||
|
"scopes": [
|
||||||
|
"common"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"css": [
|
"css": [
|
||||||
|
@ -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'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user