问题描述
我如何获得 SID &使用 strophejs 连接到 XMPP 服务器时的 RID ?我使用 Ejabbered 作为 XMPP 服务器.
How can I get the SID & RID when connecting to a XMPP server using strophejs ? I am using Ejabbered as the XMPP server.
这是我的代码
$(document).bind('connect', function (ev, data) {
var conn = new Strophe.Connection('http://localhost:5280/http-bind');
conn.connect(data.jid, data.password, function (status) {
if (status === Strophe.Status.CONNECTED) {
$(document).trigger('connected');
} else if (status === Strophe.Status.DISCONNECTED) {
$(document).trigger('disconnected');
}
});
Gab.connection = conn;
});
$(document).bind('connected', function () {
---------------------------------
---------------------------------
console.log(Gab.connection.jid); // Got jid
console.log(Gab.connection.rid); // Value is undefined
console.log(Gab.connection.sid); // value is undefined
});
我已经尝试过上面的代码.但未定义为值.
I have tried the above code. But getting undefined as value.
我已经检查了这个问题,XMPP:检索 BOSH 会话 ID 和 RID
I have checked this question, XMPP: retrieving BOSH Session ID and RID
但在那里的评论中,'undefined' 是结果!
but in the comments there, 'undefined' is the result!
推荐答案
我通过向 connection.xmlOutput 添加一个函数,从我的 strophe 连接中获取 RID 和 SID.这提供了在发送之前查看传出节的能力.下面是一个例子:
I get the RID and SID from my strophe connection by adding a function to connection.xmlOutput. This gives the ability to view the outgoing stanza's before they're sent. Here is an example:
connection.xmlOutput = function (e) {
if (IS_CONNECTED) {
LAST_USED_RID = $(e).attr('rid');
LAST_USED_SID = $(e).attr('sid');
log(' XMLOUTPUT INFO - OUTGOING RID=' + LAST_USED_RID + ' [SID=' + LAST_USED_SID + ']');
//log(' XMLOUTPUT INFO - OUTGOING XML = \n'+e.outerHTML);
//set some variables to keep track of our rid and sid
}
};
您也可以从连接的 ._proto
访问 RID 和 SID 属性,例如:
You may also be able to access the RID and SID properties from connection's ._proto
, ex:
connection._proto.rid
这可能是相关的:https://github.com/jcbrand/converse.js/issues/180
这篇关于获取 SID &使用 strophe.js 的 RID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!