Get SID & RID using strophe.js
How can I get SID and RID when connecting to XMPP server using strophejs? I am using Ejabbered as an XMPP server.
Here is my code
$(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 a value.
I checked this question, XMPP: Get BOSH Session ID and RID
but there is "undefined" in the comments - the result!
+3
source to share
1 answer
I am getting the RID and SID from my connection stanzas by adding the connection.xmlOutput function. This makes it possible to preview the outgoing stanza before sending. Here's 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
}
};
You can also access the RID and SID properties from the connection ._proto
, ex:
connection._proto.rid
This may be related: https://github.com/jcbrand/converse.js/issues/180
+5
source to share