AgoraRtcEngineDelegate Protocol Reference

Conforms to NSObject
Declared in AgoraRtcEngineKit.h

Overview

The AgoraRtcEngineDelegate protocol enables callbacks to your app.

The SDK uses delegate callbacks in the AgoraRtcEngineDelegate protocol to report runtime events to the app. From v1.1, some block callbacks in the SDK are replaced with delegate callbacks. The old block callbacks are therefore deprecated, but can still be used in the current version. However, Agora recommends replacing block callbacks with delegate callbacks. The SDK calls the block callback if a callback is defined in both the block and delegate callbacks.

Core Delegate Methods

– rtcEngine:didOccurWarning:

Reports a warning during SDK runtime.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didOccurWarning:(AgoraWarningCode)warningCode

Parameters

engine

AgoraRtcEngineKit object

warningCode

Warning code: AgoraWarningCode

Discussion

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.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didOccurError:

Reports an error during SDK runtime.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didOccurError:(AgoraErrorCode)errorCode

Parameters

engine

AgoraRtcEngineKit object

errorCode

Error code: AgoraErrorCode

Discussion

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.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didApiCallExecute:api:result:

Occurs when a method is executed by the SDK.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didApiCallExecute:(NSInteger)error api:(NSString *_Nonnull)api result:(NSString *_Nonnull)result

Parameters

engine

AgoraRtcEngineKit object.

error

The error code (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.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didJoinChannel:withUid:elapsed:

Occurs when the local user joins a specified channel.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didJoinChannel:(NSString *_Nonnull)channel withUid:(NSUInteger)uid elapsed:(NSInteger)elapsed

Parameters

engine

AgoraRtcEngineKit object.

channel

Channel name.

uid

User ID. If the uid is specified in the joinChannelByToken method, the specified user ID is returned. If the user ID is not specified when the joinChannelByToken method is called, the server automatically assigns a uid.

elapsed

Time elapsed (ms) from the user calling the joinChannelByToken method until the SDK triggers this callback.

Discussion

Same as joinSuccessBlock in the joinChannelByToken method.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didRejoinChannel:withUid:elapsed:

Occurs when the local user rejoins a channel.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didRejoinChannel:(NSString *_Nonnull)channel withUid:(NSUInteger)uid elapsed:(NSInteger)elapsed

Parameters

engine

AgoraRtcEngineKit object.

channel

Channel name.

uid

User ID. If the uid is specified in the joinChannelByToken method, the specified user ID is returned. If the user ID is not specified when the joinChannelByToken method is called, the server automatically assigns a uid.

elapsed

Time elapsed (ms) from the user calling joinChannelByToken until the SDK triggers this callback.

Discussion

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.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didLeaveChannelWithStats:

Occurs when the local user leaves a channel.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didLeaveChannelWithStats:(AgoraChannelStats *_Nonnull)stats

Parameters

engine

AgoraRtcEngineKit object.

stats

Statistics of the call: AgoraChannelStats.

Discussion

When the app calls the leaveChannel method, this callback notifies the app that a user leaves a channel.

With this callback, the app gets information, such as the call duration and the statistics of the received/transmitted data reported by the audioQualityOfUid callback.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didRegisteredLocalUser:withUid:

Occurs when the local user successfully registers a user account by calling the registerLocalUserAccount or joinChannelByUserAccount method.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didRegisteredLocalUser:(NSString *_Nonnull)userAccount withUid:(NSUInteger)uid

Parameters

engine

AgoraRtcEngineKit object.

userAccount

The user account of the local user.

uid

The ID of the local user.

Discussion

This callback reports the user ID and user account of the local user.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didUpdatedUserInfo:withUid:

Occurs when the SDK gets the user ID and user account of the remote user.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didUpdatedUserInfo:(AgoraUserInfo *_Nonnull)userInfo withUid:(NSUInteger)uid

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.

Discussion

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.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didClientRoleChangeFailed:currentRole:

Occurs when the user role switch fails in the interactive live streaming.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didClientRoleChangeFailed:(AgoraClientRoleChangeFailedReason)reason currentRole:(AgoraClientRole)currentRole

Parameters

engine

AgoraRtcEngineKit object.

reason

The reason for the user role switch failure. See AgoraClientRoleChangeFailedReason.

currentRole

The current user role. See AgoraClientRole.

Availability

v3.7.0

In the LiveBroadcasting channel profile, when the local user calls setClientRole to switch their user role after joining the channel but the switch fails, the SDK triggers this callback to report the reason for the failure and the current user role.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didClientRoleChanged:newRole:

Occurs when the user role switches successfully in the interactive live streaming.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didClientRoleChanged:(AgoraClientRole)oldRole newRole:(AgoraClientRole)newRole

Parameters

engine

AgoraRtcEngineKit object.

oldRole

Role that the user switches from: AgoraClientRole.

newRole

Role that the user switches to: AgoraClientRole.

Discussion

In the LiveBroadcasting channel profile, when the local user successfully calls setClientRole to switch their user role after joining the channel, for example, from a host to an audience member or vice versa, the SDK triggers this callback to report the user role before and after the switch.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didJoinedOfUid:elapsed:

Occurs when a remote user or host joins a channel. Same as userJoinedBlock.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didJoinedOfUid:(NSUInteger)uid elapsed:(NSInteger)elapsed

Parameters

engine

AgoraRtcEngineKit object.

uid

ID of the user or host who joins the channel. If the uid is specified in the joinChannelByToken method, the specified user ID is returned. If the uid is not specified in the joinChannelByToken method, the Agora server automatically assigns a uid.

elapsed

Time elapsed (ms) from the local user calling the joinChannelByToken or setClientRole method until the SDK triggers this callback.

Discussion

  • Communication profile: This callback notifies the app that another user joins the channel. If other users are already in the channel, the SDK also reports to the app on the existing users.
  • Interactive live streaming profile: This callback notifies the app that a host joins the channel. If other hosts are already in the channel, the SDK also reports to the app on the existing hosts. Agora recommends limiting the number of hosts to 17.

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.

Note:

Interactive live streaming 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.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didOfflineOfUid:reason:

Occurs when a remote user (Communication)/host (Live Broadcast) leaves a channel. Same as userOfflineBlock.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didOfflineOfUid:(NSUInteger)uid reason:(AgoraUserOfflineReason)reason

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.

Discussion

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 interactive live streaming profile), the SDK assumes that the user/host drops offline. Unreliable network connections may lead to NO detections, so Agora recommends using the Agora RTM SDK for more reliable offline detection.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:connectionChangedToState:reason:

Occurs when the network connection state changes.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine connectionChangedToState:(AgoraConnectionStateType)state reason:(AgoraConnectionChangedReason)reason

Parameters

engine

AgoraRtcEngineKit object.

state

The current network connection state, see AgoraConnectionStateType.

reason

The reason of the connection state change, see AgoraConnectionChangedReason.

Discussion

The SDK triggers this callback to report on the current network connection state when it changes, and the reason of the change.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:networkTypeChangedToType:

Occurs when the local network type changes.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine networkTypeChangedToType:(AgoraNetworkType)type

Parameters

engine

AgoraRtcEngineKit object.

