index.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. .. Converse.js documentation master file, created by
  2. sphinx-quickstart on Fri Apr 26 20:48:03 2013.
  3. You can adapt this file completely to your liking, but it should at least
  4. contain the root `toctree` directive.
  5. .. toctree::
  6. :maxdepth: 2
  7. .. contents:: Table of Contents
  8. :depth: 3
  9. :local:
  10. ============
  11. Introduction
  12. ============
  13. Even though you can connect to public XMPP servers on the `conversejs.org`_
  14. website, *Converse.js* is not really meant to be a "Software-as-a-service" (SaaS)
  15. webchat.
  16. Instead, its goal is to provide the means for website owners to add a tightly
  17. integrated instant messaging service to their own sites.
  18. As a website owner, you are expected to host *Converse.js* yourself, and to do some legwork to
  19. properly configure and integrate it into your site.
  20. The benefit in doing this, is that your users have a much more streamlined and integrated
  21. webchat experience and that you have control over the data. The latter being a
  22. requirement for many sites dealing with sensitive information.
  23. You'll need to set up your own XMPP server and in order to have
  24. `Session Support`_ (i.e. single-signon functionality whereby users are authenticated once and stay
  25. logged in to XMPP upon page reload) you will also have to add some server-side
  26. code.
  27. The `What you will need`_ section has more information on all these
  28. requirements.
  29. ==================
  30. What you will need
  31. ==================
  32. An XMPP/Jabber server
  33. =====================
  34. *Converse.js* implements `XMPP`_ as its messaging protocol, and therefore needs
  35. to connect to an XMPP/Jabber server (Jabber is really just a synonym for XMPP).
  36. You can connect to public XMPP servers like ``jabber.org`` but if you want to
  37. have `Session Support`_ you'll have to set up your own XMPP server.
  38. You can find a list of public XMPP servers/providers on `xmpp.net`_ and a list of
  39. servers that you can set up yourself on `xmpp.org`_.
  40. Connection Manager
  41. ==================
  42. Your website and *Converse.js* use `HTTP`_ as protocol to communicate with
  43. the webserver. HTTP connections are stateless and usually shortlived.
  44. `XMPP`_ on the other hand, is the protocol that enables instant messaging, and
  45. its connections are stateful and usually longer.
  46. To enable a web application like *Converse.js* to communicate with an XMPP
  47. server, we need a proxy in the middle that can act as a bridge between the two
  48. protocols.
  49. This is the job of a connection manager. A connection manager can be either a
  50. standalone application or part of an XMPP server. `ejabberd`_ for example,
  51. includes a connection manager (but you have to enable it).
  52. The demo on the `Converse.js homepage`_ uses a a connection manager located at https://bind.opkode.im.
  53. This connection manager is for testing purposes only, please don't use it in
  54. production.
  55. Overcoming cross-domain request restrictions
  56. --------------------------------------------
  57. The domain of the *Converse.js* demo is *conversejs.org*, but the domain of the connection manager is *opkode.im*.
  58. HTTP requests are made by *Converse.js* to the connection manager via XmlHttpRequests (XHR).
  59. Until recently, it was not possible to make such requests to a different domain
  60. than the one currently being served (to prevent XSS attacks).
  61. Luckily there is now a standard called `CORS`_ (Cross-origin resource sharing), which enables exactly that.
  62. Modern browsers support CORS, but there are problems with Internet Explorer <
  63. 10.
  64. IE 8 and 9 partially support CORS via a proprietary implementation called
  65. XDomainRequest. There is a `Strophe.js plugin`_ which you can use to enable
  66. support for XDomainRequest when it is present.
  67. In IE < 8, there is no support for CORS.
  68. If you need to support these browsers, you can add a front-end proxy in
  69. Apache/Nginx which serves the connection manager under the same domain as your
  70. website. This will remove the need for any cross-domain XHR support.
  71. Server-side authentication
  72. ==========================
  73. Session Support
  74. ---------------
  75. It's possible to enable single-site login, whereby users already
  76. authenticated in your website will also automatically be logged in on the chat server,
  77. but this will require custom code on your server.
  78. Jack Moffitt has a great `blogpost`_ about this and even provides an `example Django application`_ to demonstrate it.
  79. =========================================
  80. Quickstart (to get a demo up and running)
  81. =========================================
  82. When you download a specific release of *Converse.js*, say for example version 0.3,
  83. there will be two minified files inside the zip file.
  84. For version 0.3 they will be:
  85. * converse.0.3.min.js
  86. * converse.0.3.min.css
  87. You can include these two files in your website via the *script* and *link*
  88. tags:
  89. ::
  90. <link rel="stylesheet" type="text/css" media="screen" href="converse.0.3.min.css">
  91. <script src="converse.0.3.min.js"></script>
  92. The *index.html* file inside the Converse.js folder serves as a nice usable
  93. example of this.
  94. These minified files provide the same demo-like functionality as is available
  95. on the `conversejs.org`_ website. Useful for testing or demoing, but not very
  96. practical.
  97. You'll most likely want to implement some kind of single-signon solution for
  98. your website, where users authenticate once in your website and then stay
  99. logged into their XMPP session upon page reload.
  100. For more info on this, read `Session Support`_.
  101. You might also want to have more fine-grained control of what gets included in
  102. the minified Javascript file. Read `Configuration`_ and `Minification`_ for more info on how to do
  103. that.
  104. =============
  105. Configuration
  106. =============
  107. The included minified JS and CSS files can be used for demoing or testing, but
  108. you'll want to configure *Converse.js* to suit your needs before you deploy it
  109. on your website.
  110. *Converse.js* is passed its configuration settings when you call its
  111. *initialize* method.
  112. Please refer to the `Configuration variables`_ section below for info on
  113. all the available configuration settings.
  114. After you have configured *Converse.js*, you'll have to regenerate the minified
  115. JS file so that it will include the new settings. Please refer to the
  116. `Minification`_ section for more info on how to do this.
  117. Configuration variables
  118. =======================
  119. animate
  120. -------
  121. Default = True
  122. Show animations, for example when opening and closing chat boxes.
  123. auto_list_rooms
  124. ---------------
  125. Default = False
  126. If true, and the XMPP server on which the current user is logged in supports
  127. multi-user chat, then a list of rooms on that server will be fetched.
  128. Not recommended for servers with lots of chat rooms.
  129. For each room on the server a query is made to fetch further details (e.g.
  130. features, number of occupants etc.), so on servers with many rooms this
  131. option will create lots of extra connection traffic.
  132. auto_subscribe
  133. --------------
  134. Default = False
  135. If true, the user will automatically subscribe back to any contact requests.
  136. bosh_service_url
  137. ----------------
  138. Connections to an XMPP server depend on a BOSH connection manager which acts as
  139. a middle man between HTTP and XMPP.
  140. See `here`_ for more information.
  141. fullname
  142. --------
  143. If you are using prebinding, you need to specify the fullname of the currently
  144. logged in user.
  145. hide_muc_server
  146. ---------------
  147. Default = False
  148. Hide the ``server`` input field of the form inside the ``Room`` panel of the
  149. controlbox. Useful if you want to restrict users to a specific XMPP server of
  150. your choosing.
  151. prebind
  152. --------
  153. Default = False
  154. Use this option when you want to attach to an existing XMPP connection that was
  155. already authenticated (usually on the backend before page load).
  156. This is useful when you don't want to render the login form on the chat control
  157. box with each page load.
  158. When set to true, you'll need to make sure that the onConnected method is
  159. called, and passed to it a Strophe connection object.
  160. Besides requiring the back-end to authenticate you, you'll also
  161. have to write a Javascript snippet to attach to the set up connection::
  162. $.JSON({
  163. 'url': 'mysite.com/xmpp-authenticate',
  164. 'success': function (data) {
  165. connection = new Strophe.Connection(bosh_service_url);
  166. connection.attach(data.jid, data.sid, data.rid, converse.onConnected);
  167. }
  168. The backend must authenticate for you, and then return a SID (session ID) and
  169. RID (Request ID), which you use when you attach to the connection.
  170. xhr_user_search
  171. ---------------
  172. Default = False
  173. There are two ways to add users.
  174. * The user inputs a valid JID (Jabber ID), and the user is added as a pending contact.
  175. * 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.
  176. This setting enables the second mechanism, otherwise by default the first will
  177. be used.
  178. ============
  179. Minification
  180. ============
  181. Minifying Javascript
  182. ====================
  183. We use `require.js`_ to keep track of *Converse.js* and its dependencies and to
  184. to bundle them together in a single minified file fit for deployment to a
  185. production site.
  186. To use the require.js's optimization tool, you'll need Node and it's package
  187. manager, NPM.
  188. You can then install install require.js for Node like so:
  189. ::
  190. npm install requirejs
  191. The minified javascript file is then created like this:
  192. ::
  193. r.js -o build.js
  194. You should now have a new minified file (the name which is specified in build.js).
  195. You can `read more about require.js's optimizer here`_.
  196. Minifying CSS
  197. =============
  198. CSS can be minimized with Yahoo's yuicompressor tool:
  199. ::
  200. yui-compressor --type=css converse.css -o converse.min.css
  201. .. _`conversejs.org`: http://conversejs.org
  202. .. _`require.js`: http://requirejs.org
  203. .. _`read more about require.js's optimizer here`: http://requirejs.org/docs/optimization.html
  204. .. _`here`: http://metajack.im/2008/09/08/which-bosh-server-do-you-need/l
  205. .. _`HTTP`: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
  206. .. _`XMPP`: https://en.wikipedia.org/wiki/Xmpp
  207. .. _`Converse.js homepage`: http://conversejs.org
  208. .. _`CORS`: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing
  209. .. _`Strophe.js plugin`: https://gist.github.com/1095825/6b4517276f26b66b01fa97b0a78c01275fdc6ff2
  210. .. _`xmpp.net`: http://xmpp.net
  211. .. _`xmpp.org`: http://xmpp.org/xmpp-software/servers/
  212. .. _`ejabberd`: http://www.ejabberd.im
  213. .. _`blogpost`: http://metajack.im/2008/10/03/getting-attached-to-strophe
  214. .. _`example Django application`: https://github.com/metajack/strophejs/tree/master/examples/attach