IAgoraRtcEngineEventHandler

The SDK uses the IAgoraRtcEngineEventHandler interface to send event notifications to your app. Your app can get those notifications through methods that inherit this interface.

All methods in this interface have default (empty) implementation. You can choose to inherit events related to your app scenario. In the callbacks, avoid implementing time-consuming tasks or calling APIs that may cause thread blocking (such as sendMessage). Otherwise, the SDK may not work properly.

OnActiveSpeaker

Occurs when the most active speaker is detected.

public virtual void OnActiveSpeaker(uint uid)

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 exceeds two (included) and an active speaker is detected, the SDK triggers this callback and reports the uid of the most active speaker.
  • If the most active speaker remains the same, the SDK triggers the OnActiveSpeaker 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.

Parameters

uid
The user ID of the most active speaker.

OnApiCallExecuted

Occurs when a method is executed by the SDK.

public virtual void OnApiCallExecuted(int err, string api, string result)

Parameters

err
The error code returned by the SDK when the method call fails. For detailed error information and troubleshooting methods, see Error Code and Warning Code.If the SDK returns 0, then the method call is successful.
api
The method executed by the SDK.
result
The result of the method call.

OnAudioDeviceStateChanged

Occurs when the audio device state changes.

public virtual void OnAudioDeviceStateChanged(string deviceId, int deviceType, int deviceState)

This callback notifies the application that the system's audio device state is changed. For example, a headset is unplugged from the device.

Attention: This method is for Windows and macOS only.

Parameters

deviceId
The device ID.
deviceType
The device type. For details, see MEDIA_DEVICE_TYPE.
deviceState
The device state.

OnAudioDeviceTestVolumeIndication

Reports the result of an audio device test.

public virtual void OnAudioDeviceTestVolumeIndication(AudioDeviceTestVolumeType volumeType, int volume)

After successfully calling StartRecordingDeviceTest, StartPlaybackDeviceTest, or StartAudioDeviceLoopbackTest to start an audio device test, the SDK triggers the OnAudioDeviceTestVolumeIndication callback at the set time interval to report the volume information of the audio device tested.

Parameters

volumeType

The volume type. See AudioDeviceTestVolumeType.

volume

Volume level in the range [0,255].

OnAudioDeviceVolumeChanged

Occurs when the volume on the playback or audio capture device, or the volume in the application changes.

public virtual void OnAudioDeviceVolumeChanged(MEDIA_DEVICE_TYPE deviceType, int volume, bool muted)

Parameters

deviceType
The device type. For details, see MEDIA_DEVICE_TYPE.
volume
The volume value. The range is [0, 255].
muted
Whether the audio device is muted:
  • true: The audio device is muted.
  • false: The audio device is not muted.

OnAudioEffectFinished

Occurs when the playback of the local audio effect file finishes.

public virtual void OnAudioEffectFinished(int soundId)

This callback occurs when the local audio effect file finishes playing.

Parameters

soundId
The audio effect ID. The ID of each audio effect file is unique.

OnAudioMixingFinished

Occurs when the playback of the local music file finishes.

public virtual void OnAudioMixingFinished()
Deprecated:
This method is deprecated as of v2.4.0. Use OnAudioMixingStateChanged instead.

After you call StartAudioMixing [2/2] to play a local music file, this callback occurs when the playback finishes. If the call of StartAudioMixing [2/2] fails, the callback returns the error code WARN_AUDIO_MIXING_OPEN_ERROR.

OnAudioMixingStateChanged

Occurs when the playback state of the music file changes.

public virtual void OnAudioMixingStateChanged(AUDIO_MIXING_STATE_TYPE state, AUDIO_MIXING_REASON_TYPE reason)

This callback occurs when the playback state of the music file changes, and reports the current state and error code.

Parameters

state
The playback state of the music file. For details, see AUDIO_MIXING_STATE_TYPE.
reason
The reason why the playback state of the music file changes. For details, see AUDIO_MIXING_REASON_TYPE.

OnAudioPublishStateChanged

Occurs when the audio publishing state changes.

public virtual void OnAudioPublishStateChanged(string channel, STREAM_PUBLISH_STATE oldState,
            STREAM_PUBLISH_STATE newState, int elapseSinceLastState)

Parameters

channel
The name of the channel.
oldState
For the previous publishing state, see STREAM_PUBLISH_STATE.
newState
For the current publishing state, see STREAM_PUBLISH_STATE.
elapseSinceLastState
The time elapsed (ms) from the previous state to the current state.

OnAudioQuality

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

public virtual void OnAudioQuality(uint uid, int quality, ushort delay, ushort lost)
Deprecated:
Please use OnRemoteAudioStats instead.

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

Parameters

uid
The user ID of the remote user sending the audio stream.
quality
Audio quality of the user. For details, see QUALITY_TYPE.
delay
The network delay (ms) from the sender to the receiver, including the delay caused by audio sampling pre-processing, network transmission, and network jitter buffering.
lost
Packet loss rate (%) of the audio packet sent from the sender to the receiver.

OnAudioSubscribeStateChanged

Occurs when the audio subscribing state changes.