type

The network type, see AgoraNetworkType.

Discussion

When the network connection is interrupted, this callback indicates whether the interruption is caused by a network type change or poor network conditions.

Declared In

AgoraRtcEngineKit.h

– rtcEngineConnectionDidLost:

Occurs when the SDK cannot reconnect to Agora’s edge server 10 seconds after its connection to the server is interrupted.

- (void)rtcEngineConnectionDidLost:(AgoraRtcEngineKit *_Nonnull)engine

Parameters

engine

AgoraRtcEngineKit object.

Discussion

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.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:tokenPrivilegeWillExpire:

Occurs when the token expires in 30 seconds.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine tokenPrivilegeWillExpire:(NSString *_Nonnull)token

Parameters

engine

AgoraRtcEngineKit object.

token

The token that expires in 30 seconds.

Discussion

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.

Declared In

AgoraRtcEngineKit.h

– rtcEngineRequestToken:

Occurs when the token expires.

- (void)rtcEngineRequestToken:(AgoraRtcEngineKit *_Nonnull)engine

Parameters

engine

AgoraRtcEngineKit object.

Discussion

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.

This callback notifies the app to generate a new token and call joinChannelByToken to rejoin the channel with the new token.

Declared In

AgoraRtcEngineKit.h

Media Delegate Methods

– rtcEngine:reportAudioVolumeIndicationOfSpeakers:totalVolume:

Reports the volume information of users.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine reportAudioVolumeIndicationOfSpeakers:(NSArray<AgoraRtcAudioVolumeInfo*> *_Nonnull)speakers totalVolume:(NSInteger)totalVolume

Parameters

engine

AgoraRtcEngineKit object.

speakers

The volume information of users. See AgoraRtcAudioVolumeInfo.

An empty speakers array in the callback indicates that no remote user is in the channel or sending a stream at the moment.

totalVolume

Total volume after audio mixing. The value ranges between 0 (lowest volume) and 255 (highest volume).

  • In the local user’s callback, totalVolume is the volume of the local user who sends a stream.
  • In the remote speakers' callback, totalVolume is the sum of the volume of all remote users (up to three) whose instantaneous volumes are the highest.

If the user calls startAudioMixing, totalVolume is the sum of the voice volume and audio-mixing volume.

Discussion

By default, this callback is disabled. You can enable it by calling enableAudioVolumeIndication. Once this callback is enabled and users send streams in the channel, the SDK triggers the reportAudioVolumeIndicationOfSpeakers callback at the time interval set in enableAudioVolumeIndication.

The SDK triggers two independent reportAudioVolumeIndicationOfSpeakers callbacks simultaneously, which separately report the volume information of the local user who sends a stream and the remote users (up to three) whose instantaneous volumes are the highest.

Note: After you enable this callback, calling muteLocalAudioStream affects the SDK’s behavior as follows:

  • If the local user calls muteLocalAudioStream, the SDK stops triggering the local user’s callback.
  • 20 seconds after a remote user whose volume is one of the three highest calls muteLocalAudioStream method, the remote users' callback excludes this remote user’s information; 20 seconds after all remote users call muteLocalAudioStream, the SDK stops triggering the remote users' callback.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:reportLocalVoicePitchFrequency:

Reports the voice pitch of the local user.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine reportLocalVoicePitchFrequency:(NSInteger)pitchInHz

Parameters

engine

AgoraRtcEngineKit object.

pitchInHz

The voice pitch (Hz) of the local user.

Availability

v3.7.0

After the local audio capture is enabled, and you call enableLocalVoicePitchCallback, the SDK triggers this callback at the time interval set in enableLocalVoicePitchCallback.

Discussion

Note: After this callback is enabled, if the user disables the local audio capture, for example, by calling enableLocalAudio(NO), the SDK immediately stops sending this callback.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:reportAudioDeviceTestVolume:volume:

Reports the result of an audio device test.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine reportAudioDeviceTestVolume:(AgoraAudioDeviceTestVolumeType)volumeType volume:(NSInteger)volume

Parameters

engine

AgoraRtcEngineKit

volumeType

The volume type. See AgoraAudioDeviceTestVolumeType.

volume

The volume, in the range of [0,255].

Availability

v3.6.2

After successfully calling startRecordingDeviceTest, startPlaybackDeviceTest, or startAudioDeviceLoopbackTest to start an audio device test, the SDK triggers this callback at the set time interval to report the volume information of the audio device tested.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:activeSpeaker:

Occurs when the most active remote speaker is detected.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine activeSpeaker:(NSUInteger)speakerUid

Parameters

engine

AgoraRtcEngineKit object.

speakerUid

The user ID of the most active remote speaker.

Discussion

After a successful call of enableAudioVolumeIndication, the SDK continuously detects which remote user has the loudest volume. During the current period, the remote user, who is detected as the loudest for the most times, is the most active user.

When the number of users is more than or equal to two and an active speaker exists, the SDK triggers this callback and reports the uid of the most active speaker.

  • If the most active speaker is always the same user, the SDK triggers this callback only once.
  • If the most active speaker changes to another user, the SDK triggers this callback again and reports the uid of the new active speaker.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:firstLocalAudioFramePublished:

Occurs when the first audio frame is published.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine firstLocalAudioFramePublished:(NSInteger)elapsed

Parameters

engine

AgoraRtcEngineKit object.

elapsed

The time elapsed (ms) from the local client calling joinChannelByToken until the SDK triggers this callback.

Availability

v3.1.0

The SDK triggers this callback under one of the following circumstances:

Declared In

AgoraRtcEngineKit.h

– rtcEngine:firstLocalVideoFrameWithSize:elapsed:

Occurs when the first local video frame is displayed/rendered on the local video view.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine firstLocalVideoFrameWithSize:(CGSize)size elapsed:(NSInteger)elapsed

Parameters

engine

AgoraRtcEngineKit object.

size

Size of the first local video frame (width and height).

elapsed

Time elapsed (ms) from the local user calling the joinChannelByToken method until the SDK calls this callback.

If the startPreview method is called before the joinChannelByToken method, then elapsed is the time elapsed from calling the startPreview method until the SDK triggers this callback.

Discussion

Same as firstLocalVideoFrameBlock.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:firstLocalVideoFramePublished:

Occurs when the first video frame is published.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine firstLocalVideoFramePublished:(NSInteger)elapsed

Parameters

engine

AgoraRtcEngineKit object.

elapsed

The time elapsed (ms) from the local client calling joinChannelByToken until the SDK triggers this callback.

Availability

v3.1.0

The SDK triggers this callback under one of the following circumstances:

Declared In

AgoraRtcEngineKit.h

– rtcEngine:videoSizeChangedOfUid:size:rotation:

Occurs when the video size or rotation of a specific remote user changes.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine videoSizeChangedOfUid:(NSUInteger)uid size:(CGSize)size rotation:(NSInteger)rotation

Parameters

engine

AgoraRtcEngineKit object.

uid

User ID of the remote user or local user (0) whose video size or rotation changes.

size

New video size.

rotation

New rotation of the video. The value ranges between 0 and 360.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:remoteVideoStateChangedOfUid:state:reason:elapsed:

