首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Strophe.js :如何使用strophe.roster.js插件

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

Stack Overflow用户
提问于 2013-12-24 18:29:23
回答 2查看 3.4K关注 0票数 1

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

我找到了插件here,但是没有提供足够的文档。

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

代码语言:javascript
复制
    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 Professional编程书籍有很大的不同。

提前感谢:)

EN

回答 2

Stack Overflow用户

发布于 2014-10-22 00:18:44

我是这样做的。但我同意,所有的插件都是一场斗争,因为几乎没有文档。

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

代码语言:javascript
复制
    /**
 * 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
EN

Stack Overflow用户

发布于 2013-12-26 22:07:01

使用conn.roster.get(rostercb);。别忘了设置你的状态。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20759253

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档