public virtual void OnAudioSubscribeStateChanged(string channel, uint uid, STREAM_SUBSCRIBE_STATE oldState,
            STREAM_SUBSCRIBE_STATE newState, int elapseSinceLastState)

Parameters

channel
The name of the channel.
uid
The ID of the remote user.
oldState
The previous subscribing status, see STREAM_SUBSCRIBE_STATE for details.
newState
The current subscribing status, see STREAM_SUBSCRIBE_STATE for details.
elapseSinceLastState
The time elapsed (ms) from the previous state to the current state.

OnAudioVolumeIndication

Reports the volume information of users.

public virtual void OnAudioVolumeIndication(AudioVolumeInfo[] speakers, uint speakerNumber, int totalVolume)

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 EnableAudioVolumeIndication callback at the time interval set in OnAudioVolumeIndication. The SDK triggers two independent OnAudioVolumeIndication 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.

Attention: After you enable this callback, calling MuteLocalAudioStream affects the SDK's behavior as follows:
  • If the local user stops publishing the audio stream, the SDK stops triggering the local user's callback.
  • 20 seconds after a remote user whose volume is one of the three highest stops publishing the audio stream, the callback excludes this user's information; 20 seconds after all remote users stop publishing audio streams, the SDK stops triggering the callback for remote users.

Parameters

speakers
The volume information of the users, see AudioVolumeInfo. An empty speakers array in the callback indicates that no remote user is in the channel or sending a stream at the moment.
speakerNumber
The total number of users.
  • In the callback for the local user, if the local user is sending streams, the value of speakerNumber is 1.
  • In the callback for remote users, the value range of speakerNumber is [0,3]. If the number of remote users who send streams is greater than or equal to three, the value of speakerNumber is 3.
totalVolume
The volume of the speaker. The value range is [0,255].
  • In the callback for the local user, totalVolume is the volume of the local user who sends a stream.
  • In the callback for remote users, 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 [2/2], then totalVolume is the volume after audio mixing.

OnCameraReady

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

public virtual void OnCameraReady()
Deprecated:

Please use LOCAL_VIDEO_STREAM_STATE_CAPTURING(1) in OnLocalVideoStateChanged instead.

This callback indicates that the camera has been successfully turned on and you can start to capture video.

OnChannelMediaRelayStateChanged

Occurs when the state of the media stream relay changes.

public virtual void OnChannelMediaRelayStateChanged(CHANNEL_MEDIA_RELAY_STATE state,
            CHANNEL_MEDIA_RELAY_ERROR code)

The SDK returns the state of the current media relay with any error message.

Parameters

state

The state code. For details, see CHANNEL_MEDIA_RELAY_STATE.

code

The error code of the channel media replay. For details, see CHANNEL_MEDIA_RELAY_ERROR.

OnClientRoleChanged

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

public virtual void OnClientRoleChanged(CLIENT_ROLE_TYPE oldRole, CLIENT_ROLE_TYPE newRole)

The SDK triggers this callback when the local user switches the user role after joining the channel.

Parameters

oldRole
Role that the user switches from: CLIENT_ROLE_TYPE.
newRole
Role that the user switches to: CLIENT_ROLE_TYPE.

OnConnectionInterrupted

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

public virtual void OnConnectionInterrupted()
Deprecated:
Please use OnConnectionStateChanged instead.
The SDK triggers this callback when it loses connection with the server for more than four seconds after the connection is established. After triggering this callback, the SDK tries to reconnect to the server. You can use this callback to implement pop-up reminders. The difference between this callback and OnConnectionLost is:
  • The SDK triggers the OnConnectionInterrupted callback when it loses connection with the server for more than four seconds after it successfully joins the channel.
  • The SDK triggers the OnConnectionLost callback when it loses connection with the server for more than 10 seconds, whether or not it joins the channel.
If the SDK fails to rejoin the channel 20 minutes after being disconnected from Agora's edge server, the SDK stops rejoining the channel.

OnConnectionLost

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

public virtual void OnConnectionLost()

The SDK triggers this callback when it cannot connect to the server 10 seconds after calling the JoinChannel [2/2] method, regardless of whether it is in the channel. If the SDK fails to rejoin the channel 20 minutes after being disconnected from Agora's edge server, the SDK stops rejoining the channel.

OnConnectionStateChanged

Occurs when the network connection state changes.

public virtual void OnConnectionStateChanged(CONNECTION_STATE_TYPE state, CONNECTION_CHANGED_REASON_TYPE reason)

When the network connection state changes, the SDK triggers this callback and reports the current connection state and the reason for the change.

Parameters

state

The current connection state. For details, see CONNECTION_STATE_TYPE.

reason

The reason for a connection state change. For details, see CONNECTION_CHANGED_REASON_TYPE.

OnError

Reports an error during SDK runtime.

public virtual void OnError(int err, string msg)

This callback indicates that an error (concerning network or media) occurs during SDK runtime. In most cases, the SDK cannot fix the issue and resume running. The SDK requires the application to take action or informs the user about the issue. For example, the SDK reports an ERR_START_CALL error when failing to initialize a call. The app informs the user that the call initialization failed and calls LeaveChannel to leave the channel.

Parameters

err
The error code. For details, see Error Codes and Warning Codes.
msg
The error message.

OnFirstLocalAudioFrame

