angular-websocket icon indicating copy to clipboard operation
angular-websocket copied to clipboard

Tell the onClose handler how many reconnects were tried

Open kevinrenskers opened this issue 11 years ago • 0 comments

Currently when the connection is closed it tries to reconnect and on success calls this code:

$WebSocket.prototype._onOpenHandler = function _onOpenHandler(event) {
    this._reconnectAttempts = 0;
    this.notifyOpenCallbacks(event);
    this.fireQueue();
};

A couple of weird things. I thought that this._reconnectAttempts is a configuration option, where you can tell the library how often to try to reconnect (since you can pass it along as options.reconnectAttempts), but it turns out that it's a counter that controls the reconnect delay and stuff. Why would I want to pass this is as an option? Would a maxReconnectAttempts maybe make sense instead?

The second thing: should it maybe be reset after calling this.notifyOpenCallbacks(event) so that my onOpen handler knows if it's called because of an initial connection or a reconnect? Right now I don't know the difference between an onOpen and an onReconnect, so to speak (which would be a nice handler to support btw).

kevinrenskers avatar Feb 06 '15 13:02 kevinrenskers