Created
April 22, 2022 13:13
-
-
Save thisisjofrank/bc0415c85c2bcb1c376447fb58b6cc59 to your computer and use it in GitHub Desktop.
If there is no leader, we sort the members array alphabetically, using the clientId property of each PresenceMessage:
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
... | |
const sortedMembers = members.sort( | |
(a, b) => (a.connectionId as any) - (b.connectionId as any) | |
); | |
if (sortedMembers[0].clientId === this.id) { | |
await this.channel.presence.update("leader"); | |
this.onElection(this.channel); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment