ARAudience
open class ARAudience : UIViewController
extension ARAudience: AgoraRtcEngineDelegate
The ARAudience
is a UIViewController
that implements all the needed methods for the viewer (aundience member) of the AR Live Stream. The class provides a manged UI for the audience user.
Note
All class methods can be extended or overwritten.-
Sets the AgoraChannelProfile.
Defaults to
.liveBroadcasting
Declaration
Swift
public var channelProfile: AgoraChannelProfile
-
Flag to determine whether the device enable to speaker mode when entering the channel
Defaults to
true
Declaration
Swift
public var defaultToSpeakerPhone: Bool
-
Name of the channel to use when connecting to an Agora channel.
Note
Defaults tonil
Warning
This value must be set before the ViewController is presented.Declaration
Swift
public var channelName: String!
-
A reference to the host user.
Declaration
Swift
public var remoteUser: UInt?
-
A
UIView
representing the video stream of the host userDeclaration
Swift
public var remoteVideoView: UIView!
-
A Dictionary of
UIView
s representing the video streams of the host usersDeclaration
Swift
public var remoteVideoViews: [UInt : UIView]
-
The
remoteViewBackgroundColor
is the background color for the UIView until the remote video stream is received.Defaults to
.lightGray
Declaration
Swift
public var remoteViewBackgroundColor: UIColor
-
A
UIButton
that dismisses the view controller when tappedDeclaration
Swift
public var backBtn: UIButton!
-
A
CGRect
that represents the frame for thebackBtn
.Note
If a value is not explicitly set, the managed UI will uses default settingsDeclaration
Swift
public var backBtnFrame: CGRect?
-
An optional
UIImage
that is used as the image for thebackBtn
Declaration
Swift
public var backBtnImage: UIImage?
-
The default value to display if an image is not set for the
backBtn
Declaration
Swift
public var backBtnTextLabel: String
-
An optional
UIImageView
that displays a watermark over part of the video.Declaration
Swift
public var watermark: UIImageView?
-
An optional
UIImage
that is used as the image for thewatermark
Warning
If this value is not set, then a watermark will not be displayed.Declaration
Swift
public var watermarkImage: UIImage?
-
A
CGRect
that represents the frame for thewatermark
,Note
If awatermarkImage
is set butwatermarkFrame
is not explicitly set, the managed UI will uses default settingsDeclaration
Swift
public var watermarkFrame: CGRect?
-
A
CGFloat
that represents the transparency of thewatermark
Declaration
Swift
public var watermarkAlpha: CGFloat
-
Undocumented
Declaration
Swift
public var showLogs: Bool
-
Undocumented
Declaration
Swift
public var debug: Bool
-
AgoraARKit uses the
viewDidLoad
method to create the UI and set up the Agora engine configurationDeclaration
Swift
override open func viewDidLoad()
-
AgoraARKit joins the Agora channel within the
viewDidAppear
Declaration
Swift
override open func viewDidAppear(_ animated: Bool)
-
Undocumented
Declaration
Swift
override open var prefersStatusBarHidden: Bool { get }
-
Conencts to the Agora channel, and sets the default audio route to speakerphone
Declaration
Swift
open func joinChannel()
-
Undocumented
Declaration
Swift
open func leaveChannel()
-
Programmatically generated UI, creates the view, and buttons.
Declaration
Swift
open func createUI()
-
Reports a warning during the Agora SDK at runtime.
In most cases, the app can ignore the warning reported by the SDK because the SDK can usually fix the issue and resume running.
For instance, the SDK may report an AgoraWarningCodeOpenChannelTimeout(106) warning upon disconnection from the server and attempts to reconnect.
See AgoraWarningCode.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, didOccurWarning warningCode: AgoraWarningCode)
Parameters
engine
AgoraRtcEngineKit object
warningCode
Warning code. Full list: AgoraWarningCode
-
Reports an error during the Agora SDK at runtime.
In most cases, the SDK cannot fix the issue and resume running. The SDK requires the app to take action or informs the user about the issue.
For example, the SDK reports an AgoraErrorCodeStartCall = 1002 error when failing to initialize a call. The app informs the user that the call initialization failed and invokes the leaveChannel method to leave the channel.
See AgoraErrorCode.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, didOccurError errorCode: AgoraErrorCode)
Parameters
engine
AgoraRtcEngineKit object
errorCode
-
Occurs when a method is executed by the SDK.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, didApiCallExecute error: NSInteger, api: String, result: String)
Parameters
engine
AgoraRtcEngineKit object
error
The AgoraErrorCode returned by the SDK when the method call fails. If the SDK returns 0, then the method call succeeds.
api
The method executed by the SDK.
result
The result of the method call.
-
Occurs when the local user joins a specified channel.
Same as joinSuccessBlock in the joinChannelByToken method.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinChannel channel: String, withUid uid: UInt, elapsed: Int)
Parameters
engine
AgoraRtcEngineKit object
channel
Channel name.
uid
User ID. If the
uid
is specified in thejoinChannelByToken
method, the specified user ID is returned. If theuser ID
is not specified when thejoinChannel
method is called, the server automatically assigns a uid.elapsed
The time elapsed (ms) from the local user calling Agora’s
joinChannelByToken
orsetClientRole
method, until the SDK triggers this callback. -
Occurs when the local user rejoins a channel.
If the client loses connection with the server because of network problems, the SDK automatically attempts to reconnect and then triggers this callback upon reconnection, indicating that the user rejoins the channel with the assigned channel ID and user ID.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, didRejoinChannel channel: String, withUid uid: UInt, elapsed: Int)
Parameters
engine
AgoraRtcEngineKit object
channel
Channel name.
uid
User ID. If the
uid
is specified in thejoinChannelByToken
method, the specified user ID is returned. If theuser ID
is not specified when thejoinChannel
method is called, the server automatically assigns a uid.elapsed
The time elapsed (ms) from the local user calling Agora’s
joinChannelByToken
orsetClientRole
method, until the SDK triggers this callback. -
Occurs when the local user leaves a channel.
When the app calls the
leaveChannel
method, this callback notifies the app that a user leaves a channel.With this callback, the app retrieves information, such as the call duration and the statistics of the received/transmitted data reported by the
audioQualityOfUid
callback.Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, didLeaveChannelWith stats: AgoraChannelStats)
Parameters
engine
AgoraRtcEngineKit object
stats
Statistics of the call:. See AgoraChannelStats for more details.
-
Occurs when the local user successfully registers a user account by calling the registerLocalUserAccount or joinChannelByUserAccount method.
This callback reports the user ID and user account of the local user.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, didRegisteredLocalUser userAccount: String, withUid uid: UInt)
Parameters
engine
AgoraRtcEngineKit object
userAccount
The user account of the local user.
uid
The ID of the local user.
-
Occurs when the SDK gets the user ID and user account of the remote user.
After a remote user joins the channel, the SDK gets the user ID and user account of the remote user, caches them in a mapping table object (userInfo), and triggers this callback on the local client.
Declaration
Swift
open func rtceEngine(_ engine: AgoraRtcEngineKit, didUpdated userInfo: AgoraUserInfo, withUid uid: UInt)
Parameters
engine
AgoraRtcEngineKit object
userInfo
The AgoraUserInfo object that contains the user ID and user account of the remote user.
uid
The ID of the remote user.
-
Occurs when the local user role switches in a live broadcast.
The SDK triggers this callback when the local user switches the user role by calling the setClientRole method after joining the channel.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, didClientRoleChanged oldRole: AgoraClientRole, newRole: AgoraClientRole)
Parameters
engine
AgoraRtcEngineKit object
oldRole
Role that the user switches from: AgoraClientRole.
newRole
Role that the user switches to: AgoraClientRole.
-
Occurs when a remote user or host joins a channel.
The SDK triggers this callback under one of the following circumstances: - A remote user/host joins the channel by calling the joinChannelByToken method. - A remote user switches the user role to the host by calling the setClientRole method after joining the channel. - A remote user/host rejoins the channel after a network interruption. - A host injects an online media stream into the channel by calling the addInjectStreamUrl method.
Note
Live-broadcast profile:- The host receives this callback when another host joins the channel.
- The audience in the channel receives this callback when a new host joins the channel.
- When a web application joins the channel, the SDK triggers this callback as long as the web application publishes streams.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, didJoinedOfUid uid: UInt, elapsed: Int)
Parameters
engine
AgoraRtcEngineKit object
channel
Channel name.
uid
ID of the remote user whose video state changes.
elapsed
The time elapsed (ms) from the local user calling Agora’s
joinChannel
method until the SDK triggers this callback. -
Occurs when a remote user (Communication)/host (Live Broadcast) leaves a channel. Same as userOfflineBlock.
There are two reasons for users to be offline:
- Leave a channel: When the user/host leaves a channel, the user/host sends a goodbye message. When the message is received, the SDK assumes that the user/host leaves a channel.
- Drop offline: When no data packet of the user or host is received for a certain period of time (20 seconds for the Communication profile, and more for the Live-broadcast profile), the SDK assumes that the user/host drops offline. Unreliable network connections may lead to false detections, so Agora recommends using a signaling system for more reliable offline detection.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, didOfflineOfUid uid: UInt, reason: AgoraUserOfflineReason)
Parameters
engine
AgoraRtcEngineKit object
uid
ID of the user or host who leaves a channel or goes offline.
reason
Reason why the user goes offline, see AgoraUserOfflineReason.
-
Occurs when the network connection state changes.
The SDK triggers this callback to report on the current network connection state when it changes, and the reason of the change.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, connectionChangedTo state: AgoraConnectionStateType, reason: AgoraConnectionChangedReason)
Parameters
engine
AgoraRtcEngineKit object
state
The current network connection state, see AgoraConnectionStateType.
reason
The reason of the connection state change, see AgoraConnectionChangedReason.
-
Occurs when the local network type changes.
When the network connection is interrupted, this callback indicates whether the interruption is caused by a network type change or poor network conditions.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, networkTypeChangedTo type: AgoraNetworkType)
Parameters
engine
AgoraRtcEngineKit object
type
The network type, see AgoraNetworkType.
-
Occurs when the SDK cannot reconnect to Agora’s edge server 10 seconds after its connection to the server is interrupted.
The SDK triggers this callback when it cannot connect to the server 10 seconds after calling the joinChannelByToken method, regardless of whether it is in the channel or not.
This callback is different from rtcEngineConnectionDidInterrupted:
- The SDK triggers the rtcEngineConnectionDidInterrupted callback when it loses connection with the server for more than four seconds after it successfully joins the channel.
- The SDK triggers the rtcEngineConnectionDidLost callback when it loses connection with the server for more than 10 seconds, regardless of whether it joins the channel or not. If the SDK fails to rejoin the channel 20 minutes after being disconnected from Agora’s edge server, the SDK stops rejoining the channel.
Declaration
Swift
open func rtcEngineConnectionDidLost(_ engine: AgoraRtcEngineKit)
Parameters
engine
AgoraRtcEngineKit object
-
Occurs when the token expires in 30 seconds.
The user becomes offline if the token used in the joinChannelByToken method expires. The SDK triggers this callback 30 seconds before the token expires to remind the app to get a new token. Upon receiving this callback, generate a new token on the server and call the renewToken method to pass the new token to the SDK.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, tokenPrivilegeWillExpire token: String)
Parameters
engine
AgoraRtcEngineKit object
token
The token that expires in 30 seconds.
-
Occurs when the token expires.
After a token is specified by calling the joinChannelByToken method, if the SDK losses connection to the Agora server due to network issues, the token may expire after a certain period of time and a new token may be required to reconnect to the server.
Th SDK triggers this callback to notify the app to generate a new token. Call the renewToken method to renew the token.
Declaration
Swift
open func rtcEngineRequestToken(_ engine: AgoraRtcEngineKit)
Parameters
engine
AgoraRtcEngineKit object
-
Reports which users are speaking, the speakers’ volumes, and whether the local user is speaking.
This callback reports the IDs and volumes of the loudest speakers at the moment in the channel, and whether the local user is speaking. By default, this callback is disabled. You can enable it by calling the enableAudioVolumeIndication method. Once enabled, this callback is triggered at the set interval, regardless of whether a user speaks or not. The SDK triggers two independent reportAudioVolumeIndicationOfSpeakers callbacks at one time, which separately report the volume information of the local user and all the remote speakers. For more information, see the detailed parameter descriptions.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, reportAudioVolumeIndicationOfSpeakers speakers: [AgoraRtcAudioVolumeInfo], totalVolume: Int)
Parameters
engine
AgoraRtcEngineKit object
speakers
AgoraRtcAudioVolumeInfo array. An empty speakers array in the callback indicates that no remote user is speaking at the moment.
- In the local user’s callback, this array contains the following members: uid = 0, volume = totalVolume, which reports the sum of the voice volume and audio-mixing volume of the local user, and vad, which reports the voice activity status of the local user.
- In the remote speakers’ callback, this array contains the following members: uid of each remote speaker, volume, which reports the sum of the voice volume and audio-mixing volume of each remote speaker, and vad = 0.
totalVolume
Total volume after audio mixing. The value range is [0,255].
- In the local user’s callback, totalVolume is the sum of the voice volume and audio-mixing volume of the local user.
- In the remote speakers’ callback, totalVolume is the sum of the voice volume and audio-mixing volume of all the remote speakers.
-
Occurs when a remote user’s audio stream is muted/unmuted.
The SDK triggers this callback when the remote user stops or resumes sending the audio stream by calling the muteLocalAudioStream method.
Note
This callback is invalid when the number of the users or broadcasters in a channel exceeds 20.Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, didAudioMuted muted: Bool, byUid uid: UInt)
Parameters
engine
AgoraRtcEngineKit object
muted
Whether the remote user’s audio stream is muted/unmuted. Where
true
represets MUTED, andfalse
is UNMUTEDuid
ID of the remote user or host who’s mic was muted
-
Reports which user is the loudest speaker over a period of time.
This callback reports the speaker with the highest accumulative volume during a certain period. If the user enables the audio volume indication by calling the enableAudioVolumeIndication method, this callback returns the user ID of the active speaker whose voice is detected by the audio volume detection module of the SDK.
Note
- To receive this callback, you need to call the enableAudioVolumeIndication method.
- This callback returns the user ID of the user with the highest voice volume during a period of time, instead of at the moment.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, activeSpeaker speakerUid: UInt)
Parameters
engine
AgoraRtcEngineKit object
speakerUid
The user ID of the active speaker. A speakerUid of 0 represents the local user.
-
Occurs when the engine sends the first local audio frame.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, firstLocalAudioFrame elapsed: Int)
Parameters
engine
AgoraRtcEngineKit object
elapsed
Time elapsed (ms) from the local user calling the joinChannelByToken method until the SDK triggers this callback.
-
Occurs when the engine receives the first audio frame from a specified remote user.
This callback is triggered in either of the following scenarios:
- The remote user joins the channel and sends the audio stream.
- The remote user stops sending the audio stream and re-sends it after 15 seconds. Possible reasons include:
- The remote user leaves channel.
- The remote user drops offline.
- The remote user calls muteLocalAudioStream.
- The remote user calls disableAudio.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, firstRemoteAudioFrameOfUid uid: UInt, elapsed: Int)
Parameters
engine
AgoraRtcEngineKit object
uid
User ID of the remote user.
elapsed
Time elapsed (ms) from the local user calling the joinChannelByToken method until the SDK triggers this callback.
-
Occurs when a remote user’s video stream playback pauses/resumes.
You can also use the remoteVideoStateChangedOfUid callback with the following parameters:
AgoraVideoRemoteStateStopped(0)
andAgoraVideoRemoteStateReasonRemoteMuted(5)
.AgoraVideoRemoteStateDecoding(2)
andAgoraVideoRemoteStateReasonRemoteUnmuted(6)
.
The SDK triggers this callback when the remote user stops or resumes sending the video stream by calling the muteLocalVideoStream method.
Note
This callback is invalid when the number of users or broadcasters in a channel exceeds 20.Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, didVideoMuted muted: Bool, byUid uid: UInt)
Parameters
engine
AgoraRtcEngineKit object
muted
A remote user’s video stream playback pauses/resumes. Where
true
represets PAUSE, andfalse
is RESUMEuid
ID of the remote user or host who’s video was paused/resumed
-
Occurs when the remote video state changes.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, remoteVideoStateChangedOfUid uid: UInt, state: AgoraVideoRemoteState, reason: AgoraVideoRemoteStateReason, elapsed: Int)
Parameters
engine
AgoraRtcEngineKit object
uid
ID of the remote user whose video state changes.
state
The state of the remote video. For more detail see AgoraVideoRemoteState
reason
The reason of the remote video state change. For more detail see AgoraVideoRemoteStateReason
elapsed
The time elapsed (ms) from the local user calling Agora’s
joinChannel
method until the SDK triggers this callback.
-
Occurs when the local user receives the data stream from a remote user within five seconds.
The SDK triggers this callback when the local user receives the stream message that the remote user sends by calling the sendStreamMessage method.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, receiveStreamMessageFromUid uid: UInt, streamId: Int, data: Data)
Parameters
engine
AgoraRtcEngineKit object
uid
User ID of the remote user sending the message.
streamId
Stream ID
data
Data received by the local user
-
Occurs when the local user does not receive the data stream from the remote user within five seconds.
The SDK triggers this callback when the local user fails to receive the stream message that the remote user sends by calling the sendStreamMessage method.
Declaration
Swift
open func rtcEngine(_ engine: AgoraRtcEngineKit, didOccurStreamMessageErrorFromUid uid: UInt, streamId: Int, error: Int, missed: Int, cached: Int)
Parameters
engine
AgoraRtcEngineKit object
uid
User ID of the remote user sending the message.
streamId
Stream ID
error
Error code. See AgoraErrorCode.
missed
Number of lost messages.
cached
Number of incoming cached messages when the data stream is interrupted.