trtc-electron-sdk 12.2.115-beta.2 → 12.2.115-beta.21
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.
- package/liteav/MediaMixingDesigner/index.d.ts +12 -8
- package/liteav/MediaMixingDesigner/index.js +135 -79
- package/liteav/base/DevicePixelRatioObserver.d.ts +12 -0
- package/liteav/base/DevicePixelRatioObserver.js +32 -0
- package/liteav/base/PromiseStore.d.ts +10 -0
- package/liteav/base/PromiseStore.js +58 -0
- package/liteav/constant.d.ts +1 -0
- package/liteav/constant.js +4 -0
- package/liteav/extensions/MediaMixingManager/MediaMixingManager.d.ts +429 -0
- package/liteav/extensions/MediaMixingManager/MediaMixingManager.js +1290 -0
- package/liteav/extensions/MediaMixingManager/MediaMixingService.d.ts +60 -0
- package/liteav/extensions/MediaMixingManager/MediaMixingService.js +80 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/BaseStreamLayoutManager.d.ts +32 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/BaseStreamLayoutManager.js +114 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/CustomStreamLayoutManager.d.ts +11 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/CustomStreamLayoutManager.js +135 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/NoneStreamLayoutManager.d.ts +11 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/NoneStreamLayoutManager.js +73 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/index.d.ts +7 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/index.js +34 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/types.d.ts +25 -0
- package/liteav/extensions/MediaMixingManager/StreamLayout/types.js +2 -0
- package/liteav/extensions/MediaMixingManager/index.d.ts +4 -227
- package/liteav/extensions/MediaMixingManager/index.js +30 -589
- package/liteav/extensions/MediaMixingManager/types.d.ts +107 -0
- package/liteav/extensions/MediaMixingManager/types.js +26 -0
- package/liteav/trtc.d.ts +67 -13
- package/liteav/trtc.js +159 -61
- package/liteav/trtc_define.d.ts +29 -3
- package/liteav/trtc_define.js +97 -29
- package/liteav/utils.d.ts +27 -0
- package/liteav/utils.js +85 -1
- package/package.json +2 -2
- package/scripts/download.js +153 -169
package/liteav/trtc_define.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
10
|
-
exports.VideoBufferInfo = exports.TRTCSwitchRoomParam = exports.AudioMusicParam = exports.TRTCStatistics = exports.TRTCRemoteStatistics = exports.TRTCLocalStatistics = void 0;
|
|
9
|
+
exports.TRTCTranscodingConfig = exports.TRTCPluginType = exports.TRTCVoiceChangerType = exports.TRTCVoiceReverbType = exports.TRTCPublishMode = exports.TRTCAudioRecordingContent = exports.TRTCMixInputType = exports.TRTCTranscodingConfigMode = exports.TRTCMixUser = exports.Rect = exports.TRTCSpeedTestResult = exports.TRTCSpeedTestParams = exports.TRTCVolumeInfo = exports.TRTCQualityInfo = exports.TRTCNetworkQosParam = exports.TRTCRenderParams = exports.TRTCVideoEncParam = exports.TRTCParams = exports.TRTCWaterMarkSrcType = exports.TRTCVideoEncodeComplexity = exports.TRTCVideoColorSpace = exports.TRTCVideoColorRange = exports.TRTCCameraCaptureMode = exports.TRTCDeviceType = exports.TRTCDeviceState = exports.TRTCLogLevel = exports.TRTCAudioFrame = exports.TRTCVideoFrame = exports.TRTCDeviceInfo = exports.TRTCScreenCaptureProperty = exports.TRTCScreenCaptureSourceInfo = exports.TRTCImageBuffer = exports.TRTCAudioQuality = exports.TRTCScreenCaptureSourceType = exports.TRTCAudioFrameFormat = exports.TRTCVideoQosPreference = exports.TRTCQosControlMode = exports.TRTCRoleType = exports.TRTCAppScene = exports.TRTCRecordType = exports.TRTCVideoMirrorType = exports.TRTCVideoBufferType = exports.TRTCVideoPixelFormat = exports.TRTCBeautyStyle = exports.TRTCVideoRotation = exports.TRTCVideoFillMode = exports.TRTCQuality = exports.TRTCVideoStreamType = exports.TRTCVideoResolutionMode = exports.TRTCVideoResolution = void 0;
|
|
10
|
+
exports.VideoBufferInfo = exports.TRTCSwitchRoomParam = exports.AudioMusicParam = exports.TRTCStatistics = exports.TRTCRemoteStatistics = exports.TRTCLocalStatistics = exports.TRTCAudioEffectParam = exports.TRTCAudioRecordingParams = exports.TRTCPublishCDNParam = void 0;
|
|
11
11
|
const util_1 = require("./Renderer/util");
|
|
12
12
|
/////////////////////////////////////////////////////////////////////////////////
|
|
13
13
|
//
|
|
@@ -22,52 +22,48 @@ const util_1 = require("./Renderer/util");
|
|
|
22
22
|
* @enum {Number}
|
|
23
23
|
*/
|
|
24
24
|
const TRTCVideoResolution_HACK_JSDOC = {
|
|
25
|
-
|
|
26
|
-
/** [C] 建议码率80kbps */
|
|
25
|
+
/** 宽高比 1:1;分辨率 120x120;建议码率(VideoCall)80kbps; 建议码率(LIVE)120kbps。 */
|
|
27
26
|
TRTCVideoResolution_120_120: 1,
|
|
28
|
-
/**
|
|
27
|
+
/** 宽高比 1:1 分辨率 160x160;建议码率(VideoCall)100kbps; 建议码率(LIVE)150kbps。 */
|
|
29
28
|
TRTCVideoResolution_160_160: 3,
|
|
30
|
-
/**
|
|
29
|
+
/** 宽高比 1:1;分辨率 270x270;建议码率(VideoCall)200kbps; 建议码率(LIVE)300kbps。 */
|
|
31
30
|
TRTCVideoResolution_270_270: 5,
|
|
32
|
-
/**
|
|
31
|
+
/** 宽高比 1:1;分辨率 480x480;建议码率(VideoCall)350kbps; 建议码率(LIVE)500kbps。 */
|
|
33
32
|
TRTCVideoResolution_480_480: 7,
|
|
34
|
-
|
|
35
|
-
/** [C] 建议码率100kbps */
|
|
33
|
+
/** 宽高比4:3;分辨率 160x120;建议码率(VideoCall)100kbps; 建议码率(LIVE)150kbps。 */
|
|
36
34
|
TRTCVideoResolution_160_120: 50,
|
|
37
|
-
/**
|
|
35
|
+
/** 宽高比 4:3;分辨率 240x180;建议码率(VideoCall)150kbps; 建议码率(LIVE)250kbps。 */
|
|
38
36
|
TRTCVideoResolution_240_180: 52,
|
|
39
|
-
/**
|
|
37
|
+
/** 宽高比 4:3;分辨率 280x210;建议码率(VideoCall)200kbps; 建议码率(LIVE)300kbps。 */
|
|
40
38
|
TRTCVideoResolution_280_210: 54,
|
|
41
|
-
/**
|
|
39
|
+
/** 宽高比 4:3;分辨率 320x240;建议码率(VideoCall)250kbps; 建议码率(LIVE)375kbps。 */
|
|
42
40
|
TRTCVideoResolution_320_240: 56,
|
|
43
|
-
/**
|
|
41
|
+
/** 宽高比 4:3;分辨率 400x300;建议码率(VideoCall)300kbps; 建议码率(LIVE)450kbps。 */
|
|
44
42
|
TRTCVideoResolution_400_300: 58,
|
|
45
|
-
/**
|
|
43
|
+
/** 宽高比 4:3;分辨率 480x360;建议码率(VideoCall)400kbps; 建议码率(LIVE)600kbps。 */
|
|
46
44
|
TRTCVideoResolution_480_360: 60,
|
|
47
|
-
/**
|
|
45
|
+
/** 宽高比 4:3;分辨率 640x480;建议码率(VideoCall)600kbps; 建议码率(LIVE)900kbps。 */
|
|
48
46
|
TRTCVideoResolution_640_480: 62,
|
|
49
|
-
/**
|
|
47
|
+
/** 宽高比 4:3;分辨率 960x720;建议码率(VideoCall)1000kbps; 建议码率(LIVE)1500kbps。 */
|
|
50
48
|
TRTCVideoResolution_960_720: 64,
|
|
51
|
-
|
|
52
|
-
/** [C] 建议码率150kbps */
|
|
49
|
+
/** 宽高比 16:9;分辨率 160x90;建议码率(VideoCall)150kbps; 建议码率(LIVE)250kbps。*/
|
|
53
50
|
TRTCVideoResolution_160_90: 100,
|
|
54
|
-
/**
|
|
51
|
+
/** 宽高比 16:9;分辨率 256x144;建议码率(VideoCall)200kbps; 建议码率(LIVE)300kbps。 */
|
|
55
52
|
TRTCVideoResolution_256_144: 102,
|
|
56
|
-
/**
|
|
53
|
+
/** 宽高比 16:9;分辨率 320x180;建议码率(VideoCall)250kbps; 建议码率(LIVE)400kbps。 */
|
|
57
54
|
TRTCVideoResolution_320_180: 104,
|
|
58
|
-
|
|
55
|
+
/**宽高比 16:9;分辨率 480x270;建议码率(VideoCall)350kbps; 建议码率(LIVE)550kbps。 */
|
|
59
56
|
TRTCVideoResolution_480_270: 106,
|
|
60
|
-
/**
|
|
57
|
+
/** 宽高比 16:9;分辨率 640x360;建议码率(VideoCall)500kbps; 建议码率(LIVE)900kbps。 */
|
|
61
58
|
TRTCVideoResolution_640_360: 108,
|
|
62
|
-
/**
|
|
59
|
+
/** 宽高比 16:9;分辨率 960x540;建议码率(VideoCall)850kbps; 建议码率(LIVE)1300kbps。 */
|
|
63
60
|
TRTCVideoResolution_960_540: 110,
|
|
64
|
-
/**
|
|
65
|
-
* [C] 摄像头采集 - 建议码率1200kbps<br>
|
|
66
|
-
* [S] 屏幕分享 - 建议码率 低清:1000kbps 高清:1600kbps
|
|
67
|
-
*/
|
|
61
|
+
/** 宽高比 16:9;分辨率 1280x720;建议码率(VideoCall)1200kbps; 建议码率(LIVE)1800kbps。 */
|
|
68
62
|
TRTCVideoResolution_1280_720: 112,
|
|
69
|
-
/**
|
|
63
|
+
/** 宽高比 16:9;分辨率 1920x1080;建议码率(VideoCall)2000kbps; 建议码率(LIVE)3000kbps。 */
|
|
70
64
|
TRTCVideoResolution_1920_1080: 114,
|
|
65
|
+
/** 宽高比 16:9;分辨率 2560x1440;建议码率(VideoCall)4000kbps; 建议码率(LIVE)6000kbps。 */
|
|
66
|
+
TRTCVideoResolution_2560_1440: 116,
|
|
71
67
|
};
|
|
72
68
|
var TRTCVideoResolution;
|
|
73
69
|
(function (TRTCVideoResolution) {
|
|
@@ -91,6 +87,7 @@ var TRTCVideoResolution;
|
|
|
91
87
|
TRTCVideoResolution[TRTCVideoResolution["TRTCVideoResolution_960_540"] = 110] = "TRTCVideoResolution_960_540";
|
|
92
88
|
TRTCVideoResolution[TRTCVideoResolution["TRTCVideoResolution_1280_720"] = 112] = "TRTCVideoResolution_1280_720";
|
|
93
89
|
TRTCVideoResolution[TRTCVideoResolution["TRTCVideoResolution_1920_1080"] = 114] = "TRTCVideoResolution_1920_1080";
|
|
90
|
+
TRTCVideoResolution[TRTCVideoResolution["TRTCVideoResolution_2560_1440"] = 116] = "TRTCVideoResolution_2560_1440";
|
|
94
91
|
})(TRTCVideoResolution = exports.TRTCVideoResolution || (exports.TRTCVideoResolution = {}));
|
|
95
92
|
/**
|
|
96
93
|
* 视频分辨率模式
|
|
@@ -651,7 +648,7 @@ exports.TRTCVideoFrame = TRTCVideoFrame;
|
|
|
651
648
|
* 音频帧数据
|
|
652
649
|
*
|
|
653
650
|
* @param {TRTCAudioFrameFormat} audioFormat - 音频帧的格式
|
|
654
|
-
* @param {ArrayBuffer} data - 音频数据
|
|
651
|
+
* @param {Buffer|ArrayBuffer} data - 音频数据
|
|
655
652
|
* @param {Number} length - 音频数据的长度
|
|
656
653
|
* @param {Number} sampleRate - 采样率
|
|
657
654
|
* @param {Number} channel - 声道数
|
|
@@ -779,6 +776,69 @@ var TRTCCameraCaptureMode;
|
|
|
779
776
|
TRTCCameraCaptureMode[TRTCCameraCaptureMode["TRTCCameraResolutionStrategyHighQuality"] = 2] = "TRTCCameraResolutionStrategyHighQuality";
|
|
780
777
|
TRTCCameraCaptureMode[TRTCCameraCaptureMode["TRTCCameraCaptureManual"] = 3] = "TRTCCameraCaptureManual";
|
|
781
778
|
})(TRTCCameraCaptureMode = exports.TRTCCameraCaptureMode || (exports.TRTCCameraCaptureMode = {}));
|
|
779
|
+
/**
|
|
780
|
+
* 视频颜色范围
|
|
781
|
+
*
|
|
782
|
+
* @enum {Number}
|
|
783
|
+
*/
|
|
784
|
+
const TRTCVideoColorRange_HACK_JSDOC = {
|
|
785
|
+
/** SDK 内部自动渲染合适范围 */
|
|
786
|
+
TRTCVideoColorRange_Auto: 0,
|
|
787
|
+
/** 限制范围 16-235 */
|
|
788
|
+
TRTCVideoColorRange_Limited: 1,
|
|
789
|
+
/** 完整范围 0-255 */
|
|
790
|
+
TRTCVideoColorRange_Full: 2
|
|
791
|
+
};
|
|
792
|
+
var TRTCVideoColorRange;
|
|
793
|
+
(function (TRTCVideoColorRange) {
|
|
794
|
+
TRTCVideoColorRange[TRTCVideoColorRange["TRTCVideoColorRange_Auto"] = 0] = "TRTCVideoColorRange_Auto";
|
|
795
|
+
TRTCVideoColorRange[TRTCVideoColorRange["TRTCVideoColorRange_Limited"] = 1] = "TRTCVideoColorRange_Limited";
|
|
796
|
+
TRTCVideoColorRange[TRTCVideoColorRange["TRTCVideoColorRange_Full"] = 2] = "TRTCVideoColorRange_Full";
|
|
797
|
+
})(TRTCVideoColorRange = exports.TRTCVideoColorRange || (exports.TRTCVideoColorRange = {}));
|
|
798
|
+
/**
|
|
799
|
+
* 视频颜色空间
|
|
800
|
+
*
|
|
801
|
+
* @enum {Number}
|
|
802
|
+
*/
|
|
803
|
+
const TRTCVideoColorSpace_HACK_JSDOC = {
|
|
804
|
+
/** SDK 内部自动渲染合适颜色空间 */
|
|
805
|
+
TRTCVideoColorSpace_Auto: 0,
|
|
806
|
+
/** BT.601 */
|
|
807
|
+
TRTCVideoColorSpace_BT601: 1,
|
|
808
|
+
/** BT.709 */
|
|
809
|
+
TRTCVideoColorSpace_BT709: 2,
|
|
810
|
+
};
|
|
811
|
+
var TRTCVideoColorSpace;
|
|
812
|
+
(function (TRTCVideoColorSpace) {
|
|
813
|
+
TRTCVideoColorSpace[TRTCVideoColorSpace["TRTCVideoColorSpace_Auto"] = 0] = "TRTCVideoColorSpace_Auto";
|
|
814
|
+
TRTCVideoColorSpace[TRTCVideoColorSpace["TRTCVideoColorSpace_BT601"] = 1] = "TRTCVideoColorSpace_BT601";
|
|
815
|
+
TRTCVideoColorSpace[TRTCVideoColorSpace["TRTCVideoColorSpace_BT709"] = 2] = "TRTCVideoColorSpace_BT709";
|
|
816
|
+
})(TRTCVideoColorSpace = exports.TRTCVideoColorSpace || (exports.TRTCVideoColorSpace = {}));
|
|
817
|
+
/**
|
|
818
|
+
* 视频编码复杂度
|
|
819
|
+
*
|
|
820
|
+
* @enum {Number}
|
|
821
|
+
*/
|
|
822
|
+
const TRTCVideoEncodeComplexity_Hack_JSDOC = {
|
|
823
|
+
/** 最快 */
|
|
824
|
+
TRTCVideoEncodeComplexity_Fastest: 0,
|
|
825
|
+
/** 快 */
|
|
826
|
+
TRTCVideoEncodeComplexity_Fast: 1,
|
|
827
|
+
/** 中 */
|
|
828
|
+
TRTCVideoEncodeComplexity_Medium: 2,
|
|
829
|
+
/** 慢 */
|
|
830
|
+
TRTCVideoEncodeComplexity_Slow: 3,
|
|
831
|
+
/** 最慢 */
|
|
832
|
+
TRTCVideoEncodeComplexity_Slowest: 4,
|
|
833
|
+
};
|
|
834
|
+
var TRTCVideoEncodeComplexity;
|
|
835
|
+
(function (TRTCVideoEncodeComplexity) {
|
|
836
|
+
TRTCVideoEncodeComplexity[TRTCVideoEncodeComplexity["TRTCVideoEncodeComplexity_Fastest"] = 0] = "TRTCVideoEncodeComplexity_Fastest";
|
|
837
|
+
TRTCVideoEncodeComplexity[TRTCVideoEncodeComplexity["TRTCVideoEncodeComplexity_Fast"] = 1] = "TRTCVideoEncodeComplexity_Fast";
|
|
838
|
+
TRTCVideoEncodeComplexity[TRTCVideoEncodeComplexity["TRTCVideoEncodeComplexity_Medium"] = 2] = "TRTCVideoEncodeComplexity_Medium";
|
|
839
|
+
TRTCVideoEncodeComplexity[TRTCVideoEncodeComplexity["TRTCVideoEncodeComplexity_Slow"] = 3] = "TRTCVideoEncodeComplexity_Slow";
|
|
840
|
+
TRTCVideoEncodeComplexity[TRTCVideoEncodeComplexity["TRTCVideoEncodeComplexity_Slowest"] = 4] = "TRTCVideoEncodeComplexity_Slowest";
|
|
841
|
+
})(TRTCVideoEncodeComplexity = exports.TRTCVideoEncodeComplexity || (exports.TRTCVideoEncodeComplexity = {}));
|
|
782
842
|
/**
|
|
783
843
|
* 摄像头采集参数
|
|
784
844
|
*
|
|
@@ -788,6 +848,8 @@ var TRTCCameraCaptureMode;
|
|
|
788
848
|
* @property {TRTCCameraCaptureMode} mode - 摄像头采集偏好
|
|
789
849
|
* @property {Number} width - 采集图像宽度
|
|
790
850
|
* @property {Number} height - 采集图像高度
|
|
851
|
+
* @property {TRTCVideoColorSpace} [colorSpace] - 可选,颜色空间
|
|
852
|
+
* @property {TRTCVideoColorRange} [colorRange] - 可选,颜色范围
|
|
791
853
|
*/
|
|
792
854
|
const TRTCCameraCaptureParams_HACK_JSDOC = null;
|
|
793
855
|
/**
|
|
@@ -892,6 +954,9 @@ exports.TRTCParams = TRTCParams;
|
|
|
892
954
|
* @param {Boolean} enableAdjustRes - 【字段含义】是否允许动态调整分辨率(开启后会对云端录制产生影响)<br>
|
|
893
955
|
* 【推荐取值】该功能适用于不需要云端录制的场景,开启后 SDK 会根据当前网络情况,智能选择出一个合适的分辨率,避免出现“大分辨率+小码率”的低效编码模式。<br>
|
|
894
956
|
* 【特别说明】默认值:关闭。如有云端录制的需求,请不要开启此功能,因为如果视频分辨率发生变化后,云端录制出的 MP4 在普通的播放器上无法正常播放。<br>
|
|
957
|
+
* @param {TRTCVideoColorSpace} [colorSpace] - 编码色彩空间
|
|
958
|
+
* @param {TRTCVideoColorRange} [colorRange] - 编码色彩范围
|
|
959
|
+
* @param {TRTCVideoEncodeComplexity} [complexity] - 编码复杂度
|
|
895
960
|
*/
|
|
896
961
|
class TRTCVideoEncParam {
|
|
897
962
|
constructor(videoResolution = TRTCVideoResolution.TRTCVideoResolution_640_360, resMode = TRTCVideoResolutionMode.TRTCVideoResolutionModeLandscape, videoFps = 15, videoBitrate = 550, minVideoBitrate = 0, enableAdjustRes = false) {
|
|
@@ -901,6 +966,9 @@ class TRTCVideoEncParam {
|
|
|
901
966
|
this.videoBitrate = videoBitrate;
|
|
902
967
|
this.minVideoBitrate = minVideoBitrate;
|
|
903
968
|
this.enableAdjustRes = enableAdjustRes;
|
|
969
|
+
this.colorRange = TRTCVideoColorRange.TRTCVideoColorRange_Auto;
|
|
970
|
+
this.colorSpace = TRTCVideoColorSpace.TRTCVideoColorSpace_Auto;
|
|
971
|
+
this.complexity = TRTCVideoEncodeComplexity.TRTCVideoEncodeComplexity_Fastest;
|
|
904
972
|
}
|
|
905
973
|
}
|
|
906
974
|
exports.TRTCVideoEncParam = TRTCVideoEncParam;
|
package/liteav/utils.d.ts
CHANGED
|
@@ -8,3 +8,30 @@ export declare function isNullOrUndefined(val: unknown): boolean;
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function safelyParse(data: string): unknown | Array<any> | Record<string, any>;
|
|
10
10
|
export declare function convertUint8ArrayToNumber(value: Uint8Array): number;
|
|
11
|
+
/**
|
|
12
|
+
* 防抖函数 (debounce)
|
|
13
|
+
*
|
|
14
|
+
* 适用场景:搜索框输入联想、窗口resize结束事件
|
|
15
|
+
*
|
|
16
|
+
* @param func 需要防抖的函数
|
|
17
|
+
* @param wait 等待时间(毫秒)
|
|
18
|
+
* @param immediate 是否立即执行第一次调用(true=立即执行,false=等待后执行)
|
|
19
|
+
* @returns 包装后的防抖函数
|
|
20
|
+
*/
|
|
21
|
+
export declare function debounce<T extends (...args: any[]) => any>(func: T, wait: number, immediate?: boolean): (...args: Parameters<T>) => void;
|
|
22
|
+
/**
|
|
23
|
+
* 节流函数 (throttle)
|
|
24
|
+
*
|
|
25
|
+
* 适用场景:滚动事件、按钮防重复点击、鼠标移动事件
|
|
26
|
+
*
|
|
27
|
+
* @param func 需要节流的函数
|
|
28
|
+
* @param wait 等待时间(毫秒)
|
|
29
|
+
* @param options 配置选项
|
|
30
|
+
* leading: 是否执行第一次调用(true=执行,false=跳过)
|
|
31
|
+
* trailing: 是否执行最后一次调用(true=执行,false=跳过)
|
|
32
|
+
* @returns 包装后的节流函数
|
|
33
|
+
*/
|
|
34
|
+
export declare function throttle<T extends (...args: any[]) => any>(func: T, wait: number, options?: {
|
|
35
|
+
leading?: boolean;
|
|
36
|
+
trailing?: boolean;
|
|
37
|
+
}): (...args: Parameters<T>) => void;
|
package/liteav/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertUint8ArrayToNumber = exports.safelyParse = exports.isNullOrUndefined = exports.isUndefined = exports.isNull = void 0;
|
|
3
|
+
exports.throttle = exports.debounce = exports.convertUint8ArrayToNumber = exports.safelyParse = exports.isNullOrUndefined = exports.isUndefined = exports.isNull = void 0;
|
|
4
4
|
function isNull(val) {
|
|
5
5
|
return val === null;
|
|
6
6
|
}
|
|
@@ -47,3 +47,87 @@ function convertUint8ArrayToNumber(value) {
|
|
|
47
47
|
return result;
|
|
48
48
|
}
|
|
49
49
|
exports.convertUint8ArrayToNumber = convertUint8ArrayToNumber;
|
|
50
|
+
/**
|
|
51
|
+
* 防抖函数 (debounce)
|
|
52
|
+
*
|
|
53
|
+
* 适用场景:搜索框输入联想、窗口resize结束事件
|
|
54
|
+
*
|
|
55
|
+
* @param func 需要防抖的函数
|
|
56
|
+
* @param wait 等待时间(毫秒)
|
|
57
|
+
* @param immediate 是否立即执行第一次调用(true=立即执行,false=等待后执行)
|
|
58
|
+
* @returns 包装后的防抖函数
|
|
59
|
+
*/
|
|
60
|
+
function debounce(func, wait, immediate = false) {
|
|
61
|
+
let timeout = null;
|
|
62
|
+
let inWait = false; // 是否处于等待周期
|
|
63
|
+
return function (...args) {
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
65
|
+
const context = this;
|
|
66
|
+
// 每次调用都清除现有定时器
|
|
67
|
+
if (timeout)
|
|
68
|
+
clearTimeout(timeout);
|
|
69
|
+
if (immediate && !inWait) {
|
|
70
|
+
// 立即执行模式且不在等待期
|
|
71
|
+
func.apply(context, args);
|
|
72
|
+
inWait = true;
|
|
73
|
+
}
|
|
74
|
+
// 设置新定时器
|
|
75
|
+
timeout = setTimeout(() => {
|
|
76
|
+
inWait = false;
|
|
77
|
+
if (!immediate) {
|
|
78
|
+
// 非立即执行模式:执行最后一次调用
|
|
79
|
+
func.apply(context, args);
|
|
80
|
+
}
|
|
81
|
+
}, wait);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
exports.debounce = debounce;
|
|
85
|
+
/**
|
|
86
|
+
* 节流函数 (throttle)
|
|
87
|
+
*
|
|
88
|
+
* 适用场景:滚动事件、按钮防重复点击、鼠标移动事件
|
|
89
|
+
*
|
|
90
|
+
* @param func 需要节流的函数
|
|
91
|
+
* @param wait 等待时间(毫秒)
|
|
92
|
+
* @param options 配置选项
|
|
93
|
+
* leading: 是否执行第一次调用(true=执行,false=跳过)
|
|
94
|
+
* trailing: 是否执行最后一次调用(true=执行,false=跳过)
|
|
95
|
+
* @returns 包装后的节流函数
|
|
96
|
+
*/
|
|
97
|
+
function throttle(func, wait, options = {}) {
|
|
98
|
+
const { leading = true, trailing = true } = options;
|
|
99
|
+
let lastExecTime = 0;
|
|
100
|
+
let timer = null;
|
|
101
|
+
let savedContext = null, savedArgs = null;
|
|
102
|
+
// 实际执行函数
|
|
103
|
+
const execute = () => {
|
|
104
|
+
lastExecTime = Date.now();
|
|
105
|
+
timer = null;
|
|
106
|
+
if (savedContext !== null && savedArgs !== null) {
|
|
107
|
+
func.apply(savedContext, savedArgs);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
return function (...args) {
|
|
111
|
+
savedContext = this;
|
|
112
|
+
savedArgs = args;
|
|
113
|
+
const now = Date.now();
|
|
114
|
+
// 计算距离上次执行的时间差
|
|
115
|
+
const sinceLast = now - lastExecTime;
|
|
116
|
+
const remaining = wait - sinceLast;
|
|
117
|
+
// 超时情况:立即执行(无论是否在等待期)
|
|
118
|
+
if (remaining <= 0 || remaining > wait) {
|
|
119
|
+
if (timer) {
|
|
120
|
+
clearTimeout(timer);
|
|
121
|
+
timer = null;
|
|
122
|
+
}
|
|
123
|
+
if (leading) {
|
|
124
|
+
execute();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else if (!timer && trailing) {
|
|
128
|
+
// 设置定时器执行尾部调用
|
|
129
|
+
timer = setTimeout(execute, remaining);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
exports.throttle = throttle;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trtc-electron-sdk",
|
|
3
|
-
"version": "12.2.115-beta.
|
|
3
|
+
"version": "12.2.115-beta.21",
|
|
4
4
|
"description": "trtc electron sdk",
|
|
5
5
|
"main": "./liteav/index.js",
|
|
6
6
|
"types": "./liteav/index.d.ts",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"doc:build": "npm run doc:build-zh && npm run doc:build-en ",
|
|
56
56
|
"doc:build-zh": "jsdoc -c ./jsdoc/jsdoc_zh.json && node ./jsdoc/fix-doc_zh.js",
|
|
57
57
|
"doc:build-en": "jsdoc -c ./jsdoc/jsdoc_en.json && node ./jsdoc/fix-doc_en.js",
|
|
58
|
-
"doc:clean": "
|
|
58
|
+
"doc:clean": "rimraf ./_doc",
|
|
59
59
|
"prerelease": "npm run build && npm run doc && node ./scripts/prerelase.js ",
|
|
60
60
|
"publish_npm": "node scripts/publish-npm.js"
|
|
61
61
|
},
|