H5 SDK Callback Functions
Unified Status Code Description: code: 0 indicates success, code: -1 indicates failure
Initialization Callbacks
onInit: Initialization
Description: Callback for SDK initialization result. Signature:
onInit({ code, msg })
Parameters:
| Parameter | Type | Description |
|---|---|---|
code | String | Initialization result code |
msg | String | Failure reason |
streamType | Number | Push stream mode (2: Default mode, 3: OBS optimized mode) |
Return Codes:
| Code | Description |
|---|---|
0 | Initialization successful |
-1 | Network fluctuation caused request failure (retry possible) |
100006 | Missing required parameter in request header: token |
100007 | Invalid token |
100008 | Token verification failed |
120001 | Room corresponding to pad does not exist |
120002 | Failed to connect to cloud phone, please retry |
120003 | Stop streaming error: command send failed |
120004 | Stop streaming error: command service exception |
120005 | Instance does not exist |
120006 | UUID bound to token does not match requested UUID |
120007 | Original token information does not exist, please check |
120008 | Instances in current batch have different push/pull methods, contact administrator |
120009 | padCode bound to token does not match requested padCode |
Connection Callbacks
onConnectSuccess: Connection Success
Description: Triggered when start() interface succeeds. Signature:
onConnectSuccess()
onConnectFail: Connection Failure
Description: Triggered when start() interface fails. Signature:
onConnectFail({ code })
Parameters:
| Parameter | Type | Description |
|---|---|---|
code | Number | Error code (see error code document) |
onConnectionStateChanged: Connection State
Description: Connection state change callback, triggered after start succeeds when state changes. Signature:
onConnectionStateChanged(e)
Parameters:
| Parameter | Type | Description |
|---|---|---|
e.state | Number | Connection state code |
State Codes:
| State Code | Description |
|---|---|
0 | Preparing before connection, locking resources |
1 | Disconnected |
2 | First connection in progress |
3 | First connection successful |
4 | Reconnecting after disconnect |
5 | Reconnect successful after disconnect |
6 | Disconnected >10s without successful reconnect; SDK continues attempting |
onSocketCallback: WebSocket Status
Description: WebSocket status information callback. Signature:
onSocketCallback({ code })
Parameters:
| Parameter | Type | Description |
|---|---|---|
code | Number | WebSocket status code |
Status Codes:
| Status Code | Description |
|---|---|
0 | Connected |
1 | Closed |
-1 | Connection failed |
Media Callbacks
onRenderedFirstFrame: First Frame Rendered
Description: Triggered when video first frame is successfully rendered. Signature:
onRenderedFirstFrame(event)
Parameters:
| Parameter | Type | Description |
|---|---|---|
event.width | number | Resolution width |
event.height | number | Resolution height |
event.userId | string | User ID |
event.isScreen | boolean | Whether full screen |
onChangeResolution: Resolution Change
Description: Monitors resolution changes, returns old and new resolutions. Signature:
onChangeResolution({ from, to })
Parameters:
| Parameter | Type | Description |
|---|---|---|
from | Object | Old resolution {width, height} |
to | Object | New resolution {width, height} |
onAutoplayFailed: Autoplay Failed
Description: Triggered when autoplay of audio/video stream fails. Signature:
onAutoplayFailed(event)
Parameters:
| Parameter | Type | Description |
|---|---|---|
userId | String | User ID of failed stream (absent if local stream failed) |
kind | String | Media type ("video" or "audio") |
streamIndex | Number | Video stream attribute (0: main stream, 1: screen stream) |
mediaType | Number | Remote media type (1: audio, 2: video, 3: both) |
onChangeRotate: Screen Rotation
Description: Triggered on portrait/landscape switch. Signature:
onChangeRotate(type, info)
Parameters:
| Parameter | Type | Description |
|---|---|---|
type | Number | Screen orientation (0: portrait, 1: landscape) |
info | Object | Screen size info {width, height} |
Data Capture Callbacks
onAudioInit: Audio Capture
Description: Audio data capture callback, indicates starting to receive microphone audio. Signature:
onAudioInit(audioTrackSettings)
Parameters:
| Parameter | Type | Description |
|---|---|---|
audioTrackSettings | Object | Audio track settings (see MediaTrackSettings) |
onAudioError: Audio Error
Description: Audio data capture error callback. Signature:
onAudioError(event)
Parameters:
| Parameter | Type | Description |
|---|---|---|
event.code | String | Error code |
Error Codes:
| Error Code | Description |
|---|---|
REPEAT_CAPTURE | Repeated capture |
GET_AUDIO_TRACK_FAILED | Audio capture failed; check available device or if occupied by other app |
STREAM_TYPE_NOT_MATCH | Stream type mismatch |
onVideoInit: Video Capture
Description: Video data capture callback, indicates starting to receive camera video. Signature:
onVideoInit(videoTrackSettings)
Parameters:
| Parameter | Type | Description |
|---|---|---|
videoTrackSettings | Object | Video track settings (see MediaTrackSettings) |
onVideoError: Video Error
Description: Video data capture error callback. Signature:
onVideoError(event)
Parameters:
| Parameter | Type | Description |
|---|---|---|
event.code | String | Error code |
Error Codes:
| Error Code | Description |
|---|---|
REPEAT_CAPTURE | Repeated capture |
GET_AUDIO_TRACK_FAILED | Audio capture failed; check available device or if occupied by other app |
STREAM_TYPE_NOT_MATCH | Stream type mismatch |
Status Monitoring Callbacks
onErrorMessage: Playback Exception
Description: Triggered when playback exception occurs. Signature:
onErrorMessage({ code })
Parameters:
| Parameter | Type | Description |
|---|---|---|
code | Number | Error type (0: RTC channel interrupted, 1: Error getting stats) |
onRunInformation: Runtime Information
Description: Callback for current runtime info, reported every 2 seconds. Signature:
onRunInformation(stats)
Parameters:
| Parameter | Type | Description |
|---|---|---|
stats | Object | Remote media stream stats |
stats.userId | String | User ID |
stats.audioStats | Object | Remote audio stats |
stats.videoStats | Object | Remote video stats |
audioStats Parameters:
| Parameter Name | Type | Description |
|---|---|---|
audioLossRate | Number | Audio packet loss rate [0, 1] |
receivedKBitrate | Number | Received bitrate (kbps) |
stallCount | Number|undefined | Stall count in period |
stallDuration | Number|undefined | Stall duration (ms) |
totalRtt | Number | End-to-end RTT (ms; may be inaccurate in Firefox) |
statsInterval | Number | Stats interval (ms) |
rtt | Number | RTT (ms) |
jitterBufferDelay | Number | Jitter delay (ms) |
numChannels | Number | Channel count |
receivedSampleRate | Number | Received sample rate |
concealedSamples | Number | Total concealed samples (PLC) |
concealmentEvent | Number | Total concealment events (PLC) |
videoStats Parameters:
| Parameter Name | Type | Description |
|---|---|---|
width | Number | Video width (px) |
height | Number | Video height (px) |
videoLossRate | Number | Video packet loss rate [0, 1] |
receivedKBitrate | Number | Received bitrate (kbps) |
decoderOutputFrameRate | Number | Decoder output frame rate (fps) |
stallCount | Number|undefined | Stall count in period |
stallDuration | Number|undefined | Stall duration (ms) |
totalRtt | Number | End-to-end RTT (ms; may be inaccurate in Firefox) |
isScreen | Boolean | Whether screen stream |
statsInterval | Number | Stats interval (ms) |
rtt | Number | RTT (ms) |
codecType | String | Video codec ("H264" or "VP8") |
onNetworkQuality: Network Quality
Description: Network quality callback, reported every 2 seconds after joining room. Signature:
onNetworkQuality(uplinkNetworkQuality, downlinkNetworkQuality)
Parameters:
| Parameter | Type | Description |
|---|---|---|
uplinkNetworkQuality | Number | Uplink quality |
downlinkNetworkQuality | Number | Downlink quality |
Quality Levels:
| Value | Description |
|---|---|
0 (UNKNOWN) | Unknown |
1 (EXCELLENT) | Excellent |
2 (GOOD) | Good (similar to EXCELLENT but possibly lower bitrate) |
3 (POOR) | Minor stalls, communication basically unaffected |
4 (BAD) | Not smooth; suggest reducing quality or audio-only mode |
5 (VBAD) | Very poor; suggest notifying user of weak network |
6 (DOWN) | Disconnected; unable to communicate |
onProgress: Loading Progress
Description: Loading progress callback. Signature:
onProgress({ code, msg })
Codes:
| Code | Description |
|---|---|
WS_CONNECT (100) | WS starting connection |
WS_SUCCESS (101) | WS connected |
WS_CLOSE (102) | WS closed |
WS_ERROR (103) | WS error |
OWN_JOIN_ROOM (200) | Received join room info |
RECEIVE_OFFER (201) | Set offer success |
RECEIVE_OFFER_ERR (202) | Set offer failed |
SEND_ANSWER (203) | Send answer |
SEND_ANSWER_ERR (204) | Send answer failed |
RECEIVE_ICE (205) | Add ICE success |
RECEIVE_ICE_ERR (206) | Add ICE failed |
SEND_ICE (207) | Send ICE |
RTC_CONNECTING (300) | RTC connecting |
RTC_CONNECTED (301) | RTC connected |
RTC_DISCONNECTED (302) | RTC disconnected |
RTC_CLOSE (303) | RTC closed |
RTC_FAILED (304) | RTC failed |
RTC_TRACK_VIDEO (305) | RTC received video track |
RTC_TRACK_VIDEO_LOAD (306) | RTC video track loaded |
RTC_CHANNEL_OPEN (307) | RTC message channel open |
RTC_CHANNEL_ERR (308) | RTC message channel error |
VIDEO_FIRST_FRAME (309) | Video loaded before UI info |
VIDEO_FIRST_FRAME (310) | Video first frame rendered |
User Interaction Callbacks
onUserLeaveOrJoin: User Join/Leave
Description: Triggered when user joins or leaves room. Signature:
onUserLeaveOrJoin({ type, userInfo })
Parameters:
| Parameter | Type | Description |
|---|---|---|
type | String | Event type (join: join, leave: leave) |
userInfo | Object | User info {userId, extraInfo} |
onUserLeave: User Leave
Description: Triggered when remote user leaves room. Signature:
onUserLeave(event)
Parameters:
| Parameter | Type | Description |
|---|---|---|
userId | String | Leaving user ID |
reason | Number | Leave reason |
Leave Reasons:
| Value | Description |
|---|---|
0 (QUIT) | Active quit (called leaveRoom) |
1 (DROPPED) | Dropped (e.g., token expired, network) |
2 (SWITCH_TO_INVISIBLE) | Switched to invisible |
3 (KICKED_BY_ADMIN) | Kicked by admin |
onUserJoined: User Join
Description: Triggered when remote user joins room. Signature:
onUserJoined({ userInfo })
Parameters:
| Parameter | Type | Description |
|---|---|---|
userInfo.userId | String | Joining user ID |
userInfo.extraInfo | String | Extra info |
onAutoRecoveryTime: Idle Timeout
Description: Triggered when idle time expires. Signature:
onAutoRecoveryTime()
onMonitorOperation: Operation Info
Description: Operation monitoring info when enabled. Signature:
onMonitorOperation(event)
Parameters:
| Parameter | Type | Description |
|---|---|---|
event.actionTime | number | Key press time |
event.actionType | number | Operation type (down/up) |
event.keyCode | number | Physical key code |
event.simulateHeight | number | Screen height |
event.simulateWidth | number | Screen width |
event.swipe | number | Swipe distance (-1: up, 1: down) |
event.touchType | string | Touch type |
event.x | number | Click X coordinate |
event.y | number | Click Y coordinate |
Feature Callbacks
onTransparentMsg: Passthrough Message
Description: Triggered when receiving passthrough message from cloud app. Signature:
onTransparentMsg(type, msg)
Parameters:
| Parameter | Type | Description |
|---|---|---|
type | String | Reserved (currently 0) |
msg | String | Message content (string) |
onOutputClipper: Content Copy
Description: Triggered when copying content on cloud phone. Signature:
onOutputClipper(data)
Parameters:
| Parameter | Type | Description |
|---|---|---|
data.content | String | Copied content |
onAdbOutput: ADB Command Result
Description: Result after executing ADB command. Signature:
onAdbOutput(event)
Parameters:
| Parameter | Type | Description |
|---|---|---|
isSuccess | Boolean | Success flag |
content | String | Result content on success |
onInjectVideoResult: Video Injection Result
Description: Result callback for starting/stopping video injection to camera. Signature:
onInjectVideoResult(type, data)
Parameters:
| Parameter | Type | Description |
|---|---|---|
type | String | Callback type (startVideoInjection or stopVideoInjection) |
data.isSuccess | Boolean | Operation success |
data.content | String | Failure reason |
onMediaDevicesToggle: Cloud Phone Media Device Toggle
Description: Callback when cloud phone opens/closes camera/microphone. Signature:
onMediaDevicesToggle(stats)
Parameters:
| Parameter | Type | Description |
|---|---|---|
stats.type | String | Type: media (both), camera, microphone |
stats.enabled | Boolean | Enabled flag |
stats.isFront | Boolean | Front camera (present for media and camera types) |
Error Handling Callbacks
onGroupControlError: Multi-Control Error
Description: Multi-control related error callback. Signature:
onGroupControlError({ code, msg })
Parameters:
| Parameter | Type | Description |
|---|---|---|
code | String | Error code |
msg | String | Error message |
Error Codes:
| Error Code | Description |
|---|---|
TOKEN_ERR | Token API failed |
INVALID_TOKEN | Invalid/expired token |
JOIN_ROOM_FAILED | Join room failed |
REPEAT_JOIN | Repeated join |
ROOM_FORBIDDEN | Room banned |
USER_FORBIDDEN | User banned |
onSendUserError: Command Send Error
Description: Exception when sending remote command. Signature:
onSendUserError(error)
Parameters:
| Parameter | Type | Description |
|---|---|---|
error.code | String | Error code |
Error Codes:
| Error Code | Description |
|---|---|
USER_MESSAGE_TIMEOUT | Message send timeout |
USER_MESSAGE_BROKEN | Channel broken, send failed |
USER_MESSAGE_NO_RECEIVER | No receiver found |
USER_MESSAGE_NOT_JOIN | Sender not joined |
USER_MESSAGE_UNKNOWN | Unknown error |