这是一个与“Strophe.Connection.addHandler no works if call Strophe.Connection.sendIQ”相关的问题,但它对我没有帮助。我正在尝试运行“Wrox Professional XMPP Programming with JavaScript and jQuery Book”一书的程序,这是一个协作编辑器。
$(document).bind('connected', function () {
$('#disconnect').removeAttr('disabled');
NetPad.connection.addHandler(NetPad.on_message, null, "message");
if (NetPad.collaborator) {
NetPad.master = false;
$('#status')
.text('Checking feature support for ' + NetPad.collaborator + '.')
.attr('class', 'try-collab');
// check for feature support
NetPad.connection.sendIQ(
$iq({to: NetPad.collaborator, type: 'get'})
.c('query', {xmlns: Strophe.NS.DISCO_INFO}),
function (iq) {
console.log(iq);
var f = $(iq).find(
'feature[var="' + NetPad.NS_NETPAD + '"]');
if (f.length > 0) {
$('#status')
.text('Establishing session with ' +
NetPad.collaborator + '.')
.attr('class', 'try-collab');
NetPad.connection.send(
$pres({to: NetPad.collaborator})
.c('collaborate', {xmlns: NetPad.NS_NETPAD}));
} else {
$('#status')
.text('Collaboration not supported with ' +
NetPad.collaborator + '.')
.attr('class', 'no-collab');
NetPad.connection.disconnect();
}
});
} else {
NetPad.master = true;
$('#pad').removeAttr('disabled');
// handle incoming discovery and collaboration requests
**NetPad.connection.addHandler(NetPad.on_disco_info,
Strophe.NS.DISCO_INFO, "iq", "get");**
NetPad.connection.addHandler(NetPad.on_collaborate,
NetPad.NS_NETPAD, "presence");
NetPad.connection.addHandler(NetPad.on_unavailable,
null, "presence");
}
});
on_disco_info: function (iq) {
console.log("==> On_disco_info()...");
NetPad.connection.sendIQ(
$iq({to: $(iq).attr('from'),
id: $(iq).attr('id'),
type: "result"})
.c('query', {xmlns: Strophe.NS.DISCO_INFO})
.c('identity', {category: 'client',
type: 'pc'}).up()
.c('feature', {'var': NetPad.NS_NETPAD}));
return true;
},
问题是 NetPad.on_disco_info(iq) 在与另一个合作者建立连接时不会被触发,尽管发送了一个 iq 节。我省略了 addHandler 的其余参数,以获取所有 iq 但又一无所获。我的服务器是 ejabberd。请问有什么不明白的地方。