Skip to content

Commit dade6d4

Browse files
committed
[Hygiene]Additional logging
1 parent 8280c1a commit dade6d4

File tree

10 files changed

+141
-29
lines changed

10 files changed

+141
-29
lines changed

Sources/StreamVideo/CallSettings/MicrophoneManager.swift

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,72 @@ public final class MicrophoneManager: ObservableObject, CallSettingsManager, @un
1212
/// The status of the microphone.
1313
@Published public internal(set) var status: CallSettingsStatus
1414
let state = CallSettingsState()
15-
15+
1616
init(callController: CallController, initialStatus: CallSettingsStatus) {
1717
self.callController = callController
1818
status = initialStatus
1919
}
20-
20+
2121
/// Toggles the microphone state.
22-
public func toggle() async throws {
23-
try await updateAudioStatus(status.next)
22+
public func toggle(
23+
file: StaticString = #file,
24+
function: StaticString = #function,
25+
line: UInt = #line
26+
) async throws {
27+
try await updateAudioStatus(
28+
status.next,
29+
file: file,
30+
function: function,
31+
line: line
32+
)
2433
}
25-
34+
2635
/// Enables the microphone.
27-
public func enable() async throws {
28-
try await updateAudioStatus(.enabled)
36+
public func enable(
37+
file: StaticString = #file,
38+
function: StaticString = #function,
39+
line: UInt = #line
40+
) async throws {
41+
try await updateAudioStatus(
42+
.enabled,
43+
file: file,
44+
function: function,
45+
line: line
46+
)
2947
}
30-
48+
3149
/// Disables the microphone.
32-
public func disable() async throws {
33-
try await updateAudioStatus(.disabled)
50+
public func disable(
51+
file: StaticString = #file,
52+
function: StaticString = #function,
53+
line: UInt = #line
54+
) async throws {
55+
try await updateAudioStatus(
56+
.disabled,
57+
file: file,
58+
function: function,
59+
line: line
60+
)
3461
}
3562

3663
// MARK: - private
3764

38-
private func updateAudioStatus(_ status: CallSettingsStatus) async throws {
65+
private func updateAudioStatus(
66+
_ status: CallSettingsStatus,
67+
file: StaticString = #file,
68+
function: StaticString = #function,
69+
line: UInt = #line
70+
) async throws {
3971
try await updateState(
4072
newState: status.boolValue,
4173
current: self.status.boolValue,
4274
action: { [unowned self] state in
43-
try await callController.changeAudioState(isEnabled: state)
75+
try await callController.changeAudioState(
76+
isEnabled: state,
77+
file: file,
78+
function: function,
79+
line: line
80+
)
4481
},
4582
onUpdate: { _ in
4683
self.status = status

Sources/StreamVideo/Controllers/CallController.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,18 @@ class CallController: @unchecked Sendable {
152152

153153
/// Changes the audio state for the current user.
154154
/// - Parameter isEnabled: whether audio should be enabled.
155-
func changeAudioState(isEnabled: Bool) async throws {
156-
await webRTCCoordinator.changeAudioState(isEnabled: isEnabled)
155+
func changeAudioState(
156+
isEnabled: Bool,
157+
file: StaticString = #file,
158+
function: StaticString = #function,
159+
line: UInt = #line
160+
) async throws {
161+
await webRTCCoordinator.changeAudioState(
162+
isEnabled: isEnabled,
163+
file: file,
164+
function: function,
165+
line: line
166+
)
157167
}
158168

159169
/// Changes the video state for the current user.

Sources/StreamVideo/Utils/AudioSession/RTCAudioStore/Effects/RTCAudioStore+RouteChangeEffect.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ extension RTCAudioStore {
9292
subsystems: .audioSession
9393
)
9494
delegate?.audioSessionAdapterDidUpdateSpeakerOn(
95-
session.currentRoute.isSpeaker
95+
session.currentRoute.isSpeaker,
96+
file: #file,
97+
function: #function,
98+
line: #line
9699
)
97100
}
98101
return
@@ -101,12 +104,18 @@ extension RTCAudioStore {
101104
switch (activeCallSettings.speakerOn, session.currentRoute.isSpeaker) {
102105
case (true, false):
103106
delegate?.audioSessionAdapterDidUpdateSpeakerOn(
104-
false
107+
false,
108+
file: #file,
109+
function: #function,
110+
line: #line
105111
)
106112

107113
case (false, true) where session.category == AVAudioSession.Category.playAndRecord.rawValue:
108114
delegate?.audioSessionAdapterDidUpdateSpeakerOn(
109-
true
115+
true,
116+
file: #file,
117+
function: #function,
118+
line: #line
110119
)
111120

112121
default:

Sources/StreamVideo/Utils/AudioSession/StreamAudioSessionAdapterDelegate.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ protocol StreamAudioSessionAdapterDelegate: AnyObject {
1212
/// - audioSession: The `AudioSession` instance that made the update.
1313
/// - callSettings: The updated `CallSettings`.
1414
func audioSessionAdapterDidUpdateSpeakerOn(
15-
_ speakerOn: Bool
15+
_ speakerOn: Bool,
16+
file: StaticString,
17+
function: StaticString,
18+
line: UInt
1619
)
1720
}

Sources/StreamVideo/Utils/CustomStringInterpolation/String.StringInterpolation+Nil.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,12 @@ extension String.StringInterpolation {
88
mutating func appendInterpolation<T: CustomStringConvertible>(_ value: T?) {
99
appendInterpolation(value ?? "nil" as CustomStringConvertible)
1010
}
11+
12+
mutating func appendInterpolation<T: AnyObject>(_ value: T) {
13+
if let convertible = value as? CustomStringConvertible {
14+
appendInterpolation(convertible)
15+
} else {
16+
appendInterpolation("\(Unmanaged.passUnretained(value).toOpaque())")
17+
}
18+
}
1119
}

Sources/StreamVideo/WebRTC/v2/WebRTCCoordinator.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,25 @@ final class WebRTCCoordinator: @unchecked Sendable {
135135
/// Changes the audio state (enabled/disabled) for the call.
136136
///
137137
/// - Parameter isEnabled: Whether the audio should be enabled.
138-
func changeAudioState(isEnabled: Bool) async {
138+
func changeAudioState(
139+
isEnabled: Bool,
140+
file: StaticString = #file,
141+
function: StaticString = #function,
142+
line: UInt = #line
143+
) async {
139144
await stateAdapter
140-
.enqueueCallSettings { $0.withUpdatedAudioState(isEnabled) }
145+
.enqueueCallSettings(
146+
functionName: function,
147+
fileName: file,
148+
lineNumber: line
149+
) {
150+
$0.withUpdatedAudioState(
151+
isEnabled,
152+
file: file,
153+
function: function,
154+
line: line
155+
)
156+
}
141157
}
142158

143159
/// Changes the video state (enabled/disabled) for the call.

Sources/StreamVideo/WebRTC/v2/WebRTCStateAdapter.swift

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,13 @@ actor WebRTCStateAdapter: ObservableObject, StreamAudioSessionAdapterDelegate, W
508508
}
509509

510510
await set(callSettings: updatedCallSettings)
511+
log.debug(
512+
"CallSettings updated \(currentCallSettings) -> \(updatedCallSettings)",
513+
subsystems: .webRTC,
514+
functionName: functionName,
515+
fileName: fileName,
516+
lineNumber: lineNumber
517+
)
511518

512519
guard
513520
let publisher = await self.publisher
@@ -684,19 +691,32 @@ actor WebRTCStateAdapter: ObservableObject, StreamAudioSessionAdapterDelegate, W
684691

685692
// MARK: - AudioSessionDelegate
686693

687-
nonisolated func audioSessionAdapterDidUpdateSpeakerOn(_ speakerOn: Bool) {
694+
nonisolated func audioSessionAdapterDidUpdateSpeakerOn(
695+
_ speakerOn: Bool,
696+
file: StaticString,
697+
function: StaticString,
698+
line: UInt
699+
700+
) {
688701
Task(disposableBag: disposableBag) { [weak self] in
689702
guard let self else {
690703
return
691704
}
692-
await self.enqueueCallSettings {
705+
await self.enqueueCallSettings(
706+
functionName: function,
707+
fileName: file,
708+
lineNumber: line
709+
) {
693710
$0.withUpdatedSpeakerState(speakerOn)
694711
}
695-
log.debug(
696-
"AudioSession delegated updated speakerOn:\(speakerOn).",
697-
subsystems: .audioSession
698-
)
699712
}
713+
log.debug(
714+
"AudioSession delegated updated speakerOn:\(speakerOn).",
715+
subsystems: .audioSession,
716+
functionName: function,
717+
fileName: file,
718+
lineNumber: line
719+
)
700720
}
701721

702722
// MARK: - WebRTCPermissionsAdapterDelegate

StreamVideoTests/Mock/CallController_Mock.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class CallController_Mock: CallController, @unchecked Sendable {
2424
mockResponseBuilder.makeJoinCallResponse(cid: super.call?.cId ?? "default:\(String.unique)")
2525
}
2626

27-
override func changeAudioState(isEnabled: Bool) async throws { /* no op */ }
27+
override func changeAudioState(isEnabled: Bool, file: StaticString, function: StaticString, line: UInt) async throws {
28+
/* no op */ }
2829

2930
override func changeVideoState(isEnabled: Bool) async throws { /* no op */ }
3031

StreamVideoTests/Utils/AudioSession/RTCAudioStore/Effects/RouteChangeEffect_Tests.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ final class RouteChangeEffect_Tests: XCTestCase, @unchecked Sendable {
1414
final class MockDelegate: StreamAudioSessionAdapterDelegate {
1515
private(set) var updatedSpeakerOn: Bool?
1616

17-
func audioSessionAdapterDidUpdateSpeakerOn(_ speakerOn: Bool) {
17+
func audioSessionAdapterDidUpdateSpeakerOn(
18+
_ speakerOn: Bool,
19+
file: StaticString,
20+
function: StaticString,
21+
line: UInt
22+
) {
1823
updatedSpeakerOn = speakerOn
1924
}
2025
}

StreamVideoTests/WebRTC/v2/WebRTCStateAdapter_Tests.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,10 @@ final class WebRTCStateAdapter_Tests: XCTestCase, @unchecked Sendable {
831831
}
832832

833833
subject.audioSessionAdapterDidUpdateSpeakerOn(
834-
true
834+
true,
835+
file: #file,
836+
function: #function,
837+
line: #line
835838
)
836839

837840
await fulfillment { await self.subject.callSettings.speakerOn }

0 commit comments

Comments
 (0)