Occurs when the remote video state changes.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine remoteVideoStateChangedOfUid:(NSUInteger)uid state:(AgoraVideoRemoteState)state reason:(AgoraVideoRemoteStateReason)reason elapsed:(NSInteger)elapsed

Parameters

engine

AgoraRtcEngineKit object.

uid

ID of the remote user whose video state changes.

state

The state of the remote video. See AgoraVideoRemoteState.

reason

The reason of the remote video state change. See AgoraVideoRemoteStateReason.

elapsed

The time elapsed (ms) from the local user calling the joinChannel method until the SDK triggers this callback.

Discussion

Note: This callback can be inaccurate when the number of users (in the communication profile) or hosts (in the interactive live streaming profile) in a channel exceeds 17.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:superResolutionEnabledOfUid:enabled:reason:

Reports whether the super resolution feature is successfully enabled. (beta feature)

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine superResolutionEnabledOfUid:(NSUInteger)uid enabled:(BOOL)enabled reason:(AgoraSuperResolutionStateReason)reason

Parameters

engine

AgoraRtcEngineKit object.

uid

The user ID of the remote user.

enabled

Whether super resolution is successfully enabled:

  • YES: Super resolution is successfully enabled.
  • NO: Super resolution is not successfully enabled.
reason

The reason why super resolution is not successfully enabled or the message that confirms success. See AgoraSuperResolutionStateReason.

Availability

v3.5.1

After calling enableRemoteSuperResolution, the SDK triggers this callback to report whether super resolution is successfully enabled. If it is not successfully enabled, use reason for troubleshooting.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:virtualBackgroundSourceEnabled:reason:

Reports whether the virtual background is successfully enabled.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine virtualBackgroundSourceEnabled:(BOOL)enabled reason:(AgoraVirtualBackgroundSourceStateReason)reason

Parameters

engine

AgoraRtcEngineKit object.

enabled

Whether the virtual background is successfully enabled:

  • YES: The virtual background is successfully enabled.
  • NO: The virtual background is not successfully enabled.
reason

The reason why the virtual background is not successfully enabled or the message that confirms success. See AgoraVirtualBackgroundSourceStateReason.

Availability

Support for macOS as of v3.4.5 and iOS as of v3.5.0.

After you call enableVirtualBackground, the SDK triggers this callback to report whether the virtual background is successfully enabled.

Discussion

Note: If the background image customized in the virtual background is in PNG or JPG format, the triggering of this callback is delayed until the image is read.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:snapshotTaken:uid:filePath:width:height:errCode:

Reports the result of taking a video snapshot.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine snapshotTaken:(NSString *_Nonnull)channel uid:(NSUInteger)uid filePath:(NSString *_Nonnull)filePath width:(NSInteger)width height:(NSInteger)height errCode:(NSInteger)errCode

Parameters

engine

AgoraRtcEngineKit

channel

The channel name.

uid

The user ID of the user. A uid of 0 indicates the local user.

filePath

The local path of the snapshot.

width

The width (px) of the snapshot.

height

The height (px) of the snapshot.

errCode

The message that confirms success or the reason why the snapshot is not successfully taken:

  • 0: Success.
  • < 0: Failure:

    • -1: The SDK fails to write data to a file or encode a JPEG image.
    • -2: The SDK does not find the video stream of the specified user within one second after the takeSnapshot method call succeeds.

Availability

v3.5.2

After a successful takeSnapshot method call, the SDK triggers this callback to report whether the snapshot is successfully taken as well as the details for the snapshot taken.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:localVideoStateChange:error:

Occurs when the local video stream state changes.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine localVideoStateChange:(AgoraLocalVideoStreamState)state error:(AgoraLocalVideoStreamError)error

Parameters

engine

AgoraRtcEngineKit object.

state

The local video state, see AgoraLocalVideoStreamState.

error

The detailed error information of the local video, see AgoraLocalVideoStreamError.

Discussion

The SDK reports the current video state in this callback.

The SDK triggers the localVideoStateChange(AgoraLocalVideoStreamStateFailed, AgoraLocalVideoStreamErrorCaptureFailure) callback in the following situations:

  • The application exits to the background, and the system recycles the camera.
  • The camera starts normally, but the captured video is not output for four seconds.

When the camera outputs the captured video frames, if all the video frames are the same for 15 consecutive frames, the SDK triggers the localVideoStateChange(AgoraLocalVideoStreamStateCapturing, AgoraLocalVideoStreamErrorCaptureFailure) callback. Note that the video frame duplication detection is only available for video frames with a resolution greater than 200 × 200, a frame rate greater than or equal to 10 fps, and a bitrate less than 20 Kbps.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:remoteAudioStateChangedOfUid:state:reason:elapsed:

Occurs when the local audio state changes.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine remoteAudioStateChangedOfUid:(NSUInteger)uid state:(AgoraAudioRemoteState)state reason:(AgoraAudioRemoteStateReason)reason elapsed:(NSInteger)elapsed

Parameters

engine

See AgoraRtcEngineKit.

uid

ID of the remote user whose audio state changes.

state

State of the remote audio. See AgoraAudioRemoteState.

reason

The reason of the remote audio state change. See AgoraAudioRemoteStateReason.

elapsed

Time elapsed (ms) from the local user calling the joinChannel method until the SDK triggers this callback.

Discussion

This callback indicates the state change of the local audio stream, including the state of the audio sampling and encoding, and allows you to troubleshoot issues when exceptions occur.

Note: This callback can be inaccurate when the number of users (in the communication profile) or hosts (in the interactive live streaming profile) in a channel exceeds 17.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:localAudioStateChange:error:

Occurs when the local audio state changes.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine localAudioStateChange:(AgoraAudioLocalState)state error:(AgoraAudioLocalError)error

Parameters

engine

See AgoraRtcEngineKit.

state

The state of the local audio. See AgoraAudioLocalState.

error

The error information of the local audio. See AgoraAudioLocalError.

Discussion

This callback indicates the state change of the local audio stream, including the state of the audio sampling and encoding, and allows you to troubleshoot issues when exceptions occur.

Note: When the state is AgoraAudioLocalStateFailed(3), see the error parameter for details.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:firstRemoteVideoFrameOfUid:size:elapsed:

Occurs when the first remote video frame is rendered.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine firstRemoteVideoFrameOfUid:(NSUInteger)uid size:(CGSize)size elapsed:(NSInteger)elapsed

Parameters

engine

AgoraRtcEngineKit object.

uid

User ID of the remote user sending the video stream.

size

Size of the video frame (width and height).

elapsed

Time elapsed (ms) from the local user calling the joinChannelByToken method until the SDK triggers this callback.

Discussion

Same as firstRemoteVideoFrameBlock.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didAudioPublishStateChange:oldState:newState:elapseSinceLastState:

Occurs when the audio publishing state changes.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didAudioPublishStateChange:(NSString *_Nonnull)channel oldState:(AgoraStreamPublishState)oldState newState:(AgoraStreamPublishState)newState elapseSinceLastState:(NSInteger)elapseSinceLastState

Parameters

engine

AgoraRtcEngineKit object.

channel

The channel name.

