index.rst 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. .. Converse.js documentation master file, created by
  2. sphinx-quickstart on Fri Apr 26 20:48:03 2013.
  3. You can adapt this file completely to your liking, but it should at least
  4. contain the root `toctree` directive.
  5. .. toctree::
  6. :maxdepth: 2
  7. .. contents:: Table of Contents
  8. :depth: 3
  9. :local:
  10. =========================================
  11. Quickstart (to get a demo up and running)
  12. =========================================
  13. When you download a specific release of *Converse.js* there will be two minified files inside the zip file.
  14. * converse.min.js
  15. * converse.min.css
  16. You can include these two files inside the *<head>* element of your website via the *script* and *link*
  17. tags:
  18. ::
  19. <link rel="stylesheet" type="text/css" media="screen" href="converse.min.css">
  20. <script src="converse.min.js"></script>
  21. You need to initialize Converse.js with configuration settings particular to
  22. your requirements.
  23. Please refer to the `Configuration variables`_ section further below for info on
  24. all the available configuration settings.
  25. To do this, put the following inline Javascript code at the
  26. bottom of your page (after the closing *</body>* element).
  27. ::
  28. require(['converse'], function (converse) {
  29. converse.initialize({
  30. auto_list_rooms: false,
  31. auto_subscribe: false,
  32. bosh_service_url: 'https://bind.opkode.im', // Please use this connection manager only for testing purposes
  33. hide_muc_server: false,
  34. i18n: locales.en, // Refer to ./locale/locales.js to see which locales are supported
  35. prebind: false,
  36. show_controlbox_by_default: true,
  37. xhr_user_search: false
  38. });
  39. });
  40. Finally, Converse.js requires a special snippet of HTML markup to be included in your page:
  41. ::
  42. <div id="conversejs"></div>
  43. The `index.html <https://github.com/jcbrand/converse.js/blob/master/index.html>`_ file inside the
  44. Converse.js repository serves as a nice usable example of this.
  45. These minified files provide the same demo-like functionality as is available
  46. on the `conversejs.org <http://conversejs.org>`_ website. Useful for testing or demoing, but not very
  47. practical.
  48. You'll most likely want to implement some kind of single-signon solution for
  49. your website, where users authenticate once in your website and then stay
  50. logged into their XMPP session upon page reload.
  51. For more info on this, read: `Pre-binding and Single Session Support`_.
  52. You might also want to have more fine-grained control of what gets included in
  53. the minified Javascript file. Read `Configuration`_ and `Minification`_ for more info on how to do
  54. that.
  55. ============
  56. Introduction
  57. ============
  58. Even though you can connect to public XMPP servers on the `conversejs.org`_
  59. website, *Converse.js* is not really meant to be a "Software-as-a-service" (SaaS)
  60. webchat.
  61. Instead, its goal is to provide the means for website owners to add a tightly
  62. integrated instant messaging service to their own sites.
  63. As a website owner, you are expected to host *Converse.js* yourself, and to do some legwork to
  64. properly configure and integrate it into your site.
  65. The benefit in doing this, is that your users have a much more streamlined and integrated
  66. webchat experience and that you have control over the data. The latter being a
  67. requirement for many sites dealing with sensitive information.
  68. You'll need to set up your own XMPP server and in order to have
  69. `Session Support`_ (i.e. single-signon functionality whereby users are authenticated once and stay
  70. logged in to XMPP upon page reload) you will also have to add some server-side
  71. code.
  72. The `What you will need`_ section has more information on all these
  73. requirements.
  74. ==================
  75. What you will need
  76. ==================
  77. An XMPP/Jabber server
  78. =====================
  79. *Converse.js* implements `XMPP`_ as its messaging protocol, and therefore needs
  80. to connect to an XMPP/Jabber server (Jabber is really just a synonym for XMPP).
  81. You can connect to public XMPP servers like ``jabber.org`` but if you want to
  82. have `Session Support`_ you'll have to set up your own XMPP server.
  83. You can find a list of public XMPP servers/providers on `xmpp.net`_ and a list of
  84. servers that you can set up yourself on `xmpp.org`_.
  85. Connection Manager
  86. ==================
  87. Your website and *Converse.js* use `HTTP`_ as protocol to communicate with
  88. the webserver. HTTP connections are stateless and usually shortlived.
  89. `XMPP`_ on the other hand, is the protocol that enables instant messaging, and
  90. its connections are stateful and usually longer.
  91. To enable a web application like *Converse.js* to communicate with an XMPP
  92. server, we need a proxy in the middle that can act as a bridge between the two
  93. protocols.
  94. This is the job of a connection manager. A connection manager can be either a
  95. standalone application or part of an XMPP server. `ejabberd`_ for example,
  96. includes a connection manager (but you have to enable it).
  97. The demo on the `Converse.js homepage`_ uses a a connection manager located at https://bind.opkode.im.
  98. This connection manager is for testing purposes only, please don't use it in
  99. production.
  100. Overcoming cross-domain request restrictions
  101. --------------------------------------------
  102. The domain of the *Converse.js* demo is *conversejs.org*, but the domain of the connection manager is *opkode.im*.
  103. HTTP requests are made by *Converse.js* to the connection manager via XmlHttpRequests (XHR).
  104. Until recently, it was not possible to make such requests to a different domain
  105. than the one currently being served (to prevent XSS attacks).
  106. Luckily there is now a standard called `CORS`_ (Cross-origin resource sharing), which enables exactly that.
  107. Modern browsers support CORS, but there are problems with Internet Explorer <
  108. 10.
  109. IE 8 and 9 partially support CORS via a proprietary implementation called
  110. XDomainRequest. There is a `Strophe.js plugin`_ which you can use to enable
  111. support for XDomainRequest when it is present.
  112. In IE < 8, there is no support for CORS.
  113. Instead of using CORS, you can add a reverse proxy in
  114. Apache/Nginx which serves the connection manager under the same domain as your
  115. website. This will remove the need for any cross-domain XHR support.
  116. For example:
  117. ~~~~~~~~~~~~
  118. Assuming your site is accessible on port ``80`` for the domain ``mysite.com``
  119. and your connection manager manager is running at ``someothersite.com/http-bind``.
  120. The *bosh_service_url* value you want to give Converse.js to overcome
  121. the cross-domain restriction is ``mysite.com/http-bind`` and not
  122. ``someothersite.com/http-bind``.
  123. Your ``nginx`` or ``apache`` configuration will look as follows:
  124. Nginx
  125. ~~~~~
  126. ::
  127. http {
  128. server {
  129. listen 80
  130. server_name mysite.com;
  131. location ~ ^/http-bind/ {
  132. proxy_pass http://someothersite.com;
  133. }
  134. }
  135. }
  136. Apache
  137. ~~~~~~
  138. ::
  139. <VirtualHost *:80>
  140. ServerName mysite.com
  141. RewriteEngine On
  142. RewriteRule ^/http-bind(.*) http://someothersite.com/http-bind$1 [P,L]
  143. </VirtualHost>
  144. Server-side authentication
  145. ==========================
  146. .. _`Session Support`:
  147. Prebinding and Single Session Support
  148. -------------------------------------
  149. It's possible to enable single-site login, whereby users already
  150. authenticated in your website will also automatically be logged in on the chat server,
  151. This session should also persist across page loads. In other words, we don't
  152. want the user to have to give their chat credentials every time they reload the
  153. page.
  154. To do this you will require a `BOSH server <http://xmpp.org/about-xmpp/technology-overview/bosh/>`_
  155. for converse.js to connect to (see the `bosh_service_url`_ under `Configuration variables`_)
  156. as well as a BOSH client on your own server (written for example in Python, Ruby or PHP) that will
  157. do the pre-authentication before the web page loads.
  158. .. note::
  159. A BOSH server acts as a bridge between HTTP, the protocol of the web, and
  160. XMPP, the instant messaging protocol.
  161. Converse.js can only communicate via HTTP, but we need to communicate with
  162. an XMPP server in order to chat. So the BOSH server acts as a middle man,
  163. translating our HTTP requests into XMPP stanzas and vice versa.
  164. Jack Moffitt has a great `blogpost`_ about this and even provides an `example Django application`_ to demonstrate it.
  165. When you authenticate to the XMPP server on your backend application (for
  166. example via a BOSH client in Django), you'll receive two tokens, RID (request ID) and SID (session ID).
  167. The **Session ID (SID)** is a unique identifier for the current *session*. This
  168. number stays constant for the entire session.
  169. The **Request ID (RID)** is a unique identifier for the current *request* (i.e.
  170. page load). Each page load is a new request which requires a new unique RID.
  171. The best way to achieve this is to simply increment the RID with each page
  172. load.
  173. When you initialize converse.js in your browser, you need to pass it these two
  174. tokens. Converse.js will then use them to attach to the session you just
  175. created.
  176. You can embed the RID and SID tokens in your HTML markup or you can do an
  177. XMLHttpRequest call to your server and ask it to return them for you.
  178. Below is one example of how this could work. An Ajax call is made to the
  179. relative URL **/prebind** and it expects to receive JSON data back.
  180. ::
  181. $.getJSON('/prebind', function (data) {
  182. converse.initialize({
  183. prebind: true,
  184. bosh_service_url: data.bosh_service_url,
  185. jid: data.jid,
  186. sid: data.sid,
  187. rid: data.rid
  188. });
  189. );
  190. **Here's what's happening:**
  191. The JSON data returned from the Ajax call to example.com/prebind contains the user's JID (jabber ID), RID, SID and the URL to the
  192. BOSH server (also called a *connection manager*).
  193. These values are then passed to converse.js's ``initialize`` method.
  194. .. note::
  195. If you want to enable single session support, you need to set **prebind: true**
  196. when calling **converse.initialize** (see ./index.html).
  197. Additionally you need to pass in valid **jid**, **sid**, **rid** and
  198. **bosh_service_url** values.
  199. Example code for server-side prebinding
  200. ---------------------------------------
  201. * PHP:
  202. See `xmpp-prebind-php <https://github.com/candy-chat/xmpp-prebind-php>`_ by
  203. Michael Weibel and the folks from Candy chat.
  204. * Python:
  205. See this `example Django application`_ by Jack Moffitt.
  206. Setting up a BOSH server
  207. ------------------------
  208. The `Movim <http://movim.eu/>`_ project wiki has a very thorough page on setting up a BOSH server for
  209. a wide variety of standalone or XMPP servers.
  210. http://wiki.movim.eu/manual:bosh_servers
  211. Facebook integration
  212. ====================
  213. .. Note ::
  214. It should be possible to integrate Converse.js with Facebook chat, and
  215. below I'll provide some tips and documentation on how to achieve this. That
  216. said, I don't have a Facebook account and therefore haven't tried to do
  217. this myself. Feedback and patches from people who have succesfully done this
  218. will be appreciated.
  219. Converse.js uses `Strophe.js <http://strophe.im/strophejs>`_ to connect and
  220. communicate with the XMPP server. One nice thing about Strophe.js is that it
  221. can be extended via `plugins <http://github.com/strophe/strophejs-plugins>`_.
  222. Here is a `plugin for authenticating with facebook
  223. <https://github.com/kissrobber/turedsocial/blob/master/strophe-plugins/src/facebook.js>`_.
  224. You will need your own BOSH connection manager to act as a proxy between
  225. Converse.js/Strophe.js and Facebook's XMPP server. That is because Facebook's
  226. XMPP server doesn't support BOSH natively.
  227. The BOSH connection manager that I make available for
  228. testing purposes (at https://bind.opkode.im) uses `Punjab <https://github.com/twonds/punjab>`_,
  229. although there are quite a few other options available as well.
  230. When you configure Converse.js, via its ``initialize`` method, you must specify the
  231. `bosh_service_url`_ value, which is to be your BOSH connection manager.
  232. Please note, to enable Facebook integration, you'll have to
  233. get your hands dirty and modify Converse.js's code, so that it calls the
  234. ``facebookConnect`` method of the plugin above.
  235. The plugin above gives the following code example for you to meditate upon:
  236. ::
  237. connection = new Strophe.Connection("http://localhost:5280/bosh");
  238. connection.facebookConnect(
  239. "12345@chat.facebook.com",
  240. onConnectFacebook,
  241. 300,
  242. 1,
  243. '5e64a30272af065bd72258c565a03f2f',
  244. '8147a27e4a7f9b55ffc85c2683f9529a',
  245. FB.getSession().session_key
  246. );
  247. The connection is already created inside Converse.js, so the
  248. ``facebookConnect`` method needs to also be called from there.
  249. If someone submits a sane patch that does the above, I'll be happy to merge it.
  250. Until then, people will have to do this themselves.
  251. ========
  252. Features
  253. ========
  254. Off-the-record encryption
  255. =========================
  256. Converse.js supports `Off-the-record (OTR) <https://otr.cypherpunks.ca/>`_
  257. encrypted messaging.
  258. The OTR protocol not only **encrypts your messages**, it provides ways to
  259. **verify the identity** of the person you are talking to,
  260. **plausible deniability** and **perfect forward secrecy** by generating
  261. new encryption keys for each conversation.
  262. In its current state, Javascript cryptography is fraught with dangers and
  263. challenges that make it impossible to reach the same standard of security that
  264. is available with native "desktop" software.
  265. This is due to its runtime malleability, the way it is "installed" (e.g.
  266. served) and the browser's lack of cryptographic primitives needed to implement
  267. secure crypto.
  268. For harsh but fairly valid criticism of Javascript cryptography, read:
  269. `Javascript Cryptography Considered Harmful <http://www.matasano.com/articles/javascript-cryptography/>`_.
  270. To get an idea on how this applies to OTR support in Converse.js, please read
  271. `my thoughts on it <https://opkode.com/media/blog/2013/11/11/conversejs-otr-support>`_.
  272. For now, suffice to say that although its useful to have OTR support in
  273. Converse.js in order to avoid most eavesdroppers, if you need serious
  274. communications privacy, then you're much better off using native software.
  275. ===========
  276. Development
  277. ===========
  278. If you want to work with the non-minified Javascript and CSS files you'll soon
  279. notice that there are references to a missing *components* folder. Please
  280. follow the instructions below to create this folder and fetch Converse's
  281. 3rd-party dependencies.
  282. Install Node.js and development dependencies
  283. ============================================
  284. We use development tools (`Grunt <http://gruntjs.com>`_ and `Bower <http://bower.io>`_)
  285. which depend on Node.js and npm (the Node package manager).
  286. If you don't have Node.js installed, you can download and install the latest
  287. version `here <https://nodejs.org/download>`_.
  288. Once you have Node.js installed, run the following command inside the Converse.js
  289. directory:
  290. ::
  291. npm install
  292. This will install all the development dependencies for Converse.js. If you are
  293. curious to know what these are, take a look at whats under the *devDependencies* key in
  294. `package.json <https://github.com/jcbrand/converse.js/blob/master/package.json>`.
  295. Install 3rd party dependencies
  296. ==============================
  297. After running ``npm install``, you will now have Grunt and Bower installed.
  298. We use Bower to manage Converse's front-end dependencies (e.g. Javascript that
  299. should get loaded in the browser).
  300. To fetch these dependencies, run:
  301. ::
  302. grunt fetch
  303. If you don't have grunt installed globally, you need to specify the relative
  304. path:
  305. ::
  306. ./node_modules/.bin/grunt fetch
  307. This will call Bower in the background to fetch all the front-end
  308. dependencies (like backbone.js, strophe.js etc.) and then put them in the
  309. *components* folder.
  310. With AMD and require.js (recommended)
  311. =====================================
  312. Converse.js uses `require.js <http://requirejs.org>`_ to asynchronously load dependencies.
  313. If you want to develop or customize converse.js, you'll want to load the
  314. non-minified javascript files.
  315. Add the following two lines to the *<head>* section of your webpage:
  316. ::
  317. <link rel="stylesheet" type="text/css" media="screen" href="converse.css">
  318. <script data-main="main" src="components/requirejs/require.js"></script>
  319. require.js will then let the main.js file be parsed (because of the *data-main*
  320. attribute on the *script* tag), which will in turn cause converse.js to be
  321. parsed.
  322. Without AMD and require.js
  323. ==========================
  324. Converse.js can also be used without require.js. If you for some reason prefer
  325. to use it this way, please refer to
  326. `non_amd.html <https://github.com/jcbrand/converse.js/blob/master/non_amd.html>`_
  327. for an example of how and in what order all the Javascript files that converse.js
  328. depends on need to be loaded.
  329. Before submitting a pull request
  330. ================================
  331. Add tests for your bugfix or feature
  332. ------------------------------------
  333. Add a test for any bug fixed or feature added. We use Jasmine
  334. for testing.
  335. Take a look at ``tests.html`` and ``spec/MainSpec.js`` to see how
  336. the tests are implemented.
  337. If you are unsure how to write tests, please
  338. `contact me <http://opkode.com/contact>`_ and I'll be happy to help.
  339. Check that the tests pass
  340. -------------------------
  341. Check that the Jasmine tests complete sucessfully. Open
  342. `tests.html <https://github.com/jcbrand/converse.js/blob/master/tests.html>`_
  343. in your browser, and the tests will run automatically.
  344. On the command line you can run:
  345. ::
  346. grunt test
  347. Check your code for errors or bad habits by running JSHint
  348. ----------------------------------------------------------
  349. `JSHint <http://jshint.com>`_ will do a static analysis of your code and hightlight potential errors
  350. and/or bad habits.
  351. ::
  352. grunt jshint
  353. You can run both the tests and jshint in one go by calling:
  354. ::
  355. grunt check
  356. Minification
  357. ============
  358. Minifying Javascript and CSS
  359. ----------------------------
  360. Please make sure to read the section `Development`_ and that you have installed
  361. all development dependencies (long story short, you can run ``npm install``
  362. and then ``grunt fetch``).
  363. We use `require.js`_ to keep track of *Converse.js* and its dependencies and to
  364. to bundle them together in a single minified file fit for deployment to a
  365. production site.
  366. To minify the Javascript and CSS, run the following command:
  367. ::
  368. grunt minify
  369. Javascript will be bundled and minified with `require.js`_'s optimization tool,
  370. using `almond <https://github.com/jrburke/almond>`_.
  371. You can `read more about require.js's optimizer here`_.
  372. CSS is minified via `cssmin <https://github.com/gruntjs/grunt-contrib-cssmin>`_.
  373. Translations
  374. ============
  375. .. Note ::
  376. Translations take up a lot of space and will bloat your minified file.
  377. At the time of writing, all the translations add about 50KB of extra data to
  378. the minified javascript file. Therefore, make sure to only
  379. include those languages that you intend to support and remove from
  380. ./locale/locales.js those which you don't need. Remember to rebuild the
  381. minified file afterwards.
  382. The gettext POT file located in ./locale/converse.pot is the template
  383. containing all translations and from which for each language an individual PO
  384. file is generated.
  385. The POT file contains all translateable strings extracted from converse.js.
  386. To make a user facing string translateable, wrap it in the double underscore helper
  387. function like so:
  388. ::
  389. __('This string will be translated at runtime');
  390. After adding the string, you'll need to regenerate the POT file, like so:
  391. ::
  392. make pot
  393. You can then create or update the PO file for a specific language by doing the following:
  394. ::
  395. msgmerge ./locale/de/LC_MESSAGES/converse.po ./locale/converse.pot -U
  396. To do this for ALL languages, run:
  397. ::
  398. make merge
  399. The resulting PO file is then what gets translated.
  400. If you've created a new PO file, please make sure to add the following
  401. attributes at the top of the file (under *Content-Transfer-Encoding*). They are
  402. required as configuration settings for Jed, the Javascript translations library
  403. that we're using.
  404. ::
  405. "domain: converse\n"
  406. "lang: de\n"
  407. "plural_forms: nplurals=2; plural=(n != 1);\n"
  408. Unfortunately `Jed <http://slexaxton.github.io/Jed>`_ cannot use the PO files directly. We have to generate from it
  409. a file in JSON format and then put that in a .js file for the specific
  410. language.
  411. To generate JSON from a PO file, you'll need po2json for node.js. Run the
  412. following command to install it (npm being the node.js package manager):
  413. ::
  414. npm install po2json
  415. You can then convert the translations into JSON format:
  416. ::
  417. po2json locale/de/LC_MESSAGES/converse.po locale/de/LC_MESSAGES/converse.json
  418. Now from converse.json paste the data as a value for the "locale_data" key in the
  419. object in the language's .js file.
  420. So, if you are for example translating into German (language code 'de'), you'll
  421. create or update the file ./locale/LC_MESSAGES/de.js with the following code:
  422. ::
  423. (function (root, factory) {
  424. define("de", ['jed'], function () {
  425. return factory(new Jed({
  426. "domain": "converse",
  427. "locale_data": {
  428. // Paste the JSON data from converse.json here
  429. }
  430. })
  431. }
  432. }(this, function (i18n) {
  433. return i18n;
  434. }));
  435. making sure to also paste the JSON data as value to the "locale_data" key.
  436. .. Note ::
  437. If you are adding translations for a new language that is not already supported,
  438. you'll have to make one more edit in ./locale/locales.js to make sure the
  439. language is loaded by require.js.
  440. Congratulations, you've now succesfully added your translations. Sorry for all
  441. those hoops you had to jump through.
  442. ===============
  443. Troubleshooting
  444. ===============
  445. Conflicts with other Javascript libraries
  446. =========================================
  447. Problem:
  448. ---------
  449. You are using other Javascript libraries (like JQuery plugins), and
  450. get errors like these in your browser console::
  451. Uncaught TypeError: Object [object Object] has no method 'xxx' from example.js
  452. Solution:
  453. ---------
  454. First, find out which object is referred to by ``Object [object Object]``.
  455. It will probably be the jQuery object ``$`` or perhaps the underscore.js object ``_``.
  456. For the purpose of demonstration, I'm going to assume its ``$``, but the same
  457. rules apply if its something else.
  458. The bundled and minified default build of converse.js, ``converse.min.js``
  459. includes within it all of converse.js's dependencies, which include for example *jQuery*.
  460. If you are having conflicts where attributes or methods aren't available
  461. on the jQuery object, you are probably loading ``converse.min.js`` (which
  462. includes jQuery) as well as your own jQuery version separately.
  463. What then happens is that there are two ``$`` objects (one from
  464. converse.js and one from the jQuery version you included manually)
  465. and only one of them has been extended to have the methods or attributes you require.
  466. Which jQuery object you get depends on the order in which you load the libraries.
  467. There are multiple ways to solve this issue.
  468. Firstly, make sure whether you really need to include a separate version of
  469. jQuery. Chances are that you don't. If you can remove the separate
  470. version, your problem should be solved, as long as your libraries are loaded in
  471. the right order.
  472. Either case, whether you need to keep two versions or not, the solution depends
  473. on whether you'll use require.js to manage your libraries or whether you'll
  474. load them manually.
  475. With require.js
  476. ~~~~~~~~~~~~~~~
  477. Instead of using ``converse.min.js``, manage all the libraries in your project
  478. (i.e. converse.js and its dependencies plus all other libraries you use) as one
  479. require.js project, making sure everything is loaded in the correct order.
  480. Then, before deployment, you make your own custom minified build that bundles everything
  481. you need.
  482. With <script> tags
  483. ~~~~~~~~~~~~~~~~~~
  484. Take a look at `non_amd.html <https://github.com/jcbrand/converse.js/blob/master/non_amd.html>`_
  485. in the converse.js repo.
  486. It shows in which order the libraries must be loaded via ``<script>`` tags. Add
  487. your own libraries, making sure that they are loaded in the correct order (e.g.
  488. jQuery plugins must load after jQuery).
  489. ======
  490. Events
  491. ======
  492. Converse.js emits events to which you can subscribe from your own Javascript.
  493. Concerning events, the following methods are available:
  494. Event Methods
  495. =============
  496. * **on(eventName, callback)**:
  497. Calling the ``on`` method allows you to subscribe to an event.
  498. Every time the event fires, the callback method specified by ``callback`` will be
  499. called.
  500. Parameters:
  501. * ``eventName`` is the event name as a string.
  502. * ``callback`` is the callback method to be called when the event is emitted.
  503. For example::
  504. converse.on('onMessage', function (messageXML) { ... });
  505. * **once(eventName, callback)**:
  506. Calling the ``once`` method allows you to listen to an event
  507. exactly once.
  508. Parameters:
  509. * ``eventName`` is the event name as a string.
  510. * ``callback`` is the callback method to be called when the event is emitted.
  511. For example::
  512. converse.once('onMessage', function (messageXML) { ... });
  513. * **off(eventName, callback)**
  514. To stop listening to an event, you can use the ``off`` method.
  515. Parameters:
  516. * ``eventName`` is the event name as a string.
  517. * ``callback`` refers to the function that is to be no longer executed.
  518. Event Types
  519. ===========
  520. Here are the different events that are emitted:
  521. * **onInitialized**
  522. ``converse.on('onInitialized', function () { ... });``
  523. Triggered once converse.js has been initialized.
  524. * **onReady**
  525. Triggered after a connection has been established and converse.js has
  526. got all its ducks in a row.
  527. ``converse.on('onReady', function () { ... });``
  528. * **onMessage**
  529. ``converse.on('onMessage', function (messageXML) { ... });``
  530. Triggered when a message is received.
  531. * **onMessageSend**
  532. ``converse.on('onMessageSend', function (messageText) { ... });``
  533. Triggered when a message will be sent out.
  534. * **onRoster**
  535. ``converse.on('onRoster', function (items) { ... });``
  536. Triggered when the roster is updated.
  537. * **onRosterViewUpdated**
  538. ``converse.on('onRosterViewUpdated', function (items) { ... });``
  539. Triggered whenever the roster view (i.e. the rendered HTML) has changed.
  540. * **onChatBoxFocused**
  541. ``converse.on('onChatBoxFocused', function (chatbox) { ... });``
  542. Triggered when the focus has been moved to a chat box.
  543. * **onChatBoxOpened**
  544. ``converse.on('onChatBoxOpened', function (chatbox) { ... });``
  545. Triggered when a chat box has been opened.
  546. * **onChatBoxClosed**
  547. ``converse.on('onChatBoxClosed', function (chatbox) { ... });``
  548. Triggered when a chat box has been closed.
  549. * **onStatusChanged**
  550. ``converse.on('onStatusChanged', function (status) { ... });``
  551. Triggered when own chat status has changed.
  552. * **onStatusMessageChanged**
  553. ``converse.on('onStatusMessageChanged', function (message) { ... });``
  554. Triggered when own custom status message has changed.
  555. * **onBuddyStatusChanged**
  556. ``converse.on('onBuddyStatusChanged', function (buddy, status) { ... });``
  557. Triggered when a chat buddy's chat status has changed.
  558. * **onBuddyStatusMessageChanged**
  559. ``converse.on('onBuddyStatusMessageChanged', function (buddy, messageText) { ... });``
  560. Triggered when a chat buddy's custom status message has changed.
  561. =============
  562. Configuration
  563. =============
  564. The included minified JS and CSS files can be used for demoing or testing, but
  565. you'll want to configure *Converse.js* to suit your needs before you deploy it
  566. on your website.
  567. *Converse.js* is passed its configuration settings when you call its
  568. *initialize* method.
  569. You'll most likely want to call the *initialize* method in your HTML page. For
  570. an example of how this is done, please see the bottom of the *./index.html* page.
  571. Please refer to the `Configuration variables`_ section below for info on
  572. all the available configuration settings.
  573. After you have configured *Converse.js*, you'll have to regenerate the minified
  574. JS file so that it will include the new settings. Please refer to the
  575. `Minification`_ section for more info on how to do this.
  576. Configuration variables
  577. =======================
  578. allow_contact_requests
  579. ----------------------
  580. Default = ``true``
  581. Allow users to add one another as contacts. If this is set to false, the
  582. **Add a contact** widget, **Contact Requests** and **Pending Contacts** roster
  583. sections will all not appear. Additionally, all incoming contact requests will be
  584. ignored.
  585. allow_muc
  586. ---------
  587. Default = ``true``
  588. Allow multi-user chat (muc) in chatrooms. Setting this to ``false`` will remove
  589. the ``Chatrooms`` tab from the control box.
  590. animate
  591. -------
  592. Default = ``true``
  593. Show animations, for example when opening and closing chat boxes.
  594. auto_list_rooms
  595. ---------------
  596. Default = ``false``
  597. If true, and the XMPP server on which the current user is logged in supports
  598. multi-user chat, then a list of rooms on that server will be fetched.
  599. Not recommended for servers with lots of chat rooms.
  600. For each room on the server a query is made to fetch further details (e.g.
  601. features, number of occupants etc.), so on servers with many rooms this
  602. option will create lots of extra connection traffic.
  603. auto_reconnect
  604. --------------
  605. Default = ``true``
  606. Automatically reconnect to the XMPP server if the connection drops
  607. unexpectedly.
  608. auto_subscribe
  609. --------------
  610. Default = ``false``
  611. If true, the user will automatically subscribe back to any contact requests.
  612. bosh_service_url
  613. ----------------
  614. Connections to an XMPP server depend on a BOSH connection manager which acts as
  615. a middle man between HTTP and XMPP.
  616. See `here <http://metajack.im/2008/09/08/which-bosh-server-do-you-need>`_ for more information.
  617. cache_otr_key
  618. -------------
  619. Default = ``false``
  620. Let the `OTR (Off-the-record encryption) <https://otr.cypherpunks.ca>`_ private
  621. key be cached in your browser's session storage.
  622. The browser's session storage persists across page loads but is deleted once
  623. the tab or window is closed.
  624. If this option is set to ``false``, a new OTR private key will be generated
  625. for each page load. While more inconvenient, this is a much more secure option.
  626. This setting can only be used together with ``allow_otr = true``.
  627. .. Note ::
  628. A browser window's session storage is accessible by all javascript that
  629. is served from the same domain. So if there is malicious javascript served by
  630. the same server (or somehow injected via an attacker), then they will be able
  631. to retrieve your private key and read your all the chat messages in your
  632. current session. Previous sessions however cannot be decrypted.
  633. debug
  634. -----
  635. Default = ``false``
  636. If set to true, debugging output will be logged to the browser console.
  637. expose_rid_and_sid
  638. ------------------
  639. Allow the prebind tokens, RID (request ID) and SID (session ID), to be exposed
  640. globally via the API. This allows other scripts served on the same page to use
  641. these values.
  642. *Beware*: a malicious script could use these tokens to assume your identity
  643. and inject fake chat messages.
  644. fullname
  645. --------
  646. If you are using prebinding, can specify the fullname of the currently
  647. logged in user, otherwise the user's vCard will be fetched.
  648. hide_muc_server
  649. ---------------
  650. Default = ``false``
  651. Hide the ``server`` input field of the form inside the ``Room`` panel of the
  652. controlbox. Useful if you want to restrict users to a specific XMPP server of
  653. your choosing.
  654. i18n
  655. ----
  656. Specify the locale/language. The language must be in the ``locales`` object. Refer to
  657. ``./locale/locales.js`` to see which locales are supported.
  658. prebind
  659. --------
  660. Default = ``false``
  661. Use this option when you want to attach to an existing XMPP connection that was
  662. already authenticated (usually on the backend before page load).
  663. This is useful when you don't want to render the login form on the chat control
  664. box with each page load.
  665. For prebinding to work, your backend server must authenticate for you, and
  666. then return a JID (jabber ID), SID (session ID) and RID (Request ID).
  667. If you set ``prebind`` to ``true``, you have to make sure to also pass in these
  668. values as ``jid``, ``sid``, ``rid``.
  669. Additionally, you have to specify ``bosh_service_url``.
  670. show_controlbox_by_default
  671. --------------------------
  672. Default = ``false``
  673. The "controlbox" refers to the special chatbox containing your contacts roster,
  674. status widget, chatrooms and other controls.
  675. By default this box is hidden and can be toggled by clicking on any element in
  676. the page with class *toggle-online-users*.
  677. If this options is set to true, the controlbox will by default be shown upon
  678. page load.
  679. show_call_button
  680. ----------------
  681. Default = ``false``
  682. Enable to display a call button on the chatbox toolbar.
  683. When the call button is pressed, it will emit an event that can be used by a third-party library to initiate a call.
  684. ::
  685. converse.on('onCallButtonClicked', function(event, data) {
  686. console.log('Call button was clicked.');
  687. console.log('Strophe connection is', data.connection);
  688. console.log('Bare buddy JID is', data.model.get('jid'));
  689. // ... Third-party library code ...
  690. });
  691. show_only_online_users
  692. ----------------------
  693. Default = ``false``
  694. If set to ``true``, only online users will be shown in the contacts roster.
  695. Users with any other status (e.g. away, busy etc.) will not be shown.
  696. use_otr_by_default
  697. ------------------
  698. Default = ``false``
  699. If set to ``true``, Converse.js will automatically try to initiate an OTR (off-the-record)
  700. encrypted chat session every time you open a chat box.
  701. use_vcards
  702. ----------
  703. Default = ``true``
  704. Determines whether the XMPP server will be queried for roster contacts' VCards
  705. or not. VCards contain extra personal information such as your fullname and
  706. avatar image.
  707. xhr_custom_status
  708. -----------------
  709. Default = ``false``
  710. .. Note ::
  711. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  712. This option will let converse.js make an AJAX POST with your changed custom chat status to a
  713. remote server.
  714. xhr_custom_status_url
  715. ---------------------
  716. .. Note ::
  717. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  718. Default = Empty string
  719. Used only in conjunction with ``xhr_custom_status``.
  720. This is the URL to which the AJAX POST request to set the user's custom status
  721. message will be made.
  722. The message itself is sent in the request under the key ``msg``.
  723. xhr_user_search
  724. ---------------
  725. Default = ``false``
  726. .. Note ::
  727. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  728. There are two ways to add users.
  729. * The user inputs a valid JID (Jabber ID), and the user is added as a pending contact.
  730. * The user inputs some text (for example part of a firstname or lastname), an XHR (Ajax Request) will be made to a remote server, and a list of matches are returned. The user can then choose one of the matches to add as a contact.
  731. This setting enables the second mechanism, otherwise by default the first will be used.
  732. *What is expected from the remote server?*
  733. A default JSON encoded list of objects must be returned. Each object
  734. corresponds to a matched user and needs the keys ``id`` and ``fullname``.
  735. xhr_user_search_url
  736. -------------------
  737. .. Note ::
  738. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  739. Default = Empty string
  740. Used only in conjunction with ``xhr_user_search``.
  741. This is the URL to which an AJAX GET request will be made to fetch user data from your remote server.
  742. The query string will be included in the request with ``q`` as its key.
  743. .. _`read more about require.js's optimizer here`: http://requirejs.org/docs/optimization.html
  744. .. _`HTTP`: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
  745. .. _`XMPP`: https://en.wikipedia.org/wiki/Xmpp
  746. .. _`Converse.js homepage`: http://conversejs.org
  747. .. _`CORS`: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing
  748. .. _`Strophe.js plugin`: https://gist.github.com/1095825/6b4517276f26b66b01fa97b0a78c01275fdc6ff2
  749. .. _`xmpp.net`: http://xmpp.net
  750. .. _`xmpp.org`: http://xmpp.org/xmpp-software/servers/
  751. .. _`ejabberd`: http://www.ejabberd.im
  752. .. _`blogpost`: http://metajack.im/2008/10/03/getting-attached-to-strophe
  753. .. _`example Django application`: https://github.com/metajack/strophejs/tree/master/examples/attach