Callback Functions

Callback functions are interfaces triggered by the SDK in specific scenarios, and you can choose to implement them based on your specific business needs.

Callback Function List

Unified Status Codes: code: 0 for success, -1 for failure.

Callback Function NameCallback ParametersDescription
onInitonInit({code, msg})
code: Initialization result, 0: success, -1: failure
msg: Reason for initialization failure
Initialization callback
onConnectSuccessNo parametersTriggered when the start() interface is called successfully
onErrorMessageonErrorMessage({code})
code: 0 RTC channel interrupted, 1 error retrieving statistics, 2 packet loss rate
Triggered when playback encounters an exception
onConnectFailonConnectFail({code})
code: Error code, see error code documentation for details
Triggered when the start() interface fails
onAutoRecoveryTimeNo parametersTriggered when the inactivity time expires
onAutoplayFailedonAutoplayFailed(event)
event: Player event
{
userId: string, // User ID of the stream that failed to autoplay (omitted for local stream failures)
kind: string, // Media type of autoplay failure: "video" or "audio"
streamIndex: number, // Video stream property: 0: main stream; 1: screen stream
mediaType: number, // Type of remote media stream: 1: audio; 2: video; 3: audio and video
}
Triggered when autoplaying audio or video streams fails
onRunInformationonRunInformation(stats)
stats: Remote media stream statistics, updated every 2 seconds.
{
userId: string, // User ID of the participant
audioStats: object, // Remote audio stream information
videoStats: object, // Remote video stream information
isScreen: boolean, // Indicates whether the media stream belongs to a screen stream
}
Callback for current running information
onChangeResolutiononChangeResolution(width, height)
width: Current resolution width
height: Current resolution height
Triggered when the resolution changes
onTransparentMsgonTransparentMsg(type, msg)
type: Reserved field, currently unused, default is 0.
msg: Message content, string.
Triggered when a message is received from the cloud app
onOutputClipperonOutputClipper(msg)
msg: Copied message content, string.
Triggered when content is copied in the cloud machine
onRenderedFirstFrameNo parametersTriggered when the first frame of video rendering is successful
onAudioErroronAudioError({code, msg})
msg: API_NOT_AVAILABLE: The current browser does not support microphone functionality
Triggered when obtaining audio-related permissions fails
onAudioInitonAudioInit({code})Triggered when audio permissions are successfully obtained, and microphone sound is being collected
onAudioPauseonAudioPause({code})Callback for successfully pausing audio collection
onProgressonProgress({code, msg})
{
"WS_CONNECT": {code: 100, msg: "WS starting connection"},
"WS_SUCCESS": {code: 101, msg: "WS connection successful"},
"WS_CLOSE": {code: 102, msg: "WS connection closed"},
"WS_ERROR": {code: 103, msg: "WS connection error"},
"OWN_JOIN_ROOM": {code: 200, msg: "Received join room information"},
"RECEIVE_OFFER": {code: 201, msg: "Offer information set successfully"},
"RECEIVE_OFFER_ERR": {code: 202, msg: "Failed to set offer information"},
"SEND_ANSWER": {code: 203, msg: "Sending answer information"},
"SEND_ANSWER_ERR": {code: 204, msg: "Failed to send answer information"},
"RECEIVE_ICE": {code: 205, msg: "ICE information added successfully"},
"RECEIVE_ICE_ERR": {code: 206, msg: "Failed to add ICE information"},
"SEND_ICE": {code: 207, msg: "Sending ICE information"},
"RTC_CONNECTING": {code: 300, msg: "RTC is connecting"},
"RTC_CONNECTED": {code: 301, msg: "RTC connection successful"},
"RTC_DISCONNECTED": {code: 302, msg: "RTC disconnected"},
"RTC_CLOSE": {code: 303, msg: "RTC connection closed"},
"RTC_FAILED": {code: 304, msg: "RTC connection failed"},
"RTC_TRACK_VIDEO": {code: 305, msg: "RTC received VIDEO stream"},
"RTC_TRACK_VIDEO_LOAD": {code: 306, msg: "RTC loaded successfully in VIDEO after receiving VIDEO stream"},
"RTC_CHANNEL_OPEN": {code: 307, msg: "RTC message channel connection successful"},
"RTC_CHANNEL_ERR": {code: 308, msg: "RTC message channel connection failed"},
"VIDEO_FIRST_FRAME": {code: 309, msg: "VIDEO loaded successfully when UI information from the cloud machine has not been received"},
"VIDEO_FIRST_FRAME": {code: 310, msg: "VIDEO first frame rendered successfully"}}
Loading progress callback
onSocketCallbackonSocketCallback({code})
code: 0 for connection successful, 1 for connection closed, -1 for connection failed
WebSocket related callback
onUserLeaveOrJoinonUserLeaveOrJoin({type, userInfo})
type: join for joining room, leave for leaving room
userInfo: {userId: "", extraInfo: ""}
Callback for user joining or leaving the room
onGroupControlErroronGroupControlError({code, msg})
code: TOKEN_ERR token retrieval failed
INVALID_TOKEN: Used an expired or invalid token when joining the room
JOIN_ROOM_FAILED: Room join failed
REPEAT_JOIN: Repeatedly joining the room
ROOM_FORBIDDEN: Room is banned, causing join failure
USER_FORBIDDEN: User is banned, causing join failure
msg: Error message
Callback for group control errors