mediasoup-client 3.6.49 → 3.6.52

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.
Files changed (77) hide show
  1. package/lib/Consumer.d.ts +6 -6
  2. package/lib/Consumer.d.ts.map +1 -1
  3. package/lib/Consumer.js +2 -1
  4. package/lib/DataConsumer.d.ts +4 -4
  5. package/lib/DataConsumer.d.ts.map +1 -1
  6. package/lib/DataConsumer.js +2 -1
  7. package/lib/DataProducer.d.ts +4 -4
  8. package/lib/DataProducer.d.ts.map +1 -1
  9. package/lib/DataProducer.js +2 -1
  10. package/lib/Device.d.ts.map +1 -1
  11. package/lib/Device.js +8 -4
  12. package/lib/Producer.d.ts +6 -6
  13. package/lib/Producer.d.ts.map +1 -1
  14. package/lib/Producer.js +2 -1
  15. package/lib/Transport.d.ts +9 -3
  16. package/lib/Transport.d.ts.map +1 -1
  17. package/lib/Transport.js +83 -6
  18. package/lib/handlers/Chrome55.d.ts +2 -2
  19. package/lib/handlers/Chrome55.d.ts.map +1 -1
  20. package/lib/handlers/Chrome55.js +7 -3
  21. package/lib/handlers/Chrome67.d.ts +2 -2
  22. package/lib/handlers/Chrome67.d.ts.map +1 -1
  23. package/lib/handlers/Chrome67.js +7 -3
  24. package/lib/handlers/Chrome70.d.ts +2 -2
  25. package/lib/handlers/Chrome70.d.ts.map +1 -1
  26. package/lib/handlers/Chrome70.js +13 -7
  27. package/lib/handlers/Chrome74.d.ts +2 -2
  28. package/lib/handlers/Chrome74.d.ts.map +1 -1
  29. package/lib/handlers/Chrome74.js +27 -17
  30. package/lib/handlers/Edge11.d.ts +2 -2
  31. package/lib/handlers/Edge11.d.ts.map +1 -1
  32. package/lib/handlers/Edge11.js +7 -3
  33. package/lib/handlers/FakeHandler.d.ts +2 -2
  34. package/lib/handlers/FakeHandler.d.ts.map +1 -1
  35. package/lib/handlers/FakeHandler.js +7 -3
  36. package/lib/handlers/Firefox60.d.ts +2 -2
  37. package/lib/handlers/Firefox60.d.ts.map +1 -1
  38. package/lib/handlers/Firefox60.js +27 -17
  39. package/lib/handlers/HandlerInterface.d.ts +2 -2
  40. package/lib/handlers/HandlerInterface.d.ts.map +1 -1
  41. package/lib/handlers/ReactNative.d.ts +2 -2
  42. package/lib/handlers/ReactNative.d.ts.map +1 -1
  43. package/lib/handlers/ReactNative.js +7 -3
  44. package/lib/handlers/Safari11.d.ts +2 -2
  45. package/lib/handlers/Safari11.d.ts.map +1 -1
  46. package/lib/handlers/Safari11.js +7 -3
  47. package/lib/handlers/Safari12.d.ts +2 -2
  48. package/lib/handlers/Safari12.d.ts.map +1 -1
  49. package/lib/handlers/Safari12.js +27 -17
  50. package/lib/handlers/ortc/edgeUtils.js +5 -1
  51. package/lib/handlers/sdp/MediaSection.js +5 -1
  52. package/lib/handlers/sdp/RemoteSdp.js +5 -1
  53. package/lib/handlers/sdp/commonUtils.js +5 -1
  54. package/lib/index.d.ts +1 -1
  55. package/lib/index.js +6 -2
  56. package/lib/ortc.js +5 -1
  57. package/lib/types.js +5 -1
  58. package/package.json +11 -11
  59. package/src/Consumer.ts +10 -9
  60. package/src/DataConsumer.ts +7 -6
  61. package/src/DataProducer.ts +7 -6
  62. package/src/Device.ts +3 -3
  63. package/src/Producer.ts +8 -7
  64. package/src/Transport.ts +120 -13
  65. package/src/handlers/Chrome55.ts +3 -3
  66. package/src/handlers/Chrome67.ts +2 -2
  67. package/src/handlers/Chrome70.ts +9 -6
  68. package/src/handlers/Chrome74.ts +27 -18
  69. package/src/handlers/Edge11.ts +2 -2
  70. package/src/handlers/FakeHandler.ts +2 -2
  71. package/src/handlers/Firefox60.ts +27 -18
  72. package/src/handlers/HandlerInterface.ts +2 -2
  73. package/src/handlers/ReactNative.ts +2 -2
  74. package/src/handlers/Safari11.ts +2 -2
  75. package/src/handlers/Safari12.ts +27 -18
  76. package/.vimrc +0 -21
  77. package/NO_GIT/Notes.txt +0 -18
