index.html 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Quickstart (to get a demo up and running) &mdash; Converse.js 0.5 documentation</title>
  7. <link rel="stylesheet" href="_static/stylesheet.css" type="text/css" />
  8. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: '',
  12. VERSION: '0.5',
  13. COLLAPSE_INDEX: false,
  14. FILE_SUFFIX: '.html',
  15. HAS_SOURCE: true
  16. };
  17. </script>
  18. <script type="text/javascript" src="_static/jquery.js"></script>
  19. <script type="text/javascript" src="_static/underscore.js"></script>
  20. <script type="text/javascript" src="_static/doctools.js"></script>
  21. <link rel="top" title="Converse.js 0.5 documentation" href="#" />
  22. </head>
  23. <body>
  24. <div id="header_wrap" class="outer">
  25. <header class="inner">
  26. <a id="forkme_banner" href="https://github.com/jcbrand/converse.js">View on GitHub</a>
  27. <h1 id="project_title"><a href="http://conversejs.org">Converse.js</a></h1>
  28. <h2 id="project_tagline">Documentation</h2>
  29. <section id="downloads">
  30. <a class="zip_download_link" href="https://github.com/jcbrand/converse.js/zipball/master">Download this project as a .zip file</a>
  31. <a class="tar_download_link" href="https://github.com/jcbrand/converse.js/tarball/master">Download this project as a tar.gz file</a>
  32. </section>
  33. </header>
  34. </div>
  35. <div id="main_content_wrap" class="outer">
  36. <div class="related">
  37. <h3>Navigation</h3>
  38. <ul>
  39. <li class="right" style="margin-right: 10px">
  40. <a href="genindex.html" title="General Index"
  41. accesskey="I">index</a></li>
  42. <li><a href="#">Converse.js 0.5 documentation</a> &raquo;</li>
  43. </ul>
  44. </div>
  45. <section id="main_content" class="inner">
  46. <div class="document">
  47. <div class="documentwrapper">
  48. <div class="body">
  49. <div class="toctree-wrapper compound">
  50. <ul class="simple">
  51. </ul>
  52. </div>
  53. <div class="contents local topic" id="table-of-contents">
  54. <p class="topic-title first">Table of Contents</p>
  55. <ul class="simple">
  56. <li><a class="reference internal" href="#quickstart-to-get-a-demo-up-and-running" id="id2">Quickstart (to get a demo up and running)</a></li>
  57. <li><a class="reference internal" href="#introduction" id="id3">Introduction</a></li>
  58. <li><a class="reference internal" href="#what-you-will-need" id="id4">What you will need</a><ul>
  59. <li><a class="reference internal" href="#an-xmpp-jabber-server" id="id5">An XMPP/Jabber server</a></li>
  60. <li><a class="reference internal" href="#connection-manager" id="id6">Connection Manager</a><ul>
  61. <li><a class="reference internal" href="#overcoming-cross-domain-request-restrictions" id="id7">Overcoming cross-domain request restrictions</a></li>
  62. </ul>
  63. </li>
  64. <li><a class="reference internal" href="#server-side-authentication" id="id8">Server-side authentication</a><ul>
  65. <li><a class="reference internal" href="#pre-binding-and-single-session-support" id="id9">Pre-binding and Single Session Support</a></li>
  66. </ul>
  67. </li>
  68. </ul>
  69. </li>
  70. <li><a class="reference internal" href="#development" id="id10">Development</a><ul>
  71. <li><a class="reference internal" href="#install-node-js-and-development-dependencies" id="id11">Install Node.js and development dependencies</a></li>
  72. <li><a class="reference internal" href="#install-3rd-party-dependencies" id="id12">Install 3rd party dependencies</a></li>
  73. <li><a class="reference internal" href="#with-amd-and-require-js-recommended" id="id13">With AMD and require.js (recommended)</a></li>
  74. <li><a class="reference internal" href="#without-amd-and-require-js" id="id14">Without AMD and require.js</a></li>
  75. <li><a class="reference internal" href="#before-submitting-a-pull-request" id="id15">Before submitting a pull request</a><ul>
  76. <li><a class="reference internal" href="#add-tests-for-your-bugfix-or-feature" id="id16">Add tests for your bugfix or feature</a></li>
  77. <li><a class="reference internal" href="#check-that-the-tests-pass" id="id17">Check that the tests pass</a></li>
  78. <li><a class="reference internal" href="#check-your-code-for-errors-or-bad-habits-by-running-jshint" id="id18">Check your code for errors or bad habits by running JSHint</a></li>
  79. </ul>
  80. </li>
  81. </ul>
  82. </li>
  83. <li><a class="reference internal" href="#configuration" id="id19">Configuration</a><ul>
  84. <li><a class="reference internal" href="#configuration-variables" id="id20">Configuration variables</a><ul>
  85. <li><a class="reference internal" href="#animate" id="id21">animate</a></li>
  86. <li><a class="reference internal" href="#auto-list-rooms" id="id22">auto_list_rooms</a></li>
  87. <li><a class="reference internal" href="#auto-subscribe" id="id23">auto_subscribe</a></li>
  88. <li><a class="reference internal" href="#bosh-service-url" id="id24">bosh_service_url</a></li>
  89. <li><a class="reference internal" href="#fullname" id="id25">fullname</a></li>
  90. <li><a class="reference internal" href="#hide-muc-server" id="id26">hide_muc_server</a></li>
  91. <li><a class="reference internal" href="#prebind" id="id27">prebind</a></li>
  92. <li><a class="reference internal" href="#show-controlbox-by-default" id="id28">show_controlbox_by_default</a></li>
  93. <li><a class="reference internal" href="#xhr-user-search" id="id29">xhr_user_search</a></li>
  94. </ul>
  95. </li>
  96. </ul>
  97. </li>
  98. <li><a class="reference internal" href="#minification" id="id30">Minification</a><ul>
  99. <li><a class="reference internal" href="#minifying-javascript" id="id31">Minifying Javascript</a></li>
  100. <li><a class="reference internal" href="#minifying-css" id="id32">Minifying CSS</a></li>
  101. </ul>
  102. </li>
  103. <li><a class="reference internal" href="#translations" id="id33">Translations</a></li>
  104. </ul>
  105. </div>
  106. <div class="section" id="quickstart-to-get-a-demo-up-and-running">
  107. <h1><a class="toc-backref" href="#id2">Quickstart (to get a demo up and running)</a><a class="headerlink" href="#quickstart-to-get-a-demo-up-and-running" title="Permalink to this headline">¶</a></h1>
  108. <p>When you download a specific release of <em>Converse.js</em> there will be two minified files inside the zip file.</p>
  109. <ul class="simple">
  110. <li>converse.min.js</li>
  111. <li>converse.min.css</li>
  112. </ul>
  113. <p>You can include these two files inside the <em>&lt;head&gt;</em> element of your website via the <em>script</em> and <em>link</em>
  114. tags:</p>
  115. <div class="highlight-python"><pre>&lt;link rel="stylesheet" type="text/css" media="screen" href="converse.min.css"&gt;
  116. &lt;script src="converse.min.js"&gt;&lt;/script&gt;</pre>
  117. </div>
  118. <p>Then, at the bottom of your page, after the closing <em>&lt;/body&gt;</em> element, put the
  119. following inline Javascript code:</p>
  120. <div class="highlight-python"><pre>require(['converse'], function (converse) {
  121. converse.initialize({
  122. auto_list_rooms: false,
  123. auto_subscribe: false,
  124. bosh_service_url: 'https://bind.opkode.im', // Please use this connection manager only for testing purposes
  125. hide_muc_server: false,
  126. i18n: locales.en, // Refer to ./locale/locales.js to see which locales are supported
  127. prebind: false,
  128. show_controlbox_by_default: true,
  129. xhr_user_search: false
  130. });
  131. });</pre>
  132. </div>
  133. <p>The <em>index.html</em> file inside the Converse.js folder serves as a nice usable
  134. example of this.</p>
  135. <p>These minified files provide the same demo-like functionality as is available
  136. on the <a class="reference external" href="http://conversejs.org">conversejs.org</a> website. Useful for testing or demoing, but not very
  137. practical.</p>
  138. <p>You&#8217;ll most likely want to implement some kind of single-signon solution for
  139. your website, where users authenticate once in your website and then stay
  140. logged into their XMPP session upon page reload.</p>
  141. <p>For more info on this, read: <a class="reference internal" href="#pre-binding-and-single-session-support">Pre-binding and Single Session Support</a>.</p>
  142. <p>You might also want to have more fine-grained control of what gets included in
  143. the minified Javascript file. Read <a class="reference internal" href="#configuration">Configuration</a> and <a class="reference internal" href="#minification">Minification</a> for more info on how to do
  144. that.</p>
  145. </div>
  146. <div class="section" id="introduction">
  147. <h1><a class="toc-backref" href="#id3">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h1>
  148. <p>Even though you can connect to public XMPP servers on the <a class="reference external" href="http://conversejs.org">conversejs.org</a>
  149. website, <em>Converse.js</em> is not really meant to be a &#8220;Software-as-a-service&#8221; (SaaS)
  150. webchat.</p>
  151. <p>Instead, its goal is to provide the means for website owners to add a tightly
  152. integrated instant messaging service to their own sites.</p>
  153. <p>As a website owner, you are expected to host <em>Converse.js</em> yourself, and to do some legwork to
  154. properly configure and integrate it into your site.</p>
  155. <p>The benefit in doing this, is that your users have a much more streamlined and integrated
  156. webchat experience and that you have control over the data. The latter being a
  157. requirement for many sites dealing with sensitive information.</p>
  158. <p>You&#8217;ll need to set up your own XMPP server and in order to have
  159. <a class="reference internal" href="#session-support">Session Support</a> (i.e. single-signon functionality whereby users are authenticated once and stay
  160. logged in to XMPP upon page reload) you will also have to add some server-side
  161. code.</p>
  162. <p>The <a class="reference internal" href="#what-you-will-need">What you will need</a> section has more information on all these
  163. requirements.</p>
  164. </div>
  165. <div class="section" id="what-you-will-need">
  166. <h1><a class="toc-backref" href="#id4">What you will need</a><a class="headerlink" href="#what-you-will-need" title="Permalink to this headline">¶</a></h1>
  167. <div class="section" id="an-xmpp-jabber-server">
  168. <h2><a class="toc-backref" href="#id5">An XMPP/Jabber server</a><a class="headerlink" href="#an-xmpp-jabber-server" title="Permalink to this headline">¶</a></h2>
  169. <p><em>Converse.js</em> implements <a class="reference external" href="https://en.wikipedia.org/wiki/Xmpp">XMPP</a> as its messaging protocol, and therefore needs
  170. to connect to an XMPP/Jabber server (Jabber is really just a synonym for XMPP).</p>
  171. <p>You can connect to public XMPP servers like <tt class="docutils literal"><span class="pre">jabber.org</span></tt> but if you want to
  172. have <a class="reference internal" href="#session-support">Session Support</a> you&#8217;ll have to set up your own XMPP server.</p>
  173. <p>You can find a list of public XMPP servers/providers on <a class="reference external" href="http://xmpp.net">xmpp.net</a> and a list of
  174. servers that you can set up yourself on <a class="reference external" href="http://xmpp.org/xmpp-software/servers/">xmpp.org</a>.</p>
  175. </div>
  176. <div class="section" id="connection-manager">
  177. <h2><a class="toc-backref" href="#id6">Connection Manager</a><a class="headerlink" href="#connection-manager" title="Permalink to this headline">¶</a></h2>
  178. <p>Your website and <em>Converse.js</em> use <a class="reference external" href="https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP</a> as protocol to communicate with
  179. the webserver. HTTP connections are stateless and usually shortlived.</p>
  180. <p><a class="reference external" href="https://en.wikipedia.org/wiki/Xmpp">XMPP</a> on the other hand, is the protocol that enables instant messaging, and
  181. its connections are stateful and usually longer.</p>
  182. <p>To enable a web application like <em>Converse.js</em> to communicate with an XMPP
  183. server, we need a proxy in the middle that can act as a bridge between the two
  184. protocols.</p>
  185. <p>This is the job of a connection manager. A connection manager can be either a
  186. standalone application or part of an XMPP server. <a class="reference external" href="http://www.ejabberd.im">ejabberd</a> for example,
  187. includes a connection manager (but you have to enable it).</p>
  188. <p>The demo on the <a class="reference external" href="http://conversejs.org">Converse.js homepage</a> uses a a connection manager located at <a class="reference external" href="https://bind.opkode.im">https://bind.opkode.im</a>.
  189. This connection manager is for testing purposes only, please don&#8217;t use it in
  190. production.</p>
  191. <div class="section" id="overcoming-cross-domain-request-restrictions">
  192. <h3><a class="toc-backref" href="#id7">Overcoming cross-domain request restrictions</a><a class="headerlink" href="#overcoming-cross-domain-request-restrictions" title="Permalink to this headline">¶</a></h3>
  193. <p>The domain of the <em>Converse.js</em> demo is <em>conversejs.org</em>, but the domain of the connection manager is <em>opkode.im</em>.
  194. HTTP requests are made by <em>Converse.js</em> to the connection manager via XmlHttpRequests (XHR).
  195. Until recently, it was not possible to make such requests to a different domain
  196. than the one currently being served (to prevent XSS attacks).</p>
  197. <p>Luckily there is now a standard called <a class="reference external" href="https://en.wikipedia.org/wiki/Cross-origin_resource_sharing">CORS</a> (Cross-origin resource sharing), which enables exactly that.
  198. Modern browsers support CORS, but there are problems with Internet Explorer &lt;
  199. 10.</p>
  200. <p>IE 8 and 9 partially support CORS via a proprietary implementation called
  201. XDomainRequest. There is a <a class="reference external" href="https://gist.github.com/1095825/6b4517276f26b66b01fa97b0a78c01275fdc6ff2">Strophe.js plugin</a> which you can use to enable
  202. support for XDomainRequest when it is present.</p>
  203. <p>In IE &lt; 8, there is no support for CORS.</p>
  204. <p>If you need to support these browsers, you can add a front-end proxy in
  205. Apache/Nginx which serves the connection manager under the same domain as your
  206. website. This will remove the need for any cross-domain XHR support.</p>
  207. </div>
  208. </div>
  209. <div class="section" id="server-side-authentication">
  210. <h2><a class="toc-backref" href="#id8">Server-side authentication</a><a class="headerlink" href="#server-side-authentication" title="Permalink to this headline">¶</a></h2>
  211. <div class="section" id="pre-binding-and-single-session-support">
  212. <span id="session-support"></span><h3><a class="toc-backref" href="#id9">Pre-binding and Single Session Support</a><a class="headerlink" href="#pre-binding-and-single-session-support" title="Permalink to this headline">¶</a></h3>
  213. <p>It&#8217;s possible to enable single-site login, whereby users already
  214. authenticated in your website will also automatically be logged in on the chat server,
  215. but this will require custom code on your server.</p>
  216. <p>Jack Moffitt has a great <a class="reference external" href="http://metajack.im/2008/10/03/getting-attached-to-strophe">blogpost</a> about this and even provides an <a class="reference external" href="https://github.com/metajack/strophejs/tree/master/examples/attach">example Django application</a> to demonstrate it.</p>
  217. <div class="admonition note">
  218. <p class="first admonition-title">Note</p>
  219. <p class="last">If you want to enable single session support, make sure to pass <strong>prebind: true</strong>
  220. when you call <strong>converse.initialize</strong> (see ./index.html).</p>
  221. </div>
  222. <p>When you authenticate to the XMPP server on your backend, you&#8217;ll receive two
  223. tokens, RID (request ID) and SID (session ID).</p>
  224. <p>These tokens then need to be passed back to the javascript running in your
  225. browser, where you will need them attach to the existing session.</p>
  226. <p>You can embed the RID and SID tokens in your HTML markup or you can do an
  227. XMLHttpRequest call to you server and ask it to return them for you.</p>
  228. <p>Below is one example of how this could work. An Ajax call is made to the
  229. relative URL <strong>/prebind</strong> and it expects to receive JSON data back.</p>
  230. <div class="highlight-python"><pre>$.getJSON('/prebind', function (data) {
  231. var connection = new Strophe.Connection(converse.bosh_service_url);
  232. connection.attach(data.jid, data.sid, data.rid, function (status) {
  233. if ((status === Strophe.Status.ATTACHED) || (status === Strophe.Status.CONNECTED)) {
  234. converse.onConnected(connection)
  235. }
  236. });
  237. }
  238. );</pre>
  239. </div>
  240. <p><strong>Here&#8217;s what&#8217;s happening:</strong></p>
  241. <p>The JSON data contains the user&#8217;s JID (jabber ID), RID and SID. The URL to the
  242. BOSH connection manager is already set as a configuration setting on the
  243. <em>converse</em> object (see ./main.js), so we can reuse it from there.</p>
  244. <p>A new Strophe.Connection object is instantiated and then <em>attach</em> is called with
  245. the user&#8217;s JID, the necessary tokens and a callback function.</p>
  246. <p>In the callback function, you call <em>converse.onConnected</em> together with the
  247. connection object.</p>
  248. </div>
  249. </div>
  250. </div>
  251. <div class="section" id="development">
  252. <h1><a class="toc-backref" href="#id10">Development</a><a class="headerlink" href="#development" title="Permalink to this headline">¶</a></h1>
  253. <div class="section" id="install-node-js-and-development-dependencies">
  254. <h2><a class="toc-backref" href="#id11">Install Node.js and development dependencies</a><a class="headerlink" href="#install-node-js-and-development-dependencies" title="Permalink to this headline">¶</a></h2>
  255. <p>We use development tools (<a class="reference external" href="http://gruntjs.com">Grunt</a> and <a class="reference external" href="http://bower.io">Bower</a>)
  256. which depend on Node.js and npm (the Node package manager).</p>
  257. <p>If you don&#8217;t have Node.js installed, you can download and install the latest
  258. version <a class="reference external" href="https://nodejs.org/download">here</a>.</p>
  259. <p>Once you have Node.js installed, run the following command in the Converse.js
  260. directory:</p>
  261. <div class="highlight-python"><pre>npm install</pre>
  262. </div>
  263. </div>
  264. <div class="section" id="install-3rd-party-dependencies">
  265. <h2><a class="toc-backref" href="#id12">Install 3rd party dependencies</a><a class="headerlink" href="#install-3rd-party-dependencies" title="Permalink to this headline">¶</a></h2>
  266. <p>Now that we have Grunt and Bower, you can install and configure Converse&#8217;s
  267. 3rd party dependencies with the following command:</p>
  268. <div class="highlight-python"><pre>grunt fetch</pre>
  269. </div>
  270. </div>
  271. <div class="section" id="with-amd-and-require-js-recommended">
  272. <h2><a class="toc-backref" href="#id13">With AMD and require.js (recommended)</a><a class="headerlink" href="#with-amd-and-require-js-recommended" title="Permalink to this headline">¶</a></h2>
  273. <p>Converse.js uses <a class="reference external" href="http://requirejs.org">require.js</a> to asynchronously load dependencies.</p>
  274. <p>If you want to develop or customize converse.js, you&#8217;ll want to load the
  275. non-minified javascript files.</p>
  276. <p>Add the following two lines to the <em>&lt;head&gt;</em> section of your webpage:</p>
  277. <div class="highlight-python"><pre>&lt;link rel="stylesheet" type="text/css" media="screen" href="converse.css"&gt;
  278. &lt;script data-main="main" src="components/requirejs/require.js"&gt;&lt;/script&gt;</pre>
  279. </div>
  280. <p>require.js will then let the main.js file be parsed (because of the <em>data-main</em>
  281. attribute on the <em>script</em> tag), which will in turn cause converse.js to be
  282. parsed.</p>
  283. </div>
  284. <div class="section" id="without-amd-and-require-js">
  285. <h2><a class="toc-backref" href="#id14">Without AMD and require.js</a><a class="headerlink" href="#without-amd-and-require-js" title="Permalink to this headline">¶</a></h2>
  286. <p>Converse.js can also be used without require.js. If you for some reason prefer
  287. to use it this way, please refer to
  288. <a class="reference external" href="https://github.com/jcbrand/converse.js/blob/master/non_amd.html">non_amd.html</a>
  289. for an example of how and in what order all the Javascript files that converse.js
  290. depends on need to be loaded.</p>
  291. </div>
  292. <div class="section" id="before-submitting-a-pull-request">
  293. <h2><a class="toc-backref" href="#id15">Before submitting a pull request</a><a class="headerlink" href="#before-submitting-a-pull-request" title="Permalink to this headline">¶</a></h2>
  294. <div class="section" id="add-tests-for-your-bugfix-or-feature">
  295. <h3><a class="toc-backref" href="#id16">Add tests for your bugfix or feature</a><a class="headerlink" href="#add-tests-for-your-bugfix-or-feature" title="Permalink to this headline">¶</a></h3>
  296. <p>Add a test for any bug fixed or feature added. We use Jasmine
  297. for testing.</p>
  298. <p>Take a look at <tt class="docutils literal"><span class="pre">tests.html</span></tt> and <tt class="docutils literal"><span class="pre">spec/MainSpec.js</span></tt> to see how
  299. the tests are implemented.</p>
  300. <p>If you are unsure how to write tests, please
  301. <a class="reference external" href="http://conversejs.org">contact me</a> and I&#8217;ll be happy to help.</p>
  302. </div>
  303. <div class="section" id="check-that-the-tests-pass">
  304. <h3><a class="toc-backref" href="#id17">Check that the tests pass</a><a class="headerlink" href="#check-that-the-tests-pass" title="Permalink to this headline">¶</a></h3>
  305. <p>Check that the Jasmine tests complete sucessfully. Open
  306. <a class="reference external" href="https://github.com/jcbrand/converse.js/blob/master/tests.html">tests.html</a>
  307. in your browser, and the tests will run automatically.</p>
  308. <p>On the command line you can run:</p>
  309. <div class="highlight-python"><pre>grunt test</pre>
  310. </div>
  311. </div>
  312. <div class="section" id="check-your-code-for-errors-or-bad-habits-by-running-jshint">
  313. <h3><a class="toc-backref" href="#id18">Check your code for errors or bad habits by running JSHint</a><a class="headerlink" href="#check-your-code-for-errors-or-bad-habits-by-running-jshint" title="Permalink to this headline">¶</a></h3>
  314. <p><a class="reference external" href="http://jshint.com">JSHint</a> will do a static analysis of your code and hightlight potential errors
  315. and/or bad habits.</p>
  316. <div class="highlight-python"><pre>grunt jshint</pre>
  317. </div>
  318. <p>You can run both the tests and jshint in one go by calling:</p>
  319. <div class="highlight-python"><pre>grunt check</pre>
  320. </div>
  321. </div>
  322. </div>
  323. </div>
  324. <div class="section" id="configuration">
  325. <h1><a class="toc-backref" href="#id19">Configuration</a><a class="headerlink" href="#configuration" title="Permalink to this headline">¶</a></h1>
  326. <p>The included minified JS and CSS files can be used for demoing or testing, but
  327. you&#8217;ll want to configure <em>Converse.js</em> to suit your needs before you deploy it
  328. on your website.</p>
  329. <p><em>Converse.js</em> is passed its configuration settings when you call its
  330. <em>initialize</em> method.</p>
  331. <p>You&#8217;ll most likely want to call the <em>initialize</em> method in your HTML page. For
  332. an example of how this is done, please see the bottom of the <em>./index.html</em> page.</p>
  333. <p>Please refer to the <a class="reference internal" href="#configuration-variables">Configuration variables</a> section below for info on
  334. all the available configuration settings.</p>
  335. <p>After you have configured <em>Converse.js</em>, you&#8217;ll have to regenerate the minified
  336. JS file so that it will include the new settings. Please refer to the
  337. <a class="reference internal" href="#minification">Minification</a> section for more info on how to do this.</p>
  338. <div class="section" id="configuration-variables">
  339. <h2><a class="toc-backref" href="#id20">Configuration variables</a><a class="headerlink" href="#configuration-variables" title="Permalink to this headline">¶</a></h2>
  340. <div class="section" id="animate">
  341. <h3><a class="toc-backref" href="#id21">animate</a><a class="headerlink" href="#animate" title="Permalink to this headline">¶</a></h3>
  342. <p>Default = True</p>
  343. <p>Show animations, for example when opening and closing chat boxes.</p>
  344. </div>
  345. <div class="section" id="auto-list-rooms">
  346. <h3><a class="toc-backref" href="#id22">auto_list_rooms</a><a class="headerlink" href="#auto-list-rooms" title="Permalink to this headline">¶</a></h3>
  347. <p>Default = False</p>
  348. <p>If true, and the XMPP server on which the current user is logged in supports
  349. multi-user chat, then a list of rooms on that server will be fetched.</p>
  350. <p>Not recommended for servers with lots of chat rooms.</p>
  351. <p>For each room on the server a query is made to fetch further details (e.g.
  352. features, number of occupants etc.), so on servers with many rooms this
  353. option will create lots of extra connection traffic.</p>
  354. </div>
  355. <div class="section" id="auto-subscribe">
  356. <h3><a class="toc-backref" href="#id23">auto_subscribe</a><a class="headerlink" href="#auto-subscribe" title="Permalink to this headline">¶</a></h3>
  357. <p>Default = False</p>
  358. <p>If true, the user will automatically subscribe back to any contact requests.</p>
  359. </div>
  360. <div class="section" id="bosh-service-url">
  361. <h3><a class="toc-backref" href="#id24">bosh_service_url</a><a class="headerlink" href="#bosh-service-url" title="Permalink to this headline">¶</a></h3>
  362. <p>Connections to an XMPP server depend on a BOSH connection manager which acts as
  363. a middle man between HTTP and XMPP.</p>
  364. <p>See <a class="reference external" href="http://metajack.im/2008/09/08/which-bosh-server-do-you-need">here</a> for more information.</p>
  365. </div>
  366. <div class="section" id="fullname">
  367. <h3><a class="toc-backref" href="#id25">fullname</a><a class="headerlink" href="#fullname" title="Permalink to this headline">¶</a></h3>
  368. <p>If you are using prebinding, you need to specify the fullname of the currently
  369. logged in user.</p>
  370. </div>
  371. <div class="section" id="hide-muc-server">
  372. <h3><a class="toc-backref" href="#id26">hide_muc_server</a><a class="headerlink" href="#hide-muc-server" title="Permalink to this headline">¶</a></h3>
  373. <p>Default = False</p>
  374. <p>Hide the <tt class="docutils literal"><span class="pre">server</span></tt> input field of the form inside the <tt class="docutils literal"><span class="pre">Room</span></tt> panel of the
  375. controlbox. Useful if you want to restrict users to a specific XMPP server of
  376. your choosing.</p>
  377. </div>
  378. <div class="section" id="prebind">
  379. <h3><a class="toc-backref" href="#id27">prebind</a><a class="headerlink" href="#prebind" title="Permalink to this headline">¶</a></h3>
  380. <p>Default = False</p>
  381. <p>Use this option when you want to attach to an existing XMPP connection that was
  382. already authenticated (usually on the backend before page load).</p>
  383. <p>This is useful when you don&#8217;t want to render the login form on the chat control
  384. box with each page load.</p>
  385. <p>When set to true, you&#8217;ll need to make sure that the onConnected method is
  386. called, and passed to it a Strophe connection object.</p>
  387. <p>Besides requiring the back-end to authenticate you, you&#8217;ll also
  388. have to write a Javascript snippet to attach to the set up connection:</p>
  389. <div class="highlight-python"><pre>$.JSON({
  390. 'url': 'mysite.com/xmpp-authenticate',
  391. 'success': function (data) {
  392. connection = new Strophe.Connection(bosh_service_url);
  393. connection.attach(data.jid, data.sid, data.rid, converse.onConnected);
  394. }</pre>
  395. </div>
  396. <p>The backend must authenticate for you, and then return a SID (session ID) and
  397. RID (Request ID), which you use when you attach to the connection.</p>
  398. </div>
  399. <div class="section" id="show-controlbox-by-default">
  400. <h3><a class="toc-backref" href="#id28">show_controlbox_by_default</a><a class="headerlink" href="#show-controlbox-by-default" title="Permalink to this headline">¶</a></h3>
  401. <p>Default = False</p>
  402. <p>The &#8220;controlbox&#8221; refers to the special chatbox containing your contacts roster,
  403. status widget, chatrooms and other controls.</p>
  404. <p>By default this box is hidden and can be toggled by clicking on any element in
  405. the page with class <em>toggle-online-users</em>.</p>
  406. <p>If this options is set to true, the controlbox will by default be shown upon
  407. page load.</p>
  408. </div>
  409. <div class="section" id="xhr-user-search">
  410. <h3><a class="toc-backref" href="#id29">xhr_user_search</a><a class="headerlink" href="#xhr-user-search" title="Permalink to this headline">¶</a></h3>
  411. <p>Default = False</p>
  412. <p>There are two ways to add users.</p>
  413. <ul class="simple">
  414. <li>The user inputs a valid JID (Jabber ID), and the user is added as a pending contact.</li>
  415. <li>The user inputs some text (for example part of a firstname or lastname), an XHR will be made to a backend, and a list of matches are returned. The user can then choose one of the matches to add as a contact.</li>
  416. </ul>
  417. <p>This setting enables the second mechanism, otherwise by default the first will
  418. be used.</p>
  419. </div>
  420. </div>
  421. </div>
  422. <div class="section" id="minification">
  423. <h1><a class="toc-backref" href="#id30">Minification</a><a class="headerlink" href="#minification" title="Permalink to this headline">¶</a></h1>
  424. <div class="section" id="minifying-javascript">
  425. <h2><a class="toc-backref" href="#id31">Minifying Javascript</a><a class="headerlink" href="#minifying-javascript" title="Permalink to this headline">¶</a></h2>
  426. <p>We use <a class="reference external" href="http://requirejs.org">require.js</a> to keep track of <em>Converse.js</em> and its dependencies and to
  427. to bundle them together in a single minified file fit for deployment to a
  428. production site.</p>
  429. <p>To use the require.js&#8217;s optimization tool, you&#8217;ll need Node and it&#8217;s package
  430. manager, NPM.</p>
  431. <p>You can then install install require.js for Node like so:</p>
  432. <div class="highlight-python"><pre>npm install requirejs</pre>
  433. </div>
  434. <p>The minified javascript file is then created like this:</p>
  435. <div class="highlight-python"><pre>r.js -o build.js</pre>
  436. </div>
  437. <p>You should now have a new minified file (the name which is specified in build.js).</p>
  438. <p>You can <a class="reference external" href="http://requirejs.org/docs/optimization.html">read more about require.js&#8217;s optimizer here</a>.</p>
  439. </div>
  440. <div class="section" id="minifying-css">
  441. <h2><a class="toc-backref" href="#id32">Minifying CSS</a><a class="headerlink" href="#minifying-css" title="Permalink to this headline">¶</a></h2>
  442. <p>CSS can be minimized with Yahoo&#8217;s yuicompressor tool:</p>
  443. <div class="highlight-python"><pre>yui-compressor --type=css converse.css -o converse.min.css</pre>
  444. </div>
  445. </div>
  446. </div>
  447. <div class="section" id="translations">
  448. <h1><a class="toc-backref" href="#id33">Translations</a><a class="headerlink" href="#translations" title="Permalink to this headline">¶</a></h1>
  449. <div class="admonition note">
  450. <p class="first admonition-title">Note</p>
  451. <p class="last">Translations take up a lot of space and will bloat your minified file.
  452. At the time of writing, all the translations add about 50KB of extra data to
  453. the minified javascript file. Therefore, make sure to only
  454. include those languages that you intend to support and remove from
  455. ./locale/locales.js those which you don&#8217;t need. Remember to rebuild the
  456. minified file afterwards.</p>
  457. </div>
  458. <p>The gettext POT file located in ./locale/converse.pot is the template
  459. containing all translations and from which for each language an individual PO
  460. file is generated.</p>
  461. <p>The POT file contains all translateable strings extracted from converse.js.</p>
  462. <p>To make a user facing string translateable, wrap it in the double underscore helper
  463. function like so:</p>
  464. <div class="highlight-python"><div class="highlight"><pre><span class="n">__</span><span class="p">(</span><span class="s">&#39;This string will be translated at runtime&#39;</span><span class="p">);</span>
  465. </pre></div>
  466. </div>
  467. <p>After adding the string, you&#8217;ll need to regenerate the POT file, like so:</p>
  468. <div class="highlight-python"><pre>make pot</pre>
  469. </div>
  470. <p>You can then create or update the PO file for a specific language by doing the following:</p>
  471. <div class="highlight-python"><pre>msgmerge ./locale/af/LC_MESSAGES/converse.po ./locale/converse.pot -U</pre>
  472. </div>
  473. <p>This PO file is then what gets translated.</p>
  474. <p>If you&#8217;ve created a new PO file, please make sure to add the following
  475. attributes at the top of the file (under <em>Content-Transfer-Encoding</em>). They are
  476. required as configuration settings for Jed, the Javascript translations library
  477. that we&#8217;re using.</p>
  478. <div class="highlight-python"><div class="highlight"><pre><span class="s">&quot;domain: converse</span><span class="se">\n</span><span class="s">&quot;</span>
  479. <span class="s">&quot;lang: af</span><span class="se">\n</span><span class="s">&quot;</span>
  480. <span class="s">&quot;plural_forms: nplurals=2; plural=(n != 1);</span><span class="se">\n</span><span class="s">&quot;</span>
  481. </pre></div>
  482. </div>
  483. <p>Unfortunately Jed cannot use the PO files directly. We have to generate from it
  484. a file in JSON format and then put that in a .js file for the specific
  485. language.</p>
  486. <p>To generate JSON from a PO file, you&#8217;ll need po2json for node.js. Run the
  487. following command to install it (npm being the node.js package manager):</p>
  488. <div class="highlight-python"><pre>npm install po2json</pre>
  489. </div>
  490. <p>You can then convert the translations into JSON format:</p>
  491. <div class="highlight-python"><pre>po2json locale/af/LC_MESSAGES/converse.po locale/af/LC_MESSAGES/converse.json</pre>
  492. </div>
  493. <p>Now from converse.json paste the data as a value for the &#8220;locale_data&#8221; key in the
  494. object in the language&#8217;s .js file.</p>
  495. <p>So, if you are for example translating into German (language code &#8216;de&#8217;), you&#8217;ll
  496. create or update the file ./locale/LC_MESSAGES/de.js with the following code:</p>
  497. <div class="highlight-python"><pre>(function (root, factory) {
  498. define("af", ['jed'], function () {
  499. return factory(new Jed({
  500. "domain": "converse",
  501. "locale_data": {
  502. // Paste the JSON data from converse.json here
  503. }
  504. })
  505. }
  506. }(this, function (i18n) {
  507. return i18n;
  508. }));</pre>
  509. </div>
  510. <p>making sure to also paste the JSON data as value to the &#8220;locale_data&#8221; key.</p>
  511. <div class="admonition note">
  512. <p class="first admonition-title">Note</p>
  513. <p class="last">If you are adding translations for a new language that is not already supported,
  514. you&#8217;ll have to make one more edit in ./locale/locales.js to make sure the
  515. language is loaded by require.js.</p>
  516. </div>
  517. <p>Congratulations, you&#8217;ve now succesfully added your translations. Sorry for all
  518. those hoops you had to jump through.</p>
  519. </div>
  520. </div>
  521. </div>
  522. <div class="clearer"></div>
  523. </div>
  524. </section>
  525. <div class="related">
  526. <h3>Navigation</h3>
  527. <ul>
  528. <li class="right" style="margin-right: 10px">
  529. <a href="genindex.html" title="General Index"
  530. >index</a></li>
  531. <li><a href="#">Converse.js 0.5 documentation</a> &raquo;</li>
  532. </ul>
  533. </div>
  534. </div>
  535. <div id="footer_wrap" class="outer">
  536. <footer class="inner">
  537. &copy; Copyright 2013, JC Brand.
  538. <p class="copyright">Converse.js created by <a href="http://opkode.com" target="_blank">jcbrand</a></p>
  539. </footer>
  540. </div>
  541. </body>
  542. </html>