// 接收到<message>functiononMessage(msg) {// 解析出<message>的from、type属性,以及body子元素var from = msg.getAttribute('from');
var type = msg.getAttribute('type');
var elems = msg.getElementsByTagName('body');
if (type == "chat" && elems.length > 0) {
var body = elems[0];
console.log(from , Strophe.getText(body) );
}
returntrue;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
1
2
3
4
5
6
7
8
9
10
11
12
13
注意事项: 发送者与接收者JID要填写完整的地址,如: test1@pc-20160820rwic
4. 获得好友列表
var iq = $iq({type: 'get'}).c('query', {xmlns: 'jabber:iq:roster'});
connection.sendIQ(iq, function(a){
console.log('sent iq',a);
$(a).find('item').each(function(){var jid = $(this).attr('jid'); // jid
console.log('jid',jid);
});
});