package/src/Transport.ts CHANGED
@@ -48,7 +48,7 @@ export type TransportOptions =
48
48
  iceTransportPolicy?: RTCIceTransportPolicy;
49
49
  additionalSettings?: any;
50
50
  proprietaryConstraints?: any;
51
- appData?: any;
51
+ appData?: Record<string, unknown>;
52
52
  }
53
53
 
54
54
  export type CanProduceByKind =
@@ -170,7 +170,7 @@ export class Transport extends EnhancedEventEmitter
170
170
  // Transport connection state.
171
171
  private _connectionState: ConnectionState = 'new';
172
172
  // App custom data.
173
- private readonly _appData: any;
173
+ private readonly _appData: Record<string, unknown>;
174
174
  // Map of Producers indexed by id.
175
175
  private readonly _producers: Map<string, Producer> = new Map();
176
176
  // Map of Consumers indexed by id.
@@ -187,6 +187,14 @@ export class Transport extends EnhancedEventEmitter
187
187
  private _pendingConsumerTasks: ConsumerCreationTask[] = [];
188
188
  // Consumer creation in progress flag.
189
189
  private _consumerCreationInProgress = false;
190
+ // Consumers pending to be paused.
191
+ private _pendingPauseConsumers: Map<string, Consumer> = new Map();
192
+ // Consumer pause in progress flag.
193
+ private _consumerPauseInProgress = false;
194
+ // Consumers pending to be resumed.
195
+ private _pendingResumeConsumers: Map<string, Consumer> = new Map();
196
+ // Consumer resume in progress flag.
197
+ private _consumerResumeInProgress = false;
190
198
  // Observer instance.
191
199
  protected readonly _observer = new EnhancedEventEmitter();
192
200
 
@@ -251,7 +259,7 @@ export class Transport extends EnhancedEventEmitter
251
259
  extendedRtpCapabilities
252
260
  });
253
261
 
254
- this._appData = appData;
262
+ this._appData = appData || {};
255
263
 
256
264
  this._handleHandler();
257
265
  }
@@ -299,7 +307,7 @@ export class Transport extends EnhancedEventEmitter
299
307
  /**
300
308
  * App custom data.
301
309
  */
302
- get appData(): any
310
+ get appData(): Record<string, unknown>
303
311
  {
304
312
  return this._appData;
305
313
  }
@@ -307,7 +315,8 @@ export class Transport extends EnhancedEventEmitter
307
315
  /**
308
316
  * Invalid setter.
309
317
  */
310
- set appData(appData: any) // eslint-disable-line no-unused-vars
318
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
319
+ set appData(appData: Record<string, unknown>)
311
320
  {
312
321
  throw new Error('cannot override appData object');
313
322
  }
@@ -892,6 +901,82 @@ export class Transport extends EnhancedEventEmitter
892
901
  .catch(() => {});
893
902
  }
894
903
 
