Channel breakdown detection in js

Tags: #<Tag:0x00007f1142980c38> #<Tag:0x00007f1142980af8>



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.


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.