index.txt 10 KB

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