904
+ _pausePendingConsumers()
905
+ {
906
+ this._awaitQueue.push(
907
+ async () =>
908
+ {
909
+ this._consumerPauseInProgress = true;
910
+
911
+ const pendingPauseConsumers = Array.from(this._pendingPauseConsumers.values());
912
+
913
+ // Clear pending pause Consumer map.
914
+ this._pendingPauseConsumers.clear();
915
+
916
+ try
917
+ {
918
+ await this._handler.pauseReceiving(
919
+ pendingPauseConsumers.map((consumer) => consumer.localId)
920
+ );
921
+ }
922
+ catch (error)
923
+ {
924
+ logger.error('_pausePendingConsumers() | failed to pause Consumers:', error);
925
+ }
926
+
927
+ this._consumerPauseInProgress = false;
928
+ },
929
+ 'consumer @pause event')
930
+ .then(() =>
931
+ {
932
+ // There are pending Consumers to be paused, do it.
933
+ if (this._pendingPauseConsumers.size > 0)
934
+ {
935
+ this._pausePendingConsumers();
936
+ }
937
+ })
938
+ // NOTE: We only get here when the await queue is closed.
939
+ .catch(() => { });
940
+ }
941
+
942
+ _resumePendingConsumers()
943
+ {
944
+ this._awaitQueue.push(
945
+ async () =>
946
+ {
947
+ this._consumerResumeInProgress = true;
948
+
949
+ const pendingResumeConsumers = Array.from(this._pendingResumeConsumers.values());
950
+
951
+ // Clear pending resume Consumer map.
952
+ this._pendingResumeConsumers.clear();
953
+
954
+ try
955
+ {
956
+ await this._handler.resumeReceiving(
957
+ pendingResumeConsumers.map((consumer) => consumer.localId)
958
+ );
959
+ }
960
+ catch (error)
961
+ {
962
+ logger.error('_resumePendingConsumers() | failed to resume Consumers:', error);
963
+ }
964
+ },
965
+ 'consumer @resume event')
966
+ .then(() =>
967
+ {
968
+ this._consumerResumeInProgress = false;
969
+
970
+ // There are pending Consumer to be resumed, do it.
971
+ if (this._pendingResumeConsumers.size > 0)
972
+ {
973
+ this._resumePendingConsumers();
974
+ }
975
+ })
976
+ // NOTE: We only get here when the await queue is closed.
977
+ .catch(() => { });
978
+ }
979
+
895
980
  _handleHandler(): void
