xmpp.chapril.org-conversejs/docs/html/index.html
JC Brand 38c26013d0 Simplify the boilerplate HTML require even more.
Use id 'conversejs' instead of 'chatpanel'.

The controlbox toggle is now generated via a backbone view, you don't need to
manually include it in your markup.
2013-10-20 22:42:34 +02:00

718 lines
47 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Quickstart (to get a demo up and running) &mdash; Converse.js 0.6.6 documentation</title>
<link rel="stylesheet" href="_static/stylesheet.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '0.6.6',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Converse.js 0.6.6 documentation" href="#" />
</head>
<body>
<div id="header_wrap" class="outer">
<header class="inner">
<a id="forkme_banner" href="https://github.com/jcbrand/converse.js">View on GitHub</a>
<h1 id="project_title"><a href="http://conversejs.org">Converse.js</a></h1>
<h2 id="project_tagline">Documentation</h2>
<section id="downloads">
<a class="zip_download_link" href="https://github.com/jcbrand/converse.js/zipball/master">Download this project as a .zip file</a>
<a class="tar_download_link" href="https://github.com/jcbrand/converse.js/tarball/master">Download this project as a tar.gz file</a>
</section>
</header>
</div>
<div id="main_content_wrap" class="outer">
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li><a href="#">Converse.js 0.6.6 documentation</a> &raquo;</li>
</ul>
</div>
<section id="main_content" class="inner">
<div class="document">
<div class="documentwrapper">
<div class="body">
<div class="toctree-wrapper compound">
<ul class="simple">
</ul>
</div>
<div class="contents local topic" id="table-of-contents">
<p class="topic-title first">Table of Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#quickstart-to-get-a-demo-up-and-running" id="id2">Quickstart (to get a demo up and running)</a></li>
<li><a class="reference internal" href="#introduction" id="id3">Introduction</a></li>
<li><a class="reference internal" href="#what-you-will-need" id="id4">What you will need</a><ul>
<li><a class="reference internal" href="#an-xmpp-jabber-server" id="id5">An XMPP/Jabber server</a></li>
<li><a class="reference internal" href="#connection-manager" id="id6">Connection Manager</a><ul>
<li><a class="reference internal" href="#overcoming-cross-domain-request-restrictions" id="id7">Overcoming cross-domain request restrictions</a></li>
</ul>
</li>
<li><a class="reference internal" href="#server-side-authentication" id="id8">Server-side authentication</a><ul>
<li><a class="reference internal" href="#pre-binding-and-single-session-support" id="id9">Pre-binding and Single Session Support</a></li>
</ul>
</li>
<li><a class="reference internal" href="#facebook-integration" id="id10">Facebook integration</a></li>
</ul>
</li>
<li><a class="reference internal" href="#development" id="id11">Development</a><ul>
<li><a class="reference internal" href="#install-node-js-and-development-dependencies" id="id12">Install Node.js and development dependencies</a></li>
<li><a class="reference internal" href="#install-3rd-party-dependencies" id="id13">Install 3rd party dependencies</a></li>
<li><a class="reference internal" href="#with-amd-and-require-js-recommended" id="id14">With AMD and require.js (recommended)</a></li>
<li><a class="reference internal" href="#without-amd-and-require-js" id="id15">Without AMD and require.js</a></li>
<li><a class="reference internal" href="#before-submitting-a-pull-request" id="id16">Before submitting a pull request</a><ul>
<li><a class="reference internal" href="#add-tests-for-your-bugfix-or-feature" id="id17">Add tests for your bugfix or feature</a></li>
<li><a class="reference internal" href="#check-that-the-tests-pass" id="id18">Check that the tests pass</a></li>
<li><a class="reference internal" href="#check-your-code-for-errors-or-bad-habits-by-running-jshint" id="id19">Check your code for errors or bad habits by running JSHint</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#configuration" id="id20">Configuration</a><ul>
<li><a class="reference internal" href="#configuration-variables" id="id21">Configuration variables</a><ul>
<li><a class="reference internal" href="#allow-contact-requests" id="id22">allow_contact_requests</a></li>
<li><a class="reference internal" href="#allow-muc" id="id23">allow_muc</a></li>
<li><a class="reference internal" href="#animate" id="id24">animate</a></li>
<li><a class="reference internal" href="#auto-list-rooms" id="id25">auto_list_rooms</a></li>
<li><a class="reference internal" href="#auto-subscribe" id="id26">auto_subscribe</a></li>
<li><a class="reference internal" href="#bosh-service-url" id="id27">bosh_service_url</a></li>
<li><a class="reference internal" href="#debug" id="id28">debug</a></li>
<li><a class="reference internal" href="#fullname" id="id29">fullname</a></li>
<li><a class="reference internal" href="#hide-muc-server" id="id30">hide_muc_server</a></li>
<li><a class="reference internal" href="#i18n" id="id31">i18n</a></li>
<li><a class="reference internal" href="#prebind" id="id32">prebind</a></li>
<li><a class="reference internal" href="#show-controlbox-by-default" id="id33">show_controlbox_by_default</a></li>
<li><a class="reference internal" href="#show-only-online-users" id="id34">show_only_online_users</a></li>
<li><a class="reference internal" href="#xhr-custom-status" id="id35">xhr_custom_status</a></li>
<li><a class="reference internal" href="#xhr-custom-status-url" id="id36">xhr_custom_status_url</a></li>
<li><a class="reference internal" href="#xhr-user-search" id="id37">xhr_user_search</a></li>
<li><a class="reference internal" href="#xhr-user-search-url" id="id38">xhr_user_search_url</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#minification" id="id39">Minification</a><ul>
<li><a class="reference internal" href="#minifying-javascript-and-css" id="id40">Minifying Javascript and CSS</a></li>
</ul>
</li>
<li><a class="reference internal" href="#translations" id="id41">Translations</a></li>
</ul>
</div>
<div class="section" id="quickstart-to-get-a-demo-up-and-running">
<h1><a class="toc-backref" href="#id2">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>
<p>When you download a specific release of <em>Converse.js</em> there will be two minified files inside the zip file.</p>
<ul class="simple">
<li>converse.min.js</li>
<li>converse.min.css</li>
</ul>
<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>
tags:</p>
<div class="highlight-python"><pre>&lt;link rel="stylesheet" type="text/css" media="screen" href="converse.min.css"&gt;
&lt;script src="converse.min.js"&gt;&lt;/script&gt;</pre>
</div>
<p>You need to initialize Converse.js with configuration settings particular to
your requirements.</p>
<p>Please refer to the <a class="reference internal" href="#configuration-variables">Configuration variables</a> section further below for info on
all the available configuration settings.</p>
<p>To do this, put the following inline Javascript code at the
bottom of your page (after the closing <em>&lt;/body&gt;</em> element).</p>
<div class="highlight-python"><pre>require(['converse'], function (converse) {
converse.initialize({
auto_list_rooms: false,
auto_subscribe: false,
bosh_service_url: 'https://bind.opkode.im', // Please use this connection manager only for testing purposes
hide_muc_server: false,
i18n: locales.en, // Refer to ./locale/locales.js to see which locales are supported
prebind: false,
show_controlbox_by_default: true,
xhr_user_search: false
});
});</pre>
</div>
<p>Finally, Converse.js requires a special snippet of HTML markup to be included in your page:</p>
<div class="highlight-python"><pre>&lt;div id="conversejs"&gt;&lt;/div&gt;</pre>
</div>
<p>The <a class="reference external" href="https://github.com/jcbrand/converse.js/blob/master/index.html">index.html</a> file inside the
Converse.js repository serves as a nice usable example of this.</p>
<p>These minified files provide the same demo-like functionality as is available
on the <a class="reference external" href="http://conversejs.org">conversejs.org</a> website. Useful for testing or demoing, but not very
practical.</p>
<p>You&#8217;ll most likely want to implement some kind of single-signon solution for
your website, where users authenticate once in your website and then stay
logged into their XMPP session upon page reload.</p>
<p>For more info on this, read: <a class="reference internal" href="#pre-binding-and-single-session-support">Pre-binding and Single Session Support</a>.</p>
<p>You might also want to have more fine-grained control of what gets included in
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
that.</p>
</div>
<div class="section" id="introduction">
<h1><a class="toc-backref" href="#id3">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline"></a></h1>
<p>Even though you can connect to public XMPP servers on the <a class="reference external" href="http://conversejs.org">conversejs.org</a>
website, <em>Converse.js</em> is not really meant to be a &#8220;Software-as-a-service&#8221; (SaaS)
webchat.</p>
<p>Instead, its goal is to provide the means for website owners to add a tightly
integrated instant messaging service to their own sites.</p>
<p>As a website owner, you are expected to host <em>Converse.js</em> yourself, and to do some legwork to
properly configure and integrate it into your site.</p>
<p>The benefit in doing this, is that your users have a much more streamlined and integrated
webchat experience and that you have control over the data. The latter being a
requirement for many sites dealing with sensitive information.</p>
<p>You&#8217;ll need to set up your own XMPP server and in order to have
<a class="reference internal" href="#session-support">Session Support</a> (i.e. single-signon functionality whereby users are authenticated once and stay
logged in to XMPP upon page reload) you will also have to add some server-side
code.</p>
<p>The <a class="reference internal" href="#what-you-will-need">What you will need</a> section has more information on all these
requirements.</p>
</div>
<div class="section" id="what-you-will-need">
<h1><a class="toc-backref" href="#id4">What you will need</a><a class="headerlink" href="#what-you-will-need" title="Permalink to this headline"></a></h1>
<div class="section" id="an-xmpp-jabber-server">
<h2><a class="toc-backref" href="#id5">An XMPP/Jabber server</a><a class="headerlink" href="#an-xmpp-jabber-server" title="Permalink to this headline"></a></h2>
<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
to connect to an XMPP/Jabber server (Jabber is really just a synonym for XMPP).</p>
<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
have <a class="reference internal" href="#session-support">Session Support</a> you&#8217;ll have to set up your own XMPP server.</p>
<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
servers that you can set up yourself on <a class="reference external" href="http://xmpp.org/xmpp-software/servers/">xmpp.org</a>.</p>
</div>
<div class="section" id="connection-manager">
<h2><a class="toc-backref" href="#id6">Connection Manager</a><a class="headerlink" href="#connection-manager" title="Permalink to this headline"></a></h2>
<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
the webserver. HTTP connections are stateless and usually shortlived.</p>
<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
its connections are stateful and usually longer.</p>
<p>To enable a web application like <em>Converse.js</em> to communicate with an XMPP
server, we need a proxy in the middle that can act as a bridge between the two
protocols.</p>
<p>This is the job of a connection manager. A connection manager can be either a
standalone application or part of an XMPP server. <a class="reference external" href="http://www.ejabberd.im">ejabberd</a> for example,
includes a connection manager (but you have to enable it).</p>
<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>.
This connection manager is for testing purposes only, please don&#8217;t use it in
production.</p>
<div class="section" id="overcoming-cross-domain-request-restrictions">
<h3><a class="toc-backref" href="#id7">Overcoming cross-domain request restrictions</a><a class="headerlink" href="#overcoming-cross-domain-request-restrictions" title="Permalink to this headline"></a></h3>
<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>.
HTTP requests are made by <em>Converse.js</em> to the connection manager via XmlHttpRequests (XHR).
Until recently, it was not possible to make such requests to a different domain
than the one currently being served (to prevent XSS attacks).</p>
<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.
Modern browsers support CORS, but there are problems with Internet Explorer &lt;
10.</p>
<p>IE 8 and 9 partially support CORS via a proprietary implementation called
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
support for XDomainRequest when it is present.</p>
<p>In IE &lt; 8, there is no support for CORS.</p>
<p>Instead of using CORS, you can add a reverse proxy in
Apache/Nginx which serves the connection manager under the same domain as your
website. This will remove the need for any cross-domain XHR support.</p>
<div class="section" id="for-example">
<h4>For example:<a class="headerlink" href="#for-example" title="Permalink to this headline"></a></h4>
<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>
and your connection manager manager is running at <tt class="docutils literal"><span class="pre">someothersite.com/http-bind</span></tt>.</p>
<p>The <em>bosh_service_url</em> value you want to give Converse.js to overcome
the cross-domain restriction is <tt class="docutils literal"><span class="pre">mysite.com/http-bind</span></tt> and not
<tt class="docutils literal"><span class="pre">someothersite.com/http-bind</span></tt>.</p>
<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>
</div>
<div class="section" id="nginx">
<h4>Nginx<a class="headerlink" href="#nginx" title="Permalink to this headline"></a></h4>
<div class="highlight-python"><pre>http {
server {
listen 80
server_name mysite.com;
location ~ ^/http-bind/ {
proxy_pass http://someothersite.com;
}
}
}</pre>
</div>
</div>
<div class="section" id="apache">
<h4>Apache<a class="headerlink" href="#apache" title="Permalink to this headline"></a></h4>
<div class="highlight-python"><pre>&lt;VirtualHost *:80&gt;
ServerName mysite.com
RewriteEngine On
RewriteRule ^/http-bind(.*) http://someothersite.com/http-bind$1 [P,L]
&lt;/VirtualHost&gt;</pre>
</div>
</div>
</div>
</div>
<div class="section" id="server-side-authentication">
<h2><a class="toc-backref" href="#id8">Server-side authentication</a><a class="headerlink" href="#server-side-authentication" title="Permalink to this headline"></a></h2>
<div class="section" id="pre-binding-and-single-session-support">
<span id="session-support"></span><h3><a class="toc-backref" href="#id9">Pre-binding and Single Session Support</a><a class="headerlink" href="#pre-binding-and-single-session-support" title="Permalink to this headline"></a></h3>
<p>It&#8217;s possible to enable single-site login, whereby users already
authenticated in your website will also automatically be logged in on the chat server,
but this will require custom code on your server.</p>
<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>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If you want to enable single session support, make sure to pass <strong>prebind: true</strong>
when you call <strong>converse.initialize</strong> (see ./index.html).
Additionally you need to pass in valid <strong>jid</strong>, <strong>sid</strong>, <strong>rid</strong> and
<strong>bosh_service_url</strong> values.</p>
</div>
<p>When you authenticate to the XMPP server on your backend, you&#8217;ll receive two
tokens, RID (request ID) and SID (session ID).</p>
<p>These tokens then need to be passed back to the javascript running in your
browser, where you will need them to attach to the existing session.</p>
<p>You can embed the RID and SID tokens in your HTML markup or you can do an
XMLHttpRequest call to your server and ask it to return them for you.</p>
<p>Below is one example of how this could work. An Ajax call is made to the
relative URL <strong>/prebind</strong> and it expects to receive JSON data back.</p>
<div class="highlight-python"><pre>$.getJSON('/prebind', function (data) {
converse.initialize({
prebind: true,
bosh_service_url: data.bosh_service_url,
jid: data.jid,
sid: data.sid,
rid: data.rid
});
);</pre>
</div>
<p><strong>Here&#8217;s what&#8217;s happening:</strong></p>
<p>The JSON data contains the user&#8217;s JID (jabber ID), RID, SID and the URL to the
BOSH connection manager.</p>
</div>
</div>
<div class="section" id="facebook-integration">
<h2><a class="toc-backref" href="#id10">Facebook integration</a><a class="headerlink" href="#facebook-integration" title="Permalink to this headline"></a></h2>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">It should be possible to integrate Converse.js with Facebook chat, and
below I&#8217;ll provide some tips and documentation on how to achieve this. That
said, I don&#8217;t have a Facebook account and therefore haven&#8217;t tried to do
this myself. Feedback and patches from people who have succesfully done this
will be appreciated.</p>
</div>
<p>Converse.js uses <a class="reference external" href="http://strophe.im/strophejs">Strophe.js</a> to connect and
communicate with the XMPP server. One nice thing about Strophe.js is that it
can be extended via <a class="reference external" href="http://github.com/strophe/strophejs-plugins">plugins</a>.</p>
<p>Here is a <a class="reference external" href="https://github.com/kissrobber/turedsocial/blob/master/strophe-plugins/src/facebook.js">plugin for authenticating with facebook</a>.</p>
<p>You will need your own BOSH connection manager to act as a proxy between
Converse.js/Strophe.js and Facebook&#8217;s XMPP server. That is because Facebook&#8217;s
XMPP server doesn&#8217;t support BOSH natively.</p>
<p>The BOSH connection manager that I make available for
testing purposes (at <a class="reference external" href="https://bind.opkode.im">https://bind.opkode.im</a>) uses <a class="reference external" href="https://github.com/twonds/punjab">Punjab</a>,
although there are quite a few other options available as well.</p>
<p>When you configure Converse.js, via its <tt class="docutils literal"><span class="pre">initialize</span></tt> method, you must specify the
<a class="reference internal" href="#bosh-service-url">bosh_service_url</a> value, which is to be your BOSH connection manager.</p>
<p>Please note, to enable Facebook integration, you&#8217;ll have to
get your hands dirty and modify Converse.js&#8217;s code, so that it calls the
<tt class="docutils literal"><span class="pre">facebookConnect</span></tt> method of the plugin above.</p>
<p>The plugin above gives the following code example for you to meditate upon:</p>
<div class="highlight-python"><pre>connection = new Strophe.Connection("http://localhost:5280/bosh");
connection.facebookConnect(
"12345@chat.facebook.com",
onConnectFacebook,
300,
1,
'5e64a30272af065bd72258c565a03f2f',
'8147a27e4a7f9b55ffc85c2683f9529a',
FB.getSession().session_key
);</pre>
</div>
<p>The connection is already created inside Converse.js, so the
<tt class="docutils literal"><span class="pre">facebookConnect</span></tt> method needs to also be called from there.</p>
<p>If someone submits a sane patch that does the above, I&#8217;ll be happy to merge it.
Until then, people will have to do this themselves.</p>
</div>
</div>
<div class="section" id="development">
<h1><a class="toc-backref" href="#id11">Development</a><a class="headerlink" href="#development" title="Permalink to this headline"></a></h1>
<p>If you want to work with the non-minified Javascript and CSS files you&#8217;ll soon
notice that there are references to a missing <em>components</em> folder. Please
follow the instructions below to create this folder and fetch Converse&#8217;s
3rd-party dependencies.</p>
<div class="section" id="install-node-js-and-development-dependencies">
<h2><a class="toc-backref" href="#id12">Install Node.js and development dependencies</a><a class="headerlink" href="#install-node-js-and-development-dependencies" title="Permalink to this headline"></a></h2>
<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>)
which depend on Node.js and npm (the Node package manager).</p>
<p>If you don&#8217;t have Node.js installed, you can download and install the latest
version <a class="reference external" href="https://nodejs.org/download">here</a>.</p>
<p>Once you have Node.js installed, run the following command inside the Converse.js
directory:</p>
<div class="highlight-python"><pre>npm install</pre>
</div>
<p>This will install all the development dependencies for Converse.js. If you are
curious to know what these are, take a look at whats under the <em>devDependencies</em> key in
<cite>package.json &lt;https://github.com/jcbrand/converse.js/blob/master/package.json&gt;</cite>.</p>
</div>
<div class="section" id="install-3rd-party-dependencies">
<h2><a class="toc-backref" href="#id13">Install 3rd party dependencies</a><a class="headerlink" href="#install-3rd-party-dependencies" title="Permalink to this headline"></a></h2>
<p>After running <tt class="docutils literal"><span class="pre">npm</span> <span class="pre">install</span></tt>, you will now have Grunt and Bower installed.</p>
<p>We use Bower to manage Converse&#8217;s front-end dependencies (e.g. Javascript that
should get loaded in the browser).</p>
<p>To fetch these dependencies, run:</p>
<div class="highlight-python"><pre>grunt fetch</pre>
</div>
<p>If you don&#8217;t have grunt installed globally, you need to specify the relative
path:</p>
<dl class="docutils">
<dt>::</dt>
<dd>./node_modules/.bin/grunt fetch</dd>
</dl>
<p>This will call Bower in the background to fetch all the front-end
dependencies (like backbone.js, strophe.js etc.) and then put them in the
<em>components</em> folder.</p>
</div>
<div class="section" id="with-amd-and-require-js-recommended">
<h2><a class="toc-backref" href="#id14">With AMD and require.js (recommended)</a><a class="headerlink" href="#with-amd-and-require-js-recommended" title="Permalink to this headline"></a></h2>
<p>Converse.js uses <a class="reference external" href="http://requirejs.org">require.js</a> to asynchronously load dependencies.</p>
<p>If you want to develop or customize converse.js, you&#8217;ll want to load the
non-minified javascript files.</p>
<p>Add the following two lines to the <em>&lt;head&gt;</em> section of your webpage:</p>
<div class="highlight-python"><pre>&lt;link rel="stylesheet" type="text/css" media="screen" href="converse.css"&gt;
&lt;script data-main="main" src="components/requirejs/require.js"&gt;&lt;/script&gt;</pre>
</div>
<p>require.js will then let the main.js file be parsed (because of the <em>data-main</em>
attribute on the <em>script</em> tag), which will in turn cause converse.js to be
parsed.</p>
</div>
<div class="section" id="without-amd-and-require-js">
<h2><a class="toc-backref" href="#id15">Without AMD and require.js</a><a class="headerlink" href="#without-amd-and-require-js" title="Permalink to this headline"></a></h2>
<p>Converse.js can also be used without require.js. If you for some reason prefer
to use it this way, please refer to
<a class="reference external" href="https://github.com/jcbrand/converse.js/blob/master/non_amd.html">non_amd.html</a>
for an example of how and in what order all the Javascript files that converse.js
depends on need to be loaded.</p>
</div>
<div class="section" id="before-submitting-a-pull-request">
<h2><a class="toc-backref" href="#id16">Before submitting a pull request</a><a class="headerlink" href="#before-submitting-a-pull-request" title="Permalink to this headline"></a></h2>
<div class="section" id="add-tests-for-your-bugfix-or-feature">
<h3><a class="toc-backref" href="#id17">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>
<p>Add a test for any bug fixed or feature added. We use Jasmine
for testing.</p>
<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
the tests are implemented.</p>
<p>If you are unsure how to write tests, please
<a class="reference external" href="http://opkode.com/contact">contact me</a> and I&#8217;ll be happy to help.</p>
</div>
<div class="section" id="check-that-the-tests-pass">
<h3><a class="toc-backref" href="#id18">Check that the tests pass</a><a class="headerlink" href="#check-that-the-tests-pass" title="Permalink to this headline"></a></h3>
<p>Check that the Jasmine tests complete sucessfully. Open
<a class="reference external" href="https://github.com/jcbrand/converse.js/blob/master/tests.html">tests.html</a>
in your browser, and the tests will run automatically.</p>
<p>On the command line you can run:</p>
<div class="highlight-python"><pre>grunt test</pre>
</div>
</div>
<div class="section" id="check-your-code-for-errors-or-bad-habits-by-running-jshint">
<h3><a class="toc-backref" href="#id19">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>
<p><a class="reference external" href="http://jshint.com">JSHint</a> will do a static analysis of your code and hightlight potential errors
and/or bad habits.</p>
<div class="highlight-python"><pre>grunt jshint</pre>
</div>
<p>You can run both the tests and jshint in one go by calling:</p>
<div class="highlight-python"><pre>grunt check</pre>
</div>
</div>
</div>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#id20">Configuration</a><a class="headerlink" href="#configuration" title="Permalink to this headline"></a></h1>
<p>The included minified JS and CSS files can be used for demoing or testing, but
you&#8217;ll want to configure <em>Converse.js</em> to suit your needs before you deploy it
on your website.</p>
<p><em>Converse.js</em> is passed its configuration settings when you call its
<em>initialize</em> method.</p>
<p>You&#8217;ll most likely want to call the <em>initialize</em> method in your HTML page. For
an example of how this is done, please see the bottom of the <em>./index.html</em> page.</p>
<p>Please refer to the <a class="reference internal" href="#configuration-variables">Configuration variables</a> section below for info on
all the available configuration settings.</p>
<p>After you have configured <em>Converse.js</em>, you&#8217;ll have to regenerate the minified
JS file so that it will include the new settings. Please refer to the
<a class="reference internal" href="#minification">Minification</a> section for more info on how to do this.</p>
<div class="section" id="configuration-variables">
<h2><a class="toc-backref" href="#id21">Configuration variables</a><a class="headerlink" href="#configuration-variables" title="Permalink to this headline"></a></h2>
<div class="section" id="allow-contact-requests">
<h3><a class="toc-backref" href="#id22">allow_contact_requests</a><a class="headerlink" href="#allow-contact-requests" title="Permalink to this headline"></a></h3>
<p>Default = <tt class="docutils literal"><span class="pre">true</span></tt></p>
<p>Allow users to add one another as contacts. If this is set to false, the
<strong>Add a contact</strong> widget, <strong>Contact Requests</strong> and <strong>Pending Contacts</strong> roster
sections will all not appear. Additionally, all incoming contact requests will be
ignored.</p>
</div>
<div class="section" id="allow-muc">
<h3><a class="toc-backref" href="#id23">allow_muc</a><a class="headerlink" href="#allow-muc" title="Permalink to this headline"></a></h3>
<p>Default = <tt class="docutils literal"><span class="pre">true</span></tt></p>
<p>Allow multi-user chat (muc) in chatrooms. Setting this to <tt class="docutils literal"><span class="pre">false</span></tt> will remove
the <tt class="docutils literal"><span class="pre">Chatrooms</span></tt> tab from the control box.</p>
</div>
<div class="section" id="animate">
<h3><a class="toc-backref" href="#id24">animate</a><a class="headerlink" href="#animate" title="Permalink to this headline"></a></h3>
<p>Default = <tt class="docutils literal"><span class="pre">true</span></tt></p>
<p>Show animations, for example when opening and closing chat boxes.</p>
</div>
<div class="section" id="auto-list-rooms">
<h3><a class="toc-backref" href="#id25">auto_list_rooms</a><a class="headerlink" href="#auto-list-rooms" title="Permalink to this headline"></a></h3>
<p>Default = <tt class="docutils literal"><span class="pre">false</span></tt></p>
<p>If true, and the XMPP server on which the current user is logged in supports
multi-user chat, then a list of rooms on that server will be fetched.</p>
<p>Not recommended for servers with lots of chat rooms.</p>
<p>For each room on the server a query is made to fetch further details (e.g.
features, number of occupants etc.), so on servers with many rooms this
option will create lots of extra connection traffic.</p>
</div>
<div class="section" id="auto-subscribe">
<h3><a class="toc-backref" href="#id26">auto_subscribe</a><a class="headerlink" href="#auto-subscribe" title="Permalink to this headline"></a></h3>
<p>Default = <tt class="docutils literal"><span class="pre">false</span></tt></p>
<p>If true, the user will automatically subscribe back to any contact requests.</p>
</div>
<div class="section" id="bosh-service-url">
<h3><a class="toc-backref" href="#id27">bosh_service_url</a><a class="headerlink" href="#bosh-service-url" title="Permalink to this headline"></a></h3>
<p>Connections to an XMPP server depend on a BOSH connection manager which acts as
a middle man between HTTP and XMPP.</p>
<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>
</div>
<div class="section" id="debug">
<h3><a class="toc-backref" href="#id28">debug</a><a class="headerlink" href="#debug" title="Permalink to this headline"></a></h3>
<p>Default = <tt class="docutils literal"><span class="pre">false</span></tt></p>
<p>If set to true, debugging output will be logged to the browser console.</p>
</div>
<div class="section" id="fullname">
<h3><a class="toc-backref" href="#id29">fullname</a><a class="headerlink" href="#fullname" title="Permalink to this headline"></a></h3>
<p>If you are using prebinding, can specify the fullname of the currently
logged in user, otherwise the user&#8217;s vCard will be fetched.</p>
</div>
<div class="section" id="hide-muc-server">
<h3><a class="toc-backref" href="#id30">hide_muc_server</a><a class="headerlink" href="#hide-muc-server" title="Permalink to this headline"></a></h3>
<p>Default = <tt class="docutils literal"><span class="pre">false</span></tt></p>
<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
controlbox. Useful if you want to restrict users to a specific XMPP server of
your choosing.</p>
</div>
<div class="section" id="i18n">
<h3><a class="toc-backref" href="#id31">i18n</a><a class="headerlink" href="#i18n" title="Permalink to this headline"></a></h3>
<p>Specify the locale/language. The language must be in the <tt class="docutils literal"><span class="pre">locales</span></tt> object. Refer to
<tt class="docutils literal"><span class="pre">./locale/locales.js</span></tt> to see which locales are supported.</p>
</div>
<div class="section" id="prebind">
<h3><a class="toc-backref" href="#id32">prebind</a><a class="headerlink" href="#prebind" title="Permalink to this headline"></a></h3>
<p>Default = <tt class="docutils literal"><span class="pre">false</span></tt></p>
<p>Use this option when you want to attach to an existing XMPP connection that was
already authenticated (usually on the backend before page load).</p>
<p>This is useful when you don&#8217;t want to render the login form on the chat control
box with each page load.</p>
<p>For prebinding to work, your backend server must authenticate for you, and
then return a JID (jabber ID), SID (session ID) and RID (Request ID).</p>
<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
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>
<p>Additionally, you have to specify <tt class="docutils literal"><span class="pre">bosh_service_url</span></tt>.</p>
</div>
<div class="section" id="show-controlbox-by-default">
<h3><a class="toc-backref" href="#id33">show_controlbox_by_default</a><a class="headerlink" href="#show-controlbox-by-default" title="Permalink to this headline"></a></h3>
<p>Default = <tt class="docutils literal"><span class="pre">false</span></tt></p>
<p>The &#8220;controlbox&#8221; refers to the special chatbox containing your contacts roster,
status widget, chatrooms and other controls.</p>
<p>By default this box is hidden and can be toggled by clicking on any element in
the page with class <em>toggle-online-users</em>.</p>
<p>If this options is set to true, the controlbox will by default be shown upon
page load.</p>
</div>
<div class="section" id="show-only-online-users">
<h3><a class="toc-backref" href="#id34">show_only_online_users</a><a class="headerlink" href="#show-only-online-users" title="Permalink to this headline"></a></h3>
<p>Default = <tt class="docutils literal"><span class="pre">false</span></tt></p>
<p>If set to <tt class="docutils literal"><span class="pre">true</span></tt>, only online users will be shown in the contacts roster.
Users with any other status (e.g. away, busy etc.) will not be shown.</p>
</div>
<div class="section" id="xhr-custom-status">
<h3><a class="toc-backref" href="#id35">xhr_custom_status</a><a class="headerlink" href="#xhr-custom-status" title="Permalink to this headline"></a></h3>
<p>Default = <tt class="docutils literal"><span class="pre">false</span></tt></p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).</p>
</div>
<p>This option will let converse.js make an AJAX POST with your changed custom chat status to a
remote server.</p>
</div>
<div class="section" id="xhr-custom-status-url">
<h3><a class="toc-backref" href="#id36">xhr_custom_status_url</a><a class="headerlink" href="#xhr-custom-status-url" title="Permalink to this headline"></a></h3>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).</p>
</div>
<p>Default = Empty string</p>
<p>Used only in conjunction with <tt class="docutils literal"><span class="pre">xhr_custom_status</span></tt>.</p>
<p>This is the URL to which the AJAX POST request to set the user&#8217;s custom status
message will be made.</p>
<p>The message itself is sent in the request under the key <tt class="docutils literal"><span class="pre">msg</span></tt>.</p>
</div>
<div class="section" id="xhr-user-search">
<h3><a class="toc-backref" href="#id37">xhr_user_search</a><a class="headerlink" href="#xhr-user-search" title="Permalink to this headline"></a></h3>
<p>Default = <tt class="docutils literal"><span class="pre">false</span></tt></p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).</p>
</div>
<p>There are two ways to add users.</p>
<ul class="simple">
<li>The user inputs a valid JID (Jabber ID), and the user is added as a pending contact.</li>
<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>
</ul>
<p>This setting enables the second mechanism, otherwise by default the first will be used.</p>
<p><em>What is expected from the remote server?</em></p>
<p>A default JSON encoded list of objects must be returned. Each object
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>
</div>
<div class="section" id="xhr-user-search-url">
<h3><a class="toc-backref" href="#id38">xhr_user_search_url</a><a class="headerlink" href="#xhr-user-search-url" title="Permalink to this headline"></a></h3>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).</p>
</div>
<p>Default = Empty string</p>
<p>Used only in conjunction with <tt class="docutils literal"><span class="pre">xhr_user_search</span></tt>.</p>
<p>This is the URL to which an AJAX GET request will be made to fetch user data from your remote server.
The query string will be included in the request with <tt class="docutils literal"><span class="pre">q</span></tt> as its key.</p>
</div>
</div>
</div>
<div class="section" id="minification">
<h1><a class="toc-backref" href="#id39">Minification</a><a class="headerlink" href="#minification" title="Permalink to this headline"></a></h1>
<div class="section" id="minifying-javascript-and-css">
<h2><a class="toc-backref" href="#id40">Minifying Javascript and CSS</a><a class="headerlink" href="#minifying-javascript-and-css" title="Permalink to this headline"></a></h2>
<p>Please make sure to read the section <a class="reference internal" href="#development">Development</a> and that you have installed
all development dependencies (long story short, you can run <tt class="docutils literal"><span class="pre">npm</span> <span class="pre">install</span></tt>
and then <tt class="docutils literal"><span class="pre">grunt</span> <span class="pre">fetch</span></tt>).</p>
<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
to bundle them together in a single minified file fit for deployment to a
production site.</p>
<p>To minify the Javascript and CSS, run the following command:</p>
<div class="highlight-python"><pre>grunt minify</pre>
</div>
<p>Javascript will be bundled and minified with <a class="reference external" href="http://requirejs.org">require.js</a>&#8216;s optimization tool,
using <a class="reference external" href="https://github.com/jrburke/almond">almond</a>.</p>
<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>
<p>CSS is minified via <a class="reference external" href="https://github.com/gruntjs/grunt-contrib-cssmin">cssmin</a>.</p>
</div>
</div>
<div class="section" id="translations">
<h1><a class="toc-backref" href="#id41">Translations</a><a class="headerlink" href="#translations" title="Permalink to this headline"></a></h1>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Translations take up a lot of space and will bloat your minified file.
At the time of writing, all the translations add about 50KB of extra data to
the minified javascript file. Therefore, make sure to only
include those languages that you intend to support and remove from
./locale/locales.js those which you don&#8217;t need. Remember to rebuild the
minified file afterwards.</p>
</div>
<p>The gettext POT file located in ./locale/converse.pot is the template
containing all translations and from which for each language an individual PO
file is generated.</p>
<p>The POT file contains all translateable strings extracted from converse.js.</p>
<p>To make a user facing string translateable, wrap it in the double underscore helper
function like so:</p>
<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>
</pre></div>
</div>
<p>After adding the string, you&#8217;ll need to regenerate the POT file, like so:</p>
<div class="highlight-python"><pre>make pot</pre>
</div>
<p>You can then create or update the PO file for a specific language by doing the following:</p>
<div class="highlight-python"><pre>msgmerge ./locale/de/LC_MESSAGES/converse.po ./locale/converse.pot -U</pre>
</div>
<p>To do this for ALL languages, run:</p>
<div class="highlight-python"><pre>make merge</pre>
</div>
<p>The resulting PO file is then what gets translated.</p>
<p>If you&#8217;ve created a new PO file, please make sure to add the following
attributes at the top of the file (under <em>Content-Transfer-Encoding</em>). They are
required as configuration settings for Jed, the Javascript translations library
that we&#8217;re using.</p>
<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>
<span class="s">&quot;lang: de</span><span class="se">\n</span><span class="s">&quot;</span>
<span class="s">&quot;plural_forms: nplurals=2; plural=(n != 1);</span><span class="se">\n</span><span class="s">&quot;</span>
</pre></div>
</div>
<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
a file in JSON format and then put that in a .js file for the specific
language.</p>
<p>To generate JSON from a PO file, you&#8217;ll need po2json for node.js. Run the
following command to install it (npm being the node.js package manager):</p>
<div class="highlight-python"><pre>npm install po2json</pre>
</div>
<p>You can then convert the translations into JSON format:</p>
<div class="highlight-python"><pre>po2json locale/de/LC_MESSAGES/converse.po locale/de/LC_MESSAGES/converse.json</pre>
</div>
<p>Now from converse.json paste the data as a value for the &#8220;locale_data&#8221; key in the
object in the language&#8217;s .js file.</p>
<p>So, if you are for example translating into German (language code &#8216;de&#8217;), you&#8217;ll
create or update the file ./locale/LC_MESSAGES/de.js with the following code:</p>
<div class="highlight-python"><pre>(function (root, factory) {
define("de", ['jed'], function () {
return factory(new Jed({
"domain": "converse",
"locale_data": {
// Paste the JSON data from converse.json here
}
})
}
}(this, function (i18n) {
return i18n;
}));</pre>
</div>
<p>making sure to also paste the JSON data as value to the &#8220;locale_data&#8221; key.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If you are adding translations for a new language that is not already supported,
you&#8217;ll have to make one more edit in ./locale/locales.js to make sure the
language is loaded by require.js.</p>
</div>
<p>Congratulations, you&#8217;ve now succesfully added your translations. Sorry for all
those hoops you had to jump through.</p>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
</section>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li><a href="#">Converse.js 0.6.6 documentation</a> &raquo;</li>
</ul>
</div>
</div>
<div id="footer_wrap" class="outer">
<footer class="inner">
&copy; Copyright 2013, JC Brand.
<p class="copyright">Converse.js created by <a href="http://opkode.com" target="_blank">jcbrand</a></p>
</footer>
</div>
</body>
</html>