Skip to content

Commit 46e7ba3

Browse files
committed
Fix unit tests
1 parent 965a210 commit 46e7ba3

File tree

14 files changed

+151
-200
lines changed

14 files changed

+151
-200
lines changed

Sources/StreamVideo/Call.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ public class Call: @unchecked Sendable, WSEventsSubscriber {
174174
currentStage.id == .joining {
175175
return stateMachine
176176
.publisher
177-
.tryCompactMap {
178-
switch $0.id {
177+
.tryMap { (stage) -> JoinCallResponse? in
178+
switch stage.id {
179179
case .joined:
180180
guard
181-
let stage = $0 as? Call.StateMachine.Stage.JoinedStage
181+
let stage = stage as? Call.StateMachine.Stage.JoinedStage
182182
else {
183183
throw ClientError()
184184
}
@@ -190,7 +190,7 @@ public class Call: @unchecked Sendable, WSEventsSubscriber {
190190
}
191191
case .error:
192192
guard
193-
let stage = $0 as? Call.StateMachine.Stage.ErrorStage
193+
let stage = stage as? Call.StateMachine.Stage.ErrorStage
194194
else {
195195
throw ClientError()
196196
}
@@ -201,7 +201,7 @@ public class Call: @unchecked Sendable, WSEventsSubscriber {
201201
}
202202
.eraseToAnyPublisher()
203203
} else {
204-
let deliverySubject = PassthroughSubject<JoinCallResponse, Error>()
204+
let deliverySubject = CurrentValueSubject<JoinCallResponse?, Error>(nil)
205205
transitionHandler(
206206
.joining(
207207
self,
@@ -224,8 +224,11 @@ public class Call: @unchecked Sendable, WSEventsSubscriber {
224224

225225
if let joinResponse = result as? JoinCallResponse {
226226
return joinResponse
227-
} else if let publisher = result as? AnyPublisher<JoinCallResponse, Error> {
228-
return try await publisher.nextValue(timeout: CallConfiguration.timeout.join)
227+
} else if let publisher = result as? AnyPublisher<JoinCallResponse?, Error> {
228+
let result = try await publisher
229+
.compactMap { $0 }
230+
.nextValue(timeout: CallConfiguration.timeout.join)
231+
return result
229232
} else {
230233
throw ClientError("Call was unable to join call.")
231234
}

Sources/StreamVideo/CallKit/CallKitService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ open class CallKitService: NSObject, CXProviderDelegate, @unchecked Sendable {
107107
private let muteActionSubject = PassthroughSubject<MuteRequest, Never>()
108108
private var muteActionCancellable: AnyCancellable?
109109
private let muteProcessingQueue = OperationQueue(maxConcurrentOperationCount: 1)
110-
private var isMuted = false
110+
private var isMuted: Bool?
111111

112112
/// Initialize.
113113
override public init() {

Sources/StreamVideo/CallStateMachine/Stages/Call+Stage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extension Call.StateMachine {
3131
var ring: Bool
3232
var notify: Bool
3333
var source: JoinSource
34-
var deliverySubject: PassthroughSubject<JoinCallResponse, Error>
34+
var deliverySubject: CurrentValueSubject<JoinCallResponse?, Error>
3535

3636
var currentNumberOfRetries = 0
3737
var retryPolicy: RetryPolicy = .fastAndSimple

Sources/StreamVideo/Utils/AudioSession/RTCAudioStore/Namespace/Middleware/RTCAudioStore+AudioDeviceModuleMiddleware.swift

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ extension RTCAudioStore {
1010

1111
/// Keeps the `AudioDeviceModule` in sync with store-driven intent and
1212
/// propagates ADM state changes back into the store.
13-
final class AudioDeviceModuleMiddleware: Middleware<RTCAudioStore.Namespace>, @unchecked Sendable {
13+
final class AudioDeviceModuleMiddleware: Middleware<RTCAudioStore.Namespace>,
14+
@unchecked Sendable {
1415

1516
private let disposableBag = DisposableBag()
1617

@@ -23,50 +24,50 @@ extension RTCAudioStore {
2324
function: StaticString,
2425
line: UInt
2526
) {
26-
guard
27-
let audioDeviceModule = state.audioDeviceModule
28-
else {
29-
return
30-
}
31-
3227
switch action {
33-
case let .setInterrupted(value):
34-
log.throwing(
35-
"Unable to process setInterrupted:\(value).",
36-
subsystems: .audioSession
37-
) {
38-
try didSetInterrupted(
39-
value,
40-
state: state,
41-
audioDeviceModule: audioDeviceModule
42-
)
28+
case .setInterrupted(let value):
29+
if let audioDeviceModule = state.audioDeviceModule {
30+
log.throwing(
31+
"Unable to process setInterrupted:\(value).",
32+
subsystems: .audioSession
33+
) {
34+
try didSetInterrupted(
35+
value,
36+
state: state,
37+
audioDeviceModule: audioDeviceModule
38+
)
39+
}
4340
}
4441

45-
case let .setShouldRecord(value):
46-
log.throwing(
47-
"Unable to process setShouldRecord:\(value).",
48-
subsystems: .audioSession
49-
) {
50-
try didSetShouldRecord(
51-
value,
52-
state: state,
53-
audioDeviceModule: audioDeviceModule
54-
)
42+
case .setShouldRecord(let value):
43+
if let audioDeviceModule = state.audioDeviceModule {
44+
log.throwing(
45+
"Unable to process setShouldRecord:\(value).",
46+
subsystems: .audioSession
47+
) {
48+
try didSetShouldRecord(
49+
value,
50+
state: state,
51+
audioDeviceModule: audioDeviceModule
52+
)
53+
}
5554
}
5655

57-
case let .setMicrophoneMuted(value):
58-
log.throwing(
59-
"Unable to process setMicrophoneMuted:\(value).",
60-
subsystems: .audioSession
61-
) {
62-
try didSetMicrophoneMuted(
63-
value,
64-
state: state,
65-
audioDeviceModule: audioDeviceModule
66-
)
56+
case .setMicrophoneMuted(let value):
57+
if let audioDeviceModule = state.audioDeviceModule {
58+
log.throwing(
59+
"Unable to process setMicrophoneMuted:\(value).",
60+
subsystems: .audioSession
61+
) {
62+
try didSetMicrophoneMuted(
63+
value,
64+
state: state,
65+
audioDeviceModule: audioDeviceModule
66+
)
67+
}
6768
}
6869

69-
case let .setAudioDeviceModule(value):
70+
case .setAudioDeviceModule(let value):
7071
log.throwing(
7172
"Unable to process setAudioDeviceModule:\(value).",
7273
subsystems: .audioSession

Sources/StreamVideo/Utils/AudioSession/RTCAudioStore/RTCAudioStore.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ final class RTCAudioStore: @unchecked Sendable {
5959

6060
// MARK: - Observation
6161

62+
func add(_ middleware: Middleware<Namespace>) {
63+
store.add(middleware)
64+
}
65+
6266
/// Emits values when the provided key path changes within the store state.
6367
/// - Parameter keyPath: The state value to observe.
6468
/// - Returns: A publisher of distinct values for the key path.

Sources/StreamVideo/Utils/Store/Store.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ final class Store<Namespace: StoreNamespace>: @unchecked Sendable {
5151
/// For observing changes, use ``publisher(_:)`` instead.
5252
var state: Namespace.State { stateSubject.value }
5353

54+
let statePublisher: AnyPublisher<Namespace.State, Never>
55+
5456
/// Unique identifier for this store instance.
5557
private let identifier: String
5658

@@ -95,7 +97,9 @@ final class Store<Namespace: StoreNamespace>: @unchecked Sendable {
9597
coordinator: StoreCoordinator<Namespace>
9698
) {
9799
self.identifier = identifier
98-
stateSubject = .init(initialState)
100+
let stateSubject = CurrentValueSubject<Namespace.State, Never>(initialState)
101+
self.stateSubject = stateSubject
102+
self.statePublisher = stateSubject.eraseToAnyPublisher()
99103
self.reducers = reducers
100104
self.middleware = []
101105
self.logger = logger

0 commit comments

Comments
 (0)