Merge pull request #360 from vector-im/dbkr/consistent_sort

Sort call feeds consistently when choosing active speaker
This commit is contained in:
David Baker 2022-06-01 10:12:56 +01:00 committed by GitHub
commit 1860eaae7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,6 +30,21 @@ 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. 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 activeSpeakerFeed = null;
let highestPowerLevel = null; let highestPowerLevel = null;
for (const feed of activeSpeakerFeeds) { for (const feed of activeSpeakerFeeds) {