index.html 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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.3 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.3',
  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.3 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.3 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. <li><a class="reference internal" href="#facebook-integration" id="id10">Facebook integration</a></li>
  69. </ul>
  70. </li>
  71. <li><a class="reference internal" href="#development" id="id11">Development</a><ul>
  72. <li><a class="reference internal" href="#install-node-js-and-development-dependencies" id="id12">Install Node.js and development dependencies</a></li>
  73. <li><a class="reference internal" href="#install-3rd-party-dependencies" id="id13">Install 3rd party dependencies</a></li>
  74. <li><a class="reference internal" href="#with-amd-and-require-js-recommended" id="id14">With AMD and require.js (recommended)</a></li>
  75. <li><a class="reference internal" href="#without-amd-and-require-js" id="id15">Without AMD and require.js</a></li>
  76. <li><a class="reference internal" href="#before-submitting-a-pull-request" id="id16">Before submitting a pull request</a><ul>
  77. <li><a class="reference internal" href="#add-tests-for-your-bugfix-or-feature" id="id17">Add tests for your bugfix or feature</a></li>
  78. <li><a class="reference internal" href="#check-that-the-tests-pass" id="id18">Check that the tests pass</a></li>
  79. <li><a class="reference internal" href="#check-your-code-for-errors-or-bad-habits-by-running-jshint" id="id19">Check your code for errors or bad habits by running JSHint</a></li>
  80. </ul>
  81. </li>
  82. </ul>
  83. </li>
  84. <li><a class="reference internal" href="#configuration" id="id20">Configuration</a><ul>
  85. <li><a class="reference internal" href="#configuration-variables" id="id21">Configuration variables</a><ul>
  86. <li><a class="reference internal" href="#animate" id="id22">animate</a></li>
  87. <li><a class="reference internal" href="#auto-list-rooms" id="id23">auto_list_rooms</a></li>
  88. <li><a class="reference internal" href="#auto-subscribe" id="id24">auto_subscribe</a></li>
  89. <li><a class="reference internal" href="#bosh-service-url" id="id25">bosh_service_url</a></li>
  90. <li><a class="reference internal" href="#debug" id="id26">debug</a></li>
  91. <li><a class="reference internal" href="#fullname" id="id27">fullname</a></li>
  92. <li><a class="reference internal" href="#hide-muc-server" id="id28">hide_muc_server</a></li>
  93. <li><a class="reference internal" href="#prebind" id="id29">prebind</a></li>
  94. <li><a class="reference internal" href="#show-controlbox-by-default" id="id30">show_controlbox_by_default</a></li>
  95. <li><a class="reference internal" href="#xhr-user-search" id="id31">xhr_user_search</a></li>
  96. </ul>
  97. </li>
  98. </ul>
  99. </li>
  100. <li><a class="reference internal" href="#minification" id="id32">Minification</a><ul>
  101. <li><a class="reference internal" href="#minifying-javascript-and-css" id="id33">Minifying Javascript and CSS</a></li>
  102. </ul>
  103. </li>
  104. <li><a class="reference internal" href="#translations" id="id34">Translations</a></li>
  105. </ul>
  106. </div>
  107. <div class="section" id="quickstart-to-get-a-demo-up-and-running">
  108. <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>
  109. <p>When you download a specific release of <em>Converse.js</em> there will be two minified files inside the zip file.</p>
  110. <ul class="simple">
  111. <li>converse.min.js</li>
  112. <li>converse.min.css</li>
  113. </ul>
  114. <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>
  115. tags:</p>
  116. <div class="highlight-python"><pre>&lt;link rel="stylesheet" type="text/css" media="screen" href="converse.min.css"&gt;
  117. &lt;script src="converse.min.js"&gt;&lt;/script&gt;</pre>
  118. </div>
  119. <p>You need to initialize Converse.js with configuration settings particular to
  120. your requirements.</p>
  121. <p>Please refer to the <a class="reference internal" href="#configuration-variables">Configuration variables</a> section further below for info on
  122. all the available configuration settings.</p>
  123. <p>To do this, put the following inline Javascript code at the
  124. bottom of your page (after the closing <em>&lt;/body&gt;</em> element).</p>
  125. <div class="highlight-python"><pre>require(['converse'], function (converse) {
  126. converse.initialize({
  127. auto_list_rooms: false,
  128. auto_subscribe: false,
  129. bosh_service_url: 'https://bind.opkode.im', // Please use this connection manager only for testing purposes
  130. hide_muc_server: false,
  131. i18n: locales.en, // Refer to ./locale/locales.js to see which locales are supported
  132. prebind: false,
  133. show_controlbox_by_default: true,
  134. xhr_user_search: false
  135. });
  136. });</pre>
  137. </div>
  138. <p>Finally, Converse.js requires a special snippet of HTML markup to be included in your page:</p>
  139. <div class="highlight-python"><pre>&lt;div id="chatpanel"&gt;
  140. &lt;div id="collective-xmpp-chat-data"&gt;&lt;/div&gt;
  141. &lt;div id="toggle-controlbox"&gt;
  142. &lt;a href="#" class="chat toggle-online-users"&gt;
  143. &lt;strong class="conn-feedback"&gt;Toggle chat&lt;/strong&gt; &lt;strong style="display: none" id="online-count"&gt;(0)&lt;/strong&gt;
  144. &lt;/a&gt;
  145. &lt;/div&gt;
  146. &lt;/div&gt;</pre>
  147. </div>
  148. <p>The <a class="reference external" href="https://github.com/jcbrand/converse.js/blob/master/index.html">index.html</a> file inside the
  149. Converse.js repository serves as a nice usable example of this.</p>
  150. <p>These minified files provide the same demo-like functionality as is available
  151. on the <a class="reference external" href="http://conversejs.org">conversejs.org</a> website. Useful for testing or demoing, but not very
  152. practical.</p>
  153. <p>You&#8217;ll most likely want to implement some kind of single-signon solution for
  154. your website, where users authenticate once in your website and then stay
  155. logged into their XMPP session upon page reload.</p>
  156. <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>
  157. <p>You might also want to have more fine-grained control of what gets included in
  158. 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
  159. that.</p>
  160. </div>
  161. <div class="section" id="introduction">
  162. <h1><a class="toc-backref" href="#id3">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h1>
  163. <p>Even though you can connect to public XMPP servers on the <a class="reference external" href="http://conversejs.org">conversejs.org</a>
  164. website, <em>Converse.js</em> is not really meant to be a &#8220;Software-as-a-service&#8221; (SaaS)
  165. webchat.</p>
  166. <p>Instead, its goal is to provide the means for website owners to add a tightly
  167. integrated instant messaging service to their own sites.</p>
  168. <p>As a website owner, you are expected to host <em>Converse.js</em> yourself, and to do some legwork to
  169. properly configure and integrate it into your site.</p>
  170. <p>The benefit in doing this, is that your users have a much more streamlined and integrated
  171. webchat experience and that you have control over the data. The latter being a
  172. requirement for many sites dealing with sensitive information.</p>
  173. <p>You&#8217;ll need to set up your own XMPP server and in order to have
  174. <a class="reference internal" href="#session-support">Session Support</a> (i.e. single-signon functionality whereby users are authenticated once and stay
  175. logged in to XMPP upon page reload) you will also have to add some server-side
  176. code.</p>
  177. <p>The <a class="reference internal" href="#what-you-will-need">What you will need</a> section has more information on all these
  178. requirements.</p>
  179. </div>
  180. <div class="section" id="what-you-will-need">
  181. <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>
  182. <div class="section" id="an-xmpp-jabber-server">
  183. <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>
  184. <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
  185. to connect to an XMPP/Jabber server (Jabber is really just a synonym for XMPP).</p>
  186. <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
  187. have <a class="reference internal" href="#session-support">Session Support</a> you&#8217;ll have to set up your own XMPP server.</p>
  188. <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
  189. servers that you can set up yourself on <a class="reference external" href="http://xmpp.org/xmpp-software/servers/">xmpp.org</a>.</p>
  190. </div>
  191. <div class="section" id="connection-manager">
  192. <h2><a class="toc-backref" href="#id6">Connection Manager</a><a class="headerlink" href="#connection-manager" title="Permalink to this headline">¶</a></h2>
  193. <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
  194. the webserver. HTTP connections are stateless and usually shortlived.</p>
  195. <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
  196. its connections are stateful and usually longer.</p>
  197. <p>To enable a web application like <em>Converse.js</em> to communicate with an XMPP
  198. server, we need a proxy in the middle that can act as a bridge between the two
  199. protocols.</p>
  200. <p>This is the job of a connection manager. A connection manager can be either a
  201. standalone application or part of an XMPP server. <a class="reference external" href="http://www.ejabberd.im">ejabberd</a> for example,
  202. includes a connection manager (but you have to enable it).</p>
  203. <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>.
  204. This connection manager is for testing purposes only, please don&#8217;t use it in
  205. production.</p>
  206. <div class="section" id="overcoming-cross-domain-request-restrictions">
  207. <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>
  208. <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>.
  209. HTTP requests are made by <em>Converse.js</em> to the connection manager via XmlHttpRequests (XHR).
  210. Until recently, it was not possible to make such requests to a different domain
  211. than the one currently being served (to prevent XSS attacks).</p>
  212. <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.
  213. Modern browsers support CORS, but there are problems with Internet Explorer &lt;
  214. 10.</p>
  215. <p>IE 8 and 9 partially support CORS via a proprietary implementation called
  216. 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
  217. support for XDomainRequest when it is present.</p>
  218. <p>In IE &lt; 8, there is no support for CORS.</p>
  219. <p>If you need to support these browsers, you can add a front-end proxy in
  220. Apache/Nginx which serves the connection manager under the same domain as your
  221. website. This will remove the need for any cross-domain XHR support.</p>
  222. </div>
  223. </div>
  224. <div class="section" id="server-side-authentication">
  225. <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>
  226. <div class="section" id="pre-binding-and-single-session-support">
  227. <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>
  228. <p>It&#8217;s possible to enable single-site login, whereby users already
  229. authenticated in your website will also automatically be logged in on the chat server,
  230. but this will require custom code on your server.</p>
  231. <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>
  232. <div class="admonition note">
  233. <p class="first admonition-title">Note</p>
  234. <p class="last">If you want to enable single session support, make sure to pass <strong>prebind: true</strong>
  235. when you call <strong>converse.initialize</strong> (see ./index.html).</p>
  236. </div>
  237. <p>When you authenticate to the XMPP server on your backend, you&#8217;ll receive two
  238. tokens, RID (request ID) and SID (session ID).</p>
  239. <p>These tokens then need to be passed back to the javascript running in your
  240. browser, where you will need them attach to the existing session.</p>
  241. <p>You can embed the RID and SID tokens in your HTML markup or you can do an
  242. XMLHttpRequest call to you server and ask it to return them for you.</p>
  243. <p>Below is one example of how this could work. An Ajax call is made to the
  244. relative URL <strong>/prebind</strong> and it expects to receive JSON data back.</p>
  245. <div class="highlight-python"><pre>$.getJSON('/prebind', function (data) {
  246. var connection = new Strophe.Connection(converse.bosh_service_url);
  247. connection.attach(data.jid, data.sid, data.rid, function (status) {
  248. if ((status === Strophe.Status.ATTACHED) || (status === Strophe.Status.CONNECTED)) {
  249. converse.onConnected(connection)
  250. }
  251. });
  252. }
  253. );</pre>
  254. </div>
  255. <p><strong>Here&#8217;s what&#8217;s happening:</strong></p>
  256. <p>The JSON data contains the user&#8217;s JID (jabber ID), RID and SID. The URL to the
  257. BOSH connection manager is already set as a configuration setting on the
  258. <em>converse</em> object (see ./main.js), so we can reuse it from there.</p>
  259. <p>A new Strophe.Connection object is instantiated and then <em>attach</em> is called with
  260. the user&#8217;s JID, the necessary tokens and a callback function.</p>
  261. <p>In the callback function, you call <em>converse.onConnected</em> together with the
  262. connection object.</p>
  263. </div>
  264. </div>
  265. <div class="section" id="facebook-integration">
  266. <h2><a class="toc-backref" href="#id10">Facebook integration</a><a class="headerlink" href="#facebook-integration" title="Permalink to this headline">¶</a></h2>
  267. <div class="admonition note">
  268. <p class="first admonition-title">Note</p>
  269. <p class="last">It should be possible to integrate Converse.js with Facebook chat, and
  270. below I&#8217;ll provide some tips and documentation on how to achieve this. That
  271. said, I don&#8217;t have a Facebook account and therefore haven&#8217;t tried to do
  272. this myself. Feedback and patches from people who have succesfully done this
  273. will be appreciated.</p>
  274. </div>
  275. <p>Converse.js uses <a class="reference external" href="http://strophe.im/strophejs">Strophe.js</a> to connect and
  276. communicate with the XMPP server. One nice thing about Strophe.js is that it
  277. can be extended via <a class="reference external" href="http://github.com/strophe/strophejs-plugins">plugins</a>.</p>
  278. <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>
  279. <p>You will need your own BOSH connection manager to act as a proxy between
  280. Converse.js/Strophe.js and Facebook&#8217;s XMPP server. That is because Facebook&#8217;s
  281. XMPP server doesn&#8217;t support BOSH natively.</p>
  282. <p>The BOSH connection manager that I make available for
  283. 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>,
  284. although there are quite a few other options available as well.</p>
  285. <p>When you configure Converse.js, via its <tt class="docutils literal"><span class="pre">initialize</span></tt> method, you must specify the
  286. <a class="reference internal" href="#bosh-service-url">bosh_service_url</a> value, which is to be your BOSH connection manager.</p>
  287. <p>Please note, to enable Facebook integration, you&#8217;ll have to
  288. get your hands dirty and modify Converse.js&#8217;s code, so that it calls the
  289. <tt class="docutils literal"><span class="pre">facebookConnect</span></tt> method of the plugin above.</p>
  290. <p>The plugin above gives the following code example for you to meditate upon:</p>
  291. <div class="highlight-python"><pre>connection = new Strophe.Connection("http://localhost:5280/bosh");
  292. connection.facebookConnect(
  293. "12345@chat.facebook.com",
  294. onConnectFacebook,
  295. 300,
  296. 1,
  297. '5e64a30272af065bd72258c565a03f2f',
  298. '8147a27e4a7f9b55ffc85c2683f9529a',
  299. FB.getSession().session_key
  300. );</pre>
  301. </div>
  302. <p>The connection is already created inside Converse.js, so the
  303. <tt class="docutils literal"><span class="pre">facebookConnect</span></tt> method needs to also be called from there.</p>
  304. <p>If someone submits a sane patch that does the above, I&#8217;ll be happy to merge it.
  305. Until then, people will have to do this themselves.</p>
  306. </div>
  307. </div>
  308. <div class="section" id="development">
  309. <h1><a class="toc-backref" href="#id11">Development</a><a class="headerlink" href="#development" title="Permalink to this headline">¶</a></h1>
  310. <p>If you want to work with the non-minified Javascript and CSS files you&#8217;ll soon
  311. notice that there are references to a missing <em>components</em> folder. Please
  312. follow the instructions below to create this folder and fetch Converse&#8217;s
  313. 3rd-party dependencies.</p>
  314. <div class="section" id="install-node-js-and-development-dependencies">
  315. <h2><a class="toc-backref" href="#id12">Install Node.js and development dependencies</a><a class="headerlink" href="#install-node-js-and-development-dependencies" title="Permalink to this headline">¶</a></h2>
  316. <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>)
  317. which depend on Node.js and npm (the Node package manager).</p>
  318. <p>If you don&#8217;t have Node.js installed, you can download and install the latest
  319. version <a class="reference external" href="https://nodejs.org/download">here</a>.</p>
  320. <p>Once you have Node.js installed, run the following command inside the Converse.js
  321. directory:</p>
  322. <div class="highlight-python"><pre>npm install</pre>
  323. </div>
  324. <p>This will install all the development dependencies for Converse.js. If you are
  325. curious to know what these are, take a look at whats under the <em>devDependencies</em> key in
  326. <cite>package.json &lt;https://github.com/jcbrand/converse.js/blob/master/package.json&gt;</cite>.</p>
  327. </div>
  328. <div class="section" id="install-3rd-party-dependencies">
  329. <h2><a class="toc-backref" href="#id13">Install 3rd party dependencies</a><a class="headerlink" href="#install-3rd-party-dependencies" title="Permalink to this headline">¶</a></h2>
  330. <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>
  331. <p>We use Bower to manage Converse&#8217;s front-end dependencies (e.g. Javascript that
  332. should get loaded in the browser).</p>
  333. <p>To fetch these dependencies, run:</p>
  334. <div class="highlight-python"><pre>grunt fetch</pre>
  335. </div>
  336. <p>This will call Bower in the background to fetch all the front-end
  337. dependencies (like backbone.js, strophe.js etc.) and then put them in the
  338. <em>components</em> folder.</p>
  339. </div>
  340. <div class="section" id="with-amd-and-require-js-recommended">
  341. <h2><a class="toc-backref" href="#id14">With AMD and require.js (recommended)</a><a class="headerlink" href="#with-amd-and-require-js-recommended" title="Permalink to this headline">¶</a></h2>
  342. <p>Converse.js uses <a class="reference external" href="http://requirejs.org">require.js</a> to asynchronously load dependencies.</p>
  343. <p>If you want to develop or customize converse.js, you&#8217;ll want to load the
  344. non-minified javascript files.</p>
  345. <p>Add the following two lines to the <em>&lt;head&gt;</em> section of your webpage:</p>
  346. <div class="highlight-python"><pre>&lt;link rel="stylesheet" type="text/css" media="screen" href="converse.css"&gt;
  347. &lt;script data-main="main" src="components/requirejs/require.js"&gt;&lt;/script&gt;</pre>
  348. </div>
  349. <p>require.js will then let the main.js file be parsed (because of the <em>data-main</em>
  350. attribute on the <em>script</em> tag), which will in turn cause converse.js to be
  351. parsed.</p>
  352. </div>
  353. <div class="section" id="without-amd-and-require-js">
  354. <h2><a class="toc-backref" href="#id15">Without AMD and require.js</a><a class="headerlink" href="#without-amd-and-require-js" title="Permalink to this headline">¶</a></h2>
  355. <p>Converse.js can also be used without require.js. If you for some reason prefer
  356. to use it this way, please refer to
  357. <a class="reference external" href="https://github.com/jcbrand/converse.js/blob/master/non_amd.html">non_amd.html</a>
  358. for an example of how and in what order all the Javascript files that converse.js
  359. depends on need to be loaded.</p>
  360. </div>
  361. <div class="section" id="before-submitting-a-pull-request">
  362. <h2><a class="toc-backref" href="#id16">Before submitting a pull request</a><a class="headerlink" href="#before-submitting-a-pull-request" title="Permalink to this headline">¶</a></h2>
  363. <div class="section" id="add-tests-for-your-bugfix-or-feature">
  364. <h3><a class="toc-backref" href="#id17">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>
  365. <p>Add a test for any bug fixed or feature added. We use Jasmine
  366. for testing.</p>
  367. <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
  368. the tests are implemented.</p>
  369. <p>If you are unsure how to write tests, please
  370. <a class="reference external" href="http://opkode.com/contact">contact me</a> and I&#8217;ll be happy to help.</p>
  371. </div>
  372. <div class="section" id="check-that-the-tests-pass">
  373. <h3><a class="toc-backref" href="#id18">Check that the tests pass</a><a class="headerlink" href="#check-that-the-tests-pass" title="Permalink to this headline">¶</a></h3>
  374. <p>Check that the Jasmine tests complete sucessfully. Open
  375. <a class="reference external" href="https://github.com/jcbrand/converse.js/blob/master/tests.html">tests.html</a>
  376. in your browser, and the tests will run automatically.</p>
  377. <p>On the command line you can run:</p>
  378. <div class="highlight-python"><pre>grunt test</pre>
  379. </div>
  380. </div>
  381. <div class="section" id="check-your-code-for-errors-or-bad-habits-by-running-jshint">
  382. <h3><a class="toc-backref" href="#id19">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>
  383. <p><a class="reference external" href="http://jshint.com">JSHint</a> will do a static analysis of your code and hightlight potential errors
  384. and/or bad habits.</p>
  385. <div class="highlight-python"><pre>grunt jshint</pre>
  386. </div>
  387. <p>You can run both the tests and jshint in one go by calling:</p>
  388. <div class="highlight-python"><pre>grunt check</pre>
  389. </div>
  390. </div>
  391. </div>
  392. </div>
  393. <div class="section" id="configuration">
  394. <h1><a class="toc-backref" href="#id20">Configuration</a><a class="headerlink" href="#configuration" title="Permalink to this headline">¶</a></h1>
  395. <p>The included minified JS and CSS files can be used for demoing or testing, but
  396. you&#8217;ll want to configure <em>Converse.js</em> to suit your needs before you deploy it
  397. on your website.</p>
  398. <p><em>Converse.js</em> is passed its configuration settings when you call its
  399. <em>initialize</em> method.</p>
  400. <p>You&#8217;ll most likely want to call the <em>initialize</em> method in your HTML page. For
  401. an example of how this is done, please see the bottom of the <em>./index.html</em> page.</p>
  402. <p>Please refer to the <a class="reference internal" href="#configuration-variables">Configuration variables</a> section below for info on
  403. all the available configuration settings.</p>
  404. <p>After you have configured <em>Converse.js</em>, you&#8217;ll have to regenerate the minified
  405. JS file so that it will include the new settings. Please refer to the
  406. <a class="reference internal" href="#minification">Minification</a> section for more info on how to do this.</p>
  407. <div class="section" id="configuration-variables">
  408. <h2><a class="toc-backref" href="#id21">Configuration variables</a><a class="headerlink" href="#configuration-variables" title="Permalink to this headline">¶</a></h2>
  409. <div class="section" id="animate">
  410. <h3><a class="toc-backref" href="#id22">animate</a><a class="headerlink" href="#animate" title="Permalink to this headline">¶</a></h3>
  411. <p>Default = True</p>
  412. <p>Show animations, for example when opening and closing chat boxes.</p>
  413. </div>
  414. <div class="section" id="auto-list-rooms">
  415. <h3><a class="toc-backref" href="#id23">auto_list_rooms</a><a class="headerlink" href="#auto-list-rooms" title="Permalink to this headline">¶</a></h3>
  416. <p>Default = False</p>
  417. <p>If true, and the XMPP server on which the current user is logged in supports
  418. multi-user chat, then a list of rooms on that server will be fetched.</p>
  419. <p>Not recommended for servers with lots of chat rooms.</p>
  420. <p>For each room on the server a query is made to fetch further details (e.g.
  421. features, number of occupants etc.), so on servers with many rooms this
  422. option will create lots of extra connection traffic.</p>
  423. </div>
  424. <div class="section" id="auto-subscribe">
  425. <h3><a class="toc-backref" href="#id24">auto_subscribe</a><a class="headerlink" href="#auto-subscribe" title="Permalink to this headline">¶</a></h3>
  426. <p>Default = False</p>
  427. <p>If true, the user will automatically subscribe back to any contact requests.</p>
  428. </div>
  429. <div class="section" id="bosh-service-url">
  430. <h3><a class="toc-backref" href="#id25">bosh_service_url</a><a class="headerlink" href="#bosh-service-url" title="Permalink to this headline">¶</a></h3>
  431. <p>Connections to an XMPP server depend on a BOSH connection manager which acts as
  432. a middle man between HTTP and XMPP.</p>
  433. <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>
  434. </div>
  435. <div class="section" id="debug">
  436. <h3><a class="toc-backref" href="#id26">debug</a><a class="headerlink" href="#debug" title="Permalink to this headline">¶</a></h3>
  437. <p>If set to true, debugging output will be logged to the browser console.</p>
  438. </div>
  439. <div class="section" id="fullname">
  440. <h3><a class="toc-backref" href="#id27">fullname</a><a class="headerlink" href="#fullname" title="Permalink to this headline">¶</a></h3>
  441. <p>If you are using prebinding, you need to specify the fullname of the currently
  442. logged in user.</p>
  443. </div>
  444. <div class="section" id="hide-muc-server">
  445. <h3><a class="toc-backref" href="#id28">hide_muc_server</a><a class="headerlink" href="#hide-muc-server" title="Permalink to this headline">¶</a></h3>
  446. <p>Default = False</p>
  447. <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
  448. controlbox. Useful if you want to restrict users to a specific XMPP server of
  449. your choosing.</p>
  450. </div>
  451. <div class="section" id="prebind">
  452. <h3><a class="toc-backref" href="#id29">prebind</a><a class="headerlink" href="#prebind" title="Permalink to this headline">¶</a></h3>
  453. <p>Default = False</p>
  454. <p>Use this option when you want to attach to an existing XMPP connection that was
  455. already authenticated (usually on the backend before page load).</p>
  456. <p>This is useful when you don&#8217;t want to render the login form on the chat control
  457. box with each page load.</p>
  458. <p>When set to true, you&#8217;ll need to make sure that the onConnected method is
  459. called, and passed to it a Strophe connection object.</p>
  460. <p>Besides requiring the back-end to authenticate you, you&#8217;ll also
  461. have to write a Javascript snippet to attach to the set up connection:</p>
  462. <div class="highlight-python"><pre>$.JSON({
  463. 'url': 'mysite.com/xmpp-authenticate',
  464. 'success': function (data) {
  465. connection = new Strophe.Connection(bosh_service_url);
  466. connection.attach(data.jid, data.sid, data.rid, converse.onConnected);
  467. }</pre>
  468. </div>
  469. <p>The backend must authenticate for you, and then return a SID (session ID) and
  470. RID (Request ID), which you use when you attach to the connection.</p>
  471. </div>
  472. <div class="section" id="show-controlbox-by-default">
  473. <h3><a class="toc-backref" href="#id30">show_controlbox_by_default</a><a class="headerlink" href="#show-controlbox-by-default" title="Permalink to this headline">¶</a></h3>
  474. <p>Default = False</p>
  475. <p>The &#8220;controlbox&#8221; refers to the special chatbox containing your contacts roster,
  476. status widget, chatrooms and other controls.</p>
  477. <p>By default this box is hidden and can be toggled by clicking on any element in
  478. the page with class <em>toggle-online-users</em>.</p>
  479. <p>If this options is set to true, the controlbox will by default be shown upon
  480. page load.</p>
  481. </div>
  482. <div class="section" id="xhr-user-search">
  483. <h3><a class="toc-backref" href="#id31">xhr_user_search</a><a class="headerlink" href="#xhr-user-search" title="Permalink to this headline">¶</a></h3>
  484. <p>Default = False</p>
  485. <p>There are two ways to add users.</p>
  486. <ul class="simple">
  487. <li>The user inputs a valid JID (Jabber ID), and the user is added as a pending contact.</li>
  488. <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>
  489. </ul>
  490. <p>This setting enables the second mechanism, otherwise by default the first will
  491. be used.</p>
  492. </div>
  493. </div>
  494. </div>
  495. <div class="section" id="minification">
  496. <h1><a class="toc-backref" href="#id32">Minification</a><a class="headerlink" href="#minification" title="Permalink to this headline">¶</a></h1>
  497. <div class="section" id="minifying-javascript-and-css">
  498. <h2><a class="toc-backref" href="#id33">Minifying Javascript and CSS</a><a class="headerlink" href="#minifying-javascript-and-css" title="Permalink to this headline">¶</a></h2>
  499. <p>Please make sure to read the section <a class="reference internal" href="#development">Development</a> and that you have installed
  500. all development dependencies (long story short, you can run <tt class="docutils literal"><span class="pre">npm</span> <span class="pre">install</span></tt>
  501. and then <tt class="docutils literal"><span class="pre">grunt</span> <span class="pre">fetch</span></tt>).</p>
  502. <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
  503. to bundle them together in a single minified file fit for deployment to a
  504. production site.</p>
  505. <p>To minify the Javascript and CSS, run the following command:</p>
  506. <div class="highlight-python"><pre>grunt minify</pre>
  507. </div>
  508. <p>Javascript will be bundled and minified via <a class="reference external" href="http://requirejs.org">require.js</a>&#8216;s optimization tool.
  509. You can <a class="reference external" href="http://requirejs.org/docs/optimization.html">read more about require.js&#8217;s optimizer here</a>.</p>
  510. <p>CSS is minified via <a class="reference external" href="https://github.com/gruntjs/grunt-contrib-cssmin">cssmin</a>.</p>
  511. </div>
  512. </div>
  513. <div class="section" id="translations">
  514. <h1><a class="toc-backref" href="#id34">Translations</a><a class="headerlink" href="#translations" title="Permalink to this headline">¶</a></h1>
  515. <div class="admonition note">
  516. <p class="first admonition-title">Note</p>
  517. <p class="last">Translations take up a lot of space and will bloat your minified file.
  518. At the time of writing, all the translations add about 50KB of extra data to
  519. the minified javascript file. Therefore, make sure to only
  520. include those languages that you intend to support and remove from
  521. ./locale/locales.js those which you don&#8217;t need. Remember to rebuild the
  522. minified file afterwards.</p>
  523. </div>
  524. <p>The gettext POT file located in ./locale/converse.pot is the template
  525. containing all translations and from which for each language an individual PO
  526. file is generated.</p>
  527. <p>The POT file contains all translateable strings extracted from converse.js.</p>
  528. <p>To make a user facing string translateable, wrap it in the double underscore helper
  529. function like so:</p>
  530. <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>
  531. </pre></div>
  532. </div>
  533. <p>After adding the string, you&#8217;ll need to regenerate the POT file, like so:</p>
  534. <div class="highlight-python"><pre>make pot</pre>
  535. </div>
  536. <p>You can then create or update the PO file for a specific language by doing the following:</p>
  537. <div class="highlight-python"><pre>msgmerge ./locale/af/LC_MESSAGES/converse.po ./locale/converse.pot -U</pre>
  538. </div>
  539. <p>This PO file is then what gets translated.</p>
  540. <p>If you&#8217;ve created a new PO file, please make sure to add the following
  541. attributes at the top of the file (under <em>Content-Transfer-Encoding</em>). They are
  542. required as configuration settings for Jed, the Javascript translations library
  543. that we&#8217;re using.</p>
  544. <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>
  545. <span class="s">&quot;lang: af</span><span class="se">\n</span><span class="s">&quot;</span>
  546. <span class="s">&quot;plural_forms: nplurals=2; plural=(n != 1);</span><span class="se">\n</span><span class="s">&quot;</span>
  547. </pre></div>
  548. </div>
  549. <p>Unfortunately Jed cannot use the PO files directly. We have to generate from it
  550. a file in JSON format and then put that in a .js file for the specific
  551. language.</p>
  552. <p>To generate JSON from a PO file, you&#8217;ll need po2json for node.js. Run the
  553. following command to install it (npm being the node.js package manager):</p>
  554. <div class="highlight-python"><pre>npm install po2json</pre>
  555. </div>
  556. <p>You can then convert the translations into JSON format:</p>
  557. <div class="highlight-python"><pre>po2json locale/af/LC_MESSAGES/converse.po locale/af/LC_MESSAGES/converse.json</pre>
  558. </div>
  559. <p>Now from converse.json paste the data as a value for the &#8220;locale_data&#8221; key in the
  560. object in the language&#8217;s .js file.</p>
  561. <p>So, if you are for example translating into German (language code &#8216;de&#8217;), you&#8217;ll
  562. create or update the file ./locale/LC_MESSAGES/de.js with the following code:</p>
  563. <div class="highlight-python"><pre>(function (root, factory) {
  564. define("af", ['jed'], function () {
  565. return factory(new Jed({
  566. "domain": "converse",
  567. "locale_data": {
  568. // Paste the JSON data from converse.json here
  569. }
  570. })
  571. }
  572. }(this, function (i18n) {
  573. return i18n;
  574. }));</pre>
  575. </div>
  576. <p>making sure to also paste the JSON data as value to the &#8220;locale_data&#8221; key.</p>
  577. <div class="admonition note">
  578. <p class="first admonition-title">Note</p>
  579. <p class="last">If you are adding translations for a new language that is not already supported,
  580. you&#8217;ll have to make one more edit in ./locale/locales.js to make sure the
  581. language is loaded by require.js.</p>
  582. </div>
  583. <p>Congratulations, you&#8217;ve now succesfully added your translations. Sorry for all
  584. those hoops you had to jump through.</p>
  585. </div>
  586. </div>
  587. </div>
  588. <div class="clearer"></div>
  589. </div>
  590. </section>
  591. <div class="related">
  592. <h3>Navigation</h3>
  593. <ul>
  594. <li class="right" style="margin-right: 10px">
  595. <a href="genindex.html" title="General Index"
  596. >index</a></li>
  597. <li><a href="#">Converse.js 0.5.3 documentation</a> &raquo;</li>
  598. </ul>
  599. </div>
  600. </div>
  601. <div id="footer_wrap" class="outer">
  602. <footer class="inner">
  603. &copy; Copyright 2013, JC Brand.
  604. <p class="copyright">Converse.js created by <a href="http://opkode.com" target="_blank">jcbrand</a></p>
  605. </footer>
  606. </div>
  607. </body>
  608. </html>