index.txt 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  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. Setting up a BOSH server
  200. ------------------------
  201. The `Movim <http://movim.eu/>`_ project wiki has a very thorough page on setting up a BOSH server for
  202. a wide variety of standalone or XMPP servers.
  203. http://wiki.movim.eu/manual:bosh_servers
  204. Facebook integration
  205. ====================
  206. .. Note ::
  207. It should be possible to integrate Converse.js with Facebook chat, and
  208. below I'll provide some tips and documentation on how to achieve this. That
  209. said, I don't have a Facebook account and therefore haven't tried to do
  210. this myself. Feedback and patches from people who have succesfully done this
  211. will be appreciated.
  212. Converse.js uses `Strophe.js <http://strophe.im/strophejs>`_ to connect and
  213. communicate with the XMPP server. One nice thing about Strophe.js is that it
  214. can be extended via `plugins <http://github.com/strophe/strophejs-plugins>`_.
  215. Here is a `plugin for authenticating with facebook
  216. <https://github.com/kissrobber/turedsocial/blob/master/strophe-plugins/src/facebook.js>`_.
  217. You will need your own BOSH connection manager to act as a proxy between
  218. Converse.js/Strophe.js and Facebook's XMPP server. That is because Facebook's
  219. XMPP server doesn't support BOSH natively.
  220. The BOSH connection manager that I make available for
  221. testing purposes (at https://bind.opkode.im) uses `Punjab <https://github.com/twonds/punjab>`_,
  222. although there are quite a few other options available as well.
  223. When you configure Converse.js, via its ``initialize`` method, you must specify the
  224. `bosh_service_url`_ value, which is to be your BOSH connection manager.
  225. Please note, to enable Facebook integration, you'll have to
  226. get your hands dirty and modify Converse.js's code, so that it calls the
  227. ``facebookConnect`` method of the plugin above.
  228. The plugin above gives the following code example for you to meditate upon:
  229. ::
  230. connection = new Strophe.Connection("http://localhost:5280/bosh");
  231. connection.facebookConnect(
  232. "12345@chat.facebook.com",
  233. onConnectFacebook,
  234. 300,
  235. 1,
  236. '5e64a30272af065bd72258c565a03f2f',
  237. '8147a27e4a7f9b55ffc85c2683f9529a',
  238. FB.getSession().session_key
  239. );
  240. The connection is already created inside Converse.js, so the
  241. ``facebookConnect`` method needs to also be called from there.
  242. If someone submits a sane patch that does the above, I'll be happy to merge it.
  243. Until then, people will have to do this themselves.
  244. ===========
  245. Development
  246. ===========
  247. If you want to work with the non-minified Javascript and CSS files you'll soon
  248. notice that there are references to a missing *components* folder. Please
  249. follow the instructions below to create this folder and fetch Converse's
  250. 3rd-party dependencies.
  251. Install Node.js and development dependencies
  252. ============================================
  253. We use development tools (`Grunt <http://gruntjs.com>`_ and `Bower <http://bower.io>`_)
  254. which depend on Node.js and npm (the Node package manager).
  255. If you don't have Node.js installed, you can download and install the latest
  256. version `here <https://nodejs.org/download>`_.
  257. Once you have Node.js installed, run the following command inside the Converse.js
  258. directory:
  259. ::
  260. npm install
  261. This will install all the development dependencies for Converse.js. If you are
  262. curious to know what these are, take a look at whats under the *devDependencies* key in
  263. `package.json <https://github.com/jcbrand/converse.js/blob/master/package.json>`.
  264. Install 3rd party dependencies
  265. ==============================
  266. After running ``npm install``, you will now have Grunt and Bower installed.
  267. We use Bower to manage Converse's front-end dependencies (e.g. Javascript that
  268. should get loaded in the browser).
  269. To fetch these dependencies, run:
  270. ::
  271. grunt fetch
  272. If you don't have grunt installed globally, you need to specify the relative
  273. path:
  274. ::
  275. ./node_modules/.bin/grunt fetch
  276. This will call Bower in the background to fetch all the front-end
  277. dependencies (like backbone.js, strophe.js etc.) and then put them in the
  278. *components* folder.
  279. With AMD and require.js (recommended)
  280. =====================================
  281. Converse.js uses `require.js <http://requirejs.org>`_ to asynchronously load dependencies.
  282. If you want to develop or customize converse.js, you'll want to load the
  283. non-minified javascript files.
  284. Add the following two lines to the *<head>* section of your webpage:
  285. ::
  286. <link rel="stylesheet" type="text/css" media="screen" href="converse.css">
  287. <script data-main="main" src="components/requirejs/require.js"></script>
  288. require.js will then let the main.js file be parsed (because of the *data-main*
  289. attribute on the *script* tag), which will in turn cause converse.js to be
  290. parsed.
  291. Without AMD and require.js
  292. ==========================
  293. Converse.js can also be used without require.js. If you for some reason prefer
  294. to use it this way, please refer to
  295. `non_amd.html <https://github.com/jcbrand/converse.js/blob/master/non_amd.html>`_
  296. for an example of how and in what order all the Javascript files that converse.js
  297. depends on need to be loaded.
  298. Before submitting a pull request
  299. ================================
  300. Add tests for your bugfix or feature
  301. ------------------------------------
  302. Add a test for any bug fixed or feature added. We use Jasmine
  303. for testing.
  304. Take a look at ``tests.html`` and ``spec/MainSpec.js`` to see how
  305. the tests are implemented.
  306. If you are unsure how to write tests, please
  307. `contact me <http://opkode.com/contact>`_ and I'll be happy to help.
  308. Check that the tests pass
  309. -------------------------
  310. Check that the Jasmine tests complete sucessfully. Open
  311. `tests.html <https://github.com/jcbrand/converse.js/blob/master/tests.html>`_
  312. in your browser, and the tests will run automatically.
  313. On the command line you can run:
  314. ::
  315. grunt test
  316. Check your code for errors or bad habits by running JSHint
  317. ----------------------------------------------------------
  318. `JSHint <http://jshint.com>`_ will do a static analysis of your code and hightlight potential errors
  319. and/or bad habits.
  320. ::
  321. grunt jshint
  322. You can run both the tests and jshint in one go by calling:
  323. ::
  324. grunt check
  325. ===============
  326. Troubleshooting
  327. ===============
  328. Conflicts with other Javascript libraries
  329. =========================================
  330. Problem:
  331. ---------
  332. You are using other Javascript libraries (like JQuery plugins), and
  333. get errors like these in your browser console::
  334. Uncaught TypeError: Object [object Object] has no method 'xxx' from example.js
  335. Solution:
  336. ---------
  337. First, find out which object is referred to by ``Object [object Object]``.
  338. It will probably be the jQuery object ``$`` or perhaps the underscore.js object ``_``.
  339. For the purpose of demonstration, I'm going to assume its ``$``, but the same
  340. rules apply if its something else.
  341. The bundled and minified default build of converse.js, ``converse.min.js``
  342. includes within it all of converse.js's dependencies, which include for example *jQuery*.
  343. If you are having conflicts where attributes or methods aren't available
  344. on the jQuery object, you are probably loading ``converse.min.js`` (which
  345. includes jQuery) as well as your own jQuery version separately.
  346. What then happens is that there are two ``$`` objects (one from
  347. converse.js and one from the jQuery version you included manually)
  348. and only one of them has been extended to have the methods or attributes you require.
  349. Which jQuery object you get depends on the order in which you load the libraries.
  350. There are multiple ways to solve this issue.
  351. Firstly, make sure whether you really need to include a separate version of
  352. jQuery. Chances are that you don't. If you can remove the separate
  353. version, your problem should be solved, as long as your libraries are loaded in
  354. the right order.
  355. Either case, whether you need to keep two versions or not, the solution depends
  356. on whether you'll use require.js to manage your libraries or whether you'll
  357. load them manually.
  358. With require.js
  359. ~~~~~~~~~~~~~~~
  360. Instead of using ``converse.min.js``, manage all the libraries in your project
  361. (i.e. converse.js and its dependencies plus all other libraries you use) as one
  362. require.js project, making sure everything is loaded in the correct order.
  363. Then, before deployment, you make your own custom minified build that bundles everything
  364. you need.
  365. With <script> tags
  366. ~~~~~~~~~~~~~~~~~~
  367. Take a look at `non_amd.html <https://github.com/jcbrand/converse.js/blob/master/non_amd.html>`_
  368. in the converse.js repo.
  369. It shows in which order the libraries must be loaded via ``<script>`` tags. Add
  370. your own libraries, making sure that they are loaded in the correct order (e.g.
  371. jQuery plugins must load after jQuery).
  372. =============
  373. Configuration
  374. =============
  375. The included minified JS and CSS files can be used for demoing or testing, but
  376. you'll want to configure *Converse.js* to suit your needs before you deploy it
  377. on your website.
  378. *Converse.js* is passed its configuration settings when you call its
  379. *initialize* method.
  380. You'll most likely want to call the *initialize* method in your HTML page. For
  381. an example of how this is done, please see the bottom of the *./index.html* page.
  382. Please refer to the `Configuration variables`_ section below for info on
  383. all the available configuration settings.
  384. After you have configured *Converse.js*, you'll have to regenerate the minified
  385. JS file so that it will include the new settings. Please refer to the
  386. `Minification`_ section for more info on how to do this.
  387. Configuration variables
  388. =======================
  389. allow_contact_requests
  390. ----------------------
  391. Default = ``true``
  392. Allow users to add one another as contacts. If this is set to false, the
  393. **Add a contact** widget, **Contact Requests** and **Pending Contacts** roster
  394. sections will all not appear. Additionally, all incoming contact requests will be
  395. ignored.
  396. allow_muc
  397. ---------
  398. Default = ``true``
  399. Allow multi-user chat (muc) in chatrooms. Setting this to ``false`` will remove
  400. the ``Chatrooms`` tab from the control box.
  401. animate
  402. -------
  403. Default = ``true``
  404. Show animations, for example when opening and closing chat boxes.
  405. auto_list_rooms
  406. ---------------
  407. Default = ``false``
  408. If true, and the XMPP server on which the current user is logged in supports
  409. multi-user chat, then a list of rooms on that server will be fetched.
  410. Not recommended for servers with lots of chat rooms.
  411. For each room on the server a query is made to fetch further details (e.g.
  412. features, number of occupants etc.), so on servers with many rooms this
  413. option will create lots of extra connection traffic.
  414. auto_subscribe
  415. --------------
  416. Default = ``false``
  417. If true, the user will automatically subscribe back to any contact requests.
  418. bosh_service_url
  419. ----------------
  420. Connections to an XMPP server depend on a BOSH connection manager which acts as
  421. a middle man between HTTP and XMPP.
  422. See `here <http://metajack.im/2008/09/08/which-bosh-server-do-you-need>`_ for more information.
  423. debug
  424. -----
  425. Default = ``false``
  426. If set to true, debugging output will be logged to the browser console.
  427. fullname
  428. --------
  429. If you are using prebinding, can specify the fullname of the currently
  430. logged in user, otherwise the user's vCard will be fetched.
  431. hide_muc_server
  432. ---------------
  433. Default = ``false``
  434. Hide the ``server`` input field of the form inside the ``Room`` panel of the
  435. controlbox. Useful if you want to restrict users to a specific XMPP server of
  436. your choosing.
  437. i18n
  438. ----
  439. Specify the locale/language. The language must be in the ``locales`` object. Refer to
  440. ``./locale/locales.js`` to see which locales are supported.
  441. prebind
  442. --------
  443. Default = ``false``
  444. Use this option when you want to attach to an existing XMPP connection that was
  445. already authenticated (usually on the backend before page load).
  446. This is useful when you don't want to render the login form on the chat control
  447. box with each page load.
  448. For prebinding to work, your backend server must authenticate for you, and
  449. then return a JID (jabber ID), SID (session ID) and RID (Request ID).
  450. If you set ``prebind`` to ``true``, you have to make sure to also pass in these
  451. values as ``jid``, ``sid``, ``rid``.
  452. Additionally, you have to specify ``bosh_service_url``.
  453. show_controlbox_by_default
  454. --------------------------
  455. Default = ``false``
  456. The "controlbox" refers to the special chatbox containing your contacts roster,
  457. status widget, chatrooms and other controls.
  458. By default this box is hidden and can be toggled by clicking on any element in
  459. the page with class *toggle-online-users*.
  460. If this options is set to true, the controlbox will by default be shown upon
  461. page load.
  462. show_only_online_users
  463. ----------------------
  464. Default = ``false``
  465. If set to ``true``, only online users will be shown in the contacts roster.
  466. Users with any other status (e.g. away, busy etc.) will not be shown.
  467. xhr_custom_status
  468. -----------------
  469. Default = ``false``
  470. .. Note ::
  471. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  472. This option will let converse.js make an AJAX POST with your changed custom chat status to a
  473. remote server.
  474. xhr_custom_status_url
  475. ---------------------
  476. .. Note ::
  477. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  478. Default = Empty string
  479. Used only in conjunction with ``xhr_custom_status``.
  480. This is the URL to which the AJAX POST request to set the user's custom status
  481. message will be made.
  482. The message itself is sent in the request under the key ``msg``.
  483. xhr_user_search
  484. ---------------
  485. Default = ``false``
  486. .. Note ::
  487. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  488. There are two ways to add users.
  489. * The user inputs a valid JID (Jabber ID), and the user is added as a pending contact.
  490. * 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.
  491. This setting enables the second mechanism, otherwise by default the first will be used.
  492. *What is expected from the remote server?*
  493. A default JSON encoded list of objects must be returned. Each object
  494. corresponds to a matched user and needs the keys ``id`` and ``fullname``.
  495. xhr_user_search_url
  496. -------------------
  497. .. Note ::
  498. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  499. Default = Empty string
  500. Used only in conjunction with ``xhr_user_search``.
  501. This is the URL to which an AJAX GET request will be made to fetch user data from your remote server.
  502. The query string will be included in the request with ``q`` as its key.
  503. ============
  504. Minification
  505. ============
  506. Minifying Javascript and CSS
  507. ============================
  508. Please make sure to read the section `Development`_ and that you have installed
  509. all development dependencies (long story short, you can run ``npm install``
  510. and then ``grunt fetch``).
  511. We use `require.js`_ to keep track of *Converse.js* and its dependencies and to
  512. to bundle them together in a single minified file fit for deployment to a
  513. production site.
  514. To minify the Javascript and CSS, run the following command:
  515. ::
  516. grunt minify
  517. Javascript will be bundled and minified with `require.js`_'s optimization tool,
  518. using `almond <https://github.com/jrburke/almond>`_.
  519. You can `read more about require.js's optimizer here`_.
  520. CSS is minified via `cssmin <https://github.com/gruntjs/grunt-contrib-cssmin>`_.
  521. ============
  522. Translations
  523. ============
  524. .. Note ::
  525. Translations take up a lot of space and will bloat your minified file.
  526. At the time of writing, all the translations add about 50KB of extra data to
  527. the minified javascript file. Therefore, make sure to only
  528. include those languages that you intend to support and remove from
  529. ./locale/locales.js those which you don't need. Remember to rebuild the
  530. minified file afterwards.
  531. The gettext POT file located in ./locale/converse.pot is the template
  532. containing all translations and from which for each language an individual PO
  533. file is generated.
  534. The POT file contains all translateable strings extracted from converse.js.
  535. To make a user facing string translateable, wrap it in the double underscore helper
  536. function like so:
  537. ::
  538. __('This string will be translated at runtime');
  539. After adding the string, you'll need to regenerate the POT file, like so:
  540. ::
  541. make pot
  542. You can then create or update the PO file for a specific language by doing the following:
  543. ::
  544. msgmerge ./locale/de/LC_MESSAGES/converse.po ./locale/converse.pot -U
  545. To do this for ALL languages, run:
  546. ::
  547. make merge
  548. The resulting PO file is then what gets translated.
  549. If you've created a new PO file, please make sure to add the following
  550. attributes at the top of the file (under *Content-Transfer-Encoding*). They are
  551. required as configuration settings for Jed, the Javascript translations library
  552. that we're using.
  553. ::
  554. "domain: converse\n"
  555. "lang: de\n"
  556. "plural_forms: nplurals=2; plural=(n != 1);\n"
  557. Unfortunately `Jed <http://slexaxton.github.io/Jed>`_ cannot use the PO files directly. We have to generate from it
  558. a file in JSON format and then put that in a .js file for the specific
  559. language.
  560. To generate JSON from a PO file, you'll need po2json for node.js. Run the
  561. following command to install it (npm being the node.js package manager):
  562. ::
  563. npm install po2json
  564. You can then convert the translations into JSON format:
  565. ::
  566. po2json locale/de/LC_MESSAGES/converse.po locale/de/LC_MESSAGES/converse.json
  567. Now from converse.json paste the data as a value for the "locale_data" key in the
  568. object in the language's .js file.
  569. So, if you are for example translating into German (language code 'de'), you'll
  570. create or update the file ./locale/LC_MESSAGES/de.js with the following code:
  571. ::
  572. (function (root, factory) {
  573. define("de", ['jed'], function () {
  574. return factory(new Jed({
  575. "domain": "converse",
  576. "locale_data": {
  577. // Paste the JSON data from converse.json here
  578. }
  579. })
  580. }
  581. }(this, function (i18n) {
  582. return i18n;
  583. }));
  584. making sure to also paste the JSON data as value to the "locale_data" key.
  585. .. Note ::
  586. If you are adding translations for a new language that is not already supported,
  587. you'll have to make one more edit in ./locale/locales.js to make sure the
  588. language is loaded by require.js.
  589. Congratulations, you've now succesfully added your translations. Sorry for all
  590. those hoops you had to jump through.
  591. .. _`read more about require.js's optimizer here`: http://requirejs.org/docs/optimization.html
  592. .. _`HTTP`: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
  593. .. _`XMPP`: https://en.wikipedia.org/wiki/Xmpp
  594. .. _`Converse.js homepage`: http://conversejs.org
  595. .. _`CORS`: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing
  596. .. _`Strophe.js plugin`: https://gist.github.com/1095825/6b4517276f26b66b01fa97b0a78c01275fdc6ff2
  597. .. _`xmpp.net`: http://xmpp.net
  598. .. _`xmpp.org`: http://xmpp.org/xmpp-software/servers/
  599. .. _`ejabberd`: http://www.ejabberd.im
  600. .. _`blogpost`: http://metajack.im/2008/10/03/getting-attached-to-strophe
  601. .. _`example Django application`: https://github.com/metajack/strophejs/tree/master/examples/attach