Last active
July 12, 2016 14:09
-
-
Save mattheworiordan/82d6777d8ee38870dd8cbab67153981c to your computer and use it in GitHub Desktop.
v0.8 channel attach example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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