TRTCCloudListener
Copyright (c) 2026 Tencent. All rights reserved.
Module: TRTCCloudListener @ TXLiteAVSDK
Function: Event callback APIs of Tencent Cloud TRTC
Version: 13.5
Tencent Cloud TRTC event callback APIs. Flutter SDK:
tencent_rtc_sdk. After creating a TRTCCloudListener object and registering it via TRTCCloud's registerListener, you can receive various events thrown by the SDK.Callback List
Error and Warning Events
Room Events
Callback | Description |
Callback of whether room entry is successful. | |
Callback of exiting a room. | |
Callback of role switching. | |
Callback of the result of room switching. | |
Callback of the result of requesting a cross-room call. | |
Callback of the result of ending a cross-room call. |
User and Audio/Video Stream Events
Callback | Description |
A user joined the current room. | |
A user left the current room. | |
A remote user published/unpublished the primary video stream. | |
A remote user published/unpublished the substream video. | |
A remote user published/unpublished their audio. | |
The SDK started rendering the first video frame of the local or a remote user. | |
The SDK started playing the first audio frame of a remote user. | |
The first local video frame was published. | |
The first local audio frame was published. | |
Callback of remote video status change. | |
Callback of remote audio status change. | |
Callback of remote video resolution change. |
Network and Technical Metric Statistics
Callback | Description |
Real-time network quality statistics callback. | |
Real-time callback of audio/video technical metric statistics. | |
Callback of network speed test result. |
Connection to the Cloud
Callback | Description |
The SDK was disconnected from the cloud. | |
The SDK is trying to reconnect to the cloud. | |
The SDK is reconnected to the cloud. |
Hardware Device Events
Callback | Description |
The camera is ready. | |
The microphone is ready. | |
The current audio route changed. | |
Volume feedback callback. | |
The system capture volume of the current microphone changed (desktop). | |
The current system playback volume changed (desktop). | |
Callback of whether system audio capturing was enabled successfully (desktop only). | |
Volume callback during microphone test. | |
Volume callback during speaker test. |
Custom Message Receiving Events
Callback | Description |
Callback of receiving a custom message. | |
Callback of losing custom messages. | |
Callback of receiving an SEI message. |
CDN Events
Callback | Description |
Callback of starting to publish media streams. | |
Callback of updating media streams. | |
Callback of stopping media streams. | |
Callback of RTMP/RTMPS push status change. |
Screen Sharing Events
Callback | Description |
Callback of screen sharing start. | |
Callback of screen sharing pause. | |
Callback of screen sharing resume. | |
Callback of screen sharing stop. | |
Callback of the target window of screen sharing being covered (Windows only). |
Local Recording and Local Screenshot Events
Callback | Description |
Callback of local recording task start. | |
Callback of local recording task progress. | |
Callback of recording segment end. | |
Callback of local recording task end. | |
Callback of local screenshot completion. |
Callback Details
The following describes the signature, trigger timing, parameters and notes of each callback, in the order of the callback list.
onError
final void Function(int errCode, String errMsg)? onError
Error event callback.
Error event, indicating an unrecoverable error thrown by the SDK, such as a failure to enter a room or to turn on a device.
Parameter | Type | Description |
errCode | int | Error code. |
errMsg | String | Error message. |
onWarning
final void Function(int warningCode, String warningMsg)? onWarning
Warning event callback.
Warning event, indicating an issue thrown by the SDK that requires attention, such as video stuttering or excessive CPU usage.
Parameter | Type | Description |
warningCode | int | Warning code. |
warningMsg | String | Warning message. |
onEnterRoom
final void Function(int result)? onEnterRoom
Callback of whether room entry is successful.
After calling the enterRoom API in
TRTCCloud to enter a room, you will receive the onEnterRoom(result) callback from the SDK:If room entry succeeded,
result will be a positive number (result > 0), indicating the time taken to enter the room in milliseconds (ms).If room entry failed,
result will be a negative number (result < 0), indicating the error code of the room entry failure.Parameter | Type | Description |
result | int | When result > 0, it is the time taken to enter the room, in milliseconds.When result < 0, it is the room entry error code. |
Description:
1. In TRTC versions earlier than 6.6, the
onEnterRoom(result) callback is thrown only when room entry succeeds, and room entry failure is thrown by the onError() callback.2. Starting from TRTC 6.6, the
onEnterRoom(result) callback is thrown regardless of whether room entry succeeds or fails, and the onError() callback is also thrown when room entry fails.onExitRoom
final void Function(int reason)? onExitRoom
Callback of exiting a room.
Calling the exitRoom API in
TRTCCloud executes the room exit logic, such as releasing audio/video device resources and codec resources. After all resources occupied by the SDK are released, the SDK will notify you through the onExitRoom() callback.If you want to call
enterRoom() again or switch to another audio/video SDK, wait for the onExitRoom() callback before proceeding. Otherwise, you may encounter problems such as the camera or microphone being occupied.Parameter | Type | Description |
reason | int | Reason for leaving the room. 0: Exited the room by actively calling exitRoom.1: Kicked out of the current room by the server.2: The current room was dismissed. |
onSwitchRole
final void Function(int errCode, String errMsg)? onSwitchRole
Callback of role switching.
Calling the switchRole API in
TRTCCloud switches between the anchor and audience roles, which involves a channel switching process. After the SDK completes the switch, it throws the onSwitchRole() event callback.Parameter | Type | Description |
errCode | int | |
errMsg | String | Error message. |
onSwitchRoom
final void Function(int errCode, String errMsg)? onSwitchRoom
Callback of the result of room switching.
Calling the switchRoom API in
TRTCCloud allows a user to switch from one room to another. After the SDK completes the switch, it throws the onSwitchRoom() event callback.Parameter | Type | Description |
errCode | int | |
errMsg | String | Error message. |
onConnectOtherRoom
final void Function(String userId, int errCode, String errMsg)? onConnectOtherRoom
Callback of the result of requesting a cross-room call.
Calling the connectOtherRoom API in
TRTCCloud connects anchors in two different rooms for a video call, which is the so-called "anchor PK" feature. The caller will receive the onConnectOtherRoom() callback to learn whether the cross-room call is successful.If successful, all users in both rooms will receive the
onUserVideoAvailable() callback of the PK anchor from the other room.Parameter | Type | Description |
userId | String | User ID of the anchor in the other room for the cross-room call. |
errCode | int | |
errMsg | String | Error message. |
onDisconnectOtherRoom
final void Function(int errCode, String errMsg)? onDisconnectOtherRoom
Callback of the result of ending a cross-room call.
Parameter | Type | Description |
errCode | int | |
errMsg | String | Error message. |
onRemoteUserEnterRoom
final void Function(String userId)? onRemoteUserEnterRoom
A user joined the current room.
For performance reasons, the behavior of this callback varies in different application scenarios (i.e.,
AppScene, specified by the second parameter of enterRoom):Live streaming scenarios (
TRTCAppScene.live or TRTCAppScene.voiceChatRoom): Users in these scenarios are divided into anchors and audience members, and this notification is triggered only when an anchor enters the room.Call scenarios (
TRTCAppScene.videoCall or TRTCAppScene.audioCall): Users in these scenarios have no role distinction (all can be regarded as anchors), and this notification is triggered when any user enters the room.Parameter | Type | Description |
userId | String | User ID of the remote user. |
Description:
1. The
onRemoteUserEnterRoom event callback only indicates that a user has entered the room, not that the user has enabled audio or video.2. If you want to know whether a user has enabled video, it is recommended to use the onUserVideoAvailable callback.
onRemoteUserLeaveRoom
final void Function(String userId, int reason)? onRemoteUserLeaveRoom
A user left the current room.
Corresponding to
onRemoteUserEnterRoom, the behavior of this callback varies in different application scenarios (i.e., TRTCAppScene, specified by the second parameter of enterRoom):Live streaming scenarios (
TRTCAppScene.live or TRTCAppScene.voiceChatRoom): This notification is triggered only when an anchor leaves the room.Call scenarios (
TRTCAppScene.videoCall or TRTCAppScene.audioCall): Users in these scenarios have no role distinction, and this notification is triggered when any user leaves the room.Parameter | Type | Description |
userId | String | User ID of the remote user. |
reason | int | Reason for leaving. 0: The user actively exited the room.1: The user exited due to timeout.2: The user was kicked out of the room.3: The anchor exited the room due to switching to audience. |
onUserVideoAvailable
final void Function(String userId, bool available)? onUserVideoAvailable
A remote user published/unpublished the primary video stream.
The "primary stream" is generally used for camera images. When you receive the
onUserVideoAvailable(userId, true) notification, it indicates that the user has a playable primary stream. At this point, you can call the startRemoteView API to subscribe to the user's remote video. After successful subscription, you will further receive the first-frame rendering callback onFirstVideoFrame(userId) of the user.When you receive the
onUserVideoAvailable(userId, false) notification, it indicates that the remote video has been disabled, possibly because the user called muteLocalVideo or stopLocalPreview.Parameter | Type | Description |
userId | String | User ID of the remote user. |
available | bool | Whether the user published (or unpublished) the primary video stream. true: Published.false: Unpublished. |
onUserSubStreamAvailable
final void Function(String userId, bool available)? onUserSubStreamAvailable
A remote user published/unpublished the substream video.
The "substream" is generally used for screen sharing images. When you receive the
onUserSubStreamAvailable(userId, true) notification, it indicates that the user has a playable substream. At this point, you can call the startRemoteView API to subscribe to the user's remote video. After successful subscription, you will further receive the first-frame rendering callback onFirstVideoFrame(userId) of the user.Parameter | Type | Description |
userId | String | User ID of the remote user. |
available | bool | Whether the user published (or unpublished) the substream video. true: Published.false: Unpublished. |
Description:
The API used to display the substream is startRemoteView (pass
TRTCVideoStreamType.sub for streamType).onUserAudioAvailable
final void Function(String userId, bool available)? onUserAudioAvailable
A remote user published/unpublished their audio.
When you receive the
onUserAudioAvailable(userId, true) notification, it indicates that the user has published their audio:In automatic subscription mode, the SDK automatically plays the user's audio.
In manual subscription mode, you can call muteRemoteAudio
(userId, false) to play the user's audio.Parameter | Type | Description |
userId | String | User ID of the remote user. |
available | bool | Whether the user published (or unpublished) their audio. true: Published.false: Unpublished. |
Description:
The SDK uses automatic subscription mode by default. You can switch to manual subscription by calling setDefaultStreamRecvMode, but it must be called before room entry to take effect.
onFirstVideoFrame
final void Function(String userId, TRTCVideoStreamType streamType, int width, int height)? onFirstVideoFrame
The SDK started rendering the first video frame of the local or a remote user.
The SDK throws this event when rendering the first video frame of the local or a remote user. You can use the
userId parameter in the callback to determine whether the event comes from "local" or "remote":If
userId is empty, the SDK has started rendering the local video, provided that you have called startLocalPreview or startScreenCapture.If
userId is not empty, the SDK has started rendering the video of a remote user, provided that you have called startRemoteView to subscribe to the user's video.Parameter | Type | Description |
userId | String | User ID of the local or remote user. Empty indicates that the first local video frame has arrived; non-empty indicates that the first video frame of a remote user has arrived. |
streamType | Video stream type: the primary stream is generally used for camera images, and the substream is generally used for screen sharing images. | |
width | int | Width of the video. |
height | int | Height of the video. |
Description:
1. The first local video frame event callback is triggered only after you call startLocalPreview or startScreenCapture.
2. The first video frame event callback of a remote user is triggered only after you call startRemoteView.
onFirstAudioFrame
final void Function(String userId)? onFirstAudioFrame
The SDK started playing the first audio frame of a remote user.
The SDK throws this event when playing the first audio frame of a remote user. The first-frame event of local audio is not thrown.
Parameter | Type | Description |
userId | String | User ID of the remote user. |
onSendFirstLocalVideoFrame
final void Function(TRTCVideoStreamType streamType)? onSendFirstLocalVideoFrame
The first local video frame was published.
After you successfully enter a room and enable local video capturing via startLocalPreview or startScreenCapture (the order of enabling capturing and entering the room does not matter), the SDK starts video encoding and publishes the local video data to the cloud through its own network module.
After the SDK successfully sends the first video data frame to the cloud, it throws the
onSendFirstLocalVideoFrame event callback.Parameter | Type | Description |
streamType | Video stream type: the primary stream is generally used for camera images, and the substream is generally used for screen sharing images. |
onSendFirstLocalAudioFrame
final void Function()? onSendFirstLocalAudioFrame
The first local audio frame was published.
After you successfully enter a room and enable local audio capturing via startLocalAudio (the order of enabling capturing and entering the room does not matter), the SDK starts audio encoding and publishes the local audio data to the cloud through its own network module.
After the SDK successfully sends the first audio data frame to the cloud, it throws the
onSendFirstLocalAudioFrame event callback.onRemoteVideoStatusUpdated
final void Function(String userId, TRTCVideoStreamType streamType, TRTCAVStatusType status, TRTCAVStatusChangeReason reason)? onRemoteVideoStatusUpdated
Callback of remote video status change.
You can use this callback to get the video status of each remote user (including
Playing, Loading and Stopped) and display the UI accordingly.Parameter | Type | Description |
userId | String | User ID. |
streamType | Video stream type: the primary stream is generally used for camera images, and the substream is generally used for screen sharing images. | |
status | ||
reason |
onRemoteAudioStatusUpdated
final void Function(String userId, TRTCAVStatusType status, TRTCAVStatusChangeReason reason)? onRemoteAudioStatusUpdated
Callback of remote audio status change.
You can use this callback to get the audio status of each remote user (including
Playing, Loading and Stopped) and display the UI accordingly.Parameter | Type | Description |
userId | String | User ID. |
status | ||
reason |
onUserVideoSizeChanged
final void Function(String userId, TRTCVideoStreamType streamType, int newWidth, int newHeight)? onUserVideoSizeChanged
Callback of remote video resolution change.
When you receive the
onUserVideoSizeChanged(userId, streamType, newWidth, newHeight) callback, it indicates that the resolution of the video stream has changed, which may be caused by the remote user calling setVideoEncoderParam or setSubStreamEncoderParam.Parameter | Type | Description |
userId | String | User ID. |
streamType | Video stream type: the primary stream is generally used for camera images, and the substream is generally used for screen sharing images. | |
newWidth | int | Width of the video stream. |
newHeight | int | Height of the video stream. |
onNetworkQuality
final void Function(TRTCQualityInfo localQuality, List<TRTCQualityInfo> remoteQuality)? onNetworkQuality
Real-time network quality statistics callback.
This statistics callback is thrown every 2 seconds to notify you of the current upstream and downstream network quality perceived by the SDK. The SDK uses a set of built-in proprietary algorithms to evaluate the latency, bandwidth and stability of the current network and calculates an evaluation result:
An evaluation result of
1 (Excellent) means the current network is very good; 6 (Down) means the current network cannot support normal TRTC calls. For values, see TRTCQuality.Parameter | Type | Description |
localQuality | Upstream network quality. | |
remoteQuality | List<TRTCQualityInfo> | Downstream network quality, i.e., the data quality finally measured locally after the data stream passes through the complete transmission link of "remote > cloud > local". Therefore, the downstream network quality here reflects the combined effect of the remote upstream link and the local downstream link. |
Description:
This API cannot determine the upstream quality of remote users alone.
onStatistics
final void Function(TRTCStatistics statistics)? onStatistics
Real-time callback of audio/video technical metric statistics.
This statistics callback is thrown every 2 seconds to notify you of the SDK's internal professional technical metrics related to audio, video and network, all of which are listed in TRTCStatistics:
Video statistics: Video resolution (
resolution), frame rate (FPS), bitrate (bitrate), etc.Audio statistics: Audio sample rate (
samplerate), channels (channel), bitrate (bitrate), etc.Network statistics: Round-trip time between the SDK and the cloud (SDK > Cloud > SDK) (
rtt), packet loss rate (loss), upstream traffic (sentBytes), downstream traffic (receivedBytes), etc.Parameter | Type | Description |
statistics | Statistics, including local statistics and statistics of remote users. |
Description:
If you only need to know whether the current network quality is good or bad and don't want to spend much time studying this statistics callback, onNetworkQuality is recommended.
onSpeedTestResult
final void Function(TRTCSpeedTestResult result)? onSpeedTestResult
Callback of network speed test result.
Parameter | Type | Description |
result | Network speed test data, including packet loss rate, round-trip latency, and upstream and downstream bandwidth. |
onConnectionLost
final void Function()? onConnectionLost
The SDK was disconnected from the cloud.
onTryToReconnect
final void Function()? onTryToReconnect
The SDK is trying to reconnect to the cloud.
onConnectionRecovery
final void Function()? onConnectionRecovery
The SDK is reconnected to the cloud.
onCameraDidReady
final void Function()? onCameraDidReady
The camera is ready.
onMicDidReady
final void Function()? onMicDidReady
The microphone is ready.
onAudioRouteChanged
final void Function(TXAudioRoute newRoute, TXAudioRoute oldRoute)? onAudioRouteChanged
The current audio route changed.
Parameter | Type | Description |
newRoute | ||
oldRoute |
onUserVoiceVolume
final void Function(List<TRTCVolumeInfo> userVolumes, int totalVolume)? onUserVoiceVolume
Volume feedback callback.
The SDK can evaluate the volume of each audio stream and throw this callback periodically. You can display effects such as sound waves or volume bars on the UI based on the callback results.
You need to call enableAudioVolumeEvaluation first to enable this feature and set the callback interval.
Note that the SDK throws this callback periodically at the interval you set regardless of whether anyone in the room is speaking.
Parameter | Type | Description |
userVolumes | List<TRTCVolumeInfo> | Volume of all users who are speaking in the room. |
totalVolume | int | Total volume of all remote users. Value range: 0 - 100. |
Description:
userVolumes is an array. For each element in the array, an empty userId indicates the volume of the local user, and a non-empty userId indicates the volume of a remote user.onAudioDeviceCaptureVolumeChanged
final void Function(int volume, bool muted)? onAudioDeviceCaptureVolumeChanged
The system capture volume of the current microphone changed (desktop).
On desktop operating systems such as macOS and Windows, users can set the capture volume of the microphone in the volume control panel. The higher the value, the louder the raw volume of the sound captured by the microphone. On some keyboards and laptops, users can also mute the microphone by pressing the "disable microphone" button (the icon is a microphone with a slash).
The SDK throws this event when the user adjusts the capture volume of the microphone through the system UI or shortcut keys.
Parameter | Type | Description |
volume | int | System capture volume, i.e., the volume users can set in the volume control panel. Value range: 0 - 100. |
muted | bool | Whether the microphone is disabled by the user. true: Disabled.false: Enabled. |
Description:
You need to call enableAudioVolumeEvaluation and set
interval > 0 to enable this event callback, or set interval = 0 to disable it.onAudioDevicePlayoutVolumeChanged
final void Function(int volume, bool muted)? onAudioDevicePlayoutVolumeChanged
The current system playback volume changed (desktop).
On desktop operating systems such as macOS and Windows, users can set the system playback volume in the volume control panel. On some keyboards and laptops, users can also mute the speaker by pressing the "mute" button (the icon is a speaker with a slash).
The SDK throws this event when the user adjusts the system playback volume through the system UI or shortcut keys.
Parameter | Type | Description |
volume | int | System playback volume, i.e., the volume users can set in the volume control panel. Value range: 0 - 100. |
muted | bool | Whether the speaker is disabled by the user. true: Disabled.false: Enabled. |
Description:
You need to call enableAudioVolumeEvaluation and set
interval > 0 to enable this event callback, or set interval = 0 to disable it.onSystemAudioLoopbackError
final void Function(int errCode)? onSystemAudioLoopbackError
Callback of whether system audio capturing was enabled successfully (desktop only).
On macOS, you can install an audio driver by calling startSystemAudioLoopback and let the SDK capture the sound played by the current system.
On Windows, you can call startSystemAudioLoopback to let the SDK capture the sound played by the current system.
In application scenarios such as video teaching and music live streaming, teachers can use this feature to have the SDK capture the sound of videos played on their computers, so that students in the room can also hear it.
The SDK throws the result of this attempt to enable system audio capturing through this callback. Pay attention to the error code in the parameters.
Parameter | Type | Description |
errCode | int | ERR_NULL indicates that system audio capturing was enabled successfully; otherwise, it failed. |
onTestMicVolume
final void Function(int volume)? onTestMicVolume
Volume callback during microphone test.
When you call startMicDeviceTest to test whether the microphone works properly, the SDK continuously throws this callback. The
volume parameter indicates the volume currently captured by the microphone.If
volume fluctuates during the test, the microphone is healthy; if the value of volume is always 0, the microphone is abnormal and the user should be prompted to replace it.Parameter | Type | Description |
volume | int | Volume captured by the microphone. Value range: 0 - 100. |
onTestSpeakerVolume
final void Function(int volume)? onTestSpeakerVolume
Volume callback during speaker test.
When you call startSpeakerDeviceTest to test whether the speaker works properly, the SDK continuously throws this callback.
The
volume parameter indicates the volume of the sound submitted by the SDK to the system speaker for playback. If the value keeps changing but the user reports hearing no sound, the speaker is abnormal.Parameter | Type | Description |
volume | int | Volume of the sound submitted by the SDK to the speaker for playback. Value range: 0 - 100. |
onRecvCustomCmdMsg
final void Function(String userId, int cmdId, int seq, String message)? onRecvCustomCmdMsg
Callback of receiving a custom message.
When a user in the room sends a custom message via sendCustomCmdMsg, other users in the room can receive the message through the
onRecvCustomCmdMsg event callback.Parameter | Type | Description |
userId | String | User ID. |
cmdId | int | Command ID. |
seq | int | Message sequence number. |
message | String | Message data. |
onMissCustomCmdMsg
final void Function(String userId, int cmdId, int errCode, int missed)? onMissCustomCmdMsg
Callback of losing custom messages.
When you send custom UDP messages via sendCustomCmdMsg, even if reliable transmission is set (
reliable is true), 100% delivery cannot be guaranteed; the probability of message loss is just very low, which meets the reliability requirements of most scenarios.After reliable transmission is set on the sending side (
reliable is true), the SDK uses this callback to notify the receiver of the number of custom messages lost in transit over a past period (usually 5s).Parameter | Type | Description |
userId | String | User ID. |
cmdId | int | Command ID. |
errCode | int | Error code. |
missed | int | Number of lost messages. |
Description:
The receiver can receive the message loss callback only if reliable transmission is set on the sending side (
reliable is true).onRecvSEIMsg
final void Function(String userId, String message)? onRecvSEIMsg
Callback of receiving an SEI message.
When a user in the room sends an SEI message via video data frames using sendSEIMsg, other users in the room can receive the message through the
onRecvSEIMsg event callback.Parameter | Type | Description |
userId | String | User ID. |
message | String | Data. |
onStartPublishMediaStream
final void Function(String taskId, int errCode, String errMsg, String extraInfo)? onStartPublishMediaStream
Callback of starting to publish media streams.
When you call startPublishMediaStream to start publishing media streams to the TRTC backend service, the SDK immediately synchronizes this instruction to the cloud server, then receives the processing result from the cloud server and notifies you of the execution result through this event callback.
Parameter | Type | Description |
taskId | String | If the request succeeds, the TRTC backend returns the taskId of this task in the callback. You can then use this taskId with updatePublishMediaStream and stopPublishMediaStream to update and stop the task. |
errCode | int | Callback result. 0 indicates success, and other values indicate failure. |
errMsg | String | Detailed callback information. |
extraInfo | String | Extra information. For some error codes, extra information may be provided to help you troubleshoot. |
onUpdatePublishMediaStream
final void Function(String taskId, int errCode, String errMsg, String extraInfo)? onUpdatePublishMediaStream
Callback of updating media streams.
When you call updatePublishMediaStream to modify publishing parameters, the SDK immediately synchronizes this instruction to the cloud server, then receives the processing result from the cloud server and notifies you of the execution result through this event callback.
Parameter | Type | Description |
taskId | String | The taskId you passed in when calling updatePublishMediaStream, used to identify which request this callback belongs to. |
errCode | int | Callback result. 0 indicates success, and other values indicate failure. |
errMsg | String | Detailed callback information. |
extraInfo | String | Extra information. For some error codes, extra information may be provided to help you troubleshoot. |
onStopPublishMediaStream
final void Function(String taskId, int errCode, String errMsg, String extraInfo)? onStopPublishMediaStream
Callback of stopping media streams.
When you call stopPublishMediaStream to stop publishing media streams, the SDK immediately synchronizes this instruction to the cloud server, then receives the processing result from the cloud server and notifies you of the execution result through this event callback.
Parameter | Type | Description |
taskId | String | The taskId you passed in when calling stopPublishMediaStream, used to identify which request this callback belongs to. |
errCode | int | Callback result. 0 indicates success, and other values indicate failure. |
errMsg | String | Detailed callback information. |
extraInfo | String | Extra information. For some error codes, extra information may be provided to help you troubleshoot. |
onCdnStreamStateChanged
final void Function(String cdnUrl, int status, int errCode, String errMsg, String extraInfo)? onCdnStreamStateChanged
Callback of RTMP/RTMPS push status change.
When you call startPublishMediaStream to start publishing media streams to the TRTC backend service, the SDK immediately synchronizes this instruction to the cloud server.
If you set the URL of Tencent Cloud or a third-party CDN in the target push configuration (TRTCPublishTarget), the specific RTMP/RTMPS push status will be synchronized to you through this callback.
Parameter | Type | Description |
cdnUrl | String | The URL you passed in through the target push configuration (TRTCPublishTarget) when calling startPublishMediaStream. |
status | int | Push status. For values, see "Push Status Values" below. |
errCode | int | Push result. 0 indicates success, and other values indicate failure. |
errMsg | String | Detailed push information. |
extraInfo | String | Extra information. For some error codes, extra information may be provided to help you troubleshoot. |
Push Status Values:
Value | Description |
0 | Pushing has not started or has ended. This status is returned when you call stopPublishMediaStream. |
1 | Connecting to the TRTC server and the CDN server. If the connection cannot succeed immediately, the TRTC backend service retries pushing multiple times and returns this status (every 5s). If pushing succeeds, the status changes to 2.If a server error occurs or pushing does not succeed within 60 seconds, the status changes to 4. |
2 | CDN pushing is in progress. This status is returned after pushing succeeds. |
3 | Pushing between the TRTC server and the CDN server is interrupted and is being recovered. When the CDN is abnormal or pushing is interrupted, the TRTC backend service tries to recover pushing and returns this status (every 5s). If pushing is recovered successfully, the status changes to 2.If a server error occurs or recovery does not succeed within 60 seconds, the status changes to 4. |
4 | Pushing between the TRTC server and the CDN server is interrupted, and recovery or connection has timed out, i.e., pushing has failed. You can call updatePublishMediaStream again to retry pushing. |
5 | Disconnecting from the TRTC server and the CDN server. When you call stopPublishMediaStream, the SDK first returns this status and then returns status 0. |
onScreenCaptureStarted
final void Function()? onScreenCaptureStarted
Callback of screen sharing start.
onScreenCapturePaused
final void Function(int reason)? onScreenCapturePaused
Callback of screen sharing pause.
Parameter | Type | Description |
reason | int | Reason for pausing. 0: Paused by the user.1: Paused because the shared window became invisible (Mac), or because screen sharing parameters were being set (Windows).2: Paused because the shared window was minimized (Windows only).3: Paused because the shared window was hidden (Windows only). |
onScreenCaptureResumed
final void Function(int reason)? onScreenCaptureResumed
Callback of screen sharing resume.
Parameter | Type | Description |
reason | int | Reason for resuming. 0: Resumed by the user.1: Automatically resumed after the shared window became visible again (Mac), or after screen sharing parameters were set (Windows).2: Automatically resumed after the shared window was restored from being minimized (Windows only).3: Automatically resumed after the shared window was restored from being hidden (Windows only). |
onScreenCaptureStopped
final void Function(int reason)? onScreenCaptureStopped
Callback of screen sharing stop.
Parameter | Type | Description |
reason | int | Reason for stopping. 0: Stopped by the user.1: The shared window was closed. |
onScreenCaptureCovered
final void Function()? onScreenCaptureCovered
Callback of the target window of screen sharing being covered (Windows only).
The SDK throws this event callback when the target window of screen sharing is covered and cannot be captured properly. After receiving this callback, you can prompt the user via the UI to move away the covering window.
onLocalRecordBegin
final void Function(int errCode, String storagePath)? onLocalRecordBegin
Callback of local recording task start.
When you call startLocalRecording to start a local media recording task, the SDK throws this event callback to notify you whether the recording task has started successfully.
Parameter | Type | Description |
errCode | int | Recording status. 0: The recording task started successfully.-1: The recording task failed to start.-2: Unsupported recording format.-6: Recording has already started and needs to be stopped first.-7: The recording file already exists and needs to be deleted first.-8: No write permission on the recording directory. Check the directory permissions. |
storagePath | String | Storage path of the recording file. |
onLocalRecording
final void Function(int duration, String storagePath)? onLocalRecording
Callback of local recording task progress.
After you successfully start a local media recording task by calling startLocalRecording, the SDK throws this event callback periodically. You can use this callback to learn the status of the recording task.
You can set the interval of this event callback when calling
startLocalRecording.Parameter | Type | Description |
duration | int | Accumulated recording duration, in milliseconds. |
storagePath | String | Storage path of the recording file. |
onLocalRecordFragment
final void Function(String storagePath)? onLocalRecordFragment
Callback of recording segment end.
When segmented recording is enabled, the SDK throws this event callback each time a segment file is completed.
Parameter | Type | Description |
storagePath | String | Storage path of the segment file. |
onLocalRecordComplete
final void Function(int errCode, String storagePath)? onLocalRecordComplete
Callback of local recording task end.
When you call stopLocalRecording to stop a local media recording task, the SDK throws this event callback to notify you of the final result of the recording task.
Parameter | Type | Description |
errCode | int | Recording status. 0: Recording succeeded.-1: Recording failed.-2: Recording ended due to a change in resolution or screen orientation.-3: The recording duration is too short, or no video or audio data was captured. Check the recording duration or whether audio/video capturing has been enabled. |
storagePath | String | Storage path of the recording file. |
onSnapshotComplete
final void Function(String userId, String path, int errCode, String errMsg)? onSnapshotComplete
Callback of local screenshot completion.
After a screenshot is taken by calling snapshotVideo, the SDK returns the screenshot result through this callback.
Parameter | Type | Description |
userId | String | User ID corresponding to the screenshot. |
path | String | Path of the screenshot file. |
errCode | int | Error code. |
errMsg | String | Error message. |
Type Definitions
The enums and data classes used in the callback parameters of this document are defined in
lib/trtc_cloud_def.dart. For details, see TRTCCloudDef. Commonly used ones include:Type | Description |
Audio/Video playback status. | |
Reason for playback status change. | |
Network quality. | |
Network quality information. | |
Summary statistics of network and performance. | |
Volume. | |
Network speed test result. | |
Video stream type. | |
Log level. |
Other Callback Classes
TRTCLogCallback
TRTCLogCallback({required void Function(String log, TRTCLogLevel level, String module) onLog})
Log callback.
onLog
final void Function(String log, TRTCLogLevel level, String module) onLog
Local log printing callback.
If you want to capture the local log printing of the SDK, you can set a log callback to have the SDK call back all logs to be printed to you through this callback.
Parameter | Type | Description |
log | String | Log content. |
level | Log level. | |
module | String | Reserved field with no specific meaning yet. Currently it is the fixed value TXLiteAVSDK. |
Sample Code
trtcCloud.setLogCallback(TRTCLogCallback(onLog: (String log, TRTCLogLevel level, String module) {debugPrint('[$level] $log');},));
