2
我正在使用Strophejs與XMPP openfire連接的應用程序。問題是存在發送正確,但iq處理程序不會被調用。我在瀏覽器中查看了控制檯,但沒有發現錯誤。Strophe不使用javascript調用iq addHandler
我想發送狀態併發送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;
}
請告訴我,我究竟做錯了什麼?我已經嘗試並Google搜索,但我仍然無法解決。
在此先感謝。
感謝@beaver的指導。我現在正在學習XMPP,Strophe;這就是爲什麼我面臨這樣的問題... 你可以請指導我關於'智商'在strophe。? 我很困惑 –