2024-05-23 09:42:14 +00:00
|
|
|
// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-05-24 13:09:56 +00:00
|
|
|
import type { LiveChatJSONLDAttributeV1 } from './types'
|
2023-04-21 14:56:48 +00:00
|
|
|
|
|
|
|
interface AnonymousConnectionInfos {
|
|
|
|
roomJID: string
|
|
|
|
boshUri?: string
|
|
|
|
wsUri?: string
|
|
|
|
userJID: string
|
|
|
|
}
|
|
|
|
|
2023-05-24 13:09:56 +00:00
|
|
|
function anonymousConnectionInfos (livechatInfos: LiveChatJSONLDAttributeV1 | false): AnonymousConnectionInfos | null {
|
2023-04-21 14:56:48 +00:00
|
|
|
if (!livechatInfos) { return null }
|
|
|
|
if (livechatInfos.type !== 'xmpp') { return null }
|
2023-05-24 13:09:56 +00:00
|
|
|
if (!livechatInfos.xmppserver) { return null }
|
|
|
|
if (!livechatInfos.xmppserver.anonymous) { return null }
|
2023-04-21 14:56:48 +00:00
|
|
|
const r: AnonymousConnectionInfos = {
|
|
|
|
roomJID: livechatInfos.jid,
|
2023-05-24 13:09:56 +00:00
|
|
|
userJID: livechatInfos.xmppserver.anonymous.virtualhost
|
2023-04-21 14:56:48 +00:00
|
|
|
}
|
2023-05-24 13:09:56 +00:00
|
|
|
if (livechatInfos.xmppserver.anonymous.bosh) {
|
|
|
|
r.boshUri = livechatInfos.xmppserver.anonymous.bosh
|
2023-04-21 14:56:48 +00:00
|
|
|
}
|
2023-05-24 13:09:56 +00:00
|
|
|
if (livechatInfos.xmppserver.anonymous.websocket) {
|
|
|
|
r.wsUri = livechatInfos.xmppserver.anonymous.websocket
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!r.boshUri && !r.wsUri) {
|
2023-04-21 14:56:48 +00:00
|
|
|
return null
|
|
|
|
}
|
2023-05-24 13:09:56 +00:00
|
|
|
|
2023-04-21 14:56:48 +00:00
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2023-05-24 13:09:56 +00:00
|
|
|
function remoteAuthenticatedConnectionEnabled (livechatInfos: LiveChatJSONLDAttributeV1): boolean {
|
2023-05-04 17:14:23 +00:00
|
|
|
if (!livechatInfos) { return false }
|
|
|
|
if (livechatInfos.type !== 'xmpp') { return false }
|
2023-05-24 13:09:56 +00:00
|
|
|
if (!('xmppserver' in livechatInfos)) { return false }
|
|
|
|
if (!livechatInfos.xmppserver) { return false }
|
|
|
|
|
|
|
|
if (livechatInfos.xmppserver.websockets2s) { return true }
|
|
|
|
if (livechatInfos.xmppserver.directs2s) { return true }
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
function compatibleRemoteAuthenticatedConnectionEnabled (
|
|
|
|
livechatInfos: LiveChatJSONLDAttributeV1,
|
|
|
|
canWebsocketS2S: boolean,
|
|
|
|
canDirectS2S: boolean
|
|
|
|
): boolean {
|
|
|
|
if (!livechatInfos) { return false }
|
|
|
|
if (livechatInfos.type !== 'xmpp') { return false }
|
|
|
|
if (!('xmppserver' in livechatInfos)) { return false }
|
|
|
|
if (!livechatInfos.xmppserver) { return false }
|
|
|
|
|
|
|
|
if (canWebsocketS2S && livechatInfos.xmppserver.websockets2s) { return true }
|
2023-06-01 11:06:59 +00:00
|
|
|
// Note: see comments neer option s2s_peertubelivechat_no_outgoing_directs2s_to_peertube
|
|
|
|
// to understand why we need both to be true.
|
2023-05-24 13:09:56 +00:00
|
|
|
if (canDirectS2S && livechatInfos.xmppserver.directs2s) { return true }
|
|
|
|
|
2023-05-04 17:14:23 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-04-21 14:56:48 +00:00
|
|
|
export {
|
2023-05-04 17:14:23 +00:00
|
|
|
anonymousConnectionInfos,
|
2023-05-24 13:09:56 +00:00
|
|
|
remoteAuthenticatedConnectionEnabled,
|
|
|
|
compatibleRemoteAuthenticatedConnectionEnabled
|
2023-04-21 14:56:48 +00:00
|
|
|
}
|