werift 0.20.0 → 0.21.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/common/src/event.d.ts +45 -0
- package/lib/common/src/event.js +229 -0
- package/lib/common/src/event.js.map +1 -0
- package/lib/common/src/index.d.ts +1 -0
- package/lib/common/src/index.js +1 -0
- package/lib/common/src/index.js.map +1 -1
- package/lib/dtls/src/flight/client/flight5.js +6 -1
- package/lib/dtls/src/flight/client/flight5.js.map +1 -1
- package/lib/dtls/src/flight/server/flight2.js +5 -3
- package/lib/dtls/src/flight/server/flight2.js.map +1 -1
- package/lib/dtls/src/imports/common.d.ts +1 -0
- package/lib/dtls/src/imports/common.js +18 -0
- package/lib/dtls/src/imports/common.js.map +1 -0
- package/lib/dtls/src/index.d.ts +1 -1
- package/lib/dtls/src/index.js.map +1 -1
- package/lib/dtls/src/record/receive.js +1 -1
- package/lib/dtls/src/record/receive.js.map +1 -1
- package/lib/dtls/src/socket.d.ts +1 -1
- package/lib/dtls/src/socket.js +5 -5
- package/lib/dtls/src/socket.js.map +1 -1
- package/lib/ice/src/candidate.d.ts +3 -2
- package/lib/ice/src/candidate.js +19 -5
- package/lib/ice/src/candidate.js.map +1 -1
- package/lib/ice/src/helper.d.ts +6 -6
- package/lib/ice/src/helper.js +20 -17
- package/lib/ice/src/helper.js.map +1 -1
- package/lib/ice/src/ice.d.ts +29 -71
- package/lib/ice/src/ice.js +417 -417
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/iceBase.d.ts +109 -0
- package/lib/ice/src/iceBase.js +166 -0
- package/lib/ice/src/iceBase.js.map +1 -0
- package/lib/ice/src/imports/common.d.ts +1 -0
- package/lib/ice/src/imports/common.js +18 -0
- package/lib/ice/src/imports/common.js.map +1 -0
- package/lib/ice/src/index.d.ts +5 -0
- package/lib/ice/src/index.js +5 -0
- package/lib/ice/src/index.js.map +1 -1
- package/lib/ice/src/stun/message.d.ts +7 -0
- package/lib/ice/src/stun/message.js +20 -6
- package/lib/ice/src/stun/message.js.map +1 -1
- package/lib/ice/src/stun/protocol.d.ts +6 -6
- package/lib/ice/src/stun/protocol.js +29 -23
- package/lib/ice/src/stun/protocol.js.map +1 -1
- package/lib/ice/src/stun/transaction.js +10 -4
- package/lib/ice/src/stun/transaction.js.map +1 -1
- package/lib/ice/src/transport.d.ts +21 -4
- package/lib/ice/src/transport.js +115 -7
- package/lib/ice/src/transport.js.map +1 -1
- package/lib/ice/src/turn/protocol.d.ts +54 -37
- package/lib/ice/src/turn/protocol.js +219 -94
- package/lib/ice/src/turn/protocol.js.map +1 -1
- package/lib/ice/src/types/model.d.ts +9 -5
- package/lib/ice/src/types/model.js.map +1 -1
- package/lib/ice/src/utils.d.ts +1 -0
- package/lib/ice/src/utils.js +15 -16
- package/lib/ice/src/utils.js.map +1 -1
- package/lib/rtp/src/extra/container/mp4/container.d.ts +1 -1
- package/lib/rtp/src/extra/container/mp4/container.js +2 -5
- package/lib/rtp/src/extra/container/mp4/container.js.map +1 -1
- package/lib/rtp/src/extra/container/webm/container.d.ts +3 -1
- package/lib/rtp/src/extra/container/webm/container.js +8 -2
- package/lib/rtp/src/extra/container/webm/container.js.map +1 -1
- package/lib/rtp/src/extra/container/webm/ebml/id.d.ts +6 -0
- package/lib/rtp/src/extra/container/webm/ebml/id.js +6 -0
- package/lib/rtp/src/extra/container/webm/ebml/id.js.map +1 -1
- package/lib/rtp/src/extra/processor/depacketizer.d.ts +1 -1
- package/lib/rtp/src/extra/processor/depacketizer.js +2 -2
- package/lib/rtp/src/extra/processor/depacketizer.js.map +1 -1
- package/lib/rtp/src/extra/processor/mp4.d.ts +1 -1
- package/lib/rtp/src/extra/processor/mp4.js +2 -5
- package/lib/rtp/src/extra/processor/mp4.js.map +1 -1
- package/lib/rtp/src/extra/processor/nack.d.ts +1 -1
- package/lib/rtp/src/extra/processor/nack.js +3 -3
- package/lib/rtp/src/extra/processor/nack.js.map +1 -1
- package/lib/rtp/src/extra/processor/rtcpCallback.d.ts +1 -1
- package/lib/rtp/src/extra/processor/rtcpCallback.js +2 -5
- package/lib/rtp/src/extra/processor/rtcpCallback.js.map +1 -1
- package/lib/rtp/src/extra/processor/rtpCallback.d.ts +1 -1
- package/lib/rtp/src/extra/processor/rtpCallback.js +2 -5
- package/lib/rtp/src/extra/processor/rtpCallback.js.map +1 -1
- package/lib/rtp/src/extra/processor/webm.d.ts +12 -17
- package/lib/rtp/src/extra/processor/webm.js +2 -5
- package/lib/rtp/src/extra/processor/webm.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmCallback.d.ts +1 -10
- package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
- package/lib/rtp/src/imports/common.d.ts +1 -0
- package/lib/rtp/src/imports/common.js +18 -0
- package/lib/rtp/src/imports/common.js.map +1 -0
- package/lib/rtp/src/rtp/headerExtension.d.ts +45 -3
- package/lib/rtp/src/rtp/headerExtension.js +15 -0
- package/lib/rtp/src/rtp/headerExtension.js.map +1 -1
- package/lib/sctp/src/helper.js +2 -5
- package/lib/sctp/src/helper.js.map +1 -1
- package/lib/sctp/src/imports/common.d.ts +1 -0
- package/lib/sctp/src/imports/common.js +18 -0
- package/lib/sctp/src/imports/common.js.map +1 -0
- package/lib/sctp/src/index.d.ts +1 -1
- package/lib/sctp/src/index.js.map +1 -1
- package/lib/sctp/src/sctp.d.ts +1 -1
- package/lib/sctp/src/sctp.js +3 -3
- package/lib/sctp/src/sctp.js.map +1 -1
- package/lib/webrtc/src/const.d.ts +2 -2
- package/lib/webrtc/src/const.js.map +1 -1
- package/lib/webrtc/src/dataChannel.d.ts +1 -1
- package/lib/webrtc/src/dataChannel.js +5 -5
- package/lib/webrtc/src/dataChannel.js.map +1 -1
- package/lib/webrtc/src/imports/common.d.ts +1 -0
- package/lib/webrtc/src/imports/common.js +18 -0
- package/lib/webrtc/src/imports/common.js.map +1 -0
- package/lib/webrtc/src/media/extension/rtpExtension.d.ts +1 -0
- package/lib/webrtc/src/media/extension/rtpExtension.js +6 -0
- package/lib/webrtc/src/media/extension/rtpExtension.js.map +1 -1
- package/lib/webrtc/src/media/receiver/nack.d.ts +1 -1
- package/lib/webrtc/src/media/receiver/nack.js +2 -2
- package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
- package/lib/webrtc/src/media/router.d.ts +0 -3
- package/lib/webrtc/src/media/router.js.map +1 -1
- package/lib/webrtc/src/media/rtpReceiver.d.ts +3 -4
- package/lib/webrtc/src/media/rtpReceiver.js +4 -7
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpSender.d.ts +1 -1
- package/lib/webrtc/src/media/rtpSender.js +5 -5
- package/lib/webrtc/src/media/rtpSender.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.js +2 -5
- package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
- package/lib/webrtc/src/media/sender/senderBWE.d.ts +1 -1
- package/lib/webrtc/src/media/sender/senderBWE.js +4 -7
- package/lib/webrtc/src/media/sender/senderBWE.js.map +1 -1
- package/lib/webrtc/src/media/track.d.ts +3 -3
- package/lib/webrtc/src/media/track.js +4 -7
- package/lib/webrtc/src/media/track.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/index.d.ts +3 -1
- package/lib/webrtc/src/nonstandard/recorder/index.js +2 -5
- package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/index.d.ts +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.d.ts +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +3 -2
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +15 -8
- package/lib/webrtc/src/peerConnection.js +107 -93
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/sdp.js +15 -3
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/transport/dtls.d.ts +6 -6
- package/lib/webrtc/src/transport/dtls.js +19 -26
- package/lib/webrtc/src/transport/dtls.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +22 -11
- package/lib/webrtc/src/transport/ice.js +106 -38
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/lib/webrtc/src/transport/sctp.d.ts +1 -1
- package/lib/webrtc/src/transport/sctp.js +2 -2
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/package.json +1 -1
- package/src/const.ts +2 -2
- package/src/dataChannel.ts +1 -1
- package/src/imports/common.ts +1 -0
- package/src/media/extension/rtpExtension.ts +6 -0
- package/src/media/receiver/nack.ts +1 -1
- package/src/media/router.ts +2 -3
- package/src/media/rtpReceiver.ts +5 -4
- package/src/media/rtpSender.ts +1 -1
- package/src/media/rtpTransceiver.ts +1 -1
- package/src/media/sender/senderBWE.ts +1 -1
- package/src/media/track.ts +9 -4
- package/src/nonstandard/recorder/index.ts +4 -1
- package/src/nonstandard/recorder/writer/index.ts +1 -1
- package/src/nonstandard/recorder/writer/webm.ts +48 -44
- package/src/peerConnection.ts +122 -89
- package/src/sdp.ts +16 -3
- package/src/transport/dtls.ts +22 -14
- package/src/transport/ice.ts +83 -31
- package/src/transport/sctp.ts +1 -1
|
@@ -34,8 +34,8 @@ exports.allocateMid = allocateMid;
|
|
|
34
34
|
const debug_1 = __importDefault(require("debug"));
|
|
35
35
|
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
36
36
|
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
37
|
-
const rx_mini_1 = __importDefault(require("rx.mini"));
|
|
38
37
|
const uuid = __importStar(require("uuid"));
|
|
38
|
+
const common_1 = require("./imports/common");
|
|
39
39
|
const _1 = require(".");
|
|
40
40
|
const _2 = require(".");
|
|
41
41
|
const const_1 = require("./const");
|
|
@@ -78,6 +78,9 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
78
78
|
get extIdUriMap() {
|
|
79
79
|
return this.router.extIdUriMap;
|
|
80
80
|
}
|
|
81
|
+
get iceGeneration() {
|
|
82
|
+
return this.iceTransports[0].connection.generation;
|
|
83
|
+
}
|
|
81
84
|
constructor(config = {}) {
|
|
82
85
|
super();
|
|
83
86
|
Object.defineProperty(this, "cname", {
|
|
@@ -92,12 +95,6 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
92
95
|
writable: true,
|
|
93
96
|
value: void 0
|
|
94
97
|
});
|
|
95
|
-
Object.defineProperty(this, "transportEstablished", {
|
|
96
|
-
enumerable: true,
|
|
97
|
-
configurable: true,
|
|
98
|
-
writable: true,
|
|
99
|
-
value: false
|
|
100
|
-
});
|
|
101
98
|
Object.defineProperty(this, "config", {
|
|
102
99
|
enumerable: true,
|
|
103
100
|
configurable: true,
|
|
@@ -140,71 +137,71 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
140
137
|
writable: true,
|
|
141
138
|
value: []
|
|
142
139
|
});
|
|
143
|
-
Object.defineProperty(this, "
|
|
140
|
+
Object.defineProperty(this, "needRestart", {
|
|
144
141
|
enumerable: true,
|
|
145
142
|
configurable: true,
|
|
146
143
|
writable: true,
|
|
147
|
-
value:
|
|
144
|
+
value: false
|
|
148
145
|
});
|
|
149
146
|
Object.defineProperty(this, "iceGatheringStateChange", {
|
|
150
147
|
enumerable: true,
|
|
151
148
|
configurable: true,
|
|
152
149
|
writable: true,
|
|
153
|
-
value: new
|
|
150
|
+
value: new common_1.Event()
|
|
154
151
|
});
|
|
155
152
|
Object.defineProperty(this, "iceConnectionStateChange", {
|
|
156
153
|
enumerable: true,
|
|
157
154
|
configurable: true,
|
|
158
155
|
writable: true,
|
|
159
|
-
value: new
|
|
156
|
+
value: new common_1.Event()
|
|
160
157
|
});
|
|
161
158
|
Object.defineProperty(this, "signalingStateChange", {
|
|
162
159
|
enumerable: true,
|
|
163
160
|
configurable: true,
|
|
164
161
|
writable: true,
|
|
165
|
-
value: new
|
|
162
|
+
value: new common_1.Event()
|
|
166
163
|
});
|
|
167
164
|
Object.defineProperty(this, "connectionStateChange", {
|
|
168
165
|
enumerable: true,
|
|
169
166
|
configurable: true,
|
|
170
167
|
writable: true,
|
|
171
|
-
value: new
|
|
168
|
+
value: new common_1.Event()
|
|
172
169
|
});
|
|
173
170
|
Object.defineProperty(this, "onDataChannel", {
|
|
174
171
|
enumerable: true,
|
|
175
172
|
configurable: true,
|
|
176
173
|
writable: true,
|
|
177
|
-
value: new
|
|
174
|
+
value: new common_1.Event()
|
|
178
175
|
});
|
|
179
176
|
Object.defineProperty(this, "onRemoteTransceiverAdded", {
|
|
180
177
|
enumerable: true,
|
|
181
178
|
configurable: true,
|
|
182
179
|
writable: true,
|
|
183
|
-
value: new
|
|
180
|
+
value: new common_1.Event()
|
|
184
181
|
});
|
|
185
182
|
Object.defineProperty(this, "onTransceiverAdded", {
|
|
186
183
|
enumerable: true,
|
|
187
184
|
configurable: true,
|
|
188
185
|
writable: true,
|
|
189
|
-
value: new
|
|
186
|
+
value: new common_1.Event()
|
|
190
187
|
});
|
|
191
188
|
Object.defineProperty(this, "onIceCandidate", {
|
|
192
189
|
enumerable: true,
|
|
193
190
|
configurable: true,
|
|
194
191
|
writable: true,
|
|
195
|
-
value: new
|
|
192
|
+
value: new common_1.Event()
|
|
196
193
|
});
|
|
197
194
|
Object.defineProperty(this, "onNegotiationneeded", {
|
|
198
195
|
enumerable: true,
|
|
199
196
|
configurable: true,
|
|
200
197
|
writable: true,
|
|
201
|
-
value: new
|
|
198
|
+
value: new common_1.Event()
|
|
202
199
|
});
|
|
203
200
|
Object.defineProperty(this, "onTrack", {
|
|
204
201
|
enumerable: true,
|
|
205
202
|
configurable: true,
|
|
206
203
|
writable: true,
|
|
207
|
-
value: new
|
|
204
|
+
value: new common_1.Event()
|
|
208
205
|
});
|
|
209
206
|
Object.defineProperty(this, "ondatachannel", {
|
|
210
207
|
enumerable: true,
|
|
@@ -248,11 +245,11 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
248
245
|
writable: true,
|
|
249
246
|
value: new router_1.RtpRouter()
|
|
250
247
|
});
|
|
251
|
-
Object.defineProperty(this, "
|
|
248
|
+
Object.defineProperty(this, "certificate", {
|
|
252
249
|
enumerable: true,
|
|
253
250
|
configurable: true,
|
|
254
251
|
writable: true,
|
|
255
|
-
value:
|
|
252
|
+
value: void 0
|
|
256
253
|
});
|
|
257
254
|
Object.defineProperty(this, "sctpRemotePort", {
|
|
258
255
|
enumerable: true,
|
|
@@ -308,8 +305,9 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
308
305
|
writable: true,
|
|
309
306
|
value: async () => {
|
|
310
307
|
this.shouldNegotiationneeded = true;
|
|
311
|
-
if (this.negotiationneeded || this.signalingState !== "stable")
|
|
308
|
+
if (this.negotiationneeded || this.signalingState !== "stable") {
|
|
312
309
|
return;
|
|
310
|
+
}
|
|
313
311
|
this.shouldNegotiationneeded = false;
|
|
314
312
|
setImmediate(() => {
|
|
315
313
|
this.negotiationneeded = true;
|
|
@@ -319,6 +317,19 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
319
317
|
});
|
|
320
318
|
}
|
|
321
319
|
});
|
|
320
|
+
this.setConfiguration(config);
|
|
321
|
+
this.iceConnectionStateChange.subscribe((state) => {
|
|
322
|
+
switch (state) {
|
|
323
|
+
case "disconnected":
|
|
324
|
+
this.setConnectionState("disconnected");
|
|
325
|
+
break;
|
|
326
|
+
case "closed":
|
|
327
|
+
this.close();
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
setConfiguration(config) {
|
|
322
333
|
(0, _1.deepMerge)(this.config, config);
|
|
323
334
|
if (this.config.icePortRange) {
|
|
324
335
|
const [min, max] = this.config.icePortRange;
|
|
@@ -361,19 +372,9 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
361
372
|
if (this.config.dtls) {
|
|
362
373
|
const { keys } = this.config.dtls;
|
|
363
374
|
if (keys) {
|
|
364
|
-
this.
|
|
375
|
+
this.certificate = new dtls_1.RTCCertificate(keys.keyPem, keys.certPem, keys.signatureHash);
|
|
365
376
|
}
|
|
366
377
|
}
|
|
367
|
-
this.iceConnectionStateChange.subscribe((state) => {
|
|
368
|
-
switch (state) {
|
|
369
|
-
case "disconnected":
|
|
370
|
-
this.setConnectionState("disconnected");
|
|
371
|
-
break;
|
|
372
|
-
case "closed":
|
|
373
|
-
this.close();
|
|
374
|
-
break;
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
378
|
}
|
|
378
379
|
get localDescription() {
|
|
379
380
|
if (!this._localDescription) {
|
|
@@ -404,7 +405,13 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
404
405
|
getConfiguration() {
|
|
405
406
|
return this.config;
|
|
406
407
|
}
|
|
407
|
-
async createOffer() {
|
|
408
|
+
async createOffer({ iceRestart } = {}) {
|
|
409
|
+
if (iceRestart || this.needRestart) {
|
|
410
|
+
this.needRestart = false;
|
|
411
|
+
for (const t of this.iceTransports) {
|
|
412
|
+
t.restart();
|
|
413
|
+
}
|
|
414
|
+
}
|
|
408
415
|
await this.ensureCerts();
|
|
409
416
|
const description = this.buildOfferSdp();
|
|
410
417
|
return description.toJSON();
|
|
@@ -584,11 +591,13 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
584
591
|
additionalHostAddresses: this.config.iceAdditionalHostAddresses,
|
|
585
592
|
filterStunResponse: this.config.iceFilterStunResponse,
|
|
586
593
|
filterCandidatePair: this.config.iceFilterCandidatePair,
|
|
594
|
+
localPasswordPrefix: this.config.icePasswordPrefix,
|
|
587
595
|
useIpv4: this.config.iceUseIpv4,
|
|
588
596
|
useIpv6: this.config.iceUseIpv6,
|
|
597
|
+
turnTransport: this.config.forceTurnTCP === true ? "tcp" : "udp",
|
|
589
598
|
});
|
|
590
599
|
if (existing) {
|
|
591
|
-
iceGatherer.connection.
|
|
600
|
+
iceGatherer.connection.localUsername = existing.connection.localUsername;
|
|
592
601
|
iceGatherer.connection.localPassword = existing.connection.localPassword;
|
|
593
602
|
}
|
|
594
603
|
iceGatherer.onGatheringStateChange.subscribe(() => {
|
|
@@ -599,7 +608,10 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
599
608
|
iceTransport.onStateChange.subscribe(() => {
|
|
600
609
|
this.updateIceConnectionState();
|
|
601
610
|
});
|
|
602
|
-
iceTransport.
|
|
611
|
+
iceTransport.onNegotiationNeeded.subscribe(() => {
|
|
612
|
+
this.needNegotiation();
|
|
613
|
+
});
|
|
614
|
+
iceTransport.onIceCandidate.subscribe((candidate) => {
|
|
603
615
|
if (!this.localDescription) {
|
|
604
616
|
log("localDescription not found when ice candidate was gathered");
|
|
605
617
|
return;
|
|
@@ -632,22 +644,13 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
632
644
|
}
|
|
633
645
|
}
|
|
634
646
|
candidate.foundation = "candidate:" + candidate.foundation;
|
|
635
|
-
// prevent ice candidates that have already been sent from being being resent
|
|
636
|
-
// when the connection is renegotiated during a later setLocalDescription call.
|
|
637
|
-
if (candidate.sdpMid) {
|
|
638
|
-
const candidateKey = `${candidate.foundation}:${candidate.sdpMid}`;
|
|
639
|
-
if (this.candidatesSent.has(candidateKey)) {
|
|
640
|
-
return;
|
|
641
|
-
}
|
|
642
|
-
this.candidatesSent.add(candidateKey);
|
|
643
|
-
}
|
|
644
647
|
this.onIceCandidate.execute(candidate.toJSON());
|
|
645
648
|
if (this.onicecandidate) {
|
|
646
649
|
this.onicecandidate({ candidate: candidate.toJSON() });
|
|
647
650
|
}
|
|
648
651
|
this.emit("icecandidate", { candidate });
|
|
649
|
-
};
|
|
650
|
-
const dtlsTransport = new dtls_1.RTCDtlsTransport(this.config, iceTransport, this.router, this.
|
|
652
|
+
});
|
|
653
|
+
const dtlsTransport = new dtls_1.RTCDtlsTransport(this.config, iceTransport, this.router, this.certificate, srtpProfiles);
|
|
651
654
|
return dtlsTransport;
|
|
652
655
|
}
|
|
653
656
|
createSctpTransport() {
|
|
@@ -682,7 +685,7 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
682
685
|
this.setSignalingState("stable");
|
|
683
686
|
}
|
|
684
687
|
// # assign MID
|
|
685
|
-
|
|
688
|
+
for (const [i, media] of (0, helper_1.enumerate)(description.media)) {
|
|
686
689
|
const mid = media.rtp.muxId;
|
|
687
690
|
this.seenMid.add(mid);
|
|
688
691
|
if (["audio", "video"].includes(media.kind)) {
|
|
@@ -694,8 +697,9 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
694
697
|
if (media.kind === "application" && this.sctpTransport) {
|
|
695
698
|
this.sctpTransport.mid = mid;
|
|
696
699
|
}
|
|
697
|
-
}
|
|
698
|
-
|
|
700
|
+
}
|
|
701
|
+
// setup ice,dtls role
|
|
702
|
+
for (const dtlsTransport of this.dtlsTransports) {
|
|
699
703
|
const iceTransport = dtlsTransport.iceTransport;
|
|
700
704
|
// # set ICE role
|
|
701
705
|
if (description.type === "offer") {
|
|
@@ -717,26 +721,19 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
717
721
|
dtlsTransport.role = role;
|
|
718
722
|
}
|
|
719
723
|
}
|
|
720
|
-
}
|
|
721
|
-
this.dtlsTransports.forEach((d) => setupRole(d));
|
|
724
|
+
}
|
|
722
725
|
// # configure direction
|
|
723
726
|
if (["answer", "pranswer"].includes(description.type)) {
|
|
724
|
-
this.transceivers
|
|
727
|
+
for (const t of this.transceivers) {
|
|
725
728
|
const direction = (0, utils_1.andDirection)(t.direction, t.offerDirection);
|
|
726
729
|
t.setCurrentDirection(direction);
|
|
727
|
-
}
|
|
730
|
+
}
|
|
728
731
|
}
|
|
729
732
|
// for trickle ice
|
|
730
733
|
this.setLocal(description);
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
// no need to gather ice candidates on an existing bundled connection
|
|
735
|
-
await connected.iceGather.gather();
|
|
736
|
-
}
|
|
737
|
-
else {
|
|
738
|
-
await Promise.allSettled(this.iceTransports.map((iceTransport) => iceTransport.iceGather.gather()));
|
|
739
|
-
}
|
|
734
|
+
await this.gatherCandidates().catch((e) => {
|
|
735
|
+
log("gatherCandidates failed", e);
|
|
736
|
+
});
|
|
740
737
|
// connect transports
|
|
741
738
|
if (description.type === "answer") {
|
|
742
739
|
this.connect().catch((err) => {
|
|
@@ -750,6 +747,16 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
750
747
|
}
|
|
751
748
|
return description;
|
|
752
749
|
}
|
|
750
|
+
async gatherCandidates() {
|
|
751
|
+
// # gather candidates
|
|
752
|
+
const connected = this.iceTransports.find((transport) => transport.state === "connected");
|
|
753
|
+
if (this.remoteIsBundled && connected) {
|
|
754
|
+
// no need to gather ice candidates on an existing bundled connection
|
|
755
|
+
}
|
|
756
|
+
else {
|
|
757
|
+
await Promise.allSettled(this.iceTransports.map((iceTransport) => iceTransport.gather()));
|
|
758
|
+
}
|
|
759
|
+
}
|
|
753
760
|
setLocal(description) {
|
|
754
761
|
description.media
|
|
755
762
|
.filter((m) => ["audio", "video"].includes(m.kind))
|
|
@@ -811,17 +818,20 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
811
818
|
}
|
|
812
819
|
}
|
|
813
820
|
async connect() {
|
|
814
|
-
if (this.transportEstablished) {
|
|
815
|
-
return;
|
|
816
|
-
}
|
|
817
821
|
log("start connect");
|
|
818
|
-
this.setConnectionState("connecting");
|
|
819
822
|
await Promise.allSettled(this.dtlsTransports.map(async (dtlsTransport) => {
|
|
820
823
|
const { iceTransport } = dtlsTransport;
|
|
824
|
+
if (iceTransport.state === "connected") {
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
this.setConnectionState("connecting");
|
|
821
828
|
await iceTransport.start().catch((err) => {
|
|
822
829
|
log("iceTransport.start failed", err);
|
|
823
830
|
throw err;
|
|
824
831
|
});
|
|
832
|
+
if (dtlsTransport.state === "connected") {
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
825
835
|
await dtlsTransport.start().catch((err) => {
|
|
826
836
|
log("dtlsTransport.start failed", err);
|
|
827
837
|
throw err;
|
|
@@ -834,7 +844,6 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
834
844
|
log("sctp connected");
|
|
835
845
|
}
|
|
836
846
|
}));
|
|
837
|
-
this.transportEstablished = true;
|
|
838
847
|
this.setConnectionState("connected");
|
|
839
848
|
}
|
|
840
849
|
getLocalRtpParams(transceiver) {
|
|
@@ -880,6 +889,10 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
880
889
|
const bundle = remoteSdp.group.find((g) => g.semantic === "BUNDLE" && this.config.bundlePolicy !== "disable");
|
|
881
890
|
return bundle;
|
|
882
891
|
}
|
|
892
|
+
restartIce() {
|
|
893
|
+
this.needRestart = true;
|
|
894
|
+
this.needNegotiation();
|
|
895
|
+
}
|
|
883
896
|
async setRemoteDescription(sessionDescription) {
|
|
884
897
|
if (!sessionDescription.sdp ||
|
|
885
898
|
!sessionDescription.type ||
|
|
@@ -954,15 +967,18 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
954
967
|
throw new Error("invalid media kind");
|
|
955
968
|
}
|
|
956
969
|
const iceTransport = dtlsTransport.iceTransport;
|
|
957
|
-
if (remoteMedia.iceParams
|
|
958
|
-
|
|
959
|
-
|
|
970
|
+
if (remoteMedia.iceParams) {
|
|
971
|
+
const renomination = !!remoteSdp.media.find((m) => m.direction === "inactive");
|
|
972
|
+
iceTransport.setRemoteParams(remoteMedia.iceParams, renomination);
|
|
960
973
|
// One agent full, one lite: The full agent MUST take the controlling role, and the lite agent MUST take the controlled role
|
|
961
974
|
// RFC 8445 S6.1.1
|
|
962
975
|
if (remoteMedia.iceParams?.iceLite) {
|
|
963
976
|
iceTransport.connection.iceControlling = true;
|
|
964
977
|
}
|
|
965
978
|
}
|
|
979
|
+
if (remoteMedia.dtlsParams) {
|
|
980
|
+
dtlsTransport.setRemoteParams(remoteMedia.dtlsParams);
|
|
981
|
+
}
|
|
966
982
|
// # add ICE candidates
|
|
967
983
|
remoteMedia.iceCandidates.forEach(iceTransport.addRemoteCandidate);
|
|
968
984
|
if (remoteMedia.iceCandidatesComplete) {
|
|
@@ -1015,14 +1031,16 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
1015
1031
|
transceiver.codecs = remoteMedia.rtp.codecs.filter((remoteCodec) => {
|
|
1016
1032
|
const localCodecs = this.config.codecs[remoteMedia.kind] || [];
|
|
1017
1033
|
const existCodec = (0, exports.findCodecByMimeType)(localCodecs, remoteCodec);
|
|
1018
|
-
if (!existCodec)
|
|
1034
|
+
if (!existCodec) {
|
|
1019
1035
|
return false;
|
|
1036
|
+
}
|
|
1020
1037
|
if (existCodec?.name.toLowerCase() === "rtx") {
|
|
1021
1038
|
const params = (0, _2.codecParametersFromString)(existCodec.parameters ?? "");
|
|
1022
1039
|
const pt = params["apt"];
|
|
1023
1040
|
const origin = remoteMedia.rtp.codecs.find((c) => c.payloadType === pt);
|
|
1024
|
-
if (!origin)
|
|
1041
|
+
if (!origin) {
|
|
1025
1042
|
return false;
|
|
1043
|
+
}
|
|
1026
1044
|
return !!(0, exports.findCodecByMimeType)(localCodecs, origin);
|
|
1027
1045
|
}
|
|
1028
1046
|
return true;
|
|
@@ -1221,17 +1239,11 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
1221
1239
|
}
|
|
1222
1240
|
}
|
|
1223
1241
|
async ensureCerts() {
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
this.certificates.push(localCertificate);
|
|
1228
|
-
}
|
|
1229
|
-
else {
|
|
1230
|
-
dtlsTransport.localCertificate = this.certificates[0];
|
|
1231
|
-
}
|
|
1232
|
-
};
|
|
1242
|
+
if (!this.certificate) {
|
|
1243
|
+
this.certificate = await dtls_1.RTCDtlsTransport.SetupCertificate();
|
|
1244
|
+
}
|
|
1233
1245
|
for (const dtlsTransport of this.dtlsTransports) {
|
|
1234
|
-
|
|
1246
|
+
dtlsTransport.localCertificate = this.certificate;
|
|
1235
1247
|
}
|
|
1236
1248
|
}
|
|
1237
1249
|
async createAnswer() {
|
|
@@ -1284,11 +1296,11 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
1284
1296
|
});
|
|
1285
1297
|
if (this.config.bundlePolicy !== "disable") {
|
|
1286
1298
|
const bundle = new sdp_1.GroupDescription("BUNDLE", []);
|
|
1287
|
-
description.media
|
|
1299
|
+
for (const media of description.media) {
|
|
1288
1300
|
if (media.direction !== "inactive") {
|
|
1289
1301
|
bundle.items.push(media.rtp.muxId);
|
|
1290
1302
|
}
|
|
1291
|
-
}
|
|
1303
|
+
}
|
|
1292
1304
|
description.group.push(bundle);
|
|
1293
1305
|
}
|
|
1294
1306
|
return description;
|
|
@@ -1322,8 +1334,8 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
1322
1334
|
updateIceGatheringState() {
|
|
1323
1335
|
const all = this.iceTransports;
|
|
1324
1336
|
function allMatch(...state) {
|
|
1325
|
-
return (all.filter((check) => state.includes(check.
|
|
1326
|
-
|
|
1337
|
+
return (all.filter((check) => state.includes(check.gatheringState)).length ===
|
|
1338
|
+
all.length);
|
|
1327
1339
|
}
|
|
1328
1340
|
let newState;
|
|
1329
1341
|
if (all.length && allMatch("complete")) {
|
|
@@ -1332,7 +1344,7 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
1332
1344
|
else if (!all.length || allMatch("new", "complete")) {
|
|
1333
1345
|
newState = "new";
|
|
1334
1346
|
}
|
|
1335
|
-
else if (all.map((check) => check.
|
|
1347
|
+
else if (all.map((check) => check.gatheringState).includes("gathering")) {
|
|
1336
1348
|
newState = "gathering";
|
|
1337
1349
|
}
|
|
1338
1350
|
else {
|
|
@@ -1397,8 +1409,9 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
1397
1409
|
log("connectionStateChange", state);
|
|
1398
1410
|
this.connectionState = state;
|
|
1399
1411
|
this.connectionStateChange.execute(state);
|
|
1400
|
-
if (this.onconnectionstatechange)
|
|
1412
|
+
if (this.onconnectionstatechange) {
|
|
1401
1413
|
this.onconnectionstatechange();
|
|
1414
|
+
}
|
|
1402
1415
|
this.emit("connectionstatechange");
|
|
1403
1416
|
}
|
|
1404
1417
|
dispose() {
|
|
@@ -1450,10 +1463,9 @@ function createMediaDescriptionForSctp(sctp) {
|
|
|
1450
1463
|
}
|
|
1451
1464
|
function addTransportDescription(media, dtlsTransport) {
|
|
1452
1465
|
const iceTransport = dtlsTransport.iceTransport;
|
|
1453
|
-
|
|
1454
|
-
media.
|
|
1455
|
-
media.
|
|
1456
|
-
media.iceParams = iceGatherer.localParameters;
|
|
1466
|
+
media.iceCandidates = iceTransport.localCandidates;
|
|
1467
|
+
media.iceCandidatesComplete = iceTransport.gatheringState === "complete";
|
|
1468
|
+
media.iceParams = iceTransport.localParameters;
|
|
1457
1469
|
media.iceOptions = "trickle";
|
|
1458
1470
|
media.host = const_1.DISCARD_HOST;
|
|
1459
1471
|
media.port = const_1.DISCARD_PORT;
|
|
@@ -1521,9 +1533,11 @@ exports.defaultPeerConfig = {
|
|
|
1521
1533
|
iceUseIpv6: true,
|
|
1522
1534
|
iceFilterStunResponse: undefined,
|
|
1523
1535
|
iceFilterCandidatePair: undefined,
|
|
1536
|
+
icePasswordPrefix: undefined,
|
|
1524
1537
|
dtls: {},
|
|
1525
1538
|
bundlePolicy: "max-compat",
|
|
1526
1539
|
debug: {},
|
|
1527
1540
|
midSuffix: false,
|
|
1541
|
+
forceTurnTCP: false,
|
|
1528
1542
|
};
|
|
1529
1543
|
//# sourceMappingURL=peerConnection.js.map
|