oldState

The previous publishing state. For details, see AgoraStreamPublishState.

newState

The current publishing state. For details, see AgoraStreamPublishState.

elapseSinceLastState

The time elapsed (ms) from the previous state to the current state.

Availability

v3.1.0

This callback indicates the publishing state change of the local audio stream.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didVideoPublishStateChange:oldState:newState:elapseSinceLastState:

Occurs when the video publishing state changes.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didVideoPublishStateChange:(NSString *_Nonnull)channel oldState:(AgoraStreamPublishState)oldState newState:(AgoraStreamPublishState)newState elapseSinceLastState:(NSInteger)elapseSinceLastState

Parameters

engine

AgoraRtcEngineKit object.

channel

The channel name.

oldState

The previous publishing state. For details, see AgoraStreamPublishState.

newState

The current publishing state. For details, see AgoraStreamPublishState.

elapseSinceLastState

The time elapsed (ms) from the previous state to the current state.

Availability

v3.1.0

This callback indicates the publishing state change of the local video stream.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didAudioSubscribeStateChange:withUid:oldState:newState:elapseSinceLastState:

Occurs when the audio subscribing state changes.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didAudioSubscribeStateChange:(NSString *_Nonnull)channel withUid:(NSUInteger)uid oldState:(AgoraStreamSubscribeState)oldState newState:(AgoraStreamSubscribeState)newState elapseSinceLastState:(NSInteger)elapseSinceLastState

Parameters

engine

AgoraRtcEngineKit object.

channel

The channel name.

uid

The ID of the remote user.

oldState

The previous subscribing state. For details, see AgoraStreamSubscribeState.

newState

The current subscribing state. For details, see AgoraStreamSubscribeState.

elapseSinceLastState

The time elapsed (ms) from the previous state to the current state.

Availability

v3.1.0

This callback indicates the subscribing state change of a remote audio stream.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didVideoSubscribeStateChange:withUid:oldState:newState:elapseSinceLastState:

Occurs when the video subscribing state changes.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didVideoSubscribeStateChange:(NSString *_Nonnull)channel withUid:(NSUInteger)uid oldState:(AgoraStreamSubscribeState)oldState newState:(AgoraStreamSubscribeState)newState elapseSinceLastState:(NSInteger)elapseSinceLastState

Parameters

engine

AgoraRtcEngineKit object.

channel

The channel name.

uid

The ID of the remote user.

oldState

The previous subscribing state. For details, see AgoraStreamSubscribeState.

newState

The current subscribing state. For details, see AgoraStreamSubscribeState.

elapseSinceLastState

The time elapsed (ms) from the previous state to the current state.

Availability

v3.1.0

This callback indicates the subscribing state change of a remote video stream.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didAudioMuted:byUid:

Occurs when a remote user’s audio stream is muted/unmuted.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didAudioMuted:(BOOL)muted byUid:(NSUInteger)uid

Parameters

engine

AgoraRtcEngineKit object.

muted

Whether the remote user’s audio stream is muted/unmuted:

  • YES: Muted.
  • NO: Unmuted.
uid

ID of the remote user.

Discussion

You can also use the remoteAudioStateChangedOfUid callback with the following parameters instead:

  • AgoraAudioRemoteStateStopped(0) and AgoraAudioRemoteReasonRemoteMuted(5).
  • AgoraAudioRemoteStateDecoding(2) and AgoraAudioRemoteReasonRemoteUnmuted(6).

The SDK triggers this callback when the remote user stops or resumes sending the audio stream by calling the muteLocalAudioStream method.

Note: This callback can be inaccurate when the number of users (in the communication profile) or hosts (in the interactive live streaming profile) in a channel exceeds 17.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didVideoMuted:byUid:

Occurs when a remote user stops or resumes publishing the video stream.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didVideoMuted:(BOOL)muted byUid:(NSUInteger)uid

Parameters

engine

AgoraRtcEngineKit object.

muted

A remote user’s video stream playback pauses/resumes:

  • YES: Pause.
  • NO: Resume.
uid

User ID of the remote user.

Discussion

Same as userMuteVideoBlock.

When a remote user calls muteLocalVideoStream to stop or resume publishing the video stream, the SDK triggers this callback to report the state of the remote user’s publishing stream to the local user.

Note: This callback can be inaccurate when the number of users (in the communication profile) or hosts (in the interactive live streaming profile) in a channel exceeds 17.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didProxyConnected:withUid:proxyType:localProxyIp:elapsed:

Reports the proxy connection state.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didProxyConnected:(NSString *_Nonnull)channel withUid:(NSUInteger)uid proxyType:(AgoraProxyType)proxyType localProxyIp:(NSString *_Nonnull)localProxyIp elapsed:(NSInteger)elapsed

Parameters

engine

AgoraRtcEngineKit object.

channel

The channel name.

uid

The user ID.

proxyType

The proxy type connected. See AgoraProxyType.

localProxyIp

Reserved for future use.

elapsed

The time elapsed (ms) from the user calling joinChannel until this callback is triggered.

Availability

v3.6.2

You can use this callback to listen for the state of the SDK connecting to a proxy. For example, when a user calls setCloudProxy and joins a channel successfully, the SDK triggers this callback to report the user ID, the proxy type connected, and the time elapsed from the user calling joinChannelByToken until this callback is triggered.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didVideoEnabled:byUid:

Occurs when a specific remote user enables/disables the video module.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didVideoEnabled:(BOOL)enabled byUid:(NSUInteger)uid

Parameters

engine

AgoraRtcEngineKit object.

enabled

Whether the remote user enables/disables the video module:

  • YES: Enable. The remote user can enter a video session.
  • NO: Disable. The remote user can only enter a voice session, and cannot send or receive any video stream.
uid

User ID of the remote user.

Discussion

Once the video module is disabled, the remote user can only use a voice call. The remote user cannot send or receive any video from other users.

The SDK triggers this callback when the remote user enables or disables the video module by calling the enableVideo or disableVideo method.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didLocalVideoEnabled:byUid:

Occurs when a specific remote user enables/disables the local video capturing function.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didLocalVideoEnabled:(BOOL)enabled byUid:(NSUInteger)uid

Parameters

engine

AgoraRtcEngineKit object.

enabled

Whether the specific remote user enables/disables the local video capturing function:

  • YES: Enable. Other users in the channel can see the video of this remote user.
  • NO: Disable. Other users in the channel do not receive the video stream from this remote user, while this remote user can still receive the video streams from other users.
uid

User ID of the remote user.

Discussion

This callback is only applicable to the scenario when the user only wants to watch the remote video without sending any video stream to the other user.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:firstRemoteVideoDecodedOfUid:size:elapsed:

Occurs when the first remote video frame is received and decoded.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine firstRemoteVideoDecodedOfUid:(NSUInteger)uid size:(CGSize)size elapsed:(NSInteger)elapsed

Parameters

engine

AgoraRtcEngineKit object.

uid

User ID of the remote user sending the video stream.

size

Size of the video frame (width and height).

elapsed

Time elapsed (ms) from the local user calling the joinChannelByToken method until the SDK triggers this callback.

Discussion

