index.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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-i-e-single-site-login" id="id7">Session support (i.e. single site login)</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 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 integrated 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. 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 either set up your own XMPP server, or use a public one. You can find a
  117. list of public XMPP servers/providers on <a class="reference external" href="http://xmpp.net">xmpp.net</a> and a list of servers that
  118. you can set up yourself on <a class="reference external" href="http://xmpp.org/xmpp-software/servers/">xmpp.org</a>.</p>
  119. </div>
  120. <div class="section" id="connection-manager">
  121. <h2><a class="toc-backref" href="#id4">Connection Manager</a><a class="headerlink" href="#connection-manager" title="Permalink to this headline">¶</a></h2>
  122. <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
  123. the webserver. HTTP connections are stateless and usually shortlived.</p>
  124. <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
  125. its connections are stateful and usually longer.</p>
  126. <p>To enable a web application like <em>Converse.js</em> to communicate with an XMPP
  127. server, we need a proxy in the middle that can act as a bridge between the two
  128. protocols.</p>
  129. <p>This is the job of a connection manager. A connection manager can be either a
  130. standalone application or part of an XMPP server. <a class="reference external" href="http://www.ejabberd.im">ejabberd</a> for example,
  131. includes a connection manager (but you have to enable it).</p>
  132. <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>.
  133. This connection manager is for testing purposes only, please don&#8217;t use it in
  134. production.</p>
  135. <div class="section" id="overcoming-cross-domain-request-restrictions">
  136. <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>
  137. <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>.
  138. HTTP requests are made by <em>Converse.js</em> to the connection manager via XmlHttpRequests (XHR).
  139. Until recently, it was not possible to make such requests to a different domain
  140. than the one currently being served (to prevent XSS attacks).</p>
  141. <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.
  142. Modern browsers support CORS, but there are problems with Internet Explorer &lt;
  143. 10.</p>
  144. <p>IE 8 and 9 partially support CORS via a proprietary implementation called
  145. 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
  146. support for XDomainRequest when it is present.</p>
  147. <p>In IE &lt; 8, there is no support for CORS.</p>
  148. <p>If you need to support these browsers, you can add a front-end proxy in
  149. Apache/Nginx which serves the connection manager under the same domain as your
  150. website. This will remove the need for any cross-domain XHR support.</p>
  151. </div>
  152. </div>
  153. <div class="section" id="server-side-authentication">
  154. <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>
  155. <div class="section" id="session-support-i-e-single-site-login">
  156. <h3><a class="toc-backref" href="#id7">Session support (i.e. single site login)</a><a class="headerlink" href="#session-support-i-e-single-site-login" title="Permalink to this headline">¶</a></h3>
  157. <p>It&#8217;s possible to enable single-site login, whereby users already
  158. authenticated in your website will also automatically be logged in on the chat server,
  159. but this will require custom code on your server.</p>
  160. <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>
  161. </div>
  162. </div>
  163. </div>
  164. <div class="section" id="quickstart-to-get-a-demo-up-and-running">
  165. <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>
  166. <p>When you download a specific release of <em>Converse.js</em>, say for example version 0.3,
  167. there will be two minified files inside the zip file.</p>
  168. <p>For version 0.3 they will be:</p>
  169. <ul class="simple">
  170. <li>converse.0.3.min.js</li>
  171. <li>converse.0.3.min.css</li>
  172. </ul>
  173. <p>You can include these two files in your website via the <em>script</em> and <em>link</em>
  174. tags:</p>
  175. <div class="highlight-python"><pre>&lt;link rel="stylesheet" type="text/css" media="screen" href="converse.0.3.min.css"&gt;
  176. &lt;script src="converse.0.3.min.js"&gt;&lt;/script&gt;</pre>
  177. </div>
  178. <p>The <em>index.html</em> file inside the Converse.js folder serves as a nice usable
  179. example of this.</p>
  180. <p>These minified files provide the same demo-like functionality as is available
  181. on the <a class="reference external" href="http://conversejs.org">conversejs.org</a> website. Useful for testing or demoing, but not very
  182. practical.</p>
  183. <p>You&#8217;ll most likely want to implement some kind of single-signon solution for
  184. your website, where users authenticate once in your website and then stay
  185. logged into their XMPP session upon page reload.</p>
  186. <p>For more info on this, read <a class="reference internal" href="#session-support-i-e-single-site-login">Session support (i.e. single site login)</a>.</p>
  187. <p>You might also want to have more fine-grained control of what gets included in
  188. 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
  189. that.</p>
  190. </div>
  191. <div class="section" id="configuration">
  192. <h1><a class="toc-backref" href="#id9">Configuration</a><a class="headerlink" href="#configuration" title="Permalink to this headline">¶</a></h1>
  193. <p>The included minified JS and CSS files can be used for demoing or testing, but
  194. you&#8217;ll want to configure <em>Converse.js</em> to suit your needs before you deploy it
  195. on your website.</p>
  196. <p><em>Converse.js</em> is passed its configuration settings when you call its
  197. <em>initialize</em> method.</p>
  198. <p>Please refer to the <a class="reference internal" href="#configuration-variables">Configuration variables</a> section below for info on
  199. all the available configuration settings.</p>
  200. <p>After you have configured <em>Converse.js</em>, you&#8217;ll have to regenerate the minified
  201. JS file so that it will include the new settings. Please refer to the
  202. <a class="reference internal" href="#minification">Minification</a> section for more info on how to do this.</p>
  203. <div class="section" id="configuration-variables">
  204. <h2><a class="toc-backref" href="#id10">Configuration variables</a><a class="headerlink" href="#configuration-variables" title="Permalink to this headline">¶</a></h2>
  205. <div class="section" id="animate">
  206. <h3><a class="toc-backref" href="#id11">animate</a><a class="headerlink" href="#animate" title="Permalink to this headline">¶</a></h3>
  207. <p>Default = True</p>
  208. <p>Show animations, for example when opening and closing chat boxes.</p>
  209. </div>
  210. <div class="section" id="auto-list-rooms">
  211. <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>
  212. <p>Default = False</p>
  213. <p>If true, and the XMPP server on which the current user is logged in supports
  214. multi-user chat, then a list of rooms on that server will be fetched.</p>
  215. <p>Not recommended for servers with lots of chat rooms.</p>
  216. <p>For each room on the server a query is made to fetch further details (e.g.
  217. features, number of occupants etc.), so on servers with many rooms this
  218. option will create lots of extra connection traffic.</p>
  219. </div>
  220. <div class="section" id="auto-subscribe">
  221. <h3><a class="toc-backref" href="#id13">auto_subscribe</a><a class="headerlink" href="#auto-subscribe" title="Permalink to this headline">¶</a></h3>
  222. <p>Default = False</p>
  223. <p>If true, the user will automatically subscribe back to any contact requests.</p>
  224. </div>
  225. <div class="section" id="bosh-service-url">
  226. <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>
  227. <p>Connections to an XMPP server depend on a BOSH connection manager which acts as
  228. a middle man between HTTP and XMPP.</p>
  229. <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>
  230. </div>
  231. <div class="section" id="fullname">
  232. <h3><a class="toc-backref" href="#id15">fullname</a><a class="headerlink" href="#fullname" title="Permalink to this headline">¶</a></h3>
  233. <p>If you are using prebinding, you need to specify the fullname of the currently
  234. logged in user.</p>
  235. </div>
  236. <div class="section" id="hide-muc-server">
  237. <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>
  238. <p>Default = False</p>
  239. <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
  240. controlbox. Useful if you want to restrict users to a specific XMPP server of
  241. your choosing.</p>
  242. </div>
  243. <div class="section" id="prebind">
  244. <h3><a class="toc-backref" href="#id17">prebind</a><a class="headerlink" href="#prebind" title="Permalink to this headline">¶</a></h3>
  245. <p>Default = False</p>
  246. <p>Use this option when you want to attach to an existing XMPP connection that was
  247. already authenticated (usually on the backend before page load).</p>
  248. <p>This is useful when you don&#8217;t want to render the login form on the chat control
  249. box with each page load.</p>
  250. <p>When set to true, you&#8217;ll need to make sure that the onConnected method is
  251. called, and passed to it a Strophe connection object.</p>
  252. <p>Besides requiring the back-end to authenticate you, you&#8217;ll also
  253. have to write a Javascript snippet to attach to the set up connection:</p>
  254. <div class="highlight-python"><pre>$.JSON({
  255. 'url': 'mysite.com/xmpp-authenticate',
  256. 'success': function (data) {
  257. connection = new Strophe.Connection(bosh_service_url);
  258. connection.attach(data.jid, data.sid, data.rid, converse.onConnected);
  259. }</pre>
  260. </div>
  261. <p>The backend must authenticate for you, and then return a SID (session ID) and
  262. RID (Request ID), which you use when you attach to the connection.</p>
  263. </div>
  264. <div class="section" id="xhr-user-search">
  265. <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>
  266. <p>Default = False</p>
  267. <p>There are two ways to add users.</p>
  268. <ul class="simple">
  269. <li>The user inputs a valid JID (Jabber ID), and the user is added as a pending contact.</li>
  270. <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>
  271. </ul>
  272. <p>This setting enables the second mechanism, otherwise by default the first will
  273. be used.</p>
  274. </div>
  275. </div>
  276. </div>
  277. <div class="section" id="minification">
  278. <h1><a class="toc-backref" href="#id19">Minification</a><a class="headerlink" href="#minification" title="Permalink to this headline">¶</a></h1>
  279. <div class="section" id="minifying-javascript">
  280. <h2><a class="toc-backref" href="#id20">Minifying Javascript</a><a class="headerlink" href="#minifying-javascript" title="Permalink to this headline">¶</a></h2>
  281. <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
  282. to bundle them together in a single minified file fit for deployment to a
  283. production site.</p>
  284. <p>To use the require.js&#8217;s optimization tool, you&#8217;ll need Node and it&#8217;s package
  285. manager, NPM.</p>
  286. <p>You can then install install require.js for Node like so:</p>
  287. <div class="highlight-python"><pre>npm install requirejs</pre>
  288. </div>
  289. <p>The minified javascript file is then created like this:</p>
  290. <div class="highlight-python"><pre>r.js -o build.js</pre>
  291. </div>
  292. <p>You should now have a new minified file (the name which is specified in build.js).</p>
  293. <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>
  294. </div>
  295. <div class="section" id="minifying-css">
  296. <h2><a class="toc-backref" href="#id21">Minifying CSS</a><a class="headerlink" href="#minifying-css" title="Permalink to this headline">¶</a></h2>
  297. <p>CSS can be minimized with Yahoo&#8217;s yuicompressor tool:</p>
  298. <div class="highlight-python"><pre>yui-compressor --type=css converse.css -o converse.min.css</pre>
  299. </div>
  300. </div>
  301. </div>
  302. </div>
  303. </div>
  304. <div class="clearer"></div>
  305. </div>
  306. </section>
  307. <div class="related">
  308. <h3>Navigation</h3>
  309. <ul>
  310. <li class="right" style="margin-right: 10px">
  311. <a href="genindex.html" title="General Index"
  312. >index</a></li>
  313. <li><a href="#">Converse.js 0.3 documentation</a> &raquo;</li>
  314. </ul>
  315. </div>
  316. </div>
  317. <div id="footer_wrap" class="outer">
  318. <footer class="inner">
  319. &copy; Copyright 2013, JC Brand.
  320. <p class="copyright">Converse.js created by <a href="http://opkode.com" target="_blank">jcbrand</a></p>
  321. </footer>
  322. </div>
  323. </body>
  324. </html>