RtcEngineEventHandler

The SDK uses the RtcEngineEventHandler 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.

Attention:
  • 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.
  • The SDK no longer catches exceptions in the code logic that developers implement themselves in RtcEngineEventHandler class. You need to handle this exception yourself, otherwise the app may crash when the exception occurs.

onActiveSpeaker

Occurs when the most active remote speaker is detected.

final void Function(RtcConnection connection, int uid)? onActiveSpeaker;

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

When the number of users is no less than two and an active remote speaker exists, the SDK triggers this callback and reports the uid of the most active remote speaker.
  • If the most active remote speaker is always the same user, the SDK triggers the onActiveSpeaker callback only once.
  • If the most active remote speaker changes to another user, the SDK triggers this callback again and reports the uid of the new active remote speaker.

Parameters

connection
The connection information. See RtcConnection.
uid
The user ID of the most active speaker.

onAudioDeviceStateChanged

Occurs when the audio device state changes.

final void Function(String deviceId, MediaDeviceType deviceType,
      MediaDeviceStateType deviceState)? onAudioDeviceStateChanged;

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

Note: This method is for Windows and macOS only.

Parameters

deviceId
The device ID.
deviceType
The device type. See MediaDeviceType.
deviceState
The device state. See MediaDeviceStateType.

onAudioDeviceVolumeChanged

Reports the volume change of the audio device or app.

final void Function(MediaDeviceType deviceType, int volume, bool muted)?
      onAudioDeviceVolumeChanged;

Occurs when the volume on the playback device, audio capture device, or the volume of the app changes.

Note: This callback is for Windows and macOS only.

Parameters

deviceType
The device type. See MediaDeviceType.
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 music file finishes.

final void Function(int soundId)? onAudioEffectFinished;

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

Parameters

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

onAudioMixingFinished

Occurs when the playback of the local music file finishes.

final void Function()? onAudioMixingFinished;
Deprecated:
Use onAudioMixingStateChanged instead.

After you call startAudioMixing to play a local music file, this callback occurs when the playback finishes. If the call of startAudioMixing fails, the error code WARN_AUDIO_MIXING_OPEN_ERROR is returned.

onAudioMixingStateChanged

Occurs when the playback state of the music file changes.

final void Function(AudioMixingStateType state, AudioMixingReasonType reason)?
      onAudioMixingStateChanged;

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. See AudioMixingStateType.
reason
Error code. See AudioMixingReasonType.

onAudioPublishStateChanged

Occurs when the audio publishing state changes.

final void Function(
      String channel,
      StreamPublishState oldState,
      StreamPublishState newState,
      int elapseSinceLastState)? onAudioPublishStateChanged;

Parameters

channel
The channel name.
oldState
The previous publishing state. See StreamPublishState.
newState
The current publishing stat. See StreamPublishState.
elapseSinceLastState
The time elapsed (ms) from the previous state to the current state.

onAudioQuality

Reports the statistics of the audio stream sent by each remote user.

final void Function(RtcConnection connection, int remoteUid,
      QualityType quality, int delay, int lost)? onAudioQuality;
Deprecated:
Use onRemoteAudioStats instead.

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

Parameters

connection
The connection information. See RtcConnection.
remoteUid
The user ID of the remote user sending the audio stream.
quality
Audio quality of the user. See QualityType.
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
The packet loss rate (%) of the audio packet sent from the remote user to the receiver.

onAudioRoutingChanged

Occurs when the local audio route changes.

final void Function(int routing)? onAudioRoutingChanged;
Note:

This method is for Android, iOS and macOS only.

Parameters

routing

The current audio routing. See AudioRoute.

onAudioSubscribeStateChanged

Occurs when the audio subscribing state changes.

final void Function(
      String channel,
      int uid,
      StreamSubscribeState oldState,
      StreamSubscribeState newState,
      int elapseSinceLastState)? onAudioSubscribeStateChanged;

Parameters

channel
The channel name.
uid
The user ID of the remote user.
oldState
The previous subscribing status. See StreamSubscribeState.
newState
The current subscribing status. See StreamSubscribeState.
elapseSinceLastState
The time elapsed (ms) from the previous state to the current state.

onAudioVolumeIndication

