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
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pairKey = exports.RegularNomination = exports.decideNomination = exports.PREFERRED_PAIR_WAIT_MS = exports.ICE_NOMINATION_ABANDONED = exports.NOMINATION_ATTEMPTS = exports.DEFAULT_NOMINATION_DELAY_MS = void 0;
|
|
4
|
+
const iceBase_1 = require("../iceBase");
|
|
5
|
+
const common_1 = require("../imports/common");
|
|
6
|
+
const log = (0, common_1.debug)("werift-ice : packages/ice/src/nomination/regularNomination.ts : log");
|
|
7
|
+
/** Default of `IceOptions.nominationDelayMs`. */
|
|
8
|
+
exports.DEFAULT_NOMINATION_DELAY_MS = 300;
|
|
9
|
+
/**
|
|
10
|
+
* USE-CANDIDATE transactions sent for one pair before an unanswered
|
|
11
|
+
* nomination gives up (each one retransmits as a check does).
|
|
12
|
+
*/
|
|
13
|
+
exports.NOMINATION_ATTEMPTS = 3;
|
|
14
|
+
/**
|
|
15
|
+
* Check-list result: an unanswered nomination was abandoned. Unlike
|
|
16
|
+
* ICE_FAILED (which connect() keeps waiting past, as more candidates may
|
|
17
|
+
* still pair), it ends connect() with an error.
|
|
18
|
+
*/
|
|
19
|
+
exports.ICE_NOMINATION_ABANDONED = 3;
|
|
20
|
+
/**
|
|
21
|
+
* How long, from the start of its checks, the live checklist waits for the pair
|
|
22
|
+
* a provisional nomination may have selected (`NominationHint`) to appear.
|
|
23
|
+
* It can appear after end-of-candidates: a peer-reflexive or passive TCP
|
|
24
|
+
* pair forms only when the peer's check arrives. Covers the peer's check
|
|
25
|
+
* pacing and a TCP check's response timeout (`TCP_CHECK_RESPONSE_TIMEOUT_MS`).
|
|
26
|
+
*/
|
|
27
|
+
exports.PREFERRED_PAIR_WAIT_MS = 3000;
|
|
28
|
+
/**
|
|
29
|
+
* RFC 8445 §8.1.1 regular nomination: when the controlling agent stops
|
|
30
|
+
* checking and nominates, shared by the live and the provisional checklist.
|
|
31
|
+
*
|
|
32
|
+
* - With a `preferred` rule (the peer may have selected that path already,
|
|
33
|
+
* see `NominationHint`), only the matching pair may be nominated: as soon
|
|
34
|
+
* as it is valid, waited for while its check runs. When it fails, or is not
|
|
35
|
+
* in the checklist `PREFERRED_PAIR_WAIT_MS` (at least the delay) after the
|
|
36
|
+
* checklist began, even after end-of-candidates or with no other valid
|
|
37
|
+
* pair, the nomination is
|
|
38
|
+
* abandoned (as an unanswered one is):
|
|
39
|
+
* nominating another pair could leave the agents on different paths.
|
|
40
|
+
* - The candidate is the first valid (Succeeded) pair of `pairs` (priority
|
|
41
|
+
* order, highest first), so the choice is deterministic.
|
|
42
|
+
* - Nominate at once when both sides signalled end-of-candidates and no
|
|
43
|
+
* higher-priority pair can still succeed.
|
|
44
|
+
* - Otherwise wait until `quietSince + delayMs`, then nominate anyway: a
|
|
45
|
+
* higher-priority pair still in progress (an unreachable host pair takes
|
|
46
|
+
* seconds to fail) or a peer that never signals end-of-candidates must not
|
|
47
|
+
* hold the selection back longer than that.
|
|
48
|
+
*/
|
|
49
|
+
const decideNomination = ({ pairs, remoteCandidatesEnd, localCandidatesEnd, quietSince, delayMs, now, unchecked, preferred, preferredSince, }) => {
|
|
50
|
+
if (preferred) {
|
|
51
|
+
const hinted = pairs.find(preferred);
|
|
52
|
+
if (hinted?.state === iceBase_1.CandidatePairState.SUCCEEDED) {
|
|
53
|
+
return { action: "nominate", pair: hinted };
|
|
54
|
+
}
|
|
55
|
+
if (hinted) {
|
|
56
|
+
if (hinted.state === iceBase_1.CandidatePairState.FAILED || unchecked(hinted)) {
|
|
57
|
+
return { action: "abandon", pair: hinted };
|
|
58
|
+
}
|
|
59
|
+
// Its check finishing re-evaluates the nomination.
|
|
60
|
+
return { action: "none" };
|
|
61
|
+
}
|
|
62
|
+
// Not (yet) in the checklist. End-of-candidates does not settle it, nor
|
|
63
|
+
// does an empty checklist: a peer-reflexive pair (or a passive TCP one) is
|
|
64
|
+
// only formed when the peer's check arrives, so wait for it a bounded time
|
|
65
|
+
// from when the checklist began.
|
|
66
|
+
const deadline = (preferredSince ?? now) + Math.max(delayMs, exports.PREFERRED_PAIR_WAIT_MS);
|
|
67
|
+
if (now >= deadline)
|
|
68
|
+
return { action: "abandon" };
|
|
69
|
+
return { action: "wait", deadline };
|
|
70
|
+
}
|
|
71
|
+
const index = pairs.findIndex((pair) => pair.state === iceBase_1.CandidatePairState.SUCCEEDED);
|
|
72
|
+
if (index === -1)
|
|
73
|
+
return { action: "none" };
|
|
74
|
+
const pair = pairs[index];
|
|
75
|
+
const pendingAbove = pairs
|
|
76
|
+
.slice(0, index)
|
|
77
|
+
.some((above) => above.state !== iceBase_1.CandidatePairState.FAILED && !unchecked(above));
|
|
78
|
+
if (remoteCandidatesEnd && localCandidatesEnd && !pendingAbove) {
|
|
79
|
+
return { action: "nominate", pair };
|
|
80
|
+
}
|
|
81
|
+
const deadline = (quietSince ?? now) + delayMs;
|
|
82
|
+
if (now >= deadline)
|
|
83
|
+
return { action: "nominate", pair };
|
|
84
|
+
return { action: "wait", deadline };
|
|
85
|
+
};
|
|
86
|
+
exports.decideNomination = decideNomination;
|
|
87
|
+
/**
|
|
88
|
+
* The regular nomination (RFC 8445 §8.1.1) of one checklist: the single
|
|
89
|
+
* state and rule set the live checklist and the provisional (ICE-restart)
|
|
90
|
+
* checklist share. It holds the delay, the USE-CANDIDATE attempt in flight,
|
|
91
|
+
* its repeats and the abandoned state; the checklist supplies the pairs and
|
|
92
|
+
* applies the outcome (`NominationHost`).
|
|
93
|
+
*
|
|
94
|
+
* - Delay: `quietSince` is the first valid pair, moved forward by every pair
|
|
95
|
+
* added later that outranks the best valid pair and is checked locally
|
|
96
|
+
* (a forceTurn-excluded pair cannot replace it and does not count).
|
|
97
|
+
* - One attempt at a time; a result whose attempt is no longer current (a
|
|
98
|
+
* restart, a replacement pranswer, close or a role change replaced it) is
|
|
99
|
+
* ignored and its transaction aborted.
|
|
100
|
+
* - An unanswered attempt may have been accepted: it is repeated on the same
|
|
101
|
+
* pair (never another), also when a repeat is answered with an error. When
|
|
102
|
+
* all `NOMINATION_ATTEMPTS` go unanswered nothing else is nominated.
|
|
103
|
+
* - An error answering the first attempt: only that pair fails.
|
|
104
|
+
*/
|
|
105
|
+
class RegularNomination {
|
|
106
|
+
constructor(host) {
|
|
107
|
+
Object.defineProperty(this, "quietSince", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
configurable: true,
|
|
110
|
+
writable: true,
|
|
111
|
+
value: void 0
|
|
112
|
+
});
|
|
113
|
+
/** The checklist began waiting for the preferred pair (see `decideNomination`). */
|
|
114
|
+
Object.defineProperty(this, "preferredSince", {
|
|
115
|
+
enumerable: true,
|
|
116
|
+
configurable: true,
|
|
117
|
+
writable: true,
|
|
118
|
+
value: void 0
|
|
119
|
+
});
|
|
120
|
+
Object.defineProperty(this, "timer", {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
configurable: true,
|
|
123
|
+
writable: true,
|
|
124
|
+
value: void 0
|
|
125
|
+
});
|
|
126
|
+
Object.defineProperty(this, "attempt", {
|
|
127
|
+
enumerable: true,
|
|
128
|
+
configurable: true,
|
|
129
|
+
writable: true,
|
|
130
|
+
value: void 0
|
|
131
|
+
});
|
|
132
|
+
/** Every attempt went unanswered: no other pair is nominated until reset. */
|
|
133
|
+
Object.defineProperty(this, "abandoned", {
|
|
134
|
+
enumerable: true,
|
|
135
|
+
configurable: true,
|
|
136
|
+
writable: true,
|
|
137
|
+
value: false
|
|
138
|
+
});
|
|
139
|
+
/**
|
|
140
|
+
* The pair a USE-CANDIDATE was sent to and the peer did not refuse: the
|
|
141
|
+
* peer may have selected it (the provisional checklist hands it to the
|
|
142
|
+
* live one at the final answer, see `NominationHint`).
|
|
143
|
+
*/
|
|
144
|
+
Object.defineProperty(this, "maybeSelected", {
|
|
145
|
+
enumerable: true,
|
|
146
|
+
configurable: true,
|
|
147
|
+
writable: true,
|
|
148
|
+
value: void 0
|
|
149
|
+
});
|
|
150
|
+
Object.defineProperty(this, "host", {
|
|
151
|
+
enumerable: true,
|
|
152
|
+
configurable: true,
|
|
153
|
+
writable: true,
|
|
154
|
+
value: void 0
|
|
155
|
+
});
|
|
156
|
+
this.host = host;
|
|
157
|
+
}
|
|
158
|
+
/** A USE-CANDIDATE transaction is in flight. */
|
|
159
|
+
get inFlight() {
|
|
160
|
+
return this.attempt !== undefined;
|
|
161
|
+
}
|
|
162
|
+
/** Waiting for the delay to end. */
|
|
163
|
+
get waiting() {
|
|
164
|
+
return this.timer !== undefined;
|
|
165
|
+
}
|
|
166
|
+
/** `pair` joined the checklist; `best` was its best valid pair before. */
|
|
167
|
+
pairAdded(pair, best) {
|
|
168
|
+
// A pair that may replace the best valid pair restarts the delay; a
|
|
169
|
+
// lower-priority one, or one the agent never checks, cannot change the
|
|
170
|
+
// choice and does not.
|
|
171
|
+
if (best && !this.host.unchecked(pair) && this.host.outranks(pair, best)) {
|
|
172
|
+
this.quietSince = Date.now();
|
|
173
|
+
this.evaluate();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Nominate now, or arm the timer that re-evaluates at the deadline. Called
|
|
178
|
+
* whenever the answer may change: a check finished, a pair was added,
|
|
179
|
+
* end-of-candidates, the role changed, the timer fired.
|
|
180
|
+
*/
|
|
181
|
+
evaluate() {
|
|
182
|
+
if (!this.host.active() || this.attempt || this.abandoned) {
|
|
183
|
+
this.stop();
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const pairs = this.host.pairs();
|
|
187
|
+
const now = Date.now();
|
|
188
|
+
if (this.quietSince === undefined &&
|
|
189
|
+
pairs.some((pair) => pair.state === iceBase_1.CandidatePairState.SUCCEEDED)) {
|
|
190
|
+
this.quietSince = now;
|
|
191
|
+
}
|
|
192
|
+
const preferred = this.host.preferred();
|
|
193
|
+
if (preferred &&
|
|
194
|
+
this.preferredSince === undefined &&
|
|
195
|
+
this.host.checking()) {
|
|
196
|
+
this.preferredSince = now;
|
|
197
|
+
}
|
|
198
|
+
const decision = (0, exports.decideNomination)({
|
|
199
|
+
pairs,
|
|
200
|
+
remoteCandidatesEnd: this.host.remoteCandidatesEnd(),
|
|
201
|
+
localCandidatesEnd: this.host.localCandidatesEnd(),
|
|
202
|
+
quietSince: this.quietSince,
|
|
203
|
+
delayMs: this.host.delayMs(),
|
|
204
|
+
now,
|
|
205
|
+
unchecked: this.host.unchecked,
|
|
206
|
+
preferred,
|
|
207
|
+
preferredSince: this.preferredSince,
|
|
208
|
+
});
|
|
209
|
+
this.stop();
|
|
210
|
+
if (decision.action === "wait") {
|
|
211
|
+
this.timer = setTimeout(() => {
|
|
212
|
+
this.timer = undefined;
|
|
213
|
+
this.evaluate();
|
|
214
|
+
this.host.deadlinePassed?.();
|
|
215
|
+
}, Math.max(0, decision.deadline - now));
|
|
216
|
+
}
|
|
217
|
+
else if (decision.action === "nominate") {
|
|
218
|
+
this.nominate(decision.pair, 1, false);
|
|
219
|
+
}
|
|
220
|
+
else if (decision.action === "abandon") {
|
|
221
|
+
log("preferred pair cannot be nominated, giving up");
|
|
222
|
+
this.abandoned = true;
|
|
223
|
+
this.host.abandoned(decision.pair);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/** Stop waiting (a pair was nominated, or nomination is not possible now). */
|
|
227
|
+
stop() {
|
|
228
|
+
if (this.timer !== undefined) {
|
|
229
|
+
clearTimeout(this.timer);
|
|
230
|
+
this.timer = undefined;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/** The role changed: the attempt in flight was sent as the controlling agent and changes nothing after it. */
|
|
234
|
+
invalidate() {
|
|
235
|
+
this.attempt?.abort.abort();
|
|
236
|
+
this.attempt = undefined;
|
|
237
|
+
this.abandoned = false;
|
|
238
|
+
}
|
|
239
|
+
/** The checklist starts over (restart, replacement pranswer, renomination, close). */
|
|
240
|
+
reset() {
|
|
241
|
+
this.invalidate();
|
|
242
|
+
this.stop();
|
|
243
|
+
this.quietSince = undefined;
|
|
244
|
+
this.preferredSince = undefined;
|
|
245
|
+
this.maybeSelected = undefined;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* @param maybeAccepted an earlier attempt for `pair` went unanswered: the
|
|
249
|
+
* peer may have selected the pair already, so no later outcome lets the
|
|
250
|
+
* nomination move to another pair.
|
|
251
|
+
*/
|
|
252
|
+
nominate(pair, attempt, maybeAccepted) {
|
|
253
|
+
log("nominate", pair.toJSON(), { attempt, maybeAccepted });
|
|
254
|
+
const current = { pair, abort: new AbortController() };
|
|
255
|
+
this.attempt = current;
|
|
256
|
+
this.maybeSelected = pair;
|
|
257
|
+
void this.host.send(pair, current.abort.signal).then((outcome) => {
|
|
258
|
+
if (this.attempt !== current)
|
|
259
|
+
return;
|
|
260
|
+
this.attempt = undefined;
|
|
261
|
+
if (!this.host.owns(pair)) {
|
|
262
|
+
// The pair left the checklist (another remote generation dropped).
|
|
263
|
+
if (this.maybeSelected === pair)
|
|
264
|
+
this.maybeSelected = undefined;
|
|
265
|
+
this.evaluate();
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (outcome === "nominated") {
|
|
269
|
+
this.stop();
|
|
270
|
+
this.host.nominated(pair);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (outcome === "role-conflict") {
|
|
274
|
+
// The peer did not accept it as controlled; it nominates now.
|
|
275
|
+
log("nomination role conflict", pair.toJSON());
|
|
276
|
+
if (!maybeAccepted)
|
|
277
|
+
this.maybeSelected = undefined;
|
|
278
|
+
this.host.roleConflict(pair);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (outcome === "unanswered" || maybeAccepted) {
|
|
282
|
+
if (attempt < exports.NOMINATION_ATTEMPTS) {
|
|
283
|
+
log("nomination unanswered, repeating", pair.toJSON(), { attempt });
|
|
284
|
+
this.nominate(pair, attempt + 1, true);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
log("nomination unanswered, giving up", pair.toJSON());
|
|
288
|
+
this.abandoned = true;
|
|
289
|
+
this.stop();
|
|
290
|
+
this.host.abandoned(pair);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
log("nomination rejected", pair.toJSON());
|
|
294
|
+
this.maybeSelected = undefined;
|
|
295
|
+
this.host.rejected(pair);
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
exports.RegularNomination = RegularNomination;
|
|
300
|
+
/** Local foundation and the 5-tuple: the same path in another checklist. */
|
|
301
|
+
const pairKey = (pair) => [
|
|
302
|
+
pair.localCandidate.foundation,
|
|
303
|
+
pair.localCandidate.transport.toLowerCase(),
|
|
304
|
+
pair.localCandidate.host,
|
|
305
|
+
pair.localCandidate.port,
|
|
306
|
+
pair.remoteCandidate.transport.toLowerCase(),
|
|
307
|
+
pair.remoteCandidate.host,
|
|
308
|
+
pair.remoteCandidate.port,
|
|
309
|
+
].join(" ");
|
|
310
|
+
exports.pairKey = pairKey;
|
|
311
|
+
//# sourceMappingURL=regularNomination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regularNomination.js","sourceRoot":"","sources":["../../../../../ice/src/nomination/regularNomination.ts"],"names":[],"mappings":";;;AAAA,wCAAoE;AACpE,8CAA0C;AAG1C,MAAM,GAAG,GAAG,IAAA,cAAK,EACf,qEAAqE,CACtE,CAAC;AAEF,iDAAiD;AACpC,QAAA,2BAA2B,GAAG,GAAG,CAAC;AAC/C;;;GAGG;AACU,QAAA,mBAAmB,GAAG,CAAC,CAAC;AACrC;;;;GAIG;AACU,QAAA,wBAAwB,GAAG,CAAC,CAAC;AAC1C;;;;;;GAMG;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AI,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA9KD,8CA8KC;AA6BD,4EAA4E;AACrE,MAAM,OAAO,GAAG,CAAC,IAAmB,EAAE,EAAE,CAC7C;IACE,IAAI,CAAC,cAAc,CAAC,UAAU;IAC9B,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,WAAW,EAAE;IAC3C,IAAI,CAAC,cAAc,CAAC,IAAI;IACxB,IAAI,CAAC,cAAc,CAAC,IAAI;IACxB,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,WAAW,EAAE;IAC5C,IAAI,CAAC,eAAe,CAAC,IAAI;IACzB,IAAI,CAAC,eAAe,CAAC,IAAI;CAC1B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AATD,QAAA,OAAO,WASN","sourcesContent":["import { type CandidatePair, CandidatePairState } from \"../iceBase\";\nimport { debug } from \"../imports/common\";\nimport type { Protocol } from \"../types/model\";\n\nconst log = debug(\n \"werift-ice : packages/ice/src/nomination/regularNomination.ts : log\",\n);\n\n/** Default of `IceOptions.nominationDelayMs`. */\nexport const DEFAULT_NOMINATION_DELAY_MS = 300;\n/**\n * USE-CANDIDATE transactions sent for one pair before an unanswered\n * nomination gives up (each one retransmits as a check does).\n */\nexport const NOMINATION_ATTEMPTS = 3;\n/**\n * Check-list result: an unanswered nomination was abandoned. Unlike\n * ICE_FAILED (which connect() keeps waiting past, as more candidates may\n * still pair), it ends connect() with an error.\n */\nexport const ICE_NOMINATION_ABANDONED = 3;\n/**\n * How long, from the start of its checks, the live checklist waits for the pair\n * a provisional nomination may have selected (`NominationHint`) to appear.\n * It can appear after end-of-candidates: a peer-reflexive or passive TCP\n * pair forms only when the peer's check arrives. Covers the peer's check\n * pacing and a TCP check's response timeout (`TCP_CHECK_RESPONSE_TIMEOUT_MS`).\n */\nexport const PREFERRED_PAIR_WAIT_MS = 3000;\n\nexport type NominationDecision =\n | { action: \"nominate\"; pair: CandidatePair }\n | { action: \"wait\"; deadline: number }\n /** The pair the peer may have selected cannot be nominated: nominate nothing else. */\n | { action: \"abandon\"; pair?: CandidatePair }\n | { action: \"none\" };\n\n/**\n * RFC 8445 §8.1.1 regular nomination: when the controlling agent stops\n * checking and nominates, shared by the live and the provisional checklist.\n *\n * - With a `preferred` rule (the peer may have selected that path already,\n * see `NominationHint`), only the matching pair may be nominated: as soon\n * as it is valid, waited for while its check runs. When it fails, or is not\n * in the checklist `PREFERRED_PAIR_WAIT_MS` (at least the delay) after the\n * checklist began, even after end-of-candidates or with no other valid\n * pair, the nomination is\n * abandoned (as an unanswered one is):\n * nominating another pair could leave the agents on different paths.\n * - The candidate is the first valid (Succeeded) pair of `pairs` (priority\n * order, highest first), so the choice is deterministic.\n * - Nominate at once when both sides signalled end-of-candidates and no\n * higher-priority pair can still succeed.\n * - Otherwise wait until `quietSince + delayMs`, then nominate anyway: a\n * higher-priority pair still in progress (an unreachable host pair takes\n * seconds to fail) or a peer that never signals end-of-candidates must not\n * hold the selection back longer than that.\n */\nexport const decideNomination = ({\n pairs,\n remoteCandidatesEnd,\n localCandidatesEnd,\n quietSince,\n delayMs,\n now,\n unchecked,\n preferred,\n preferredSince,\n}: {\n pairs: readonly CandidatePair[];\n remoteCandidatesEnd: boolean;\n localCandidatesEnd: boolean;\n quietSince: number | undefined;\n delayMs: number;\n now: number;\n /** Pairs never checked locally, which cannot be waited for. */\n unchecked: (pair: CandidatePair) => boolean;\n preferred: ((pair: CandidatePair) => boolean) | undefined;\n /** When the checklist began waiting for the `preferred` pair. */\n preferredSince: number | undefined;\n}): NominationDecision => {\n if (preferred) {\n const hinted = pairs.find(preferred);\n if (hinted?.state === CandidatePairState.SUCCEEDED) {\n return { action: \"nominate\", pair: hinted };\n }\n if (hinted) {\n if (hinted.state === CandidatePairState.FAILED || unchecked(hinted)) {\n return { action: \"abandon\", pair: hinted };\n }\n // Its check finishing re-evaluates the nomination.\n return { action: \"none\" };\n }\n // Not (yet) in the checklist. End-of-candidates does not settle it, nor\n // does an empty checklist: a peer-reflexive pair (or a passive TCP one) is\n // only formed when the peer's check arrives, so wait for it a bounded time\n // from when the checklist began.\n const deadline =\n (preferredSince ?? now) + Math.max(delayMs, PREFERRED_PAIR_WAIT_MS);\n if (now >= deadline) return { action: \"abandon\" };\n return { action: \"wait\", deadline };\n }\n const index = pairs.findIndex(\n (pair) => pair.state === CandidatePairState.SUCCEEDED,\n );\n if (index === -1) return { action: \"none\" };\n const pair = pairs[index];\n const pendingAbove = pairs\n .slice(0, index)\n .some(\n (above) => above.state !== CandidatePairState.FAILED && !unchecked(above),\n );\n if (remoteCandidatesEnd && localCandidatesEnd && !pendingAbove) {\n return { action: \"nominate\", pair };\n }\n const deadline = (quietSince ?? now) + delayMs;\n if (now >= deadline) return { action: \"nominate\", pair };\n return { action: \"wait\", deadline };\n};\n\n/** What a USE-CANDIDATE check came back with. */\nexport type NominationOutcome =\n /** Answered with success. */\n | \"nominated\"\n /** Timed out: the request may have reached the peer, which may have selected the pair. */\n | \"unanswered\"\n /** An error response, or the request never left (e.g. a refused TCP connect). */\n | \"rejected\"\n /** 487: the peer is controlling too and wins (RFC 8445 §7.2.5.1). */\n | \"role-conflict\";\n\n/** What a checklist (live or provisional) supplies to its `RegularNomination`. */\nexport type NominationHost = {\n /** The controlling agent nominates in this checklist now (full ICE on both sides, nothing nominated yet, the checklist still current). */\n active: () => boolean;\n /** The checklist's checks began (connect(), startProvisionalChecks()). */\n checking: () => boolean;\n /** The checklist, highest priority first. */\n pairs: () => readonly CandidatePair[];\n remoteCandidatesEnd: () => boolean;\n localCandidatesEnd: () => boolean;\n delayMs: () => number;\n /** Pairs never checked locally (forceTurn), which cannot be waited for. */\n unchecked: (pair: CandidatePair) => boolean;\n outranks: (pair: CandidatePair, other: CandidatePair) => boolean;\n /** Matches the only pair that may be nominated: the peer may have selected it already (see `NominationHint`). */\n preferred: () => ((pair: CandidatePair) => boolean) | undefined;\n /** A result for `pair` still applies: the pair is in the checklist and the agent open. */\n owns: (pair: CandidatePair) => boolean;\n /** Send the USE-CANDIDATE check; never rejects. */\n send: (\n pair: CandidatePair,\n signal: AbortSignal,\n ) => Promise<NominationOutcome>;\n nominated: (pair: CandidatePair) => void;\n /** The peer refused the pair: fail it, so the next valid pair is nominated. */\n rejected: (pair: CandidatePair) => void;\n roleConflict: (pair: CandidatePair) => void;\n /**\n * No attempt on a pair the peer may have selected was answered, or that\n * pair (the hint) failed or never appeared (`pair` undefined).\n */\n abandoned: (pair?: CandidatePair) => void;\n /** The delay ended (after the re-evaluation it triggers). */\n deadlinePassed?: () => void;\n};\n\n/**\n * The regular nomination (RFC 8445 §8.1.1) of one checklist: the single\n * state and rule set the live checklist and the provisional (ICE-restart)\n * checklist share. It holds the delay, the USE-CANDIDATE attempt in flight,\n * its repeats and the abandoned state; the checklist supplies the pairs and\n * applies the outcome (`NominationHost`).\n *\n * - Delay: `quietSince` is the first valid pair, moved forward by every pair\n * added later that outranks the best valid pair and is checked locally\n * (a forceTurn-excluded pair cannot replace it and does not count).\n * - One attempt at a time; a result whose attempt is no longer current (a\n * restart, a replacement pranswer, close or a role change replaced it) is\n * ignored and its transaction aborted.\n * - An unanswered attempt may have been accepted: it is repeated on the same\n * pair (never another), also when a repeat is answered with an error. When\n * all `NOMINATION_ATTEMPTS` go unanswered nothing else is nominated.\n * - An error answering the first attempt: only that pair fails.\n */\nexport class RegularNomination {\n private quietSince?: number;\n /** The checklist began waiting for the preferred pair (see `decideNomination`). */\n private preferredSince?: number;\n private timer?: ReturnType<typeof setTimeout>;\n private attempt?: { pair: CandidatePair; abort: AbortController };\n /** Every attempt went unanswered: no other pair is nominated until reset. */\n abandoned = false;\n /**\n * The pair a USE-CANDIDATE was sent to and the peer did not refuse: the\n * peer may have selected it (the provisional checklist hands it to the\n * live one at the final answer, see `NominationHint`).\n */\n maybeSelected?: CandidatePair;\n\n private readonly host: NominationHost;\n\n constructor(host: NominationHost) {\n this.host = host;\n }\n\n /** A USE-CANDIDATE transaction is in flight. */\n get inFlight() {\n return this.attempt !== undefined;\n }\n\n /** Waiting for the delay to end. */\n get waiting() {\n return this.timer !== undefined;\n }\n\n /** `pair` joined the checklist; `best` was its best valid pair before. */\n pairAdded(pair: CandidatePair, best: CandidatePair | undefined) {\n // A pair that may replace the best valid pair restarts the delay; a\n // lower-priority one, or one the agent never checks, cannot change the\n // choice and does not.\n if (best && !this.host.unchecked(pair) && this.host.outranks(pair, best)) {\n this.quietSince = Date.now();\n this.evaluate();\n }\n }\n\n /**\n * Nominate now, or arm the timer that re-evaluates at the deadline. Called\n * whenever the answer may change: a check finished, a pair was added,\n * end-of-candidates, the role changed, the timer fired.\n */\n evaluate() {\n if (!this.host.active() || this.attempt || this.abandoned) {\n this.stop();\n return;\n }\n const pairs = this.host.pairs();\n const now = Date.now();\n if (\n this.quietSince === undefined &&\n pairs.some((pair) => pair.state === CandidatePairState.SUCCEEDED)\n ) {\n this.quietSince = now;\n }\n const preferred = this.host.preferred();\n if (\n preferred &&\n this.preferredSince === undefined &&\n this.host.checking()\n ) {\n this.preferredSince = now;\n }\n const decision = decideNomination({\n pairs,\n remoteCandidatesEnd: this.host.remoteCandidatesEnd(),\n localCandidatesEnd: this.host.localCandidatesEnd(),\n quietSince: this.quietSince,\n delayMs: this.host.delayMs(),\n now,\n unchecked: this.host.unchecked,\n preferred,\n preferredSince: this.preferredSince,\n });\n this.stop();\n if (decision.action === \"wait\") {\n this.timer = setTimeout(\n () => {\n this.timer = undefined;\n this.evaluate();\n this.host.deadlinePassed?.();\n },\n Math.max(0, decision.deadline - now),\n );\n } else if (decision.action === \"nominate\") {\n this.nominate(decision.pair, 1, false);\n } else if (decision.action === \"abandon\") {\n log(\"preferred pair cannot be nominated, giving up\");\n this.abandoned = true;\n this.host.abandoned(decision.pair);\n }\n }\n\n /** Stop waiting (a pair was nominated, or nomination is not possible now). */\n stop() {\n if (this.timer !== undefined) {\n clearTimeout(this.timer);\n this.timer = undefined;\n }\n }\n\n /** The role changed: the attempt in flight was sent as the controlling agent and changes nothing after it. */\n invalidate() {\n this.attempt?.abort.abort();\n this.attempt = undefined;\n this.abandoned = false;\n }\n\n /** The checklist starts over (restart, replacement pranswer, renomination, close). */\n reset() {\n this.invalidate();\n this.stop();\n this.quietSince = undefined;\n this.preferredSince = undefined;\n this.maybeSelected = undefined;\n }\n\n /**\n * @param maybeAccepted an earlier attempt for `pair` went unanswered: the\n * peer may have selected the pair already, so no later outcome lets the\n * nomination move to another pair.\n */\n private nominate(\n pair: CandidatePair,\n attempt: number,\n maybeAccepted: boolean,\n ) {\n log(\"nominate\", pair.toJSON(), { attempt, maybeAccepted });\n const current = { pair, abort: new AbortController() };\n this.attempt = current;\n this.maybeSelected = pair;\n void this.host.send(pair, current.abort.signal).then((outcome) => {\n if (this.attempt !== current) return;\n this.attempt = undefined;\n if (!this.host.owns(pair)) {\n // The pair left the checklist (another remote generation dropped).\n if (this.maybeSelected === pair) this.maybeSelected = undefined;\n this.evaluate();\n return;\n }\n if (outcome === \"nominated\") {\n this.stop();\n this.host.nominated(pair);\n return;\n }\n if (outcome === \"role-conflict\") {\n // The peer did not accept it as controlled; it nominates now.\n log(\"nomination role conflict\", pair.toJSON());\n if (!maybeAccepted) this.maybeSelected = undefined;\n this.host.roleConflict(pair);\n return;\n }\n if (outcome === \"unanswered\" || maybeAccepted) {\n if (attempt < NOMINATION_ATTEMPTS) {\n log(\"nomination unanswered, repeating\", pair.toJSON(), { attempt });\n this.nominate(pair, attempt + 1, true);\n return;\n }\n log(\"nomination unanswered, giving up\", pair.toJSON());\n this.abandoned = true;\n this.stop();\n this.host.abandoned(pair);\n return;\n }\n log(\"nomination rejected\", pair.toJSON());\n this.maybeSelected = undefined;\n this.host.rejected(pair);\n });\n }\n}\n\n/**\n * The pair the controlling agent may have nominated in the provisional\n * checklist when a final answer replaced it with the live one. The peer\n * may have selected that pair already: a USE-CANDIDATE retransmission can\n * reach its live checklist (same credentials) after it committed the\n * answer, and a peer that keeps the ICE session across pranswer -> answer\n * (JSEP) keeps its provisional selection. The live checklist checks from\n * scratch (`[2.7-T4a]`) but nominates only the pair with the same 5-tuple;\n * when that pair fails or never appears it nominates nothing else and the\n * agent fails (see `decideNomination`). It only applies while the live\n * checklist uses the provisional credentials and the agent keeps the pair's\n * local socket (`protocol`); otherwise the usual rules choose the pair.\n */\nexport type NominationHint = {\n localUsername: string;\n remoteUsername: string;\n remotePassword: string;\n key: string;\n /**\n * The local socket (or TURN allocation) of the pair. The hint holds only\n * while the agent keeps it: a commit that closes it (an ICE restart\n * allocates TURN afresh, gather options that exclude the socket) ends the\n * path for both agents, so no selection of the peer is left to match.\n */\n protocol: Protocol;\n};\n\n/** Local foundation and the 5-tuple: the same path in another checklist. */\nexport const pairKey = (pair: CandidatePair) =>\n [\n pair.localCandidate.foundation,\n pair.localCandidate.transport.toLowerCase(),\n pair.localCandidate.host,\n pair.localCandidate.port,\n pair.remoteCandidate.transport.toLowerCase(),\n pair.remoteCandidate.host,\n pair.remoteCandidate.port,\n ].join(\" \");\n"]}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { notReceivingSince, type PairLiveness } from "../failover";
|
|
2
|
+
import { type CandidatePair } from "../iceBase";
|
|
3
|
+
/** What `shouldSwitch` knows about a pair. */
|
|
4
|
+
export type SwitchPairState = {
|
|
5
|
+
/** A response to a check came back and the pair is not unwritable (`isWritable`). */
|
|
6
|
+
writable: boolean;
|
|
7
|
+
/** The last response, request or application data received on the pair (ms). */
|
|
8
|
+
lastReceived: number;
|
|
9
|
+
/**
|
|
10
|
+
* When the first of the consecutive unanswered checks of the pair was
|
|
11
|
+
* counted (ms, `PairLiveness.missedSince`); undefined while its last check
|
|
12
|
+
* was answered.
|
|
13
|
+
*/
|
|
14
|
+
missedSince?: number;
|
|
15
|
+
/** The smoothed RTT (seconds, `CandidatePair.smoothedRtt`); undefined: not known yet. */
|
|
16
|
+
rtt?: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Why a pair wins over the selected one (`shouldSwitch`):
|
|
20
|
+
* - `writable`: the selection is not writable;
|
|
21
|
+
* - `receiving`: the selection has not been receiving for
|
|
22
|
+
* `RECEIVING_SWITCHING_DELAY`, the pair is receiving;
|
|
23
|
+
* - `priority`: the pair outranks the selection;
|
|
24
|
+
* - `rtt`: equal otherwise, the pair's smoothed RTT is at least
|
|
25
|
+
* `RTT_SWITCH_MIN_IMPROVEMENT` lower.
|
|
26
|
+
*/
|
|
27
|
+
export type SwitchReason = "writable" | "receiving" | "priority" | "rtt";
|
|
28
|
+
export type SwitchDecision = {
|
|
29
|
+
/** The pair wins over the selection; undefined: the selection stays. */
|
|
30
|
+
reason?: SwitchReason;
|
|
31
|
+
/**
|
|
32
|
+
* When (ms) to decide again while a receiving switch is held back
|
|
33
|
+
* (libwebrtc's recheck event).
|
|
34
|
+
* @see tests/ice/selection-controller.test.ts "a pair that wins only by receiving waits RECEIVING_SWITCHING_DELAY and asks for a recheck"
|
|
35
|
+
*/
|
|
36
|
+
recheckAt?: number;
|
|
37
|
+
};
|
|
38
|
+
export { notReceivingSince };
|
|
39
|
+
/**
|
|
40
|
+
* Whether the controlling agent moves the selection from `selected` to
|
|
41
|
+
* `candidate` (`priority` > 0: `candidate` outranks it), as libwebrtc's
|
|
42
|
+
* `BasicIceController::ShouldSwitchConnection`: writable, receiving (held for
|
|
43
|
+
* `RECEIVING_SWITCHING_DELAY`), priority, then the smoothed RTT. The network
|
|
44
|
+
* cost libwebrtc compares before the priority is unknown in Node.js.
|
|
45
|
+
* @see tests/ice/selection-controller.test.ts "state comes before priority and priority before RTT"
|
|
46
|
+
* @see tests/ice/selection-controller.test.ts "a pair that wins only by receiving waits RECEIVING_SWITCHING_DELAY and asks for a recheck"
|
|
47
|
+
* @see tests/ice/selection-controller.test.ts "silence alone (no unanswered check) is not 'not receiving'; a receiving selection beats a pair that is not"
|
|
48
|
+
* @see tests/ice/selection-controller.test.ts "a late unanswered check starts the hold at the check, and a recovery in the hold keeps the selection"
|
|
49
|
+
* @see tests/ice/selection-controller.test.ts "equal priority: moves only to a pair whose smoothed RTT is at least 10 ms lower"
|
|
50
|
+
*/
|
|
51
|
+
export declare function shouldSwitch({ selected, candidate, priority, now, receivingSwitchingDelay, receivingTimeout, minRttImprovement, }: {
|
|
52
|
+
selected: SwitchPairState;
|
|
53
|
+
candidate: SwitchPairState;
|
|
54
|
+
priority: number;
|
|
55
|
+
now: number;
|
|
56
|
+
receivingSwitchingDelay?: number;
|
|
57
|
+
receivingTimeout?: number;
|
|
58
|
+
minRttImprovement?: number;
|
|
59
|
+
}): SwitchDecision;
|
|
60
|
+
/** What the agent supplies to its `SelectionController`. */
|
|
61
|
+
export type SelectionControllerHost = {
|
|
62
|
+
/**
|
|
63
|
+
* The controller applies now: a controlling full agent with
|
|
64
|
+
* semi-aggressive nomination or renomination within the failover scope,
|
|
65
|
+
* a selection that is up (failover handles one that stopped answering)
|
|
66
|
+
* and no nominating check in flight.
|
|
67
|
+
*/
|
|
68
|
+
active: () => boolean;
|
|
69
|
+
selected: () => CandidatePair | undefined;
|
|
70
|
+
/** The pairs the selection may move to (the monitored backups). */
|
|
71
|
+
candidates: () => readonly CandidatePair[];
|
|
72
|
+
/** The liveness the failover monitor keeps for `pair`. */
|
|
73
|
+
liveness: (pair: CandidatePair) => PairLiveness | undefined;
|
|
74
|
+
writable: (pair: CandidatePair, now: number) => boolean;
|
|
75
|
+
/** `IceOptions.failover` thresholds (`receivingTimeout`, `receivingSwitchingDelay`). */
|
|
76
|
+
thresholds?: () => {
|
|
77
|
+
receivingTimeout: number;
|
|
78
|
+
receivingSwitchingDelay: number;
|
|
79
|
+
};
|
|
80
|
+
/** `pair` may be nominated (not on a path the agent failed over from). */
|
|
81
|
+
allows: (pair: CandidatePair) => boolean;
|
|
82
|
+
/** > 0 when `pair` outranks `other` (pair priority). */
|
|
83
|
+
comparePriority: (pair: CandidatePair, other: CandidatePair) => number;
|
|
84
|
+
/** Nominate `pair` to replace the selection for `reason`. */
|
|
85
|
+
switchTo: (pair: CandidatePair, reason: "receiving" | "rtt") => void;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* The controlling agent's moves of the selected pair by receiving state and
|
|
89
|
+
* RTT (`shouldSwitch`), as libwebrtc's ICE controller.
|
|
90
|
+
* @see tests/ice/selection-controller.test.ts "equal priority: the selection moves to the pair whose RTT is 11 ms lower, nominating it"
|
|
91
|
+
* @see tests/ice/selection-controller.test.ts "receiving: a selection that recovers within RECEIVING_SWITCHING_DELAY stays; one that does not moves after it"
|
|
92
|
+
* @see tests/ice/selection-controller.test.ts "the hold is counted from the unanswered check: no switch right after it, the recheck at its end switches"
|
|
93
|
+
* @see tests/ice/selection-controller.test.ts "controlled: the agent does not switch by RTT itself (it follows the peer's nominations)"
|
|
94
|
+
*/
|
|
95
|
+
export declare class SelectionController {
|
|
96
|
+
private recheck?;
|
|
97
|
+
private readonly host;
|
|
98
|
+
constructor(host: SelectionControllerHost);
|
|
99
|
+
/** Decide whether the selection moves, and nominate the pair it moves to. */
|
|
100
|
+
evaluate(): void;
|
|
101
|
+
/** Stop the pending recheck (restart, close, the failover monitor reset). */
|
|
102
|
+
stop(): void;
|
|
103
|
+
/**
|
|
104
|
+
* Whether `a` is a better target than `b`: receiving, priority, then RTT.
|
|
105
|
+
* @see tests/ice/selection-controller.test.ts "a receiving backup of lower priority wins over a silent one of equal priority and lower RTT"
|
|
106
|
+
* @see tests/ice/selection-controller.test.ts "among receiving backups the higher priority wins, then the lower RTT"
|
|
107
|
+
*/
|
|
108
|
+
private betterTarget;
|
|
109
|
+
private scheduleRecheck;
|
|
110
|
+
private clearRecheck;
|
|
111
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SelectionController = exports.notReceivingSince = void 0;
|
|
4
|
+
exports.shouldSwitch = shouldSwitch;
|
|
5
|
+
const failover_1 = require("../failover");
|
|
6
|
+
Object.defineProperty(exports, "notReceivingSince", { enumerable: true, get: function () { return failover_1.notReceivingSince; } });
|
|
7
|
+
const iceBase_1 = require("../iceBase");
|
|
8
|
+
const common_1 = require("../imports/common");
|
|
9
|
+
const log = (0, common_1.debug)("werift-ice : packages/ice/src/nomination/selectionController.ts : log");
|
|
10
|
+
/**
|
|
11
|
+
* Whether the controlling agent moves the selection from `selected` to
|
|
12
|
+
* `candidate` (`priority` > 0: `candidate` outranks it), as libwebrtc's
|
|
13
|
+
* `BasicIceController::ShouldSwitchConnection`: writable, receiving (held for
|
|
14
|
+
* `RECEIVING_SWITCHING_DELAY`), priority, then the smoothed RTT. The network
|
|
15
|
+
* cost libwebrtc compares before the priority is unknown in Node.js.
|
|
16
|
+
* @see tests/ice/selection-controller.test.ts "state comes before priority and priority before RTT"
|
|
17
|
+
* @see tests/ice/selection-controller.test.ts "a pair that wins only by receiving waits RECEIVING_SWITCHING_DELAY and asks for a recheck"
|
|
18
|
+
* @see tests/ice/selection-controller.test.ts "silence alone (no unanswered check) is not 'not receiving'; a receiving selection beats a pair that is not"
|
|
19
|
+
* @see tests/ice/selection-controller.test.ts "a late unanswered check starts the hold at the check, and a recovery in the hold keeps the selection"
|
|
20
|
+
* @see tests/ice/selection-controller.test.ts "equal priority: moves only to a pair whose smoothed RTT is at least 10 ms lower"
|
|
21
|
+
*/
|
|
22
|
+
function shouldSwitch({ selected, candidate, priority, now, receivingSwitchingDelay = iceBase_1.RECEIVING_SWITCHING_DELAY, receivingTimeout = iceBase_1.WEAK_CONNECTION_RECEIVE_TIMEOUT, minRttImprovement = iceBase_1.RTT_SWITCH_MIN_IMPROVEMENT, }) {
|
|
23
|
+
if (!candidate.writable)
|
|
24
|
+
return {};
|
|
25
|
+
if (!selected.writable)
|
|
26
|
+
return { reason: "writable" };
|
|
27
|
+
let recheckAt;
|
|
28
|
+
const selectedSince = (0, failover_1.notReceivingSince)(selected, now, receivingTimeout);
|
|
29
|
+
const candidateSince = (0, failover_1.notReceivingSince)(candidate, now, receivingTimeout);
|
|
30
|
+
if (selectedSince === undefined && candidateSince !== undefined)
|
|
31
|
+
return {};
|
|
32
|
+
if (selectedSince !== undefined && candidateSince === undefined) {
|
|
33
|
+
if (now - selectedSince >= receivingSwitchingDelay) {
|
|
34
|
+
return { reason: "receiving" };
|
|
35
|
+
}
|
|
36
|
+
recheckAt = selectedSince + receivingSwitchingDelay;
|
|
37
|
+
}
|
|
38
|
+
if (priority > 0)
|
|
39
|
+
return { reason: "priority", recheckAt };
|
|
40
|
+
if (priority < 0)
|
|
41
|
+
return { recheckAt };
|
|
42
|
+
if (candidate.rtt !== undefined &&
|
|
43
|
+
selected.rtt !== undefined &&
|
|
44
|
+
candidate.rtt * 1000 <= selected.rtt * 1000 - minRttImprovement) {
|
|
45
|
+
return { reason: "rtt", recheckAt };
|
|
46
|
+
}
|
|
47
|
+
return { recheckAt };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The controlling agent's moves of the selected pair by receiving state and
|
|
51
|
+
* RTT (`shouldSwitch`), as libwebrtc's ICE controller.
|
|
52
|
+
* @see tests/ice/selection-controller.test.ts "equal priority: the selection moves to the pair whose RTT is 11 ms lower, nominating it"
|
|
53
|
+
* @see tests/ice/selection-controller.test.ts "receiving: a selection that recovers within RECEIVING_SWITCHING_DELAY stays; one that does not moves after it"
|
|
54
|
+
* @see tests/ice/selection-controller.test.ts "the hold is counted from the unanswered check: no switch right after it, the recheck at its end switches"
|
|
55
|
+
* @see tests/ice/selection-controller.test.ts "controlled: the agent does not switch by RTT itself (it follows the peer's nominations)"
|
|
56
|
+
*/
|
|
57
|
+
class SelectionController {
|
|
58
|
+
constructor(host) {
|
|
59
|
+
Object.defineProperty(this, "recheck", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
writable: true,
|
|
63
|
+
value: void 0
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(this, "host", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: void 0
|
|
70
|
+
});
|
|
71
|
+
this.host = host;
|
|
72
|
+
}
|
|
73
|
+
/** Decide whether the selection moves, and nominate the pair it moves to. */
|
|
74
|
+
evaluate() {
|
|
75
|
+
this.clearRecheck();
|
|
76
|
+
if (!this.host.active())
|
|
77
|
+
return;
|
|
78
|
+
const selected = this.host.selected();
|
|
79
|
+
if (!selected)
|
|
80
|
+
return;
|
|
81
|
+
const selectedLiveness = this.host.liveness(selected);
|
|
82
|
+
if (!selectedLiveness)
|
|
83
|
+
return;
|
|
84
|
+
const now = Date.now();
|
|
85
|
+
const thresholds = this.host.thresholds?.();
|
|
86
|
+
const selectedState = {
|
|
87
|
+
writable: this.host.writable(selected, now),
|
|
88
|
+
lastReceived: selectedLiveness.lastReceived,
|
|
89
|
+
missedSince: selectedLiveness.missedSince,
|
|
90
|
+
rtt: selected.smoothedRtt,
|
|
91
|
+
};
|
|
92
|
+
let best;
|
|
93
|
+
let recheckAt;
|
|
94
|
+
for (const pair of this.host.candidates()) {
|
|
95
|
+
if (pair === selected || !this.host.allows(pair))
|
|
96
|
+
continue;
|
|
97
|
+
const liveness = this.host.liveness(pair);
|
|
98
|
+
if (!liveness)
|
|
99
|
+
continue;
|
|
100
|
+
const candidateState = {
|
|
101
|
+
writable: this.host.writable(pair, now),
|
|
102
|
+
lastReceived: liveness.lastReceived,
|
|
103
|
+
missedSince: liveness.missedSince,
|
|
104
|
+
rtt: pair.smoothedRtt,
|
|
105
|
+
};
|
|
106
|
+
const decision = shouldSwitch({
|
|
107
|
+
selected: selectedState,
|
|
108
|
+
candidate: candidateState,
|
|
109
|
+
priority: this.host.comparePriority(pair, selected),
|
|
110
|
+
now,
|
|
111
|
+
receivingTimeout: thresholds?.receivingTimeout,
|
|
112
|
+
receivingSwitchingDelay: thresholds?.receivingSwitchingDelay,
|
|
113
|
+
});
|
|
114
|
+
if (decision.recheckAt !== undefined) {
|
|
115
|
+
recheckAt = Math.min(recheckAt ?? Infinity, decision.recheckAt);
|
|
116
|
+
}
|
|
117
|
+
// Test: tests/ice/selection-controller.test.ts "a backup that wins by priority or over an unwritable selection is left to SelectionReplacement and the failover"
|
|
118
|
+
const reason = decision.reason;
|
|
119
|
+
if (reason !== "receiving" && reason !== "rtt")
|
|
120
|
+
continue;
|
|
121
|
+
const receiving = (0, failover_1.notReceivingSince)(candidateState, now, thresholds?.receivingTimeout) ===
|
|
122
|
+
undefined;
|
|
123
|
+
if (!best || this.betterTarget({ pair, receiving }, best)) {
|
|
124
|
+
best = { pair, reason, receiving };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (best) {
|
|
128
|
+
log("switch selection", best.reason, best.pair.toJSON(), {
|
|
129
|
+
selected: selected.toJSON(),
|
|
130
|
+
rtt: best.pair.smoothedRtt,
|
|
131
|
+
selectedRtt: selected.smoothedRtt,
|
|
132
|
+
});
|
|
133
|
+
this.host.switchTo(best.pair, best.reason);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (recheckAt !== undefined)
|
|
137
|
+
this.scheduleRecheck(recheckAt);
|
|
138
|
+
}
|
|
139
|
+
/** Stop the pending recheck (restart, close, the failover monitor reset). */
|
|
140
|
+
stop() {
|
|
141
|
+
this.clearRecheck();
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Whether `a` is a better target than `b`: receiving, priority, then RTT.
|
|
145
|
+
* @see tests/ice/selection-controller.test.ts "a receiving backup of lower priority wins over a silent one of equal priority and lower RTT"
|
|
146
|
+
* @see tests/ice/selection-controller.test.ts "among receiving backups the higher priority wins, then the lower RTT"
|
|
147
|
+
*/
|
|
148
|
+
betterTarget(a, b) {
|
|
149
|
+
if (a.receiving !== b.receiving)
|
|
150
|
+
return a.receiving;
|
|
151
|
+
const priority = this.host.comparePriority(a.pair, b.pair);
|
|
152
|
+
if (priority !== 0)
|
|
153
|
+
return priority > 0;
|
|
154
|
+
return (a.pair.smoothedRtt ?? Infinity) < (b.pair.smoothedRtt ?? Infinity);
|
|
155
|
+
}
|
|
156
|
+
scheduleRecheck(at) {
|
|
157
|
+
this.recheck = {
|
|
158
|
+
at,
|
|
159
|
+
timer: setTimeout(() => {
|
|
160
|
+
this.recheck = undefined;
|
|
161
|
+
this.evaluate();
|
|
162
|
+
}, Math.max(0, at - Date.now())),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
clearRecheck() {
|
|
166
|
+
if (this.recheck)
|
|
167
|
+
clearTimeout(this.recheck.timer);
|
|
168
|
+
this.recheck = undefined;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.SelectionController = SelectionController;
|
|
172
|
+
//# sourceMappingURL=selectionController.js.map
|