Skip to content

Commit 80705fb

Browse files
authored
[Fix]Speaker toggling uncontrolably (#968)
1 parent 5df3432 commit 80705fb

File tree

9 files changed

+18
-34
lines changed

9 files changed

+18
-34
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
44

55
# Upcoming
66

7-
### 🔄 Changed
7+
### 🐞 Fixed
8+
- An issue that was causing the speaker to toggle nonstop. [#968](https://github.com/GetStream/stream-video-swift/pull/968)
89

910
# [1.34.0](https://github.com/GetStream/stream-video-swift/releases/tag/1.34.0)
1011
_October 07, 2025_

Sources/StreamVideo/Utils/AudioSession/CallAudioSession.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ final class CallAudioSession: @unchecked Sendable {
188188
private func initialAudioSessionConfiguration() {
189189
let state = audioStore.state
190190
let requiresCategoryUpdate = state.category != .playAndRecord
191-
let requiresModeUpdate = state.mode != .voiceChat && state.mode != .videoChat
191+
let requiresModeUpdate = state.mode != .voiceChat
192192

193193
guard requiresCategoryUpdate || requiresModeUpdate else {
194194
log.info(

Sources/StreamVideo/Utils/AudioSession/Policies/DefaultAudioSessionPolicy.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public struct DefaultAudioSessionPolicy: AudioSessionPolicy {
2727
return .init(
2828
isActive: callSettings.audioOutputOn,
2929
category: .playAndRecord,
30-
mode: callSettings.videoOn ? .videoChat : .voiceChat,
30+
mode: .voiceChat,
3131
options: .playAndRecord(
3232
videoOn: callSettings.videoOn,
3333
speakerOn: callSettings.speakerOn,
@@ -42,7 +42,7 @@ public struct DefaultAudioSessionPolicy: AudioSessionPolicy {
4242
return .init(
4343
isActive: callSettings.audioOutputOn,
4444
category: .playAndRecord,
45-
mode: callSettings.videoOn && callSettings.speakerOn ? .videoChat : .voiceChat,
45+
mode: .voiceChat,
4646
options: .playAndRecord(
4747
videoOn: callSettings.videoOn,
4848
speakerOn: callSettings.speakerOn,

Sources/StreamVideo/Utils/AudioSession/Policies/OwnCapabilitiesAudioSessionPolicy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public struct OwnCapabilitiesAudioSessionPolicy: AudioSessionPolicy {
5555
: .playback
5656

5757
let mode: AVAudioSession.Mode = category == .playAndRecord
58-
? callSettings.videoOn && callSettings.speakerOn ? .videoChat : .voiceChat
58+
? .voiceChat
5959
: .default
6060

6161
let categoryOptions: AVAudioSession.CategoryOptions = category == .playAndRecord

Sources/StreamVideo/Utils/AudioSession/Protocols/AVAudioSessionProtocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ protocol AVAudioSessionProtocol {
1010
/// Configures the audio session category and options.
1111
/// - Parameters:
1212
/// - category: The audio category (e.g., `.playAndRecord`).
13-
/// - mode: The audio mode (e.g., `.videoChat`).
13+
/// - mode: The audio mode (e.g., `.voiceChat`).
1414
/// - categoryOptions: The options for the category (e.g., `.allowBluetooth`).
1515
/// - Throws: An error if setting the category fails.
1616
func setCategory(

StreamVideoTests/Utils/AudioSession/AudioRecorder/Namespace/Middleware/StreamCallAudioRecorder_CategoryMiddlewareTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class StreamCallAudioRecorder_CategoryMiddlewareTests: XCTestCase, @unchec
2626
validation.isInverted = true
2727
subject.dispatcher = .init { _, _, _, _ in }
2828

29-
audioStore.dispatch(.audioSession(.setCategory(.playAndRecord, mode: .videoChat, options: [])))
29+
audioStore.dispatch(.audioSession(.setCategory(.playAndRecord, mode: .voiceChat, options: [])))
3030

3131
await safeFulfillment(of: [validation], timeout: 1)
3232
}
@@ -36,7 +36,7 @@ final class StreamCallAudioRecorder_CategoryMiddlewareTests: XCTestCase, @unchec
3636
validation.isInverted = true
3737
subject.dispatcher = .init { _, _, _, _ in }
3838

39-
audioStore.dispatch(.audioSession(.setCategory(.record, mode: .videoChat, options: [])))
39+
audioStore.dispatch(.audioSession(.setCategory(.record, mode: .voiceChat, options: [])))
4040

4141
await safeFulfillment(of: [validation], timeout: 1)
4242
}
@@ -52,7 +52,7 @@ final class StreamCallAudioRecorder_CategoryMiddlewareTests: XCTestCase, @unchec
5252
}
5353
}
5454

55-
audioStore.dispatch(.audioSession(.setCategory(.playback, mode: .videoChat, options: [])))
55+
audioStore.dispatch(.audioSession(.setCategory(.playback, mode: .voiceChat, options: [])))
5656

5757
await safeFulfillment(of: [validation])
5858
}

StreamVideoTests/Utils/AudioSession/Policies/DefaultAudioSessionPolicyTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class DefaultAudioSessionPolicyTests: XCTestCase, @unchecked Sendable {
3535
)
3636

3737
XCTAssertEqual(configuration.category, .playAndRecord)
38-
XCTAssertEqual(configuration.mode, .videoChat)
38+
XCTAssertEqual(configuration.mode, .voiceChat)
3939
XCTAssertEqual(
4040
configuration.options,
4141
[
@@ -56,7 +56,7 @@ final class DefaultAudioSessionPolicyTests: XCTestCase, @unchecked Sendable {
5656
)
5757

5858
XCTAssertEqual(configuration.category, .playAndRecord)
59-
XCTAssertEqual(configuration.mode, .videoChat)
59+
XCTAssertEqual(configuration.mode, .voiceChat)
6060
XCTAssertEqual(
6161
configuration.options,
6262
[
@@ -97,7 +97,7 @@ final class DefaultAudioSessionPolicyTests: XCTestCase, @unchecked Sendable {
9797
)
9898

9999
XCTAssertEqual(configuration.category, .playAndRecord)
100-
XCTAssertEqual(configuration.mode, .videoChat)
100+
XCTAssertEqual(configuration.mode, .voiceChat)
101101
XCTAssertEqual(
102102
configuration.options,
103103
[

StreamVideoTests/Utils/AudioSession/Policies/OwnCapabilitiesAudioSessionPolicyTests.swift

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ final class OwnCapabilitiesAudioSessionPolicyTests: XCTestCase, @unchecked Senda
9292

9393
// Then
9494
XCTAssertEqual(configuration.category, .playAndRecord)
95-
XCTAssertEqual(configuration.mode, .videoChat)
95+
XCTAssertEqual(configuration.mode, .voiceChat)
9696
XCTAssertEqual(
9797
configuration.options,
9898
[
@@ -144,23 +144,6 @@ final class OwnCapabilitiesAudioSessionPolicyTests: XCTestCase, @unchecked Senda
144144

145145
// MARK: - Tests for different video settings
146146

147-
func testConfiguration_WhenVideoOnSpeakerOn_ReturnsVideoChatMode() async {
148-
// Given
149-
currentDeviceType = .phone
150-
await fulfilmentInMainActor { self.currentDevice.deviceType == self.currentDeviceType }
151-
let callSettings = CallSettings(audioOn: true, videoOn: true, speakerOn: true)
152-
let ownCapabilities: Set<OwnCapability> = [.sendAudio, .sendVideo]
153-
154-
// When
155-
let configuration = subject.configuration(
156-
for: callSettings,
157-
ownCapabilities: ownCapabilities
158-
)
159-
160-
// Then
161-
XCTAssertEqual(configuration.mode, .videoChat)
162-
}
163-
164147
func testConfiguration_WhenVideoOffSpeakerOnBackgroundFalse_ReturnsVoiceChatMode() async {
165148
// Given
166149
currentDeviceType = .phone

StreamVideoTests/Utils/AudioSession/RTCAudioStore/Reducers/RTCAudioSessionReducer_Tests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ final class RTCAudioSessionReducer_Tests: XCTestCase, @unchecked Sendable {
140140
action: .audioSession(
141141
.setCategory(
142142
.playAndRecord,
143-
mode: .videoChat,
143+
mode: .voiceChat,
144144
options: [
145145
.allowBluetooth,
146146
.mixWithOthers
@@ -160,7 +160,7 @@ final class RTCAudioSessionReducer_Tests: XCTestCase, @unchecked Sendable {
160160
)?.first
161161
)
162162
XCTAssertEqual(input.category, AVAudioSession.Category.playAndRecord.rawValue)
163-
XCTAssertEqual(input.mode, AVAudioSession.Mode.videoChat.rawValue)
163+
XCTAssertEqual(input.mode, AVAudioSession.Mode.voiceChat.rawValue)
164164
XCTAssertEqual(input.categoryOptions, [.allowBluetooth, .mixWithOthers])
165165
}
166166

@@ -175,7 +175,7 @@ final class RTCAudioSessionReducer_Tests: XCTestCase, @unchecked Sendable {
175175
action: .audioSession(
176176
.setCategory(
177177
.playAndRecord,
178-
mode: .videoChat,
178+
mode: .voiceChat,
179179
options: [
180180
.allowBluetooth,
181181
.mixWithOthers
@@ -188,7 +188,7 @@ final class RTCAudioSessionReducer_Tests: XCTestCase, @unchecked Sendable {
188188
)
189189

190190
XCTAssertEqual(updatedState.category, .playAndRecord)
191-
XCTAssertEqual(updatedState.mode, .videoChat)
191+
XCTAssertEqual(updatedState.mode, .voiceChat)
192192
XCTAssertEqual(updatedState.options, [.allowBluetooth, .mixWithOthers])
193193
}
194194

0 commit comments

Comments
 (0)