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
});
};