pladaria / reconnecting-websocket

Reconnecting WebSocket. For Web, React Native, cli (Node.js)
MIT License
1.22k stars 197 forks source link

ReconnectingWebSocket much slower than WebSocket #91

Closed physicsai closed 5 years ago

physicsai commented 5 years ago

I have a simple app for asynchronous message passing, using websockets (React + Django).

If I use WebSocket, the connection opens almost instantaneously upon loading the page, whereas if I switch to ReconnectingWebSocket (that's the only change in the code and using import ReconnectingWebSocket from 'reconnecting-websocket'; ), it takes around 3-5 seconds.

Is the reason behind this delay understood?

pladaria commented 5 years ago

Hi, you can change minReconnectionDelay option

For example:

const ws = new ReconnectingWebSocket(url, '', {minReconnectionDelay: 1}); // 1 millisecond

Anyway, you're right, by default, the first connection attempt should be immediate. I will change that.

physicsai commented 5 years ago

Thank you, @pladaria. With the the minReconnectionDelay option, ReconnectingWebSocket also connects instantaneously.

quentinus95 commented 5 years ago

it would indeed be great to have the first attempt to be immediate!

curran commented 5 years ago

Yes please! Happy to come across this issue. Thanks for your work on this module!

quentinus95 commented 5 years ago

@pladaria any idea on when you could fix this?

quentinus95 commented 5 years ago

I've just opened a pull request here: #94

naggie commented 5 years ago

Wow thanks, this option has made my application go from being slow to instant!

I was relying on the reconnect method combined with a URL function to change the URL without reassociating handler. Edit: It seems this also applied to the initial connection, as specified above.

naggie commented 5 years ago

I suggest that calling the reconnect() method should reconnect immediately (like the initial connection) as it's an explicit action. The automatic reconnects should still be throttled.

Fxlr8 commented 5 years ago

Almost a year passed and a huge delay before the first connection is still here. Why is this the default behavior? I can't imagine a single use case where this will not ruin the user experience. C'mon the lib is nice, just fix this issue finally please

curran commented 5 years ago

The fix has been sitting in this open PR since Nov 2018 https://github.com/pladaria/reconnecting-websocket/pull/94 . It appears @pladaria is not maintaining the lib anymore. Does anyone know of an active fork of this project? I think that's what's needed to actually solve this, unfortunately.

pladaria commented 5 years ago

Fixed in #94