Strophe addHandler不起作用

时间:2014-08-22 17:35:10

标签: xmpp strophe addhandler

对于" Strophe.Connection.addHandler这是一个相关的问题,如果调用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)在与另一个colloborator建立连接时没有被触发,尽管发出了iq节。我省略了其余的addHandler参数,以获得所有iq但又没有任何东西。 我的服务器是ejabberd。 请问是否有些事情是不可理解的。

0 个答案:

没有答案