Skip to content

Commit

Permalink
Merge pull request #360 from vector-im/dbkr/consistent_sort
Browse files Browse the repository at this point in the history
Sort call feeds consistently when choosing active speaker
  • Loading branch information
dbkr authored Jun 1, 2022
2 parents 925a909 + 771424c commit 1860eaa
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/room/usePTT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ function getActiveSpeakerFeed(
): CallFeed | null {
const activeSpeakerFeeds = feeds.filter((f) => !f.isAudioMuted());

// make sure the feeds are in a deterministic order so every client picks
// the same one as the active speaker. The custom sort function sorts
// by user ID, so needs a collator of some kind to compare. We make a
// specific one to help ensure every client sorts the same way
// although of course user IDs shouldn't contain accented characters etc.
// anyway).
const collator = new Intl.Collator("en", {
sensitivity: "variant",
usage: "sort",
ignorePunctuation: false,
});
activeSpeakerFeeds.sort((a: CallFeed, b: CallFeed): number =>
collator.compare(a.userId, b.userId)
);

let activeSpeakerFeed = null;
let highestPowerLevel = null;
for (const feed of activeSpeakerFeeds) {
Expand Down

0 comments on commit 1860eaa

Please sign in to comment.