Reports the volume information of users.

final void Function(RtcConnection connection, List<AudioVolumeInfo> speakers,
      int speakerNumber, int totalVolume)? onAudioVolumeIndication;

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 onAudioVolumeIndication callback according to the time interval set in enableAudioVolumeIndication. 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 volume is the highest.

Attention:

Once this callback is enabled, if the local user calls the muteLocalAudioStream method to mute, the SDK continues to report the volume indication of the local user.

If a remote user whose volume is one of the three highest in the channel stops publishing the audio stream for 20 seconds, the callback excludes this user's information; if all remote users stop publishing audio streams for 20 seconds, the SDK stops triggering the callback for remote users.

Parameters

connection
The connection information. See RtcConnection.
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 is sending a stream.
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 volume is the highest.

onCameraExposureAreaChanged

Occurs when the camera exposure area changes.

final void Function(int x, int y, int width, int height)?
      onCameraExposureAreaChanged;

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

Attention: This callback is for Android and iOS only.

Parameters

onCameraFocusAreaChanged

Occurs when the camera focus area changes.

final void Function(int x, int y, int width, int height)?
      onCameraFocusAreaChanged;

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

Attention: This callback is for Android and iOS only.

Parameters

x
The x-coordinate of the changed camera focus area.
y
The y-coordinate of the changed camera focus area.
width
The width of the changed camera focus area.
height
The height of the changed camera focus area.

onCameraReady

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

final void Function()? onCameraReady;
Deprecated:

