これは、「Strophe.Connection.sendIQ を呼び出しても Strophe.Connection.addHandler が機能しない」に関連する質問ですが、役に立ちません。共同編集者である本「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;
},
問題は、iq スタンザが送信されても、別のコラボレータとの接続が確立されたときに NetPad.on_disco_info(iq) が起動されないことです。addHandler の残りの引数を省略して、すべての iq を取得しましたが、ここでも何も取得しませんでした。私のサーバーはejabberdです。わからないことがあれば聞いてください。