Skip to content

Commit 122be21

Browse files
committed
Fixes and update to webrtc 137.0.51
1 parent 090378f commit 122be21

File tree

13 files changed

+60
-97
lines changed

13 files changed

+60
-97
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let package = Package(
2323
],
2424
dependencies: [
2525
.package(url: "https://github.com/apple/swift-protobuf.git", exact: "1.30.0"),
26-
.package(url: "https://github.com/GetStream/stream-video-swift-webrtc.git", exact: "137.0.50")
26+
.package(url: "https://github.com/GetStream/stream-video-swift-webrtc.git", exact: "137.0.51")
2727
],
2828
targets: [
2929
.target(

Sources/StreamVideo/Utils/AudioSession/AudioDeviceModule/AudioDeviceModule.swift

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -243,36 +243,45 @@ final class AudioDeviceModule: NSObject, RTCAudioDeviceModuleDelegate, Encodable
243243
)
244244
/// - Important: We can probably set this one to false when the user doesn't have
245245
/// sendAudio capability.
246-
(source as? RTCAudioDeviceModule)?.setRecordingAlwaysPreparedMode(true)
246+
(source as? RTCAudioDeviceModule)?.setRecordingAlwaysPreparedMode(false)
247247
source.prefersStereoPlayout = isPreferred
248248

249-
/// We store the mic state before we perform `InitAndStartRecording` so we can restore
250-
/// the state at the end.
251-
let isMuted = isMicrophoneMuted
252-
253-
_ = source.stopRecording()
254-
_ = source.initAndStartRecording()
255-
256-
if isPreferred {
257-
setVoiceProcessingBypassed(isPreferred)
258-
}
259-
260-
if isMuted {
261-
_ = source.setMicrophoneMuted(isMuted)
262-
}
249+
// /// We store the mic state before we perform `InitAndStartRecording` so we can restore
250+
// /// the state at the end.
251+
// let isMuted = isMicrophoneMuted
252+
//
253+
//// _ = source.stopRecording()
254+
//// _ = source.initAndStartRecording()
255+
//
256+
// if isPreferred {
257+
// setVoiceProcessingBypassed(isPreferred)
258+
// }
259+
//
260+
// if isMuted {
261+
// _ = source.setMicrophoneMuted(isMuted)
262+
// }
263263
}
264264

