@tencentcloud/trtc-cloud-wx 1.0.8 → 1.0.9-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/.babelrc +6 -0
  2. package/.eslintrc.json +129 -0
  3. package/build/chokidar.js +19 -0
  4. package/build/clear.js +24 -0
  5. package/build/copy.js +24 -0
  6. package/build/copy_to_roomkit.js +19 -0
  7. package/dist/package.json +14 -0
  8. package/{trtc-cloud-wx.js → dist/trtc-cloud-wx.js} +15 -5
  9. package/docs/API/TRTCCloud.html +4353 -0
  10. package/docs/API/index.html +98 -0
  11. package/docs/API/scripts/add-toc.js +57 -0
  12. package/docs/API/scripts/collapse.js +20 -0
  13. package/docs/API/scripts/highlight/highlight.min.js +1282 -0
  14. package/docs/API/scripts/highlight/highlightjs-line-numbers.min.js +1 -0
  15. package/docs/API/scripts/linenumber.js +25 -0
  16. package/docs/API/scripts/nav.js +12 -0
  17. package/docs/API/scripts/polyfill.js +4 -0
  18. package/docs/API/scripts/prettify/Apache-License-2.0.txt +202 -0
  19. package/docs/API/scripts/prettify/lang-css.js +2 -0
  20. package/docs/API/scripts/prettify/prettify.js +28 -0
  21. package/docs/API/scripts/search.js +83 -0
  22. package/docs/API/styles/font.css +81 -0
  23. package/docs/API/styles/fonts/JTURjIg1_i6t8kCHKm45_dJE3g3D_vx3rCubqg.woff2 +0 -0
  24. package/docs/API/styles/fonts/JTURjIg1_i6t8kCHKm45_dJE3gTD_vx3rCubqg.woff2 +0 -0
  25. package/docs/API/styles/fonts/JTURjIg1_i6t8kCHKm45_dJE3gbD_vx3rCubqg.woff2 +0 -0
  26. package/docs/API/styles/fonts/JTURjIg1_i6t8kCHKm45_dJE3gfD_vx3rCubqg.woff2 +0 -0
  27. package/docs/API/styles/fonts/JTURjIg1_i6t8kCHKm45_dJE3gnD_vx3rCs.woff2 +0 -0
  28. package/docs/API/styles/fonts/JTUSjIg1_i6t8kCHKm459W1hyyTh89ZNpQ.woff2 +0 -0
  29. package/docs/API/styles/fonts/JTUSjIg1_i6t8kCHKm459WRhyyTh89ZNpQ.woff2 +0 -0
  30. package/docs/API/styles/fonts/JTUSjIg1_i6t8kCHKm459WZhyyTh89ZNpQ.woff2 +0 -0
  31. package/docs/API/styles/fonts/JTUSjIg1_i6t8kCHKm459WdhyyTh89ZNpQ.woff2 +0 -0
  32. package/docs/API/styles/fonts/JTUSjIg1_i6t8kCHKm459WlhyyTh89Y.woff2 +0 -0
  33. package/docs/API/styles/highlight/highlight.min.css +26 -0
  34. package/docs/API/styles/highlight/rainbow.min.css +1 -0
  35. package/docs/API/styles/jsdoc.css +684 -0
  36. package/docs/API/styles/prettify.css +79 -0
  37. package/docs/API/styles/toc.css +44 -0
  38. package/docs/API/tutorial-00-guideline.html +81 -0
  39. package/docs/doc-src/home.md +7 -0
  40. package/docs/doc-src/tutorials/00-guideline.md +1 -0
  41. package/docs/doc-src/tutorials/tutorials.json +5 -0
  42. package/jsdoc.json +43 -0
  43. package/package.json +40 -2
  44. package/rollup.config.js +19 -0
  45. package/sdk_publish.bash +5 -0
  46. package/src/TaskMachine.ts +371 -0
  47. package/src/index.ts +1184 -0
  48. package/src/interface/index.ts +45 -0
  49. package/src/interface/types.ts +95 -0
  50. package/src/log/logger.ts +80 -0
  51. package/src/types.d.ts +1 -0
  52. package/src/utils/common.ts +50 -0
  53. package/src/utils/index.ts +2 -0
  54. package/src/utils/translate.ts +139 -0
  55. package/tsconfig.json +15 -0
  56. package/typedoc.json +21 -0
