From 1ff9073a1afc038fd0913d25dd3b68eb2323a4fb Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 30 May 2022 12:14:25 +0100 Subject: [PATCH 1/2] Sort call feeds consistently when choosing active speaker --- src/room/usePTT.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/room/usePTT.ts b/src/room/usePTT.ts index 5965c5435..cc4214094 100644 --- a/src/room/usePTT.ts +++ b/src/room/usePTT.ts @@ -30,6 +30,17 @@ 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 + 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) { From 771424cbf0d266d95543bb4bc84a058570d777ac Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 1 Jun 2022 10:11:02 +0100 Subject: [PATCH 2/2] Expand comment --- src/room/usePTT.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/room/usePTT.ts b/src/room/usePTT.ts index cc4214094..3446ff61f 100644 --- a/src/room/usePTT.ts +++ b/src/room/usePTT.ts @@ -31,7 +31,11 @@ function getActiveSpeakerFeed( 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 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",