PatrickJS / angular-websocket

:arrow_upper_left: The missing Angular WebSocket module for connecting client applications to servers by @AngularClass
https://angularclass.github.io/angular-websocket
MIT License
1.22k stars 194 forks source link

Reconnecting even after a close() #89

Open lionelB opened 8 years ago

lionelB commented 8 years ago

Hello,

I'm having an issue using this lib. when I do .close() without any parameter, servers send a frame with no code which is in returned, interpreted by browsers as a 'code:1005' as no code given for closing. And since the code is not 1000 , the library try to reconnect.

var ws = new WebSocket("ws://echo.websocket.org");
ws.onopen = (e) => console.log(e);
ws.onclose = (e) => console.log(e);
ws.close()
// { target: WebSocket, isTrusted: true, wasClean: true, code: 1005, reason: "", currentTarget: WebSocket, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, timeStamp: 1467967416163584 }

to retrieve a 1000 code, we have to send it as a close reason. ws.close(1000) Unfortunatly, the $websocket lib doesn't allow to send a code on close (nor a reason). I can make a PR for the changes, but I don't know if it's better to check 1000 and 1005 code for normal close, since we can't send code, or, if we add other parameters to the close().

BT-Wolf-00 commented 7 years ago

I was able to get around this bug by calling close (with code) on the underlying socket: this.socket.socket.close(1000, "Client closed socket");

It would be nice to have the library updated to include this.

lengfo commented 5 years ago

same issue