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
package/lib/handlers/Chrome70.js
DELETED
|
@@ -1,634 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Chrome70 = void 0;
|
|
4
|
-
const sdpTransform = require("sdp-transform");
|
|
5
|
-
const Logger_1 = require("../Logger");
|
|
6
|
-
const utils = require("../utils");
|
|
7
|
-
const ortc = require("../ortc");
|
|
8
|
-
const sdpCommonUtils = require("./sdp/commonUtils");
|
|
9
|
-
const sdpUnifiedPlanUtils = require("./sdp/unifiedPlanUtils");
|
|
10
|
-
const HandlerInterface_1 = require("./HandlerInterface");
|
|
11
|
-
const RemoteSdp_1 = require("./sdp/RemoteSdp");
|
|
12
|
-
const scalabilityModes_1 = require("../scalabilityModes");
|
|
13
|
-
const logger = new Logger_1.Logger('Chrome70');
|
|
14
|
-
const NAME = 'Chrome70';
|
|
15
|
-
const SCTP_NUM_STREAMS = { OS: 1024, MIS: 1024 };
|
|
16
|
-
class Chrome70 extends HandlerInterface_1.HandlerInterface {
|
|
17
|
-
// Handler direction.
|
|
18
|
-
_direction;
|
|
19
|
-
// Remote SDP handler.
|
|
20
|
-
_remoteSdp;
|
|
21
|
-
// Generic sending RTP parameters for audio and video.
|
|
22
|
-
_sendingRtpParametersByKind;
|
|
23
|
-
// Generic sending RTP parameters for audio and video suitable for the SDP
|
|
24
|
-
// remote answer.
|
|
25
|
-
_sendingRemoteRtpParametersByKind;
|
|
26
|
-
// Initial server side DTLS role. If not 'auto', it will force the opposite
|
|
27
|
-
// value in client side.
|
|
28
|
-
_forcedLocalDtlsRole;
|
|
29
|
-
// RTCPeerConnection instance.
|
|
30
|
-
_pc;
|
|
31
|
-
// 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 Chrome70();
|
|
46
|
-
}
|
|
47
|
-
constructor() {
|
|
48
|
-
super();
|
|
49
|
-
}
|
|
50
|
-
get name() {
|
|
51
|
-
return NAME;
|
|
52
|
-
}
|
|
53
|
-
close() {
|
|
54
|
-
logger.debug('close()');
|
|
55
|
-
// Close RTCPeerConnection.
|
|
56
|
-
if (this._pc) {
|
|
57
|
-
try {
|
|
58
|
-
this._pc.close();
|
|
59
|
-
}
|
|
60
|
-
catch (error) { }
|
|
61
|
-
}
|
|
62
|
-
this.emit('@close');
|
|
63
|
-
}
|
|
64
|
-
async getNativeRtpCapabilities() {
|
|
65
|
-
logger.debug('getNativeRtpCapabilities()');
|
|
66
|
-
const pc = new RTCPeerConnection({
|
|
67
|
-
iceServers: [],
|
|
68
|
-
iceTransportPolicy: 'all',
|
|
69
|
-
bundlePolicy: 'max-bundle',
|
|
70
|
-
rtcpMuxPolicy: 'require',
|
|
71
|
-
sdpSemantics: 'unified-plan',
|
|
72
|
-
});
|
|
73
|
-
try {
|
|
74
|
-
pc.addTransceiver('audio');
|
|
75
|
-
pc.addTransceiver('video');
|
|
76
|
-
const offer = await pc.createOffer();
|
|
77
|
-
try {
|
|
78
|
-
pc.close();
|
|
79
|
-
}
|
|
80
|
-
catch (error) { }
|
|
81
|
-
const sdpObject = sdpTransform.parse(offer.sdp);
|
|
82
|
-
const nativeRtpCapabilities = sdpCommonUtils.extractRtpCapabilities({
|
|
83
|
-
sdpObject,
|
|
84
|
-
});
|
|
85
|
-
return nativeRtpCapabilities;
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
try {
|
|
89
|
-
pc.close();
|
|
90
|
-
}
|
|
91
|
-
catch (error2) { }
|
|
92
|
-
throw error;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
async getNativeSctpCapabilities() {
|
|
96
|
-
logger.debug('getNativeSctpCapabilities()');
|
|
97
|
-
return {
|
|
98
|
-
numStreams: SCTP_NUM_STREAMS,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
run({ direction, iceParameters, iceCandidates, dtlsParameters, sctpParameters, iceServers, iceTransportPolicy, additionalSettings, proprietaryConstraints, extendedRtpCapabilities, }) {
|
|
102
|
-
logger.debug('run()');
|
|
103
|
-
this._direction = direction;
|
|
104
|
-
this._remoteSdp = new RemoteSdp_1.RemoteSdp({
|
|
105
|
-
iceParameters,
|
|
106
|
-
iceCandidates,
|
|
107
|
-
dtlsParameters,
|
|
108
|
-
sctpParameters,
|
|
109
|
-
});
|
|
110
|
-
this._sendingRtpParametersByKind = {
|
|
111
|
-
audio: ortc.getSendingRtpParameters('audio', extendedRtpCapabilities),
|
|
112
|
-
video: ortc.getSendingRtpParameters('video', extendedRtpCapabilities),
|
|
113
|
-
};
|
|
114
|
-
this._sendingRemoteRtpParametersByKind = {
|
|
115
|
-
audio: ortc.getSendingRemoteRtpParameters('audio', extendedRtpCapabilities),
|
|
116
|
-
video: ortc.getSendingRemoteRtpParameters('video', extendedRtpCapabilities),
|
|
117
|
-
};
|
|
118
|
-
if (dtlsParameters.role && dtlsParameters.role !== 'auto') {
|
|
119
|
-
this._forcedLocalDtlsRole =
|
|
120
|
-
dtlsParameters.role === 'server' ? 'client' : 'server';
|
|
121
|
-
}
|
|
122
|
-
this._pc = new RTCPeerConnection({
|
|
123
|
-
iceServers: iceServers ?? [],
|
|
124
|
-
iceTransportPolicy: iceTransportPolicy ?? 'all',
|
|
125
|
-
bundlePolicy: 'max-bundle',
|
|
126
|
-
rtcpMuxPolicy: 'require',
|
|
127
|
-
sdpSemantics: 'unified-plan',
|
|
128
|
-
...additionalSettings,
|
|
129
|
-
}, proprietaryConstraints);
|
|
130
|
-
this._pc.addEventListener('icegatheringstatechange', () => {
|
|
131
|
-
this.emit('@icegatheringstatechange', this._pc.iceGatheringState);
|
|
132
|
-
});
|
|
133
|
-
this._pc.addEventListener('icecandidateerror', (event) => {
|
|
134
|
-
this.emit('@icecandidateerror', event);
|
|
135
|
-
});
|
|
136
|
-
if (this._pc.connectionState) {
|
|
137
|
-
this._pc.addEventListener('connectionstatechange', () => {
|
|
138
|
-
this.emit('@connectionstatechange', this._pc.connectionState);
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
this._pc.addEventListener('iceconnectionstatechange', () => {
|
|
143
|
-
logger.warn('run() | pc.connectionState not supported, using pc.iceConnectionState');
|
|
144
|
-
switch (this._pc.iceConnectionState) {
|
|
145
|
-
case 'checking': {
|
|
146
|
-
this.emit('@connectionstatechange', 'connecting');
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
case 'connected':
|
|
150
|
-
case 'completed': {
|
|
151
|
-
this.emit('@connectionstatechange', 'connected');
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
case 'failed': {
|
|
155
|
-
this.emit('@connectionstatechange', 'failed');
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
case 'disconnected': {
|
|
159
|
-
this.emit('@connectionstatechange', 'disconnected');
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
case 'closed': {
|
|
163
|
-
this.emit('@connectionstatechange', 'closed');
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
async updateIceServers(iceServers) {
|
|
171
|
-
logger.debug('updateIceServers()');
|
|
172
|
-
const configuration = this._pc.getConfiguration();
|
|
173
|
-
configuration.iceServers = iceServers;
|
|
174
|
-
this._pc.setConfiguration(configuration);
|
|
175
|
-
}
|
|
176
|
-
async restartIce(iceParameters) {
|
|
177
|
-
logger.debug('restartIce()');
|
|
178
|
-
// Provide the remote SDP handler with new remote ICE parameters.
|
|
179
|
-
this._remoteSdp.updateIceParameters(iceParameters);
|
|
180
|
-
if (!this._transportReady) {
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
if (this._direction === 'send') {
|
|
184
|
-
const offer = await this._pc.createOffer({ iceRestart: true });
|
|
185
|
-
logger.debug('restartIce() | calling pc.setLocalDescription() [offer:%o]', offer);
|
|
186
|
-
await this._pc.setLocalDescription(offer);
|
|
187
|
-
const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
|
|
188
|
-
logger.debug('restartIce() | calling pc.setRemoteDescription() [answer:%o]', answer);
|
|
189
|
-
await this._pc.setRemoteDescription(answer);
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
|
|
193
|
-
logger.debug('restartIce() | calling pc.setRemoteDescription() [offer:%o]', offer);
|
|
194
|
-
await this._pc.setRemoteDescription(offer);
|
|
195
|
-
const answer = await this._pc.createAnswer();
|
|
196
|
-
logger.debug('restartIce() | calling pc.setLocalDescription() [answer:%o]', answer);
|
|
197
|
-
await this._pc.setLocalDescription(answer);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
async getTransportStats() {
|
|
201
|
-
return this._pc.getStats();
|
|
202
|
-
}
|
|
203
|
-
async send({ track, encodings, codecOptions, codec, }) {
|
|
204
|
-
this.assertSendDirection();
|
|
205
|
-
logger.debug('send() [kind:%s, track.id:%s]', track.kind, track.id);
|
|
206
|
-
const sendingRtpParameters = utils.clone(this._sendingRtpParametersByKind[track.kind]);
|
|
207
|
-
// This may throw.
|
|
208
|
-
sendingRtpParameters.codecs = ortc.reduceCodecs(sendingRtpParameters.codecs, codec);
|
|
209
|
-
const sendingRemoteRtpParameters = utils.clone(this._sendingRemoteRtpParametersByKind[track.kind]);
|
|
210
|
-
// This may throw.
|
|
211
|
-
sendingRemoteRtpParameters.codecs = ortc.reduceCodecs(sendingRemoteRtpParameters.codecs, codec);
|
|
212
|
-
const mediaSectionIdx = this._remoteSdp.getNextMediaSectionIdx();
|
|
213
|
-
const transceiver = this._pc.addTransceiver(track, {
|
|
214
|
-
direction: 'sendonly',
|
|
215
|
-
streams: [this._sendStream],
|
|
216
|
-
});
|
|
217
|
-
let offer = await this._pc.createOffer();
|
|
218
|
-
let localSdpObject = sdpTransform.parse(offer.sdp);
|
|
219
|
-
// @ts-expect-error --- sdpTransform.SessionDescription type doesn't
|
|
220
|
-
// define extmapAllowMixed field.
|
|
221
|
-
if (localSdpObject.extmapAllowMixed) {
|
|
222
|
-
this._remoteSdp.setSessionExtmapAllowMixed();
|
|
223
|
-
}
|
|
224
|
-
let offerMediaObject;
|
|
225
|
-
if (!this._transportReady) {
|
|
226
|
-
await this.setupTransport({
|
|
227
|
-
localDtlsRole: this._forcedLocalDtlsRole ?? 'client',
|
|
228
|
-
localSdpObject,
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
if (encodings && encodings.length > 1) {
|
|
232
|
-
logger.debug('send() | enabling legacy simulcast');
|
|
233
|
-
localSdpObject = sdpTransform.parse(offer.sdp);
|
|
234
|
-
offerMediaObject = localSdpObject.media[mediaSectionIdx.idx];
|
|
235
|
-
sdpUnifiedPlanUtils.addLegacySimulcast({
|
|
236
|
-
offerMediaObject,
|
|
237
|
-
numStreams: encodings.length,
|
|
238
|
-
});
|
|
239
|
-
offer = { type: 'offer', sdp: sdpTransform.write(localSdpObject) };
|
|
240
|
-
}
|
|
241
|
-
// Special case for VP9 with SVC.
|
|
242
|
-
let hackVp9Svc = false;
|
|
243
|
-
const layers = (0, scalabilityModes_1.parse)((encodings ?? [{}])[0].scalabilityMode);
|
|
244
|
-
if (encodings &&
|
|
245
|
-
encodings.length === 1 &&
|
|
246
|
-
layers.spatialLayers > 1 &&
|
|
247
|
-
sendingRtpParameters.codecs[0].mimeType.toLowerCase() === 'video/vp9') {
|
|
248
|
-
logger.debug('send() | enabling legacy simulcast for VP9 SVC');
|
|
249
|
-
hackVp9Svc = true;
|
|
250
|
-
localSdpObject = sdpTransform.parse(offer.sdp);
|
|
251
|
-
offerMediaObject = localSdpObject.media[mediaSectionIdx.idx];
|
|
252
|
-
sdpUnifiedPlanUtils.addLegacySimulcast({
|
|
253
|
-
offerMediaObject,
|
|
254
|
-
numStreams: layers.spatialLayers,
|
|
255
|
-
});
|
|
256
|
-
offer = { type: 'offer', sdp: sdpTransform.write(localSdpObject) };
|
|
257
|
-
}
|
|
258
|
-
logger.debug('send() | calling pc.setLocalDescription() [offer:%o]', offer);
|
|
259
|
-
await this._pc.setLocalDescription(offer);
|
|
260
|
-
// If encodings are given, apply them now.
|
|
261
|
-
if (encodings) {
|
|
262
|
-
logger.debug('send() | applying given encodings');
|
|
263
|
-
const parameters = transceiver.sender.getParameters();
|
|
264
|
-
for (let idx = 0; idx < (parameters.encodings ?? []).length; ++idx) {
|
|
265
|
-
const encoding = parameters.encodings[idx];
|
|
266
|
-
const desiredEncoding = encodings[idx];
|
|
267
|
-
// Should not happen but just in case.
|
|
268
|
-
if (!desiredEncoding) {
|
|
269
|
-
break;
|
|
270
|
-
}
|
|
271
|
-
parameters.encodings[idx] = Object.assign(encoding, desiredEncoding);
|
|
272
|
-
}
|
|
273
|
-
await transceiver.sender.setParameters(parameters);
|
|
274
|
-
}
|
|
275
|
-
// We can now get the transceiver.mid.
|
|
276
|
-
const localId = transceiver.mid;
|
|
277
|
-
// Set MID.
|
|
278
|
-
sendingRtpParameters.mid = localId;
|
|
279
|
-
localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);
|
|
280
|
-
offerMediaObject = localSdpObject.media[mediaSectionIdx.idx];
|
|
281
|
-
// Set RTCP CNAME.
|
|
282
|
-
sendingRtpParameters.rtcp.cname = sdpCommonUtils.getCname({
|
|
283
|
-
offerMediaObject,
|
|
284
|
-
});
|
|
285
|
-
// Set RTP encodings.
|
|
286
|
-
sendingRtpParameters.encodings = sdpUnifiedPlanUtils.getRtpEncodings({
|
|
287
|
-
offerMediaObject,
|
|
288
|
-
});
|
|
289
|
-
// Complete encodings with given values.
|
|
290
|
-
if (encodings) {
|
|
291
|
-
for (let idx = 0; idx < sendingRtpParameters.encodings.length; ++idx) {
|
|
292
|
-
if (encodings[idx]) {
|
|
293
|
-
Object.assign(sendingRtpParameters.encodings[idx], encodings[idx]);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
// Hack for VP9 SVC.
|
|
298
|
-
if (hackVp9Svc) {
|
|
299
|
-
sendingRtpParameters.encodings = [sendingRtpParameters.encodings[0]];
|
|
300
|
-
}
|
|
301
|
-
// If VP8 or H264 and there is effective simulcast, add scalabilityMode to
|
|
302
|
-
// each encoding.
|
|
303
|
-
if (sendingRtpParameters.encodings.length > 1 &&
|
|
304
|
-
(sendingRtpParameters.codecs[0].mimeType.toLowerCase() === 'video/vp8' ||
|
|
305
|
-
sendingRtpParameters.codecs[0].mimeType.toLowerCase() === 'video/h264')) {
|
|
306
|
-
for (const encoding of sendingRtpParameters.encodings) {
|
|
307
|
-
encoding.scalabilityMode = 'L1T3';
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
this._remoteSdp.send({
|
|
311
|
-
offerMediaObject,
|
|
312
|
-
reuseMid: mediaSectionIdx.reuseMid,
|
|
313
|
-
offerRtpParameters: sendingRtpParameters,
|
|
314
|
-
answerRtpParameters: sendingRemoteRtpParameters,
|
|
315
|
-
codecOptions,
|
|
316
|
-
});
|
|
317
|
-
const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
|
|
318
|
-
logger.debug('send() | calling pc.setRemoteDescription() [answer:%o]', answer);
|
|
319
|
-
await this._pc.setRemoteDescription(answer);
|
|
320
|
-
// Store in the map.
|
|
321
|
-
this._mapMidTransceiver.set(localId, transceiver);
|
|
322
|
-
return {
|
|
323
|
-
localId,
|
|
324
|
-
rtpParameters: sendingRtpParameters,
|
|
325
|
-
rtpSender: transceiver.sender,
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
async stopSending(localId) {
|
|
329
|
-
this.assertSendDirection();
|
|
330
|
-
logger.debug('stopSending() [localId:%s]', localId);
|
|
331
|
-
const transceiver = this._mapMidTransceiver.get(localId);
|
|
332
|
-
if (!transceiver) {
|
|
333
|
-
throw new Error('associated RTCRtpTransceiver not found');
|
|
334
|
-
}
|
|
335
|
-
void transceiver.sender.replaceTrack(null);
|
|
336
|
-
this._pc.removeTrack(transceiver.sender);
|
|
337
|
-
const mediaSectionClosed = this._remoteSdp.closeMediaSection(transceiver.mid);
|
|
338
|
-
if (mediaSectionClosed) {
|
|
339
|
-
try {
|
|
340
|
-
transceiver.stop();
|
|
341
|
-
}
|
|
342
|
-
catch (error) { }
|
|
343
|
-
}
|
|
344
|
-
const offer = await this._pc.createOffer();
|
|
345
|
-
logger.debug('stopSending() | calling pc.setLocalDescription() [offer:%o]', offer);
|
|
346
|
-
await this._pc.setLocalDescription(offer);
|
|
347
|
-
const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
|
|
348
|
-
logger.debug('stopSending() | calling pc.setRemoteDescription() [answer:%o]', answer);
|
|
349
|
-
await this._pc.setRemoteDescription(answer);
|
|
350
|
-
this._mapMidTransceiver.delete(localId);
|
|
351
|
-
}
|
|
352
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
353
|
-
async pauseSending(localId) {
|
|
354
|
-
// Unimplemented.
|
|
355
|
-
}
|
|
356
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
357
|
-
async resumeSending(localId) {
|
|
358
|
-
// Unimplemented.
|
|
359
|
-
}
|
|
360
|
-
async replaceTrack(localId, track) {
|
|
361
|
-
this.assertSendDirection();
|
|
362
|
-
if (track) {
|
|
363
|
-
logger.debug('replaceTrack() [localId:%s, track.id:%s]', localId, track.id);
|
|
364
|
-
}
|
|
365
|
-
else {
|
|
366
|
-
logger.debug('replaceTrack() [localId:%s, no track]', localId);
|
|
367
|
-
}
|
|
368
|
-
const transceiver = this._mapMidTransceiver.get(localId);
|
|
369
|
-
if (!transceiver) {
|
|
370
|
-
throw new Error('associated RTCRtpTransceiver not found');
|
|
371
|
-
}
|
|
372
|
-
await transceiver.sender.replaceTrack(track);
|
|
373
|
-
}
|
|
374
|
-
async setMaxSpatialLayer(localId, spatialLayer) {
|
|
375
|
-
this.assertSendDirection();
|
|
376
|
-
logger.debug('setMaxSpatialLayer() [localId:%s, spatialLayer:%s]', localId, spatialLayer);
|
|
377
|
-
const transceiver = this._mapMidTransceiver.get(localId);
|
|
378
|
-
if (!transceiver) {
|
|
379
|
-
throw new Error('associated RTCRtpTransceiver not found');
|
|
380
|
-
}
|
|
381
|
-
const parameters = transceiver.sender.getParameters();
|
|
382
|
-
parameters.encodings.forEach((encoding, idx) => {
|
|
383
|
-
if (idx <= spatialLayer) {
|
|
384
|
-
encoding.active = true;
|
|
385
|
-
}
|
|
386
|
-
else {
|
|
387
|
-
encoding.active = false;
|
|
388
|
-
}
|
|
389
|
-
});
|
|
390
|
-
await transceiver.sender.setParameters(parameters);
|
|
391
|
-
this._remoteSdp.muxMediaSectionSimulcast(localId, parameters.encodings);
|
|
392
|
-
const offer = await this._pc.createOffer();
|
|
393
|
-
logger.debug('setMaxSpatialLayer() | calling pc.setLocalDescription() [offer:%o]', offer);
|
|
394
|
-
await this._pc.setLocalDescription(offer);
|
|
395
|
-
const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
|
|
396
|
-
logger.debug('setMaxSpatialLayer() | calling pc.setRemoteDescription() [answer:%o]', answer);
|
|
397
|
-
await this._pc.setRemoteDescription(answer);
|
|
398
|
-
}
|
|
399
|
-
async setRtpEncodingParameters(localId, params) {
|
|
400
|
-
this.assertSendDirection();
|
|
401
|
-
logger.debug('setRtpEncodingParameters() [localId:%s, params:%o]', localId, params);
|
|
402
|
-
const transceiver = this._mapMidTransceiver.get(localId);
|
|
403
|
-
if (!transceiver) {
|
|
404
|
-
throw new Error('associated RTCRtpTransceiver not found');
|
|
405
|
-
}
|
|
406
|
-
const parameters = transceiver.sender.getParameters();
|
|
407
|
-
parameters.encodings.forEach((encoding, idx) => {
|
|
408
|
-
parameters.encodings[idx] = { ...encoding, ...params };
|
|
409
|
-
});
|
|
410
|
-
await transceiver.sender.setParameters(parameters);
|
|
411
|
-
this._remoteSdp.muxMediaSectionSimulcast(localId, parameters.encodings);
|
|
412
|
-
const offer = await this._pc.createOffer();
|
|
413
|
-
logger.debug('setRtpEncodingParameters() | calling pc.setLocalDescription() [offer:%o]', offer);
|
|
414
|
-
await this._pc.setLocalDescription(offer);
|
|
415
|
-
const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
|
|
416
|
-
logger.debug('setRtpEncodingParameters() | calling pc.setRemoteDescription() [answer:%o]', answer);
|
|
417
|
-
await this._pc.setRemoteDescription(answer);
|
|
418
|
-
}
|
|
419
|
-
async getSenderStats(localId) {
|
|
420
|
-
this.assertSendDirection();
|
|
421
|
-
const transceiver = this._mapMidTransceiver.get(localId);
|
|
422
|
-
if (!transceiver) {
|
|
423
|
-
throw new Error('associated RTCRtpTransceiver not found');
|
|
424
|
-
}
|
|
425
|
-
return transceiver.sender.getStats();
|
|
426
|
-
}
|
|
427
|
-
async sendDataChannel({ ordered, maxPacketLifeTime, maxRetransmits, label, protocol, }) {
|
|
428
|
-
this.assertSendDirection();
|
|
429
|
-
const options = {
|
|
430
|
-
negotiated: true,
|
|
431
|
-
id: this._nextSendSctpStreamId,
|
|
432
|
-
ordered,
|
|
433
|
-
maxPacketLifeTime,
|
|
434
|
-
maxRetransmitTime: maxPacketLifeTime, // NOTE: Old spec.
|
|
435
|
-
maxRetransmits,
|
|
436
|
-
protocol,
|
|
437
|
-
};
|
|
438
|
-
logger.debug('sendDataChannel() [options:%o]', options);
|
|
439
|
-
const dataChannel = this._pc.createDataChannel(label, options);
|
|
440
|
-
// Increase next id.
|
|
441
|
-
this._nextSendSctpStreamId =
|
|
442
|
-
++this._nextSendSctpStreamId % SCTP_NUM_STREAMS.MIS;
|
|
443
|
-
// If this is the first DataChannel we need to create the SDP answer with
|
|
444
|
-
// m=application section.
|
|
445
|
-
if (!this._hasDataChannelMediaSection) {
|
|
446
|
-
const offer = await this._pc.createOffer();
|
|
447
|
-
const localSdpObject = sdpTransform.parse(offer.sdp);
|
|
448
|
-
const offerMediaObject = localSdpObject.media.find((m) => m.type === 'application');
|
|
449
|
-
if (!this._transportReady) {
|
|
450
|
-
await this.setupTransport({
|
|
451
|
-
localDtlsRole: this._forcedLocalDtlsRole ?? 'client',
|
|
452
|
-
localSdpObject,
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
logger.debug('sendDataChannel() | calling pc.setLocalDescription() [offer:%o]', offer);
|
|
456
|
-
await this._pc.setLocalDescription(offer);
|
|
457
|
-
this._remoteSdp.sendSctpAssociation({ offerMediaObject });
|
|
458
|
-
const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };
|
|
459
|
-
logger.debug('sendDataChannel() | calling pc.setRemoteDescription() [answer:%o]', answer);
|
|
460
|
-
await this._pc.setRemoteDescription(answer);
|
|
461
|
-
this._hasDataChannelMediaSection = true;
|
|
462
|
-
}
|
|
463
|
-
const sctpStreamParameters = {
|
|
464
|
-
streamId: options.id,
|
|
465
|
-
ordered: options.ordered,
|
|
466
|
-
maxPacketLifeTime: options.maxPacketLifeTime,
|
|
467
|
-
maxRetransmits: options.maxRetransmits,
|
|
468
|
-
};
|
|
469
|
-
return { dataChannel, sctpStreamParameters };
|
|
470
|
-
}
|
|
471
|
-
async receive(optionsList) {
|
|
472
|
-
this.assertRecvDirection();
|
|
473
|
-
const results = [];
|
|
474
|
-
const mapLocalId = new Map();
|
|
475
|
-
for (const options of optionsList) {
|
|
476
|
-
const { trackId, kind, rtpParameters, streamId } = options;
|
|
477
|
-
logger.debug('receive() [trackId:%s, kind:%s]', trackId, kind);
|
|
478
|
-
const localId = rtpParameters.mid ?? String(this._mapMidTransceiver.size);
|
|
479
|
-
mapLocalId.set(trackId, localId);
|
|
480
|
-
this._remoteSdp.receive({
|
|
481
|
-
mid: localId,
|
|
482
|
-
kind,
|
|
483
|
-
offerRtpParameters: rtpParameters,
|
|
484
|
-
streamId: streamId ?? rtpParameters.rtcp.cname,
|
|
485
|
-
trackId,
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
|
|
489
|
-
logger.debug('receive() | calling pc.setRemoteDescription() [offer:%o]', offer);
|
|
490
|
-
await this._pc.setRemoteDescription(offer);
|
|
491
|
-
let answer = await this._pc.createAnswer();
|
|
492
|
-
const localSdpObject = sdpTransform.parse(answer.sdp);
|
|
493
|
-
for (const options of optionsList) {
|
|
494
|
-
const { trackId, rtpParameters } = options;
|
|
495
|
-
const localId = mapLocalId.get(trackId);
|
|
496
|
-
const answerMediaObject = localSdpObject.media.find((m) => String(m.mid) === localId);
|
|
497
|
-
// May need to modify codec parameters in the answer based on codec
|
|
498
|
-
// parameters in the offer.
|
|
499
|
-
sdpCommonUtils.applyCodecParameters({
|
|
500
|
-
offerRtpParameters: rtpParameters,
|
|
501
|
-
answerMediaObject,
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
answer = { type: 'answer', sdp: sdpTransform.write(localSdpObject) };
|
|
505
|
-
if (!this._transportReady) {
|
|
506
|
-
await this.setupTransport({
|
|
507
|
-
localDtlsRole: this._forcedLocalDtlsRole ?? 'client',
|
|
508
|
-
localSdpObject,
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
logger.debug('receive() | calling pc.setLocalDescription() [answer:%o]', answer);
|
|
512
|
-
await this._pc.setLocalDescription(answer);
|
|
513
|
-
for (const options of optionsList) {
|
|
514
|
-
const { trackId } = options;
|
|
515
|
-
const localId = mapLocalId.get(trackId);
|
|
516
|
-
const transceiver = this._pc
|
|
517
|
-
.getTransceivers()
|
|
518
|
-
.find((t) => t.mid === localId);
|
|
519
|
-
if (!transceiver) {
|
|
520
|
-
throw new Error('new RTCRtpTransceiver not found');
|
|
521
|
-
}
|
|
522
|
-
// Store in the map.
|
|
523
|
-
this._mapMidTransceiver.set(localId, transceiver);
|
|
524
|
-
results.push({
|
|
525
|
-
localId,
|
|
526
|
-
track: transceiver.receiver.track,
|
|
527
|
-
rtpReceiver: transceiver.receiver,
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
return results;
|
|
531
|
-
}
|
|
532
|
-
async stopReceiving(localIds) {
|
|
533
|
-
this.assertRecvDirection();
|
|
534
|
-
for (const localId of localIds) {
|
|
535
|
-
logger.debug('stopReceiving() [localId:%s]', localId);
|
|
536
|
-
const transceiver = this._mapMidTransceiver.get(localId);
|
|
537
|
-
if (!transceiver) {
|
|
538
|
-
throw new Error('associated RTCRtpTransceiver not found');
|
|
539
|
-
}
|
|
540
|
-
this._remoteSdp.closeMediaSection(transceiver.mid);
|
|
541
|
-
}
|
|
542
|
-
const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
|
|
543
|
-
logger.debug('stopReceiving() | calling pc.setRemoteDescription() [offer:%o]', offer);
|
|
544
|
-
await this._pc.setRemoteDescription(offer);
|
|
545
|
-
const answer = await this._pc.createAnswer();
|
|
546
|
-
logger.debug('stopReceiving() | calling pc.setLocalDescription() [answer:%o]', answer);
|
|
547
|
-
await this._pc.setLocalDescription(answer);
|
|
548
|
-
for (const localId of localIds) {
|
|
549
|
-
this._mapMidTransceiver.delete(localId);
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
async pauseReceiving(
|
|
553
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
554
|
-
localIds) {
|
|
555
|
-
// Unimplemented.
|
|
556
|
-
}
|
|
557
|
-
async resumeReceiving(
|
|
558
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
559
|
-
localIds) {
|
|
560
|
-
// Unimplemented.
|
|
561
|
-
}
|
|
562
|
-
async getReceiverStats(localId) {
|
|
563
|
-
this.assertRecvDirection();
|
|
564
|
-
const transceiver = this._mapMidTransceiver.get(localId);
|
|
565
|
-
if (!transceiver) {
|
|
566
|
-
throw new Error('associated RTCRtpTransceiver not found');
|
|
567
|
-
}
|
|
568
|
-
return transceiver.receiver.getStats();
|
|
569
|
-
}
|
|
570
|
-
async receiveDataChannel({ sctpStreamParameters, label, protocol, }) {
|
|
571
|
-
this.assertRecvDirection();
|
|
572
|
-
const { streamId, ordered, maxPacketLifeTime, maxRetransmits, } = sctpStreamParameters;
|
|
573
|
-
const options = {
|
|
574
|
-
negotiated: true,
|
|
575
|
-
id: streamId,
|
|
576
|
-
ordered,
|
|
577
|
-
maxPacketLifeTime,
|
|
578
|
-
maxRetransmitTime: maxPacketLifeTime, // NOTE: Old spec.
|
|
579
|
-
maxRetransmits,
|
|
580
|
-
protocol,
|
|
581
|
-
};
|
|
582
|
-
logger.debug('receiveDataChannel() [options:%o]', options);
|
|
583
|
-
const dataChannel = this._pc.createDataChannel(label, options);
|
|
584
|
-
// If this is the first DataChannel we need to create the SDP offer with
|
|
585
|
-
// m=application section.
|
|
586
|
-
if (!this._hasDataChannelMediaSection) {
|
|
587
|
-
this._remoteSdp.receiveSctpAssociation();
|
|
588
|
-
const offer = { type: 'offer', sdp: this._remoteSdp.getSdp() };
|
|
589
|
-
logger.debug('receiveDataChannel() | calling pc.setRemoteDescription() [offer:%o]', offer);
|
|
590
|
-
await this._pc.setRemoteDescription(offer);
|
|
591
|
-
const answer = await this._pc.createAnswer();
|
|
592
|
-
if (!this._transportReady) {
|
|
593
|
-
const localSdpObject = sdpTransform.parse(answer.sdp);
|
|
594
|
-
await this.setupTransport({
|
|
595
|
-
localDtlsRole: this._forcedLocalDtlsRole ?? 'client',
|
|
596
|
-
localSdpObject,
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
|
-
logger.debug('receiveDataChannel() | calling pc.setRemoteDescription() [answer:%o]', answer);
|
|
600
|
-
await this._pc.setLocalDescription(answer);
|
|
601
|
-
this._hasDataChannelMediaSection = true;
|
|
602
|
-
}
|
|
603
|
-
return { dataChannel };
|
|
604
|
-
}
|
|
605
|
-
async setupTransport({ localDtlsRole, localSdpObject, }) {
|
|
606
|
-
if (!localSdpObject) {
|
|
607
|
-
localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);
|
|
608
|
-
}
|
|
609
|
-
// Get our local DTLS parameters.
|
|
610
|
-
const dtlsParameters = sdpCommonUtils.extractDtlsParameters({
|
|
611
|
-
sdpObject: localSdpObject,
|
|
612
|
-
});
|
|
613
|
-
// Set our DTLS role.
|
|
614
|
-
dtlsParameters.role = localDtlsRole;
|
|
615
|
-
// Update the remote DTLS role in the SDP.
|
|
616
|
-
this._remoteSdp.updateDtlsRole(localDtlsRole === 'client' ? 'server' : 'client');
|
|
617
|
-
// Need to tell the remote transport about our parameters.
|
|
618
|
-
await new Promise((resolve, reject) => {
|
|
619
|
-
this.safeEmit('@connect', { dtlsParameters }, resolve, reject);
|
|
620
|
-
});
|
|
621
|
-
this._transportReady = true;
|
|
622
|
-
}
|
|
623
|
-
assertSendDirection() {
|
|
624
|
-
if (this._direction !== 'send') {
|
|
625
|
-
throw new Error('method can just be called for handlers with "send" direction');
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
assertRecvDirection() {
|
|
629
|
-
if (this._direction !== 'recv') {
|
|
630
|
-
throw new Error('method can just be called for handlers with "recv" direction');
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
exports.Chrome70 = Chrome70;
|
package/lib/handlers/Edge11.d.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { type HandlerFactory, HandlerInterface, type HandlerRunOptions, type HandlerSendOptions, type HandlerSendResult, type HandlerReceiveOptions, type HandlerReceiveResult, type HandlerSendDataChannelOptions, type HandlerSendDataChannelResult, type HandlerReceiveDataChannelOptions, type HandlerReceiveDataChannelResult } from './HandlerInterface';
|
|
2
|
-
import type { IceParameters } from '../Transport';
|
|
3
|
-
import type { RtpCapabilities } from '../RtpParameters';
|
|
4
|
-
import type { SctpCapabilities } from '../SctpParameters';
|
|
5
|
-
export declare class Edge11 extends HandlerInterface {
|
|
6
|
-
private _sendingRtpParametersByKind?;
|
|
7
|
-
private _remoteIceParameters?;
|
|
8
|
-
private _remoteIceCandidates?;
|
|
9
|
-
private _remoteDtlsParameters?;
|
|
10
|
-
private _iceGatherer?;
|
|
11
|
-
private _iceTransport?;
|
|
12
|
-
private _dtlsTransport?;
|
|
13
|
-
private readonly _rtpSenders;
|
|
14
|
-
private readonly _rtpReceivers;
|
|
15
|
-
private _nextSendLocalId;
|
|
16
|
-
private _cname?;
|
|
17
|
-
private _transportReady;
|
|
18
|
-
/**
|
|
19
|
-
* Creates a factory function.
|
|
20
|
-
*/
|
|
21
|
-
static createFactory(): HandlerFactory;
|
|
22
|
-
constructor();
|
|
23
|
-
get name(): string;
|
|
24
|
-
close(): void;
|
|
25
|
-
getNativeRtpCapabilities(): Promise<RtpCapabilities>;
|
|
26
|
-
getNativeSctpCapabilities(): Promise<SctpCapabilities>;
|
|
27
|
-
run({ direction, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
28
|
-
iceParameters, iceCandidates, dtlsParameters, sctpParameters, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
29
|
-
iceServers, iceTransportPolicy, additionalSettings, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
30
|
-
proprietaryConstraints, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
31
|
-
extendedRtpCapabilities, }: HandlerRunOptions): void;
|
|
32
|
-
updateIceServers(iceServers: RTCIceServer[]): Promise<void>;
|
|
33
|
-
restartIce(iceParameters: IceParameters): Promise<void>;
|
|
34
|
-
getTransportStats(): Promise<RTCStatsReport>;
|
|
35
|
-
send({ track, encodings, codecOptions, codec }: HandlerSendOptions): Promise<HandlerSendResult>;
|
|
36
|
-
stopSending(localId: string): Promise<void>;
|
|
37
|
-
pauseSending(localId: string): Promise<void>;
|
|
38
|
-
resumeSending(localId: string): Promise<void>;
|
|
39
|
-
replaceTrack(localId: string, track: MediaStreamTrack | null): Promise<void>;
|
|
40
|
-
setMaxSpatialLayer(localId: string, spatialLayer: number): Promise<void>;
|
|
41
|
-
setRtpEncodingParameters(localId: string, params: any): Promise<void>;
|
|
42
|
-
getSenderStats(localId: string): Promise<RTCStatsReport>;
|
|
43
|
-
sendDataChannel(options: HandlerSendDataChannelOptions): Promise<HandlerSendDataChannelResult>;
|
|
44
|
-
receive(optionsList: HandlerReceiveOptions[]): Promise<HandlerReceiveResult[]>;
|
|
45
|
-
stopReceiving(localIds: string[]): Promise<void>;
|
|
46
|
-
pauseReceiving(localIds: string[]): Promise<void>;
|
|
47
|
-
resumeReceiving(localIds: string[]): Promise<void>;
|
|
48
|
-
getReceiverStats(localId: string): Promise<RTCStatsReport>;
|
|
49
|
-
receiveDataChannel(options: HandlerReceiveDataChannelOptions): Promise<HandlerReceiveDataChannelResult>;
|
|
50
|
-
private setIceGatherer;
|
|
51
|
-
private setIceTransport;
|
|
52
|
-
private setDtlsTransport;
|
|
53
|
-
private setupTransport;
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=Edge11.d.ts.map
|