Skip to content

Commit a886f74

Browse files
authored
fix(llc): Improved participant sorting based on source type (#1073)
* Improved participant sorting based on source type * changelog
1 parent 36ae8cf commit a886f74

File tree

5 files changed

+35
-14
lines changed

5 files changed

+35
-14
lines changed

packages/stream_video/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Unreleased
2+
3+
🔄 Changed
4+
- The `byParticipantSource` participant sorting now accepts a list of sources. The default sorting for `speaker` and `livestream` presets now include other ingress sources.
5+
16
## 0.11.0
27

38
🚧 Build breaking changes

packages/stream_video/lib/src/call/call.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2762,7 +2762,7 @@ class Call {
27622762
AudioConstraints? constraints,
27632763
}) async {
27642764
if (enabled && !hasPermission(CallPermission.sendAudio)) {
2765-
return Result.error('Missing permission to send video');
2765+
return Result.error('Missing permission to send audio');
27662766
}
27672767

27682768
if (enabled && CurrentPlatform.isAndroid) {

packages/stream_video/lib/src/sorting/call_participant_sorting_presets.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ mixin CallParticipantSortingPresets {
2121
dominantSpeaker,
2222
ifInvisibleBy(speaking),
2323
ifInvisibleBy(byReactionType('raised-hand')),
24+
ifInvisibleBy(byVideoIngressSource()),
2425
ifInvisibleBy(publishingVideo),
2526
ifInvisibleBy(publishingAudio),
2627
]);
@@ -31,7 +32,7 @@ mixin CallParticipantSortingPresets {
3132
ifInvisibleBy(dominantSpeaker),
3233
ifInvisibleBy(speaking),
3334
ifInvisibleBy(byReactionType('raised-hand')),
34-
ifInvisibleBy(byParticipantSource(SfuParticipantSource.rtmp)),
35+
ifInvisibleBy(byVideoIngressSource()),
3536
ifInvisibleBy(publishingVideo),
3637
ifInvisibleBy(publishingAudio),
3738
byRole(['admin', 'host', 'speaker']),

packages/stream_video/lib/src/sorting/call_participant_state_sorting.dart

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,35 @@ int pinned(CallParticipantState a, CallParticipantState b) {
5555
}
5656

5757
/// A comparator factory which creates a comparator which prioritizes
58-
/// participants who are from a specific source (e.g., WebRTC, RTMP, WHIP...).
58+
/// participants who are from a specific sources (e.g., WebRTC, RTMP, WHIP...).
5959
Comparator<CallParticipantState> byParticipantSource(
60-
SfuParticipantSource source,
60+
List<SfuParticipantSource> sources,
6161
) {
62-
return (CallParticipantState a, CallParticipantState b) {
63-
if (a.participantSource == source && b.participantSource != source) {
64-
return -1;
65-
}
62+
double sourcePriority(SfuParticipantSource? source) {
63+
if (source == null) return double.maxFinite;
6664

67-
if (a.participantSource != source && b.participantSource == source) {
68-
return 1;
69-
}
65+
final index = sources.indexOf(source);
66+
return index == -1 ? double.maxFinite : index.toDouble();
67+
}
7068

69+
return (CallParticipantState a, CallParticipantState b) {
70+
final priorityA = sourcePriority(a.participantSource);
71+
final priorityB = sourcePriority(b.participantSource);
72+
if (priorityA < priorityB) return -1;
73+
if (priorityA > priorityB) return 1;
7174
return 0;
7275
};
7376
}
7477

78+
Comparator<CallParticipantState> byVideoIngressSource() {
79+
return byParticipantSource([
80+
SfuParticipantSource.rtmp,
81+
SfuParticipantSource.srt,
82+
SfuParticipantSource.whip,
83+
SfuParticipantSource.rtsp,
84+
]);
85+
}
86+
7587
/// A comparator creator which will set up a comparator which prioritizes
7688
/// participants who have a specific reaction.
7789
Comparator<CallParticipantState> byReactionType(String type) {

packages/stream_video/test/src/call/call_participant_state_sorting_test.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ import 'package:stream_video/src/sorting/call_participant_state_sorting.dart';
1515

1616
void main() {
1717
group('sorting comparators', () {
18-
test('byParticipantSource prioritizes requested source', () {
18+
test('byParticipantSource prioritizes requested sources', () {
1919
final comparator = combineComparators<CallParticipantState>([
20-
byParticipantSource(SfuParticipantSource.rtmp),
20+
byParticipantSource([
21+
SfuParticipantSource.rtmp,
22+
SfuParticipantSource.sip,
23+
]),
2124
byName,
2225
]);
2326

@@ -63,7 +66,7 @@ void main() {
6366

6467
final list = [user1, user3, user4, user2]..sort(comparator);
6568
expect(list.first, user2);
66-
expect(list.map((p) => p.name), ['user2', 'user3', 'user1', 'user4']);
69+
expect(list.map((p) => p.name), ['user2', 'user3', 'user4', 'user1']);
6770
});
6871

6972
test('byReactionType prioritizes given reaction type', () {

0 commit comments

Comments
 (0)