Я работаю над приложением, которое соединяется с XMPP openfire с помощью Strofejs. Проблема в том, что присутствие отправляется правильно, но обработчик iq никогда не вызывается. Я проверил консоль в браузерах, но ошибок не нашел.
Я хочу отправить присутствие и отправить iq, чтобы клиенты вошли в систему в клиентских сеансах openfire (автоматическое закрытие сеанса в течение 10 секунд).
Вот мой js:
function onConnect(status) {
debugger;
if (status == Strophe.Status.CONNECTING) {
alert('Strophe is connecting.');
log('Strophe is connecting.');
} else if (status === Strophe.Status.AUTHENTICATING) {
alert ('status AUTHENTICATING');
} else if (status === Strophe.Status.AUTHFAIL) {
alert ('status AUTHFAIL');
} else if (status === Strophe.Status.ATTACHED) {
alert ('status ATTACHED');
} else if (status == Strophe.Status.CONNFAIL) {
alert('Strophe failed to connect.');
log('Strophe failed to connect.');
} else if (status == Strophe.Status.DISCONNECTING) {
alert('Strophe is disconnecting.');
log('Strophe is disconnecting.');
} else if (status == Strophe.Status.DISCONNECTED) {
alert('Strophe is disconnected.');
log('Strophe is disconnected.');
reConnectTimer = setInterval(reConnect, 3000);
} else if (status == Strophe.Status.CONNECTED) {
connection.addHandler(onOwnMessage, null, 'iq', 'set', null, null);
connection.addHandler(onMessage, null, 'message', null, null, null);
connection.addHandler(on_presence, null, 'presence', null, null, null);
connection.send($pres().tree());
var pres = $pres({ to: '[email protected]/' + Math.random() });
connection.send(pres);
alert('Strophe is connected.');
log('Strophe is connected.');
clearInterval(reConnect);
//connection.disconnect();
}
}
function onOwnMessage(msg) {
debugger;
// console.log(msg);
alert('msg is: ' + msg);
var elems = msg.getElementsByTagName('own-message');
if (elems.length > 0) {
var own = elems[0];
var to = $(msg).attr('to');
var from = $(msg).attr('from');
var iq = $iq({
to: from,
type: 'error',
id: $(msg).attr('id')
}).cnode(own).up().c('error', { type: 'cancel', code: '501' })
.c('feature-not-implemented', { xmlns: 'urn:ietf:params:xml:ns:xmpp-stanzas' });
connection.sendIQ(iq);
alert(iq);
}
return true;
}
Пожалуйста, скажите мне, что я делаю неправильно? Я пробовал и гуглил, но я все еще не могу решить.
Заранее спасибо.