【发布时间】:2016-02-07 07:30:56
【问题描述】:
我正在开发使用 Strophejs 与 XMPP openfire 连接的应用程序。问题是存在正确发送,但从未调用 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: 'myroom@support.myroom/' + 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;
}
请告诉我我做错了什么?我已经尝试和谷歌搜索,但我仍然无法解决。
提前致谢。
【问题讨论】:
标签: javascript xmpp openfire strophe