You can also use AgoraVideoRemoteStateStarting(1) or AgoraVideoRemoteStateDecoding(2) in the remoteVideoStateChangedOfUid callback instead.

Same as firstRemoteVideoDecodedBlock.

This callback is triggered in either of the following scenarios:

  • The remote user joins the channel and sends the video stream.
  • The remote user stops sending the video stream and re-sends it after 15 seconds. Possible reasons include:

Declared In

AgoraRtcEngineKit.h

Fallback Delegate Methods

– rtcEngine:didLocalPublishFallbackToAudioOnly:

Occurs when the published video stream falls back to an audio-only stream due to unreliable network conditions or switches back to the video when the network conditions improve.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didLocalPublishFallbackToAudioOnly:(BOOL)isFallbackOrRecover

Parameters

engine

AgoraRtcEngineKit object.

isFallbackOrRecover

Whether the published stream falls back to audio-only or switches back to the video:

  • YES: The published stream falls back to audio-only due to unreliable network conditions.
  • NO: The published stream switches back to the video after the network conditions improve.

Discussion

If you call the setLocalPublishFallbackOption method and set option as AgoraStreamFallbackOptionAudioOnly, the SDK triggers this callback when the published stream falls back to audio-only mode due to unreliable uplink conditions, or when the audio stream switches back to the video when the uplink network condition improves.

Note:

Once the published stream falls back to audio only, the remote app receives the userMuteVideoBlock callback.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didRemoteSubscribeFallbackToAudioOnly:byUid:

Occurs when the remote video stream falls back to an audio-only stream due to unreliable network conditions or switches back to the video after the network conditions improve.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didRemoteSubscribeFallbackToAudioOnly:(BOOL)isFallbackOrRecover byUid:(NSUInteger)uid

Parameters

engine

AgoraRtcEngineKit object.

isFallbackOrRecover

Whether the remote media stream falls back to audio-only or switches back to the video:

  • YES: The remote media stream falls back to audio-only due to unreliable network conditions.
  • NO: The remote media stream switches back to the video stream after the network conditions improve.
uid

ID of the remote user sending the stream.

Discussion

If you call setRemoteSubscribeFallbackOption and set option as AgoraStreamFallbackOptionAudioOnly, the SDK triggers this callback when the remote media stream falls back to audio only due to poor downlink conditions or switches back to the video after the downlink network condition improves.

Note:

Once the remote media stream is switched to the low stream due to unreliable network conditions, you can monitor the stream switch between a high stream and low stream in the remoteVideoStats callback.

Declared In

AgoraRtcEngineKit.h

Face Detection Delegate Methods

– rtcEngine:facePositionDidChangeWidth:previewHeight:faces:

Reports the face detection result of the local user. (iOS only)

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine facePositionDidChangeWidth:(int)width previewHeight:(int)height faces:(NSArray<AgoraFacePositionInfo*> *_Nullable)faces

Parameters

engine

AgoraRtcEngineKit object.

width

The width (px) of the local video.

height

The height (px) of the local video.

faces

An AgoraFacePositionInfo array, which contains the information of the detected human face.

The number of the AgoraFacePositionInfo array depends on the number of human faces detected. If the array length is 0, it means that no human face is detected.

Discussion

Since: v3.0.1.

Once you enable face detection by calling enableFaceDetection, you can get the following information on the local user in real-time:

  • The width and height of the local video.
  • The position of the human face in the local view.
  • The distance between the human face and the device screen. This value is based on the fitting calculation of the local video size and the position of the human face.

Note

  • If the SDK does not detect a face, it reduces the frequency of this callback to reduce power consumption on the local device.
  • The SDK stops triggering this callback when a human face is in close proximity to the screen.

Declared In

AgoraRtcEngineKit.h

Device Delegate Methods

– rtcEngine:device:type:stateChanged:

Occurs when the device state changes (macOS only).

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine device:(NSString *_Nonnull)deviceId type:(AgoraMediaDeviceType)deviceType stateChanged:(NSInteger)state

Parameters

engine

AgoraRtcEngineKit object.

deviceId

Device ID.

deviceType

Device type: AgoraMediaDeviceType.

state

The state of the device:

  • 0: The device is connected but not in use.
  • 1: The video device is not connected.
  • 8: The audio device is not connected.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didAudioRouteChanged:

Occurs when the local audio route changes.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didAudioRouteChanged:(AgoraAudioOutputRouting)routing

Parameters

engine

AgoraRtcEngineKit object.

routing

The current audio route: AgoraAudioOutputRouting.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:cameraFocusDidChangedToRect:

Occurs when a camera focus area changes. (iOS only.)

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine cameraFocusDidChangedToRect:(CGRect)rect

Parameters

engine

AgoraRtcEngineKit object.

rect

Rectangular area in the camera zoom specifying the focus area.

Discussion

The SDK triggers this callback when the local user changes the camera focus position by calling the setCameraFocusPositionInPreview method.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:cameraExposureDidChangedToRect:

Occurs when the camera exposure area changes. (iOS only)

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine cameraExposureDidChangedToRect:(CGRect)rect

Parameters

engine

AgoraRtcEngineKit object.

rect

Rectangular area in the camera zoom specifying the exposure area.

Discussion

The SDK triggers this callback when the local user changes the camera exposure position by calling the setCameraExposurePosition method.

Declared In

AgoraRtcEngineKit.h

Statistics Delegate Methods

– rtcEngine:reportRtcStats:

Reports the statistics of the current call. The SDK triggers this callback once every two seconds after the user joins the channel.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine reportRtcStats:(AgoraChannelStats *_Nonnull)stats

Parameters

engine

AgoraRtcEngineKit object.

stats

Statistics of the AgoraRtcEngineKit: AgoraChannelStats.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:lastmileQuality:

Reports the last mile network quality of the local user once every two seconds before the user joins a channel.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine lastmileQuality:(AgoraNetworkQuality)quality

Parameters

engine

AgoraRtcEngineKit object.

quality

The last mile network quality based on the uplink and dowlink packet loss rate and jitter. See AgoraNetworkQuality.

Discussion

Last mile refers to the connection between the local device and Agora’s edge server. After the app calls the enableLastmileTest method, the SDK triggers this callback once every two seconds to report the uplink and downlink last mile network conditions of the local user before the user joins the channel.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:networkQuality:txQuality:rxQuality:

Reports the last mile network quality of each user in the channel once every two seconds.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine networkQuality:(NSUInteger)uid txQuality:(AgoraNetworkQuality)txQuality rxQuality:(AgoraNetworkQuality)rxQuality

Parameters

engine

AgoraRtcEngineKit object.

uid

User ID. The network quality of the user with this uid is reported. If uid is 0, the local network quality is reported.

txQuality

Uplink transmission quality of the user in terms of the transmission bitrate, packet loss rate, average RTT (Round-Trip Time), and jitter of the uplink network. txQuality is a quality rating helping you understand how well the current uplink network conditions can support the selected AgoraVideoEncoderConfiguration. For example, a 1000-Kbps uplink network may be adequate for video frames with a resolution of 640 * 480 and a frame rate of 15 fps in the interactive live streaming profile, but may be inadequate for resolutions higher than 1280 * 720. See AgoraNetworkQuality.

