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.
- package/lib/Device.d.ts +1 -1
- package/lib/Device.d.ts.map +1 -1
- package/lib/Device.js +8 -81
- package/lib/RtpParameters.d.ts +1 -1
- package/lib/RtpParameters.d.ts.map +1 -1
- package/lib/handlers/{ReactNativeUnifiedPlan.d.ts → ReactNative106.d.ts} +2 -2
- package/lib/handlers/ReactNative106.d.ts.map +1 -0
- package/lib/handlers/{ReactNativeUnifiedPlan.js → ReactNative106.js} +6 -6
- package/lib/handlers/sdp/MediaSection.d.ts +3 -15
- package/lib/handlers/sdp/MediaSection.d.ts.map +1 -1
- package/lib/handlers/sdp/MediaSection.js +6 -113
- package/lib/handlers/sdp/RemoteSdp.d.ts +1 -7
- package/lib/handlers/sdp/RemoteSdp.d.ts.map +1 -1
- package/lib/handlers/sdp/RemoteSdp.js +18 -41
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/test/fakeParameters.d.ts.map +1 -1
- package/lib/test/fakeParameters.js +0 -14
- package/lib/test/test.js +0 -112
- package/lib/test/uaTestCases.d.ts.map +1 -1
- package/lib/test/uaTestCases.js +0 -25
- package/npm-scripts.mjs +26 -14
- package/package.json +8 -8
- package/lib/handlers/Chrome55.d.ts +0 -51
- package/lib/handlers/Chrome55.d.ts.map +0 -1
- package/lib/handlers/Chrome55.js +0 -554
- package/lib/handlers/Chrome67.d.ts +0 -51
- package/lib/handlers/Chrome67.d.ts.map +0 -1
- package/lib/handlers/Chrome67.js +0 -609
- package/lib/handlers/Chrome70.d.ts +0 -49
- package/lib/handlers/Chrome70.d.ts.map +0 -1
- package/lib/handlers/Chrome70.js +0 -634
- package/lib/handlers/Edge11.d.ts +0 -55
- package/lib/handlers/Edge11.d.ts.map +0 -1
- package/lib/handlers/Edge11.js +0 -447
- package/lib/handlers/Firefox60.d.ts +0 -50
- package/lib/handlers/Firefox60.d.ts.map +0 -1
- package/lib/handlers/Firefox60.js +0 -721
- package/lib/handlers/ReactNative.d.ts +0 -51
- package/lib/handlers/ReactNative.d.ts.map +0 -1
- package/lib/handlers/ReactNative.js +0 -569
- package/lib/handlers/ReactNativeUnifiedPlan.d.ts.map +0 -1
- package/lib/handlers/Safari11.d.ts +0 -51
- package/lib/handlers/Safari11.d.ts.map +0 -1
- package/lib/handlers/Safari11.js +0 -604
- package/lib/handlers/ortc/edgeUtils.d.ts +0 -11
- package/lib/handlers/ortc/edgeUtils.d.ts.map +0 -1
- package/lib/handlers/ortc/edgeUtils.js +0 -70
- package/lib/handlers/sdp/planBUtils.d.ts +0 -14
- package/lib/handlers/sdp/planBUtils.d.ts.map +0 -1
- package/lib/handlers/sdp/planBUtils.js +0 -150
|
@@ -1,721 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Firefox60 = 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 sdpUnifiedPlanUtils = require("./sdp/unifiedPlanUtils");
|
|
11
|
-
const HandlerInterface_1 = require("./HandlerInterface");
|
|
12
|
-
const RemoteSdp_1 = require("./sdp/RemoteSdp");
|
|
13
|
-
const scalabilityModes_1 = require("../scalabilityModes");
|
|
14
|
-
const logger = new Logger_1.Logger('Firefox60');
|
|
15
|
-
const NAME = 'Firefox60';
|
|
16
|
-
const SCTP_NUM_STREAMS = { OS: 16, MIS: 2048 };
|
|
17
|
-
class Firefox60 extends HandlerInterface_1.HandlerInterface {
|
|
18
|
-
// Closed flag.
|
|
19
|
-
_closed = false;
|
|
20
|
-
// Handler direction.
|
|
21
|
-
_direction;
|
|
22
|
-
// Remote SDP handler.
|
|
23
|
-
_remoteSdp;
|
|
24
|
-
// Generic sending RTP parameters for audio and video.
|
|
25
|
-
_sendingRtpParametersByKind;
|
|
26
|
-
// Generic sending RTP parameters for audio and video suitable for the SDP
|
|
27
|
-
// remote answer.
|
|
28
|
-
_sendingRemoteRtpParametersByKind;
|
|
29
|
-
// RTCPeerConnection instance.
|
|
30
|
-
_pc;
|
|
31
|
-
// Map of RTCTransceivers indexed by MID.
|
|
32
|
-
_mapMidTransceiver = new Map();
|
|
33
|
-
// Local stream for sending.
|
|
34
|
-
_sendStream = new MediaStream();
|
|
35
|
-
// Whether a DataChannel m=application section has been created.
|
|
36
|
-
_hasDataChannelMediaSection = false;
|
|
37
|
-
// Sending DataChannel id value counter. Incremented for each new DataChannel.
|
|
38
|
-
_nextSendSctpStreamId = 0;
|
|
39
|
-
// Got transport local and remote parameters.
|
|
40
|
-
_transportReady = false;
|
|
41
|
-
/**
|
|
42
|
-
* Creates a factory function.
|
|
43
|
-
*/
|
|
44
|
-
static createFactory() {
|
|
45
|
-
return () => new Firefox60();
|
|
46
|
-
}
|
|
47
|
-
constructor() {
|
|
48
|
-
super();
|
|
49
|
-
}
|
|
50
|
-
get name() {
|
|
51
|
-
return NAME;
|
|
52
|
-
}
|
|
53
|
-
close() {
|
|
54
|
-
logger.debug('close()');
|
|
55
|
-
if (this._closed) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
this._closed = true;
|
|
59
|
-
// Close RTCPeerConnection.
|
|
60
|
-
if (this._pc) {
|
|
61
|
-
try {
|
|
62
|
-
this._pc.close();
|
|
63
|
-
}
|
|
64
|
-
catch (error) { }
|
|
65
|
-
}
|
|
66
|
-
this.emit('@close');
|
|
67
|
-
}
|
|
68
|
-
async getNativeRtpCapabilities() {
|
|
69
|
-
logger.debug('getNativeRtpCapabilities()');
|
|
70
|
-
const pc = new RTCPeerConnection({
|
|
71
|
-
iceServers: [],
|
|
72
|
-
iceTransportPolicy: 'all',
|
|
73
|
-
bundlePolicy: 'max-bundle',
|
|
74
|
-
rtcpMuxPolicy: 'require',
|
|
75
|
-
});
|
|
76
|
-
// NOTE: We need to add a real video track to get the RID extension mapping.
|
|
77
|
-
const canvas = document.createElement('canvas');
|
|
78
|
-
// NOTE: Otherwise Firefox fails in next line.
|
|
79
|
-
canvas.getContext('2d');
|
|
80
|
-
const fakeStream = canvas.captureStream();
|
|
81
|
-
const fakeVideoTrack = fakeStream.getVideoTracks()[0];
|
|
82
|
-
try {
|
|
83
|
-
pc.addTransceiver('audio', { direction: 'sendrecv' });
|
|
84
|
-
const videoTransceiver = pc.addTransceiver(fakeVideoTrack, {
|
|
85
|
-
direction: 'sendrecv',
|
|
86
|
-
});
|
|
87
|
-
const parameters = videoTransceiver.sender.getParameters();
|
|
88
|
-
const encodings = [
|
|
89
|
-
{ rid: 'r0', maxBitrate: 100000 },
|
|
90
|
-
{ rid: 'r1', maxBitrate: 500000 },
|
|
91
|
-
];
|
|
92
|
-
parameters.encodings = encodings;
|
|
93
|
-
await videoTransceiver.sender.setParameters(parameters);
|
|
94
|
-
const offer = await pc.createOffer();
|
|
95
|
-
try {
|
|
96
|
-
canvas.remove();
|
|
97
|
-
}
|
|
98
|
-
catch (error) { }
|
|
99
|
-
try {
|
|
100
|
-
fakeVideoTrack.stop();
|
|
101
|
-
}
|
|
102
|
-
catch (error) { }
|
|
103
|
-
try {
|
|
104
|
-
pc.close();
|
|
105
|
-
}
|
|
106
|
-
catch (error) { }
|
|
107
|
-
const sdpObject = sdpTransform.parse(offer.sdp);
|
|
108
|
-
const nativeRtpCapabilities = sdpCommonUtils.extractRtpCapabilities({
|
|
109
|
-
sdpObject,
|
|
110
|
-
});
|
|
111
|
-
return nativeRtpCapabilities;
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
try {
|
|
115
|
-
canvas.remove();
|
|
116
|
-
}
|
|
117
|
-
catch (error2) { }
|
|
118
|
-
try {
|
|
119
|
-
fakeVideoTrack.stop();
|
|
120
|
-
}
|
|
121
|
-
catch (error2) { }
|
|
122
|
-
try {
|
|
123
|
-
pc.close();
|
|
124
|
-
}
|
|
125
|
-
catch (error2) { }
|
|
126
|
-
throw error;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
async getNativeSctpCapabilities() {
|
|
130
|
-
logger.debug('getNativeSctpCapabilities()');
|
|
131
|
-
return {
|
|
132
|
-
numStreams: SCTP_NUM_STREAMS,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
run({ direction, iceParameters, iceCandidates, dtlsParameters, sctpParameters, iceServers, iceTransportPolicy, additionalSettings, proprietaryConstraints, extendedRtpCapabilities, }) {
|
|
136
|
-
this.assertNotClosed();
|
|
137
|
-
logger.debug('run()');
|
|
138
|
-
this._direction = direction;
|
|
139
|
-
this._remoteSdp = new RemoteSdp_1.RemoteSdp({
|
|
140
|
-
iceParameters,
|
|
141
|
-
iceCandidates,
|
|
142
|
-
dtlsParameters,
|
|
143
|
-
sctpParameters,
|
|
144
|
-
});
|
|
145
|
-
this._sendingRtpParametersByKind = {
|
|
146
|
-
audio: ortc.getSendingRtpParameters('audio', extendedRtpCapabilities),
|
|
147
|
-
video: ortc.getSendingRtpParameters('video', extendedRtpCapabilities),
|
|
148
|
-
};
|
|
149
|
-
this._sendingRemoteRtpParametersByKind = {
|
|
150
|
-
audio: ortc.getSendingRemoteRtpParameters('audio', extendedRtpCapabilities),
|
|
151
|
-
video: ortc.getSendingRemoteRtpParameters('video', extendedRtpCapabilities),
|
|
152
|
-
};
|
|
153
|
-
this._pc = new RTCPeerConnection({
|
|
154
|
-
iceServers: iceServers ?? [],
|
|
155
|
-
iceTransportPolicy: iceTransportPolicy ?? 'all',
|
|
156
|
-
bundlePolicy: 'max-bundle',
|
|
157
|
-
rtcpMuxPolicy: 'require',
|
|
158
|
-
...additionalSettings,
|
|
159
|
-
}, proprietaryConstraints);
|
|
160
|
-
this._pc.addEventListener('icegatheringstatechange', () => {
|
|
161
|
-
this.emit('@icegatheringstatechange', this._pc.iceGatheringState);
|
|
162
|
-
});
|
|
163
|
-
this._pc.addEventListener('icecandidateerror', (event) => {
|
|
164
|
-
this.emit('@icecandidateerror', event);
|
|
165
|
-
});
|
|
166
|
-
if (this._pc.connectionState) {
|
|
167
|
-
this._pc.addEventListener('connectionstatechange', () => {
|
|
168
|
-
this.emit('@connectionstatechange', this._pc.connectionState);
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
this._pc.addEventListener('iceconnectionstatechange', () => {
|
|
173
|
-
logger.warn('run() | pc.connectionState not supported, using pc.iceConnectionState');
|
|
174
|
-
switch (this._pc.iceConnectionState) {
|
|
175
|
-
case 'checking': {
|
|
176
|
-
this.emit('@connectionstatechange', 'connecting');
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
case 'connected':
|
|
180
|
-
case 'completed': {
|
|
181
|
-
this.emit('@connectionstatechange', 'connected');
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
184
|
-
case 'failed': {
|
|
185
|
-
this.emit('@connectionstatechange', 'failed');
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
188
|
-
case 'disconnected': {
|
|
189
|
-
this.emit('@connectionstatechange', 'disconnected');
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
192
|
-
case 'closed': {
|
|
193
|
-
this.emit('@connectionstatechange', 'closed');
|
|
194
|
-
break;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
201
|
-
async updateIceServers(iceServers) {
|
|
202
|
-
this.assertNotClosed();
|
|
203
|
-
// NOTE: Firefox does not implement pc.setConfiguration().
|
|
204
|
-
throw new errors_1.UnsupportedError('not supported');
|
|
205
|
-
}
|
|
206
|
-
async restartIce(iceParameters) {
|
|
207
|
-
this.assertNotClosed();
|
|
208
|
-
logger.debug('restartIce()');
|
|
209
|
-
// Provide the remote SDP handler with new remote ICE parameters.
|
|
210
|
-
this._remoteSdp.updateIceParameters(iceParameters);
|
|
211
|
-
if (!this._transportReady) {
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
if (this._direction === 'send') {
|
|
215
|
-
const offer = await this._pc.createOffer({ iceRestart: true });
|
|
216
|
-
logger.debug('restartIce() | calling pc.setLocalDescription() [offer:%o]', offer);
|
|
217
|
-
await this._pc.setLocalDescription(offer);
|
|
218
|
-
const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
|
|
219
|
-
logger.debug('restartIce() | calling pc.setRemoteDescription() [answer:%o]', answer);
|
|
220
|
-
await this._pc.setRemoteDescription(answer);
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
|
|
224
|
-
logger.debug('restartIce() | calling pc.setRemoteDescription() [offer:%o]', offer);
|
|
225
|
-
await this._pc.setRemoteDescription(offer);
|
|
226
|
-
const answer = await this._pc.createAnswer();
|
|
227
|
-
logger.debug('restartIce() | calling pc.setLocalDescription() [answer:%o]', answer);
|
|
228
|
-
await this._pc.setLocalDescription(answer);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
async getTransportStats() {
|
|
232
|
-
this.assertNotClosed();
|
|
233
|
-
return this._pc.getStats();
|
|
234
|
-
}
|
|
235
|
-
async send({ track, encodings, codecOptions, codec, }) {
|
|
236
|
-
this.assertNotClosed();
|
|
237
|
-
this.assertSendDirection();
|
|
238
|
-
logger.debug('send() [kind:%s, track.id:%s]', track.kind, track.id);
|
|
239
|
-
if (encodings) {
|
|
240
|
-
encodings = utils.clone(encodings);
|
|
241
|
-
encodings.forEach((encoding, idx) => {
|
|
242
|
-
encoding.rid = `r${idx}`;
|
|
243
|
-
});
|
|
244
|
-
// Clone the encodings and reverse them because Firefox likes them
|
|
245
|
-
// from high to low.
|
|
246
|
-
encodings.reverse();
|
|
247
|
-
}
|
|
248
|
-
const sendingRtpParameters = utils.clone(this._sendingRtpParametersByKind[track.kind]);
|
|
249
|
-
// This may throw.
|
|
250
|
-
sendingRtpParameters.codecs = ortc.reduceCodecs(sendingRtpParameters.codecs, codec);
|
|
251
|
-
const sendingRemoteRtpParameters = utils.clone(this._sendingRemoteRtpParametersByKind[track.kind]);
|
|
252
|
-
// This may throw.
|
|
253
|
-
sendingRemoteRtpParameters.codecs = ortc.reduceCodecs(sendingRemoteRtpParameters.codecs, codec);
|
|
254
|
-
// NOTE: Firefox fails sometimes to properly anticipate the closed media
|
|
255
|
-
// section that it should use, so don't reuse closed media sections.
|
|
256
|
-
// https://github.com/versatica/mediasoup-client/issues/104
|
|
257
|
-
//
|
|
258
|
-
// const mediaSectionIdx = this._remoteSdp!.getNextMediaSectionIdx();
|
|
259
|
-
const transceiver = this._pc.addTransceiver(track, {
|
|
260
|
-
direction: 'sendonly',
|
|
261
|
-
streams: [this._sendStream],
|
|
262
|
-
});
|
|
263
|
-
// NOTE: This is not spec compliants. Encodings should be given in addTransceiver
|
|
264
|
-
// second argument, but Firefox does not support it.
|
|
265
|
-
if (encodings) {
|
|
266
|
-
const parameters = transceiver.sender.getParameters();
|
|
267
|
-
parameters.encodings = encodings;
|
|
268
|
-
await transceiver.sender.setParameters(parameters);
|
|
269
|
-
}
|
|
270
|
-
const offer = await this._pc.createOffer();
|
|
271
|
-
let localSdpObject = sdpTransform.parse(offer.sdp);
|
|
272
|
-
// @ts-expect-error --- sdpTransform.SessionDescription type doesn't
|
|
273
|
-
// define extmapAllowMixed field.
|
|
274
|
-
if (localSdpObject.extmapAllowMixed) {
|
|
275
|
-
this._remoteSdp.setSessionExtmapAllowMixed();
|
|
276
|
-
}
|
|
277
|
-
// In Firefox use DTLS role client even if we are the "offerer" since
|
|
278
|
-
// Firefox does not respect ICE-Lite.
|
|
279
|
-
if (!this._transportReady) {
|
|
280
|
-
await this.setupTransport({ localDtlsRole: 'client', localSdpObject });
|
|
281
|
-
}
|
|
282
|
-
const layers = (0, scalabilityModes_1.parse)((encodings ?? [{}])[0].scalabilityMode);
|
|
283
|
-
logger.debug('send() | calling pc.setLocalDescription() [offer:%o]', offer);
|
|
284
|
-
await this._pc.setLocalDescription(offer);
|
|
285
|
-
// We can now get the transceiver.mid.
|
|
286
|
-
const localId = transceiver.mid;
|
|
287
|
-
// Set MID.
|
|
288
|
-
sendingRtpParameters.mid = localId;
|
|
289
|
-
localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);
|
|
290
|
-
const offerMediaObject = localSdpObject.media[localSdpObject.media.length - 1];
|
|
291
|
-
// Set RTCP CNAME.
|
|
292
|
-
sendingRtpParameters.rtcp.cname = sdpCommonUtils.getCname({
|
|
293
|
-
offerMediaObject,
|
|
294
|
-
});
|
|
295
|
-
// Set RTP encodings by parsing the SDP offer if no encodings are given.
|
|
296
|
-
if (!encodings) {
|
|
297
|
-
sendingRtpParameters.encodings = sdpUnifiedPlanUtils.getRtpEncodings({
|
|
298
|
-
offerMediaObject,
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
// Set RTP encodings by parsing the SDP offer and complete them with given
|
|
302
|
-
// one if just a single encoding has been given.
|
|
303
|
-
else if (encodings.length === 1) {
|
|
304
|
-
const newEncodings = sdpUnifiedPlanUtils.getRtpEncodings({
|
|
305
|
-
offerMediaObject,
|
|
306
|
-
});
|
|
307
|
-
Object.assign(newEncodings[0], encodings[0]);
|
|
308
|
-
sendingRtpParameters.encodings = newEncodings;
|
|
309
|
-
}
|
|
310
|
-
// Otherwise if more than 1 encoding are given use them verbatim (but
|
|
311
|
-
// reverse them back since we reversed them above to satisfy Firefox).
|
|
312
|
-
else {
|
|
313
|
-
sendingRtpParameters.encodings = encodings.reverse();
|
|
314
|
-
}
|
|
315
|
-
// If VP8 or H264 and there is effective simulcast, add scalabilityMode to
|
|
316
|
-
// each encoding.
|
|
317
|
-
if (sendingRtpParameters.encodings.length > 1 &&
|
|
318
|
-
(sendingRtpParameters.codecs[0].mimeType.toLowerCase() === 'video/vp8' ||
|
|
319
|
-
sendingRtpParameters.codecs[0].mimeType.toLowerCase() === 'video/h264')) {
|
|
320
|
-
for (const encoding of sendingRtpParameters.encodings) {
|
|
321
|
-
if (encoding.scalabilityMode) {
|
|
322
|
-
encoding.scalabilityMode = `L1T${layers.temporalLayers}`;
|
|
323
|
-
}
|
|
324
|
-
else {
|
|
325
|
-
encoding.scalabilityMode = 'L1T3';
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
this._remoteSdp.send({
|
|
330
|
-
offerMediaObject,
|
|
331
|
-
offerRtpParameters: sendingRtpParameters,
|
|
332
|
-
answerRtpParameters: sendingRemoteRtpParameters,
|
|
333
|
-
codecOptions,
|
|
334
|
-
});
|
|
335
|
-
const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
|
|
336
|
-
logger.debug('send() | calling pc.setRemoteDescription() [answer:%o]', answer);
|
|
337
|
-
await this._pc.setRemoteDescription(answer);
|
|
338
|
-
// Store in the map.
|
|
339
|
-
this._mapMidTransceiver.set(localId, transceiver);
|
|
340
|
-
return {
|
|
341
|
-
localId,
|
|
342
|
-
rtpParameters: sendingRtpParameters,
|
|
343
|
-
rtpSender: transceiver.sender,
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
async stopSending(localId) {
|
|
347
|
-
this.assertSendDirection();
|
|
348
|
-
logger.debug('stopSending() [localId:%s]', localId);
|
|
349
|
-
if (this._closed) {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
const transceiver = this._mapMidTransceiver.get(localId);
|
|
353
|
-
if (!transceiver) {
|
|
354
|
-
throw new Error('associated transceiver not found');
|
|
355
|
-
}
|
|
356
|
-
void transceiver.sender.replaceTrack(null);
|
|
357
|
-
// NOTE: Cannot use stop() the transceiver due to the the note above in
|
|
358
|
-
// send() method.
|
|
359
|
-
// try
|
|
360
|
-
// {
|
|
361
|
-
// transceiver.stop();
|
|
362
|
-
// }
|
|
363
|
-
// catch (error)
|
|
364
|
-
// {}
|
|
365
|
-
this._pc.removeTrack(transceiver.sender);
|
|
366
|
-
// NOTE: Cannot use closeMediaSection() due to the the note above in send()
|
|
367
|
-
// method.
|
|
368
|
-
// this._remoteSdp!.closeMediaSection(transceiver.mid);
|
|
369
|
-
this._remoteSdp.disableMediaSection(transceiver.mid);
|
|
370
|
-
const offer = await this._pc.createOffer();
|
|
371
|
-
logger.debug('stopSending() | calling pc.setLocalDescription() [offer:%o]', offer);
|
|
372
|
-
await this._pc.setLocalDescription(offer);
|
|
373
|
-
const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
|
|
374
|
-
logger.debug('stopSending() | calling pc.setRemoteDescription() [answer:%o]', answer);
|
|
375
|
-
await this._pc.setRemoteDescription(answer);
|
|
376
|
-
this._mapMidTransceiver.delete(localId);
|
|
377
|
-
}
|
|
378
|
-
async pauseSending(localId) {
|
|
379
|
-
this.assertNotClosed();
|
|
380
|
-
this.assertSendDirection();
|
|
381
|
-
logger.debug('pauseSending() [localId:%s]', localId);
|
|
382
|
-
const transceiver = this._mapMidTransceiver.get(localId);
|
|
383
|
-
if (!transceiver) {
|
|
384
|
-
throw new Error('associated RTCRtpTransceiver not found');
|
|
385
|
-
}
|
|
386
|
-
transceiver.direction = 'inactive';
|
|
387
|
-
this._remoteSdp.pauseMediaSection(localId);
|
|
388
|
-
const offer = await this._pc.createOffer();
|
|
389
|
-
logger.debug('pauseSending() | calling pc.setLocalDescription() [offer:%o]', offer);
|
|
390
|
-
await this._pc.setLocalDescription(offer);
|
|
391
|
-
const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
|
|
392
|
-
logger.debug('pauseSending() | calling pc.setRemoteDescription() [answer:%o]', answer);
|
|
393
|
-
await this._pc.setRemoteDescription(answer);
|
|
394
|
-
}
|
|
395
|
-
async resumeSending(localId) {
|
|
396
|
-
this.assertNotClosed();
|
|
397
|
-
this.assertSendDirection();
|
|
398
|
-
logger.debug('resumeSending() [localId:%s]', localId);
|
|
399
|
-
const transceiver = this._mapMidTransceiver.get(localId);
|
|
400
|
-
if (!transceiver) {
|
|
401
|
-
throw new Error('associated RTCRtpTransceiver not found');
|
|
402
|
-
}
|
|
403
|
-
transceiver.direction = 'sendonly';
|
|
404
|
-
this._remoteSdp.resumeSendingMediaSection(localId);
|
|
405
|
-
const offer = await this._pc.createOffer();
|
|
406
|
-
logger.debug('resumeSending() | calling pc.setLocalDescription() [offer:%o]', offer);
|
|
407
|
-
await this._pc.setLocalDescription(offer);
|
|
408
|
-
const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
|
|
409
|
-
logger.debug('resumeSending() | calling pc.setRemoteDescription() [answer:%o]', answer);
|
|
410
|
-
await this._pc.setRemoteDescription(answer);
|
|
411
|
-
}
|
|
412
|
-
async replaceTrack(localId, track) {
|
|
413
|
-
this.assertNotClosed();
|
|
414
|
-
this.assertSendDirection();
|
|
415
|
-
if (track) {
|
|
416
|
-
logger.debug('replaceTrack() [localId:%s, track.id:%s]', localId, track.id);
|
|
417
|
-
}
|
|
418
|
-
else {
|
|
419
|
-
logger.debug('replaceTrack() [localId:%s, no track]', localId);
|
|
420
|
-
}
|
|
421
|
-
const transceiver = this._mapMidTransceiver.get(localId);
|
|
422
|
-
if (!transceiver) {
|
|
423
|
-
throw new Error('associated RTCRtpTransceiver not found');
|
|
424
|
-
}
|
|
425
|
-
await transceiver.sender.replaceTrack(track);
|
|
426
|
-
}
|
|
427
|
-
async setMaxSpatialLayer(localId, spatialLayer) {
|
|
428
|
-
this.assertNotClosed();
|
|
429
|
-
this.assertSendDirection();
|
|
430
|
-
logger.debug('setMaxSpatialLayer() [localId:%s, spatialLayer:%s]', localId, spatialLayer);
|
|
431
|
-
const transceiver = this._mapMidTransceiver.get(localId);
|
|
432
|
-
if (!transceiver) {
|
|
433
|
-
throw new Error('associated transceiver not found');
|
|
434
|
-
}
|
|
435
|
-
const parameters = transceiver.sender.getParameters();
|
|
436
|
-
// NOTE: We require encodings given from low to high, however Firefox
|
|
437
|
-
// requires them in reverse order, so do magic here.
|
|
438
|
-
spatialLayer = parameters.encodings.length - 1 - spatialLayer;
|
|
439
|
-
parameters.encodings.forEach((encoding, idx) => {
|
|
440
|
-
if (idx >= spatialLayer) {
|
|
441
|
-
encoding.active = true;
|
|
442
|
-
}
|
|
443
|
-
else {
|
|
444
|
-
encoding.active = false;
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
await transceiver.sender.setParameters(parameters);
|
|
448
|
-
this._remoteSdp.muxMediaSectionSimulcast(localId, parameters.encodings);
|
|
449
|
-
const offer = await this._pc.createOffer();
|
|
450
|
-
logger.debug('setMaxSpatialLayer() | calling pc.setLocalDescription() [offer:%o]', offer);
|
|
451
|
-
await this._pc.setLocalDescription(offer);
|
|
452
|
-
const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
|
|
453
|
-
logger.debug('setMaxSpatialLayer() | calling pc.setRemoteDescription() [answer:%o]', answer);
|
|
454
|
-
await this._pc.setRemoteDescription(answer);
|
|
455
|
-
}
|
|
456
|
-
async setRtpEncodingParameters(localId, params) {
|
|
457
|
-
this.assertNotClosed();
|
|
458
|
-
this.assertSendDirection();
|
|
459
|
-
logger.debug('setRtpEncodingParameters() [localId:%s, params:%o]', localId, params);
|
|
460
|
-
const transceiver = this._mapMidTransceiver.get(localId);
|
|
461
|
-
if (!transceiver) {
|
|
462
|
-
throw new Error('associated RTCRtpTransceiver not found');
|
|
463
|
-
}
|
|
464
|
-
const parameters = transceiver.sender.getParameters();
|
|
465
|
-
parameters.encodings.forEach((encoding, idx) => {
|
|
466
|
-
parameters.encodings[idx] = { ...encoding, ...params };
|
|
467
|
-
});
|
|
468
|
-
await transceiver.sender.setParameters(parameters);
|
|
469
|
-
this._remoteSdp.muxMediaSectionSimulcast(localId, parameters.encodings);
|
|
470
|
-
const offer = await this._pc.createOffer();
|
|
471
|
-
logger.debug('setRtpEncodingParameters() | calling pc.setLocalDescription() [offer:%o]', offer);
|
|
472
|
-
await this._pc.setLocalDescription(offer);
|
|
473
|
-
const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
|
|
474
|
-
logger.debug('setRtpEncodingParameters() | calling pc.setRemoteDescription() [answer:%o]', answer);
|
|
475
|
-
await this._pc.setRemoteDescription(answer);
|
|
476
|
-
}
|
|
477
|
-
async getSenderStats(localId) {
|
|
478
|
-
this.assertNotClosed();
|
|
479
|
-
this.assertSendDirection();
|
|
480
|
-
const transceiver = this._mapMidTransceiver.get(localId);
|
|
481
|
-
if (!transceiver) {
|
|
482
|
-
throw new Error('associated RTCRtpTransceiver not found');
|
|
483
|
-
}
|
|
484
|
-
return transceiver.sender.getStats();
|
|
485
|
-
}
|
|
486
|
-
async sendDataChannel({ ordered, maxPacketLifeTime, maxRetransmits, label, protocol, }) {
|
|
487
|
-
this.assertNotClosed();
|
|
488
|
-
this.assertSendDirection();
|
|
489
|
-
const options = {
|
|
490
|
-
negotiated: true,
|
|
491
|
-
id: this._nextSendSctpStreamId,
|
|
492
|
-
ordered,
|
|
493
|
-
maxPacketLifeTime,
|
|
494
|
-
maxRetransmits,
|
|
495
|
-
protocol,
|
|
496
|
-
};
|
|
497
|
-
logger.debug('sendDataChannel() [options:%o]', options);
|
|
498
|
-
const dataChannel = this._pc.createDataChannel(label, options);
|
|
499
|
-
// Increase next id.
|
|
500
|
-
this._nextSendSctpStreamId =
|
|
501
|
-
++this._nextSendSctpStreamId % SCTP_NUM_STREAMS.MIS;
|
|
502
|
-
// If this is the first DataChannel we need to create the SDP answer with
|
|
503
|
-
// m=application section.
|
|
504
|
-
if (!this._hasDataChannelMediaSection) {
|
|
505
|
-
const offer = await this._pc.createOffer();
|
|
506
|
-
const localSdpObject = sdpTransform.parse(offer.sdp);
|
|
507
|
-
const offerMediaObject = localSdpObject.media.find((m) => m.type === 'application');
|
|
508
|
-
if (!this._transportReady) {
|
|
509
|
-
await this.setupTransport({ localDtlsRole: 'client', localSdpObject });
|
|
510
|
-
}
|
|
511
|
-
logger.debug('sendDataChannel() | calling pc.setLocalDescription() [offer:%o]', offer);
|
|
512
|
-
await this._pc.setLocalDescription(offer);
|
|
513
|
-
this._remoteSdp.sendSctpAssociation({ offerMediaObject });
|
|
514
|
-
const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
|
|
515
|
-
logger.debug('sendDataChannel() | calling pc.setRemoteDescription() [answer:%o]', answer);
|
|
516
|
-
await this._pc.setRemoteDescription(answer);
|
|
517
|
-
this._hasDataChannelMediaSection = true;
|
|
518
|
-
}
|
|
519
|
-
const sctpStreamParameters = {
|
|
520
|
-
streamId: options.id,
|
|
521
|
-
ordered: options.ordered,
|
|
522
|
-
maxPacketLifeTime: options.maxPacketLifeTime,
|
|
523
|
-
maxRetransmits: options.maxRetransmits,
|
|
524
|
-
};
|
|
525
|
-
return { dataChannel, sctpStreamParameters };
|
|
526
|
-
}
|
|
527
|
-
async receive(optionsList) {
|
|
528
|
-
this.assertNotClosed();
|
|
529
|
-
this.assertRecvDirection();
|
|
530
|
-
const results = [];
|
|
531
|
-
const mapLocalId = new Map();
|
|
532
|
-
for (const options of optionsList) {
|
|
533
|
-
const { trackId, kind, rtpParameters, streamId } = options;
|
|
534
|
-
logger.debug('receive() [trackId:%s, kind:%s]', trackId, kind);
|
|
535
|
-
const localId = rtpParameters.mid ?? String(this._mapMidTransceiver.size);
|
|
536
|
-
mapLocalId.set(trackId, localId);
|
|
537
|
-
this._remoteSdp.receive({
|
|
538
|
-
mid: localId,
|
|
539
|
-
kind,
|
|
540
|
-
offerRtpParameters: rtpParameters,
|
|
541
|
-
streamId: streamId ?? rtpParameters.rtcp.cname,
|
|
542
|
-
trackId,
|
|
543
|
-
});
|
|
544
|
-
}
|
|
545
|
-
const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
|
|
546
|
-
logger.debug('receive() | calling pc.setRemoteDescription() [offer:%o]', offer);
|
|
547
|
-
await this._pc.setRemoteDescription(offer);
|
|
548
|
-
let answer = await this._pc.createAnswer();
|
|
549
|
-
const localSdpObject = sdpTransform.parse(answer.sdp);
|
|
550
|
-
for (const options of optionsList) {
|
|
551
|
-
const { trackId, rtpParameters } = options;
|
|
552
|
-
const localId = mapLocalId.get(trackId);
|
|
553
|
-
const answerMediaObject = localSdpObject.media.find((m) => String(m.mid) === localId);
|
|
554
|
-
// May need to modify codec parameters in the answer based on codec
|
|
555
|
-
// parameters in the offer.
|
|
556
|
-
sdpCommonUtils.applyCodecParameters({
|
|
557
|
-
offerRtpParameters: rtpParameters,
|
|
558
|
-
answerMediaObject,
|
|
559
|
-
});
|
|
560
|
-
answer = { type: 'answer', sdp: sdpTransform.write(localSdpObject) };
|
|
561
|
-
}
|
|
562
|
-
if (!this._transportReady) {
|
|
563
|
-
await this.setupTransport({ localDtlsRole: 'client', localSdpObject });
|
|
564
|
-
}
|
|
565
|
-
logger.debug('receive() | calling pc.setLocalDescription() [answer:%o]', answer);
|
|
566
|
-
await this._pc.setLocalDescription(answer);
|
|
567
|
-
for (const options of optionsList) {
|
|
568
|
-
const { trackId } = options;
|
|
569
|
-
const localId = mapLocalId.get(trackId);
|
|
570
|
-
const transceiver = this._pc
|
|
571
|
-
.getTransceivers()
|
|
572
|
-
.find((t) => t.mid === localId);
|
|
573
|
-
if (!transceiver) {
|
|
574
|
-
throw new Error('new RTCRtpTransceiver not found');
|
|
575
|
-
}
|
|
576
|
-
// Store in the map.
|
|
577
|
-
this._mapMidTransceiver.set(localId, transceiver);
|
|
578
|
-
results.push({
|
|
579
|
-
localId,
|
|
580
|
-
track: transceiver.receiver.track,
|
|
581
|
-
rtpReceiver: transceiver.receiver,
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
return results;
|
|
585
|
-
}
|
|
586
|
-
async stopReceiving(localIds) {
|
|
587
|
-
this.assertRecvDirection();
|
|
588
|
-
if (this._closed) {
|
|
589
|
-
return;
|
|
590
|
-
}
|
|
591
|
-
for (const localId of localIds) {
|
|
592
|
-
logger.debug('stopReceiving() [localId:%s]', localId);
|
|
593
|
-
const transceiver = this._mapMidTransceiver.get(localId);
|
|
594
|
-
if (!transceiver) {
|
|
595
|
-
throw new Error('associated RTCRtpTransceiver not found');
|
|
596
|
-
}
|
|
597
|
-
this._remoteSdp.closeMediaSection(transceiver.mid);
|
|
598
|
-
}
|
|
599
|
-
const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
|
|
600
|
-
logger.debug('stopReceiving() | calling pc.setRemoteDescription() [offer:%o]', offer);
|
|
601
|
-
await this._pc.setRemoteDescription(offer);
|
|
602
|
-
const answer = await this._pc.createAnswer();
|
|
603
|
-
logger.debug('stopReceiving() | calling pc.setLocalDescription() [answer:%o]', answer);
|
|
604
|
-
await this._pc.setLocalDescription(answer);
|
|
605
|
-
for (const localId of localIds) {
|
|
606
|
-
this._mapMidTransceiver.delete(localId);
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
async pauseReceiving(localIds) {
|
|
610
|
-
this.assertNotClosed();
|
|
611
|
-
this.assertRecvDirection();
|
|
612
|
-
for (const localId of localIds) {
|
|
613
|
-
logger.debug('pauseReceiving() [localId:%s]', localId);
|
|
614
|
-
const transceiver = this._mapMidTransceiver.get(localId);
|
|
615
|
-
if (!transceiver) {
|
|
616
|
-
throw new Error('associated RTCRtpTransceiver not found');
|
|
617
|
-
}
|
|
618
|
-
transceiver.direction = 'inactive';
|
|
619
|
-
this._remoteSdp.pauseMediaSection(localId);
|
|
620
|
-
}
|
|
621
|
-
const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
|
|
622
|
-
logger.debug('pauseReceiving() | calling pc.setRemoteDescription() [offer:%o]', offer);
|
|
623
|
-
await this._pc.setRemoteDescription(offer);
|
|
624
|
-
const answer = await this._pc.createAnswer();
|
|
625
|
-
logger.debug('pauseReceiving() | calling pc.setLocalDescription() [answer:%o]', answer);
|
|
626
|
-
await this._pc.setLocalDescription(answer);
|
|
627
|
-
}
|
|
628
|
-
async resumeReceiving(localIds) {
|
|
629
|
-
this.assertNotClosed();
|
|
630
|
-
this.assertRecvDirection();
|
|
631
|
-
for (const localId of localIds) {
|
|
632
|
-
logger.debug('resumeReceiving() [localId:%s]', localId);
|
|
633
|
-
const transceiver = this._mapMidTransceiver.get(localId);
|
|
634
|
-
if (!transceiver) {
|
|
635
|
-
throw new Error('associated RTCRtpTransceiver not found');
|
|
636
|
-
}
|
|
637
|
-
transceiver.direction = 'recvonly';
|
|
638
|
-
this._remoteSdp.resumeReceivingMediaSection(localId);
|
|
639
|
-
}
|
|
640
|
-
const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
|
|
641
|
-
logger.debug('resumeReceiving() | calling pc.setRemoteDescription() [offer:%o]', offer);
|
|
642
|
-
await this._pc.setRemoteDescription(offer);
|
|
643
|
-
const answer = await this._pc.createAnswer();
|
|
644
|
-
logger.debug('resumeReceiving() | calling pc.setLocalDescription() [answer:%o]', answer);
|
|
645
|
-
await this._pc.setLocalDescription(answer);
|
|
646
|
-
}
|
|
647
|
-
async getReceiverStats(localId) {
|
|
648
|
-
this.assertRecvDirection();
|
|
649
|
-
const transceiver = this._mapMidTransceiver.get(localId);
|
|
650
|
-
if (!transceiver) {
|
|
651
|
-
throw new Error('associated RTCRtpTransceiver not found');
|
|
652
|
-
}
|
|
653
|
-
return transceiver.receiver.getStats();
|
|
654
|
-
}
|
|
655
|
-
async receiveDataChannel({ sctpStreamParameters, label, protocol, }) {
|
|
656
|
-
this.assertNotClosed();
|
|
657
|
-
this.assertRecvDirection();
|
|
658
|
-
const { streamId, ordered, maxPacketLifeTime, maxRetransmits, } = sctpStreamParameters;
|
|
659
|
-
const options = {
|
|
660
|
-
negotiated: true,
|
|
661
|
-
id: streamId,
|
|
662
|
-
ordered,
|
|
663
|
-
maxPacketLifeTime,
|
|
664
|
-
maxRetransmits,
|
|
665
|
-
protocol,
|
|
666
|
-
};
|
|
667
|
-
logger.debug('receiveDataChannel() [options:%o]', options);
|
|
668
|
-
const dataChannel = this._pc.createDataChannel(label, options);
|
|
669
|
-
// If this is the first DataChannel we need to create the SDP offer with
|
|
670
|
-
// m=application section.
|
|
671
|
-
if (!this._hasDataChannelMediaSection) {
|
|
672
|
-
this._remoteSdp.receiveSctpAssociation();
|
|
673
|
-
const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
|
|
674
|
-
logger.debug('receiveDataChannel() | calling pc.setRemoteDescription() [offer:%o]', offer);
|
|
675
|
-
await this._pc.setRemoteDescription(offer);
|
|
676
|
-
const answer = await this._pc.createAnswer();
|
|
677
|
-
if (!this._transportReady) {
|
|
678
|
-
const localSdpObject = sdpTransform.parse(answer.sdp);
|
|
679
|
-
await this.setupTransport({ localDtlsRole: 'client', localSdpObject });
|
|
680
|
-
}
|
|
681
|
-
logger.debug('receiveDataChannel() | calling pc.setRemoteDescription() [answer:%o]', answer);
|
|
682
|
-
await this._pc.setLocalDescription(answer);
|
|
683
|
-
this._hasDataChannelMediaSection = true;
|
|
684
|
-
}
|
|
685
|
-
return { dataChannel };
|
|
686
|
-
}
|
|
687
|
-
async setupTransport({ localDtlsRole, localSdpObject, }) {
|
|
688
|
-
if (!localSdpObject) {
|
|
689
|
-
localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);
|
|
690
|
-
}
|
|
691
|
-
// Get our local DTLS parameters.
|
|
692
|
-
const dtlsParameters = sdpCommonUtils.extractDtlsParameters({
|
|
693
|
-
sdpObject: localSdpObject,
|
|
694
|
-
});
|
|
695
|
-
// Set our DTLS role.
|
|
696
|
-
dtlsParameters.role = localDtlsRole;
|
|
697
|
-
// Update the remote DTLS role in the SDP.
|
|
698
|
-
this._remoteSdp.updateDtlsRole(localDtlsRole === 'client' ? 'server' : 'client');
|
|
699
|
-
// Need to tell the remote transport about our parameters.
|
|
700
|
-
await new Promise((resolve, reject) => {
|
|
701
|
-
this.safeEmit('@connect', { dtlsParameters }, resolve, reject);
|
|
702
|
-
});
|
|
703
|
-
this._transportReady = true;
|
|
704
|
-
}
|
|
705
|
-
assertNotClosed() {
|
|
706
|
-
if (this._closed) {
|
|
707
|
-
throw new errors_1.InvalidStateError('method called in a closed handler');
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
assertSendDirection() {
|
|
711
|
-
if (this._direction !== 'send') {
|
|
712
|
-
throw new Error('method can just be called for handlers with "send" direction');
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
assertRecvDirection() {
|
|
716
|
-
if (this._direction !== 'recv') {
|
|
717
|
-
throw new Error('method can just be called for handlers with "recv" direction');
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
exports.Firefox60 = Firefox60;
|