Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jquery] when websocket is reconnected I have no event fired #529

Closed
PavelR577 opened this issue Jul 25, 2012 · 12 comments
Closed

[jquery] when websocket is reconnected I have no event fired #529

PavelR577 opened this issue Jul 25, 2012 · 12 comments

Comments

@PavelR577
Copy link

  1. open web socket
  2. close server - websocket is disconnected and the onClose event is invoked (and then the onClose and onReconnect is invoked in a loop)
  3. start server
  4. websocket is reconnected but no event is fired

(basiclly I just want to create an icon that will show if we're connected or not just like messenger apps)

@jfarcand
Copy link
Member

Actually it works all the time for me. Just tested with atmosphere-chat.war and Chrome. Closing as not a bug, if you can share your latest war privately I will take a look (haven't yet has a chance to look at your disconnect issue).

@PavelR577
Copy link
Author

what event should fire after the reconnect? I do see that the reconnect is called and tries to reconnect but after is reconnects - no event is fired.

By the way - is it possible to add a simple method that will return if the websocket is connected or not? (or just add a property inside the request object)

@PavelR577
Copy link
Author

I've also went over the code and if you go to line 970:

if (!webSocketOpened) {
_open('opening', "websocket", _request);
}

webSocketOpened = true;

then after the first connection it wont go into the onOpen event cause the webSocketOpened = true; will stay always true.
removing the "if" fixes the issue - ie:

//if (!webSocketOpened) {
_open('opening', "websocket", _request);
//}

Please double check and let me know. (tested both on Chrome and firefox with beta4)

@jfarcand
Copy link
Member

That's expected. You will get the re-opening event and you don't want to get the 'open' again. Why do you specifically needs 'opening' events?

@PavelR577
Copy link
Author

well - I want to show an icon to the user that will show if he's connected or not.

So this is the scenario:

  1. users enters page - icon goes green (OK)
  2. server crashed/websocket disconnected- icon goes red (OK)
  3. server restarted and websocket reopened- I have no way of knowing this and I can't turn the icon back to green. (ISSUE)

@jfarcand
Copy link
Member

You can by catching the re-opening events. As an example, just write:

    request.onReconnect = function (request, response) {
    };

but I see you point, e.g you want to get the event at the same moment you are getting the 'onpening' events. Let me thing of it.

@jfarcand jfarcand reopened this Jul 26, 2012
@PavelR577
Copy link
Author

solved it like so (line 971):
"
if (!webSocketOpened) {
_open('opening', "websocket", _request);
}else{
_request.onOpen(_request);
}

"

@jfarcand
Copy link
Member

I agree it will works for your case, but it will break other transport
logic IMO. Another events is needed here to be invoked, for all
transport, when the physical connection is made (similar to 'open').
Looking.

On 12-07-30 8:25 AM, poi212003 wrote:

solved it like so (line 971):
"
if (!webSocketOpened) {
_open('opening', "websocket", _request);
}else{
_request.onOpen(_request);
}

"


Reply to this email directly or view it on GitHub:
#529 (comment)

@hapali
Copy link

hapali commented Dec 14, 2012

I have the same issue. With the current atmosphere.js its very hard to track when a connection is actually successfully opened.

You know when it's opening. You can only assume that: if after the opOpen you dont get onError, onClose or onReconnect you have a "good" connection. Same story with onReconnect.

I want also translate the state of the request (with any transport): we have now opening, closed, reconnecting and error. But 'opened' state is missing. Another issue is that if you have some post connect code that you want to execute when connection is made and post connect relies on websocket or comet connections you get lots of issues if atmosphere fails to open or reconnect.

@jfarcand
Copy link
Member

@hapali It's pretty hard to implement what you want without writing a protocol on top of Atmosphere. I'm open to contribution :-)

@hapali
Copy link

hapali commented Dec 17, 2012

@jfarcand I will give it a try

@jfarcand
Copy link
Member

Fixed in 1.0.0.RC1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants