werift 0.20.1 → 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.
Files changed (90) hide show
  1. package/lib/common/src/event.js +0 -3
  2. package/lib/common/src/event.js.map +1 -1
  3. package/lib/dtls/src/flight/server/flight2.js +5 -3
  4. package/lib/dtls/src/flight/server/flight2.js.map +1 -1
  5. package/lib/dtls/src/index.d.ts +1 -1
  6. package/lib/dtls/src/index.js.map +1 -1
  7. package/lib/dtls/src/record/receive.js +1 -1
  8. package/lib/dtls/src/record/receive.js.map +1 -1
  9. package/lib/ice/src/candidate.d.ts +2 -1
  10. package/lib/ice/src/candidate.js +17 -4
  11. package/lib/ice/src/candidate.js.map +1 -1
  12. package/lib/ice/src/helper.d.ts +6 -6
  13. package/lib/ice/src/helper.js +18 -15
  14. package/lib/ice/src/helper.js.map +1 -1
  15. package/lib/ice/src/ice.d.ts +28 -75
  16. package/lib/ice/src/ice.js +388 -418
  17. package/lib/ice/src/ice.js.map +1 -1
  18. package/lib/ice/src/iceBase.d.ts +109 -0
  19. package/lib/ice/src/iceBase.js +166 -0
  20. package/lib/ice/src/iceBase.js.map +1 -0
  21. package/lib/ice/src/index.d.ts +1 -0
  22. package/lib/ice/src/index.js +1 -0
  23. package/lib/ice/src/index.js.map +1 -1
  24. package/lib/ice/src/stun/message.d.ts +6 -0
  25. package/lib/ice/src/stun/message.js +4 -0
  26. package/lib/ice/src/stun/message.js.map +1 -1
  27. package/lib/ice/src/stun/protocol.d.ts +5 -6
  28. package/lib/ice/src/stun/protocol.js +18 -18
  29. package/lib/ice/src/stun/protocol.js.map +1 -1
  30. package/lib/ice/src/stun/transaction.js +6 -1
  31. package/lib/ice/src/stun/transaction.js.map +1 -1
  32. package/lib/ice/src/turn/protocol.d.ts +6 -5
  33. package/lib/ice/src/turn/protocol.js +54 -36
  34. package/lib/ice/src/turn/protocol.js.map +1 -1
  35. package/lib/ice/src/types/model.d.ts +4 -0
  36. package/lib/ice/src/types/model.js.map +1 -1
  37. package/lib/rtp/src/extra/container/webm/container.d.ts +3 -1
  38. package/lib/rtp/src/extra/container/webm/container.js +8 -2
  39. package/lib/rtp/src/extra/container/webm/container.js.map +1 -1
  40. package/lib/rtp/src/extra/container/webm/ebml/id.d.ts +6 -0
  41. package/lib/rtp/src/extra/container/webm/ebml/id.js +6 -0
  42. package/lib/rtp/src/extra/container/webm/ebml/id.js.map +1 -1
  43. package/lib/rtp/src/extra/processor/webm.d.ts +11 -16
  44. package/lib/rtp/src/extra/processor/webm.js.map +1 -1
  45. package/lib/rtp/src/extra/processor/webmCallback.d.ts +1 -10
  46. package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
  47. package/lib/rtp/src/rtp/headerExtension.d.ts +45 -3
  48. package/lib/rtp/src/rtp/headerExtension.js +15 -0
  49. package/lib/rtp/src/rtp/headerExtension.js.map +1 -1
  50. package/lib/sctp/src/index.d.ts +1 -1
  51. package/lib/sctp/src/index.js.map +1 -1
  52. package/lib/webrtc/src/const.d.ts +2 -2
  53. package/lib/webrtc/src/const.js.map +1 -1
  54. package/lib/webrtc/src/media/extension/rtpExtension.d.ts +1 -0
  55. package/lib/webrtc/src/media/extension/rtpExtension.js +6 -0
  56. package/lib/webrtc/src/media/extension/rtpExtension.js.map +1 -1
  57. package/lib/webrtc/src/media/router.d.ts +0 -3
  58. package/lib/webrtc/src/media/router.js.map +1 -1
  59. package/lib/webrtc/src/media/rtpReceiver.d.ts +1 -2
  60. package/lib/webrtc/src/media/rtpReceiver.js +2 -2
  61. package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
  62. package/lib/webrtc/src/media/track.d.ts +2 -2
  63. package/lib/webrtc/src/media/track.js.map +1 -1
  64. package/lib/webrtc/src/nonstandard/recorder/index.d.ts +1 -0
  65. package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
  66. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +1 -0
  67. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
  68. package/lib/webrtc/src/peerConnection.d.ts +12 -6
  69. package/lib/webrtc/src/peerConnection.js +94 -82
  70. package/lib/webrtc/src/peerConnection.js.map +1 -1
  71. package/lib/webrtc/src/sdp.js +15 -3
  72. package/lib/webrtc/src/sdp.js.map +1 -1
  73. package/lib/webrtc/src/transport/dtls.d.ts +5 -5
  74. package/lib/webrtc/src/transport/dtls.js +7 -18
  75. package/lib/webrtc/src/transport/dtls.js.map +1 -1
  76. package/lib/webrtc/src/transport/ice.d.ts +20 -9
  77. package/lib/webrtc/src/transport/ice.js +97 -32
  78. package/lib/webrtc/src/transport/ice.js.map +1 -1
  79. package/package.json +1 -1
  80. package/src/const.ts +2 -2
  81. package/src/media/extension/rtpExtension.ts +6 -0
  82. package/src/media/router.ts +2 -3
  83. package/src/media/rtpReceiver.ts +4 -3
  84. package/src/media/track.ts +7 -2
  85. package/src/nonstandard/recorder/index.ts +1 -0
  86. package/src/nonstandard/recorder/writer/webm.ts +47 -43
  87. package/src/peerConnection.ts +118 -88
  88. package/src/sdp.ts +16 -3
  89. package/src/transport/dtls.ts +11 -9
  90. package/src/transport/ice.ts +73 -26
