AshBringer
AshBringer

Reputation: 2673

Strophejs get roster success callback response

I have these functions that allow me to get the roster on ejabberd server.

function callback(){
 alert('hi');
}

function getInfo(){

  var iq = $iq({type: 'get'}).c('query', { xmlns: Strophe.NS.ROSTER });
  conn.sendIQ(iq, callback);
}

The request is a success since I have an alert. My question is how can I handle the response from the server ? I can see on Wireshark the following response :

<body xmlns='http://jabber.org/protocol/httpbind'>
<iq xmlns='jabber:client'
from='azerty@localhost' to='azerty@localhost/24988088151432746377322003' id='4:sendIQ'
type='result'><query xmlns='jabber:iq:roster'>
<item subscription='both' jid='user1@localhost'><group>EveryBody</group></item>
<item subscription='both' jid='user2@localhost'><group>EveryBody</group></item>
<item subscription='both' jid='user2@localhost'><group>EveryBody</group></item>
</query></iq></body>

I would like to get a list with user1, user2, user3.

Any advice on how can I access at least the response like xhr ?

Upvotes: 0

Views: 511

Answers (2)

AshBringer
AshBringer

Reputation: 2673

I've changed the callback function like this :

function callback(iq){
    $(iq).find('item').each(function(){
          var jid = $(this).attr('jid'); 
          alert(jid);
    });
}

Works well..

Upvotes: 0

Mark S
Mark S

Reputation: 869

Update your callback function to include the iq.

function callback(iq) {
    iq.each(function (o) {
        if (o.subscription === 'both') {
            var jid = Strophe.getNodeFromJid(o.jid);
            //do  whatever
        } else{
           //do something else
        }
    })
}

Upvotes: 1

Related Questions