Sort call feeds consistently when choosing active speaker

This commit is contained in:
David Baker 2022-05-30 12:14:25 +01:00
parent 5c4bab2a8a
commit 1ff9073a1a

View file

@ -30,6 +30,17 @@ function getActiveSpeakerFeed(
): CallFeed | null { ): CallFeed | null {
const activeSpeakerFeeds = feeds.filter((f) => !f.isAudioMuted()); 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
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 activeSpeakerFeed = null;
let highestPowerLevel = null; let highestPowerLevel = null;
for (const feed of activeSpeakerFeeds) { for (const feed of activeSpeakerFeeds) {