Occurs when the engine sends the first local audio frame.

public virtual void OnFirstLocalAudioFrame(int elapsed)
Deprecated:
Please use OnFirstLocalAudioFramePublished instead.

Parameters

elapsed
The time elapsed (ms) from the local user calling JoinChannel [2/2] until the SDK triggers this callback.

OnFirstLocalAudioFramePublished

Occurs when the first audio frame is published.

public virtual void OnFirstLocalAudioFramePublished(int elapsed)
The SDK triggers this callback under one of the following circumstances:
  • The local client enables the audio module and calls JoinChannel [2/2] successfully.
  • The local client calls MuteLocalAudioStream(true) and MuteLocalAudioStream(false) in sequence.
  • The local client calls DisableAudio and EnableAudio in sequence.

Parameters

elapsed
The time elapsed (ms) from the local client calling JoinChannel [2/2] until the SDK triggers this callback.

OnFirstLocalVideoFrame

Occurs when the first local video frame is rendered.

public virtual void OnFirstLocalVideoFrame(int width, int height, int elapsed)

The SDK triggers this callback when the first local video frame is displayed/rendered on the local video view.

Parameters

width
The width (px) of the first local video frame.
height
The height (px) of the first local video frame.
elapsed
The time elapsed (ms) from the local user calling JoinChannel [2/2]until the SDK triggers this callback. If you call StartPreview before calling JoinChannel [2/2], then this parameter is the time elapsed from calling the StartPreview method until the SDK triggers this callback.

OnFirstLocalVideoFramePublished

Occurs when the first video frame is published.

public virtual void OnFirstLocalVideoFramePublished(int elapsed)
The SDK triggers this callback under one of the following circumstances:
  • The local client enables the video module and calls JoinChannel [2/2] successfully.
  • The local client calls MuteLocalVideoStream(true) and MuteLocalVideoStream(false) in sequence.
  • The local client calls DisableVideo and EnableVideo in sequence.

Parameters

elapsed
The time elapsed(ms) from the local client calling JoinChannel [2/2] until the SDK triggers this callback.

OnFirstRemoteAudioDecoded

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

public virtual void OnFirstRemoteAudioDecoded(uint uid, int elapsed)
Deprecated:
Please use OnRemoteAudioStateChanged instead.
The SDK triggers this callback under one of the following circumstances:
  • The remote user joins the channel and sends the audio stream for the first time.
  • The remote user's audio is offline and then goes online to re-send audio. It means the local user cannot receive audio in 15 seconds. Reasons for such an interruption include:
    • The remote user leaves channel.
    • The remote user drops offline.
    • The remote user calls MuteLocalAudioStream to stop sending the audio stream.
    • The remote user calls DisableAudio to disable audio.

Parameters

uid
The ID of the remote user.
elapsed
The time elapsed (ms) from the local user calling JoinChannel [2/2] until the SDK triggers this callback.

OnFirstRemoteAudioFrame

Occurs when the SDK receives the first audio frame from a specific remote user.

public virtual void OnFirstRemoteAudioFrame(uint uid, int elapsed)
Deprecated:
Please use OnRemoteAudioStateChanged instead.

Parameters

uid
The user ID of the remote user.
elapsed
The time elapsed (ms) from the local user calling JoinChannel [2/2] until the SDK triggers this callback.

OnFirstRemoteVideoDecoded

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

public virtual void OnFirstRemoteVideoDecoded(uint uid, int width, int height, int elapsed)
Deprecated:
Please use the OnRemoteVideoStateChanged callback with the following parameters:
  • REMOTE_VIDEO_STATE_STARTING (1).
  • REMOTE_VIDEO_STATE_DECODING (2).
The SDK triggers this callback under one of the following circumstances:
  • 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. Reasons for such an interruption include:
    • The remote user leaves the channel.
    • The remote user drops offline.
    • The remote user calls MuteLocalVideoStream to stop sending the video stream.
    • The remote user calls DisableVideo to disable video.

Parameters

uid
The user ID of the remote user sending the video stream.
width
The width (px) of the video stream.
height
The height (px) of the video stream.
elapsed
The time elapsed (ms) from the local user calling JoinChannel [2/2] until the SDK triggers this callback.

OnFirstRemoteVideoFrame

Occurs when the first remote video frame is rendered.

public virtual void OnFirstRemoteVideoFrame(uint uid, int width, int height, int elapsed)

The SDK triggers this callback when the first local video frame is displayed/rendered on the local video view. The application can retrieve the time elapsed (the elapsed parameter) from a user joining the channel until the first video frame is displayed.

Parameters

uid
The user ID of the remote user sending the video stream.
width
The width (px) of the video stream.
height
The height (px) of the video stream.
elapsed
Time elapsed (ms) from the local user calling JoinChannel [2/2] until the SDK triggers this callback.

OnJoinChannelSuccess

Occurs when a user joins a channel.

public virtual void OnJoinChannelSuccess(string channel, uint uid, int elapsed)

This callback notifies the application that a user joins a specified channel.

Parameters

channel
The name of the channel.
uid
The ID of the user who joins the channel.
elapsed
The time elapsed (ms) from the local user calling JoinChannel [2/2] until the SDK triggers this callback.

OnLastmileQuality