Use localVideoStreamStateCapturing(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.

final void Function(
          ChannelMediaRelayState state, ChannelMediaRelayError code)?
      onChannelMediaRelayStateChanged;

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

Parameters

state

The state code. See ChannelMediaRelayState.

code

The error code of the channel media relay. See ChannelMediaRelayError.

onClientRoleChanged

Occurs when the user role or the audience latency level changes.

final void Function(
      RtcConnection connection,
      ClientRoleType oldRole,
      ClientRoleType newRole,
      ClientRoleOptions newRoleOptions)? onClientRoleChanged;

Trigger timing

This callback will be triggered in any of the following situations:
  • Calling setClientRole to set the user role or audience latency level after joining a channel.
  • Calling setClientRole to set the user role to AUDIENCE before joining a channel.

Restrictions

This callback will not be triggered when you call or setClientRole and set the user role to BROADCASTER before joining a channel.

Parameters

connection
The connection information. See RtcConnection.
oldRole
Role that the user switches from: ClientRoleType.
newRole
Role that the user switches to: ClientRoleType.
newRoleOptions

Properties of the role that the user switches to. See ClientRoleOptions.

onClientRoleChangeFailed

Occurs when switching a user role fails.

final void Function(
            RtcConnection connection,
            ClientRoleChangeFailedReason reason,
            ClientRoleType currentRole)? onClientRoleChangeFailed;

This callback informs you about the reason for failing to switching and your current user role.

Trigger timing

The SDK triggers this callback when the local user calls setClientRole after joining a channel to switch the user role but the switching fails.

Restrictions

None.

Parameters

reason
The reason for a user role switch failure. See ClientRoleChangeFailedReason.
currentRole
Current user role. See ClientRoleType.
connection
The connection information. See RtcConnection.

onConnectionInterrupted

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

final void Function(RtcConnection connection)? onConnectionInterrupted;
Deprecated:
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 differences between this callback and onConnectionLost are as follow:
  • 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.

Parameters

connection
The connection information. See RtcConnection.

onConnectionLost

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

final void Function(RtcConnection connection)? onConnectionLost;

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. If the SDK fails to rejoin the channel 20 minutes after being disconnected from Agora's edge server, the SDK stops rejoining the channel.

Parameters

connection
The connection information. See RtcConnection.

onConnectionStateChanged

Occurs when the network connection state changes.

final void Function(RtcConnection connection, ConnectionStateType state,
      ConnectionChangedReasonType reason)? onConnectionStateChanged;

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

Parameters

connection
The connection information. See RtcConnection.
state

The current connection state. See ConnectionStateType.

reason

The reason for a connection state change. See ConnectionChangedReasonType.

onEncryptionError

Reports the built-in encryption errors.

final void Function(RtcConnection connection, EncryptionErrorType errorType)?
      onEncryptionError;

When encryption is enabled by calling enableEncryption, the SDK triggers this callback if an error occurs in encryption or decryption on the sender or the receiver side.

Parameters

connection
The connection information. See RtcConnection.
errorType
Details about the error type. See EncryptionErrorType.

onError

Reports an error during SDK runtime.

final void Function(ErrorCodeType err, String msg)? onError;

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 app to take action or informs the user about the issue.

Parameters

err
Error code. See ErrorCodeType.
msg
The error message.

onExtensionError

Occurs when the extension runs incorrectly.

final void Function(
          String provider, String extension, int error, String message)?
      onExtensionError;

In case of extension enabling failure or runtime errors, the extension triggers this callback and reports the error code along with the reasons.

Parameters

provider
The name of the extension provider.
extension
The name of the extension.
error
Error code. For details, see the extension documentation provided by the extension provider.
message
Reason. For details, see the extension documentation provided by the extension provider.

onExtensionEvent

The event callback of the extension.

final void Function(
          String provider, String extName, String key, String value)?
      onExtensionEvent;

To listen for events while the extension is running, you need to register this callback.

Parameters

provider
The name of the extension provider.
extName
The name of the extension.
key
The key of the extension.
value
The value of the extension key.

onExtensionStarted

Occurs when the extension is enabled.

final void Function(String provider, String extName)? onExtensionStarted;

The extension triggers this callback after it is successfully enabled.

Parameters

provider
The name of the extension provider.
extName
The name of the extension.

onExtensionStopped

Occurs when the extension is disabled.

final void Function(String provider, String extName)? onExtensionStopped;

The extension triggers this callback after it is successfully destroyed.

Parameters

provider
The name of the extension provider.
extName
The name of the extension.

onFacePositionChanged

Reports the face detection result of the local user.

final void Function(int imageWidth, int imageHeight, Rectangle vecRectangle,
      int vecDistance, int numFaces)? onFacePositionChanged;
Once you enable face detection by calling enableFaceDetection(true), 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 screen.

This value is based on the fitting calculation of the local video size and the position of the human face.

Attention:
  • This callback is for Android and iOS only.
  • When it is detected that the face in front of the camera disappears, the callback will be triggered immediately. When no human face is detected, the frequency of this callback to be triggered wil be decreased 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.
  • On Android, the value of distance reported in this callback may be slightly different from the actual distance. Therefore, Agora does not recommend using it for accurate calculation.

Parameters

imageWidth
The width (px) of the video image captured by the local camera.
imageHeight
The height (px) of the video image captured by the local camera.
vecRectangle
The information of the detected human face. See Rectangle.
vecDistance
The distance between the human face and the device screen (cm).
numFaces
The number of faces detected. If the value is 0, it means that no human face is detected.

onFirstLocalAudioFramePublished

Occurs when the first audio frame is published.

final void Function(RtcConnection connection, int elapsed)?
      onFirstLocalAudioFramePublished;
The SDK triggers this callback under one of the following circumstances:
  • The local client enables the audio module and calls joinChannel successfully.
  • The local client calls muteLocalAudioStream(true) and muteLocalAudioStream(false) in sequence.
  • The local client calls disableAudio and enableAudio in sequence.

Parameters

connection
The connection information. See RtcConnection.
elapsed
Time elapsed (ms) from the local user calling joinChannel until the SDK triggers this callback.

onFirstLocalVideoFrame

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

final void Function(
          VideoSourceType source, int width, int height, int elapsed)?
      onFirstLocalVideoFrame;

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

Parameters

source
The type of the video source. See VideoSourceType.
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 to join the channel to when the SDK triggers this callback. If startPreviewWithoutSourceType/startPreview is called before joining the channel, this parameter indicates the time elapsed from calling startPreviewWithoutSourceType or startPreview to when this event occurred.

onFirstLocalVideoFramePublished

Occurs when the first video frame is published.

final void Function(RtcConnection connection, int elapsed)?
      onFirstLocalVideoFramePublished;
The SDK triggers this callback under one of the following circumstances:

Parameters

connection
The connection information. See RtcConnection.
elapsed
Time elapsed (ms) from the local user calling joinChannel until this callback is triggered.

onFirstRemoteAudioFrame

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

final void Function(RtcConnection connection, int userId, int elapsed)?
      onFirstRemoteAudioFrame;
Deprecated:
Use onRemoteAudioStateChanged instead.

Parameters

connection
The connection information. See RtcConnection.
userId
The user ID of the remote user.
elapsed
The time elapsed (ms) from the local user calling joinChannel until the SDK triggers this callback.

onFirstRemoteAudioDecoded

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

final void Function(RtcConnection connection, int uid, int elapsed)?
      onFirstRemoteAudioDecoded;
Deprecated:
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

connection
The connection information. See RtcConnection.
uid
The user ID of the remote user.
elapsed
The time elapsed (ms) from the local user calling joinChannel until the SDK triggers this callback.

onFirstRemoteVideoDecoded

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

final void Function(RtcConnection connection, int remoteUid, int width,
      int height, int elapsed)? onFirstRemoteVideoDecoded;
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 disableVideo to disable video.

Parameters

connection
The connection information. See RtcConnection.
remoteUid
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 until the SDK triggers this callback.

onFirstRemoteVideoFrame

Occurs when the renderer receives the first frame of the remote video.

final void Function(RtcConnection connection, int remoteUid, int width,
      int height, int elapsed)? onFirstRemoteVideoFrame;
Attention: This callback is only triggered when the video frame is rendered by the SDK; it will not be triggered if the user employs custom video rendering.You need to implement this independently using methods outside the SDK.

Parameters

uid
remoteUid
The user ID of the remote user sending the video stream.
connection
The connection information. See RtcConnection.
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 until the SDK triggers this callback.

onJoinChannelSuccess

Occurs when a user joins a channel.

final void Function(RtcConnection connection, int elapsed)?
      onJoinChannelSuccess;

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

Parameters

connection
The connection information. See RtcConnection.
elapsed
The time elapsed (ms) from the local user calling joinChannel until the SDK triggers this callback.

onLastmileProbeResult

Reports the last mile network probe result.

final void Function(LastmileProbeResult result)? onLastmileProbeResult;

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

Parameters

result
The uplink and downlink last-mile network probe test result. See LastmileProbeResult.

onLastmileQuality

Reports the last-mile network quality of the local user.

final void Function(QualityType quality)? onLastmileQuality;

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 oncestartLastmileProbeTest is called and reports the last-mile network conditions of the local user.

Parameters

quality
The last-mile network quality. See QualityType.

onLeaveChannel

Occurs when a user leaves a channel.

final void Function(RtcConnection connection, RtcStats stats)? onLeaveChannel;

You can obtain information such as the total duration of a call, and the data traffic that the SDK transmits and receives.

Trigger timing

The SDK triggers this callback after you call leaveChannel or leaveChannelEx to leave a channel.

Restrictions

None.

Parameters

connection
The connection information. See RtcConnection.
stats
Call statistics. See RtcStats.

onLocalAudioStateChanged

Occurs when the local audio stream state changes.

final void Function(RtcConnection connection, LocalAudioStreamState state,
    LocalAudioStreamReason reason)? onLocalAudioStateChanged;

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 is localAudioStreamStateFailed (3), you can view the error information in the error parameter.

Parameters

connection
The connection information. See RtcConnection.
state
The state of the local audio. See LocalAudioStreamState.
reason
Reasons for local audio state changes. See LocalAudioStreamReason.

onLocalAudioStats

Reports the statistics of the local audio stream.

final void Function(RtcConnection connection, LocalAudioStats stats)?
      onLocalAudioStats;

The SDK triggers this callback once every two seconds.

Parameters

connection
The connection information. See RtcConnection.
stats
Local audio statistics. See LocalAudioStats.

onLocalUserRegistered

Occurs when the local user registers a user account.

final void Function(bool isFallbackOrRecover)?
      onLocalPublishFallbackToAudioOnly;

After the local user successfully calls registerLocalUserAccount to register the user account or calls joinChannelWithUserAccount 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.

final void Function(VideoSourceType source, LocalVideoStreamState state,
    LocalVideoStreamReason reason)? onLocalVideoStateChanged;;

When the status of the local video changes, the SDK triggers this callback to report the current local video state and the reason for the state change.

Applicable scenarios

You can use this callback to stay updated on the state changes of the local video stream, and take corresponding measures based on the reasons for the state changes, to better manage and debug issues related to the video stream.

Trigger timing

  • The SDK triggeres this callback under the following circumstances, with the state as localVideoStreamStateFailed, and the reason as localVideoStreamReasonCaptureFailure:
    • The app switches to the background, and the system revokes the camera resource.
    • For Android 9 and later versions, after an app is in the background for a period, the system automatically revokes camera permissions.
    • For Android 6 and later versions, if the camera is held by a third-party app for a certain duration and then released, the SDK triggers this callback and reports the onLocalVideoStateChanged(localVideoStreamStateCapturing,localVideoStreamReasonOk) callback.
    • The camera starts normally, but does not output video frames for four consecutive seconds.
  • When the camera outputs captured video frames, if the SDK detects 15 consecutive duplicate video frames, it triggers this callback, with the state as localVideoStreamStateCapturing and the reason as localVideoStreamReasonCaptureFailure.
    Note: 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.

Restrictions

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

source
The type of the video source. See VideoSourceType.
state

The state of the local video, see LocalVideoStreamState.

reason

The reasons for changes in local video state. See LocalVideoStreamReason.

onLocalVideoStats

Reports the statistics of the local video stream.

final void Function(RtcConnection connection, LocalVideoStats stats)?
      onLocalVideoStats;

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

Parameters

connection
The connection information. See RtcConnection.
stats
The statistics of the local video stream. See LocalVideoStats.

onNetworkQuality

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

final void Function(RtcConnection connection, int remoteUid,
      QualityType txQuality, QualityType rxQuality)? onNetworkQuality;

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.

This callback provides feedback on network quality through sending and receiving broadcast packets within the channel. Excessive broadcast packets can lead to broadcast storms. To prevent broadcast storms from causing a large amount of data transmission within the channel, this callback supports feedback on the network quality of up to 4 remote hosts simultaneously by default.

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

Parameters

connection
The connection information. See RtcConnection.
remoteUid

The 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. See QualityType.
rxQuality
Downlink network quality rating of the user in terms of packet loss rate, average RTT, and jitter of the downlink network. See QualityType.

onNetworkTypeChanged

Occurs when the local network type changes.

final void Function(RtcConnection connection, NetworkType type)?
      onNetworkTypeChanged;

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

connection
The connection information. See RtcConnection.
type

The type of the local network connection. See NetworkType.

onPermissionError

Occurs when the SDK cannot get the device permission.

final void Function(PermissionType permissionType)? onPermissionError;

When the SDK fails to get the device permission, the SDK triggers this callback to report which device permission cannot be got.

Parameters

permissionType
The type of the device permission. See PermissionType.

onProxyConnected

Reports the proxy connection state.

final void Function(String channel, int uid, ProxyType proxyType,
      String localProxyIp, int elapsed)? onProxyConnected;

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 fromthe user calling joinChannel until this callback is triggered.

Parameters

channel
The channel name.
uid
The user ID.
localProxyIp
Reserved for future use.
elapsed
The time elapsed (ms) from the user calling joinChannel until this callback is triggered.

onRejoinChannelSuccess

Occurs when a user rejoins the channel.

final void Function(RtcConnection connection, int elapsed)?
      onRejoinChannelSuccess;

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

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

onRemoteAudioStateChanged

Occurs when the remote audio state changes.

final void Function(
      RtcConnection connection,
      int remoteUid,
      RemoteAudioState state,
      RemoteAudioStateReason reason,
      int elapsed)? onRemoteAudioStateChanged;

When the audio state of a remote user (in a voice/video call channel) or host (in a 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 communication profile) or hosts (in the live streaming channel) in a channel exceeds 17.

Parameters

connection
The connection information. See RtcConnection.
remoteUid
The ID of the remote user whose audio state changes.
state
The state of the remote audio. See RemoteAudioState.
reason
The reason of the remote audio state change. See RemoteAudioStateReason.
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.

final void Function(RtcConnection connection, RemoteAudioStats stats)?
      onRemoteAudioStats;

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

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

onRemoteAudioTransportStats

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

final void Function(RtcConnection connection, int remoteUid, int delay,
      int lost, int rxKBitRate)? onRemoteAudioTransportStats;
Deprecated:
Use onRemoteAudioStats instead.

This callback reports the transport-layer statistics, such as the packet loss rate and network time delay 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, the callback is triggered every 2 seconds.

Parameters

connection
The connection information. See RtcConnection.
remoteUid
The ID of the remote user sending the audio streams.
delay
The network delay (ms) from the remote user to the receiver.
lost
The packet loss rate (%) of the audio packet sent from the remote user to the receiver.
rxKBitrate
The bitrate of the received audio (Kbps).

onRemoteVideoStateChanged

Occurs when the remote video stream state changes.

final void Function(
      RtcConnection connection,
      int remoteUid,
      RemoteVideoState state,
      RemoteVideoStateReason reason,
      int elapsed)? onRemoteVideoStateChanged;
Attention: This callback does not work properly when the number of users (in the communication profile) or hosts (in the live streaming channel) in a channel exceeds 17.

Parameters

connection
The connection information. See RtcConnection.
remoteUid
The ID of the remote user whose video state changes.
state

The state of the remote video. See RemoteVideoState.

reason

The reason for the remote video state change. See RemoteVideoStateReason.

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

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.

  final void Function(int uid, bool isFallbackOrRecover)?
      onRemoteSubscribeFallbackToAudioOnly;
If you call setRemoteSubscribeFallbackOptionand set option to streamFallbackOptionAudioOnly, the SDK triggers this callback in the following situations:
  • The downstream network condition is poor, and the subscribed video stream is downgraded to audio-only stream.
  • The downstream network condition has improved, and the subscribed stream has been restored to video stream.
Attention: Once the remote media stream switches to the low-quality video stream due to weak network conditions, you can monitor the stream switch between a high-quality and low-quality stream in the onRemoteVideoStatscallback.

Parameters

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

onRemoteVideoStats

Reports the statistics of the video stream sent by each remote users.

 

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

connection
The connection information. See RtcConnection.
stats
Statistics of the remote video stream. See RemoteVideoStats.

onRemoteVideoTransportStats

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

final void Function(RtcConnection connection, int remoteUid, int delay,
      int lost, int rxKBitRate)? onRemoteVideoTransportStats;
Deprecated:
This callback is deprecated. Use onRemoteVideoStats instead.

This callback reports the transport-layer statistics, such as the packet loss rate and network time delay 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

connection
The connection information. See RtcConnection.
remoteUid
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).

