1
votes

This will query all the list of contacts in my roster,but it only allows me to query the JID and not the fullname. How do I query the roster and get each name?

$(document).bind('connected', function(){
   var iq = $iq({type: 'get'}).c('query', {xmlns: 'jabber:iq:roster'});
});

Thanks.

1

1 Answers

1
votes
 var iq = $iq({type: 'get'}).c('query', {xmlns: 'jabber:iq:roster'});
conn.sendIQ(iq,
            function success(iq){
                $(iq).find('item').each(function () { //all contacts 
                    var jid = $(this).attr('jid');
                    var name = $(this).attr('name') || jid;
                    var subscr = $(this).attr('subscription'); //type subscription
                    console.log('contacts: jid:' + jid + '  Name:' + name);
                });
            },
            function failure(iq){
                console.log(iq);
            },30000/*timeout sendIQ*/
        );

Also you can mix with

<iq from='[email protected]'
    id='v1'
    type='get'>
  <vCard xmlns='vcard-temp'/>
</iq>

To get vcard's of each user and then get full name.

Try it.