1
votes

I try to use strophe + ejabberd to make something like webchat.

What i've done already:

  • when I login to website, i also authenticate to ejabberd (to achieve RID and SID),
  • after login is finished, i attach RID and SID i got from context processor,
  • connection status seems to be: connection established, logs:

.

POST: <body rid='406266360' xmlns='http://jabber.org/protocol/httpbind' sid='9c66aa19123e96dc2925c24d4f985d458763eb67'><presence xmlns='jabber:client'><priority>-1</priority></presence><presence to='localhost/m' xmlns='jabber:client'><x xmlns='http://jabber.org/protocol/muc'/></presence></body>

RESP: <body xmlns='http://jabber.org/protocol/httpbind'><success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/></body>

After that, connection hangs on:

POST: <body rid='406266361' xmlns='http://jabber.org/protocol/httpbind' sid='9c66aa19123e96dc2925c24d4f985d458763eb67'/>

When i try to send a message now (while its hanged):

POST: <body rid='406266362' xmlns='http://jabber.org/protocol/httpbind' sid='175e45333109f74c36f9dffbe4e3cc6cffc80df4'><message to='localhost' type='groupchat' xmlns='jabber:client'><body>yrdy</body></message></body>

Im getting:

RESP: <body type='terminate' condition='remote-stream-error' xmlns='http://jabber.org/protocol/httpbind' xmlns:stream='http://etherx.jabber.org/streams'><stream:error><xml-not-well-formed xmlns='urn:ietf:params:xml:ns:xmpp-streams'/></stream:error></body>

Whats wrong? Strange thing is that after some seconds request is aborted, and next request hangs again. When i try to send message then, there are no errors but response is:

RESP: <body xmlns='http://jabber.org/protocol/httpbind'/>

With no errors (connection is still connected and authenticated, but message doesnt seem to be delivered).

Code I use to send message:

var body = $('#input_text').val();                                                            |        // make sure this presence is for the right room
var msg_body = {                                                                              |        if (room === Groupie.room) {
    to: Chat.room,                                                                       |            var nick = Strophe.getResourceFromJid(from);
    type: 'groupchat'                                                                         |
}                                                                                             |            if ($(presence).attr('type') === 'error' &&
var msg = $msg(msg_body).c('body').t(body);                                                   |                !Groupie.joined) {
                                                                                              |                // error joining room; reset app
Chat.connection.send(msg);
1

1 Answers

0
votes

You can use Strophe.js to attach like so:

Chat.connection = new Strophe.Connection(Chat.BOSH_SERVICE_URL);
Chat.connection.attach(jid, sid, rid, onConnectHandler);

onConnectHandler is then called once you've attached successfully. From then one, you don't have to worry about the SID and RID again (until page reload).

Also, are you aware of the MUC strophe plugin?

If you want some example code to use/study, I wrote something similar to what you're doing for Plone, called collective.xmpp.chat

The javascript is reusable separately: converse.js