H5 SDK callback function reference
Unified Status Code Description: code: 0 indicates success, code: -1 indicates failure
Initialize the relevant callback
onInit: Initialization
Feature Description: SDK initialization result callback.
Signature Call:
onInit({ code, msg })
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
code | String | Initialize the result status code |
msg | String | Initialization failure reasons |
streamType | Number | Streaming Mode (2. Default mode 3. OBS Optimization Mode) |
Return Code Explanation:
| Code | Explanation |
|---|---|
0 | Initialization successful |
-1 | Network fluctuations causing request failures (connection can be reattempted) |
100006 | Request header information is missing, necessary parameter: token |
100007 | Invalid tokens |
100008 | Token verification failed |
120001 | The room corresponding to the pad does not exist |
120002 | Cloud machine connection failed, please try again! |
120003 | Stream interruption error, command transmission failure |
120004 | Stream interruption error, command service error |
120005 | There are no instances |
120006 | The UUID bound to the token does not match the requested UUID |
120007 | The original token information does not exist, please check |
120008 | There are different push-pull flow methods in the current batch instance. Please contact the administrator for assistance |
120009 | The padCode bound to the token does not match the padCode requested |
Connect related callbacks
onConnectSuccess: Connection successful
Function Description: Triggered when the start() interface is successfully called.
Signature Call:
onConnectSuccess()
onConnectFail: Connection failed
Function Description: Triggered when a call to the start() interface fails.
Signature Call:
onConnectFail({ code })
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
code | Number | For error codes, please refer to the error code documentation for details |
onConnectionStateChanged: Connection status
Function Description: Connection status change callback, triggered when the connection status changes after a successful start.
Signature Call:
onConnectionStateChanged(e)
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
e.state | Number | Connection status code |
Status Code Description:
| Status code | Description |
|---|---|
0 | Prepare before connecting and lock in related resources |
1 | The connection is disconnected |
2 | First connection, currently connecting |
3 | The first connection was successful |
4 | Disconnected and reconnected |
5 | After the connection is disconnected, the connection is successfully reconnected |
6 | If the device remains disconnected for more than 10 seconds and reconnects fail, the SDK will continue to attempt reconnection |
onSocketCallback: WebSocket status
Feature Description: WebSocket status information callback.
Signature Call:
onSocketCallback({ code })
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
code | Number | WebSocket status code |
Status Code Description:
| Status code | Description |
|---|---|
0 | Connection successful |
1 | Connection closed |
-1 | Connection failed |
Media-related pullback
onRenderedFirstFrame: First frame rendering
Function Description: Triggered when the first frame of a video is rendered successfully.
Signature Call:
onRenderedFirstFrame(event)
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
event.width | number | High resolution |
event.height | number | High resolution |
event.userId | string | User ID |
event.isScreen | boolean | Is it full screen? |
onChangeResolution: Change in resolution
Function Description: Used to monitor resolution changes and return between old and new resolutions.
Signature Call:
onChangeResolution({ from, to })
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
from | Object | Old resolution object {width, height} |
to | Object | New resolution objects {width, height} |
onAutoplayFailed: Autoplay failed
Function Description: Triggered when automatic playback of audio or video streams fails.
Signature Call:
onAutoplayFailed(event)
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
userId | String | User ID of the stream that failed to autoplay (if not included, the local stream failed to play) |
kind | String | Media types that fail to autoplay ("video" or "audio") |
streamIndex | Number | Video streaming attributes (0: mainstream, 1: screen streaming) |
mediaType | Number | Remote media stream types (1: audio, 2: video, 3: audio and video) |
onChangeRotate: Screen rotation
Function Description: Triggered when switching between landscape and portrait modes.
Signature Call:
onChangeRotate(type, info)
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
type | Number | Screen orientation (0: portrait, 1: landscape) |
info | Object | Screen size information: {width, height} |
Data Collection Related Callbacks
onAudioInit: Audio capture
Function Description: Audio data collection callback, indicating start recording microphone sound.
Signature Call:
onAudioInit(audioTrackSettings)
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
audioTrackSettings | Object | For audio track settings, see MediaTrackSettings |
onAudioError: Audio error
Function Description: Captures audio data error callbacks.
Signature Call:
onAudioError(event)
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
event.code | String | Error code |
Error Code Explanation:
| Error code | Description |
|---|---|
REPEAT_CAPTURE | Repeat collection |
GET_AUDIO_TRACK_FAILED | If audio capture fails, please check whether there are available recording devices or if other apps are taking up the space |
STREAM_TYPE_NOT_MATCH | Stream type mismatch |
onVideoInit: Video capture
Function Description: Captures video data with callback, indicating the start of receiving camera footage.
Signature Call:
onVideoInit(videoTrackSettings)
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
videoTrackSettings | Object | For video track settings, see MediaTrackSettings |
onVideoError: Video error
Function Description: Error callback for capturing video data.
Signature Call:
onVideoError(event)
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
event.code | String | Error code |
Error Code Explanation:
| Error code | Description |
|---|---|
REPEAT_CAPTURE | Repeat collection |
GET_AUDIO_TRACK_FAILED | If audio capture fails, please check whether there are available recording devices or if other apps are taking up the space |
STREAM_TYPE_NOT_MATCH | Stream type mismatch |
Status monitoring callbacks
onErrorMessage: Playback Exception
Function Description: Triggered when playback is abnormal.
Signature Call:
onErrorMessage({ code })
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
code | Number | Error Types (0: RTC channel interruption, 1: Error when retrieving statistics) |
onRunInformation: RunInformation
Function Description: Pullback current running information, with statistics every 2 seconds.
Signature Call:
onRunInformation(stats)
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
stats | Object | Remote media flow statistics |
stats.userId | String | The userId of the user entering the room |
stats.audioStats | Object | Remote audio stream information |
stats.videoStats | Object | Remote video streaming information |
audioStats parameter description:
| Parameter name | Type | Description |
|---|---|---|
audioLossRate | Number | Audio packet loss rate (range: [0, 1]) |
receivedKBitrate | Number | Received bitrate (unit: kbps) |
stallCount | Number|undefined | Count the number of lag times within a cycle |
stallDuration | Number|undefined | Stutter duration (unit: ms) |
totalRtt | Number | Full-link round-trip latency (unit: ms; Firefox browser may not be accurate) |
statsInterval | Number | Statistical interval (unit: ms) |
rtt | Number | Round-trip delay (unit: ms) |
jitterBufferDelay | Number | Jitter Delay (unit: ms) |
numChannels | Number | The number of sound channels |
receivedSampleRate | Number | Reception sampling rate |
concealedSamples | Number | Total number of audio packet loss compensation (PLC) sample points |
concealmentEvent | Number | Cumulative number of audio packet loss compensation (PLC) instances |
videoStats parameter description:
| Parameter name | Type | Description |
|---|---|---|
width | Number | Video width (unit: px) |
height | Number | Video height (unit: px) |
videoLossRate | Number | Video packet loss rate (range: [0, 1]) |
receivedKBitrate | Number | Received bitrate (unit: kbps) |
decoderOutputFrameRate | Number | Decoder output frame rate (unit: fps) |
stallCount | Number|undefined | Count the number of lag times within a cycle |
stallDuration | Number|undefined | Stutter duration (unit: ms) |
totalRtt | Number | Full-link round-trip latency (unit: ms; Firefox browser may not be accurate) |
isScreen | Boolean | Is it screen streaming? |
statsInterval | Number | Statistical interval (unit: ms) |
rtt | Number | Round-trip delay (unit: ms) |
codecType | String | Video encoding format ("H264" or "VP8") |
onNetworkQuality: Network quality
Feature Description: Network quality information callback, returns every 2 seconds after joining a room.
Signature Call:
onNetworkQuality(uplinkNetworkQuality, downlinkNetworkQuality)
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
uplinkNetworkQuality | Number | Uplink network quality |
downlinkNetworkQuality | Number | Downlink network quality |
Network Quality Level:
| Value | Explanation |
|---|---|
0 (UNKNOWN) | Network quality is unknown |
1 (EXCELLENT) | The network quality is excellent |
2 (GOOD) | Good network quality (similar to EXCELLENT's subjective impression, but bitrate may be slightly lower) |
3 (POOR) | There was slight lag, but it basically didn't affect communication |
4 (BAD) | Communication is not smooth; it is recommended to reduce the sampling rate or switch to pure voice mode |
5 (VBAD) | The network is extremely poor, basically impossible to communicate. It is recommended to alert users that the network is weak |
6 (DOWN) | The network connection is disconnected, making calls impossible |
onProgress: Load progress
Feature Description: Load-progress-related callbacks.
Signature Call:
onProgress({ code, msg })
Parameter Description:
| Code | Explanation |
|---|---|
WS_CONNECT (100) | WS began to connect |
WS_SUCCESS (101) | WS connection successful |
WS_CLOSE (102) | WS connection is closed |
WS_ERROR (103) | WS connection error |
OWN_JOIN_ROOM (200) | Received information to join the room |
RECEIVE_OFFER (201) | Successfully set the offer information |
RECEIVE_OFFER_ERR (202) | Failed to set offer information |
SEND_ANSWER (203) | Send the answer message |
SEND_ANSWER_ERR (204) | Failed to send the answer message |
RECEIVE_ICE (205) | ICE information was added successfully |
RECEIVE_ICE_ERR (206) | Failed to add ICE information |
SEND_ICE (207) | Send ICE messages |
RTC_CONNECTING (300) | RTC is connecting |
RTC_CONNECTED (301) | RTC connection successful |
RTC_DISCONNECTED (302) | RTC disconnects |
RTC_CLOSE (303) | RTC connection is off |
RTC_FAILED (304) | RTC connection failed |
RTC_TRACK_VIDEO (305) | RTC receives the VIDEO stream |
RTC_TRACK_VIDEO_LOAD (306) | RTC successfully loads the VIDEO stream after receiving it |
RTC_CHANNEL_OPEN (307) | RTC message channel connection successful |
RTC_CHANNEL_ERR (308) | RTC message channel connection failed |
VIDEO_FIRST_FRAME (309) | If the VIDEO loads successfully, the cloud phone's UI message has not been received |
VIDEO_FIRST_FRAME (310) | The first frame of VIDEO was rendered successfully |
User interaction callbacks
onUserLeaveOrJoin: Users enter and exit the room
Feature Description: Triggered when a user joins or leaves a room.
Signature Call:
onUserLeaveOrJoin({ type, userInfo })
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
type | String | Event Types (join: Join Room, leave: Leave Room) |
userInfo | Object | User information {userId, extraInfo} |
onUserLeave: User exits
Function Description: Triggered when a remote user leaves the room.
Signature Call:
onUserLeave(event)
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
userId | String | User ID for leaving the room |
reason | Number | Reasons for leaving |
Explanation of Reason for Departure:
| Value | Explanation |
|---|---|
0 (QUIT) | Active Exit (Call leaveRoom) |
1 (DROPPED) | Disconnection (such as expired tokens, network issues) |
2 (SWITCH_TO_INVISIBLE) | Switch to invisible (call setUserVisibility) |
3 (KICKED_BY_ADMIN) | Kicked out by the administrator |
onUserJoined: User joined
Function Description: Triggered when a remote user joins a room.
Signature Call:
onUserJoined({ userInfo })
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
userInfo.userId | String | User ID of the room joined |
userInfo.extraInfo | String | Other information |
onAutoRecoveryTime: No operation timeout
Function Description: Triggers when the operation time expires.
Signature Call:
onAutoRecoveryTime()
onMonitorOperation: Operation information
Function Description: Enable monitoring operation callback information
Signature Call:
onMonitorOperation(event)
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
event.actionTime | number | Button time |
event.actionType | number | Operation types (such as press, lift) |
event.keyCode | number | Physical key numbering |
event.simulateHeight | number | Screen height |
event.simulateWidth | number | Screen width |
event.swipe | number | Rolling distance (-1 indicates up, 1 indicates down) |
event.touchType | string | Key type |
event.x | number | The X coordinate of the screen tap |
event.y | number | The Y coordinate of the screen tap |
Feature Callbacks
onTransparentMsg: Transmitting messages
Function Description: Triggered when receiving a message from the cloud app.
Signature Call:
onTransparentMsg(type, msg)
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
type | String | Reserved fields (currently filled in by default 0) |
msg | String | Message content (string) |
onOutputClipper: Content copy
Function Description: Triggered when the cloud phone copies content.
Signature Call:
onOutputClipper(data)
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
data.content | String | Copying content |
onAdbOutput: Result of the ADB command
Function Description: Returns results after executing the ADB command.
Signature Call:
onAdbOutput(event)
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
isSuccess | Boolean | Whether it succeeds |
content | String | Results returned after success |
onInjectVideoResult: Video injection result
Function Description: Video injection camera start or stop operation result callback.
Signature Call:
onInjectVideoResult(type, data)
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
type | String | Callback type (startVideoInjection or stopVideoInjection) |
data.isSuccess | Boolean | Whether the operation was successful |
data.content | String | Reasons for operation failure |
onMediaDevicesToggle: Turning Cloud Phone On or Off (Camera/Microphone)
Function Description: Cloud device on or off (camera/microphone) callback.
Signature Call:
onMediaDevicesToggle(stats)
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
stats.type | String | media: camera and microphone, camera: camera, microphone: microphone |
stats.enabled | Boolean | Whether to open it |
stats.isFront | Boolean | Whether to precede or not: Note: This property only exists for types media and camera |
Error handling callbacks
onGroupControlError: Group control error
Function Description: Error callbacks related to group control.
Signature Call:
onGroupControlError({ code, msg })
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
code | String | Error code |
msg | String | False information |
Error Code Explanation:
| Error code | Description |
|---|---|
TOKEN_ERR | Token acquisition interface failed |
INVALID_TOKEN | Tokens are invalid or expired |
JOIN_ROOM_FAILED | Failed to enter the room |
REPEAT_JOIN | Repeated entry into the room |
ROOM_FORBIDDEN | The room was sealed off |
USER_FORBIDDEN | Users were banned |
onSendUserError: Command transmission error
Function Description: Abnormalities occur when sending remote commands.
Signature Call:
onSendUserError(error)
Parameter Description:
| Parameters | Type | Description |
|---|---|---|
error.code | String | Error code |
Error Code Explanation:
| Error code | Description |
|---|---|
USER_MESSAGE_TIMEOUT | Message timeout has passed |
USER_MESSAGE_BROKEN | Channel disconnected, sending failed |
USER_MESSAGE_NO_RECEIVER | No recipient found |
USER_MESSAGE_NOT_JOIN | The sender did not join the room |
USER_MESSAGE_UNKNOWN | Unknown errors |