mediasoup-client 3.12.4 → 3.13.0

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