InitConfig

TCGSDK InitConfig related configuration.

Members

appid :number

Tencent cloud APPID, Optional

Type:
  • number

mount :string

Cloud rendering mount point(HTML element ID).

Type:
  • string

mic :boolean|MicProfileConstraints

Default Value:
  • false

Whether to enable mic

Type:
  • boolean | MicProfileConstraints

camera :boolean|CameraProfileConstraints|CameraProfileType

Default Value:
  • false

Whether to enable camera

Type:

tabletMode :boolean

Default Value:
  • false

Enables/Disables the cursor sliding mode. This API is generally used in scenarios where there is an offset between the displayed cursor and the actual touch point.

Can not use it on PC

Type:
  • boolean

mobileGame :boolean

Default Value:
  • false

Mobile Game

Type:
  • boolean

mobileVpx :boolean

Default Value:
  • false

Whether to enable VPX encoding

Type:
  • boolean

cursorMode :number

Default Value:
  • 0

Cursor mode valid values:

mode=0: Fixed cursor image rendered on the page, if the default mouse image is not set, the system mouse will be used.

mode=1: Cursor image delivered from the cloud and rendered by the browser page

mode=2: (Not recommended) Cursor image rendered on the cloud page. In this case, the locally rendered cursor will be hidden. This mode has the best compatibility but causes a delay in cursor movement.

Type:
  • number

clickToFullscreen :boolean

Default Value:
  • false

Whether to enable click any point to fullscreen.

Type:
  • boolean

clickBodyToPlay :boolean

Default Value:
  • true

Whether to enable click any point to play video.

Type:
  • boolean

idleThreshold :number

Default Value:
  • 300

User no action threshold, in seconds. Default value 300s, it will callback on onEvent with message {type: 'idle', data: {times: 1}}

Instance can be released in the callback by calling TCGSDK.destroy()

Type:
  • number

keepLastFrame :boolean

Default Value:
  • false

Keep last frame image when destroy. Mac safari/ios webview does not work.

Type:
  • boolean

reconnect :boolean

Default Value:
  • true

Whether to enable auto reconnect. It will happen when FPS is 0 for 10s or first connect failed.

Rule: Attempts every 6 seconds, maximum 10 times

Type:
  • boolean

showLoading :boolean

Default Value:
  • true

Whether to show loading.

Type:
  • boolean

loadingText :string

Default Value:
  • '正在启动云渲染'

Loading text

Type:
  • string

restartText :string

Default Value:
  • '重新连接'

Restart button text

Type:
  • string

autoRotateContainer :boolean

Default Value:
  • false

