Hi,
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.
Hi,
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"))
or
channel.onError(() => console.log("there was an error!"))
channel.onClose(() => console.log("the channel has gone away gracefully"))
See https://github.com/phoenixframework/phoenix/blob/master/assets/js/phoenix.js#L68-L95 for more info about different socket and channel hooks.