index.html 69 KB

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