rxQuality

Downlink network quality rating of the user in terms of packet loss rate, average RTT, and jitter of the downlink network. See AgoraNetworkQuality.

Discussion

Last mile refers to the connection between the local device and Agora’s edge server. The SDK triggers this callback once every two seconds to report the last mile network conditions of each user in the channel. If a channel includes multiple users, the SDK triggers this callback as many times.

Note: txQuality is Unknown when the user is not sending a stream; rxQuality is Unknown when the user is not receiving a stream.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:lastmileProbeTestResult:

Reports the last-mile network probe result.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine lastmileProbeTestResult:(AgoraLastmileProbeResult *_Nonnull)result

Parameters

engine

AgoraRtcEngineKit object.

result

The uplink and downlink last-mile network probe test result, see AgoraLastmileProbeResult.

Discussion

The SDK triggers this callback within 30 seconds after the app calls the startLastmileProbeTest method.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:localVideoStats:

Reports the statistics of the uploading local video streams once every two seconds. Same as localVideoStatBlock.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine localVideoStats:(AgoraRtcLocalVideoStats *_Nonnull)stats

Parameters

engine

AgoraRtcEngineKit object.

stats

Statistics of the uploading local video streams. See AgoraRtcLocalVideoStats.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:localAudioStats:

Reports the statistics of the local audio stream.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine localAudioStats:(AgoraRtcLocalAudioStats *_Nonnull)stats

Parameters

engine

See AgoraRtcEngineKit.

stats

The statistics of the local audio stream. See AgoraRtcLocalAudioStats.

Discussion

The SDK triggers this callback once every two seconds.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:remoteVideoStats:

Reports the statistics of the video stream from each remote user/host.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine remoteVideoStats:(AgoraRtcRemoteVideoStats *_Nonnull)stats

Parameters

engine

AgoraRtcEngineKit object.

stats

Statistics of the received remote video streams. See AgoraRtcRemoteVideoStats.

Discussion

The SDK triggers this callback once every two seconds for each remote user/host. If a channel includes multiple remote users, the SDK triggers this callback as many times.

This callback reports the statistics more closely linked to the real-user experience of the video transmission quality than the statistics that the videoTransportStatsOfUid callback reports. This callback reports more about media layer statistics such as the frame loss rate, while the videoTransportStatsOfUid callback reports more about the transport layer statistics such as the packet loss rate.

Schemes such as FEC (Forward Error Correction) or retransmission counter the frame loss rate. Hence, users may find the overall video quality acceptable even when the packet loss rate is high.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:remoteAudioStats:

Reports the statistics of the audio stream from each remote user/host.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine remoteAudioStats:(AgoraRtcRemoteAudioStats *_Nonnull)stats

Parameters

engine

AgoraRtcEngineKit object.

stats

Statistics of the received remote audio streams. See AgoraRtcRemoteAudioStats.

Discussion

This callback replaces the audioQualityOfUid callback.

The SDK triggers this callback once every two seconds for each remote user/host. If a channel includes multiple remote users, the SDK triggers this callback as many times.

This callback reports the statistics more closely linked to the real-user experience of the audio transmission quality than the statistics that the audioTransportStatsOfUid callback reports. This callback reports more about media layer statistics such as the frame loss rate, while the audioTransportStatsOfUid callback reports more about the transport layer statistics such as the packet loss rate.

Schemes such as FEC (Forward Error Correction) or retransmission counter the frame loss rate. Hence, users may find the overall audio quality acceptable even when the packet loss rate is high.

Declared In

AgoraRtcEngineKit.h

Audio Player Delegate Methods

– rtcEngineLocalAudioMixingDidFinish:

Occurs when the audio mixing file playback finishes.

- (void)rtcEngineLocalAudioMixingDidFinish:(AgoraRtcEngineKit *_Nonnull)engine

Parameters

engine

AgoraRtcEngineKit object.

Discussion

You can start an audio mixing file playback by calling the startAudioMixing method. The SDK triggers this callback when the audio mixing file playback finishes.

If the startAudioMixing method call fails, a warning code, AgoraWarningCodeAudioMixingOpenError, returns in the didOccurWarning callback.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:localAudioMixingStateDidChanged:reason:

Occurs when the playback state of the local user’s music file changes.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine localAudioMixingStateDidChanged:(AgoraAudioMixingStateCode)state reason:(AgoraAudioMixingReasonCode)reason

Parameters

engine

AgoraRtcEngineKit object.

state

The current music file playback state. See AgoraAudioMixingStateCode.

reason

The reason for the change of the music file playback state. See AgoraAudioMixingReasonCode.

Availability

v3.4.0

Discussion

When the playback state of the local user’s music file changes, the SDK triggers this callback and reports the current playback state and the reason for the change.

Note: When you use startAudioMixing to play an online music file, the moment when the localAudioMixingStateDidChanged callback reports AgoraAudioMixingStatePlaying can be different from the moment when the user hears the music if network conditions are poor. Because the SDK triggers this callback to report the Playing state after decoding the first audio frame, but the SDK cannot receive online audio packets stably under poor network conditions, the music playback is unstable; and the moment when the user subjectively experiences the audio start playing can be later than the moment when the first audio frame is decoded.

Declared In

AgoraRtcEngineKit.h

– rtcEngineRemoteAudioMixingDidStart:

Occurs when a remote user starts audio mixing.

- (void)rtcEngineRemoteAudioMixingDidStart:(AgoraRtcEngineKit *_Nonnull)engine

Parameters

engine

AgoraRtcEngineKit object.

Discussion

The SDK triggers this callback when a remote user calls the startAudioMixing method.

Declared In

AgoraRtcEngineKit.h

– rtcEngineRemoteAudioMixingDidFinish:

Occurs when a remote user finishes audio mixing.

- (void)rtcEngineRemoteAudioMixingDidFinish:(AgoraRtcEngineKit *_Nonnull)engine

Parameters

engine

AgoraRtcEngineKit object.

Declared In

AgoraRtcEngineKit.h

– rtcEngineDidAudioEffectFinish:soundId:

Occurs when the local audio effect playback finishes.

- (void)rtcEngineDidAudioEffectFinish:(AgoraRtcEngineKit *_Nonnull)engine soundId:(NSInteger)soundId

Parameters

engine

AgoraRtcEngineKit object.

soundId

ID of the local audio effect. Each local audio effect has a unique ID.

Discussion

You can start a local audio effect playback by calling the playEffect method. The SDK triggers this callback when the local audio effect file playback finishes.

Declared In

AgoraRtcEngineKit.h

CDN Live Streaming Delegate Methods

– rtcEngine:rtmpStreamingChangedToState:state:errorCode:

Occurs when the state of the RTMP or RTMPS streaming changes.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine rtmpStreamingChangedToState:(NSString *_Nonnull)url state:(AgoraRtmpStreamingState)state errorCode:(AgoraRtmpStreamingErrorCode)errorCode

Parameters

engine

AgoraRtcEngineKit object.

url

The CDN streaming URL.

state

The RTMP or RTMPS streaming state: AgoraRtmpStreamingState.

errorCode

