atmosphere icon indicating copy to clipboard operation
atmosphere copied to clipboard

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

Open PavelR577 opened this issue 14 years ago • 12 comments

  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)

PavelR577 avatar Jul 25 '12 15:07 PavelR577

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).

jfarcand avatar Jul 25 '12 20:07 jfarcand

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 avatar Jul 26 '12 06:07 PavelR577

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)

PavelR577 avatar Jul 26 '12 06:07 PavelR577

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?

jfarcand avatar Jul 26 '12 12:07 jfarcand

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)

PavelR577 avatar Jul 26 '12 12:07 PavelR577

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 avatar Jul 26 '12 12:07 jfarcand

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

"

PavelR577 avatar Jul 30 '12 15:07 PavelR577

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: https://github.com/Atmosphere/atmosphere/issues/529#issuecomment-7371523

jfarcand avatar Aug 27 '12 19:08 jfarcand

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.

hapali avatar Dec 14 '12 07:12 hapali

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

jfarcand avatar Dec 14 '12 19:12 jfarcand

@jfarcand I will give it a try

hapali avatar Dec 17 '12 07:12 hapali

Fixed in 1.0.0.RC1

jfarcand avatar Mar 25 '13 19:03 jfarcand