index.html 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  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.7.1 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.7.1',
  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.7.1 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.7.1 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="id3">Quickstart (to get a demo up and running)</a></li>
  57. <li><a class="reference internal" href="#introduction" id="id4">Introduction</a></li>
  58. <li><a class="reference internal" href="#what-you-will-need" id="id5">What you will need</a><ul>
  59. <li><a class="reference internal" href="#an-xmpp-jabber-server" id="id6">An XMPP/Jabber server</a></li>
  60. <li><a class="reference internal" href="#connection-manager" id="id7">Connection Manager</a><ul>
  61. <li><a class="reference internal" href="#overcoming-cross-domain-request-restrictions" id="id8">Overcoming cross-domain request restrictions</a></li>
  62. </ul>
  63. </li>
  64. <li><a class="reference internal" href="#server-side-authentication" id="id9">Server-side authentication</a><ul>
  65. <li><a class="reference internal" href="#prebinding-and-single-session-support" id="id10">Prebinding and Single Session Support</a></li>
  66. <li><a class="reference internal" href="#setting-up-a-bosh-server" id="id11">Setting up a BOSH server</a></li>
  67. </ul>
  68. </li>
  69. <li><a class="reference internal" href="#facebook-integration" id="id12">Facebook integration</a></li>
  70. </ul>
  71. </li>
  72. <li><a class="reference internal" href="#development" id="id13">Development</a><ul>
  73. <li><a class="reference internal" href="#install-node-js-and-development-dependencies" id="id14">Install Node.js and development dependencies</a></li>
  74. <li><a class="reference internal" href="#install-3rd-party-dependencies" id="id15">Install 3rd party dependencies</a></li>
  75. <li><a class="reference internal" href="#with-amd-and-require-js-recommended" id="id16">With AMD and require.js (recommended)</a></li>
  76. <li><a class="reference internal" href="#without-amd-and-require-js" id="id17">Without AMD and require.js</a></li>
  77. <li><a class="reference internal" href="#before-submitting-a-pull-request" id="id18">Before submitting a pull request</a><ul>
  78. <li><a class="reference internal" href="#add-tests-for-your-bugfix-or-feature" id="id19">Add tests for your bugfix or feature</a></li>
  79. <li><a class="reference internal" href="#check-that-the-tests-pass" id="id20">Check that the tests pass</a></li>
  80. <li><a class="reference internal" href="#check-your-code-for-errors-or-bad-habits-by-running-jshint" id="id21">Check your code for errors or bad habits by running JSHint</a></li>
  81. </ul>
  82. </li>
  83. </ul>
  84. </li>
  85. <li><a class="reference internal" href="#troubleshooting" id="id22">Troubleshooting</a><ul>
  86. <li><a class="reference internal" href="#conflicts-with-other-javascript-libraries" id="id23">Conflicts with other Javascript libraries</a><ul>
  87. <li><a class="reference internal" href="#problem" id="id24">Problem:</a></li>
  88. <li><a class="reference internal" href="#solution" id="id25">Solution:</a></li>
  89. </ul>
  90. </li>
  91. </ul>
  92. </li>
  93. <li><a class="reference internal" href="#configuration" id="id26">Configuration</a><ul>
  94. <li><a class="reference internal" href="#configuration-variables" id="id27">Configuration variables</a><ul>
  95. <li><a class="reference internal" href="#allow-contact-requests" id="id28">allow_contact_requests</a></li>
  96. <li><a class="reference internal" href="#allow-muc" id="id29">allow_muc</a></li>
  97. <li><a class="reference internal" href="#animate" id="id30">animate</a></li>
  98. <li><a class="reference internal" href="#auto-list-rooms" id="id31">auto_list_rooms</a></li>
  99. <li><a class="reference internal" href="#auto-subscribe" id="id32">auto_subscribe</a></li>
  100. <li><a class="reference internal" href="#bosh-service-url" id="id33">bosh_service_url</a></li>
  101. <li><a class="reference internal" href="#debug" id="id34">debug</a></li>
  102. <li><a class="reference internal" href="#fullname" id="id35">fullname</a></li>
  103. <li><a class="reference internal" href="#hide-muc-server" id="id36">hide_muc_server</a></li>
  104. <li><a class="reference internal" href="#i18n" id="id37">i18n</a></li>
  105. <li><a class="reference internal" href="#prebind" id="id38">prebind</a></li>
  106. <li><a class="reference internal" href="#show-controlbox-by-default" id="id39">show_controlbox_by_default</a></li>
  107. <li><a class="reference internal" href="#show-only-online-users" id="id40">show_only_online_users</a></li>
  108. <li><a class="reference internal" href="#xhr-custom-status" id="id41">xhr_custom_status</a></li>
  109. <li><a class="reference internal" href="#xhr-custom-status-url" id="id42">xhr_custom_status_url</a></li>
  110. <li><a class="reference internal" href="#xhr-user-search" id="id43">xhr_user_search</a></li>
  111. <li><a class="reference internal" href="#xhr-user-search-url" id="id44">xhr_user_search_url</a></li>
  112. </ul>
  113. </li>
  114. </ul>
  115. </li>
  116. <li><a class="reference internal" href="#minification" id="id45">Minification</a><ul>
  117. <li><a class="reference internal" href="#minifying-javascript-and-css" id="id46">Minifying Javascript and CSS</a></li>
  118. </ul>
  119. </li>
  120. <li><a class="reference internal" href="#translations" id="id47">Translations</a></li>
  121. </ul>
  122. </div>
  123. <div class="section" id="quickstart-to-get-a-demo-up-and-running">
  124. <h1><a class="toc-backref" href="#id3">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>
  125. <p>When you download a specific release of <em>Converse.js</em> there will be two minified files inside the zip file.</p>
  126. <ul class="simple">
  127. <li>converse.min.js</li>
  128. <li>converse.min.css</li>
  129. </ul>
  130. <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>
  131. tags:</p>
  132. <div class="highlight-python"><pre>&lt;link rel="stylesheet" type="text/css" media="screen" href="converse.min.css"&gt;
  133. &lt;script src="converse.min.js"&gt;&lt;/script&gt;</pre>
  134. </div>
  135. <p>You need to initialize Converse.js with configuration settings particular to
  136. your requirements.</p>
  137. <p>Please refer to the <a class="reference internal" href="#configuration-variables">Configuration variables</a> section further below for info on
  138. all the available configuration settings.</p>
  139. <p>To do this, put the following inline Javascript code at the
  140. bottom of your page (after the closing <em>&lt;/body&gt;</em> element).</p>
  141. <div class="highlight-python"><pre>require(['converse'], function (converse) {
  142. converse.initialize({
  143. auto_list_rooms: false,
  144. auto_subscribe: false,
  145. bosh_service_url: 'https://bind.opkode.im', // Please use this connection manager only for testing purposes
  146. hide_muc_server: false,
  147. i18n: locales.en, // Refer to ./locale/locales.js to see which locales are supported
  148. prebind: false,
  149. show_controlbox_by_default: true,
  150. xhr_user_search: false
  151. });
  152. });</pre>
  153. </div>
  154. <p>Finally, Converse.js requires a special snippet of HTML markup to be included in your page:</p>
  155. <div class="highlight-python"><pre>&lt;div id="conversejs"&gt;&lt;/div&gt;</pre>
  156. </div>
  157. <p>The <a class="reference external" href="https://github.com/jcbrand/converse.js/blob/master/index.html">index.html</a> file inside the
  158. Converse.js repository serves as a nice usable example of this.</p>
  159. <p>These minified files provide the same demo-like functionality as is available
  160. on the <a class="reference external" href="http://conversejs.org">conversejs.org</a> website. Useful for testing or demoing, but not very
  161. practical.</p>
  162. <p>You&#8217;ll most likely want to implement some kind of single-signon solution for
  163. your website, where users authenticate once in your website and then stay
  164. logged into their XMPP session upon page reload.</p>
  165. <p>For more info on this, read: <a href="#id48"><span class="problematic" id="id49">`Pre-binding and Single Session Support`_</span></a>.</p>
  166. <p>You might also want to have more fine-grained control of what gets included in
  167. 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
  168. that.</p>
  169. </div>
  170. <div class="section" id="introduction">
  171. <h1><a class="toc-backref" href="#id4">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h1>
  172. <p>Even though you can connect to public XMPP servers on the <a class="reference external" href="http://conversejs.org">conversejs.org</a>
  173. website, <em>Converse.js</em> is not really meant to be a &#8220;Software-as-a-service&#8221; (SaaS)
  174. webchat.</p>
  175. <p>Instead, its goal is to provide the means for website owners to add a tightly
  176. integrated instant messaging service to their own sites.</p>
  177. <p>As a website owner, you are expected to host <em>Converse.js</em> yourself, and to do some legwork to
  178. properly configure and integrate it into your site.</p>
  179. <p>The benefit in doing this, is that your users have a much more streamlined and integrated
  180. webchat experience and that you have control over the data. The latter being a
  181. requirement for many sites dealing with sensitive information.</p>
  182. <p>You&#8217;ll need to set up your own XMPP server and in order to have
  183. <a class="reference internal" href="#session-support">Session Support</a> (i.e. single-signon functionality whereby users are authenticated once and stay
  184. logged in to XMPP upon page reload) you will also have to add some server-side
  185. code.</p>
  186. <p>The <a class="reference internal" href="#what-you-will-need">What you will need</a> section has more information on all these
  187. requirements.</p>
  188. </div>
  189. <div class="section" id="what-you-will-need">
  190. <h1><a class="toc-backref" href="#id5">What you will need</a><a class="headerlink" href="#what-you-will-need" title="Permalink to this headline">¶</a></h1>
  191. <div class="section" id="an-xmpp-jabber-server">
  192. <h2><a class="toc-backref" href="#id6">An XMPP/Jabber server</a><a class="headerlink" href="#an-xmpp-jabber-server" title="Permalink to this headline">¶</a></h2>
  193. <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
  194. to connect to an XMPP/Jabber server (Jabber is really just a synonym for XMPP).</p>
  195. <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
  196. have <a class="reference internal" href="#session-support">Session Support</a> you&#8217;ll have to set up your own XMPP server.</p>
  197. <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
  198. servers that you can set up yourself on <a class="reference external" href="http://xmpp.org/xmpp-software/servers/">xmpp.org</a>.</p>
  199. </div>
  200. <div class="section" id="connection-manager">
  201. <h2><a class="toc-backref" href="#id7">Connection Manager</a><a class="headerlink" href="#connection-manager" title="Permalink to this headline">¶</a></h2>
  202. <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
  203. the webserver. HTTP connections are stateless and usually shortlived.</p>
  204. <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
  205. its connections are stateful and usually longer.</p>
  206. <p>To enable a web application like <em>Converse.js</em> to communicate with an XMPP
  207. server, we need a proxy in the middle that can act as a bridge between the two
  208. protocols.</p>
  209. <p>This is the job of a connection manager. A connection manager can be either a
  210. standalone application or part of an XMPP server. <a class="reference external" href="http://www.ejabberd.im">ejabberd</a> for example,
  211. includes a connection manager (but you have to enable it).</p>
  212. <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>.
  213. This connection manager is for testing purposes only, please don&#8217;t use it in
  214. production.</p>
  215. <div class="section" id="overcoming-cross-domain-request-restrictions">
  216. <h3><a class="toc-backref" href="#id8">Overcoming cross-domain request restrictions</a><a class="headerlink" href="#overcoming-cross-domain-request-restrictions" title="Permalink to this headline">¶</a></h3>
  217. <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>.
  218. HTTP requests are made by <em>Converse.js</em> to the connection manager via XmlHttpRequests (XHR).
  219. Until recently, it was not possible to make such requests to a different domain
  220. than the one currently being served (to prevent XSS attacks).</p>
  221. <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.
  222. Modern browsers support CORS, but there are problems with Internet Explorer &lt;
  223. 10.</p>
  224. <p>IE 8 and 9 partially support CORS via a proprietary implementation called
  225. 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
  226. support for XDomainRequest when it is present.</p>
  227. <p>In IE &lt; 8, there is no support for CORS.</p>
  228. <p>Instead of using CORS, you can add a reverse proxy in
  229. Apache/Nginx which serves the connection manager under the same domain as your
  230. website. This will remove the need for any cross-domain XHR support.</p>
  231. <div class="section" id="for-example">
  232. <h4>For example:<a class="headerlink" href="#for-example" title="Permalink to this headline">¶</a></h4>
  233. <p>Assuming your site is accessible on port <tt class="docutils literal"><span class="pre">80</span></tt> for the domain <tt class="docutils literal"><span class="pre">mysite.com</span></tt>
  234. and your connection manager manager is running at <tt class="docutils literal"><span class="pre">someothersite.com/http-bind</span></tt>.</p>
  235. <p>The <em>bosh_service_url</em> value you want to give Converse.js to overcome
  236. the cross-domain restriction is <tt class="docutils literal"><span class="pre">mysite.com/http-bind</span></tt> and not
  237. <tt class="docutils literal"><span class="pre">someothersite.com/http-bind</span></tt>.</p>
  238. <p>Your <tt class="docutils literal"><span class="pre">nginx</span></tt> or <tt class="docutils literal"><span class="pre">apache</span></tt> configuration will look as follows:</p>
  239. </div>
  240. <div class="section" id="nginx">
  241. <h4>Nginx<a class="headerlink" href="#nginx" title="Permalink to this headline">¶</a></h4>
  242. <div class="highlight-python"><pre>http {
  243. server {
  244. listen 80
  245. server_name mysite.com;
  246. location ~ ^/http-bind/ {
  247. proxy_pass http://someothersite.com;
  248. }
  249. }
  250. }</pre>
  251. </div>
  252. </div>
  253. <div class="section" id="apache">
  254. <h4>Apache<a class="headerlink" href="#apache" title="Permalink to this headline">¶</a></h4>
  255. <div class="highlight-python"><pre>&lt;VirtualHost *:80&gt;
  256. ServerName mysite.com
  257. RewriteEngine On
  258. RewriteRule ^/http-bind(.*) http://someothersite.com/http-bind$1 [P,L]
  259. &lt;/VirtualHost&gt;</pre>
  260. </div>
  261. </div>
  262. </div>
  263. </div>
  264. <div class="section" id="server-side-authentication">
  265. <h2><a class="toc-backref" href="#id9">Server-side authentication</a><a class="headerlink" href="#server-side-authentication" title="Permalink to this headline">¶</a></h2>
  266. <div class="section" id="prebinding-and-single-session-support">
  267. <span id="session-support"></span><h3><a class="toc-backref" href="#id10">Prebinding and Single Session Support</a><a class="headerlink" href="#prebinding-and-single-session-support" title="Permalink to this headline">¶</a></h3>
  268. <p>It&#8217;s possible to enable single-site login, whereby users already
  269. authenticated in your website will also automatically be logged in on the chat server,</p>
  270. <p>This session should also persist across page loads. In other words, we don&#8217;t
  271. want the user to have to give their chat credentials every time they reload the
  272. page.</p>
  273. <p>To do this you will require a <a class="reference external" href="http://xmpp.org/about-xmpp/technology-overview/bosh/">BOSH server</a>
  274. for converse.js to connect to (see the <a class="reference internal" href="#bosh-service-url">bosh_service_url</a> under <a class="reference internal" href="#configuration-variables">Configuration variables</a>)
  275. as well as a BOSH client on your own server (written for example in Python, Ruby or PHP) that will
  276. do the pre-authentication before the web page loads.</p>
  277. <div class="admonition note">
  278. <p class="first admonition-title">Note</p>
  279. <p class="last">A BOSH server acts as a bridge between HTTP, the protocol of the web, and
  280. XMPP, the instant messaging protocol.
  281. Converse.js can only communicate via HTTP, but we need to communicate with
  282. an XMPP server in order to chat. So the BOSH server acts as a middle man,
  283. translating our HTTP requests into XMPP stanzas and vice versa.</p>
  284. </div>
  285. <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>
  286. <p>When you authenticate to the XMPP server on your backend application (for
  287. example via a BOSH client in Django), you&#8217;ll receive two tokens, RID (request ID) and SID (session ID).</p>
  288. <p>The <strong>Session ID (SID)</strong> is a unique identifier for the current <em>session</em>. This
  289. number stays constant for the entire session.</p>
  290. <p>The <strong>Request ID (RID)</strong> is a unique identifier for the current <em>request</em> (i.e.
  291. page load). Each page load is a new request which requires a new unique RID.
  292. The best way to achieve this is to simply increment the RID with each page
  293. load.</p>
  294. <p>When you initialize converse.js in your browser, you need to pass it these two
  295. tokens. Converse.js will then use them to attach to the session you just
  296. created.</p>
  297. <p>You can embed the RID and SID tokens in your HTML markup or you can do an
  298. XMLHttpRequest call to your server and ask it to return them for you.</p>
  299. <p>Below is one example of how this could work. An Ajax call is made to the
  300. relative URL <strong>/prebind</strong> and it expects to receive JSON data back.</p>
  301. <div class="highlight-python"><pre>$.getJSON('/prebind', function (data) {
  302. converse.initialize({
  303. prebind: true,
  304. bosh_service_url: data.bosh_service_url,
  305. jid: data.jid,
  306. sid: data.sid,
  307. rid: data.rid
  308. });
  309. );</pre>
  310. </div>
  311. <p><strong>Here&#8217;s what&#8217;s happening:</strong></p>
  312. <p>The JSON data returned from the Ajax call to example.com/prebind contains the user&#8217;s JID (jabber ID), RID, SID and the URL to the
  313. BOSH server (also called a <em>connection manager</em>).</p>
  314. <p>These values are then passed to converse.js&#8217;s <tt class="docutils literal"><span class="pre">initialize</span></tt> method.</p>
  315. <div class="admonition note">
  316. <p class="first admonition-title">Note</p>
  317. <p class="last">If you want to enable single session support, you need to set <strong>prebind: true</strong>
  318. when calling <strong>converse.initialize</strong> (see ./index.html).
  319. Additionally you need to pass in valid <strong>jid</strong>, <strong>sid</strong>, <strong>rid</strong> and
  320. <strong>bosh_service_url</strong> values.</p>
  321. </div>
  322. </div>
  323. <div class="section" id="setting-up-a-bosh-server">
  324. <h3><a class="toc-backref" href="#id11">Setting up a BOSH server</a><a class="headerlink" href="#setting-up-a-bosh-server" title="Permalink to this headline">¶</a></h3>
  325. <p>The <a class="reference external" href="http://movim.eu/">Movim</a> project wiki has a very thorough page on setting up a BOSH server for
  326. a wide variety of standalone or XMPP servers.</p>
  327. <p><a class="reference external" href="http://wiki.movim.eu/manual:bosh_servers">http://wiki.movim.eu/manual:bosh_servers</a></p>
  328. </div>
  329. </div>
  330. <div class="section" id="facebook-integration">
  331. <h2><a class="toc-backref" href="#id12">Facebook integration</a><a class="headerlink" href="#facebook-integration" title="Permalink to this headline">¶</a></h2>
  332. <div class="admonition note">
  333. <p class="first admonition-title">Note</p>
  334. <p class="last">It should be possible to integrate Converse.js with Facebook chat, and
  335. below I&#8217;ll provide some tips and documentation on how to achieve this. That
  336. said, I don&#8217;t have a Facebook account and therefore haven&#8217;t tried to do
  337. this myself. Feedback and patches from people who have succesfully done this
  338. will be appreciated.</p>
  339. </div>
  340. <p>Converse.js uses <a class="reference external" href="http://strophe.im/strophejs">Strophe.js</a> to connect and
  341. communicate with the XMPP server. One nice thing about Strophe.js is that it
  342. can be extended via <a class="reference external" href="http://github.com/strophe/strophejs-plugins">plugins</a>.</p>
  343. <p>Here is a <a class="reference external" href="https://github.com/kissrobber/turedsocial/blob/master/strophe-plugins/src/facebook.js">plugin for authenticating with facebook</a>.</p>
  344. <p>You will need your own BOSH connection manager to act as a proxy between
  345. Converse.js/Strophe.js and Facebook&#8217;s XMPP server. That is because Facebook&#8217;s
  346. XMPP server doesn&#8217;t support BOSH natively.</p>
  347. <p>The BOSH connection manager that I make available for
  348. testing purposes (at <a class="reference external" href="https://bind.opkode.im">https://bind.opkode.im</a>) uses <a class="reference external" href="https://github.com/twonds/punjab">Punjab</a>,
  349. although there are quite a few other options available as well.</p>
  350. <p>When you configure Converse.js, via its <tt class="docutils literal"><span class="pre">initialize</span></tt> method, you must specify the
  351. <a class="reference internal" href="#bosh-service-url">bosh_service_url</a> value, which is to be your BOSH connection manager.</p>
  352. <p>Please note, to enable Facebook integration, you&#8217;ll have to
  353. get your hands dirty and modify Converse.js&#8217;s code, so that it calls the
  354. <tt class="docutils literal"><span class="pre">facebookConnect</span></tt> method of the plugin above.</p>
  355. <p>The plugin above gives the following code example for you to meditate upon:</p>
  356. <div class="highlight-python"><pre>connection = new Strophe.Connection("http://localhost:5280/bosh");
  357. connection.facebookConnect(
  358. "12345@chat.facebook.com",
  359. onConnectFacebook,
  360. 300,
  361. 1,
  362. '5e64a30272af065bd72258c565a03f2f',
  363. '8147a27e4a7f9b55ffc85c2683f9529a',
  364. FB.getSession().session_key
  365. );</pre>
  366. </div>
  367. <p>The connection is already created inside Converse.js, so the
  368. <tt class="docutils literal"><span class="pre">facebookConnect</span></tt> method needs to also be called from there.</p>
  369. <p>If someone submits a sane patch that does the above, I&#8217;ll be happy to merge it.
  370. Until then, people will have to do this themselves.</p>
  371. </div>
  372. </div>
  373. <div class="section" id="development">
  374. <h1><a class="toc-backref" href="#id13">Development</a><a class="headerlink" href="#development" title="Permalink to this headline">¶</a></h1>
  375. <p>If you want to work with the non-minified Javascript and CSS files you&#8217;ll soon
  376. notice that there are references to a missing <em>components</em> folder. Please
  377. follow the instructions below to create this folder and fetch Converse&#8217;s
  378. 3rd-party dependencies.</p>
  379. <div class="section" id="install-node-js-and-development-dependencies">
  380. <h2><a class="toc-backref" href="#id14">Install Node.js and development dependencies</a><a class="headerlink" href="#install-node-js-and-development-dependencies" title="Permalink to this headline">¶</a></h2>
  381. <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>)
  382. which depend on Node.js and npm (the Node package manager).</p>
  383. <p>If you don&#8217;t have Node.js installed, you can download and install the latest
  384. version <a class="reference external" href="https://nodejs.org/download">here</a>.</p>
  385. <p>Once you have Node.js installed, run the following command inside the Converse.js
  386. directory:</p>
  387. <div class="highlight-python"><pre>npm install</pre>
  388. </div>
  389. <p>This will install all the development dependencies for Converse.js. If you are
  390. curious to know what these are, take a look at whats under the <em>devDependencies</em> key in
  391. <cite>package.json &lt;https://github.com/jcbrand/converse.js/blob/master/package.json&gt;</cite>.</p>
  392. </div>
  393. <div class="section" id="install-3rd-party-dependencies">
  394. <h2><a class="toc-backref" href="#id15">Install 3rd party dependencies</a><a class="headerlink" href="#install-3rd-party-dependencies" title="Permalink to this headline">¶</a></h2>
  395. <p>After running <tt class="docutils literal"><span class="pre">npm</span> <span class="pre">install</span></tt>, you will now have Grunt and Bower installed.</p>
  396. <p>We use Bower to manage Converse&#8217;s front-end dependencies (e.g. Javascript that
  397. should get loaded in the browser).</p>
  398. <p>To fetch these dependencies, run:</p>
  399. <div class="highlight-python"><pre>grunt fetch</pre>
  400. </div>
  401. <p>If you don&#8217;t have grunt installed globally, you need to specify the relative
  402. path:</p>
  403. <dl class="docutils">
  404. <dt>::</dt>
  405. <dd>./node_modules/.bin/grunt fetch</dd>
  406. </dl>
  407. <p>This will call Bower in the background to fetch all the front-end
  408. dependencies (like backbone.js, strophe.js etc.) and then put them in the
  409. <em>components</em> folder.</p>
  410. </div>
  411. <div class="section" id="with-amd-and-require-js-recommended">
  412. <h2><a class="toc-backref" href="#id16">With AMD and require.js (recommended)</a><a class="headerlink" href="#with-amd-and-require-js-recommended" title="Permalink to this headline">¶</a></h2>
  413. <p>Converse.js uses <a class="reference external" href="http://requirejs.org">require.js</a> to asynchronously load dependencies.</p>
  414. <p>If you want to develop or customize converse.js, you&#8217;ll want to load the
  415. non-minified javascript files.</p>
  416. <p>Add the following two lines to the <em>&lt;head&gt;</em> section of your webpage:</p>
  417. <div class="highlight-python"><pre>&lt;link rel="stylesheet" type="text/css" media="screen" href="converse.css"&gt;
  418. &lt;script data-main="main" src="components/requirejs/require.js"&gt;&lt;/script&gt;</pre>
  419. </div>
  420. <p>require.js will then let the main.js file be parsed (because of the <em>data-main</em>
  421. attribute on the <em>script</em> tag), which will in turn cause converse.js to be
  422. parsed.</p>
  423. </div>
  424. <div class="section" id="without-amd-and-require-js">
  425. <h2><a class="toc-backref" href="#id17">Without AMD and require.js</a><a class="headerlink" href="#without-amd-and-require-js" title="Permalink to this headline">¶</a></h2>
  426. <p>Converse.js can also be used without require.js. If you for some reason prefer
  427. to use it this way, please refer to
  428. <a class="reference external" href="https://github.com/jcbrand/converse.js/blob/master/non_amd.html">non_amd.html</a>
  429. for an example of how and in what order all the Javascript files that converse.js
  430. depends on need to be loaded.</p>
  431. </div>
  432. <div class="section" id="before-submitting-a-pull-request">
  433. <h2><a class="toc-backref" href="#id18">Before submitting a pull request</a><a class="headerlink" href="#before-submitting-a-pull-request" title="Permalink to this headline">¶</a></h2>
  434. <div class="section" id="add-tests-for-your-bugfix-or-feature">
  435. <h3><a class="toc-backref" href="#id19">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>
  436. <p>Add a test for any bug fixed or feature added. We use Jasmine
  437. for testing.</p>
  438. <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
  439. the tests are implemented.</p>
  440. <p>If you are unsure how to write tests, please
  441. <a class="reference external" href="http://opkode.com/contact">contact me</a> and I&#8217;ll be happy to help.</p>
  442. </div>
  443. <div class="section" id="check-that-the-tests-pass">
  444. <h3><a class="toc-backref" href="#id20">Check that the tests pass</a><a class="headerlink" href="#check-that-the-tests-pass" title="Permalink to this headline">¶</a></h3>
  445. <p>Check that the Jasmine tests complete sucessfully. Open
  446. <a class="reference external" href="https://github.com/jcbrand/converse.js/blob/master/tests.html">tests.html</a>
  447. in your browser, and the tests will run automatically.</p>
  448. <p>On the command line you can run:</p>
  449. <div class="highlight-python"><pre>grunt test</pre>
  450. </div>
  451. </div>
  452. <div class="section" id="check-your-code-for-errors-or-bad-habits-by-running-jshint">
  453. <h3><a class="toc-backref" href="#id21">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>
  454. <p><a class="reference external" href="http://jshint.com">JSHint</a> will do a static analysis of your code and hightlight potential errors
  455. and/or bad habits.</p>
  456. <div class="highlight-python"><pre>grunt jshint</pre>
  457. </div>
  458. <p>You can run both the tests and jshint in one go by calling:</p>
  459. <div class="highlight-python"><pre>grunt check</pre>
  460. </div>
  461. </div>
  462. </div>
  463. </div>
  464. <div class="section" id="troubleshooting">
  465. <h1><a class="toc-backref" href="#id22">Troubleshooting</a><a class="headerlink" href="#troubleshooting" title="Permalink to this headline">¶</a></h1>
  466. <div class="section" id="conflicts-with-other-javascript-libraries">
  467. <h2><a class="toc-backref" href="#id23">Conflicts with other Javascript libraries</a><a class="headerlink" href="#conflicts-with-other-javascript-libraries" title="Permalink to this headline">¶</a></h2>
  468. <div class="section" id="problem">
  469. <h3><a class="toc-backref" href="#id24">Problem:</a><a class="headerlink" href="#problem" title="Permalink to this headline">¶</a></h3>
  470. <p>You are using other Javascript libraries (like JQuery plugins), and
  471. get errors like these in your browser console:</p>
  472. <div class="highlight-python"><pre>Uncaught TypeError: Object [object Object] has no method 'xxx' from example.js</pre>
  473. </div>
  474. </div>
  475. <div class="section" id="solution">
  476. <h3><a class="toc-backref" href="#id25">Solution:</a><a class="headerlink" href="#solution" title="Permalink to this headline">¶</a></h3>
  477. <p>First, find out which object is referred to by <tt class="docutils literal"><span class="pre">Object</span> <span class="pre">[object</span> <span class="pre">Object]</span></tt>.</p>
  478. <p>It will probably be the jQuery object <tt class="docutils literal"><span class="pre">$</span></tt> or perhaps the underscore.js object <tt class="docutils literal"><span class="pre">_</span></tt>.</p>
  479. <p>For the purpose of demonstration, I&#8217;m going to assume its <tt class="docutils literal"><span class="pre">$</span></tt>, but the same
  480. rules apply if its something else.</p>
  481. <p>The bundled and minified default build of converse.js, <tt class="docutils literal"><span class="pre">converse.min.js</span></tt>
  482. includes within it all of converse.js&#8217;s dependencies, which include for example <em>jQuery</em>.</p>
  483. <p>If you are having conflicts where attributes or methods aren&#8217;t available
  484. on the jQuery object, you are probably loading <tt class="docutils literal"><span class="pre">converse.min.js</span></tt> (which
  485. includes jQuery) as well as your own jQuery version separately.</p>
  486. <p>What then happens is that there are two <tt class="docutils literal"><span class="pre">$</span></tt> objects (one from
  487. converse.js and one from the jQuery version you included manually)
  488. and only one of them has been extended to have the methods or attributes you require.</p>
  489. <p>Which jQuery object you get depends on the order in which you load the libraries.</p>
  490. <p>There are multiple ways to solve this issue.</p>
  491. <p>Firstly, make sure whether you really need to include a separate version of
  492. jQuery. Chances are that you don&#8217;t. If you can remove the separate
  493. version, your problem should be solved, as long as your libraries are loaded in
  494. the right order.</p>
  495. <p>Either case, whether you need to keep two versions or not, the solution depends
  496. on whether you&#8217;ll use require.js to manage your libraries or whether you&#8217;ll
  497. load them manually.</p>
  498. <div class="section" id="with-require-js">
  499. <h4>With require.js<a class="headerlink" href="#with-require-js" title="Permalink to this headline">¶</a></h4>
  500. <p>Instead of using <tt class="docutils literal"><span class="pre">converse.min.js</span></tt>, manage all the libraries in your project
  501. (i.e. converse.js and its dependencies plus all other libraries you use) as one
  502. require.js project, making sure everything is loaded in the correct order.</p>
  503. <p>Then, before deployment, you make your own custom minified build that bundles everything
  504. you need.</p>
  505. </div>
  506. <div class="section" id="with-script-tags">
  507. <h4>With &lt;script&gt; tags<a class="headerlink" href="#with-script-tags" title="Permalink to this headline">¶</a></h4>
  508. <p>Take a look at <a class="reference external" href="https://github.com/jcbrand/converse.js/blob/master/non_amd.html">non_amd.html</a>
  509. in the converse.js repo.</p>
  510. <p>It shows in which order the libraries must be loaded via <tt class="docutils literal"><span class="pre">&lt;script&gt;</span></tt> tags. Add
  511. your own libraries, making sure that they are loaded in the correct order (e.g.
  512. jQuery plugins must load after jQuery).</p>
  513. </div>
  514. </div>
  515. </div>
  516. </div>
  517. <div class="section" id="configuration">
  518. <h1><a class="toc-backref" href="#id26">Configuration</a><a class="headerlink" href="#configuration" title="Permalink to this headline">¶</a></h1>
  519. <p>The included minified JS and CSS files can be used for demoing or testing, but
  520. you&#8217;ll want to configure <em>Converse.js</em> to suit your needs before you deploy it
  521. on your website.</p>
  522. <p><em>Converse.js</em> is passed its configuration settings when you call its
  523. <em>initialize</em> method.</p>
  524. <p>You&#8217;ll most likely want to call the <em>initialize</em> method in your HTML page. For
  525. an example of how this is done, please see the bottom of the <em>./index.html</em> page.</p>
  526. <p>Please refer to the <a class="reference internal" href="#configuration-variables">Configuration variables</a> section below for info on
  527. all the available configuration settings.</p>
  528. <p>After you have configured <em>Converse.js</em>, you&#8217;ll have to regenerate the minified
  529. JS file so that it will include the new settings. Please refer to the
  530. <a class="reference internal" href="#minification">Minification</a> section for more info on how to do this.</p>
  531. <div class="section" id="configuration-variables">
  532. <h2><a class="toc-backref" href="#id27">Configuration variables</a><a class="headerlink" href="#configuration-variables" title="Permalink to this headline">¶</a></h2>
  533. <div class="section" id="allow-contact-requests">
  534. <h3><a class="toc-backref" href="#id28">allow_contact_requests</a><a class="headerlink" href="#allow-contact-requests" title="Permalink to this headline">¶</a></h3>
  535. <p>Default = <tt class="docutils literal"><span class="pre">true</span></tt></p>
  536. <p>Allow users to add one another as contacts. If this is set to false, the
  537. <strong>Add a contact</strong> widget, <strong>Contact Requests</strong> and <strong>Pending Contacts</strong> roster
  538. sections will all not appear. Additionally, all incoming contact requests will be
  539. ignored.</p>
  540. </div>
  541. <div class="section" id="allow-muc">
  542. <h3><a class="toc-backref" href="#id29">allow_muc</a><a class="headerlink" href="#allow-muc" title="Permalink to this headline">¶</a></h3>
  543. <p>Default = <tt class="docutils literal"><span class="pre">true</span></tt></p>
  544. <p>Allow multi-user chat (muc) in chatrooms. Setting this to <tt class="docutils literal"><span class="pre">false</span></tt> will remove
  545. the <tt class="docutils literal"><span class="pre">Chatrooms</span></tt> tab from the control box.</p>
  546. </div>
  547. <div class="section" id="animate">
  548. <h3><a class="toc-backref" href="#id30">animate</a><a class="headerlink" href="#animate" title="Permalink to this headline">¶</a></h3>
  549. <p>Default = <tt class="docutils literal"><span class="pre">true</span></tt></p>
  550. <p>Show animations, for example when opening and closing chat boxes.</p>
  551. </div>
  552. <div class="section" id="auto-list-rooms">
  553. <h3><a class="toc-backref" href="#id31">auto_list_rooms</a><a class="headerlink" href="#auto-list-rooms" title="Permalink to this headline">¶</a></h3>
  554. <p>Default = <tt class="docutils literal"><span class="pre">false</span></tt></p>
  555. <p>If true, and the XMPP server on which the current user is logged in supports
  556. multi-user chat, then a list of rooms on that server will be fetched.</p>
  557. <p>Not recommended for servers with lots of chat rooms.</p>
  558. <p>For each room on the server a query is made to fetch further details (e.g.
  559. features, number of occupants etc.), so on servers with many rooms this
  560. option will create lots of extra connection traffic.</p>
  561. </div>
  562. <div class="section" id="auto-subscribe">
  563. <h3><a class="toc-backref" href="#id32">auto_subscribe</a><a class="headerlink" href="#auto-subscribe" title="Permalink to this headline">¶</a></h3>
  564. <p>Default = <tt class="docutils literal"><span class="pre">false</span></tt></p>
  565. <p>If true, the user will automatically subscribe back to any contact requests.</p>
  566. </div>
  567. <div class="section" id="bosh-service-url">
  568. <h3><a class="toc-backref" href="#id33">bosh_service_url</a><a class="headerlink" href="#bosh-service-url" title="Permalink to this headline">¶</a></h3>
  569. <p>Connections to an XMPP server depend on a BOSH connection manager which acts as
  570. a middle man between HTTP and XMPP.</p>
  571. <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>
  572. </div>
  573. <div class="section" id="debug">
  574. <h3><a class="toc-backref" href="#id34">debug</a><a class="headerlink" href="#debug" title="Permalink to this headline">¶</a></h3>
  575. <p>Default = <tt class="docutils literal"><span class="pre">false</span></tt></p>
  576. <p>If set to true, debugging output will be logged to the browser console.</p>
  577. </div>
  578. <div class="section" id="fullname">
  579. <h3><a class="toc-backref" href="#id35">fullname</a><a class="headerlink" href="#fullname" title="Permalink to this headline">¶</a></h3>
  580. <p>If you are using prebinding, can specify the fullname of the currently
  581. logged in user, otherwise the user&#8217;s vCard will be fetched.</p>
  582. </div>
  583. <div class="section" id="hide-muc-server">
  584. <h3><a class="toc-backref" href="#id36">hide_muc_server</a><a class="headerlink" href="#hide-muc-server" title="Permalink to this headline">¶</a></h3>
  585. <p>Default = <tt class="docutils literal"><span class="pre">false</span></tt></p>
  586. <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
  587. controlbox. Useful if you want to restrict users to a specific XMPP server of
  588. your choosing.</p>
  589. </div>
  590. <div class="section" id="i18n">
  591. <h3><a class="toc-backref" href="#id37">i18n</a><a class="headerlink" href="#i18n" title="Permalink to this headline">¶</a></h3>
  592. <p>Specify the locale/language. The language must be in the <tt class="docutils literal"><span class="pre">locales</span></tt> object. Refer to
  593. <tt class="docutils literal"><span class="pre">./locale/locales.js</span></tt> to see which locales are supported.</p>
  594. </div>
  595. <div class="section" id="prebind">
  596. <h3><a class="toc-backref" href="#id38">prebind</a><a class="headerlink" href="#prebind" title="Permalink to this headline">¶</a></h3>
  597. <p>Default = <tt class="docutils literal"><span class="pre">false</span></tt></p>
  598. <p>Use this option when you want to attach to an existing XMPP connection that was
  599. already authenticated (usually on the backend before page load).</p>
  600. <p>This is useful when you don&#8217;t want to render the login form on the chat control
  601. box with each page load.</p>
  602. <p>For prebinding to work, your backend server must authenticate for you, and
  603. then return a JID (jabber ID), SID (session ID) and RID (Request ID).</p>
  604. <p>If you set <tt class="docutils literal"><span class="pre">prebind</span></tt> to <tt class="docutils literal"><span class="pre">true</span></tt>, you have to make sure to also pass in these
  605. values as <tt class="docutils literal"><span class="pre">jid</span></tt>, <tt class="docutils literal"><span class="pre">sid</span></tt>, <tt class="docutils literal"><span class="pre">rid</span></tt>.</p>
  606. <p>Additionally, you have to specify <tt class="docutils literal"><span class="pre">bosh_service_url</span></tt>.</p>
  607. </div>
  608. <div class="section" id="show-controlbox-by-default">
  609. <h3><a class="toc-backref" href="#id39">show_controlbox_by_default</a><a class="headerlink" href="#show-controlbox-by-default" title="Permalink to this headline">¶</a></h3>
  610. <p>Default = <tt class="docutils literal"><span class="pre">false</span></tt></p>
  611. <p>The &#8220;controlbox&#8221; refers to the special chatbox containing your contacts roster,
  612. status widget, chatrooms and other controls.</p>
  613. <p>By default this box is hidden and can be toggled by clicking on any element in
  614. the page with class <em>toggle-online-users</em>.</p>
  615. <p>If this options is set to true, the controlbox will by default be shown upon
  616. page load.</p>
  617. </div>
  618. <div class="section" id="show-only-online-users">
  619. <h3><a class="toc-backref" href="#id40">show_only_online_users</a><a class="headerlink" href="#show-only-online-users" title="Permalink to this headline">¶</a></h3>
  620. <p>Default = <tt class="docutils literal"><span class="pre">false</span></tt></p>
  621. <p>If set to <tt class="docutils literal"><span class="pre">true</span></tt>, only online users will be shown in the contacts roster.
  622. Users with any other status (e.g. away, busy etc.) will not be shown.</p>
  623. </div>
  624. <div class="section" id="xhr-custom-status">
  625. <h3><a class="toc-backref" href="#id41">xhr_custom_status</a><a class="headerlink" href="#xhr-custom-status" title="Permalink to this headline">¶</a></h3>
  626. <p>Default = <tt class="docutils literal"><span class="pre">false</span></tt></p>
  627. <div class="admonition note">
  628. <p class="first admonition-title">Note</p>
  629. <p class="last">XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).</p>
  630. </div>
  631. <p>This option will let converse.js make an AJAX POST with your changed custom chat status to a
  632. remote server.</p>
  633. </div>
  634. <div class="section" id="xhr-custom-status-url">
  635. <h3><a class="toc-backref" href="#id42">xhr_custom_status_url</a><a class="headerlink" href="#xhr-custom-status-url" title="Permalink to this headline">¶</a></h3>
  636. <div class="admonition note">
  637. <p class="first admonition-title">Note</p>
  638. <p class="last">XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).</p>
  639. </div>
  640. <p>Default = Empty string</p>
  641. <p>Used only in conjunction with <tt class="docutils literal"><span class="pre">xhr_custom_status</span></tt>.</p>
  642. <p>This is the URL to which the AJAX POST request to set the user&#8217;s custom status
  643. message will be made.</p>
  644. <p>The message itself is sent in the request under the key <tt class="docutils literal"><span class="pre">msg</span></tt>.</p>
  645. </div>
  646. <div class="section" id="xhr-user-search">
  647. <h3><a class="toc-backref" href="#id43">xhr_user_search</a><a class="headerlink" href="#xhr-user-search" title="Permalink to this headline">¶</a></h3>
  648. <p>Default = <tt class="docutils literal"><span class="pre">false</span></tt></p>
  649. <div class="admonition note">
  650. <p class="first admonition-title">Note</p>
  651. <p class="last">XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).</p>
  652. </div>
  653. <p>There are two ways to add users.</p>
  654. <ul class="simple">
  655. <li>The user inputs a valid JID (Jabber ID), and the user is added as a pending contact.</li>
  656. <li>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.</li>
  657. </ul>
  658. <p>This setting enables the second mechanism, otherwise by default the first will be used.</p>
  659. <p><em>What is expected from the remote server?</em></p>
  660. <p>A default JSON encoded list of objects must be returned. Each object
  661. corresponds to a matched user and needs the keys <tt class="docutils literal"><span class="pre">id</span></tt> and <tt class="docutils literal"><span class="pre">fullname</span></tt>.</p>
  662. </div>
  663. <div class="section" id="xhr-user-search-url">
  664. <h3><a class="toc-backref" href="#id44">xhr_user_search_url</a><a class="headerlink" href="#xhr-user-search-url" title="Permalink to this headline">¶</a></h3>
  665. <div class="admonition note">
  666. <p class="first admonition-title">Note</p>
  667. <p class="last">XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).</p>
  668. </div>
  669. <p>Default = Empty string</p>
  670. <p>Used only in conjunction with <tt class="docutils literal"><span class="pre">xhr_user_search</span></tt>.</p>
  671. <p>This is the URL to which an AJAX GET request will be made to fetch user data from your remote server.
  672. The query string will be included in the request with <tt class="docutils literal"><span class="pre">q</span></tt> as its key.</p>
  673. </div>
  674. </div>
  675. </div>
  676. <div class="section" id="minification">
  677. <h1><a class="toc-backref" href="#id45">Minification</a><a class="headerlink" href="#minification" title="Permalink to this headline">¶</a></h1>
  678. <div class="section" id="minifying-javascript-and-css">
  679. <h2><a class="toc-backref" href="#id46">Minifying Javascript and CSS</a><a class="headerlink" href="#minifying-javascript-and-css" title="Permalink to this headline">¶</a></h2>
  680. <p>Please make sure to read the section <a class="reference internal" href="#development">Development</a> and that you have installed
  681. all development dependencies (long story short, you can run <tt class="docutils literal"><span class="pre">npm</span> <span class="pre">install</span></tt>
  682. and then <tt class="docutils literal"><span class="pre">grunt</span> <span class="pre">fetch</span></tt>).</p>
  683. <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
  684. to bundle them together in a single minified file fit for deployment to a
  685. production site.</p>
  686. <p>To minify the Javascript and CSS, run the following command:</p>
  687. <div class="highlight-python"><pre>grunt minify</pre>
  688. </div>
  689. <p>Javascript will be bundled and minified with <a class="reference external" href="http://requirejs.org">require.js</a>&#8216;s optimization tool,
  690. using <a class="reference external" href="https://github.com/jrburke/almond">almond</a>.</p>
  691. <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>
  692. <p>CSS is minified via <a class="reference external" href="https://github.com/gruntjs/grunt-contrib-cssmin">cssmin</a>.</p>
  693. </div>
  694. </div>
  695. <div class="section" id="translations">
  696. <h1><a class="toc-backref" href="#id47">Translations</a><a class="headerlink" href="#translations" title="Permalink to this headline">¶</a></h1>
  697. <div class="admonition note">
  698. <p class="first admonition-title">Note</p>
  699. <p class="last">Translations take up a lot of space and will bloat your minified file.
  700. At the time of writing, all the translations add about 50KB of extra data to
  701. the minified javascript file. Therefore, make sure to only
  702. include those languages that you intend to support and remove from
  703. ./locale/locales.js those which you don&#8217;t need. Remember to rebuild the
  704. minified file afterwards.</p>
  705. </div>
  706. <p>The gettext POT file located in ./locale/converse.pot is the template
  707. containing all translations and from which for each language an individual PO
  708. file is generated.</p>
  709. <p>The POT file contains all translateable strings extracted from converse.js.</p>
  710. <p>To make a user facing string translateable, wrap it in the double underscore helper
  711. function like so:</p>
  712. <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>
  713. </pre></div>
  714. </div>
  715. <p>After adding the string, you&#8217;ll need to regenerate the POT file, like so:</p>
  716. <div class="highlight-python"><pre>make pot</pre>
  717. </div>
  718. <p>You can then create or update the PO file for a specific language by doing the following:</p>
  719. <div class="highlight-python"><pre>msgmerge ./locale/de/LC_MESSAGES/converse.po ./locale/converse.pot -U</pre>
  720. </div>
  721. <p>To do this for ALL languages, run:</p>
  722. <div class="highlight-python"><pre>make merge</pre>
  723. </div>
  724. <p>The resulting PO file is then what gets translated.</p>
  725. <p>If you&#8217;ve created a new PO file, please make sure to add the following
  726. attributes at the top of the file (under <em>Content-Transfer-Encoding</em>). They are
  727. required as configuration settings for Jed, the Javascript translations library
  728. that we&#8217;re using.</p>
  729. <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>
  730. <span class="s">&quot;lang: de</span><span class="se">\n</span><span class="s">&quot;</span>
  731. <span class="s">&quot;plural_forms: nplurals=2; plural=(n != 1);</span><span class="se">\n</span><span class="s">&quot;</span>
  732. </pre></div>
  733. </div>
  734. <p>Unfortunately <a class="reference external" href="http://slexaxton.github.io/Jed">Jed</a> cannot use the PO files directly. We have to generate from it
  735. a file in JSON format and then put that in a .js file for the specific
  736. language.</p>
  737. <p>To generate JSON from a PO file, you&#8217;ll need po2json for node.js. Run the
  738. following command to install it (npm being the node.js package manager):</p>
  739. <div class="highlight-python"><pre>npm install po2json</pre>
  740. </div>
  741. <p>You can then convert the translations into JSON format:</p>
  742. <div class="highlight-python"><pre>po2json locale/de/LC_MESSAGES/converse.po locale/de/LC_MESSAGES/converse.json</pre>
  743. </div>
  744. <p>Now from converse.json paste the data as a value for the &#8220;locale_data&#8221; key in the
  745. object in the language&#8217;s .js file.</p>
  746. <p>So, if you are for example translating into German (language code &#8216;de&#8217;), you&#8217;ll
  747. create or update the file ./locale/LC_MESSAGES/de.js with the following code:</p>
  748. <div class="highlight-python"><pre>(function (root, factory) {
  749. define("de", ['jed'], function () {
  750. return factory(new Jed({
  751. "domain": "converse",
  752. "locale_data": {
  753. // Paste the JSON data from converse.json here
  754. }
  755. })
  756. }
  757. }(this, function (i18n) {
  758. return i18n;
  759. }));</pre>
  760. </div>
  761. <p>making sure to also paste the JSON data as value to the &#8220;locale_data&#8221; key.</p>
  762. <div class="admonition note">
  763. <p class="first admonition-title">Note</p>
  764. <p class="last">If you are adding translations for a new language that is not already supported,
  765. you&#8217;ll have to make one more edit in ./locale/locales.js to make sure the
  766. language is loaded by require.js.</p>
  767. </div>
  768. <p>Congratulations, you&#8217;ve now succesfully added your translations. Sorry for all
  769. those hoops you had to jump through.</p>
  770. </div>
  771. </div>
  772. </div>
  773. <div class="clearer"></div>
  774. </div>
  775. </section>
  776. <div class="related">
  777. <h3>Navigation</h3>
  778. <ul>
  779. <li class="right" style="margin-right: 10px">
  780. <a href="genindex.html" title="General Index"
  781. >index</a></li>
  782. <li><a href="#">Converse.js 0.7.1 documentation</a> &raquo;</li>
  783. </ul>
  784. </div>
  785. </div>
  786. <div id="footer_wrap" class="outer">
  787. <footer class="inner">
  788. &copy; Copyright 2013, JC Brand.
  789. <p class="copyright">Converse.js created by <a href="http://opkode.com" target="_blank">jcbrand</a></p>
  790. </footer>
  791. </div>
  792. </body>
  793. </html>