werift 0.15.3 → 0.15.4
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/ice/src/ice.js +4 -7
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/webrtc/src/media/rtpReceiver.js +1 -1
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +3 -1
- package/lib/webrtc/src/media/rtpTransceiver.js +7 -1
- package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +5 -2
- package/lib/webrtc/src/peerConnection.js +86 -30
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/sdp.d.ts +0 -2
- package/lib/webrtc/src/sdp.js +0 -7
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +6 -0
- package/lib/webrtc/src/transport/ice.js +9 -0
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/lib/webrtc/src/transport/sctp.d.ts +2 -1
- package/lib/webrtc/src/transport/sctp.js +1 -1
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/package.json +1 -1
- package/src/media/rtpReceiver.ts +1 -1
- package/src/media/rtpTransceiver.ts +7 -1
- package/src/peerConnection.ts +102 -45
- package/src/sdp.ts +0 -8
- package/src/transport/ice.ts +10 -0
- package/src/transport/sctp.ts +2 -1
|
@@ -194,10 +194,18 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
194
194
|
}
|
|
195
195
|
async createOffer() {
|
|
196
196
|
await this.ensureCerts();
|
|
197
|
+
const description = this.buildOfferSdp();
|
|
198
|
+
return description.toJSON();
|
|
199
|
+
}
|
|
200
|
+
buildOfferSdp() {
|
|
197
201
|
this.transceivers.forEach((transceiver) => {
|
|
198
|
-
transceiver.codecs
|
|
199
|
-
|
|
200
|
-
|
|
202
|
+
if (transceiver.codecs.length === 0) {
|
|
203
|
+
transceiver.codecs = this.configuration.codecs[transceiver.kind];
|
|
204
|
+
}
|
|
205
|
+
if (transceiver.headerExtensions.length === 0) {
|
|
206
|
+
transceiver.headerExtensions =
|
|
207
|
+
this.configuration.headerExtensions[transceiver.kind];
|
|
208
|
+
}
|
|
201
209
|
});
|
|
202
210
|
const description = new sdp_1.SessionDescription();
|
|
203
211
|
(0, sdp_1.addSDPHeader)("offer", description);
|
|
@@ -212,16 +220,19 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
212
220
|
return;
|
|
213
221
|
}
|
|
214
222
|
if (m.kind === "application") {
|
|
215
|
-
|
|
223
|
+
if (!this.sctpTransport) {
|
|
224
|
+
throw new Error("sctpTransport not found");
|
|
225
|
+
}
|
|
226
|
+
this.sctpTransport.mLineIndex = i;
|
|
227
|
+
description.media.push(createMediaDescriptionForSctp(this.sctpTransport));
|
|
216
228
|
}
|
|
217
229
|
else {
|
|
218
230
|
const transceiver = this.getTransceiverByMid(mid);
|
|
219
231
|
if (!transceiver) {
|
|
220
|
-
|
|
221
|
-
return;
|
|
232
|
+
throw new Error("transceiver not found");
|
|
222
233
|
}
|
|
223
234
|
transceiver.mLineIndex = i;
|
|
224
|
-
description.media.push(createMediaDescriptionForTransceiver(transceiver, this.cname, transceiver.direction
|
|
235
|
+
description.media.push(createMediaDescriptionForTransceiver(transceiver, this.cname, transceiver.direction));
|
|
225
236
|
}
|
|
226
237
|
});
|
|
227
238
|
// # handle new transceivers / sctp
|
|
@@ -229,11 +240,18 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
229
240
|
.filter((t) => !description.media.find((m) => m.rtp.muxId === t.mid))
|
|
230
241
|
.forEach((transceiver) => {
|
|
231
242
|
transceiver.mLineIndex = description.media.length;
|
|
232
|
-
|
|
243
|
+
if (transceiver.mid == undefined) {
|
|
244
|
+
transceiver.mid = allocateMid(this.seenMid) + "_srtp";
|
|
245
|
+
}
|
|
246
|
+
description.media.push(createMediaDescriptionForTransceiver(transceiver, this.cname, transceiver.direction));
|
|
233
247
|
});
|
|
234
248
|
if (this.sctpTransport &&
|
|
235
|
-
!description.media.find((m) =>
|
|
236
|
-
|
|
249
|
+
!description.media.find((m) => m.kind === "application")) {
|
|
250
|
+
this.sctpTransport.mLineIndex = description.media.length;
|
|
251
|
+
if (this.sctpTransport.mid == undefined) {
|
|
252
|
+
this.sctpTransport.mid = allocateMid(this.seenMid) + "_sctp";
|
|
253
|
+
}
|
|
254
|
+
description.media.push(createMediaDescriptionForSctp(this.sctpTransport));
|
|
237
255
|
}
|
|
238
256
|
if (this.configuration.bundlePolicy !== "disable") {
|
|
239
257
|
const mids = description.media
|
|
@@ -242,7 +260,7 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
242
260
|
const bundle = new sdp_1.GroupDescription("BUNDLE", mids);
|
|
243
261
|
description.group.push(bundle);
|
|
244
262
|
}
|
|
245
|
-
return description
|
|
263
|
+
return description;
|
|
246
264
|
}
|
|
247
265
|
createDataChannel(label, options = {}) {
|
|
248
266
|
const base = {
|
|
@@ -321,14 +339,15 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
321
339
|
iceTransport.iceGather.onIceCandidate = (candidate) => {
|
|
322
340
|
if (!this.localDescription)
|
|
323
341
|
return;
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
342
|
+
const transceiver = this.transceivers.find((t) => t.dtlsTransport.iceTransport.id === iceTransport.id);
|
|
343
|
+
if (transceiver) {
|
|
344
|
+
candidate.sdpMLineIndex = transceiver.mLineIndex;
|
|
345
|
+
candidate.sdpMid = transceiver.mid;
|
|
346
|
+
}
|
|
347
|
+
if (this.sctpTransport?.dtlsTransport.iceTransport.id === iceTransport.id) {
|
|
348
|
+
candidate.sdpMLineIndex = this.sctpTransport.mLineIndex;
|
|
349
|
+
candidate.sdpMid = this.sctpTransport.mid;
|
|
329
350
|
}
|
|
330
|
-
candidate.sdpMLineIndex = 0;
|
|
331
|
-
candidate.sdpMid = media.rtp.muxId;
|
|
332
351
|
candidate.foundation = "candidate:" + candidate.foundation;
|
|
333
352
|
this.onIceCandidate.execute(candidate.toJSON());
|
|
334
353
|
if (this.onicecandidate)
|
|
@@ -417,9 +436,7 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
417
436
|
// for trickle ice
|
|
418
437
|
this.setLocal(description);
|
|
419
438
|
// # gather candidates
|
|
420
|
-
|
|
421
|
-
await iceTransport.iceGather.gather();
|
|
422
|
-
}
|
|
439
|
+
await Promise.all(this.iceTransports.map((iceTransport) => iceTransport.iceGather.gather()));
|
|
423
440
|
description.media
|
|
424
441
|
.filter((m) => ["audio", "video"].includes(m.kind))
|
|
425
442
|
.forEach((m, i) => {
|
|
@@ -452,11 +469,47 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
452
469
|
this.pendingLocalDescription = description;
|
|
453
470
|
}
|
|
454
471
|
}
|
|
472
|
+
getTransportByMid(mid) {
|
|
473
|
+
let iceTransport;
|
|
474
|
+
const transceiver = this.transceivers.find((t) => t.mid === mid);
|
|
475
|
+
if (transceiver) {
|
|
476
|
+
iceTransport = transceiver.dtlsTransport.iceTransport;
|
|
477
|
+
}
|
|
478
|
+
else if (!iceTransport && this.sctpTransport?.mid === mid) {
|
|
479
|
+
iceTransport = this.sctpTransport?.dtlsTransport.iceTransport;
|
|
480
|
+
}
|
|
481
|
+
return iceTransport;
|
|
482
|
+
}
|
|
483
|
+
getTransportByMLineIndex(index) {
|
|
484
|
+
const sdp = this.buildOfferSdp();
|
|
485
|
+
const media = sdp.media[index];
|
|
486
|
+
if (!media) {
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
const transport = this.getTransportByMid(media.rtp.muxId);
|
|
490
|
+
return transport;
|
|
491
|
+
}
|
|
455
492
|
async addIceCandidate(candidateMessage) {
|
|
456
493
|
const candidate = ice_1.IceCandidate.fromJSON(candidateMessage);
|
|
457
|
-
|
|
494
|
+
if (!candidate) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
let iceTransport;
|
|
498
|
+
if (typeof candidate.sdpMid === "number") {
|
|
499
|
+
iceTransport = this.getTransportByMid(candidate.sdpMid);
|
|
500
|
+
}
|
|
501
|
+
if (!iceTransport && typeof candidate.sdpMLineIndex === "number") {
|
|
502
|
+
iceTransport = this.getTransportByMLineIndex(candidate.sdpMLineIndex);
|
|
503
|
+
}
|
|
504
|
+
if (!iceTransport) {
|
|
505
|
+
iceTransport = this.iceTransports[0];
|
|
506
|
+
}
|
|
507
|
+
if (iceTransport) {
|
|
458
508
|
await iceTransport.addRemoteCandidate(candidate);
|
|
459
509
|
}
|
|
510
|
+
else {
|
|
511
|
+
log("iceTransport not found", candidate);
|
|
512
|
+
}
|
|
460
513
|
}
|
|
461
514
|
async connect() {
|
|
462
515
|
if (this.masterTransportEstablished)
|
|
@@ -543,6 +596,7 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
543
596
|
transceiver = this.addTransceiver(remoteMedia.kind, {
|
|
544
597
|
direction: "recvonly",
|
|
545
598
|
});
|
|
599
|
+
transceiver.mid = remoteMedia.rtp.muxId;
|
|
546
600
|
this.onRemoteTransceiverAdded.execute(transceiver);
|
|
547
601
|
}
|
|
548
602
|
if (bundle) {
|
|
@@ -559,6 +613,7 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
559
613
|
else if (remoteMedia.kind === "application") {
|
|
560
614
|
if (!this.sctpTransport) {
|
|
561
615
|
this.sctpTransport = this.createSctpTransport();
|
|
616
|
+
this.sctpTransport.mid = remoteMedia.rtp.muxId;
|
|
562
617
|
}
|
|
563
618
|
if (bundle) {
|
|
564
619
|
if (!bundleTransport) {
|
|
@@ -569,7 +624,7 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
569
624
|
}
|
|
570
625
|
}
|
|
571
626
|
dtlsTransport = this.sctpTransport.dtlsTransport;
|
|
572
|
-
this.setRemoteSCTP(remoteMedia, this.sctpTransport);
|
|
627
|
+
this.setRemoteSCTP(remoteMedia, this.sctpTransport, i);
|
|
573
628
|
}
|
|
574
629
|
else {
|
|
575
630
|
throw new Error("invalid media kind");
|
|
@@ -676,13 +731,14 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
676
731
|
}
|
|
677
732
|
transceiver.receiver.setupTWCC(remoteMedia.ssrc[0]?.ssrc);
|
|
678
733
|
}
|
|
679
|
-
setRemoteSCTP(remoteMedia, sctpTransport) {
|
|
734
|
+
setRemoteSCTP(remoteMedia, sctpTransport, mLineIndex) {
|
|
680
735
|
// # configure sctp
|
|
681
736
|
this.sctpRemotePort = remoteMedia.sctpPort;
|
|
682
737
|
if (!this.sctpRemotePort) {
|
|
683
738
|
throw new Error("sctpRemotePort not exist");
|
|
684
739
|
}
|
|
685
740
|
sctpTransport.setRemotePort(this.sctpRemotePort);
|
|
741
|
+
sctpTransport.mLineIndex = mLineIndex;
|
|
686
742
|
if (!sctpTransport.mid) {
|
|
687
743
|
sctpTransport.mid = remoteMedia.rtp.muxId;
|
|
688
744
|
}
|
|
@@ -839,14 +895,14 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
839
895
|
let media;
|
|
840
896
|
if (["audio", "video"].includes(remoteMedia.kind)) {
|
|
841
897
|
const transceiver = this.getTransceiverByMid(remoteMedia.rtp.muxId);
|
|
842
|
-
media = createMediaDescriptionForTransceiver(transceiver, this.cname, (0, utils_1.andDirection)(transceiver.direction, transceiver.offerDirection)
|
|
898
|
+
media = createMediaDescriptionForTransceiver(transceiver, this.cname, (0, utils_1.andDirection)(transceiver.direction, transceiver.offerDirection));
|
|
843
899
|
dtlsTransport = transceiver.dtlsTransport;
|
|
844
900
|
}
|
|
845
901
|
else if (remoteMedia.kind === "application") {
|
|
846
902
|
if (!this.sctpTransport || !this.sctpTransport.mid) {
|
|
847
903
|
throw new Error("sctpTransport not found");
|
|
848
904
|
}
|
|
849
|
-
media = createMediaDescriptionForSctp(this.sctpTransport
|
|
905
|
+
media = createMediaDescriptionForSctp(this.sctpTransport);
|
|
850
906
|
dtlsTransport = this.sctpTransport.dtlsTransport;
|
|
851
907
|
}
|
|
852
908
|
else {
|
|
@@ -996,14 +1052,14 @@ class RTCPeerConnection extends helper_1.EventTarget {
|
|
|
996
1052
|
}
|
|
997
1053
|
}
|
|
998
1054
|
exports.RTCPeerConnection = RTCPeerConnection;
|
|
999
|
-
function createMediaDescriptionForTransceiver(transceiver, cname, direction
|
|
1055
|
+
function createMediaDescriptionForTransceiver(transceiver, cname, direction) {
|
|
1000
1056
|
const media = new sdp_1.MediaDescription(transceiver.kind, 9, "UDP/TLS/RTP/SAVPF", transceiver.codecs.map((c) => c.payloadType));
|
|
1001
1057
|
media.direction = direction;
|
|
1002
1058
|
media.msid = transceiver.msid;
|
|
1003
1059
|
media.rtp = {
|
|
1004
1060
|
codecs: transceiver.codecs,
|
|
1005
1061
|
headerExtensions: transceiver.headerExtensions,
|
|
1006
|
-
muxId: mid,
|
|
1062
|
+
muxId: transceiver.mid,
|
|
1007
1063
|
};
|
|
1008
1064
|
media.rtcpHost = "0.0.0.0";
|
|
1009
1065
|
media.rtcpPort = 9;
|
|
@@ -1025,10 +1081,10 @@ function createMediaDescriptionForTransceiver(transceiver, cname, direction, mid
|
|
|
1025
1081
|
return media;
|
|
1026
1082
|
}
|
|
1027
1083
|
exports.createMediaDescriptionForTransceiver = createMediaDescriptionForTransceiver;
|
|
1028
|
-
function createMediaDescriptionForSctp(sctp
|
|
1084
|
+
function createMediaDescriptionForSctp(sctp) {
|
|
1029
1085
|
const media = new sdp_1.MediaDescription("application", const_1.DISCARD_PORT, "UDP/DTLS/SCTP", ["webrtc-datachannel"]);
|
|
1030
1086
|
media.sctpPort = sctp.port;
|
|
1031
|
-
media.rtp.muxId = mid;
|
|
1087
|
+
media.rtp.muxId = sctp.mid;
|
|
1032
1088
|
media.sctpCapabilities = sctp_1.RTCSctpTransport.getCapabilities();
|
|
1033
1089
|
addTransportDescription(media, sctp.dtlsTransport);
|
|
1034
1090
|
return media;
|