-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex_en.d.ts
2063 lines (2005 loc) · 72.7 KB
/
index_en.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
interface BaseResponse {
readonly code: number;
readonly msg?: string;
}
export interface OnInitSuccessResponse {
readonly code: number;
readonly msg?: string;
readonly description?: any;
}
/**
*
* Usually the reconnection time exceeds two minutes (for example, disconnected or the in mobile switches to the background, and the reconnection is triggered after two minutes)
* The system will automatically recycle the instance, and it will return code > 0, needs to init and createSession
*
* code=-3 Retries exceeded, needs to init and createSession
* code=-2 Auto reconnecting
* code=-1 Connect failed, try again alter
* code>0 Proxy error, connect failed, needs to init and createSession
* @ignore
*/
export interface OnConnectFailedResponse extends BaseResponse {}
export interface OnConnectSuccessResponse {
readonly code: number;
readonly seat_index: number; // seats index,multi player scene
readonly role: string; // role,multi player scene
}
/**
* code=-2 Failed to get H264 encoding
* code=-1 Failed to setRemoteDescription
* code=1 System busy
* code=2 Token illegal
* code=3 Insufficient user bandwidth
* code=4 Insufficient resources, no resource available
* code=5 Session failed, need to retry
* code=6 Incorrect media description information
* code=7 Launch game failed
* code=100 Proxy error
* code=255 Device does not support webrtc
* @ignore
*/
export interface OnWebrtcStatusChangeResponse extends BaseResponse {}
/**
* code=-2 Create offer failed, need to init and createSession
* code=-1 Need to reconnect, when fps is 0 for 10s, can not receive stream, connection timeout or ice disconnected. If you passed init param `reconnect: true`, SDK will reconnect automatically, or you can reconnect manually.
* code=0 Server close
* code=1 User repeated connection
* code=2 The user's heartbeat times out, the webrtc server actively disconnects, and this message may be lost
* @ignore
*/
export interface OnDisconnectResponse extends BaseResponse {}
export interface WebrtcStats {
readonly bit_rate?: number; // Bit rate received by the client, unit: Mbps
readonly cpu?: number | string; // Cloud CPU usage
readonly gpu?: string; // Cloud GPU usage
readonly delay?: number; // The delay from the client receiving the image frame to the decoding display, unit: ms, iOS may not receive
readonly fps?: number; // FPS
readonly load_cost_time?: number; // unit: Mbps
readonly nack?: number;
readonly packet_lost?: number;
readonly packet_received?: number;
readonly rtt?: number;
readonly timestamp?: number;
}
/**
* latency values
* value=0 NETWORK_NORMAL
* value=1 NETWORK_CONGESTION
* value=2 NACK_RISING
* value=3 HIGH_DELAY
* value=4 NETWORK_JITTER
* @ignore
*/
export interface OnNetworkChangeResponse {
readonly status: 'idle' | 'noflow' | 'noflowcenter' | 'stats' | 'jitter' | 'openurl' | 'latency';
readonly times?: number;
readonly stats?: WebrtcStats;
readonly data?: {
code?: number;
value?: number | string;
message?: string;
begin?: number;
finish?: number;
};
}
/**
* Touch Type valid values: `touchstart`, `touchmove`, `touchend`, `touchcancel`.
*/
export type TouchType = 'touchstart' | 'touchmove' | 'touchend' | 'touchcancel' | string;
/**
* onTouchEvent response OnTouchEventResponse[]
* @ignore
*/
export interface OnTouchEventResponse {
/**
* identifier
*/
readonly id: number;
/**
* Touch Type valid values: `touchstart`, `touchmove`, `touchend`, `touchcancel`.
*/
readonly type: TouchType;
/**
* The X coordinate of the video view
*/
readonly x: number;
/**
* The Y coordinate of the video view
*/
readonly y: number;
/**
* The X coordinate of the page
*/
readonly pageX: number;
/**
* The Y coordinate of the page
*/
readonly pageY: number;
/**
* The delta movement of X coordinate
*/
readonly movementX: number;
/**
* The delta movement of Y coordinate
*/
readonly movementY: number;
}
export interface OnGameStartCompleteResponse {
readonly request_id: string;
readonly app_id: number;
readonly user_id: string;
readonly game_id: string;
readonly status: number; // 0 success 1 failed
}
export interface OnGameStopResponse {
readonly user_id: string;
readonly game_name: string;
readonly timestamp: number;
readonly message: string;
}
export interface OnLoadGameArchiveResponse {
readonly user_id: string;
readonly game_id: string;
readonly name: string; // Archive filename
readonly url: string; // Archive download url
readonly status: number; // 0: load success 1: load failed 2: verify failed 3: unzip failed 4: other errors 5: downloading
readonly save_type: 'Auto' | 'Normal';
readonly category_id: string;
readonly archive_size: number;
readonly loaded_size: number;
}
export interface OnSaveGameArchiveResponse {
readonly user_id: string;
readonly game_id: string;
readonly name: string; // Archive filename
readonly md5: string;
readonly status: number; // 0: success 1: failed 2: zip failed 3: other errors 4: uploading
readonly save_type: 'Auto' | 'Normal';
readonly category_id: string;
readonly archive_size: number;
readonly saved_size: number;
}
export interface ServerSideDescriptionGameConfig {
readonly sdk_conf: {
login_helper?: any;
virtual_keys?: any;
user_keys?: any;
cursor_mode?: number;
webdraft_level?: number;
connect_timeout?: number;
noflow_timeout?: number;
cursor_scale?: number;
cursor_style?: 'standard' | 'default_huge';
bgimg_url?: string;
default_cursor_url?: string;
lock_by_mouseright?: boolean;
keep_lastframe?: boolean;
tablet_mode?: boolean;
mobile_show_cursor?: boolean;
enable_event_intercept?: boolean;
};
readonly GameEncodePreset?: any;
readonly GameRunningInfo?: any;
}
export interface ServerSideDescriptionFeatureSwitch {
network_event_script?: {
loss_rate_threshold?: number;
nack_rate_threshold?: number;
rtt_avg_threshold?: number;
rtt_dev_threshold?: number;
notify_threshold?: number;
};
}
export interface ServerSideDescription {
readonly app_id: number;
readonly game_id: string;
readonly group_id: string;
/**
* code=-2 Failed to get H264 encoding
* code=-1 Failed to setRemoteDescription
* code=0 Success
* code=1 System busy
* code=2 Token illegal
* code=6 SDP error
* code=8 Waiting for host to connect
* code=9 The role has reached the limit
* code=100 Proxy error
*/
readonly code: number;
readonly msg?: string;
readonly message: string;
readonly type: string;
readonly sdp: string;
readonly server_ip: string;
readonly server_version: string;
readonly server_port?: string;
readonly region: string;
readonly instance_type?: string; // L1 S1 M1
readonly request_id: string;
readonly user_id: string;
readonly user_ip: string;
readonly input_seat: number;
readonly game_config?: ServerSideDescriptionGameConfig;
readonly feature_switch?: ServerSideDescriptionFeatureSwitch;
readonly role: string;
readonly metric_key: string;
readonly plat: 'android' | 'pc' | 'Android';
readonly sig_key?: string;
readonly host_name: string; // Only in mobile game
readonly video: {
height: number;
width: number;
};
readonly video_codec: string;
readonly screen_config?: {
width: number;
height: number;
orientation: 'landscape' | 'portrait';
};
/**
* The webrtc structure returned by Proxy
*/
readonly WebrtcResponse?: {
Code: number;
Msg: string;
Sdp: string;
};
}
/**
* When the cloud input state changes, it will be triggered, You can judge whether the input box is focused.
* @ignore
*/
export interface OnInputStatusChangeResponse {
readonly field_type: 'normal_input' | 'unfocused';
readonly status: 'disabled' | 'enabled';
}
/**
* Gamepad connection status
* @ignore
*/
export interface OnGamepadConnectChangeResponse {
readonly status: 'gamepadconnect' | 'gamepaddisconnect';
readonly index: number;
readonly gamepad?: Gamepad;
}
/**
* Cursor show/hide, only trigger when status changed.
* @ignore
*/
export interface OnCursorShowStatChangeResponse {
readonly oldStatus: boolean;
readonly newStatus: boolean;
}
/**
* Cloud config changed, only trigger when status changed.
* @ignore
*/
export interface OnConfigurationChangeResponse {
readonly screen_config: {
width: number;
height: number;
orientation: 'landscape' | 'portrait';
};
}
/**
* Cloud screen resolution changed.
* @ignore
*/
export interface OnRemoteScreenResolutionChangeResponse {
width: number;
height: number;
top: number;
left: number;
}
export interface SeatsInfo {
players: {
name: string;
seat_index: number;
/**
* 0 host forbid mic
* 1 close mic(self)
* 2 open mic
*/
mic_status: number;
}[];
viewers: {
name: string;
seat_index: number;
/**
* 0 host forbid mic
* 1 close mic(self)
* 2 open mic
*/
mic_status: number;
}[];
}
export interface SeatChangeInfo {
user_id: string;
to_role?: 'viewer' | 'player';
seat_index?: number;
}
export interface ChangeMicStatusResponse {
type?: string; // mic_status
/**
* 0: Success
* -2: NoAuthorized
* -4: NoSuchUser
*/
code: number;
/**
* 0 host forbid mic
* 1 close mic(self)
* 2 open mic
*/
status?: number;
user_id?: string;
}
export interface OnMultiPlayerChangeResponse {
readonly user_state?: {
state: 'offline' | 'online';
user_id: string;
};
readonly seats_info?: SeatsInfo;
/**
* Only host can receive this message.
*/
readonly submit_seat_change?: SeatChangeInfo;
}
export type EventAutoPlayResponse = {
readonly type: 'autoplay';
readonly data: {
code: number; // 0 success -1 failed
message: string;
};
};
export type EventIdleResponse = {
readonly type: 'idle';
readonly data: {
times: number;
};
};
export type OnEventResponseType = 'autoplay' | 'idle';
export type OnEventAutoplayResponse = {
type: 'autoplay';
data: {
code: number; // 0 success -1 failed
message: string;
};
};
export type OnEventVideoPlayStateResponse = {
type: 'video_state';
data: {
code: number; // 0 playing 1 pause 2 ended
message: string;
};
};
export type OnEventIdleResponse = {
type: 'idle';
data: {
times: number;
};
};
export type OnEventOpenUrlResponse = {
type: 'openurl';
data: {
value: string;
};
};
export type OnEventWebrtcStatsResponse = {
type: 'webrtc_stats';
data: WebrtcStats;
};
export type OnEventNoflowResponse = {
type: 'noflow';
data?: {};
};
export type OnEventNoflowcenterResponse = {
type: 'noflowcenter';
data?: {};
};
export type OnEventLatencyResponse = {
type: 'latency';
data: {
value: number;
/**
* latency values
* value=0 NETWORK_NORMAL
* value=1 NETWORK_CONGESTION
* value=2 NACK_RISING
* value=3 HIGH_DELAY
* value=4 NETWORK_JITTER
*/
message: string;
};
};
/**
* Usually the http protocol will fail to read clipboard
*/
export type OnEventReadClipboardErrorResponse = {
type: 'readclipboarderror';
data?: {
message?: any;
};
};
export type OnEventPointerLockErrorResponse = {
type: 'pointerlockerror';
data?: {};
};
export type OnEventIceConnectionStateChangeResponse = {
type: 'ice_state';
data?: {
value?: 'connected' | 'disconnected';
};
};
export type OnEventResponse =
| OnEventAutoplayResponse
| OnEventVideoPlayStateResponse
| OnEventIdleResponse
| OnEventOpenUrlResponse
| OnEventWebrtcStatsResponse
| OnEventNoflowResponse
| OnEventNoflowcenterResponse
| OnEventLatencyResponse
| OnEventReadClipboardErrorResponse
| OnEventPointerLockErrorResponse
| OnEventIceConnectionStateChangeResponse;
/**
* Push stream
*/
export type StreamPushState = 'NoStreamPushing' | 'PushConnecting' | 'Pushing' | 'PushPaused' | 'PushReConnecting';
export type OnStreamPushStateChangeResponse = {
stream_push_state: StreamPushState;
};
/**
* Debug settings
*/
export type DebugSettingParams = {
/**
* Whether to print the messages input by the keyboard/mouse.
*/
showSendKmData?: boolean;
/**
* Whether to print the sent ACK messages.
*/
showSendAckData?: boolean;
/**
* Whether to print the sent heartbeat messages.
*/
showSendHbData?: boolean;
/**
* Whether to print the heartbeat response packet messages.
*/
showOnHbMessage?: boolean;
/**
* Whether to print the keyboard/mouse response messages.
*/
showOnKmMessage?: boolean;
/**
* Whether to print the ACK response packet messages.
*/
showOnAckMessage?: boolean;
/**
* Whether to print the CD response packet messages.
*/
showOnCdMessage?: boolean;
/**
* Whether to print the server response packet messages.
*/
showOnSvMessage?: boolean;
/**
* Whether to print all logs of the SDK.
*/
showLog?: boolean;
/**
* Whether to display the WebRTC status on the data panel. You can also press CTRL + ~ to display it.
*/
showStats?: boolean;
};
/**
* Mouse events on PC
*/
export type MouseEvent =
| 'mouseleft'
| 'mouseright'
| 'mousemiddle'
| 'mouseforward'
| 'mousebackward'
| 'mousescroll'
| 'mousemove'
| 'mousemove_v2'
| 'mousedeltamove'
| 'mousedeltamove_v2'
| 'mousehorizontalscroll';
/**
* Gamepad events
*/
export type GamePadEvent =
| 'gamepadconnect'
| 'gamepaddisconnect'
| 'gamepadkey'
| 'axisleft'
| 'axisright'
| 'lt'
| 'rt';
export type KeyBoardEvent = 'keyboard';
/**
* KM DataChannel data types
*/
type KMMessageType = MouseEvent | GamePadEvent | KeyBoardEvent;
/**
* The underlying raw data type, which can be used to send mouse, keyboard, and joystick messages.
*/
type RawEventData = {
type: KMMessageType;
x?: number;
y?: number;
down?: boolean;
delta?: number;
key?: number;
};
/**
* Microphone parameters, specific values can be set according to requirements.
* @ignore
*/
export interface MicProfileConstraints extends MediaTrackConstraints {
sampleRate?: number; // default 44100
echoCancellation?: ConstrainBoolean; // default true
noiseSuppression?: ConstrainBoolean; // default true
autoGainControl?: ConstrainBoolean; // default true
deviceId?: string; // You can through getDevices interface to get deviceID. The default deviceId depends on system default value.
}
/**
* Camera parameters, specific values can be set according to requirements.
* @ignore
*/
export interface CameraProfileConstraints {
/**
* default 1280, pass null to use the default value
*/
width?: number | null;
/**
* default 720, pass null to use the default value
*/
height?: number | null;
frameRate?: number;
/**
* @deprecated
*/
bitrate?: number;
/**
* You can through getDevices interface to get deviceID. The default deviceId depends on system default value.
*
* Mobile can pass 'user' | 'environment', to use front/rear camera.
*/
deviceId?: string | 'user' | 'environment';
}
/**
* Camera resolution type for quick setup
*/
export type CameraProfileType = '120p' | '180p' | '240p' | '360p' | '480p' | '720p' | '1080p';
/**
* TCGSDK InitConfig related configuration.
*/
export interface InitConfig {
/**
* Tencent cloud APPID, Optional
*/
appid?: number;
/**
* Cloud rendering mount point(HTML element ID).
*/
mount: string;
/**
* Whether to enable mic
*
* @default false
*/
mic?: boolean | MicProfileConstraints;
/**
* Whether to enable camera
*
* @default false
*/
camera?: boolean | CameraProfileConstraints | CameraProfileType;
/**
* 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
*
* @default false
*/
tabletMode?: boolean;
/**
* Mobile Game
*
* @default false
*/
mobileGame?: boolean;
/**
* Whether to enable VPX encoding
*
* @default false
*/
mobileVpx?: boolean;
/**
* 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.
*
*
* @default 0
*/
cursorMode?: number;
/**
* Whether to enable click any point to fullscreen.
*
* @default false
*/
clickToFullscreen?: boolean;
/**
* Whether to enable click any point to play video.
*
* @default true
*/
clickBodyToPlay?: boolean;
/**
* 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()**
*
* @default 300
*/
idleThreshold?: number;
/**
* Keep last frame image when destroy. Mac safari/ios webview does not work.
*
* @default false
*/
keepLastFrame?: boolean;
/**
* 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
*
* @default true
*/
reconnect?: boolean;
/**
* Whether to show loading.
*
* @default true
*/
showLoading?: boolean;
/**
* Loading text
*
* @default '正在启动云渲染'
*/
loadingText?: string;
/**
* Restart button text
*
* @default '重新连接'
*/
restartText?: string;
/**
* Whether to rotate the entire HTML view. Default value: `false.
*
* @default false
*/
autoRotateContainer?: boolean;
/**
* Whether to rotate the `mountPoint` node. Default value: `false`.
*
* @default false
*/
autoRotateMountPoint?: boolean;
/**
* 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.
*
* @default true
*/
fullVideoToScreen?: boolean;
/**
* Enables/Disables the debugging mode. If it is enabled, logs will be printed in the console.
*/
debugSetting?: DebugSettingParams;
/**
* 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
*
* @default 0
*/
webDraftLevel?: number;
/**
* Force display of mouse
*
* @default false
*/
forceShowCursor?: boolean;
/**
* Sets background image for web container, not cloud desktop background image.
*/
bgImgUrl?: string;
/**
* Default does not show cursor.
*
* Default cursor image(https/http url)
*
* Pass 'dot' to show a 3px blue dot in mobile.
*
* @default null
*/
defaultCursorImgUrl?: string;
/**
* CLoud client interaction mode, support mouse or touch
*
* @default 'cursor'
*/
clientInteractMode?: 'cursor' | 'touch';
/**
* 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.**
*
* @default true
*/
enablePaste?: boolean;
/**
* Whether to enable cloud computing mouse
*
* Could be smoother
*
* @default true
*/
enableMousemoveV2?: boolean;
/**
* 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 width*2 and height*2 to ensure a clear resolution).**
*
* @default null
*/
remoteDesktopResolution?: {
width: number;
height: number;
};
/**
* Whether to enable event interception
*
* Intercept events such as mouse/keyboard. Send commands to the cloud only for cloud rendering nodes.
*
* @default true
*/
enableEventIntercept?: boolean;
/**
*
* Init success callback
*
* CreateSession in this callback.
*
* @function
* @param {Object} response - OnInitSuccess response
* @param {number} response.code 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.
* @param {string} response.msg
* @param {any} response.description
*
*/
onInitSuccess?: (response: OnInitSuccessResponse) => void;
/**
* 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`
*
* @function
* @param {Object} response - onConnectSuccess response
* @param {number} response.code code=0 Success
* @param {number} response.seat_index - multi player scene
* @param {string} response.role -multi player scene
*
*/
onConnectSuccess?: (response: OnConnectSuccessResponse) => void;
/**
* 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.
*
*
* @function
* @param {Object} response - onConnectFail response
* @param {number} response.code
*
* 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 |
* @param {string} response.msg - message
*
*/
onConnectFail?: (response: OnConnectFailedResponse) => void;
/**
* Webrtc status callback, it will trigger after call `TCGSDK.start()`.
*
* @function
* @param {Object} response - onWebrtcStatusChange response
* @param {number} response.code
*
* 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 |
* @param {string} response.msg - message
*/
onWebrtcStatusChange?: (response: OnWebrtcStatusChangeResponse) => void;
/**
* 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.
*
* @function
* @param {Object} response - onDisconnect response
* @param {number} response.code
*
* 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 |
* @param {string} response.msg - message
*/
onDisconnect?: (response: OnDisconnectResponse) => void;
/**
* Network status change callback
*
* @function
* @param {Object} response - onNetworkChange response
* @param {('idle'|'noflow'|'noflowcenter'|'stats'|'jitter'|'openurl'|'latency')} response.status
* @param {number} response.times
* @param {WebrtcStats} response.stats
* @param {Object} response.data
* @param {number} response.data.code
* @param {(number | string)} response.data.value
* @param {string} response.data.message
* @param {number} response.data.begin
* @param {number} response.data.finish
*
*/
onNetworkChange?: (response: OnNetworkChangeResponse) => void;
/**
* 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.
*
* @function
* @param {Object[]} response - onTouchEvent response
* @param {number} response.id - ID
* @param {TouchType} response.type - Touch Type valid values: `touchstart`, `touchmove`, `touchend`, `touchcancel`.
* @param {number} response.x - The X coordinate of the video view
* @param {number} response.y - The Y coordinate of the video view
* @param {number} response.pageX - The X coordinate of the page
* @param {number} response.pageY - The Y coordinate of the page
* @param {number} response.movementX - The delta movement of X coordinate
* @param {number} response.movementY - The delta movement of Y coordinate
*
* @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;