Reports the last-mile network quality of the local user once every two seconds.

public virtual void OnLastmileQuality(int quality)

This callback reports the last-mile network conditions of the local user before the user joins the channel. Last mile refers to the connection between the local device and Agora's edge server.

Before the user joins the channel, this callback is triggered by the SDK once StartLastmileProbeTest is called and reports the last-mile network conditions of the local user.

Parameters

quality
The last mile network quality.

OnLeaveChannel

Occurs when a user leaves a channel.

public virtual void OnLeaveChannel(RtcStats stats)

This callback notifies the app that the user leaves the channel by calling LeaveChannel. From this callback, the app can get information such as the call duration and quality statistics.

Parameters

stats
The statistics of the call, see RtcStats .

OnLocalAudioStateChanged

Occurs when the local audio stream state changes.

public virtual void OnLocalAudioStateChanged(LOCAL_AUDIO_STREAM_STATE state, LOCAL_AUDIO_STREAM_ERROR error)

When the state of the local audio stream changes (including the state of the audio capture and encoding), the SDK triggers this callback to report the current state. This callback indicates the state of the local audio stream, and allows you to troubleshoot issues when audio exceptions occur.

Attention: When the state isLOCAL_AUDIO_STREAM_STATE_FAILED (3), you can view the error information in the error parameter.

Parameters

state
The state of the local audio. For details, see LOCAL_AUDIO_STREAM_STATE.
error
Local audio state error codes. For details, see LOCAL_AUDIO_STREAM_ERROR.

OnLocalAudioStats

Reports the statistics of the local audio stream.

public virtual void OnLocalAudioStats(LocalAudioStats stats)

The SDK triggers this callback once every two seconds.

Parameters

stats
Local audio statistics. For details, see LocalAudioStats.

OnLocalPublishFallbackToAudioOnly

Occurs when the published media stream falls back to an audio-only stream.

public virtual void OnLocalPublishFallbackToAudioOnly(bool isFallbackOrRecover)

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

Attention: If the local stream falls back to the audio-only stream, the remote user receives the OnUserMuteVideo callback.

Parameters

isFallbackOrRecover
  • true: The published stream falls back to audio-only due to poor network conditions.
  • false: The published stream switches back to the video after the network conditions improve.

OnLocalUserRegistered

Occurs when the local user registers a user account.

public virtual void OnLocalUserRegistered(uint uid, string userAccount)

After the local user successfully calls RegisterLocalUserAccount to register the user account or calls JoinChannelWithUserAccount [2/2] to join a channel, the SDK triggers the callback and informs the local user's UID and User Account.

Parameters

uid
The ID of the local user.
userAccount
The user account of the local user.

OnLocalVideoStateChanged

Occurs when the local video stream state changes.

public virtual void OnLocalVideoStateChanged(LOCAL_VIDEO_STREAM_STATE localVideoState,
            LOCAL_VIDEO_STREAM_ERROR error)

When the state of the local video stream changes (including the state of the video capture and encoding), the SDK triggers this callback to report the current state. This callback indicates the state of the local video stream, including camera capturing and video encoding, and allows you to troubleshoot issues when exceptions occur.

The SDK triggers the OnLocalVideoStateChanged callback with the state code of LOCAL_VIDEO_STREAM_STATE_FAILED and error code of LOCAL_VIDEO_STREAM_ERROR_CAPTURE_FAILURE in the following situations:
  • The app switches to the background, and the system gets the camera resource.
  • The camera starts normally, but does not output video for four consecutive seconds.

When the camera outputs the captured video frames, if the video frames are the same for 15 consecutive frames, the SDK triggers the OnLocalVideoStateChanged callback with the state code of LOCAL_VIDEO_STREAM_STATE_CAPTURING and error code of LOCAL_VIDEO_STREAM_ERROR_CAPTURE_FAILURE. 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.

Attention: For some device models, the SDK does not trigger this callback when the state of the local video changes while the local video capturing device is in use, so you have to make your own timeout judgment.

Parameters

localVideoState

The state of the local video, see LOCAL_VIDEO_STREAM_STATE.

error

The detailed error information, see LOCAL_VIDEO_STREAM_ERROR.

OnLocalVideoStats

Reports the statistics of the local video stream.

public virtual void OnLocalVideoStats(LocalVideoStats stats)

The SDK triggers this callback once every two seconds to report the statistics of the local video stream.

Parameters

stats
The statistics of the local video stream. For details, see LocalVideoStats.

OnMetadataReceived

Occurs when the local user receives the metadata.

public virtual void OnMetadataReceived(Metadata metadata)

Parameters

metadata
The metadata received.

OnMicrophoneEnabled

Occurs when the microphone is enabled/disabled.

public virtual void OnMicrophoneEnabled(bool enabled)
Deprecated:
Please use the OnLocalAudioStateChanged callback:
  • LOCAL_AUDIO_STREAM_STATE_STOPPED(0).
  • LOCAL_AUDIO_STREAM_STATE_RECORDING(1).

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

Parameters

enabled
Whether the microphone is enabled/disabled:
  • true: The microphone is enabled.
  • false: The microphone is disabled.

OnNetworkQuality

Reports the last mile network quality of each user in the channel.

