-
Notifications
You must be signed in to change notification settings - Fork 9
Examples
The following examples are valid from version
1.8.0
of Agora UIKit. For previous versions, appendimport AgoraUIKit
with_iOS
or_macOS
, depending on your platform.
These three examples show how to create an instance of AgoraVideoViewer (or AgoraViewer in SwiftUI), the standard view from Agora UIKit, which contains the local video feed as well as all incoming streams.
self.agoraView = AgoraVideoViewer(
connectionData: AgoraConnectionData(
appId: <#Agora App ID#>,
rtcToken: <#Agora Token or nil#>
)
)
struct ContentView: View {
var agview: AgoraViewer {
let agoraView = AgoraViewer(
connectionData: AgoraConnectionData(
appId: <#Agora App ID#>,
rtcToken: <#Agora Token or nil#>
),
style: .floating
)
agoraView.join(channel: "test", with: <#Agora Token#>, as: .broadcaster)
}
var body: some View {
agview
}
}
self.agoraView = AgoraVideoViewer(
connectionData: AgoraConnectionData(
appId: <#Agora App ID#>,
rtcToken: <#Agora Token or nil#>
)
)
This example also sets up the delegate, frame the view to fill the screen, and connect to a channel. This is the minimum requirement to get all the features, including mute/unmute requests.
import UIKit
import AgoraUIKit
class ViewController: UIViewController, AgoraVideoViewerDelegate {
var agoraView: AgoraVideoViewer!
override func viewDidLoad() {
super.viewDidLoad()
self.agoraView = AgoraVideoViewer(
connectionData: AgoraConnectionData(
appId: <#Agora App ID#>,
rtcToken: <#Agora Token or nil#>
), delegate: self
)
// frame the view
agoraView.fills(view: self.view)
// join the channel "test"
agoraView.join(channel: "test", as: .broadcaster)
}
}
For macOS, you would just need to replace import UIKit
with import AppKit
, and UIViewController
with NSViewController
.
The way to assign any of the properties is the same across iOS and macOS. This is an example of a few properties being assigned, and then applied to AgoraVideoViewer.
var agSettings = AgoraSettings()
agSettings.colors.micFlag = .red
agSettings.enabledButtons = [.cameraButton, .micButton, .screenShareButton]
agSettings.tokenURL = "https://example.com/agoraToken"
agSettings.lowBitrateParam = """
{ "che.video.lowBitRateStreamParameter": {
"width":160,"height":120,"frameRate":5,"bitRate":45
}}
"""
let agoraView = AgoraVideoViewer(
connectionData: AgoraConnectionData(
appId: <#Agora App ID#>,
rtcToken: <#Agora Token or nil#>
),
agoraSettings: agSettings
)
If you want access to more properties found in Agora's full API Reference, you can do so by importing AgoraRtcKit
, and accessing the engine via AgoraVideoViewer.agkit
.