【问题标题】:Receive 'subscribe' presences with Strophe.js Roster plugin and Ejabberd使用 Strophe.js 名册插件和 Ejabberd 接收“订阅”状态
【发布时间】:2016-08-23 15:45:20
【问题描述】:

我使用 Strophe.js Roster pluginEjabberd 作为 XMPP 服务器。当我使用Adium 或其他一些 XMPP 客户端时,我可以在我的名册中添加一些其他帐户。当我发送邀请时,其他帐户收到出席type=='subscribe'

Wit Strophe.js 名册,我从来没有收到type == 'subscribe' 的任何出席! 我尝试了一切...我添加了一些处理程序...我“过滤”了 ...

这是我的代码:

HTML 包括

    <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js'></script>
    <script src='../strophe.js'></script>
    <script src="../strophe.muc.js"></script>
    <script src="../strophe.register.js"></script>
    <script src="../strophe.roster.js"></script>
    <script src='my-code.js'></script>

my-code.js

var jid;
$(document).ready(function () {
    connection = new Strophe.Connection(BOSH_SERVICE, {'keepalive': true});
    //connection.rawInput = rawInput;
    //connection.rawOutput = rawOutput;

    connection.addHandler(onPresence, null, 'presence', null, null, null);
    connection.roster.registerRequestCallback(onRequest);


    // Manage connection
    try {
        $('#connect').get(0).value = 'disconnect';
        connection.restore(null, onRegister);
    } catch(e) {
        if (e.name !== "StropheSessionError") { throw(e); }
        $('#connect').get(0).value = 'connect';
    }
    $('#connect').bind('click', function () {
       var button = $('#connect').get(0);
       if (button.value == 'connect') {
           button.value = 'disconnect';

           jid = $('#jid').get(0).value;
           connection.connect(jid, $('#pass').get(0).value, onConnect, 10);
       } else {
           button.value = 'connect';
           connection.disconnect();
       }
   });
});


function onPresence(stanza)
{
    log("PRESENCE");
    console.log(stanza);

    return true;
}

function onRequest(req) {

    console.log("Request");
    console.log(req);

    return true;
}

我错过了什么吗?

【问题讨论】:

标签: xmpp ejabberd strophe strophe.js rosters


【解决方案1】:

我的问题解决了!

我们必须在连接状态为 Strophe.Status.CONNECTING

function onConnect(status)
{
    if (status == Strophe.Status.CONNECTING) {
        log('Strophe is connecting.');
    } else if (status == Strophe.Status.CONNFAIL) {
        log('Strophe failed to connect.');
    } else if (status == Strophe.Status.DISCONNECTING) {
        log('Strophe is disconnecting.');
    } else if (status == Strophe.Status.DISCONNECTED) {
        log('Strophe is disconnected.');
    } else if (status == Strophe.Status.CONNECTED) {
        log('Strophe is connected.');


        // Send a presence to the server
        connection.send($pres().tree());

    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 2017-10-16
    • 1970-01-01
    • 2017-03-20
    • 1970-01-01
    • 2013-10-08
    • 2021-09-03
    相关资源
    最近更新 更多