2
0

index.html 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  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.8.0 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.8.0',
  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.8.0 documentation" href="#" />
  22. </head>
  23. <body>
  24. <div id="header_wrap" class="outer">
  25. <header class="inner">
  26. <h1 id="project_title"><a href="http://conversejs.org">Converse.js</a></h1>
  27. <h2 id="project_tagline">Documentation</h2>
  28. </header>
  29. </div>
  30. <div id="main_content_wrap" class="outer">
  31. <div class="related">
  32. <h3>Navigation</h3>
  33. <ul>
  34. <li class="right" style="margin-right: 10px">
  35. <a href="genindex.html" title="General Index"
  36. accesskey="I">index</a></li>
  37. <li><a href="#">Converse.js 0.8.0 documentation</a> &raquo;</li>
  38. </ul>
  39. </div>
  40. <section id="main_content" class="inner">
  41. <div class="document">
  42. <div class="documentwrapper">
  43. <div class="body">
  44. <div class="toctree-wrapper compound">
  45. <ul class="simple">
  46. </ul>
  47. </div>
  48. <div class="contents local topic" id="table-of-contents">
  49. <p class="topic-title first">Table of Contents</p>
  50. <ul class="simple">
  51. <li><a class="reference internal" href="#quickstart-to-get-a-demo-up-and-running" id="id7">Quickstart (to get a demo up and running)</a></li>
  52. <li><a class="reference internal" href="#introduction" id="id8">Introduction</a></li>
  53. <li><a class="reference internal" href="#what-you-will-need" id="id9">What you will need</a><ul>
  54. <li><a class="reference internal" href="#an-xmpp-jabber-server" id="id10">An XMPP/Jabber server</a></li>
  55. <li><a class="reference internal" href="#a-bosh-connection-manager" id="id11">A BOSH Connection Manager</a><ul>
  56. <li><a class="reference internal" href="#overcoming-cross-domain-request-restrictions" id="id12">Overcoming cross-domain request restrictions</a></li>
  57. </ul>
  58. </li>
  59. <li><a class="reference internal" href="#server-side-authentication" id="id13">Server-side authentication</a><ul>
  60. <li><a class="reference internal" href="#prebinding-and-single-session-support" id="id14">Prebinding and Single Session Support</a></li>
  61. <li><a class="reference internal" href="#example-code-for-server-side-prebinding" id="id15">Example code for server-side prebinding</a></li>
  62. </ul>
  63. </li>
  64. </ul>
  65. </li>
  66. <li><a class="reference internal" href="#features" id="id16">Features</a><ul>
  67. <li><a class="reference internal" href="#off-the-record-encryption" id="id17">Off-the-record encryption</a></li>
  68. <li><a class="reference internal" href="#sound-notifications" id="id18">Sound Notifications</a></li>
  69. <li><a class="reference internal" href="#multilingual-support" id="id19">Multilingual Support</a></li>
  70. </ul>
  71. </li>
  72. <li><a class="reference internal" href="#development" id="id20">Development</a><ul>
  73. <li><a class="reference internal" href="#install-the-development-and-front-end-dependencies" id="id21">Install the development and front-end dependencies</a></li>
  74. <li><a class="reference internal" href="#with-amd-and-require-js-recommended" id="id22">With AMD and require.js (recommended)</a></li>
  75. <li><a class="reference internal" href="#without-amd-and-require-js" id="id23">Without AMD and require.js</a></li>
  76. <li><a class="reference internal" href="#before-submitting-a-pull-request" id="id24">Before submitting a pull request</a><ul>
  77. <li><a class="reference internal" href="#add-tests-for-your-bugfix-or-feature" id="id25">Add tests for your bugfix or feature</a></li>
  78. <li><a class="reference internal" href="#check-that-the-tests-pass" id="id26">Check that the tests pass</a></li>
  79. <li><a class="reference internal" href="#check-your-code-for-errors-or-bad-habits-by-running-jshint" id="id27">Check your code for errors or bad habits by running JSHint</a></li>
  80. </ul>
  81. </li>
  82. <li><a class="reference internal" href="#minification" id="id28">Minification</a><ul>
  83. <li><a class="reference internal" href="#minifying-javascript-and-css" id="id29">Minifying Javascript and CSS</a></li>
  84. </ul>
  85. </li>
  86. <li><a class="reference internal" href="#translations" id="id30">Translations</a></li>
  87. </ul>
  88. </li>
  89. <li><a class="reference internal" href="#troubleshooting" id="id31">Troubleshooting</a><ul>
  90. <li><a class="reference internal" href="#conflicts-with-other-javascript-libraries" id="id32">Conflicts with other Javascript libraries</a><ul>
  91. <li><a class="reference internal" href="#problem" id="id33">Problem:</a></li>
  92. <li><a class="reference internal" href="#solution" id="id34">Solution:</a></li>
  93. </ul>
  94. </li>
  95. </ul>
  96. </li>
  97. <li><a class="reference internal" href="#events" id="id35">Events</a><ul>
  98. <li><a class="reference internal" href="#event-methods" id="id36">Event Methods</a></li>
  99. <li><a class="reference internal" href="#event-types" id="id37">Event Types</a></li>
  100. </ul>
  101. </li>
  102. <li><a class="reference internal" href="#configuration" id="id38">Configuration</a><ul>
  103. <li><a class="reference internal" href="#configuration-variables" id="id39">Configuration variables</a><ul>
  104. <li><a class="reference internal" href="#allow-contact-requests" id="id40">allow_contact_requests</a></li>
  105. <li><a class="reference internal" href="#allow-muc" id="id41">allow_muc</a></li>
  106. <li><a class="reference internal" href="#id3" id="id42">allow_muc</a></li>
  107. <li><a class="reference internal" href="#animate" id="id43">animate</a></li>
  108. <li><a class="reference internal" href="#auto-list-rooms" id="id44">auto_list_rooms</a></li>
  109. <li><a class="reference internal" href="#auto-reconnect" id="id45">auto_reconnect</a></li>
  110. <li><a class="reference internal" href="#auto-subscribe" id="id46">auto_subscribe</a></li>
  111. <li><a class="reference internal" href="#bosh-service-url" id="id47">bosh_service_url</a></li>
  112. <li><a class="reference internal" href="#cache-otr-key" id="id48">cache_otr_key</a></li>
  113. <li><a class="reference internal" href="#debug" id="id49">debug</a></li>
  114. <li><a class="reference internal" href="#message-carbons" id="id50">message_carbons</a></li>
  115. <li><a class="reference internal" href="#expose-rid-and-sid" id="id51">expose_rid_and_sid</a></li>
  116. <li><a class="reference internal" href="#forward-messages" id="id52">forward_messages</a></li>
  117. <li><a class="reference internal" href="#fullname" id="id53">fullname</a></li>
  118. <li><a class="reference internal" href="#hide-muc-server" id="id54">hide_muc_server</a></li>
  119. <li><a class="reference internal" href="#i18n" id="id55">i18n</a></li>
  120. <li><a class="reference internal" href="#play-sounds" id="id56">play_sounds</a></li>
  121. <li><a class="reference internal" href="#prebind" id="id57">prebind</a></li>
  122. <li><a class="reference internal" href="#roster-groups" id="id58">roster_groups</a></li>
  123. <li><a class="reference internal" href="#show-controlbox-by-default" id="id59">show_controlbox_by_default</a></li>
  124. <li><a class="reference internal" href="#show-only-online-users" id="id60">show_only_online_users</a></li>
  125. <li><a class="reference internal" href="#storage" id="id61">storage</a></li>
  126. <li><a class="reference internal" href="#use-otr-by-default" id="id62">use_otr_by_default</a></li>
  127. <li><a class="reference internal" href="#use-vcards" id="id63">use_vcards</a></li>
  128. <li><a class="reference internal" href="#visible-toolbar-buttons" id="id64">visible_toolbar_buttons</a></li>
  129. <li><a class="reference internal" href="#xhr-custom-status" id="id65">xhr_custom_status</a></li>
  130. <li><a class="reference internal" href="#xhr-custom-status-url" id="id66">xhr_custom_status_url</a></li>
  131. <li><a class="reference internal" href="#xhr-user-search" id="id67">xhr_user_search</a></li>
  132. <li><a class="reference internal" href="#xhr-user-search-url" id="id68">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="#id7">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>builds/converse.min.js</li>
  144. <li>css/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"><div class="highlight"><pre>&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;screen&quot; href=&quot;css/converse.min.css&quot;&gt;
  149. &lt;script src=&quot;builds/converse.min.js&quot;&gt;&lt;/script&gt;
  150. </pre></div>
  151. </div>
  152. <p>You need to initialize Converse.js with configuration settings particular to
  153. your requirements.</p>
  154. <p>Please refer to the <a class="reference internal" href="#configuration-variables">Configuration variables</a> section further below for info on
  155. all the available configuration settings.</p>
  156. <p>To configure Converse.js, put the following inline Javascript code at the
  157. bottom of your page (after the closing <em>&lt;/body&gt;</em> element).</p>
  158. <div class="highlight-python"><div class="highlight"><pre>require([&#39;converse&#39;], function (converse) {
  159. converse.initialize({
  160. auto_list_rooms: false,
  161. auto_subscribe: false,
  162. bosh_service_url: &#39;https://bind.conversejs.org&#39;, // Please use this connection manager only for testing purposes
  163. hide_muc_server: false,
  164. i18n: locales.en, // Refer to ./locale/locales.js to see which locales are supported
  165. prebind: false,
  166. show_controlbox_by_default: true,
  167. roster_groups: true
  168. });
  169. });
  170. </pre></div>
  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 may serve as a nice usable example.</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="#id8">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 websites.</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="#id9">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="#id10">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="a-bosh-connection-manager">
  216. <h2><a class="toc-backref" href="#id11">A BOSH Connection Manager</a><a class="headerlink" href="#a-bosh-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>The <a class="reference external" href="https://github.com/jcbrand/converse.js/blob/master/index.html">index.html</a> file inside the</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. Popular XMPP servers such as
  227. <a class="reference external" href="http://www.ejabberd.im">ejabberd</a>, <a class="reference external" href="http://prosody.im/doc/setting_up_bosh">prosody</a> and
  228. <a class="reference external" href="http://www.igniterealtime.org/projects/openfire/">openfire</a> all include their own connection managers
  229. (but you usually have to enable them in the configuration).</p>
  230. <p>Standalone connection managers also exist, see for example <a class="reference external" href="https://github.com/twonds/punjab">Punjab</a>.</p>
  231. <p>The demo on the <a class="reference external" href="http://conversejs.org">Converse.js homepage</a> uses a connection manager located at <a class="reference external" href="https://bind.conversejs.org">https://bind.conversejs.org</a>.
  232. This connection manager is available for testing purposes only, please don&#8217;t use it in production.</p>
  233. <div class="section" id="overcoming-cross-domain-request-restrictions">
  234. <h3><a class="toc-backref" href="#id12">Overcoming cross-domain request restrictions</a><a class="headerlink" href="#overcoming-cross-domain-request-restrictions" title="Permalink to this headline">¶</a></h3>
  235. <p>Lets say your domain is <em>example.org</em>, but the domain of your connection
  236. manager is <em>example.com</em>.</p>
  237. <p>HTTP requests are made by <em>Converse.js</em> to the connection manager via XmlHttpRequests (XHR).
  238. Until recently, it was not possible to make such requests to a different domain
  239. than the one currently being served (to prevent XSS attacks).</p>
  240. <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.
  241. Modern browsers support CORS, but there are problems with Internet Explorer &lt;
  242. 10.</p>
  243. <p>IE 8 and 9 partially support CORS via a proprietary implementation called
  244. 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
  245. support for XDomainRequest when it is present.</p>
  246. <p>In IE &lt; 8, there is no support for CORS.</p>
  247. <p>Instead of using CORS, you can add a reverse proxy in
  248. Apache/Nginx which serves the connection manager under the same domain as your
  249. website. This will remove the need for any cross-domain XHR support.</p>
  250. <div class="section" id="for-example">
  251. <h4>For example:<a class="headerlink" href="#for-example" title="Permalink to this headline">¶</a></h4>
  252. <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>
  253. and your connection manager manager is running at <tt class="docutils literal"><span class="pre">someothersite.com/http-bind</span></tt>.</p>
  254. <p>The <em>bosh_service_url</em> value you want to give Converse.js to overcome
  255. the cross-domain restriction is <tt class="docutils literal"><span class="pre">mysite.com/http-bind</span></tt> and not
  256. <tt class="docutils literal"><span class="pre">someothersite.com/http-bind</span></tt>.</p>
  257. <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>
  258. </div>
  259. <div class="section" id="nginx">
  260. <h4>Nginx<a class="headerlink" href="#nginx" title="Permalink to this headline">¶</a></h4>
  261. <div class="highlight-python"><div class="highlight"><pre>http {
  262. server {
  263. listen 80
  264. server_name mysite.com;
  265. location ~ ^/http-bind/ {
  266. proxy_pass http://someothersite.com;
  267. }
  268. }
  269. }
  270. </pre></div>
  271. </div>
  272. </div>
  273. <div class="section" id="apache">
  274. <h4>Apache<a class="headerlink" href="#apache" title="Permalink to this headline">¶</a></h4>
  275. <div class="highlight-python"><div class="highlight"><pre>&lt;VirtualHost *:80&gt;
  276. ServerName mysite.com
  277. RewriteEngine On
  278. RewriteRule ^/http-bind(.*) http://someothersite.com/http-bind$1 [P,L]
  279. &lt;/VirtualHost&gt;
  280. </pre></div>
  281. </div>
  282. </div>
  283. </div>
  284. </div>
  285. <div class="section" id="server-side-authentication">
  286. <h2><a class="toc-backref" href="#id13">Server-side authentication</a><a class="headerlink" href="#server-side-authentication" title="Permalink to this headline">¶</a></h2>
  287. <div class="section" id="prebinding-and-single-session-support">
  288. <span id="session-support"></span><h3><a class="toc-backref" href="#id14">Prebinding and Single Session Support</a><a class="headerlink" href="#prebinding-and-single-session-support" title="Permalink to this headline">¶</a></h3>
  289. <p>It&#8217;s possible to enable single-site login, whereby users already
  290. authenticated in your website will also automatically be logged in on the chat server,</p>
  291. <p>This session should also persist across page loads. In other words, we don&#8217;t
  292. want the user to have to give their chat credentials every time they reload the
  293. page.</p>
  294. <p>To do this you will require a <a class="reference external" href="http://xmpp.org/about-xmpp/technology-overview/bosh/">BOSH server</a>
  295. 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>)
  296. as well as a BOSH client on your own server (written for example in Python, Ruby or PHP) that will
  297. do the pre-authentication before the web page loads.</p>
  298. <div class="admonition note">
  299. <p class="first admonition-title">Note</p>
  300. <p class="last">A BOSH server acts as a bridge between HTTP, the protocol of the web, and
  301. XMPP, the instant messaging protocol.
  302. Converse.js can only communicate via HTTP, but we need to communicate with
  303. an XMPP server in order to chat. So the BOSH server acts as a middle man,
  304. translating our HTTP requests into XMPP stanzas and vice versa.</p>
  305. </div>
  306. <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>
  307. <p>When you authenticate to the XMPP server on your backend application (for
  308. example via a BOSH client in Django), you&#8217;ll receive two tokens, RID (request ID) and SID (session ID).</p>
  309. <p>The <strong>Session ID (SID)</strong> is a unique identifier for the current <em>session</em>. This
  310. number stays constant for the entire session.</p>
  311. <p>The <strong>Request ID (RID)</strong> is a unique identifier for the current <em>request</em> (i.e.
  312. page load). Each page load is a new request which requires a new unique RID.
  313. The best way to achieve this is to simply increment the RID with each page
  314. load.</p>
  315. <p>When you initialize converse.js in your browser, you need to pass it these two
  316. tokens. Converse.js will then use them to attach to the session you just
  317. created.</p>
  318. <p>You can embed the RID and SID tokens in your HTML markup or you can do an
  319. XMLHttpRequest call to your server and ask it to return them for you.</p>
  320. <p>Below is one example of how this could work. An Ajax call is made to the
  321. relative URL <strong>/prebind</strong> and it expects to receive JSON data back.</p>
  322. <div class="highlight-python"><div class="highlight"><pre>$.getJSON(&#39;/prebind&#39;, function (data) {
  323. converse.initialize({
  324. prebind: true,
  325. bosh_service_url: data.bosh_service_url,
  326. jid: data.jid,
  327. sid: data.sid,
  328. rid: data.rid
  329. });
  330. );
  331. </pre></div>
  332. </div>
  333. <p><strong>Here&#8217;s what&#8217;s happening:</strong></p>
  334. <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
  335. BOSH server (also called a <em>connection manager</em>).</p>
  336. <p>These values are then passed to converse.js&#8217;s <tt class="docutils literal"><span class="pre">initialize</span></tt> method.</p>
  337. <div class="admonition note">
  338. <p class="first admonition-title">Note</p>
  339. <p class="last">If you want to enable single session support, you need to set <strong>prebind: true</strong>
  340. when calling <strong>converse.initialize</strong> (see ./index.html).
  341. Additionally you need to pass in valid <strong>jid</strong>, <strong>sid</strong>, <strong>rid</strong> and
  342. <strong>bosh_service_url</strong> values.</p>
  343. </div>
  344. </div>
  345. <div class="section" id="example-code-for-server-side-prebinding">
  346. <h3><a class="toc-backref" href="#id15">Example code for server-side prebinding</a><a class="headerlink" href="#example-code-for-server-side-prebinding" title="Permalink to this headline">¶</a></h3>
  347. <ul>
  348. <li><dl class="first docutils">
  349. <dt>PHP:</dt>
  350. <dd><p class="first last">See <a class="reference external" href="https://github.com/candy-chat/xmpp-prebind-php">xmpp-prebind-php</a> by
  351. Michael Weibel and the folks from Candy chat.</p>
  352. </dd>
  353. </dl>
  354. </li>
  355. <li><dl class="first docutils">
  356. <dt>Python:</dt>
  357. <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>
  358. </dd>
  359. </dl>
  360. </li>
  361. </ul>
  362. </div>
  363. </div>
  364. </div>
  365. <div class="section" id="features">
  366. <h1><a class="toc-backref" href="#id16">Features</a><a class="headerlink" href="#features" title="Permalink to this headline">¶</a></h1>
  367. <div class="section" id="off-the-record-encryption">
  368. <h2><a class="toc-backref" href="#id17">Off-the-record encryption</a><a class="headerlink" href="#off-the-record-encryption" title="Permalink to this headline">¶</a></h2>
  369. <p>Converse.js supports <a class="reference external" href="https://otr.cypherpunks.ca/">Off-the-record (OTR)</a>
  370. encrypted messaging.</p>
  371. <p>The OTR protocol not only <strong>encrypts your messages</strong>, it provides ways to
  372. <strong>verify the identity</strong> of the person you are talking to,
  373. <strong>plausible deniability</strong> and <strong>perfect forward secrecy</strong> by generating
  374. new encryption keys for each conversation.</p>
  375. <p>In its current state, Javascript cryptography is fraught with dangers and
  376. challenges that make it impossible to reach the same standard of security that
  377. is available with native &#8220;desktop&#8221; software.</p>
  378. <p>This is due to its runtime malleability, the way it is &#8220;installed&#8221; (e.g.
  379. served) and the browser&#8217;s lack of cryptographic primitives needed to implement
  380. secure crypto.</p>
  381. <p>For harsh but fairly valid criticism of Javascript cryptography, read:
  382. <a class="reference external" href="http://www.matasano.com/articles/javascript-cryptography/">Javascript Cryptography Considered Harmful</a>.</p>
  383. <p>To get an idea on how this applies to OTR support in Converse.js, please read
  384. <a class="reference external" href="https://opkode.com/media/blog/2013/11/11/conversejs-otr-support">my thoughts on it</a>.</p>
  385. <p>For now, suffice to say that although its useful to have OTR support in
  386. Converse.js in order to avoid most eavesdroppers, if you need serious
  387. communications privacy, then you&#8217;re much better off using native software.</p>
  388. </div>
  389. <div class="section" id="sound-notifications">
  390. <h2><a class="toc-backref" href="#id18">Sound Notifications</a><a class="headerlink" href="#sound-notifications" title="Permalink to this headline">¶</a></h2>
  391. <p>From version 0.8.1 Converse.js can play a sound notification when you receive a
  392. message.</p>
  393. <p>For more info, please see the <a class="reference internal" href="#play-sounds">play_sounds</a> configuration setting.</p>
  394. </div>
  395. <div class="section" id="multilingual-support">
  396. <h2><a class="toc-backref" href="#id19">Multilingual Support</a><a class="headerlink" href="#multilingual-support" title="Permalink to this headline">¶</a></h2>
  397. <p>Converse.js is translated into multiple languages. The default build,
  398. <tt class="docutils literal"><span class="pre">converse.min.js</span></tt>, includes all languages.</p>
  399. <p>Languages increase the size of the Converse.js significantly.</p>
  400. <p>If you only need one, or a subset of the available languages, it&#8217;s better to
  401. make a custom build which includes only those languages that you need.</p>
  402. </div>
  403. </div>
  404. <div class="section" id="development">
  405. <h1><a class="toc-backref" href="#id20">Development</a><a class="headerlink" href="#development" title="Permalink to this headline">¶</a></h1>
  406. <p>If you want to work with the non-minified Javascript and CSS files you&#8217;ll soon
  407. notice that there are references to a missing <em>components</em> folder. Please
  408. follow the instructions below to create this folder and fetch Converse&#8217;s
  409. 3rd-party dependencies.</p>
  410. <div class="section" id="install-the-development-and-front-end-dependencies">
  411. <h2><a class="toc-backref" href="#id21">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>
  412. <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>)
  413. which depend on Node.js and npm (the Node package manager).</p>
  414. <p>If you don&#8217;t have Node.js installed, you can download and install the latest
  415. version <a class="reference external" href="https://nodejs.org/download">here</a>.</p>
  416. <p>Also make sure you have <tt class="docutils literal"><span class="pre">git</span></tt> installed. <a class="reference external" href="http://git-scm.com/book/en/Getting-Started-Installing-Git">Details</a>.</p>
  417. <p>Once you have <em>Node.js</em> and <em>git</em> installed, run the following command inside the Converse.js
  418. directory:</p>
  419. <div class="highlight-python"><div class="highlight"><pre>make dev
  420. </pre></div>
  421. </div>
  422. <p>Or alternatively, if you don&#8217;t have GNU Make:</p>
  423. <div class="highlight-python"><div class="highlight"><pre>npm install
  424. bower update
  425. </pre></div>
  426. </div>
  427. <p>This will first install the Node.js development tools (like Grunt and Bower)
  428. and then use Bower to install all of Converse.js&#8217;s front-end dependencies.</p>
  429. <p>The front-end dependencies are those javascript files on which
  430. Converse.js directly depends and which will be loaded in the browser.</p>
  431. <p>If you are curious to know what the different dependencies are:</p>
  432. <ul>
  433. <li><dl class="first docutils">
  434. <dt>Development dependencies:</dt>
  435. <dd><p class="first last">Take a look at whats under the <em>devDependencies</em> key in
  436. <a class="reference external" href="https://github.com/jcbrand/converse.js/blob/master/package.json">package.json</a>.</p>
  437. </dd>
  438. </dl>
  439. </li>
  440. <li><dl class="first docutils">
  441. <dt>Front-end dependencies:</dt>
  442. <dd><p class="first last">See <em>dependencies</em> in
  443. <a class="reference external" href="https://github.com/jcbrand/converse.js/blob/master/bower.json">bower.json</a>.</p>
  444. </dd>
  445. </dl>
  446. </li>
  447. </ul>
  448. </div>
  449. <div class="section" id="with-amd-and-require-js-recommended">
  450. <h2><a class="toc-backref" href="#id22">With AMD and require.js (recommended)</a><a class="headerlink" href="#with-amd-and-require-js-recommended" title="Permalink to this headline">¶</a></h2>
  451. <p>Converse.js uses <a class="reference external" href="http://requirejs.org">require.js</a> to asynchronously load dependencies.</p>
  452. <p>If you want to develop or customize converse.js, you&#8217;ll want to load the
  453. non-minified javascript files.</p>
  454. <p>Add the following two lines to the <em>&lt;head&gt;</em> section of your webpage:</p>
  455. <div class="highlight-python"><div class="highlight"><pre>&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;screen&quot; href=&quot;converse.css&quot;&gt;
  456. &lt;script data-main=&quot;main&quot; src=&quot;components/requirejs/require.js&quot;&gt;&lt;/script&gt;
  457. </pre></div>
  458. </div>
  459. <p>require.js will then let the main.js file be parsed (because of the <em>data-main</em>
  460. attribute on the <em>script</em> tag), which will in turn cause converse.js to be
  461. parsed.</p>
  462. </div>
  463. <div class="section" id="without-amd-and-require-js">
  464. <h2><a class="toc-backref" href="#id23">Without AMD and require.js</a><a class="headerlink" href="#without-amd-and-require-js" title="Permalink to this headline">¶</a></h2>
  465. <p>Converse.js can also be used without require.js. If you for some reason prefer
  466. to use it this way, please refer to
  467. <a class="reference external" href="https://github.com/jcbrand/converse.js/blob/master/non_amd.html">non_amd.html</a>
  468. for an example of how and in what order all the Javascript files that converse.js
  469. depends on need to be loaded.</p>
  470. </div>
  471. <div class="section" id="before-submitting-a-pull-request">
  472. <h2><a class="toc-backref" href="#id24">Before submitting a pull request</a><a class="headerlink" href="#before-submitting-a-pull-request" title="Permalink to this headline">¶</a></h2>
  473. <div class="section" id="add-tests-for-your-bugfix-or-feature">
  474. <h3><a class="toc-backref" href="#id25">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>
  475. <p>Add a test for any bug fixed or feature added. We use Jasmine
  476. for testing.</p>
  477. <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
  478. the tests are implemented.</p>
  479. <p>If you are unsure how to write tests, please
  480. <a class="reference external" href="http://opkode.com/contact">contact me</a> and I&#8217;ll be happy to help.</p>
  481. </div>
  482. <div class="section" id="check-that-the-tests-pass">
  483. <h3><a class="toc-backref" href="#id26">Check that the tests pass</a><a class="headerlink" href="#check-that-the-tests-pass" title="Permalink to this headline">¶</a></h3>
  484. <p>Check that the Jasmine tests complete sucessfully. Open
  485. <a class="reference external" href="https://github.com/jcbrand/converse.js/blob/master/tests.html">tests.html</a>
  486. in your browser, and the tests will run automatically.</p>
  487. <p>On the command line you can run:</p>
  488. <div class="highlight-python"><div class="highlight"><pre>grunt test
  489. </pre></div>
  490. </div>
  491. </div>
  492. <div class="section" id="check-your-code-for-errors-or-bad-habits-by-running-jshint">
  493. <h3><a class="toc-backref" href="#id27">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>
  494. <p><a class="reference external" href="http://jshint.com">JSHint</a> will do a static analysis of your code and hightlight potential errors
  495. and/or bad habits.</p>
  496. <div class="highlight-python"><div class="highlight"><pre>grunt jshint
  497. </pre></div>
  498. </div>
  499. <p>You can run both the tests and jshint in one go by calling:</p>
  500. <div class="highlight-python"><div class="highlight"><pre>grunt check
  501. </pre></div>
  502. </div>
  503. </div>
  504. </div>
  505. <div class="section" id="minification">
  506. <h2><a class="toc-backref" href="#id28">Minification</a><a class="headerlink" href="#minification" title="Permalink to this headline">¶</a></h2>
  507. <div class="section" id="minifying-javascript-and-css">
  508. <h3><a class="toc-backref" href="#id29">Minifying Javascript and CSS</a><a class="headerlink" href="#minifying-javascript-and-css" title="Permalink to this headline">¶</a></h3>
  509. <p>Please make sure to read the section <a class="reference internal" href="#development">Development</a> and that you have installed
  510. all development dependencies (long story short, you can run <tt class="docutils literal"><span class="pre">npm</span> <span class="pre">install</span></tt>
  511. and then <tt class="docutils literal"><span class="pre">grunt</span> <span class="pre">fetch</span></tt>).</p>
  512. <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
  513. to bundle them together in a single minified file fit for deployment to a
  514. production site.</p>
  515. <p>To minify the Javascript and CSS, run the following command:</p>
  516. <div class="highlight-python"><div class="highlight"><pre>grunt minify
  517. </pre></div>
  518. </div>
  519. <p>Javascript will be bundled and minified with <a class="reference external" href="http://requirejs.org">require.js</a>&#8216;s optimization tool,
  520. using <a class="reference external" href="https://github.com/jrburke/almond">almond</a>.</p>
  521. <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>
  522. <p>CSS is minified via <a class="reference external" href="https://github.com/gruntjs/grunt-contrib-cssmin">cssmin</a>.</p>
  523. </div>
  524. </div>
  525. <div class="section" id="translations">
  526. <h2><a class="toc-backref" href="#id30">Translations</a><a class="headerlink" href="#translations" title="Permalink to this headline">¶</a></h2>
  527. <div class="admonition note">
  528. <p class="first admonition-title">Note</p>
  529. <p class="last">Translations take up a lot of space and will bloat your minified file.
  530. At the time of writing, all the translations add about 50KB of extra data to
  531. the minified javascript file. Therefore, make sure to only
  532. include those languages that you intend to support and remove from
  533. ./locale/locales.js those which you don&#8217;t need. Remember to rebuild the
  534. minified file afterwards.</p>
  535. </div>
  536. <p>The gettext POT file located in ./locale/converse.pot is the template
  537. containing all translations and from which for each language an individual PO
  538. file is generated.</p>
  539. <p>The POT file contains all translateable strings extracted from converse.js.</p>
  540. <p>To make a user facing string translateable, wrap it in the double underscore helper
  541. function like so:</p>
  542. <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>
  543. </pre></div>
  544. </div>
  545. <p>After adding the string, you&#8217;ll need to regenerate the POT file, like so:</p>
  546. <div class="highlight-python"><div class="highlight"><pre>make pot
  547. </pre></div>
  548. </div>
  549. <p>You can then create or update the PO file for a specific language by doing the following:</p>
  550. <div class="highlight-python"><div class="highlight"><pre>msgmerge ./locale/de/LC_MESSAGES/converse.po ./locale/converse.pot -U
  551. </pre></div>
  552. </div>
  553. <p>To do this for ALL languages, run:</p>
  554. <div class="highlight-python"><div class="highlight"><pre>make po
  555. </pre></div>
  556. </div>
  557. <p>The resulting PO file is then what gets translated.</p>
  558. <p>If you&#8217;ve created a new PO file, please make sure to add the following
  559. attributes at the top of the file (under <em>Content-Transfer-Encoding</em>). They are
  560. required as configuration settings for Jed, the Javascript translations library
  561. that we&#8217;re using.</p>
  562. <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>
  563. <span class="s">&quot;lang: de</span><span class="se">\n</span><span class="s">&quot;</span>
  564. <span class="s">&quot;plural_forms: nplurals=2; plural=(n != 1);</span><span class="se">\n</span><span class="s">&quot;</span>
  565. </pre></div>
  566. </div>
  567. <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
  568. a file in JSON format and then put that in a .js file for the specific
  569. language.</p>
  570. <p>To generate JSON from a PO file, you&#8217;ll need po2json for node.js. Run the
  571. following command to install it (npm being the node.js package manager):</p>
  572. <div class="highlight-python"><div class="highlight"><pre>npm install po2json
  573. </pre></div>
  574. </div>
  575. <p>You can then convert the translations into JSON format:</p>
  576. <div class="highlight-python"><div class="highlight"><pre>po2json locale/de/LC_MESSAGES/converse.po locale/de/LC_MESSAGES/converse.json
  577. </pre></div>
  578. </div>
  579. <p>Now from converse.json paste the data as a value for the &#8220;locale_data&#8221; key in the
  580. object in the language&#8217;s .js file.</p>
  581. <p>So, if you are for example translating into German (language code &#8216;de&#8217;), you&#8217;ll
  582. create or update the file ./locale/LC_MESSAGES/de.js with the following code:</p>
  583. <div class="highlight-python"><div class="highlight"><pre>(function (root, factory) {
  584. define(&quot;de&quot;, [&#39;jed&#39;], function () {
  585. return factory(new Jed({
  586. &quot;domain&quot;: &quot;converse&quot;,
  587. &quot;locale_data&quot;: {
  588. // Paste the JSON data from converse.json here
  589. }
  590. })
  591. }
  592. }(this, function (i18n) {
  593. return i18n;
  594. }));
  595. </pre></div>
  596. </div>
  597. <p>making sure to also paste the JSON data as value to the &#8220;locale_data&#8221; key.</p>
  598. <div class="admonition note">
  599. <p class="first admonition-title">Note</p>
  600. <p class="last">If you are adding translations for a new language that is not already supported,
  601. you&#8217;ll have to make one more edit in ./locale/locales.js to make sure the
  602. language is loaded by require.js.</p>
  603. </div>
  604. <p>Congratulations, you&#8217;ve now succesfully added your translations. Sorry for all
  605. those hoops you had to jump through.</p>
  606. </div>
  607. </div>
  608. <div class="section" id="troubleshooting">
  609. <h1><a class="toc-backref" href="#id31">Troubleshooting</a><a class="headerlink" href="#troubleshooting" title="Permalink to this headline">¶</a></h1>
  610. <div class="section" id="conflicts-with-other-javascript-libraries">
  611. <h2><a class="toc-backref" href="#id32">Conflicts with other Javascript libraries</a><a class="headerlink" href="#conflicts-with-other-javascript-libraries" title="Permalink to this headline">¶</a></h2>
  612. <div class="section" id="problem">
  613. <h3><a class="toc-backref" href="#id33">Problem:</a><a class="headerlink" href="#problem" title="Permalink to this headline">¶</a></h3>
  614. <p>You are using other Javascript libraries (like JQuery plugins), and
  615. get errors like these in your browser console:</p>
  616. <div class="highlight-python"><div class="highlight"><pre>Uncaught TypeError: Object [object Object] has no method &#39;xxx&#39; from example.js
  617. </pre></div>
  618. </div>
  619. </div>
  620. <div class="section" id="solution">
  621. <h3><a class="toc-backref" href="#id34">Solution:</a><a class="headerlink" href="#solution" title="Permalink to this headline">¶</a></h3>
  622. <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>
  623. <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>
  624. <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
  625. rules apply if its something else.</p>
  626. <p>The bundled and minified default build of converse.js, <tt class="docutils literal"><span class="pre">converse.min.js</span></tt>
  627. includes within it all of converse.js&#8217;s dependencies, which include for example <em>jQuery</em>.</p>
  628. <p>If you are having conflicts where attributes or methods aren&#8217;t available
  629. on the jQuery object, you are probably loading <tt class="docutils literal"><span class="pre">converse.min.js</span></tt> (which
  630. includes jQuery) as well as your own jQuery version separately.</p>
  631. <p>What then happens is that there are two <tt class="docutils literal"><span class="pre">$</span></tt> objects (one from
  632. converse.js and one from the jQuery version you included manually)
  633. and only one of them has been extended to have the methods or attributes you require.</p>
  634. <p>Which jQuery object you get depends on the order in which you load the libraries.</p>
  635. <p>There are multiple ways to solve this issue.</p>
  636. <p>Firstly, make sure whether you really need to include a separate version of
  637. jQuery. Chances are that you don&#8217;t. If you can remove the separate
  638. version, your problem should be solved, as long as your libraries are loaded in
  639. the right order.</p>
  640. <p>Either case, whether you need to keep two versions or not, the solution depends
  641. on whether you&#8217;ll use require.js to manage your libraries or whether you&#8217;ll
  642. load them manually.</p>
  643. <div class="section" id="with-require-js">
  644. <h4>With require.js<a class="headerlink" href="#with-require-js" title="Permalink to this headline">¶</a></h4>
  645. <p>Instead of using <tt class="docutils literal"><span class="pre">converse.min.js</span></tt>, manage all the libraries in your project
  646. (i.e. converse.js and its dependencies plus all other libraries you use) as one
  647. require.js project, making sure everything is loaded in the correct order.</p>
  648. <p>Then, before deployment, you make your own custom minified build that bundles everything
  649. you need.</p>
  650. </div>
  651. <div class="section" id="with-script-tags">
  652. <h4>With &lt;script&gt; tags<a class="headerlink" href="#with-script-tags" title="Permalink to this headline">¶</a></h4>
  653. <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>
  654. in the converse.js repo.</p>
  655. <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
  656. your own libraries, making sure that they are loaded in the correct order (e.g.
  657. jQuery plugins must load after jQuery).</p>
  658. </div>
  659. </div>
  660. </div>
  661. </div>
  662. <div class="section" id="events">
  663. <h1><a class="toc-backref" href="#id35">Events</a><a class="headerlink" href="#events" title="Permalink to this headline">¶</a></h1>
  664. <p>Converse.js emits events to which you can subscribe from your own Javascript.</p>
  665. <p>Concerning events, the following methods are available:</p>
  666. <div class="section" id="event-methods">
  667. <h2><a class="toc-backref" href="#id36">Event Methods</a><a class="headerlink" href="#event-methods" title="Permalink to this headline">¶</a></h2>
  668. <ul>
  669. <li><p class="first"><strong>on(eventName, callback)</strong>:</p>
  670. <blockquote>
  671. <div><p>Calling the <tt class="docutils literal"><span class="pre">on</span></tt> method allows you to subscribe to an event.
  672. Every time the event fires, the callback method specified by <tt class="docutils literal"><span class="pre">callback</span></tt> will be
  673. called.</p>
  674. <p>Parameters:</p>
  675. <ul class="simple">
  676. <li><tt class="docutils literal"><span class="pre">eventName</span></tt> is the event name as a string.</li>
  677. <li><tt class="docutils literal"><span class="pre">callback</span></tt> is the callback method to be called when the event is emitted.</li>
  678. </ul>
  679. <p>For example:</p>
  680. <div class="highlight-python"><div class="highlight"><pre>converse.on(&#39;message&#39;, function (messageXML) { ... });
  681. </pre></div>
  682. </div>
  683. </div></blockquote>
  684. </li>
  685. <li><p class="first"><strong>once(eventName, callback)</strong>:</p>
  686. <blockquote>
  687. <div><p>Calling the <tt class="docutils literal"><span class="pre">once</span></tt> method allows you to listen to an event
  688. exactly once.</p>
  689. <p>Parameters:</p>
  690. <ul class="simple">
  691. <li><tt class="docutils literal"><span class="pre">eventName</span></tt> is the event name as a string.</li>
  692. <li><tt class="docutils literal"><span class="pre">callback</span></tt> is the callback method to be called when the event is emitted.</li>
  693. </ul>
  694. <p>For example:</p>
  695. <div class="highlight-python"><div class="highlight"><pre>converse.once(&#39;message&#39;, function (messageXML) { ... });
  696. </pre></div>
  697. </div>
  698. </div></blockquote>
  699. </li>
  700. <li><p class="first"><strong>off(eventName, callback)</strong></p>
  701. <blockquote>
  702. <div><p>To stop listening to an event, you can use the <tt class="docutils literal"><span class="pre">off</span></tt> method.</p>
  703. <p>Parameters:</p>
  704. <ul class="simple">
  705. <li><tt class="docutils literal"><span class="pre">eventName</span></tt> is the event name as a string.</li>
  706. <li><tt class="docutils literal"><span class="pre">callback</span></tt> refers to the function that is to be no longer executed.</li>
  707. </ul>
  708. </div></blockquote>
  709. </li>
  710. </ul>
  711. </div>
  712. <div class="section" id="event-types">
  713. <h2><a class="toc-backref" href="#id37">Event Types</a><a class="headerlink" href="#event-types" title="Permalink to this headline">¶</a></h2>
  714. <p>Here are the different events that are emitted:</p>
  715. <table border="1" class="docutils">
  716. <colgroup>
  717. <col width="15%" />
  718. <col width="45%" />
  719. <col width="40%" />
  720. </colgroup>
  721. <thead valign="bottom">
  722. <tr class="row-odd"><th class="head">Event Type</th>
  723. <th class="head">When is it triggered?</th>
  724. <th class="head">Example</th>
  725. </tr>
  726. </thead>
  727. <tbody valign="top">
  728. <tr class="row-even"><td><strong>initialized</strong></td>
  729. <td>Once converse.js has been initialized.</td>
  730. <td><tt class="docutils literal"><span class="pre">converse.on('initialized',</span> <span class="pre">function</span> <span class="pre">()</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">});</span></tt></td>
  731. </tr>
  732. <tr class="row-odd"><td><strong>ready</strong></td>
  733. <td>After connection has been established and converse.js has got all its ducks in a row.</td>
  734. <td><tt class="docutils literal"><span class="pre">converse.on('ready',</span> <span class="pre">function</span> <span class="pre">()</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">});</span></tt></td>
  735. </tr>
  736. <tr class="row-even"><td><strong>reconnect</strong></td>
  737. <td>After the connection has dropped. Converse.js will attempt to reconnect when not in prebind mode.</td>
  738. <td><tt class="docutils literal"><span class="pre">converse.on('reconnect',</span> <span class="pre">function</span> <span class="pre">()</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">});</span></tt></td>
  739. </tr>
  740. <tr class="row-odd"><td><strong>message</strong></td>
  741. <td>When a message is received.</td>
  742. <td><tt class="docutils literal"><span class="pre">converse.on('message',</span> <span class="pre">function</span> <span class="pre">(messageXML)</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">});</span></tt></td>
  743. </tr>
  744. <tr class="row-even"><td><strong>messageSend</strong></td>
  745. <td>When a message will be sent out.</td>
  746. <td><tt class="docutils literal"><span class="pre">converse.on('messageSend',</span> <span class="pre">function</span> <span class="pre">(messageText)</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">});</span></tt></td>
  747. </tr>
  748. <tr class="row-odd"><td><strong>roster</strong></td>
  749. <td>When the roster is updated.</td>
  750. <td><tt class="docutils literal"><span class="pre">converse.on('roster',</span> <span class="pre">function</span> <span class="pre">(items)</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">});</span></tt></td>
  751. </tr>
  752. <tr class="row-even"><td><strong>callButtonClicked</strong></td>
  753. <td>When a call button (i.e. with class .toggle-call) on a chat box has been clicked.</td>
  754. <td><tt class="docutils literal"><span class="pre">converse.on('callButtonClicked',</span> <span class="pre">function</span> <span class="pre">(connection,</span> <span class="pre">model)</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">});</span></tt></td>
  755. </tr>
  756. <tr class="row-odd"><td><strong>chatBoxOpened</strong></td>
  757. <td>When a chat box has been opened.</td>
  758. <td><tt class="docutils literal"><span class="pre">converse.on('chatBoxOpened',</span> <span class="pre">function</span> <span class="pre">(chatbox)</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">});</span></tt></td>
  759. </tr>
  760. <tr class="row-even"><td><strong>chatRoomOpened</strong></td>
  761. <td>When a chat room has been opened.</td>
  762. <td><tt class="docutils literal"><span class="pre">converse.on('chatRoomOpened',</span> <span class="pre">function</span> <span class="pre">(chatbox)</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">});</span></tt></td>
  763. </tr>
  764. <tr class="row-odd"><td><strong>chatBoxClosed</strong></td>
  765. <td>When a chat box has been closed.</td>
  766. <td><tt class="docutils literal"><span class="pre">converse.on('chatBoxClosed',</span> <span class="pre">function</span> <span class="pre">(chatbox)</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">});</span></tt></td>
  767. </tr>
  768. <tr class="row-even"><td><strong>chatBoxFocused</strong></td>
  769. <td>When the focus has been moved to a chat box.</td>
  770. <td><tt class="docutils literal"><span class="pre">converse.on('chatBoxFocused',</span> <span class="pre">function</span> <span class="pre">(chatbox)</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">});</span></tt></td>
  771. </tr>
  772. <tr class="row-odd"><td><strong>chatBoxToggled</strong></td>
  773. <td>When a chat box has been minimized or maximized.</td>
  774. <td><tt class="docutils literal"><span class="pre">converse.on('chatBoxToggled',</span> <span class="pre">function</span> <span class="pre">(chatbox)</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">});</span></tt></td>
  775. </tr>
  776. <tr class="row-even"><td><strong>statusChanged</strong></td>
  777. <td>When own chat status has changed.</td>
  778. <td><tt class="docutils literal"><span class="pre">converse.on('statusChanged',</span> <span class="pre">function</span> <span class="pre">(status)</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">});</span></tt></td>
  779. </tr>
  780. <tr class="row-odd"><td><strong>statusMessageChanged</strong></td>
  781. <td>When own custom status message has changed.</td>
  782. <td><tt class="docutils literal"><span class="pre">converse.on('statusMessageChanged',</span> <span class="pre">function</span> <span class="pre">(message)</span> <span class="pre">{</span> <span class="pre">...</span> <span class="pre">});</span></tt></td>
  783. </tr>
  784. <tr class="row-even"><td><strong>buddyStatusChanged</strong></td>
  785. <td>When a chat buddy&#8217;s chat status has changed.</td>
  786. <td><tt class="docutils literal"><span class="pre">converse.on('buddyStatusChanged',</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></td>
  787. </tr>
  788. <tr class="row-odd"><td><strong>buddyStatusMessageChanged</strong></td>
  789. <td>When a chat buddy&#8217;s custom status message has changed.</td>
  790. <td><tt class="docutils literal"><span class="pre">converse.on('buddyStatusMessageChanged',</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></td>
  791. </tr>
  792. </tbody>
  793. </table>
  794. </div>
  795. </div>
  796. <div class="section" id="configuration">
  797. <h1><a class="toc-backref" href="#id38">Configuration</a><a class="headerlink" href="#configuration" title="Permalink to this headline">¶</a></h1>
  798. <p>The included minified JS and CSS files can be used for demoing or testing, but
  799. you&#8217;ll want to configure <em>Converse.js</em> to suit your needs before you deploy it
  800. on your website.</p>
  801. <p><em>Converse.js</em> is passed its configuration settings when you call its
  802. <em>initialize</em> method.</p>
  803. <p>You&#8217;ll most likely want to call the <em>initialize</em> method in your HTML page. For
  804. an example of how this is done, please see the bottom of the <em>./index.html</em> page.</p>
  805. <p>Please refer to the <a class="reference internal" href="#configuration-variables">Configuration variables</a> section below for info on
  806. all the available configuration settings.</p>
  807. <p>After you have configured <em>Converse.js</em>, you&#8217;ll have to regenerate the minified
  808. JS file so that it will include the new settings. Please refer to the
  809. <a class="reference internal" href="#minification">Minification</a> section for more info on how to do this.</p>
  810. <div class="section" id="configuration-variables">
  811. <h2><a class="toc-backref" href="#id39">Configuration variables</a><a class="headerlink" href="#configuration-variables" title="Permalink to this headline">¶</a></h2>
  812. <div class="section" id="allow-contact-requests">
  813. <h3><a class="toc-backref" href="#id40">allow_contact_requests</a><a class="headerlink" href="#allow-contact-requests" title="Permalink to this headline">¶</a></h3>
  814. <p>Default: <tt class="docutils literal"><span class="pre">true</span></tt></p>
  815. <p>Allow users to add one another as contacts. If this is set to false, the
  816. <strong>Add a contact</strong> widget, <strong>Contact Requests</strong> and <strong>Pending Contacts</strong> roster
  817. sections will all not appear. Additionally, all incoming contact requests will be
  818. ignored.</p>
  819. </div>
  820. <div class="section" id="allow-muc">
  821. <h3><a class="toc-backref" href="#id41">allow_muc</a><a class="headerlink" href="#allow-muc" title="Permalink to this headline">¶</a></h3>
  822. <p>Default: <tt class="docutils literal"><span class="pre">true</span></tt></p>
  823. <p>Allow multi-user chat (muc) in chatrooms. Setting this to <tt class="docutils literal"><span class="pre">false</span></tt> will remove
  824. the <tt class="docutils literal"><span class="pre">Chatrooms</span></tt> tab from the control box.</p>
  825. </div>
  826. <div class="section" id="id3">
  827. <h3><a class="toc-backref" href="#id42">allow_muc</a><a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h3>
  828. <p>Default: <tt class="docutils literal"><span class="pre">true</span></tt></p>
  829. <p>Allow Off-the-record encryption of single-user chat messages.</p>
  830. </div>
  831. <div class="section" id="animate">
  832. <h3><a class="toc-backref" href="#id43">animate</a><a class="headerlink" href="#animate" title="Permalink to this headline">¶</a></h3>
  833. <p>Default: <tt class="docutils literal"><span class="pre">true</span></tt></p>
  834. <p>Show animations, for example when opening and closing chat boxes.</p>
  835. </div>
  836. <div class="section" id="auto-list-rooms">
  837. <h3><a class="toc-backref" href="#id44">auto_list_rooms</a><a class="headerlink" href="#auto-list-rooms" title="Permalink to this headline">¶</a></h3>
  838. <p>Default: <tt class="docutils literal"><span class="pre">false</span></tt></p>
  839. <p>If true, and the XMPP server on which the current user is logged in supports
  840. multi-user chat, then a list of rooms on that server will be fetched.</p>
  841. <p>Not recommended for servers with lots of chat rooms.</p>
  842. <p>For each room on the server a query is made to fetch further details (e.g.
  843. features, number of occupants etc.), so on servers with many rooms this
  844. option will create lots of extra connection traffic.</p>
  845. </div>
  846. <div class="section" id="auto-reconnect">
  847. <h3><a class="toc-backref" href="#id45">auto_reconnect</a><a class="headerlink" href="#auto-reconnect" title="Permalink to this headline">¶</a></h3>
  848. <p>Default: <tt class="docutils literal"><span class="pre">true</span></tt></p>
  849. <p>Automatically reconnect to the XMPP server if the connection drops
  850. unexpectedly.</p>
  851. </div>
  852. <div class="section" id="auto-subscribe">
  853. <h3><a class="toc-backref" href="#id46">auto_subscribe</a><a class="headerlink" href="#auto-subscribe" title="Permalink to this headline">¶</a></h3>
  854. <p>Default: <tt class="docutils literal"><span class="pre">false</span></tt></p>
  855. <p>If true, the user will automatically subscribe back to any contact requests.</p>
  856. </div>
  857. <div class="section" id="bosh-service-url">
  858. <h3><a class="toc-backref" href="#id47">bosh_service_url</a><a class="headerlink" href="#bosh-service-url" title="Permalink to this headline">¶</a></h3>
  859. <p>Connections to an XMPP server depend on a BOSH connection manager which acts as
  860. a middle man between HTTP and XMPP.</p>
  861. <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>
  862. </div>
  863. <div class="section" id="cache-otr-key">
  864. <h3><a class="toc-backref" href="#id48">cache_otr_key</a><a class="headerlink" href="#cache-otr-key" title="Permalink to this headline">¶</a></h3>
  865. <p>Default: <tt class="docutils literal"><span class="pre">false</span></tt></p>
  866. <p>Let the <a class="reference external" href="https://otr.cypherpunks.ca">OTR (Off-the-record encryption)</a> private
  867. key be cached in your browser&#8217;s session storage.</p>
  868. <p>The browser&#8217;s session storage persists across page loads but is deleted once
  869. the tab or window is closed.</p>
  870. <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
  871. for each page load. While more inconvenient, this is a much more secure option.</p>
  872. <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>
  873. <div class="admonition note">
  874. <p class="first admonition-title">Note</p>
  875. <p class="last">A browser window&#8217;s session storage is accessible by all javascript that
  876. is served from the same domain. So if there is malicious javascript served by
  877. the same server (or somehow injected via an attacker), then they will be able
  878. to retrieve your private key and read your all the chat messages in your
  879. current session. Previous sessions however cannot be decrypted.</p>
  880. </div>
  881. </div>
  882. <div class="section" id="debug">
  883. <h3><a class="toc-backref" href="#id49">debug</a><a class="headerlink" href="#debug" title="Permalink to this headline">¶</a></h3>
  884. <p>Default: <tt class="docutils literal"><span class="pre">false</span></tt></p>
  885. <p>If set to true, debugging output will be logged to the browser console.</p>
  886. </div>
  887. <div class="section" id="message-carbons">
  888. <h3><a class="toc-backref" href="#id50">message_carbons</a><a class="headerlink" href="#message-carbons" title="Permalink to this headline">¶</a></h3>
  889. <p>Default: <tt class="docutils literal"><span class="pre">false</span></tt></p>
  890. <p>Support for <a class="reference external" href="https://xmpp.org/extensions/xep-0280.html">XEP-0280: Message Carbons</a></p>
  891. </div>
  892. <div class="section" id="expose-rid-and-sid">
  893. <h3><a class="toc-backref" href="#id51">expose_rid_and_sid</a><a class="headerlink" href="#expose-rid-and-sid" title="Permalink to this headline">¶</a></h3>
  894. <p>Default: <tt class="docutils literal"><span class="pre">false</span></tt></p>
  895. <p>Allow the prebind tokens, RID (request ID) and SID (session ID), to be exposed
  896. globally via the API. This allows other scripts served on the same page to use
  897. these values.</p>
  898. <p><em>Beware</em>: a malicious script could use these tokens to assume your identity
  899. and inject fake chat messages.</p>
  900. </div>
  901. <div class="section" id="forward-messages">
  902. <h3><a class="toc-backref" href="#id52">forward_messages</a><a class="headerlink" href="#forward-messages" title="Permalink to this headline">¶</a></h3>
  903. <p>Default: <tt class="docutils literal"><span class="pre">false</span></tt></p>
  904. <p>If set to <tt class="docutils literal"><span class="pre">true</span></tt>, sent messages will also be forwarded to other connected
  905. XMPP resources (e.g. chat clients) of the same user.</p>
  906. <p>This is useful for example if converse.js is running in multiple tabs of the
  907. browser and you want sent messages to appear in all of them.</p>
  908. <p>See also <a class="reference external" href="http://www.xmpp.org/extensions/xep-0297.html">XEP 0297: Stanza Forwarding</a></p>
  909. </div>
  910. <div class="section" id="fullname">
  911. <h3><a class="toc-backref" href="#id53">fullname</a><a class="headerlink" href="#fullname" title="Permalink to this headline">¶</a></h3>
  912. <p>If you are using prebinding, can specify the fullname of the currently
  913. logged in user, otherwise the user&#8217;s vCard will be fetched.</p>
  914. </div>
  915. <div class="section" id="hide-muc-server">
  916. <h3><a class="toc-backref" href="#id54">hide_muc_server</a><a class="headerlink" href="#hide-muc-server" title="Permalink to this headline">¶</a></h3>
  917. <p>Default: <tt class="docutils literal"><span class="pre">false</span></tt></p>
  918. <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
  919. controlbox. Useful if you want to restrict users to a specific XMPP server of
  920. your choosing.</p>
  921. </div>
  922. <div class="section" id="i18n">
  923. <h3><a class="toc-backref" href="#id55">i18n</a><a class="headerlink" href="#i18n" title="Permalink to this headline">¶</a></h3>
  924. <p>Specify the locale/language. The language must be in the <tt class="docutils literal"><span class="pre">locales</span></tt> object. Refer to
  925. <tt class="docutils literal"><span class="pre">./locale/locales.js</span></tt> to see which locales are supported.</p>
  926. </div>
  927. <div class="section" id="play-sounds">
  928. <h3><a class="toc-backref" href="#id56">play_sounds</a><a class="headerlink" href="#play-sounds" title="Permalink to this headline">¶</a></h3>
  929. <p>Default: <tt class="docutils literal"><span class="pre">false</span></tt></p>
  930. <p>Inside the <tt class="docutils literal"><span class="pre">./sounds</span></tt> directory of the Converse.js repo, you&#8217;ll see MP3 and Ogg
  931. formatted sound files. We need both, because neither format is supported by all browsers.</p>
  932. <p>For now, sound files are looked up by convention, not configuration. So to have
  933. a sound play when a message is received, make sure that your webserver serves
  934. it in both formats as <tt class="docutils literal"><span class="pre">http://yoursite.com/sounds/msg_received.mp3</span></tt> and
  935. <tt class="docutils literal"><span class="pre">http://yoursite.com/sounds/msg_received.ogg</span></tt>.</p>
  936. <p><tt class="docutils literal"><span class="pre">http://yoursite.com</span></tt> should of course be your site&#8217;s URL.</p>
  937. </div>
  938. <div class="section" id="prebind">
  939. <h3><a class="toc-backref" href="#id57">prebind</a><a class="headerlink" href="#prebind" title="Permalink to this headline">¶</a></h3>
  940. <p>Default: <tt class="docutils literal"><span class="pre">false</span></tt></p>
  941. <p>Use this option when you want to attach to an existing XMPP connection that was
  942. already authenticated (usually on the backend before page load).</p>
  943. <p>This is useful when you don&#8217;t want to render the login form on the chat control
  944. box with each page load.</p>
  945. <p>For prebinding to work, your backend server must authenticate for you, and
  946. then return a JID (jabber ID), SID (session ID) and RID (Request ID).</p>
  947. <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
  948. 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>
  949. <p>Additionally, you have to specify <tt class="docutils literal"><span class="pre">bosh_service_url</span></tt>.</p>
  950. </div>
  951. <div class="section" id="roster-groups">
  952. <h3><a class="toc-backref" href="#id58">roster_groups</a><a class="headerlink" href="#roster-groups" title="Permalink to this headline">¶</a></h3>
  953. <p>Default: <tt class="docutils literal"><span class="pre">false</span></tt></p>
  954. <p>If set to <tt class="docutils literal"><span class="pre">true</span></tt>, converse.js will show any roster groups you might have
  955. configured.</p>
  956. <div class="admonition note">
  957. <p class="first admonition-title">Note</p>
  958. <p class="last">It&#8217;s currently not possible to use converse.js to assign contacts to groups.
  959. Converse.js can only show users and groups that were previously configured
  960. elsewhere.</p>
  961. </div>
  962. </div>
  963. <div class="section" id="show-controlbox-by-default">
  964. <h3><a class="toc-backref" href="#id59">show_controlbox_by_default</a><a class="headerlink" href="#show-controlbox-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>The &#8220;controlbox&#8221; refers to the special chatbox containing your contacts roster,
  967. status widget, chatrooms and other controls.</p>
  968. <p>By default this box is hidden and can be toggled by clicking on any element in
  969. the page with class <em>toggle-controlbox</em>.</p>
  970. <p>If this options is set to true, the controlbox will by default be shown upon
  971. page load.</p>
  972. </div>
  973. <div class="section" id="show-only-online-users">
  974. <h3><a class="toc-backref" href="#id60">show_only_online_users</a><a class="headerlink" href="#show-only-online-users" title="Permalink to this headline">¶</a></h3>
  975. <p>Default: <tt class="docutils literal"><span class="pre">false</span></tt></p>
  976. <p>If set to <tt class="docutils literal"><span class="pre">true</span></tt>, only online users will be shown in the contacts roster.
  977. Users with any other status (e.g. away, busy etc.) will not be shown.</p>
  978. </div>
  979. <div class="section" id="storage">
  980. <h3><a class="toc-backref" href="#id61">storage</a><a class="headerlink" href="#storage" title="Permalink to this headline">¶</a></h3>
  981. <p>Default: <tt class="docutils literal"><span class="pre">session</span></tt></p>
  982. <p>Valid options: <tt class="docutils literal"><span class="pre">session</span></tt>, <tt class="docutils literal"><span class="pre">local</span></tt>.</p>
  983. <p>This option determines the type of <a class="reference external" href="https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage">storage</a>
  984. (<tt class="docutils literal"><span class="pre">localStorage</span></tt> or <tt class="docutils literal"><span class="pre">sessionStorage</span></tt>) used by converse.js to cache user data.</p>
  985. <p>Originally converse.js used only localStorage, however sessionStorage is from a
  986. privacy perspective a better choice.</p>
  987. <p>The main difference between the two is that sessionStorage only persists while
  988. the current tab or window containing a converse.js instance is open. As soon as
  989. it&#8217;s closed, the data is cleared.</p>
  990. <p>Data in localStorage on the other hand is kept indefinitely.</p>
  991. </div>
  992. <div class="section" id="use-otr-by-default">
  993. <h3><a class="toc-backref" href="#id62">use_otr_by_default</a><a class="headerlink" href="#use-otr-by-default" title="Permalink to this headline">¶</a></h3>
  994. <p>Default: <tt class="docutils literal"><span class="pre">false</span></tt></p>
  995. <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)
  996. encrypted chat session every time you open a chat box.</p>
  997. </div>
  998. <div class="section" id="use-vcards">
  999. <h3><a class="toc-backref" href="#id63">use_vcards</a><a class="headerlink" href="#use-vcards" title="Permalink to this headline">¶</a></h3>
  1000. <p>Default: <tt class="docutils literal"><span class="pre">true</span></tt></p>
  1001. <p>Determines whether the XMPP server will be queried for roster contacts&#8217; VCards
  1002. or not. VCards contain extra personal information such as your fullname and
  1003. avatar image.</p>
  1004. </div>
  1005. <div class="section" id="visible-toolbar-buttons">
  1006. <h3><a class="toc-backref" href="#id64">visible_toolbar_buttons</a><a class="headerlink" href="#visible-toolbar-buttons" title="Permalink to this headline">¶</a></h3>
  1007. <p>Default:</p>
  1008. <div class="highlight-python"><div class="highlight"><pre><span class="p">{</span>
  1009. <span class="s">&#39;emoticons&#39;</span><span class="p">:</span> <span class="n">true</span><span class="p">,</span>
  1010. <span class="s">&#39;call&#39;</span><span class="p">:</span> <span class="n">false</span><span class="p">,</span>
  1011. <span class="s">&#39;clear&#39;</span><span class="p">:</span> <span class="n">true</span>
  1012. <span class="p">}</span>
  1013. </pre></div>
  1014. </div>
  1015. <p>Allows you to show or hide buttons on the chat boxes&#8217; toolbars.</p>
  1016. <ul>
  1017. <li><dl class="first docutils">
  1018. <dt><em>emoticons</em>:</dt>
  1019. <dd><p class="first last">Enables rendering of emoticons and provides a toolbar button for choosing them.</p>
  1020. </dd>
  1021. </dl>
  1022. </li>
  1023. <li><dl class="first docutils">
  1024. <dt><em>call</em>:</dt>
  1025. <dd><p class="first">Provides a button with a picture of a telephone on it.
  1026. 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>
  1027. <div class="last highlight-python"><div class="highlight"><pre>converse.on(&#39;callButtonClicked&#39;, function(event, data) {
  1028. console.log(&#39;Strophe connection is&#39;, data.connection);
  1029. console.log(&#39;Bare buddy JID is&#39;, data.model.get(&#39;jid&#39;));
  1030. // ... Third-party library code ...
  1031. });
  1032. </pre></div>
  1033. </div>
  1034. </dd>
  1035. </dl>
  1036. </li>
  1037. <li><dl class="first docutils">
  1038. <dt><em>clear</em>:</dt>
  1039. <dd><p class="first last">Provides a button for clearing messages from a chat box.</p>
  1040. </dd>
  1041. </dl>
  1042. </li>
  1043. </ul>
  1044. </div>
  1045. <div class="section" id="xhr-custom-status">
  1046. <h3><a class="toc-backref" href="#id65">xhr_custom_status</a><a class="headerlink" href="#xhr-custom-status" title="Permalink to this headline">¶</a></h3>
  1047. <p>Default: <tt class="docutils literal"><span class="pre">false</span></tt></p>
  1048. <div class="admonition note">
  1049. <p class="first admonition-title">Note</p>
  1050. <p class="last">XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).</p>
  1051. </div>
  1052. <p>This option will let converse.js make an AJAX POST with your changed custom chat status to a
  1053. remote server.</p>
  1054. </div>
  1055. <div class="section" id="xhr-custom-status-url">
  1056. <h3><a class="toc-backref" href="#id66">xhr_custom_status_url</a><a class="headerlink" href="#xhr-custom-status-url" title="Permalink to this headline">¶</a></h3>
  1057. <div class="admonition note">
  1058. <p class="first admonition-title">Note</p>
  1059. <p class="last">XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).</p>
  1060. </div>
  1061. <p>Default: Empty string</p>
  1062. <p>Used only in conjunction with <tt class="docutils literal"><span class="pre">xhr_custom_status</span></tt>.</p>
  1063. <p>This is the URL to which the AJAX POST request to set the user&#8217;s custom status
  1064. message will be made.</p>
  1065. <p>The message itself is sent in the request under the key <tt class="docutils literal"><span class="pre">msg</span></tt>.</p>
  1066. </div>
  1067. <div class="section" id="xhr-user-search">
  1068. <h3><a class="toc-backref" href="#id67">xhr_user_search</a><a class="headerlink" href="#xhr-user-search" title="Permalink to this headline">¶</a></h3>
  1069. <p>Default: <tt class="docutils literal"><span class="pre">false</span></tt></p>
  1070. <div class="admonition note">
  1071. <p class="first admonition-title">Note</p>
  1072. <p class="last">XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).</p>
  1073. </div>
  1074. <p>There are two ways to add users.</p>
  1075. <ul class="simple">
  1076. <li>The user inputs a valid JID (Jabber ID), and the user is added as a pending contact.</li>
  1077. <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>
  1078. </ul>
  1079. <p>This setting enables the second mechanism, otherwise by default the first will be used.</p>
  1080. <p><em>What is expected from the remote server?</em></p>
  1081. <p>A default JSON encoded list of objects must be returned. Each object
  1082. 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>
  1083. </div>
  1084. <div class="section" id="xhr-user-search-url">
  1085. <h3><a class="toc-backref" href="#id68">xhr_user_search_url</a><a class="headerlink" href="#xhr-user-search-url" title="Permalink to this headline">¶</a></h3>
  1086. <div class="admonition note">
  1087. <p class="first admonition-title">Note</p>
  1088. <p class="last">XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).</p>
  1089. </div>
  1090. <p>Default: Empty string</p>
  1091. <p>Used only in conjunction with <tt class="docutils literal"><span class="pre">xhr_user_search</span></tt>.</p>
  1092. <p>This is the URL to which an AJAX GET request will be made to fetch user data from your remote server.
  1093. The query string will be included in the request with <tt class="docutils literal"><span class="pre">q</span></tt> as its key.</p>
  1094. <p>The calendar can be configured through a <cite>data-pat-calendar</cite> attribute.
  1095. The available options are:</p>
  1096. </div>
  1097. </div>
  1098. </div>
  1099. </div>
  1100. </div>
  1101. <div class="clearer"></div>
  1102. </div>
  1103. </section>
  1104. <div class="related">
  1105. <h3>Navigation</h3>
  1106. <ul>
  1107. <li class="right" style="margin-right: 10px">
  1108. <a href="genindex.html" title="General Index"
  1109. >index</a></li>
  1110. <li><a href="#">Converse.js 0.8.0 documentation</a> &raquo;</li>
  1111. </ul>
  1112. </div>
  1113. </div>
  1114. <div id="footer_wrap" class="outer">
  1115. <footer class="inner">
  1116. &copy; Copyright 2014, JC Brand.
  1117. <p class="copyright">Converse.js created by <a href="http://opkode.com" target="_blank">jcbrand</a></p>
  1118. </footer>
  1119. </div>
  1120. </body>
  1121. </html>