public virtual void OnNetworkQuality(uint uid, int txQuality, int rxQuality)

This callback reports the last mile network conditions of each user in the channel. Last mile refers to the connection between the local device and Agora's edge server.

The SDK triggers this callback once every two seconds. If a channel includes multiple users, the SDK triggers this callback as many times.

Parameters

uid

User ID. The network quality of the user with this user ID is reported.

If the uid is 0, the local network quality is reported.

txQuality
Uplink network quality rating of the user in terms of the transmission bit rate, packet loss rate, average RTT (Round-Trip Time) and jitter of the uplink network. This parameter is a quality rating helping you understand how well the current uplink network conditions can support the selected video encoder configuration. 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 LIVE_BROADCASTING profile, but might be inadequate for resolutions higher than 1280 × 720. For details, see QUALITY_TYPE.
rxQuality
Downlink network quality rating of the user in terms of packet loss rate, average RTT, and jitter of the downlink network. For details, see QUALITY_TYPE.

OnNetworkTypeChanged

Occurs when the local network type changes.

public virtual void OnNetworkTypeChanged(NETWORK_TYPE type)

This callback occurs when the connection state of the local user changes. You can get the connection state and reason for the state change in this callback. When the network connection is interrupted, this callback indicates whether the interruption is caused by a network type change or poor network conditions.

Parameters

type

The type of the local network connection. For details, see NETWORK_TYPE.

OnReadyToSendMetadata

Occurs when the SDK is ready to send metadata.

public virtual bool OnReadyToSendMetadata(Metadata metadata)
        {
            return true;
        }

This callback is triggered when the SDK is ready to send metadata.

After receiving this callback, you can call SendMetadata to send the media metadata.

Parameters

metadata
The metadata that the user wants to send. For details, see Metadata.

Returns

  • true: Send the metadata.
  • false: Do not send the metadata.

OnRejoinChannelSuccess

Occurs when a user rejoins the channel.

public virtual void OnRejoinChannelSuccess(string channel, uint uid, int elapsed)

When a user loses connection with the server because of network problems, the SDK automatically tries to reconnect and triggers this callback upon reconnection.

Parameters

channel
The name of the channel.
uid
The ID of the user who rejoins the channel.
elapsed
Time elapsed (ms) from starting to reconnect until the SDK triggers this callback.

OnRemoteAudioMixingEnd

Occurs when a remote user finishes audio mixing.

public virtual void OnRemoteAudioMixingEnd()

The SDK triggers this callback when a remote user finishes audio mixing.

OnRemoteAudioStateChanged

Occurs when the remote audio state changes.

public virtual void OnRemoteAudioStateChanged(uint uid, REMOTE_AUDIO_STATE state,
            REMOTE_AUDIO_STATE_REASON reason, int elapsed)

When the audio state of a remote user (in the voice/video call channel) or host (in the live streaming channel) changes, the SDK triggers this callback to report the current state of the remote audio stream.

Attention: This callback does not work properly when the number of users (in the voice/video call channel) or hosts (in the live streaming channel) in the channel exceeds 17.

Parameters

uid
The ID of the remote user whose audio state changes.
state
The state of the remote audio, see REMOTE_AUDIO_STATE.
reason
The reason of the remote audio state change, see REMOTE_AUDIO_STATE_REASON.
elapsed
Time elapsed (ms) from the local user calling the JoinChannel [2/2] method until the SDK triggers this callback.

OnRemoteAudioStats

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

public virtual void OnRemoteAudioStats(RemoteAudioStats stats)

The SDK triggers this callback once every two seconds for each remote user who is sending audio streams. If a channel includes multiple remote users, the SDK triggers this callback as many times.

Parameters

stats
The statistics of the received remote audio streams. See RemoteAudioStats.

OnRemoteAudioTransportStats

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

public virtual void OnRemoteAudioTransportStats(uint uid, ushort delay, ushort lost, ushort rxKBitRate)
Deprecated:
Please use OnRemoteAudioStats 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. During a call, when the user receives the audio packet sent by the remote user/host, the callback is triggered every 2 seconds.

Parameters

uid
The ID of the remote user sending the audio streams.
delay
The network delay (ms) from the sender to the receiver.
lost
Packet loss rate (%) of the audio packet sent from the sender to the receiver.
rxKBitrate
Bitrate of the received audio (Kbps).

OnRemoteSubscribeFallbackToAudioOnly

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

public virtual void OnRemoteSubscribeFallbackToAudioOnly(uint uid, bool isFallbackOrRecover)

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

Attention: Once the remote media stream switches to the low-quality stream due to poor network conditions, you can monitor the stream switch between a high-quality and low-quality stream in the OnRemoteVideoStats callback.

Parameters

uid
The user ID of the remote user.
isFallbackOrRecover
  • true: The remotely subscribed media stream falls back to audio-only due to poor network conditions.
  • false: The remotely subscribed media stream switches back to the video stream after the network conditions improved.

OnRemoteVideoStateChanged

Occurs when the remote video state changes.

public virtual void OnRemoteVideoStateChanged(uint uid, REMOTE_VIDEO_STATE state,
            REMOTE_VIDEO_STATE_REASON reason, int elapsed)
