How do I catch a WebSocket connection interruption?

前端 未结 2 432
天命终不由人
天命终不由人 2020-12-31 11:07

In Firefox (at least), if you hit ESC, then it will close all open WebSockets connections. I need to capture that disconnection and try to re-connect once it\'s available ag

2条回答
  •  攒了一身酷
    2020-12-31 11:40

    You can attach a handler to the socket.onclose event. It will be called when you hit ESC and the connection is interrupted.

    See: http://jsfiddle.net/w5aAK/1/

    One problem that you can't get around at the moment is the interrupted error being output to the console. There's no way of capturing that at the moment I'm afraid.

提交回复
热议问题