Channel breakdown detection in js


How can I detect in JavaScript when a Phoenix channel/socket breaks down because of network or server problems? Can I set up a callback function for this kind of events? channel.join().on(“error”, xxx) doesn’t do the trick.

1 Like

You might use

socket.onError(() => console.log("there was an error with the connection!"))
socket.onClose(() => console.log("the connection dropped"))


channel.onError(() => console.log("there was an error!"))
channel.onClose(() => console.log("the channel has gone away gracefully"))

See for more info about different socket and channel hooks.