Attention: This callback does not work properly when the number of users (in the voice/video call channel) or hosts (in the live streaming channel) in the channel exceeds 17.

Parameters

uid
The ID of the remote user whose video state changes.
state

The state of the remote video, see REMOTE_VIDEO_STATE.

reason

The reason for the remote video state change, see REMOTE_VIDEO_STATE_REASON.

elapsed
Time elapsed (ms) from the local user calling the JoinChannel [2/2] method until the SDK triggers this callback.

OnRemoteVideoStats

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

public virtual void OnRemoteVideoStats(RemoteVideoStats stats)

Reports the statistics of the video stream from the remote users. The SDK triggers this callback once every two seconds for each remote user. If a channel has multiple users/hosts sending video streams, the SDK triggers this callback as many times.

Parameters

stats
Statistics of the remote video stream. For details, see RemoteVideoStats.

OnRemoteVideoTransportStats

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

public virtual void OnRemoteVideoTransportStats(uint uid, ushort delay, ushort lost, ushort rxKBitRate)
Deprecated:
Please use OnRemoteVideoStats 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.

During a call, when the user receives the video packet sent by the remote user/host, the callback is triggered every 2 seconds.

Parameters

uid
The ID of the remote user sending the video packets.
delay
The network delay (ms) from the sender to the receiver.
lost
The packet loss rate (%) of the video packet sent from the remote user.
rxKBitRate
The bitrate of the received video (Kbps).

OnRequestAudioFileInfo

Reports the information of an audio file.

public virtual void OnRequestAudioFileInfo(AudioFileInfo info, AUDIO_FILE_INFO_ERROR error)

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

Parameters

info
The information of an audio file. See AudioFileInfo.
error
The information acquisition state. See AUDIO_FILE_INFO_ERROR.

OnRequestToken

Occurs when the token expires.

public virtual void OnRequestToken()

When the token expires during a call, the SDK triggers this callback to remind the app to renew the token.

Once you receive this callback, generate a new token on your app server, and call JoinChannel [2/2] to rejoin the channel.

OnRtcStats

Reports the statistics of the current call.

public virtual void OnRtcStats(RtcStats stats)

The SDK triggers this callback once every two seconds after the user joins the channel.

Parameters

stats

Statistics of the RTC engine, see RtcStats for details.

OnRtmpStreamingEvent

Reports events during the media push.

public virtual void OnRtmpStreamingEvent(string url, RTMP_STREAMING_EVENT eventCode)

Parameters

url
The URL for media push.
eventCode
The event code of media push. See RTMP_STREAMING_EVENT for details.

OnRtmpStreamingStateChanged

Occurs when the media push state changes.

public virtual void OnRtmpStreamingStateChanged(string url, RTMP_STREAM_PUBLISH_STATE state,
            RTMP_STREAM_PUBLISH_ERROR errCode)

When the media push state changes, the SDK triggers this callback to report the current state and the reason why the state has changed. When exceptions occur, you can troubleshoot issues by referring to the detailed error descriptions in the error code parameter.

Parameters

url

The URL address where the state of the media push changes.

state
The current state of the media push. See RTMP_STREAM_PUBLISH_STATE. When the streaming state is RTMP_STREAM_PUBLISH_STATE_FAILURE (4), you can view the error information in the errorCode parameter.
errCode
The detailed error information for the media push. See RTMP_STREAM_PUBLISH_ERROR_TYPE.

OnProxyConnected

Reports the proxy connection state.

public virtual void OnProxyConnected(string channel, uint uid, PROXY_TYPE proxyType, string localProxyIp, int elapsed)

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 JoinChannel [1/2] until this callback is triggered.

Parameters

channel
The channel name.
uid
The user ID.
proxyType
The proxy type connected. See CLOUD_PROXY_TYPE .
localProxyIp
Reserved for future use.
elapsed
The time elapsed (ms) from the user calling JoinChannel [1/2] until this callback is triggered.

OnSnapshotTaken

Reports the result of taking a video snapshot.

public virtual void OnSnapshotTaken(string channel, uint uid, string filePath, int width, int height, int errCode)
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.

Parameters

channel
The channel name.
uid
The user ID. 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.

OnStreamMessage

Occurs when the local user receives the data stream from the remote user.

public virtual void OnStreamMessage(uint uid, int streamId, byte[] data, uint length)

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

Parameters

uid
The ID of the remote user sending the message.
streamId
The stream ID of the received message.
data
The data received.
length
The data length (byte).

OnStreamMessageError

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

public virtual void OnStreamMessageError(uint uid, int streamId, int code, int missed, int cached)

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.

Parameters

uid
The ID of the remote user sending the message.
streamId
The stream ID of the received message.
code
The error code.
missed
The number of lost messages.
cached
Number of incoming cached messages when the data stream is interrupted.

OnStreamPublished

Occurs when an RTMP or RTMPS stream is published.

public virtual void OnStreamPublished(string url, int error)
Deprecated:
Please use OnRtmpStreamingStateChanged instead.

Reports the result of publishing an RTMP or RTMPS stream.

Parameters

