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,558 +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.ReactNative = void 0;
27
- const sdpTransform = __importStar(require("sdp-transform"));
28
- const Logger_1 = require("../Logger");
29
- const errors_1 = require("../errors");
30
- const utils = __importStar(require("../utils"));
31
- const ortc = __importStar(require("../ortc"));
32
- const sdpCommonUtils = __importStar(require("./sdp/commonUtils"));
33
- const sdpPlanBUtils = __importStar(require("./sdp/planBUtils"));
34
- const HandlerInterface_1 = require("./HandlerInterface");
35
- const RemoteSdp_1 = require("./sdp/RemoteSdp");
36
- const logger = new Logger_1.Logger('ReactNative');
37
- const SCTP_NUM_STREAMS = { OS: 1024, MIS: 1024 };
38
- class ReactNative extends HandlerInterface_1.HandlerInterface {
39
- /**
40
- * Creates a factory function.
41
- */
42
- static createFactory() {
43
- return () => new ReactNative();
44
- }
45
- constructor() {
46
- super();
47
- // Local stream for sending.
48
- this._sendStream = new MediaStream();
49
- // Map of sending MediaStreamTracks indexed by localId.
50
- this._mapSendLocalIdTrack = new Map();
51
- // Next sending localId.
52
- this._nextSendLocalId = 0;
53
- // Map of MID, RTP parameters and RTCRtpReceiver indexed by local id.
54
- // Value is an Object with mid, rtpParameters and rtpReceiver.
55
- this._mapRecvLocalIdInfo = new Map();
56
- // Whether a DataChannel m=application section has been created.
57
- this._hasDataChannelMediaSection = false;
58
- // Sending DataChannel id value counter. Incremented for each new DataChannel.
59
- this._nextSendSctpStreamId = 0;
60
- // Got transport local and remote parameters.
61
- this._transportReady = false;
62
- }
63
- get name() {
64
- return 'ReactNative';
65
- }
66
- close() {
67
- logger.debug('close()');
68
- // Free/dispose native MediaStream but DO NOT free/dispose native
69
- // MediaStreamTracks (that is parent's business).
70
- // @ts-ignore (proprietary API in react-native-webrtc).
71
- this._sendStream.release(/* releaseTracks */ false);
72
- // Close RTCPeerConnection.
73
- if (this._pc) {
74
- try {
75
- this._pc.close();
76
- }
77
- catch (error) { }
78
- }
79
- this.emit('@close');
80
- }
81
- async getNativeRtpCapabilities() {
82
- logger.debug('getNativeRtpCapabilities()');
83
- const pc = new RTCPeerConnection({
84
- iceServers: [],
85
- iceTransportPolicy: 'all',
86
- bundlePolicy: 'max-bundle',
87
- rtcpMuxPolicy: 'require',
88
- sdpSemantics: 'plan-b'
89
- });
90
- try {
91
- const offer = await pc.createOffer({
92
- offerToReceiveAudio: true,
93
- offerToReceiveVideo: true
94
- });
95
- try {
96
- pc.close();
97
- }
98
- catch (error) { }
99
- const sdpObject = sdpTransform.parse(offer.sdp);
100
- const nativeRtpCapabilities = sdpCommonUtils.extractRtpCapabilities({ sdpObject });
101
- return nativeRtpCapabilities;
102
- }
103
- catch (error) {
104
- try {
105
- pc.close();
106
- }
107
- catch (error2) { }
108
- throw error;
109
- }
110
- }
111
- async getNativeSctpCapabilities() {
112
- logger.debug('getNativeSctpCapabilities()');
113
- return {
114
- numStreams: SCTP_NUM_STREAMS
115
- };
116
- }
117
- run({ direction, iceParameters, iceCandidates, dtlsParameters, sctpParameters, iceServers, iceTransportPolicy, additionalSettings, proprietaryConstraints, extendedRtpCapabilities }) {
118
- logger.debug('run()');
119
- this._direction = direction;
120
- this._remoteSdp = new RemoteSdp_1.RemoteSdp({
121
- iceParameters,
122
- iceCandidates,
123
- dtlsParameters,
124
- sctpParameters,
125
- planB: true
126
- });
127
- this._sendingRtpParametersByKind =
128
- {
129
- audio: ortc.getSendingRtpParameters('audio', extendedRtpCapabilities),
130
- video: ortc.getSendingRtpParameters('video', extendedRtpCapabilities)
131
- };
132
- this._sendingRemoteRtpParametersByKind =
133
- {
134
- audio: ortc.getSendingRemoteRtpParameters('audio', extendedRtpCapabilities),
135
- video: ortc.getSendingRemoteRtpParameters('video', extendedRtpCapabilities)
136
- };
137
- if (dtlsParameters.role && dtlsParameters.role !== 'auto') {
138
- this._forcedLocalDtlsRole = dtlsParameters.role === 'server'
139
- ? 'client'
140
- : 'server';
141
- }
142
- this._pc = new RTCPeerConnection({
143
- iceServers: iceServers || [],
144
- iceTransportPolicy: iceTransportPolicy || 'all',
145
- bundlePolicy: 'max-bundle',
146
- rtcpMuxPolicy: 'require',
147
- sdpSemantics: 'plan-b',
148
- ...additionalSettings
149
- }, proprietaryConstraints);
150
- if (this._pc.connectionState) {
151
- this._pc.addEventListener('connectionstatechange', () => {
152
- this.emit('@connectionstatechange', this._pc.connectionState);
153
- });
154
- }
155
- else {
156
- this._pc.addEventListener('iceconnectionstatechange', () => {
157
- logger.warn('run() | pc.connectionState not supported, using pc.iceConnectionState');
158
- switch (this._pc.iceConnectionState) {
159
- case 'checking':
160
- this.emit('@connectionstatechange', 'connecting');
161
- break;
162
- case 'connected':
163
- case 'completed':
164
- this.emit('@connectionstatechange', 'connected');
165
- break;
166
- case 'failed':
167
- this.emit('@connectionstatechange', 'failed');
168
- break;
169
- case 'disconnected':
170
- this.emit('@connectionstatechange', 'disconnected');
171
- break;
172
- case 'closed':
173
- this.emit('@connectionstatechange', 'closed');
174
- break;
175
- }
176
- });
177
- }
178
- }
179
- async updateIceServers(iceServers) {
180
- logger.debug('updateIceServers()');
181
- const configuration = this._pc.getConfiguration();
182
- configuration.iceServers = iceServers;
183
- this._pc.setConfiguration(configuration);
184
- }
185
- async restartIce(iceParameters) {
186
- logger.debug('restartIce()');
187
- // Provide the remote SDP handler with new remote ICE parameters.
188
- this._remoteSdp.updateIceParameters(iceParameters);
189
- if (!this._transportReady) {
190
- return;
191
- }
192
- if (this._direction === 'send') {
193
- const offer = await this._pc.createOffer({ iceRestart: true });
194
- logger.debug('restartIce() | calling pc.setLocalDescription() [offer:%o]', offer);
195
- await this._pc.setLocalDescription(offer);
196
- const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
197
- logger.debug('restartIce() | calling pc.setRemoteDescription() [answer:%o]', answer);
198
- await this._pc.setRemoteDescription(answer);
199
- }
200
- else {
201
- const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
202
- logger.debug('restartIce() | calling pc.setRemoteDescription() [offer:%o]', offer);
203
- await this._pc.setRemoteDescription(offer);
204
- const answer = await this._pc.createAnswer();
205
- logger.debug('restartIce() | calling pc.setLocalDescription() [answer:%o]', answer);
206
- await this._pc.setLocalDescription(answer);
207
- }
208
- }
209
- async getTransportStats() {
210
- return this._pc.getStats();
211
- }
212
- async send({ track, encodings, codecOptions, codec }) {
213
- var _a;
214
- this.assertSendDirection();
215
- logger.debug('send() [kind:%s, track.id:%s]', track.kind, track.id);
216
- if (codec) {
217
- logger.warn('send() | codec selection is not available in %s handler', this.name);
218
- }
219
- this._sendStream.addTrack(track);
220
- this._pc.addStream(this._sendStream);
221
- let offer = await this._pc.createOffer();
222
- let localSdpObject = sdpTransform.parse(offer.sdp);
223
- let offerMediaObject;
224
- const sendingRtpParameters = utils.clone(this._sendingRtpParametersByKind[track.kind], {});
225
- sendingRtpParameters.codecs =
226
- ortc.reduceCodecs(sendingRtpParameters.codecs);
227
- const sendingRemoteRtpParameters = utils.clone(this._sendingRemoteRtpParametersByKind[track.kind], {});
228
- sendingRemoteRtpParameters.codecs =
229
- ortc.reduceCodecs(sendingRemoteRtpParameters.codecs);
230
- if (!this._transportReady) {
231
- await this.setupTransport({
232
- localDtlsRole: (_a = this._forcedLocalDtlsRole) !== null && _a !== void 0 ? _a : 'client',
233
- localSdpObject
234
- });
235
- }
236
- if (track.kind === 'video' && encodings && encodings.length > 1) {
237
- logger.debug('send() | enabling simulcast');
238
- localSdpObject = sdpTransform.parse(offer.sdp);
239
- offerMediaObject = localSdpObject.media
240
- .find((m) => m.type === 'video');
241
- sdpPlanBUtils.addLegacySimulcast({
242
- offerMediaObject,
243
- track,
244
- numStreams: encodings.length
245
- });
246
- offer = { type: 'offer', sdp: sdpTransform.write(localSdpObject) };
247
- }
248
- logger.debug('send() | calling pc.setLocalDescription() [offer:%o]', offer);
249
- await this._pc.setLocalDescription(offer);
250
- localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);
251
- offerMediaObject = localSdpObject.media
252
- .find((m) => m.type === track.kind);
253
- // Set RTCP CNAME.
254
- sendingRtpParameters.rtcp.cname =
255
- sdpCommonUtils.getCname({ offerMediaObject });
256
- // Set RTP encodings.
257
- sendingRtpParameters.encodings =
258
- sdpPlanBUtils.getRtpEncodings({ offerMediaObject, track });
259
- // Complete encodings with given values.
260
- if (encodings) {
261
- for (let idx = 0; idx < sendingRtpParameters.encodings.length; ++idx) {
262
- if (encodings[idx]) {
263
- Object.assign(sendingRtpParameters.encodings[idx], encodings[idx]);
264
- }
265
- }
266
- }
267
- // If VP8 or H264 and there is effective simulcast, add scalabilityMode to
268
- // each encoding.
269
- if (sendingRtpParameters.encodings.length > 1 &&
270
- (sendingRtpParameters.codecs[0].mimeType.toLowerCase() === 'video/vp8' ||
271
- sendingRtpParameters.codecs[0].mimeType.toLowerCase() === 'video/h264')) {
272
- for (const encoding of sendingRtpParameters.encodings) {
273
- encoding.scalabilityMode = 'L1T3';
274
- }
275
- }
276
- this._remoteSdp.send({
277
- offerMediaObject,
278
- offerRtpParameters: sendingRtpParameters,
279
- answerRtpParameters: sendingRemoteRtpParameters,
280
- codecOptions
281
- });
282
- const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
283
- logger.debug('send() | calling pc.setRemoteDescription() [answer:%o]', answer);
284
- await this._pc.setRemoteDescription(answer);
285
- const localId = String(this._nextSendLocalId);
286
- this._nextSendLocalId++;
287
- // Insert into the map.
288
- this._mapSendLocalIdTrack.set(localId, track);
289
- return {
290
- localId: localId,
291
- rtpParameters: sendingRtpParameters
292
- };
293
- }
294
- async stopSending(localId) {
295
- this.assertSendDirection();
296
- logger.debug('stopSending() [localId:%s]', localId);
297
- const track = this._mapSendLocalIdTrack.get(localId);
298
- if (!track) {
299
- throw new Error('track not found');
300
- }
301
- this._mapSendLocalIdTrack.delete(localId);
302
- this._sendStream.removeTrack(track);
303
- this._pc.addStream(this._sendStream);
304
- const offer = await this._pc.createOffer();
305
- logger.debug('stopSending() | calling pc.setLocalDescription() [offer:%o]', offer);
306
- try {
307
- await this._pc.setLocalDescription(offer);
308
- }
309
- catch (error) {
310
- // NOTE: If there are no sending tracks, setLocalDescription() will fail with
311
- // "Failed to create channels". If so, ignore it.
312
- if (this._sendStream.getTracks().length === 0) {
313
- logger.warn('stopSending() | ignoring expected error due no sending tracks: %s', error.toString());
314
- return;
315
- }
316
- throw error;
317
- }
318
- if (this._pc.signalingState === 'stable') {
319
- return;
320
- }
321
- const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
322
- logger.debug('stopSending() | calling pc.setRemoteDescription() [answer:%o]', answer);
323
- await this._pc.setRemoteDescription(answer);
324
- }
325
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
326
- async pauseSending(localId) {
327
- // Unimplemented.
328
- }
329
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
330
- async resumeSending(localId) {
331
- // Unimplemented.
332
- }
333
- async replaceTrack(
334
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
335
- localId, track) {
336
- throw new errors_1.UnsupportedError('not implemented');
337
- }
338
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
339
- async setMaxSpatialLayer(localId, spatialLayer) {
340
- throw new errors_1.UnsupportedError('not implemented');
341
- }
342
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
343
- async setRtpEncodingParameters(localId, params) {
344
- throw new errors_1.UnsupportedError('not implemented');
345
- }
346
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
347
- async getSenderStats(localId) {
348
- throw new errors_1.UnsupportedError('not implemented');
349
- }
350
- async sendDataChannel({ ordered, maxPacketLifeTime, maxRetransmits, label, protocol }) {
351
- var _a;
352
- this.assertSendDirection();
353
- const options = {
354
- negotiated: true,
355
- id: this._nextSendSctpStreamId,
356
- ordered,
357
- maxPacketLifeTime,
358
- maxRetransmitTime: maxPacketLifeTime,
359
- maxRetransmits,
360
- protocol
361
- };
362
- logger.debug('sendDataChannel() [options:%o]', options);
363
- const dataChannel = this._pc.createDataChannel(label, options);
364
- // Increase next id.
365
- this._nextSendSctpStreamId =
366
- ++this._nextSendSctpStreamId % SCTP_NUM_STREAMS.MIS;
367
- // If this is the first DataChannel we need to create the SDP answer with
368
- // m=application section.
369
- if (!this._hasDataChannelMediaSection) {
370
- const offer = await this._pc.createOffer();
371
- const localSdpObject = sdpTransform.parse(offer.sdp);
372
- const offerMediaObject = localSdpObject.media
373
- .find((m) => m.type === 'application');
374
- if (!this._transportReady) {
375
- await this.setupTransport({
376
- localDtlsRole: (_a = this._forcedLocalDtlsRole) !== null && _a !== void 0 ? _a : 'client',
377
- localSdpObject
378
- });
379
- }
380
- logger.debug('sendDataChannel() | calling pc.setLocalDescription() [offer:%o]', offer);
381
- await this._pc.setLocalDescription(offer);
382
- this._remoteSdp.sendSctpAssociation({ offerMediaObject });
383
- const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
384
- logger.debug('sendDataChannel() | calling pc.setRemoteDescription() [answer:%o]', answer);
385
- await this._pc.setRemoteDescription(answer);
386
- this._hasDataChannelMediaSection = true;
387
- }
388
- const sctpStreamParameters = {
389
- streamId: options.id,
390
- ordered: options.ordered,
391
- maxPacketLifeTime: options.maxPacketLifeTime,
392
- maxRetransmits: options.maxRetransmits
393
- };
394
- return { dataChannel, sctpStreamParameters };
395
- }
396
- async receive(optionsList) {
397
- var _a;
398
- this.assertRecvDirection();
399
- const results = [];
400
- const mapStreamId = new Map();
401
- for (const options of optionsList) {
402
- const { trackId, kind, rtpParameters } = options;
403
- logger.debug('receive() [trackId:%s, kind:%s]', trackId, kind);
404
- const mid = kind;
405
- let streamId = options.streamId || rtpParameters.rtcp.cname;
406
- // NOTE: In React-Native we cannot reuse the same remote MediaStream for new
407
- // remote tracks. This is because react-native-webrtc does not react on new
408
- // tracks generated within already existing streams, so force the streamId
409
- // to be different. See:
410
- // https://github.com/react-native-webrtc/react-native-webrtc/issues/401
411
- logger.debug('receive() | forcing a random remote streamId to avoid well known bug in react-native-webrtc');
412
- streamId += `-hack-${utils.generateRandomNumber()}`;
413
- mapStreamId.set(trackId, streamId);
414
- this._remoteSdp.receive({
415
- mid,
416
- kind,
417
- offerRtpParameters: rtpParameters,
418
- streamId,
419
- trackId
420
- });
421
- }
422
- const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
423
- logger.debug('receive() | calling pc.setRemoteDescription() [offer:%o]', offer);
424
- await this._pc.setRemoteDescription(offer);
425
- let answer = await this._pc.createAnswer();
426
- const localSdpObject = sdpTransform.parse(answer.sdp);
427
- for (const options of optionsList) {
428
- const { kind, rtpParameters } = options;
429
- const mid = kind;
430
- const answerMediaObject = localSdpObject.media
431
- .find((m) => String(m.mid) === mid);
432
- // May need to modify codec parameters in the answer based on codec
433
- // parameters in the offer.
434
- sdpCommonUtils.applyCodecParameters({
435
- offerRtpParameters: rtpParameters,
436
- answerMediaObject
437
- });
438
- }
439
- answer = { type: 'answer', sdp: sdpTransform.write(localSdpObject) };
440
- if (!this._transportReady) {
441
- await this.setupTransport({
442
- localDtlsRole: (_a = this._forcedLocalDtlsRole) !== null && _a !== void 0 ? _a : 'client',
443
- localSdpObject
444
- });
445
- }
446
- logger.debug('receive() | calling pc.setLocalDescription() [answer:%o]', answer);
447
- await this._pc.setLocalDescription(answer);
448
- for (const options of optionsList) {
449
- const { kind, trackId, rtpParameters } = options;
450
- const localId = trackId;
451
- const mid = kind;
452
- const streamId = mapStreamId.get(trackId);
453
- const stream = this._pc.getRemoteStreams()
454
- .find((s) => s.id === streamId);
455
- const track = stream.getTrackById(localId);
456
- if (!track) {
457
- throw new Error('remote track not found');
458
- }
459
- // Insert into the map.
460
- this._mapRecvLocalIdInfo.set(localId, { mid, rtpParameters });
461
- results.push({ localId, track });
462
- }
463
- return results;
464
- }
465
- async stopReceiving(localIds) {
466
- this.assertRecvDirection();
467
- for (const localId of localIds) {
468
- logger.debug('stopReceiving() [localId:%s]', localId);
469
- const { mid, rtpParameters } = this._mapRecvLocalIdInfo.get(localId) || {};
470
- // Remove from the map.
471
- this._mapRecvLocalIdInfo.delete(localId);
472
- this._remoteSdp.planBStopReceiving({ mid: mid, offerRtpParameters: rtpParameters });
473
- }
474
- const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
475
- logger.debug('stopReceiving() | calling pc.setRemoteDescription() [offer:%o]', offer);
476
- await this._pc.setRemoteDescription(offer);
477
- const answer = await this._pc.createAnswer();
478
- logger.debug('stopReceiving() | calling pc.setLocalDescription() [answer:%o]', answer);
479
- await this._pc.setLocalDescription(answer);
480
- }
481
- async pauseReceiving(
482
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
483
- localIds) {
484
- // Unimplemented.
485
- }
486
- async resumeReceiving(
487
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
488
- localIds) {
489
- // Unimplemented.
490
- }
491
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
492
- async getReceiverStats(localId) {
493
- throw new errors_1.UnsupportedError('not implemented');
494
- }
495
- async receiveDataChannel({ sctpStreamParameters, label, protocol }) {
496
- var _a;
497
- this.assertRecvDirection();
498
- const { streamId, ordered, maxPacketLifeTime, maxRetransmits } = sctpStreamParameters;
499
- const options = {
500
- negotiated: true,
501
- id: streamId,
502
- ordered,
503
- maxPacketLifeTime,
504
- maxRetransmitTime: maxPacketLifeTime,
505
- maxRetransmits,
506
- protocol
507
- };
508
- logger.debug('receiveDataChannel() [options:%o]', options);
509
- const dataChannel = this._pc.createDataChannel(label, options);
510
- // If this is the first DataChannel we need to create the SDP offer with
511
- // m=application section.
512
- if (!this._hasDataChannelMediaSection) {
513
- this._remoteSdp.receiveSctpAssociation({ oldDataChannelSpec: true });
514
- const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
515
- logger.debug('receiveDataChannel() | calling pc.setRemoteDescription() [offer:%o]', offer);
516
- await this._pc.setRemoteDescription(offer);
517
- const answer = await this._pc.createAnswer();
518
- if (!this._transportReady) {
519
- const localSdpObject = sdpTransform.parse(answer.sdp);
520
- await this.setupTransport({
521
- localDtlsRole: (_a = this._forcedLocalDtlsRole) !== null && _a !== void 0 ? _a : 'client',
522
- localSdpObject
523
- });
524
- }
525
- logger.debug('receiveDataChannel() | calling pc.setRemoteDescription() [answer:%o]', answer);
526
- await this._pc.setLocalDescription(answer);
527
- this._hasDataChannelMediaSection = true;
528
- }
529
- return { dataChannel };
530
- }
531
- async setupTransport({ localDtlsRole, localSdpObject }) {
532
- if (!localSdpObject) {
533
- localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);
534
- }
535
- // Get our local DTLS parameters.
536
- const dtlsParameters = sdpCommonUtils.extractDtlsParameters({ sdpObject: localSdpObject });
537
- // Set our DTLS role.
538
- dtlsParameters.role = localDtlsRole;
539
- // Update the remote DTLS role in the SDP.
540
- this._remoteSdp.updateDtlsRole(localDtlsRole === 'client' ? 'server' : 'client');
541
- // Need to tell the remote transport about our parameters.
542
- await new Promise((resolve, reject) => {
543
- this.safeEmit('@connect', { dtlsParameters }, resolve, reject);
544
- });
545
- this._transportReady = true;
546
- }
547
- assertSendDirection() {
548
- if (this._direction !== 'send') {
549
- throw new Error('method can just be called for handlers with "send" direction');
550
- }
551
- }
552
- assertRecvDirection() {
553
- if (this._direction !== 'recv') {
554
- throw new Error('method can just be called for handlers with "recv" direction');
555
- }
556
- }
557
- }
558
- exports.ReactNative = ReactNative;
@@ -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 ReactNativeUnifiedPlan 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=ReactNativeUnifiedPlan.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ReactNativeUnifiedPlan.d.ts","sourceRoot":"","sources":["../../src/handlers/ReactNativeUnifiedPlan.ts"],"names":[],"mappings":"AAOA,OAAO,EACN,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,6BAA6B,EA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