Better xmpp share link (#114)
This commit is contained in:
parent
d359d3ad99
commit
1bd5c4decc
@ -1,7 +1,7 @@
|
||||
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
|
||||
import type { Video } from '@peertube/peertube-types'
|
||||
import { logger } from './logger'
|
||||
import { getIframeUri, getXMPPUri, UriOptions } from './uri'
|
||||
import { getIframeUri, getXMPPAddr, UriOptions } from './uri'
|
||||
import { isAutoColorsAvailable } from 'shared/lib/autocolors'
|
||||
|
||||
interface ShareForm {
|
||||
@ -213,9 +213,10 @@ async function shareChatUrl (registerOptions: RegisterClientOptions, settings: a
|
||||
}
|
||||
|
||||
openButton.onclick = () => {
|
||||
const uri = shareString.getAttribute('open-uri') ?? shareString.value
|
||||
// Don't open the url if it is an iframe!
|
||||
if (shareString.value.startsWith('http') || shareString.value.startsWith('xmpp')) {
|
||||
window.open(shareString.value)
|
||||
if (uri.startsWith('http') || uri.startsWith('xmpp')) {
|
||||
window.open(uri)
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,6 +273,7 @@ async function shareChatUrl (registerOptions: RegisterClientOptions, settings: a
|
||||
form.readonlyOptions.classList.add('livechat-shareurl-web-options-readonly-disabled')
|
||||
}
|
||||
let shareStringValue
|
||||
let shareStringOpen: string | undefined
|
||||
if (!form.radioProtocolXMPP?.checked) {
|
||||
shareStringValue = getIframeUri(registerOptions, settings, video, uriOptions)
|
||||
if (form.generateIframe.checked) {
|
||||
@ -293,9 +295,16 @@ async function shareChatUrl (registerOptions: RegisterClientOptions, settings: a
|
||||
} else {
|
||||
// we must generate a XMPP room address
|
||||
// form.openButton.disabled = true
|
||||
shareStringValue = getXMPPUri(registerOptions, settings, video)
|
||||
const addr = getXMPPAddr(registerOptions, settings, video)
|
||||
shareStringValue = addr?.jid
|
||||
shareStringOpen = addr?.uri
|
||||
}
|
||||
form.shareString.setAttribute('value', shareStringValue ?? '')
|
||||
if (shareStringOpen) {
|
||||
form.shareString.setAttribute('open-uri', shareStringOpen)
|
||||
} else {
|
||||
form.shareString.removeAttribute('open-uri')
|
||||
}
|
||||
}
|
||||
|
||||
function save (form: ShareForm): void {
|
||||
|
@ -66,9 +66,13 @@ function getIframeUri (
|
||||
return iframeUriStr
|
||||
}
|
||||
|
||||
function getXMPPUri (
|
||||
interface XMPPAddr {
|
||||
uri: string
|
||||
jid: string
|
||||
}
|
||||
function getXMPPAddr (
|
||||
registerOptions: RegisterClientOptions, settings: any, video: Video
|
||||
): string | null {
|
||||
): XMPPAddr | null {
|
||||
// returns something like xmpp:256896ac-199a-4dab-bb3a-4fd916140272@room.instance.tdl?join
|
||||
if (!settings['prosody-room-allow-s2s']) {
|
||||
return null
|
||||
@ -83,7 +87,11 @@ function getXMPPUri (
|
||||
|
||||
const hostname = window.location.hostname
|
||||
|
||||
return 'xmpp:' + uuid + '@room.' + hostname + '?join'
|
||||
const jid = uuid + '@room.' + hostname
|
||||
return {
|
||||
jid,
|
||||
uri: 'xmpp:' + jid + '?join'
|
||||
}
|
||||
}
|
||||
|
||||
export type {
|
||||
@ -92,5 +100,5 @@ export type {
|
||||
export {
|
||||
getBaseRoute,
|
||||
getIframeUri,
|
||||
getXMPPUri
|
||||
getXMPPAddr
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user