url
The CDN streaming URL.
error
Error codes of the RTMP or RTMPS streaming.
  • ERR_OK (0): The publishing succeeds.
  • ERR_FAILED (1): The publishing fails.
  • ERR_INVALID_ARGUMENT (-2): Invalid argument used. If you do not call SetLiveTranscoding to configure LiveTranscoding before calling AddPublishStreamUrl, the SDK reports ERR_INVALID_ARGUMENT.
  • ERR_TIMEDOUT (10): The publishing timed out.
  • ERR_ALREADY_IN_USE (19): The chosen URL address is already in use for CDN live streaming.
  • ERR_ENCRYPTED_STREAM_NOT_ALLOWED_PUBLISH (130): You cannot publish an encrypted stream.
  • ERR_PUBLISH_STREAM_CDN_ERROR (151): CDN related error. Remove the original URL address and add a new one by calling the RemovePublishStreamUrl and AddPublishStreamUrl methods.
  • ERR_PUBLISH_STREAM_NUM_REACH_LIMIT (152): The host manipulates more than 10 URLs. Delete the unnecessary URLs before adding new ones.
  • ERR_PUBLISH_STREAM_NOT_AUTHORIZED (153): The host manipulates other hosts' URLs. Please check your app logic.
  • ERR_PUBLISH_STREAM_INTERNAL_SERVER_ERROR (154): An error occurs in Agora's streaming server. Call the RemovePublishStreamUrl method to publish the streaming again.
  • ERR_PUBLISH_STREAM_FORMAT_NOT_SUPPORTED (156): The format of the CDN streaming URL is not supported. Check whether the URL format is correct.

OnStreamUnpublished

Occurs when the media push stops.

public virtual void OnStreamUnpublished(string url)
Deprecated:
Please use OnRtmpStreamingStateChanged instead.

Parameters

url
Removes an RTMP or RTMPS URL of the media push.

OnTokenPrivilegeWillExpire

Occurs when the token expires in 30 seconds.

public virtual void OnTokenPrivilegeWillExpire(string token)

When the token is about to expire in 30 seconds, the SDK triggers this callback to remind the app to renew the token.

Upon receiving this callback, generate a new token on your server, and call RenewToken to pass the new token to the SDK.

Parameters

token
The token that expires in 30 seconds.

OnTranscodingUpdated

Occurs when the publisher's transcoding is updated.

public virtual void OnTranscodingUpdated()

When the LiveTranscoding class in the SetLiveTranscoding method updates, the SDK triggers the OnTranscodingUpdated callback to report the update information.

Attention: If you call the SetLiveTranscoding method to set the LiveTranscoding class for the first time, the SDK does not trigger this callback.

OnUploadLogResult

Reports the result of uploading the SDK log files.

public virtual void OnUploadLogResult(string requestId, bool success, UPLOAD_ERROR_REASON reason)
Since
v3.3.0

After UploadLogFile is called, the SDK triggers the callback to report the result of uploading the SDK log files. If the upload fails, refer to the reason parameter to troubleshoot.

Parameters

requestId
The request ID. The request ID is the same as the requestId returned in UploadLogFile. You can use the requestId to match a specific upload with a callback.
success
Whether the log file is uploaded successfully:
  • true: Successfully upload the log files.
  • false: Fails to upload the log files. For details, see the reason parameter.
reason
The reason for the upload failure. For details, see UPLOAD_ERROR_REASON.

OnUserEnableLocalVideo

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

public virtual void OnUserEnableLocalVideo(uint uid, bool enabled)

The SDK triggers this callback when the remote user resumes or stops capturing the video stream by calling the EnableLocalVideo method.

Parameters

uid
The user ID of the remote user.
enabled
Whether the specified remote user enables/disables the local video capturing function:
  • true: Enable. Other users in the channel can see the video of this remote user.
  • false: Disable. Other users in the channel can no longer receive the video stream from this remote user, while this remote user can still receive the video streams from other users.

OnUserEnableVideo

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

public virtual void OnUserEnableVideo(uint uid, bool enabled)

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

The SDK triggers this callback when a remote user enables or disables the video module by calling the EnableVideo or DisableVideo method.

Parameters

uid
The user ID of the remote user.
enabled
  • true: Enable.
  • false: Disable.

OnUserInfoUpdated

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

public virtual void OnUserInfoUpdated(uint uid, UserInfo info)

After a remote user joins the channel, the SDK gets the UID and user account of the remote user, caches them in a mapping table object, and triggers this callback on the local client.

Parameters

uid
The ID of the remote user.
info
The UserInfo object that contains the user ID and user account of the remote user. See UserInfo for details.

OnUserJoined

Occurs when a remote user (COMMUNICATION)/ host (LIVE_BROADCASTING) joins the channel.

public virtual void OnUserJoined(uint uid, int elapsed)
  • In a communication channel, this callback indicates that a remote user joins the channel. The SDK also triggers this callback to report the existing users in the channel when a user joins the channel.
  • In a live-broadcast channel, this callback indicates that a host joins the channel. The SDK also triggers this callback to report the existing hosts in the channel when a host joins the channel. 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 JoinChannel [2/2] method.
  • A remote user switches the user role to the host after joining the channel.
  • A remote user/host rejoins the channel after a network interruption.

Parameters

uid
The ID of the user or host who joins the channel.
elapsed
Time delay (ms) from the local user calling JoinChannel [2/2] until this callback is triggered.

