trtc-electron-sdk 10.3.100-alpha.2 → 10.3.100-alpha.3

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 CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { EventEmitter } from 'events';
3
4
  import { AudioMusicParam, Rect, TRTCAppScene, TRTCAudioEffectParam, TRTCAudioQuality, TRTCBeautyStyle, TRTCDeviceState, TRTCDeviceType, TRTCLogLevel, TRTCRenderParams, TRTCRoleType, TRTCSwitchRoomParam, TRTCVideoBufferType, TRTCVideoFillMode, TRTCVideoFrame, TRTCVideoPixelFormat, TRTCVideoRotation, TRTCVideoStreamType, TRTCWaterMarkSrcType, PluginInfo, TRTCAudioRecordingParams, TRTCScreenCaptureSourceInfo, TRTCScreenCaptureProperty } from './trtc_define';
4
5
  export * from './trtc_define';
@@ -43,6 +44,7 @@ declare class TRTCCloud extends EventEmitter {
43
44
  private enableRenderFrame;
44
45
  private screenCaptureStreamType;
45
46
  private isScreenCapturing;
47
+ private userStreamDumpRecord;
46
48
  constructor();
47
49
  /**
48
50
  * 创建 TRTCCloud 对象单例
@@ -2026,6 +2028,15 @@ declare class TRTCCloud extends EventEmitter {
2026
2028
  * @throws {Error}
2027
2029
  */
2028
2030
  _writefile(path: string, data: any): void;
2031
+ _dumpframe(options: {
2032
+ uid: string;
2033
+ type: number;
2034
+ timestamp: number;
2035
+ width: number;
2036
+ height: number;
2037
+ pixelFormat: number;
2038
+ data: Uint8Array | Buffer;
2039
+ }): void;
2029
2040
  _writeLog(info: string): void;
2030
2041
  _onUserRenderCallback(callback: (userid: string, streamType: TRTCVideoStreamType, videoframe: TRTCVideoFrame) => void, format: TRTCVideoPixelFormat, userid: string, streamType: TRTCVideoStreamType, width: number, height: number, timestamp: number, rotation: number, data: any): void;
2031
2042
  _initImageData(width: number, height: number): void;
package/liteav/trtc.js CHANGED
@@ -155,6 +155,7 @@ class TRTCCloud extends events_1.EventEmitter {
155
155
  this.remoteVideoCallback = new Map();
156
156
  secMethods(this);
157
157
  this.callExperimentalAPI("{\"api\":\"setCurrentEnvironment\",\"params\" :{\"electron\":true}}");
158
+ this.userStreamDumpRecord = new Map();
158
159
  }
159
160
  /**
160
161
  * 创建 TRTCCloud 对象单例
@@ -183,6 +184,7 @@ class TRTCCloud extends events_1.EventEmitter {
183
184
  }
184
185
  setExternalRenderEnabled(enabled) {
185
186
  this.isExternalRenderEnabled = enabled;
187
+ console.log('trtc:setExternalRenderEnabled:', enabled);
186
188
  }
187
189
  /**
188
190
  * 清理资源
@@ -2717,7 +2719,7 @@ class TRTCCloud extends events_1.EventEmitter {
2717
2719
  if (userId !== undefined && userId !== null
2718
2720
  && pixelFormat !== undefined && bufferType !== undefined && callback !== undefined) {
2719
2721
  if (callback !== null) {
2720
- let remotecallback = new VideoRenderCallback();
2722
+ const remotecallback = new VideoRenderCallback();
2721
2723
  remotecallback.callback = callback;
2722
2724
  remotecallback.pixelFormat = pixelFormat;
2723
2725
  this.remoteVideoCallback.set(String(userId), remotecallback);
@@ -3182,7 +3184,7 @@ class TRTCCloud extends events_1.EventEmitter {
3182
3184
  startCameraDeviceTest(view) {
3183
3185
  if (view !== undefined) {
3184
3186
  if (view !== null) {
3185
- let key = this.getKey(CAMERA_DEVICE_TEST_VIEW, trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeBig);
3187
+ const key = this.getKey(CAMERA_DEVICE_TEST_VIEW, trtc_define_1.TRTCVideoStreamType.TRTCVideoStreamTypeBig);
3186
3188
  this._initRender(key, view);
3187
3189
  const renderer = this.streams.get(key);
3188
3190
  renderer.setContentMode(trtc_define_1.TRTCVideoFillMode.TRTCVideoFillMode_Fill);
@@ -3386,7 +3388,7 @@ class TRTCCloud extends events_1.EventEmitter {
3386
3388
  this._onRenderFrame(id, type, width, height, timestamp, rotation, videoBufferInfo.buffer);
3387
3389
  }
3388
3390
  else {
3389
- // 宽高发生变化,不能渲染,此时JS层新建了Buffer,低层C++回调上来的是写入旧Buffer的帧,渲染会导致录屏
3391
+ // 宽高发生变化,不能渲染,此时JS层新建了Buffer,低层C++回调上来的是写入旧Buffer的帧,渲染会导致绿屏
3390
3392
  console.warn('trtc: received old buffer size data:', id, type, width, height, videoBufferInfo.width, videoBufferInfo.height);
3391
3393
  }
3392
3394
  }
@@ -3419,7 +3421,7 @@ class TRTCCloud extends events_1.EventEmitter {
3419
3421
  if (this.renderMode !== mode) {
3420
3422
  this.renderMode = mode;
3421
3423
  // 遍历原有的renderer,改为新的渲染模式
3422
- let oldStreams = new Map();
3424
+ const oldStreams = new Map();
3423
3425
  this.streams.forEach((value, key, map) => {
3424
3426
  oldStreams.set(key, value);
3425
3427
  });
@@ -3510,14 +3512,24 @@ class TRTCCloud extends events_1.EventEmitter {
3510
3512
  }
3511
3513
  }
3512
3514
  _getRenderer(uid, type) {
3513
- let key = this.getKey(uid, type);
3515
+ const key = this.getKey(uid, type);
3514
3516
  return this.streams.get(key);
3515
3517
  }
3516
3518
  _onRenderFrame(uid, type, width, height, timestamp, rotation, data) {
3519
+ console.log(`trtc:_onRenderFrame:${uid}_${type}_${timestamp}_${width}_${height}_${this.pixelformate}`);
3520
+ this._dumpframe({
3521
+ uid,
3522
+ type,
3523
+ timestamp,
3524
+ width,
3525
+ height,
3526
+ pixelFormat: this.pixelformate,
3527
+ data: new Uint8Array(data.slice(0))
3528
+ });
3517
3529
  // 由于 mac 监听自定义渲染回调后不会回调 onFirstVideoFrame ,所以在这里自己实现回调 onFirstVideoFrame
3518
3530
  if (this._isMacPlatform()) {
3519
3531
  setImmediate(() => {
3520
- let index = this.firstVideoFrameList.findIndex(function (item) {
3532
+ const index = this.firstVideoFrameList.findIndex(function (item) {
3521
3533
  return uid === item.uid && type === item.type;
3522
3534
  });
3523
3535
  if (index === -1) {
@@ -3578,11 +3590,12 @@ class TRTCCloud extends events_1.EventEmitter {
3578
3590
  this._onRealRender(uid, streamType, width, height, timestamp, rotation, data);
3579
3591
  }
3580
3592
  //回调远程给用户数据
3581
- let remoteCallback = this.remoteVideoCallback.get(uid);
3593
+ const remoteCallback = this.remoteVideoCallback.get(uid);
3582
3594
  if (remoteCallback !== undefined &&
3583
3595
  remoteCallback !== null &&
3584
3596
  remoteCallback.callback !== undefined &&
3585
3597
  remoteCallback.callback !== null) {
3598
+ console.log(`trtc:remote_render_callback_${uid}_${type}_${timestamp}_${remoteCallback.pixelFormat}`);
3586
3599
  this._onUserRenderCallback(remoteCallback.callback, remoteCallback.pixelFormat, uid, type, width, height, timestamp, rotation, data);
3587
3600
  }
3588
3601
  }
@@ -3682,22 +3695,51 @@ class TRTCCloud extends events_1.EventEmitter {
3682
3695
  * @throws {Error}
3683
3696
  */
3684
3697
  _writefile(path, data) {
3685
- let fs = require('fs');
3686
- fs.writeFile(path, data, (err) => {
3687
- if (err) {
3688
- throw err;
3698
+ try {
3699
+ // const fs = require("fs");
3700
+ if (global.fs && global.fs.writeFile) {
3701
+ global.fs.writeFile(path, data, (err) => {
3702
+ if (err) {
3703
+ throw err;
3704
+ }
3705
+ else {
3706
+ console.log('trtc:write file ok, path:' + path);
3707
+ }
3708
+ });
3689
3709
  }
3690
3710
  else {
3691
- console.log('trtc:write file ok, path:' + path);
3711
+ console.error('trtc: _writeFile failed.', global.fs, global.fs.writeFile);
3692
3712
  }
3693
- });
3713
+ }
3714
+ catch (err) {
3715
+ console.error('trtc: _writeFile failed.', err);
3716
+ }
3717
+ }
3718
+ _dumpframe(options) {
3719
+ if (global.homedir) {
3720
+ const { uid, type, timestamp, width, height, data, pixelFormat } = options;
3721
+ const timestampSecond = Math.floor(timestamp / 5000);
3722
+ const key = `${uid}_${type}_${timestampSecond}`;
3723
+ const timestampRecord = this.userStreamDumpRecord.get(key);
3724
+ if (timestampRecord || timestampSecond === 0) {
3725
+ return;
3726
+ }
3727
+ const midPath = this._isMacPlatform() ? "/Documents/log/" : "/AppData/Roaming/liteav/log/";
3728
+ const fileName = `${uid}_${type}_${timestamp}_${width}_${height}_${pixelFormat}.jfdump`;
3729
+ const fullPath = `${global.homedir}${midPath}${fileName}`;
3730
+ this._writefile(fullPath, data);
3731
+ this.userStreamDumpRecord.set(key, timestampSecond);
3732
+ }
3733
+ else {
3734
+ console.error("trtc: no homedir, please add in Electron preload.js");
3735
+ }
3694
3736
  }
3695
3737
  _writeLog(info) {
3696
3738
  this.rtcCloud.writeLog(info);
3697
3739
  }
3698
3740
  _onUserRenderCallback(callback, format, userid, streamType, width, height, timestamp, rotation, data) {
3699
3741
  if (callback !== null) {
3700
- let videoframe = new trtc_define_1.TRTCVideoFrame();
3742
+ const videoframe = new trtc_define_1.TRTCVideoFrame();
3701
3743
  videoframe.videoFormat = format;
3702
3744
  videoframe.bufferType = trtc_define_1.TRTCVideoBufferType.TRTCVideoBufferType_Buffer;
3703
3745
  videoframe.textureId = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trtc-electron-sdk",
3
- "version": "10.3.100-alpha.2",
3
+ "version": "10.3.100-alpha.3",
4
4
  "description": "trtc electron sdk",
5
5
  "main": "./liteav/trtc.js",
6
6
  "types": "./liteav/trtc.d.ts",