Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
v0.8 channel attach example
function reattach(channel) {
channel.attach();
/* Example when using presence on the channel */
channel.presence.enter();
}
/* Connection state changes can trigger channels to become detached
Automatically re-attach channels, nothing will happen if already attached */
client.connection.on('connected', function() {
for (let channelName in client.channels.all) {
let channel = client.channels.get(channelName);
reattach(channel);
}
});
/* If a channel becomes detached due to channel failure (some edge cases exist)
You should explicitly re-attach the channel if you are connected */
channel.on('detached', function() {
if (client.connection.state === 'connected') {
reattach(channel);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.