trtc-electron-sdk 11.3.502-beta.5 → 11.3.502-beta.7
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/trtc.d.ts +98 -8
- package/liteav/trtc.js +125 -12
- package/liteav/trtc_define.d.ts +29 -0
- package/liteav/trtc_define.js +37 -2
- package/package.json +5 -1
- package/scripts/download.js +0 -3
- package/scripts/postinstall.js +46 -0
package/liteav/trtc.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import { VodPlayer } from './vod_player';
|
|
4
|
-
import { AudioMusicParam, Rect, TRTCAppScene, TRTCAudioEffectParam, TRTCAudioQuality, TRTCBeautyStyle, TRTCDeviceState, TRTCDeviceType, TRTCLogLevel, TRTCRenderParams, TRTCRoleType, TRTCSwitchRoomParam, TRTCVideoBufferType, TRTCVideoFillMode, TRTCVideoPixelFormat, TRTCVideoRotation, TRTCVideoStreamType, TRTCWaterMarkSrcType, PluginInfo, TRTCAudioRecordingParams, TRTCScreenCaptureSourceInfo, TRTCScreenCaptureProperty, TRTCSpeedTestParams, TRTCRecordType, TRTCDeviceInfo, TRTCCameraCaptureParams, TRTCImageBuffer, TRTCInitConfig } from './trtc_define';
|
|
4
|
+
import { AudioMusicParam, Rect, TRTCAppScene, TRTCAudioEffectParam, TRTCAudioQuality, TRTCBeautyStyle, TRTCDeviceState, TRTCDeviceType, TRTCLogLevel, TRTCRenderParams, TRTCRoleType, TRTCSwitchRoomParam, TRTCVideoBufferType, TRTCVideoFillMode, TRTCAudioFrame, TRTCVideoPixelFormat, TRTCVideoRotation, TRTCVideoStreamType, TRTCWaterMarkSrcType, PluginInfo, TRTCAudioRecordingParams, TRTCScreenCaptureSourceInfo, TRTCScreenCaptureProperty, TRTCSpeedTestParams, TRTCRecordType, TRTCDeviceInfo, TRTCCameraCaptureParams, TRTCImageBuffer, TRTCInitConfig, TRTCAudioParallelParams } from './trtc_define';
|
|
5
5
|
export * from './trtc_define';
|
|
6
6
|
export * from './trtc_code';
|
|
7
7
|
export * from './vod_player';
|
|
@@ -12,7 +12,7 @@ export * from './vod_player';
|
|
|
12
12
|
* @example
|
|
13
13
|
* // 创建/使用/销毁 TRTCCloud 对象的示例代码:
|
|
14
14
|
* import TRTCCloud from 'trtc-electron-sdk';
|
|
15
|
-
* this.rtcCloud =
|
|
15
|
+
* this.rtcCloud = TRTCCloud.getTRTCShareInstance();
|
|
16
16
|
* // 获取 SDK 版本号
|
|
17
17
|
* let version = this.rtcCloud.getSDKVersion();
|
|
18
18
|
*
|
|
@@ -66,7 +66,7 @@ declare class TRTCCloud extends EventEmitter {
|
|
|
66
66
|
* @example
|
|
67
67
|
* // Enable 'debug' mode
|
|
68
68
|
* const TRTCCloud = require('trtc-electron-sdk');
|
|
69
|
-
* const rtcCloud =
|
|
69
|
+
* const rtcCloud = TRTCCloud.getTRTCShareInstance();
|
|
70
70
|
* rtcCloud.getConfigObject().setDebugMode(true);
|
|
71
71
|
*
|
|
72
72
|
* @returns {TRTCConfig}
|
|
@@ -84,7 +84,7 @@ declare class TRTCCloud extends EventEmitter {
|
|
|
84
84
|
* @example
|
|
85
85
|
* // 创建/使用/销毁 TRTCCloud 对象的示例代码:
|
|
86
86
|
* import TRTCCloud from 'trtc-electron-sdk';
|
|
87
|
-
* this.rtcCloud =
|
|
87
|
+
* this.rtcCloud = TRTCCloud.getTRTCShareInstance();
|
|
88
88
|
*
|
|
89
89
|
* // 注册回调的方法,事件关键字详见下方"通用事件回调"
|
|
90
90
|
* subscribeEvents = (rtcCloud) => {
|
|
@@ -1208,6 +1208,12 @@ declare class TRTCCloud extends EventEmitter {
|
|
|
1208
1208
|
* 如果录制任务在退出房间前尚未通过本接口停止,则退出房间后录音任务会自动被停止。
|
|
1209
1209
|
*/
|
|
1210
1210
|
stopLocalRecording(): void;
|
|
1211
|
+
/**
|
|
1212
|
+
* 设置远端音频流智能并发播放策略
|
|
1213
|
+
*
|
|
1214
|
+
* @param {TRTCAudioParallelParams} - 指定用户必定能并发播放。
|
|
1215
|
+
*/
|
|
1216
|
+
setRemoteAudioParallelParams(param: TRTCAudioParallelParams): void;
|
|
1211
1217
|
/**
|
|
1212
1218
|
* 开启本地音频的采集和上行
|
|
1213
1219
|
*
|
|
@@ -1612,7 +1618,7 @@ declare class TRTCCloud extends EventEmitter {
|
|
|
1612
1618
|
* TRTCScreenCaptureProperty
|
|
1613
1619
|
* } from 'trtc-electron-sdk';
|
|
1614
1620
|
*
|
|
1615
|
-
* const rtcCloud =
|
|
1621
|
+
* const rtcCloud = TRTCCloud.getTRTCShareInstance();
|
|
1616
1622
|
*
|
|
1617
1623
|
* const screenAndWindows = rtcCloud.getScreenCaptureSources(320, 180, 32, 32);
|
|
1618
1624
|
*
|
|
@@ -1639,7 +1645,7 @@ declare class TRTCCloud extends EventEmitter {
|
|
|
1639
1645
|
* // 示例2: 选择要分享的窗口或屏幕,9.3 及之前版本只能使用此方式
|
|
1640
1646
|
* import TRTCCloud, { Rect } from 'trtc-electron-sdk';
|
|
1641
1647
|
*
|
|
1642
|
-
* const rtcCloud =
|
|
1648
|
+
* const rtcCloud = TRTCCloud.getTRTCShareInstance();
|
|
1643
1649
|
*
|
|
1644
1650
|
* const screenAndWindows = rtcCloud.getScreenCaptureSources(320, 180, 32, 32);
|
|
1645
1651
|
*
|
|
@@ -1677,7 +1683,7 @@ declare class TRTCCloud extends EventEmitter {
|
|
|
1677
1683
|
* TRTCVideoResolutionMode
|
|
1678
1684
|
* } from 'trtc-electron-sdk';
|
|
1679
1685
|
*
|
|
1680
|
-
* const rtcCloud =
|
|
1686
|
+
* const rtcCloud = TRTCCloud.getTRTCShareInstance();
|
|
1681
1687
|
*
|
|
1682
1688
|
* const screenAndWindows = rtcCloud.getScreenCaptureSources(320, 180, 32, 32);
|
|
1683
1689
|
*
|
|
@@ -1779,6 +1785,90 @@ declare class TRTCCloud extends EventEmitter {
|
|
|
1779
1785
|
* @note 该方法只有在 TRTCScreenCaptureSourceInfo 中的 type 指定为 TRTCScreenCaptureSourceTypeScreen 时生效,即分享屏幕时生效
|
|
1780
1786
|
*/
|
|
1781
1787
|
removeAllExcludedShareWindow(): void;
|
|
1788
|
+
/**
|
|
1789
|
+
* 启用音频自定义采集模式
|
|
1790
|
+
*
|
|
1791
|
+
* 开启该模式后,SDK 不在运行原有的音频采集流程,即不再继续从麦克风采集音频数据,而是只保留音频编码和发送能力。
|
|
1792
|
+
* 您需要通过 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 不断地向 SDK 塞入自己采集的音频数据。
|
|
1793
|
+
*
|
|
1794
|
+
* 注意:
|
|
1795
|
+
* - 音频自定义采集与 SDK 默认的麦克疯音频采集互斥。因此,调用 `enableCustomAudioCapture(true)` 开启音频自定义采集前,需要先调用 [stopLocalAudio]{@link TRTCCloud#stopLocalAudio} 接口关闭默认的麦克风音频上行,否则不生效;调用 `enableCustomAudioCapture(false)` 关闭自定义采集后,要调用 [startLocalAudio]{@link TRTCCloud#startLocalAudio} 接口才能开启 SDK 默认的麦克风音频采集。
|
|
1796
|
+
* - 由于回声抵消(AEC)需要严格的控制声音采集和播放的时间,所以开启自定义音频采集后,AEC 能力可能会失效。
|
|
1797
|
+
*
|
|
1798
|
+
* @param {Boolean} enable - 是否启用,默认值:false。
|
|
1799
|
+
*/
|
|
1800
|
+
enableCustomAudioCapture(enable: boolean): void;
|
|
1801
|
+
/**
|
|
1802
|
+
* 向 SDK 投送自己采集的音频数据
|
|
1803
|
+
*
|
|
1804
|
+
* 参数 {@link TRTCAudioFrame} 推荐下列填写方式(其他字段不需要填写):
|
|
1805
|
+
* - audioFormat:音频数据格式,仅支持 TRTCAudioFrameFormatPCM。
|
|
1806
|
+
* - data:音频帧 buffer。音频帧数据只支持 PCM 格式,支持[5ms ~ 100ms]帧长,推荐使用 20ms 帧长,长度计算方法:【48000采样率、单声道的帧长度:48000 × 0.02s × 1 × 16bit = 15360bit = 1920字节】。
|
|
1807
|
+
* - sampleRate:采样率,支持:16000、24000、32000、44100、48000。
|
|
1808
|
+
* - channel:声道数(如果是立体声,数据是交叉的),单声道:1; 双声道:2。
|
|
1809
|
+
* - timestamp:时间戳,单位为毫秒(ms),请使用音频帧在采集时被记录下来的时间戳(可以在采集到一帧音频帧之后,通过调用 [generateCustomPTS]{@link TRTCCloud#generateCustomPTS} 获取时间戳)。
|
|
1810
|
+
*
|
|
1811
|
+
* 注意:请您精准地按每帧时长的间隔调用本接口,数据投送间隔不均匀时极易触发声音卡顿。
|
|
1812
|
+
*
|
|
1813
|
+
* @param {TRTCAudioFrame} frame - 音频数据
|
|
1814
|
+
*/
|
|
1815
|
+
sendCustomAudioData(frame: TRTCAudioFrame): void;
|
|
1816
|
+
/**
|
|
1817
|
+
* 启用/关闭自定义音轨
|
|
1818
|
+
*
|
|
1819
|
+
* 开启后,您可以通过本接口向 SDK 混入一条自定义的音轨。通过两个布尔型参数,您可以控制该音轨是否要在远端和本地播放。
|
|
1820
|
+
*
|
|
1821
|
+
* 注意: 如果您指定参数 enablePublish 和 enablePlayout 均为 false,代表完全关闭您的自定义音轨。
|
|
1822
|
+
* @param {Boolean} enablePublish - 控制混入的音轨是否要在远端播放,默认值:false。
|
|
1823
|
+
* @param {Boolean} enablePlayout - 控制混入的音轨是否要在本地播放,默认值:false。
|
|
1824
|
+
*
|
|
1825
|
+
*/
|
|
1826
|
+
enableMixExternalAudioFrame(enablePublish: boolean, enablePlayout: boolean): void;
|
|
1827
|
+
/**
|
|
1828
|
+
* 向 SDK 混入自定义音轨
|
|
1829
|
+
*
|
|
1830
|
+
* * 调用该接口之前,您需要先通过 [enableMixExternalAudioFrame]{@link TRTCCloud#enableMixExternalAudioFrame} 开启自定义音轨,之后就可以通过本接口将自己的音轨以 PCM 格式混入到 SDK 中。
|
|
1831
|
+
* 理想情况下,我们期望您的代码能够以非常均匀的速度向 SDK 提供音轨数据。但我们也非常清楚,完美的调用间隔是一个巨大的挑战。
|
|
1832
|
+
* 所以 SDK 内部会开启一个音轨数据的缓冲区,该缓冲区的作用类似一个“蓄水池”,它能够暂存您传入的音轨数据,平抑由于接口调用间隔的抖动问题。
|
|
1833
|
+
* 本接口的返回值代表这个音轨缓冲区的大小,单位是毫秒(ms),比如:如果该接口返回 50,则代表当前的音轨缓冲区有 50ms 的音轨数据。因此只要您在 50ms 内再次调用本接口,SDK 就能保证您混入的音轨数据是连续的。
|
|
1834
|
+
* 当您调用该接口后,如果发现返回值 > 100ms,则可以等待一帧音频帧的播放时间之后再次调用;如果返回值 < 100ms,则代表缓冲区比较小,您可以再次混入一些音轨数据以确保音轨缓冲区的大小维持在“安全水位”以上。
|
|
1835
|
+
* 参数 {@link TRTCAudioFrame} 推荐下列填写方式(其他字段不需要填写):
|
|
1836
|
+
* - data:音频帧 buffer。音频帧数据只支持 PCM 格式,支持[5ms ~ 100ms]帧长,推荐使用 20ms 帧长,长度计算方法:【48000采样率、单声道的帧长度:48000 × 0.02s × 1 × 16bit = 15360bit = 1920字节】。
|
|
1837
|
+
* - sampleRate:采样率,支持:16000、24000、32000、44100、48000。
|
|
1838
|
+
* - channel:声道数(如果是立体声,数据是交叉的),单声道:1; 双声道:2。
|
|
1839
|
+
* - timestamp:时间戳,单位为毫秒(ms),请使用音频帧在采集时被记录下来的时间戳(可以在获得一帧音频帧之后,通过调用 [generateCustomPTS]{@link TRTCCloud#generateCustomPTS} 获得时间戳)。
|
|
1840
|
+
*
|
|
1841
|
+
* 注意:
|
|
1842
|
+
* - 混入自定义音轨,需要有上行音频流驱动,支持的上行音频流包括:
|
|
1843
|
+
* - SDK 默认采集的麦克风音频流,调用 [startLocalAudio]{@link TRTCCloud#startLocalAudio} 接口开启。
|
|
1844
|
+
* - 开启了自定义音频流,并有自定义音频数据上行,分别调用 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 和 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 接口。
|
|
1845
|
+
* - 开启了背景音乐,调用接口 [startPlayMusic]{@link TRTCCloud#startPlayMusic}。
|
|
1846
|
+
* - 请您精准地按每帧时长的间隔调用本接口,数据投送间隔不均匀时极易触发声音卡顿。
|
|
1847
|
+
*
|
|
1848
|
+
* @param {TRTCAudioFrame} frame - 音频数据
|
|
1849
|
+
* @returns {Number} - 音频缓冲时长,单位:ms。< 0 错误(-1 未启用 mixExternalAudioFrame)
|
|
1850
|
+
*/
|
|
1851
|
+
mixExternalAudioFrame(frame: TRTCAudioFrame): number;
|
|
1852
|
+
/**
|
|
1853
|
+
* 设置推流时混入外部音频的推流音量和播放音量
|
|
1854
|
+
*
|
|
1855
|
+
* @param {Number} publishVolume - 设置的推流音量大小,范围0 - 100,-1表示不改变。
|
|
1856
|
+
* @param {Number} playoutVolume - 设置的播放音量大小,范围0 - 100,-1表示不改变。
|
|
1857
|
+
*/
|
|
1858
|
+
setMixExternalAudioVolume(publishVolume: number, playoutVolume: number): void;
|
|
1859
|
+
/**
|
|
1860
|
+
* 生成自定义采集时的时间戳
|
|
1861
|
+
*
|
|
1862
|
+
* 本接口仅适用于自定义采集模式,用于解决音视频帧的采集时间(capture time)和投送时间(send time)不一致所导致的音画不同步问题。
|
|
1863
|
+
* 当您通过 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 等接口进行自定义视频或音频采集时,请按照如下操作使用该接口:
|
|
1864
|
+
* 1. 首先,在采集到一帧视频或音频帧时,通过调用本接口获得当时的 PTS 时间戳。
|
|
1865
|
+
* 2. 之后可以将该视频或音频帧送入您使用的前处理模块(如第三方美颜组件,或第三方音效组件)。
|
|
1866
|
+
* 3. 在真正调用 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 进行投送时,请将该帧在采集时记录的 PTS 时间戳赋值给 {@link TRTCVideoFrame} 或 {@link TRTCAudioFrame} 中的 timestamp 字段。
|
|
1867
|
+
*
|
|
1868
|
+
*
|
|
1869
|
+
* @returns {Number} - 时间戳(单位:ms)
|
|
1870
|
+
*/
|
|
1871
|
+
generateCustomPTS(): number;
|
|
1782
1872
|
/**
|
|
1783
1873
|
* @private
|
|
1784
1874
|
* 设置本地视频自定义渲染(Electron 平台下不可用)
|
|
@@ -1953,7 +2043,7 @@ declare class TRTCCloud extends EventEmitter {
|
|
|
1953
2043
|
* @example
|
|
1954
2044
|
* // 音乐播放
|
|
1955
2045
|
* import TRTCCloud, { AudioMusicParam } from 'trtc-electron-sdk';
|
|
1956
|
-
* const rtcCloud =
|
|
2046
|
+
* const rtcCloud = TRTCCloud.getTRTCShareInstance();
|
|
1957
2047
|
*
|
|
1958
2048
|
* const params = new AudioMusicParam();
|
|
1959
2049
|
* params.id = 1;
|
package/liteav/trtc.js
CHANGED
|
@@ -144,7 +144,7 @@ let oriRtcCloud = null;
|
|
|
144
144
|
* @example
|
|
145
145
|
* // 创建/使用/销毁 TRTCCloud 对象的示例代码:
|
|
146
146
|
* import TRTCCloud from 'trtc-electron-sdk';
|
|
147
|
-
* this.rtcCloud =
|
|
147
|
+
* this.rtcCloud = TRTCCloud.getTRTCShareInstance();
|
|
148
148
|
* // 获取 SDK 版本号
|
|
149
149
|
* let version = this.rtcCloud.getSDKVersion();
|
|
150
150
|
*
|
|
@@ -225,7 +225,7 @@ class TRTCCloud extends events_1.EventEmitter {
|
|
|
225
225
|
* @example
|
|
226
226
|
* // Enable 'debug' mode
|
|
227
227
|
* const TRTCCloud = require('trtc-electron-sdk');
|
|
228
|
-
* const rtcCloud =
|
|
228
|
+
* const rtcCloud = TRTCCloud.getTRTCShareInstance();
|
|
229
229
|
* rtcCloud.getConfigObject().setDebugMode(true);
|
|
230
230
|
*
|
|
231
231
|
* @returns {TRTCConfig}
|
|
@@ -267,7 +267,7 @@ class TRTCCloud extends events_1.EventEmitter {
|
|
|
267
267
|
* @example
|
|
268
268
|
* // 创建/使用/销毁 TRTCCloud 对象的示例代码:
|
|
269
269
|
* import TRTCCloud from 'trtc-electron-sdk';
|
|
270
|
-
* this.rtcCloud =
|
|
270
|
+
* this.rtcCloud = TRTCCloud.getTRTCShareInstance();
|
|
271
271
|
*
|
|
272
272
|
* // 注册回调的方法,事件关键字详见下方"通用事件回调"
|
|
273
273
|
* subscribeEvents = (rtcCloud) => {
|
|
@@ -2367,6 +2367,28 @@ class TRTCCloud extends events_1.EventEmitter {
|
|
|
2367
2367
|
stopLocalRecording() {
|
|
2368
2368
|
this.rtcCloud.stopLocalRecording();
|
|
2369
2369
|
}
|
|
2370
|
+
/**
|
|
2371
|
+
* 设置远端音频流智能并发播放策略
|
|
2372
|
+
*
|
|
2373
|
+
* @param {TRTCAudioParallelParams} - 指定用户必定能并发播放。
|
|
2374
|
+
*/
|
|
2375
|
+
setRemoteAudioParallelParams(param) {
|
|
2376
|
+
if (param.maxCount < 0) {
|
|
2377
|
+
throw new Error("maxCount must be greater or equal 0");
|
|
2378
|
+
}
|
|
2379
|
+
if (Array.isArray(param.includeUsers) && param.includeUsers.length >= 1) {
|
|
2380
|
+
const includeUsersFilterArray = param.includeUsers.filter(item => {
|
|
2381
|
+
return typeof item === 'string';
|
|
2382
|
+
});
|
|
2383
|
+
this.rtcCloud.setRemoteAudioParallelParams({
|
|
2384
|
+
maxCount: param.maxCount,
|
|
2385
|
+
includeUsers: includeUsersFilterArray
|
|
2386
|
+
});
|
|
2387
|
+
}
|
|
2388
|
+
else {
|
|
2389
|
+
throw new Error('includeUsers must be Array<String> type and not empty');
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2370
2392
|
/////////////////////////////////////////////////////////////////////////////////
|
|
2371
2393
|
//
|
|
2372
2394
|
// (四)音频相关接口函数
|
|
@@ -2922,7 +2944,7 @@ class TRTCCloud extends events_1.EventEmitter {
|
|
|
2922
2944
|
* TRTCScreenCaptureProperty
|
|
2923
2945
|
* } from 'trtc-electron-sdk';
|
|
2924
2946
|
*
|
|
2925
|
-
* const rtcCloud =
|
|
2947
|
+
* const rtcCloud = TRTCCloud.getTRTCShareInstance();
|
|
2926
2948
|
*
|
|
2927
2949
|
* const screenAndWindows = rtcCloud.getScreenCaptureSources(320, 180, 32, 32);
|
|
2928
2950
|
*
|
|
@@ -2949,7 +2971,7 @@ class TRTCCloud extends events_1.EventEmitter {
|
|
|
2949
2971
|
* // 示例2: 选择要分享的窗口或屏幕,9.3 及之前版本只能使用此方式
|
|
2950
2972
|
* import TRTCCloud, { Rect } from 'trtc-electron-sdk';
|
|
2951
2973
|
*
|
|
2952
|
-
* const rtcCloud =
|
|
2974
|
+
* const rtcCloud = TRTCCloud.getTRTCShareInstance();
|
|
2953
2975
|
*
|
|
2954
2976
|
* const screenAndWindows = rtcCloud.getScreenCaptureSources(320, 180, 32, 32);
|
|
2955
2977
|
*
|
|
@@ -3005,7 +3027,7 @@ class TRTCCloud extends events_1.EventEmitter {
|
|
|
3005
3027
|
* TRTCVideoResolutionMode
|
|
3006
3028
|
* } from 'trtc-electron-sdk';
|
|
3007
3029
|
*
|
|
3008
|
-
* const rtcCloud =
|
|
3030
|
+
* const rtcCloud = TRTCCloud.getTRTCShareInstance();
|
|
3009
3031
|
*
|
|
3010
3032
|
* const screenAndWindows = rtcCloud.getScreenCaptureSources(320, 180, 32, 32);
|
|
3011
3033
|
*
|
|
@@ -3172,11 +3194,102 @@ class TRTCCloud extends events_1.EventEmitter {
|
|
|
3172
3194
|
// (九)自定义采集和渲染
|
|
3173
3195
|
//
|
|
3174
3196
|
/////////////////////////////////////////////////////////////////////////////////
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3197
|
+
/**
|
|
3198
|
+
* 启用音频自定义采集模式
|
|
3199
|
+
*
|
|
3200
|
+
* 开启该模式后,SDK 不在运行原有的音频采集流程,即不再继续从麦克风采集音频数据,而是只保留音频编码和发送能力。
|
|
3201
|
+
* 您需要通过 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 不断地向 SDK 塞入自己采集的音频数据。
|
|
3202
|
+
*
|
|
3203
|
+
* 注意:
|
|
3204
|
+
* - 音频自定义采集与 SDK 默认的麦克疯音频采集互斥。因此,调用 `enableCustomAudioCapture(true)` 开启音频自定义采集前,需要先调用 [stopLocalAudio]{@link TRTCCloud#stopLocalAudio} 接口关闭默认的麦克风音频上行,否则不生效;调用 `enableCustomAudioCapture(false)` 关闭自定义采集后,要调用 [startLocalAudio]{@link TRTCCloud#startLocalAudio} 接口才能开启 SDK 默认的麦克风音频采集。
|
|
3205
|
+
* - 由于回声抵消(AEC)需要严格的控制声音采集和播放的时间,所以开启自定义音频采集后,AEC 能力可能会失效。
|
|
3206
|
+
*
|
|
3207
|
+
* @param {Boolean} enable - 是否启用,默认值:false。
|
|
3208
|
+
*/
|
|
3209
|
+
enableCustomAudioCapture(enable) {
|
|
3210
|
+
this.rtcCloud.enableCustomAudioCapture(enable);
|
|
3211
|
+
}
|
|
3212
|
+
/**
|
|
3213
|
+
* 向 SDK 投送自己采集的音频数据
|
|
3214
|
+
*
|
|
3215
|
+
* 参数 {@link TRTCAudioFrame} 推荐下列填写方式(其他字段不需要填写):
|
|
3216
|
+
* - audioFormat:音频数据格式,仅支持 TRTCAudioFrameFormatPCM。
|
|
3217
|
+
* - data:音频帧 buffer。音频帧数据只支持 PCM 格式,支持[5ms ~ 100ms]帧长,推荐使用 20ms 帧长,长度计算方法:【48000采样率、单声道的帧长度:48000 × 0.02s × 1 × 16bit = 15360bit = 1920字节】。
|
|
3218
|
+
* - sampleRate:采样率,支持:16000、24000、32000、44100、48000。
|
|
3219
|
+
* - channel:声道数(如果是立体声,数据是交叉的),单声道:1; 双声道:2。
|
|
3220
|
+
* - timestamp:时间戳,单位为毫秒(ms),请使用音频帧在采集时被记录下来的时间戳(可以在采集到一帧音频帧之后,通过调用 [generateCustomPTS]{@link TRTCCloud#generateCustomPTS} 获取时间戳)。
|
|
3221
|
+
*
|
|
3222
|
+
* 注意:请您精准地按每帧时长的间隔调用本接口,数据投送间隔不均匀时极易触发声音卡顿。
|
|
3223
|
+
*
|
|
3224
|
+
* @param {TRTCAudioFrame} frame - 音频数据
|
|
3225
|
+
*/
|
|
3226
|
+
sendCustomAudioData(frame) {
|
|
3227
|
+
this.rtcCloud.sendCustomAudioData(frame);
|
|
3228
|
+
}
|
|
3229
|
+
/**
|
|
3230
|
+
* 启用/关闭自定义音轨
|
|
3231
|
+
*
|
|
3232
|
+
* 开启后,您可以通过本接口向 SDK 混入一条自定义的音轨。通过两个布尔型参数,您可以控制该音轨是否要在远端和本地播放。
|
|
3233
|
+
*
|
|
3234
|
+
* 注意: 如果您指定参数 enablePublish 和 enablePlayout 均为 false,代表完全关闭您的自定义音轨。
|
|
3235
|
+
* @param {Boolean} enablePublish - 控制混入的音轨是否要在远端播放,默认值:false。
|
|
3236
|
+
* @param {Boolean} enablePlayout - 控制混入的音轨是否要在本地播放,默认值:false。
|
|
3237
|
+
*
|
|
3238
|
+
*/
|
|
3239
|
+
enableMixExternalAudioFrame(enablePublish, enablePlayout) {
|
|
3240
|
+
this.rtcCloud.enableMixExternalAudioFrame(enablePublish, enablePlayout);
|
|
3241
|
+
}
|
|
3242
|
+
/**
|
|
3243
|
+
* 向 SDK 混入自定义音轨
|
|
3244
|
+
*
|
|
3245
|
+
* * 调用该接口之前,您需要先通过 [enableMixExternalAudioFrame]{@link TRTCCloud#enableMixExternalAudioFrame} 开启自定义音轨,之后就可以通过本接口将自己的音轨以 PCM 格式混入到 SDK 中。
|
|
3246
|
+
* 理想情况下,我们期望您的代码能够以非常均匀的速度向 SDK 提供音轨数据。但我们也非常清楚,完美的调用间隔是一个巨大的挑战。
|
|
3247
|
+
* 所以 SDK 内部会开启一个音轨数据的缓冲区,该缓冲区的作用类似一个“蓄水池”,它能够暂存您传入的音轨数据,平抑由于接口调用间隔的抖动问题。
|
|
3248
|
+
* 本接口的返回值代表这个音轨缓冲区的大小,单位是毫秒(ms),比如:如果该接口返回 50,则代表当前的音轨缓冲区有 50ms 的音轨数据。因此只要您在 50ms 内再次调用本接口,SDK 就能保证您混入的音轨数据是连续的。
|
|
3249
|
+
* 当您调用该接口后,如果发现返回值 > 100ms,则可以等待一帧音频帧的播放时间之后再次调用;如果返回值 < 100ms,则代表缓冲区比较小,您可以再次混入一些音轨数据以确保音轨缓冲区的大小维持在“安全水位”以上。
|
|
3250
|
+
* 参数 {@link TRTCAudioFrame} 推荐下列填写方式(其他字段不需要填写):
|
|
3251
|
+
* - data:音频帧 buffer。音频帧数据只支持 PCM 格式,支持[5ms ~ 100ms]帧长,推荐使用 20ms 帧长,长度计算方法:【48000采样率、单声道的帧长度:48000 × 0.02s × 1 × 16bit = 15360bit = 1920字节】。
|
|
3252
|
+
* - sampleRate:采样率,支持:16000、24000、32000、44100、48000。
|
|
3253
|
+
* - channel:声道数(如果是立体声,数据是交叉的),单声道:1; 双声道:2。
|
|
3254
|
+
* - timestamp:时间戳,单位为毫秒(ms),请使用音频帧在采集时被记录下来的时间戳(可以在获得一帧音频帧之后,通过调用 [generateCustomPTS]{@link TRTCCloud#generateCustomPTS} 获得时间戳)。
|
|
3255
|
+
*
|
|
3256
|
+
* 注意:
|
|
3257
|
+
* - 混入自定义音轨,需要有上行音频流驱动,支持的上行音频流包括:
|
|
3258
|
+
* - SDK 默认采集的麦克风音频流,调用 [startLocalAudio]{@link TRTCCloud#startLocalAudio} 接口开启。
|
|
3259
|
+
* - 开启了自定义音频流,并有自定义音频数据上行,分别调用 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 和 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 接口。
|
|
3260
|
+
* - 开启了背景音乐,调用接口 [startPlayMusic]{@link TRTCCloud#startPlayMusic}。
|
|
3261
|
+
* - 请您精准地按每帧时长的间隔调用本接口,数据投送间隔不均匀时极易触发声音卡顿。
|
|
3262
|
+
*
|
|
3263
|
+
* @param {TRTCAudioFrame} frame - 音频数据
|
|
3264
|
+
* @returns {Number} - 音频缓冲时长,单位:ms。< 0 错误(-1 未启用 mixExternalAudioFrame)
|
|
3265
|
+
*/
|
|
3266
|
+
mixExternalAudioFrame(frame) {
|
|
3267
|
+
return this.rtcCloud.mixExternalAudioFrame(frame);
|
|
3268
|
+
}
|
|
3269
|
+
/**
|
|
3270
|
+
* 设置推流时混入外部音频的推流音量和播放音量
|
|
3271
|
+
*
|
|
3272
|
+
* @param {Number} publishVolume - 设置的推流音量大小,范围0 - 100,-1表示不改变。
|
|
3273
|
+
* @param {Number} playoutVolume - 设置的播放音量大小,范围0 - 100,-1表示不改变。
|
|
3274
|
+
*/
|
|
3275
|
+
setMixExternalAudioVolume(publishVolume, playoutVolume) {
|
|
3276
|
+
this.rtcCloud.setMixExternalAudioVolume(publishVolume, playoutVolume);
|
|
3277
|
+
}
|
|
3278
|
+
/**
|
|
3279
|
+
* 生成自定义采集时的时间戳
|
|
3280
|
+
*
|
|
3281
|
+
* 本接口仅适用于自定义采集模式,用于解决音视频帧的采集时间(capture time)和投送时间(send time)不一致所导致的音画不同步问题。
|
|
3282
|
+
* 当您通过 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 等接口进行自定义视频或音频采集时,请按照如下操作使用该接口:
|
|
3283
|
+
* 1. 首先,在采集到一帧视频或音频帧时,通过调用本接口获得当时的 PTS 时间戳。
|
|
3284
|
+
* 2. 之后可以将该视频或音频帧送入您使用的前处理模块(如第三方美颜组件,或第三方音效组件)。
|
|
3285
|
+
* 3. 在真正调用 [sendCustomAudioData]{@link TRTCCloud#sendCustomAudioData} 进行投送时,请将该帧在采集时记录的 PTS 时间戳赋值给 {@link TRTCVideoFrame} 或 {@link TRTCAudioFrame} 中的 timestamp 字段。
|
|
3286
|
+
*
|
|
3287
|
+
*
|
|
3288
|
+
* @returns {Number} - 时间戳(单位:ms)
|
|
3289
|
+
*/
|
|
3290
|
+
generateCustomPTS() {
|
|
3291
|
+
return this.rtcCloud.generateCustomPTS();
|
|
3292
|
+
}
|
|
3180
3293
|
/**
|
|
3181
3294
|
* @private
|
|
3182
3295
|
* 设置本地视频自定义渲染(Electron 平台下不可用)
|
|
@@ -3433,7 +3546,7 @@ class TRTCCloud extends events_1.EventEmitter {
|
|
|
3433
3546
|
* @example
|
|
3434
3547
|
* // 音乐播放
|
|
3435
3548
|
* import TRTCCloud, { AudioMusicParam } from 'trtc-electron-sdk';
|
|
3436
|
-
* const rtcCloud =
|
|
3549
|
+
* const rtcCloud = TRTCCloud.getTRTCShareInstance();
|
|
3437
3550
|
*
|
|
3438
3551
|
* const params = new AudioMusicParam();
|
|
3439
3552
|
* params.id = 1;
|
package/liteav/trtc_define.d.ts
CHANGED
|
@@ -84,6 +84,12 @@ export declare enum TRTCRecordType {
|
|
|
84
84
|
/** 同时录制音频、视频 */
|
|
85
85
|
TRTCRecordTypeBoth = 2
|
|
86
86
|
}
|
|
87
|
+
export type TRTCAudioParallelParams = {
|
|
88
|
+
/** 最大并发播放数。默认值:0 */
|
|
89
|
+
maxCount: number;
|
|
90
|
+
/** 指定用户必定能并发播放 */
|
|
91
|
+
includeUsers: Array<string>;
|
|
92
|
+
};
|
|
87
93
|
export declare enum TRTCAppScene {
|
|
88
94
|
TRTCAppSceneVideoCall = 0,
|
|
89
95
|
TRTCAppSceneLIVE = 1,
|
|
@@ -226,6 +232,29 @@ export declare class TRTCVideoFrame {
|
|
|
226
232
|
rotation: number;
|
|
227
233
|
constructor(videoFormat?: TRTCVideoPixelFormat, bufferType?: TRTCVideoBufferType, data?: null | ArrayBuffer, textureId?: number, length?: number, width?: number, height?: number, timestamp?: number, rotation?: number);
|
|
228
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* 音频帧数据
|
|
237
|
+
*
|
|
238
|
+
* @param {TRTCAudioFrameFormat} audioFormat - 音频帧的格式
|
|
239
|
+
* @param {ArrayBuffer} data - 音频数据
|
|
240
|
+
* @param {Number} length - 音频数据的长度
|
|
241
|
+
* @param {Number} sampleRate - 采样率
|
|
242
|
+
* @param {Number} channel - 声道数
|
|
243
|
+
* @param {Number} timestamp - 时间戳,单位ms
|
|
244
|
+
* @param {ArrayBuffer|null} extraData - 音频额外数据,远端用户通过 `onLocalProcessedAudioFrame` 写入的数据会通过该字段回调
|
|
245
|
+
* @param {Number} extraDataLength - 音频消息数据的长度
|
|
246
|
+
*/
|
|
247
|
+
export declare class TRTCAudioFrame {
|
|
248
|
+
audioFormat: TRTCAudioFrameFormat;
|
|
249
|
+
data: ArrayBuffer | null;
|
|
250
|
+
length: number;
|
|
251
|
+
sampleRate: number;
|
|
252
|
+
channel: number;
|
|
253
|
+
timestamp: number;
|
|
254
|
+
extraData: ArrayBuffer | null;
|
|
255
|
+
extraDataLength: number;
|
|
256
|
+
constructor(audioFormat?: TRTCAudioFrameFormat, data?: any, length?: number, sampleRate?: number, channel?: number, timestamp?: number, extraData?: any, extraDataLength?: number);
|
|
257
|
+
}
|
|
229
258
|
export declare enum TRTCLogLevel {
|
|
230
259
|
TRTCLogLevelNone = 0,
|
|
231
260
|
TRTCLogLevelVerbose = 1,
|
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 = void 0;
|
|
9
|
+
exports.AudioMusicParam = exports.TRTCStatistics = exports.TRTCRemoteStatistics = exports.TRTCLocalStatistics = exports.TRTCAudioEffectParam = exports.TRTCAudioRecordingParams = exports.TRTCPublishCDNParam = exports.TRTCTranscodingConfig = 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.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 = void 0;
|
|
11
11
|
const util_1 = require("./Renderer/util");
|
|
12
12
|
/////////////////////////////////////////////////////////////////////////////////
|
|
13
13
|
//
|
|
@@ -338,6 +338,15 @@ var TRTCRecordType;
|
|
|
338
338
|
/** 同时录制音频、视频 */
|
|
339
339
|
TRTCRecordType[TRTCRecordType["TRTCRecordTypeBoth"] = 2] = "TRTCRecordTypeBoth";
|
|
340
340
|
})(TRTCRecordType = exports.TRTCRecordType || (exports.TRTCRecordType = {}));
|
|
341
|
+
/**
|
|
342
|
+
* 设置远端音频流智能并发播放策略
|
|
343
|
+
*
|
|
344
|
+
* @typedef {Object} TRTCAudioParallelParam
|
|
345
|
+
* @property {Number} maxCount - 最大并发播放数
|
|
346
|
+
* @property {Array<String>} includeUsers - 指定用户必定能并发播放
|
|
347
|
+
*
|
|
348
|
+
*/
|
|
349
|
+
const TRTCAudioParallelParams_HACK_JSDOC = null;
|
|
341
350
|
/////////////////////////////////////////////////////////////////////////////////
|
|
342
351
|
//
|
|
343
352
|
// 【(二)网络相关枚举值定义】
|
|
@@ -648,6 +657,32 @@ class TRTCVideoFrame {
|
|
|
648
657
|
}
|
|
649
658
|
exports.TRTCVideoFrame = TRTCVideoFrame;
|
|
650
659
|
;
|
|
660
|
+
/**
|
|
661
|
+
* 音频帧数据
|
|
662
|
+
*
|
|
663
|
+
* @param {TRTCAudioFrameFormat} audioFormat - 音频帧的格式
|
|
664
|
+
* @param {ArrayBuffer} data - 音频数据
|
|
665
|
+
* @param {Number} length - 音频数据的长度
|
|
666
|
+
* @param {Number} sampleRate - 采样率
|
|
667
|
+
* @param {Number} channel - 声道数
|
|
668
|
+
* @param {Number} timestamp - 时间戳,单位ms
|
|
669
|
+
* @param {ArrayBuffer|null} extraData - 音频额外数据,远端用户通过 `onLocalProcessedAudioFrame` 写入的数据会通过该字段回调
|
|
670
|
+
* @param {Number} extraDataLength - 音频消息数据的长度
|
|
671
|
+
*/
|
|
672
|
+
class TRTCAudioFrame {
|
|
673
|
+
constructor(audioFormat = TRTCAudioFrameFormat.TRTCAudioFrameFormatNone, data = null, length = 0, sampleRate = 48000, channel = 1, timestamp = 0, extraData = null, extraDataLength = 0) {
|
|
674
|
+
this.audioFormat = audioFormat;
|
|
675
|
+
this.data = data;
|
|
676
|
+
this.length = length;
|
|
677
|
+
this.sampleRate = sampleRate;
|
|
678
|
+
this.channel = channel;
|
|
679
|
+
this.timestamp = timestamp;
|
|
680
|
+
this.extraData = extraData;
|
|
681
|
+
this.extraDataLength = extraDataLength;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
exports.TRTCAudioFrame = TRTCAudioFrame;
|
|
685
|
+
;
|
|
651
686
|
/////////////////////////////////////////////////////////////////////////////////
|
|
652
687
|
//
|
|
653
688
|
// 【(四)更多枚举值定义】
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trtc-electron-sdk",
|
|
3
|
-
"version": "11.3.502-beta.
|
|
3
|
+
"version": "11.3.502-beta.7",
|
|
4
4
|
"description": "trtc electron sdk",
|
|
5
5
|
"main": "./liteav/trtc.js",
|
|
6
6
|
"types": "./liteav/trtc.d.ts",
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
"yuv-canvas": "^1.2.6",
|
|
19
19
|
"hpagent": "^1.2.0"
|
|
20
20
|
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"electron": ">=4.0.0"
|
|
23
|
+
},
|
|
21
24
|
"devDependencies": {
|
|
22
25
|
"@babel/cli": "^7.11.6",
|
|
23
26
|
"@babel/core": "^7.11.6",
|
|
@@ -37,6 +40,7 @@
|
|
|
37
40
|
"scripts": {
|
|
38
41
|
"download": "node ./scripts/download.js",
|
|
39
42
|
"install": "npm run download",
|
|
43
|
+
"postinstall": "node ./scripts/postinstall.js",
|
|
40
44
|
"build": "npm run build:types && npm run build:js && npm run copy:types",
|
|
41
45
|
"build:types": "rimraf ./types && tsc -p dtsconfig.json",
|
|
42
46
|
"build:js": "rimraf ./liteav && tsc -p tsconfig.json",
|
package/scripts/download.js
CHANGED
|
@@ -142,9 +142,6 @@ const main = () => {
|
|
|
142
142
|
);
|
|
143
143
|
signale.success(`copy success! - mac ${anotherArch}`);
|
|
144
144
|
|
|
145
|
-
// Mac 下完成文件下载后,执行该命令,同步文件到 Electron 目录下
|
|
146
|
-
exec(`rsync -a ../../node_modules/trtc-electron-sdk/build/mac-framework/${archType}/ ../../node_modules/electron/dist/Electron.app/Contents/Frameworks`);
|
|
147
|
-
|
|
148
145
|
rimraf.sync(outputDir);
|
|
149
146
|
})
|
|
150
147
|
.catch(err => {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const { exec } = require('child_process');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const { arch, platform } = process;
|
|
5
|
+
|
|
6
|
+
let retryCount = 0;
|
|
7
|
+
const retryInterval = 5000; // ms
|
|
8
|
+
const maxRetryCount = 60;
|
|
9
|
+
|
|
10
|
+
function rsync() {
|
|
11
|
+
if (platform === 'darwin') {
|
|
12
|
+
const sourcePath = path.join(__dirname, `../../trtc-electron-sdk/build/mac-framework/${arch}/`);
|
|
13
|
+
const targetPath = path.join(__dirname, '../../electron/dist/Electron.app/Contents/Frameworks');
|
|
14
|
+
|
|
15
|
+
if (targetPath.indexOf("node_modules") === -1) {
|
|
16
|
+
// SDK 本身安装,不用同步动态库,直接退出
|
|
17
|
+
console.warn(`trtc-electron-sdk self install do not need 'rsync'`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
retryCount++;
|
|
22
|
+
if (fs.existsSync(targetPath)) {
|
|
23
|
+
const command = `rsync -a ${sourcePath} ${targetPath}`;
|
|
24
|
+
console.log(command);
|
|
25
|
+
exec(command);
|
|
26
|
+
} else {
|
|
27
|
+
if (retryCount <= maxRetryCount) {
|
|
28
|
+
setTimeout(rsync, retryInterval);
|
|
29
|
+
} else {
|
|
30
|
+
const errorMessage = `
|
|
31
|
+
'trtc-electron-sdk' 安装失败,请先确认 'Electron' 已安装,再执行 'npm install trtc-electron-sdk' 命令重新安装一次。
|
|
32
|
+
Failed to install trtc-electron-sdk correctly, please make sure that 'Electron' has been installed, then run 'npm install trtc-electron-sdk' command to try again.
|
|
33
|
+
|
|
34
|
+
more detail:
|
|
35
|
+
trtc-electron-sdk postinstall cwd: ${process.cwd()}
|
|
36
|
+
__dirname: ${__dirname}
|
|
37
|
+
sourcePath: ${sourcePath}
|
|
38
|
+
targetPath: ${targetPath}
|
|
39
|
+
`;
|
|
40
|
+
console.error(errorMessage);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
rsync();
|