Angular2 - How to close WebSocketSubject underlying socket

Viewed 3834

Is there a way to obtain the socket being subscribed by WebSocketSubject?

When a certain condition happens I need to close the underlying socket.

I tried to close it by complete() but it didn't close the socket. The unsubscribed doesn't work either.

Could anybody help me? Or point me in the right direction?

4 Answers

More accurate way is to call complete() on WebSocketSubject. But there is one more solution. You can obtain socket using code like this. It`s bad, but works too.

var wrapper: any = subject;
wrapper._socket.close();
Related