[jquery] when websocket is reconnected I have no event fired
- open web socket
- close server - websocket is disconnected and the onClose event is invoked (and then the onClose and onReconnect is invoked in a loop)
- start server
- 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)
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).
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)
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)
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?
well - I want to show an icon to the user that will show if he's connected or not.
So this is the scenario:
- users enters page - icon goes green (OK)
- server crashed/websocket disconnected- icon goes red (OK)
- server restarted and websocket reopened- I have no way of knowing this and I can't turn the icon back to green. (ISSUE)
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.
solved it like so (line 971): " if (!webSocketOpened) { _open('opening', "websocket", _request); }else{ _request.onOpen(_request); }
"
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
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 It's pretty hard to implement what you want without writing a protocol on top of Atmosphere. I'm open to contribution :-)
@jfarcand I will give it a try
Fixed in 1.0.0.RC1