index.html 69 KB

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