strophejs icon indicating copy to clipboard operation
strophejs copied to clipboard

Strophe Http-bind runs every second - ejabberd

Open devendrawebdeveloper opened this issue 7 years ago • 7 comments

I am using strophe for chat,"Connect" function is working fine. After that on page load, I am using attach function but after attached, Strophe Http-bind runs every second with stanza.

Request:-

<body rid="362421498" sid="0301cbe60c19d96a4e71f9dc6943ee774938cf48" xmlns="http://jabber.org/protocol/httpbind"/>  

Response:-

<body xmlns='http://jabber.org/protocol/httpbind'/>

Every request running 2 times with same RID.

Code:-

        var sid = localStorage.getItem('sid');
		var rid = localStorage.getItem('rid');
		var jid = localStorage.getItem('jid');
		if(sid && rid && jid){
			jQuery(document).trigger('attach', {
				jid: jid,
				rid: rid,
				sid: sid,
			});
		}else{
			jQuery(document).trigger('connect', {
				jid: userdata.eusername.toLowerCase(),
				password: userdata.password
			});
		}

Thank you in advance.

devendrawebdeveloper avatar Apr 15 '19 09:04 devendrawebdeveloper

I guess this solves your issue: http://strophe.im/strophejs/doc/1.3.0/files/strophe-js.html#Strophe.Connection.restore

sualko avatar Apr 15 '19 10:04 sualko

So first we need to use restore function then attach function. Am i right?

devendrawebdeveloper avatar Apr 15 '19 12:04 devendrawebdeveloper

This function is only useful in conjunction with providing the “keepalive”:true option when instantiating a new Strophe.Connection.

I guess something like this should work (untested):

var conn = new Strophe.Connection('/http-bind/', {
   keepalive: true,
});

try {
  conn.restore(JID);
} catch() {
  conn.start(....);
}

Maybe you get an idea what restore does, if you look at the code: https://github.com/strophe/strophejs/blob/ac043ff0c13979ead61f94d19144f81e1dbeafe0/src/core.js#L1834-L1869

https://github.com/strophe/strophejs/blob/ac043ff0c13979ead61f94d19144f81e1dbeafe0/src/bosh.js#L295-L336

sualko avatar Apr 15 '19 13:04 sualko

@sualko Thankyou But it is not working .Please find the attachment for more detail.

If you have any idea? continous request send multiple request with same Rid

devendrawebdeveloper avatar Apr 15 '19 18:04 devendrawebdeveloper

@devendrawebdeveloper Are you using keepalive and restore like @sualko suggested?

That's the best way to reattach to an existing session.

Looking at the network traffic, you're sending the same RID with every request, this is why it's not working for you. If you use restore then this won't happen, so I'm quite sure the problem is in your code and not in Strophe.

So first we need to use restore function then attach function.

No, you shouldn't call attach at all. Look at the code snippet that @sualko pasted. Also read the relevant docs: http://strophe.im/strophejs/doc/1.3.0/files/strophe-js.html#Strophe.Connection.restore

jcbrand avatar Apr 16 '19 10:04 jcbrand

I am using restore function.

devendrawebdeveloper avatar Apr 16 '19 10:04 devendrawebdeveloper

Your answer is basically useless, since we don't know what else you are doing as well. You'll need to provide more information to show that this is an issue with Strophe.

I'm personally averse to providing general debugging support to people in the Github issue trackers. The issue tracker should be for bug reports and feature requests, not to get experts to help you debug your code.

jcbrand avatar Apr 16 '19 11:04 jcbrand