index.html 44 KB

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