2013-10-15 55 views
1

我正在使用'simple-xmpp'模塊,並在登錄後嘗試獲取Jabber用戶的名單。連接到Jabber服務器(在我的情況下爲Openfire)併發送消息工作得很好。當我嘗試執行xmpp.getRoster()調用時,它僅返回'undefined'。如何通過simple-xmpp/node-xmpp獲得Jabber用戶的名單?

這是我的代碼。我想我應該得到某種JSON對象。我究竟做錯了什麼?謝謝。

var config = require('../lib/config'); 
var xmpp = require('simple-xmpp'); 

xmpp.on('online', function() { 
    console.log('Yes, I\'m connected!'); 

    console.log(xmpp.getRoster()); 
}); 

xmpp.on('error', function(err) { 
    console.error(err); 
}); 

xmpp.on('chat', function(from, message) { 
console.log(from + " said: " + message); 
}); 


exports.connect = function (username, password) { 
    xmpp.connect({ 
     jid   : username, 
     password : password, 
     host  : config.jabberHost, 
     port  : config.jabberPort 
    }); 
}; 

回答

0

我知道這是一個古老的問題,但我偶然發現它尋找別的東西。

我做到了,通過使用節點XMPP的核心節點XMPP協議的客戶端和LTX併發送以下內容:

 
client.send(new ltx.Element('iq', { from: '[email protected]', type:'get', id:'roster_1'}) 
    .c('query', { xmlns: 'jabber:iq:roster' }).t().up() 
) 
)