mediasoup-client 3.6.79 → 3.6.81

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 (61) hide show
  1. package/lib/Consumer.d.ts.map +1 -1
  2. package/lib/Consumer.js +6 -3
  3. package/lib/DataConsumer.d.ts.map +1 -1
  4. package/lib/DataConsumer.js +14 -7
  5. package/lib/DataProducer.d.ts.map +1 -1
  6. package/lib/DataProducer.js +18 -9
  7. package/lib/Device.d.ts +1 -1
  8. package/lib/Device.d.ts.map +1 -1
  9. package/lib/Device.js +37 -15
  10. package/lib/Producer.d.ts +1 -0
  11. package/lib/Producer.d.ts.map +1 -1
  12. package/lib/Producer.js +28 -14
  13. package/lib/handlers/Chrome111.d.ts +49 -0
  14. package/lib/handlers/Chrome111.d.ts.map +1 -0
  15. package/lib/handlers/Chrome111.js +658 -0
  16. package/lib/handlers/Chrome55.d.ts.map +1 -1
  17. package/lib/handlers/Chrome55.js +13 -7
  18. package/lib/handlers/Chrome67.d.ts.map +1 -1
  19. package/lib/handlers/Chrome67.js +33 -17
  20. package/lib/handlers/Chrome70.d.ts.map +1 -1
  21. package/lib/handlers/Chrome70.js +29 -15
  22. package/lib/handlers/Chrome74.d.ts.map +1 -1
  23. package/lib/handlers/Chrome74.js +36 -19
  24. package/lib/handlers/Edge11.d.ts.map +1 -1
  25. package/lib/handlers/Edge11.js +30 -15
  26. package/lib/handlers/FakeHandler.d.ts.map +1 -1
  27. package/lib/handlers/FakeHandler.js +16 -8
  28. package/lib/handlers/Firefox60.d.ts.map +1 -1
  29. package/lib/handlers/Firefox60.js +39 -21
  30. package/lib/handlers/ReactNative.d.ts.map +1 -1
  31. package/lib/handlers/ReactNative.js +13 -7
  32. package/lib/handlers/ReactNativeUnifiedPlan.d.ts.map +1 -1
  33. package/lib/handlers/ReactNativeUnifiedPlan.js +41 -17
  34. package/lib/handlers/Safari11.d.ts.map +1 -1
  35. package/lib/handlers/Safari11.js +33 -17
  36. package/lib/handlers/Safari12.d.ts.map +1 -1
  37. package/lib/handlers/Safari12.js +39 -20
  38. package/lib/handlers/ortc/edgeUtils.d.ts.map +1 -1
  39. package/lib/handlers/ortc/edgeUtils.js +8 -4
  40. package/lib/handlers/ortc/utils.d.ts +6 -0
  41. package/lib/handlers/ortc/utils.d.ts.map +1 -0
  42. package/lib/handlers/ortc/utils.js +20 -0
  43. package/lib/handlers/sdp/MediaSection.d.ts.map +1 -1
  44. package/lib/handlers/sdp/MediaSection.js +56 -23
  45. package/lib/handlers/sdp/RemoteSdp.d.ts.map +1 -1
  46. package/lib/handlers/sdp/RemoteSdp.js +8 -4
  47. package/lib/handlers/sdp/commonUtils.d.ts.map +1 -1
  48. package/lib/handlers/sdp/commonUtils.js +26 -13
  49. package/lib/handlers/sdp/plainRtpUtils.d.ts.map +1 -1
  50. package/lib/handlers/sdp/plainRtpUtils.js +8 -4
  51. package/lib/handlers/sdp/planBUtils.d.ts.map +1 -1
  52. package/lib/handlers/sdp/planBUtils.js +22 -11
  53. package/lib/handlers/sdp/unifiedPlanUtils.d.ts.map +1 -1
  54. package/lib/handlers/sdp/unifiedPlanUtils.js +16 -8
  55. package/lib/index.d.ts +1 -1
  56. package/lib/index.js +1 -1
  57. package/lib/ortc.d.ts.map +1 -1
  58. package/lib/ortc.js +196 -98
  59. package/lib/utils.d.ts.map +1 -1
  60. package/lib/utils.js +2 -1
  61. package/package.json +4 -4
