mediasoup-client 3.13.0 → 3.14.1

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 (67) hide show
  1. package/lib/Consumer.d.ts.map +1 -1
  2. package/lib/Consumer.js +3 -0
  3. package/lib/DataConsumer.d.ts.map +1 -1
  4. package/lib/DataConsumer.js +8 -8
  5. package/lib/DataProducer.d.ts.map +1 -1
  6. package/lib/DataProducer.js +8 -7
  7. package/lib/Device.d.ts +2 -2
  8. package/lib/Device.d.ts.map +1 -1
  9. package/lib/Device.js +53 -70
  10. package/lib/Producer.d.ts.map +1 -1
  11. package/lib/Producer.js +3 -0
  12. package/lib/RtpParameters.d.ts +8 -8
  13. package/lib/RtpParameters.d.ts.map +1 -1
  14. package/lib/Transport.d.ts +4 -4
  15. package/lib/Transport.d.ts.map +1 -1
  16. package/lib/Transport.js +9 -7
  17. package/lib/enhancedEvents.d.ts +4 -0
  18. package/lib/enhancedEvents.d.ts.map +1 -1
  19. package/lib/enhancedEvents.js +7 -0
  20. package/lib/handlers/Chrome111.d.ts +13 -13
  21. package/lib/handlers/Chrome111.d.ts.map +1 -1
  22. package/lib/handlers/Chrome111.js +175 -124
  23. package/lib/handlers/Chrome74.d.ts +13 -13
  24. package/lib/handlers/Chrome74.d.ts.map +1 -1
  25. package/lib/handlers/Chrome74.js +175 -120
  26. package/lib/handlers/FakeHandler.d.ts +8 -10
  27. package/lib/handlers/FakeHandler.d.ts.map +1 -1
  28. package/lib/handlers/FakeHandler.js +204 -61
  29. package/lib/handlers/Firefox120.d.ts +13 -13
  30. package/lib/handlers/Firefox120.d.ts.map +1 -1
  31. package/lib/handlers/Firefox120.js +200 -147
  32. package/lib/handlers/HandlerInterface.d.ts +11 -9
  33. package/lib/handlers/HandlerInterface.d.ts.map +1 -1
  34. package/lib/handlers/ReactNative106.d.ts +13 -13
  35. package/lib/handlers/ReactNative106.d.ts.map +1 -1
  36. package/lib/handlers/ReactNative106.js +181 -127
  37. package/lib/handlers/Safari12.d.ts +13 -13
  38. package/lib/handlers/Safari12.d.ts.map +1 -1
  39. package/lib/handlers/Safari12.js +178 -116
  40. package/lib/handlers/sdp/MediaSection.d.ts +5 -5
  41. package/lib/handlers/sdp/MediaSection.d.ts.map +1 -1
  42. package/lib/handlers/sdp/MediaSection.js +43 -45
  43. package/lib/handlers/sdp/RemoteSdp.d.ts +5 -6
  44. package/lib/handlers/sdp/RemoteSdp.d.ts.map +1 -1
  45. package/lib/handlers/sdp/RemoteSdp.js +5 -8
  46. package/lib/handlers/sdp/commonUtils.d.ts +5 -4
  47. package/lib/handlers/sdp/commonUtils.d.ts.map +1 -1
  48. package/lib/handlers/sdp/commonUtils.js +2 -2
  49. package/lib/handlers/sdp/plainRtpUtils.d.ts +4 -3
  50. package/lib/handlers/sdp/plainRtpUtils.d.ts.map +1 -1
  51. package/lib/handlers/sdp/plainRtpUtils.js +2 -2
  52. package/lib/handlers/sdp/unifiedPlanUtils.d.ts +3 -2
  53. package/lib/handlers/sdp/unifiedPlanUtils.d.ts.map +1 -1
  54. package/lib/handlers/sdp/unifiedPlanUtils.js +10 -8
  55. package/lib/index.d.ts +1 -1
  56. package/lib/index.js +1 -1
  57. package/lib/ortc.d.ts +7 -6
  58. package/lib/ortc.d.ts.map +1 -1
  59. package/lib/ortc.js +13 -14
  60. package/lib/privateTypes.d.ts +27 -0
  61. package/lib/privateTypes.d.ts.map +1 -0
  62. package/lib/privateTypes.js +2 -0
  63. package/lib/test/test.js +22 -3
  64. package/lib/utils.d.ts +1 -1
  65. package/lib/utils.d.ts.map +1 -1
  66. package/lib/utils.js +5 -4
  67. package/package.json +8 -9