@@ -10,7 +10,7 @@ import { RTCRtpReceiver } from "./media/rtpReceiver";
10
10
  import { RTCRtpSender } from "./media/rtpSender";
11
11
  import { type Direction, RTCRtpTransceiver, type TransceiverOptions } from "./media/rtpTransceiver";
12
12
  import { MediaStream, type MediaStreamTrack } from "./media/track";
13
- import { GroupDescription, MediaDescription, SessionDescription } from "./sdp";
13
+ import { MediaDescription, SessionDescription } from "./sdp";
14
14
  import { RTCDtlsTransport } from "./transport/dtls";
15
15
  import { type IceGathererState, type RTCIceCandidate, type RTCIceConnectionState, RTCIceTransport } from "./transport/ice";
16
16
  import { RTCSctpTransport } from "./transport/sctp";
@@ -19,7 +19,6 @@ import type { Callback, CallbackWithValue } from "./types/util";
19
19
  export declare class RTCPeerConnection extends EventTarget {
20
20
  readonly cname: string;
21
21
  sctpTransport?: RTCSctpTransport;
22
- transportEstablished: boolean;
23
22
  config: Required<PeerConfig>;
24
23
  connectionState: ConnectionState;
25
24
  iceConnectionState: RTCIceConnectionState;
@@ -29,7 +28,7 @@ export declare class RTCPeerConnection extends EventTarget {
29
28
  private readonly transceivers;
30
29
  private pushTransceiver;
31
30
  private replaceTransceiver;
32
- candidatesSent: Set<string>;
31
+ needRestart: boolean;
33
32
  readonly iceGatheringStateChange: Event<["complete" | "new" | "gathering"]>;
34
33
  readonly iceConnectionStateChange: Event<["disconnected" | "closed" | "completed" | "new" | "connected" | "failed" | "checking"]>;
35
34
  readonly signalingStateChange: Event<["closed" | "stable" | "have-local-offer" | "have-remote-offer" | "have-local-pranswer" | "have-remote-pranswer"]>;
@@ -47,7 +46,7 @@ export declare class RTCPeerConnection extends EventTarget {
47
46
  ontrack?: CallbackWithValue<RTCTrackEvent>;
48
47
  onconnectionstatechange?: Callback;
49
48
  private readonly router;
50
- private readonly certificates;
49
+ private certificate?;
51
50
  sctpRemotePort?: number;
52
51
  private seenMid;
53
52
  private currentLocalDescription?;
@@ -61,7 +60,9 @@ export declare class RTCPeerConnection extends EventTarget {
61
60
  get extIdUriMap(): {
62
61
  [id: number]: string;
63
62
  };
63
+ get iceGeneration(): number;
64
64
  constructor(config?: Partial<PeerConfig>);
65
+ setConfiguration(config: Partial<PeerConfig>): void;
65
66
  get localDescription(): import("./sdp").RTCSessionDescription | undefined;
66
67
  get remoteDescription(): import("./sdp").RTCSessionDescription | undefined;
67
68
  /**@private */
@@ -71,7 +72,9 @@ export declare class RTCPeerConnection extends EventTarget {
71
72
  private getTransceiverByMid;
72
73
  private getTransceiverByMLineIndex;
73
74
  getConfiguration(): Required<PeerConfig>;
74
- createOffer(): Promise<import("./sdp").RTCSessionDescription>;
75
+ createOffer({ iceRestart }?: {
76
+ iceRestart?: boolean;
77
+ }): Promise<import("./sdp").RTCSessionDescription>;
75
78
  private assignTransceiverCodecs;
76
79
  buildOfferSdp(): SessionDescription;
77
80
  createDataChannel(label: string, options?: Partial<{
@@ -90,6 +93,7 @@ export declare class RTCPeerConnection extends EventTarget {
90
93
  type: "offer" | "answer";
91
94
  sdp: string;
92
95
  }): Promise<SessionDescription>;
96
+ private gatherCandidates;
93
97
  private setLocal;
94
98
  private getTransportByMid;
95
99
  private getTransportByMLineIndex;
@@ -97,7 +101,8 @@ export declare class RTCPeerConnection extends EventTarget {
97
101
  private connect;
98
102
  private getLocalRtpParams;
99
103
  private getRemoteRtpParams;
100
- get remoteIsBundled(): GroupDescription | undefined;
104
+ private get remoteIsBundled();
105
+ restartIce(): void;
101
106
  setRemoteDescription(sessionDescription: RTCSessionDescriptionInit): Promise<void>;
102
107
  private setRemoteRTP;
103
108
  private setRemoteSCTP;
@@ -159,6 +164,7 @@ export interface PeerConfig {
159
164
  dtls: Partial<{
160
165
  keys: DtlsKeys;
161
166
  }>;
167
+ icePasswordPrefix: string | undefined;
162
168
  bundlePolicy: BundlePolicy;
163
169
  debug: Partial<{
164
170
  /**% */
@@ -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,11 +137,11 @@ class RTCPeerConnection extends helper_1.EventTarget {
140
137
  writable: true,
141
138
  value: []
142
139
  });
143
- Object.defineProperty(this, "candidatesSent", {
140
+ Object.defineProperty(this, "needRestart", {
144
141
  enumerable: true,
145
142
  configurable: true,
146
143
  writable: true,
147
- value: new Set()
144
+ value: false
148
145
  });
149
146
  Object.defineProperty(this, "iceGatheringStateChange", {
150
147
  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, "certificates", {
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.certificates.push(new dtls_1.RTCCertificate(keys.keyPem, keys.certPem, keys.signatureHash));
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,12 +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,
589
597
  turnTransport: this.config.forceTurnTCP === true ? "tcp" : "udp",
590
598
  });
591
599
  if (existing) {
592
- iceGatherer.connection.localUserName = existing.connection.localUserName;
600
+ iceGatherer.connection.localUsername = existing.connection.localUsername;
593
601
  iceGatherer.connection.localPassword = existing.connection.localPassword;
594
602
  }
595
603
  iceGatherer.onGatheringStateChange.subscribe(() => {
@@ -600,7 +608,10 @@ class RTCPeerConnection extends helper_1.EventTarget {
600
608
  iceTransport.onStateChange.subscribe(() => {
601
609
  this.updateIceConnectionState();
602
610
  });
603
- iceTransport.iceGather.onIceCandidate = (candidate) => {
611
+ iceTransport.onNegotiationNeeded.subscribe(() => {
612
+ this.needNegotiation();
613
+ });
614
+ iceTransport.onIceCandidate.subscribe((candidate) => {
604
615
  if (!this.localDescription) {
605
616
  log("localDescription not found when ice candidate was gathered");
606
617
  return;
@@ -633,22 +644,13 @@ class RTCPeerConnection extends helper_1.EventTarget {
633
644
  }
634
645
  }
635
646
  candidate.foundation = "candidate:" + candidate.foundation;
636
- // prevent ice candidates that have already been sent from being being resent
637
- // when the connection is renegotiated during a later setLocalDescription call.
638
- if (candidate.sdpMid) {
639
- const candidateKey = `${candidate.foundation}:${candidate.sdpMid}`;
640
- if (this.candidatesSent.has(candidateKey)) {
641
- return;
642
- }
643
- this.candidatesSent.add(candidateKey);
644
- }
645
647
  this.onIceCandidate.execute(candidate.toJSON());
646
648
  if (this.onicecandidate) {
647
649
  this.onicecandidate({ candidate: candidate.toJSON() });
648
650
  }
649
651
  this.emit("icecandidate", { candidate });
650
- };
651
- const dtlsTransport = new dtls_1.RTCDtlsTransport(this.config, iceTransport, this.router, this.certificates, srtpProfiles);
652
+ });
653
+ const dtlsTransport = new dtls_1.RTCDtlsTransport(this.config, iceTransport, this.router, this.certificate, srtpProfiles);
652
654
  return dtlsTransport;
653
655
  }
654
656
  createSctpTransport() {
@@ -683,7 +685,7 @@ class RTCPeerConnection extends helper_1.EventTarget {
683
685
  this.setSignalingState("stable");
684
686
  }
685
687
  // # assign MID
686
- description.media.forEach((media, i) => {
688
+ for (const [i, media] of (0, helper_1.enumerate)(description.media)) {
687
689
  const mid = media.rtp.muxId;
688
690
  this.seenMid.add(mid);
689
691
  if (["audio", "video"].includes(media.kind)) {
@@ -695,8 +697,9 @@ class RTCPeerConnection extends helper_1.EventTarget {
695
697
  if (media.kind === "application" && this.sctpTransport) {
696
698
  this.sctpTransport.mid = mid;
697
699
  }
698
- });
699
- const setupRole = (dtlsTransport) => {
700
+ }
701
+ // setup ice,dtls role
702
+ for (const dtlsTransport of this.dtlsTransports) {
700
703
  const iceTransport = dtlsTransport.iceTransport;
701
704
  // # set ICE role
702
705
  if (description.type === "offer") {
@@ -718,26 +721,19 @@ class RTCPeerConnection extends helper_1.EventTarget {
718
721
  dtlsTransport.role = role;
719
722
  }
720
723
  }
721
- };
722
- this.dtlsTransports.forEach((d) => setupRole(d));
724
+ }
723
725
  // # configure direction
724
726
  if (["answer", "pranswer"].includes(description.type)) {
725
- this.transceivers.forEach((t) => {
727
+ for (const t of this.transceivers) {
726
728
  const direction = (0, utils_1.andDirection)(t.direction, t.offerDirection);
727
729
  t.setCurrentDirection(direction);
728
- });
730
+ }
729
731
  }
730
732
  // for trickle ice
731
733
  this.setLocal(description);
732
- // # gather candidates
733
- const connected = this.iceTransports.find((transport) => transport.state === "connected");
734
- if (this.remoteIsBundled && connected) {
735
- // no need to gather ice candidates on an existing bundled connection
736
- await connected.iceGather.gather();
737
- }
738
- else {
739
- await Promise.allSettled(this.iceTransports.map((iceTransport) => iceTransport.iceGather.gather()));
740
- }
734
+ await this.gatherCandidates().catch((e) => {
735
+ log("gatherCandidates failed", e);
736
+ });
741
737
  // connect transports
742
738
  if (description.type === "answer") {
743
739
  this.connect().catch((err) => {
@@ -751,6 +747,16 @@ class RTCPeerConnection extends helper_1.EventTarget {
751
747
  }
752
748
  return description;
753
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
+ }
754
760
  setLocal(description) {
755
761
  description.media
756
762
  .filter((m) => ["audio", "video"].includes(m.kind))
@@ -812,17 +818,20 @@ class RTCPeerConnection extends helper_1.EventTarget {
812
818
  }
813
819
  }
814
820
  async connect() {
815
- if (this.transportEstablished) {
816
- return;
817
- }
818
821
  log("start connect");
819
- this.setConnectionState("connecting");
820
822
  await Promise.allSettled(this.dtlsTransports.map(async (dtlsTransport) => {
821
823
  const { iceTransport } = dtlsTransport;
824
+ if (iceTransport.state === "connected") {
825
+ return;
826
+ }
827
+ this.setConnectionState("connecting");
822
828
  await iceTransport.start().catch((err) => {
823
829
  log("iceTransport.start failed", err);
824
830
  throw err;
825
831
  });
832
+ if (dtlsTransport.state === "connected") {
833
+ return;
834
+ }
826
835
  await dtlsTransport.start().catch((err) => {
827
836
  log("dtlsTransport.start failed", err);
828
837
  throw err;
@@ -835,7 +844,6 @@ class RTCPeerConnection extends helper_1.EventTarget {
835
844
  log("sctp connected");
836
845
  }
837
846
  }));
838
- this.transportEstablished = true;
839
847
  this.setConnectionState("connected");
840
848
  }
841
849
  getLocalRtpParams(transceiver) {
@@ -881,6 +889,10 @@ class RTCPeerConnection extends helper_1.EventTarget {
881
889
  const bundle = remoteSdp.group.find((g) => g.semantic === "BUNDLE" && this.config.bundlePolicy !== "disable");
882
890
  return bundle;
883
891
  }
892
+ restartIce() {
893
+ this.needRestart = true;
894
+ this.needNegotiation();
895
+ }
884
896
  async setRemoteDescription(sessionDescription) {
885
897
  if (!sessionDescription.sdp ||
886
898
  !sessionDescription.type ||
@@ -955,15 +967,18 @@ class RTCPeerConnection extends helper_1.EventTarget {
955
967
  throw new Error("invalid media kind");
956
968
  }
957
969
  const iceTransport = dtlsTransport.iceTransport;
958
- if (remoteMedia.iceParams && remoteMedia.dtlsParams) {
959
- iceTransport.setRemoteParams(remoteMedia.iceParams);
960
- dtlsTransport.setRemoteParams(remoteMedia.dtlsParams);
970
+ if (remoteMedia.iceParams) {
971
+ const renomination = !!remoteSdp.media.find((m) => m.direction === "inactive");
972
+ iceTransport.setRemoteParams(remoteMedia.iceParams, renomination);
961
973
  // One agent full, one lite: The full agent MUST take the controlling role, and the lite agent MUST take the controlled role
962
974
  // RFC 8445 S6.1.1
963
975
  if (remoteMedia.iceParams?.iceLite) {
964
976
  iceTransport.connection.iceControlling = true;
965
977
  }
966
978
  }
979
+ if (remoteMedia.dtlsParams) {
980
+ dtlsTransport.setRemoteParams(remoteMedia.dtlsParams);
981
+ }
967
982
  // # add ICE candidates
968
983
  remoteMedia.iceCandidates.forEach(iceTransport.addRemoteCandidate);
969
984
  if (remoteMedia.iceCandidatesComplete) {
@@ -1016,14 +1031,16 @@ class RTCPeerConnection extends helper_1.EventTarget {
1016
1031
  transceiver.codecs = remoteMedia.rtp.codecs.filter((remoteCodec) => {
1017
1032
  const localCodecs = this.config.codecs[remoteMedia.kind] || [];
1018
1033
  const existCodec = (0, exports.findCodecByMimeType)(localCodecs, remoteCodec);
1019
- if (!existCodec)
1034
+ if (!existCodec) {
1020
1035
  return false;
1036
+ }
1021
1037
  if (existCodec?.name.toLowerCase() === "rtx") {
1022
1038
  const params = (0, _2.codecParametersFromString)(existCodec.parameters ?? "");
1023
1039
  const pt = params["apt"];
1024
1040
  const origin = remoteMedia.rtp.codecs.find((c) => c.payloadType === pt);
1025
- if (!origin)
1041
+ if (!origin) {
1026
1042
  return false;
1043
+ }
1027
1044
  return !!(0, exports.findCodecByMimeType)(localCodecs, origin);
1028
1045
  }
1029
1046
  return true;
@@ -1222,17 +1239,11 @@ class RTCPeerConnection extends helper_1.EventTarget {
1222
1239
  }
1223
1240
  }
1224
1241
  async ensureCerts() {
1225
- const ensureCert = async (dtlsTransport) => {
1226
- if (this.certificates.length === 0) {
1227
- const localCertificate = await dtlsTransport.setupCertificate();
1228
- this.certificates.push(localCertificate);
1229
- }
1230
- else {
1231
- dtlsTransport.localCertificate = this.certificates[0];
1232
- }
1233
- };
1242
+ if (!this.certificate) {
1243
+ this.certificate = await dtls_1.RTCDtlsTransport.SetupCertificate();
1244
+ }
1234
1245
  for (const dtlsTransport of this.dtlsTransports) {
1235
- await ensureCert(dtlsTransport);
1246
+ dtlsTransport.localCertificate = this.certificate;
1236
1247
  }
1237
1248
  }
1238
1249
  async createAnswer() {
@@ -1285,11 +1296,11 @@ class RTCPeerConnection extends helper_1.EventTarget {
1285
1296
  });
1286
1297
  if (this.config.bundlePolicy !== "disable") {
1287
1298
  const bundle = new sdp_1.GroupDescription("BUNDLE", []);
1288
- description.media.forEach((media) => {
1299
+ for (const media of description.media) {
1289
1300
  if (media.direction !== "inactive") {
1290
1301
  bundle.items.push(media.rtp.muxId);
1291
1302
  }
1292
- });
1303
+ }
1293
1304
  description.group.push(bundle);
1294
1305
  }
1295
1306
  return description;
@@ -1323,8 +1334,8 @@ class RTCPeerConnection extends helper_1.EventTarget {
1323
1334
  updateIceGatheringState() {
1324
1335
  const all = this.iceTransports;
1325
1336
  function allMatch(...state) {
1326
- return (all.filter((check) => state.includes(check.iceGather.gatheringState))
1327
- .length === all.length);
1337
+ return (all.filter((check) => state.includes(check.gatheringState)).length ===
1338
+ all.length);
1328
1339
  }
1329
1340
  let newState;
1330
1341
  if (all.length && allMatch("complete")) {
@@ -1333,7 +1344,7 @@ class RTCPeerConnection extends helper_1.EventTarget {
1333
1344
  else if (!all.length || allMatch("new", "complete")) {
1334
1345
  newState = "new";
1335
1346
  }
1336
- else if (all.map((check) => check.iceGather.gatheringState).includes("gathering")) {
1347
+ else if (all.map((check) => check.gatheringState).includes("gathering")) {
1337
1348
  newState = "gathering";
1338
1349
  }
1339
1350
  else {
@@ -1398,8 +1409,9 @@ class RTCPeerConnection extends helper_1.EventTarget {
1398
1409
  log("connectionStateChange", state);
1399
1410
  this.connectionState = state;
1400
1411
  this.connectionStateChange.execute(state);
1401
- if (this.onconnectionstatechange)
1412
+ if (this.onconnectionstatechange) {
1402
1413
  this.onconnectionstatechange();
1414
+ }
1403
1415
  this.emit("connectionstatechange");
1404
1416
  }
1405
1417
  dispose() {
@@ -1451,10 +1463,9 @@ function createMediaDescriptionForSctp(sctp) {
1451
1463
  }
1452
1464
  function addTransportDescription(media, dtlsTransport) {
1453
1465
  const iceTransport = dtlsTransport.iceTransport;
1454
- const iceGatherer = iceTransport.iceGather;
1455
- media.iceCandidates = iceGatherer.localCandidates;
1456
- media.iceCandidatesComplete = iceGatherer.gatheringState === "complete";
1457
- media.iceParams = iceGatherer.localParameters;
1466
+ media.iceCandidates = iceTransport.localCandidates;
1467
+ media.iceCandidatesComplete = iceTransport.gatheringState === "complete";
1468
+ media.iceParams = iceTransport.localParameters;
1458
1469
  media.iceOptions = "trickle";
1459
1470
  media.host = const_1.DISCARD_HOST;
1460
1471
  media.port = const_1.DISCARD_PORT;
@@ -1522,6 +1533,7 @@ exports.defaultPeerConfig = {
1522
1533
  iceUseIpv6: true,
1523
1534
  iceFilterStunResponse: undefined,
1524
1535
  iceFilterCandidatePair: undefined,
1536
+ icePasswordPrefix: undefined,
1525
1537
  dtls: {},
1526
1538
  bundlePolicy: "max-compat",
1527
1539
  debug: {},