onRequestToken

Occurs when the token expires.

final void Function(RtcConnection connection)? onRequestToken;

The SDK triggers this callback if the token expires.

When receiving this callback, you need to generate a new token on your token server and you can renew your token through one of the following ways:
  • In scenarios involving one channel:
    • Call renewToken to pass in the new token.
    • Call leaveChannel to leave the current channel and then pass in the new token when you call joinChannel to join a channel.
  • In scenarios involving mutiple channels: Call updateChannelMediaOptionsEx to pass in the new token.

Restrictions

None.

Parameters

connection
The connection information. See RtcConnection.

onRhythmPlayerStateChanged

Occurs when the state of virtual metronome changes.

final void Function(RhythmPlayerStateType state, RhythmPlayerReason reason)?
    onRhythmPlayerStateChanged;

When the state of the virtual metronome changes, the SDK triggers this callback to report the current state of the virtual metronome. This callback indicates the state of the local audio stream and enables you to troubleshoot issues when audio exceptions occur.

Attention: This callback is for Android and iOS only.

Parameters

state
For the current virtual metronome status, see RhythmPlayerStateType.
errorCode
For the error codes and error messages related to virtual metronome errors, see RhythmPlayerReason.

onRtcStats

Reports the statistics about the current call.

final void Function(RtcConnection connection, RtcStats stats)? onRtcStats;

