Chat Federation, connection to remote chat:

Front-end connect using BOSH or WS directly on the remote server.
If use is logged-in, his nickname is use as default nickname.
This commit is contained in:
John Livingston
2023-04-21 16:56:48 +02:00
parent b85a1dc90a
commit 5d323b2dfd
7 changed files with 236 additions and 79 deletions

View File

@ -82,6 +82,7 @@ function randomNick (base: string): string {
interface InitConverseParams {
jid: string
remoteAnonymousXMPPServer: boolean
assetsPath: string
room: string
boshServiceUrl: string
@ -95,6 +96,7 @@ interface InitConverseParams {
}
window.initConverse = async function initConverse ({
jid,
remoteAnonymousXMPPServer,
assetsPath,
room,
boshServiceUrl,
@ -205,6 +207,7 @@ window.initConverse = async function initConverse ({
// TODO: params.clear_messages_on_reconnection = true when muc_mam will be available.
let isAuthenticated: boolean = false
let isRemoteWithNicknameSet: boolean = false
if (authenticationUrl === '') {
throw new Error('Missing authenticationUrl')
}
@ -218,19 +221,27 @@ window.initConverse = async function initConverse ({
const auth = await authenticatedMode(authenticationUrl)
if (auth) {
params.authentication = 'login'
params.auto_login = true
params.jid = auth.jid
params.password = auth.password
if (auth.nickname) {
params.nickname = auth.nickname
if (remoteAnonymousXMPPServer) {
// Spécial case: anonymous connection to remote XMPP server.
if (auth.nickname) {
params.nickname = auth.nickname
isRemoteWithNicknameSet = true
}
} else {
params.muc_nickname_from_jid = true
params.authentication = 'login'
params.auto_login = true
params.jid = auth.jid
params.password = auth.password
if (auth.nickname) {
params.nickname = auth.nickname
} else {
params.muc_nickname_from_jid = true
}
// We dont need the keepalive. And I suppose it is related to some bugs when opening a previous chat window.
params.keepalive = false
isAuthenticated = true
// FIXME: use params.oauth_providers?
}
// We dont need the keepalive. And I suppose it is related to some bugs when opening a previous chat window.
params.keepalive = false
isAuthenticated = true
// FIXME: use params.oauth_providers?
}
if (!isAuthenticated) {
@ -267,7 +278,7 @@ window.initConverse = async function initConverse ({
}
})
if (autoViewerMode && !isAuthenticated) {
if (autoViewerMode && !isAuthenticated && !isRemoteWithNicknameSet) {
converse.plugins.add('livechatViewerModePlugin', {
dependencies: ['converse-muc', 'converse-muc-views'],
initialize: function () {

View File

@ -16,6 +16,7 @@
<script type="text/javascript">
initConverse({
jid: '{{JID}}',
remoteAnonymousXMPPServer: '{{REMOTE_ANONYMOUS_XMPP_SERVER}}' === 'true',
assetsPath : '{{BASE_STATIC_URL}}conversejs/',
room: '{{ROOM}}',
boshServiceUrl: '{{BOSH_SERVICE_URL}}',