From 78360c8ac593cdcf5b6b18db3ecc4293bd973d4c Mon Sep 17 00:00:00 2001 From: Ionel Lescai Date: Wed, 20 Nov 2024 15:17:01 +0200 Subject: [PATCH] Track state of call to enableLocalVideo from remote users --- Sources/SwiftUIRtc/AgoraManager.swift | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Sources/SwiftUIRtc/AgoraManager.swift b/Sources/SwiftUIRtc/AgoraManager.swift index 2e82680..029bccd 100644 --- a/Sources/SwiftUIRtc/AgoraManager.swift +++ b/Sources/SwiftUIRtc/AgoraManager.swift @@ -30,6 +30,9 @@ open class AgoraManager: NSObject, ObservableObject, AgoraRtcEngineDelegate { /// πŸ§β€β™‚οΈ The set of all users in the channel. @Published public var allUsers: Set = [] + + /// πŸ“Ή The set of all users in the channel that have camera enabled. + @Published public var enabledVideos: Set = [] /// πŸš€ Initializes and configures the Agora RTC Engine Kit. /// @@ -140,4 +143,31 @@ open class AgoraManager: NSObject, ObservableObject, AgoraRtcEngineDelegate { open func rtcEngine(_ engine: AgoraRtcEngineKit, didOfflineOfUid uid: UInt, reason: AgoraUserOfflineReason) { self.allUsers.remove(uid) } + + /// πŸ“ΉThe remote video state has change. + /// + /// - Parameters: + /// - engine: The Agora RTC enging kit object. + /// - uid: The ID of the user who left the channel. + /// - state: The reason of the remote video state change: #AgoraVideoRemoteReason. + /// - reason: The reason of the remote video state change: #AgoraVideoRemoteReason. + /// - elapsed: The time elapsed (ms) from the local user calling `joinChannel` until this callback is triggered. + /// + /// This method adds or removes the remote user from `enabledVideos` set. + open func rtcEngine(_ engine: AgoraRtcEngineKit, + remoteVideoStateChangedOfUid uid: UInt, + state: AgoraVideoRemoteState, + reason: AgoraVideoRemoteReason, + elapsed: Int) { + switch state { + case .starting: + enabledVideos.insert(uid) + + case .stopped: + enabledVideos.remove(uid) + + default: + break + } + } }