265265
/// Starts or stops speaker playout on the ADM, retrying transient failures.
266266
/// - Parameter isActive: `true` to start playout, `false` to stop.
267267
/// - Throws: `ClientError` when WebRTC returns a non-zero status.
268268
func setPlayout(_ isActive: Bool) throws {
269-
try RetriableTask.run(iterations: 3) {
270-
try throwingExecution("Unable to start playout") {
271-
if isActive {
272-
return source.initAndStartPlayout()
273-
} else {
274-
return source.stopPlayout()
269+
guard isActive != isPlaying else {
270+
return
271+
}
272+
if isActive {
273+
if source.isPlayoutInitialized {
274+
try throwingExecution("Unable to start playout") {
275+
source.startPlayout()
275276
}
277+
} else {
278+
try throwingExecution("Unable to initAndStart playout") {
279+
source.initAndStartPlayout()
280+
}
281+
}
282+
} else {
283+
try throwingExecution("Unable to stop playout") {
284+
source.stopPlayout()
276285
}
277286
}
278287
}
@@ -284,23 +293,18 @@ final class AudioDeviceModule: NSObject, RTCAudioDeviceModuleDelegate, Encodable
284293
guard isEnabled != isRecording else {
285294
return
286295
}
287-
288296
if isEnabled {
289-
let isMicrophoneMuted = source.isMicrophoneMuted
290-
291-
try throwingExecution("Unable to initAndStartRecording.") {
292-
source.initAndStartRecording()
293-
}
294-
295-
// After restarting the ADM it always returns with microphoneMute:false.
296-
// Here we reinstate the muted condition after restarting ADM.
297-
if isMicrophoneMuted {
298-
try throwingExecution("Unable to setMicrophoneMuted:\(isEnabled).") {
299-
source.setMicrophoneMuted(isMicrophoneMuted)
297+
if source.isRecordingInitialized {
298+
try throwingExecution("Unable to start recording") {
299+
source.startRecording()
300+
}
301+
} else {
302+
try throwingExecution("Unable to initAndStart recording") {
303+
source.initAndStartRecording()
300304
}
301305
}
302306
} else {
303-
try throwingExecution("Unable to stopRecording.") {
307+
try throwingExecution("Unable to stop recording") {
304308
source.stopRecording()
305309
}
306310
}
@@ -316,10 +320,6 @@ final class AudioDeviceModule: NSObject, RTCAudioDeviceModuleDelegate, Encodable
316320
return
317321
}
318322

319-
try throwingExecution("Unable to initAndStartRecording for setMicrophoneMuted:\(isMuted)") {
320-
source.initAndStartRecording()
321-
}
322-
323323
try throwingExecution("Unable to setMicrophoneMuted:\(isMuted)") {
324324
source.setMicrophoneMuted(isMuted)
325325
}

Sources/StreamVideo/Utils/AudioSession/AudioDeviceModule/RTCAudioDeviceModuleControlling.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ protocol RTCAudioDeviceModuleControlling: AnyObject {
1111
var observer: RTCAudioDeviceModuleDelegate? { get set }
1212
var isPlaying: Bool { get }
1313
var isRecording: Bool { get }
14+
var isPlayoutInitialized: Bool { get }
15+
var isRecordingInitialized: Bool { get }
1416
var isMicrophoneMuted: Bool { get }
1517
var isStereoPlayoutEnabled: Bool { get }
1618
var isVoiceProcessingBypassed: Bool { get set }
@@ -24,6 +26,7 @@ protocol RTCAudioDeviceModuleControlling: AnyObject {
2426
func stopPlayout() -> Int
2527
func initAndStartRecording() -> Int
2628
func setMicrophoneMuted(_ isMuted: Bool) -> Int
29+
func startRecording() -> Int
2730
func stopRecording() -> Int
2831
func refreshStereoPlayoutState()
2932
}

Sources/StreamVideo/Utils/AudioSession/CallAudioSession.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ final class CallAudioSession: @unchecked Sendable {
278278

279279
var actions: [StoreActionBox<RTCAudioStore.Namespace.Action>] = []
280280

281-
actions.append(.normal(.setShouldRecord(ownCapabilities.contains(.sendAudio))))
281+
// actions.append(.normal(.setRecording(ownCapabilities.contains(.sendAudio))))
282282
actions.append(.normal(.setMicrophoneMuted(!callSettings.audioOn || !ownCapabilities.contains(.sendAudio))))
283283

284284
actions.append(

Sources/StreamVideo/Utils/AudioSession/RTCAudioStore/Namespace/Effects/RTCAudioStore+StereoPlayoutEffect.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ extension RTCAudioStore {
4545
return
4646
}
4747

48+
/// This is important to support cases (e.g. a wired headphone) that do not trigger a valid
49+
/// route change for WebRTC causing the user to join the call without stereo and requiring
50+
/// either toggling the speaker or reconnect their wired headset.
51+
statePublisher
52+
.map(\.currentRoute)
53+
.removeDuplicates()
54+
.debounce(for: .seconds(2), scheduler: processingQueue)
55+
.sink { [weak audioDeviceModule] _ in audioDeviceModule?.refreshStereoPlayoutState() }
56+
.store(in: disposableBag)
57+
4858
audioDeviceModule
4959
.isStereoPlayoutEnabledPublisher
5060
.removeDuplicates()

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

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,6 @@ extension RTCAudioStore {
3939
}
4040
}
4141

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-
}
54-
}
55-
5642
case .setMicrophoneMuted(let value):
5743
if let audioDeviceModule = state.audioDeviceModule {
5844
log.throwing(
@@ -97,31 +83,14 @@ extension RTCAudioStore {
9783
) throws {
9884
guard
9985
state.isActive,
100-
state.shouldRecord
86+
state.isRecording
10187
else {
10288
return
10389
}
10490

105-
if value {
106-
try audioDeviceModule.setRecording(false)
107-
} else {
108-
// Restart the ADM
109-
try audioDeviceModule.setRecording(false)
110-
try audioDeviceModule.setRecording(true)
111-
}
112-
}
113-
114-
/// Starts or stops ADM recording when `shouldRecord` changes.
115-
private func didSetShouldRecord(
116-
_ value: Bool,
117-
state: RTCAudioStore.StoreState,
118-
audioDeviceModule: AudioDeviceModule
119-
) throws {
120-
guard audioDeviceModule.isRecording != value else {
121-
return
122-
}
123-
124-
try audioDeviceModule.setRecording(value)
91+
// Restart the ADM
92+
try audioDeviceModule.setRecording(false)
93+
try audioDeviceModule.setRecording(true)
12594
}
12695

12796
/// Applies the store's microphone muted state to the ADM.
@@ -131,7 +100,7 @@ extension RTCAudioStore {
131100
audioDeviceModule: AudioDeviceModule
132101
) throws {
133102
guard
134-
state.shouldRecord
103+
state.isRecording
135104
else {
136105
return
137106
}

Sources/StreamVideo/Utils/AudioSession/RTCAudioStore/Namespace/RTCAudioStore+Action.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ extension RTCAudioStore {
126126

127127
case setActive(Bool)
128128
case setInterrupted(Bool)
129-
case setShouldRecord(Bool)
130129
case setRecording(Bool)
131130
case setMicrophoneMuted(Bool)
132131
case setHasRecordingPermission(Bool)
@@ -147,9 +146,6 @@ extension RTCAudioStore {
147146
case .setInterrupted(let value):
148147
return ".setInterrupted(\(value))"
149148

150-
case .setShouldRecord(let value):
151-
return ".setShouldRecord(\(value))"
152-
153149
case .setRecording(let value):
154150
return ".setRecording(\(value))"
155151

Sources/StreamVideo/Utils/AudioSession/RTCAudioStore/Namespace/RTCAudioStore+Coordinator.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ extension RTCAudioStore {
2222
case let .setInterrupted(value):
2323
return value != state.isInterrupted
2424

25-
case let .setShouldRecord(value):
26-
return value != state.shouldRecord
27-
2825
case let .setRecording(value):
2926
return value != state.isRecording
3027

Sources/StreamVideo/Utils/AudioSession/RTCAudioStore/Namespace/RTCAudioStore+State.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ extension RTCAudioStore {
219219

220220
var isActive: Bool
221221
var isInterrupted: Bool
222-
var shouldRecord: Bool
223222
var isRecording: Bool
224223
var isMicrophoneMuted: Bool
225224
var hasRecordingPermission: Bool
@@ -235,7 +234,6 @@ extension RTCAudioStore {
235234
" { " +
236235
"isActive:\(isActive)" +
237236
", isInterrupted:\(isInterrupted)" +
238-
", shouldRecord:\(shouldRecord)" +
239237
", isRecording:\(isRecording)" +
240238
", isMicrophoneMuted:\(isMicrophoneMuted)" +
241239
", hasRecordingPermission:\(hasRecordingPermission)" +
@@ -250,7 +248,6 @@ extension RTCAudioStore {
250248
private enum CodingKeys: String, CodingKey {
251249
case isActive
252250
case isInterrupted
253-
case shouldRecord
254251
case isRecording
255252
case isMicrophoneMuted
256253
case hasRecordingPermission
@@ -265,7 +262,6 @@ extension RTCAudioStore {
265262
var container = encoder.container(keyedBy: CodingKeys.self)
266263
try container.encode(isActive, forKey: .isActive)
267264
try container.encode(isInterrupted, forKey: .isInterrupted)
268-
try container.encode(shouldRecord, forKey: .shouldRecord)
269265
try container.encode(isRecording, forKey: .isRecording)
270266
try container.encode(isMicrophoneMuted, forKey: .isMicrophoneMuted)
271267
try container.encode(
@@ -294,7 +290,6 @@ extension RTCAudioStore {
294290
static func == (lhs: StoreState, rhs: StoreState) -> Bool {
295291
lhs.isActive == rhs.isActive
296292
&& lhs.isInterrupted == rhs.isInterrupted
297-
&& lhs.shouldRecord == rhs.shouldRecord
298293
&& lhs.isRecording == rhs.isRecording
299294
&& lhs.isMicrophoneMuted == rhs.isMicrophoneMuted
300295
&& lhs.hasRecordingPermission == rhs.hasRecordingPermission
@@ -308,7 +303,6 @@ extension RTCAudioStore {
308303
func hash(into hasher: inout Hasher) {
309304
hasher.combine(isActive)
310305
hasher.combine(isInterrupted)
311-
hasher.combine(shouldRecord)
312306
hasher.combine(isRecording)
313307
hasher.combine(isMicrophoneMuted)
314308
hasher.combine(hasRecordingPermission)

Sources/StreamVideo/Utils/AudioSession/RTCAudioStore/Namespace/Reducers/RTCAudioStore+DefaultReducer.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ extension RTCAudioStore.Namespace {
4343
case let .setInterrupted(value):
4444
updatedState.isInterrupted = value
4545

46-
case let .setShouldRecord(value):
47-
updatedState.shouldRecord = value
48-
4946
case let .setRecording(value):
5047
updatedState.isRecording = value
5148

@@ -58,7 +55,6 @@ extension RTCAudioStore.Namespace {
5855
case let .setAudioDeviceModule(value):
5956
updatedState.audioDeviceModule = value
6057
if value == nil {
61-
updatedState.shouldRecord = false
6258
updatedState.isRecording = false
6359
updatedState.isMicrophoneMuted = true
6460
updatedState.stereoConfiguration = .init(

0 commit comments

Comments
 (0)