mediasoup-client 3.6.89 → 3.6.90

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