896
981
  {
897
982
  const handler = this._handler;
@@ -986,6 +1071,8 @@ export class Transport extends EnhancedEventEmitter
986
1071
  consumer.on('@close', () =>
987
1072
  {
988
1073
  this._consumers.delete(consumer.id);
1074
+ this._pendingPauseConsumers.delete(consumer.id);
1075
+ this._pendingResumeConsumers.delete(consumer.id);
989
1076
 
990
1077
  if (this._closed)
991
1078
  return;
@@ -998,18 +1085,38 @@ export class Transport extends EnhancedEventEmitter
998
1085
 
999
1086
  consumer.on('@pause', () =>
1000
1087
  {
1001
- this._awaitQueue.push(
1002
- async () => this._handler.pauseReceiving(consumer.localId),
1003
- 'consumer @pause event')
1004
- .catch(() => {});
1088
+ // If Consumer is pending to be resumed, remove from pending resume list.
1089
+ if (this._pendingResumeConsumers.has(consumer.id))
1090
+ {
1091
+ this._pendingResumeConsumers.delete(consumer.id);
1092
+ }
1093
+
1094
+ // Store the Consumer into the pending list.
1095
+ this._pendingPauseConsumers.set(consumer.id, consumer);
1096
+
1097
+ // There is no Consumer pause in progress, do it now.
1098
+ if (this._consumerPauseInProgress === false)
1099
+ {
1100
+ this._pausePendingConsumers();
1101
+ }
1005
1102
  });
1006
1103
 
1007
1104
  consumer.on('@resume', () =>
1008
1105
  {
1009
- this._awaitQueue.push(
1010
- async () => this._handler.resumeReceiving(consumer.localId),
1011
- 'consumer @resume event')
1012
- .catch(() => {});
1106
+ // If Consumer is pending to be paused, remove from pending pause list.
1107
+ if (this._pendingPauseConsumers.has(consumer.id))
1108
+ {
1109
+ this._pendingPauseConsumers.delete(consumer.id);
1110
+ }
1111
+
1112
+ // Store the Consumer into the pending list.
1113
+ this._pendingResumeConsumers.set(consumer.id, consumer);
1114
+
1115
+ // There is no Consumer resume in progress, do it now.
1116
+ if (this._consumerResumeInProgress === false)
1117
+ {
1118
+ this._resumePendingConsumers();
1119
+ }
1013
1120
  });
1014
1121
 
1015
1122
  consumer.on('@getstats', (callback, errback) =>
@@ -702,17 +702,17 @@ export class Chrome55 extends HandlerInterface
702
702
 
703
703
  await this._pc.setLocalDescription(answer);
704
704
  }
705
-
705
+
706
706
  async pauseReceiving(
707
707
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
708
- localId: string): Promise<void>
708
+ localIds: string[]): Promise<void>
709
709
  {
710
710
  // Unimplemented.
711
711
  }
712
712
 
713
713
  async resumeReceiving(
714
714
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
715
- localId: string): Promise<void>
715
+ localIds: string[]): Promise<void>
716
716
  {
717
717
  // Unimplemented.
718
718
  }
@@ -784,14 +784,14 @@ export class Chrome67 extends HandlerInterface
784
784
 
785
785
  async pauseReceiving(
786
786
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
787
- localId: string): Promise<void>
787
+ localIds: string[]): Promise<void>
788
788
  {
789
789
  // Unimplemented.
790
790
  }
791
791
 
792
792
  async resumeReceiving(
793
793
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
794
- localId: string): Promise<void>
794
+ localIds: string[]): Promise<void>
795
795
  {
796
796
  // Unimplemented.
797
797
  }
@@ -669,6 +669,7 @@ export class Chrome70 extends HandlerInterface
669
669
  this._assertRecvDirection();
670
670
 
671
671
  const results: HandlerReceiveResult[] = [];
672
+ const mapLocalId: Map<string, string> = new Map();
672
673
 
673
674
  for (const options of optionsList)
