node-xmpp モジュールを使用して XMPP サーバーに接続し、グループ チャットに参加しています。サーバーへの接続、プレゼンスの設定、ルームへの参加、メッセージの読み上げは今のところ機能しています。しかし、部屋のユーザーリストも受け取りたいです。
XMPP プロトコルでは、クライアントがルームに入るときにプレゼンス スタンザを送信する必要があります ( http://xmpp.org/extensions/xep-0045.html#enter-pres )。しかし、どうすればノードで解析できますか?
私のコードは現在次のようになっています。
var xmpp = require('node-xmpp');
// Create the XMPP Client
var cl = new xmpp.Client({
jid: jid,
password: password,
reconnect: true
});
// Do things when online
cl.on('online', function() {
util.log("We're online!");
// Set client's presence
cl.send(new xmpp.Element('presence', { type: 'available' }).c('show').t('chat'));
cl.send(new xmpp.Element('presence', { to: room_jid+'/'+room_nick }).c('x', { xmlns: 'http://jabber.org/protocol/muc' }).c('history', {seconds: 1}));
// Send keepalive
setInterval(function() {
cl.send(' ');
}, 30000);
cl.on('stanza', function(stanza) {
// always log error stanzas
if (stanza.attrs.type == 'error') {
util.log('[error] ' + stanza);
return;
}
// ignore everything that isn't a room message
if (!stanza.is('message') || !stanza.attrs.type == 'chat') {
return;
}
var body = stanza.getChild('body');
// message without body is probably a topic change
if (!body) {
return;
}
// Extract username
var from, room, _ref;
_ref = stanza.attrs.from.split('/'), room = _ref[0], from = _ref[1];
var message = body.getText();
// Log topics and messages to the console
if(!from) {
util.log('Topic: ' + message);
} else {
util.log('[' + from + ']: ' + message);
}
});
});
私はすでに使用してプレゼンスをトリガーしようとしました
if(stanza.is('presence')) {}
cl.on('stanza') 部分内ですが、機能しません。