Skip to content

Commit

Permalink
added the allUsers set to be included in the default class
Browse files Browse the repository at this point in the history
  • Loading branch information
maxxfrazer committed Mar 30, 2023
1 parent d7f3718 commit e92a2ac
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 25 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/deploy_docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Deploy DocC

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true

jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: macos-12
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- name: Build All DocC 🛠
run: |
xcodebuild docbuild -scheme AgoraVideoSwiftUI -derivedDataPath /tmp/docbuild -destination 'generic/platform=iOS';
$(xcrun --find docc) process-archive \
transform-for-static-hosting /tmp/docbuild/Build/Products/Debug-iphoneos/AgoraVideoSwiftUI.doccarchive \
--output-path docs \
--hosting-base-path AgoraVideoSwiftUI;
echo "<script>window.location.href += \"/documentation/agoravideoswiftui\"</script>" > docs/index.html;
- name: Upload artifact 📜
uses: actions/upload-pages-artifact@v1
with:
# Upload docs directory
path: 'docs'
- name: Deploy to GitHub Pages 🐙
id: deployment
uses: actions/deploy-pages@v1
23 changes: 1 addition & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import AgoraVideoSwiftUI
import AgoraRtcKit

struct AgoraGettingStartedView: View {
@ObservedObject var agoraManager = GettingStartedManager(appId: <#AppId#>, role: .broadcaster)
@ObservedObject var agoraManager = AgoraManager(appId: <#AppId#>, role: .broadcaster)
var channelId: String = "test"
var body: some View {
ScrollView {
Expand All @@ -39,27 +39,6 @@ struct AgoraGettingStartedView: View {
}
}
}

// To show and hide all the users in the channel, we need to make a small subclass of AgoraManager.
class GettingStartedManager: AgoraManager {
@Published var allUsers: Set<UInt> = []
override func leaveChannel(leaveChannelBlock: ((AgoraChannelStats) -> Void)? = nil) {
allUsers.removeAll()
super.leaveChannel(leaveChannelBlock: leaveChannelBlock)
}
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinChannel channel: String, withUid uid: UInt, elapsed: Int) {
if self.role == .broadcaster {
self.allUsers.insert(0)
}
}
func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinedOfUid uid: UInt, elapsed: Int) {
self.allUsers.insert(uid)
}
func rtcEngine(_ engine: AgoraRtcEngineKit, didOfflineOfUid uid: UInt, reason: AgoraUserOfflineReason) {
self.allUsers.remove(uid)
}
}

```

## Contributing
Expand Down
55 changes: 52 additions & 3 deletions Sources/AgoraVideoSwiftUI/AgoraManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ open class AgoraManager: NSObject, ObservableObject, AgoraRtcEngineDelegate {
return eng
}

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

/**
Initializes a new instance of `AgoraManager` with the specified app ID and client role.

- Parameters:
- appId: The Agora App ID for the session.
- role: The client's role in the session. The default value is `.audience`.
- appId: The Agora App ID for the session.
- role: The client's role in the session. The default value is `.audience`.
*/
public init(appId: String, role: AgoraClientRole = .audience) {
self.appId = appId
Expand All @@ -44,11 +47,57 @@ open class AgoraManager: NSObject, ObservableObject, AgoraRtcEngineDelegate {
Leaves the channel and stops the preview for the session.

- Parameter leaveChannelBlock: An optional closure that will be called when the client leaves the channel. The closure takes an `AgoraChannelStats` object as its parameter.


This method also empties all entries in ``allUsers``
*/
open func leaveChannel(leaveChannelBlock: ((AgoraChannelStats) -> Void)? = nil) {
self.engine.leaveChannel(leaveChannelBlock)
self.engine.stopPreview()
AgoraRtcEngineKit.destroy()
self.allUsers.removeAll()
}
}

/**
Tells the delegate that the user has successfully joined the channel.
- Parameters:
- engine: The Agora RTC engine kit object.
- channel: The channel name.
- uid: The ID of the user joining the channel.
- elapsed: The time elapsed (ms) from the user calling `joinChannel` until this method is called.

If the client's role is `.broadcaster`, this method also adds the broadcaster to the `allUsers` set.
*/
open func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinChannel channel: String, withUid uid: UInt, elapsed: Int) {
if self.role == .broadcaster {
self.allUsers.insert(0)
}
}

/**
Tells the delegate that a remote user has joined the channel.

- Parameters:
- engine: The Agora RTC engine kit object.
- uid: The ID of the user joining the channel.
- elapsed: The time elapsed (ms) from the user calling `joinChannel` until this method is called.

This method adds the remote user to the `allUsers` set.
*/
open func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinedOfUid uid: UInt, elapsed: Int) {
self.allUsers.insert(uid)
}
/**
Tells the delegate that a remote user has left the channel.

- Parameters:
- engine: The Agora RTC engine kit object.
- uid: The ID of the user who left the channel.
- reason: The reason why the user left the channel.

This method removes the remote user from the `allUsers` set.
*/
open func rtcEngine(_ engine: AgoraRtcEngineKit, didOfflineOfUid uid: UInt, reason: AgoraUserOfflineReason) {
self.allUsers.remove(uid)
}
}

0 comments on commit e92a2ac

Please sign in to comment.