trtc-electron-sdk 11.8.603-beta.4 → 11.8.603

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.
@@ -0,0 +1,21 @@
1
+ import TRTCCloud from '../trtc';
2
+ declare class LocalVideoRenderController {
3
+ private logPrefix;
4
+ private trtcCloud;
5
+ private currentState;
6
+ private isExternalRenderEnabled;
7
+ private isLocalPreviewStarted;
8
+ private hasLocalPreviewView;
9
+ private isLocalSharingStarted;
10
+ private hasLocalSharingView;
11
+ constructor(trtcCloud: TRTCCloud);
12
+ startLocalPreview(views: Array<HTMLElement> | HTMLElement | null): void;
13
+ stopLocalPreview(): void;
14
+ updateLocalView(views: Array<HTMLElement> | HTMLElement | null): void;
15
+ startScreenCapture(view?: HTMLElement | null): void;
16
+ stopScreenCapture(): void;
17
+ setExternalRenderEnabled(enabled: boolean): void;
18
+ private update;
19
+ private calcTargetState;
20
+ }
21
+ export default LocalVideoRenderController;
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const type_1 = require("./type");
7
+ const logger_1 = __importDefault(require("../logger"));
8
+ class LocalVideoRenderController {
9
+ constructor(trtcCloud) {
10
+ this.logPrefix = '[LocalVideoRenderController]';
11
+ this.trtcCloud = trtcCloud;
12
+ this.currentState = type_1.LocalVideoRenderCallbackState.NotListening;
13
+ this.isExternalRenderEnabled = false;
14
+ this.isLocalPreviewStarted = false;
15
+ this.hasLocalPreviewView = false;
16
+ this.isLocalSharingStarted = false;
17
+ this.hasLocalSharingView = false;
18
+ }
19
+ startLocalPreview(views) {
20
+ this.isLocalPreviewStarted = true;
21
+ this.hasLocalPreviewView = views !== null && views !== undefined;
22
+ if (Array.isArray(views)) {
23
+ this.hasLocalPreviewView = views.length >= 1;
24
+ }
25
+ this.update();
26
+ }
27
+ stopLocalPreview() {
28
+ this.isLocalPreviewStarted = false;
29
+ this.hasLocalPreviewView = false;
30
+ this.update();
31
+ }
32
+ updateLocalView(views) {
33
+ this.hasLocalPreviewView = views !== null && views !== undefined;
34
+ if (Array.isArray(views)) {
35
+ this.hasLocalPreviewView = views.length >= 1;
36
+ }
37
+ this.update();
38
+ }
39
+ startScreenCapture(view = null) {
40
+ this.isLocalSharingStarted = true;
41
+ this.hasLocalSharingView = view !== null && view !== undefined;
42
+ this.update();
43
+ }
44
+ stopScreenCapture() {
45
+ this.isLocalSharingStarted = false;
46
+ this.hasLocalSharingView = false;
47
+ this.update();
48
+ }
49
+ setExternalRenderEnabled(enabled) {
50
+ this.isExternalRenderEnabled = enabled;
51
+ }
52
+ update() {
53
+ const targetState = this.calcTargetState();
54
+ if (targetState !== this.currentState) {
55
+ if (targetState === type_1.LocalVideoRenderCallbackState.NotListening) {
56
+ logger_1.default.log(`${this.logPrefix}update not listening`);
57
+ this.trtcCloud.removeLocalVideoRenderCallback();
58
+ }
59
+ else {
60
+ logger_1.default.log(`${this.logPrefix}update listening`);
61
+ this.trtcCloud.addLocalVideoRenderCallback();
62
+ }
63
+ this.currentState = targetState;
64
+ }
65
+ else {
66
+ return;
67
+ }
68
+ }
69
+ calcTargetState() {
70
+ if (this.isExternalRenderEnabled) {
71
+ return type_1.LocalVideoRenderCallbackState.Listening;
72
+ }
73
+ if (this.isLocalPreviewStarted && this.hasLocalPreviewView) {
74
+ return type_1.LocalVideoRenderCallbackState.Listening;
75
+ }
76
+ if (this.isLocalSharingStarted && this.hasLocalSharingView) {
77
+ return type_1.LocalVideoRenderCallbackState.Listening;
78
+ }
79
+ return type_1.LocalVideoRenderCallbackState.NotListening;
80
+ }
81
+ }
82
+ exports.default = LocalVideoRenderController;
@@ -0,0 +1,4 @@
1
+ export declare enum LocalVideoRenderCallbackState {
2
+ Listening = 1,
3
+ NotListening = 2
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocalVideoRenderCallbackState = void 0;
4
+ var LocalVideoRenderCallbackState;
5
+ (function (LocalVideoRenderCallbackState) {
6
+ LocalVideoRenderCallbackState[LocalVideoRenderCallbackState["Listening"] = 1] = "Listening";
7
+ LocalVideoRenderCallbackState[LocalVideoRenderCallbackState["NotListening"] = 2] = "NotListening";
8
+ })(LocalVideoRenderCallbackState = exports.LocalVideoRenderCallbackState || (exports.LocalVideoRenderCallbackState = {}));
package/liteav/trtc.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from 'events';
3
3
  import { TRTCConfig } from './Renderer/util';
4
- import { AudioMusicParam, Rect, TRTCAppScene, TRTCAudioEffectParam, TRTCAudioQuality, TRTCBeautyStyle, TRTCDeviceState, TRTCDeviceType, TRTCLogLevel, TRTCRenderParams, TRTCRoleType, TRTCSpeedTestResult, TRTCStatistics, TRTCSwitchRoomParam, TRTCVideoBufferType, TRTCVideoFillMode, TRTCAudioFrame, TRTCVideoPixelFormat, TRTCVideoRotation, TRTCVideoStreamType, TRTCVolumeInfo, TRTCWaterMarkSrcType, TRTCQualityInfo, TRTCPluginType, TRTCPluginInfo, TRTCVideoProcessPluginOptions, TRTCMediaEncryptDecryptPluginOptions, TRTCAudioRecordingParams, TRTCScreenCaptureSourceInfo, TRTCScreenCaptureProperty, TRTCSpeedTestParams, TRTCRecordType, TRTCDeviceInfo, TRTCCameraCaptureParams, TRTCImageBuffer, TRTCInitConfig, TRTCAudioParallelParams, TRTCVoiceReverbType, TRTCMusicPlayObserver } from './trtc_define';
4
+ import { AudioMusicParam, Rect, TRTCAppScene, TRTCAudioEffectParam, TRTCAudioQuality, TRTCBeautyStyle, TRTCDeviceState, TRTCDeviceType, TRTCLogLevel, TRTCRenderParams, TRTCRoleType, TRTCSpeedTestResult, TRTCStatistics, TRTCSwitchRoomParam, TRTCVideoBufferType, TRTCVideoFillMode, TRTCAudioFrame, TRTCVideoPixelFormat, TRTCVideoRotation, TRTCVideoStreamType, TRTCVolumeInfo, TRTCWaterMarkSrcType, TRTCQualityInfo, TRTCPluginType, TRTCPluginInfo, TRTCVideoProcessPluginOptions, TRTCMediaEncryptDecryptPluginOptions, TRTCAudioRecordingParams, TRTCScreenCaptureSourceInfo, TRTCScreenCaptureProperty, TRTCSpeedTestParams, TRTCRecordType, TRTCDeviceInfo, TRTCCameraCaptureParams, TRTCImageBuffer, TRTCInitConfig, TRTCAudioParallelParams, TRTCVoiceReverbType, TRTCMusicPlayObserver, TRTCAudioFrameCallback } from './trtc_define';
5
5
  export * from './trtc_define';
6
6
  export * from './trtc_code';
7
7
  export * from './vod_player';
@@ -40,6 +40,7 @@ declare class TRTCCloud extends EventEmitter {
40
40
  private videoProcessBufferType;
41
41
  private videoProcessPixelFormat;
42
42
  private videoRenderFPS;
43
+ private localVideoRenderController;
43
44
  private localRotation;
44
45
  private localMirrorType;
45
46
  private remoteMainStreamFillMode;
@@ -1895,6 +1896,51 @@ declare class TRTCCloud extends EventEmitter {
1895
1896
  * @returns {Number} - 时间戳(单位:ms)
1896
1897
  */
1897
1898
  generateCustomPTS(): number;
1899
+ /**
1900
+ * 设置音频数据自定义回调
1901
+ *
1902
+ * 设置该回调之后,SDK 内部会把音频数据(PCM 格式)回调出来,包括:
1903
+ * {onCapturedAudioFrame}:本地麦克风采集到的音频数据回调
1904
+ * - {onLocalProcessedAudioFrame}:本地采集并经过音频模块前处理后的音频数据回调
1905
+ * - {onPlayAudioFrame}:混音前的每一路远程用户的音频数据
1906
+ * - {onMixedPlayAudioFrame}:将各路音频混合之后并最终要由系统播放出的音频数据回调
1907
+ * - {onMixedAllAudioFrame}:SDK 所有音频混合后的音频数据(包括采集到的和待播放的)
1908
+ *
1909
+ * 注意: 设置回调为空即代表停止自定义音频回调,反之,设置回调不为空则代表启动自定义音频回调。
1910
+ *
1911
+ * @example
1912
+ * import TRTCCloud from 'trtc-electron-sdk';
1913
+ *
1914
+ * const rtcCloud = TRTCCloud.getTRTCShareInstance();
1915
+ *
1916
+ * onCapturedAudioFrame(frame: TRTCAudioFrame) {}
1917
+ * onLocalProcessedAudioFrame(frame: TRTCAudioFrame) {}
1918
+ * onPlayAudioFrame(frame: TRTCAudioFrame, userId: string) {}
1919
+ * onMixedPlayAudioFrame(frame: TRTCAudioFrame) {}
1920
+ * onMixedAllAudioFrame(frame: TRTCAudioFrame) {}
1921
+ *
1922
+ * // 设置音频数据自定义回调
1923
+ * rtcCloud.setAudioFrameCallback({
1924
+ * onCapturedAudioFrame: onCapturedAudioFrame,
1925
+ * onLocalProcessedAudioFrame: onLocalProcessedAudioFrame,
1926
+ * onPlayAudioFrame: onPlayAudioFrame,
1927
+ * onMixedPlayAudioFrame: onMixedPlayAudioFrame,
1928
+ * onMixedAllAudioFrame: onMixedAllAudioFrame,
1929
+ * });
1930
+ *
1931
+ * // 取消音频数据自定义回调
1932
+ * rtcCloud.setAudioFrameCallback({
1933
+ * onCapturedAudioFrame: null,
1934
+ * onLocalProcessedAudioFrame: null,
1935
+ * onPlayAudioFrame: null,
1936
+ * onMixedPlayAudioFrame: null,
1937
+ * onMixedAllAudioFrame: null,
1938
+ * });
1939
+ *
1940
+ * @param {TRTCAudioFrameCallback} callback - 音频数据自定义回调对象。
1941
+ *
1942
+ */
1943
+ setAudioFrameCallback(callback: TRTCAudioFrameCallback): void;
1898
1944
  /**
1899
1945
  * @private
1900
1946
  * 设置本地视频自定义渲染(Electron 平台下不可用)
@@ -1906,7 +1952,7 @@ declare class TRTCCloud extends EventEmitter {
1906
1952
  * @param {Fuction} callback 自定义渲染回调
1907
1953
  * @return {Number} 0:成功;<0:错误
1908
1954
  */
1909
- setLocalVideoRenderCallback(pixelFormat: TRTCVideoPixelFormat, bufferType: TRTCVideoBufferType, callback: () => void): 0 | -1;
1955
+ setLocalVideoRenderCallback(pixelFormat: TRTCVideoPixelFormat, bufferType: TRTCVideoBufferType, callback: () => void): number;
1910
1956
  /**
1911
1957
  * @private
1912
1958
  * 设置远端视频自定义渲染(Electron 平台下不可用)
@@ -1921,7 +1967,7 @@ declare class TRTCCloud extends EventEmitter {
1921
1967
  * @param {Function} callback 自定义渲染回调
1922
1968
  * @return {Number} 0:成功;<0:错误
1923
1969
  */
1924
- setRemoteVideoRenderCallback(userId: string, pixelFormat: TRTCVideoPixelFormat, bufferType: TRTCVideoBufferType, callback: () => void): 0 | -1;
1970
+ setRemoteVideoRenderCallback(userId: string, pixelFormat: TRTCVideoPixelFormat, bufferType: TRTCVideoBufferType, callback: () => void): number;
1925
1971
  /**
1926
1972
  * 发送自定义消息给房间内所有用户
1927
1973
  *
@@ -2359,8 +2405,12 @@ declare class TRTCCloud extends EventEmitter {
2359
2405
  * @param {String} jsonStr - 接口及参数描述的 JSON 字符串
2360
2406
  */
2361
2407
  callExperimentalAPI(jsonStr: string): void;
2408
+ private _localVideoRenderCallback;
2362
2409
  addLocalVideoRenderCallback(): void;
2410
+ removeLocalVideoRenderCallback(): void;
2411
+ private _remoteVideoRenderCallback;
2363
2412
  addRemoteVideoRenderCallback(userId: string): void;
2413
+ removeRemoteVideoRenderCallback(userId: string): void;
2364
2414
  /**
2365
2415
  * 废弃接口:选择绘制的模式 (webgl/yuvcanvs/)
2366
2416
  *
package/liteav/trtc.js CHANGED
@@ -35,6 +35,7 @@ const YCbCr_1 = __importDefault(require("yuv-canvas/src/YCbCr"));
35
35
  const trtc_define_1 = require("./trtc_define");
36
36
  const validate_util_1 = require("./validate-util");
37
37
  const logger_1 = __importStar(require("./logger"));
38
+ const LocalVideoRenderController_1 = __importDefault(require("./VideoRenderControl/LocalVideoRenderController"));
38
39
  const NodeTRTCEngine = require('../build/Release/trtc_electron_sdk.node');
39
40
  const pkg = require('../package.json');
40
41
  __exportStar(require("./trtc_define"), exports);
@@ -206,6 +207,9 @@ class TRTCCloud extends events_1.EventEmitter {
206
207
  this.videoRenderFPS = 15;
207
208
  this.setVideoRenderFPS(this.videoRenderFPS);
208
209
  this.callExperimentalAPI("{\"api\":\"setCurrentEnvironment\",\"params\" :{\"electron\":true}}");
210
+ this._localVideoRenderCallback = this._localVideoRenderCallback.bind(this);
211
+ this._remoteVideoRenderCallback = this._remoteVideoRenderCallback.bind(this);
212
+ this.localVideoRenderController = new LocalVideoRenderController_1.default(this);
209
213
  if (!TRTCCloud.sharedTRTCCloudInstance) {
210
214
  TRTCCloud.sharedTRTCCloudInstance = this;
211
215
  }
@@ -277,6 +281,7 @@ class TRTCCloud extends events_1.EventEmitter {
277
281
  }
278
282
  setExternalRenderEnabled(enabled) {
279
283
  this.isExternalRenderEnabled = enabled;
284
+ this.localVideoRenderController.setExternalRenderEnabled(enabled);
280
285
  if (this.isExternalRenderEnabled) {
281
286
  this.pixelFormat = trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_RGBA32;
282
287
  this.pixelLength = 4;
@@ -1792,7 +1797,6 @@ class TRTCCloud extends events_1.EventEmitter {
1792
1797
  this.rtcCloud.setLocalVideoBuffer('', this.localVideoBufferMap.big.buffer, trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeBig, this.localVideoBufferMap.big.width, this.localVideoBufferMap.big.height, this.localVideoBufferMap.big.pixelFormat, this.localVideoBufferMap.big.id);
1793
1798
  }
1794
1799
  this.rtcCloud.startLocalPreview();
1795
- this.addLocalVideoRenderCallback();
1796
1800
  }
1797
1801
  /**
1798
1802
  * 启动本地摄像头采集和预览
@@ -1817,6 +1821,7 @@ class TRTCCloud extends events_1.EventEmitter {
1817
1821
  else {
1818
1822
  this._startLocalPreview([]);
1819
1823
  }
1824
+ this.localVideoRenderController.startLocalPreview(views);
1820
1825
  }
1821
1826
  else {
1822
1827
  this.logger.error('startLocalPreview parameter is undefined, it should be Array<HTMLElement>, HTMLElement or null');
@@ -1829,6 +1834,7 @@ class TRTCCloud extends events_1.EventEmitter {
1829
1834
  this.logger.debug(`stopLocalPreview`);
1830
1835
  const key = this._getKey(LOCAL_USER_VIDEO_ID, trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeBig);
1831
1836
  this._destroyRenderer(key, null);
1837
+ this.localVideoRenderController.stopLocalPreview();
1832
1838
  this.rtcCloud.stopLocalPreview();
1833
1839
  if (this.localVideoBufferMap.big.buffer) {
1834
1840
  this.rtcCloud.setLocalVideoBuffer('', this.localVideoBufferMap.big.buffer, trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeBig, 0, 0, this.localVideoBufferMap.big.pixelFormat, this.localVideoBufferMap.big.id);
@@ -1862,6 +1868,7 @@ class TRTCCloud extends events_1.EventEmitter {
1862
1868
  else {
1863
1869
  this._destroyRenderer(key, null);
1864
1870
  }
1871
+ this.localVideoRenderController.updateLocalView(views);
1865
1872
  }
1866
1873
  else {
1867
1874
  this.logger.error('updateLocalView parameter is undefined, it should be Array<HTMLElement>, HTMLElement or null');
@@ -3142,7 +3149,7 @@ class TRTCCloud extends events_1.EventEmitter {
3142
3149
  const key = this._getKey(LOCAL_USER_VIDEO_ID, type);
3143
3150
  this._initRenderer(key, [view]);
3144
3151
  }
3145
- this.addLocalVideoRenderCallback();
3152
+ this.localVideoRenderController.startScreenCapture(view);
3146
3153
  }
3147
3154
  if (params) {
3148
3155
  this.rtcCloud.startScreenCapture(type, params);
@@ -3169,6 +3176,7 @@ class TRTCCloud extends events_1.EventEmitter {
3169
3176
  stopScreenCapture() {
3170
3177
  const key = this._getKey(LOCAL_USER_VIDEO_ID, this.screenCaptureStreamType);
3171
3178
  this._destroyRenderer(key, null);
3179
+ this.localVideoRenderController.stopScreenCapture();
3172
3180
  this.rtcCloud.stopScreenCapture();
3173
3181
  this.screenCaptureStreamType = trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeSub;
3174
3182
  }
@@ -3387,6 +3395,53 @@ class TRTCCloud extends events_1.EventEmitter {
3387
3395
  generateCustomPTS() {
3388
3396
  return this.rtcCloud.generateCustomPTS();
3389
3397
  }
3398
+ /**
3399
+ * 设置音频数据自定义回调
3400
+ *
3401
+ * 设置该回调之后,SDK 内部会把音频数据(PCM 格式)回调出来,包括:
3402
+ * {onCapturedAudioFrame}:本地麦克风采集到的音频数据回调
3403
+ * - {onLocalProcessedAudioFrame}:本地采集并经过音频模块前处理后的音频数据回调
3404
+ * - {onPlayAudioFrame}:混音前的每一路远程用户的音频数据
3405
+ * - {onMixedPlayAudioFrame}:将各路音频混合之后并最终要由系统播放出的音频数据回调
3406
+ * - {onMixedAllAudioFrame}:SDK 所有音频混合后的音频数据(包括采集到的和待播放的)
3407
+ *
3408
+ * 注意: 设置回调为空即代表停止自定义音频回调,反之,设置回调不为空则代表启动自定义音频回调。
3409
+ *
3410
+ * @example
3411
+ * import TRTCCloud from 'trtc-electron-sdk';
3412
+ *
3413
+ * const rtcCloud = TRTCCloud.getTRTCShareInstance();
3414
+ *
3415
+ * onCapturedAudioFrame(frame: TRTCAudioFrame) {}
3416
+ * onLocalProcessedAudioFrame(frame: TRTCAudioFrame) {}
3417
+ * onPlayAudioFrame(frame: TRTCAudioFrame, userId: string) {}
3418
+ * onMixedPlayAudioFrame(frame: TRTCAudioFrame) {}
3419
+ * onMixedAllAudioFrame(frame: TRTCAudioFrame) {}
3420
+ *
3421
+ * // 设置音频数据自定义回调
3422
+ * rtcCloud.setAudioFrameCallback({
3423
+ * onCapturedAudioFrame: onCapturedAudioFrame,
3424
+ * onLocalProcessedAudioFrame: onLocalProcessedAudioFrame,
3425
+ * onPlayAudioFrame: onPlayAudioFrame,
3426
+ * onMixedPlayAudioFrame: onMixedPlayAudioFrame,
3427
+ * onMixedAllAudioFrame: onMixedAllAudioFrame,
3428
+ * });
3429
+ *
3430
+ * // 取消音频数据自定义回调
3431
+ * rtcCloud.setAudioFrameCallback({
3432
+ * onCapturedAudioFrame: null,
3433
+ * onLocalProcessedAudioFrame: null,
3434
+ * onPlayAudioFrame: null,
3435
+ * onMixedPlayAudioFrame: null,
3436
+ * onMixedAllAudioFrame: null,
3437
+ * });
3438
+ *
3439
+ * @param {TRTCAudioFrameCallback} callback - 音频数据自定义回调对象。
3440
+ *
3441
+ */
3442
+ setAudioFrameCallback(callback) {
3443
+ this.rtcCloud.setAudioFrameCallback(callback.onCapturedAudioFrame, callback.onLocalProcessedAudioFrame, callback.onPlayAudioFrame, callback.onMixedPlayAudioFrame, callback.onMixedAllAudioFrame);
3444
+ }
3390
3445
  /**
3391
3446
  * @private
3392
3447
  * 设置本地视频自定义渲染(Electron 平台下不可用)
@@ -4102,56 +4157,67 @@ class TRTCCloud extends events_1.EventEmitter {
4102
4157
  //
4103
4158
  /////////////////////////////////////////////////////////////////////////////////
4104
4159
  ///------------------------内部方法-----------------------------
4105
- addLocalVideoRenderCallback() {
4106
- this.rtcCloud.addLocalVideoRenderCallback((args) => {
4107
- const [id, type, width, height, timestamp, rotation, valid, bufferId] = args;
4108
- if (this.enableRenderFrame) {
4109
- if (valid === true) {
4110
- if (this.isScreenCapturing
4111
- && this.screenCaptureStreamType === type
4112
- && this.localVideoBufferMap.sub
4113
- && this.localVideoBufferMap.sub.id === bufferId) {
4114
- this._onRenderFrame(id, type, width, height, timestamp, rotation, this.localVideoBufferMap.sub.buffer);
4115
- }
4116
- else if (this.localVideoBufferMap.big.id === bufferId) {
4117
- this._onRenderFrame(id, type, width, height, timestamp, rotation, this.localVideoBufferMap.big.buffer);
4118
- }
4119
- else {
4120
- this.logger.log(`${id} ${type} video buffer reallocated`);
4121
- }
4160
+ _localVideoRenderCallback(args) {
4161
+ const [id, type, width, height, timestamp, rotation, valid, bufferId] = args;
4162
+ if (this.enableRenderFrame) {
4163
+ if (valid === true) {
4164
+ if (this.isScreenCapturing
4165
+ && this.screenCaptureStreamType === type
4166
+ && this.localVideoBufferMap.sub
4167
+ && this.localVideoBufferMap.sub.id === bufferId) {
4168
+ this._onRenderFrame(id, type, width, height, timestamp, rotation, this.localVideoBufferMap.sub.buffer);
4169
+ }
4170
+ else if (this.localVideoBufferMap.big.id === bufferId) {
4171
+ this._onRenderFrame(id, type, width, height, timestamp, rotation, this.localVideoBufferMap.big.buffer);
4122
4172
  }
4123
4173
  else {
4124
- this.handleVideoSizeChange(id, type, width, height);
4174
+ this.logger.log(`${id} ${type} video buffer reallocated`);
4125
4175
  }
4126
4176
  }
4127
- }, this.pixelFormat);
4177
+ else {
4178
+ this.handleVideoSizeChange(id, type, width, height);
4179
+ }
4180
+ }
4128
4181
  }
4129
- addRemoteVideoRenderCallback(userId) {
4130
- this.rtcCloud.addRemoteVideoRenderCallback(userId, (args) => {
4131
- const [id, type, width, height, timestamp, rotation, valid, bufferId] = args;
4132
- if (this.enableRenderFrame) {
4133
- if (valid === true) {
4134
- const remoteUserVideoBuffers = this.remoteVideoBufferMap.get(id);
4135
- if (remoteUserVideoBuffers) {
4136
- if (type === trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeBig && remoteUserVideoBuffers.big && remoteUserVideoBuffers.big.id === bufferId) {
4137
- this._onRenderFrame(id, type, width, height, timestamp, rotation, remoteUserVideoBuffers.big.buffer);
4138
- }
4139
- else if (type === trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeSmall && remoteUserVideoBuffers.small && remoteUserVideoBuffers.small.id === bufferId) {
4140
- this._onRenderFrame(id, type, width, height, timestamp, rotation, remoteUserVideoBuffers.small.buffer);
4141
- }
4142
- else if (type === trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeSub && remoteUserVideoBuffers.sub && remoteUserVideoBuffers.sub.id === bufferId) {
4143
- this._onRenderFrame(id, type, width, height, timestamp, rotation, remoteUserVideoBuffers.sub.buffer);
4144
- }
4182
+ addLocalVideoRenderCallback() {
4183
+ this.rtcCloud.addLocalVideoRenderCallback(this._localVideoRenderCallback, this.pixelFormat);
4184
+ }
4185
+ removeLocalVideoRenderCallback() {
4186
+ this.rtcCloud.removeLocalVideoRenderCallback();
4187
+ }
4188
+ _remoteVideoRenderCallback(args) {
4189
+ const [id, type, width, height, timestamp, rotation, valid, bufferId] = args;
4190
+ if (this.enableRenderFrame) {
4191
+ if (valid === true) {
4192
+ const remoteUserVideoBuffers = this.remoteVideoBufferMap.get(id);
4193
+ if (remoteUserVideoBuffers) {
4194
+ if (type === trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeBig && remoteUserVideoBuffers.big && remoteUserVideoBuffers.big.id === bufferId) {
4195
+ this._onRenderFrame(id, type, width, height, timestamp, rotation, remoteUserVideoBuffers.big.buffer);
4196
+ }
4197
+ else if (type === trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeSmall && remoteUserVideoBuffers.small && remoteUserVideoBuffers.small.id === bufferId) {
4198
+ this._onRenderFrame(id, type, width, height, timestamp, rotation, remoteUserVideoBuffers.small.buffer);
4199
+ }
4200
+ else if (type === trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeSub && remoteUserVideoBuffers.sub && remoteUserVideoBuffers.sub.id === bufferId) {
4201
+ this._onRenderFrame(id, type, width, height, timestamp, rotation, remoteUserVideoBuffers.sub.buffer);
4145
4202
  }
4146
4203
  else {
4147
4204
  this.logger.log(`${id} ${type} video buffer reallocated`);
4148
4205
  }
4149
4206
  }
4150
4207
  else {
4151
- this.handleVideoSizeChange(id, type, width, height);
4208
+ this.logger.warn(`no remote video render for frame:`, args);
4152
4209
  }
4153
4210
  }
4154
- }, this.pixelFormat);
4211
+ else {
4212
+ this.handleVideoSizeChange(id, type, width, height);
4213
+ }
4214
+ }
4215
+ }
4216
+ addRemoteVideoRenderCallback(userId) {
4217
+ this.rtcCloud.addRemoteVideoRenderCallback(userId, this._remoteVideoRenderCallback, this.pixelFormat);
4218
+ }
4219
+ removeRemoteVideoRenderCallback(userId) {
4220
+ this.rtcCloud.removeRemoteVideoRenderCallback(userId);
4155
4221
  }
4156
4222
  //----------------------------------//
4157
4223
  // Render Mode API
@@ -901,6 +901,42 @@ export declare type TRTCMusicPlayObserver = {
901
901
  */
902
902
  onComplete: (id: number, errCode: number) => void | null;
903
903
  };
904
+ /**
905
+ * 音频数据自定义回调事件监听器类型定义
906
+ */
907
+ export declare type TRTCAudioFrameCallback = {
908
+ /**
909
+ * 本地采集并经过音频模块前处理后的音频数据回调
910
+ * @param {TRTCAudioFrame} frame - PCM 格式的音频数据帧(只读)
911
+ * @returns
912
+ */
913
+ onCapturedAudioFrame: (frame: TRTCAudioFrame) => void | null;
914
+ /**
915
+ * 本地采集并经过音频模块前处理、音效处理和混 BGM 后的音频数据回调
916
+ * @param {TRTCAudioFrame} frame - PCM 格式的音频数据帧(只读)
917
+ * @returns
918
+ */
919
+ onLocalProcessedAudioFrame: (frame: TRTCAudioFrame) => void | null;
920
+ /**
921
+ * 混音前的每一路远程用户的音频数据
922
+ * @param {TRTCAudioFrame} frame - PCM 格式的音频数据帧(只读)
923
+ * @param {String} userId - 用户ID
924
+ * @returns
925
+ */
926
+ onPlayAudioFrame: (frame: TRTCAudioFrame, userId: string) => void | null;
927
+ /**
928
+ * 将各路待播放音频混合之后并在最终提交系统播放之前的数据回调
929
+ * @param {TRTCAudioFrame} frame - PCM 格式的音频数据帧(只读)
930
+ * @returns
931
+ */
932
+ onMixedPlayAudioFrame: (frame: TRTCAudioFrame) => void | null;
933
+ /**
934
+ * SDK 所有音频混合后的音频数据(包括采集到的和待播放的)
935
+ * @param {TRTCAudioFrame} frame - PCM 格式的音频数据帧(只读)
936
+ * @returns
937
+ */
938
+ onMixedAllAudioFrame: (frame: TRTCAudioFrame) => void | null;
939
+ };
904
940
  /**
905
941
  * 房间切换参数
906
942
  *
@@ -1617,6 +1617,17 @@ exports.AudioMusicParam = AudioMusicParam;
1617
1617
  * @property {TRTCMusicEvent~onComplete|null} onComplete - 背景音乐播放完毕事件。
1618
1618
  */
1619
1619
  const TRTCMusicPlayObserver_HACK_JSDOC = null;
1620
+ /**
1621
+ * 音频数据自定义回调
1622
+ *
1623
+ * @typedef {Object} TRTCAudioFrameCallback
1624
+ * @property {TRTCAudioFrameCallback~onCapturedAudioFrame|null} onCapturedAudioFrame - 本地采集并经过音频模块前处理后的音频数据回调。
1625
+ * @property {TRTCAudioFrameCallback~onLocalProcessedAudioFrame|null} onLocalProcessedAudioFrame - 本地采集并经过音频模块前处理、音效处理和混 BGM 后的音频数据回调。
1626
+ * @property {TRTCAudioFrameCallback~onPlayAudioFrame|null} onPlayAudioFrame - 混音前的每一路远程用户的音频数据。
1627
+ * @property {TRTCAudioFrameCallback~onMixedPlayAudioFrame|null} onMixedPlayAudioFrame - 将各路待播放音频混合之后并在最终提交系统播放之前的数据回调。
1628
+ * @property {TRTCAudioFrameCallback~onMixedAllAudioFrame|null} onMixedAllAudioFrame - SDK 所有音频混合后的音频数据(包括采集到的和待播放的)。
1629
+ */
1630
+ const TRTCAudioFrameCallback_HACK_JSDOC = null;
1620
1631
  /**
1621
1632
  * 房间切换参数
1622
1633
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trtc-electron-sdk",
3
- "version": "11.8.603-beta.4",
3
+ "version": "11.8.603",
4
4
  "description": "trtc electron sdk",
5
5
  "main": "./liteav/trtc.js",
6
6
  "types": "./liteav/trtc.d.ts",