The detailed error information for streaming: AgoraRtmpStreamingErrorCode.

Discussion

When the CDN live streaming state changes, the SDK triggers this callback to report the current state and the reason why the state has changed.

This callback indicates the state of the RTMP or RTMPS streaming. When exceptions occur, you can troubleshoot issues by referring to the detailed error descriptions in the errorCode parameter.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:rtmpStreamingEventWithUrl:eventCode:

Reports events during the RTMP or RTMPS streaming.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine rtmpStreamingEventWithUrl:(NSString *_Nonnull)url eventCode:(AgoraRtmpStreamingEvent)eventCode

Parameters

engine

AgoraRtcEngineKit object.

url

The RTMP or RTMPS streaming URL.

eventCode

The event code. See AgoraRtmpStreamingEvent.

Availability

v3.1.0

Declared In

AgoraRtcEngineKit.h

– rtcEngineTranscodingUpdated:

Occurs when the CDN live streaming settings are updated.

- (void)rtcEngineTranscodingUpdated:(AgoraRtcEngineKit *_Nonnull)engine

Parameters

engine

AgoraRtcEngineKit object.

Discussion

When the LiveTranscoding class in the setLiveTranscoding method updates, the SDK triggers the rtcEngineTranscodingUpdated callback to report the update information to the local host.

Note:

If you call the setLiveTranscoding method to set the LiveTranscoding class for the first time, the SDK does not trigger the rtcEngineTranscodingUpdated callback.

Declared In

AgoraRtcEngineKit.h

Stream Message Delegate Methods

– rtcEngine:receiveStreamMessageFromUid:streamId:data:

Occurs when the local user receives the data stream from a remote user within five seconds.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine receiveStreamMessageFromUid:(NSUInteger)uid streamId:(NSInteger)streamId data:(NSData *_Nonnull)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.

Discussion

The SDK triggers this callback when the local user receives the stream message that the remote user sends by calling the sendStreamMessage method.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didOccurStreamMessageErrorFromUid:streamId:error:missed:cached:

Occurs when the local user does not receive the data stream from the remote user within five seconds.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didOccurStreamMessageErrorFromUid:(NSUInteger)uid streamId:(NSInteger)streamId error:(NSInteger)error missed:(NSInteger)missed cached:(NSInteger)cached

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.

Discussion

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.

Declared In

AgoraRtcEngineKit.h

Miscellaneous Delegate Methods

– rtcEngine:didRequestAudioFileInfo:error:

Reports the information of an audio file.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didRequestAudioFileInfo:(AgoraRtcAudioFileInfo *_Nonnull)info error:(AgoraAudioFileInfoError)error

Parameters

engine

AgoraRtcEngineKit object.

info

The information of an audio file. See AgoraRtcAudioFileInfo.

error

The information acquisition state. See AgoraAudioFileInfoError.

Availability

v3.5.1

After successfully calling getAudioFileInfo, the SDK triggers this callback to report the information of the audio file, such as the file path and duration.

Declared In

AgoraRtcEngineKit.h

– rtcEngineMediaEngineDidLoaded:

Occurs when the media engine loads.

- (void)rtcEngineMediaEngineDidLoaded:(AgoraRtcEngineKit *_Nonnull)engine

Parameters

engine

AgoraRtcEngineKit object.

Declared In

AgoraRtcEngineKit.h

– rtcEngineMediaEngineDidStartCall:

Occurs when the media engine call starts.

- (void)rtcEngineMediaEngineDidStartCall:(AgoraRtcEngineKit *_Nonnull)engine

Parameters

engine

AgoraRtcEngineKit object.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:channelMediaRelayStateDidChange:error:

Occurs when the state of the media stream relay changes.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine channelMediaRelayStateDidChange:(AgoraChannelMediaRelayState)state error:(AgoraChannelMediaRelayError)error

Parameters

engine

AgoraRtcEngineKit object.

state

The state code in AgoraChannelMediaRelayState.

error

The error code in AgoraChannelMediaRelayError.

Discussion

The SDK reports the state of the current media relay and possible error messages in this callback.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didReceiveChannelMediaRelayEvent:

Reports events during the media stream relay.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didReceiveChannelMediaRelayEvent:(AgoraChannelMediaRelayEvent)event

Parameters

engine

AgoraRtcEngineKit object.

event

The event code in AgoraChannelMediaRelayEvent.

Declared In

AgoraRtcEngineKit.h

Deprecated Delegates

– rtcEngine:firstLocalAudioFrame:

Occurs when the engine sends the first local audio frame.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine firstLocalAudioFrame:(NSInteger)elapsed

Parameters

engine

AgoraRtcEngineKit object.

elapsed

Time elapsed (ms) from the local user calling the joinChannelByToken method until the SDK triggers this callback.

Discussion

Deprecated from v3.1.0. Use firstLocalAudioFramePublished instead.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:firstRemoteAudioFrameOfUid:elapsed:

Occurs when the engine receives the first audio frame from a specified remote user.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine firstRemoteAudioFrameOfUid:(NSUInteger)uid elapsed:(NSInteger)elapsed

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.

Discussion

Deprecated from v3.0.0. Use AgoraAudioRemoteStateStarting(1) in the remoteAudioStateChangedOfUid callback.

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:

Declared In

AgoraRtcEngineKit.h

– rtcEngine:firstRemoteAudioFrameDecodedOfUid:elapsed:

Occurs when the SDK decodes the first remote audio frame for playback.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine firstRemoteAudioFrameDecodedOfUid:(NSUInteger)uid elapsed:(NSInteger)elapsed

Parameters

engine

AgoraRtcEngineKit object.

uid

User ID of the remote user sending the audio stream.

elapsed

The time elapsed (ms) from the local user calling the joinChannelByToken method until the SDK triggers this callback.

Discussion

Deprecated from v3.0.0. Use AgoraAudioRemoteStateDecoding(2) in the remoteAudioStateChangedOfUid callback instead.

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. Reasons for such an interruption include:

    • The remote user leaves channel.
    • The remote user drops offline.
    • The remote user calls the muteLocalAudioStream method to stop sending the local audio stream.
    • The remote user calls the disableAudio method to disable audio.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:streamPublishedWithUrl:errorCode:

Reports the result of calling the addPublishStreamUrl method.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine streamPublishedWithUrl:(NSString *_Nonnull)url errorCode:(AgoraErrorCode)errorCode

Parameters

engine

AgoraRtcEngineKit object.

url

The CDN streaming URL.

errorCode

