Share chat link popup: add an option to generate an iframe.
Implements #110, and #92 partially.
This commit is contained in:
parent
3f47c3c65a
commit
ce9d531db7
@ -8,6 +8,10 @@ If you haven't upgraded to v6.0.0 yet, please read v6.0.0 changelog first.
|
|||||||
|
|
||||||
### New Features
|
### New Features
|
||||||
|
|
||||||
|
### New features
|
||||||
|
|
||||||
|
* Share chat link popup: add an option to generate an iframe.
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
|
|
||||||
* Minimum Peertube version is now v4.2.0.
|
* Minimum Peertube version is now v4.2.0.
|
||||||
|
@ -5,12 +5,15 @@ import { getIframeUri, UriOptions } from './uri'
|
|||||||
import { isAutoColorsAvailable } from 'shared/lib/autocolors'
|
import { isAutoColorsAvailable } from 'shared/lib/autocolors'
|
||||||
|
|
||||||
interface ShareForm {
|
interface ShareForm {
|
||||||
|
shareString: HTMLInputElement
|
||||||
|
openButton: HTMLButtonElement
|
||||||
|
copyButton: HTMLButtonElement
|
||||||
readonly: HTMLInputElement
|
readonly: HTMLInputElement
|
||||||
withscroll: HTMLInputElement
|
withscroll: HTMLInputElement
|
||||||
transparent: HTMLInputElement
|
transparent: HTMLInputElement
|
||||||
readonlyOptions: HTMLElement
|
readonlyOptions: HTMLElement
|
||||||
url: HTMLInputElement
|
|
||||||
autoColors?: HTMLInputElement
|
autoColors?: HTMLInputElement
|
||||||
|
generateIframe: HTMLInputElement
|
||||||
}
|
}
|
||||||
|
|
||||||
async function shareChatUrl (registerOptions: RegisterClientOptions, settings: any, video: Video): Promise<void> {
|
async function shareChatUrl (registerOptions: RegisterClientOptions, settings: any, video: Video): Promise<void> {
|
||||||
@ -26,7 +29,9 @@ async function shareChatUrl (registerOptions: RegisterClientOptions, settings: a
|
|||||||
labelCopied,
|
labelCopied,
|
||||||
labelError,
|
labelError,
|
||||||
labelOpen,
|
labelOpen,
|
||||||
labelAutocolors
|
labelAutocolors,
|
||||||
|
labelGenerateIframe,
|
||||||
|
labelChatFor
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
peertubeHelpers.translate('Share chat link'),
|
peertubeHelpers.translate('Share chat link'),
|
||||||
peertubeHelpers.translate('Read-only'),
|
peertubeHelpers.translate('Read-only'),
|
||||||
@ -38,7 +43,9 @@ async function shareChatUrl (registerOptions: RegisterClientOptions, settings: a
|
|||||||
peertubeHelpers.translate('Link copied'),
|
peertubeHelpers.translate('Link copied'),
|
||||||
peertubeHelpers.translate('Error'),
|
peertubeHelpers.translate('Error'),
|
||||||
peertubeHelpers.translate('Open'),
|
peertubeHelpers.translate('Open'),
|
||||||
peertubeHelpers.translate('Use current theme colors')
|
peertubeHelpers.translate('Use current theme colors'),
|
||||||
|
peertubeHelpers.translate('Generate an iframe to embed the chat in a website'),
|
||||||
|
peertubeHelpers.translate('Chat for live stream:')
|
||||||
])
|
])
|
||||||
|
|
||||||
const defaultUri = getIframeUri(registerOptions, settings, video)
|
const defaultUri = getIframeUri(registerOptions, settings, video)
|
||||||
@ -53,24 +60,24 @@ async function shareChatUrl (registerOptions: RegisterClientOptions, settings: a
|
|||||||
|
|
||||||
container.classList.add('peertube-plugin-livechat-shareurl-modal')
|
container.classList.add('peertube-plugin-livechat-shareurl-modal')
|
||||||
|
|
||||||
const divUrl = document.createElement('div')
|
const divShareString = document.createElement('div')
|
||||||
divUrl.classList.add('livechat-shareurl-copy')
|
divShareString.classList.add('livechat-shareurl-copy')
|
||||||
const url = document.createElement('input')
|
const shareString = document.createElement('input')
|
||||||
url.setAttribute('type', 'text')
|
shareString.setAttribute('type', 'text')
|
||||||
url.setAttribute('readonly', '')
|
shareString.setAttribute('readonly', '')
|
||||||
url.setAttribute('autocomplete', 'off')
|
shareString.setAttribute('autocomplete', 'off')
|
||||||
url.setAttribute('placeholder', '')
|
shareString.setAttribute('placeholder', '')
|
||||||
url.classList.add('form-control', 'readonly')
|
shareString.classList.add('form-control', 'readonly')
|
||||||
divUrl.append(url)
|
divShareString.append(shareString)
|
||||||
const copy = document.createElement('button')
|
const copyButton = document.createElement('button')
|
||||||
copy.classList.add('btn', 'btn-outline-secondary', 'text-uppercase')
|
copyButton.classList.add('btn', 'btn-outline-secondary', 'text-uppercase')
|
||||||
copy.textContent = labelCopy
|
copyButton.textContent = labelCopy
|
||||||
divUrl.append(copy)
|
divShareString.append(copyButton)
|
||||||
const open = document.createElement('button')
|
const openButton = document.createElement('button')
|
||||||
open.classList.add('btn', 'btn-outline-secondary', 'text-uppercase')
|
openButton.classList.add('btn', 'btn-outline-secondary', 'text-uppercase')
|
||||||
open.textContent = labelOpen
|
openButton.textContent = labelOpen
|
||||||
divUrl.append(open)
|
divShareString.append(openButton)
|
||||||
container.append(divUrl)
|
container.append(divShareString)
|
||||||
|
|
||||||
const divTips = document.createElement('div')
|
const divTips = document.createElement('div')
|
||||||
divTips.textContent = tipsOBS
|
divTips.textContent = tipsOBS
|
||||||
@ -115,6 +122,13 @@ async function shareChatUrl (registerOptions: RegisterClientOptions, settings: a
|
|||||||
divCustom.append(label)
|
divCustom.append(label)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const generateIframe = document.createElement('input')
|
||||||
|
generateIframe.setAttribute('type', 'checkbox')
|
||||||
|
const generateIframeLabelEl = document.createElement('label')
|
||||||
|
generateIframeLabelEl.textContent = labelGenerateIframe
|
||||||
|
generateIframeLabelEl.prepend(generateIframe)
|
||||||
|
divCustom.append(generateIframeLabelEl)
|
||||||
|
|
||||||
readonly.onclick = () => {
|
readonly.onclick = () => {
|
||||||
renderContent(container)
|
renderContent(container)
|
||||||
}
|
}
|
||||||
@ -124,39 +138,47 @@ async function shareChatUrl (registerOptions: RegisterClientOptions, settings: a
|
|||||||
transparent.onclick = () => {
|
transparent.onclick = () => {
|
||||||
renderContent(container)
|
renderContent(container)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (autoColors) {
|
if (autoColors) {
|
||||||
autoColors.onclick = () => {
|
autoColors.onclick = () => {
|
||||||
renderContent(container)
|
renderContent(container)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
generateIframe.onclick = () => {
|
||||||
url.onclick = () => {
|
renderContent(container)
|
||||||
url.select()
|
|
||||||
url.setSelectionRange(0, 99999) /* For mobile devices */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
copy.onclick = () => {
|
shareString.onclick = () => {
|
||||||
url.select()
|
shareString.select()
|
||||||
url.setSelectionRange(0, 99999) /* For mobile devices */
|
shareString.setSelectionRange(0, 99999) /* For mobile devices */
|
||||||
navigator.clipboard.writeText(url.value).then(() => {
|
}
|
||||||
|
|
||||||
|
copyButton.onclick = () => {
|
||||||
|
shareString.select()
|
||||||
|
shareString.setSelectionRange(0, 99999) /* For mobile devices */
|
||||||
|
navigator.clipboard.writeText(shareString.value).then(() => {
|
||||||
peertubeHelpers.notifier.success(labelCopied)
|
peertubeHelpers.notifier.success(labelCopied)
|
||||||
}, () => {
|
}, () => {
|
||||||
peertubeHelpers.notifier.error(labelError)
|
peertubeHelpers.notifier.error(labelError)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
open.onclick = () => {
|
openButton.onclick = () => {
|
||||||
window.open(url.value)
|
// Don't open the url if it is an iframe!
|
||||||
|
if (shareString.value.startsWith('http')) {
|
||||||
|
window.open(shareString.value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
form = {
|
form = {
|
||||||
|
shareString,
|
||||||
|
copyButton,
|
||||||
|
openButton,
|
||||||
readonly,
|
readonly,
|
||||||
withscroll,
|
withscroll,
|
||||||
transparent,
|
transparent,
|
||||||
readonlyOptions,
|
readonlyOptions,
|
||||||
url,
|
autoColors,
|
||||||
autoColors
|
generateIframe
|
||||||
}
|
}
|
||||||
restore(form)
|
restore(form)
|
||||||
}
|
}
|
||||||
@ -185,8 +207,24 @@ async function shareChatUrl (registerOptions: RegisterClientOptions, settings: a
|
|||||||
form.transparent.disabled = true
|
form.transparent.disabled = true
|
||||||
form.readonlyOptions.classList.add('livechat-shareurl-custom-readonly-disabled')
|
form.readonlyOptions.classList.add('livechat-shareurl-custom-readonly-disabled')
|
||||||
}
|
}
|
||||||
const iframeUri = getIframeUri(registerOptions, settings, video, uriOptions)
|
let shareStringValue = getIframeUri(registerOptions, settings, video, uriOptions)
|
||||||
form.url.setAttribute('value', iframeUri ?? '')
|
if (form.generateIframe.checked) {
|
||||||
|
form.openButton.disabled = true
|
||||||
|
if (shareStringValue) {
|
||||||
|
// To properly escape all attributes, we are constructing an HTMLIframeElement
|
||||||
|
const iframe = document.createElement('iframe')
|
||||||
|
iframe.setAttribute('src', shareStringValue)
|
||||||
|
iframe.setAttribute('title', labelChatFor + ' ' + video.name)
|
||||||
|
iframe.setAttribute('sandbox', 'allow-same-origin allow-scripts allow-popups allow-forms')
|
||||||
|
iframe.setAttribute('width', '560')
|
||||||
|
iframe.setAttribute('height', '315')
|
||||||
|
iframe.setAttribute('frameborder', '0')
|
||||||
|
shareStringValue = iframe.outerHTML
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
form.openButton.disabled = false
|
||||||
|
}
|
||||||
|
form.shareString.setAttribute('value', shareStringValue ?? '')
|
||||||
}
|
}
|
||||||
|
|
||||||
function save (form: ShareForm): void {
|
function save (form: ShareForm): void {
|
||||||
@ -198,7 +236,8 @@ async function shareChatUrl (registerOptions: RegisterClientOptions, settings: a
|
|||||||
readonly: !!form.readonly.checked,
|
readonly: !!form.readonly.checked,
|
||||||
withscroll: !!form.withscroll.checked,
|
withscroll: !!form.withscroll.checked,
|
||||||
transparent: !!form.transparent.checked,
|
transparent: !!form.transparent.checked,
|
||||||
autocolors: !!form.autoColors?.checked
|
autocolors: !!form.autoColors?.checked,
|
||||||
|
generateIframe: !!form.generateIframe.checked
|
||||||
}
|
}
|
||||||
window.localStorage.setItem('peertube-plugin-livechat-shareurl', JSON.stringify(v))
|
window.localStorage.setItem('peertube-plugin-livechat-shareurl', JSON.stringify(v))
|
||||||
}
|
}
|
||||||
@ -223,6 +262,7 @@ async function shareChatUrl (registerOptions: RegisterClientOptions, settings: a
|
|||||||
if (form.autoColors) {
|
if (form.autoColors) {
|
||||||
form.autoColors.checked = !!v.autocolors
|
form.autoColors.checked = !!v.autocolors
|
||||||
}
|
}
|
||||||
|
form.generateIframe.checked = !!v.generateIframe
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err as string)
|
logger.error(err as string)
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,7 @@
|
|||||||
"Link copied": false,
|
"Link copied": false,
|
||||||
"Error": false,
|
"Error": false,
|
||||||
"Open": false,
|
"Open": false,
|
||||||
"Use current theme colors": false
|
"Use current theme colors": false,
|
||||||
|
"Generate an iframe to embed the chat in a website": false,
|
||||||
|
"Chat for live stream": false
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,7 @@
|
|||||||
"Link copied": "Link kopiert",
|
"Link copied": "Link kopiert",
|
||||||
"Error": "Fehler",
|
"Error": "Fehler",
|
||||||
"Open": "Öffnen",
|
"Open": "Öffnen",
|
||||||
"Use current theme colors": "Die derzeitigen Themenfarben nutzen"
|
"Use current theme colors": "Die derzeitigen Themenfarben nutzen",
|
||||||
|
"Generate an iframe to embed the chat in a website": false,
|
||||||
|
"Chat for live stream": false
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,7 @@
|
|||||||
"Link copied": "Ligilo kopiata",
|
"Link copied": "Ligilo kopiata",
|
||||||
"Error": "Eraro",
|
"Error": "Eraro",
|
||||||
"Open": "Malfermi",
|
"Open": "Malfermi",
|
||||||
"Use current theme colors": "Uzi koloroj el la nuna etoso"
|
"Use current theme colors": "Uzi koloroj el la nuna etoso",
|
||||||
|
"Generate an iframe to embed the chat in a website": false,
|
||||||
|
"Chat for live stream": false
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,7 @@
|
|||||||
"Link copied": "Enlace copiado",
|
"Link copied": "Enlace copiado",
|
||||||
"Error": "Error",
|
"Error": "Error",
|
||||||
"Open": "Abrir",
|
"Open": "Abrir",
|
||||||
"Use current theme colors": "Utilizar los colores del tema actual"
|
"Use current theme colors": "Utilizar los colores del tema actual",
|
||||||
|
"Generate an iframe to embed the chat in a website": false,
|
||||||
|
"Chat for live stream": false
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,7 @@
|
|||||||
"Link copied": "Esteka kopiatu da",
|
"Link copied": "Esteka kopiatu da",
|
||||||
"Error": "Errorea",
|
"Error": "Errorea",
|
||||||
"Open": "Ireki",
|
"Open": "Ireki",
|
||||||
"Use current theme colors": "Erabili uneko itxuraren koloreak"
|
"Use current theme colors": "Erabili uneko itxuraren koloreak",
|
||||||
|
"Generate an iframe to embed the chat in a website": false,
|
||||||
|
"Chat for live stream": false
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,7 @@
|
|||||||
"Link copied": "Lien copié",
|
"Link copied": "Lien copié",
|
||||||
"Error": "Erreur",
|
"Error": "Erreur",
|
||||||
"Open": "Ouvrir",
|
"Open": "Ouvrir",
|
||||||
"Use current theme colors": "Utiliser les couleurs du thème courant"
|
"Use current theme colors": "Utiliser les couleurs du thème courant",
|
||||||
|
"Generate an iframe to embed the chat in a website": "Générer une iframe pour intégrer le tchat dans un site web",
|
||||||
|
"Chat for live stream:": "Tchat pour le direct :"
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,7 @@
|
|||||||
"Link copied": false,
|
"Link copied": false,
|
||||||
"Error": false,
|
"Error": false,
|
||||||
"Open": false,
|
"Open": false,
|
||||||
"Use current theme colors": false
|
"Use current theme colors": false,
|
||||||
|
"Generate an iframe to embed the chat in a website": false,
|
||||||
|
"Chat for live stream": false
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,7 @@
|
|||||||
"Link copied": "リンクをコピーしました",
|
"Link copied": "リンクをコピーしました",
|
||||||
"Error": "エラー",
|
"Error": "エラー",
|
||||||
"Open": "開く",
|
"Open": "開く",
|
||||||
"Use current theme colors": "現在のテーマカラーを使用する"
|
"Use current theme colors": "現在のテーマカラーを使用する",
|
||||||
|
"Generate an iframe to embed the chat in a website": false,
|
||||||
|
"Chat for live stream": false
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,7 @@
|
|||||||
"Link copied": "Ligam copiat",
|
"Link copied": "Ligam copiat",
|
||||||
"Error": "Error",
|
"Error": "Error",
|
||||||
"Open": "Dobrir",
|
"Open": "Dobrir",
|
||||||
"Use current theme colors": "Utilizar las colors del tèma actual"
|
"Use current theme colors": "Utilizar las colors del tèma actual" ,
|
||||||
|
"Generate an iframe to embed the chat in a website": false,
|
||||||
|
"Chat for live stream": false
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,7 @@
|
|||||||
"Link copied": false,
|
"Link copied": false,
|
||||||
"Error": false,
|
"Error": false,
|
||||||
"Open": false,
|
"Open": false,
|
||||||
"Use current theme colors": false
|
"Use current theme colors": false,
|
||||||
|
"Generate an iframe to embed the chat in a website": false,
|
||||||
|
"Chat for live stream": false
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user