I'm using native methods provided by WebSocket API.
I'm wondering if I need to remove event listeners because removeEventListener
method is not mentioned in the link nor in the MDN example code for websockets.
I'm using event methods like this:
const ws = new WebSocket(url);
ws.onopen = () => {}
In addition I'm wondering if I need to remove event listeners if I'm closing the connection with ws.close()
method I suppose it will remove the listeners anyway as it's cleaning up.
You would have to remove the event listeners manually. The fact is that added listeners will remain active on the element until they are destroyed or they are removed manually in modern browsers. You can try testing if the events are fired after the web socket connection has been closed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With