@@ -3,19 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Chrome74 = void 0;
4
4
  const sdpTransform = require("sdp-transform");
5
5
  const Logger_1 = require("../Logger");
6
+ const enhancedEvents_1 = require("../enhancedEvents");
6
7
  const utils = require("../utils");
7
8
  const ortc = require("../ortc");
9
+ const errors_1 = require("../errors");
10
+ const scalabilityModes_1 = require("../scalabilityModes");
8
11
  const sdpCommonUtils = require("./sdp/commonUtils");
9
12
  const sdpUnifiedPlanUtils = require("./sdp/unifiedPlanUtils");
10
13
  const ortcUtils = require("./ortc/utils");
11
- const errors_1 = require("../errors");
12
- const HandlerInterface_1 = require("./HandlerInterface");
13
14
  const RemoteSdp_1 = require("./sdp/RemoteSdp");
14
- const scalabilityModes_1 = require("../scalabilityModes");
15
15
  const logger = new Logger_1.Logger('Chrome74');
16
16
  const NAME = 'Chrome74';
17
17
  const SCTP_NUM_STREAMS = { OS: 1024, MIS: 1024 };
18
- class Chrome74 extends HandlerInterface_1.HandlerInterface {
18
+ class Chrome74 extends enhancedEvents_1.EnhancedEventEmitter {
19
19
  // Closed flag.
20
20
  _closed = false;
21
21
  // Handler direction.
@@ -46,70 +46,54 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
46
46
  * Creates a factory function.
47
47
  */
48
48
  static createFactory() {
49
- return () => new Chrome74();
50
- }
51
- constructor() {
52
- super();
53
- }
54
- get name() {
55
- return NAME;
56
- }
57
- close() {
58
- logger.debug('close()');
59
- if (this._closed) {
60
- return;
61
- }
62
- this._closed = true;
63
- // Close RTCPeerConnection.
64
- if (this._pc) {
65
- try {
66
- this._pc.close();
67
- }
68
- catch (error) { }
69
- }
70
- this.emit('@close');
71
- }
72
- async getNativeRtpCapabilities() {
73
- logger.debug('getNativeRtpCapabilities()');
74
- const pc = new RTCPeerConnection({
75
- iceServers: [],
76
- iceTransportPolicy: 'all',
77
- bundlePolicy: 'max-bundle',
78
- rtcpMuxPolicy: 'require',
79
- sdpSemantics: 'unified-plan',
80
- });
81
- try {
82
- pc.addTransceiver('audio');
83
- pc.addTransceiver('video');
84
- const offer = await pc.createOffer();
85
- try {
86
- pc.close();
87
- }
88
- catch (error) { }
89
- const sdpObject = sdpTransform.parse(offer.sdp);
90
- const nativeRtpCapabilities = sdpCommonUtils.extractRtpCapabilities({
91
- sdpObject,
92
- });
93
- // libwebrtc supports NACK for OPUS but doesn't announce it.
94
- ortcUtils.addNackSupportForOpus(nativeRtpCapabilities);
95
- return nativeRtpCapabilities;
96
- }
97
- catch (error) {
98
- try {
99
- pc.close();
100
- }
101
- catch (error2) { }
102
- throw error;
103
- }
104
- }
105
- async getNativeSctpCapabilities() {
106
- logger.debug('getNativeSctpCapabilities()');
107
49
  return {
108
- numStreams: SCTP_NUM_STREAMS,
50
+ name: NAME,
51
+ factory: (options) => new Chrome74(options),
52
+ getNativeRtpCapabilities: async () => {
53
+ logger.debug('getNativeRtpCapabilities()');
54
+ let pc = new RTCPeerConnection({
55
+ iceServers: [],
56
+ iceTransportPolicy: 'all',
57
+ bundlePolicy: 'max-bundle',
58
+ rtcpMuxPolicy: 'require',
59
+ });
60
+ try {
61
+ pc.addTransceiver('audio');
62
+ pc.addTransceiver('video');
63
+ const offer = await pc.createOffer();
64
+ try {
65
+ pc.close();
66
+ }
67
+ catch (error) { }
68
+ pc = undefined;
69
+ const sdpObject = sdpTransform.parse(offer.sdp);
70
+ const nativeRtpCapabilities = sdpCommonUtils.extractRtpCapabilities({
71
+ sdpObject,
72
+ });
73
+ // libwebrtc supports NACK for OPUS but doesn't announce it.
74
+ ortcUtils.addNackSupportForOpus(nativeRtpCapabilities);
75
+ return nativeRtpCapabilities;
76
+ }
77
+ catch (error) {
78
+ try {
79
+ pc?.close();
80
+ }
81
+ catch (error2) { }
82
+ pc = undefined;
83
+ throw error;
84
+ }
85
+ },
86
+ getNativeSctpCapabilities: async () => {
87
+ logger.debug('getNativeSctpCapabilities()');
88
+ return {
89
+ numStreams: SCTP_NUM_STREAMS,
90
+ };
91
+ },
109
92
  };
110
93
  }
111
- run({ direction, iceParameters, iceCandidates, dtlsParameters, sctpParameters, iceServers, iceTransportPolicy, additionalSettings, proprietaryConstraints, extendedRtpCapabilities, }) {
112
- logger.debug('run()');
94
+ constructor({ direction, iceParameters, iceCandidates, dtlsParameters, sctpParameters, iceServers, iceTransportPolicy, additionalSettings, extendedRtpCapabilities, }) {
95
+ super();
96
+ logger.debug('constructor()');
113
97
  this._direction = direction;
114
98
  this._remoteSdp = new RemoteSdp_1.RemoteSdp({
115
99
  iceParameters,
@@ -134,49 +118,40 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
134
118
  iceTransportPolicy: iceTransportPolicy ?? 'all',
135
119
  bundlePolicy: 'max-bundle',
136
120
  rtcpMuxPolicy: 'require',
137
- sdpSemantics: 'unified-plan',
138
121
  ...additionalSettings,
139
- }, proprietaryConstraints);
140
- this._pc.addEventListener('icegatheringstatechange', () => {
141
- this.emit('@icegatheringstatechange', this._pc.iceGatheringState);
142
- });
143
- this._pc.addEventListener('icecandidateerror', (event) => {
144
- this.emit('@icecandidateerror', event);
145
122
  });
123
+ this._pc.addEventListener('icegatheringstatechange', this.onIceGatheringStateChange);
124
+ this._pc.addEventListener('icecandidateerror', this.onIceCandidateError);
146
125
  if (this._pc.connectionState) {
147
- this._pc.addEventListener('connectionstatechange', () => {
148
- this.emit('@connectionstatechange', this._pc.connectionState);
149
- });
126
+ this._pc.addEventListener('connectionstatechange', this.onConnectionStateChange);
150
127
  }
151
128
  else {
152
129
  logger.warn('run() | pc.connectionState not supported, using pc.iceConnectionState');
153
- this._pc.addEventListener('iceconnectionstatechange', () => {
154
- switch (this._pc.iceConnectionState) {
155
- case 'checking': {
156
- this.emit('@connectionstatechange', 'connecting');
157
- break;
158
- }
159
- case 'connected':
160
- case 'completed': {
161
- this.emit('@connectionstatechange', 'connected');
162
- break;
163
- }
164
- case 'failed': {
165
- this.emit('@connectionstatechange', 'failed');
166
- break;
167
- }
168
- case 'disconnected': {
169
- this.emit('@connectionstatechange', 'disconnected');
170
- break;
171
- }
172
- case 'closed': {
173
- this.emit('@connectionstatechange', 'closed');
174
- break;
175
- }
176
- }
177
- });
130
+ this._pc.addEventListener('iceconnectionstatechange', this.onIceConnectionStateChange);
178
131
  }
179
132
  }
133
+ get name() {
134
+ return NAME;
135
+ }
136
+ close() {
137
+ logger.debug('close()');
138
+ if (this._closed) {
139
+ return;
140
+ }
141
+ this._closed = true;
142
+ // Close RTCPeerConnection.
143
+ try {
144
+ this._pc.close();
145
+ }
146
+ catch (error) { }
147
+ this._pc.removeEventListener('icegatheringstatechange', this.onIceGatheringStateChange);
148
+ this._pc.removeEventListener('icecandidateerror', this.onIceCandidateError);
149
+ this._pc.removeEventListener('connectionstatechange', this.onConnectionStateChange);
150
+ this._pc.removeEventListener('iceconnectionstatechange', this.onIceConnectionStateChange);
151
+ this.emit('@close');
152
+ // Invoke close() in EnhancedEventEmitter classes.
153
+ super.close();
154
+ }
180
155
  async updateIceServers(iceServers) {
181
156
  this.assertNotClosed();
182
157
  logger.debug('updateIceServers()');
@@ -196,12 +171,18 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
196
171
  const offer = await this._pc.createOffer({ iceRestart: true });
197
172
  logger.debug('restartIce() | calling pc.setLocalDescription() [offer:%o]', offer);
198
173
  await this._pc.setLocalDescription(offer);
199
- const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
174
+ const answer = {
175
+ type: 'answer',
176
+ sdp: this._remoteSdp.getSdp(),
177
+ };
200
178
  logger.debug('restartIce() | calling pc.setRemoteDescription() [answer:%o]', answer);
201
179
  await this._pc.setRemoteDescription(answer);
202
180
  }
203
181
  else {
204
- const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
182
+ const offer = {
183
+ type: 'offer',
184
+ sdp: this._remoteSdp.getSdp(),
185
+ };
205
186
  logger.debug('restartIce() | calling pc.setRemoteDescription() [offer:%o]', offer);
206
187
  await this._pc.setRemoteDescription(offer);
207
188
  const answer = await this._pc.createAnswer();
@@ -236,8 +217,6 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
236
217
  });
237
218
  let offer = await this._pc.createOffer();
238
219
  let localSdpObject = sdpTransform.parse(offer.sdp);
239
- // @ts-expect-error --- sdpTransform.SessionDescription type doesn't
240
- // define extmapAllowMixed field.
241
220
  if (localSdpObject.extmapAllowMixed) {
242
221
  this._remoteSdp.setSessionExtmapAllowMixed();
243
222
  }
@@ -263,7 +242,10 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
263
242
  offerMediaObject,
264
243
  numStreams: layers.spatialLayers,
265
244
  });