Whether to rotate the entire HTML view. Default value: `false.

Type:
  • boolean

autoRotateMountPoint :boolean

Default Value:
  • false

Whether to rotate the mountPoint node. Default value: false.

Type:
  • boolean

fullVideoToScreen :boolean

Default Value:
  • true

When mount point size(width/height) bigger than cloud stream.

true Stretch video size and fit on short edge.

false Do not stretch the video, keep the original cloud resolution.

Type:
  • boolean

debugSetting :DebugSettingParams

Enables/Disables the debugging mode. If it is enabled, logs will be printed in the console.

Type:

webDraftLevel :number

Default Value:
  • 0

0: Turn off mouse high frequency sampling

1: Open mouse high frequency sampling

2: Open mouse high frequency sampling and send as package

3: Limit the length of the packet, and lose more

Type:
  • number

forceShowCursor :boolean

Default Value:
  • false

Force display of mouse

Type:
  • boolean

bgImgUrl :string

Sets background image for web container, not cloud desktop background image.

Type:
  • string

defaultCursorImgUrl :string

Default Value:
  • null

Default does not show cursor.

Default cursor image(https/http url)

Pass 'dot' to show a 3px blue dot in mobile.

Type:
  • string

clientInteractMode :'cursor'|'touch'

Default Value:
  • 'cursor'

CLoud client interaction mode, support mouse or touch

Type:
  • 'cursor' | 'touch'

enablePaste :boolean

Default Value:
  • true

Whether to hijack Ctrl/Cmd + V. When a user uses the paste feature, the content in the local clipboard will be sent to the cloud directly.

This method is usually used when the cloud input box is focused.

Type:
  • boolean

enableMousemoveV2 :boolean

Default Value:
  • true

Whether to enable cloud computing mouse

Could be smoother

Type:
  • boolean

remoteDesktopResolution :object

Default Value:
  • null
Properties:
Name Type Description
width number
height number

Initialize Cloud Desktop Resolution

You can use TCGSDK.getPageSize() to get the width and height of the page to adapt resolution (for mobile, you can set the width2 and height2 to ensure a clear resolution).

Type:
  • object

enableEventIntercept :boolean

Default Value:
  • true

Whether to enable event interception

Intercept events such as mouse/keyboard. Send commands to the cloud only for cloud rendering nodes.

Type:
  • boolean

Methods

onInitSuccess(response) → {function}

Init success callback

CreateSession in this callback.

Parameters:
Name Type Description
response Object

OnInitSuccess response

Properties
Name Type Description
code number

code=-2 The peerConnection is not disconnected, you need to call TCGSDK.destroy() first. code=-1 LocalOffer can noe get H264 encoding. code=0 Success.

msg string
description any
Returns:
Type
function

onConnectSuccess(response) → {function}

Connect success callback, it will trigger after call TCGSDK.start().

We recommend use other API after this callback. Like follow methods:

  1. createCustomDataChannel
  2. Use plugin, lick new joystick().
  3. setRemoteDesktopResolution
Parameters:
Name Type Description
response Object

onConnectSuccess response

Properties
Name Type Description
code number

code=0 Success

seat_index number

multi player scene

role string

multi player scene

Returns:
Type
function

onConnectFail(response) → {function}

Connect failed callback.

Reconnection take longer than two minutes (e.g. connection disconnected/mobile switch to background, reconnection triggered after two minutes) CAR backend will automatically destroy the instance and return code > 0. It is recommended to init + createSession again in this case.

Parameters:
Name Type Description
response Object

onConnectFail response

Properties
Name Type Description
code number

code as follows:

code Description
-3 Retries exceeded, needs to init and createSession
-2 Auto reconnecting
-1 Connect failed, try again alter
code > 0 Proxy error, connect failed, needs to init and createSession
msg string

message

Returns:
Type
function

onWebrtcStatusChange(response) → {function}

Webrtc status callback, it will trigger after call TCGSDK.start().

Parameters:
Name Type Description
response Object

onWebrtcStatusChange response

Properties
Name Type Description
code number

code as follows:

code Description
-2 Failed to get H264 encoding
-1 Failed to setRemoteDescription
1 System busy
2 Token illegal
3 Insufficient user bandwidth
4 Insufficient resources, no resource available
5 Session failed, need to retry
6 Incorrect media description information
7 Launch game failed
100 Proxy error
255 Device does not support webrtc
msg string

message

Returns:
Type
function

onDisconnect(response) → {function}

User disconnect or disconnect from server, it will trigger after call TCGSDK.start().

if sets init param reconnect: true, this callback will also be trigger, You can judge whether the page needs to be refreshed according to the corresponding code.

Parameters:
Name Type Description
response Object

onDisconnect response

Properties
Name Type Description
code number

code as follows:

code Description
-2 -2 Create offer failed, need to init and createSession
-1 Need to reconnect, when fps is 0 for 10s, can not receive stream, connection timeout or ice disconnected.
0 Server close
1 User repeated connection
2 The user's heartbeat times out, the webrtc server actively disconnects, and this message may be lost
msg string

message

Returns:
Type
function

onNetworkChange(response) → {function}

Network status change callback

Parameters:
Name Type Description
response Object

onNetworkChange response

Properties
Name Type Description
status 'idle' | 'noflow' | 'noflowcenter' | 'stats' | 'jitter' | 'openurl' | 'latency'
times number
stats WebrtcStats
data Object
Properties
Name Type Description
code number
value number | string
message string
begin number
finish number
Returns:
Type
function

onTouchEvent(response) → {function}

Touch event callback, it will trigger after call TCGSDK.start().

Response is OnTouchEventResponse[], Corresponds to the number of touch points on the current screen, multi-finger operation can be judged according to the length of the array.

Example
onTouchEvent: async (res) => {
  // console.log('onTouchEvent', res);
  // Single finger
  if (res.length === 1) {
    const [{ id, type, pageX, pageY }] = res;
    // console.log('onTouchEvent', id, type, pageX, pageY);
    TCGSDK.mouseMove(id, type, pageX, pageY);
    if (type === 'touchstart') {
      TCGSDK.sendMouseEvent({ type: 'mouseleft', down: true });
    }
    if (type === 'touchend' || type === 'touchcancel') {
      TCGSDK.sendMouseEvent({ type: 'mouseleft', down: false });
    }
  }
  // Multi-finger, simulate the mouse wheel event of the PC
  if (res.length === 2) {
    const [{ pageX: oneX, pageY: oneY, type: oneType }, { pageX: twoX, pageY: twoY, type: twoType }] = res;

    const currentX = Math.ceil(Math.abs(oneX - twoX));
    const currentY = Math.ceil(Math.abs(oneY - twoY));
    // lastX, lastY, can be defined globally, like: let lastX = null, lastY = null
    lastX || (lastX = currentX);
    lastY || (lastY = currentY);

    if (lastX && currentX - lastX < 0 && lastY && currentY - lastY < 0) {
      TCGSDK.sendMouseEvent({ type: 'mousescroll', delta: 1 });
      lastX = currentX;
      lastY = currentY;
    }

    if (lastX && currentX - lastX > 0 && lastY && currentY - lastY > 0) {
      TCGSDK.sendMouseEvent({ type: 'mousescroll', delta: -1 });
      lastX = currentX;
      lastY = currentY;
    }

    // Sends a mouse up action after two fingers are touchend or touchcancel
    if (
      oneType === 'touchend' ||
      oneType === 'touchcancel' ||
      twoType === 'touchend' ||
      twoType === 'touchcancel'
    ) {
      TCGSDK.sendMouseEvent({ type: 'mouseleft', down: false });
    }
  }
}
Parameters:
Name Type Description
response Array.<Object>

onTouchEvent response

Properties
Name Type Description
id number

ID

type TouchType

Touch Type valid values: touchstart, touchmove, touchend, touchcancel.

x number

The X coordinate of the video view

y number

The Y coordinate of the video view

pageX number

The X coordinate of the page

pageY number

The Y coordinate of the page

movementX number

The delta movement of X coordinate

movementY number

The delta movement of Y coordinate

Returns:
Type
function

onDoubleTap() → {function}

Only for mobile, double tao callback(same as onTouchEvent)

Returns:
Type
function

onGameStartComplete(response) → {function}

Game start success callback

Parameters:
Name Type Description
response Object

onGameStartComplete response

Properties
Name Type Description
request_id string
user_id string

user_id

game_id string

game_id

status number

0 success; 1 failed

Returns:
Type
function

onGameStop(response) → {function}

Game stop callback

Parameters:
Name Type Description
response Object

onGameStop response

Properties
Name Type Description
user_id string

user_id

game_name string

game_name

timestamp number

timestamp

message string

message

Returns:
Type
function

onLoadGameArchive(response) → {function}

Game archive loading callback, will continue to call back size

Parameters:
Name Type Description
response Object

onLoadGameArchive response

Properties
Name Type Description
user_id string

user_id

game_id string

game_id

name string

Archive filename

url string

Archive download url

status number

0: load success 1: load failed 2: verify failed 3: unzip failed 4: other errors 5: downloading

save_type 'Auto' | 'Normal'

'Auto' or 'Normal'

category_id string
archive_size number

archive_size

loaded_size number
Returns:
Type
function

onSaveGameArchive(response) → {function}

游戏保存存档回调

Parameters:
Name Type Description
response Object

onLoadGameArchive response

Properties
Name Type Description
user_id string

user_id

game_id string

game_id

name string

Archive filename

md5 string

md5

status number

0: success 1: failed 2: zip failed 3: other errors 4: uploading

save_type 'Auto' | 'Normal'

'Auto' or 'Normal'

category_id string
archive_size number

archive_size

saved_size number
Returns:
Type
function

onInputStatusChange(response) → {function}

When the cloud input state changes, it will be triggered, You can judge whether the input box is focused.

This callback might be called twice, once when the mouseleft clicks down, and once when the mouseleft clicks up.

Parameters:
Name Type Description
response Object

onInputStatusChange response

Properties
Name Type Description
field_type 'normal_input' | 'unfocused'

unfocused, normal_input

status 'disabled' | 'enabled'
Returns:
Type
function

onGamepadConnectChange(response) → {function}

Gamepad connection status callback

Parameters:
Name Type Description
response Object

onGamepadConnectChange response

Properties
Name Type Description
status 'gamepadconnect' | 'gamepaddisconnect'

status

index number
gamepad Gamepad

Gamepad API interface

Returns:
Type
function

onCursorShowStatChange(response) → {function}

Cursor show/hide, only trigger when status changed.

Parameters:
Name Type Description
response Object

onCursorShowStatChange response

Properties
Name Type Description
oldStatus boolean
newStatus boolean
Returns:
Type
function

onOrientationChange(response) → {function}

Orientation change callback.

Parameters:
Name Type Description
response Object

onOrientationChange response

Properties
Name Type Description
type 'portrait' | 'landscape'

current screen status

Returns:
Type
function

onVisibilityChange(response) → {function}

Page visibility changes.

Parameters:
Name Type Description
response Object

onVisibilityChange response

Properties
Name Type Description
status 'visible' | 'hidden'
Returns:
Type
function

onConfigurationChange(response) → {function}

Cloud config changed, only trigger when status changed.

Parameters:
Name Type Description
response Object

onConfigurationChange response

Properties
Name Type Description
width number
height number
orientation 'landscape' | 'portrait'

orientation

Returns:
Type
function

onRemoteScreenResolutionChange(response) → {function}

Cloud screen resolution changed.

Parameters:
Name Type Description
response Object

onRemoteScreenResolutionChange response

Properties
Name Type Description
width number
height number
top number
left number
Returns:
Type
function

onVideoStreamConfigChange(response) → {function}

Video stream resolution changed.

The difference between onRemoteScreenResolutionChange and onRemoteScreenResolutionChange is that the former is the resolution of the cloud screen/application, and the latter is the resolution of the stream decoded.

There may be a case where the screen/application resolution is set to 1280720, but the resolution of the push stream is 19201080.

Parameters:
Name Type Description
response Object

onVideoStreamConfigChange response

Properties
Name Type Description
width number
height number
Returns:
Type
function

onDeviceChange() → {function}

Connected devices have changed and can be get by navigator.mediaDevices.enumerateDevices().

Returns:
Type
function

onGetUserMediaStatusChange(response) → {function}

User media callback

Parameters:
Name Type Description
response Object

onGetUserMediaStatusChange response

Properties
Name Type Description
code number

0 Success; 1 NotFoundError; 2 NotAllowedError; 3 OverconstrainedError

msg string

'NotFoundError' | 'NotAllowedError' | string;

userMedia MediaStream

userMedia

Returns:
Type
function

onEvent(response) → {function}

Event callback

It is mainly used to callback whether the autoplay is successful or not.

Parameters:
Name Type Description
response Object

onEvent response

Properties
Name Type Attributes Description
type string

Event types: 'autoplay'| 'video_state' | 'idle' | 'noflow' | 'noflowcenter' | 'openurl' | 'pointerlockerror' | 'readclipboarderror' | 'webrtc_stats' | 'latency'

data Object <optional>

The data may be different for different types, refer to the following table

type data
autoplay Object<{code: number; message: string;}>
code0 success -1 failed
messagestring
video_state Object<{code: number; message: string;}>
code0 playing 1 pause 2 ended
messagestring
idle Object<{times: number;}>
timesnumber
noflow -
noflowcenter -
openurl Object<{value: string;}>
valuestring
pointerlockerror -
readclipboarderror Object<{message?: string;}>
messagestring
webrtc_stats Object<>
bit_ratenumberBit rate received by the client, unit: Mbps
cpunumberCloud CPU usage
gpustringCloud GPU usage
delaynumber
fpsnumber
load_cost_timenumberunit: ms
nacknumber
packet_lostnumber
packet_receivednumber
rttnumberunit: ms
timestampnumberunit: ms
latency Object<{value: number; message: string;}>
valuevalue=0 NETWORK_NORMAL
value=1 NETWORK_CONGESTION
value=2 NACK_RISING
value=3 HIGH_DELAY
value=4 NETWORK_JITTER
messagestring
ice_state Object<{value: string;}>
valueconnected / disconnected
Returns:
Type
function

onStreamPushStateChange(response) → {function}

Parameters:
Name Type Description
response Object

onStreamPushStateChange response

Properties
Name Type Description
stream_push_state string

Push state 'NoStreamPushing' | 'PushConnecting' | 'Pushing' | 'PushPaused' | 'PushReConnecting';

Returns:
Type
function

onMultiPlayerChange(response) → {function}

Multi-player cloud game

Parameters:
Name Type Description
response Object

onMultiPlayerChange response

Properties
Name Type Description
user_state Object
Properties
Name Type Description
state 'offline' | 'online'

user state

user_id string
seats_info Object
Properties
Name Type Description
players Array.<Object>
Properties
Name Type Description
name string
seat_index number
mic_status number

0 host forbid mic 1 close mic(self) 2 open mic

viewers Array.<Object>
Properties
Name Type Description
name string
seat_index number
mic_status number

0 host forbid mic 1 close mic(self) 2 open mic

submit_seat_change Object

Only host can receive this message

Properties
Name Type Description
user_id string
to_role 'viewer' | 'player'
seat_index number

to seta index

Returns:
Type
function

onLog(response) → {function}

Log callback, same as setLogHandler

Parameters:
Name Type Description
response string
Returns:
Type
function