index.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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>Introduction &mdash; Converse.js 0.3 documentation</title>
  7. <link rel="stylesheet" href="_static/stylesheet.css" type="text/css" />
  8. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: '',
  12. VERSION: '0.3',
  13. COLLAPSE_INDEX: false,
  14. FILE_SUFFIX: '.html',
  15. HAS_SOURCE: true
  16. };
  17. </script>
  18. <script type="text/javascript" src="_static/jquery.js"></script>
  19. <script type="text/javascript" src="_static/underscore.js"></script>
  20. <script type="text/javascript" src="_static/doctools.js"></script>
  21. <link rel="top" title="Converse.js 0.3 documentation" href="#" />
  22. </head>
  23. <body>
  24. <div id="header_wrap" class="outer">
  25. <header class="inner">
  26. <a id="forkme_banner" href="https://github.com/jcbrand/converse.js">View on GitHub</a>
  27. <h1 id="project_title"><a href="http://conversejs.org">Converse.js</a></h1>
  28. <h2 id="project_tagline">Documentation</h2>
  29. <section id="downloads">
  30. <a class="zip_download_link" href="https://github.com/jcbrand/converse.js/zipball/master">Download this project as a .zip file</a>
  31. <a class="tar_download_link" href="https://github.com/jcbrand/converse.js/tarball/master">Download this project as a tar.gz file</a>
  32. </section>
  33. </header>
  34. </div>
  35. <div id="main_content_wrap" class="outer">
  36. <div class="related">
  37. <h3>Navigation</h3>
  38. <ul>
  39. <li class="right" style="margin-right: 10px">
  40. <a href="genindex.html" title="General Index"
  41. accesskey="I">index</a></li>
  42. <li><a href="#">Converse.js 0.3 documentation</a> &raquo;</li>
  43. </ul>
  44. </div>
  45. <section id="main_content" class="inner">
  46. <div class="document">
  47. <div class="documentwrapper">
  48. <div class="body">
  49. <div class="toctree-wrapper compound">
  50. <ul class="simple">
  51. </ul>
  52. </div>
  53. <div class="contents local topic" id="table-of-contents">
  54. <p class="topic-title first">Table of Contents</p>
  55. <ul class="simple">
  56. <li><a class="reference internal" href="#introduction" id="id1">Introduction</a></li>
  57. <li><a class="reference internal" href="#what-you-will-need" id="id2">What you will need</a><ul>
  58. <li><a class="reference internal" href="#an-xmpp-jabber-server" id="id3">An XMPP/Jabber server</a></li>
  59. <li><a class="reference internal" href="#connection-manager" id="id4">Connection Manager</a><ul>
  60. <li><a class="reference internal" href="#overcoming-cross-domain-request-restrictions" id="id5">Overcoming cross-domain request restrictions</a></li>
  61. </ul>
  62. </li>
  63. <li><a class="reference internal" href="#server-side-authentication" id="id6">Server-side authentication</a><ul>
  64. <li><a class="reference internal" href="#session-support" id="id7">Session support</a></li>
  65. </ul>
  66. </li>
  67. </ul>
  68. </li>
  69. <li><a class="reference internal" href="#quickstart-to-get-a-demo-up-and-running" id="id8">Quickstart (to get a demo up and running)</a></li>
  70. <li><a class="reference internal" href="#configuration" id="id9">Configuration</a><ul>
  71. <li><a class="reference internal" href="#configuration-variables" id="id10">Configuration variables</a><ul>
  72. <li><a class="reference internal" href="#animate" id="id11">animate</a></li>
  73. <li><a class="reference internal" href="#auto-list-rooms" id="id12">auto_list_rooms</a></li>
  74. <li><a class="reference internal" href="#auto-subscribe" id="id13">auto_subscribe</a></li>
  75. <li><a class="reference internal" href="#bosh-service-url" id="id14">bosh_service_url</a></li>
  76. <li><a class="reference internal" href="#fullname" id="id15">fullname</a></li>
  77. <li><a class="reference internal" href="#hide-muc-server" id="id16">hide_muc_server</a></li>
  78. <li><a class="reference internal" href="#prebind" id="id17">prebind</a></li>
  79. <li><a class="reference internal" href="#xhr-user-search" id="id18">xhr_user_search</a></li>
  80. </ul>
  81. </li>
  82. </ul>
  83. </li>
  84. <li><a class="reference internal" href="#minification" id="id19">Minification</a><ul>
  85. <li><a class="reference internal" href="#minifying-javascript" id="id20">Minifying Javascript</a></li>
  86. <li><a class="reference internal" href="#minifying-css" id="id21">Minifying CSS</a></li>
  87. </ul>
  88. </li>
  89. </ul>
  90. </div>
  91. <div class="section" id="introduction">
  92. <h1><a class="toc-backref" href="#id1">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h1>
  93. <p>Even though you can connect to public XMPP servers on the <a class="reference external" href="http://conversejs.org">conversejs.org</a>
  94. website, <em>Converse.js</em> is not really meant to be a &#8220;Software-as-a-service&#8221; (SaaS)
  95. webchat.</p>
  96. <p>Instead, its goal is to provide the means for website owners to add a tightly
  97. integrated instant messaging service to their own sites.</p>
  98. <p>As a website owner, you are expected to host <em>Converse.js</em> yourself, and to do some legwork to
  99. properly configure and integrate it into your site.</p>
  100. <p>The benefit in doing this, is that your users have a much more streamlined and integrated
  101. webchat experience and that you have control over the data. The latter being a
  102. requirement for many sites dealing with sensitive information.</p>
  103. <p>You&#8217;ll need to set up your own XMPP server and in order to have
  104. <a class="reference internal" href="#session-support">Session support</a> (i.e. single-signon functionality whereby users are authenticated once and stay
  105. logged in to XMPP upon page reload) you will also have to add some server-side
  106. code.</p>
  107. <p>The <a class="reference internal" href="#what-you-will-need">What you will need</a> section has more information on all these
  108. requirements.</p>
  109. </div>
  110. <div class="section" id="what-you-will-need">
  111. <h1><a class="toc-backref" href="#id2">What you will need</a><a class="headerlink" href="#what-you-will-need" title="Permalink to this headline">¶</a></h1>
  112. <div class="section" id="an-xmpp-jabber-server">
  113. <h2><a class="toc-backref" href="#id3">An XMPP/Jabber server</a><a class="headerlink" href="#an-xmpp-jabber-server" title="Permalink to this headline">¶</a></h2>
  114. <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
  115. to connect to an XMPP/Jabber server (Jabber is really just a synonym for XMPP).</p>
  116. <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
  117. have <a class="reference internal" href="#session-support">Session support</a> you&#8217;ll have to set up your own XMPP server.</p>
  118. <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
  119. servers that you can set up yourself on <a class="reference external" href="http://xmpp.org/xmpp-software/servers/">xmpp.org</a>.</p>
  120. </div>
  121. <div class="section" id="connection-manager">
  122. <h2><a class="toc-backref" href="#id4">Connection Manager</a><a class="headerlink" href="#connection-manager" title="Permalink to this headline">¶</a></h2>
  123. <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
  124. the webserver. HTTP connections are stateless and usually shortlived.</p>
  125. <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
  126. its connections are stateful and usually longer.</p>
  127. <p>To enable a web application like <em>Converse.js</em> to communicate with an XMPP
  128. server, we need a proxy in the middle that can act as a bridge between the two
  129. protocols.</p>
  130. <p>This is the job of a connection manager. A connection manager can be either a
  131. standalone application or part of an XMPP server. <a class="reference external" href="http://www.ejabberd.im">ejabberd</a> for example,
  132. includes a connection manager (but you have to enable it).</p>
  133. <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>.
  134. This connection manager is for testing purposes only, please don&#8217;t use it in
  135. production.</p>
  136. <div class="section" id="overcoming-cross-domain-request-restrictions">
  137. <h3><a class="toc-backref" href="#id5">Overcoming cross-domain request restrictions</a><a class="headerlink" href="#overcoming-cross-domain-request-restrictions" title="Permalink to this headline">¶</a></h3>
  138. <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>.
  139. HTTP requests are made by <em>Converse.js</em> to the connection manager via XmlHttpRequests (XHR).
  140. Until recently, it was not possible to make such requests to a different domain
  141. than the one currently being served (to prevent XSS attacks).</p>
  142. <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.
  143. Modern browsers support CORS, but there are problems with Internet Explorer &lt;
  144. 10.</p>
  145. <p>IE 8 and 9 partially support CORS via a proprietary implementation called
  146. 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
  147. support for XDomainRequest when it is present.</p>
  148. <p>In IE &lt; 8, there is no support for CORS.</p>
  149. <p>If you need to support these browsers, you can add a front-end proxy in
  150. Apache/Nginx which serves the connection manager under the same domain as your
  151. website. This will remove the need for any cross-domain XHR support.</p>
  152. </div>
  153. </div>
  154. <div class="section" id="server-side-authentication">
  155. <h2><a class="toc-backref" href="#id6">Server-side authentication</a><a class="headerlink" href="#server-side-authentication" title="Permalink to this headline">¶</a></h2>
  156. <div class="section" id="session-support">
  157. <h3><a class="toc-backref" href="#id7">Session support</a><a class="headerlink" href="#session-support" title="Permalink to this headline">¶</a></h3>
  158. <p>It&#8217;s possible to enable single-site login, whereby users already
  159. authenticated in your website will also automatically be logged in on the chat server,
  160. but this will require custom code on your server.</p>
  161. <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>
  162. </div>
  163. </div>
  164. </div>
  165. <div class="section" id="quickstart-to-get-a-demo-up-and-running">
  166. <h1><a class="toc-backref" href="#id8">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>
  167. <p>When you download a specific release of <em>Converse.js</em>, say for example version 0.3,
  168. there will be two minified files inside the zip file.</p>
  169. <p>For version 0.3 they will be:</p>
  170. <ul class="simple">
  171. <li>converse.0.3.min.js</li>
  172. <li>converse.0.3.min.css</li>
  173. </ul>
  174. <p>You can include these two files in your website via the <em>script</em> and <em>link</em>
  175. tags:</p>
  176. <div class="highlight-python"><pre>&lt;link rel="stylesheet" type="text/css" media="screen" href="converse.0.3.min.css"&gt;
  177. &lt;script src="converse.0.3.min.js"&gt;&lt;/script&gt;</pre>
  178. </div>
  179. <p>The <em>index.html</em> file inside the Converse.js folder serves as a nice usable
  180. example of this.</p>
  181. <p>These minified files provide the same demo-like functionality as is available
  182. on the <a class="reference external" href="http://conversejs.org">conversejs.org</a> website. Useful for testing or demoing, but not very
  183. practical.</p>
  184. <p>You&#8217;ll most likely want to implement some kind of single-signon solution for
  185. your website, where users authenticate once in your website and then stay
  186. logged into their XMPP session upon page reload.</p>
  187. <p>For more info on this, read <a class="reference internal" href="#session-support">Session support</a>.</p>
  188. <p>You might also want to have more fine-grained control of what gets included in
  189. 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
  190. that.</p>
  191. </div>
  192. <div class="section" id="configuration">
  193. <h1><a class="toc-backref" href="#id9">Configuration</a><a class="headerlink" href="#configuration" title="Permalink to this headline">¶</a></h1>
  194. <p>The included minified JS and CSS files can be used for demoing or testing, but
  195. you&#8217;ll want to configure <em>Converse.js</em> to suit your needs before you deploy it
  196. on your website.</p>
  197. <p><em>Converse.js</em> is passed its configuration settings when you call its
  198. <em>initialize</em> method.</p>
  199. <p>Please refer to the <a class="reference internal" href="#configuration-variables">Configuration variables</a> section below for info on
  200. all the available configuration settings.</p>
  201. <p>After you have configured <em>Converse.js</em>, you&#8217;ll have to regenerate the minified
  202. JS file so that it will include the new settings. Please refer to the
  203. <a class="reference internal" href="#minification">Minification</a> section for more info on how to do this.</p>
  204. <div class="section" id="configuration-variables">
  205. <h2><a class="toc-backref" href="#id10">Configuration variables</a><a class="headerlink" href="#configuration-variables" title="Permalink to this headline">¶</a></h2>
  206. <div class="section" id="animate">
  207. <h3><a class="toc-backref" href="#id11">animate</a><a class="headerlink" href="#animate" title="Permalink to this headline">¶</a></h3>
  208. <p>Default = True</p>
  209. <p>Show animations, for example when opening and closing chat boxes.</p>
  210. </div>
  211. <div class="section" id="auto-list-rooms">
  212. <h3><a class="toc-backref" href="#id12">auto_list_rooms</a><a class="headerlink" href="#auto-list-rooms" title="Permalink to this headline">¶</a></h3>
  213. <p>Default = False</p>
  214. <p>If true, and the XMPP server on which the current user is logged in supports
  215. multi-user chat, then a list of rooms on that server will be fetched.</p>
  216. <p>Not recommended for servers with lots of chat rooms.</p>
  217. <p>For each room on the server a query is made to fetch further details (e.g.
  218. features, number of occupants etc.), so on servers with many rooms this
  219. option will create lots of extra connection traffic.</p>
  220. </div>
  221. <div class="section" id="auto-subscribe">
  222. <h3><a class="toc-backref" href="#id13">auto_subscribe</a><a class="headerlink" href="#auto-subscribe" title="Permalink to this headline">¶</a></h3>
  223. <p>Default = False</p>
  224. <p>If true, the user will automatically subscribe back to any contact requests.</p>
  225. </div>
  226. <div class="section" id="bosh-service-url">
  227. <h3><a class="toc-backref" href="#id14">bosh_service_url</a><a class="headerlink" href="#bosh-service-url" title="Permalink to this headline">¶</a></h3>
  228. <p>Connections to an XMPP server depend on a BOSH connection manager which acts as
  229. a middle man between HTTP and XMPP.</p>
  230. <p>See <a class="reference external" href="http://metajack.im/2008/09/08/which-bosh-server-do-you-need/l">here</a> for more information.</p>
  231. </div>
  232. <div class="section" id="fullname">
  233. <h3><a class="toc-backref" href="#id15">fullname</a><a class="headerlink" href="#fullname" title="Permalink to this headline">¶</a></h3>
  234. <p>If you are using prebinding, you need to specify the fullname of the currently
  235. logged in user.</p>
  236. </div>
  237. <div class="section" id="hide-muc-server">
  238. <h3><a class="toc-backref" href="#id16">hide_muc_server</a><a class="headerlink" href="#hide-muc-server" title="Permalink to this headline">¶</a></h3>
  239. <p>Default = False</p>
  240. <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
  241. controlbox. Useful if you want to restrict users to a specific XMPP server of
  242. your choosing.</p>
  243. </div>
  244. <div class="section" id="prebind">
  245. <h3><a class="toc-backref" href="#id17">prebind</a><a class="headerlink" href="#prebind" title="Permalink to this headline">¶</a></h3>
  246. <p>Default = False</p>
  247. <p>Use this option when you want to attach to an existing XMPP connection that was
  248. already authenticated (usually on the backend before page load).</p>
  249. <p>This is useful when you don&#8217;t want to render the login form on the chat control
  250. box with each page load.</p>
  251. <p>When set to true, you&#8217;ll need to make sure that the onConnected method is
  252. called, and passed to it a Strophe connection object.</p>
  253. <p>Besides requiring the back-end to authenticate you, you&#8217;ll also
  254. have to write a Javascript snippet to attach to the set up connection:</p>
  255. <div class="highlight-python"><pre>$.JSON({
  256. 'url': 'mysite.com/xmpp-authenticate',
  257. 'success': function (data) {
  258. connection = new Strophe.Connection(bosh_service_url);
  259. connection.attach(data.jid, data.sid, data.rid, converse.onConnected);
  260. }</pre>
  261. </div>
  262. <p>The backend must authenticate for you, and then return a SID (session ID) and
  263. RID (Request ID), which you use when you attach to the connection.</p>
  264. </div>
  265. <div class="section" id="xhr-user-search">
  266. <h3><a class="toc-backref" href="#id18">xhr_user_search</a><a class="headerlink" href="#xhr-user-search" title="Permalink to this headline">¶</a></h3>
  267. <p>Default = False</p>
  268. <p>There are two ways to add users.</p>
  269. <ul class="simple">
  270. <li>The user inputs a valid JID (Jabber ID), and the user is added as a pending contact.</li>
  271. <li>The user inputs some text (for example part of a firstname or lastname), an XHR will be made to a backend, and a list of matches are returned. The user can then choose one of the matches to add as a contact.</li>
  272. </ul>
  273. <p>This setting enables the second mechanism, otherwise by default the first will
  274. be used.</p>
  275. </div>
  276. </div>
  277. </div>
  278. <div class="section" id="minification">
  279. <h1><a class="toc-backref" href="#id19">Minification</a><a class="headerlink" href="#minification" title="Permalink to this headline">¶</a></h1>
  280. <div class="section" id="minifying-javascript">
  281. <h2><a class="toc-backref" href="#id20">Minifying Javascript</a><a class="headerlink" href="#minifying-javascript" title="Permalink to this headline">¶</a></h2>
  282. <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
  283. to bundle them together in a single minified file fit for deployment to a
  284. production site.</p>
  285. <p>To use the require.js&#8217;s optimization tool, you&#8217;ll need Node and it&#8217;s package
  286. manager, NPM.</p>
  287. <p>You can then install install require.js for Node like so:</p>
  288. <div class="highlight-python"><pre>npm install requirejs</pre>
  289. </div>
  290. <p>The minified javascript file is then created like this:</p>
  291. <div class="highlight-python"><pre>r.js -o build.js</pre>
  292. </div>
  293. <p>You should now have a new minified file (the name which is specified in build.js).</p>
  294. <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>
  295. </div>
  296. <div class="section" id="minifying-css">
  297. <h2><a class="toc-backref" href="#id21">Minifying CSS</a><a class="headerlink" href="#minifying-css" title="Permalink to this headline">¶</a></h2>
  298. <p>CSS can be minimized with Yahoo&#8217;s yuicompressor tool:</p>
  299. <div class="highlight-python"><pre>yui-compressor --type=css converse.css -o converse.min.css</pre>
  300. </div>
  301. </div>
  302. </div>
  303. </div>
  304. </div>
  305. <div class="clearer"></div>
  306. </div>
  307. </section>
  308. <div class="related">
  309. <h3>Navigation</h3>
  310. <ul>
  311. <li class="right" style="margin-right: 10px">
  312. <a href="genindex.html" title="General Index"
  313. >index</a></li>
  314. <li><a href="#">Converse.js 0.3 documentation</a> &raquo;</li>
  315. </ul>
  316. </div>
  317. </div>
  318. <div id="footer_wrap" class="outer">
  319. <footer class="inner">
  320. &copy; Copyright 2013, JC Brand.
  321. <p class="copyright">Converse.js created by <a href="http://opkode.com" target="_blank">jcbrand</a></p>
  322. </footer>
  323. </div>
  324. </body>
  325. </html>