Skip to content

Instantly share code, notes, and snippets.

@thisisjofrank
Created April 22, 2022 13:12
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 thisisjofrank/2e7283e81bebeaf03baed01cf0099369 to your computer and use it in GitHub Desktop.
Save thisisjofrank/2e7283e81bebeaf03baed01cf0099369 to your computer and use it in GitHub Desktop.
The onPresenceChanged callback will be called when a client joins or leaves the channel. Whenever this happens, we retrieve the latest full presence set from the channel instance (which is cached), trigger the election process, and finally call the onSwarmPresenceChanged callback.
private async onPresenceChanged() {
const members = await this.channel.presence.get();
this.ensureLeaderElected(members);
this.onSwarmPresenceChanged(members);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment