index.txt 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  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. Development
  253. ===========
  254. If you want to work with the non-minified Javascript and CSS files you'll soon
  255. notice that there are references to a missing *components* folder. Please
  256. follow the instructions below to create this folder and fetch Converse's
  257. 3rd-party dependencies.
  258. Install Node.js and development dependencies
  259. ============================================
  260. We use development tools (`Grunt <http://gruntjs.com>`_ and `Bower <http://bower.io>`_)
  261. which depend on Node.js and npm (the Node package manager).
  262. If you don't have Node.js installed, you can download and install the latest
  263. version `here <https://nodejs.org/download>`_.
  264. Once you have Node.js installed, run the following command inside the Converse.js
  265. directory:
  266. ::
  267. npm install
  268. This will install all the development dependencies for Converse.js. If you are
  269. curious to know what these are, take a look at whats under the *devDependencies* key in
  270. `package.json <https://github.com/jcbrand/converse.js/blob/master/package.json>`.
  271. Install 3rd party dependencies
  272. ==============================
  273. After running ``npm install``, you will now have Grunt and Bower installed.
  274. We use Bower to manage Converse's front-end dependencies (e.g. Javascript that
  275. should get loaded in the browser).
  276. To fetch these dependencies, run:
  277. ::
  278. grunt fetch
  279. If you don't have grunt installed globally, you need to specify the relative
  280. path:
  281. ::
  282. ./node_modules/.bin/grunt fetch
  283. This will call Bower in the background to fetch all the front-end
  284. dependencies (like backbone.js, strophe.js etc.) and then put them in the
  285. *components* folder.
  286. With AMD and require.js (recommended)
  287. =====================================
  288. Converse.js uses `require.js <http://requirejs.org>`_ to asynchronously load dependencies.
  289. If you want to develop or customize converse.js, you'll want to load the
  290. non-minified javascript files.
  291. Add the following two lines to the *<head>* section of your webpage:
  292. ::
  293. <link rel="stylesheet" type="text/css" media="screen" href="converse.css">
  294. <script data-main="main" src="components/requirejs/require.js"></script>
  295. require.js will then let the main.js file be parsed (because of the *data-main*
  296. attribute on the *script* tag), which will in turn cause converse.js to be
  297. parsed.
  298. Without AMD and require.js
  299. ==========================
  300. Converse.js can also be used without require.js. If you for some reason prefer
  301. to use it this way, please refer to
  302. `non_amd.html <https://github.com/jcbrand/converse.js/blob/master/non_amd.html>`_
  303. for an example of how and in what order all the Javascript files that converse.js
  304. depends on need to be loaded.
  305. Before submitting a pull request
  306. ================================
  307. Add tests for your bugfix or feature
  308. ------------------------------------
  309. Add a test for any bug fixed or feature added. We use Jasmine
  310. for testing.
  311. Take a look at ``tests.html`` and ``spec/MainSpec.js`` to see how
  312. the tests are implemented.
  313. If you are unsure how to write tests, please
  314. `contact me <http://opkode.com/contact>`_ and I'll be happy to help.
  315. Check that the tests pass
  316. -------------------------
  317. Check that the Jasmine tests complete sucessfully. Open
  318. `tests.html <https://github.com/jcbrand/converse.js/blob/master/tests.html>`_
  319. in your browser, and the tests will run automatically.
  320. On the command line you can run:
  321. ::
  322. grunt test
  323. Check your code for errors or bad habits by running JSHint
  324. ----------------------------------------------------------
  325. `JSHint <http://jshint.com>`_ will do a static analysis of your code and hightlight potential errors
  326. and/or bad habits.
  327. ::
  328. grunt jshint
  329. You can run both the tests and jshint in one go by calling:
  330. ::
  331. grunt check
  332. ===============
  333. Troubleshooting
  334. ===============
  335. Conflicts with other Javascript libraries
  336. =========================================
  337. Problem:
  338. ---------
  339. You are using other Javascript libraries (like JQuery plugins), and
  340. get errors like these in your browser console::
  341. Uncaught TypeError: Object [object Object] has no method 'xxx' from example.js
  342. Solution:
  343. ---------
  344. First, find out which object is referred to by ``Object [object Object]``.
  345. It will probably be the jQuery object ``$`` or perhaps the underscore.js object ``_``.
  346. For the purpose of demonstration, I'm going to assume its ``$``, but the same
  347. rules apply if its something else.
  348. The bundled and minified default build of converse.js, ``converse.min.js``
  349. includes within it all of converse.js's dependencies, which include for example *jQuery*.
  350. If you are having conflicts where attributes or methods aren't available
  351. on the jQuery object, you are probably loading ``converse.min.js`` (which
  352. includes jQuery) as well as your own jQuery version separately.
  353. What then happens is that there are two ``$`` objects (one from
  354. converse.js and one from the jQuery version you included manually)
  355. and only one of them has been extended to have the methods or attributes you require.
  356. Which jQuery object you get depends on the order in which you load the libraries.
  357. There are multiple ways to solve this issue.
  358. Firstly, make sure whether you really need to include a separate version of
  359. jQuery. Chances are that you don't. If you can remove the separate
  360. version, your problem should be solved, as long as your libraries are loaded in
  361. the right order.
  362. Either case, whether you need to keep two versions or not, the solution depends
  363. on whether you'll use require.js to manage your libraries or whether you'll
  364. load them manually.
  365. With require.js
  366. ~~~~~~~~~~~~~~~
  367. Instead of using ``converse.min.js``, manage all the libraries in your project
  368. (i.e. converse.js and its dependencies plus all other libraries you use) as one
  369. require.js project, making sure everything is loaded in the correct order.
  370. Then, before deployment, you make your own custom minified build that bundles everything
  371. you need.
  372. With <script> tags
  373. ~~~~~~~~~~~~~~~~~~
  374. Take a look at `non_amd.html <https://github.com/jcbrand/converse.js/blob/master/non_amd.html>`_
  375. in the converse.js repo.
  376. It shows in which order the libraries must be loaded via ``<script>`` tags. Add
  377. your own libraries, making sure that they are loaded in the correct order (e.g.
  378. jQuery plugins must load after jQuery).
  379. ======
  380. Events
  381. ======
  382. Converse.js emits events to which you can subscribe from your own Javascript.
  383. Concerning events, the following methods are available:
  384. Event Methods
  385. =============
  386. * **on(eventName, callback)**:
  387. Calling the ``on`` method allows you to subscribe to an event.
  388. Every time the event fires, the callback method specified by ``callback`` will be
  389. called.
  390. Parameters:
  391. * ``eventName`` is the event name as a string.
  392. * ``callback`` is the callback method to be called when the event is emitted.
  393. For example::
  394. converse.on('onMessage', function (messageXML) { ... });
  395. * **once(eventName, callback)**:
  396. Calling the ``once`` method allows you to listen to an event
  397. exactly once.
  398. Parameters:
  399. * ``eventName`` is the event name as a string.
  400. * ``callback`` is the callback method to be called when the event is emitted.
  401. For example::
  402. converse.once('onMessage', function (messageXML) { ... });
  403. * **off(eventName, callback)**
  404. To stop listening to an event, you can use the ``off`` method.
  405. Parameters:
  406. * ``eventName`` is the event name as a string.
  407. * ``callback`` refers to the function that is to be no longer executed.
  408. Event Types
  409. ===========
  410. Here are the different events that are emitted:
  411. * **onInitialized**
  412. ``converse.on('onInitialized', function () { ... });``
  413. Triggered once converse.js has been initialized.
  414. * **onReady**
  415. Triggered after a connection has been established and converse.js has
  416. got all its ducks in a row.
  417. ``converse.on('onReady', function () { ... });``
  418. * **onMessage**
  419. ``converse.on('onMessage', function (messageXML) { ... });``
  420. Triggered when a message is received.
  421. * **onMessageSend**
  422. ``converse.on('onMessageSend', function (messageText) { ... });``
  423. Triggered when a message will be sent out.
  424. * **onRoster**
  425. ``converse.on('onRoster', function (items) { ... });``
  426. Triggered when the roster is updated.
  427. * **onRosterViewUpdated**
  428. ``converse.on('onRosterViewUpdated', function (items) { ... });``
  429. Triggered whenever the roster view (i.e. the rendered HTML) has changed.
  430. * **onChatBoxFocused**
  431. ``converse.on('onChatBoxFocused', function (chatbox) { ... });``
  432. Triggered when the focus has been moved to a chat box.
  433. * **onChatBoxOpened**
  434. ``converse.on('onChatBoxOpened', function (chatbox) { ... });``
  435. Triggered when a chat box has been opened.
  436. * **onChatBoxClosed**
  437. ``converse.on('onChatBoxClosed', function (chatbox) { ... });``
  438. Triggered when a chat box has been closed.
  439. * **onStatusChanged**
  440. ``converse.on('onStatusChanged', function (status) { ... });``
  441. Triggered when own chat status has changed.
  442. * **onStatusMessageChanged**
  443. ``converse.on('onStatusMessageChanged', function (message) { ... });``
  444. Triggered when own custom status message has changed.
  445. * **onBuddyStatusChanged**
  446. ``converse.on('onBuddyStatusChanged', function (buddy, status) { ... });``
  447. Triggered when a chat buddy's chat status has changed.
  448. * **onBuddyStatusMessageChanged**
  449. ``converse.on('onBuddyStatusMessageChanged', function (buddy, messageText) { ... });``
  450. Triggered when a chat buddy's custom status message has changed.
  451. =============
  452. Configuration
  453. =============
  454. The included minified JS and CSS files can be used for demoing or testing, but
  455. you'll want to configure *Converse.js* to suit your needs before you deploy it
  456. on your website.
  457. *Converse.js* is passed its configuration settings when you call its
  458. *initialize* method.
  459. You'll most likely want to call the *initialize* method in your HTML page. For
  460. an example of how this is done, please see the bottom of the *./index.html* page.
  461. Please refer to the `Configuration variables`_ section below for info on
  462. all the available configuration settings.
  463. After you have configured *Converse.js*, you'll have to regenerate the minified
  464. JS file so that it will include the new settings. Please refer to the
  465. `Minification`_ section for more info on how to do this.
  466. Configuration variables
  467. =======================
  468. allow_contact_requests
  469. ----------------------
  470. Default = ``true``
  471. Allow users to add one another as contacts. If this is set to false, the
  472. **Add a contact** widget, **Contact Requests** and **Pending Contacts** roster
  473. sections will all not appear. Additionally, all incoming contact requests will be
  474. ignored.
  475. allow_muc
  476. ---------
  477. Default = ``true``
  478. Allow multi-user chat (muc) in chatrooms. Setting this to ``false`` will remove
  479. the ``Chatrooms`` tab from the control box.
  480. animate
  481. -------
  482. Default = ``true``
  483. Show animations, for example when opening and closing chat boxes.
  484. auto_list_rooms
  485. ---------------
  486. Default = ``false``
  487. If true, and the XMPP server on which the current user is logged in supports
  488. multi-user chat, then a list of rooms on that server will be fetched.
  489. Not recommended for servers with lots of chat rooms.
  490. For each room on the server a query is made to fetch further details (e.g.
  491. features, number of occupants etc.), so on servers with many rooms this
  492. option will create lots of extra connection traffic.
  493. auto_subscribe
  494. --------------
  495. Default = ``false``
  496. If true, the user will automatically subscribe back to any contact requests.
  497. bosh_service_url
  498. ----------------
  499. Connections to an XMPP server depend on a BOSH connection manager which acts as
  500. a middle man between HTTP and XMPP.
  501. See `here <http://metajack.im/2008/09/08/which-bosh-server-do-you-need>`_ for more information.
  502. debug
  503. -----
  504. Default = ``false``
  505. If set to true, debugging output will be logged to the browser console.
  506. fullname
  507. --------
  508. If you are using prebinding, can specify the fullname of the currently
  509. logged in user, otherwise the user's vCard will be fetched.
  510. hide_muc_server
  511. ---------------
  512. Default = ``false``
  513. Hide the ``server`` input field of the form inside the ``Room`` panel of the
  514. controlbox. Useful if you want to restrict users to a specific XMPP server of
  515. your choosing.
  516. i18n
  517. ----
  518. Specify the locale/language. The language must be in the ``locales`` object. Refer to
  519. ``./locale/locales.js`` to see which locales are supported.
  520. prebind
  521. --------
  522. Default = ``false``
  523. Use this option when you want to attach to an existing XMPP connection that was
  524. already authenticated (usually on the backend before page load).
  525. This is useful when you don't want to render the login form on the chat control
  526. box with each page load.
  527. For prebinding to work, your backend server must authenticate for you, and
  528. then return a JID (jabber ID), SID (session ID) and RID (Request ID).
  529. If you set ``prebind`` to ``true``, you have to make sure to also pass in these
  530. values as ``jid``, ``sid``, ``rid``.
  531. Additionally, you have to specify ``bosh_service_url``.
  532. show_controlbox_by_default
  533. --------------------------
  534. Default = ``false``
  535. The "controlbox" refers to the special chatbox containing your contacts roster,
  536. status widget, chatrooms and other controls.
  537. By default this box is hidden and can be toggled by clicking on any element in
  538. the page with class *toggle-online-users*.
  539. If this options is set to true, the controlbox will by default be shown upon
  540. page load.
  541. show_call_button
  542. ----------------
  543. Default = ``false``
  544. Enable to display a call button on the chatbox toolbar.
  545. When the call button is pressed, it will emit an event that can be used by a third-party library to initiate a call.
  546. ::
  547. converse.on('onCallButtonClicked', function(event, data) {
  548. console.log('Call button was clicked.');
  549. console.log('Strophe connection is', data.connection);
  550. console.log('Bare buddy JID is', data.model.get('jid'));
  551. // ... Third-party library code ...
  552. });
  553. show_only_online_users
  554. ----------------------
  555. Default = ``false``
  556. If set to ``true``, only online users will be shown in the contacts roster.
  557. Users with any other status (e.g. away, busy etc.) will not be shown.
  558. use_vcards
  559. ----------
  560. Default = ``true``
  561. Determines whether the XMPP server will be queried for roster contacts' VCards
  562. or not. VCards contain extra personal information such as your fullname and
  563. avatar image.
  564. xhr_custom_status
  565. -----------------
  566. Default = ``false``
  567. .. Note ::
  568. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  569. This option will let converse.js make an AJAX POST with your changed custom chat status to a
  570. remote server.
  571. xhr_custom_status_url
  572. ---------------------
  573. .. Note ::
  574. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  575. Default = Empty string
  576. Used only in conjunction with ``xhr_custom_status``.
  577. This is the URL to which the AJAX POST request to set the user's custom status
  578. message will be made.
  579. The message itself is sent in the request under the key ``msg``.
  580. xhr_user_search
  581. ---------------
  582. Default = ``false``
  583. .. Note ::
  584. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  585. There are two ways to add users.
  586. * The user inputs a valid JID (Jabber ID), and the user is added as a pending contact.
  587. * 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.
  588. This setting enables the second mechanism, otherwise by default the first will be used.
  589. *What is expected from the remote server?*
  590. A default JSON encoded list of objects must be returned. Each object
  591. corresponds to a matched user and needs the keys ``id`` and ``fullname``.
  592. xhr_user_search_url
  593. -------------------
  594. .. Note ::
  595. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  596. Default = Empty string
  597. Used only in conjunction with ``xhr_user_search``.
  598. This is the URL to which an AJAX GET request will be made to fetch user data from your remote server.
  599. The query string will be included in the request with ``q`` as its key.
  600. ============
  601. Minification
  602. ============
  603. Minifying Javascript and CSS
  604. ============================
  605. Please make sure to read the section `Development`_ and that you have installed
  606. all development dependencies (long story short, you can run ``npm install``
  607. and then ``grunt fetch``).
  608. We use `require.js`_ to keep track of *Converse.js* and its dependencies and to
  609. to bundle them together in a single minified file fit for deployment to a
  610. production site.
  611. To minify the Javascript and CSS, run the following command:
  612. ::
  613. grunt minify
  614. Javascript will be bundled and minified with `require.js`_'s optimization tool,
  615. using `almond <https://github.com/jrburke/almond>`_.
  616. You can `read more about require.js's optimizer here`_.
  617. CSS is minified via `cssmin <https://github.com/gruntjs/grunt-contrib-cssmin>`_.
  618. ============
  619. Translations
  620. ============
  621. .. Note ::
  622. Translations take up a lot of space and will bloat your minified file.
  623. At the time of writing, all the translations add about 50KB of extra data to
  624. the minified javascript file. Therefore, make sure to only
  625. include those languages that you intend to support and remove from
  626. ./locale/locales.js those which you don't need. Remember to rebuild the
  627. minified file afterwards.
  628. The gettext POT file located in ./locale/converse.pot is the template
  629. containing all translations and from which for each language an individual PO
  630. file is generated.
  631. The POT file contains all translateable strings extracted from converse.js.
  632. To make a user facing string translateable, wrap it in the double underscore helper
  633. function like so:
  634. ::
  635. __('This string will be translated at runtime');
  636. After adding the string, you'll need to regenerate the POT file, like so:
  637. ::
  638. make pot
  639. You can then create or update the PO file for a specific language by doing the following:
  640. ::
  641. msgmerge ./locale/de/LC_MESSAGES/converse.po ./locale/converse.pot -U
  642. To do this for ALL languages, run:
  643. ::
  644. make merge
  645. The resulting PO file is then what gets translated.
  646. If you've created a new PO file, please make sure to add the following
  647. attributes at the top of the file (under *Content-Transfer-Encoding*). They are
  648. required as configuration settings for Jed, the Javascript translations library
  649. that we're using.
  650. ::
  651. "domain: converse\n"
  652. "lang: de\n"
  653. "plural_forms: nplurals=2; plural=(n != 1);\n"
  654. Unfortunately `Jed <http://slexaxton.github.io/Jed>`_ cannot use the PO files directly. We have to generate from it
  655. a file in JSON format and then put that in a .js file for the specific
  656. language.
  657. To generate JSON from a PO file, you'll need po2json for node.js. Run the
  658. following command to install it (npm being the node.js package manager):
  659. ::
  660. npm install po2json
  661. You can then convert the translations into JSON format:
  662. ::
  663. po2json locale/de/LC_MESSAGES/converse.po locale/de/LC_MESSAGES/converse.json
  664. Now from converse.json paste the data as a value for the "locale_data" key in the
  665. object in the language's .js file.
  666. So, if you are for example translating into German (language code 'de'), you'll
  667. create or update the file ./locale/LC_MESSAGES/de.js with the following code:
  668. ::
  669. (function (root, factory) {
  670. define("de", ['jed'], function () {
  671. return factory(new Jed({
  672. "domain": "converse",
  673. "locale_data": {
  674. // Paste the JSON data from converse.json here
  675. }
  676. })
  677. }
  678. }(this, function (i18n) {
  679. return i18n;
  680. }));
  681. making sure to also paste the JSON data as value to the "locale_data" key.
  682. .. Note ::
  683. If you are adding translations for a new language that is not already supported,
  684. you'll have to make one more edit in ./locale/locales.js to make sure the
  685. language is loaded by require.js.
  686. Congratulations, you've now succesfully added your translations. Sorry for all
  687. those hoops you had to jump through.
  688. .. _`read more about require.js's optimizer here`: http://requirejs.org/docs/optimization.html
  689. .. _`HTTP`: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
  690. .. _`XMPP`: https://en.wikipedia.org/wiki/Xmpp
  691. .. _`Converse.js homepage`: http://conversejs.org
  692. .. _`CORS`: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing
  693. .. _`Strophe.js plugin`: https://gist.github.com/1095825/6b4517276f26b66b01fa97b0a78c01275fdc6ff2
  694. .. _`xmpp.net`: http://xmpp.net
  695. .. _`xmpp.org`: http://xmpp.org/xmpp-software/servers/
  696. .. _`ejabberd`: http://www.ejabberd.im
  697. .. _`blogpost`: http://metajack.im/2008/10/03/getting-attached-to-strophe
  698. .. _`example Django application`: https://github.com/metajack/strophejs/tree/master/examples/attach