2019-07-11 10:48:52 +02:00
|
|
|
|
/**
|
2020-01-26 16:21:20 +01:00
|
|
|
|
* @copyright The Converse.js contributors
|
2019-09-19 16:54:55 +02:00
|
|
|
|
* @license Mozilla Public License (MPLv2)
|
2019-07-11 10:48:52 +02:00
|
|
|
|
*/
|
2021-07-05 17:15:48 +02:00
|
|
|
|
import URI from 'urijs';
|
2022-12-28 21:36:40 +01:00
|
|
|
|
import _converse from './shared/_converse';
|
2019-05-21 16:18:14 +02:00
|
|
|
|
import advancedFormat from 'dayjs/plugin/advancedFormat';
|
2022-12-28 21:36:40 +01:00
|
|
|
|
import connection_api from './shared/connection/api.js';
|
2019-06-05 06:57:20 +02:00
|
|
|
|
import dayjs from 'dayjs';
|
2022-12-28 21:36:40 +01:00
|
|
|
|
import i18n from './shared/i18n';
|
2021-05-12 12:14:28 +02:00
|
|
|
|
import invoke from 'lodash-es/invoke';
|
2022-12-28 21:36:40 +01:00
|
|
|
|
import log from './log.js';
|
2021-05-12 11:07:38 +02:00
|
|
|
|
import pluggable from 'pluggable.js/src/pluggable.js';
|
2019-06-05 06:57:20 +02:00
|
|
|
|
import sizzle from 'sizzle';
|
2023-02-26 10:39:57 +01:00
|
|
|
|
import u, { setUnloadEvent } from './utils/core.js';
|
2022-04-25 09:47:11 +02:00
|
|
|
|
import { CHAT_STATES, KEYCODES } from './shared/constants.js';
|
2020-06-08 16:08:50 +02:00
|
|
|
|
import { Collection } from "@converse/skeletor/src/collection";
|
|
|
|
|
import { Model } from '@converse/skeletor/src/model.js';
|
2020-09-10 07:33:00 +02:00
|
|
|
|
import { Strophe, $build, $iq, $msg, $pres } from 'strophe.js/src/strophe';
|
2021-04-14 22:56:59 +02:00
|
|
|
|
import { html } from 'lit';
|
2022-12-28 21:36:40 +01:00
|
|
|
|
import { initAppSettings } from './shared/settings/utils.js';
|
2023-02-26 10:39:57 +01:00
|
|
|
|
import { settings_api } from './shared/settings/api.js';
|
2020-09-10 07:33:00 +02:00
|
|
|
|
import { sprintf } from 'sprintf-js';
|
2023-02-26 10:39:57 +01:00
|
|
|
|
import send_api from './shared/api/send.js';
|
|
|
|
|
import user_api from './shared/api/user.js';
|
|
|
|
|
import events_api from './shared/api/events.js';
|
|
|
|
|
import promise_api from './shared/api/promise.js';
|
2018-10-23 03:41:38 +02:00
|
|
|
|
|
2021-03-09 12:55:44 +01:00
|
|
|
|
export { _converse };
|
|
|
|
|
export { i18n };
|
2019-05-29 17:40:16 +02:00
|
|
|
|
|
2021-07-15 18:45:16 +02:00
|
|
|
|
import {
|
|
|
|
|
cleanup,
|
|
|
|
|
initClientConfig,
|
|
|
|
|
initPlugins,
|
|
|
|
|
initSessionStorage,
|
2022-03-24 21:41:05 +01:00
|
|
|
|
registerGlobalEventHandlers,
|
2021-07-15 18:45:16 +02:00
|
|
|
|
} from './utils/init.js';
|
|
|
|
|
|
2019-05-21 16:18:14 +02:00
|
|
|
|
dayjs.extend(advancedFormat);
|
2019-05-06 11:16:56 +02:00
|
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
|
// Add Strophe Namespaces
|
2021-08-13 10:18:24 +02:00
|
|
|
|
Strophe.addNamespace('ACTIVITY', 'http://jabber.org/protocol/activity');
|
2018-10-23 03:41:38 +02:00
|
|
|
|
Strophe.addNamespace('CARBONS', 'urn:xmpp:carbons:2');
|
|
|
|
|
Strophe.addNamespace('CHATSTATES', 'http://jabber.org/protocol/chatstates');
|
|
|
|
|
Strophe.addNamespace('CSI', 'urn:xmpp:csi:0');
|
|
|
|
|
Strophe.addNamespace('DELAY', 'urn:xmpp:delay');
|
2021-07-05 14:56:20 +02:00
|
|
|
|
Strophe.addNamespace('EME', 'urn:xmpp:eme:0');
|
2019-09-24 15:33:41 +02:00
|
|
|
|
Strophe.addNamespace('FASTEN', 'urn:xmpp:fasten:0');
|
2018-10-23 03:41:38 +02:00
|
|
|
|
Strophe.addNamespace('FORWARD', 'urn:xmpp:forward:0');
|
|
|
|
|
Strophe.addNamespace('HINTS', 'urn:xmpp:hints');
|
|
|
|
|
Strophe.addNamespace('HTTPUPLOAD', 'urn:xmpp:http:upload:0');
|
|
|
|
|
Strophe.addNamespace('MAM', 'urn:xmpp:mam:2');
|
2021-02-22 21:07:54 +01:00
|
|
|
|
Strophe.addNamespace('MARKERS', 'urn:xmpp:chat-markers:0');
|
2020-12-21 13:45:04 +01:00
|
|
|
|
Strophe.addNamespace('MENTIONS', 'urn:xmpp:mmn:0');
|
2021-02-22 21:07:54 +01:00
|
|
|
|
Strophe.addNamespace('MESSAGE_CORRECT', 'urn:xmpp:message-correct:0');
|
2019-09-24 15:33:41 +02:00
|
|
|
|
Strophe.addNamespace('MODERATE', 'urn:xmpp:message-moderate:0');
|
2018-10-23 03:41:38 +02:00
|
|
|
|
Strophe.addNamespace('NICK', 'http://jabber.org/protocol/nick');
|
2021-11-03 21:33:23 +01:00
|
|
|
|
Strophe.addNamespace('OCCUPANTID', 'urn:xmpp:occupant-id:0');
|
2019-06-05 06:57:20 +02:00
|
|
|
|
Strophe.addNamespace('OMEMO', 'eu.siacs.conversations.axolotl');
|
2018-10-23 03:41:38 +02:00
|
|
|
|
Strophe.addNamespace('OUTOFBAND', 'jabber:x:oob');
|
|
|
|
|
Strophe.addNamespace('PUBSUB', 'http://jabber.org/protocol/pubsub');
|
2020-12-08 14:51:04 +01:00
|
|
|
|
Strophe.addNamespace('RAI', 'urn:xmpp:rai:0');
|
2021-02-22 21:07:54 +01:00
|
|
|
|
Strophe.addNamespace('RECEIPTS', 'urn:xmpp:receipts');
|
|
|
|
|
Strophe.addNamespace('REFERENCE', 'urn:xmpp:reference:0');
|
2018-10-23 03:41:38 +02:00
|
|
|
|
Strophe.addNamespace('REGISTER', 'jabber:iq:register');
|
2019-09-24 15:33:41 +02:00
|
|
|
|
Strophe.addNamespace('RETRACT', 'urn:xmpp:message-retract:0');
|
2018-10-23 03:41:38 +02:00
|
|
|
|
Strophe.addNamespace('ROSTERX', 'http://jabber.org/protocol/rosterx');
|
|
|
|
|
Strophe.addNamespace('RSM', 'http://jabber.org/protocol/rsm');
|
|
|
|
|
Strophe.addNamespace('SID', 'urn:xmpp:sid:0');
|
|
|
|
|
Strophe.addNamespace('SPOILER', 'urn:xmpp:spoiler:0');
|
2019-04-10 22:03:00 +02:00
|
|
|
|
Strophe.addNamespace('STANZAS', 'urn:ietf:params:xml:ns:xmpp-stanzas');
|
2020-10-16 09:02:12 +02:00
|
|
|
|
Strophe.addNamespace('STYLING', 'urn:xmpp:styling:0');
|
2018-10-23 03:41:38 +02:00
|
|
|
|
Strophe.addNamespace('VCARD', 'vcard-temp');
|
|
|
|
|
Strophe.addNamespace('VCARDUPDATE', 'vcard-temp:x:update');
|
|
|
|
|
Strophe.addNamespace('XFORM', 'jabber:x:data');
|
2021-02-17 15:59:44 +01:00
|
|
|
|
Strophe.addNamespace('XHTML', 'http://www.w3.org/1999/xhtml');
|
2018-10-23 03:41:38 +02:00
|
|
|
|
|
2023-02-17 11:56:30 +01:00
|
|
|
|
_converse.VERSION_NAME = "v10.1.2";
|
2018-11-15 22:59:55 +01:00
|
|
|
|
|
2020-03-31 12:51:30 +02:00
|
|
|
|
// Make converse pluggable
|
|
|
|
|
pluggable.enable(_converse, '_converse', 'pluggable');
|
2019-05-21 11:12:34 +02:00
|
|
|
|
|
2018-11-15 22:59:55 +01:00
|
|
|
|
|
2020-03-31 12:51:30 +02:00
|
|
|
|
/**
|
|
|
|
|
* ### The private API
|
|
|
|
|
*
|
|
|
|
|
* The private API methods are only accessible via the closured {@link _converse}
|
|
|
|
|
* object, which is only available to plugins.
|
|
|
|
|
*
|
|
|
|
|
* These methods are kept private (i.e. not global) because they may return
|
|
|
|
|
* sensitive data which should be kept off-limits to other 3rd-party scripts
|
|
|
|
|
* that might be running in the page.
|
|
|
|
|
*
|
|
|
|
|
* @namespace _converse.api
|
|
|
|
|
* @memberOf _converse
|
|
|
|
|
*/
|
2020-04-15 13:59:55 +02:00
|
|
|
|
export const api = _converse.api = {
|
2022-04-25 09:47:11 +02:00
|
|
|
|
connection: connection_api,
|
|
|
|
|
settings: settings_api,
|
2023-02-26 10:39:57 +01:00
|
|
|
|
...send_api,
|
|
|
|
|
...user_api,
|
|
|
|
|
...events_api,
|
|
|
|
|
...promise_api,
|
2020-03-31 12:51:30 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2020-10-20 06:45:35 +02:00
|
|
|
|
_converse.shouldClearCache = () => (
|
|
|
|
|
!_converse.config.get('trusted') ||
|
|
|
|
|
api.settings.get('clear_cache_on_logout') ||
|
|
|
|
|
_converse.isTestEnv()
|
|
|
|
|
);
|
2020-03-31 12:51:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_converse.ConnectionFeedback = Model.extend({
|
|
|
|
|
defaults: {
|
|
|
|
|
'connection_status': Strophe.Status.DISCONNECTED,
|
|
|
|
|
'message': ''
|
|
|
|
|
},
|
|
|
|
|
initialize () {
|
|
|
|
|
this.on('change', () => api.trigger('connfeedback', _converse.connfeedback));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
|
/**
|
|
|
|
|
* ### The Public API
|
|
|
|
|
*
|
|
|
|
|
* This namespace contains public API methods which are are
|
|
|
|
|
* accessible on the global `converse` object.
|
|
|
|
|
* They are public, because any JavaScript in the
|
|
|
|
|
* page can call them. Public methods therefore don’t expose any sensitive
|
|
|
|
|
* or closured data. To do that, you’ll need to create a plugin, which has
|
|
|
|
|
* access to the private API method.
|
|
|
|
|
*
|
2019-07-20 21:55:42 +02:00
|
|
|
|
* @global
|
2018-10-23 03:41:38 +02:00
|
|
|
|
* @namespace converse
|
|
|
|
|
*/
|
2023-02-23 07:03:50 +01:00
|
|
|
|
export const converse = Object.assign(window.converse || {}, {
|
2020-03-18 19:32:03 +01:00
|
|
|
|
|
2022-03-09 12:22:44 +01:00
|
|
|
|
CHAT_STATES,
|
|
|
|
|
|
|
|
|
|
keycodes: KEYCODES,
|
2019-09-11 15:23:58 +02:00
|
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
|
/**
|
|
|
|
|
* Public API method which initializes Converse.
|
|
|
|
|
* This method must always be called when using Converse.
|
2020-03-31 12:28:11 +02:00
|
|
|
|
* @async
|
2018-10-23 03:41:38 +02:00
|
|
|
|
* @memberOf converse
|
|
|
|
|
* @method initialize
|
2023-02-23 07:03:50 +01:00
|
|
|
|
* @param { object } config A map of [configuration-settings](https://conversejs.org/docs/html/configuration.html#configuration-settings).
|
2018-10-23 03:41:38 +02:00
|
|
|
|
* @example
|
|
|
|
|
* converse.initialize({
|
|
|
|
|
* auto_list_rooms: false,
|
|
|
|
|
* auto_subscribe: false,
|
|
|
|
|
* bosh_service_url: 'https://bind.example.com',
|
|
|
|
|
* hide_muc_server: false,
|
2019-08-07 10:28:49 +02:00
|
|
|
|
* i18n: 'en',
|
2018-10-23 03:41:38 +02:00
|
|
|
|
* play_sounds: true,
|
|
|
|
|
* show_controlbox_by_default: true,
|
|
|
|
|
* debug: false,
|
|
|
|
|
* roster_groups: true
|
|
|
|
|
* });
|
|
|
|
|
*/
|
2020-03-31 12:28:11 +02:00
|
|
|
|
async initialize (settings) {
|
2021-07-15 18:45:16 +02:00
|
|
|
|
await cleanup(_converse);
|
2020-09-03 16:05:56 +02:00
|
|
|
|
|
2020-03-31 12:28:11 +02:00
|
|
|
|
setUnloadEvent();
|
2021-03-09 12:55:44 +01:00
|
|
|
|
initAppSettings(settings);
|
2020-03-31 12:28:11 +02:00
|
|
|
|
_converse.strict_plugin_dependencies = settings.strict_plugin_dependencies; // Needed by pluggable.js
|
|
|
|
|
log.setLogLevel(api.settings.get("loglevel"));
|
|
|
|
|
|
|
|
|
|
if (api.settings.get("authentication") === _converse.ANONYMOUS) {
|
|
|
|
|
if (api.settings.get("auto_login") && !api.settings.get('jid')) {
|
|
|
|
|
throw new Error("Config Error: you need to provide the server's " +
|
|
|
|
|
"domain via the 'jid' option when using anonymous " +
|
|
|
|
|
"authentication with auto_login.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_converse.router.route(
|
|
|
|
|
/^converse\?loglevel=(debug|info|warn|error|fatal)$/, 'loglevel',
|
|
|
|
|
l => log.setLogLevel(l)
|
|
|
|
|
);
|
|
|
|
|
_converse.connfeedback = new _converse.ConnectionFeedback();
|
|
|
|
|
|
|
|
|
|
/* When reloading the page:
|
|
|
|
|
* For new sessions, we need to send out a presence stanza to notify
|
|
|
|
|
* the server/network that we're online.
|
|
|
|
|
* When re-attaching to an existing session we don't need to again send out a presence stanza,
|
|
|
|
|
* because it's as if "we never left" (see onConnectStatusChanged).
|
|
|
|
|
* https://github.com/conversejs/converse.js/issues/521
|
|
|
|
|
*/
|
|
|
|
|
_converse.send_initial_presence = true;
|
|
|
|
|
|
2021-07-15 18:45:16 +02:00
|
|
|
|
await initSessionStorage(_converse);
|
|
|
|
|
await initClientConfig(_converse);
|
2020-09-28 12:55:06 +02:00
|
|
|
|
await i18n.initialize();
|
2021-07-15 18:45:16 +02:00
|
|
|
|
initPlugins(_converse);
|
2021-09-24 10:32:33 +02:00
|
|
|
|
|
|
|
|
|
// Register all custom elements
|
2022-02-03 12:39:59 +01:00
|
|
|
|
// XXX: api.elements is defined in the UI part of Converse, outside of @converse/headless.
|
|
|
|
|
// This line should probably be moved to the UI code as part of a larger refactoring.
|
|
|
|
|
api.elements?.register();
|
2021-09-24 10:32:33 +02:00
|
|
|
|
|
2021-07-15 18:45:16 +02:00
|
|
|
|
registerGlobalEventHandlers(_converse);
|
2020-03-31 12:51:30 +02:00
|
|
|
|
|
2021-02-24 15:48:11 +01:00
|
|
|
|
try {
|
|
|
|
|
!History.started && _converse.router.history.start();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
log.error(e);
|
|
|
|
|
}
|
2020-03-31 12:51:30 +02:00
|
|
|
|
|
|
|
|
|
const plugins = _converse.pluggable.plugins
|
|
|
|
|
if (api.settings.get("auto_login") || api.settings.get("keepalive") && invoke(plugins['converse-bosh'], 'enabled')) {
|
|
|
|
|
await api.user.login(null, null, true);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-26 16:07:59 +02:00
|
|
|
|
/**
|
|
|
|
|
* Triggered once converse.initialize has finished.
|
|
|
|
|
* @event _converse#initialized
|
|
|
|
|
*/
|
|
|
|
|
api.trigger('initialized');
|
|
|
|
|
|
2020-03-31 12:28:11 +02:00
|
|
|
|
if (_converse.isTestEnv()) {
|
|
|
|
|
return _converse;
|
|
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
|
},
|
2020-03-31 12:28:11 +02:00
|
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
|
/**
|
|
|
|
|
* Exposes methods for adding and removing plugins. You'll need to write a plugin
|
|
|
|
|
* if you want to have access to the private API methods defined further down below.
|
|
|
|
|
*
|
|
|
|
|
* For more information on plugins, read the documentation on [writing a plugin](/docs/html/plugin_development.html).
|
|
|
|
|
* @namespace plugins
|
|
|
|
|
* @memberOf converse
|
|
|
|
|
*/
|
2019-06-05 06:57:20 +02:00
|
|
|
|
plugins: {
|
2019-08-16 15:44:58 +02:00
|
|
|
|
/**
|
|
|
|
|
* Registers a new plugin.
|
2018-10-23 03:41:38 +02:00
|
|
|
|
* @method converse.plugins.add
|
2023-02-23 07:03:50 +01:00
|
|
|
|
* @param { string } name The name of the plugin
|
|
|
|
|
* @param { object } plugin The plugin object
|
2018-09-02 10:11:37 +02:00
|
|
|
|
* @example
|
2018-10-23 03:41:38 +02:00
|
|
|
|
* const plugin = {
|
|
|
|
|
* initialize: function () {
|
|
|
|
|
* // Gets called as soon as the plugin has been loaded.
|
2018-09-02 10:11:37 +02:00
|
|
|
|
*
|
2018-10-23 03:41:38 +02:00
|
|
|
|
* // Inside this method, you have access to the private
|
|
|
|
|
* // API via `_covnerse.api`.
|
2018-09-02 10:11:37 +02:00
|
|
|
|
*
|
2018-10-23 03:41:38 +02:00
|
|
|
|
* // The private _converse object contains the core logic
|
|
|
|
|
* // and data-structures of Converse.
|
|
|
|
|
* }
|
|
|
|
|
* }
|
|
|
|
|
* converse.plugins.add('myplugin', plugin);
|
2018-09-02 10:11:37 +02:00
|
|
|
|
*/
|
2019-06-05 06:57:20 +02:00
|
|
|
|
add (name, plugin) {
|
2018-10-23 03:41:38 +02:00
|
|
|
|
plugin.__name__ = name;
|
2019-07-29 10:19:05 +02:00
|
|
|
|
if (_converse.pluggable.plugins[name] !== undefined) {
|
2018-10-23 03:41:38 +02:00
|
|
|
|
throw new TypeError(
|
2019-06-05 06:57:20 +02:00
|
|
|
|
`Error: plugin with name "${name}" has already been ` + 'registered!'
|
|
|
|
|
);
|
2018-10-23 03:41:38 +02:00
|
|
|
|
} else {
|
|
|
|
|
_converse.pluggable.plugins[name] = plugin;
|
|
|
|
|
}
|
2017-02-14 15:08:39 +01:00
|
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Utility methods and globals from bundled 3rd party libraries.
|
2020-09-10 14:08:43 +02:00
|
|
|
|
* @typedef ConverseEnv
|
2018-10-23 03:41:38 +02:00
|
|
|
|
* @property {function} converse.env.$build - Creates a Strophe.Builder, for creating stanza objects.
|
|
|
|
|
* @property {function} converse.env.$iq - Creates a Strophe.Builder with an <iq/> element as the root.
|
|
|
|
|
* @property {function} converse.env.$msg - Creates a Strophe.Builder with an <message/> element as the root.
|
|
|
|
|
* @property {function} converse.env.$pres - Creates a Strophe.Builder with an <presence/> element as the root.
|
|
|
|
|
* @property {function} converse.env.Promise - The Promise implementation used by Converse.
|
|
|
|
|
* @property {function} converse.env.Strophe - The [Strophe](http://strophe.im/strophejs) XMPP library used by Converse.
|
|
|
|
|
* @property {function} converse.env.f - And instance of Lodash with its methods wrapped to produce immutable auto-curried iteratee-first data-last methods.
|
|
|
|
|
* @property {function} converse.env.sizzle - [Sizzle](https://sizzlejs.com) CSS selector engine.
|
2020-09-10 14:08:43 +02:00
|
|
|
|
* @property {function} converse.env.sprintf
|
|
|
|
|
* @property {object} converse.env._ - The instance of [lodash-es](http://lodash.com) used by Converse.
|
|
|
|
|
* @property {object} converse.env.dayjs - [DayJS](https://github.com/iamkun/dayjs) date manipulation library.
|
2018-10-23 03:41:38 +02:00
|
|
|
|
* @property {object} converse.env.utils - Module containing common utility methods used by Converse.
|
2020-09-10 14:08:43 +02:00
|
|
|
|
* @memberOf converse
|
2018-10-23 03:41:38 +02:00
|
|
|
|
*/
|
2020-09-10 14:08:43 +02:00
|
|
|
|
'env': {
|
|
|
|
|
$build,
|
|
|
|
|
$iq,
|
|
|
|
|
$msg,
|
|
|
|
|
$pres,
|
|
|
|
|
'utils': u,
|
|
|
|
|
Collection,
|
|
|
|
|
Model,
|
|
|
|
|
Promise,
|
|
|
|
|
Strophe,
|
2021-07-05 17:15:48 +02:00
|
|
|
|
URI,
|
2020-09-10 14:08:43 +02:00
|
|
|
|
dayjs,
|
|
|
|
|
html,
|
|
|
|
|
log,
|
|
|
|
|
sizzle,
|
|
|
|
|
sprintf,
|
2022-08-11 15:28:34 +02:00
|
|
|
|
stx: u.stx,
|
2020-09-10 14:08:43 +02:00
|
|
|
|
u,
|
|
|
|
|
}
|
2019-10-06 12:48:05 +02:00
|
|
|
|
});
|