Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Foundation
public struct OwnCapabilitiesAudioSessionPolicy: AudioSessionPolicy {

@Injected(\.applicationStateAdapter) private var applicationStateAdapter
@Injected(\.currentDevice) private var currentDevice

/// Initializes a new `OwnCapabilitiesAudioSessionPolicy` instance.
public init() {}
Expand Down
4 changes: 4 additions & 0 deletions Sources/StreamVideo/Utils/CurrentDevice/CurrentDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ public final class CurrentDevice: @unchecked Sendable {
self.deviceType = currentDeviceProvider()
}
}

func didUpdate(_ deviceType: DeviceType) {
self.deviceType = deviceType
}
}

extension CurrentDevice: InjectionKey {
Expand Down
4 changes: 3 additions & 1 deletion Sources/StreamVideo/Utils/Logger/Logger+WebRTC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import StreamWebRTC
extension Logger {

public enum WebRTC {
public enum LogMode { case none, validFilesOnly, all }
public enum LogMode: Sendable { case none, validFilesOnly, all }

public nonisolated(unsafe) static var mode: LogMode = .all {
didSet { RTCLogger.default.didUpdate(mode: mode) }
Expand Down Expand Up @@ -69,6 +69,8 @@ extension Logger.WebRTC {
}

guard mode != .none else {
logger.stop()
isRunning = false
return
}

Expand Down
4 changes: 0 additions & 4 deletions StreamVideo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,6 @@
40B31AA82D10594F005FB448 /* PublishOptions+Dummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B31AA72D10594F005FB448 /* PublishOptions+Dummy.swift */; };
40B31AA92D10594F005FB448 /* PublishOptions+Dummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B31AA72D10594F005FB448 /* PublishOptions+Dummy.swift */; };
40B3E53C2DBBAF9500DE8F50 /* ProximityMonitor_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B3E53B2DBBAF9500DE8F50 /* ProximityMonitor_Tests.swift */; };
40B3E53E2DBBB0AB00DE8F50 /* CurrentDevice+Dummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B3E53D2DBBB0AB00DE8F50 /* CurrentDevice+Dummy.swift */; };
40B3E5402DBBB6D900DE8F50 /* MockProximityMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B3E53F2DBBB6D900DE8F50 /* MockProximityMonitor.swift */; };
40B3E5422DBBB83A00DE8F50 /* ProximityManager_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B3E5412DBBB83A00DE8F50 /* ProximityManager_Tests.swift */; };
40B3E5442DBBB99200DE8F50 /* MockProximityPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B3E5432DBBB99200DE8F50 /* MockProximityPolicy.swift */; };
Expand Down Expand Up @@ -2299,7 +2298,6 @@
40B284E22D52423B0064C1FE /* AVAudioSessionCategory+Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AVAudioSessionCategory+Convenience.swift"; sourceTree = "<group>"; };
40B31AA72D10594F005FB448 /* PublishOptions+Dummy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PublishOptions+Dummy.swift"; sourceTree = "<group>"; };
40B3E53B2DBBAF9500DE8F50 /* ProximityMonitor_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProximityMonitor_Tests.swift; sourceTree = "<group>"; };
40B3E53D2DBBB0AB00DE8F50 /* CurrentDevice+Dummy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CurrentDevice+Dummy.swift"; sourceTree = "<group>"; };
40B3E53F2DBBB6D900DE8F50 /* MockProximityMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockProximityMonitor.swift; sourceTree = "<group>"; };
40B3E5412DBBB83A00DE8F50 /* ProximityManager_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProximityManager_Tests.swift; sourceTree = "<group>"; };
40B3E5432DBBB99200DE8F50 /* MockProximityPolicy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockProximityPolicy.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7077,7 +7075,6 @@
40FAAC8A2DDCB488007BF93A /* MockConsumableBucketItemTransformer.swift */,
40AAD1902D2EF18A00D10330 /* MockCaptureDevice.swift */,
40F1017F2D5D078800C49481 /* MockAudioSessionPolicy.swift */,
40B3E53D2DBBB0AB00DE8F50 /* CurrentDevice+Dummy.swift */,
40D75C5B2E438633000E0438 /* AVAudioSessionRouteDescription+Dummy.swift */,
4019A2862E43565A00CE70A4 /* MockAudioSession.swift */,
4019A2882E4357B200CE70A4 /* MockRTCAudioStore.swift */,
Expand Down Expand Up @@ -9412,7 +9409,6 @@
40B31AA92D10594F005FB448 /* PublishOptions+Dummy.swift in Sources */,
842747F129EED88800E063AD /* InternetConnection_Tests.swift in Sources */,
40C9E4552C988CE100802B28 /* WebRTCJoinRequestFactory_Tests.swift in Sources */,
40B3E53E2DBBB0AB00DE8F50 /* CurrentDevice+Dummy.swift in Sources */,
84F58B9329EEB53E00010C4C /* EventMiddleware_Mock.swift in Sources */,
40FAAC892DDC9F88007BF93A /* ConsumableBucket_Tests.swift in Sources */,
40B48C2E2D14D15E002C4EAB /* StreamVideoSfuModelsPublishOption_VideoLayersTests.swift in Sources */,
Expand Down
8 changes: 4 additions & 4 deletions StreamVideoTests/CallKit/CallKitAdapterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ final class CallKitAdapterTests: XCTestCase, @unchecked Sendable {
private lazy var callKitService: MockCallKitService! = .init()
private lazy var subject: CallKitAdapter! = .init()

override func setUp() {
super.setUp()
@MainActor
override func setUp() async throws {
try await super.setUp()
InjectedValues[\.callKitPushNotificationAdapter] = callKitPushNotificationAdapter
InjectedValues[\.callKitService] = callKitService
InjectedValues[\.currentDevice] = CurrentDevice(currentDeviceProvider: { .phone })
CurrentDevice.currentValue.didUpdate(.phone)
}

override func tearDown() {
callKitPushNotificationAdapter = nil
callKitService = nil
subject = nil
InjectedValues[\.currentDevice] = CurrentDevice.currentValue
super.tearDown()
}

Expand Down
7 changes: 2 additions & 5 deletions StreamVideoTests/CallSettings/ProximityManager_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import XCTest
@MainActor
final class ProximityManager_Tests: XCTestCase, @unchecked Sendable {

private var mockCurrentDevice: CurrentDevice! = .dummy { .phone }
private lazy var mockProximityMonitor: MockProximityMonitor! = .init()
private lazy var mockCall: MockCall! = .init(.dummy())
private lazy var mockActiveCallSubject: PassthroughSubject<Call?, Never>! = .init()
Expand All @@ -19,12 +18,11 @@ final class ProximityManager_Tests: XCTestCase, @unchecked Sendable {
activeCallPublisher: mockActiveCallSubject.eraseToAnyPublisher()
)

@MainActor
override func setUp() async throws {
try await super.setUp()
CurrentDevice.currentValue = mockCurrentDevice
await fulfillment { CurrentDevice.currentValue.deviceType == .phone }
CurrentDevice.currentValue.didUpdate(.phone)
_ = mockProximityMonitor
_ = mockCurrentDevice
_ = mockCall
_ = subject
}
Expand All @@ -33,7 +31,6 @@ final class ProximityManager_Tests: XCTestCase, @unchecked Sendable {
subject = nil
mockCall = nil
mockActiveCallSubject = nil
mockCurrentDevice = nil
mockProximityMonitor = nil
CurrentDevice.currentValue = .init()
try await super.tearDown()
Expand Down
14 changes: 0 additions & 14 deletions StreamVideoTests/Mock/CurrentDevice+Dummy.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,24 @@ final class OwnCapabilitiesAudioSessionPolicyTests: XCTestCase, @unchecked Senda

private lazy var stubbedAppStateAdapter: MockAppStateAdapter! = .init()
private lazy var subject: OwnCapabilitiesAudioSessionPolicy! = .init()
private lazy var currentDeviceType: CurrentDevice.DeviceType! = CurrentDevice.DeviceType.phone
private lazy var currentDevice: CurrentDevice! = .init { self.currentDeviceType }

override func setUp() {
super.setUp()
AppStateProviderKey.currentValue = stubbedAppStateAdapter
InjectedValues[\.currentDevice] = currentDevice
_ = subject
}

override func tearDown() {
subject = nil
stubbedAppStateAdapter = nil
currentDevice = nil
InjectedValues[\.currentDevice] = CurrentDevice.currentValue
super.tearDown()
}

// MARK: - Tests for users without sendAudio capability

func testConfiguration_WhenUserCannotSendAudio_ReturnsPlaybackConfiguration() async {
// Given
currentDeviceType = .phone
await fulfilmentInMainActor { self.currentDevice.deviceType == self.currentDeviceType }
CurrentDevice.currentValue.didUpdate(.phone)
let callSettings = CallSettings(audioOn: true, videoOn: true, speakerOn: true)
let ownCapabilities: Set<OwnCapability> = [.sendVideo]

Expand All @@ -54,8 +48,7 @@ final class OwnCapabilitiesAudioSessionPolicyTests: XCTestCase, @unchecked Senda

func testConfiguration_WhenUserCanSendAudioAndAudioOn_ReturnsPlayAndRecordConfiguration() async {
// Given
currentDeviceType = .phone
await fulfilmentInMainActor { self.currentDevice.deviceType == self.currentDeviceType }
CurrentDevice.currentValue.didUpdate(.phone)
let callSettings = CallSettings(audioOn: true, videoOn: true, speakerOn: false)
let ownCapabilities: Set<OwnCapability> = [.sendAudio, .sendVideo]

Expand All @@ -80,8 +73,7 @@ final class OwnCapabilitiesAudioSessionPolicyTests: XCTestCase, @unchecked Senda

func testConfiguration_WhenUserCanSendAudioAndSpeakerOnWithEarpiece_ReturnsPlayAndRecordConfiguration() async {
// Given
currentDeviceType = .phone
await fulfilmentInMainActor { self.currentDevice.deviceType == self.currentDeviceType }
CurrentDevice.currentValue.didUpdate(.phone)
let callSettings = CallSettings(audioOn: false, videoOn: true, speakerOn: true)
let ownCapabilities: Set<OwnCapability> = [.sendAudio, .sendVideo]

Expand All @@ -106,8 +98,7 @@ final class OwnCapabilitiesAudioSessionPolicyTests: XCTestCase, @unchecked Senda

func testConfiguration_WhenUserCanSendAudioAndSpeakerOnWithoutEarpiece_ReturnsPlaybackAndRecordConfiguration() async {
// Given
currentDeviceType = .pad
await fulfilmentInMainActor { self.currentDevice.deviceType == self.currentDeviceType }
CurrentDevice.currentValue.didUpdate(.pad)
let callSettings = CallSettings(audioOn: false, videoOn: true, speakerOn: true)
let ownCapabilities: Set<OwnCapability> = [.sendAudio, .sendVideo]

Expand All @@ -126,8 +117,7 @@ final class OwnCapabilitiesAudioSessionPolicyTests: XCTestCase, @unchecked Senda

func testConfiguration_WhenUserCanSendAudioAndAudioOff_ReturnsPlaybackConfiguration() async {
// Given
currentDeviceType = .phone
await fulfilmentInMainActor { self.currentDevice.deviceType == self.currentDeviceType }
CurrentDevice.currentValue.didUpdate(.phone)
let callSettings = CallSettings(audioOn: false, videoOn: true, speakerOn: false)
let ownCapabilities: Set<OwnCapability> = [.sendAudio, .sendVideo]

Expand All @@ -148,8 +138,7 @@ final class OwnCapabilitiesAudioSessionPolicyTests: XCTestCase, @unchecked Senda

func testConfiguration_WhenVideoOffSpeakerOnBackgroundFalse_ReturnsVoiceChatMode() async {
// Given
currentDeviceType = .phone
await fulfilmentInMainActor { self.currentDevice.deviceType == self.currentDeviceType }
CurrentDevice.currentValue.didUpdate(.phone)
let callSettings = CallSettings(audioOn: true, videoOn: false, speakerOn: true)
let ownCapabilities: Set<OwnCapability> = [.sendAudio, .sendVideo]

Expand All @@ -172,8 +161,7 @@ final class OwnCapabilitiesAudioSessionPolicyTests: XCTestCase, @unchecked Senda

func testConfiguration_WhenVideoOffSpeakerFalseBackgroundFalse_ReturnsVoiceChatMode() async {
// Given
currentDeviceType = .phone
await fulfilmentInMainActor { self.currentDevice.deviceType == self.currentDeviceType }
CurrentDevice.currentValue.didUpdate(.phone)
let callSettings = CallSettings(audioOn: true, videoOn: false, speakerOn: false)
let ownCapabilities: Set<OwnCapability> = [.sendAudio, .sendVideo]

Expand All @@ -196,8 +184,7 @@ final class OwnCapabilitiesAudioSessionPolicyTests: XCTestCase, @unchecked Senda

func testConfiguration_WhenVideoOffSpeakerOnBackgroundTrue_ReturnsVoiceChatMode() async {
// Given
currentDeviceType = .phone
await fulfilmentInMainActor { self.currentDevice.deviceType == self.currentDeviceType }
CurrentDevice.currentValue.didUpdate(.phone)
stubbedAppStateAdapter.stubbedState = .background
let callSettings = CallSettings(audioOn: true, videoOn: false, speakerOn: true)
let ownCapabilities: Set<OwnCapability> = [.sendAudio, .sendVideo]
Expand All @@ -221,8 +208,7 @@ final class OwnCapabilitiesAudioSessionPolicyTests: XCTestCase, @unchecked Senda

func testConfiguration_WhenVideoOffSpeakerFalseBackgroundTrue_ReturnsVoiceChatMode() async {
// Given
currentDeviceType = .phone
await fulfilmentInMainActor { self.currentDevice.deviceType == self.currentDeviceType }
CurrentDevice.currentValue.didUpdate(.phone)
stubbedAppStateAdapter.stubbedState = .background
let callSettings = CallSettings(audioOn: true, videoOn: false, speakerOn: false)
let ownCapabilities: Set<OwnCapability> = [.sendAudio, .sendVideo]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ final class ProximityMonitor_Tests: XCTestCase, @unchecked Sendable {

@MainActor
func test_stopObservation_isActiveBecomesFalse() async {
CurrentDevice.currentValue = .dummy { .phone }
CurrentDevice.currentValue.didUpdate(.phone)
await fulfillment { CurrentDevice.currentValue.deviceType == .phone }

subject.startObservation()
Expand All @@ -76,7 +76,7 @@ final class ProximityMonitor_Tests: XCTestCase, @unchecked Sendable {
function: StaticString = #function,
line: UInt = #line
) async {
CurrentDevice.currentValue = .dummy { deviceType }
CurrentDevice.currentValue.didUpdate(deviceType)
await fulfillment { CurrentDevice.currentValue.deviceType == deviceType }
_ = subject

Expand Down