266
- offer = { type: 'offer', sdp: sdpTransform.write(localSdpObject) };
245
+ offer = {
246
+ type: 'offer',
247
+ sdp: sdpTransform.write(localSdpObject),
248
+ };
267
249
  }
268
250
  logger.debug('send() | calling pc.setLocalDescription() [offer:%o]', offer);
269
251
  await this._pc.setLocalDescription(offer);
@@ -321,7 +303,10 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
321
303
  answerRtpParameters: sendingRemoteRtpParameters,
322
304
  codecOptions,
323
305
  });
324
- const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
306
+ const answer = {
307
+ type: 'answer',
308
+ sdp: this._remoteSdp.getSdp(),
309
+ };
325
310
  logger.debug('send() | calling pc.setRemoteDescription() [answer:%o]', answer);
326
311
  await this._pc.setRemoteDescription(answer);
327
312
  // Store in the map.
@@ -354,7 +339,10 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
354
339
  const offer = await this._pc.createOffer();
355
340
  logger.debug('stopSending() | calling pc.setLocalDescription() [offer:%o]', offer);
356
341
  await this._pc.setLocalDescription(offer);
357
- const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
342
+ const answer = {
343
+ type: 'answer',
344
+ sdp: this._remoteSdp.getSdp(),
345
+ };
358
346
  logger.debug('stopSending() | calling pc.setRemoteDescription() [answer:%o]', answer);
