Skip to content

Commit 5cacb27

Browse files
authored
[Enhancement]WebRTC logs via SDK logger (#892)
1 parent e71a36f commit 5cacb27

File tree

6 files changed

+80
-3
lines changed

6 files changed

+80
-3
lines changed

DemoApp/Sources/Components/AppEnvironment.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,3 +639,9 @@ extension String: Debuggable {
639639
self
640640
}
641641
}
642+
643+
extension Bool: Debuggable {
644+
var title: String {
645+
self ? "True" : "False"
646+
}
647+
}

DemoApp/Sources/Extensions/DemoApp+Sentry.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func configureSentry() {
2727
]
2828
} else {
2929
LogConfig.level = .debug
30+
LogConfig.webRTCLogsEnabled = true
3031
LogConfig.destinationTypes = [
3132
MemoryLogDestination.self,
3233
OSLogDestination.self

DemoApp/Sources/Views/Login/DebugMenu.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,12 @@ struct DebugMenu: View {
298298
label: "Log Level"
299299
) { LogConfig.level = $0 }
300300

301+
makeMenu(
302+
for: [true, false],
303+
currentValue: LogConfig.webRTCLogsEnabled,
304+
label: "WebRTC Logs"
305+
) { LogConfig.webRTCLogsEnabled = $0 }
306+
301307
Button {
302308
isLogsViewerVisible = true
303309
} label: {

Sources/StreamVideo/Utils/Logger/Logger.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public struct LogSubsystem: OptionSet, CustomStringConvertible, Sendable {
3232
.audioSession,
3333
.videoCapturer,
3434
.pictureInPicture,
35-
.callKit
35+
.callKit,
36+
.webRTCInternal
3637
]
3738

3839
/// All subsystems within the SDK.
@@ -52,7 +53,8 @@ public struct LogSubsystem: OptionSet, CustomStringConvertible, Sendable {
5253
.audioSession,
5354
.videoCapturer,
5455
.pictureInPicture,
55-
.callKit
56+
.callKit,
57+
.webRTCInternal
5658
]
5759

5860
/// The subsystem responsible for any other part of the SDK.
@@ -88,6 +90,7 @@ public struct LogSubsystem: OptionSet, CustomStringConvertible, Sendable {
8890
public static let pictureInPicture = Self(rawValue: 1 << 14)
8991
/// The subsystem responsible for PicutreInPicture.
9092
public static let callKit = Self(rawValue: 1 << 15)
93+
public static let webRTCInternal = Self(rawValue: 1 << 16)
9194

9295
public var description: String {
9396
switch rawValue {
@@ -123,6 +126,8 @@ public struct LogSubsystem: OptionSet, CustomStringConvertible, Sendable {
123126
return "picture-in-picture"
124127
case LogSubsystem.callKit.rawValue:
125128
return "CallKit"
129+
case LogSubsystem.webRTCInternal.rawValue:
130+
return "webRTC-Internal"
126131
default:
127132
return "unknown(rawValue:\(rawValue)"
128133
}
@@ -284,7 +289,12 @@ public enum LogConfig {
284289
_logger = newValue
285290
}
286291
}
287-
292+
293+
public static var webRTCLogsEnabled: Bool {
294+
get { WebRTCLogger.default.enabled }
295+
set { WebRTCLogger.default.enabled = true }
296+
}
297+
288298
/// Invalidates the current logger instance so it can be recreated.
289299
private static func invalidateLogger() {
290300
_logger = nil
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// Copyright © 2025 Stream.io Inc. All rights reserved.
3+
//
4+
5+
import Foundation
6+
import OSLog
7+
import StreamWebRTC
8+
9+
final class WebRTCLogger: @unchecked Sendable {
10+
11+
static let `default` = WebRTCLogger()
12+
13+
var enabled: Bool = false {
14+
didSet { didUpdate(enabled) }
15+
}
16+
17+
var severity: RTCLoggingSeverity = .error {
18+
didSet { webRTCLogger.severity = severity }
19+
}
20+
21+
private let webRTCLogger: RTCCallbackLogger = .init()
22+
23+
private init() {
24+
webRTCLogger.severity = .verbose
25+
}
26+
27+
private func didUpdate(_ enabled: Bool) {
28+
guard enabled else {
29+
webRTCLogger.stop()
30+
return
31+
}
32+
webRTCLogger.start { message, severity in
33+
let trimmedMessage = message.trimmingCharacters(
34+
in: .whitespacesAndNewlines
35+
)
36+
switch severity {
37+
case .none, .verbose:
38+
log.debug(trimmedMessage, subsystems: .webRTCInternal)
39+
case .info:
40+
log.info(trimmedMessage, subsystems: .webRTCInternal)
41+
case .warning:
42+
log.warning(trimmedMessage, subsystems: .webRTCInternal)
43+
case .error:
44+
log.error(trimmedMessage, subsystems: .webRTCInternal)
45+
@unknown default:
46+
log.debug(trimmedMessage, subsystems: .webRTCInternal)
47+
}
48+
}
49+
}
50+
}

StreamVideo.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@
737737
40E363772D0A2E320028C52A /* BroadcastBufferReaderKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E363762D0A2E320028C52A /* BroadcastBufferReaderKey.swift */; };
738738
40E741FA2D54E6F40044C955 /* RTCAudioSessionDelegatePublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E741F92D54E6F40044C955 /* RTCAudioSessionDelegatePublisher.swift */; };
739739
40E741FF2D553ACD0044C955 /* CurrentDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E741FE2D553ACD0044C955 /* CurrentDevice.swift */; };
740+
40E7A45B2E29495500E8AB8B /* WebRTCLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E7A4582E29487700E8AB8B /* WebRTCLogger.swift */; };
740741
40E9B3B12BCD755F00ACF18F /* MemberResponse+Dummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E9B3B02BCD755F00ACF18F /* MemberResponse+Dummy.swift */; };
741742
40E9B3B32BCD93AE00ACF18F /* JoinCallResponse+Dummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E9B3B22BCD93AE00ACF18F /* JoinCallResponse+Dummy.swift */; };
742743
40E9B3B52BCD93F500ACF18F /* Credentials+Dummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40E9B3B42BCD93F500ACF18F /* Credentials+Dummy.swift */; };
@@ -2246,6 +2247,7 @@
22462247
40E363762D0A2E320028C52A /* BroadcastBufferReaderKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BroadcastBufferReaderKey.swift; sourceTree = "<group>"; };
22472248
40E741F92D54E6F40044C955 /* RTCAudioSessionDelegatePublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RTCAudioSessionDelegatePublisher.swift; sourceTree = "<group>"; };
22482249
40E741FE2D553ACD0044C955 /* CurrentDevice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentDevice.swift; sourceTree = "<group>"; };
2250+
40E7A4582E29487700E8AB8B /* WebRTCLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebRTCLogger.swift; sourceTree = "<group>"; };
22492251
40E9B3B02BCD755F00ACF18F /* MemberResponse+Dummy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MemberResponse+Dummy.swift"; sourceTree = "<group>"; };
22502252
40E9B3B22BCD93AE00ACF18F /* JoinCallResponse+Dummy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "JoinCallResponse+Dummy.swift"; sourceTree = "<group>"; };
22512253
40E9B3B42BCD93F500ACF18F /* Credentials+Dummy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Credentials+Dummy.swift"; sourceTree = "<group>"; };
@@ -5894,6 +5896,7 @@
58945896
8456E6C7287EC343004E180E /* Logger */ = {
58955897
isa = PBXGroup;
58965898
children = (
5899+
40E7A4582E29487700E8AB8B /* WebRTCLogger.swift */,
58975900
40BBC4A92C6270F5002AEF92 /* Array+Logger.swift */,
58985901
40AB34E02C5E73F900B5B6B3 /* Publisher+Logger.swift */,
58995902
8456E6C8287EC343004E180E /* Logger.swift */,
@@ -8161,6 +8164,7 @@
81618164
4092517E2E05AFF000DC0FB3 /* MidStereoInformation.swift in Sources */,
81628165
843DAB9929E695CF00E0EB63 /* CreateGuestResponse.swift in Sources */,
81638166
84DC389229ADFCFD00946713 /* RequestPermissionRequest.swift in Sources */,
8167+
40E7A45B2E29495500E8AB8B /* WebRTCLogger.swift in Sources */,
81648168
84C28C922A84D16A00742E33 /* GoLiveRequest.swift in Sources */,
81658169
84FC2C1328ACDF3A00181490 /* ProtoModel.swift in Sources */,
81668170
40BBC4CE2C639054002AEF92 /* WebRTCCoordinator+Error.swift in Sources */,

0 commit comments

Comments
 (0)