afrad / angular2-websocket

Websocket wrapper for angular2 based on angular-websocket
Apache License 2.0
210 stars 84 forks source link

Interrupt reconnectAttempts manually #87

Closed mburger81 closed 6 years ago

mburger81 commented 7 years ago

If we leave component we can close WebSocket fine and anything is as expected. The problem is if the WebSocket is not connected and we set {"reconnectIfNotNormalClose": true} the Websocket could not by closed or interrupted.

On leaving the component we do this

            console.log('#close 1: ', this.ws.getReadyState());
            console.log('#close 2: ', this.ws.close(true));
            console.log('#close 3: ', this.ws);
            console.log('#close 4: ', this.ws.getReadyState());

we can see before set close command the readyState is 0 which means connecting and after forsce the close the state is 3 which means closed. But the problem is, also after leaving the component and closed the websocket, the websocket is still attempting to reconnect the websocket.

close method could handle something like this:

$WebSocket.prototype.close = function (force) {
        if (force === void 0) { force = false; }
        if (force || !this.socket.bufferedAmount) {
            this.socket.close(this.normalCloseCode);

            // NEW CODE
            this.config.reconnectIfNotNormalClose = false
            // NEW CODE
        }
        return this;
    };
mburger81 commented 6 years ago

the PR #93 should resolve this please merge and release it thx

mburger81 commented 6 years ago

closed by release 0.9.5