Skip to content

Commit

Permalink
[Fix]CleanUp active videoCapturing and screenSharing sessions (#636)
Browse files Browse the repository at this point in the history
  • Loading branch information
ipavlidakis authored Jan 15, 2025
1 parent 66f077e commit 6e2eab4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### 🔄 Changed

### 🐞 Fixed
- Fix an issue that was causing the video capturer to no be cleaned up when the call was ended, causing the camera access system indicator to remain on while the `CallEnded` screen is visible. [#636](https://github.com/GetStream/stream-video-swift/pull/636)

# [1.15.0](https://github.com/GetStream/stream-video-swift/releases/tag/1.15.0)
_January 14, 2025_

Expand Down
2 changes: 2 additions & 0 deletions Sources/StreamVideo/WebRTC/v2/WebRTCStateAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ actor WebRTCStateAdapter: ObservableObject, StreamAudioSessionAdapterDelegate {
/// Cleans up the WebRTC session by closing connections and resetting
/// states.
func cleanUp() async {
screenShareSessionProvider.activeSession = nil
videoCaptureSessionProvider.activeSession = nil
peerConnectionsDisposableBag.removeAll()
await publisher?.close()
await subscriber?.close()
Expand Down
46 changes: 38 additions & 8 deletions StreamVideoTests/WebRTC/v2/WebRTCStateAdapter_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,35 @@ import StreamWebRTC

final class WebRTCStateAdapter_Tests: XCTestCase, @unchecked Sendable {

private static var videoConfig: VideoConfig! = .dummy()

private lazy var user: User! = .dummy()
private lazy var apiKey: String! = .unique
private lazy var callCid: String! = .unique
private lazy var videoConfig: VideoConfig! = .dummy()
private lazy var rtcPeerConnectionCoordinatorFactory: MockRTCPeerConnectionCoordinatorFactory! = .init()
private lazy var screenShareSessionProvider: ScreenShareSessionProvider! = .init()
private lazy var subject: WebRTCStateAdapter! = .init(
user: user,
apiKey: apiKey,
callCid: callCid,
videoConfig: videoConfig,
rtcPeerConnectionCoordinatorFactory: rtcPeerConnectionCoordinatorFactory,
screenShareSessionProvider: screenShareSessionProvider
videoConfig: Self.videoConfig,
rtcPeerConnectionCoordinatorFactory: rtcPeerConnectionCoordinatorFactory
)

// MARK: - Lifecycle

override func tearDown() {
subject = nil
screenShareSessionProvider = nil
rtcPeerConnectionCoordinatorFactory = nil
videoConfig = nil
callCid = nil
apiKey = nil
user = nil
super.tearDown()
}

override class func tearDown() {
videoConfig = nil
super.tearDown()
}

// MARK: - audioSession

func test_audioSession_delegateWasSetAsExpected() async throws {
Expand Down Expand Up @@ -368,6 +369,7 @@ final class WebRTCStateAdapter_Tests: XCTestCase, @unchecked Sendable {
let sfuStack = MockSFUStack()
sfuStack.setConnectionState(to: .connected(healthCheckInfo: .init()))
await subject.set(sfuAdapter: sfuStack.adapter)
let screenShareSessionProvider = await subject.screenShareSessionProvider
screenShareSessionProvider.activeSession = .init(
localTrack: await subject.peerConnectionFactory.mockVideoTrack(forScreenShare: true),
screenSharingType: .inApp,
Expand Down Expand Up @@ -436,6 +438,34 @@ final class WebRTCStateAdapter_Tests: XCTestCase, @unchecked Sendable {
await assertEqualAsync(await subject.participantPins, [])
}

func test_cleanUp_shouldStopActiveCaptureSession() async throws {
let mockVideoCapturer = MockStreamVideoCapturer()
let videoCaptureSessionProvider = await subject.videoCaptureSessionProvider
videoCaptureSessionProvider.activeSession = .init(
position: .front,
localTrack: PeerConnectionFactory.mock().mockVideoTrack(forScreenShare: false),
capturer: mockVideoCapturer
)

await subject.cleanUp()

await fulfillment { mockVideoCapturer.timesCalled(.stopCapture) > 0 }
}

func test_cleanUp_shouldStopActiveScreemShareSession() async throws {
let mockVideoCapturer = MockStreamVideoCapturer()
let screenShareSessionProvider = await subject.screenShareSessionProvider
screenShareSessionProvider.activeSession = .init(
localTrack: PeerConnectionFactory.mock().mockVideoTrack(forScreenShare: true),
screenSharingType: .inApp,
capturer: mockVideoCapturer
)

await subject.cleanUp()

await fulfillment { mockVideoCapturer.timesCalled(.stopCapture) > 0 }
}

// MARK: - cleanUpForReconnection

func test_cleanUpForReconnection_shouldResetPropertiesForReconnection() async throws {
Expand Down

0 comments on commit 6e2eab4

Please sign in to comment.