@@ -0,0 +1,45 @@
1
+ import {
2
+ TRTCRoleType,
3
+ TRTCVideoFillMode,
4
+ TRTCVideoMirrorType,
5
+ TRTCVideoResolution,
6
+ TRTCVideoResolutionMode,
7
+ TRTCVideoRotation,
8
+ TRTCAudioRoute,
9
+ } from './types'
10
+
11
+ export interface TRTCParams {
12
+ sdkAppId: number;
13
+ userId: string;
14
+ userSig: string;
15
+ roomId: number;
16
+ strRoomId?: string;
17
+ role: TRTCRoleType;
18
+ privateMapKey?: string;
19
+ }
20
+
21
+ export interface TRTCVideoEncParam {
22
+ videoResolution: TRTCVideoResolution;
23
+ resMode: TRTCVideoResolutionMode;
24
+ videoFps: number;
25
+ videoBitrate: number;
26
+ minVideoBitrate: number;
27
+ }
28
+
29
+ export interface TRTCRenderParams {
30
+ rotation: TRTCVideoRotation;
31
+ fillMode: TRTCVideoFillMode;
32
+ mirrorType: TRTCVideoMirrorType;
33
+ }
34
+
35
+ export interface TRTCVolumeInfo {
36
+ userId: string;
37
+ volume: number;
38
+ }
39
+
40
+ export interface AudioMusicParam {
41
+ path: string;
42
+ startTimeMS: number;
43
+ endTimeMS: number;
44
+ }
45
+ export * from './types'
@@ -0,0 +1,95 @@
1
+ export enum TRTCAppScene {
2
+ // web
3
+ // TRTCAppSceneVideoCall = 0,
4
+ // TRTCAppSceneLIVE = 1,
5
+ // TRTCAppSceneAudioCall = 2,
6
+ // TRTCAppSceneVoiceChatRoom = 3,
7
+
8
+ // miniprogram
9
+ // TRTCAppSceneVideoCall = 'videocall',
10
+ // TRTCAppSceneLIVE = 'live',
11
+ // TRTCAppSceneAudioCall = 'audiocall',
12
+ // TRTCAppSceneVoiceChatRoom = 'voicechatroom',
13
+ TRTCAppSceneVideoCall = 0,
14
+ TRTCAppSceneLIVE = 1, // live
15
+ TRTCAppSceneAudioCall = 2,
16
+ TRTCAppSceneVoiceChatRoom = 3,
17
+ }
18
+
19
+ export enum TRTCRoleType {
20
+ TRTCRoleAnchor = 20,
21
+ TRTCRoleAudience = 21,
22
+ }
23
+
24
+ export enum TRTCVideoStreamType {
25
+ TRTCVideoStreamTypeBig = 0,
26
+ TRTCVideoStreamTypeSmall = 1,
27
+ TRTCVideoStreamTypeSub = 2, // aux
28
+ }
29
+
30
+ export enum TRTCVideoResolution {
31
+ TRTCVideoResolution_120_120 = 1,
32
+ TRTCVideoResolution_160_160 = 3,
33
+ TRTCVideoResolution_270_270 = 5,
34
+ TRTCVideoResolution_480_480 = 7,
35
+ TRTCVideoResolution_160_120 = 50,
36
+ TRTCVideoResolution_240_180 = 52,
37
+ TRTCVideoResolution_280_210 = 54,
38
+ TRTCVideoResolution_320_240 = 56,
39
+ TRTCVideoResolution_400_300 = 58,
40
+ TRTCVideoResolution_480_360 = 60,
41
+ TRTCVideoResolution_640_480 = 62,
42
+ TRTCVideoResolution_960_720 = 64,
43
+ TRTCVideoResolution_160_90 = 100,
44
+ TRTCVideoResolution_256_144 = 102,
45
+ TRTCVideoResolution_320_180 = 104,
46
+ TRTCVideoResolution_480_270 = 106,
47
+ TRTCVideoResolution_640_360 = 108,
48
+ TRTCVideoResolution_960_540 = 110,
49
+ TRTCVideoResolution_1280_720 = 112,
50
+ TRTCVideoResolution_1920_1080 = 114,
51
+ }
52
+
53
+ export enum TRTCVideoResolutionMode {
54
+ TRTCVideoResolutionModeLandscape = 0,
55
+ TRTCVideoResolutionModePortrait = 1,
56
+ }
57
+
58
+ export enum TRTCVideoRotation {
59
+ TRTCVideoRotation0 = 0,
60
+ TRTCVideoRotation90 = 1,
61
+ TRTCVideoRotation180 = 2,
62
+ TRTCVideoRotation270 = 3,
63
+ }
64
+
65
+ export enum TRTCVideoFillMode {
66
+ TRTCVideoFillMode_Fill = 0,
67
+ TRTCVideoFillMode_Fit = 1,
68
+ }
69
+
70
+ export enum TRTCVideoMirrorType {
71
+ TRTCVideoMirrorType_Auto = 0,
72
+ TRTCVideoMirrorType_Enable = 1,
73
+ TRTCVideoMirrorType_Disable = 2,
74
+ }
75
+
76
+ export enum TRTCAudioQuality {
77
+ /** 语音模式:采样率:16k;单声道;音频裸码率:16kbps;适合语音通话为主的场景,比如在线会议,语音通话。 */
78
+ TRTCAudioQualitySpeech = 1,
79
+ /** 标准模式(或者默认模式):采样率:48k;单声道;音频裸码率:50kbps;SDK 默认的音频质量,如无特殊需求推荐选择之。 */
80
+ TRTCAudioQualityDefault = 2,
81
+ /** 音乐模式:采样率:48k;双声道 + 全频带;音频裸码率:128kbps;适合需要高保真传输音乐的场景,比如K歌、音乐直播等。 */
82
+ TRTCAudioQualityMusic = 3,
83
+ }
84
+
85
+ export enum TRTCBeautyStyle {
86
+ TRTCBeautyStyleSmooth = 0,
87
+ TRTCBeautyStyleNature = 1,
88
+ }
89
+
90
+ export enum TRTCAudioRoute {
91
+ /** 扬声器模式 */
92
+ TRTC_AUDIO_ROUTE_SPEAKER = 0,
93
+ /** 听筒模式 */
94
+ TRTC_AUDIO_ROUTE_EARPIECE = 1,
95
+ }
@@ -0,0 +1,80 @@
1
+ import {formatTime} from '../utils/common'
2
+
3
+ const LOGLEVEL = {
4
+ LOG: 0,
5
+ INFO: 1,
6
+ DEBUG: 2,
7
+ WARN: 3,
8
+ ERROR: 4, // 无日志记录级别,sdk将不打印任何日志
9
+ NON_LOGGING: 5, // 无日志记录级别,sdk将不打印任何日志
10
+ }
11
+ export class Logger {
12
+ private logLevel = 0
13
+
14
+ private sdkAppId
15
+
16
+ private userId
17
+
18
+ private roomId
19
+
20
+ private TAG_NAME = ''
21
+
22
+ constructor(tagName?: string) {
23
+ this.TAG_NAME = tagName || '[TRTCCloud-WX]'
24
+ }
25
+
26
+ setInfo(params: {
27
+ sdkAppId: number | string;
28
+ userId: string;
29
+ roomId: string | number;
30
+ }): void {
31
+ const {sdkAppId, userId, roomId} = params
32
+ this.sdkAppId = sdkAppId
33
+ this.userId = userId
34
+ this.roomId = roomId
35
+ }
36
+
37
+ setLogLevel(level: number): void {
38
+ this.logLevel = level
39
+ }
40
+
41
+ // 打印普通日志
42
+ log(...args: any): void {
43
+ if (this.logLevel === LOGLEVEL.LOG) {
44
+ console.log(this.TAG_NAME, formatTime(), ...args)
45
+ }
46
+ }
47
+
48
+ info(...args: any): void {
49
+ if (this.logLevel <= LOGLEVEL.INFO) {
50
+ console.info(this.TAG_NAME, formatTime(), ...args)
51
+ }
52
+ }
53
+
54
+ // 打印告警日志
55
+ warn(...args: any): void {
56
+ // SDK 上报的相关事件
57
+ if (this.logLevel <= LOGLEVEL.WARN) {
58
+ console.warn(this.TAG_NAME, formatTime(), ...args)
59
+ }
60
+ }
61
+
62
+ // 打印错误日志
63
+ error(...args: any): void {
64
+ // 状态机内部错误信息
65
+ if (this.logLevel <= LOGLEVEL.ERROR) {
66
+ console.error(this.TAG_NAME, formatTime(), ...args)
67
+ }
68
+ }
69
+
70
+ debug(...args: any): void {
71
+ // 状态机内部错误信息
72
+ if (this.logLevel <= LOGLEVEL.DEBUG) {
73
+ console.debug(this.TAG_NAME, formatTime(), ...args)
74
+ }
75
+ }
76
+ }
77
+
78
+ export const logger = new Logger()
79
+
80
+ export default logger
package/src/types.d.ts ADDED
@@ -0,0 +1 @@
1
+ declare const wx: any
@@ -0,0 +1,50 @@
1
+ export const uniqueFunc = (arr, uniId) => {
2
+ const res = new Map()
3
+ return arr.filter((item) => !res.has(item[uniId]) && res.set(item[uniId], 1))
4
+ }
5
+
6
+ export const isFunction = (param: any) => typeof param === 'function'
7
+ export const isUndefined = (param: any) => typeof param === 'undefined'
8
+ export const isString = (param: any) => typeof param === 'string'
9
+ export const isNumber = (param: any) => typeof param === 'number'
10
+ export const isBoolean = (param: any) => typeof param === 'boolean'
11
+
12
+ /**
13
+ * 安全执行 JSON.parse
14
+ * @param data
15
+ * @returns
16
+ */
17
+ export function safelyParse(data: string) {
18
+ if (typeof data !== 'string') {
19
+ return data
20
+ }
21
+ let result
22
+ try {
23
+ const tempData = JSON.parse(data)
24
+ // 规避 JSON.parse('12345') 转化为 12345 的情况
25
+ if (typeof tempData === 'object' && tempData) {
26
+ result = tempData
27
+ } else {
28
+ result = data
29
+ }
30
+ } catch (error) {
31
+ result = data
32
+ }
33
+ return result
34
+ }
35
+
36
+ export const formatTime = (): string => {
37
+ const timestamp = new Date().getTime()
38
+ const date = new Date(timestamp)
39
+ // const year = date.getFullYear()
40
+ // const month = date.getMonth() + 1
41
+ // const day = date.getDate()
42
+ let hour = date.getHours() as any
43
+ let minute = date.getMinutes() as any
44
+ let second = date.getSeconds() as any
45
+ const millisecond = date.getMilliseconds()
46
+ hour = hour < 10 ? `0${hour}` : hour
47
+ minute = minute < 10 ? `0${minute}` : minute
48
+ second = second < 10 ? `0${second}` : second
49
+ return `${hour}:${minute}:${second}.${millisecond}`
50
+ }
@@ -0,0 +1,2 @@
1
+ export * from './translate'
2
+ export * from './common'
@@ -0,0 +1,139 @@
1
+ import {
2
+ TRTCAppScene,
3
+ TRTCBeautyStyle,
4
+ TRTCVideoFillMode,
5
+ TRTCVideoMirrorType,
6
+ TRTCVideoResolution,
7
+ TRTCVideoResolutionMode,
8
+ TRTCVideoRotation,
9
+ TRTCVideoStreamType,
10
+ TRTCAudioRoute,
11
+ } from '../interface'
12
+
13
+ export const translateTRTCAppScene = (scene: TRTCAppScene): string => {
14
+ switch (scene) {
15
+ case 0:
16
+ return 'videocall'
17
+ case 1:
18
+ return 'live'
19
+ case 2:
20
+ return 'audiocall'
21
+ case 3:
22
+ return 'voicechatroom'
23
+ default:
24
+ return ''
25
+ }
26
+ }
27
+
28
+ export const translateTRTCVideoStreamType = (
29
+ streamType: TRTCVideoStreamType
30
+ ): string => {
31
+ switch (streamType) {
32
+ case 0:
33
+ return 'main'
34
+ case 1:
35
+ return 'small'
36
+ case 2:
37
+ return 'aux'
38
+ default:
39
+ return ''
40
+ }
41
+ }
42
+
43
+ export const translateTRTCStreamId = (
44
+ userId: string,
45
+ streamType: TRTCVideoStreamType
46
+ ): string => `${userId}_${translateTRTCVideoStreamType(streamType)}`
47
+
48
+ const TRTCVideoResolutionMap = {
49
+ [TRTCVideoResolution.TRTCVideoResolution_120_120]: [120, 120],
50
+ [TRTCVideoResolution.TRTCVideoResolution_160_160]: [160, 160],
51
+ [TRTCVideoResolution.TRTCVideoResolution_270_270]: [270, 270],
52
+ [TRTCVideoResolution.TRTCVideoResolution_480_480]: [480, 480],
53
+ [TRTCVideoResolution.TRTCVideoResolution_160_120]: [160, 120],
54
+ [TRTCVideoResolution.TRTCVideoResolution_240_180]: [240, 180],
55
+ [TRTCVideoResolution.TRTCVideoResolution_280_210]: [280, 210],
56
+ [TRTCVideoResolution.TRTCVideoResolution_320_240]: [320, 240],
57
+ [TRTCVideoResolution.TRTCVideoResolution_400_300]: [400, 300],
58
+ [TRTCVideoResolution.TRTCVideoResolution_480_360]: [480, 360],
59
+ [TRTCVideoResolution.TRTCVideoResolution_640_480]: [640, 480],
60
+ [TRTCVideoResolution.TRTCVideoResolution_960_720]: [960, 720],
61
+ [TRTCVideoResolution.TRTCVideoResolution_160_90]: [160, 90],
62
+ [TRTCVideoResolution.TRTCVideoResolution_256_144]: [256, 144],
63
+ [TRTCVideoResolution.TRTCVideoResolution_320_180]: [320, 180],
64
+ [TRTCVideoResolution.TRTCVideoResolution_480_270]: [480, 270],
65
+ [TRTCVideoResolution.TRTCVideoResolution_640_360]: [640, 360],
66
+ [TRTCVideoResolution.TRTCVideoResolution_960_540]: [960, 540],
67
+ [TRTCVideoResolution.TRTCVideoResolution_1280_720]: [1280, 720],
68
+ [TRTCVideoResolution.TRTCVideoResolution_1920_1080]: [1920, 1080],
69
+ }
70
+ export const translateTRTCVideoResolution = (
71
+ resolution: TRTCVideoResolution
72
+ ): Record<'videoWidth' | 'videoHeight', number> => {
73
+ const [videoWidth = 0, videoHeight = 0] = TRTCVideoResolutionMap[resolution]
74
+ return {videoWidth, videoHeight}
75
+ }
76
+
77
+ export const translateTRTCVideoResolutionMode = (
78
+ resolutionMode: TRTCVideoResolutionMode
79
+ ): string => {
80
+ switch (resolutionMode) {
81
+ case TRTCVideoResolutionMode.TRTCVideoResolutionModeLandscape:
82
+ return 'horizontal'
83
+ case TRTCVideoResolutionMode.TRTCVideoResolutionModePortrait:
84
+ return 'vertical'
85
+ default:
86
+ return ''
87
+ }
88
+ }
89
+
90
+ export const translateTRTCVideoRotation = (rotation: TRTCVideoRotation): string => {
91
+ switch (rotation) {
92
+ case TRTCVideoRotation.TRTCVideoRotation0:
93
+ return 'vertical'
94
+ case TRTCVideoRotation.TRTCVideoRotation90:
95
+ return 'horizontal'
96
+ default:
97
+ return ''
98
+ }
99
+ }
100
+
101
+ export const translateTRTCVideoMirrorType = (
102
+ mirrorType: TRTCVideoMirrorType
103
+ ): string => {
104
+ switch (mirrorType) {
105
+ case TRTCVideoMirrorType.TRTCVideoMirrorType_Auto:
106
+ return 'auto'
107
+ case TRTCVideoMirrorType.TRTCVideoMirrorType_Enable:
108
+ return 'enable'
109
+ case TRTCVideoMirrorType.TRTCVideoMirrorType_Disable:
110
+ return 'disable'
111
+ default:
112
+ return ''
113
+ }
114
+ }
115
+
116
+ export const translateTRTCAudioRoute = (
117
+ route: TRTCAudioRoute
118
+ ): string => {
119
+ switch (route) {
120
+ case TRTCAudioRoute.TRTC_AUDIO_ROUTE_SPEAKER:
121
+ return 'speaker'
122
+ case TRTCAudioRoute.TRTC_AUDIO_ROUTE_EARPIECE:
123
+ return 'ear'
124
+ default:
125
+ return ''
126
+ }
127
+ }
128
+
129
+ const TRTCBeautyStyleMap = {
130
+ [TRTCBeautyStyle.TRTCBeautyStyleSmooth]: 'smooth',
131
+ [TRTCBeautyStyle.TRTCBeautyStyleNature]: 'nature'
132
+ }
133
+ export const translateBeautyStyle = (beautyStyle: TRTCBeautyStyle): string => TRTCBeautyStyleMap[beautyStyle]
134
+
135
+ const TRTCVideoFillModeMap = {
136
+ [TRTCVideoFillMode.TRTCVideoFillMode_Fill]: 'fillCrop',
137
+ [TRTCVideoFillMode.TRTCVideoFillMode_Fit]: 'contain'
138
+ }
139
+ export const translateVideoFillMod = (videoFillMod: TRTCVideoFillMode): string => TRTCVideoFillModeMap[videoFillMod]
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2015",
4
+ "esModuleInterop": true,
5
+ "allowSyntheticDefaultImports": true,
6
+ "moduleResolution": "node",
7
+ "lib": ["dom", "ES2015", "ES2015.Promise"],
8
+ "resolveJsonModule": true,
9
+ "experimentalDecorators": true
10
+ },
11
+ "include": [
12
+ "src"
13
+ ],
14
+ "exclude": ["node_moudles"]
15
+ }
package/typedoc.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ // 输入选项 - 入口文件/文件夹
3
+ "entryPoints": [
4
+ "src/index.ts"
5
+ ],
6
+ // 输入选项 - 排除文件/文件夹
7
+ "exclude": [
8
+ "node_moudles",
9
+ ],
10
+ "tsconfig": "./tsconfig.json",
11
+ "entryPointStrategy": "expand",
12
+ // 输出选项 - 将软件包package.json中的版本version添加到项目名称中
13
+ "includeVersion": true,
14
+ // 输出选项 - 设置将在模板标题中使用的项目的名称。默认为package.json中的name
15
+ "name": "TRTCCloud",
16
+ // 输出选项 - 不在页面末尾打印TypeDoc链接
17
+ "hideGenerator": true,
18
+ // 输出选项 - 禁用描述代码位置
19
+ "disableSources": true,
20
+ "categoryOrder": ["Base", "房间", "视频", "*"]
21
+ }