Trigger timing

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

Restrictions

None.

Parameters

connection
The connection information. See RtcConnection.
stats

Statistics of the RTC engine. See RtcStats.

onRtmpStreamingEvent

Reports events during the Media Push.

final void Function(String url, RtmpStreamingEvent eventCode)?
      onRtmpStreamingEvent;

Parameters

url
The URL for Media Push.
eventCode
The event code of Media Push. See RtmpStreamingEvent.

onRtmpStreamingStateChanged

Occurs when the state of Media Push changes.

final void Function(String url, RtmpStreamPublishState state,
    RtmpStreamPublishReason reason)? onRtmpStreamingStateChanged;

When the state of Media Push changes, the SDK triggers this callback and reports the URL address and the current state of the Media Push. This callback indicates the state of the Media Push. 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 RtmpStreamPublishState.
reason
Reasons for the changes in the Media Push status. See RtmpStreamPublishReason.

onSnapshotTaken

Reports the result of taking a video snapshot.

  final void Function(RtcConnection connection, int uid, String filePath,
      int width, int height, int errCode)? onSnapshotTaken;

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

uid
The user ID. One uid of 0 indicates the local user.
connection
The connection information. See RtcConnection.
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 gives 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. The possible reasons are: local capture stops, remote end stops publishing, or video data processing is blocked.
    • -3: Calling the takeSnapshot method too frequently.