OnUserMuteAudio

Occurs when a remote user (in the communication profile)/ host (in the live streaming profile) joins the channel.

public virtual void OnUserMuteAudio(uint uid, bool muted)

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

Attention: This callback does not work properly when the number of users (in the communication profile) or hosts (in the live streaming profile) in the channel exceeds 17.

Parameters

uid
User ID.
muted
Whether the remote user's audio stream is muted/unmuted:
  • true: Muted.
  • false: Unmuted.

OnUserMuteVideo

Occurs when a remote user's video stream playback pauses/resumes.

public virtual void OnUserMuteVideo(uint uid, bool muted)

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

Attention: This callback does not work properly when the number of users (in the COMMUNICATION profile) or hosts (in the LIVE_BROADCASTING profile) in the channel exceeds 17.

Parameters

uid
The ID of the remote user.
muted
Whether the remote user's video stream playback is paused/resumed:
  • true: Paused.
  • false: Resumed.

OnUserOffline

Occurs when a remote user (COMMUNICATION)/ host (LIVE_BROADCASTING) leaves the channel.

public virtual void OnUserOffline(uint uid, USER_OFFLINE_REASON_TYPE reason)
There are two reasons for users to become offline:
  • Leave the channel: When a user/host leaves the channel, the user/host sends a goodbye message. When this message is received, the SDK determines that the user/host leaves the 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. A poor network connection may lead to false detections. It's recommended to use the Agora RTM SDK for reliable offline detection.

Parameters

uid
The ID of the user who leaves the channel or goes offline.
reason

Reasons why the user goes offline: USER_OFFLINE_REASON_TYPE.

OnVideoDeviceStateChanged

Occurs when the video device state changes.

public virtual void OnVideoDeviceStateChanged(string deviceId, int deviceType, int deviceState)

This callback reports the change of system video devices, such as being unplugged or removed. On a Windows device with an external camera for video capturing, the video disables once the external camera is unplugged.

Parameters

deviceId
The device ID.
deviceType
Media device types. For details, see MEDIA_DEVICE_TYPE.
deviceState
Media device states. For details, see MEDIA_DEVICE_STATE_TYPE.

OnVideoPublishStateChanged

Occurs when the video publishing state changes.

public virtual void OnVideoPublishStateChanged(string channel, STREAM_PUBLISH_STATE oldState,
            STREAM_PUBLISH_STATE newState, int elapseSinceLastState)

Parameters

channel
The name of the channel.
oldState
For the previous publishing state, see STREAM_PUBLISH_STATE.
newState
For the current publishing state, see STREAM_PUBLISH_STATE.
elapseSinceLastState
The time elapsed (ms) from the previous state to the current state.

OnVideoSizeChanged

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

public virtual void OnVideoSizeChanged(uint uid, int width, int height, int rotation)

Parameters

uid
The ID of the user whose video size or rotation changes. uid is 0 for the local user.
width
The width (pixels) of the video stream.
height
The height (pixels) of the video stream.
rotation
The rotation information. The value range is [0,360).

OnVideoStopped

Occurs when the video stops playing.

public virtual void OnVideoStopped()
Deprecated:
Please use LOCAL_VIDEO_STREAM_STATE_STOPPED(0) in the OnLocalVideoStateChanged callback instead.

The application can use this callback to change the configuration of the view (for example, displaying other pictures in the view) after the video stops playing.

OnVideoSubscribeStateChanged

Occurs when the video subscribing state changes.

public virtual void OnVideoSubscribeStateChanged(string channel, uint uid, STREAM_SUBSCRIBE_STATE oldState,
            STREAM_SUBSCRIBE_STATE newState, int elapseSinceLastState)

Parameters

channel
The name of the channel.
uid
The ID of the remote user.
oldState
The previous subscribing status, see STREAM_SUBSCRIBE_STATE for details.
newState
The current subscribing status, see STREAM_SUBSCRIBE_STATE for details.
elapseSinceLastState
The time elapsed (ms) from the previous state to the current state.

OnVirtualBackgroundSourceEnabled

Reports whether virtual background is successfully enabled. (beta feature)

public virtual void OnVirtualBackgroundSourceEnabled(bool enabled,
            VIRTUAL_BACKGROUND_SOURCE_STATE_REASON reason)
Since
v3.5.0

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

Note: If the background image customized in the virtual background is in the PNG or JPG format, this callback is triggered after the image is read.

Parameters

enabled
Whether virtual background is successfully enabled:
  • true: Virtual background is successfully enabled.
  • false: Virtual background is not successfully enabled.
reason
The reason why virtual background is not successfully enabled. See VIRTUAL_BACKGROUND_SOURCE_STATE_REASON.

OnWarning

Reports a warning during SDK runtime.

public virtual void OnWarning(int warn, string msg)

Occurs when a warning occurs during SDK runtime. In most cases, the app can ignore the warnings reported by the SDK because the SDK can usually fix the issue and resume running. For example, when losing connection with the server, the SDK may report WARN_LOOKUP_CHANNEL_TIMEOUT and automatically try to reconnect.

Parameters

warn
Warning codes. For details, see Error Codes and Warning Codes.
msg
Warning description.