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