Atmosphere / atmosphere-javascript

atmosphere-javascript
Apache License 2.0
122 stars 98 forks source link

Why the _reconnectWithFallbackTransport function uses the connectTimeout instead of the reconnectInterval parameter? #271

Closed SuperPat45 closed 3 years ago

SuperPat45 commented 3 years ago

The _reconnectWithFallbackTransport function uses the connectTimeout parameter as reconnectInterval:

            function _reconnectWithFallbackTransport(errorMessage) {
                atmosphere.util.log(_request.logLevel, [errorMessage]);

                if (typeof (_request.onTransportFailure) !== 'undefined') {
                    _request.onTransportFailure(errorMessage, _request);
                } else if (typeof (atmosphere.util.onTransportFailure) !== 'undefined') {
                    atmosphere.util.onTransportFailure(errorMessage, _request);
                }

                var reconnectInterval = _request.connectTimeout === -1 ? 0 : _request.connectTimeout;
                if (_request.reconnect && _request.transport !== 'none' || _request.transport == null) {
                    _request.transport = _request.fallbackTransport;
                    _request.method = _request.fallbackMethod;
                    _response.transport = _request.fallbackTransport;
                    _response.state = '';
                    _request.fallbackTransport = 'none';
                    if (reconnectInterval > 0) {
                        _request.reconnectId = setTimeout(function () {
                            _execute();
                        }, reconnectInterval);
                    } else {
                        _execute();
                    }
                } else {
                    _onError(500, "Unable to reconnect with fallback transport");
                }
            }

Are there any reason to do this instead of use the true reconnectInterval parameter of the request ?

This would seem more logical and would allow in case the websocket is not available to reconnect in long-pooling without waiting as reconnectInterval is 0 even if connectTimeout is > 0.

jfarcand commented 3 years ago

@SuperPat45 Good point. I don't recall the reason behind connectTimeout, but clearly I fully agree with your analysis. If you can test it and send me a pull request I will do the release. Gigantic thanks as usual!