developer_api.rst 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  1. .. raw:: html
  2. <div id="banner"><a href="https://github.com/jcbrand/converse.js/blob/master/docs/source/theming.rst">Edit me on GitHub</a></div>
  3. =============================
  4. The converse.js developer API
  5. =============================
  6. .. contents:: Table of Contents
  7. :depth: 2
  8. :local:
  9. .. note:: The API documented here is available in Converse.js 0.8.4 and higher.
  10. Earlier versions of Converse.js might have different API methods or none at all.
  11. .. note:: From version 3.0.0 and onwards many API methods have been made
  12. private and available to plugins only. This means that if you want to
  13. use the API, you'll first need to create a plugin from which you can
  14. access it. This change is done to avoid leakage of sensitive data to
  15. malicious or non-whitelisted scripts.
  16. The Converse.js API is broken up into different logical "groupings" (for
  17. example ``converse.plugins`` or ``converse.contacts``).
  18. There are some exceptions to this, like ``converse.initialize``, which aren't
  19. groupings but single methods.
  20. The groupings logically group methods, such as standardised accessors and
  21. mutators::
  22. .get
  23. .set
  24. .add
  25. .remove
  26. So for example, to get a contact, you would do the following::
  27. _converse.contacts.get('jid@example.com');
  28. To get multiple contacts, just pass in an array of jids::
  29. _converse.contacts.get(['jid1@example.com', 'jid2@example.com']);
  30. To get all contacts, simply call ``get`` without any jids::
  31. _converse.contacts.get();
  32. Public API methods
  33. ==================
  34. Publich API methods are those methods that are accessible on the global
  35. ``window.converse`` object. They are public, because any Javascript in the page
  36. can call them. Public methods therefore don't expose any sensitive or closured
  37. data. To do that, you'll need to create a plugin, which has access to the
  38. private API method.
  39. initialize
  40. ----------
  41. .. note:: This method is the one exception of a method which is not logically grouped as explained above.
  42. Publich API method which initializes converse.js.
  43. This method must always be called when using converse.js.
  44. The `initialize` method takes a map of :ref:`configuration-variables`.
  45. Example:
  46. .. code-block:: javascript
  47. converse.initialize({
  48. allow_otr: true,
  49. auto_list_rooms: false,
  50. auto_subscribe: false,
  51. bosh_service_url: 'https://bind.example.com',
  52. hide_muc_server: false,
  53. i18n: locales['en'],
  54. keepalive: true,
  55. play_sounds: true,
  56. prebind: false,
  57. show_controlbox_by_default: true,
  58. debug: false,
  59. roster_groups: true
  60. });
  61. The **plugin** grouping
  62. ------------------------
  63. Exposes methods for adding and removing plugins. You'll need to write a plugin
  64. if you want to have access to the private API methods defined further down below.
  65. For more information on plugins, read the section :ref:`writing-a-plugin`.
  66. add
  67. ~~~
  68. Registers a new plugin.
  69. .. code-block:: javascript
  70. var plugin = {
  71. initialize: function () {
  72. // method on any plugin (if it exists) as soon as the plugin has
  73. // been loaded.
  74. // Inside this method, you have access to the closured
  75. // _converse object, which contains the core logic and data
  76. // structures of converse.js
  77. }
  78. }
  79. converse.plugins.add('myplugin', plugin);
  80. remove
  81. ~~~~~~
  82. Removes a plugin from the registry.
  83. .. code-block:: javascript
  84. converse.plugins.remove('myplugin');
  85. Private API methods
  86. ===================
  87. The private API methods are only accessible via the closured ``_converse``
  88. object, which is only available to plugins.
  89. These methods are kept private (i.e. not global) because they may return
  90. sensitive data which should be kept off-limits to other 3rd-party scripts
  91. that might be running in the page.
  92. .. note:: The example code snippets shown below are a bit contrived. I've added
  93. the minimum plugin boilerplace around the actual example, to show that
  94. these API methods can only be called inside a plugin where the
  95. ``_converse`` object is available. However, sometimes other considerations
  96. need to be made as well. For example, for certain API methods it is
  97. necessary to first wait until the data has been received from the XMPP
  98. server (or from the browser's sessionStorage cache). Due to
  99. time-constriaints these limitations are ignored in the examples below. For
  100. a fuller picture, refer to the section :ref:`events-API` as well.
  101. send
  102. ----
  103. Allows you to send XML stanzas.
  104. For example, to send a message stanza:
  105. .. code-block:: javascript
  106. converse.plugins.add('myplugin', {
  107. initialize: function () {
  108. var msg = converse.env.$msg({
  109. from: 'juliet@example.com/balcony',
  110. to:'romeo@example.net',
  111. type:'chat'
  112. });
  113. this._converse.send(msg);
  114. }
  115. });
  116. The **archive** grouping
  117. ------------------------
  118. Converse.js supports the *Message Archive Management*
  119. (`XEP-0313 <https://xmpp.org/extensions/xep-0313.html>`_) protocol,
  120. through which it is able to query an XMPP server for archived messages.
  121. See also the **message_archiving** option in the :ref:`configuration-variables` section, which you'll usually
  122. want to in conjunction with this API.
  123. query
  124. ~~~~~
  125. The ``query`` method is used to query for archived messages.
  126. It accepts the following optional parameters:
  127. * **options** an object containing the query parameters. Valid query parameters
  128. are ``with``, ``start``, ``end``, ``first``, ``last``, ``after``, ``before``, ``index`` and ``count``.
  129. * **callback** is the callback method that will be called when all the messages
  130. have been received.
  131. * **errback** is the callback method to be called when an error is returned by
  132. the XMPP server, for example when it doesn't support message archiving.
  133. Examples
  134. ^^^^^^^^
  135. **Requesting all archived messages**
  136. The simplest query that can be made is to simply not pass in any parameters.
  137. Such a query will return all archived messages for the current user.
  138. Generally, you'll however always want to pass in a callback method, to receive
  139. the returned messages.
  140. .. code-block:: javascript
  141. converse.plugins.add('myplugin', {
  142. initialize: function () {
  143. var errback = function (iq) {
  144. // The query was not successful, perhaps inform the user?
  145. // The IQ stanza returned by the XMPP server is passed in, so that you
  146. // may inspect it and determine what the problem was.
  147. }
  148. var callback = function (messages) {
  149. // Do something with the messages, like showing them in your webpage.
  150. }
  151. this._converse.archive.query(callback, errback))
  152. }
  153. });
  154. **Waiting until server support has been determined**
  155. The query method will only work if converse.js has been able to determine that
  156. the server supports MAM queries, otherwise the following error will be raised:
  157. - *This server does not support XEP-0313, Message Archive Management*
  158. The very first time converse.js loads in a browser tab, if you call the query
  159. API too quickly, the above error might appear because service discovery has not
  160. yet been completed.
  161. To work solve this problem, you can first listen for the ``serviceDiscovered`` event,
  162. through which you can be informed once support for MAM has been determined.
  163. For example:
  164. .. code-block:: javascript
  165. converse.plugins.add('myplugin', {
  166. initialize: function () {
  167. var _converse = this._converse;
  168. _converse.listen.on('serviceDiscovered', function (feature) {
  169. if (feature.get('var') === converse.env.Strophe.NS.MAM) {
  170. _converse.archive.query()
  171. }
  172. });
  173. }
  174. });
  175. **Requesting all archived messages for a particular contact or room**
  176. To query for messages sent between the current user and another user or room,
  177. the query options need to contain the the JID (Jabber ID) of the user or
  178. room under the ``with`` key.
  179. .. code-block:: javascript
  180. converse.plugins.add('myplugin', {
  181. initialize: function () {
  182. // For a particular user
  183. this._converse.archive.query({'with': 'john@doe.net'}, callback, errback);)
  184. // For a particular room
  185. this._converse.archive.query({'with': 'discuss@conference.doglovers.net'}, callback, errback);)
  186. }
  187. });
  188. **Requesting all archived messages before or after a certain date**
  189. The ``start`` and ``end`` parameters are used to query for messages
  190. within a certain timeframe. The passed in date values may either be ISO8601
  191. formatted date strings, or Javascript Date objects.
  192. .. code-block:: javascript
  193. converse.plugins.add('myplugin', {
  194. initialize: function () {
  195. var options = {
  196. 'with': 'john@doe.net',
  197. 'start': '2010-06-07T00:00:00Z',
  198. 'end': '2010-07-07T13:23:54Z'
  199. };
  200. this._converse.archive.query(options, callback, errback);
  201. }
  202. });
  203. **Limiting the amount of messages returned**
  204. The amount of returned messages may be limited with the ``max`` parameter.
  205. By default, the messages are returned from oldest to newest.
  206. .. code-block:: javascript
  207. converse.plugins.add('myplugin', {
  208. initialize: function () {
  209. // Return maximum 10 archived messages
  210. this._converse.archive.query({'with': 'john@doe.net', 'max':10}, callback, errback);
  211. }
  212. });
  213. **Paging forwards through a set of archived messages**
  214. When limiting the amount of messages returned per query, you might want to
  215. repeatedly make a further query to fetch the next batch of messages.
  216. To simplify this usecase for you, the callback method receives not only an array
  217. with the returned archived messages, but also a special RSM (*Result Set
  218. Management*) object which contains the query parameters you passed in, as well
  219. as two utility methods ``next``, and ``previous``.
  220. When you call one of these utility methods on the returned RSM object, and then
  221. pass the result into a new query, you'll receive the next or previous batch of
  222. archived messages. Please note, when calling these methods, pass in an integer
  223. to limit your results.
  224. .. code-block:: javascript
  225. converse.plugins.add('myplugin', {
  226. initialize: function () {
  227. var _converse = this._converse;
  228. var callback = function (messages, rsm) {
  229. // Do something with the messages, like showing them in your webpage.
  230. // ...
  231. // You can now use the returned "rsm" object, to fetch the next batch of messages:
  232. _converse.archive.query(rsm.next(10), callback, errback))
  233. }
  234. _converse.archive.query({'with': 'john@doe.net', 'max':10}, callback, errback);
  235. }
  236. });
  237. **Paging backwards through a set of archived messages**
  238. To page backwards through the archive, you need to know the UID of the message
  239. which you'd like to page backwards from and then pass that as value for the
  240. ``before`` parameter. If you simply want to page backwards from the most recent
  241. message, pass in the ``before`` parameter with an empty string value ``''``.
  242. .. code-block:: javascript
  243. converse.plugins.add('myplugin', {
  244. initialize: function () {
  245. var _converse = this._converse;
  246. _converse.archive.query({'before': '', 'max':5}, function (message, rsm) {
  247. // Do something with the messages, like showing them in your webpage.
  248. // ...
  249. // You can now use the returned "rsm" object, to fetch the previous batch of messages:
  250. rsm.previous(5); // Call previous method, to update the object's parameters,
  251. // passing in a limit value of 5.
  252. // Now we query again, to get the previous batch.
  253. _converse.archive.query(rsm, callback, errback);
  254. }
  255. }
  256. });
  257. The **connection** grouping
  258. ---------------------------
  259. This grouping collects API functions related to the XMPP connection.
  260. connected
  261. ~~~~~~~~~
  262. A boolean attribute (i.e. not a callable) which is set to `true` or `false` depending
  263. on whether there is an established connection.
  264. disconnect
  265. ~~~~~~~~~~
  266. Terminates the connection.
  267. The **user** grouping
  268. ---------------------
  269. This grouping collects API functions related to the current logged in user.
  270. jid
  271. ~~~
  272. Return's the current user's full JID (Jabber ID).
  273. .. code-block:: javascript
  274. converse.plugins.add('myplugin', {
  275. initialize: function () {
  276. alert(this._converse.user.jid());
  277. }
  278. });
  279. login
  280. ~~~~~
  281. Logs the user in. This method can accept a map with the credentials, like this:
  282. .. code-block:: javascript
  283. converse.plugins.add('myplugin', {
  284. initialize: function () {
  285. this._converse.user.login({
  286. 'jid': 'dummy@example.com',
  287. 'password': 'secret'
  288. });
  289. }
  290. });
  291. or it can be called without any parameters, in which case converse.js will try
  292. to log the user in by calling the `prebind_url` or `credentials_url` depending
  293. on whether prebinding is used or not.
  294. logout
  295. ~~~~~~
  296. Log the user out of the current XMPP session.
  297. .. code-block:: javascript
  298. converse.plugins.add('myplugin', {
  299. initialize: function () {
  300. this._converse.user.logout();
  301. }
  302. });
  303. The **status** sub-grouping
  304. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  305. Set and get the user's chat status, also called their *availability*.
  306. get
  307. ^^^
  308. Return the current user's availability status:
  309. .. code-block:: javascript
  310. converse.plugins.add('myplugin', {
  311. initialize: function () {
  312. alert(this._converse.user.status.get()); // For example "dnd"
  313. }
  314. });
  315. set
  316. ^^^
  317. The user's status can be set to one of the following values:
  318. * **away**
  319. * **dnd**
  320. * **offline**
  321. * **online**
  322. * **unavailable**
  323. * **xa**
  324. For example:
  325. .. code-block:: javascript
  326. converse.plugins.add('myplugin', {
  327. initialize: function () {
  328. this._converse.user.status.set('dnd');
  329. }
  330. });
  331. Because the user's availability is often set together with a custom status
  332. message, this method also allows you to pass in a status message as a
  333. second parameter:
  334. .. code-block:: javascript
  335. converse.plugins.add('myplugin', {
  336. initialize: function () {
  337. this._converse.user.status.set('dnd', 'In a meeting');
  338. }
  339. });
  340. The **message** sub-grouping
  341. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  342. The ``user.status.message`` sub-grouping exposes methods for setting and
  343. retrieving the user's custom status message.
  344. .. code-block:: javascript
  345. converse.plugins.add('myplugin', {
  346. initialize: function () {
  347. this._converse.user.status.message.set('In a meeting');
  348. // Returns "In a meeting"
  349. return this._converse.user.status.message.get();
  350. }
  351. });
  352. The **contacts** grouping
  353. -------------------------
  354. get
  355. ~~~
  356. This method is used to retrieve roster contacts.
  357. To get a single roster contact, call the method with the contact's JID (Jabber ID):
  358. .. code-block:: javascript
  359. converse.plugins.add('myplugin', {
  360. initialize: function () {
  361. var _converse = this._converse;
  362. _converse.on('rosterContactsFetched', function () {
  363. var contact = _converse.contacts.get('buddy@example.com')
  364. });
  365. }
  366. });
  367. To get multiple contacts, pass in an array of JIDs:
  368. .. code-block:: javascript
  369. converse.plugins.add('myplugin', {
  370. initialize: function () {
  371. var _converse = this._converse;
  372. _converse.on('rosterContactsFetched', function () {
  373. var contacts = _converse.contacts.get(
  374. ['buddy1@example.com', 'buddy2@example.com']
  375. )
  376. });
  377. }
  378. });
  379. To return all contacts, simply call ``get`` without any parameters:
  380. .. code-block:: javascript
  381. converse.plugins.add('myplugin', {
  382. initialize: function () {
  383. var _converse = this._converse;
  384. _converse.on('rosterContactsFetched', function () {
  385. var contacts = _converse.contacts.get();
  386. });
  387. }
  388. });
  389. The returned roster contact objects have these attributes:
  390. +----------------+-----------------------------------------------------------------------------------------------------------------+
  391. | Attribute | |
  392. +================+=================================================================================================================+
  393. | ask | If ask === 'subscribe', then we have asked this person to be our chat buddy. |
  394. +----------------+-----------------------------------------------------------------------------------------------------------------+
  395. | fullname | The person's full name. |
  396. +----------------+-----------------------------------------------------------------------------------------------------------------+
  397. | jid | The person's Jabber/XMPP username. |
  398. +----------------+-----------------------------------------------------------------------------------------------------------------+
  399. | requesting | If true, then this person is asking to be our chat buddy. |
  400. +----------------+-----------------------------------------------------------------------------------------------------------------+
  401. | subscription | The subscription state between the current user and this chat buddy. Can be `none`, `to`, `from` or `both`. |
  402. +----------------+-----------------------------------------------------------------------------------------------------------------+
  403. | id | A unique id, same as the jid. |
  404. +----------------+-----------------------------------------------------------------------------------------------------------------+
  405. | chat_status | The person's chat status. Can be `online`, `offline`, `busy`, `xa` (extended away) or `away`. |
  406. +----------------+-----------------------------------------------------------------------------------------------------------------+
  407. | user_id | The user id part of the JID (the part before the `@`). |
  408. +----------------+-----------------------------------------------------------------------------------------------------------------+
  409. | resources | The known resources for this chat buddy. Each resource denotes a separate and connected chat client. |
  410. +----------------+-----------------------------------------------------------------------------------------------------------------+
  411. | groups | The roster groups in which this chat buddy was placed. |
  412. +----------------+-----------------------------------------------------------------------------------------------------------------+
  413. | status | Their human readable custom status message. |
  414. +----------------+-----------------------------------------------------------------------------------------------------------------+
  415. | image_type | The image's file type. |
  416. +----------------+-----------------------------------------------------------------------------------------------------------------+
  417. | image | The Base64 encoded image data. |
  418. +----------------+-----------------------------------------------------------------------------------------------------------------+
  419. | url | The buddy's website URL, as specified in their VCard data. |
  420. +----------------+-----------------------------------------------------------------------------------------------------------------+
  421. | vcard_updated | When last the buddy's VCard was updated. |
  422. +----------------+-----------------------------------------------------------------------------------------------------------------+
  423. add
  424. ~~~
  425. Add a contact.
  426. Provide the JID of the contact you want to add:
  427. .. code-block:: javascript
  428. _converse.contacts.add('buddy@example.com')
  429. You may also provide the fullname. If not present, we use the jid as fullname:
  430. .. code-block:: javascript
  431. _converse.contacts.add('buddy@example.com', 'Buddy')
  432. The **chats** grouping
  433. ----------------------
  434. Note, for MUC chat rooms, you need to use the "rooms" grouping instead.
  435. get
  436. ~~~
  437. Returns an object representing a chat box.
  438. To return a single chat box, provide the JID of the contact you're chatting
  439. with in that chat box:
  440. .. code-block:: javascript
  441. _converse.chats.get('buddy@example.com')
  442. To return an array of chat boxes, provide an array of JIDs:
  443. .. code-block:: javascript
  444. _converse.chats.get(['buddy1@example.com', 'buddy2@example.com'])
  445. To return all open chat boxes, call the method without any JIDs::
  446. _converse.chats.get()
  447. open
  448. ~~~~
  449. Opens a chat box and returns an object representing a chat box.
  450. To open a single chat box, provide the JID of the contact:
  451. .. code-block:: javascript
  452. converse.plugins.add('myplugin', {
  453. initialize: function () {
  454. this._converse.chats.open('buddy@example.com')
  455. }
  456. });
  457. To return an array of chat boxes, provide an array of JIDs:
  458. .. code-block:: javascript
  459. converse.plugins.add('myplugin', {
  460. initialize: function () {
  461. this._converse.chats.open(['buddy1@example.com', 'buddy2@example.com'])
  462. }
  463. });
  464. *The returned chat box object contains the following methods:*
  465. +-------------+------------------------------------------+
  466. | Method | Description |
  467. +=============+==========================================+
  468. | endOTR | End an OTR (Off-the-record) session. |
  469. +-------------+------------------------------------------+
  470. | get | Get an attribute (i.e. accessor). |
  471. +-------------+------------------------------------------+
  472. | initiateOTR | Start an OTR (off-the-record) session. |
  473. +-------------+------------------------------------------+
  474. | maximize | Minimize the chat box. |
  475. +-------------+------------------------------------------+
  476. | minimize | Maximize the chat box. |
  477. +-------------+------------------------------------------+
  478. | set | Set an attribute (i.e. mutator). |
  479. +-------------+------------------------------------------+
  480. | close | Close the chat box. |
  481. +-------------+------------------------------------------+
  482. | open | Opens the chat box. |
  483. +-------------+------------------------------------------+
  484. *The get and set methods can be used to retrieve and change the following attributes:*
  485. +-------------+-----------------------------------------------------+
  486. | Attribute | Description |
  487. +=============+=====================================================+
  488. | height | The height of the chat box. |
  489. +-------------+-----------------------------------------------------+
  490. | url | The URL of the chat box heading. |
  491. +-------------+-----------------------------------------------------+
  492. The **rooms** grouping
  493. ----------------------
  494. get
  495. ~~~
  496. Returns an object representing a multi user chat box (room).
  497. It takes 3 parameters:
  498. * the room JID (if not specified, all rooms will be returned).
  499. * a map (object) containing any extra room attributes For example, if you want
  500. to specify the nickname, use ``{'nick': 'bloodninja'}``. Previously (before
  501. version 1.0.7, the second parameter only accepted the nickname (as a string
  502. value). This is currently still accepted, but then you can't pass in any
  503. other room attributes. If the nickname is not specified then the node part of
  504. the user's JID will be used.
  505. * a boolean, indicating whether the room should be created if not found (default: `false`)
  506. .. code-block:: javascript
  507. converse.plugins.add('myplugin', {
  508. initialize: function () {
  509. var nick = 'dread-pirate-roberts';
  510. var create_if_not_found = true;
  511. this._converse.rooms.open(
  512. 'group@muc.example.com',
  513. {'nick': nick},
  514. create_if_not_found
  515. )
  516. }
  517. });
  518. open
  519. ~~~~
  520. Opens a multi user chat box and returns an object representing it.
  521. Similar to the ``chats.get`` API.
  522. It takes 2 parameters:
  523. * The room JID or JIDs (if not specified, all currently open rooms will be returned).
  524. * A map (object) containing any extra room attributes. For example, if you want
  525. to specify the nickname, use ``{'nick': 'bloodninja'}``.
  526. To open a single multi user chat box, provide the JID of the room:
  527. .. code-block:: javascript
  528. converse.plugins.add('myplugin', {
  529. initialize: function () {
  530. this._converse.rooms.open('group@muc.example.com')
  531. }
  532. });
  533. To return an array of rooms, provide an array of room JIDs:
  534. .. code-block:: javascript
  535. converse.plugins.add('myplugin', {
  536. initialize: function () {
  537. this._converse.rooms.open(['group1@muc.example.com', 'group2@muc.example.com'])
  538. }
  539. });
  540. To setup a custom nickname when joining the room, provide the optional nick argument:
  541. .. code-block:: javascript
  542. converse.plugins.add('myplugin', {
  543. initialize: function () {
  544. this._converse.rooms.open('group@muc.example.com', {'nick': 'mycustomnick'})
  545. }
  546. });
  547. Room attributes that may be passed in:
  548. * *nick*: The nickname to be used
  549. * *auto_configure*: A boolean, indicating whether the room should be configured
  550. automatically or not. If set to ``true``, then it makes sense to pass in
  551. configuration settings.
  552. * *roomconfig*: A map of configuration settings to be used when the room gets
  553. configured automatically. Currently it doesn't make sense to specify
  554. ``roomconfig`` values if ``auto_configure`` is set to ``false``.
  555. For a list of configuration values that can be passed in, refer to these values
  556. in the `XEP-0045 MUC specification <http://xmpp.org/extensions/xep-0045.html#registrar-formtype-owner>`_.
  557. The values should be named without the ``muc#roomconfig_`` prefix.
  558. * *maximize*: A boolean, indicating whether minimized rooms should also be
  559. maximized, when opened. Set to ``false`` by default.
  560. For example, opening a room with a specific default configuration:
  561. .. code-block:: javascript
  562. converse.plugins.add('myplugin', {
  563. initialize: function () {
  564. this._converse.rooms.open(
  565. 'myroom@conference.example.org',
  566. { 'nick': 'coolguy69',
  567. 'auto_configure': true,
  568. 'roomconfig': {
  569. 'changesubject': false,
  570. 'membersonly': true,
  571. 'persistentroom': true,
  572. 'publicroom': true,
  573. 'roomdesc': 'Comfy room for hanging out',
  574. 'whois': 'anyone'
  575. }
  576. },
  577. true
  578. );
  579. }
  580. });
  581. .. note:: `multi-list` configuration values are not yet supported.
  582. close
  583. ~~~~~
  584. Lets you close open chat rooms. You can call this method without any arguments
  585. to close all open chat rooms, or you can specify a single JID or an array of
  586. JIDs.
  587. The **settings** grouping
  588. -------------------------
  589. This grouping allows you to get or set the configuration settings of converse.js.
  590. get(key)
  591. ~~~~~~~~
  592. Returns the value of a configuration settings. For example:
  593. .. code-block:: javascript
  594. converse.plugins.add('myplugin', {
  595. initialize: function () {
  596. // default value would be false;
  597. alert(this._converse.settings.get("play_sounds"));
  598. }
  599. });
  600. set(key, value) or set(object)
  601. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  602. Set one or many configuration settings. For example:
  603. .. code-block:: javascript
  604. converse.plugins.add('myplugin', {
  605. initialize: function () {
  606. this._converse.settings.set("play_sounds", true);
  607. }
  608. });
  609. or :
  610. .. code-block:: javascript
  611. converse.plugins.add('myplugin', {
  612. initialize: function () {
  613. this._converse.settings.set({
  614. "play_sounds", true,
  615. "hide_offline_users" true
  616. });
  617. }
  618. });
  619. Note, this is not an alternative to calling ``converse.initialize``, which still needs
  620. to be called. Generally, you'd use this method after converse.js is already
  621. running and you want to change the configuration on-the-fly.
  622. The **tokens** grouping
  623. -----------------------
  624. get
  625. ~~~
  626. Returns a token, either the RID or SID token depending on what's asked for.
  627. Example:
  628. .. code-block:: javascript
  629. converse.plugins.add('myplugin', {
  630. initialize: function () {
  631. alert(this._converse.tokens.get('rid'));
  632. }
  633. });
  634. .. _`listen-grouping`:
  635. The **listen** grouping
  636. -----------------------
  637. Converse.js emits events to which you can subscribe from your own Javascript.
  638. Concerning events, the following methods are available under the "listen"
  639. grouping:
  640. * **on(eventName, callback, [context])**:
  641. Calling the ``on`` method allows you to subscribe to an event.
  642. Every time the event fires, the callback method specified by ``callback`` will be
  643. called.
  644. Parameters:
  645. * ``eventName`` is the event name as a string.
  646. * ``callback`` is the callback method to be called when the event is emitted.
  647. * ``context`` (optional), the value of the `this` parameter for the callback.
  648. For example:
  649. .. code-block:: javascript
  650. _converse.listen.on('message', function (messageXML) { ... });
  651. * **once(eventName, callback, [context])**:
  652. Calling the ``once`` method allows you to listen to an event
  653. exactly once.
  654. Parameters:
  655. * ``eventName`` is the event name as a string.
  656. * ``callback`` is the callback method to be called when the event is emitted.
  657. * ``context`` (optional), the value of the `this` parameter for the callback.
  658. For example:
  659. .. code-block:: javascript
  660. _converse.listen.once('message', function (messageXML) { ... });
  661. * **not(eventName, callback)**
  662. To stop listening to an event, you can use the ``not`` method.
  663. Parameters:
  664. * ``eventName`` is the event name as a string.
  665. * ``callback`` refers to the function that is to be no longer executed.
  666. For example:
  667. .. code-block:: javascript
  668. _converse.listen.not('message', function (messageXML) { ... });