Skip to content

Commit

Permalink
[Improve]Default participants ordering (#515)
Browse files Browse the repository at this point in the history
  • Loading branch information
ipavlidakis authored Sep 9, 2024
1 parent 663bafa commit 6e12656
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
# Upcoming

### 🔄 Changed
- Updated the default sorting for Participants during a call to minimize the movement of already visible tiles [#515](https://github.com/GetStream/stream-video-swift/pull/515)

# [1.10.0](https://github.com/GetStream/stream-video-swift/releases/tag/1.10.0)
_August 29, 2024_
Expand Down
11 changes: 7 additions & 4 deletions Sources/StreamVideo/Utils/Sorting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ public typealias StreamSortComparator<Value> = (Value, Value) -> ComparisonResul
public let defaultComparators: [StreamSortComparator<CallParticipant>] = [
pinned,
screensharing,
dominantSpeaker,
ifInvisible(isSpeaking),
ifInvisible(publishingVideo),
ifInvisible(publishingAudio),
ifInvisible(combineComparators([
dominantSpeaker,
isSpeaking,
isSpeaking,
publishingVideo,
publishingAudio
])),
ifInvisible(userId)
]

Expand Down
70 changes: 70 additions & 0 deletions StreamVideoTests/Utils/Sorting_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,76 @@ final class Sorting_Tests: XCTestCase {
)
}

func test_defaultComparators_someSpeakingWhileDominantSpeakerIsVisible_orderDoesNotChange() {
let combined = combineComparators(defaultComparators)

assertSort(
[
.dummy(
hasAudio: true,
showTrack: true,
isSpeaking: true,
isDominantSpeaker: false
),
.dummy(
hasAudio: true,
showTrack: true,
isSpeaking: true,
isDominantSpeaker: false
),
.dummy(
hasAudio: true,
showTrack: true,
isSpeaking: true,
isDominantSpeaker: false
),
.dummy(
hasAudio: true,
showTrack: true,
isSpeaking: true,
isDominantSpeaker: true
)
],
comparator: combined,
expectedTransformer: { [$0[0], $0[1], $0[2], $0[3]] }
)
}

func test_defaultComparators_someSpeakingWhileDominantSpeakerIsInisible_orderChanges() {
let combined = combineComparators(defaultComparators)

assertSort(
[
.dummy(
hasAudio: true,
showTrack: true,
isSpeaking: true,
isDominantSpeaker: false
),
.dummy(
hasAudio: true,
showTrack: true,
isSpeaking: true,
isDominantSpeaker: false
),
.dummy(
hasAudio: true,
showTrack: true,
isSpeaking: true,
isDominantSpeaker: false
),
.dummy(
hasAudio: true,
showTrack: false,
isSpeaking: true,
isDominantSpeaker: true
)
],
comparator: combined,
expectedTransformer: { [$0[3], $0[0], $0[1], $0[2]] }
)
}

// MARK: - Private Helpers

private func assertSort(
Expand Down

0 comments on commit 6e12656

Please sign in to comment.