Reputation: 105
How can I get the SID & RID when connecting to a XMPP server using strophejs ? I am using Ejabbered as the 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 value.
I have checked this question, XMPP: retrieving BOSH Session ID and RID
but in the comments there, 'undefined' is the result!
Upvotes: 3
Views: 2679
Reputation: 873
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
}
};
You may also be able to access the RID and SID properties from connection's ._proto
, ex:
connection._proto.rid
This may be related: https://github.com/jcbrand/converse.js/issues/180
Upvotes: 5