werift 0.27.0 → 0.29.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/README.md +299 -8
- package/lib/common/src/event.d.ts +26 -0
- package/lib/common/src/event.js +87 -2
- package/lib/common/src/event.js.map +1 -1
- package/lib/common/src/network.d.ts +6 -1
- package/lib/common/src/network.js +8 -2
- package/lib/common/src/network.js.map +1 -1
- package/lib/common/src/transport.d.ts +51 -10
- package/lib/common/src/transport.js +35 -9
- package/lib/common/src/transport.js.map +1 -1
- package/lib/dtls/src/alert.d.ts +49 -0
- package/lib/dtls/src/alert.js +103 -0
- package/lib/dtls/src/alert.js.map +1 -0
- package/lib/dtls/src/carrier/direct.d.ts +67 -0
- package/lib/dtls/src/carrier/direct.js +226 -0
- package/lib/dtls/src/carrier/direct.js.map +1 -0
- package/lib/dtls/src/carrier/types.d.ts +81 -0
- package/lib/dtls/src/carrier/types.js +7 -0
- package/lib/dtls/src/carrier/types.js.map +1 -0
- package/lib/dtls/src/cipher/const.d.ts +6 -0
- package/lib/dtls/src/cipher/const.js +13 -2
- package/lib/dtls/src/cipher/const.js.map +1 -1
- package/lib/dtls/src/cipher/prf.js +11 -2
- package/lib/dtls/src/cipher/prf.js.map +1 -1
- package/lib/dtls/src/cipher/tls13/aead.d.ts +41 -0
- package/lib/dtls/src/cipher/tls13/aead.js +128 -0
- package/lib/dtls/src/cipher/tls13/aead.js.map +1 -0
- package/lib/dtls/src/cipher/tls13/hkdf.d.ts +30 -0
- package/lib/dtls/src/cipher/tls13/hkdf.js +76 -0
- package/lib/dtls/src/cipher/tls13/hkdf.js.map +1 -0
- package/lib/dtls/src/cipher/tls13/keySchedule.d.ts +70 -0
- package/lib/dtls/src/cipher/tls13/keySchedule.js +114 -0
- package/lib/dtls/src/cipher/tls13/keySchedule.js.map +1 -0
- package/lib/dtls/src/cipher/tls13/signature.d.ts +30 -0
- package/lib/dtls/src/cipher/tls13/signature.js +149 -0
- package/lib/dtls/src/cipher/tls13/signature.js.map +1 -0
- package/lib/dtls/src/client.d.ts +253 -0
- package/lib/dtls/src/client.js +1269 -14
- package/lib/dtls/src/client.js.map +1 -1
- package/lib/dtls/src/context/dtls.d.ts +47 -0
- package/lib/dtls/src/context/dtls.js +121 -0
- package/lib/dtls/src/context/dtls.js.map +1 -1
- package/lib/dtls/src/context/transport.d.ts +30 -1
- package/lib/dtls/src/context/transport.js +67 -3
- package/lib/dtls/src/context/transport.js.map +1 -1
- package/lib/dtls/src/engine/v1_3/connection-base.d.ts +520 -0
- package/lib/dtls/src/engine/v1_3/connection-base.js +1644 -0
- package/lib/dtls/src/engine/v1_3/connection-base.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/connection.d.ts +181 -0
- package/lib/dtls/src/engine/v1_3/connection.js +680 -0
- package/lib/dtls/src/engine/v1_3/connection.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/early-data-buffer.d.ts +38 -0
- package/lib/dtls/src/engine/v1_3/early-data-buffer.js +166 -0
- package/lib/dtls/src/engine/v1_3/early-data-buffer.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/certificate.d.ts +4 -0
- package/lib/dtls/src/engine/v1_3/flight/certificate.js +62 -0
- package/lib/dtls/src/engine/v1_3/flight/certificate.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight1.d.ts +8 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight1.js +119 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight1.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight4.d.ts +8 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight4.js +251 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight4.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight5.d.ts +5 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight5.js +99 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight5.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/dispatch.d.ts +12 -0
- package/lib/dtls/src/engine/v1_3/flight/dispatch.js +138 -0
- package/lib/dtls/src/engine/v1_3/flight/dispatch.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/extensions.d.ts +13 -0
- package/lib/dtls/src/engine/v1_3/flight/extensions.js +46 -0
- package/lib/dtls/src/engine/v1_3/flight/extensions.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/finished.d.ts +6 -0
- package/lib/dtls/src/engine/v1_3/flight/finished.js +16 -0
- package/lib/dtls/src/engine/v1_3/flight/finished.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/post-hs.d.ts +12 -0
- package/lib/dtls/src/engine/v1_3/flight/post-hs.js +94 -0
- package/lib/dtls/src/engine/v1_3/flight/post-hs.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight2.d.ts +21 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight2.js +227 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight2.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight4.d.ts +6 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight4.js +455 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight4.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight5.d.ts +5 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight5.js +48 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight5.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight-tx.d.ts +119 -0
- package/lib/dtls/src/engine/v1_3/flight-tx.js +782 -0
- package/lib/dtls/src/engine/v1_3/flight-tx.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/host.d.ts +86 -0
- package/lib/dtls/src/engine/v1_3/host.js +11 -0
- package/lib/dtls/src/engine/v1_3/host.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/record-rx.d.ts +77 -0
- package/lib/dtls/src/engine/v1_3/record-rx.js +818 -0
- package/lib/dtls/src/engine/v1_3/record-rx.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/transcript.d.ts +22 -0
- package/lib/dtls/src/engine/v1_3/transcript.js +65 -0
- package/lib/dtls/src/engine/v1_3/transcript.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/types.d.ts +169 -0
- package/lib/dtls/src/engine/v1_3/types.js +113 -0
- package/lib/dtls/src/engine/v1_3/types.js.map +1 -0
- package/lib/dtls/src/flight/client/flight1.d.ts +7 -1
- package/lib/dtls/src/flight/client/flight1.js +9 -3
- package/lib/dtls/src/flight/client/flight1.js.map +1 -1
- package/lib/dtls/src/flight/client/flight3.d.ts +8 -0
- package/lib/dtls/src/flight/client/flight3.js +24 -4
- package/lib/dtls/src/flight/client/flight3.js.map +1 -1
- package/lib/dtls/src/flight/client/flight5.js +17 -2
- package/lib/dtls/src/flight/client/flight5.js.map +1 -1
- package/lib/dtls/src/flight/flight.d.ts +21 -0
- package/lib/dtls/src/flight/flight.js +119 -9
- package/lib/dtls/src/flight/flight.js.map +1 -1
- package/lib/dtls/src/flight/server/commitClientHello.d.ts +35 -0
- package/lib/dtls/src/flight/server/commitClientHello.js +149 -0
- package/lib/dtls/src/flight/server/commitClientHello.js.map +1 -0
- package/lib/dtls/src/flight/server/flight2.d.ts +12 -3
- package/lib/dtls/src/flight/server/flight2.js +29 -105
- package/lib/dtls/src/flight/server/flight2.js.map +1 -1
- package/lib/dtls/src/flight/server/flight4.js +14 -2
- package/lib/dtls/src/flight/server/flight4.js.map +1 -1
- package/lib/dtls/src/flight/server/flight6.js +12 -1
- package/lib/dtls/src/flight/server/flight6.js.map +1 -1
- package/lib/dtls/src/handshake/const.d.ts +10 -0
- package/lib/dtls/src/handshake/const.js +10 -0
- package/lib/dtls/src/handshake/const.js.map +1 -1
- package/lib/dtls/src/handshake/extensions/cookie.d.ts +113 -0
- package/lib/dtls/src/handshake/extensions/cookie.js +326 -0
- package/lib/dtls/src/handshake/extensions/cookie.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/ids.d.ts +7 -0
- package/lib/dtls/src/handshake/extensions/ids.js +11 -0
- package/lib/dtls/src/handshake/extensions/ids.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/keyShare.d.ts +28 -0
- package/lib/dtls/src/handshake/extensions/keyShare.js +156 -0
- package/lib/dtls/src/handshake/extensions/keyShare.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/signatureAlgorithms.d.ts +27 -0
- package/lib/dtls/src/handshake/extensions/signatureAlgorithms.js +67 -0
- package/lib/dtls/src/handshake/extensions/signatureAlgorithms.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/supportedVersions.d.ts +20 -0
- package/lib/dtls/src/handshake/extensions/supportedVersions.js +90 -0
- package/lib/dtls/src/handshake/extensions/supportedVersions.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/unique.d.ts +7 -0
- package/lib/dtls/src/handshake/extensions/unique.js +19 -0
- package/lib/dtls/src/handshake/extensions/unique.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/useSrtp.d.ts +26 -3
- package/lib/dtls/src/handshake/extensions/useSrtp.js +68 -12
- package/lib/dtls/src/handshake/extensions/useSrtp.js.map +1 -1
- package/lib/dtls/src/handshake/message/tls13/ack.d.ts +50 -0
- package/lib/dtls/src/handshake/message/tls13/ack.js +107 -0
- package/lib/dtls/src/handshake/message/tls13/ack.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/certificate.d.ts +17 -0
- package/lib/dtls/src/handshake/message/tls13/certificate.js +112 -0
- package/lib/dtls/src/handshake/message/tls13/certificate.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/certificateRequest.d.ts +17 -0
- package/lib/dtls/src/handshake/message/tls13/certificateRequest.js +99 -0
- package/lib/dtls/src/handshake/message/tls13/certificateRequest.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/certificateVerify.d.ts +21 -0
- package/lib/dtls/src/handshake/message/tls13/certificateVerify.js +77 -0
- package/lib/dtls/src/handshake/message/tls13/certificateVerify.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/encryptedExtensions.d.ts +19 -0
- package/lib/dtls/src/handshake/message/tls13/encryptedExtensions.js +56 -0
- package/lib/dtls/src/handshake/message/tls13/encryptedExtensions.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/keyUpdate.d.ts +13 -0
- package/lib/dtls/src/handshake/message/tls13/keyUpdate.js +54 -0
- package/lib/dtls/src/handshake/message/tls13/keyUpdate.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/newSessionTicket.d.ts +33 -0
- package/lib/dtls/src/handshake/message/tls13/newSessionTicket.js +158 -0
- package/lib/dtls/src/handshake/message/tls13/newSessionTicket.js.map +1 -0
- package/lib/dtls/src/handshake/random.d.ts +14 -0
- package/lib/dtls/src/handshake/random.js +24 -0
- package/lib/dtls/src/handshake/random.js.map +1 -1
- package/lib/dtls/src/handshake/validation.d.ts +26 -0
- package/lib/dtls/src/handshake/validation.js +32 -0
- package/lib/dtls/src/handshake/validation.js.map +1 -0
- package/lib/dtls/src/index.d.ts +8 -1
- package/lib/dtls/src/index.js +125 -44
- package/lib/dtls/src/index.js.map +1 -1
- package/lib/dtls/src/internal.d.ts +7 -0
- package/lib/dtls/src/internal.js +57 -0
- package/lib/dtls/src/internal.js.map +1 -0
- package/lib/dtls/src/peer.d.ts +49 -0
- package/lib/dtls/src/peer.js +54 -0
- package/lib/dtls/src/peer.js.map +1 -0
- package/lib/dtls/src/record/antiReplayWindow.d.ts +33 -0
- package/lib/dtls/src/record/antiReplayWindow.js +119 -0
- package/lib/dtls/src/record/antiReplayWindow.js.map +1 -0
- package/lib/dtls/src/record/const.d.ts +15 -0
- package/lib/dtls/src/record/const.js +15 -1
- package/lib/dtls/src/record/const.js.map +1 -1
- package/lib/dtls/src/record/message/fragment.d.ts +0 -2
- package/lib/dtls/src/record/message/fragment.js +36 -17
- package/lib/dtls/src/record/message/fragment.js.map +1 -1
- package/lib/dtls/src/record/message/reassembler.d.ts +62 -0
- package/lib/dtls/src/record/message/reassembler.js +249 -0
- package/lib/dtls/src/record/message/reassembler.js.map +1 -0
- package/lib/dtls/src/record/receive.d.ts +6 -0
- package/lib/dtls/src/record/receive.js +58 -19
- package/lib/dtls/src/record/receive.js.map +1 -1
- package/lib/dtls/src/record/v1_3/header.d.ts +34 -0
- package/lib/dtls/src/record/v1_3/header.js +95 -0
- package/lib/dtls/src/record/v1_3/header.js.map +1 -0
- package/lib/dtls/src/record/v1_3/record.d.ts +133 -0
- package/lib/dtls/src/record/v1_3/record.js +370 -0
- package/lib/dtls/src/record/v1_3/record.js.map +1 -0
- package/lib/dtls/src/retransmission.d.ts +26 -0
- package/lib/dtls/src/retransmission.js +39 -0
- package/lib/dtls/src/retransmission.js.map +1 -0
- package/lib/dtls/src/server.d.ts +38 -0
- package/lib/dtls/src/server.js +382 -17
- package/lib/dtls/src/server.js.map +1 -1
- package/lib/dtls/src/socket.d.ts +487 -11
- package/lib/dtls/src/socket.js +1359 -70
- package/lib/dtls/src/socket.js.map +1 -1
- package/lib/dtls/src/version.d.ts +89 -0
- package/lib/dtls/src/version.js +204 -0
- package/lib/dtls/src/version.js.map +1 -0
- package/lib/ice/src/candidateError.d.ts +155 -0
- package/lib/ice/src/candidateError.js +246 -0
- package/lib/ice/src/candidateError.js.map +1 -0
- package/lib/ice/src/candidateGatherer.d.ts +127 -0
- package/lib/ice/src/candidateGatherer.js +745 -0
- package/lib/ice/src/candidateGatherer.js.map +1 -0
- package/lib/ice/src/consent.d.ts +126 -0
- package/lib/ice/src/consent.js +470 -0
- package/lib/ice/src/consent.js.map +1 -0
- package/lib/ice/src/dns/lookup.d.ts +10 -0
- package/lib/ice/src/dns/lookup.js +130 -3
- package/lib/ice/src/dns/lookup.js.map +1 -1
- package/lib/ice/src/exceptions.d.ts +9 -0
- package/lib/ice/src/exceptions.js +14 -1
- package/lib/ice/src/exceptions.js.map +1 -1
- package/lib/ice/src/failover.d.ts +270 -0
- package/lib/ice/src/failover.js +674 -0
- package/lib/ice/src/failover.js.map +1 -0
- package/lib/ice/src/gatheringError.d.ts +28 -0
- package/lib/ice/src/gatheringError.js +17 -0
- package/lib/ice/src/gatheringError.js.map +1 -0
- package/lib/ice/src/ice.d.ts +486 -78
- package/lib/ice/src/ice.js +2415 -1129
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/iceBase.d.ts +404 -14
- package/lib/ice/src/iceBase.js +251 -38
- package/lib/ice/src/iceBase.js.map +1 -1
- package/lib/ice/src/index.d.ts +3 -0
- package/lib/ice/src/index.js +5 -1
- package/lib/ice/src/index.js.map +1 -1
- package/lib/ice/src/internal/checkMessages.d.ts +41 -0
- package/lib/ice/src/internal/checkMessages.js +63 -0
- package/lib/ice/src/internal/checkMessages.js.map +1 -0
- package/lib/ice/src/internal/datagram.d.ts +37 -0
- package/lib/ice/src/internal/datagram.js +45 -0
- package/lib/ice/src/internal/datagram.js.map +1 -0
- package/lib/ice/src/internal/defaultRoute.d.ts +20 -0
- package/lib/ice/src/internal/defaultRoute.js +134 -0
- package/lib/ice/src/internal/defaultRoute.js.map +1 -0
- package/lib/ice/src/internal/hostInterfaces.d.ts +28 -0
- package/lib/ice/src/internal/hostInterfaces.js +89 -0
- package/lib/ice/src/internal/hostInterfaces.js.map +1 -0
- package/lib/ice/src/internal/hostPreference.d.ts +24 -0
- package/lib/ice/src/internal/hostPreference.js +38 -0
- package/lib/ice/src/internal/hostPreference.js.map +1 -0
- package/lib/ice/src/internal/resolveHostAddresses.d.ts +56 -8
- package/lib/ice/src/internal/resolveHostAddresses.js +127 -24
- package/lib/ice/src/internal/resolveHostAddresses.js.map +1 -1
- package/lib/ice/src/internal/selectAddresses.d.ts +27 -0
- package/lib/ice/src/internal/selectAddresses.js +37 -18
- package/lib/ice/src/internal/selectAddresses.js.map +1 -1
- package/lib/ice/src/internal/sped-bind.d.ts +44 -0
- package/lib/ice/src/internal/sped-bind.js +53 -0
- package/lib/ice/src/internal/sped-bind.js.map +1 -0
- package/lib/ice/src/internal/sped-binding-cache.d.ts +27 -0
- package/lib/ice/src/internal/sped-binding-cache.js +102 -0
- package/lib/ice/src/internal/sped-binding-cache.js.map +1 -0
- package/lib/ice/src/internal/sped.d.ts +15 -0
- package/lib/ice/src/internal/sped.js +62 -0
- package/lib/ice/src/internal/sped.js.map +1 -0
- package/lib/ice/src/nomination/regularNomination.d.ts +200 -0
- package/lib/ice/src/nomination/regularNomination.js +311 -0
- package/lib/ice/src/nomination/regularNomination.js.map +1 -0
- package/lib/ice/src/nomination/selectionController.d.ts +111 -0
- package/lib/ice/src/nomination/selectionController.js +172 -0
- package/lib/ice/src/nomination/selectionController.js.map +1 -0
- package/lib/ice/src/nomination/selectionReplacement.d.ts +178 -0
- package/lib/ice/src/nomination/selectionReplacement.js +429 -0
- package/lib/ice/src/nomination/selectionReplacement.js.map +1 -0
- package/lib/ice/src/provisional.d.ts +139 -0
- package/lib/ice/src/provisional.js +468 -0
- package/lib/ice/src/provisional.js.map +1 -0
- package/lib/ice/src/sped/draft00/codec.d.ts +20 -0
- package/lib/ice/src/sped/draft00/codec.js +59 -0
- package/lib/ice/src/sped/draft00/codec.js.map +1 -0
- package/lib/ice/src/sped/draft00/constants.d.ts +14 -0
- package/lib/ice/src/sped/draft00/constants.js +18 -0
- package/lib/ice/src/sped/draft00/constants.js.map +1 -0
- package/lib/ice/src/sped/draft00/index.d.ts +6 -0
- package/lib/ice/src/sped/draft00/index.js +26 -0
- package/lib/ice/src/sped/draft00/index.js.map +1 -0
- package/lib/ice/src/sped/draft00/mtu.d.ts +38 -0
- package/lib/ice/src/sped/draft00/mtu.js +96 -0
- package/lib/ice/src/sped/draft00/mtu.js.map +1 -0
- package/lib/ice/src/sped/draft00/session.d.ts +86 -0
- package/lib/ice/src/sped/draft00/session.js +353 -0
- package/lib/ice/src/sped/draft00/session.js.map +1 -0
- package/lib/ice/src/sped/draft00/types.d.ts +16 -0
- package/lib/ice/src/sped/draft00/types.js +3 -0
- package/lib/ice/src/sped/draft00/types.js.map +1 -0
- package/lib/ice/src/sped/runtime.d.ts +188 -0
- package/lib/ice/src/sped/runtime.js +643 -0
- package/lib/ice/src/sped/runtime.js.map +1 -0
- package/lib/ice/src/stun/protocol.d.ts +38 -2
- package/lib/ice/src/stun/protocol.js +107 -21
- package/lib/ice/src/stun/protocol.js.map +1 -1
- package/lib/ice/src/stun/rawAttributeValue.d.ts +1 -0
- package/lib/ice/src/stun/rawAttributeValue.js +6 -0
- package/lib/ice/src/stun/rawAttributeValue.js.map +1 -0
- package/lib/ice/src/stun/tcpProtocol.d.ts +2 -1
- package/lib/ice/src/stun/tcpProtocol.js +21 -9
- package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
- package/lib/ice/src/stun/transaction.d.ts +4 -0
- package/lib/ice/src/stun/transaction.js +27 -2
- package/lib/ice/src/stun/transaction.js.map +1 -1
- package/lib/ice/src/turn/protocol.d.ts +23 -4
- package/lib/ice/src/turn/protocol.js +99 -11
- package/lib/ice/src/turn/protocol.js.map +1 -1
- package/lib/ice/src/types/model.d.ts +25 -5
- package/lib/ice/src/types/model.js.map +1 -1
- package/lib/ice/src/utils.d.ts +13 -0
- package/lib/ice/src/utils.js +13 -0
- package/lib/ice/src/utils.js.map +1 -1
- package/lib/ice-server/src/stun/attributes.js +4 -0
- package/lib/ice-server/src/stun/attributes.js.map +1 -1
- package/lib/ice-server/src/stun/const.d.ts +20 -1
- package/lib/ice-server/src/stun/const.js +9 -1
- package/lib/ice-server/src/stun/const.js.map +1 -1
- package/lib/ice-server/src/stun/message.d.ts +43 -3
- package/lib/ice-server/src/stun/message.js +258 -40
- package/lib/ice-server/src/stun/message.js.map +1 -1
- package/lib/ice-server/src/stun/rawAttributeValue.d.ts +6 -0
- package/lib/ice-server/src/stun/rawAttributeValue.js +12 -0
- package/lib/ice-server/src/stun/rawAttributeValue.js.map +1 -0
- package/lib/index.mjs +47427 -25303
- package/lib/nonstandard/index.mjs +3076 -1318
- package/lib/polyfill/dom.mjs +40430 -18730
- package/lib/polyfill/index.mjs +40333 -18639
- package/lib/rtp/src/extra/processor/fsRetry.d.ts +20 -0
- package/lib/rtp/src/extra/processor/fsRetry.js +73 -0
- package/lib/rtp/src/extra/processor/fsRetry.js.map +1 -0
- package/lib/rtp/src/extra/processor/webm.d.ts +6 -0
- package/lib/rtp/src/extra/processor/webm.js +6 -2
- package/lib/rtp/src/extra/processor/webm.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmCallback.d.ts +11 -0
- package/lib/rtp/src/extra/processor/webmCallback.js +23 -31
- package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmFileWriter.d.ts +24 -0
- package/lib/rtp/src/extra/processor/webmFileWriter.js +94 -0
- package/lib/rtp/src/extra/processor/webmFileWriter.js.map +1 -0
- package/lib/rtp/src/index.d.ts +1 -0
- package/lib/rtp/src/index.js +1 -0
- package/lib/rtp/src/index.js.map +1 -1
- package/lib/rtp/src/rtp/continuity.d.ts +14 -1
- package/lib/rtp/src/rtp/continuity.js +24 -4
- package/lib/rtp/src/rtp/continuity.js.map +1 -1
- package/lib/rtp/src/rtp/timelineRewriter.d.ts +178 -0
- package/lib/rtp/src/rtp/timelineRewriter.js +417 -0
- package/lib/rtp/src/rtp/timelineRewriter.js.map +1 -0
- package/lib/sctp/src/chunk.d.ts +5 -0
- package/lib/sctp/src/chunk.js +10 -0
- package/lib/sctp/src/chunk.js.map +1 -1
- package/lib/sctp/src/index.d.ts +1 -1
- package/lib/sctp/src/index.js +4 -1
- package/lib/sctp/src/index.js.map +1 -1
- package/lib/sctp/src/sctp.d.ts +86 -5
- package/lib/sctp/src/sctp.js +354 -75
- package/lib/sctp/src/sctp.js.map +1 -1
- package/lib/webrtc/src/api/compatibilityOptions.d.ts +43 -0
- package/lib/webrtc/src/api/compatibilityOptions.js +43 -0
- package/lib/webrtc/src/api/compatibilityOptions.js.map +1 -0
- package/lib/webrtc/src/api/peerConfig.d.ts +547 -36
- package/lib/webrtc/src/api/peerConfig.js +187 -26
- package/lib/webrtc/src/api/peerConfig.js.map +1 -1
- package/lib/webrtc/src/api/peerConnectionEvents.d.ts +87 -2
- package/lib/webrtc/src/api/peerConnectionEvents.js +105 -1
- package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -1
- package/lib/webrtc/src/dataChannel.d.ts +122 -10
- package/lib/webrtc/src/dataChannel.js +214 -20
- package/lib/webrtc/src/dataChannel.js.map +1 -1
- package/lib/webrtc/src/helper.d.ts +8 -0
- package/lib/webrtc/src/helper.js +40 -4
- package/lib/webrtc/src/helper.js.map +1 -1
- package/lib/webrtc/src/media/codecCompatibility.d.ts +87 -1
- package/lib/webrtc/src/media/codecCompatibility.js +338 -12
- package/lib/webrtc/src/media/codecCompatibility.js.map +1 -1
- package/lib/webrtc/src/media/domEventTarget.d.ts +55 -0
- package/lib/webrtc/src/media/domEventTarget.js +216 -0
- package/lib/webrtc/src/media/domEventTarget.js.map +1 -0
- package/lib/webrtc/src/media/index.d.ts +2 -0
- package/lib/webrtc/src/media/index.js +1 -0
- package/lib/webrtc/src/media/index.js.map +1 -1
- package/lib/webrtc/src/media/parameters.d.ts +5 -0
- package/lib/webrtc/src/media/parameters.js +10 -0
- package/lib/webrtc/src/media/parameters.js.map +1 -1
- package/lib/webrtc/src/media/receiver/nack.d.ts +43 -10
- package/lib/webrtc/src/media/receiver/nack.js +245 -88
- package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
- package/lib/webrtc/src/media/receiver/receiverTwcc.d.ts +10 -0
- package/lib/webrtc/src/media/receiver/receiverTwcc.js +4 -10
- package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
- package/lib/webrtc/src/media/router.d.ts +245 -51
- package/lib/webrtc/src/media/router.js +702 -237
- package/lib/webrtc/src/media/router.js.map +1 -1
- package/lib/webrtc/src/media/routing/pendingRoutes.d.ts +26 -0
- package/lib/webrtc/src/media/routing/pendingRoutes.js +48 -0
- package/lib/webrtc/src/media/routing/pendingRoutes.js.map +1 -0
- package/lib/webrtc/src/media/routing/ridRouting.d.ts +37 -0
- package/lib/webrtc/src/media/routing/ridRouting.js +74 -0
- package/lib/webrtc/src/media/routing/ridRouting.js.map +1 -0
- package/lib/webrtc/src/media/routing/routeTable.d.ts +60 -0
- package/lib/webrtc/src/media/routing/routeTable.js +95 -0
- package/lib/webrtc/src/media/routing/routeTable.js.map +1 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.d.ts +34 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.js +165 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.js.map +1 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.d.ts +55 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.js +117 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.js.map +1 -0
- package/lib/webrtc/src/media/rtpReceiver.d.ts +277 -5
- package/lib/webrtc/src/media/rtpReceiver.js +826 -36
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpSender.d.ts +8 -1
- package/lib/webrtc/src/media/rtpSender.js +13 -6
- package/lib/webrtc/src/media/rtpSender.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +47 -11
- package/lib/webrtc/src/media/rtpTransceiver.js +95 -11
- package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
- package/lib/webrtc/src/media/sender/senderReportHistory.d.ts +51 -0
- package/lib/webrtc/src/media/sender/senderReportHistory.js +111 -0
- package/lib/webrtc/src/media/sender/senderReportHistory.js.map +1 -0
- package/lib/webrtc/src/media/sender/senderStats.d.ts +6 -5
- package/lib/webrtc/src/media/sender/senderStats.js +14 -19
- package/lib/webrtc/src/media/sender/senderStats.js.map +1 -1
- package/lib/webrtc/src/media/stats.d.ts +13 -0
- package/lib/webrtc/src/media/stats.js.map +1 -1
- package/lib/webrtc/src/media/track.d.ts +112 -11
- package/lib/webrtc/src/media/track.js +250 -19
- package/lib/webrtc/src/media/track.js.map +1 -1
- package/lib/webrtc/src/media/trackConstraints.d.ts +80 -0
- package/lib/webrtc/src/media/trackConstraints.js +141 -0
- package/lib/webrtc/src/media/trackConstraints.js.map +1 -0
- package/lib/webrtc/src/negotiation/internalState.d.ts +0 -4
- package/lib/webrtc/src/negotiation/internalState.js +0 -11
- package/lib/webrtc/src/negotiation/internalState.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.d.ts +20 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.js +29 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +23 -6
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js +46 -22
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -1
- package/lib/webrtc/src/negotiation/transceiverPairing.d.ts +1 -0
- package/lib/webrtc/src/negotiation/transceiverPairing.js +62 -0
- package/lib/webrtc/src/negotiation/transceiverPairing.js.map +1 -0
- package/lib/webrtc/src/negotiation/transportActivation.d.ts +12 -1
- package/lib/webrtc/src/negotiation/transportActivation.js +133 -11
- package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -1
- package/lib/webrtc/src/negotiationTransaction.d.ts +57 -5
- package/lib/webrtc/src/negotiationTransaction.js +134 -10
- package/lib/webrtc/src/negotiationTransaction.js.map +1 -1
- package/lib/webrtc/src/nonstandard/dummyMedia.d.ts +6 -0
- package/lib/webrtc/src/nonstandard/dummyMedia.js +14 -19
- package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
- package/lib/webrtc/src/nonstandard/navigator.d.ts +1 -1
- package/lib/webrtc/src/nonstandard/recorder/index.js +5 -1
- package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.d.ts +6 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +31 -2
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.d.ts +16 -0
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.js +25 -0
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia.js +6 -13
- package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +106 -11
- package/lib/webrtc/src/peerConnection.js +370 -36
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/polyfill/api.d.ts +2 -1
- package/lib/webrtc/src/polyfill/api.js +3 -3
- package/lib/webrtc/src/polyfill/api.js.map +1 -1
- package/lib/webrtc/src/polyfill/dom.d.ts +21 -7
- package/lib/webrtc/src/polyfill/dom.js +15 -0
- package/lib/webrtc/src/polyfill/dom.js.map +1 -1
- package/lib/webrtc/src/polyfill/globals.d.ts +8 -3
- package/lib/webrtc/src/polyfill/globals.js.map +1 -1
- package/lib/webrtc/src/polyfill/index.d.ts +1 -1
- package/lib/webrtc/src/polyfill/index.js +1 -1
- package/lib/webrtc/src/polyfill/index.js.map +1 -1
- package/lib/webrtc/src/polyfill/install.d.ts +5 -1
- package/lib/webrtc/src/polyfill/install.js +4 -2
- package/lib/webrtc/src/polyfill/install.js.map +1 -1
- package/lib/webrtc/src/polyfill/mediaDevices.js +28 -4
- package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
- package/lib/webrtc/src/polyfill/peerConnectionConfig.d.ts +6 -0
- package/lib/webrtc/src/polyfill/peerConnectionConfig.js +15 -4
- package/lib/webrtc/src/polyfill/peerConnectionConfig.js.map +1 -1
- package/lib/webrtc/src/polyfill/selectSettings.d.ts +4 -14
- package/lib/webrtc/src/polyfill/selectSettings.js +10 -106
- package/lib/webrtc/src/polyfill/selectSettings.js.map +1 -1
- package/lib/webrtc/src/polyfill/sourceIo.d.ts +1 -2
- package/lib/webrtc/src/polyfill/sourceIo.js +6 -6
- package/lib/webrtc/src/polyfill/sourceIo.js.map +1 -1
- package/lib/webrtc/src/sctpManager.d.ts +31 -18
- package/lib/webrtc/src/sctpManager.js +162 -38
- package/lib/webrtc/src/sctpManager.js.map +1 -1
- package/lib/webrtc/src/sdp.d.ts +107 -2
- package/lib/webrtc/src/sdp.js +223 -17
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/sdpManager.d.ts +101 -10
- package/lib/webrtc/src/sdpManager.js +236 -14
- package/lib/webrtc/src/sdpManager.js.map +1 -1
- package/lib/webrtc/src/secureTransportManager.d.ts +49 -3
- package/lib/webrtc/src/secureTransportManager.js +166 -12
- package/lib/webrtc/src/secureTransportManager.js.map +1 -1
- package/lib/webrtc/src/transceiverManager.d.ts +87 -6
- package/lib/webrtc/src/transceiverManager.js +272 -51
- package/lib/webrtc/src/transceiverManager.js.map +1 -1
- package/lib/webrtc/src/transport/dtls-application-gate.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-application-gate.js +143 -0
- package/lib/webrtc/src/transport/dtls-application-gate.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-attempt.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-attempt.js +79 -0
- package/lib/webrtc/src/transport/dtls-attempt.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-certificate.d.ts +24 -0
- package/lib/webrtc/src/transport/dtls-certificate.js +98 -0
- package/lib/webrtc/src/transport/dtls-certificate.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-fingerprint.d.ts +7 -0
- package/lib/webrtc/src/transport/dtls-fingerprint.js +66 -0
- package/lib/webrtc/src/transport/dtls-fingerprint.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-ice-transport.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-ice-transport.js +123 -0
- package/lib/webrtc/src/transport/dtls-ice-transport.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-media-queue.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-media-queue.js +95 -0
- package/lib/webrtc/src/transport/dtls-media-queue.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-readiness.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-readiness.js +173 -0
- package/lib/webrtc/src/transport/dtls-readiness.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-sped-handshake.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-sped-handshake.js +146 -0
- package/lib/webrtc/src/transport/dtls-sped-handshake.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-srtp.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-srtp.js +133 -0
- package/lib/webrtc/src/transport/dtls-srtp.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-stats.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-stats.js +134 -0
- package/lib/webrtc/src/transport/dtls-stats.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-types.d.ts +23 -0
- package/lib/webrtc/src/transport/dtls-types.js +11 -0
- package/lib/webrtc/src/transport/dtls-types.js.map +1 -0
- package/lib/webrtc/src/transport/dtls.d.ts +236 -47
- package/lib/webrtc/src/transport/dtls.js +1198 -441
- package/lib/webrtc/src/transport/dtls.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +95 -5
- package/lib/webrtc/src/transport/ice.js +323 -21
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/lib/webrtc/src/transport/iceCandidateAttribute.d.ts +4 -2
- package/lib/webrtc/src/transport/iceCandidateAttribute.js.map +1 -1
- package/lib/webrtc/src/transport/sctp.d.ts +149 -2
- package/lib/webrtc/src/transport/sctp.js +826 -128
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/lib/webrtc/src/transport/sped.d.ts +139 -0
- package/lib/webrtc/src/transport/sped.js +757 -0
- package/lib/webrtc/src/transport/sped.js.map +1 -0
- package/lib/webrtc/src/types/util.d.ts +6 -0
- package/lib/webrtc/src/types/util.js.map +1 -1
- package/lib/webrtc/src/utils.d.ts +34 -1
- package/lib/webrtc/src/utils.js +52 -3
- package/lib/webrtc/src/utils.js.map +1 -1
- package/lib/webrtc/src/webidl.d.ts +15 -0
- package/lib/webrtc/src/webidl.js +34 -0
- package/lib/webrtc/src/webidl.js.map +1 -0
- package/package.json +8 -3
- package/lib/webrtc/src/polyfill/rtcSessionDescription.d.ts +0 -18
- package/lib/webrtc/src/polyfill/rtcSessionDescription.js +0 -36
- package/lib/webrtc/src/polyfill/rtcSessionDescription.js.map +0 -1
package/lib/ice/src/iceBase.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultOptions = exports.CandidatePairState = exports.CONSENT_RESPONSE_TIMEOUT_MIN = exports.CONSENT_RESPONSE_TIMEOUT = exports.CONSENT_TIMEOUT = exports.CONSENT_FAILURES = exports.CONSENT_INTERVAL = exports.ICE_FAILED = exports.ICE_COMPLETED = exports.CandidatePair = void 0;
|
|
3
|
+
exports.defaultOptions = exports.CandidatePairState = exports.RTT_SMOOTHING_MIN_SAMPLES = exports.RTT_SMOOTHING_SAMPLES = exports.RTT_SWITCH_MIN_IMPROVEMENT = exports.FAILOVER_RECOVERY_RESPONSES = exports.FAILOVER_BACKUP_ATTEMPTS = exports.FAILOVER_CONSENT_EXPIRED_GRACE = exports.BACKUP_UNKNOWN_RTT_RESPONSE_TIMEOUT = exports.DEAD_CONNECTION_RECEIVE_TIMEOUT = exports.RECEIVING_SWITCHING_DELAY = exports.WEAK_CONNECTION_RECEIVE_TIMEOUT = exports.CONNECTION_WRITE_CONNECT_TIMEOUT = exports.CONNECTION_WRITE_CONNECT_FAILURES = exports.MIN_PINGS_AT_WEAK_PING_INTERVAL = exports.STABLE_WRITABLE_CONNECTION_PING_INTERVAL = exports.WEAK_OR_STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL = exports.CONSENT_RESPONSE_TIMEOUT_MIN = exports.CONSENT_RESPONSE_TIMEOUT = exports.CONSENT_TIMEOUT = exports.CONSENT_FAILURES = exports.CONSENT_INTERVAL = exports.ICE_FAILED = exports.ICE_COMPLETED = exports.DEFAULT_INCOMING_CHECK_TIMEOUT = exports.CandidatePair = void 0;
|
|
4
4
|
exports.consentResponseTimeoutMs = consentResponseTimeoutMs;
|
|
5
5
|
exports.validateRemoteCandidate = validateRemoteCandidate;
|
|
6
6
|
exports.sortCandidatePairs = sortCandidatePairs;
|
|
7
7
|
exports.candidatePairPriority = candidatePairPriority;
|
|
8
|
+
exports.compareCandidatePairPriority = compareCandidatePairPriority;
|
|
9
|
+
exports.queryServerReflexiveCandidate = queryServerReflexiveCandidate;
|
|
8
10
|
exports.serverReflexiveCandidate = serverReflexiveCandidate;
|
|
9
11
|
exports.validateAddress = validateAddress;
|
|
10
12
|
exports.normalizeIceServerOptions = normalizeIceServerOptions;
|
|
@@ -14,6 +16,7 @@ exports.hasTurnServer = hasTurnServer;
|
|
|
14
16
|
exports.isCandidateAllowedByGatherOptions = isCandidateAllowedByGatherOptions;
|
|
15
17
|
const crypto_1 = require("crypto");
|
|
16
18
|
const candidate_1 = require("./candidate");
|
|
19
|
+
const candidateError_1 = require("./candidateError");
|
|
17
20
|
const common_1 = require("./imports/common");
|
|
18
21
|
const const_1 = require("./stun/const");
|
|
19
22
|
const message_1 = require("./stun/message");
|
|
@@ -22,6 +25,37 @@ class CandidatePair {
|
|
|
22
25
|
get state() {
|
|
23
26
|
return this._state;
|
|
24
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Record the RTT (seconds) of an answered check: the totals, the samples of
|
|
30
|
+
* {@link smoothedRtt} and, unless `latest` is false (a response to an older
|
|
31
|
+
* check than the one `rtt` came from), `rtt`.
|
|
32
|
+
* @see tests/ice/selection-controller.test.ts "a response to an older check (latest: false) counts for the totals and the smoothed RTT, not the current RTT"
|
|
33
|
+
*/
|
|
34
|
+
recordRoundTrip(rtt, { latest = true } = {}) {
|
|
35
|
+
if (latest)
|
|
36
|
+
this.rtt = rtt;
|
|
37
|
+
this.totalRoundTripTime += rtt;
|
|
38
|
+
this.roundTripTimeMeasurements++;
|
|
39
|
+
this.rttSamples.push(rtt);
|
|
40
|
+
if (this.rttSamples.length > exports.RTT_SMOOTHING_SAMPLES)
|
|
41
|
+
this.rttSamples.shift();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The smoothed RTT (seconds) the selection switches by: the median of the
|
|
45
|
+
* last {@link RTT_SMOOTHING_SAMPLES} samples, undefined with fewer than
|
|
46
|
+
* {@link RTT_SMOOTHING_MIN_SAMPLES}.
|
|
47
|
+
* @see tests/ice/selection-controller.test.ts "the median of the last 5 samples: one outlier does not move it"
|
|
48
|
+
* @see tests/ice/selection-controller.test.ts "equal priority: one outlier RTT of the other pair does not move the selection"
|
|
49
|
+
*/
|
|
50
|
+
get smoothedRtt() {
|
|
51
|
+
if (this.rttSamples.length < exports.RTT_SMOOTHING_MIN_SAMPLES)
|
|
52
|
+
return undefined;
|
|
53
|
+
const sorted = [...this.rttSamples].sort((a, b) => a - b);
|
|
54
|
+
const middle = sorted.length >> 1;
|
|
55
|
+
return sorted.length % 2
|
|
56
|
+
? sorted[middle]
|
|
57
|
+
: (sorted[middle - 1] + sorted[middle]) / 2;
|
|
58
|
+
}
|
|
25
59
|
toJSON() {
|
|
26
60
|
return this.json;
|
|
27
61
|
}
|
|
@@ -75,6 +109,28 @@ class CandidatePair {
|
|
|
75
109
|
writable: true,
|
|
76
110
|
value: false
|
|
77
111
|
});
|
|
112
|
+
/**
|
|
113
|
+
* The largest nomination the peer sent for this pair while this agent was
|
|
114
|
+
* controlled: the NOMINATION attribute's value (renomination), or 1 for
|
|
115
|
+
* USE-CANDIDATE. The controlled agent selects the nominated pair with the
|
|
116
|
+
* largest value, the higher-priority one between equal values.
|
|
117
|
+
*/
|
|
118
|
+
Object.defineProperty(this, "remoteNomination", {
|
|
119
|
+
enumerable: true,
|
|
120
|
+
configurable: true,
|
|
121
|
+
writable: true,
|
|
122
|
+
value: 0
|
|
123
|
+
});
|
|
124
|
+
/**
|
|
125
|
+
* The NOMINATION value this agent (controlling, renomination) sent for the
|
|
126
|
+
* pair and the peer answered; 0 when it did not renominate the pair.
|
|
127
|
+
*/
|
|
128
|
+
Object.defineProperty(this, "nomination", {
|
|
129
|
+
enumerable: true,
|
|
130
|
+
configurable: true,
|
|
131
|
+
writable: true,
|
|
132
|
+
value: 0
|
|
133
|
+
});
|
|
78
134
|
// 5.7.4. Computing States
|
|
79
135
|
Object.defineProperty(this, "_state", {
|
|
80
136
|
enumerable: true,
|
|
@@ -173,6 +229,13 @@ class CandidatePair {
|
|
|
173
229
|
writable: true,
|
|
174
230
|
value: new Set()
|
|
175
231
|
});
|
|
232
|
+
/** The most recent RTT samples (seconds), oldest first (see `smoothedRtt`). */
|
|
233
|
+
Object.defineProperty(this, "rttSamples", {
|
|
234
|
+
enumerable: true,
|
|
235
|
+
configurable: true,
|
|
236
|
+
writable: true,
|
|
237
|
+
value: []
|
|
238
|
+
});
|
|
176
239
|
this.protocol = protocol;
|
|
177
240
|
this.remoteCandidate = remoteCandidate;
|
|
178
241
|
this.iceControlling = iceControlling;
|
|
@@ -209,6 +272,8 @@ class CandidatePair {
|
|
|
209
272
|
}
|
|
210
273
|
}
|
|
211
274
|
exports.CandidatePair = CandidatePair;
|
|
275
|
+
/** Default of {@link IceOptions.incomingCheckTimeout}, in seconds. */
|
|
276
|
+
exports.DEFAULT_INCOMING_CHECK_TIMEOUT = 30;
|
|
212
277
|
exports.ICE_COMPLETED = 1;
|
|
213
278
|
exports.ICE_FAILED = 2;
|
|
214
279
|
/** Basic consent check period in seconds (RFC 7675). Actual interval is 0.8–1.2× this. */
|
|
@@ -221,17 +286,127 @@ exports.CONSENT_FAILURES = 6;
|
|
|
221
286
|
/** RFC 7675: consent expires this many seconds after the last valid response. */
|
|
222
287
|
exports.CONSENT_TIMEOUT = 30;
|
|
223
288
|
/**
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
* answer in 150–300ms
|
|
289
|
+
* RTT-based response deadline of a consent request (ms) when the RTT is
|
|
290
|
+
* unknown (see {@link consentResponseTimeoutMs}). Downstream ICE-lite peers
|
|
291
|
+
* typically answer in 150–300ms. It is no longer how long the request's
|
|
292
|
+
* transaction stays open: that is {@link CONSENT_TIMEOUT}, so a response
|
|
293
|
+
* after this deadline still refreshes the consent.
|
|
227
294
|
*/
|
|
228
295
|
exports.CONSENT_RESPONSE_TIMEOUT = 1000;
|
|
229
296
|
/** RFC 8445 §14.3: ICE RTO must not be less than 500ms. */
|
|
230
297
|
exports.CONSENT_RESPONSE_TIMEOUT_MIN = 500;
|
|
298
|
+
// Failover of the selected pair without an ICE restart (semi-aggressive
|
|
299
|
+
// nomination and renomination, full ICE, not ICE-TCP). The values follow
|
|
300
|
+
// libwebrtc (`p2p/base/connection.h`, `p2p/base/ice_controller_interface.h`,
|
|
301
|
+
// `basic_ice_controller.cc`); the libwebrtc name is given where it differs.
|
|
302
|
+
/**
|
|
303
|
+
* Ping interval (ms) of a pair that is weak (a check went unanswered) or
|
|
304
|
+
* stabilizing (fewer than {@link MIN_PINGS_AT_WEAK_PING_INTERVAL} responses
|
|
305
|
+
* since it began to be monitored). libwebrtc:
|
|
306
|
+
* `WEAK_OR_STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL`.
|
|
307
|
+
*/
|
|
308
|
+
exports.WEAK_OR_STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL = 900;
|
|
309
|
+
/**
|
|
310
|
+
* Ping interval (ms) of a stable backup pair (multiplied by a random 0.8–1.2).
|
|
311
|
+
* libwebrtc: `STABLE_WRITABLE_CONNECTION_PING_INTERVAL`.
|
|
312
|
+
*/
|
|
313
|
+
exports.STABLE_WRITABLE_CONNECTION_PING_INTERVAL = 2500;
|
|
314
|
+
/**
|
|
315
|
+
* Responses a pair needs, pinged at the weak interval, before it counts as
|
|
316
|
+
* stable. libwebrtc: `MIN_PINGS_AT_WEAK_PING_INTERVAL`.
|
|
317
|
+
*/
|
|
318
|
+
exports.MIN_PINGS_AT_WEAK_PING_INTERVAL = 3;
|
|
319
|
+
/**
|
|
320
|
+
* A pair is no longer writable once at least this many consecutive checks
|
|
321
|
+
* went unanswered and {@link CONNECTION_WRITE_CONNECT_TIMEOUT} passed since
|
|
322
|
+
* its last response. libwebrtc: `CONNECTION_WRITE_CONNECT_FAILURES`.
|
|
323
|
+
*/
|
|
324
|
+
exports.CONNECTION_WRITE_CONNECT_FAILURES = 5;
|
|
325
|
+
/** See {@link CONNECTION_WRITE_CONNECT_FAILURES} (ms). libwebrtc: `CONNECTION_WRITE_CONNECT_TIMEOUT`. */
|
|
326
|
+
exports.CONNECTION_WRITE_CONNECT_TIMEOUT = 5000;
|
|
327
|
+
/**
|
|
328
|
+
* A pair that received nothing (response, request or data) for this long
|
|
329
|
+
* (ms) is weak. libwebrtc: `WEAK_CONNECTION_RECEIVE_TIMEOUT`.
|
|
330
|
+
*/
|
|
331
|
+
exports.WEAK_CONNECTION_RECEIVE_TIMEOUT = 2500;
|
|
332
|
+
/**
|
|
333
|
+
* How long (ms) the selected pair must have stopped receiving (nothing
|
|
334
|
+
* received for {@link WEAK_CONNECTION_RECEIVE_TIMEOUT}) before the
|
|
335
|
+
* controlling agent fails over to a backup that receives, without waiting
|
|
336
|
+
* for the selected pair to become unwritable. libwebrtc:
|
|
337
|
+
* `receiving_switching_delay` (default 1000 ms).
|
|
338
|
+
*/
|
|
339
|
+
exports.RECEIVING_SWITCHING_DELAY = 1000;
|
|
340
|
+
/**
|
|
341
|
+
* A backup pair that received nothing for this long (ms) is dropped (its
|
|
342
|
+
* state becomes Failed) and the next pair of its socket is monitored. The
|
|
343
|
+
* same value as {@link CONSENT_TIMEOUT}. libwebrtc:
|
|
344
|
+
* `DEAD_CONNECTION_RECEIVE_TIMEOUT`.
|
|
345
|
+
*/
|
|
346
|
+
exports.DEAD_CONNECTION_RECEIVE_TIMEOUT = exports.CONSENT_TIMEOUT * 1000;
|
|
347
|
+
/**
|
|
348
|
+
* Response timeout (ms) of a backup check while the pair's RTT is still
|
|
349
|
+
* unknown (it never answered a check of this agent). libwebrtc starts a
|
|
350
|
+
* connection's RTT estimate at `DEFAULT_RTT` (3000 ms); the consent default
|
|
351
|
+
* ({@link CONSENT_RESPONSE_TIMEOUT}, 1 s) would never let a backup path
|
|
352
|
+
* slower than that become valid. Once the pair answered, the timeout follows
|
|
353
|
+
* its RTT ({@link consentResponseTimeoutMs}).
|
|
354
|
+
*/
|
|
355
|
+
exports.BACKUP_UNKNOWN_RTT_RESPONSE_TIMEOUT = 3000;
|
|
356
|
+
/**
|
|
357
|
+
* After the selected pair's consent expired (RFC 7675: no more application
|
|
358
|
+
* data on it), how long (ms) the agent stays `disconnected` waiting for the
|
|
359
|
+
* selection to move to a writable backup (its own failover nomination, or
|
|
360
|
+
* the peer's when controlled) before it fails. A peer that fails over does
|
|
361
|
+
* so 5–10 s after the path broke, long before the 30 s expiry; the grace
|
|
362
|
+
* covers a nomination still in flight. werift's own value.
|
|
363
|
+
*/
|
|
364
|
+
exports.FAILOVER_CONSENT_EXPIRED_GRACE = 10000;
|
|
365
|
+
/**
|
|
366
|
+
* Pairs of one local socket (or TURN allocation) tried as its backup before
|
|
367
|
+
* the socket waits for a retry (1, 2, 4, 8, 16 s, then every 16 s) and starts
|
|
368
|
+
* again from its highest-priority pair. werift's own limit.
|
|
369
|
+
*/
|
|
370
|
+
exports.FAILOVER_BACKUP_ATTEMPTS = 3;
|
|
371
|
+
/**
|
|
372
|
+
* Consecutive responses a pair the agent failed over from needs before the
|
|
373
|
+
* selection may move back to it (or to another pair of its socket). Keeps
|
|
374
|
+
* the selection from flapping. werift's own value (libwebrtc relies on
|
|
375
|
+
* {@link MIN_PINGS_AT_WEAK_PING_INTERVAL} for the same purpose).
|
|
376
|
+
*/
|
|
377
|
+
exports.FAILOVER_RECOVERY_RESPONSES = 3;
|
|
378
|
+
/**
|
|
379
|
+
* Between pairs of equal state and priority, the selection moves only to a
|
|
380
|
+
* pair whose smoothed RTT ({@link CandidatePair.smoothedRtt}) is at least this
|
|
381
|
+
* much (ms) lower. libwebrtc: `kMinImprovement`.
|
|
382
|
+
* @see tests/ice/selection-controller.test.ts "equal priority: a pair only 9 ms faster does not take the selection"
|
|
383
|
+
*/
|
|
384
|
+
exports.RTT_SWITCH_MIN_IMPROVEMENT = 10;
|
|
385
|
+
/**
|
|
386
|
+
* The RTT samples {@link CandidatePair.smoothedRtt} keeps (the most recent
|
|
387
|
+
* ones). werift's own value: libwebrtc keeps a moving average instead, which
|
|
388
|
+
* one outlier still moves.
|
|
389
|
+
* @see tests/ice/selection-controller.test.ts "the median of the last 5 samples: one outlier does not move it"
|
|
390
|
+
*/
|
|
391
|
+
exports.RTT_SMOOTHING_SAMPLES = 5;
|
|
392
|
+
/**
|
|
393
|
+
* Samples a pair needs before {@link CandidatePair.smoothedRtt} has a value
|
|
394
|
+
* (the RTT takes part in a switch). The same as
|
|
395
|
+
* {@link MIN_PINGS_AT_WEAK_PING_INTERVAL}: a backup is stable from then on.
|
|
396
|
+
* @see tests/ice/selection-controller.test.ts "the median of the last 5 samples: one outlier does not move it"
|
|
397
|
+
*/
|
|
398
|
+
exports.RTT_SMOOTHING_MIN_SAMPLES = 3;
|
|
231
399
|
/**
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
400
|
+
* RTT-based response deadline (ms) from a pair RTT (seconds): when a consent
|
|
401
|
+
* request without a response counts as unanswered (failover's pacing and
|
|
402
|
+
* writability), and the response timeout of a backup check once the backup's
|
|
403
|
+
* RTT is known. Uses 2×RTT + 200ms jitter margin, floored at
|
|
404
|
+
* {@link CONSENT_RESPONSE_TIMEOUT_MIN}. Falls back to
|
|
405
|
+
* {@link CONSENT_RESPONSE_TIMEOUT} when RTT is unavailable.
|
|
406
|
+
*
|
|
407
|
+
* A consent request's transaction is not ended at this deadline: it stays
|
|
408
|
+
* open for {@link CONSENT_TIMEOUT}, so a response slower than the estimate
|
|
409
|
+
* (an RTT that rose after the selection) still refreshes the consent.
|
|
235
410
|
*/
|
|
236
411
|
function consentResponseTimeoutMs(rttSeconds) {
|
|
237
412
|
if (rttSeconds === undefined ||
|
|
@@ -267,39 +442,66 @@ function validateRemoteCandidate(candidate) {
|
|
|
267
442
|
return candidate;
|
|
268
443
|
}
|
|
269
444
|
function sortCandidatePairs(pairs, iceControlling) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
445
|
+
// Highest priority first; pairs of equal priority keep their order.
|
|
446
|
+
return pairs.sort((a, b) => compareCandidatePairPriority(b.localCandidate, b.remoteCandidate, a.localCandidate, a.remoteCandidate, iceControlling));
|
|
447
|
+
}
|
|
448
|
+
/** RFC 8445 §6.1.2.3: G is the controlling agent's candidate priority, D the controlled one's. */
|
|
449
|
+
function pairPriorityTerms(local, remote, iceControlling) {
|
|
450
|
+
const G = iceControlling ? local.priority : remote.priority;
|
|
451
|
+
const D = iceControlling ? remote.priority : local.priority;
|
|
452
|
+
return { min: Math.min(G, D), max: Math.max(G, D), tie: G > D ? 1 : 0 };
|
|
274
453
|
}
|
|
275
454
|
// 5.7.2. Computing Pair Priority and Ordering Pairs
|
|
455
|
+
/**
|
|
456
|
+
* `2^32 * MIN(G,D) + 2 * MAX(G,D) + (G > D ? 1 : 0)` (RFC 8445 §6.1.2.3).
|
|
457
|
+
* The value can exceed `Number.MAX_SAFE_INTEGER`, so it is approximate;
|
|
458
|
+
* order pairs with `compareCandidatePairPriority`, which is exact.
|
|
459
|
+
*/
|
|
276
460
|
function candidatePairPriority(local, remote, iceControlling) {
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
return (1 << 32) * Math.min(G, D) + 2 * Math.max(G, D) + (G > D ? 1 : 0);
|
|
461
|
+
const { min, max, tie } = pairPriorityTerms(local, remote, iceControlling);
|
|
462
|
+
return 2 ** 32 * min + 2 * max + tie;
|
|
280
463
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
464
|
+
/**
|
|
465
|
+
* Exact comparison of two pair priorities (RFC 8445 §6.1.2.3): negative
|
|
466
|
+
* when pair `a` has the lower priority, positive when the higher, 0 when equal.
|
|
467
|
+
*/
|
|
468
|
+
function compareCandidatePairPriority(aLocal, aRemote, bLocal, bRemote, iceControlling) {
|
|
469
|
+
const a = pairPriorityTerms(aLocal, aRemote, iceControlling);
|
|
470
|
+
const b = pairPriorityTerms(bLocal, bRemote, iceControlling);
|
|
471
|
+
return a.min - b.min || a.max - b.max || a.tie - b.tie;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Query `stunServer` from `protocol` for a server-reflexive candidate.
|
|
475
|
+
* Unlike {@link serverReflexiveCandidate} it rejects with the reason of a
|
|
476
|
+
* failure. `base` is used for wildcard sockets that advertise no host
|
|
477
|
+
* candidate themselves.
|
|
478
|
+
*/
|
|
479
|
+
async function queryServerReflexiveCandidate(protocol, stunServer, base) {
|
|
480
|
+
const localCandidate = base ?? protocol.localCandidate;
|
|
481
|
+
if (!localCandidate) {
|
|
482
|
+
throw new Error("protocol has no local candidate");
|
|
483
|
+
}
|
|
286
484
|
const request = new message_1.Message(const_1.methods.BINDING, const_1.classes.REQUEST);
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
throw new Error("not exist");
|
|
292
|
-
}
|
|
293
|
-
const candidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("srflx", localCandidate.transport, localCandidate.host), localCandidate.component, localCandidate.transport, (0, candidate_1.candidatePriority)("srflx", {
|
|
294
|
-
transport: localCandidate.transport,
|
|
295
|
-
tcptype: localCandidate.tcptype,
|
|
296
|
-
}), response.getAttributeValue("XOR-MAPPED-ADDRESS")[0], response.getAttributeValue("XOR-MAPPED-ADDRESS")[1], "srflx", localCandidate.host, localCandidate.port, localCandidate.tcptype);
|
|
297
|
-
return candidate;
|
|
485
|
+
const [response] = await protocol.request(request, stunServer);
|
|
486
|
+
const mapped = response.getAttributeValue("XOR-MAPPED-ADDRESS");
|
|
487
|
+
if (!mapped) {
|
|
488
|
+
throw new candidateError_1.MissingMappedAddressError(stunServer);
|
|
298
489
|
}
|
|
299
|
-
|
|
300
|
-
|
|
490
|
+
return new candidate_1.Candidate((0, candidate_1.candidateFoundation)("srflx", localCandidate.transport, localCandidate.host), localCandidate.component, localCandidate.transport, (0, candidate_1.candidatePriority)("srflx", {
|
|
491
|
+
transport: localCandidate.transport,
|
|
492
|
+
tcptype: localCandidate.tcptype,
|
|
493
|
+
}), mapped[0], mapped[1], "srflx", localCandidate.host, localCandidate.port, localCandidate.tcptype);
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Query a STUN server for a server-reflexive candidate. This compatibility
|
|
497
|
+
* helper resolves `undefined` on failure; use
|
|
498
|
+
* {@link queryServerReflexiveCandidate} when the failure reason is needed.
|
|
499
|
+
*/
|
|
500
|
+
async function serverReflexiveCandidate(protocol, stunServer, base) {
|
|
501
|
+
return queryServerReflexiveCandidate(protocol, stunServer, base).catch((error) => {
|
|
301
502
|
log("error serverReflexiveCandidate", error);
|
|
302
|
-
|
|
503
|
+
return undefined;
|
|
504
|
+
});
|
|
303
505
|
}
|
|
304
506
|
function validateAddress(addr) {
|
|
305
507
|
if (addr && Number.isNaN(addr[1])) {
|
|
@@ -331,7 +533,8 @@ const sameAddress = (a, b) => a[0] === b[0] && a[1] === b[1];
|
|
|
331
533
|
* credential) are kept once, at their first position;
|
|
332
534
|
* - an invalid address (see {@link validateAddress}) is dropped, and so is a
|
|
333
535
|
* TURN server without username or password (it cannot allocate);
|
|
334
|
-
* - a TURN transport left unset is "udp"
|
|
536
|
+
* - a TURN transport left unset is "udp";
|
|
537
|
+
* - the `urls` of merged TURN duplicates are merged (in order, once each).
|
|
335
538
|
*
|
|
336
539
|
* The built-in default STUN server is not added here; Connection falls back
|
|
337
540
|
* to it when the result has no STUN server.
|
|
@@ -376,16 +579,25 @@ function normalizeIceServerOptions(options) {
|
|
|
376
579
|
log("TURN server without username / credential ignored", address);
|
|
377
580
|
continue;
|
|
378
581
|
}
|
|
582
|
+
const urls = Array.isArray(server.urls)
|
|
583
|
+
? server.urls.filter((url) => typeof url === "string")
|
|
584
|
+
: undefined;
|
|
379
585
|
const entry = {
|
|
380
586
|
address,
|
|
381
587
|
username,
|
|
382
588
|
password,
|
|
383
589
|
transport: server.transport ?? "udp",
|
|
590
|
+
...(urls ? { urls: [...new Set(urls)] } : {}),
|
|
384
591
|
};
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
592
|
+
const existing = turnServers.find((known) => sameAddress(known.address, entry.address) &&
|
|
593
|
+
known.transport === entry.transport &&
|
|
594
|
+
known.username === entry.username &&
|
|
595
|
+
known.password === entry.password);
|
|
596
|
+
if (existing) {
|
|
597
|
+
// One allocation serves both: it answers to every name of them.
|
|
598
|
+
if (entry.urls) {
|
|
599
|
+
existing.urls = [...new Set([...(existing.urls ?? []), ...entry.urls])];
|
|
600
|
+
}
|
|
389
601
|
continue;
|
|
390
602
|
}
|
|
391
603
|
turnServers.push(entry);
|
|
@@ -403,6 +615,7 @@ function mergeIceServerOptions(current, update) {
|
|
|
403
615
|
...current,
|
|
404
616
|
stunServer: update.stunServer,
|
|
405
617
|
stunServers: update.stunServers,
|
|
618
|
+
stunServerUrls: update.stunServerUrls,
|
|
406
619
|
turnServer: update.turnServer,
|
|
407
620
|
turnServers: update.turnServers,
|
|
408
621
|
turnUsername: update.turnUsername,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iceBase.js","sourceRoot":"","sources":["../../../../ice/src/iceBase.ts"],"names":[],"mappings":";;;AAsQA,4DAYC;AAmJD,0DASC;AAED,gDAsBC;AAGD,sDAQC;AAED,4DA0CC;AAED,0CAKC;AA2CD,8DA+DC;AAQD,sDAkBC;AAUD,oDAEC;AAMD,sCAEC;AAUD,8EAYC;AAlrBD,mCAAoC;AACpC,2CAAgF;AAGhF,6CAM0B;AAC1B,wCAAgD;AAChD,4CAAyC;AAGzC,MAAM,GAAG,GAAG,IAAA,cAAK,EA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AE3B,OAAO;QACL,GAAG,OAAO;QACV,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS;QAChD,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM;KACxC,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAAC,OAAsC;IACzE,OAAO,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;AAC7B,CAAC;AAED;;;GAGG;AACH,SAAgB,aAAa,CAAC,OAAwB;IACpD,OAAO,yBAAyB,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC;AACnE,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,iCAAiC,CAC/C,SAAgD,EAChD,OAEiB;IAEjB,IAAI,SAAS,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC;IAC9D,IAAI,oBAAoB,CAAC,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IAChD,IAAI,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,KAAK,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACnE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { randomUUID } from \"crypto\";\nimport { Candidate, candidateFoundation, candidatePriority } from \"./candidate\";\nimport type { MdnsLookup } from \"./dns/lookup\";\nimport type { Cancelable } from \"./helper\";\nimport {\n type Address,\n debug,\n type Event,\n type InterfaceAddresses,\n type TlsConnectionOptions,\n} from \"./imports/common\";\nimport { classes, methods } from \"./stun/const\";\nimport { Message } from \"./stun/message\";\nimport type { Protocol } from \"./types/model\";\n\nconst log = debug(\"werift-ice : packages/ice/src/ice.ts : log\");\n\nexport interface IceConnection {\n iceLite: boolean;\n iceControlling: boolean;\n localUsername: string;\n localPassword: string;\n remotePassword: string;\n remoteUsername: string;\n remoteIsLite: boolean;\n checkList: CandidatePair[];\n localCandidates: Candidate[];\n remoteCandidates: Candidate[];\n candidatePairs: CandidatePair[];\n /**\n * STUN servers gathering queries, normalized from the options (see\n * {@link normalizeIceServerOptions}). Optional so that other\n * implementations of this interface keep compiling.\n */\n stunServers?: Address[];\n /** TURN servers gathering allocates on, each with its own credential. */\n turnServers?: TurnServerOptions[];\n /** @deprecated The first of {@link IceConnection.stunServers}. */\n stunServer?: Address;\n /** @deprecated The address of the first of {@link IceConnection.turnServers}. */\n turnServer?: Address;\n generation: number;\n options: IceOptions;\n remoteCandidatesEnd: boolean;\n localCandidatesEnd: boolean;\n state: IceState;\n lookup?: MdnsLookup;\n nominated?: CandidatePair;\n\n readonly onData: Event<[Buffer]>;\n readonly stateChanged: Event<[IceState]>;\n readonly onIceCandidate: Event<[Candidate]>;\n\n restart(): void;\n /**\n * Optional staged-restart and provisional-generation support. An\n * implementation without them still restarts ICE at the final answer, but\n * cannot answer or run checks for the new generation during pranswer.\n */\n /**\n * `gatherOptions`: the options the staged generation gathers with (an ICE\n * server update applied at the commit); its provisional checks use only\n * the sockets those options allow. Defaults to the current options.\n */\n stageLocalCredentials?(\n usernameFragment: string,\n password: string,\n gatherOptions?: Partial<IceOptions>,\n ): void;\n discardStagedLocalCredentials?(usernameFragment: string): void;\n commitLocalCredentials?(usernameFragment: string, password: string): void;\n /**\n * The remote side alone restarted (new remote credentials in an answer):\n * drop the remote generation and its checks, keep the local credentials\n * and gathered candidates.\n */\n restartRemote?(): void;\n setProvisionalRemoteParams?(params: {\n usernameFragment: string;\n password: string;\n }): void;\n addProvisionalRemoteCandidate?(\n candidate: Candidate | undefined,\n ): Promise<void>;\n startProvisionalChecks?(): void;\n readonly provisionalNominated?: CandidatePair;\n\n setIceServers(options: Partial<IceOptions>): void;\n\n setRemoteParams(params: {\n iceLite: boolean;\n usernameFragment: string;\n password: string;\n }): void;\n\n /**\n * Gather the current generation's candidates. After an ICE restart the\n * candidates the kept sockets advertised are re-advertised synchronously;\n * only server work (STUN, TURN) is awaited.\n */\n gatherCandidates(): Promise<void>;\n\n /** Whether gathering contacts a STUN or TURN server. */\n readonly gathersFromServers?: boolean;\n\n connect(): Promise<void>;\n\n close(): Promise<void>;\n\n addRemoteCandidate(remoteCandidate: Candidate | undefined): Promise<void>;\n\n send(data: Buffer): Promise<void>;\n\n getDefaultCandidate(): Candidate | undefined;\n resetNominatedPair(): void;\n /** Drop remote candidates and pairs that name another remote ufrag. */\n dropOtherRemoteGenerations?(usernameFragment: string): void;\n}\n\nexport interface CandidatePairStats {\n packetsSent: number;\n packetsReceived: number;\n bytesSent: number;\n bytesReceived: number;\n rtt?: number;\n totalRoundTripTime: number;\n roundTripTimeMeasurements: number;\n requestsReceived: number;\n requestsSent: number;\n responsesReceived: number;\n responsesSent: number;\n retransmissionsReceived: number;\n retransmissionsSent: number;\n consentRequestsSent: number;\n}\n\nexport class CandidatePair implements CandidatePairStats {\n public protocol: Protocol;\n public remoteCandidate: Candidate;\n public iceControlling: boolean;\n\n readonly id = randomUUID().toString();\n handle?: Cancelable<void>;\n nominated = false;\n remoteNominated = false;\n // 5.7.4. Computing States\n private _state: CandidatePairState = CandidatePairState.FROZEN;\n get state() {\n return this._state;\n }\n\n // Statistics tracking\n packetsSent = 0;\n packetsReceived = 0;\n bytesSent = 0;\n bytesReceived = 0;\n rtt?: number;\n totalRoundTripTime = 0;\n roundTripTimeMeasurements = 0;\n requestsReceived = 0;\n requestsSent = 0;\n responsesReceived = 0;\n responsesSent = 0;\n retransmissionsReceived = 0;\n retransmissionsSent = 0;\n consentRequestsSent = 0;\n private readonly requestTransactionIds = new Set<string>();\n\n toJSON() {\n return this.json;\n }\n\n get json() {\n return {\n protocol: this.protocol.type,\n localCandidate: this.localCandidate.toSdp(),\n remoteCandidate: this.remoteCandidate.toSdp(),\n };\n }\n\n constructor(\n protocol: Protocol,\n remoteCandidate: Candidate,\n iceControlling: boolean,\n ) {\n this.protocol = protocol;\n this.remoteCandidate = remoteCandidate;\n this.iceControlling = iceControlling;\n }\n\n updateState(state: CandidatePairState) {\n this._state = state;\n }\n\n get localCandidate() {\n if (!this.protocol.localCandidate) {\n throw new Error(\"localCandidate not exist\");\n }\n return this.protocol.localCandidate;\n }\n\n get remoteAddr(): Address {\n return [this.remoteCandidate.host, this.remoteCandidate.port];\n }\n\n get component() {\n return this.localCandidate.component;\n }\n\n get priority() {\n return candidatePairPriority(\n this.localCandidate,\n this.remoteCandidate,\n this.iceControlling,\n );\n }\n\n get foundation() {\n return this.localCandidate.foundation;\n }\n\n noteIncomingRequest(transactionId: string) {\n const isRetransmission = this.requestTransactionIds.has(transactionId);\n if (!isRetransmission) {\n this.requestTransactionIds.add(transactionId);\n return false;\n }\n this.retransmissionsReceived++;\n return true;\n }\n}\n\nexport const ICE_COMPLETED = 1 as const;\nexport const ICE_FAILED = 2 as const;\n\n/** Basic consent check period in seconds (RFC 7675). Actual interval is 0.8–1.2× this. */\nexport const CONSENT_INTERVAL = 5;\n\n/**\n * @deprecated Consent expiry is based on {@link CONSENT_TIMEOUT} (30s after the\n * last valid response), not a consecutive failure count. Kept for API compatibility.\n */\nexport const CONSENT_FAILURES = 6;\n\n/** RFC 7675: consent expires this many seconds after the last valid response. */\nexport const CONSENT_TIMEOUT = 30;\n\n/**\n * Default single-shot response wait for consent requests (ms) when RTT is unknown.\n * Independent of retransmission count. Downstream ICE-lite peers typically\n * answer in 150–300ms; 1s is a conservative default used by interop patches.\n */\nexport const CONSENT_RESPONSE_TIMEOUT = 1000;\n\n/** RFC 8445 §14.3: ICE RTO must not be less than 500ms. */\nexport const CONSENT_RESPONSE_TIMEOUT_MIN = 500;\n\n/**\n * Compute consent response wait from pair RTT (seconds).\n * Uses 2×RTT + 200ms jitter margin, floored at {@link CONSENT_RESPONSE_TIMEOUT_MIN}.\n * Falls back to {@link CONSENT_RESPONSE_TIMEOUT} when RTT is unavailable.\n */\nexport function consentResponseTimeoutMs(rttSeconds?: number): number {\n if (\n rttSeconds === undefined ||\n !Number.isFinite(rttSeconds) ||\n rttSeconds <= 0\n ) {\n return CONSENT_RESPONSE_TIMEOUT;\n }\n return Math.max(\n CONSENT_RESPONSE_TIMEOUT_MIN,\n Math.round(rttSeconds * 1000 * 2 + 200),\n );\n}\n\n/**\n * @enum\n */\nexport const CandidatePairState = {\n FROZEN: 0,\n WAITING: 1,\n IN_PROGRESS: 2,\n SUCCEEDED: 3,\n FAILED: 4,\n} as const;\nexport type CandidatePairState =\n (typeof CandidatePairState)[keyof typeof CandidatePairState];\n\nexport type IceState =\n | \"disconnected\"\n | \"closed\"\n | \"completed\"\n | \"new\"\n | \"connected\"\n | \"failed\";\n\n/** A TURN server and the credential and transport used for it. */\nexport type TurnServerOptions = {\n address: Address;\n username: string;\n password: string;\n /** Defaults to \"udp\" (with a TCP fallback when the UDP allocation fails). */\n transport?: \"udp\" | \"tcp\" | \"tls\";\n};\n\nexport interface IceOptions {\n /** Advertise and operate as an ICE lite agent. */\n iceLite: boolean;\n useTcp: boolean;\n /**\n * Gather passive TCP host candidates (opens a listening TCP server per\n * interface). Defaults to true. Send-only agents that never accept inbound\n * connections can set this false to avoid the listener while still gathering\n * active TCP candidates.\n */\n tcpPassive?: boolean;\n /**\n * Seconds to wait for server-reflexive candidates while gathering.\n * Defaults to 5. Where UDP is blocked these STUN queries are never answered,\n * so the wait always runs to the timeout; agents that must not stall on such\n * networks can lower it.\n */\n stunGatherTimeout?: number;\n /**\n * Seconds to wait for a TURN TCP/TLS connection to be established.\n * Defaults to 8.\n */\n turnConnectTimeout?: number;\n /**\n * STUN servers queried while gathering, in priority order. Every IPv4 UDP\n * host socket queries each of them in parallel; equal mappings are\n * advertised once, different ones (a NAT that maps per destination) each.\n * Gathering ends when the slowest server answers or `stunGatherTimeout`\n * runs out.\n *\n * Merged with the deprecated `stunServer`: the singular one comes first,\n * duplicates are dropped (see {@link normalizeIceServerOptions}).\n */\n stunServers?: Address[];\n /**\n * TURN servers allocated on while gathering, in priority order. Each one\n * gets its own allocation with its own credential and transport; one that\n * fails or times out does not stop the others. Gathering ends when the\n * slowest allocation completes or fails (`turnConnectTimeout` bounds a\n * TCP/TLS connection, the STUN transaction timeout an unanswered request).\n * `turnTlsOptions`, `turnUdpFamily`, `turnConnectTimeout`, `portRange` and\n * `interfaceAddresses` apply to every TURN server.\n *\n * Merged with the deprecated `turnServer` / `turnUsername` /\n * `turnPassword` / `turnTransport`: the singular one comes first,\n * duplicates are dropped and an entry without username / password is\n * ignored (see {@link normalizeIceServerOptions}).\n */\n turnServers?: TurnServerOptions[];\n /** @deprecated Use {@link IceOptions.stunServers}. Kept as their first entry. */\n stunServer?: Address;\n /**\n * Whether the built-in public STUN server (stun.l.google.com:19302) is used\n * when no STUN server is given. Defaults to true; false gathers no\n * server-reflexive candidate unless a STUN server is set.\n */\n useDefaultStunServer?: boolean;\n /** @deprecated Use {@link IceOptions.turnServers}. Kept as their first entry. */\n turnServer?: Address;\n /** @deprecated Use {@link TurnServerOptions.username} of {@link IceOptions.turnServers}. */\n turnUsername?: string;\n /** @deprecated Use {@link TurnServerOptions.password} of {@link IceOptions.turnServers}. */\n turnPassword?: string;\n /** @deprecated Use {@link TurnServerOptions.transport} of {@link IceOptions.turnServers}. */\n turnTransport?: \"udp\" | \"tcp\" | \"tls\";\n /** Applied to every TLS TURN server. */\n turnTlsOptions?: TlsConnectionOptions;\n /**\n * Preferred IP family of a TURN/UDP socket, applied (to every TURN server)\n * only when the server is a hostname. Ignored for an IP literal server,\n * whose own family always selects the socket. Defaults to 4.\n */\n turnUdpFamily?: 4 | 6;\n forceTurn?: boolean;\n localPasswordPrefix?: string;\n useIpv4: boolean;\n useIpv6: boolean;\n useLinkLocalAddress?: boolean;\n portRange?: [number, number];\n /**\n * Local addresses to bind the UDP host sockets to, per family.\n *\n * The address given for a family (`udp4` / `udp6`) is the only host\n * address of that family: its UDP host candidate advertises the address and\n * port the socket is actually bound to, even when the address is not among\n * the enumerated network interfaces (loopback, tun, ...), and its TCP host\n * candidates use it too. Other enumerated addresses of that family are not\n * gathered. If the bind fails, the family has no UDP host candidate.\n *\n * A family left unspecified while the other one is set gathers no\n * enumerated addresses (only its `additionalHostAddresses`). Without any\n * family set, every enumerated address is gathered over wildcard sockets.\n */\n interfaceAddresses?: InterfaceAddresses;\n /**\n * Host addresses gathered in addition to the enumerated ones. For a family\n * bound by `interfaceAddresses`, addresses other than the bound one are\n * ignored.\n */\n additionalHostAddresses?: string[];\n filterStunResponse?: (\n message: Message,\n addr: Address,\n protocol: Protocol,\n ) => boolean;\n filterCandidatePair?: (pair: CandidatePair) => boolean;\n}\n\nexport const defaultOptions: IceOptions = {\n iceLite: false,\n useTcp: false,\n useIpv4: true,\n useIpv6: true,\n};\n\nexport function validateRemoteCandidate(candidate: Candidate) {\n // \"\"\"\n // Check the remote candidate is supported.\n // \"\"\"\n if (![\"host\", \"relay\", \"srflx\"].includes(candidate.type))\n throw new Error(`Unexpected candidate type \"${candidate.type}\"`);\n\n // ipaddress.ip_address(candidate.host)\n return candidate;\n}\n\nexport function sortCandidatePairs(\n pairs: {\n localCandidate: Pick<Candidate, \"priority\">;\n remoteCandidate: Pick<Candidate, \"priority\">;\n }[],\n iceControlling: boolean,\n) {\n return pairs\n .sort(\n (a, b) =>\n candidatePairPriority(\n a.localCandidate,\n a.remoteCandidate,\n iceControlling,\n ) -\n candidatePairPriority(\n b.localCandidate,\n b.remoteCandidate,\n iceControlling,\n ),\n )\n .reverse();\n}\n\n// 5.7.2. Computing Pair Priority and Ordering Pairs\nexport function candidatePairPriority(\n local: Pick<Candidate, \"priority\">,\n remote: Pick<Candidate, \"priority\">,\n iceControlling: boolean,\n) {\n const G = (iceControlling && local.priority) || remote.priority;\n const D = (iceControlling && remote.priority) || local.priority;\n return (1 << 32) * Math.min(G, D) + 2 * Math.max(G, D) + (G > D ? 1 : 0);\n}\n\nexport async function serverReflexiveCandidate(\n protocol: Protocol,\n stunServer: Address,\n) {\n // \"\"\"\n // Query STUN server to obtain a server-reflexive candidate.\n // \"\"\"\n\n // # perform STUN query\n const request = new Message(methods.BINDING, classes.REQUEST);\n try {\n const [response] = await protocol.request(request, stunServer);\n\n const localCandidate = protocol.localCandidate;\n if (!localCandidate) {\n throw new Error(\"not exist\");\n }\n\n const candidate = new Candidate(\n candidateFoundation(\n \"srflx\",\n localCandidate.transport,\n localCandidate.host,\n ),\n localCandidate.component,\n localCandidate.transport,\n candidatePriority(\"srflx\", {\n transport: localCandidate.transport,\n tcptype: localCandidate.tcptype,\n }),\n response.getAttributeValue(\"XOR-MAPPED-ADDRESS\")[0],\n response.getAttributeValue(\"XOR-MAPPED-ADDRESS\")[1],\n \"srflx\",\n localCandidate.host,\n localCandidate.port,\n localCandidate.tcptype,\n );\n return candidate;\n } catch (error) {\n // todo fix\n log(\"error serverReflexiveCandidate\", error);\n }\n}\n\nexport function validateAddress(addr?: Address): Address | undefined {\n if (addr && Number.isNaN(addr[1])) {\n return [addr[0], 443];\n }\n return addr;\n}\n\n/** The STUN/TURN server fields of {@link IceOptions}, singular and plural. */\nexport type IceServerFields = Partial<\n Pick<\n IceOptions,\n | \"stunServer\"\n | \"stunServers\"\n | \"turnServer\"\n | \"turnServers\"\n | \"turnUsername\"\n | \"turnPassword\"\n | \"turnTransport\"\n >\n>;\n\n/** A STUN/TURN server address: validated (see {@link validateAddress}) or undefined. */\nfunction validServerAddress(addr: unknown): Address | undefined {\n if (!Array.isArray(addr)) return undefined;\n const validated = validateAddress(addr as unknown as Address);\n if (!validated) return undefined;\n const [host, port] = validated;\n if (typeof host !== \"string\" || host === \"\") return undefined;\n if (typeof port !== \"number\" || !Number.isFinite(port)) return undefined;\n return validated;\n}\n\nconst sameAddress = (a: Address, b: Address) => a[0] === b[0] && a[1] === b[1];\n\n/**\n * The STUN and TURN servers `options` configure, the one place the singular\n * (deprecated) and plural fields are merged:\n *\n * - order: the singular server first, then the plural list in its order;\n * - duplicates (the same STUN address; the same TURN address, transport and\n * credential) are kept once, at their first position;\n * - an invalid address (see {@link validateAddress}) is dropped, and so is a\n * TURN server without username or password (it cannot allocate);\n * - a TURN transport left unset is \"udp\".\n *\n * The built-in default STUN server is not added here; Connection falls back\n * to it when the result has no STUN server.\n */\nexport function normalizeIceServerOptions(options: IceServerFields): {\n stunServers: Address[];\n turnServers: Required<TurnServerOptions>[];\n} {\n const stunServers: Address[] = [];\n for (const server of [options.stunServer, ...(options.stunServers ?? [])]) {\n if (server === undefined) continue;\n const address = validServerAddress(server);\n if (!address) {\n log(\"invalid STUN server ignored\", server);\n continue;\n }\n if (stunServers.some((existing) => sameAddress(existing, address))) {\n continue;\n }\n stunServers.push(address);\n }\n\n const turnServers: Required<TurnServerOptions>[] = [];\n const configured: Partial<TurnServerOptions>[] = [\n ...(options.turnServer !== undefined\n ? [\n {\n address: options.turnServer,\n username: options.turnUsername,\n password: options.turnPassword,\n transport: options.turnTransport,\n },\n ]\n : []),\n ...(options.turnServers ?? []),\n ];\n for (const server of configured) {\n const address = validServerAddress(server?.address);\n if (!address) {\n log(\"invalid TURN server ignored\", server?.address);\n continue;\n }\n const { username, password } = server;\n if (!username || !password) {\n log(\"TURN server without username / credential ignored\", address);\n continue;\n }\n const entry: Required<TurnServerOptions> = {\n address,\n username,\n password,\n transport: server.transport ?? \"udp\",\n };\n if (\n turnServers.some(\n (existing) =>\n sameAddress(existing.address, entry.address) &&\n existing.transport === entry.transport &&\n existing.username === entry.username &&\n existing.password === entry.password,\n )\n ) {\n continue;\n }\n turnServers.push(entry);\n }\n return { stunServers, turnServers };\n}\n\n/**\n * `current` with an ICE server update applied (Connection.setIceServers): the\n * STUN/TURN fields, singular and plural, are replaced, an undefined one\n * included, so a STUN-only update cannot leave a previous TURN\n * host/credential behind; forceTurn and useTcp change only when given.\n */\nexport function mergeIceServerOptions<T extends Partial<IceOptions>>(\n current: T,\n update: Partial<IceOptions>,\n): T {\n return {\n ...current,\n stunServer: update.stunServer,\n stunServers: update.stunServers,\n turnServer: update.turnServer,\n turnServers: update.turnServers,\n turnUsername: update.turnUsername,\n turnPassword: update.turnPassword,\n turnTransport: update.turnTransport,\n turnTlsOptions: update.turnTlsOptions,\n turnUdpFamily: update.turnUdpFamily,\n forceTurn: update.forceTurn ?? current.forceTurn,\n useTcp: update.useTcp ?? current.useTcp,\n };\n}\n\n/**\n * Whether a generation gathered with `options` is relay-only: forceTurn (the\n * \"relay\" ICE transport policy). The policy holds whatever the TURN settings\n * are: without a usable TURN server / credential (or for an ICE-lite agent,\n * which gathers no relay candidate) the generation has no candidate at all\n * rather than falling back to host / server-reflexive ones, so the local and\n * public addresses are neither advertised nor used for checks.\n */\nexport function isRelayOnlyGathering(options: Pick<IceOptions, \"forceTurn\">) {\n return !!options.forceTurn;\n}\n\n/**\n * Whether `options` carry at least one usable TURN server with its\n * credential, the ones a gathering with them allocates relay candidates from.\n */\nexport function hasTurnServer(options: IceServerFields) {\n return normalizeIceServerOptions(options).turnServers.length > 0;\n}\n\n/**\n * Whether `candidate`, kept from an earlier generation (an ICE restart keeps\n * the sockets), may be advertised and paired in a generation gathered with\n * `options`. A fresh gathering with the same options would not have produced\n * a host / server-reflexive candidate for a relay-only policy, a TCP host\n * candidate without useTcp, nor a relay candidate without a TURN server;\n * the kept ones are held back the same way.\n */\nexport function isCandidateAllowedByGatherOptions(\n candidate: Pick<Candidate, \"type\" | \"transport\">,\n options: Pick<IceOptions, \"forceTurn\"> &\n Partial<Pick<IceOptions, \"useTcp\">> &\n IceServerFields,\n) {\n if (candidate.type === \"relay\") return hasTurnServer(options);\n if (isRelayOnlyGathering(options)) return false;\n if (candidate.transport.toLowerCase() === \"tcp\" && !options.useTcp) {\n return false;\n }\n return true;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"iceBase.js","sourceRoot":"","sources":["../../../../ice/src/iceBase.ts"],"names":[],"mappings":";;;AAoeA,4DAYC;AA4UD,0DASC;AAED,gDAiBC;AAmBD,sDAOC;AAMD,oEAUC;AAQD,sEAmCC;AAOD,4DAYC;AAED,0CAKC;AA6CD,8DAsEC;AAQD,sDAmBC;AAUD,oDAEC;AAMD,sCAEC;AAUD,8EAYC;AA/nCD,mCAAoC;AACpC,2CAAgF;AAChF,qDAI0B;AAI1B,6CAM0B;AAC1B,wCAA2E;AAC3E,4CAAyC;AAGzC,MAAM,GAAG,GAAG,IAAA,cAAK,EAAC,4CAA4C,CAAC,CAAC;AAqKhE,MAAa,aAAa;IAuBxB,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAqBD;;;;;OAKG;IACH,eAAe,CAAC,GAAW,EAAE,EAAE,MAAM,GAAG,IAAI,KAA2B,EAAE;QACvE,IAAI,MAAM;YAAE,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QAC3B,IAAI,CAAC,kBAAkB,IAAI,GAAG,CAAC;QAC/B,IAAI,CAAC,yBAAyB,EAAE,CAAC;QACjC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,6BAAqB;YAAE,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC9E,CAAC;IAED;;;;;;OAMG;IACH,IAAI,WAAW;QACb,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,iCAAyB;YAAE,OAAO,SAAS,CAAC;QACzE,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAA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SAAgD,EAChD,OAEiB;IAEjB,IAAI,SAAS,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC;IAC9D,IAAI,oBAAoB,CAAC,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IAChD,IAAI,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,KAAK,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACnE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { randomUUID } from \"crypto\";\nimport { Candidate, candidateFoundation, candidatePriority } from \"./candidate\";\nimport {\n type IceCandidateErrorInfo,\n type IceServerReachedInfo,\n MissingMappedAddressError,\n} from \"./candidateError\";\nimport type { MdnsLookup } from \"./dns/lookup\";\nimport type { IceGatheringErrorInfo } from \"./gatheringError\";\nimport type { Cancelable } from \"./helper\";\nimport {\n type Address,\n debug,\n type Event,\n type InterfaceAddresses,\n type TlsConnectionOptions,\n} from \"./imports/common\";\nimport { classes, type MessageIntegrityMode, methods } from \"./stun/const\";\nimport { Message } from \"./stun/message\";\nimport type { Protocol } from \"./types/model\";\n\nconst log = debug(\"werift-ice : packages/ice/src/ice.ts : log\");\n\nexport interface IceConnection {\n iceLite: boolean;\n iceControlling: boolean;\n localUsername: string;\n localPassword: string;\n remotePassword: string;\n remoteUsername: string;\n remoteIsLite: boolean;\n /**\n * The peer advertised `a=ice-options:renomination`. With\n * {@link IceOptions.renomination} the controlling agent then nominates with\n * the NOMINATION attribute (see `renomination`).\n */\n remoteRenomination?: boolean;\n /**\n * The remote `a=ice-options` tokens (RFC 8839 §5.6), e.g. `trickle`,\n * `ice2`. Informational: werift already follows RFC 8445, so no token\n * changes how checks or nomination run.\n */\n remoteIceOptions?: string[];\n /** The remote declared `ice2`: an RFC 8445 agent (RFC 8445 §10). */\n readonly remoteIce2?: boolean;\n checkList: CandidatePair[];\n localCandidates: Candidate[];\n remoteCandidates: Candidate[];\n candidatePairs: CandidatePair[];\n /**\n * STUN servers gathering queries, normalized from the options (see\n * {@link normalizeIceServerOptions}). Optional so that other\n * implementations of this interface keep compiling.\n */\n stunServers?: Address[];\n /** TURN servers gathering allocates on, each with its own credential. */\n turnServers?: TurnServerOptions[];\n /** @deprecated The first of {@link IceConnection.stunServers}. */\n stunServer?: Address;\n /** @deprecated The address of the first of {@link IceConnection.turnServers}. */\n turnServer?: Address;\n generation: number;\n options: IceOptions;\n remoteCandidatesEnd: boolean;\n localCandidatesEnd: boolean;\n /**\n * Resolves when `localCandidatesEnd` becomes true after `gatherCandidates()`\n * returned (server-reflexive queries that continue in the background), or\n * when the generation ends. Optional so that other implementations of this\n * interface keep compiling; without it gathering ends when\n * `gatherCandidates()` returns.\n */\n waitForLocalCandidatesEnd?(): Promise<void>;\n state: IceState;\n lookup?: MdnsLookup;\n nominated?: CandidatePair;\n\n readonly onData: Event<[Buffer]>;\n readonly stateChanged: Event<[IceState]>;\n readonly onIceCandidate: Event<[Candidate]>;\n /**\n * A STUN or TURN server of the current generation's gathering gave no\n * candidate (see {@link IceCandidateErrorInfo}). Optional so that other\n * implementations of this interface keep compiling.\n */\n readonly onIceCandidateError?: Event<[IceCandidateErrorInfo]>;\n /**\n * A STUN or TURN server of the current generation's gathering answered\n * (see {@link IceServerReachedInfo}). Optional like onIceCandidateError.\n */\n readonly onIceServerReached?: Event<[IceServerReachedInfo]>;\n /**\n * The current generation's gathering reported an error (see\n * {@link IceGatheringErrorInfo}). Optional like onIceCandidateError.\n * @see packages/webrtc/tests/transport/iceGatheringError.test.ts「of an ICE agent without onGatheringError: gathering-failed is reported and the gathering completes」\n */\n readonly onGatheringError?: Event<[IceGatheringErrorInfo]>;\n\n restart(): void;\n /** Record the remote `a=ice-options` tokens (see remoteIceOptions). */\n setRemoteIceOptions?(options: string[]): void;\n /**\n * Optional staged-restart and provisional-generation support. An\n * implementation without them still restarts ICE at the final answer, but\n * cannot answer or run checks for the new generation during pranswer.\n */\n /**\n * `gatherOptions`: the options the staged generation gathers with (an ICE\n * server update applied at the commit); its provisional checks use only\n * the sockets those options allow. Defaults to the current options.\n */\n stageLocalCredentials?(\n usernameFragment: string,\n password: string,\n gatherOptions?: Partial<IceOptions>,\n ): void;\n discardStagedLocalCredentials?(usernameFragment: string): void;\n commitLocalCredentials?(usernameFragment: string, password: string): void;\n /**\n * The remote side alone restarted (new remote credentials in an answer):\n * drop the remote generation and its checks, keep the local credentials\n * and gathered candidates.\n */\n restartRemote?(): void;\n setProvisionalRemoteParams?(params: {\n usernameFragment: string;\n password: string;\n }): void;\n addProvisionalRemoteCandidate?(\n candidate: Candidate | undefined,\n ): Promise<void>;\n startProvisionalChecks?(): void;\n readonly provisionalNominated?: CandidatePair;\n\n setIceServers(options: Partial<IceOptions>): void;\n\n setRemoteParams(params: {\n iceLite: boolean;\n usernameFragment: string;\n password: string;\n }): void;\n\n /**\n * Gather the current generation's candidates. After an ICE restart the\n * candidates the kept sockets advertised are re-advertised synchronously;\n * only server work (STUN, TURN) is awaited.\n */\n gatherCandidates(): Promise<void>;\n\n /** Whether gathering contacts a STUN or TURN server. */\n readonly gathersFromServers?: boolean;\n\n connect(): Promise<void>;\n\n close(): Promise<void>;\n\n addRemoteCandidate(remoteCandidate: Candidate | undefined): Promise<void>;\n\n send(data: Buffer): Promise<void>;\n\n /** @internal Return whether application data has an authenticated ICE path. */\n canSendApplicationData(): boolean;\n\n getDefaultCandidate(): Candidate | undefined;\n resetNominatedPair(): void;\n /** Drop remote candidates and pairs that name another remote ufrag. */\n dropOtherRemoteGenerations?(usernameFragment: string): void;\n}\n\nexport interface CandidatePairStats {\n packetsSent: number;\n packetsReceived: number;\n bytesSent: number;\n bytesReceived: number;\n rtt?: number;\n totalRoundTripTime: number;\n roundTripTimeMeasurements: number;\n requestsReceived: number;\n requestsSent: number;\n responsesReceived: number;\n responsesSent: number;\n retransmissionsReceived: number;\n retransmissionsSent: number;\n consentRequestsSent: number;\n}\n\nexport class CandidatePair implements CandidatePairStats {\n public protocol: Protocol;\n public remoteCandidate: Candidate;\n public iceControlling: boolean;\n\n readonly id = randomUUID().toString();\n handle?: Cancelable<void>;\n nominated = false;\n remoteNominated = false;\n /**\n * The largest nomination the peer sent for this pair while this agent was\n * controlled: the NOMINATION attribute's value (renomination), or 1 for\n * USE-CANDIDATE. The controlled agent selects the nominated pair with the\n * largest value, the higher-priority one between equal values.\n */\n remoteNomination = 0;\n /**\n * The NOMINATION value this agent (controlling, renomination) sent for the\n * pair and the peer answered; 0 when it did not renominate the pair.\n */\n nomination = 0;\n // 5.7.4. Computing States\n private _state: CandidatePairState = CandidatePairState.FROZEN;\n get state() {\n return this._state;\n }\n\n // Statistics tracking\n packetsSent = 0;\n packetsReceived = 0;\n bytesSent = 0;\n bytesReceived = 0;\n rtt?: number;\n totalRoundTripTime = 0;\n roundTripTimeMeasurements = 0;\n requestsReceived = 0;\n requestsSent = 0;\n responsesReceived = 0;\n responsesSent = 0;\n retransmissionsReceived = 0;\n retransmissionsSent = 0;\n consentRequestsSent = 0;\n private readonly requestTransactionIds = new Set<string>();\n /** The most recent RTT samples (seconds), oldest first (see `smoothedRtt`). */\n private readonly rttSamples: number[] = [];\n\n /**\n * Record the RTT (seconds) of an answered check: the totals, the samples of\n * {@link smoothedRtt} and, unless `latest` is false (a response to an older\n * check than the one `rtt` came from), `rtt`.\n * @see tests/ice/selection-controller.test.ts \"a response to an older check (latest: false) counts for the totals and the smoothed RTT, not the current RTT\"\n */\n recordRoundTrip(rtt: number, { latest = true }: { latest?: boolean } = {}) {\n if (latest) this.rtt = rtt;\n this.totalRoundTripTime += rtt;\n this.roundTripTimeMeasurements++;\n this.rttSamples.push(rtt);\n if (this.rttSamples.length > RTT_SMOOTHING_SAMPLES) this.rttSamples.shift();\n }\n\n /**\n * The smoothed RTT (seconds) the selection switches by: the median of the\n * last {@link RTT_SMOOTHING_SAMPLES} samples, undefined with fewer than\n * {@link RTT_SMOOTHING_MIN_SAMPLES}.\n * @see tests/ice/selection-controller.test.ts \"the median of the last 5 samples: one outlier does not move it\"\n * @see tests/ice/selection-controller.test.ts \"equal priority: one outlier RTT of the other pair does not move the selection\"\n */\n get smoothedRtt(): number | undefined {\n if (this.rttSamples.length < RTT_SMOOTHING_MIN_SAMPLES) return undefined;\n const sorted = [...this.rttSamples].sort((a, b) => a - b);\n const middle = sorted.length >> 1;\n return sorted.length % 2\n ? sorted[middle]\n : (sorted[middle - 1] + sorted[middle]) / 2;\n }\n\n toJSON() {\n return this.json;\n }\n\n get json() {\n return {\n protocol: this.protocol.type,\n localCandidate: this.localCandidate.toSdp(),\n remoteCandidate: this.remoteCandidate.toSdp(),\n };\n }\n\n constructor(\n protocol: Protocol,\n remoteCandidate: Candidate,\n iceControlling: boolean,\n ) {\n this.protocol = protocol;\n this.remoteCandidate = remoteCandidate;\n this.iceControlling = iceControlling;\n }\n\n updateState(state: CandidatePairState) {\n this._state = state;\n }\n\n get localCandidate() {\n if (!this.protocol.localCandidate) {\n throw new Error(\"localCandidate not exist\");\n }\n return this.protocol.localCandidate;\n }\n\n get remoteAddr(): Address {\n return [this.remoteCandidate.host, this.remoteCandidate.port];\n }\n\n get component() {\n return this.localCandidate.component;\n }\n\n get priority() {\n return candidatePairPriority(\n this.localCandidate,\n this.remoteCandidate,\n this.iceControlling,\n );\n }\n\n get foundation() {\n return this.localCandidate.foundation;\n }\n\n noteIncomingRequest(transactionId: string) {\n const isRetransmission = this.requestTransactionIds.has(transactionId);\n if (!isRetransmission) {\n this.requestTransactionIds.add(transactionId);\n return false;\n }\n this.retransmissionsReceived++;\n return true;\n }\n}\n\n/** Default of {@link IceOptions.incomingCheckTimeout}, in seconds. */\nexport const DEFAULT_INCOMING_CHECK_TIMEOUT = 30;\nexport const ICE_COMPLETED = 1 as const;\nexport const ICE_FAILED = 2 as const;\n\n/** Basic consent check period in seconds (RFC 7675). Actual interval is 0.8–1.2× this. */\nexport const CONSENT_INTERVAL = 5;\n\n/**\n * @deprecated Consent expiry is based on {@link CONSENT_TIMEOUT} (30s after the\n * last valid response), not a consecutive failure count. Kept for API compatibility.\n */\nexport const CONSENT_FAILURES = 6;\n\n/** RFC 7675: consent expires this many seconds after the last valid response. */\nexport const CONSENT_TIMEOUT = 30;\n\n/**\n * RTT-based response deadline of a consent request (ms) when the RTT is\n * unknown (see {@link consentResponseTimeoutMs}). Downstream ICE-lite peers\n * typically answer in 150–300ms. It is no longer how long the request's\n * transaction stays open: that is {@link CONSENT_TIMEOUT}, so a response\n * after this deadline still refreshes the consent.\n */\nexport const CONSENT_RESPONSE_TIMEOUT = 1000;\n\n/** RFC 8445 §14.3: ICE RTO must not be less than 500ms. */\nexport const CONSENT_RESPONSE_TIMEOUT_MIN = 500;\n\n// Failover of the selected pair without an ICE restart (semi-aggressive\n// nomination and renomination, full ICE, not ICE-TCP). The values follow\n// libwebrtc (`p2p/base/connection.h`, `p2p/base/ice_controller_interface.h`,\n// `basic_ice_controller.cc`); the libwebrtc name is given where it differs.\n\n/**\n * Ping interval (ms) of a pair that is weak (a check went unanswered) or\n * stabilizing (fewer than {@link MIN_PINGS_AT_WEAK_PING_INTERVAL} responses\n * since it began to be monitored). libwebrtc:\n * `WEAK_OR_STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL`.\n */\nexport const WEAK_OR_STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL = 900;\n\n/**\n * Ping interval (ms) of a stable backup pair (multiplied by a random 0.8–1.2).\n * libwebrtc: `STABLE_WRITABLE_CONNECTION_PING_INTERVAL`.\n */\nexport const STABLE_WRITABLE_CONNECTION_PING_INTERVAL = 2500;\n\n/**\n * Responses a pair needs, pinged at the weak interval, before it counts as\n * stable. libwebrtc: `MIN_PINGS_AT_WEAK_PING_INTERVAL`.\n */\nexport const MIN_PINGS_AT_WEAK_PING_INTERVAL = 3;\n\n/**\n * A pair is no longer writable once at least this many consecutive checks\n * went unanswered and {@link CONNECTION_WRITE_CONNECT_TIMEOUT} passed since\n * its last response. libwebrtc: `CONNECTION_WRITE_CONNECT_FAILURES`.\n */\nexport const CONNECTION_WRITE_CONNECT_FAILURES = 5;\n\n/** See {@link CONNECTION_WRITE_CONNECT_FAILURES} (ms). libwebrtc: `CONNECTION_WRITE_CONNECT_TIMEOUT`. */\nexport const CONNECTION_WRITE_CONNECT_TIMEOUT = 5000;\n\n/**\n * A pair that received nothing (response, request or data) for this long\n * (ms) is weak. libwebrtc: `WEAK_CONNECTION_RECEIVE_TIMEOUT`.\n */\nexport const WEAK_CONNECTION_RECEIVE_TIMEOUT = 2500;\n\n/**\n * How long (ms) the selected pair must have stopped receiving (nothing\n * received for {@link WEAK_CONNECTION_RECEIVE_TIMEOUT}) before the\n * controlling agent fails over to a backup that receives, without waiting\n * for the selected pair to become unwritable. libwebrtc:\n * `receiving_switching_delay` (default 1000 ms).\n */\nexport const RECEIVING_SWITCHING_DELAY = 1000;\n\n/**\n * A backup pair that received nothing for this long (ms) is dropped (its\n * state becomes Failed) and the next pair of its socket is monitored. The\n * same value as {@link CONSENT_TIMEOUT}. libwebrtc:\n * `DEAD_CONNECTION_RECEIVE_TIMEOUT`.\n */\nexport const DEAD_CONNECTION_RECEIVE_TIMEOUT = CONSENT_TIMEOUT * 1000;\n\n/**\n * Response timeout (ms) of a backup check while the pair's RTT is still\n * unknown (it never answered a check of this agent). libwebrtc starts a\n * connection's RTT estimate at `DEFAULT_RTT` (3000 ms); the consent default\n * ({@link CONSENT_RESPONSE_TIMEOUT}, 1 s) would never let a backup path\n * slower than that become valid. Once the pair answered, the timeout follows\n * its RTT ({@link consentResponseTimeoutMs}).\n */\nexport const BACKUP_UNKNOWN_RTT_RESPONSE_TIMEOUT = 3000;\n\n/**\n * After the selected pair's consent expired (RFC 7675: no more application\n * data on it), how long (ms) the agent stays `disconnected` waiting for the\n * selection to move to a writable backup (its own failover nomination, or\n * the peer's when controlled) before it fails. A peer that fails over does\n * so 5–10 s after the path broke, long before the 30 s expiry; the grace\n * covers a nomination still in flight. werift's own value.\n */\nexport const FAILOVER_CONSENT_EXPIRED_GRACE = 10_000;\n\n/**\n * Pairs of one local socket (or TURN allocation) tried as its backup before\n * the socket waits for a retry (1, 2, 4, 8, 16 s, then every 16 s) and starts\n * again from its highest-priority pair. werift's own limit.\n */\nexport const FAILOVER_BACKUP_ATTEMPTS = 3;\n\n/**\n * Consecutive responses a pair the agent failed over from needs before the\n * selection may move back to it (or to another pair of its socket). Keeps\n * the selection from flapping. werift's own value (libwebrtc relies on\n * {@link MIN_PINGS_AT_WEAK_PING_INTERVAL} for the same purpose).\n */\nexport const FAILOVER_RECOVERY_RESPONSES = 3;\n\n/**\n * Between pairs of equal state and priority, the selection moves only to a\n * pair whose smoothed RTT ({@link CandidatePair.smoothedRtt}) is at least this\n * much (ms) lower. libwebrtc: `kMinImprovement`.\n * @see tests/ice/selection-controller.test.ts \"equal priority: a pair only 9 ms faster does not take the selection\"\n */\nexport const RTT_SWITCH_MIN_IMPROVEMENT = 10;\n\n/**\n * The RTT samples {@link CandidatePair.smoothedRtt} keeps (the most recent\n * ones). werift's own value: libwebrtc keeps a moving average instead, which\n * one outlier still moves.\n * @see tests/ice/selection-controller.test.ts \"the median of the last 5 samples: one outlier does not move it\"\n */\nexport const RTT_SMOOTHING_SAMPLES = 5;\n\n/**\n * Samples a pair needs before {@link CandidatePair.smoothedRtt} has a value\n * (the RTT takes part in a switch). The same as\n * {@link MIN_PINGS_AT_WEAK_PING_INTERVAL}: a backup is stable from then on.\n * @see tests/ice/selection-controller.test.ts \"the median of the last 5 samples: one outlier does not move it\"\n */\nexport const RTT_SMOOTHING_MIN_SAMPLES = 3;\n\n/**\n * RTT-based response deadline (ms) from a pair RTT (seconds): when a consent\n * request without a response counts as unanswered (failover's pacing and\n * writability), and the response timeout of a backup check once the backup's\n * RTT is known. Uses 2×RTT + 200ms jitter margin, floored at\n * {@link CONSENT_RESPONSE_TIMEOUT_MIN}. Falls back to\n * {@link CONSENT_RESPONSE_TIMEOUT} when RTT is unavailable.\n *\n * A consent request's transaction is not ended at this deadline: it stays\n * open for {@link CONSENT_TIMEOUT}, so a response slower than the estimate\n * (an RTT that rose after the selection) still refreshes the consent.\n */\nexport function consentResponseTimeoutMs(rttSeconds?: number): number {\n if (\n rttSeconds === undefined ||\n !Number.isFinite(rttSeconds) ||\n rttSeconds <= 0\n ) {\n return CONSENT_RESPONSE_TIMEOUT;\n }\n return Math.max(\n CONSENT_RESPONSE_TIMEOUT_MIN,\n Math.round(rttSeconds * 1000 * 2 + 200),\n );\n}\n\n/**\n * @enum\n */\nexport const CandidatePairState = {\n FROZEN: 0,\n WAITING: 1,\n IN_PROGRESS: 2,\n SUCCEEDED: 3,\n FAILED: 4,\n} as const;\nexport type CandidatePairState =\n (typeof CandidatePairState)[keyof typeof CandidatePairState];\n\nexport type IceState =\n | \"disconnected\"\n | \"closed\"\n | \"completed\"\n | \"new\"\n | \"connected\"\n | \"failed\";\n\n/** A TURN server and the credential and transport used for it. */\nexport type TurnServerOptions = {\n address: Address;\n username: string;\n password: string;\n /** Defaults to \"udp\" (with a TCP fallback when the UDP allocation fails). */\n transport?: \"udp\" | \"tcp\" | \"tls\";\n /**\n * The application's names (URLs) for this server. Metadata only: the\n * allocation does not use them. They are passed through unchanged to\n * {@link IceServerRef.urls} of `Connection.onIceCandidateError`, so a\n * failure can be matched to the configured server without exposing the\n * credential. Duplicates merged by {@link normalizeIceServerOptions} have\n * their urls merged.\n */\n urls?: string[];\n};\n\n/** A TURN server as gathering uses it (see {@link normalizeIceServerOptions}). */\nexport type NormalizedTurnServer = Required<Omit<TurnServerOptions, \"urls\">> &\n Pick<TurnServerOptions, \"urls\">;\n\n/**\n * The application's name (URL) of a STUN server, reported in\n * {@link IceServerRef.urls} of `Connection.onIceCandidateError`. Metadata\n * only; several entries may name the same address.\n */\nexport type StunServerUrl = { address: Address; url: string };\n\n/**\n * Thresholds of the failover of the selected pair ({@link IceOptions.failover}),\n * after libwebrtc's `RTCConfiguration` fields of the same meaning. Lower\n * values fail over sooner and also on a shorter loss burst.\n */\nexport interface IceFailoverOptions {\n /**\n * Consecutive unanswered checks after which a pair is unwritable (together\n * with `unwritableTimeout`). An integer of at least 1; defaults to\n * {@link CONNECTION_WRITE_CONNECT_FAILURES} (5). libwebrtc:\n * `ice_unwritable_min_checks`.\n */\n unwritableMinChecks?: number;\n /**\n * Time (ms) since a pair's last response after which it is unwritable\n * (together with `unwritableMinChecks`). At least 0; defaults to\n * {@link CONNECTION_WRITE_CONNECT_TIMEOUT} (5000). libwebrtc:\n * `ice_unwritable_timeout`.\n */\n unwritableTimeout?: number;\n /**\n * Time (ms) without receiving anything (response, request or data) after\n * which a pair is weak (checked at the weak interval, 900 ms) and stops\n * receiving. Greater than 0; defaults to\n * {@link WEAK_CONNECTION_RECEIVE_TIMEOUT} (2500). libwebrtc:\n * `receiving_timeout`.\n */\n receivingTimeout?: number;\n /**\n * Time (ms) the selected pair must have stopped receiving (one of its\n * checks unanswered as well) before the controlling agent fails over to a\n * backup that receives, before the selected pair becomes unwritable. At\n * least 0; defaults to {@link RECEIVING_SWITCHING_DELAY} (1000).\n * libwebrtc: `receiving_switching_delay`.\n */\n receivingSwitchingDelay?: number;\n}\n\nexport interface IceOptions {\n /** Advertise and operate as an ICE lite agent. */\n iceLite: boolean;\n useTcp: boolean;\n /**\n * Gather passive TCP host candidates (opens a listening TCP server per\n * interface). Defaults to true. Send-only agents that never accept inbound\n * connections can set this false to avoid the listener while still gathering\n * active TCP candidates.\n */\n tcpPassive?: boolean;\n /**\n * Seconds to wait for server-reflexive candidates while gathering.\n * Defaults to 5. Where UDP is blocked these STUN queries are never answered,\n * so the wait always runs to the timeout; agents that must not stall on such\n * networks can lower it.\n *\n * `gatherCandidates()` waits only for the representative sockets' queries\n * (see `stunServers`); the other host sockets' queries continue up to this\n * timeout in the background and end-of-candidates follows them.\n */\n stunGatherTimeout?: number;\n /**\n * Seconds `connect()` waits for a connectivity check from the peer when it\n * has no candidate pair of its own to check after both sides ended their\n * candidates: the peer offered only active TCP candidates (RFC 6544), or\n * none this agent can reach. A check from the peer adds a peer-reflexive\n * pair and the connection proceeds; without one, `connect()` fails when the\n * time runs out. An ICE-lite agent, which sends no checks, waits the same\n * time whenever it has no candidate pair, also while it still gathers. The\n * deadline is fixed when the wait begins; once the local gathering ended\n * without a socket that could receive a check, `connect()` fails at once.\n * Defaults to 30; 0 fails at once.\n */\n incomingCheckTimeout?: number;\n /**\n * Seconds to wait for a TURN TCP/TLS connection to be established.\n * Defaults to 8.\n */\n turnConnectTimeout?: number;\n /**\n * With `nomination: \"regular\"`: milliseconds the controlling agent keeps\n * checking before it nominates (RFC 8445 §8.1.1 regular nomination). The\n * default semi-aggressive nomination does not wait. Counted from the later of the first\n * valid pair and the last pair added that outranks the best valid pair, so\n * a higher-priority candidate trickled shortly after a lower-priority one\n * succeeded can still be selected. Once both sides signalled\n * end-of-candidates and no higher-priority pair is still being checked, the\n * best valid pair is nominated at once. Defaults to 300; 0 nominates the\n * best valid pair as soon as one exists. A negative or non-finite value\n * falls back to the default.\n */\n nominationDelayMs?: number;\n /**\n * How the controlling agent nominates toward a full ICE peer when\n * renomination is not in use (see `renomination`).\n *\n * - `\"semi-aggressive\"` (default, as libwebrtc / Chrome): a check carries\n * USE-CANDIDATE while no pair is selected and for every pair that\n * outranks the selected one. The first pair whose check succeeds is\n * selected at once; checks of higher-priority pairs go on, and one that\n * succeeds later replaces the selection. Consent checks of the selected\n * pair carry USE-CANDIDATE as well.\n * - `\"regular\"`: RFC 8445 §8.1.1 regular nomination. Checks carry no\n * USE-CANDIDATE; after `nominationDelayMs` (or end-of-candidates) the\n * best valid pair is nominated once with a separate check and never\n * replaced.\n *\n * Toward an ICE-lite peer the first valid pair is nominated in either mode.\n */\n nomination?: \"semi-aggressive\" | \"regular\";\n /**\n * Renomination (draft-thatcher-ice-renomination, as libwebrtc implements\n * it). When enabled the agent advertises `a=ice-options:renomination`\n * (packages/webrtc). When the peer advertised it too, the controlling agent\n * nominates with the NOMINATION attribute (0xC001) and an increasing value\n * instead of USE-CANDIDATE: it nominates the first valid pair, keeps\n * checking higher-priority pairs and renominates a better one when its\n * check succeeds. This replaces `nomination` for that session.\n *\n * The controlled agent always honours the NOMINATION attribute: it selects\n * the pair with the largest value. Defaults to false.\n */\n renomination?: boolean;\n /**\n * Thresholds of the failover of the selected pair without an ICE restart\n * (semi-aggressive nomination or renomination, full ICE, not ICE-TCP).\n * Each unset or invalid value keeps its default, which follows libwebrtc.\n * See {@link IceFailoverOptions}.\n */\n failover?: IceFailoverOptions;\n /**\n * STUN servers queried while gathering, in priority order. Every IPv4 UDP\n * host socket queries each of them in parallel; equal mappings are\n * advertised once, different ones (a NAT that maps per destination) each.\n *\n * Without `interfaceAddresses`, each family with a STUN server also gets a\n * UDP socket bound to the wildcard address that advertises no host\n * candidate: the OS picks its route (a full-tunnel VPN, an interface the\n * host sockets do not cover), and its server-reflexive candidates carry\n * the related address `0.0.0.0` / `::`. The IPv4 wildcard socket queries\n * every server, the IPv6 one only the IPv6 literal servers. It checks only\n * the remote candidates whose route leaves from an address no UDP host\n * socket is bound to, so a peer on a covered path learns no\n * peer-reflexive candidate from it.\n *\n * `gatherCandidates()` returns once the representative sockets answered or\n * `stunGatherTimeout` ran out: the wildcard sockets and the host socket of\n * the default-route address (every host socket when a family has neither).\n * The other host sockets' server-reflexive candidates trickle through\n * `onIceCandidate`, and `localCandidatesEnd` follows the last of them\n * (`waitForLocalCandidatesEnd()`), so an interface that cannot reach the\n * STUN server does not delay the description.\n *\n * Merged with the deprecated `stunServer`: the singular one comes first,\n * duplicates are dropped (see {@link normalizeIceServerOptions}).\n */\n stunServers?: Address[];\n /**\n * The application's names (URLs) of {@link IceOptions.stunServers}, by\n * address. Metadata only, reported in {@link IceServerRef.urls} of\n * `Connection.onIceCandidateError`; replaced together with the STUN\n * servers (see {@link mergeIceServerOptions}).\n */\n stunServerUrls?: StunServerUrl[];\n /**\n * TURN servers allocated on while gathering, in priority order. Each one\n * gets its own allocation with its own credential and transport; one that\n * fails or times out does not stop the others. Gathering ends when the\n * slowest allocation completes or fails (`turnConnectTimeout` bounds a\n * TCP/TLS connection, the STUN transaction timeout an unanswered request).\n * `turnTlsOptions`, `turnUdpFamily`, `turnConnectTimeout`, `portRange` and\n * `interfaceAddresses` apply to every TURN server.\n *\n * Merged with the deprecated `turnServer` / `turnUsername` /\n * `turnPassword` / `turnTransport`: the singular one comes first,\n * duplicates are dropped and an entry without username / password is\n * ignored (see {@link normalizeIceServerOptions}).\n */\n turnServers?: TurnServerOptions[];\n /** @deprecated Use {@link IceOptions.stunServers}. Kept as their first entry. */\n stunServer?: Address;\n /**\n * Whether the built-in public STUN server (stun.l.google.com:19302) is used\n * when no STUN server is given. Defaults to true; false gathers no\n * server-reflexive candidate unless a STUN server is set.\n */\n useDefaultStunServer?: boolean;\n /** @deprecated Use {@link IceOptions.turnServers}. Kept as their first entry. */\n turnServer?: Address;\n /** @deprecated Use {@link TurnServerOptions.username} of {@link IceOptions.turnServers}. */\n turnUsername?: string;\n /** @deprecated Use {@link TurnServerOptions.password} of {@link IceOptions.turnServers}. */\n turnPassword?: string;\n /** @deprecated Use {@link TurnServerOptions.transport} of {@link IceOptions.turnServers}. */\n turnTransport?: \"udp\" | \"tcp\" | \"tls\";\n /** Applied to every TLS TURN server. */\n turnTlsOptions?: TlsConnectionOptions;\n /**\n * Preferred IP family of a TURN/UDP socket, applied (to every TURN server)\n * only when the server is a hostname. Ignored for an IP literal server,\n * whose own family always selects the socket. Defaults to 4.\n */\n turnUdpFamily?: 4 | 6;\n forceTurn?: boolean;\n localPasswordPrefix?: string;\n useIpv4: boolean;\n useIpv6: boolean;\n useLinkLocalAddress?: boolean;\n portRange?: [number, number];\n /**\n * Local addresses to bind the UDP host sockets to, per family.\n *\n * The address given for a family (`udp4` / `udp6`) is the only host\n * address of that family: its UDP host candidate advertises the address and\n * port the socket is actually bound to, even when the address is not among\n * the enumerated network interfaces (loopback, tun, ...), and its TCP host\n * candidates use it too. Other enumerated addresses of that family are not\n * gathered. If the bind fails, the family has no UDP host candidate.\n *\n * A family left unspecified while the other one is set gathers no\n * enumerated addresses (only its `additionalHostAddresses`).\n *\n * Without any family set, every enumerated address gets its own UDP host\n * socket bound to that address (an IPv6 link-local one with its zone), so\n * the socket's packets leave from the advertised candidate address even on\n * a host with several network interfaces. An address whose bind fails, or\n * whose sends fail, loses only its own candidate; the other addresses are\n * unaffected. An `additionalHostAddresses` entry that is not assigned to a\n * local interface (a 1:1 NAT public address, for example) is gathered over\n * a wildcard socket. The enumerated addresses include costly networks (VPN\n * / tunnel interfaces: `ipsec`, `tun`, `utun`, `tap`) with a low local\n * preference; `vmnet` / `veth` interfaces are excluded. The default-route\n * address gets the highest local preference, so checks start with the path\n * the OS uses: the source address of the route to the first configured\n * STUN / TURN server that resolves in the family and has a route (UDP\n * `connect()`, no packet is sent). A family without such a server has no\n * default-route address: no other address (no public one) is probed in\n * its place, and its host candidates keep the gathering order. With a STUN\n * server, a wildcard socket per family maps the route the\n * OS picks (see `stunServers`).\n *\n * A family set to the wildcard address (`0.0.0.0` / `::`) gathers its\n * enumerated and additional addresses over wildcard sockets instead;\n * the wildcard address itself is never advertised.\n */\n interfaceAddresses?: InterfaceAddresses;\n /**\n * Host addresses gathered in addition to the enumerated ones. For a family\n * bound by `interfaceAddresses`, addresses other than the bound one are\n * ignored.\n */\n additionalHostAddresses?: string[];\n filterStunResponse?: (\n message: Message,\n addr: Address,\n protocol: Protocol,\n ) => boolean;\n filterCandidatePair?: (pair: CandidatePair) => boolean;\n /**\n * Integrity attributes of the connectivity checks and consent requests this\n * agent sends (short-term credentials, RFC 8489):\n * - `\"sha1\"` (default): MESSAGE-INTEGRITY only, what every browser accepts.\n * - `\"sha256\"`: MESSAGE-INTEGRITY-SHA256 only. A peer that does not know\n * the comprehension-required 0x001C attribute rejects such checks (420\n * or no answer), so use it only with a peer known to support it.\n * - `\"both\"`: MESSAGE-INTEGRITY followed by MESSAGE-INTEGRITY-SHA256.\n *\n * Received requests and responses are accepted with either algorithm, and\n * a response is always signed with the algorithm of its request\n * (MESSAGE-INTEGRITY-SHA256 when the request carried it, RFC 8489 §9.1.3).\n */\n messageIntegrity?: MessageIntegrityMode;\n}\n\nexport const defaultOptions: IceOptions = {\n iceLite: false,\n useTcp: false,\n useIpv4: true,\n useIpv6: true,\n};\n\nexport function validateRemoteCandidate(candidate: Candidate) {\n // \"\"\"\n // Check the remote candidate is supported.\n // \"\"\"\n if (![\"host\", \"relay\", \"srflx\"].includes(candidate.type))\n throw new Error(`Unexpected candidate type \"${candidate.type}\"`);\n\n // ipaddress.ip_address(candidate.host)\n return candidate;\n}\n\nexport function sortCandidatePairs(\n pairs: {\n localCandidate: Pick<Candidate, \"priority\">;\n remoteCandidate: Pick<Candidate, \"priority\">;\n }[],\n iceControlling: boolean,\n) {\n // Highest priority first; pairs of equal priority keep their order.\n return pairs.sort((a, b) =>\n compareCandidatePairPriority(\n b.localCandidate,\n b.remoteCandidate,\n a.localCandidate,\n a.remoteCandidate,\n iceControlling,\n ),\n );\n}\n\n/** RFC 8445 §6.1.2.3: G is the controlling agent's candidate priority, D the controlled one's. */\nfunction pairPriorityTerms(\n local: Pick<Candidate, \"priority\">,\n remote: Pick<Candidate, \"priority\">,\n iceControlling: boolean,\n) {\n const G = iceControlling ? local.priority : remote.priority;\n const D = iceControlling ? remote.priority : local.priority;\n return { min: Math.min(G, D), max: Math.max(G, D), tie: G > D ? 1 : 0 };\n}\n\n// 5.7.2. Computing Pair Priority and Ordering Pairs\n/**\n * `2^32 * MIN(G,D) + 2 * MAX(G,D) + (G > D ? 1 : 0)` (RFC 8445 §6.1.2.3).\n * The value can exceed `Number.MAX_SAFE_INTEGER`, so it is approximate;\n * order pairs with `compareCandidatePairPriority`, which is exact.\n */\nexport function candidatePairPriority(\n local: Pick<Candidate, \"priority\">,\n remote: Pick<Candidate, \"priority\">,\n iceControlling: boolean,\n) {\n const { min, max, tie } = pairPriorityTerms(local, remote, iceControlling);\n return 2 ** 32 * min + 2 * max + tie;\n}\n\n/**\n * Exact comparison of two pair priorities (RFC 8445 §6.1.2.3): negative\n * when pair `a` has the lower priority, positive when the higher, 0 when equal.\n */\nexport function compareCandidatePairPriority(\n aLocal: Pick<Candidate, \"priority\">,\n aRemote: Pick<Candidate, \"priority\">,\n bLocal: Pick<Candidate, \"priority\">,\n bRemote: Pick<Candidate, \"priority\">,\n iceControlling: boolean,\n) {\n const a = pairPriorityTerms(aLocal, aRemote, iceControlling);\n const b = pairPriorityTerms(bLocal, bRemote, iceControlling);\n return a.min - b.min || a.max - b.max || a.tie - b.tie;\n}\n\n/**\n * Query `stunServer` from `protocol` for a server-reflexive candidate.\n * Unlike {@link serverReflexiveCandidate} it rejects with the reason of a\n * failure. `base` is used for wildcard sockets that advertise no host\n * candidate themselves.\n */\nexport async function queryServerReflexiveCandidate(\n protocol: Protocol,\n stunServer: Address,\n base?: Pick<Candidate, \"host\" | \"port\" | \"transport\" | \"component\"> &\n Partial<Pick<Candidate, \"tcptype\">>,\n): Promise<Candidate> {\n const localCandidate = base ?? protocol.localCandidate;\n if (!localCandidate) {\n throw new Error(\"protocol has no local candidate\");\n }\n\n const request = new Message(methods.BINDING, classes.REQUEST);\n const [response] = await protocol.request(request, stunServer);\n const mapped = response.getAttributeValue(\"XOR-MAPPED-ADDRESS\") as\n | Address\n | undefined;\n if (!mapped) {\n throw new MissingMappedAddressError(stunServer);\n }\n\n return new Candidate(\n candidateFoundation(\"srflx\", localCandidate.transport, localCandidate.host),\n localCandidate.component,\n localCandidate.transport,\n candidatePriority(\"srflx\", {\n transport: localCandidate.transport,\n tcptype: localCandidate.tcptype,\n }),\n mapped[0],\n mapped[1],\n \"srflx\",\n localCandidate.host,\n localCandidate.port,\n localCandidate.tcptype,\n );\n}\n\n/**\n * Query a STUN server for a server-reflexive candidate. This compatibility\n * helper resolves `undefined` on failure; use\n * {@link queryServerReflexiveCandidate} when the failure reason is needed.\n */\nexport async function serverReflexiveCandidate(\n protocol: Protocol,\n stunServer: Address,\n base?: Pick<Candidate, \"host\" | \"port\" | \"transport\" | \"component\"> &\n Partial<Pick<Candidate, \"tcptype\">>,\n): Promise<Candidate | undefined> {\n return queryServerReflexiveCandidate(protocol, stunServer, base).catch(\n (error) => {\n log(\"error serverReflexiveCandidate\", error);\n return undefined;\n },\n );\n}\n\nexport function validateAddress(addr?: Address): Address | undefined {\n if (addr && Number.isNaN(addr[1])) {\n return [addr[0], 443];\n }\n return addr;\n}\n\n/** The STUN/TURN server fields of {@link IceOptions}, singular and plural. */\nexport type IceServerFields = Partial<\n Pick<\n IceOptions,\n | \"stunServer\"\n | \"stunServers\"\n | \"stunServerUrls\"\n | \"turnServer\"\n | \"turnServers\"\n | \"turnUsername\"\n | \"turnPassword\"\n | \"turnTransport\"\n >\n>;\n\n/** A STUN/TURN server address: validated (see {@link validateAddress}) or undefined. */\nfunction validServerAddress(addr: unknown): Address | undefined {\n if (!Array.isArray(addr)) return undefined;\n const validated = validateAddress(addr as unknown as Address);\n if (!validated) return undefined;\n const [host, port] = validated;\n if (typeof host !== \"string\" || host === \"\") return undefined;\n if (typeof port !== \"number\" || !Number.isFinite(port)) return undefined;\n return validated;\n}\n\nconst sameAddress = (a: Address, b: Address) => a[0] === b[0] && a[1] === b[1];\n\n/**\n * The STUN and TURN servers `options` configure, the one place the singular\n * (deprecated) and plural fields are merged:\n *\n * - order: the singular server first, then the plural list in its order;\n * - duplicates (the same STUN address; the same TURN address, transport and\n * credential) are kept once, at their first position;\n * - an invalid address (see {@link validateAddress}) is dropped, and so is a\n * TURN server without username or password (it cannot allocate);\n * - a TURN transport left unset is \"udp\";\n * - the `urls` of merged TURN duplicates are merged (in order, once each).\n *\n * The built-in default STUN server is not added here; Connection falls back\n * to it when the result has no STUN server.\n */\nexport function normalizeIceServerOptions(options: IceServerFields): {\n stunServers: Address[];\n turnServers: NormalizedTurnServer[];\n} {\n const stunServers: Address[] = [];\n for (const server of [options.stunServer, ...(options.stunServers ?? [])]) {\n if (server === undefined) continue;\n const address = validServerAddress(server);\n if (!address) {\n log(\"invalid STUN server ignored\", server);\n continue;\n }\n if (stunServers.some((existing) => sameAddress(existing, address))) {\n continue;\n }\n stunServers.push(address);\n }\n\n const turnServers: NormalizedTurnServer[] = [];\n const configured: Partial<TurnServerOptions>[] = [\n ...(options.turnServer !== undefined\n ? [\n {\n address: options.turnServer,\n username: options.turnUsername,\n password: options.turnPassword,\n transport: options.turnTransport,\n },\n ]\n : []),\n ...(options.turnServers ?? []),\n ];\n for (const server of configured) {\n const address = validServerAddress(server?.address);\n if (!address) {\n log(\"invalid TURN server ignored\", server?.address);\n continue;\n }\n const { username, password } = server;\n if (!username || !password) {\n log(\"TURN server without username / credential ignored\", address);\n continue;\n }\n const urls = Array.isArray(server.urls)\n ? server.urls.filter((url) => typeof url === \"string\")\n : undefined;\n const entry: NormalizedTurnServer = {\n address,\n username,\n password,\n transport: server.transport ?? \"udp\",\n ...(urls ? { urls: [...new Set(urls)] } : {}),\n };\n const existing = turnServers.find(\n (known) =>\n sameAddress(known.address, entry.address) &&\n known.transport === entry.transport &&\n known.username === entry.username &&\n known.password === entry.password,\n );\n if (existing) {\n // One allocation serves both: it answers to every name of them.\n if (entry.urls) {\n existing.urls = [...new Set([...(existing.urls ?? []), ...entry.urls])];\n }\n continue;\n }\n turnServers.push(entry);\n }\n return { stunServers, turnServers };\n}\n\n/**\n * `current` with an ICE server update applied (Connection.setIceServers): the\n * STUN/TURN fields, singular and plural, are replaced, an undefined one\n * included, so a STUN-only update cannot leave a previous TURN\n * host/credential behind; forceTurn and useTcp change only when given.\n */\nexport function mergeIceServerOptions<T extends Partial<IceOptions>>(\n current: T,\n update: Partial<IceOptions>,\n): T {\n return {\n ...current,\n stunServer: update.stunServer,\n stunServers: update.stunServers,\n stunServerUrls: update.stunServerUrls,\n turnServer: update.turnServer,\n turnServers: update.turnServers,\n turnUsername: update.turnUsername,\n turnPassword: update.turnPassword,\n turnTransport: update.turnTransport,\n turnTlsOptions: update.turnTlsOptions,\n turnUdpFamily: update.turnUdpFamily,\n forceTurn: update.forceTurn ?? current.forceTurn,\n useTcp: update.useTcp ?? current.useTcp,\n };\n}\n\n/**\n * Whether a generation gathered with `options` is relay-only: forceTurn (the\n * \"relay\" ICE transport policy). The policy holds whatever the TURN settings\n * are: without a usable TURN server / credential (or for an ICE-lite agent,\n * which gathers no relay candidate) the generation has no candidate at all\n * rather than falling back to host / server-reflexive ones, so the local and\n * public addresses are neither advertised nor used for checks.\n */\nexport function isRelayOnlyGathering(options: Pick<IceOptions, \"forceTurn\">) {\n return !!options.forceTurn;\n}\n\n/**\n * Whether `options` carry at least one usable TURN server with its\n * credential, the ones a gathering with them allocates relay candidates from.\n */\nexport function hasTurnServer(options: IceServerFields) {\n return normalizeIceServerOptions(options).turnServers.length > 0;\n}\n\n/**\n * Whether `candidate`, kept from an earlier generation (an ICE restart keeps\n * the sockets), may be advertised and paired in a generation gathered with\n * `options`. A fresh gathering with the same options would not have produced\n * a host / server-reflexive candidate for a relay-only policy, a TCP host\n * candidate without useTcp, nor a relay candidate without a TURN server;\n * the kept ones are held back the same way.\n */\nexport function isCandidateAllowedByGatherOptions(\n candidate: Pick<Candidate, \"type\" | \"transport\">,\n options: Pick<IceOptions, \"forceTurn\"> &\n Partial<Pick<IceOptions, \"useTcp\">> &\n IceServerFields,\n) {\n if (candidate.type === \"relay\") return hasTurnServer(options);\n if (isRelayOnlyGathering(options)) return false;\n if (candidate.transport.toLowerCase() === \"tcp\" && !options.useTcp) {\n return false;\n }\n return true;\n}\n"]}
|
package/lib/ice/src/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { randomPort } from "../../common/src";
|
|
2
2
|
export * from "./candidate";
|
|
3
|
+
export * from "./candidateError";
|
|
4
|
+
export { IceRestartedError } from "./exceptions";
|
|
5
|
+
export * from "./gatheringError";
|
|
3
6
|
export * from "./ice";
|
|
4
7
|
export * from "./iceBase";
|
|
5
8
|
export * from "./stun/const";
|
package/lib/ice/src/index.js
CHANGED
|
@@ -14,10 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.randomPort = void 0;
|
|
17
|
+
exports.IceRestartedError = exports.randomPort = void 0;
|
|
18
18
|
var src_1 = require("../../common/src");
|
|
19
19
|
Object.defineProperty(exports, "randomPort", { enumerable: true, get: function () { return src_1.randomPort; } });
|
|
20
20
|
__exportStar(require("./candidate"), exports);
|
|
21
|
+
__exportStar(require("./candidateError"), exports);
|
|
22
|
+
var exceptions_1 = require("./exceptions");
|
|
23
|
+
Object.defineProperty(exports, "IceRestartedError", { enumerable: true, get: function () { return exceptions_1.IceRestartedError; } });
|
|
24
|
+
__exportStar(require("./gatheringError"), exports);
|
|
21
25
|
__exportStar(require("./ice"), exports);
|
|
22
26
|
__exportStar(require("./iceBase"), exports);
|
|
23
27
|
__exportStar(require("./stun/const"), exports);
|