joewalnes / reconnecting-websocket

A small decorator for the JavaScript WebSocket API that automatically reconnects
MIT License
4.24k stars 970 forks source link

Detect websocket disconnecting #100

Open indapublic opened 5 years ago

indapublic commented 5 years ago

I'm using "reconnecting-websocket": "^4.1.10" in React Native project.

My code for websocket initializing:

this.ws = new ReconnectingWebSocket(this.url)
this.ws.onopen = connectedHandler
this.ws.onclose = disconnectedHandler
this.ws.onerror = disconnectedHandler
this.ws.addEventListener('error', (e) => {
    disconnectedHandler()
})
this.ws.addEventListener('close', (e) => {
    disconnectedHandler()
})
this.ws.addEventListener('open', (e) => {
    connectedHandler()
})

So I will call disconnectedHandler for close and error events.

But those events not fired when I lost my connection

screen shot 2018-12-08 at 00 48 01