trtc-electron-sdk 13.3.801-alpha.2 → 13.3.801-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.
@@ -128,6 +128,7 @@ export declare class TRTCMediaMixingManager implements ITRTCMediaMixingManager {
128
128
  private autoControlServer;
129
129
  private serverStatus;
130
130
  private serverMode;
131
+ private addMediaSourceTimers;
131
132
  private webRenderer;
132
133
  private pixelFormat;
133
134
  private pixelLength;
@@ -240,6 +241,14 @@ export declare class TRTCMediaMixingManager implements ITRTCMediaMixingManager {
240
241
  * @returns {Promise<void>}
241
242
  */
242
243
  addMediaSource(mediaSource: TRTCMediaSource): Promise<void>;
244
+ /**
245
+ * Returns the per-sourceType timeout (ms) used by addMediaSource. The
246
+ * defaults are intentionally larger than the cpp-layer timeout in
247
+ * SourceManagerProxy so that, in the normal case, the cpp side resolves the
248
+ * promise first. This JS timer is the last-resort safety net in case the
249
+ * cpp side itself fails to emit any callback (older builds, ipc lost, etc.).
250
+ */
251
+ private getAddMediaSourceTimeoutMs;
243
252
  /**
244
253
  * 删除本地混流媒体源
245
254
  * @param mediaSource {TRTCMediaSource} - 媒体源信息
@@ -304,6 +304,12 @@ class TRTCMediaMixingManager {
304
304
  this.streamLayoutManager = null;
305
305
  this.serverStatus = TRTCMediaMixingServerStatus.Idle;
306
306
  this.serverMode = TRTCMediaMixingServerMode.Independent;
307
+ // Per-source timeout handles for addMediaSource. Keyed by the same promise
308
+ // key used in promiseStore. Used to guard against the case where the native
309
+ // cpp layer never emits SM_OnSourceInserted (e.g. internal OnlineVideoSource
310
+ // state machine stuck after a previous failure), which would otherwise leave
311
+ // the returned Promise pending forever and the UI stuck on "loading".
312
+ this.addMediaSourceTimers = new Map();
307
313
  this.webRenderer = null;
308
314
  this.pixelFormat = trtc_define_1.TRTCVideoPixelFormat.TRTCVideoPixelFormat_BGRA32;
309
315
  this.pixelLength = 4;
@@ -386,6 +392,10 @@ class TRTCMediaMixingManager {
386
392
  this.nodeMediaMixingPlugin = null;
387
393
  this.eventEmitter = null;
388
394
  this.promiseStore.destroy();
395
+ // Cancel any pending addMediaSource timeout timers to avoid late-firing
396
+ // callbacks touching a destroyed instance.
397
+ this.addMediaSourceTimers.forEach(timer => clearTimeout(timer));
398
+ this.addMediaSourceTimers.clear();
389
399
  this.paramsStore = null;
390
400
  this.trtcParamsStore = null;
391
401
  });
@@ -536,6 +546,58 @@ class TRTCMediaMixingManager {
536
546
  var _a;
537
547
  const key = `${promiseKeys.addMediaSource}-${newMediaSource.sourceType}-${newMediaSource.sourceId}`;
538
548
  this.promiseStore.addPromise(key, resolve, reject);
549
+ // Arm a timeout safety net. The underlying cpp layer should normally
550
+ // call back via SM_OnSourceInserted, but for OnlineVideo / VideoFile we
551
+ // have observed the native MediaPlayer state machine getting stuck on
552
+ // the 2nd attempt after a previous network failure, with no callback
553
+ // ever emitted. Without this timer the returned Promise stays pending
554
+ // forever, freezing upstream UI (e.g. the "child view" loading state).
555
+ const timeoutMs = this.getAddMediaSourceTimeoutMs(newMediaSource.sourceType);
556
+ const timer = setTimeout(() => {
557
+ try {
558
+ // Defensive guard: destroy() may have been invoked while this
559
+ // macrotask was already scheduled but before the clearTimeout()
560
+ // loop in destroy() ran. In that case promiseStore / sourceList
561
+ // are no longer in a consistent state, and any further side-
562
+ // effect (e.g. ms.control = {}) could throw on undefined.
563
+ if (!this.nodeMediaMixingPlugin || !this.promiseStore) {
564
+ return;
565
+ }
566
+ // If the promise was already settled by the real callback, this is
567
+ // a no-op because PromiseStore.rejectPromise returns false on
568
+ // missing key.
569
+ const rejected = this.promiseStore.rejectPromise(key, {
570
+ code: types_1.TRTCMediaMixingErrorCode.InsertTimeout,
571
+ message: 'addMediaSource timeout',
572
+ });
573
+ if (rejected) {
574
+ logger_1.default.warn(`${this.logPrefix}addMediaSource timeout for sourceType:${newMediaSource.sourceType} sourceId:${newMediaSource.sourceId} timeoutMs:${timeoutMs}`);
575
+ // Mark the source as failed so subsequent removeMediaSource can
576
+ // take the fast (sync) path without waiting for cpp callbacks
577
+ // again.
578
+ const idx = this.findMediaSourceIndex({
579
+ sourceId: newMediaSource.sourceId,
580
+ sourceType: newMediaSource.sourceType,
581
+ });
582
+ if (idx !== -1) {
583
+ const ms = this.sourceList[idx];
584
+ if (ms) {
585
+ if (!ms.control) {
586
+ ms.control = {};
587
+ }
588
+ ms.control.isAddFailed = true;
589
+ }
590
+ }
591
+ }
592
+ }
593
+ finally {
594
+ // Always clear our own timer slot, even if the rejection path
595
+ // throws upstream. Without this, the Map would keep stale handles
596
+ // alive until destroy().
597
+ this.addMediaSourceTimers.delete(key);
598
+ }
599
+ }, timeoutMs);
600
+ this.addMediaSourceTimers.set(key, timer);
539
601
  this.nodeMediaMixingPlugin.addMediaSource(newMediaSource);
540
602
  (_a = this.mediaMixingDesigner) === null || _a === void 0 ? void 0 : _a.addMedia({
541
603
  id: `${newMediaSource.sourceType}__${newMediaSource.sourceId}`,
@@ -548,6 +610,23 @@ class TRTCMediaMixingManager {
548
610
  });
549
611
  });
550
612
  }
613
+ /**
614
+ * Returns the per-sourceType timeout (ms) used by addMediaSource. The
615
+ * defaults are intentionally larger than the cpp-layer timeout in
616
+ * SourceManagerProxy so that, in the normal case, the cpp side resolves the
617
+ * promise first. This JS timer is the last-resort safety net in case the
618
+ * cpp side itself fails to emit any callback (older builds, ipc lost, etc.).
619
+ */
620
+ getAddMediaSourceTimeoutMs(sourceType) {
621
+ switch (sourceType) {
622
+ case types_1.TRTCMediaSourceType.kOnlineVideo:
623
+ return 15000;
624
+ case types_1.TRTCMediaSourceType.kVideoFile:
625
+ return 10000;
626
+ default:
627
+ return 8000;
628
+ }
629
+ }
551
630
  /**
552
631
  * 删除本地混流媒体源
553
632
  * @param mediaSource {TRTCMediaSource} - 媒体源信息
@@ -1207,6 +1286,12 @@ class TRTCMediaMixingManager {
1207
1286
  onMediaSourceAdded(data) {
1208
1287
  var _a;
1209
1288
  const promiseKey = `${promiseKeys.addMediaSource}-${data.sourceType}-${data.sourceId}`;
1289
+ // Real callback arrived: cancel the JS-side timeout safety net.
1290
+ const timer = this.addMediaSourceTimers.get(promiseKey);
1291
+ if (timer) {
1292
+ clearTimeout(timer);
1293
+ this.addMediaSourceTimers.delete(promiseKey);
1294
+ }
1210
1295
  let flag = false;
1211
1296
  if (data.errCode === 0) {
1212
1297
  flag = this.promiseStore.resolvePromise(promiseKey, undefined);
@@ -13,7 +13,14 @@ export declare enum TRTCMediaMixingErrorCode {
13
13
  OnlineVideoConnectFailed = -10,
14
14
  OnlineVideoConnectionLost = -11,
15
15
  NoAvailableHevcDecoder = -12,
16
- VideoFileNotExist = -13
16
+ VideoFileNotExist = -13,
17
+ /**
18
+ * SDK 兜底超时(addMediaSource 在 cpp / js 双层超时内未收到底层 onXxxStarted 回调)。
19
+ *
20
+ * 取一个远离 SDK 自然错误码区间(-1..-13)的值,便于上层稳定区分。
21
+ * 必须与 C++ 端 `kInsertTimeoutErrCode`(SourceManagerProxy)保持一致。
22
+ */
23
+ InsertTimeout = -9001
17
24
  }
18
25
  export declare enum TRTCMediaSourceType {
19
26
  kCamera = 0,
@@ -17,6 +17,13 @@ var TRTCMediaMixingErrorCode;
17
17
  TRTCMediaMixingErrorCode[TRTCMediaMixingErrorCode["OnlineVideoConnectionLost"] = -11] = "OnlineVideoConnectionLost";
18
18
  TRTCMediaMixingErrorCode[TRTCMediaMixingErrorCode["NoAvailableHevcDecoder"] = -12] = "NoAvailableHevcDecoder";
19
19
  TRTCMediaMixingErrorCode[TRTCMediaMixingErrorCode["VideoFileNotExist"] = -13] = "VideoFileNotExist";
20
+ /**
21
+ * SDK 兜底超时(addMediaSource 在 cpp / js 双层超时内未收到底层 onXxxStarted 回调)。
22
+ *
23
+ * 取一个远离 SDK 自然错误码区间(-1..-13)的值,便于上层稳定区分。
24
+ * 必须与 C++ 端 `kInsertTimeoutErrCode`(SourceManagerProxy)保持一致。
25
+ */
26
+ TRTCMediaMixingErrorCode[TRTCMediaMixingErrorCode["InsertTimeout"] = -9001] = "InsertTimeout";
20
27
  })(TRTCMediaMixingErrorCode = exports.TRTCMediaMixingErrorCode || (exports.TRTCMediaMixingErrorCode = {}));
21
28
  var TRTCMediaSourceType;
22
29
  (function (TRTCMediaSourceType) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trtc-electron-sdk",
3
- "version": "13.3.801-alpha.2",
3
+ "version": "13.3.801-alpha.3",
4
4
  "description": "trtc electron sdk",
5
5
  "main": "./liteav/index.js",
6
6
  "types": "./liteav/index.d.ts",