359
347
  await this._pc.setRemoteDescription(answer);
360
348
  this._mapMidTransceiver.delete(localId);
@@ -372,7 +360,10 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
372
360
  const offer = await this._pc.createOffer();
373
361
  logger.debug('pauseSending() | calling pc.setLocalDescription() [offer:%o]', offer);
374
362
  await this._pc.setLocalDescription(offer);
375
- const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
363
+ const answer = {
364
+ type: 'answer',
365
+ sdp: this._remoteSdp.getSdp(),
366
+ };
376
367
  logger.debug('pauseSending() | calling pc.setRemoteDescription() [answer:%o]', answer);
377
368
  await this._pc.setRemoteDescription(answer);
378
369
  }
@@ -389,7 +380,10 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
389
380
  const offer = await this._pc.createOffer();
390
381
  logger.debug('resumeSending() | calling pc.setLocalDescription() [offer:%o]', offer);
391
382
  await this._pc.setLocalDescription(offer);
392
- const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
383
+ const answer = {
384
+ type: 'answer',
385
+ sdp: this._remoteSdp.getSdp(),
386
+ };
393
387
  logger.debug('resumeSending() | calling pc.setRemoteDescription() [answer:%o]', answer);
394
388
  await this._pc.setRemoteDescription(answer);
395
389
  }
