Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track state of call to enableLocalVideo from remote users #6

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Sources/SwiftUIRtc/AgoraManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ open class AgoraManager: NSObject, ObservableObject, AgoraRtcEngineDelegate {

/// 🧍‍♂️ The set of all users in the channel.
@Published public var allUsers: Set<UInt> = []

/// 📹 The set of all users in the channel that have camera enabled.
@Published public var enabledVideos: Set<UInt> = []

/// 🚀 Initializes and configures the Agora RTC Engine Kit.
///
Expand Down Expand Up @@ -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,
ionel71089 marked this conversation as resolved.
Show resolved Hide resolved
remoteVideoStateChangedOfUid uid: UInt,
state: AgoraVideoRemoteState,
reason: AgoraVideoRemoteReason,
elapsed: Int) {
switch state {
case .starting:
enabledVideos.insert(uid)

case .stopped:
enabledVideos.remove(uid)

default:
break
}
}
}
Loading