-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathTransport.ts
More file actions
1083 lines (911 loc) · 23.2 KB
/
Transport.ts
File metadata and controls
1083 lines (911 loc) · 23.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { v4 as uuidv4 } from 'uuid';
import { Logger } from './Logger';
import { EnhancedEventEmitter } from './EnhancedEventEmitter';
import * as utils from './utils';
import * as ortc from './ortc';
import { Channel } from './Channel';
import { PayloadChannel } from './PayloadChannel';
import { RouterInternal } from './Router';
import { WebRtcTransportData } from './WebRtcTransport';
import { PlainTransportData } from './PlainTransport';
import { PipeTransportData } from './PipeTransport';
import { DirectTransportData } from './DirectTransport';
import { Producer, ProducerOptions } from './Producer';
import { Consumer, ConsumerOptions, ConsumerType } from './Consumer';
import {
DataProducer,
DataProducerOptions,
DataProducerType
} from './DataProducer';
import {
DataConsumer,
DataConsumerOptions,
DataConsumerType
} from './DataConsumer';
import { RtpCapabilities } from './RtpParameters';
import { SctpStreamParameters } from './SctpParameters';
export type TransportListenIp =
{
/**
* Listening IPv4 or IPv6.
*/
ip: string;
/**
* Announced IPv4 or IPv6 (useful when running mediasoup behind NAT with
* private IP).
*/
announcedIp?: string;
};
/**
* Transport protocol.
*/
export type TransportProtocol = 'udp' | 'tcp';
export type TransportTuple =
{
localIp: string;
localPort: number;
remoteIp?: string;
remotePort?: number;
protocol: TransportProtocol;
};
/**
* Valid types for 'trace' event.
*/
export type TransportTraceEventType = 'probation' | 'bwe' | 'bweStats';
/**
* bweStats typings for trace event.
*/
export type TransportTraceEventBweStatsInfo = {
estimatedBitrate: number;
delay: {
slope: number;
rSquared: number;
threshold: number;
rtt: number;
rateControlState: number;
delayDetectorState: number;
};
probe: {
estimatedBitrate: number;
};
loss: {
inherent: number;
avg: number;
estimatedBitrate: number;
sendingRate: number;
};
alr: boolean;
ackBitrate: number;
desiredBitrate: number;
effectiveDesiredBitrate: number;
minBitrate: number;
maxBitrate: number;
startBitrate: number;
maxPaddingBitrate: number;
sendingRate: number;
};
/**
* 'trace' event data.
*/
export type TransportTraceEventData =
{
/**
* Trace type.
*/
type: TransportTraceEventType;
/**
* Event timestamp.
*/
timestamp: number;
/**
* Event direction.
*/
direction: 'in' | 'out';
/**
* Per type information.
*/
info: TransportTraceEventBweStatsInfo | any;
};
export type SctpState = 'new' | 'connecting' | 'connected' | 'failed' | 'closed';
export type TransportEvents =
{
routerclose: [];
listenserverclose: [];
trace: [TransportTraceEventData];
// Private events.
'@close': [];
'@newproducer': [Producer];
'@producerclose': [Producer];
'@newdataproducer': [DataProducer];
'@dataproducerclose': [DataProducer];
'@listenserverclose': [];
};
export type TransportObserverEvents =
{
close: [];
newproducer: [Producer];
newconsumer: [Consumer];
newdataproducer: [DataProducer];
newdataconsumer: [DataConsumer];
trace: [TransportTraceEventData];
};
export type TransportConstructorOptions =
{
internal: TransportInternal;
data: TransportData;
channel: Channel;
payloadChannel: PayloadChannel;
appData?: Record<string, unknown>;
getRouterRtpCapabilities: () => RtpCapabilities;
getProducerById: (producerId: string) => Producer | undefined;
getDataProducerById: (dataProducerId: string) => DataProducer | undefined;
};
export type TransportInternal = RouterInternal &
{
transportId: string;
};
type TransportData =
| WebRtcTransportData
| PlainTransportData
| PipeTransportData
| DirectTransportData;
const logger = new Logger('Transport');
export class Transport<Events extends TransportEvents = TransportEvents,
ObserverEvents extends TransportObserverEvents = TransportObserverEvents>
extends EnhancedEventEmitter<Events>
{
// Internal data.
protected readonly internal: TransportInternal;
// Transport data. This is set by the subclass.
readonly #data: TransportData;
// Channel instance.
protected readonly channel: Channel;
// PayloadChannel instance.
protected readonly payloadChannel: PayloadChannel;
// Close flag.
#closed = false;
// Custom app data.
readonly #appData: Record<string, unknown>;
// Method to retrieve Router RTP capabilities.
readonly #getRouterRtpCapabilities: () => RtpCapabilities;
// Method to retrieve a Producer.
protected readonly getProducerById: (producerId: string) => Producer | undefined;
// Method to retrieve a DataProducer.
protected readonly getDataProducerById:
(dataProducerId: string) => DataProducer | undefined;
// Producers map.
readonly #producers: Map<string, Producer> = new Map();
// Consumers map.
protected readonly consumers: Map<string, Consumer> = new Map();
// DataProducers map.
protected readonly dataProducers: Map<string, DataProducer> = new Map();
// DataConsumers map.
protected readonly dataConsumers: Map<string, DataConsumer> = new Map();
// RTCP CNAME for Producers.
#cnameForProducers?: string;
// Next MID for Consumers. It's converted into string when used.
#nextMidForConsumers = 0;
// Buffer with available SCTP stream ids.
#sctpStreamIds?: Buffer;
// Next SCTP stream id.
#nextSctpStreamId = 0;
// Observer instance.
readonly #observer = new EnhancedEventEmitter<ObserverEvents>();
/**
* @private
* @interface
*/
constructor(
{
internal,
data,
channel,
payloadChannel,
appData,
getRouterRtpCapabilities,
getProducerById,
getDataProducerById
}: TransportConstructorOptions
)
{
super();
logger.debug('constructor()');
this.internal = internal;
this.#data = data;
this.channel = channel;
this.payloadChannel = payloadChannel;
this.#appData = appData || {};
this.#getRouterRtpCapabilities = getRouterRtpCapabilities;
this.getProducerById = getProducerById;
this.getDataProducerById = getDataProducerById;
}
/**
* Transport id.
*/
get id(): string
{
return this.internal.transportId;
}
/**
* Whether the Transport is closed.
*/
get closed(): boolean
{
return this.#closed;
}
/**
* App custom data.
*/
get appData(): Record<string, unknown>
{
return this.#appData;
}
/**
* Invalid setter.
*/
set appData(appData: Record<string, unknown>) // eslint-disable-line no-unused-vars
{
throw new Error('cannot override appData object');
}
/**
* Observer.
*/
get observer(): EnhancedEventEmitter<ObserverEvents>
{
return this.#observer;
}
/**
* @private
* Just for testing purposes.
*/
get channelForTesting(): Channel
{
return this.channel;
}
/**
* Close the Transport.
*/
close(): void
{
if (this.#closed)
{
return;
}
logger.debug('close()');
this.#closed = true;
// Remove notification subscriptions.
this.channel.removeAllListeners(this.internal.transportId);
this.payloadChannel.removeAllListeners(this.internal.transportId);
const reqData = { transportId: this.internal.transportId };
this.channel.request('router.closeTransport', this.internal.routerId, reqData)
.catch(() => {});
// Close every Producer.
for (const producer of this.#producers.values())
{
producer.transportClosed();
// Must tell the Router.
this.emit('@producerclose', producer);
}
this.#producers.clear();
// Close every Consumer.
for (const consumer of this.consumers.values())
{
consumer.transportClosed();
}
this.consumers.clear();
// Close every DataProducer.
for (const dataProducer of this.dataProducers.values())
{
dataProducer.transportClosed();
// Must tell the Router.
this.emit('@dataproducerclose', dataProducer);
}
this.dataProducers.clear();
// Close every DataConsumer.
for (const dataConsumer of this.dataConsumers.values())
{
dataConsumer.transportClosed();
}
this.dataConsumers.clear();
this.emit('@close');
// Emit observer event.
this.#observer.safeEmit('close');
}
/**
* Router was closed.
*
* @private
* @virtual
*/
routerClosed(): void
{
if (this.#closed)
{
return;
}
logger.debug('routerClosed()');
this.#closed = true;
// Remove notification subscriptions.
this.channel.removeAllListeners(this.internal.transportId);
this.payloadChannel.removeAllListeners(this.internal.transportId);
// Close every Producer.
for (const producer of this.#producers.values())
{
producer.transportClosed();
// NOTE: No need to tell the Router since it already knows (it has
// been closed in fact).
}
this.#producers.clear();
// Close every Consumer.
for (const consumer of this.consumers.values())
{
consumer.transportClosed();
}
this.consumers.clear();
// Close every DataProducer.
for (const dataProducer of this.dataProducers.values())
{
dataProducer.transportClosed();
// NOTE: No need to tell the Router since it already knows (it has
// been closed in fact).
}
this.dataProducers.clear();
// Close every DataConsumer.
for (const dataConsumer of this.dataConsumers.values())
{
dataConsumer.transportClosed();
}
this.dataConsumers.clear();
this.safeEmit('routerclose');
// Emit observer event.
this.#observer.safeEmit('close');
}
/**
* Listen server was closed (this just happens in WebRtcTransports when their
* associated WebRtcServer is closed).
*
* @private
*/
listenServerClosed(): void
{
if (this.#closed)
{
return;
}
logger.debug('listenServerClosed()');
this.#closed = true;
// Remove notification subscriptions.
this.channel.removeAllListeners(this.internal.transportId);
this.payloadChannel.removeAllListeners(this.internal.transportId);
// Close every Producer.
for (const producer of this.#producers.values())
{
producer.transportClosed();
// NOTE: No need to tell the Router since it already knows (it has
// been closed in fact).
}
this.#producers.clear();
// Close every Consumer.
for (const consumer of this.consumers.values())
{
consumer.transportClosed();
}
this.consumers.clear();
// Close every DataProducer.
for (const dataProducer of this.dataProducers.values())
{
dataProducer.transportClosed();
// NOTE: No need to tell the Router since it already knows (it has
// been closed in fact).
}
this.dataProducers.clear();
// Close every DataConsumer.
for (const dataConsumer of this.dataConsumers.values())
{
dataConsumer.transportClosed();
}
this.dataConsumers.clear();
// Need to emit this event to let the parent Router know since
// transport.listenServerClosed() is called by the listen server.
// NOTE: Currently there is just WebRtcServer for WebRtcTransports.
this.emit('@listenserverclose');
this.safeEmit('listenserverclose');
// Emit observer event.
this.#observer.safeEmit('close');
}
/**
* Dump Transport.
*/
async dump(): Promise<any>
{
logger.debug('dump()');
return this.channel.request('transport.dump', this.internal.transportId);
}
/**
* Get Transport stats.
*
* @abstract
*/
async getStats(): Promise<any[]>
{
// Should not happen.
throw new Error('method not implemented in the subclass');
}
/**
* Provide the Transport remote parameters.
*
* @abstract
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async connect(params: any): Promise<void>
{
// Should not happen.
throw new Error('method not implemented in the subclass');
}
/**
* Set maximum incoming bitrate for receiving media.
*/
async setMaxIncomingBitrate(bitrate: number): Promise<void>
{
logger.debug('setMaxIncomingBitrate() [bitrate:%s]', bitrate);
const reqData = { bitrate };
await this.channel.request(
'transport.setMaxIncomingBitrate', this.internal.transportId, reqData);
}
/**
* Set maximum outgoing bitrate for sending media.
*/
async setMaxOutgoingBitrate(bitrate: number): Promise<void>
{
logger.debug('setMaxOutgoingBitrate() [bitrate:%s]', bitrate);
const reqData = { bitrate };
await this.channel.request(
'transport.setMaxOutgoingBitrate', this.internal.transportId, reqData);
}
/**
* Create a Producer.
*/
async produce(
{
id = undefined,
kind,
rtpParameters,
paused = false,
keyFrameRequestDelay,
appData
}: ProducerOptions
): Promise<Producer>
{
logger.debug('produce()');
if (id && this.#producers.has(id))
{
throw new TypeError(`a Producer with same id "${id}" already exists`);
}
else if (![ 'audio', 'video' ].includes(kind))
{
throw new TypeError(`invalid kind "${kind}"`);
}
else if (appData && typeof appData !== 'object')
{
throw new TypeError('if given, appData must be an object');
}
// This may throw.
ortc.validateRtpParameters(rtpParameters);
// If missing or empty encodings, add one.
if (
!rtpParameters.encodings ||
!Array.isArray(rtpParameters.encodings) ||
rtpParameters.encodings.length === 0
)
{
rtpParameters.encodings = [ {} ];
}
// Don't do this in PipeTransports since there we must keep CNAME value in
// each Producer.
if (this.constructor.name !== 'PipeTransport')
{
// If CNAME is given and we don't have yet a CNAME for Producers in this
// Transport, take it.
if (!this.#cnameForProducers && rtpParameters.rtcp && rtpParameters.rtcp.cname)
{
this.#cnameForProducers = rtpParameters.rtcp.cname;
}
// Otherwise if we don't have yet a CNAME for Producers and the RTP parameters
// do not include CNAME, create a random one.
else if (!this.#cnameForProducers)
{
this.#cnameForProducers = uuidv4().substr(0, 8);
}
// Override Producer's CNAME.
rtpParameters.rtcp = rtpParameters.rtcp || {};
rtpParameters.rtcp.cname = this.#cnameForProducers;
}
const routerRtpCapabilities = this.#getRouterRtpCapabilities();
// This may throw.
const rtpMapping = ortc.getProducerRtpParametersMapping(
rtpParameters, routerRtpCapabilities);
// This may throw.
const consumableRtpParameters = ortc.getConsumableRtpParameters(
kind, rtpParameters, routerRtpCapabilities, rtpMapping);
const reqData =
{
producerId : id || uuidv4(),
kind,
rtpParameters,
rtpMapping,
keyFrameRequestDelay,
paused
};
const status =
await this.channel.request('transport.produce', this.internal.transportId, reqData);
const data =
{
kind,
rtpParameters,
type : status.type,
consumableRtpParameters
};
const producer = new Producer(
{
internal :
{
...this.internal,
producerId : reqData.producerId
},
data,
channel : this.channel,
payloadChannel : this.payloadChannel,
appData,
paused
});
this.#producers.set(producer.id, producer);
producer.on('@close', () =>
{
this.#producers.delete(producer.id);
this.emit('@producerclose', producer);
});
this.emit('@newproducer', producer);
// Emit observer event.
this.#observer.safeEmit('newproducer', producer);
return producer;
}
/**
* Create a Consumer.
*
* @virtual
*/
async consume(
{
producerId,
rtpCapabilities,
paused = false,
mid,
preferredLayers,
ignoreDtx = false,
enableRtx,
pipe = false,
appData
}: ConsumerOptions
): Promise<Consumer>
{
logger.debug('consume()');
if (!producerId || typeof producerId !== 'string')
{
throw new TypeError('missing producerId');
}
else if (appData && typeof appData !== 'object')
{
throw new TypeError('if given, appData must be an object');
}
else if (mid && (typeof mid !== 'string' || mid.length === 0))
{
throw new TypeError('if given, mid must be non empty string');
}
// This may throw.
ortc.validateRtpCapabilities(rtpCapabilities!);
const producer = this.getProducerById(producerId);
if (!producer)
{
throw Error(`Producer with id "${producerId}" not found`);
}
// If enableRtx is not given, set it to true if video and false if audio.
if (enableRtx === undefined)
{
enableRtx = producer.kind === 'video';
}
// This may throw.
const rtpParameters = ortc.getConsumerRtpParameters(
{
consumableRtpParameters : producer.consumableRtpParameters,
remoteRtpCapabilities : rtpCapabilities!,
pipe,
enableRtx
}
);
// Set MID.
if (!pipe)
{
if (mid)
{
rtpParameters.mid = mid;
}
else
{
rtpParameters.mid = `${this.#nextMidForConsumers++}`;
// We use up to 8 bytes for MID (string).
if (this.#nextMidForConsumers === 100000000)
{
logger.error(
`consume() | reaching max MID value "${this.#nextMidForConsumers}"`);
this.#nextMidForConsumers = 0;
}
}
}
const reqData =
{
consumerId : uuidv4(),
producerId,
kind : producer.kind,
rtpParameters,
type : pipe ? 'pipe' : producer.type,
consumableRtpEncodings : producer.consumableRtpParameters.encodings,
paused,
preferredLayers,
ignoreDtx
};
const status =
await this.channel.request('transport.consume', this.internal.transportId, reqData);
const data =
{
producerId,
kind : producer.kind,
rtpParameters,
type : pipe ? 'pipe' : producer.type as ConsumerType
};
const consumer = new Consumer(
{
internal :
{
...this.internal,
consumerId : reqData.consumerId
},
data,
channel : this.channel,
payloadChannel : this.payloadChannel,
appData,
paused : status.paused,
producerPaused : status.producerPaused,
score : status.score,
preferredLayers : status.preferredLayers
});
this.consumers.set(consumer.id, consumer);
consumer.on('@close', () => this.consumers.delete(consumer.id));
consumer.on('@producerclose', () => this.consumers.delete(consumer.id));
// Emit observer event.
this.#observer.safeEmit('newconsumer', consumer);
return consumer;
}
/**
* Create a DataProducer.
*/
async produceData(
{
id = undefined,
sctpStreamParameters,
label = '',
protocol = '',
appData
}: DataProducerOptions = {}
): Promise<DataProducer>
{
logger.debug('produceData()');
if (id && this.dataProducers.has(id))
{
throw new TypeError(`a DataProducer with same id "${id}" already exists`);
}
else if (appData && typeof appData !== 'object')
{
throw new TypeError('if given, appData must be an object');
}
let type: DataProducerType;
// If this is not a DirectTransport, sctpStreamParameters are required.
if (this.constructor.name !== 'DirectTransport')
{
type = 'sctp';
// This may throw.
ortc.validateSctpStreamParameters(sctpStreamParameters!);
}
// If this is a DirectTransport, sctpStreamParameters must not be given.
else
{
type = 'direct';
if (sctpStreamParameters)
{
logger.warn(
'produceData() | sctpStreamParameters are ignored when producing data on a DirectTransport');
}
}
const reqData =
{
dataProducerId : id || uuidv4(),
type,
sctpStreamParameters,
label,
protocol
};
const data =
await this.channel.request('transport.produceData', this.internal.transportId, reqData);
const dataProducer = new DataProducer(
{
internal :
{
...this.internal,
dataProducerId : reqData.dataProducerId
},
data,
channel : this.channel,
payloadChannel : this.payloadChannel,
appData
});
this.dataProducers.set(dataProducer.id, dataProducer);
dataProducer.on('@close', () =>
{
this.dataProducers.delete(dataProducer.id);
this.emit('@dataproducerclose', dataProducer);
});
this.emit('@newdataproducer', dataProducer);
// Emit observer event.
this.#observer.safeEmit('newdataproducer', dataProducer);
return dataProducer;
}
/**
* Create a DataConsumer.
*/
async consumeData(
{
dataProducerId,
ordered,
maxPacketLifeTime,
maxRetransmits,
appData
}: DataConsumerOptions
): Promise<DataConsumer>
{
logger.debug('consumeData()');
if (!dataProducerId || typeof dataProducerId !== 'string')
{
throw new TypeError('missing dataProducerId');
}
else if (appData && typeof appData !== 'object')
{
throw new TypeError('if given, appData must be an object');
}
const dataProducer = this.getDataProducerById(dataProducerId);
if (!dataProducer)
{
throw Error(`DataProducer with id "${dataProducerId}" not found`);
}
let type: DataConsumerType;
let sctpStreamParameters: SctpStreamParameters | undefined;
let sctpStreamId: number;
// If this is not a DirectTransport, use sctpStreamParameters from the
// DataProducer (if type 'sctp') unless they are given in method parameters.
if (this.constructor.name !== 'DirectTransport')
{
type = 'sctp';
sctpStreamParameters =
utils.clone(dataProducer.sctpStreamParameters) as SctpStreamParameters;
// Override if given.
if (ordered !== undefined)
{
sctpStreamParameters.ordered = ordered;
}
if (maxPacketLifeTime !== undefined)
{
sctpStreamParameters.maxPacketLifeTime = maxPacketLifeTime;
}
if (maxRetransmits !== undefined)
{
sctpStreamParameters.maxRetransmits = maxRetransmits;
}
// This may throw.
sctpStreamId = this.getNextSctpStreamId();
this.#sctpStreamIds![sctpStreamId] = 1;
sctpStreamParameters.streamId = sctpStreamId;
}
// If this is a DirectTransport, sctpStreamParameters must not be used.
else
{
type = 'direct';
if (
ordered !== undefined ||
maxPacketLifeTime !== undefined ||
maxRetransmits !== undefined
)
{
logger.warn(
'consumeData() | ordered, maxPacketLifeTime and maxRetransmits are ignored when consuming data on a DirectTransport');
}
}
const { label, protocol } = dataProducer;
const reqData =
{
dataConsumerId : uuidv4(),
dataProducerId,
type,
sctpStreamParameters,
label,
protocol
};
const data =
await this.channel.request('transport.consumeData', this.internal.transportId, reqData);
const dataConsumer = new DataConsumer(
{
internal :