@@ -430,7 +424,10 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
430
424
  const offer = await this._pc.createOffer();
431
425
  logger.debug('setMaxSpatialLayer() | calling pc.setLocalDescription() [offer:%o]', offer);
432
426
  await this._pc.setLocalDescription(offer);
433
- const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
427
+ const answer = {
428
+ type: 'answer',
429
+ sdp: this._remoteSdp.getSdp(),
430
+ };
434
431
  logger.debug('setMaxSpatialLayer() | calling pc.setRemoteDescription() [answer:%o]', answer);
435
432
  await this._pc.setRemoteDescription(answer);
436
433
  }
@@ -451,7 +448,10 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
451
448
  const offer = await this._pc.createOffer();
452
449
  logger.debug('setRtpEncodingParameters() | calling pc.setLocalDescription() [offer:%o]', offer);
453
450
  await this._pc.setLocalDescription(offer);
454
- const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
451
+ const answer = {
452
+ type: 'answer',
453
+ sdp: this._remoteSdp.getSdp(),
454
+ };
455
455
  logger.debug('setRtpEncodingParameters() | calling pc.setRemoteDescription() [answer:%o]', answer);
456
456
  await this._pc.setRemoteDescription(answer);
457
457
  }
@@ -485,7 +485,7 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
485
485
  if (!this._hasDataChannelMediaSection) {
486
486
  const offer = await this._pc.createOffer();
487
487
  const localSdpObject = sdpTransform.parse(offer.sdp);
488
- const offerMediaObject = localSdpObject.media.find((m) => m.type === 'application');
488
+ const offerMediaObject = localSdpObject.media.find(m => m.type === 'application');
489
489
  if (!this._transportReady) {
490
490
  await this.setupTransport({
491
491
  localDtlsRole: this._forcedLocalDtlsRole ?? 'client',
@@ -495,7 +495,10 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
495
495
  logger.debug('sendDataChannel() | calling pc.setLocalDescription() [offer:%o]', offer);
496
496
  await this._pc.setLocalDescription(offer);
497
497
  this._remoteSdp.sendSctpAssociation({ offerMediaObject });
498
- const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
498
+ const answer = {
499
+ type: 'answer',
500
+ sdp: this._remoteSdp.getSdp(),
501
+ };
499
502
  logger.debug('sendDataChannel() | calling pc.setRemoteDescription() [answer:%o]', answer);
500
503
  await this._pc.setRemoteDescription(answer);
501
504
  this._hasDataChannelMediaSection = true;
@@ -526,7 +529,10 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
526
529
  trackId,
527
530
  });
528
531
  }
529
- const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
532
+ const offer = {
533
+ type: 'offer',
534
+ sdp: this._remoteSdp.getSdp(),
535
+ };
530
536
  logger.debug('receive() | calling pc.setRemoteDescription() [offer:%o]', offer);
531
537
  await this._pc.setRemoteDescription(offer);
532
538
  let answer = await this._pc.createAnswer();
@@ -534,7 +540,7 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
534
540
  for (const options of optionsList) {
535
541
  const { trackId, rtpParameters } = options;
536
542
  const localId = mapLocalId.get(trackId);
537
- const answerMediaObject = localSdpObject.media.find((m) => String(m.mid) === localId);
543
+ const answerMediaObject = localSdpObject.media.find(m => String(m.mid) === localId);
538
544
  // May need to modify codec parameters in the answer based on codec
539
545
  // parameters in the offer.
540
546
  sdpCommonUtils.applyCodecParameters({
@@ -542,7 +548,10 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
542
548
  answerMediaObject,
543
549
  });
544
550
  }
545
- answer = { type: 'answer', sdp: sdpTransform.write(localSdpObject) };
551
+ answer = {
552
+ type: 'answer',
553
+ sdp: sdpTransform.write(localSdpObject),
554
+ };
546
555
  if (!this._transportReady) {
547
556
  await this.setupTransport({
548
557
  localDtlsRole: this._forcedLocalDtlsRole ?? 'client',
@@ -585,7 +594,10 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
585
594
  }
586
595
  this._remoteSdp.closeMediaSection(transceiver.mid);
587
596
  }
588
- const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
597
+ const offer = {
598
+ type: 'offer',
599
+ sdp: this._remoteSdp.getSdp(),
600
+ };
589
601
  logger.debug('stopReceiving() | calling pc.setRemoteDescription() [offer:%o]', offer);
590
602
  await this._pc.setRemoteDescription(offer);
591
603
  const answer = await this._pc.createAnswer();
@@ -607,7 +619,10 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
607
619
  transceiver.direction = 'inactive';
608
620
  this._remoteSdp.pauseMediaSection(localId);
609
621
  }
610
- const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
622
+ const offer = {
623
+ type: 'offer',
624
+ sdp: this._remoteSdp.getSdp(),
625
+ };
611
626
  logger.debug('pauseReceiving() | calling pc.setRemoteDescription() [offer:%o]', offer);
612
627
  await this._pc.setRemoteDescription(offer);
613
628
  const answer = await this._pc.createAnswer();
@@ -626,7 +641,10 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
626
641
  transceiver.direction = 'recvonly';
627
642
  this._remoteSdp.resumeReceivingMediaSection(localId);
628
643
  }
