-1

I am working on an XMPP web application which need to include session attachment. I am using Openfire XMPP server. I have successfully implemented the server side attachments where the session is created and I get the sid and rid of a session. Unfortunately, I am stuck in the next part.

As I know, after getting the sid and rid, I need to use the Strophe.Connection.attach() to attach strphe to the existing session. After that I am making an IQ request which gets the correct response from the server. However, I am not getting any changes in the status i.e. the app is neither connected nor attached and hence I am not able to do anything. After the IQ request, the server responds on time with the normal message and then in the next request, I get a 403 forbidden error and the connection is terminated.

Here is the code:

var BOSH_SERVICE = 'http://localhost/cosys-rtw/';
var connection = null;
var sid = "";
var rid = 0;
function notifyUser(msg) 
{
    if (msg.getAttribute('from') == "testuser1@ghost/pingstream") {
        var elems = msg.getElementsByTagName('body');
        var body = elems[0];
        $('#notifications').append(Strophe.getText(body));
}
return true;
}

 function onConnect(status)
{
    console.log("Connect")
console.log(status)
if (status == Strophe.Status.ATTACHED) {
    $('#notifications').html('<p class="welcome">Hello! Any new posts will    appear below.</p>');
    connection.addHandler(notifyUser, null, 'message', null, null,  null);
    connection.send($pres().tree());
}       
}

$(document).ready(function () {
 $.ajax({'url':'http://localhost/x',
        'method':'get',
        'success':function(response){
            console.log(response);  
            console.log(jQuery.parseJSON(response));
            resp = jQuery.parseJSON(response);
            window.sid = resp.sid;
            window.rid = resp.rid;
            prepareStrophe();               
        }});
});

 function prepareStrophe(){
console.log(BOSH_SERVICE);
jid = "testuser1@ghost";
connection = new Strophe.Connection(BOSH_SERVICE);
console.log(window.rid);
console.log(window.sid);
connection.attach(  jid,window.sid,window.rid,null);
connection.sendIQ( $iq({to:Strophe.getDomainFromJid(jid),type:"get"})
                    .c('query',{xmlns:'http://jabber.org/protocol/disco#info'}),
                    function(){
                        if (status == Strophe.Status.ATTACHED) {
                    connection.send($pres().tree());}
                    });}

I get the follwoing response to the IQ request:

<body xmlns="http://jabber.org/protocol/httpbind">
 <iq id="6173:sendIQ" xmlns="jabber:client" type="result" from="ghost"    to="testuser1@ghost/6b8bfe07">
 <query xmlns="http://jabber.org/protocol/disco#info">
 <identity category="server" name="Openfire Server" type="im"></identity>
 <identity category="pubsub" type="pep"></identity>
 <feature var="http://jabber.org/protocol/pubsub#delete-nodes"></feature>
  .
  .
  .
 <feature var="http://jabber.org/protocol/pubsub#purge-nodes"></feature>
 <feature var="http://jabber.org/protocol/disco#info"></feature>
 <feature var="http://jabber.org/protocol/rsm"></feature>
</query>
</iq>
</body>

This response does say that the session is valid. Am I right? I am not able to figure this thing so now I am handing this to the community. By the way -- Merry Christmas

mlakhara
  • 235
  • 3
  • 11

1 Answers1

1

I think that I have got something here that I would like to share if anyone has the same problem. This thread on ignite realtime http://community.igniterealtime.org/thread/33004 discusses about this issue. The settings mentioned there did work for me.

mlakhara
  • 235
  • 3
  • 11