diff --git a/CHANGES.rst b/CHANGES.rst index 31425f534..d7dfe4f52 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -12,6 +12,8 @@ Changelog - Fixed user status handling, which wasn't 100% according to the spec. [jcbrand] - Separate messages according to day in chats. [jcbrand] +- Add support for specifying the BOSH bind URL as configuration setting. + [jcbrand] 0.2 (2013-03-28) diff --git a/converse.js b/converse.js index e08852123..c2e6a56cc 100644 --- a/converse.js +++ b/converse.js @@ -1864,27 +1864,35 @@ '
  • Sign in
  • '), template: _.template( '
    ' + - '' + + '' + '' + '' + '' + - '' + - '' + '' + ''), - authenticate: function (ev) { + bosh_url_input: _.template( + '' + + ''), + + authenticate: $.proxy(function (ev) { ev.preventDefault(); var $form = $(ev.target), - $bsu_input = $form.find('input#bosh_service_url'), - bosh_service_url = $bsu_input.val(), $jid_input = $form.find('input#jid'), jid = $jid_input.val(), $pw_input = $form.find('input#password'), password = $pw_input.val(), - connection = new Strophe.Connection(bosh_service_url); + $bsu_input = null, + errors = false; - var errors = false; + if (! this.bosh_service_url) { + $bsu_input = $form.find('input#bosh_service_url'); + this.bosh_service_url = $bsu_input.val(); + if (! this.bosh_service_url) { + errors = true; + $bsu_input.addClass('error'); + } + } if (! jid) { errors = true; $jid_input.addClass('error'); @@ -1893,43 +1901,38 @@ errors = true; $pw_input.addClass('error'); } - if (! bosh_service_url) { - errors = true; - $bsu_input.addClass('error'); - } if (errors) { return; } // Clear the form's fields, so that it can't be submitted twice - $bsu_input.val(''); + if ($bsu_input) { + $bsu_input.val(''); + } $jid_input.val(''); $pw_input.val(''); + var connection = new Strophe.Connection(this.bosh_service_url); connection.connect(jid, password, $.proxy(function (status) { if (status === Strophe.Status.CONNECTED) { console.log('Connected'); - converse.onConnected(connection); + this.onConnected(connection); } else if (status === Strophe.Status.DISCONNECTED) { - console.log('Disconnected'); - this.$feedback.text('Unable to communicate with chat server').css('background-image', "url(images/error_icon.png)"); + this.giveFeedback('Disconnected').css('background-image', "url(images/error_icon.png)"); } else if (status === Strophe.Status.Error) { - console.log('Error'); + this.giveFeedback('Error'); } else if (status === Strophe.Status.CONNECTING) { - console.log('Connecting'); - this.$feedback.text('Connecting to chat...'); + this.giveFeedback('Connecting'); } else if (status === Strophe.Status.CONNFAIL) { - console.log('Connection Failed'); + this.giveFeedback('Connection Failed'); } else if (status === Strophe.Status.AUTHENTICATING) { - console.log('Authenticating'); - converse.giveFeedback('Authenticating'); + this.giveFeedback('Authenticating'); } else if (status === Strophe.Status.AUTHFAIL) { - console.log('Authenticating Failed'); - converse.giveFeedback('Authentication failed'); + this.giveFeedback('Authentication Failed'); } else if (status === Strophe.Status.DISCONNECTING) { - console.log('Disconnecting'); + this.giveFeedback('Disconnecting'); } else if (status === Strophe.Status.ATTACHED) { console.log('Attached'); } - }, this)); - }, + }, converse)); + }, converse), remove: function () { this.$parent.find('#controlbox-tabs').empty(); @@ -1938,7 +1941,11 @@ render: function () { this.$parent.find('#controlbox-tabs').append(this.tab_template()); - this.$parent.find('#controlbox-panes').append(this.$el.html(this.template())); + template = this.template(); + if (! this.bosh_url_input) { + template.find('form').append(this.bosh_url_input); + } + this.$parent.find('#controlbox-panes').append(this.$el.html(template)); return this; } }); @@ -1973,7 +1980,7 @@ }; converse.giveFeedback = function (message) { - $('.conn-feedback').text(message); + return $('.conn-feedback').text(message); } converse.onConnected = function (connection) { @@ -2028,12 +2035,7 @@ }; converse.initialize = function (settings) { - this.prebind = settings.prebind; - this.fullname = settings.fullname; - this.xhr_user_search = settings.xhr_user_search; - this.auto_subscribe = settings.auto_subscribe; - this.animate = settings.animate; - + _.extend(this, settings); this.chatboxes = new this.ChatBoxes(); this.chatboxesview = new this.ChatBoxesView({model: this.chatboxes}); $('a.toggle-online-users').bind( diff --git a/docs/NOTES.rst b/docs/NOTES.rst index 2482f483c..751274438 100644 --- a/docs/NOTES.rst +++ b/docs/NOTES.rst @@ -9,14 +9,14 @@ Converse.js configuration variables: Prebind ======== -Use this option if you don't want to render the login form on the chat control -box. +Use this option when you want to attach to an existing XMPP connection that was +already authenticated (usually on the backend before page load). -When set to true, the onConnected method needs to be called manually, together -with a Strophe connection object. +This is useful when you don't want to render the login form on the chat control +box with each page load. -The most likely usecase is if you want to already authenticate on the backend -and merely attach to that connection in the browser. +When set to true, you'll need to make sure that the onConnected method is +called, and passed to it a Strophe connection object. Besides requiring the back-end to authenticate you, you'll also have to write a Javascript snippet to attach to the set up connection:: @@ -24,16 +24,28 @@ have to write a Javascript snippet to attach to the set up connection:: $.JSON({ 'url': 'mysite.com/xmpp-authenticate', 'success': function (data) { - connection = new Strophe.Connection(data.BOSH_SERVICE_URL); + connection = new Strophe.Connection(bosh_service_url); connection.attach(data.jid, data.sid, data.rid, converse.onConnected); } +The backend must authenticate for you, and then return a SID (session ID) and +RID (Request ID), which you use when you attach to the connection. + fullname ======== If you are using prebinding, you need to specify the fullname of the currently logged in user. +bosh_service_url +================ + +Connections to an XMPP server depend on a BOSH connection manager which acts as +a middle man between HTTP and XMPP. + +See `here`_ for more information. + + xhr_user_search =============== @@ -55,3 +67,7 @@ animate ======= Show animations, for example when opening and closing chat boxes. + +.. _`here`: http://metajack.im/2008/09/08/which-bosh-server-do-you-need/l + + diff --git a/index.html b/index.html index 2f90361d1..3ce5a996a 100644 --- a/index.html +++ b/index.html @@ -29,24 +29,41 @@
    -

    Converse.js is a web based XMPP/Jabber instant messaging client.

    -

    It is used by collective.xmpp.chat, which is a Plone instant messaging add-on.

    -

    The ultimate goal is to enable anyone to add chat functionality to their websites, independent of any backend. - You will however need an XMPP server to connect to, either your own, or a public one.

    +

    Converse.js is an open source, web based, XMPP/Jabber chat client, similar to + Facebook chat, except for the added support of multi-user chatrooms.

    + +

    It is a Javascript application that you can include in your + website, thereby providing it with instant messaging functionality.

    + +

    You will however need access to an XMPP/Jabber server.

    + +

    You can connect to any public, federated XMPP server, or you could set one up + yourself, thereby maintaining stricter control of the user data (XMPP servers + usually don't archive chat messages).

    Features

      -
    • Manually or automically subscribe to other users.
    • +
    • Single and multi-user chat
    • +
    • Contact rosters
    • +
    • Manually or automically subscribe to other contacts
    • +
    • Roster item exchange (XEP 144)
    • Accept or decline contact requests
    • Chat statuses (online, busy, away, offline)
    • Custom status messages
    • Typing notifications
    • Third person messages (/me )
    • -
    • Multi-user chat in chatrooms
    • +
    • Multi-user chat in chatrooms (XEP 45)
    • Chatroom Topics
    • -
    • vCard support
    • +
    • vCard support (XEP 54)
    +

    CMS Integration

    + +

    Converse.js is available as an add-on for the Plone CMS, called collective.xmpp.chat.

    + +

    If you have integrated Converse.js into any other CMS or framework, + please let me know and I'll mention it on this page.

    +

    Screencasts

    Demo

    -

    - The code in Converse.js is pretty solid and already used in production - in Plone installations. It's however not yet 100% ready for prime-time - as a standalone client. -

    -

    - Nevertheless, you can try out the current functionality on this page. -

    Click this link or - click the link on the bottom right corner. + click the link on the bottom right corner of this page.

    - Besides providing valid credentials for an XMPP/Jabber account, you'll also have to provide - the details of a BOSH Connection Manager. - I intend to set up a connection manager for people to play with in the - near future, but for the moment I unfortunately can't help you there. -

    -

    - You can create a Jabber/XMPP account at any of these providers: + You can log in with any existing federated Jabber/XMPP account, or create a new one at any of these providers:

    +

    + The chat client will disconnect whenever you reload the page. If you + want the user's session to persist across page reloads, you can + establish an authenticated connection on the server side and then attach to + this connection in your browser. +

    +

    Converse.js already supports this usecase, but you'll have to + do more manual work yourself. +

    Tests

    diff --git a/main.js b/main.js index f1d40bed3..63ee12427 100644 --- a/main.js +++ b/main.js @@ -1,5 +1,6 @@ require(["jquery", "converse"], function($, converse) { converse.initialize({ + bosh_service_url: 'https://bind.opkode.im', prebind: false, xhr_user_search: false, auto_subscribe: false