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 Name | Callback Parameters | Description |
---|---|---|
onInit | onInit({code, msg}) code: Initialization result, 0 : success, -1 : failuremsg: Reason for initialization failure | Initialization callback |
onConnectSuccess | No parameters | Triggered when the start() interface is called successfully |
onErrorMessage | onErrorMessage({code}) code: 0 RTC channel interrupted, 1 error retrieving statistics, 2 packet loss rate | Triggered when playback encounters an exception |
onConnectFail | onConnectFail({code}) code: Error code, see error code documentation for details | Triggered when the start() interface fails |
onAutoRecoveryTime | No parameters | Triggered when the inactivity time expires |
onAutoplayFailed | onAutoplayFailed(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 streammediaType: number, // Type of remote media stream: 1 : audio; 2 : video; 3 : audio and video} | Triggered when autoplaying audio or video streams fails |
onRunInformation | onRunInformation(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 |
onChangeResolution | onChangeResolution(width, height) width: Current resolution width height: Current resolution height | Triggered when the resolution changes |
onTransparentMsg | onTransparentMsg(type, msg) type: Reserved field, currently unused, default is 0 .msg: Message content, string. | Triggered when a message is received from the cloud app |
onOutputClipper | onOutputClipper(msg) msg: Copied message content, string. | Triggered when content is copied in the cloud machine |
onRenderedFirstFrame | No parameters | Triggered when the first frame of video rendering is successful |
onAudioError | onAudioError({code, msg}) msg: API_NOT_AVAILABLE : The current browser does not support microphone functionality | Triggered when obtaining audio-related permissions fails |
onAudioInit | onAudioInit({code}) | Triggered when audio permissions are successfully obtained, and microphone sound is being collected |
onAudioPause | onAudioPause({code}) | Callback for successfully pausing audio collection |
onProgress | onProgress({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 |
onSocketCallback | onSocketCallback({code}) code: 0 for connection successful, 1 for connection closed, -1 for connection failed | WebSocket related callback |
onUserLeaveOrJoin | onUserLeaveOrJoin({type, userInfo}) type: join for joining room, leave for leaving roomuserInfo: {userId: "", extraInfo: ""} | Callback for user joining or leaving the room |
onGroupControlError | onGroupControlError({code, msg}) code: TOKEN_ERR token retrieval failedINVALID_TOKEN : Used an expired or invalid token when joining the roomJOIN_ROOM_FAILED : Room join failedREPEAT_JOIN : Repeatedly joining the roomROOM_FORBIDDEN : Room is banned, causing join failureUSER_FORBIDDEN : User is banned, causing join failuremsg: Error message | Callback for group control errors |