Move setUserJID
to init.js
This commit is contained in:
parent
ca9e13a047
commit
b16d035975
|
@ -33,7 +33,7 @@ import {
|
||||||
cleanup,
|
cleanup,
|
||||||
initClientConfig,
|
initClientConfig,
|
||||||
initPlugins,
|
initPlugins,
|
||||||
initSession,
|
setUserJID,
|
||||||
initSessionStorage,
|
initSessionStorage,
|
||||||
registerGlobalEventHandlers
|
registerGlobalEventHandlers
|
||||||
} from './utils/init.js';
|
} from './utils/init.js';
|
||||||
|
@ -152,7 +152,7 @@ export const api = _converse.api = {
|
||||||
// We also call `_proto._doDisconnect` so that connection event handlers
|
// We also call `_proto._doDisconnect` so that connection event handlers
|
||||||
// for the old transport are removed.
|
// for the old transport are removed.
|
||||||
if (api.connection.isType('websocket') && api.settings.get('bosh_service_url')) {
|
if (api.connection.isType('websocket') && api.settings.get('bosh_service_url')) {
|
||||||
await _converse.setUserJID(_converse.bare_jid);
|
await setUserJID(_converse.bare_jid);
|
||||||
_converse.connection._proto._doDisconnect();
|
_converse.connection._proto._doDisconnect();
|
||||||
_converse.connection._proto = new Strophe.Bosh(_converse.connection);
|
_converse.connection._proto = new Strophe.Bosh(_converse.connection);
|
||||||
_converse.connection.service = api.settings.get('bosh_service_url');
|
_converse.connection.service = api.settings.get('bosh_service_url');
|
||||||
|
@ -161,9 +161,9 @@ export const api = _converse.api = {
|
||||||
// When reconnecting anonymously, we need to connect with only
|
// When reconnecting anonymously, we need to connect with only
|
||||||
// the domain, not the full JID that we had in our previous
|
// the domain, not the full JID that we had in our previous
|
||||||
// (now failed) session.
|
// (now failed) session.
|
||||||
await _converse.setUserJID(api.settings.get("jid"));
|
await setUserJID(api.settings.get("jid"));
|
||||||
} else {
|
} else {
|
||||||
await _converse.setUserJID(_converse.bare_jid);
|
await setUserJID(_converse.bare_jid);
|
||||||
}
|
}
|
||||||
_converse.connection._proto._doDisconnect();
|
_converse.connection._proto._doDisconnect();
|
||||||
_converse.connection._proto = new Strophe.Websocket(_converse.connection);
|
_converse.connection._proto = new Strophe.Websocket(_converse.connection);
|
||||||
|
@ -173,7 +173,7 @@ export const api = _converse.api = {
|
||||||
// When reconnecting anonymously, we need to connect with only
|
// When reconnecting anonymously, we need to connect with only
|
||||||
// the domain, not the full JID that we had in our previous
|
// the domain, not the full JID that we had in our previous
|
||||||
// (now failed) session.
|
// (now failed) session.
|
||||||
await _converse.setUserJID(api.settings.get("jid"));
|
await setUserJID(api.settings.get("jid"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_converse.connection?.reconnecting) {
|
if (_converse.connection?.reconnecting) {
|
||||||
|
@ -302,7 +302,7 @@ export const api = _converse.api = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (jid) {
|
if (jid) {
|
||||||
jid = await _converse.setUserJID(jid);
|
jid = await setUserJID(jid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// See whether there is a BOSH session to re-attach to
|
// See whether there is a BOSH session to re-attach to
|
||||||
|
@ -647,30 +647,6 @@ _converse.initConnection = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores the passed in JID for the current user, potentially creating a
|
|
||||||
* resource if the JID is bare.
|
|
||||||
*
|
|
||||||
* Given that we can only create an XMPP connection if we know the domain of
|
|
||||||
* the server connect to and we only know this once we know the JID, we also
|
|
||||||
* call {@link _converse.initConnection } (if necessary) to make sure that the
|
|
||||||
* connection is set up.
|
|
||||||
*
|
|
||||||
* @method _converse#setUserJID
|
|
||||||
* @emits _converse#setUserJID
|
|
||||||
* @params { String } jid
|
|
||||||
*/
|
|
||||||
_converse.setUserJID = async function (jid) {
|
|
||||||
await initSession(_converse, jid);
|
|
||||||
/**
|
|
||||||
* Triggered whenever the user's JID has been updated
|
|
||||||
* @event _converse#setUserJID
|
|
||||||
*/
|
|
||||||
_converse.api.trigger('setUserJID');
|
|
||||||
return jid;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function setUpXMLLogging () {
|
function setUpXMLLogging () {
|
||||||
const lmap = {}
|
const lmap = {}
|
||||||
lmap[Strophe.LogLevel.DEBUG] = 'debug';
|
lmap[Strophe.LogLevel.DEBUG] = 'debug';
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
/**
|
/**
|
||||||
* @module converse-bosh
|
|
||||||
* @copyright The Converse.js contributors
|
* @copyright The Converse.js contributors
|
||||||
* @license Mozilla Public License (MPLv2)
|
* @license Mozilla Public License (MPLv2)
|
||||||
* @description Converse.js plugin which add support for XEP-0206: XMPP Over BOSH
|
* @description Converse.js plugin which add support for XEP-0206: XMPP Over BOSH
|
||||||
*/
|
*/
|
||||||
import 'strophe.js/src/bosh';
|
import 'strophe.js/src/bosh';
|
||||||
|
import log from "../log.js";
|
||||||
import { Model } from '@converse/skeletor/src/model.js';
|
import { Model } from '@converse/skeletor/src/model.js';
|
||||||
import { _converse, api, converse } from "../core.js";
|
import { _converse, api, converse } from "../core.js";
|
||||||
import log from "../log.js";
|
import { setUserJID, } from '@converse/headless/utils/init.js';
|
||||||
|
|
||||||
const { Strophe } = converse.env;
|
const { Strophe } = converse.env;
|
||||||
|
|
||||||
|
@ -36,13 +36,13 @@ converse.plugins.add('converse-bosh', {
|
||||||
}
|
}
|
||||||
if (_converse.jid) {
|
if (_converse.jid) {
|
||||||
if (_converse.bosh_session.get('jid') !== _converse.jid) {
|
if (_converse.bosh_session.get('jid') !== _converse.jid) {
|
||||||
const jid = await _converse.setUserJID(_converse.jid);
|
const jid = await setUserJID(_converse.jid);
|
||||||
_converse.bosh_session.clear({'silent': true });
|
_converse.bosh_session.clear({'silent': true });
|
||||||
_converse.bosh_session.save({jid});
|
_converse.bosh_session.save({jid});
|
||||||
}
|
}
|
||||||
} else { // Keepalive
|
} else { // Keepalive
|
||||||
const jid = _converse.bosh_session.get('jid');
|
const jid = _converse.bosh_session.get('jid');
|
||||||
jid && await _converse.setUserJID(jid);
|
jid && await setUserJID(jid);
|
||||||
}
|
}
|
||||||
return _converse.bosh_session;
|
return _converse.bosh_session;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ converse.plugins.add('converse-bosh', {
|
||||||
xhr.onload = async function () {
|
xhr.onload = async function () {
|
||||||
if (xhr.status >= 200 && xhr.status < 400) {
|
if (xhr.status >= 200 && xhr.status < 400) {
|
||||||
const data = JSON.parse(xhr.responseText);
|
const data = JSON.parse(xhr.responseText);
|
||||||
const jid = await _converse.setUserJID(data.jid);
|
const jid = await setUserJID(data.jid);
|
||||||
_converse.connection.attach(
|
_converse.connection.attach(
|
||||||
jid,
|
jid,
|
||||||
data.sid,
|
data.sid,
|
||||||
|
|
|
@ -5,7 +5,7 @@ import sizzle from 'sizzle';
|
||||||
import { Strophe } from 'strophe.js/src/core';
|
import { Strophe } from 'strophe.js/src/core';
|
||||||
import { _converse, api, clearSession, tearDown } from "../core.js";
|
import { _converse, api, clearSession, tearDown } from "../core.js";
|
||||||
import { getOpenPromise } from '@converse/openpromise';
|
import { getOpenPromise } from '@converse/openpromise';
|
||||||
|
import { setUserJID, } from '@converse/headless/utils/init.js';
|
||||||
|
|
||||||
const BOSH_WAIT = 59;
|
const BOSH_WAIT = 59;
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ export class Connection extends Strophe.Connection {
|
||||||
async onConnected (reconnecting) {
|
async onConnected (reconnecting) {
|
||||||
delete this.reconnecting;
|
delete this.reconnecting;
|
||||||
this.flush(); // Solves problem of returned PubSub BOSH response not received by browser
|
this.flush(); // Solves problem of returned PubSub BOSH response not received by browser
|
||||||
await _converse.setUserJID(this.jid);
|
await setUserJID(this.jid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synchronous event triggered after we've sent an IQ to bind the
|
* Synchronous event triggered after we've sent an IQ to bind the
|
||||||
|
|
|
@ -143,6 +143,28 @@ function saveJIDtoSession (_converse, jid) {
|
||||||
_converse.connection.jid = jid;
|
_converse.connection.jid = jid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the passed in JID for the current user, potentially creating a
|
||||||
|
* resource if the JID is bare.
|
||||||
|
*
|
||||||
|
* Given that we can only create an XMPP connection if we know the domain of
|
||||||
|
* the server connect to and we only know this once we know the JID, we also
|
||||||
|
* call {@link _converse.initConnection } (if necessary) to make sure that the
|
||||||
|
* connection is set up.
|
||||||
|
*
|
||||||
|
* @emits _converse#setUserJID
|
||||||
|
* @params { String } jid
|
||||||
|
*/
|
||||||
|
export async function setUserJID (jid) {
|
||||||
|
await initSession(_converse, jid);
|
||||||
|
/**
|
||||||
|
* Triggered whenever the user's JID has been updated
|
||||||
|
* @event _converse#setUserJID
|
||||||
|
*/
|
||||||
|
_converse.api.trigger('setUserJID');
|
||||||
|
return jid;
|
||||||
|
}
|
||||||
|
|
||||||
export async function initSession (_converse, jid) {
|
export async function initSession (_converse, jid) {
|
||||||
const is_shared_session = _converse.api.settings.get('connection_options').worker;
|
const is_shared_session = _converse.api.settings.get('connection_options').worker;
|
||||||
|
|
||||||
|
@ -237,7 +259,7 @@ function fetchLoginCredentials (wait=0) {
|
||||||
xhr.onload = () => {
|
xhr.onload = () => {
|
||||||
if (xhr.status >= 200 && xhr.status < 400) {
|
if (xhr.status >= 200 && xhr.status < 400) {
|
||||||
const data = JSON.parse(xhr.responseText);
|
const data = JSON.parse(xhr.responseText);
|
||||||
_converse.setUserJID(data.jid).then(() => {
|
setUserJID(data.jid).then(() => {
|
||||||
resolve({
|
resolve({
|
||||||
jid: data.jid,
|
jid: data.jid,
|
||||||
password: data.password
|
password: data.password
|
||||||
|
|
Loading…
Reference in New Issue
Block a user