onStreamMessage

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

final void Function(RtcConnection connection, int remoteUid, int streamId,
      Uint8List data, int length, int sentTs)? onStreamMessage;

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

Parameters

connection
The connection information. See RtcConnection.
uid
remoteUid
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).
sentTs
The time when the data stream is sent.

onStreamMessageError

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

final void Function(RtcConnection connection, int remoteUid, int streamId,
      ErrorCodeType code, int missed, int cached)? onStreamMessageError;

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

connection
The connection information. See RtcConnection.
remoteUid
The ID of the remote user sending the message.
streamId
The stream ID of the received message.
code
The error code. See ErrorCodeType.
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.

final void Function(RtcConnection connection, String token)?
      onTokenPrivilegeWillExpire;
When receiving this callback, you need to generate a new token on your token server and you can renew your token through one of the following ways:
  • In scenarios involving one channel:
    • Call renewToken to pass in the new token.
    • Call leaveChannel to leave the current channel and then pass in the new token when you call joinChannel to join a channel.
  • In scenarios involving mutiple channels: Call updateChannelMediaOptionsEx to pass in the new token.

Trigger timing

The SDK triggers this callback 30 seconds before the token expires, reminding the app to update the token.

Restrictions

None.

Parameters

token
The token that is about to expire.

onTranscodedStreamLayoutInfo

