IAgoraRtcChannelEventHandler

The SDK uses IAgoraRtcChannelEventHandler to send IAgoraRtcChannel event notifications to your app.

You can use InitEventHandler to set a listener for an event.

OnActiveSpeaker

Occurs when the most active speaker is detected.

public virtual void OnActiveSpeaker(string channelId, 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

channelId
The channel ID.
uid
The user ID of the most active speaker.

OnAudioPublishStateChanged

Occurs when the audio publishing state changes.

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

Parameters

channelId
The channel ID.
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.

OnAudioSubscribeStateChanged

Occurs when the audio subscribing state changes.

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

Parameters

channelId
The channel ID.
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.

OnChannelMediaRelayEvent

Reports events during the media stream relay.

public virtual void OnChannelMediaRelayEvent(string channelId, CHANNEL_MEDIA_RELAY_EVENT code)

Parameters

channelId
The channel ID.
code

The event code of channel media relay. See CHANNEL_MEDIA_RELAY_EVENT.

OnChannelMediaRelayStateChanged

Occurs when the state of the media stream relay changes.

public virtual void OnChannelMediaRelayStateChanged(string channelId, 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

channelId
The channel ID.
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(string channelId, CLIENT_ROLE_TYPE oldRole, CLIENT_ROLE_TYPE newRole)

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

Parameters

channelId
The channel ID.
oldRole
Role that the user switches from: CLIENT_ROLE_TYPE.
newRole
Role that the user switches to: CLIENT_ROLE_TYPE.

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(string channelId)

The SDK triggers this callback when it cannot connect to the server 10 seconds after calling the JoinChannel method, regardless of whether it is in the channel.

Parameters

channelId
The channel ID.

OnConnectionStateChanged

Occurs when the network connection state changes.

public virtual void OnConnectionStateChanged(string channelId, 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

channelId
The channel ID.
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.

OnJoinChannelSuccess

Occurs when a user joins a channel.

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

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

Parameters

channelId
The channel ID.
uid
User ID. If you have specified a user ID in JoinChannel, the ID will be returned here; otherwise, the SDK returns an ID automatically assigned by the Agora server.
elapsed
The time elapsed (in milliseconds) from the local user calling JoinChannel till this event.

OnMetadataReceived

Occurs when the local user receives Metadata.

public virtual void OnMetadataReceived(Metadata metadata)

Parameters

metadata
The received metadata. See Metadata.

OnLeaveChannel

Occurs when a user leaves a channel.

public virtual void OnLeaveChannel(string channelId, RtcStats stats)

When a user leaves the channel by using the LeaveChannel method, the SDK uses this callback to notify the app when the user leaves the channel. With this callback, the app gets the channel information, such as the call duration and quality statistics.

Parameters

channelId
The channel ID.
stats
The statistics of the call, see RtcStats .

OnLocalPublishFallbackToAudioOnly

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

public virtual void OnLocalPublishFallbackToAudioOnly(string channelId, 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

channelId
The channel ID.
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.

OnNetworkQuality

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

public virtual void OnNetworkQuality(string channelId, 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

channelId
The channel ID.
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.

OnProxyConnected

Reports the proxy connection state.

public virtual void OnProxyConnected(string channelId, 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 until this callback is triggered.

Parameters

channelId
The channel ID.
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.

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 receive and send Metadata. After receiving this callback, you can call SendMetadata to send the media metadata.

Parameters

metadata
Media metadata See Metadata.

OnRejoinChannelSuccess

Occurs when a user rejoins the channel.

public virtual void OnRejoinChannelSuccess(string channelId, 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

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

OnRemoteAudioStateChanged

Occurs when the remote audio state changes.

public virtual void OnRemoteAudioStateChanged(string channelId, 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

channelId
The channel ID.
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 method until the SDK triggers this callback.

OnRemoteAudioStats

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

public virtual void OnRemoteAudioStats(string channelId, 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

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

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(string channelId, 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

channelId
The channel ID.
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(string channelId, 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

channelId
The channel ID.
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 method until the SDK triggers this callback.

OnRemoteVideoStats

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

public virtual void OnRemoteVideoStats(string channelId, 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

channelId
The channel ID.
stats
Statistics of the remote video stream. For details, see RemoteVideoStats.

OnRequestToken

Occurs when the token expires.

public virtual void OnRequestToken(string channelId)

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 to rejoin the channel.

Parameters

channelId
The channel ID.

OnRtcStats

Reports the statistics of the current call.

public virtual void OnRtcStats(string channelId, RtcStats stats)

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

Parameters

channelId
The channel ID.
stats

Statistics of the RTC engine, see RtcStats for details.

OnRtmpStreamingEvent

Reports events during the media push.

public virtual void OnRtmpStreamingEvent(string channelId, string url, RTMP_STREAMING_EVENT eventCode)

Parameters

channelId
The channel ID.
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 channelId, string url, RTMP_STREAM_PUBLISH_STATE state,
            RTMP_STREAM_PUBLISH_ERROR errCode)

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. When exceptions occur, you can troubleshoot issues by referring to the detailed error descriptions in the error code parameter.

Parameters

channelId
The channel ID.
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.

OnStreamMessage

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

public virtual void OnStreamMessage(string channelId, 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

channelId
The channel ID.
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(string channelId, 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

channelId
The channel ID.
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.

OnTokenPrivilegeWillExpire

Occurs when the token expires in 30 seconds.

public virtual void OnTokenPrivilegeWillExpire(string channelId, 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

channelId
The channel ID.
token
The token that expires in 30 seconds.

OnTranscodingUpdated

Occurs when the publisher's transcoding is updated.

public virtual void OnTranscodingUpdated(string channelId)

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.

Parameters

channelId
The channel ID.

OnUserJoined

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

public virtual void OnUserJoined(string channelId, 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 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

channelId
The channel ID.
uid
The ID of the user or host who joins the channel.
elapsed
Time delay (ms) fromthe local user calling JoinChannel until this callback is triggered.

OnUserOffline

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

public virtual void OnUserOffline(string channelId, 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

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

Reasons why the user goes offline: USER_OFFLINE_REASON_TYPE.

OnVideoPublishStateChanged

Occurs when the video publishing state changes.

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

Parameters

channelId
The channel ID.
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(string channelId, uint uid, int width, int height, int rotation)

Parameters

channelId
The channel ID.
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).

OnVideoSubscribeStateChanged

Occurs when the video subscribing state changes.

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

Parameters

channelId
The channel ID.
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.