@@ -0,0 +1,658 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Chrome111 = void 0;
27
+ const sdpTransform = __importStar(require("sdp-transform"));
28
+ const Logger_1 = require("../Logger");
29
+ const utils = __importStar(require("../utils"));
30
+ const ortc = __importStar(require("../ortc"));
31
+ const sdpCommonUtils = __importStar(require("./sdp/commonUtils"));
32
+ const sdpUnifiedPlanUtils = __importStar(require("./sdp/unifiedPlanUtils"));
33
+ const ortcUtils = __importStar(require("./ortc/utils"));
34
+ const HandlerInterface_1 = require("./HandlerInterface");
35
+ const RemoteSdp_1 = require("./sdp/RemoteSdp");
36
+ const scalabilityModes_1 = require("../scalabilityModes");
37
+ const logger = new Logger_1.Logger('Chrome111');
38
+ const SCTP_NUM_STREAMS = { OS: 1024, MIS: 1024 };
39
+ class Chrome111 extends HandlerInterface_1.HandlerInterface {
40
+ /**
41
+ * Creates a factory function.
42
+ */
43
+ static createFactory() {
44
+ return () => new Chrome111();
45
+ }
46
+ constructor() {
47
+ super();
48
+ // Map of RTCTransceivers indexed by MID.
49
+ this._mapMidTransceiver = new Map();
50
+ // Local stream for sending.
51
+ this._sendStream = new MediaStream();
52
+ // Whether a DataChannel m=application section has been created.
53
+ this._hasDataChannelMediaSection = false;
54
+ // Sending DataChannel id value counter. Incremented for each new DataChannel.
55
+ this._nextSendSctpStreamId = 0;
56
+ // Got transport local and remote parameters.
57
+ this._transportReady = false;
58
+ }
59
+ get name() {
60
+ return 'Chrome111';
61
+ }
62
+ close() {
63
+ logger.debug('close()');
64
+ // Close RTCPeerConnection.
65
+ if (this._pc) {
66
+ try {
67
+ this._pc.close();
68
+ }
69
+ catch (error) { }
70
+ }
71
+ this.emit('@close');
72
+ }
73
+ async getNativeRtpCapabilities() {
74
+ logger.debug('getNativeRtpCapabilities()');
75
+ const pc = new RTCPeerConnection({
76
+ iceServers: [],
77
+ iceTransportPolicy: 'all',
78
+ bundlePolicy: 'max-bundle',
79
+ rtcpMuxPolicy: 'require',
80
+ sdpSemantics: 'unified-plan'
81
+ });
82
+ try {
83
+ pc.addTransceiver('audio');
84
+ pc.addTransceiver('video');
85
+ const offer = await pc.createOffer();
86
+ try {
87
+ pc.close();
88
+ }
89
+ catch (error) { }
90
+ const sdpObject = sdpTransform.parse(offer.sdp);
91
+ const nativeRtpCapabilities = sdpCommonUtils.extractRtpCapabilities({ sdpObject });
92
+ // libwebrtc supports NACK for OPUS but doesn't announce it.
93
+ ortcUtils.addNackSuppportForOpus(nativeRtpCapabilities);
94
+ return nativeRtpCapabilities;
95
+ }
96
+ catch (error) {
97
+ try {
98
+ pc.close();
99
+ }
100
+ catch (error2) { }
101
+ throw error;
102
+ }
103
+ }
104
+ async getNativeSctpCapabilities() {
105
+ logger.debug('getNativeSctpCapabilities()');
106
+ return {
107
+ numStreams: SCTP_NUM_STREAMS
108
+ };
109
+ }
110
+ run({ direction, iceParameters, iceCandidates, dtlsParameters, sctpParameters, iceServers, iceTransportPolicy, additionalSettings, proprietaryConstraints, extendedRtpCapabilities }) {
111
+ logger.debug('run()');
112
+ this._direction = direction;
113
+ this._remoteSdp = new RemoteSdp_1.RemoteSdp({
114
+ iceParameters,
115
+ iceCandidates,
116
+ dtlsParameters,
117
+ sctpParameters
118
+ });
119
+ this._sendingRtpParametersByKind =
120
+ {
121
+ audio: ortc.getSendingRtpParameters('audio', extendedRtpCapabilities),
122
+ video: ortc.getSendingRtpParameters('video', extendedRtpCapabilities)
123
+ };
124
+ this._sendingRemoteRtpParametersByKind =
125
+ {
126
+ audio: ortc.getSendingRemoteRtpParameters('audio', extendedRtpCapabilities),
127
+ video: ortc.getSendingRemoteRtpParameters('video', extendedRtpCapabilities)
128
+ };
129
+ if (dtlsParameters.role && dtlsParameters.role !== 'auto') {
130
+ this._forcedLocalDtlsRole = dtlsParameters.role === 'server'
131
+ ? 'client'
132
+ : 'server';
133
+ }
134
+ this._pc = new RTCPeerConnection({
135
+ iceServers: iceServers || [],
136
+ iceTransportPolicy: iceTransportPolicy || 'all',
137
+ bundlePolicy: 'max-bundle',
138
+ rtcpMuxPolicy: 'require',
139
+ sdpSemantics: 'unified-plan',
140
+ ...additionalSettings
141
+ }, proprietaryConstraints);
142
+ if (this._pc.connectionState) {
143
+ this._pc.addEventListener('connectionstatechange', () => {
144
+ this.emit('@connectionstatechange', this._pc.connectionState);
145
+ });
146
+ }
147
+ else {
148
+ logger.warn('run() | pc.connectionState not supported, using pc.iceConnectionState');
149
+ this._pc.addEventListener('iceconnectionstatechange', () => {
150
+ switch (this._pc.iceConnectionState) {
151
+ case 'checking':
152
+ this.emit('@connectionstatechange', 'connecting');
153
+ break;
154
+ case 'connected':
155
+ case 'completed':
156
+ this.emit('@connectionstatechange', 'connected');
157
+ break;
158
+ case 'failed':
159
+ this.emit('@connectionstatechange', 'failed');
160
+ break;
161
+ case 'disconnected':
162
+ this.emit('@connectionstatechange', 'disconnected');
163
+ break;
164
+ case 'closed':
165
+ this.emit('@connectionstatechange', 'closed');
166
+ break;
167
+ }
168
+ });
169
+ }
170
+ }
171
+ async updateIceServers(iceServers) {
172
+ logger.debug('updateIceServers()');
173
+ const configuration = this._pc.getConfiguration();
174
+ configuration.iceServers = iceServers;
175
+ this._pc.setConfiguration(configuration);
176
+ }
177
+ async restartIce(iceParameters) {
178
+ logger.debug('restartIce()');
179
+ // Provide the remote SDP handler with new remote ICE parameters.
180
+ this._remoteSdp.updateIceParameters(iceParameters);
181
+ if (!this._transportReady) {
182
+ return;
183
+ }
184
+ if (this._direction === 'send') {
185
+ const offer = await this._pc.createOffer({ iceRestart: true });
186
+ logger.debug('restartIce() | calling pc.setLocalDescription() [offer:%o]', offer);
187
+ await this._pc.setLocalDescription(offer);
188
+ const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
189
+ logger.debug('restartIce() | calling pc.setRemoteDescription() [answer:%o]', answer);
190
+ await this._pc.setRemoteDescription(answer);
191
+ }
192
+ else {
193
+ const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
194
+ logger.debug('restartIce() | calling pc.setRemoteDescription() [offer:%o]', offer);
195
+ await this._pc.setRemoteDescription(offer);
196
+ const answer = await this._pc.createAnswer();
197
+ logger.debug('restartIce() | calling pc.setLocalDescription() [answer:%o]', answer);
198
+ await this._pc.setLocalDescription(answer);
199
+ }
200
+ }
201
+ async getTransportStats() {
202
+ return this._pc.getStats();
203
+ }
204
+ async send({ track, encodings, codecOptions, codec }) {
205
+ var _a;
206
+ this.assertSendDirection();
207
+ logger.debug('send() [kind:%s, track.id:%s]', track.kind, track.id);
208
+ if (encodings && encodings.length > 1) {
209
+ encodings.forEach((encoding, idx) => {
210
+ encoding.rid = `r${idx}`;
211
+ });
212
+ // Set rid and verify scalabilityMode in each encoding.
213
+ // NOTE: Even if WebRTC allows different scalabilityMode (different number
214
+ // of temporal layers) per simulcast stream, we need that those are the
215
+ // same in all them, so let's pick up the highest value.
216
+ // NOTE: If scalabilityMode is not given, Chrome will use L1T3.
217
+ let nextRid = 1;
218
+ let maxTemporalLayers = 1;
219
+ for (const encoding of encodings) {
220
+ const temporalLayers = encoding.scalabilityMode
221
+ ? (0, scalabilityModes_1.parse)(encoding.scalabilityMode).temporalLayers
222
+ : 3;
223
+ if (temporalLayers > maxTemporalLayers) {
224
+ maxTemporalLayers = temporalLayers;
225
+ }
226
+ }
227
+ for (const encoding of encodings) {
228
+ encoding.rid = `r${nextRid++}`;
229
+ encoding.scalabilityMode = `L1T${maxTemporalLayers}`;
230
+ }
231
+ }
232
+ const sendingRtpParameters = utils.clone(this._sendingRtpParametersByKind[track.kind], {});
233
+ // This may throw.
234
+ sendingRtpParameters.codecs =
235
+ ortc.reduceCodecs(sendingRtpParameters.codecs, codec);
236
+ const sendingRemoteRtpParameters = utils.clone(this._sendingRemoteRtpParametersByKind[track.kind], {});
237
+ // This may throw.
238
+ sendingRemoteRtpParameters.codecs =
239
+ ortc.reduceCodecs(sendingRemoteRtpParameters.codecs, codec);
240
+ const mediaSectionIdx = this._remoteSdp.getNextMediaSectionIdx();
241
+ const transceiver = this._pc.addTransceiver(track, {
242
+ direction: 'sendonly',
243
+ streams: [this._sendStream],
244
+ sendEncodings: encodings
245
+ });
246
+ const offer = await this._pc.createOffer();
247
+ let localSdpObject = sdpTransform.parse(offer.sdp);
248
+ if (!this._transportReady) {
249
+ await this.setupTransport({
250
+ localDtlsRole: (_a = this._forcedLocalDtlsRole) !== null && _a !== void 0 ? _a : 'client',
251
+ localSdpObject
252
+ });
253
+ }
254
+ logger.debug('send() | calling pc.setLocalDescription() [offer:%o]', offer);
255
+ await this._pc.setLocalDescription(offer);
256
+ // We can now get the transceiver.mid.
257
+ const localId = transceiver.mid;
258
+ // Set MID.
259
+ sendingRtpParameters.mid = localId;
260
+ localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);
261
+ const offerMediaObject = localSdpObject.media[mediaSectionIdx.idx];
262
+ // Set RTCP CNAME.
263
+ sendingRtpParameters.rtcp.cname =
264
+ sdpCommonUtils.getCname({ offerMediaObject });
265
+ // Set RTP encodings by parsing the SDP offer if no encodings are given.
266
+ if (!encodings) {
267
+ sendingRtpParameters.encodings =
268
+ sdpUnifiedPlanUtils.getRtpEncodings({ offerMediaObject });
269
+ }
270
+ // Set RTP encodings by parsing the SDP offer and complete them with given
271
+ // one if just a single encoding has been given.
272
+ else if (encodings.length === 1) {
273
+ const newEncodings = sdpUnifiedPlanUtils.getRtpEncodings({ offerMediaObject });
274
+ Object.assign(newEncodings[0], encodings[0]);
275
+ sendingRtpParameters.encodings = newEncodings;
276
+ }
277
+ // Otherwise if more than 1 encoding are given use them verbatim.
278
+ else {
279
+ sendingRtpParameters.encodings = encodings;
280
+ }
281
+ this._remoteSdp.send({
282
+ offerMediaObject,
283
+ reuseMid: mediaSectionIdx.reuseMid,
284
+ offerRtpParameters: sendingRtpParameters,
285
+ answerRtpParameters: sendingRemoteRtpParameters,
286
+ codecOptions,
287
+ extmapAllowMixed: true
288
+ });
289
+ const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
290
+ logger.debug('send() | calling pc.setRemoteDescription() [answer:%o]', answer);
291
+ await this._pc.setRemoteDescription(answer);
292
+ // Store in the map.
293
+ this._mapMidTransceiver.set(localId, transceiver);
294
+ return {
295
+ localId,
296
+ rtpParameters: sendingRtpParameters,
297
+ rtpSender: transceiver.sender
298
+ };
299
+ }
300
+ async stopSending(localId) {
301
+ this.assertSendDirection();
302
+ logger.debug('stopSending() [localId:%s]', localId);
303
+ const transceiver = this._mapMidTransceiver.get(localId);
304
+ if (!transceiver) {
305
+ throw new Error('associated RTCRtpTransceiver not found');
306
+ }
307
+ transceiver.sender.replaceTrack(null);
308
+ this._pc.removeTrack(transceiver.sender);
309
+ const mediaSectionClosed = this._remoteSdp.closeMediaSection(transceiver.mid);
310
+ if (mediaSectionClosed) {
311
+ try {
312
+ transceiver.stop();
313
+ }
314
+ catch (error) { }
315
+ }
316
+ const offer = await this._pc.createOffer();
317
+ logger.debug('stopSending() | calling pc.setLocalDescription() [offer:%o]', offer);
318
+ await this._pc.setLocalDescription(offer);
319
+ const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
320
+ logger.debug('stopSending() | calling pc.setRemoteDescription() [answer:%o]', answer);
321
+ await this._pc.setRemoteDescription(answer);
322
+ this._mapMidTransceiver.delete(localId);
323
+ }
324
+ async pauseSending(localId) {
325
+ this.assertSendDirection();
326
+ logger.debug('pauseSending() [localId:%s]', localId);
327
+ const transceiver = this._mapMidTransceiver.get(localId);
328
+ if (!transceiver) {
329
+ throw new Error('associated RTCRtpTransceiver not found');
330
+ }
331
+ transceiver.direction = 'inactive';
332
+ this._remoteSdp.pauseMediaSection(localId);
333
+ const offer = await this._pc.createOffer();
334
+ logger.debug('pauseSending() | calling pc.setLocalDescription() [offer:%o]', offer);
335
+ await this._pc.setLocalDescription(offer);
336
+ const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
337
+ logger.debug('pauseSending() | calling pc.setRemoteDescription() [answer:%o]', answer);
338
+ await this._pc.setRemoteDescription(answer);
339
+ }
340
+ async resumeSending(localId) {
341
+ this.assertSendDirection();
342
+ logger.debug('resumeSending() [localId:%s]', localId);
343
+ const transceiver = this._mapMidTransceiver.get(localId);
344
+ this._remoteSdp.resumeSendingMediaSection(localId);
345
+ if (!transceiver) {
346
+ throw new Error('associated RTCRtpTransceiver not found');
347
+ }
348
+ transceiver.direction = 'sendonly';
349
+ const offer = await this._pc.createOffer();
350
+ logger.debug('resumeSending() | calling pc.setLocalDescription() [offer:%o]', offer);
351
+ await this._pc.setLocalDescription(offer);
352
+ const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
353
+ logger.debug('resumeSending() | calling pc.setRemoteDescription() [answer:%o]', answer);
354
+ await this._pc.setRemoteDescription(answer);
355
+ }
356
+ async replaceTrack(localId, track) {
357
+ this.assertSendDirection();
358
+ if (track) {
359
+ logger.debug('replaceTrack() [localId:%s, track.id:%s]', localId, track.id);
360
+ }
361
+ else {
362
+ logger.debug('replaceTrack() [localId:%s, no track]', localId);
363
+ }
364
+ const transceiver = this._mapMidTransceiver.get(localId);
365
+ if (!transceiver) {
366
+ throw new Error('associated RTCRtpTransceiver not found');
367
+ }
368
+ await transceiver.sender.replaceTrack(track);
369
+ }
370
+ async setMaxSpatialLayer(localId, spatialLayer) {
371
+ this.assertSendDirection();
372
+ logger.debug('setMaxSpatialLayer() [localId:%s, spatialLayer:%s]', localId, spatialLayer);
373
+ const transceiver = this._mapMidTransceiver.get(localId);
374
+ if (!transceiver) {
375
+ throw new Error('associated RTCRtpTransceiver not found');
376
+ }
377
+ const parameters = transceiver.sender.getParameters();
378
+ parameters.encodings.forEach((encoding, idx) => {
379
+ if (idx <= spatialLayer) {
380
+ encoding.active = true;
381
+ }
382
+ else {
383
+ encoding.active = false;
384
+ }
385
+ });
386
+ await transceiver.sender.setParameters(parameters);
387
+ this._remoteSdp.muxMediaSectionSimulcast(localId, parameters.encodings);
388
+ const offer = await this._pc.createOffer();
389
+ logger.debug('setMaxSpatialLayer() | calling pc.setLocalDescription() [offer:%o]', offer);
390
+ await this._pc.setLocalDescription(offer);
391
+ const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
392
+ logger.debug('setMaxSpatialLayer() | calling pc.setRemoteDescription() [answer:%o]', answer);
393
+ await this._pc.setRemoteDescription(answer);
394
+ }
395
+ async setRtpEncodingParameters(localId, params) {
396
+ this.assertSendDirection();
397
+ logger.debug('setRtpEncodingParameters() [localId:%s, params:%o]', localId, params);
398
+ const transceiver = this._mapMidTransceiver.get(localId);
399
+ if (!transceiver) {
400
+ throw new Error('associated RTCRtpTransceiver not found');
401
+ }
402
+ const parameters = transceiver.sender.getParameters();
403
+ parameters.encodings.forEach((encoding, idx) => {
404
+ parameters.encodings[idx] = { ...encoding, ...params };
405
+ });
406
+ await transceiver.sender.setParameters(parameters);
407
+ this._remoteSdp.muxMediaSectionSimulcast(localId, parameters.encodings);
408
+ const offer = await this._pc.createOffer();
409
+ logger.debug('setRtpEncodingParameters() | calling pc.setLocalDescription() [offer:%o]', offer);
410
+ await this._pc.setLocalDescription(offer);
411
+ const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
412
+ logger.debug('setRtpEncodingParameters() | calling pc.setRemoteDescription() [answer:%o]', answer);
413
+ await this._pc.setRemoteDescription(answer);
414
+ }
415
+ async getSenderStats(localId) {
416
+ this.assertSendDirection();
417
+ const transceiver = this._mapMidTransceiver.get(localId);
418
+ if (!transceiver) {
419
+ throw new Error('associated RTCRtpTransceiver not found');
420
+ }
421
+ return transceiver.sender.getStats();
422
+ }
423
+ async sendDataChannel({ ordered, maxPacketLifeTime, maxRetransmits, label, protocol }) {
424
+ var _a;
425
+ this.assertSendDirection();
426
+ const options = {
427
+ negotiated: true,
428
+ id: this._nextSendSctpStreamId,
429
+ ordered,
430
+ maxPacketLifeTime,
431
+ maxRetransmits,
432
+ protocol
433
+ };
434
+ logger.debug('sendDataChannel() [options:%o]', options);
435
+ const dataChannel = this._pc.createDataChannel(label, options);
436
+ // Increase next id.
437
+ this._nextSendSctpStreamId =
438
+ ++this._nextSendSctpStreamId % SCTP_NUM_STREAMS.MIS;
439
+ // If this is the first DataChannel we need to create the SDP answer with
440
+ // m=application section.
441
+ if (!this._hasDataChannelMediaSection) {
442
+ const offer = await this._pc.createOffer();
443
+ const localSdpObject = sdpTransform.parse(offer.sdp);
444
+ const offerMediaObject = localSdpObject.media
445
+ .find((m) => m.type === 'application');
446
+ if (!this._transportReady) {
447
+ await this.setupTransport({
448
+ localDtlsRole: (_a = this._forcedLocalDtlsRole) !== null && _a !== void 0 ? _a : 'client',
449
+ localSdpObject
450
+ });
451
+ }
452
+ logger.debug('sendDataChannel() | calling pc.setLocalDescription() [offer:%o]', offer);
453
+ await this._pc.setLocalDescription(offer);
454
+ this._remoteSdp.sendSctpAssociation({ offerMediaObject });
455
+ const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
456
+ logger.debug('sendDataChannel() | calling pc.setRemoteDescription() [answer:%o]', answer);
457
+ await this._pc.setRemoteDescription(answer);
458
+ this._hasDataChannelMediaSection = true;
459
+ }
460
+ const sctpStreamParameters = {
461
+ streamId: options.id,
462
+ ordered: options.ordered,
463
+ maxPacketLifeTime: options.maxPacketLifeTime,
464
+ maxRetransmits: options.maxRetransmits
465
+ };
466
+ return { dataChannel, sctpStreamParameters };
467
+ }
468
+ async receive(optionsList) {
469
+ var _a;
470
+ this.assertRecvDirection();
471
+ const results = [];
472
+ const mapLocalId = new Map();
473
+ for (const options of optionsList) {
474
+ const { trackId, kind, rtpParameters, streamId } = options;
475
+ logger.debug('receive() [trackId:%s, kind:%s]', trackId, kind);
476
+ const localId = rtpParameters.mid || String(this._mapMidTransceiver.size);
477
+ mapLocalId.set(trackId, localId);
478
+ this._remoteSdp.receive({
479
+ mid: localId,
480
+ kind,
481
+ offerRtpParameters: rtpParameters,
482
+ streamId: streamId || rtpParameters.rtcp.cname,
483
+ trackId
484
+ });
485
+ }
486
+ const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
487
+ logger.debug('receive() | calling pc.setRemoteDescription() [offer:%o]', offer);
488
+ await this._pc.setRemoteDescription(offer);
489
+ let answer = await this._pc.createAnswer();
490
+ const localSdpObject = sdpTransform.parse(answer.sdp);
491
+ for (const options of optionsList) {
492
+ const { trackId, rtpParameters } = options;
493
+ const localId = mapLocalId.get(trackId);
494
+ const answerMediaObject = localSdpObject.media
495
+ .find((m) => String(m.mid) === localId);
496
+ // May need to modify codec parameters in the answer based on codec
497
+ // parameters in the offer.
498
+ sdpCommonUtils.applyCodecParameters({
499
+ offerRtpParameters: rtpParameters,
500
+ answerMediaObject
501
+ });
502
+ }
503
+ answer = { type: 'answer', sdp: sdpTransform.write(localSdpObject) };
504
+ if (!this._transportReady) {
505
+ await this.setupTransport({
506
+ localDtlsRole: (_a = this._forcedLocalDtlsRole) !== null && _a !== void 0 ? _a : 'client',
507
+ localSdpObject
508
+ });
509
+ }
510
+ logger.debug('receive() | calling pc.setLocalDescription() [answer:%o]', answer);
511
+ await this._pc.setLocalDescription(answer);
512
+ for (const options of optionsList) {
513
+ const { trackId } = options;
514
+ const localId = mapLocalId.get(trackId);
515
+ const transceiver = this._pc.getTransceivers()
516
+ .find((t) => t.mid === localId);
517
+ if (!transceiver) {
518
+ throw new Error('new RTCRtpTransceiver not found');
519
+ }
520
+ else {
521
+ // Store in the map.
522
+ this._mapMidTransceiver.set(localId, transceiver);
523
+ results.push({
524
+ localId,
525
+ track: transceiver.receiver.track,
526
+ rtpReceiver: transceiver.receiver
527
+ });
528
+ }
529
+ }
530
+ return results;
531
+ }
532
+ async stopReceiving(localIds) {
533
+ this.assertRecvDirection();
534
+ for (const localId of localIds) {
535
+ logger.debug('stopReceiving() [localId:%s]', localId);
536
+ const transceiver = this._mapMidTransceiver.get(localId);
537
+ if (!transceiver) {
538
+ throw new Error('associated RTCRtpTransceiver not found');
539
+ }
540
+ this._remoteSdp.closeMediaSection(transceiver.mid);
541
+ }
542
+ const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
543
+ logger.debug('stopReceiving() | calling pc.setRemoteDescription() [offer:%o]', offer);
544
+ await this._pc.setRemoteDescription(offer);
545
+ const answer = await this._pc.createAnswer();
546
+ logger.debug('stopReceiving() | calling pc.setLocalDescription() [answer:%o]', answer);
547
+ await this._pc.setLocalDescription(answer);
548
+ for (const localId of localIds) {
549
+ this._mapMidTransceiver.delete(localId);
550
+ }
551
+ }
552
+ async pauseReceiving(localIds) {
553
+ this.assertRecvDirection();
554
+ for (const localId of localIds) {
555
+ logger.debug('pauseReceiving() [localId:%s]', localId);
556
+ const transceiver = this._mapMidTransceiver.get(localId);
557
+ if (!transceiver) {
558
+ throw new Error('associated RTCRtpTransceiver not found');
559
+ }
560
+ transceiver.direction = 'inactive';
561
+ this._remoteSdp.pauseMediaSection(localId);
562
+ }
563
+ const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
564
+ logger.debug('pauseReceiving() | calling pc.setRemoteDescription() [offer:%o]', offer);
565
+ await this._pc.setRemoteDescription(offer);
566
+ const answer = await this._pc.createAnswer();
567
+ logger.debug('pauseReceiving() | calling pc.setLocalDescription() [answer:%o]', answer);
568
+ await this._pc.setLocalDescription(answer);
569
+ }
570
+ async resumeReceiving(localIds) {
571
+ this.assertRecvDirection();
572
+ for (const localId of localIds) {
573
+ logger.debug('resumeReceiving() [localId:%s]', localId);
574
+ const transceiver = this._mapMidTransceiver.get(localId);
575
+ if (!transceiver) {
576
+ throw new Error('associated RTCRtpTransceiver not found');
577
+ }
578
+ transceiver.direction = 'recvonly';
579
+ this._remoteSdp.resumeReceivingMediaSection(localId);
580
+ }
581
+ const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
582
+ logger.debug('resumeReceiving() | calling pc.setRemoteDescription() [offer:%o]', offer);
583
+ await this._pc.setRemoteDescription(offer);
584
+ const answer = await this._pc.createAnswer();
585
+ logger.debug('resumeReceiving() | calling pc.setLocalDescription() [answer:%o]', answer);
586
+ await this._pc.setLocalDescription(answer);
587
+ }
588
+ async getReceiverStats(localId) {
589
+ this.assertRecvDirection();
590
+ const transceiver = this._mapMidTransceiver.get(localId);
591
+ if (!transceiver) {
592
+ throw new Error('associated RTCRtpTransceiver not found');
593
+ }
594
+ return transceiver.receiver.getStats();
595
+ }
596
+ async receiveDataChannel({ sctpStreamParameters, label, protocol }) {
597
+ var _a;
598
+ this.assertRecvDirection();
599
+ const { streamId, ordered, maxPacketLifeTime, maxRetransmits } = sctpStreamParameters;
600
+ const options = {
601
+ negotiated: true,
602
+ id: streamId,
603
+ ordered,
604
+ maxPacketLifeTime,
605
+ maxRetransmits,
606
+ protocol
607
+ };
608
+ logger.debug('receiveDataChannel() [options:%o]', options);
609
+ const dataChannel = this._pc.createDataChannel(label, options);
610
+ // If this is the first DataChannel we need to create the SDP offer with
611
+ // m=application section.
612
+ if (!this._hasDataChannelMediaSection) {
613
+ this._remoteSdp.receiveSctpAssociation();
614
+ const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
615
+ logger.debug('receiveDataChannel() | calling pc.setRemoteDescription() [offer:%o]', offer);
616
+ await this._pc.setRemoteDescription(offer);
617
+ const answer = await this._pc.createAnswer();
618
+ if (!this._transportReady) {
619
+ const localSdpObject = sdpTransform.parse(answer.sdp);
620
+ await this.setupTransport({
621
+ localDtlsRole: (_a = this._forcedLocalDtlsRole) !== null && _a !== void 0 ? _a : 'client',
622
+ localSdpObject
623
+ });
624
+ }
625
+ logger.debug('receiveDataChannel() | calling pc.setRemoteDescription() [answer:%o]', answer);
626
+ await this._pc.setLocalDescription(answer);
627
+ this._hasDataChannelMediaSection = true;
628
+ }
629
+ return { dataChannel };
630
+ }
631
+ async setupTransport({ localDtlsRole, localSdpObject }) {
632
+ if (!localSdpObject) {
633
+ localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);
634
+ }
635
+ // Get our local DTLS parameters.
636
+ const dtlsParameters = sdpCommonUtils.extractDtlsParameters({ sdpObject: localSdpObject });
637
+ // Set our DTLS role.
638
+ dtlsParameters.role = localDtlsRole;
639
+ // Update the remote DTLS role in the SDP.
640
+ this._remoteSdp.updateDtlsRole(localDtlsRole === 'client' ? 'server' : 'client');
641
+ // Need to tell the remote transport about our parameters.
642
+ await new Promise((resolve, reject) => {
643
+ this.safeEmit('@connect', { dtlsParameters }, resolve, reject);
644
+ });
645
+ this._transportReady = true;
646
+ }
647
+ assertSendDirection() {
648
+ if (this._direction !== 'send') {
649
+ throw new Error('method can just be called for handlers with "send" direction');
650
+ }
651
+ }
652
+ assertRecvDirection() {
653
+ if (this._direction !== 'recv') {
654
+ throw new Error('method can just be called for handlers with "recv" direction');
655
+ }
656
+ }
657
+ }
658
+ exports.Chrome111 = Chrome111;
@@ -1 +1 @@
1
- {"version":3,"file":"Chrome55.d.ts","sourceRoot":"","sources":["../../src/handlers/Chrome55.ts"],"names":[],"mappings":"AAOA,OAAO,EACN,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,6BAA6B,EAC7B,4BAA4B,EAC5B,gCAAgC,EAChC,+BAA+B,EAC/B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,aAAa,EAAY,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,eAAe,EAAiB,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAwB,MAAM,mBAAmB,CAAC;AAM3E,qBAAa,QAAS,SAAQ,gBAAgB;IAG7C,OAAO,CAAC,UAAU,CAAC,CAAkB;IAErC,O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