Occurs when the local user receives a mixed video stream carrying layout information.

final void Function(
    RtcConnection connection,
    int uid,
    int width,
    int height,
    int layoutCount,
    List<VideoLayout> layoutlist)? onTranscodedStreamLayoutInfo;

Details

When the local user receives a mixed video stream sent by the video mixing server for the first time, or when there is a change in the layout information of the mixed stream, the SDK triggers this callback, reporting the layout information of each sub-video stream within the mixed video stream.

Note: This callback is for Android and iOS only.

Parameters

connection
The connection information. See RtcConnection.
uid
User ID who published this mixed video stream.
Layout information of a specific sub-video stream within the mixed stream. See VideoLayout.

onTranscodingUpdated

Occurs when the publisher's transcoding is updated.

final void Function()? onTranscodingUpdated;

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

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

onUplinkNetworkInfoUpdated

Occurs when the uplink network information changes.

final void Function(UplinkNetworkInfo info)? onUplinkNetworkInfoUpdated;

The SDK triggers this callback when the uplink network information changes.

Attention: This callback only applies to scenarios where you push externally encoded video data in H.264 format to the SDK.

Parameters

info
The uplink network information. See UplinkNetworkInfo.

onUserEnableLocalVideo

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

final void Function(RtcConnection connection, int remoteUid, bool enabled)?
      onUserEnableLocalVideo;
Deprecated:
This callback is deprecated, use the following enumerations in the onRemoteVideoStateChanged callback:
  • remoteVideoStateStopped(0) and remoteVideoStateReasonRemoteMuted(5).
  • remoteVideoStateDecoding(2) and remoteVideoStateReasonRemoteUnmuted(6).

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