Error code: AgoraErrorCode. Main errors include:

  • AgoraErrorCodeNoError(0): The publishing succeeds.
  • AgoraErrorCodeFailed(1): The publishing fails.
  • AgoraErrorCodeInvalidArgument(2): Invalid argument used. If, for example, you do not call the setLiveTranscoding method to configure AgoraLiveTranscoding before calling the addPublishStreamUrl method, the SDK reports this error.
  • AgoraErrorCodeTimedOut(10): The publishing times out.
  • AgoraErrorCodeAlreadyInUse(19): The CDN streaming URL is already in use for CDN live streaming.
  • AgoraErrorCodeEncryptedStreamNotAllowedPublish(130): You cannot publish an encrypted stream.
  • AgoraErrorCodePublishStreamCDNError(151): CDN related errors. Remove the original URL address and add a new one by calling the removePublishStreamUrl and addPublishStreamUrl methods.
  • AgoraErrorCodePublishStreamNumReachLimit(152): The host publishes more than 10 URLs. Delete the unnecessary URLs before adding new ones.
  • AgoraErrorCodePublishStreamNotAuthorized(153): The host manipulates other hosts' URLs. Check your app logic.
  • AgoraErrorCodePublishStreamInternalServerError(154): An error occurs in Agora’s streaming server. Call the addPublishStreamUrl method to publish the streaming again.
  • AgoraErrorCodePublishStreamFormatNotSuppported(156): The format of the RTMP or RTMPS stream URL is not supported. Check whether the URL format is correct.

Discussion

Deprecated from v3.0.0. Use the rtmpStreamingChangedToState callback instead.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:streamUnpublishedWithUrl:

Reports the result of calling the removePublishStreamUrl method.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine streamUnpublishedWithUrl:(NSString *_Nonnull)url

Parameters

engine

AgoraRtcEngineKit object.

url

The CDN streaming URL.

Discussion

Deprecated from v3.0.0. Use the rtmpStreamingChangedToState callback instead.

This callback indicates whether you have successfully removed an RTMP or RTMPS stream from the CDN.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:audioTransportStatsOfUid:delay:lost:rxKBitRate:

Reports the transport-layer statistics of each remote audio stream.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine audioTransportStatsOfUid:(NSUInteger)uid delay:(NSUInteger)delay lost:(NSUInteger)lost rxKBitRate:(NSUInteger)rxKBitRate

Parameters

engine

AgoraRtcEngineKit object.

uid

User ID of the remote user sending the audio packet.

delay

Network time delay (ms) from the remote user sending the audio packet to the local user.

lost

Packet loss rate (%) of the audio packet sent from the remote user.

rxKBitRate

Received bitrate (Kbps) of the audio packet sent from the remote user.

Discussion

Deprecated from v2.9.0. Use the remoteAudioStats callback instead.

This callback reports the transport-layer statistics, such as the packet loss rate and network time delay, once every two seconds after the local user receives an audio packet from a remote user.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:videoTransportStatsOfUid:delay:lost:rxKBitRate:

Reports the transport-layer statistics of each remote video stream.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine videoTransportStatsOfUid:(NSUInteger)uid delay:(NSUInteger)delay lost:(NSUInteger)lost rxKBitRate:(NSUInteger)rxKBitRate

Parameters

engine

AgoraRtcEngineKit object.

uid

User ID of the remote user sending the video packet.

delay

Network time delay (ms) from the remote user sending the video packet to the local user.

lost

Packet loss rate (%) of the video packet sent from the remote user.

rxKBitRate

Received bitrate (Kbps) of the video packet sent from the remote user.

Discussion

Deprecated from v2.9.0. Use the remoteVideoStats callback instead.

This callback reports the transport layer statistics, such as the packet loss rate and network time delay, once every two seconds after the local user receives a video packet from a remote user.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:didMicrophoneEnabled:

Occurs when the microphone is enabled/disabled.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didMicrophoneEnabled:(BOOL)enabled

Parameters

engine

AgoraRtcEngineKit object.

enabled

Whether the microphone is enabled/disabled:

  • YES: Enabled.
  • NO: Disabled.

Discussion

Deprecated from v2.9.0. Use AgoraAudioLocalStateStopped(0) or AgoraAudioLocalStateRecording(1) in the localAudioStateChange callback instead.

The SDK triggers this callback when the local user resumes or stops capturing the local audio stream by calling the enableLocalAudio method.

Declared In

AgoraRtcEngineKit.h

– rtcEngineConnectionDidInterrupted:

Occurs when the connection between the SDK and the server is interrupted.

- (void)rtcEngineConnectionDidInterrupted:(AgoraRtcEngineKit *_Nonnull)engine

Parameters

engine

AgoraRtcEngineKit object.

Discussion

Deprecated from v2.3.2. Use AgoraConnectionStateReconnecting(4) and AgoraConnectionChangedInterrupted(2) of the connectionChangedToState callback instead.

The SDK triggers this callback when it loses connection with the server for more than four seconds after a connection is established.

After triggering this callback, the SDK tries reconnecting to the server. You can use this callback to implement pop-up reminders.

This callback is different from rtcEngineConnectionDidLost:

  • The SDK triggers the rtcEngineConnectionDidInterrupted callback when it loses connection with the server for more than four seconds after it 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.

Declared In

AgoraRtcEngineKit.h

– rtcEngineConnectionDidBanned:

Occurs when your connection is banned by the Agora server.

- (void)rtcEngineConnectionDidBanned:(AgoraRtcEngineKit *_Nonnull)engine

Parameters

engine

AgoraRtcEngineKit object

Discussion

Deprecated from v2.3.2. Use AgoraConnectionStateFailed(5) and AgoraConnectionChangedBannedByServer(3) of connectionChangedToState callback instead.

Declared In

AgoraRtcEngineKit.h

– rtcEngine:audioQualityOfUid:quality:delay:lost:

Reports the audio quality of the remote user.

- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine audioQualityOfUid:(NSUInteger)uid quality:(AgoraNetworkQuality)quality delay:(NSUInteger)delay lost:(NSUInteger)lost

Parameters

engine

AgoraRtcEngineKit object.

uid

User ID of the speaker.

quality

Audio quality of the user, see AgoraNetworkQuality.

delay

Time delay (ms) of the audio packet sent from the sender to the receiver, including the time delay from audio sampling pre-processing, transmission, and the jitter buffer.

lost

Packet loss rate (%) of the audio packet sent from the sender to the receiver.

Discussion

Same as audioQualityBlock.

Deprecated from v2.3.2. Use remoteAudioStats instead.

The SDK triggers this callback once every two seconds. This callback reports the audio quality of each remote user/host sending an audio stream. If a channel has multiple users/hosts sending audio streams, then the SDK triggers this callback as many times.

See Also

Declared In

AgoraRtcEngineKit.h

– rtcEngineCameraDidReady:

Occurs when the camera turns on and is ready to capture video.

- (void)rtcEngineCameraDidReady:(AgoraRtcEngineKit *_Nonnull)engine

Parameters

engine

AgoraRtcEngineKit object.

Discussion

Deprecated from v2.4.1. Use AgoraLocalVideoStreamStateCapturing(1) in the state parameter of localVideoStateChange instead.

Same as cameraReadyBlock.

Declared In

AgoraRtcEngineKit.h

– rtcEngineVideoDidStop:

Occurs when the video stops playing.

- (void)rtcEngineVideoDidStop:(AgoraRtcEngineKit *_Nonnull)engine

Parameters

engine

AgoraRtcEngineKit object.

Discussion

Deprecated from v2.4.1. Use AgoraLocalVideoStreamStateStopped(0) in the state parameter of localVideoStateChange instead

The app can use this callback to change the configuration of the view (for example, to display other screens in the view) after the video stops.

Declared In

AgoraRtcEngineKit.h