Skip to content

Instantly share code, notes, and snippets.

@mattheworiordan
Last active July 12, 2016 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattheworiordan/82d6777d8ee38870dd8cbab67153981c to your computer and use it in GitHub Desktop.
Save mattheworiordan/82d6777d8ee38870dd8cbab67153981c to your computer and use it in GitHub Desktop.
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