Parameters

connection
The connection information. See RtcConnection.
remoteUid
The user ID of the remote user.
enabled
Whether the specified remote user enables/disables local video capturing:
  • true: The video module is enabled. Other users in the channel can see the video of this remote user.
  • false: The video module is disabled. 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 or disables the video module.

final void Function(RtcConnection connection, int remoteUid, bool enabled)?
      onUserEnableVideo;

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

connection
The connection information. See RtcConnection.
remoteUid
The user ID of the remote user.
enabled
  • true: The video module is enabled.
  • false: The video module is disabled.

onUserInfoUpdated

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

final void Function(int uid, UserInfo info)? onUserInfoUpdated;

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 user 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 (in the communication profile)/ host (in the live streaming profile) joins the channel.

final void Function(RtcConnection connection, int remoteUid, int elapsed)?
      onUserJoined;
  • 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.
  • 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

connection
The connection information. See RtcConnection.
remoteUid
The ID of the user or host who joins the channel.
elapsed
Time delay (ms) from the local user calling joinChannel until this callback is triggered.

onUserMuteAudio

Occurs when a remote user (in the communication profile) or a host (in the live streaming profile) stops/resumes sending the audio stream.

final void Function(RtcConnection connection, int remoteUid, bool muted)?
      onUserMuteAudio;

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 channel) in a channel exceeds 17.

Parameters

connection
The connection information. See RtcConnection.
remoteUid
The user ID.
muted
Whether the remote user's audio stream is muted:
  • true: User's audio stream is muted.
  • false: User's audio stream is unmuted.

onUserMuteVideo

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

final void Function(RtcConnection connection, int remoteUid, bool muted)?
      onUserMuteVideo;

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

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

Parameters

connection
The connection information. See RtcConnection.
remoteUid
The user ID of the remote user.
muted
Whether the remote user stops publishing the video stream:
  • true: The remote user stops publishing the video stream.
  • false: The remote user resumes publishing the video stream.

onUserOffline

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

final void Function(RtcConnection connection, int remoteUid,
      UserOfflineReasonType reason)? onUserOffline;
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

connection
The connection information. See RtcConnection.
remoteUid
The ID of the user who leaves the channel or goes offline.
reason

Reasons why the user goes offline: UserOfflineReasonType.

onVideoDeviceStateChanged

Occurs when the video device state changes.

final void Function(String deviceId, MediaDeviceType deviceType,
      MediaDeviceStateType deviceState)? onVideoDeviceStateChanged;

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.

Note: This callback is for Windows and macOS only.

Parameters

deviceId
The device ID.
deviceType
Media device types. See MediaDeviceType.
deviceState
Media device states. See MediaDeviceStateType.

onVideoPublishStateChanged

Occurs when the video publishing state changes.

final void Function(
      VideoSourceType source,
      String channel,
      StreamPublishState oldState,
      StreamPublishState newState,
      int elapseSinceLastState)? onVideoPublishStateChanged;

Parameters

channel
The channel name.
source
The type of the video source. See VideoSourceType.
oldState
The previous publishing state. See StreamPublishState.
newState
The current publishing stat. See StreamPublishState.
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.

final void Function(RtcConnection connection, VideoSourceType sourceType,
      int uid, int width, int height, int rotation)? onVideoSizeChanged;

Parameters

connection
The connection information. See RtcConnection.
sourceType
The type of the video source. See VideoSourceType.
uid
The ID of the user whose video size or rotation changes. (The uid for the local user is 0. The video is the local user's video preview).
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).
Note: On the iOS platform, the parameter value is always 0.

onVideoStopped

Occurs when the video stops playing.

final void Function()? onVideoStopped;
Deprecated:
Use localVideoStreamStateStopped(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.

final void Function(
      String channel,
      int uid,
      StreamSubscribeState oldState,
      StreamSubscribeState newState,
      int elapseSinceLastState)? onVideoSubscribeStateChanged;

Parameters

channel
The channel name.
uid
The user ID of the remote user.
oldState
The previous subscribing status. See StreamSubscribeState.
newState
The current subscribing status. See StreamSubscribeState.
elapseSinceLastState
The time elapsed (ms) from the previous state to the current state.