|
@@ -189,14 +189,13 @@ The code for it would look something like this:
|
|
|
|
|
|
// Commonly used utilities and variables can be found under the "env"
|
|
|
// namespace of the "converse" global.
|
|
|
- var Strophe = converse.env.Strophe,
|
|
|
- $iq = converse.env.$iq,
|
|
|
- $msg = converse.env.$msg,
|
|
|
- $pres = converse.env.$pres,
|
|
|
- $build = converse.env.$build,
|
|
|
- b64_sha1 = converse.env.b64_sha1,
|
|
|
- _ = converse.env._,
|
|
|
- dayjs = converse.env.dayjs;
|
|
|
+ const Strophe = converse.env.Strophe,
|
|
|
+ $iq = converse.env.$iq,
|
|
|
+ $msg = converse.env.$msg,
|
|
|
+ $pres = converse.env.$pres,
|
|
|
+ $build = converse.env.$build,
|
|
|
+ _ = converse.env._,
|
|
|
+ dayjs = converse.env.dayjs;
|
|
|
|
|
|
These dependencies are closured so that they don't pollute the global
|
|
|
namespace, that's why you need to access them in such a way inside the module.
|
|
@@ -300,7 +299,7 @@ In this case, you should first listen for the ``connection`` event, and then do
|
|
|
|
|
|
converse.plugins.add('myplugin', {
|
|
|
initialize: function () {
|
|
|
- var _converse = this._converse;
|
|
|
+ const _converse = this._converse;
|
|
|
|
|
|
_converse.api.listen.on('connected', function () {
|
|
|
_converse.api.archive.query({'with': 'admin2@localhost'});
|
|
@@ -363,152 +362,141 @@ generated by `generator-conversejs <https://github.com/jcbrand/generator-convers
|
|
|
|
|
|
.. code-block:: javascript
|
|
|
|
|
|
- (function (root, factory) {
|
|
|
- if (typeof define === 'function' && define.amd) {
|
|
|
- // AMD. Register as a module called "myplugin"
|
|
|
- define(["converse"], factory);
|
|
|
- } else {
|
|
|
- // Browser globals. If you're not using a module loader such as require.js,
|
|
|
- // then this line below executes. Make sure that your plugin's <script> tag
|
|
|
- // appears after the one from converse.js.
|
|
|
- factory(converse);
|
|
|
- }
|
|
|
- }(this, function (converse) {
|
|
|
+ import converse from "@converse/headless/converse-core";
|
|
|
+
|
|
|
+ // Commonly used utilities and variables can be found under the "env"
|
|
|
+ // namespace of the "converse" global.
|
|
|
+ const Strophe = converse.env.Strophe,
|
|
|
+ $iq = converse.env.$iq,
|
|
|
+ $msg = converse.env.$msg,
|
|
|
+ $pres = converse.env.$pres,
|
|
|
+ $build = converse.env.$build,
|
|
|
+ _ = converse.env._,
|
|
|
+ dayjs = converse.env.dayjs;
|
|
|
+
|
|
|
+ // The following line registers your plugin.
|
|
|
+ converse.plugins.add("myplugin", {
|
|
|
+
|
|
|
+ /* Dependencies are other plugins which might be
|
|
|
+ * overridden or relied upon, and therefore need to be loaded before
|
|
|
+ * this plugin. They are "optional" because they might not be
|
|
|
+ * available, in which case any overrides applicable to them will be
|
|
|
+ * ignored.
|
|
|
+ *
|
|
|
+ * NB: These plugins need to have already been imported or loaded,
|
|
|
+ * either in your plugin or somewhere else.
|
|
|
+ *
|
|
|
+ * It's possible to make these dependencies "non-optional".
|
|
|
+ * If the setting "strict_plugin_dependencies" is set to true,
|
|
|
+ * an error will be raised if the plugin is not found.
|
|
|
+ */
|
|
|
+ 'dependencies': [],
|
|
|
+
|
|
|
+ /* Converse.js's plugin mechanism will call the initialize
|
|
|
+ * method on any plugin (if it exists) as soon as the plugin has
|
|
|
+ * been loaded.
|
|
|
+ */
|
|
|
+ 'initialize': function () {
|
|
|
+ /* Inside this method, you have access to the private
|
|
|
+ * `_converse` object.
|
|
|
+ */
|
|
|
+ const _converse = this._converse;
|
|
|
+ _converse.log("The \"myplugin\" plugin is being initialized");
|
|
|
+
|
|
|
+ /* From the `_converse` object you can get any configuration
|
|
|
+ * options that the user might have passed in via
|
|
|
+ * `converse.initialize`.
|
|
|
+ *
|
|
|
+ * You can also specify new configuration settings for this
|
|
|
+ * plugin, or override the default values of existing
|
|
|
+ * configuration settings. This is done like so:
|
|
|
+ */
|
|
|
+ _converse.api.settings.update({
|
|
|
+ 'initialize_message': 'Initializing myplugin!'
|
|
|
+ });
|
|
|
+
|
|
|
+ /* The user can then pass in values for the configuration
|
|
|
+ * settings when `converse.initialize` gets called.
|
|
|
+ * For example:
|
|
|
+ *
|
|
|
+ * converse.initialize({
|
|
|
+ * "initialize_message": "My plugin has been initialized"
|
|
|
+ * });
|
|
|
+ */
|
|
|
+ alert(this._converse.initialize_message);
|
|
|
|
|
|
- // Commonly used utilities and variables can be found under the "env"
|
|
|
- // namespace of the "converse" global.
|
|
|
- var Strophe = converse.env.Strophe,
|
|
|
- $iq = converse.env.$iq,
|
|
|
- $msg = converse.env.$msg,
|
|
|
- $pres = converse.env.$pres,
|
|
|
- $build = converse.env.$build,
|
|
|
- b64_sha1 = converse.env.b64_sha1,
|
|
|
- _ = converse.env._,
|
|
|
- dayjs = converse.env.dayjs;
|
|
|
-
|
|
|
- // The following line registers your plugin.
|
|
|
- converse.plugins.add("myplugin", {
|
|
|
-
|
|
|
- /* Dependencies are other plugins which might be
|
|
|
- * overridden or relied upon, and therefore need to be loaded before
|
|
|
- * this plugin. They are "optional" because they might not be
|
|
|
- * available, in which case any overrides applicable to them will be
|
|
|
- * ignored.
|
|
|
+ /* Besides `_converse.api.settings.update`, there is also a
|
|
|
+ * `_converse.api.promises.add` method, which allows you to
|
|
|
+ * add new promises that your plugin is obligated to fulfill.
|
|
|
+ *
|
|
|
+ * This method takes a string or a list of strings which
|
|
|
+ * represent the promise names:
|
|
|
+ *
|
|
|
+ * _converse.api.promises.add('myPromise');
|
|
|
+ *
|
|
|
+ * Your plugin should then, when appropriate, resolve the
|
|
|
+ * promise by calling `_converse.api.emit`, which will also
|
|
|
+ * emit an event with the same name as the promise.
|
|
|
+ * For example:
|
|
|
*
|
|
|
- * NB: These plugins need to have already been loaded via require.js.
|
|
|
+ * _converse.api.trigger('operationCompleted');
|
|
|
*
|
|
|
- * It's possible to make these dependencies "non-optional".
|
|
|
- * If the setting "strict_plugin_dependencies" is set to true,
|
|
|
- * an error will be raised if the plugin is not found.
|
|
|
+ * Other plugins can then either listen for the event
|
|
|
+ * `operationCompleted` like so:
|
|
|
+ *
|
|
|
+ * _converse.api.listen.on('operationCompleted', function { ... });
|
|
|
+ *
|
|
|
+ * or they can wait for the promise to be fulfilled like so:
|
|
|
+ *
|
|
|
+ * _converse.api.waitUntil('operationCompleted', function { ... });
|
|
|
*/
|
|
|
- 'dependencies': [],
|
|
|
+ },
|
|
|
|
|
|
- /* Converse.js's plugin mechanism will call the initialize
|
|
|
- * method on any plugin (if it exists) as soon as the plugin has
|
|
|
- * been loaded.
|
|
|
+ /* If you want to override some function or a Backbone model or
|
|
|
+ * view defined elsewhere in converse.js, then you do that under
|
|
|
+ * the "overrides" namespace.
|
|
|
+ */
|
|
|
+ 'overrides': {
|
|
|
+ /* For example, the private *_converse* object has a
|
|
|
+ * method "onConnected". You can override that method as follows:
|
|
|
*/
|
|
|
- 'initialize': function () {
|
|
|
- /* Inside this method, you have access to the private
|
|
|
- * `_converse` object.
|
|
|
- */
|
|
|
- var _converse = this._converse;
|
|
|
- _converse.log("The \"myplugin\" plugin is being initialized");
|
|
|
-
|
|
|
- /* From the `_converse` object you can get any configuration
|
|
|
- * options that the user might have passed in via
|
|
|
- * `converse.initialize`.
|
|
|
- *
|
|
|
- * You can also specify new configuration settings for this
|
|
|
- * plugin, or override the default values of existing
|
|
|
- * configuration settings. This is done like so:
|
|
|
- */
|
|
|
- _converse.api.settings.update({
|
|
|
- 'initialize_message': 'Initializing myplugin!'
|
|
|
- });
|
|
|
-
|
|
|
- /* The user can then pass in values for the configuration
|
|
|
- * settings when `converse.initialize` gets called.
|
|
|
- * For example:
|
|
|
- *
|
|
|
- * converse.initialize({
|
|
|
- * "initialize_message": "My plugin has been initialized"
|
|
|
- * });
|
|
|
- */
|
|
|
- alert(this._converse.initialize_message);
|
|
|
-
|
|
|
- /* Besides `_converse.api.settings.update`, there is also a
|
|
|
- * `_converse.api.promises.add` method, which allows you to
|
|
|
- * add new promises that your plugin is obligated to fulfill.
|
|
|
- *
|
|
|
- * This method takes a string or a list of strings which
|
|
|
- * represent the promise names:
|
|
|
- *
|
|
|
- * _converse.api.promises.add('myPromise');
|
|
|
- *
|
|
|
- * Your plugin should then, when appropriate, resolve the
|
|
|
- * promise by calling `_converse.api.emit`, which will also
|
|
|
- * emit an event with the same name as the promise.
|
|
|
- * For example:
|
|
|
- *
|
|
|
- * _converse.api.trigger('operationCompleted');
|
|
|
- *
|
|
|
- * Other plugins can then either listen for the event
|
|
|
- * `operationCompleted` like so:
|
|
|
- *
|
|
|
- * _converse.api.listen.on('operationCompleted', function { ... });
|
|
|
- *
|
|
|
- * or they can wait for the promise to be fulfilled like so:
|
|
|
- *
|
|
|
- * _converse.api.waitUntil('operationCompleted', function { ... });
|
|
|
- */
|
|
|
+ 'onConnected': function () {
|
|
|
+ // Overrides the onConnected method in converse.js
|
|
|
+
|
|
|
+ // Top-level functions in "overrides" are bound to the
|
|
|
+ // inner "_converse" object.
|
|
|
+ const _converse = this;
|
|
|
+
|
|
|
+ // Your custom code can come here ...
|
|
|
+
|
|
|
+ // You can access the original function being overridden
|
|
|
+ // via the __super__ attribute.
|
|
|
+ // Make sure to pass on the arguments supplied to this
|
|
|
+ // function and also to apply the proper "this" object.
|
|
|
+ _converse.__super__.onConnected.apply(this, arguments);
|
|
|
+
|
|
|
+ // Your custom code can come here ...
|
|
|
},
|
|
|
|
|
|
- /* If you want to override some function or a Backbone model or
|
|
|
- * view defined elsewhere in converse.js, then you do that under
|
|
|
- * the "overrides" namespace.
|
|
|
+ /* Override converse.js's XMPPStatus Backbone model so that we can override the
|
|
|
+ * function that sends out the presence stanza.
|
|
|
*/
|
|
|
- 'overrides': {
|
|
|
- /* For example, the private *_converse* object has a
|
|
|
- * method "onConnected". You can override that method as follows:
|
|
|
- */
|
|
|
- 'onConnected': function () {
|
|
|
- // Overrides the onConnected method in converse.js
|
|
|
-
|
|
|
- // Top-level functions in "overrides" are bound to the
|
|
|
- // inner "_converse" object.
|
|
|
- var _converse = this;
|
|
|
-
|
|
|
- // Your custom code can come here ...
|
|
|
-
|
|
|
- // You can access the original function being overridden
|
|
|
- // via the __super__ attribute.
|
|
|
- // Make sure to pass on the arguments supplied to this
|
|
|
- // function and also to apply the proper "this" object.
|
|
|
- _converse.__super__.onConnected.apply(this, arguments);
|
|
|
-
|
|
|
- // Your custom code can come here ...
|
|
|
- },
|
|
|
-
|
|
|
- /* Override converse.js's XMPPStatus Backbone model so that we can override the
|
|
|
- * function that sends out the presence stanza.
|
|
|
- */
|
|
|
- 'XMPPStatus': {
|
|
|
- 'sendPresence': function (type, status_message, jid) {
|
|
|
- // The "_converse" object is available via the __super__
|
|
|
- // attribute.
|
|
|
- var _converse = this.__super__._converse;
|
|
|
-
|
|
|
- // Custom code can come here ...
|
|
|
-
|
|
|
- // You can call the original overridden method, by
|
|
|
- // accessing it via the __super__ attribute.
|
|
|
- // When calling it, you need to apply the proper
|
|
|
- // context as reference by the "this" variable.
|
|
|
- this.__super__.sendPresence.apply(this, arguments);
|
|
|
-
|
|
|
- // Custom code can come here ...
|
|
|
- }
|
|
|
+ 'XMPPStatus': {
|
|
|
+ 'sendPresence': function (type, status_message, jid) {
|
|
|
+ // The "_converse" object is available via the __super__
|
|
|
+ // attribute.
|
|
|
+ const _converse = this.__super__._converse;
|
|
|
+
|
|
|
+ // Custom code can come here ...
|
|
|
+
|
|
|
+ // You can call the original overridden method, by
|
|
|
+ // accessing it via the __super__ attribute.
|
|
|
+ // When calling it, you need to apply the proper
|
|
|
+ // context as reference by the "this" variable.
|
|
|
+ this.__super__.sendPresence.apply(this, arguments);
|
|
|
+
|
|
|
+ // Custom code can come here ...
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
- }));
|
|
|
+ }
|
|
|
+ });
|