index.txt 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  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. * builds/converse.min.js
  15. * css/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="css/converse.min.css">
  20. <script src="builds/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 configure Converse.js, 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.conversejs.org', // 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. roster_groups: true
  38. });
  39. });
  40. The `index.html <https://github.com/jcbrand/converse.js/blob/master/index.html>`_ file inside the
  41. Converse.js repository may serve as a nice usable example.
  42. These minified files provide the same demo-like functionality as is available
  43. on the `conversejs.org <http://conversejs.org>`_ website. Useful for testing or demoing, but not very
  44. practical.
  45. You'll most likely want to implement some kind of single-signon solution for
  46. your website, where users authenticate once in your website and then stay
  47. logged into their XMPP session upon page reload.
  48. For more info on this, read: `Prebinding and Single Session Support`_.
  49. You might also want to have more fine-grained control of what gets included in
  50. the minified Javascript file. Read `Configuration`_ and `Minification`_ for more info on how to do
  51. that.
  52. ============
  53. Introduction
  54. ============
  55. Even though you can connect to public XMPP servers on the `conversejs.org`_
  56. website, *Converse.js* is not really meant to be a "Software-as-a-service" (SaaS)
  57. webchat.
  58. Instead, its goal is to provide the means for website owners to add a tightly
  59. integrated instant messaging service to their own websites.
  60. As a website owner, you are expected to host *Converse.js* yourself, and to do some legwork to
  61. properly configure and integrate it into your site.
  62. The benefit in doing this, is that your users have a much more streamlined and integrated
  63. webchat experience and that you have control over the data. The latter being a
  64. requirement for many sites dealing with sensitive information.
  65. You'll need to set up your own XMPP server and in order to have
  66. `Session Support`_ (i.e. single-signon functionality whereby users are authenticated once and stay
  67. logged in to XMPP upon page reload) you will also have to add some server-side
  68. code.
  69. The `What you will need`_ section has more information on all these
  70. requirements.
  71. ==================
  72. What you will need
  73. ==================
  74. An XMPP/Jabber server
  75. =====================
  76. *Converse.js* implements `XMPP`_ as its messaging protocol, and therefore needs
  77. to connect to an XMPP/Jabber server (Jabber is really just a synonym for XMPP).
  78. You can connect to public XMPP servers like ``jabber.org`` but if you want to
  79. have `Session Support`_ you'll have to set up your own XMPP server.
  80. You can find a list of public XMPP servers/providers on `xmpp.net`_ and a list of
  81. servers that you can set up yourself on `xmpp.org`_.
  82. A BOSH Connection Manager
  83. =========================
  84. Your website and *Converse.js* use `HTTP`_ as protocol to communicate with
  85. the webserver. HTTP connections are stateless and usually shortlived.
  86. `XMPP`_ on the other hand, is the protocol that enables instant messaging, and
  87. its connections are stateful and usually longer.
  88. To enable a web application like *Converse.js* to communicate with an XMPP
  89. server, we need a proxy in the middle that can act as a bridge between the two
  90. protocols.
  91. The `index.html <https://github.com/jcbrand/converse.js/blob/master/index.html>`_ file inside the
  92. This is the job of a connection manager. A connection manager can be either a
  93. standalone application or part of an XMPP server. Popular XMPP servers such as
  94. `ejabberd <http://www.ejabberd.im>`_, `prosody <http://prosody.im/doc/setting_up_bosh>`_ and
  95. `openfire <http://www.igniterealtime.org/projects/openfire/>`_ all include their own connection managers
  96. (but you usually have to enable them in the configuration).
  97. Standalone connection managers also exist, see for example `Punjab <https://github.com/twonds/punjab>`_.
  98. The demo on the `Converse.js homepage`_ uses a connection manager located at https://bind.conversejs.org.
  99. This connection manager is available for testing purposes only, please don't use it in production.
  100. Overcoming cross-domain request restrictions
  101. --------------------------------------------
  102. Lets say your domain is *example.org*, but the domain of your connection
  103. manager is *example.com*.
  104. HTTP requests are made by *Converse.js* to the connection manager via XmlHttpRequests (XHR).
  105. Until recently, it was not possible to make such requests to a different domain
  106. than the one currently being served (to prevent XSS attacks).
  107. Luckily there is now a standard called `CORS`_ (Cross-origin resource sharing), which enables exactly that.
  108. Modern browsers support CORS, but there are problems with Internet Explorer <
  109. 10.
  110. IE 8 and 9 partially support CORS via a proprietary implementation called
  111. XDomainRequest. There is a `Strophe.js plugin`_ which you can use to enable
  112. support for XDomainRequest when it is present.
  113. In IE < 8, there is no support for CORS.
  114. Instead of using CORS, you can add a reverse proxy in
  115. Apache/Nginx which serves the connection manager under the same domain as your
  116. website. This will remove the need for any cross-domain XHR support.
  117. For example:
  118. ~~~~~~~~~~~~
  119. Assuming your site is accessible on port ``80`` for the domain ``mysite.com``
  120. and your connection manager manager is running at ``someothersite.com/http-bind``.
  121. The *bosh_service_url* value you want to give Converse.js to overcome
  122. the cross-domain restriction is ``mysite.com/http-bind`` and not
  123. ``someothersite.com/http-bind``.
  124. Your ``nginx`` or ``apache`` configuration will look as follows:
  125. Nginx
  126. ~~~~~
  127. ::
  128. http {
  129. server {
  130. listen 80
  131. server_name mysite.com;
  132. location ~ ^/http-bind/ {
  133. proxy_pass http://someothersite.com;
  134. }
  135. }
  136. }
  137. Apache
  138. ~~~~~~
  139. ::
  140. <VirtualHost *:80>
  141. ServerName mysite.com
  142. RewriteEngine On
  143. RewriteRule ^/http-bind(.*) http://someothersite.com/http-bind$1 [P,L]
  144. </VirtualHost>
  145. Server-side authentication
  146. ==========================
  147. .. _`Session Support`:
  148. Prebinding and Single Session Support
  149. -------------------------------------
  150. It's possible to enable single-site login, whereby users already
  151. authenticated in your website will also automatically be logged in on the chat server,
  152. This session should also persist across page loads. In other words, we don't
  153. want the user to have to give their chat credentials every time they reload the
  154. page.
  155. To do this you will require a `BOSH server <http://xmpp.org/about-xmpp/technology-overview/bosh/>`_
  156. for converse.js to connect to (see the `bosh_service_url`_ under `Configuration variables`_)
  157. as well as a BOSH client on your own server (written for example in Python, Ruby or PHP) that will
  158. do the pre-authentication before the web page loads.
  159. .. note::
  160. A BOSH server acts as a bridge between HTTP, the protocol of the web, and
  161. XMPP, the instant messaging protocol.
  162. Converse.js can only communicate via HTTP, but we need to communicate with
  163. an XMPP server in order to chat. So the BOSH server acts as a middle man,
  164. translating our HTTP requests into XMPP stanzas and vice versa.
  165. Jack Moffitt has a great `blogpost`_ about this and even provides an `example Django application`_ to demonstrate it.
  166. When you authenticate to the XMPP server on your backend application (for
  167. example via a BOSH client in Django), you'll receive two tokens, RID (request ID) and SID (session ID).
  168. The **Session ID (SID)** is a unique identifier for the current *session*. This
  169. number stays constant for the entire session.
  170. The **Request ID (RID)** is a unique identifier for the current *request* (i.e.
  171. page load). Each page load is a new request which requires a new unique RID.
  172. The best way to achieve this is to simply increment the RID with each page
  173. load.
  174. When you initialize converse.js in your browser, you need to pass it these two
  175. tokens. Converse.js will then use them to attach to the session you just
  176. created.
  177. You can embed the RID and SID tokens in your HTML markup or you can do an
  178. XMLHttpRequest call to your server and ask it to return them for you.
  179. Below is one example of how this could work. An Ajax call is made to the
  180. relative URL **/prebind** and it expects to receive JSON data back.
  181. ::
  182. $.getJSON('/prebind', function (data) {
  183. converse.initialize({
  184. prebind: true,
  185. bosh_service_url: data.bosh_service_url,
  186. jid: data.jid,
  187. sid: data.sid,
  188. rid: data.rid
  189. });
  190. );
  191. **Here's what's happening:**
  192. 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
  193. BOSH server (also called a *connection manager*).
  194. These values are then passed to converse.js's ``initialize`` method.
  195. .. note::
  196. If you want to enable single session support, you need to set **prebind: true**
  197. when calling **converse.initialize** (see ./index.html).
  198. Additionally you need to pass in valid **jid**, **sid**, **rid** and
  199. **bosh_service_url** values.
  200. Example code for server-side prebinding
  201. ---------------------------------------
  202. * PHP:
  203. See `xmpp-prebind-php <https://github.com/candy-chat/xmpp-prebind-php>`_ by
  204. Michael Weibel and the folks from Candy chat.
  205. * Python:
  206. See this `example Django application`_ by Jack Moffitt.
  207. ========
  208. Features
  209. ========
  210. Off-the-record encryption
  211. =========================
  212. Converse.js supports `Off-the-record (OTR) <https://otr.cypherpunks.ca/>`_
  213. encrypted messaging.
  214. The OTR protocol not only **encrypts your messages**, it provides ways to
  215. **verify the identity** of the person you are talking to,
  216. **plausible deniability** and **perfect forward secrecy** by generating
  217. new encryption keys for each conversation.
  218. In its current state, Javascript cryptography is fraught with dangers and
  219. challenges that make it impossible to reach the same standard of security that
  220. is available with native "desktop" software.
  221. This is due to its runtime malleability, the way it is "installed" (e.g.
  222. served) and the browser's lack of cryptographic primitives needed to implement
  223. secure crypto.
  224. For harsh but fairly valid criticism of Javascript cryptography, read:
  225. `Javascript Cryptography Considered Harmful <http://www.matasano.com/articles/javascript-cryptography/>`_.
  226. To get an idea on how this applies to OTR support in Converse.js, please read
  227. `my thoughts on it <https://opkode.com/media/blog/2013/11/11/conversejs-otr-support>`_.
  228. For now, suffice to say that although its useful to have OTR support in
  229. Converse.js in order to avoid most eavesdroppers, if you need serious
  230. communications privacy, then you're much better off using native software.
  231. Sound Notifications
  232. ===================
  233. From version 0.8.1 Converse.js can play a sound notification when you receive a
  234. message.
  235. For more info, please see the `play_sounds`_ configuration setting.
  236. Multilingual Support
  237. ====================
  238. Converse.js is translated into multiple languages. The default build,
  239. ``converse.min.js``, includes all languages.
  240. Languages increase the size of the Converse.js significantly.
  241. If you only need one, or a subset of the available languages, it's better to
  242. make a custom build which includes only those languages that you need.
  243. Chat Rooms
  244. ==========
  245. Commands
  246. --------
  247. Here are the different commands that may be used in a chat room:
  248. +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
  249. | Event Type | When is it triggered? | Example (substitue $nickname with an actual user's nickname) |
  250. +============+==============================================================================================+===============================================================+
  251. | **ban** | Ban a user from the chat room. They will not be able to join again. | /ban $nickname |
  252. +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
  253. | **clear** | Clear the messages shown in the chat room. | /clear |
  254. +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
  255. | **deop** | Make a moderator a normal participant. | /deop $nickname [$reason] |
  256. +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
  257. | **help** | Show the list of available commands. | /help |
  258. +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
  259. | **kick** | Kick a user out of a room. They will be able to join again. | /kick $nickname [$reason] |
  260. +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
  261. | **me** | Speak in the 3rd person. | /me $message |
  262. +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
  263. | **mute** | Remove a user's ability to post messages to the room. They will still be able to observe. | /mute $nickname [$reason] |
  264. +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
  265. | **nick** | Change your nickname. | /nick $nickname |
  266. +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
  267. | **op** | Make a normal participant a moderator. | /op $nickname [$reason] |
  268. +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
  269. | **topic** | Set the topic of the chat room. | /topic ${topic text} |
  270. +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
  271. | **voice** | Allow a muted user to post messages to the room. | /voice $nickname [$reason] |
  272. +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
  273. ===========
  274. Development
  275. ===========
  276. If you want to work with the non-minified Javascript and CSS files you'll soon
  277. notice that there are references to a missing *components* folder. Please
  278. follow the instructions below to create this folder and fetch Converse's
  279. 3rd-party dependencies.
  280. .. Note:
  281. Users have reported that converse.js cannot be built on Windows. Patches to
  282. fix this are welcome.
  283. Install the development and front-end dependencies
  284. ==================================================
  285. We use development tools (`Grunt <http://gruntjs.com>`_ and `Bower <http://bower.io>`_)
  286. which depend on Node.js and npm (the Node package manager).
  287. If you don't have Node.js installed, you can download and install the latest
  288. version `here <https://nodejs.org/download>`_.
  289. Also make sure you have ``git`` installed. `Details <http://git-scm.com/book/en/Getting-Started-Installing-Git>`_.
  290. Once you have *Node.js* and *git* installed, run the following command inside the Converse.js
  291. directory:
  292. ::
  293. make dev
  294. Or alternatively, if you don't have GNU Make:
  295. ::
  296. npm install
  297. bower update
  298. This will first install the Node.js development tools (like Grunt and Bower)
  299. and then use Bower to install all of Converse.js's front-end dependencies.
  300. The front-end dependencies are those javascript files on which
  301. Converse.js directly depends and which will be loaded in the browser.
  302. If you are curious to know what the different dependencies are:
  303. * Development dependencies:
  304. Take a look at whats under the *devDependencies* key in
  305. `package.json <https://github.com/jcbrand/converse.js/blob/master/package.json>`_.
  306. * Front-end dependencies:
  307. See *dependencies* in
  308. `bower.json <https://github.com/jcbrand/converse.js/blob/master/bower.json>`_.
  309. .. Note:
  310. After running ```make dev```, you should now have a new directory *components*,
  311. which contains all the front-end dependencies of Converse.js.
  312. If this directory does NOT exist, something must have gone wrong.
  313. Double-check the output of ```make dev``` to see if there are any errors
  314. listed. For support, you can write to the mailing list: conversejs@librelist.com
  315. With AMD and require.js (recommended)
  316. =====================================
  317. Converse.js uses `require.js <http://requirejs.org>`_ to asynchronously load dependencies.
  318. If you want to develop or customize converse.js, you'll want to load the
  319. non-minified javascript files.
  320. Add the following two lines to the *<head>* section of your webpage:
  321. ::
  322. <link rel="stylesheet" type="text/css" media="screen" href="converse.css">
  323. <script data-main="main" src="components/requirejs/require.js"></script>
  324. require.js will then let the main.js file be parsed (because of the *data-main*
  325. attribute on the *script* tag), which will in turn cause converse.js to be
  326. parsed.
  327. Without AMD and require.js
  328. ==========================
  329. Converse.js can also be used without require.js. If you for some reason prefer
  330. to use it this way, please refer to
  331. `non_amd.html <https://github.com/jcbrand/converse.js/blob/master/non_amd.html>`_
  332. for an example of how and in what order all the Javascript files that converse.js
  333. depends on need to be loaded.
  334. Before submitting a pull request
  335. ================================
  336. Add tests for your bugfix or feature
  337. ------------------------------------
  338. Add a test for any bug fixed or feature added. We use Jasmine
  339. for testing.
  340. Take a look at ``tests.html`` and ``spec/MainSpec.js`` to see how
  341. the tests are implemented.
  342. If you are unsure how to write tests, please
  343. `contact me <http://opkode.com/contact>`_ and I'll be happy to help.
  344. Check that the tests pass
  345. -------------------------
  346. Check that the Jasmine tests complete sucessfully. Open
  347. `tests.html <https://github.com/jcbrand/converse.js/blob/master/tests.html>`_
  348. in your browser, and the tests will run automatically.
  349. On the command line you can run:
  350. ::
  351. grunt test
  352. Check your code for errors or bad habits by running JSHint
  353. ----------------------------------------------------------
  354. `JSHint <http://jshint.com>`_ will do a static analysis of your code and hightlight potential errors
  355. and/or bad habits.
  356. ::
  357. grunt jshint
  358. You can run both the tests and jshint in one go by calling:
  359. ::
  360. grunt check
  361. Minification
  362. ============
  363. Minifying Javascript and CSS
  364. ----------------------------
  365. Please make sure to read the section `Development`_ and that you have installed
  366. all development dependencies (long story short, you can run ``npm install``
  367. and then ``grunt fetch``).
  368. We use `require.js`_ to keep track of *Converse.js* and its dependencies and to
  369. to bundle them together in a single minified file fit for deployment to a
  370. production site.
  371. To minify the Javascript and CSS, run the following command:
  372. ::
  373. grunt minify
  374. Javascript will be bundled and minified with `require.js`_'s optimization tool,
  375. using `almond <https://github.com/jrburke/almond>`_.
  376. You can `read more about require.js's optimizer here`_.
  377. CSS is minified via `cssmin <https://github.com/gruntjs/grunt-contrib-cssmin>`_.
  378. Translations
  379. ============
  380. .. Note ::
  381. Translations take up a lot of space and will bloat your minified file.
  382. At the time of writing, all the translations add about 50KB of extra data to
  383. the minified javascript file. Therefore, make sure to only
  384. include those languages that you intend to support and remove from
  385. ./locale/locales.js those which you don't need. Remember to rebuild the
  386. minified file afterwards.
  387. The gettext POT file located in ./locale/converse.pot is the template
  388. containing all translations and from which for each language an individual PO
  389. file is generated.
  390. The POT file contains all translateable strings extracted from converse.js.
  391. To make a user facing string translateable, wrap it in the double underscore helper
  392. function like so:
  393. ::
  394. __('This string will be translated at runtime');
  395. After adding the string, you'll need to regenerate the POT file, like so:
  396. ::
  397. make pot
  398. You can then create or update the PO file for a specific language by doing the following:
  399. ::
  400. msgmerge ./locale/de/LC_MESSAGES/converse.po ./locale/converse.pot -U
  401. To do this for ALL languages, run:
  402. ::
  403. make po
  404. The resulting PO file is then what gets translated.
  405. If you've created a new PO file, please make sure to add the following
  406. attributes at the top of the file (under *Content-Transfer-Encoding*). They are
  407. required as configuration settings for Jed, the Javascript translations library
  408. that we're using.
  409. ::
  410. "domain: converse\n"
  411. "lang: de\n"
  412. "plural_forms: nplurals=2; plural=(n != 1);\n"
  413. Unfortunately `Jed <http://slexaxton.github.io/Jed>`_ cannot use the PO files directly. We have to generate from it
  414. a file in JSON format and then put that in a .js file for the specific
  415. language.
  416. To generate JSON from a PO file, you'll need po2json for node.js. Run the
  417. following command to install it (npm being the node.js package manager):
  418. ::
  419. npm install po2json
  420. You can then convert the translations into JSON format:
  421. ::
  422. po2json locale/de/LC_MESSAGES/converse.po locale/de/LC_MESSAGES/converse.json
  423. Now from converse.json paste the data as a value for the "locale_data" key in the
  424. object in the language's .js file.
  425. So, if you are for example translating into German (language code 'de'), you'll
  426. create or update the file ./locale/LC_MESSAGES/de.js with the following code:
  427. ::
  428. (function (root, factory) {
  429. define("de", ['jed'], function () {
  430. return factory(new Jed({
  431. "domain": "converse",
  432. "locale_data": {
  433. // Paste the JSON data from converse.json here
  434. }
  435. })
  436. }
  437. }(this, function (i18n) {
  438. return i18n;
  439. }));
  440. making sure to also paste the JSON data as value to the "locale_data" key.
  441. .. Note ::
  442. If you are adding translations for a new language that is not already supported,
  443. you'll have to add the language path in main.js and make one more edit in ./locale/locales.js
  444. to make sure the language is loaded by require.js.
  445. Congratulations, you've now succesfully added your translations. Sorry for all
  446. those hoops you had to jump through.
  447. ===============
  448. Troubleshooting
  449. ===============
  450. Conflicts with other Javascript libraries
  451. =========================================
  452. Problem:
  453. ---------
  454. You are using other Javascript libraries (like JQuery plugins), and
  455. get errors like these in your browser console::
  456. Uncaught TypeError: Object [object Object] has no method 'xxx' from example.js
  457. Solution:
  458. ---------
  459. First, find out which object is referred to by ``Object [object Object]``.
  460. It will probably be the jQuery object ``$`` or perhaps the underscore.js object ``_``.
  461. For the purpose of demonstration, I'm going to assume its ``$``, but the same
  462. rules apply if its something else.
  463. The bundled and minified default build of converse.js, ``converse.min.js``
  464. includes within it all of converse.js's dependencies, which include for example *jQuery*.
  465. If you are having conflicts where attributes or methods aren't available
  466. on the jQuery object, you are probably loading ``converse.min.js`` (which
  467. includes jQuery) as well as your own jQuery version separately.
  468. What then happens is that there are two ``$`` objects (one from
  469. converse.js and one from the jQuery version you included manually)
  470. and only one of them has been extended to have the methods or attributes you require.
  471. Which jQuery object you get depends on the order in which you load the libraries.
  472. There are multiple ways to solve this issue.
  473. Firstly, make sure whether you really need to include a separate version of
  474. jQuery. Chances are that you don't. If you can remove the separate
  475. version, your problem should be solved, as long as your libraries are loaded in
  476. the right order.
  477. Either case, whether you need to keep two versions or not, the solution depends
  478. on whether you'll use require.js to manage your libraries or whether you'll
  479. load them manually.
  480. With require.js
  481. ~~~~~~~~~~~~~~~
  482. Instead of using ``converse.min.js``, manage all the libraries in your project
  483. (i.e. converse.js and its dependencies plus all other libraries you use) as one
  484. require.js project, making sure everything is loaded in the correct order.
  485. Then, before deployment, you make your own custom minified build that bundles everything
  486. you need.
  487. With <script> tags
  488. ~~~~~~~~~~~~~~~~~~
  489. Take a look at `non_amd.html <https://github.com/jcbrand/converse.js/blob/master/non_amd.html>`_
  490. in the converse.js repo.
  491. It shows in which order the libraries must be loaded via ``<script>`` tags. Add
  492. your own libraries, making sure that they are loaded in the correct order (e.g.
  493. jQuery plugins must load after jQuery).
  494. ======
  495. Events
  496. ======
  497. Converse.js emits events to which you can subscribe from your own Javascript.
  498. Concerning events, the following methods are available:
  499. Event Methods
  500. =============
  501. * **on(eventName, callback)**:
  502. Calling the ``on`` method allows you to subscribe to an event.
  503. Every time the event fires, the callback method specified by ``callback`` will be
  504. called.
  505. Parameters:
  506. * ``eventName`` is the event name as a string.
  507. * ``callback`` is the callback method to be called when the event is emitted.
  508. For example::
  509. converse.on('message', function (messageXML) { ... });
  510. * **once(eventName, callback)**:
  511. Calling the ``once`` method allows you to listen to an event
  512. exactly once.
  513. Parameters:
  514. * ``eventName`` is the event name as a string.
  515. * ``callback`` is the callback method to be called when the event is emitted.
  516. For example::
  517. converse.once('message', function (messageXML) { ... });
  518. * **off(eventName, callback)**
  519. To stop listening to an event, you can use the ``off`` method.
  520. Parameters:
  521. * ``eventName`` is the event name as a string.
  522. * ``callback`` refers to the function that is to be no longer executed.
  523. Event Types
  524. ===========
  525. Here are the different events that are emitted:
  526. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  527. | Event Type | When is it triggered? | Example |
  528. +==================================+===================================================================================================+=========================================================================================+
  529. | **initialized** | Once converse.js has been initialized. | ``converse.on('initialized', function () { ... });`` |
  530. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  531. | **ready** | After connection has been established and converse.js has got all its ducks in a row. | ``converse.on('ready', function () { ... });`` |
  532. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  533. | **reconnect** | After the connection has dropped. Converse.js will attempt to reconnect when not in prebind mode. | ``converse.on('reconnect', function () { ... });`` |
  534. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  535. | **message** | When a message is received. | ``converse.on('message', function (messageXML) { ... });`` |
  536. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  537. | **messageSend** | When a message will be sent out. | ``converse.on('messageSend', function (messageText) { ... });`` |
  538. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  539. | **roster** | When the roster is updated. | ``converse.on('roster', function (items) { ... });`` |
  540. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  541. | **callButtonClicked** | When a call button (i.e. with class .toggle-call) on a chat box has been clicked. | ``converse.on('callButtonClicked', function (connection, model) { ... });`` |
  542. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  543. | **chatBoxOpened** | When a chat box has been opened. | ``converse.on('chatBoxOpened', function (chatbox) { ... });`` |
  544. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  545. | **chatRoomOpened** | When a chat room has been opened. | ``converse.on('chatRoomOpened', function (chatbox) { ... });`` |
  546. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  547. | **chatBoxClosed** | When a chat box has been closed. | ``converse.on('chatBoxClosed', function (chatbox) { ... });`` |
  548. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  549. | **chatBoxFocused** | When the focus has been moved to a chat box. | ``converse.on('chatBoxFocused', function (chatbox) { ... });`` |
  550. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  551. | **chatBoxToggled** | When a chat box has been minimized or maximized. | ``converse.on('chatBoxToggled', function (chatbox) { ... });`` |
  552. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  553. | **roomInviteSent** | After the user has sent out a direct invitation, to a roster contact, asking them to join a room. | ``converse.on('roomInvite', function (roomview, invitee_jid, reason) { ... });`` |
  554. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  555. | **roomInviteReceived** | After the user has sent out a direct invitation, to a roster contact, asking them to join a room. | ``converse.on('roomInvite', function (roomview, invitee_jid, reason) { ... });`` |
  556. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  557. | **statusChanged** | When own chat status has changed. | ``converse.on('statusChanged', function (status) { ... });`` |
  558. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  559. | **statusMessageChanged** | When own custom status message has changed. | ``converse.on('statusMessageChanged', function (message) { ... });`` |
  560. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  561. | **buddyStatusChanged** | When a chat buddy's chat status has changed. | ``converse.on('buddyStatusChanged', function (buddy, status) { ... });`` |
  562. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  563. | **buddyStatusMessageChanged** | When a chat buddy's custom status message has changed. | ``converse.on('buddyStatusMessageChanged', function (buddy, messageText) { ... });`` |
  564. +----------------------------------+---------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------+
  565. =============
  566. Configuration
  567. =============
  568. The included minified JS and CSS files can be used for demoing or testing, but
  569. you'll want to configure *Converse.js* to suit your needs before you deploy it
  570. on your website.
  571. *Converse.js* is passed its configuration settings when you call its
  572. *initialize* method.
  573. You'll most likely want to call the *initialize* method in your HTML page. For
  574. an example of how this is done, please see the bottom of the *./index.html* page.
  575. Please refer to the `Configuration variables`_ section below for info on
  576. all the available configuration settings.
  577. After you have configured *Converse.js*, you'll have to regenerate the minified
  578. JS file so that it will include the new settings. Please refer to the
  579. `Minification`_ section for more info on how to do this.
  580. Configuration variables
  581. =======================
  582. allow_contact_requests
  583. ----------------------
  584. Default: ``true``
  585. Allow users to add one another as contacts. If this is set to false, the
  586. **Add a contact** widget, **Contact Requests** and **Pending Contacts** roster
  587. sections will all not appear. Additionally, all incoming contact requests will be
  588. ignored.
  589. allow_muc
  590. ---------
  591. Default: ``true``
  592. Allow multi-user chat (muc) in chatrooms. Setting this to ``false`` will remove
  593. the ``Chatrooms`` tab from the control box.
  594. allow_muc
  595. ---------
  596. Default: ``true``
  597. Allow Off-the-record encryption of single-user chat messages.
  598. animate
  599. -------
  600. Default: ``true``
  601. Show animations, for example when opening and closing chat boxes.
  602. auto_list_rooms
  603. ---------------
  604. Default: ``false``
  605. If true, and the XMPP server on which the current user is logged in supports
  606. multi-user chat, then a list of rooms on that server will be fetched.
  607. Not recommended for servers with lots of chat rooms.
  608. For each room on the server a query is made to fetch further details (e.g.
  609. features, number of occupants etc.), so on servers with many rooms this
  610. option will create lots of extra connection traffic.
  611. auto_reconnect
  612. --------------
  613. Default: ``true``
  614. Automatically reconnect to the XMPP server if the connection drops
  615. unexpectedly.
  616. auto_subscribe
  617. --------------
  618. Default: ``false``
  619. If true, the user will automatically subscribe back to any contact requests.
  620. bosh_service_url
  621. ----------------
  622. Connections to an XMPP server depend on a BOSH connection manager which acts as
  623. a middle man between HTTP and XMPP.
  624. See `here <http://metajack.im/2008/09/08/which-bosh-server-do-you-need>`_ for more information.
  625. cache_otr_key
  626. -------------
  627. Default: ``false``
  628. Let the `OTR (Off-the-record encryption) <https://otr.cypherpunks.ca>`_ private
  629. key be cached in your browser's session storage.
  630. The browser's session storage persists across page loads but is deleted once
  631. the tab or window is closed.
  632. If this option is set to ``false``, a new OTR private key will be generated
  633. for each page load. While more inconvenient, this is a much more secure option.
  634. This setting can only be used together with ``allow_otr = true``.
  635. .. Note ::
  636. A browser window's session storage is accessible by all javascript that
  637. is served from the same domain. So if there is malicious javascript served by
  638. the same server (or somehow injected via an attacker), then they will be able
  639. to retrieve your private key and read your all the chat messages in your
  640. current session. Previous sessions however cannot be decrypted.
  641. debug
  642. -----
  643. Default: ``false``
  644. If set to true, debugging output will be logged to the browser console.
  645. keepalive
  646. ---------
  647. Default: ``true``
  648. Determines whether Converse.js will maintain the chat session across page
  649. loads.
  650. *Please be aware*: This is a new still relatively experimental feature and there might be some
  651. unhandled edge-cases.
  652. message_carbons
  653. ---------------
  654. Default: ``false``
  655. Support for `XEP-0280: Message Carbons <https://xmpp.org/extensions/xep-0280.html>`_
  656. In order to keep all IM clients for a user engaged in a conversation,
  657. outbound messages are carbon-copied to all interested resources.
  658. This is especially important in webchat, like converse.js, where each browser
  659. tab serves as a separate IM client.
  660. Both message_carbons and `forward_messages`_ try to solve the same problem
  661. (showing sent messages in all connected chat clients aka resources), but go about it
  662. in two different ways.
  663. Message carbons is the XEP (Jabber protocol extension) specifically drafted to
  664. solve this problem, while `forwarded_messages`_ uses
  665. `stanza forwarding <http://www.xmpp.org/extensions/xep-0297.html>`_
  666. expose_rid_and_sid
  667. ------------------
  668. Default: ``false``
  669. Allow the prebind tokens, RID (request ID) and SID (session ID), to be exposed
  670. globally via the API. This allows other scripts served on the same page to use
  671. these values.
  672. *Beware*: a malicious script could use these tokens to assume your identity
  673. and inject fake chat messages.
  674. forward_messages
  675. ----------------
  676. Default: ``false``
  677. If set to ``true``, sent messages will also be forwarded to the sending user's
  678. bare JID (their Jabber ID independent of any chat clients aka resources).
  679. This means that sent messages are visible from all the user's chat clients,
  680. and not just the one from which it was actually sent.
  681. This is especially important for web chat, such as converse.js, where each
  682. browser tab functions as a separate chat client, with its own resource.
  683. This feature uses Stanza forwarding, see also `XEP 0297: Stanza Forwarding <http://www.xmpp.org/extensions/xep-0297.html>`_
  684. For an alternative approach, see also `message carbons`_.
  685. fullname
  686. --------
  687. If you are using prebinding, can specify the fullname of the currently
  688. logged in user, otherwise the user's vCard will be fetched.
  689. hide_muc_server
  690. ---------------
  691. Default: ``false``
  692. Hide the ``server`` input field of the form inside the ``Room`` panel of the
  693. controlbox. Useful if you want to restrict users to a specific XMPP server of
  694. your choosing.
  695. i18n
  696. ----
  697. Specify the locale/language. The language must be in the ``locales`` object. Refer to
  698. ``./locale/locales.js`` to see which locales are supported.
  699. play_sounds
  700. -----------
  701. Default: ``false``
  702. Plays a notification sound when you receive a personal message or when your
  703. nickname is mentioned in a chat room.
  704. Inside the ``./sounds`` directory of the Converse.js repo, you'll see MP3 and Ogg
  705. formatted sound files. We need both, because neither format is supported by all browsers.
  706. For now, sound files are looked up by convention, not configuration. So to have
  707. a sound play when a message is received, make sure that your webserver serves
  708. it in both formats as ``http://yoursite.com/sounds/msg_received.mp3`` and
  709. ``http://yoursite.com/sounds/msg_received.ogg``.
  710. ``http://yoursite.com`` should of course be your site's URL.
  711. prebind
  712. --------
  713. Default: ``false``
  714. Use this option when you want to attach to an existing XMPP connection that was
  715. already authenticated (usually on the backend before page load).
  716. This is useful when you don't want to render the login form on the chat control
  717. box with each page load.
  718. For prebinding to work, your backend server must authenticate for you, and
  719. then return a JID (jabber ID), SID (session ID) and RID (Request ID).
  720. If you set ``prebind`` to ``true``, you have to make sure to also pass in these
  721. values as ``jid``, ``sid``, ``rid``.
  722. Additionally, you have to specify ``bosh_service_url``.
  723. roster_groups
  724. -------------
  725. Default: ``false``
  726. If set to ``true``, converse.js will show any roster groups you might have
  727. configured.
  728. .. Note ::
  729. It's currently not possible to use converse.js to assign contacts to groups.
  730. Converse.js can only show users and groups that were previously configured
  731. elsewhere.
  732. show_controlbox_by_default
  733. --------------------------
  734. Default: ``false``
  735. The "controlbox" refers to the special chatbox containing your contacts roster,
  736. status widget, chatrooms and other controls.
  737. By default this box is hidden and can be toggled by clicking on any element in
  738. the page with class *toggle-controlbox*.
  739. If this options is set to true, the controlbox will by default be shown upon
  740. page load.
  741. show_only_online_users
  742. ----------------------
  743. Default: ``false``
  744. If set to ``true``, only online users will be shown in the contacts roster.
  745. Users with any other status (e.g. away, busy etc.) will not be shown.
  746. storage
  747. -------
  748. Default: ``session``
  749. Valid options: ``session``, ``local``.
  750. This option determines the type of `storage <https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage>`_
  751. (``localStorage`` or ``sessionStorage``) used by converse.js to cache user data.
  752. Originally converse.js used only localStorage, however sessionStorage is from a
  753. privacy perspective a better choice.
  754. The main difference between the two is that sessionStorage only persists while
  755. the current tab or window containing a converse.js instance is open. As soon as
  756. it's closed, the data is cleared.
  757. Data in localStorage on the other hand is kept indefinitely.
  758. .. Note ::
  759. Since version 0.8.0, the use of local storage is not recommended. The
  760. statuses (online, away, busy etc.) of your roster contacts are cached in
  761. the browser storage. If you use local storage, these values are stored for
  762. multiple sessions, and they will likely become out of sync with your contacts'
  763. actual statuses. The session storage doesn't have this problem, because
  764. roster contact statuses will not become out of sync in a single session,
  765. only across more than one session.
  766. use_otr_by_default
  767. ------------------
  768. Default: ``false``
  769. If set to ``true``, Converse.js will automatically try to initiate an OTR (off-the-record)
  770. encrypted chat session every time you open a chat box.
  771. use_vcards
  772. ----------
  773. Default: ``true``
  774. Determines whether the XMPP server will be queried for roster contacts' VCards
  775. or not. VCards contain extra personal information such as your fullname and
  776. avatar image.
  777. visible_toolbar_buttons
  778. -----------------------
  779. Default:
  780. ::
  781. {
  782. call: false,
  783. clear: true,
  784. emoticons: true,
  785. toggle_participants: true
  786. }
  787. Allows you to show or hide buttons on the chat boxes' toolbars.
  788. * *call*:
  789. Provides a button with a picture of a telephone on it.
  790. When the call button is pressed, it will emit an event that can be used by a third-party library to initiate a call.::
  791. converse.on('callButtonClicked', function(event, data) {
  792. console.log('Strophe connection is', data.connection);
  793. console.log('Bare buddy JID is', data.model.get('jid'));
  794. // ... Third-party library code ...
  795. });
  796. * *clear*:
  797. Provides a button for clearing messages from a chat box.
  798. * *emoticons*:
  799. Enables rendering of emoticons and provides a toolbar button for choosing them.
  800. * toggle_participants:
  801. Shows a button for toggling (i.e. showing/hiding) the list of participants in a chat room.
  802. xhr_custom_status
  803. -----------------
  804. Default: ``false``
  805. .. Note ::
  806. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  807. This option will let converse.js make an AJAX POST with your changed custom chat status to a
  808. remote server.
  809. xhr_custom_status_url
  810. ---------------------
  811. .. Note ::
  812. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  813. Default: Empty string
  814. Used only in conjunction with ``xhr_custom_status``.
  815. This is the URL to which the AJAX POST request to set the user's custom status
  816. message will be made.
  817. The message itself is sent in the request under the key ``msg``.
  818. xhr_user_search
  819. ---------------
  820. Default: ``false``
  821. .. Note ::
  822. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  823. There are two ways to add users.
  824. * The user inputs a valid JID (Jabber ID), and the user is added as a pending contact.
  825. * 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.
  826. This setting enables the second mechanism, otherwise by default the first will be used.
  827. *What is expected from the remote server?*
  828. A default JSON encoded list of objects must be returned. Each object
  829. corresponds to a matched user and needs the keys ``id`` and ``fullname``.
  830. xhr_user_search_url
  831. -------------------
  832. .. Note ::
  833. XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
  834. Default: Empty string
  835. Used only in conjunction with ``xhr_user_search``.
  836. This is the URL to which an AJAX GET request will be made to fetch user data from your remote server.
  837. The query string will be included in the request with ``q`` as its key.
  838. The calendar can be configured through a `data-pat-calendar` attribute.
  839. The available options are:
  840. .. _`read more about require.js's optimizer here`: http://requirejs.org/docs/optimization.html
  841. .. _`HTTP`: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
  842. .. _`XMPP`: https://en.wikipedia.org/wiki/Xmpp
  843. .. _`Converse.js homepage`: http://conversejs.org
  844. .. _`CORS`: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing
  845. .. _`Strophe.js plugin`: https://gist.github.com/1095825/6b4517276f26b66b01fa97b0a78c01275fdc6ff2
  846. .. _`xmpp.net`: http://xmpp.net
  847. .. _`xmpp.org`: http://xmpp.org/xmpp-software/servers/
  848. .. _`ejabberd`: http://www.ejabberd.im
  849. .. _`blogpost`: http://metajack.im/2008/10/03/getting-attached-to-strophe
  850. .. _`example Django application`: https://github.com/metajack/strophejs/tree/master/examples/attach