我在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 Professional编程书籍有很大的不同。
提前感谢:)
发布于 2014-10-22 00:18:44
我是这样做的。但我同意,所有的插件都是一场斗争,因为几乎没有文档。
看看这是否对任何人有帮助,因为这是非常古老的:
/**
* 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);
}发布于 2013-12-26 22:07:01
使用conn.roster.get(rostercb);。别忘了设置你的状态。
https://stackoverflow.com/questions/20759253
复制相似问题