index.html 64 KB

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