Strophe.js:如何使用strophe.roster.js插件

时间:2013-12-24 10:29:23

标签: xmpp strophe

我在strophe.js中找到了维护名册的插件。

我找到了插件here,但提供的文档不够。

这是代码初始化函数的片段:

    init: function(conn)
        {
            ...

            var newCallback = function(status)
            {
                if (status == Strophe.Status.ATTACHED || status == Strophe.Status.CONNECTED)
                {
                    try
                    {
                        // Presence subscription
                        conn.addHandler(roster._onReceivePresence.bind(roster), null, 'presence', null, null, null);
                        conn.addHandler(roster._onReceiveIQ.bind(roster), Strophe.NS.ROSTER, 'iq', "set", null, null);
                        console.log(items);
                    }
                    catch (e)
                    {
                        Strophe.error(e);
                    }
                }
            };
            ...
            Strophe.addNamespace('ROSTER_VER', 'urn:xmpp:features:rosterver');
        },

我的问题是我没有得到我的名单,因此无法更新状态。

名单请求应该在init函数上发送,但我找不到它。

有人使用这个插件吗?

如何通过此插件获取名单,因为代码与XMPP专业编程书有很大不同。

提前致谢:)

2 个答案:

答案 0 :(得分:1)

我这样做了。但我同意,所有的插件都很难,因为文档很少。

看看这是否有助于任何人,因为这是非常古老的:

    /**
 * Called when connection is fully established
 */
function onConnected() {
    // SEE http://xmpp.org/rfcs/rfc6121.html#roster-login
    // the order of setting initial presence and requesting the roster is important.
    // Get the roster for the first time (we might need to keep a copy on session storage)
    connection.roster.get(onGetRoster, 0);
    // pres is an strophe helper to represent a presence status. after connecting, we tell the server we are online.
    connection.send($pres());

}

/**
 * When user just connected and gets the roster information
 */
function onGetRoster(items) {
    if (!items || items.length == 0)
        return;
    console.log(items);
}

答案 1 :(得分:0)

使用conn.roster.get(rostercb);.不要忘记设置您的存在。