674
675
  {
@@ -678,6 +679,8 @@ export class Chrome70 extends HandlerInterface
678
679
 
679
680
  const localId = rtpParameters.mid || String(this._mapMidTransceiver.size);
680
681
 
682
+ mapLocalId.set(trackId, localId);
683
+
681
684
  this._remoteSdp!.receive(
682
685
  {
683
686
  mid : localId,
@@ -701,8 +704,8 @@ export class Chrome70 extends HandlerInterface
701
704
 
702
705
  for (const options of optionsList)
703
706
  {
704
- const { rtpParameters } = options;
705
- const localId = rtpParameters.mid || String(this._mapMidTransceiver.size);
707
+ const { trackId, rtpParameters } = options;
708
+ const localId = mapLocalId.get(trackId);
706
709
  const answerMediaObject = localSdpObject.media
707
710
  .find((m: any) => String(m.mid) === localId);
708
711
 
@@ -734,8 +737,8 @@ export class Chrome70 extends HandlerInterface
734
737
 
735
738
  for (const options of optionsList)
736
739
  {
737
- const { rtpParameters } = options;
738
- const localId = rtpParameters.mid || String(this._mapMidTransceiver.size);
740
+ const { trackId } = options;
741
+ const localId = mapLocalId.get(trackId)!;
739
742
  const transceiver = this._pc.getTransceivers()
740
743
  .find((t: RTCRtpTransceiver) => t.mid === localId);
741
744
 
@@ -789,14 +792,14 @@ export class Chrome70 extends HandlerInterface
789
792
 
790
793
  async pauseReceiving(
791
794
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
792
- localId: string): Promise<void>
795
+ localIds: string[]): Promise<void>
793
796
  {
794
797
  // Unimplemented.
795
798
  }
796
799
 
797
800
  async resumeReceiving(
798
801
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
799
- localId: string): Promise<void>
802
+ localIds: string[]): Promise<void>
800
803
  {
801
804
  // Unimplemented.
802
805
  }
@@ -655,6 +655,7 @@ export class Chrome74 extends HandlerInterface
655
655
  this._assertRecvDirection();
656
656
 
657
657
  const results: HandlerReceiveResult[] = [];
658
+ const mapLocalId: Map<string, string> = new Map();
658
659
 
659
660
  for (const options of optionsList)
660
661
  {
@@ -664,6 +665,8 @@ export class Chrome74 extends HandlerInterface
664
665
 
665
666
  const localId = rtpParameters.mid || String(this._mapMidTransceiver.size);
666
667
 
668
+ mapLocalId.set(trackId, localId);
669
+
667
670
  this._remoteSdp!.receive(
668
671
  {
669
672
  mid : localId,
@@ -687,8 +690,8 @@ export class Chrome74 extends HandlerInterface
687
690
 
688
691
  for (const options of optionsList)
689
692
  {
690
- const { rtpParameters } = options;
691
- const localId = rtpParameters.mid || String(this._mapMidTransceiver.size);
693
+ const { trackId, rtpParameters } = options;
694
+ const localId = mapLocalId.get(trackId);
692
695
  const answerMediaObject = localSdpObject.media
693
696
  .find((m: any) => String(m.mid) === localId);
694
697
 
@@ -720,8 +723,8 @@ export class Chrome74 extends HandlerInterface
720
723
 
721
724
  for (const options of optionsList)
722
725
  {
723
- const { rtpParameters } = options;
724
- const localId = rtpParameters.mid || String(this._mapMidTransceiver.size);
726
+ const { trackId } = options;
727
+ const localId = mapLocalId.get(trackId)!;
725
728
  const transceiver = this._pc.getTransceivers()
726
729
  .find((t: RTCRtpTransceiver) => t.mid === localId);
727
730
 
@@ -777,19 +780,22 @@ export class Chrome74 extends HandlerInterface
777
780
  this._mapMidTransceiver.delete(localId);
778
781
  }
779
782
 
780
- async pauseReceiving(localId: string): Promise<void>
783
+ async pauseReceiving(localIds: string[]): Promise<void>
781
784
  {
782
785
  this._assertRecvDirection();
783
786
 
784
- logger.debug('pauseReceiving() [localId:%s]', localId);
787
+ for (const localId of localIds)
788
+ {
789
+ logger.debug('pauseReceiving() [localId:%s]', localId);
785
790
 
786
- const transceiver = this._mapMidTransceiver.get(localId);
791
+ const transceiver = this._mapMidTransceiver.get(localId);
787
792
 
788
- if (!transceiver)
789
- throw new Error('associated RTCRtpTransceiver not found');
793
+ if (!transceiver)
794
+ throw new Error('associated RTCRtpTransceiver not found');
795
+
796
+ transceiver.direction = 'inactive';
797
+ }
790
798
 
791
- transceiver.direction = 'inactive';
792
-
793
799
  const offer = { type: 'offer', sdp: this._remoteSdp!.getSdp() };
794
800
 
795
801
  logger.debug(
@@ -807,19 +813,22 @@ export class Chrome74 extends HandlerInterface
807
813
  await this._pc.setLocalDescription(answer);
808
814
  }
809
815
 
810
- async resumeReceiving(localId: string): Promise<void>
816
+ async resumeReceiving(localIds: string[]): Promise<void>
811
817
  {
812
818
  this._assertRecvDirection();
813
819
 
814
- logger.debug('resumeReceiving() [localId:%s]', localId);
820
+ for (const localId of localIds)
821
+ {
822
+ logger.debug('resumeReceiving() [localId:%s]', localId);
815
823
 
816
- const transceiver = this._mapMidTransceiver.get(localId);
824
+ const transceiver = this._mapMidTransceiver.get(localId);
817
825
 
818
- if (!transceiver)
819
- throw new Error('associated RTCRtpTransceiver not found');
826
+ if (!transceiver)
827
+ throw new Error('associated RTCRtpTransceiver not found');
828
+
829
+ transceiver.direction = 'recvonly';
830
+ }
820
831
 
821
- transceiver.direction = 'recvonly';
822
-
823
832
  const offer = { type: 'offer', sdp: this._remoteSdp!.getSdp() };
824
833
 
825
834
  logger.debug(
@@ -440,14 +440,14 @@ export class Edge11 extends HandlerInterface
440
440
 
441
441
  async pauseReceiving(
442
442
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
443
- localId: string): Promise<void>
443
+ localIds: string[]): Promise<void>
444
444
  {
445
445
  // Unimplemented.
446
446
  }
447
447
 
448
448
  async resumeReceiving(
449
449
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
450
- localId: string): Promise<void>
450
+ localIds: string[]): Promise<void>
451
451
  {
452
452
  // Unimplemented.
453
453
  }
@@ -358,14 +358,14 @@ export class FakeHandler extends HandlerInterface
358
358
 
359
359
  async pauseReceiving(
360
360
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
361
- localId: string): Promise<void>
361
+ localIds: string[]): Promise<void>
362
362
  {
363
363
  // Unimplemented.
364
364
  }
365
365
 
366
366
  async resumeReceiving(
367
367
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
368
- localId: string): Promise<void>
368
+ localIds: string[]): Promise<void>
369
369
  {
370
370
  // Unimplemented.
371
371
  }
@@ -650,6 +650,7 @@ export class Firefox60 extends HandlerInterface
650
650
  this._assertRecvDirection();
651
651
 
652
652
  const results: HandlerReceiveResult[] = [];
653
+ const mapLocalId: Map<string, string> = new Map();
653
654
 
654
655
  for (const options of optionsList)
655
656
  {
@@ -659,6 +660,8 @@ export class Firefox60 extends HandlerInterface
659
660
 
660
661
  const localId = rtpParameters.mid || String(this._mapMidTransceiver.size);
661
662
 
663
+ mapLocalId.set(trackId, localId);
664
+
662
665
  this._remoteSdp!.receive(
663
666
  {
664
667
  mid : localId,
@@ -682,8 +685,8 @@ export class Firefox60 extends HandlerInterface
682
685
 
683
686
  for (const options of optionsList)
684
687
  {
685
- const { rtpParameters } = options;
686
- const localId = rtpParameters.mid || String(this._mapMidTransceiver.size);
688
+ const { trackId, rtpParameters } = options;
689
+ const localId = mapLocalId.get(trackId);
687
690
  const answerMediaObject = localSdpObject.media
688
691
  .find((m: any) => String(m.mid) === localId);
689
692
 
@@ -709,8 +712,8 @@ export class Firefox60 extends HandlerInterface
709
712
 
710
713
  for (const options of optionsList)
711
714
  {
712
- const { rtpParameters } = options;
713
- const localId = rtpParameters.mid || String(this._mapMidTransceiver.size);
715
+ const { trackId } = options;
716
+ const localId = mapLocalId.get(trackId)!;
714
717
  const transceiver = this._pc.getTransceivers()
715
718
  .find((t: RTCRtpTransceiver) => t.mid === localId);
716
719
 
@@ -762,19 +765,22 @@ export class Firefox60 extends HandlerInterface
762
765
  this._mapMidTransceiver.delete(localId);
763
766
  }
764
767
 
765
- async pauseReceiving(localId: string): Promise<void>
768
+ async pauseReceiving(localIds: string[]): Promise<void>
766
769
  {
767
770
  this._assertRecvDirection();
768
771
 
769
- logger.debug('pauseReceiving() [localId:%s]', localId);
772
+ for (const localId of localIds)
773
+ {
774
+ logger.debug('pauseReceiving() [localId:%s]', localId);
770
775
 
771
- const transceiver = this._mapMidTransceiver.get(localId);
776
+ const transceiver = this._mapMidTransceiver.get(localId);
772
777
 
773
- if (!transceiver)
774
- throw new Error('associated RTCRtpTransceiver not found');
778
+ if (!transceiver)
779
+ throw new Error('associated RTCRtpTransceiver not found');
780
+
781
+ transceiver.direction = 'inactive';
782
+ }
775
783
 
776
- transceiver.direction = 'inactive';
777
-
778
784
  const offer = { type: 'offer', sdp: this._remoteSdp!.getSdp() };
779
785
 
780
786
  logger.debug(
@@ -792,19 +798,22 @@ export class Firefox60 extends HandlerInterface
792
798
  await this._pc.setLocalDescription(answer);
793
799
  }
794
800
 
795
- async resumeReceiving(localId: string): Promise<void>
801
+ async resumeReceiving(localIds: string[]): Promise<void>
796
802
  {
797
803
  this._assertRecvDirection();
798
804
 
799
- logger.debug('resumeReceiving() [localId:%s]', localId);
805
+ for (const localId of localIds)
806
+ {
807
+ logger.debug('resumeReceiving() [localId:%s]', localId);
800
808
 
801
- const transceiver = this._mapMidTransceiver.get(localId);
809
+ const transceiver = this._mapMidTransceiver.get(localId);
802
810
 
803
- if (!transceiver)
804
- throw new Error('associated RTCRtpTransceiver not found');
811
+ if (!transceiver)
812
+ throw new Error('associated RTCRtpTransceiver not found');
813
+
814
+ transceiver.direction = 'recvonly';
815
+ }
805
816
 
806
- transceiver.direction = 'recvonly';
807
-
808
817
  const offer = { type: 'offer', sdp: this._remoteSdp!.getSdp() };
809
818
 
810
819
  logger.debug(
@@ -141,9 +141,9 @@ export abstract class HandlerInterface extends EnhancedEventEmitter
141
141
 
142
142
  abstract stopReceiving(localId: string): Promise<void>;
143
143
 
144
- abstract pauseReceiving(localId: string): Promise<void>;
144
+ abstract pauseReceiving(localIds: string[]): Promise<void>;
145
145
 
146
- abstract resumeReceiving(localId: string): Promise<void>;
146
+ abstract resumeReceiving(localIds: string[]): Promise<void>;
147
147
 
148
148
  abstract getReceiverStats(localId: string): Promise<RTCStatsReport>;
149
149
 
@@ -725,14 +725,14 @@ export class ReactNative extends HandlerInterface
725
725
 
726
726
  async pauseReceiving(
727
727
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
728
- localId: string): Promise<void>
728
+ localIds: string[]): Promise<void>
729
729
  {
730
730
  // Unimplemented.
731
731
  }
732
732
 
733
733
  async resumeReceiving(
734
734
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
735
- localId: string): Promise<void>
735
+ localIds: string[]): Promise<void>
736
736
  {
737
737
  // Unimplemented.
738
738
  }
@@ -790,14 +790,14 @@ export class Safari11 extends HandlerInterface
790
790
 
791
791
  async pauseReceiving(
792
792
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
793
- localId: string): Promise<void>
793
+ localIds: string[]): Promise<void>
794
794
  {
795
795
  // Unimplemented.
796
796
  }
797
797
 
798
798
  async resumeReceiving(
799
799
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
800
- localId: string): Promise<void>
800
+ localIds: string[]): Promise<void>
801
801
  {
802
802
  // Unimplemented.
803
803
  }
@@ -609,6 +609,7 @@ export class Safari12 extends HandlerInterface
609
609
  this._assertRecvDirection();
610
610
 
611
611
  const results: HandlerReceiveResult[] = [];
612
+ const mapLocalId: Map<string, string> = new Map();
612
613
 
613
614
  for (const options of optionsList)
614
615
  {
@@ -618,6 +619,8 @@ export class Safari12 extends HandlerInterface
618
619
 
619
620
  const localId = rtpParameters.mid || String(this._mapMidTransceiver.size);
620
621
 
622
+ mapLocalId.set(trackId, localId);
623
+
621
624
  this._remoteSdp!.receive(
622
625
  {
623
626
  mid : localId,
@@ -641,8 +644,8 @@ export class Safari12 extends HandlerInterface
641
644
 
642
645
  for (const options of optionsList)
643
646
  {
644
- const { rtpParameters } = options;
645
- const localId = rtpParameters.mid || String(this._mapMidTransceiver.size);
647
+ const { trackId, rtpParameters } = options;
648
+ const localId = mapLocalId.get(trackId);
646
649
  const answerMediaObject = localSdpObject.media
647
650
  .find((m: any) => String(m.mid) === localId);
648
651
 
@@ -674,8 +677,8 @@ export class Safari12 extends HandlerInterface
674
677
 
675
678
  for (const options of optionsList)
676
679
  {
677
- const { rtpParameters } = options;
678
- const localId = rtpParameters.mid || String(this._mapMidTransceiver.size);
680
+ const { trackId } = options;
681
+ const localId = mapLocalId.get(trackId)!;
679
682
  const transceiver = this._pc.getTransceivers()
680
683
  .find((t: RTCRtpTransceiver) => t.mid === localId);
681
684
 
@@ -727,19 +730,22 @@ export class Safari12 extends HandlerInterface
727
730
  this._mapMidTransceiver.delete(localId);
728
731
  }
729
732
 
730
- async pauseReceiving(localId: string): Promise<void>
733
+ async pauseReceiving(localIds: string[]): Promise<void>
731
734
  {
732
735
  this._assertRecvDirection();
733
736
 
734
- logger.debug('pauseReceiving() [localId:%s]', localId);
737
+ for (const localId of localIds)
738
+ {
739
+ logger.debug('pauseReceiving() [localId:%s]', localId);
735
740
 
736
- const transceiver = this._mapMidTransceiver.get(localId);
741
+ const transceiver = this._mapMidTransceiver.get(localId);
737
742
 
738
- if (!transceiver)
739
- throw new Error('associated RTCRtpTransceiver not found');
743
+ if (!transceiver)
744
+ throw new Error('associated RTCRtpTransceiver not found');
745
+
746
+ transceiver.direction = 'inactive';
747
+ }
740
748
 
741
- transceiver.direction = 'inactive';
742
-
743
749
  const offer = { type: 'offer', sdp: this._remoteSdp!.getSdp() };
744
750
 
745
751
  logger.debug(
@@ -757,19 +763,22 @@ export class Safari12 extends HandlerInterface
757
763
  await this._pc.setLocalDescription(answer);
758
764
  }
759
765
 
760
- async resumeReceiving(localId: string): Promise<void>
766
+ async resumeReceiving(localIds: string[]): Promise<void>
761
767
  {
762
768
  this._assertRecvDirection();
763
769
 
764
- logger.debug('resumeReceiving() [localId:%s]', localId);
770
+ for (const localId of localIds)
771
+ {
772
+ logger.debug('resumeReceiving() [localId:%s]', localId);
765
773
 
766
- const transceiver = this._mapMidTransceiver.get(localId);
774
+ const transceiver = this._mapMidTransceiver.get(localId);
767
775
 
768
- if (!transceiver)
769
- throw new Error('associated RTCRtpTransceiver not found');
776
+ if (!transceiver)
777
+ throw new Error('associated RTCRtpTransceiver not found');
778
+
779
+ transceiver.direction = 'recvonly';
780
+ }
770
781
 
771
- transceiver.direction = 'recvonly';
772
-
773
782
  const offer = { type: 'offer', sdp: this._remoteSdp!.getSdp() };
774
783
 
775
784
  logger.debug(