629
- const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
644
+ const offer = {
645
+ type: 'offer',
646
+ sdp: this._remoteSdp.getSdp(),
647
+ };
630
648
  logger.debug('resumeReceiving() | calling pc.setRemoteDescription() [offer:%o]', offer);
631
649
  await this._pc.setRemoteDescription(offer);
632
650
  const answer = await this._pc.createAnswer();
@@ -660,7 +678,10 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
660
678
  // m=application section.
661
679
  if (!this._hasDataChannelMediaSection) {
662
680
  this._remoteSdp.receiveSctpAssociation();
663
- const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
681
+ const offer = {
682
+ type: 'offer',
683
+ sdp: this._remoteSdp.getSdp(),
684
+ };
664
685
  logger.debug('receiveDataChannel() | calling pc.setRemoteDescription() [offer:%o]', offer);
665
686
  await this._pc.setRemoteDescription(offer);
666
687
  const answer = await this._pc.createAnswer();
@@ -695,6 +716,40 @@ class Chrome74 extends HandlerInterface_1.HandlerInterface {
695
716
  });
696
717
  this._transportReady = true;
697
718
  }
719
+ onIceGatheringStateChange = () => {
720
+ this.emit('@icegatheringstatechange', this._pc.iceGatheringState);
721
+ };
722
+ onIceCandidateError = (event) => {
723
+ this.emit('@icecandidateerror', event);
724
+ };
725
+ onConnectionStateChange = () => {
726
+ this.emit('@connectionstatechange', this._pc.connectionState);
727
+ };
728
+ onIceConnectionStateChange = () => {
729
+ switch (this._pc.iceConnectionState) {
730
+ case 'checking': {
731
+ this.emit('@connectionstatechange', 'connecting');
732
+ break;
733
+ }
734
+ case 'connected':
735
+ case 'completed': {
736
+ this.emit('@connectionstatechange', 'connected');
737
+ break;
738
+ }
739
+ case 'failed': {
740
+ this.emit('@connectionstatechange', 'failed');
741
+ break;
742
+ }
743
+ case 'disconnected': {
744
+ this.emit('@connectionstatechange', 'disconnected');
745
+ break;
746
+ }
747
+ case 'closed': {
748
+ this.emit('@connectionstatechange', 'closed');
749
+ break;
750
+ }
751
+ }
752
+ };
698
753
  assertNotClosed() {
699
754
  if (this._closed) {
700
755
  throw new errors_1.InvalidStateError('method called in a closed handler');
@@ -1,16 +1,17 @@
1
- import { HandlerInterface, type HandlerRunOptions, type HandlerSendOptions, type HandlerSendResult, type HandlerReceiveOptions, type HandlerReceiveResult, type HandlerSendDataChannelOptions, type HandlerSendDataChannelResult, type HandlerReceiveDataChannelOptions, type HandlerReceiveDataChannelResult } from './HandlerInterface';
1
+ import { EnhancedEventEmitter } from '../enhancedEvents';
2
2
  import type { IceParameters, DtlsParameters, IceGatheringState, ConnectionState } from '../Transport';
3
3
  import type { RtpCapabilities } from '../RtpParameters';
4
4
  import type { SctpCapabilities } from '../SctpParameters';
5
+ import type { HandlerFactory, HandlerInterface, HandlerEvents, HandlerSendOptions, HandlerSendResult, HandlerReceiveOptions, HandlerReceiveResult, HandlerSendDataChannelOptions, HandlerSendDataChannelResult, HandlerReceiveDataChannelOptions, HandlerReceiveDataChannelResult } from './HandlerInterface';
5
6
  export type FakeParameters = {
6
7
  generateNativeRtpCapabilities: () => RtpCapabilities;
7
8
  generateNativeSctpCapabilities: () => SctpCapabilities;
8
9
  generateLocalDtlsParameters: () => DtlsParameters;
9
10
  };
10
- export declare class FakeHandler extends HandlerInterface {
11
+ export declare class FakeHandler extends EnhancedEventEmitter<HandlerEvents> implements HandlerInterface {
11
12
  private _closed;
12
- private fakeParameters;
13
- private _rtpParametersByKind?;
13
+ private _fakeParameters;
14
+ private _rtpParametersByKind;
14
15
  private _cname;
15
16
  private _transportReady;
16
17
  private _nextLocalId;
@@ -19,15 +20,12 @@ export declare class FakeHandler extends HandlerInterface {
19
20
  /**
20
21
  * Creates a factory function.
21
22
  */
22
- static createFactory(fakeParameters: FakeParameters): () => FakeHandler;
23
- constructor(fakeParameters: any);
23
+ static createFactory(fakeParameters: FakeParameters): HandlerFactory;
24
+ private constructor();
24
25
  get name(): string;
25
26
  close(): void;
26
27
  setIceGatheringState(iceGatheringState: IceGatheringState): void;
27
28
  setConnectionState(connectionState: ConnectionState): void;
28
- getNativeRtpCapabilities(): Promise<RtpCapabilities>;
29
- getNativeSctpCapabilities(): Promise<SctpCapabilities>;
30
- run({ direction, iceParameters, iceCandidates, dtlsParameters, sctpParameters, iceServers, iceTransportPolicy, proprietaryConstraints, extendedRtpCapabilities, }: HandlerRunOptions): void;
31
29
  updateIceServers(iceServers: RTCIceServer[]): Promise<void>;
32
30
  restartIce(iceParameters: IceParameters): Promise<void>;
33
31
  getTransportStats(): Promise<RTCStatsReport>;
@@ -37,7 +35,7 @@ export declare class FakeHandler extends HandlerInterface {
37
35
  resumeSending(localId: string): Promise<void>;
38
36
  replaceTrack(localId: string, track: MediaStreamTrack | null): Promise<void>;
39
37
  setMaxSpatialLayer(localId: string, spatialLayer: number): Promise<void>;
40
- setRtpEncodingParameters(localId: string, params: any): Promise<void>;
38
+ setRtpEncodingParameters(localId: string, params: Partial<RTCRtpEncodingParameters>): Promise<void>;
41
39
  getSenderStats(localId: string): Promise<RTCStatsReport>;
42
40
  sendDataChannel({ ordered, maxPacketLifeTime, maxRetransmits, label, protocol, }: HandlerSendDataChannelOptions): Promise<HandlerSendDataChannelResult>;
43
41
  receive(optionsList: HandlerReceiveOptions[]): Promise<HandlerReceiveResult[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"FakeHandler.d.ts","sourceRoot":"","sources":["../../src/handlers/FakeHandler.ts"],"names":[],"mappings":"AAMA,OAAO,EACN,gBAAgB,EAChB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,6BAA6B,EAClC,KAAK,4BAA4B,EACjC,KAAK,gCAAgC,EACrC,KAAK,+BAA+B,EACpC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EACX,aAAa,EACb,cAAc,EAEd,iBAAiB,EACjB,eAAe,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,eAAe,EAAiB,MAAM,kBAAkB,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAqD1D,MAAM,MAAM,cAAc,GAAG;IAC5B,6B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