werift 0.26.0 → 0.27.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 +63 -0
- package/THIRD_PARTY_LICENSES_LIBWEBRTC.txt +58 -0
- package/lib/common/src/binary.d.ts +1 -3
- package/lib/common/src/binary.js +8 -6
- package/lib/common/src/binary.js.map +1 -1
- package/lib/common/src/binaryData.js +2 -1
- package/lib/common/src/binaryData.js.map +1 -1
- package/lib/common/src/log.js +5 -7
- package/lib/common/src/log.js.map +1 -1
- package/lib/common/src/transport.js +10 -5
- package/lib/common/src/transport.js.map +1 -1
- package/lib/dtls/src/context/cipher.d.ts +1 -1
- package/lib/dtls/src/context/cipher.js +6 -3
- package/lib/dtls/src/context/cipher.js.map +1 -1
- package/lib/dtls/src/context/dtls.js +4 -2
- package/lib/dtls/src/context/dtls.js.map +1 -1
- package/lib/dtls/src/context/transport.js +2 -1
- package/lib/dtls/src/context/transport.js.map +1 -1
- package/lib/dtls/src/flight/client/flight1.js +2 -1
- package/lib/dtls/src/flight/client/flight1.js.map +1 -1
- package/lib/dtls/src/flight/client/flight5.js +4 -2
- package/lib/dtls/src/flight/client/flight5.js.map +1 -1
- package/lib/dtls/src/flight/flight.d.ts +1 -1
- package/lib/dtls/src/flight/flight.js +8 -4
- package/lib/dtls/src/flight/flight.js.map +1 -1
- package/lib/dtls/src/flight/server/flight4.js +4 -2
- package/lib/dtls/src/flight/server/flight4.js.map +1 -1
- package/lib/dtls/src/flight/server/flight6.js +2 -1
- package/lib/dtls/src/flight/server/flight6.js.map +1 -1
- package/lib/dtls/src/handshake/const.d.ts +17 -13
- package/lib/dtls/src/handshake/const.js +16 -14
- package/lib/dtls/src/handshake/const.js.map +1 -1
- package/lib/dtls/src/handshake/message/alert.js +4 -2
- package/lib/dtls/src/handshake/message/alert.js.map +1 -1
- package/lib/dtls/src/handshake/message/certificate.js +2 -1
- package/lib/dtls/src/handshake/message/certificate.js.map +1 -1
- package/lib/dtls/src/handshake/message/changeCipherSpec.js +2 -1
- package/lib/dtls/src/handshake/message/changeCipherSpec.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/certificateVerify.js +4 -2
- package/lib/dtls/src/handshake/message/client/certificateVerify.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/hello.js +14 -7
- package/lib/dtls/src/handshake/message/client/hello.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/keyExchange.js +2 -1
- package/lib/dtls/src/handshake/message/client/keyExchange.js.map +1 -1
- package/lib/dtls/src/handshake/message/finished.js +2 -1
- package/lib/dtls/src/handshake/message/finished.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/certificateRequest.js +6 -3
- package/lib/dtls/src/handshake/message/server/certificateRequest.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/hello.js +12 -6
- package/lib/dtls/src/handshake/message/server/hello.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/helloDone.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js +4 -2
- package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/keyExchange.js +16 -8
- package/lib/dtls/src/handshake/message/server/keyExchange.js.map +1 -1
- package/lib/dtls/src/handshake/random.d.ts +2 -2
- package/lib/dtls/src/handshake/random.js +5 -2
- package/lib/dtls/src/handshake/random.js.map +1 -1
- package/lib/dtls/src/record/const.d.ts +43 -33
- package/lib/dtls/src/record/const.js +43 -36
- package/lib/dtls/src/record/const.js.map +1 -1
- package/lib/dtls/src/record/message/fragment.js +12 -6
- package/lib/dtls/src/record/message/fragment.js.map +1 -1
- package/lib/dtls/src/record/message/header.js +10 -5
- package/lib/dtls/src/record/message/header.js.map +1 -1
- package/lib/dtls/src/record/message/plaintext.js +4 -2
- package/lib/dtls/src/record/message/plaintext.js.map +1 -1
- package/lib/dtls/src/record/receive.js +2 -2
- package/lib/dtls/src/record/receive.js.map +1 -1
- package/lib/dtls/src/socket.js +4 -2
- package/lib/dtls/src/socket.js.map +1 -1
- package/lib/ice/src/candidate.d.ts +1 -1
- package/lib/ice/src/candidate.js +24 -12
- package/lib/ice/src/candidate.js.map +1 -1
- package/lib/ice/src/dns/lookup.d.ts +10 -1
- package/lib/ice/src/dns/lookup.js +42 -7
- package/lib/ice/src/dns/lookup.js.map +1 -1
- package/lib/ice/src/exceptions.d.ts +21 -5
- package/lib/ice/src/exceptions.js +58 -13
- package/lib/ice/src/exceptions.js.map +1 -1
- package/lib/ice/src/ice.d.ts +52 -8
- package/lib/ice/src/ice.js +288 -152
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/iceBase.d.ts +126 -11
- package/lib/ice/src/iceBase.js +165 -12
- package/lib/ice/src/iceBase.js.map +1 -1
- package/lib/ice/src/stun/transaction.d.ts +30 -1
- package/lib/ice/src/stun/transaction.js +86 -17
- package/lib/ice/src/stun/transaction.js.map +1 -1
- package/lib/ice/src/turn/credential.d.ts +49 -0
- package/lib/ice/src/turn/credential.js +78 -0
- package/lib/ice/src/turn/credential.js.map +1 -0
- package/lib/ice/src/turn/protocol.d.ts +29 -8
- package/lib/ice/src/turn/protocol.js +121 -48
- package/lib/ice/src/turn/protocol.js.map +1 -1
- package/lib/ice-server/src/stun/attributes.d.ts +2 -0
- package/lib/ice-server/src/stun/attributes.js +7 -1
- package/lib/ice-server/src/stun/attributes.js.map +1 -1
- package/lib/ice-server/src/stun/const.d.ts +24 -16
- package/lib/ice-server/src/stun/const.js +22 -18
- package/lib/ice-server/src/stun/const.js.map +1 -1
- package/lib/ice-server/src/stun/message.d.ts +1 -3
- package/lib/ice-server/src/stun/message.js +13 -9
- package/lib/ice-server/src/stun/message.js.map +1 -1
- package/lib/index.mjs +9770 -2648
- package/lib/nonstandard/index.mjs +2428 -1052
- package/lib/polyfill/dom.mjs +8738 -1815
- package/lib/polyfill/index.mjs +8738 -1815
- package/lib/rtp/src/codec/assertPayload.d.ts +4 -0
- package/lib/rtp/src/codec/assertPayload.js +12 -0
- package/lib/rtp/src/codec/assertPayload.js.map +1 -0
- package/lib/rtp/src/codec/av1.js +2 -0
- package/lib/rtp/src/codec/av1.js.map +1 -1
- package/lib/rtp/src/codec/h264.js +35 -43
- package/lib/rtp/src/codec/h264.js.map +1 -1
- package/lib/rtp/src/codec/vp8.js +11 -5
- package/lib/rtp/src/codec/vp8.js.map +1 -1
- package/lib/rtp/src/codec/vp9.js +12 -0
- package/lib/rtp/src/codec/vp9.js.map +1 -1
- package/lib/rtp/src/extra/container/mp4/container.js +2 -1
- package/lib/rtp/src/extra/container/mp4/container.js.map +1 -1
- package/lib/rtp/src/extra/container/mp4/exp-golomb.js +2 -1
- package/lib/rtp/src/extra/container/mp4/exp-golomb.js.map +1 -1
- package/lib/rtp/src/extra/container/mp4/h264.d.ts +21 -17
- package/lib/rtp/src/extra/container/mp4/h264.js +26 -24
- package/lib/rtp/src/extra/container/mp4/h264.js.map +1 -1
- package/lib/rtp/src/extra/container/ogg/index.d.ts +1 -0
- package/lib/rtp/src/extra/container/ogg/index.js +1 -0
- package/lib/rtp/src/extra/container/ogg/index.js.map +1 -1
- package/lib/rtp/src/extra/container/ogg/writer.d.ts +90 -0
- package/lib/rtp/src/extra/container/ogg/writer.js +300 -0
- package/lib/rtp/src/extra/container/ogg/writer.js.map +1 -0
- package/lib/rtp/src/extra/container/webm/ebml/ebml.js +6 -3
- package/lib/rtp/src/extra/container/webm/ebml/ebml.js.map +1 -1
- package/lib/rtp/src/extra/processor/depacketizer.d.ts +5 -0
- package/lib/rtp/src/extra/processor/depacketizer.js +28 -2
- package/lib/rtp/src/extra/processor/depacketizer.js.map +1 -1
- package/lib/rtp/src/extra/processor/dtx.js +4 -2
- package/lib/rtp/src/extra/processor/dtx.js.map +1 -1
- package/lib/rtp/src/extra/processor/index.d.ts +2 -0
- package/lib/rtp/src/extra/processor/index.js +2 -0
- package/lib/rtp/src/extra/processor/index.js.map +1 -1
- package/lib/rtp/src/extra/processor/jitterBuffer.d.ts +29 -6
- package/lib/rtp/src/extra/processor/jitterBuffer.js +101 -111
- package/lib/rtp/src/extra/processor/jitterBuffer.js.map +1 -1
- package/lib/rtp/src/extra/processor/jitterBufferTransformer.js +2 -1
- package/lib/rtp/src/extra/processor/jitterBufferTransformer.js.map +1 -1
- package/lib/rtp/src/extra/processor/lipsync.d.ts +63 -0
- package/lib/rtp/src/extra/processor/lipsync.js +202 -51
- package/lib/rtp/src/extra/processor/lipsync.js.map +1 -1
- package/lib/rtp/src/extra/processor/mp4.d.ts +0 -6
- package/lib/rtp/src/extra/processor/mp4.js +6 -3
- package/lib/rtp/src/extra/processor/mp4.js.map +1 -1
- package/lib/rtp/src/extra/processor/mute.js +4 -2
- package/lib/rtp/src/extra/processor/mute.js.map +1 -1
- package/lib/rtp/src/extra/processor/nack.js +4 -2
- package/lib/rtp/src/extra/processor/nack.js.map +1 -1
- package/lib/rtp/src/extra/processor/ntpTime.js +4 -6
- package/lib/rtp/src/extra/processor/ntpTime.js.map +1 -1
- package/lib/rtp/src/extra/processor/ogg.d.ts +72 -0
- package/lib/rtp/src/extra/processor/ogg.js +221 -0
- package/lib/rtp/src/extra/processor/ogg.js.map +1 -0
- package/lib/rtp/src/extra/processor/oggCallback.d.ts +21 -0
- package/lib/rtp/src/extra/processor/oggCallback.js +97 -0
- package/lib/rtp/src/extra/processor/oggCallback.js.map +1 -0
- package/lib/rtp/src/extra/processor/rtpCallback.js +2 -1
- package/lib/rtp/src/extra/processor/rtpCallback.js.map +1 -1
- package/lib/rtp/src/extra/processor/rtpStream.js +2 -1
- package/lib/rtp/src/extra/processor/rtpStream.js.map +1 -1
- package/lib/rtp/src/extra/processor/rtpTime.js +2 -1
- package/lib/rtp/src/extra/processor/rtpTime.js.map +1 -1
- package/lib/rtp/src/extra/processor/webm.js +14 -7
- package/lib/rtp/src/extra/processor/webm.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
- package/lib/rtp/src/index.d.ts +7 -0
- package/lib/rtp/src/index.js +7 -0
- package/lib/rtp/src/index.js.map +1 -1
- package/lib/rtp/src/rtcp/psfb/fullIntraRequest.d.ts +4 -0
- package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js +4 -0
- package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js.map +1 -1
- package/lib/rtp/src/rtcp/rtcp.js +8 -4
- package/lib/rtp/src/rtcp/rtcp.js.map +1 -1
- package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.d.ts +58 -0
- package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js +143 -0
- package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js.map +1 -0
- package/lib/rtp/src/rtcp/rtpfb/twcc.d.ts +35 -13
- package/lib/rtp/src/rtcp/rtpfb/twcc.js +132 -54
- package/lib/rtp/src/rtcp/rtpfb/twcc.js.map +1 -1
- package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.d.ts +13 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js +29 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js.map +1 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.d.ts +41 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js +89 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js.map +1 -0
- package/lib/rtp/src/rtcp/sr.js +1 -0
- package/lib/rtp/src/rtcp/sr.js.map +1 -1
- package/lib/rtp/src/rtp/continuity.d.ts +36 -0
- package/lib/rtp/src/rtp/continuity.js +100 -0
- package/lib/rtp/src/rtp/continuity.js.map +1 -0
- package/lib/rtp/src/rtp/headerExtension.js +41 -21
- package/lib/rtp/src/rtp/headerExtension.js.map +1 -1
- package/lib/rtp/src/rtp/padding.d.ts +17 -0
- package/lib/rtp/src/rtp/padding.js +37 -0
- package/lib/rtp/src/rtp/padding.js.map +1 -0
- package/lib/rtp/src/rtp/red/encoder.d.ts +10 -0
- package/lib/rtp/src/rtp/red/encoder.js +14 -1
- package/lib/rtp/src/rtp/red/encoder.js.map +1 -1
- package/lib/rtp/src/rtp/red/packet.js +24 -8
- package/lib/rtp/src/rtp/red/packet.js.map +1 -1
- package/lib/rtp/src/rtp/rtp.d.ts +24 -1
- package/lib/rtp/src/rtp/rtp.js +70 -29
- package/lib/rtp/src/rtp/rtp.js.map +1 -1
- package/lib/rtp/src/rtp/rtx.js +3 -0
- package/lib/rtp/src/rtp/rtx.js.map +1 -1
- package/lib/rtp/src/rtp/sendHeaderExtensions.d.ts +36 -0
- package/lib/rtp/src/rtp/sendHeaderExtensions.js +85 -0
- package/lib/rtp/src/rtp/sendHeaderExtensions.js.map +1 -0
- package/lib/rtp/src/srtp/cipher/ctr.js +4 -2
- package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
- package/lib/rtp/src/srtp/cipher/index.js +8 -4
- package/lib/rtp/src/srtp/cipher/index.js.map +1 -1
- package/lib/rtp/src/srtp/context/context.js +6 -3
- package/lib/rtp/src/srtp/context/context.js.map +1 -1
- package/lib/rtp/src/srtp/context/srtcp.d.ts +1 -1
- package/lib/rtp/src/srtp/context/srtcp.js +33 -0
- package/lib/rtp/src/srtp/context/srtcp.js.map +1 -1
- package/lib/rtp/src/srtp/context/srtp.d.ts +1 -1
- package/lib/rtp/src/srtp/context/srtp.js +34 -10
- package/lib/rtp/src/srtp/context/srtp.js.map +1 -1
- package/lib/rtp/src/srtp/error.d.ts +8 -0
- package/lib/rtp/src/srtp/error.js +13 -1
- package/lib/rtp/src/srtp/error.js.map +1 -1
- package/lib/rtp/src/srtp/packet.js +4 -1
- package/lib/rtp/src/srtp/packet.js.map +1 -1
- package/lib/rtp/src/srtp/replay.d.ts +24 -0
- package/lib/rtp/src/srtp/replay.js +75 -0
- package/lib/rtp/src/srtp/replay.js.map +1 -0
- package/lib/rtp/src/srtp/session.js +2 -1
- package/lib/rtp/src/srtp/session.js.map +1 -1
- package/lib/rtp/src/srtp/srtcp.js +2 -1
- package/lib/rtp/src/srtp/srtcp.js.map +1 -1
- package/lib/rtp/src/srtp/srtp.js +2 -1
- package/lib/rtp/src/srtp/srtp.js.map +1 -1
- package/lib/rtp/src/util.js +2 -1
- package/lib/rtp/src/util.js.map +1 -1
- package/lib/sctp/src/chunk.d.ts +5 -0
- package/lib/sctp/src/chunk.js +31 -8
- package/lib/sctp/src/chunk.js.map +1 -1
- package/lib/sctp/src/const.d.ts +25 -17
- package/lib/sctp/src/const.js +23 -19
- package/lib/sctp/src/const.js.map +1 -1
- package/lib/sctp/src/param.d.ts +6 -2
- package/lib/sctp/src/param.js +22 -8
- package/lib/sctp/src/param.js.map +1 -1
- package/lib/sctp/src/sctp.d.ts +80 -0
- package/lib/sctp/src/sctp.js +655 -108
- package/lib/sctp/src/sctp.js.map +1 -1
- package/lib/sctp/src/transport.js +4 -2
- package/lib/sctp/src/transport.js.map +1 -1
- package/lib/webrtc/src/api/peerConfig.d.ts +48 -5
- package/lib/webrtc/src/api/peerConfig.js +41 -0
- package/lib/webrtc/src/api/peerConfig.js.map +1 -1
- package/lib/webrtc/src/dataChannel.d.ts +10 -0
- package/lib/webrtc/src/dataChannel.js +24 -4
- package/lib/webrtc/src/dataChannel.js.map +1 -1
- package/lib/webrtc/src/media/index.d.ts +10 -0
- package/lib/webrtc/src/media/index.js +70 -0
- package/lib/webrtc/src/media/index.js.map +1 -1
- package/lib/webrtc/src/media/receiver/nack.js +2 -1
- package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
- package/lib/webrtc/src/media/receiver/receiverTwcc.d.ts +61 -1
- package/lib/webrtc/src/media/receiver/receiverTwcc.js +218 -63
- package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
- package/lib/webrtc/src/media/router.d.ts +14 -1
- package/lib/webrtc/src/media/router.js +46 -2
- package/lib/webrtc/src/media/router.js.map +1 -1
- package/lib/webrtc/src/media/rtpReceiver.d.ts +30 -2
- package/lib/webrtc/src/media/rtpReceiver.js +175 -26
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpSender.d.ts +184 -70
- package/lib/webrtc/src/media/rtpSender.js +626 -449
- package/lib/webrtc/src/media/rtpSender.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +1 -3
- package/lib/webrtc/src/media/rtpTransceiver.js +10 -7
- package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
- package/lib/webrtc/src/media/sender/bandwidthEstimator.d.ts +249 -0
- package/lib/webrtc/src/media/sender/bandwidthEstimator.js +144 -0
- package/lib/webrtc/src/media/sender/bandwidthEstimator.js.map +1 -0
- package/lib/webrtc/src/media/sender/createBandwidthEstimator.d.ts +20 -0
- package/lib/webrtc/src/media/sender/createBandwidthEstimator.js +26 -0
- package/lib/webrtc/src/media/sender/createBandwidthEstimator.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimatorBinding.d.ts +70 -0
- package/lib/webrtc/src/media/sender/estimatorBinding.js +175 -0
- package/lib/webrtc/src/media/sender/estimatorBinding.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/disabledBwe.d.ts +18 -0
- package/lib/webrtc/src/media/sender/estimators/disabledBwe.js +44 -0
- package/lib/webrtc/src/media/sender/estimators/disabledBwe.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.d.ts +79 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.js +289 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.d.ts +87 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.js +429 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.d.ts +21 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.js +84 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.d.ts +37 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.js +74 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/constants.d.ts +383 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/constants.js +408 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/constants.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.d.ts +406 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.js +1391 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/index.d.ts +19 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/index.js +75 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/index.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.d.ts +68 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.js +201 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.d.ts +26 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.js +72 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.d.ts +41 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.js +99 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.d.ts +247 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.js +1042 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.d.ts +26 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.js +132 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/probeController.d.ts +305 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/probeController.js +1073 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/probeController.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.d.ts +60 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.js +151 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.d.ts +44 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.js +246 -0
- package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/index.d.ts +7 -0
- package/lib/webrtc/src/media/sender/estimators/index.js +19 -0
- package/lib/webrtc/src/media/sender/estimators/index.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/lightweightBwe.d.ts +64 -0
- package/lib/webrtc/src/media/sender/estimators/lightweightBwe.js +216 -0
- package/lib/webrtc/src/media/sender/estimators/lightweightBwe.js.map +1 -0
- package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.d.ts +117 -0
- package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.js +250 -0
- package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.js.map +1 -0
- package/lib/webrtc/src/media/sender/outgoingQueue.d.ts +40 -0
- package/lib/webrtc/src/media/sender/outgoingQueue.js +153 -0
- package/lib/webrtc/src/media/sender/outgoingQueue.js.map +1 -0
- package/lib/webrtc/src/media/sender/padding.d.ts +45 -0
- package/lib/webrtc/src/media/sender/padding.js +134 -0
- package/lib/webrtc/src/media/sender/padding.js.map +1 -0
- package/lib/webrtc/src/media/sender/pendingRtp.d.ts +35 -0
- package/lib/webrtc/src/media/sender/pendingRtp.js +120 -0
- package/lib/webrtc/src/media/sender/pendingRtp.js.map +1 -0
- package/lib/webrtc/src/media/sender/rtpWire.d.ts +13 -0
- package/lib/webrtc/src/media/sender/rtpWire.js +38 -0
- package/lib/webrtc/src/media/sender/rtpWire.js.map +1 -0
- package/lib/webrtc/src/media/sender/sendPacer.d.ts +27 -0
- package/lib/webrtc/src/media/sender/sendPacer.js +110 -0
- package/lib/webrtc/src/media/sender/sendPacer.js.map +1 -0
- package/lib/webrtc/src/media/sender/senderBWE.d.ts +8 -33
- package/lib/webrtc/src/media/sender/senderBWE.js +5 -154
- package/lib/webrtc/src/media/sender/senderBWE.js.map +1 -1
- package/lib/webrtc/src/media/sender/senderStats.d.ts +100 -0
- package/lib/webrtc/src/media/sender/senderStats.js +322 -0
- package/lib/webrtc/src/media/sender/senderStats.js.map +1 -0
- package/lib/webrtc/src/media/track.d.ts +20 -2
- package/lib/webrtc/src/media/track.js +23 -5
- package/lib/webrtc/src/media/track.js.map +1 -1
- package/lib/webrtc/src/negotiation/bundleTopology.d.ts +1 -5
- package/lib/webrtc/src/negotiation/bundleTopology.js +15 -11
- package/lib/webrtc/src/negotiation/bundleTopology.js.map +1 -1
- package/lib/webrtc/src/negotiation/descriptionValidation.js +12 -6
- package/lib/webrtc/src/negotiation/descriptionValidation.js.map +1 -1
- package/lib/webrtc/src/negotiation/negotiationNeeded.js +2 -1
- package/lib/webrtc/src/negotiation/negotiationNeeded.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.js +10 -5
- package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +1 -1
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js +22 -6
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -1
- package/lib/webrtc/src/negotiation/transportActivation.js +19 -8
- package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -1
- package/lib/webrtc/src/negotiationTransaction.d.ts +8 -1
- package/lib/webrtc/src/negotiationTransaction.js +18 -5
- package/lib/webrtc/src/negotiationTransaction.js.map +1 -1
- package/lib/webrtc/src/nonstandard/dummyMedia.js +2 -1
- package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
- package/lib/webrtc/src/nonstandard/navigator.js +4 -3
- package/lib/webrtc/src/nonstandard/navigator.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/index.d.ts +32 -8
- package/lib/webrtc/src/nonstandard/recorder/index.js +81 -20
- package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/index.d.ts +9 -7
- package/lib/webrtc/src/nonstandard/recorder/writer/index.js +2 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/ogg.d.ts +32 -0
- package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js +185 -0
- package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js.map +1 -0
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +8 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia.js +2 -1
- package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +44 -1
- package/lib/webrtc/src/peerConnection.js +74 -8
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/polyfill/mediaDevices.js +2 -1
- package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
- package/lib/webrtc/src/sctpManager.d.ts +46 -14
- package/lib/webrtc/src/sctpManager.js +88 -25
- package/lib/webrtc/src/sctpManager.js.map +1 -1
- package/lib/webrtc/src/sdp.js +12 -6
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/secureTransportManager.d.ts +52 -4
- package/lib/webrtc/src/secureTransportManager.js +106 -23
- package/lib/webrtc/src/secureTransportManager.js.map +1 -1
- package/lib/webrtc/src/transceiverManager.js +8 -3
- package/lib/webrtc/src/transceiverManager.js.map +1 -1
- package/lib/webrtc/src/transport/dtls.d.ts +53 -1
- package/lib/webrtc/src/transport/dtls.js +131 -31
- package/lib/webrtc/src/transport/dtls.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +10 -86
- package/lib/webrtc/src/transport/ice.js +70 -31
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/lib/webrtc/src/transport/sctp.d.ts +2 -0
- package/lib/webrtc/src/transport/sctp.js +66 -20
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/lib/webrtc/src/utils.d.ts +36 -3
- package/lib/webrtc/src/utils.js +56 -16
- package/lib/webrtc/src/utils.js.map +1 -1
- package/package.json +8 -6
package/lib/ice/src/iceBase.d.ts
CHANGED
|
@@ -16,7 +16,17 @@ export interface IceConnection {
|
|
|
16
16
|
localCandidates: Candidate[];
|
|
17
17
|
remoteCandidates: Candidate[];
|
|
18
18
|
candidatePairs: CandidatePair[];
|
|
19
|
+
/**
|
|
20
|
+
* STUN servers gathering queries, normalized from the options (see
|
|
21
|
+
* {@link normalizeIceServerOptions}). Optional so that other
|
|
22
|
+
* implementations of this interface keep compiling.
|
|
23
|
+
*/
|
|
24
|
+
stunServers?: Address[];
|
|
25
|
+
/** TURN servers gathering allocates on, each with its own credential. */
|
|
26
|
+
turnServers?: TurnServerOptions[];
|
|
27
|
+
/** @deprecated The first of {@link IceConnection.stunServers}. */
|
|
19
28
|
stunServer?: Address;
|
|
29
|
+
/** @deprecated The address of the first of {@link IceConnection.turnServers}. */
|
|
20
30
|
turnServer?: Address;
|
|
21
31
|
generation: number;
|
|
22
32
|
options: IceOptions;
|
|
@@ -34,7 +44,12 @@ export interface IceConnection {
|
|
|
34
44
|
* implementation without them still restarts ICE at the final answer, but
|
|
35
45
|
* cannot answer or run checks for the new generation during pranswer.
|
|
36
46
|
*/
|
|
37
|
-
|
|
47
|
+
/**
|
|
48
|
+
* `gatherOptions`: the options the staged generation gathers with (an ICE
|
|
49
|
+
* server update applied at the commit); its provisional checks use only
|
|
50
|
+
* the sockets those options allow. Defaults to the current options.
|
|
51
|
+
*/
|
|
52
|
+
stageLocalCredentials?(usernameFragment: string, password: string, gatherOptions?: Partial<IceOptions>): void;
|
|
38
53
|
discardStagedLocalCredentials?(usernameFragment: string): void;
|
|
39
54
|
commitLocalCredentials?(usernameFragment: string, password: string): void;
|
|
40
55
|
/**
|
|
@@ -158,14 +173,26 @@ export declare const CONSENT_RESPONSE_TIMEOUT_MIN = 500;
|
|
|
158
173
|
* Falls back to {@link CONSENT_RESPONSE_TIMEOUT} when RTT is unavailable.
|
|
159
174
|
*/
|
|
160
175
|
export declare function consentResponseTimeoutMs(rttSeconds?: number): number;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
176
|
+
/**
|
|
177
|
+
* @enum
|
|
178
|
+
*/
|
|
179
|
+
export declare const CandidatePairState: {
|
|
180
|
+
readonly FROZEN: 0;
|
|
181
|
+
readonly WAITING: 1;
|
|
182
|
+
readonly IN_PROGRESS: 2;
|
|
183
|
+
readonly SUCCEEDED: 3;
|
|
184
|
+
readonly FAILED: 4;
|
|
185
|
+
};
|
|
186
|
+
export type CandidatePairState = (typeof CandidatePairState)[keyof typeof CandidatePairState];
|
|
168
187
|
export type IceState = "disconnected" | "closed" | "completed" | "new" | "connected" | "failed";
|
|
188
|
+
/** A TURN server and the credential and transport used for it. */
|
|
189
|
+
export type TurnServerOptions = {
|
|
190
|
+
address: Address;
|
|
191
|
+
username: string;
|
|
192
|
+
password: string;
|
|
193
|
+
/** Defaults to "udp" (with a TCP fallback when the UDP allocation fails). */
|
|
194
|
+
transport?: "udp" | "tcp" | "tls";
|
|
195
|
+
};
|
|
169
196
|
export interface IceOptions {
|
|
170
197
|
/** Advertise and operate as an ICE lite agent. */
|
|
171
198
|
iceLite: boolean;
|
|
@@ -189,16 +216,54 @@ export interface IceOptions {
|
|
|
189
216
|
* Defaults to 8.
|
|
190
217
|
*/
|
|
191
218
|
turnConnectTimeout?: number;
|
|
219
|
+
/**
|
|
220
|
+
* STUN servers queried while gathering, in priority order. Every IPv4 UDP
|
|
221
|
+
* host socket queries each of them in parallel; equal mappings are
|
|
222
|
+
* advertised once, different ones (a NAT that maps per destination) each.
|
|
223
|
+
* Gathering ends when the slowest server answers or `stunGatherTimeout`
|
|
224
|
+
* runs out.
|
|
225
|
+
*
|
|
226
|
+
* Merged with the deprecated `stunServer`: the singular one comes first,
|
|
227
|
+
* duplicates are dropped (see {@link normalizeIceServerOptions}).
|
|
228
|
+
*/
|
|
229
|
+
stunServers?: Address[];
|
|
230
|
+
/**
|
|
231
|
+
* TURN servers allocated on while gathering, in priority order. Each one
|
|
232
|
+
* gets its own allocation with its own credential and transport; one that
|
|
233
|
+
* fails or times out does not stop the others. Gathering ends when the
|
|
234
|
+
* slowest allocation completes or fails (`turnConnectTimeout` bounds a
|
|
235
|
+
* TCP/TLS connection, the STUN transaction timeout an unanswered request).
|
|
236
|
+
* `turnTlsOptions`, `turnUdpFamily`, `turnConnectTimeout`, `portRange` and
|
|
237
|
+
* `interfaceAddresses` apply to every TURN server.
|
|
238
|
+
*
|
|
239
|
+
* Merged with the deprecated `turnServer` / `turnUsername` /
|
|
240
|
+
* `turnPassword` / `turnTransport`: the singular one comes first,
|
|
241
|
+
* duplicates are dropped and an entry without username / password is
|
|
242
|
+
* ignored (see {@link normalizeIceServerOptions}).
|
|
243
|
+
*/
|
|
244
|
+
turnServers?: TurnServerOptions[];
|
|
245
|
+
/** @deprecated Use {@link IceOptions.stunServers}. Kept as their first entry. */
|
|
192
246
|
stunServer?: Address;
|
|
247
|
+
/**
|
|
248
|
+
* Whether the built-in public STUN server (stun.l.google.com:19302) is used
|
|
249
|
+
* when no STUN server is given. Defaults to true; false gathers no
|
|
250
|
+
* server-reflexive candidate unless a STUN server is set.
|
|
251
|
+
*/
|
|
252
|
+
useDefaultStunServer?: boolean;
|
|
253
|
+
/** @deprecated Use {@link IceOptions.turnServers}. Kept as their first entry. */
|
|
193
254
|
turnServer?: Address;
|
|
255
|
+
/** @deprecated Use {@link TurnServerOptions.username} of {@link IceOptions.turnServers}. */
|
|
194
256
|
turnUsername?: string;
|
|
257
|
+
/** @deprecated Use {@link TurnServerOptions.password} of {@link IceOptions.turnServers}. */
|
|
195
258
|
turnPassword?: string;
|
|
259
|
+
/** @deprecated Use {@link TurnServerOptions.transport} of {@link IceOptions.turnServers}. */
|
|
196
260
|
turnTransport?: "udp" | "tcp" | "tls";
|
|
261
|
+
/** Applied to every TLS TURN server. */
|
|
197
262
|
turnTlsOptions?: TlsConnectionOptions;
|
|
198
263
|
/**
|
|
199
|
-
* Preferred IP family of
|
|
200
|
-
* is a hostname. Ignored for an IP literal
|
|
201
|
-
* always selects the socket. Defaults to 4.
|
|
264
|
+
* Preferred IP family of a TURN/UDP socket, applied (to every TURN server)
|
|
265
|
+
* only when the server is a hostname. Ignored for an IP literal server,
|
|
266
|
+
* whose own family always selects the socket. Defaults to 4.
|
|
202
267
|
*/
|
|
203
268
|
turnUdpFamily?: 4 | 6;
|
|
204
269
|
forceTurn?: boolean;
|
|
@@ -243,3 +308,53 @@ export declare function sortCandidatePairs(pairs: {
|
|
|
243
308
|
export declare function candidatePairPriority(local: Pick<Candidate, "priority">, remote: Pick<Candidate, "priority">, iceControlling: boolean): number;
|
|
244
309
|
export declare function serverReflexiveCandidate(protocol: Protocol, stunServer: Address): Promise<Candidate | undefined>;
|
|
245
310
|
export declare function validateAddress(addr?: Address): Address | undefined;
|
|
311
|
+
/** The STUN/TURN server fields of {@link IceOptions}, singular and plural. */
|
|
312
|
+
export type IceServerFields = Partial<Pick<IceOptions, "stunServer" | "stunServers" | "turnServer" | "turnServers" | "turnUsername" | "turnPassword" | "turnTransport">>;
|
|
313
|
+
/**
|
|
314
|
+
* The STUN and TURN servers `options` configure, the one place the singular
|
|
315
|
+
* (deprecated) and plural fields are merged:
|
|
316
|
+
*
|
|
317
|
+
* - order: the singular server first, then the plural list in its order;
|
|
318
|
+
* - duplicates (the same STUN address; the same TURN address, transport and
|
|
319
|
+
* credential) are kept once, at their first position;
|
|
320
|
+
* - an invalid address (see {@link validateAddress}) is dropped, and so is a
|
|
321
|
+
* TURN server without username or password (it cannot allocate);
|
|
322
|
+
* - a TURN transport left unset is "udp".
|
|
323
|
+
*
|
|
324
|
+
* The built-in default STUN server is not added here; Connection falls back
|
|
325
|
+
* to it when the result has no STUN server.
|
|
326
|
+
*/
|
|
327
|
+
export declare function normalizeIceServerOptions(options: IceServerFields): {
|
|
328
|
+
stunServers: Address[];
|
|
329
|
+
turnServers: Required<TurnServerOptions>[];
|
|
330
|
+
};
|
|
331
|
+
/**
|
|
332
|
+
* `current` with an ICE server update applied (Connection.setIceServers): the
|
|
333
|
+
* STUN/TURN fields, singular and plural, are replaced, an undefined one
|
|
334
|
+
* included, so a STUN-only update cannot leave a previous TURN
|
|
335
|
+
* host/credential behind; forceTurn and useTcp change only when given.
|
|
336
|
+
*/
|
|
337
|
+
export declare function mergeIceServerOptions<T extends Partial<IceOptions>>(current: T, update: Partial<IceOptions>): T;
|
|
338
|
+
/**
|
|
339
|
+
* Whether a generation gathered with `options` is relay-only: forceTurn (the
|
|
340
|
+
* "relay" ICE transport policy). The policy holds whatever the TURN settings
|
|
341
|
+
* are: without a usable TURN server / credential (or for an ICE-lite agent,
|
|
342
|
+
* which gathers no relay candidate) the generation has no candidate at all
|
|
343
|
+
* rather than falling back to host / server-reflexive ones, so the local and
|
|
344
|
+
* public addresses are neither advertised nor used for checks.
|
|
345
|
+
*/
|
|
346
|
+
export declare function isRelayOnlyGathering(options: Pick<IceOptions, "forceTurn">): boolean;
|
|
347
|
+
/**
|
|
348
|
+
* Whether `options` carry at least one usable TURN server with its
|
|
349
|
+
* credential, the ones a gathering with them allocates relay candidates from.
|
|
350
|
+
*/
|
|
351
|
+
export declare function hasTurnServer(options: IceServerFields): boolean;
|
|
352
|
+
/**
|
|
353
|
+
* Whether `candidate`, kept from an earlier generation (an ICE restart keeps
|
|
354
|
+
* the sockets), may be advertised and paired in a generation gathered with
|
|
355
|
+
* `options`. A fresh gathering with the same options would not have produced
|
|
356
|
+
* a host / server-reflexive candidate for a relay-only policy, a TCP host
|
|
357
|
+
* candidate without useTcp, nor a relay candidate without a TURN server;
|
|
358
|
+
* the kept ones are held back the same way.
|
|
359
|
+
*/
|
|
360
|
+
export declare function isCandidateAllowedByGatherOptions(candidate: Pick<Candidate, "type" | "transport">, options: Pick<IceOptions, "forceTurn"> & Partial<Pick<IceOptions, "useTcp">> & IceServerFields): boolean;
|
package/lib/ice/src/iceBase.js
CHANGED
|
@@ -7,6 +7,11 @@ exports.sortCandidatePairs = sortCandidatePairs;
|
|
|
7
7
|
exports.candidatePairPriority = candidatePairPriority;
|
|
8
8
|
exports.serverReflexiveCandidate = serverReflexiveCandidate;
|
|
9
9
|
exports.validateAddress = validateAddress;
|
|
10
|
+
exports.normalizeIceServerOptions = normalizeIceServerOptions;
|
|
11
|
+
exports.mergeIceServerOptions = mergeIceServerOptions;
|
|
12
|
+
exports.isRelayOnlyGathering = isRelayOnlyGathering;
|
|
13
|
+
exports.hasTurnServer = hasTurnServer;
|
|
14
|
+
exports.isCandidateAllowedByGatherOptions = isCandidateAllowedByGatherOptions;
|
|
10
15
|
const crypto_1 = require("crypto");
|
|
11
16
|
const candidate_1 = require("./candidate");
|
|
12
17
|
const common_1 = require("./imports/common");
|
|
@@ -32,19 +37,19 @@ class CandidatePair {
|
|
|
32
37
|
enumerable: true,
|
|
33
38
|
configurable: true,
|
|
34
39
|
writable: true,
|
|
35
|
-
value:
|
|
40
|
+
value: void 0
|
|
36
41
|
});
|
|
37
42
|
Object.defineProperty(this, "remoteCandidate", {
|
|
38
43
|
enumerable: true,
|
|
39
44
|
configurable: true,
|
|
40
45
|
writable: true,
|
|
41
|
-
value:
|
|
46
|
+
value: void 0
|
|
42
47
|
});
|
|
43
48
|
Object.defineProperty(this, "iceControlling", {
|
|
44
49
|
enumerable: true,
|
|
45
50
|
configurable: true,
|
|
46
51
|
writable: true,
|
|
47
|
-
value:
|
|
52
|
+
value: void 0
|
|
48
53
|
});
|
|
49
54
|
Object.defineProperty(this, "id", {
|
|
50
55
|
enumerable: true,
|
|
@@ -75,7 +80,7 @@ class CandidatePair {
|
|
|
75
80
|
enumerable: true,
|
|
76
81
|
configurable: true,
|
|
77
82
|
writable: true,
|
|
78
|
-
value: CandidatePairState.FROZEN
|
|
83
|
+
value: exports.CandidatePairState.FROZEN
|
|
79
84
|
});
|
|
80
85
|
// Statistics tracking
|
|
81
86
|
Object.defineProperty(this, "packetsSent", {
|
|
@@ -168,6 +173,9 @@ class CandidatePair {
|
|
|
168
173
|
writable: true,
|
|
169
174
|
value: new Set()
|
|
170
175
|
});
|
|
176
|
+
this.protocol = protocol;
|
|
177
|
+
this.remoteCandidate = remoteCandidate;
|
|
178
|
+
this.iceControlling = iceControlling;
|
|
171
179
|
}
|
|
172
180
|
updateState(state) {
|
|
173
181
|
this._state = state;
|
|
@@ -233,14 +241,16 @@ function consentResponseTimeoutMs(rttSeconds) {
|
|
|
233
241
|
}
|
|
234
242
|
return Math.max(exports.CONSENT_RESPONSE_TIMEOUT_MIN, Math.round(rttSeconds * 1000 * 2 + 200));
|
|
235
243
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
+
/**
|
|
245
|
+
* @enum
|
|
246
|
+
*/
|
|
247
|
+
exports.CandidatePairState = {
|
|
248
|
+
FROZEN: 0,
|
|
249
|
+
WAITING: 1,
|
|
250
|
+
IN_PROGRESS: 2,
|
|
251
|
+
SUCCEEDED: 3,
|
|
252
|
+
FAILED: 4,
|
|
253
|
+
};
|
|
244
254
|
exports.defaultOptions = {
|
|
245
255
|
iceLite: false,
|
|
246
256
|
useTcp: false,
|
|
@@ -297,4 +307,147 @@ function validateAddress(addr) {
|
|
|
297
307
|
}
|
|
298
308
|
return addr;
|
|
299
309
|
}
|
|
310
|
+
/** A STUN/TURN server address: validated (see {@link validateAddress}) or undefined. */
|
|
311
|
+
function validServerAddress(addr) {
|
|
312
|
+
if (!Array.isArray(addr))
|
|
313
|
+
return undefined;
|
|
314
|
+
const validated = validateAddress(addr);
|
|
315
|
+
if (!validated)
|
|
316
|
+
return undefined;
|
|
317
|
+
const [host, port] = validated;
|
|
318
|
+
if (typeof host !== "string" || host === "")
|
|
319
|
+
return undefined;
|
|
320
|
+
if (typeof port !== "number" || !Number.isFinite(port))
|
|
321
|
+
return undefined;
|
|
322
|
+
return validated;
|
|
323
|
+
}
|
|
324
|
+
const sameAddress = (a, b) => a[0] === b[0] && a[1] === b[1];
|
|
325
|
+
/**
|
|
326
|
+
* The STUN and TURN servers `options` configure, the one place the singular
|
|
327
|
+
* (deprecated) and plural fields are merged:
|
|
328
|
+
*
|
|
329
|
+
* - order: the singular server first, then the plural list in its order;
|
|
330
|
+
* - duplicates (the same STUN address; the same TURN address, transport and
|
|
331
|
+
* credential) are kept once, at their first position;
|
|
332
|
+
* - an invalid address (see {@link validateAddress}) is dropped, and so is a
|
|
333
|
+
* TURN server without username or password (it cannot allocate);
|
|
334
|
+
* - a TURN transport left unset is "udp".
|
|
335
|
+
*
|
|
336
|
+
* The built-in default STUN server is not added here; Connection falls back
|
|
337
|
+
* to it when the result has no STUN server.
|
|
338
|
+
*/
|
|
339
|
+
function normalizeIceServerOptions(options) {
|
|
340
|
+
const stunServers = [];
|
|
341
|
+
for (const server of [options.stunServer, ...(options.stunServers ?? [])]) {
|
|
342
|
+
if (server === undefined)
|
|
343
|
+
continue;
|
|
344
|
+
const address = validServerAddress(server);
|
|
345
|
+
if (!address) {
|
|
346
|
+
log("invalid STUN server ignored", server);
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
if (stunServers.some((existing) => sameAddress(existing, address))) {
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
stunServers.push(address);
|
|
353
|
+
}
|
|
354
|
+
const turnServers = [];
|
|
355
|
+
const configured = [
|
|
356
|
+
...(options.turnServer !== undefined
|
|
357
|
+
? [
|
|
358
|
+
{
|
|
359
|
+
address: options.turnServer,
|
|
360
|
+
username: options.turnUsername,
|
|
361
|
+
password: options.turnPassword,
|
|
362
|
+
transport: options.turnTransport,
|
|
363
|
+
},
|
|
364
|
+
]
|
|
365
|
+
: []),
|
|
366
|
+
...(options.turnServers ?? []),
|
|
367
|
+
];
|
|
368
|
+
for (const server of configured) {
|
|
369
|
+
const address = validServerAddress(server?.address);
|
|
370
|
+
if (!address) {
|
|
371
|
+
log("invalid TURN server ignored", server?.address);
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
const { username, password } = server;
|
|
375
|
+
if (!username || !password) {
|
|
376
|
+
log("TURN server without username / credential ignored", address);
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
const entry = {
|
|
380
|
+
address,
|
|
381
|
+
username,
|
|
382
|
+
password,
|
|
383
|
+
transport: server.transport ?? "udp",
|
|
384
|
+
};
|
|
385
|
+
if (turnServers.some((existing) => sameAddress(existing.address, entry.address) &&
|
|
386
|
+
existing.transport === entry.transport &&
|
|
387
|
+
existing.username === entry.username &&
|
|
388
|
+
existing.password === entry.password)) {
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
turnServers.push(entry);
|
|
392
|
+
}
|
|
393
|
+
return { stunServers, turnServers };
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* `current` with an ICE server update applied (Connection.setIceServers): the
|
|
397
|
+
* STUN/TURN fields, singular and plural, are replaced, an undefined one
|
|
398
|
+
* included, so a STUN-only update cannot leave a previous TURN
|
|
399
|
+
* host/credential behind; forceTurn and useTcp change only when given.
|
|
400
|
+
*/
|
|
401
|
+
function mergeIceServerOptions(current, update) {
|
|
402
|
+
return {
|
|
403
|
+
...current,
|
|
404
|
+
stunServer: update.stunServer,
|
|
405
|
+
stunServers: update.stunServers,
|
|
406
|
+
turnServer: update.turnServer,
|
|
407
|
+
turnServers: update.turnServers,
|
|
408
|
+
turnUsername: update.turnUsername,
|
|
409
|
+
turnPassword: update.turnPassword,
|
|
410
|
+
turnTransport: update.turnTransport,
|
|
411
|
+
turnTlsOptions: update.turnTlsOptions,
|
|
412
|
+
turnUdpFamily: update.turnUdpFamily,
|
|
413
|
+
forceTurn: update.forceTurn ?? current.forceTurn,
|
|
414
|
+
useTcp: update.useTcp ?? current.useTcp,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Whether a generation gathered with `options` is relay-only: forceTurn (the
|
|
419
|
+
* "relay" ICE transport policy). The policy holds whatever the TURN settings
|
|
420
|
+
* are: without a usable TURN server / credential (or for an ICE-lite agent,
|
|
421
|
+
* which gathers no relay candidate) the generation has no candidate at all
|
|
422
|
+
* rather than falling back to host / server-reflexive ones, so the local and
|
|
423
|
+
* public addresses are neither advertised nor used for checks.
|
|
424
|
+
*/
|
|
425
|
+
function isRelayOnlyGathering(options) {
|
|
426
|
+
return !!options.forceTurn;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Whether `options` carry at least one usable TURN server with its
|
|
430
|
+
* credential, the ones a gathering with them allocates relay candidates from.
|
|
431
|
+
*/
|
|
432
|
+
function hasTurnServer(options) {
|
|
433
|
+
return normalizeIceServerOptions(options).turnServers.length > 0;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Whether `candidate`, kept from an earlier generation (an ICE restart keeps
|
|
437
|
+
* the sockets), may be advertised and paired in a generation gathered with
|
|
438
|
+
* `options`. A fresh gathering with the same options would not have produced
|
|
439
|
+
* a host / server-reflexive candidate for a relay-only policy, a TCP host
|
|
440
|
+
* candidate without useTcp, nor a relay candidate without a TURN server;
|
|
441
|
+
* the kept ones are held back the same way.
|
|
442
|
+
*/
|
|
443
|
+
function isCandidateAllowedByGatherOptions(candidate, options) {
|
|
444
|
+
if (candidate.type === "relay")
|
|
445
|
+
return hasTurnServer(options);
|
|
446
|
+
if (isRelayOnlyGathering(options))
|
|
447
|
+
return false;
|
|
448
|
+
if (candidate.transport.toLowerCase() === "tcp" && !options.useTcp) {
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
300
453
|
//# sourceMappingURL=iceBase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iceBase.js","sourceRoot":"","sources":["../../../../ice/src/iceBase.ts"],"names":[],"mappings":";;;AA2OA,4DAYC;AA+FD,0DASC;AAED,gDAsBC;AAGD,sDAQC;AAED,4DA0CC;AAED,0CAKC;AArbD,mCAAoC;AACpC,2CAAgF;AAGhF,6CAM0B;AAC1B,wCAAgD;AAChD,4CAAyC;AAGzC,MAAM,GAAG,GAAG,IAAA,cAAK,EAAC,4CAA4C,CAAC,CAAC;AAsGhE,MAAa,aAAa;IAOxB,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAmBD,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,IAAI;QACN,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;YAC5B,cAAc,EAAE,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE;YAC3C,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE;SAC9C,CAAC;IACJ,CAAC;IAED,YACS,QAAkB,EAClB,eAA0B,EAC1B,cAAuB;QAF9B;;;;mBAAO,QAAQ;WAAU;QACzB;;;;mBAAO,eAAe;WAAW;QACjC;;;;mBAAO,cAAc;WAAS;QA1CvB;;;;mBAAK,IAAA,mBAAU,GAAE,CAAC,QAAQ,EAAE;WAAC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H,CAAC;AAED,SAAgB,eAAe,CAAC,IAAc;IAC5C,IAAI,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAClC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACxB,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 stunServer?: Address;\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 stageLocalCredentials?(usernameFragment: string, password: string): 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 readonly id = randomUUID().toString();\n handle?: Cancelable<void>;\n nominated = false;\n remoteNominated = false;\n // 5.7.4. Computing States\n private _state = 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 public protocol: Protocol,\n public remoteCandidate: Candidate,\n public iceControlling: boolean,\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\nexport enum CandidatePairState {\n FROZEN = 0,\n WAITING = 1,\n IN_PROGRESS = 2,\n SUCCEEDED = 3,\n FAILED = 4,\n}\n\nexport type IceState =\n | \"disconnected\"\n | \"closed\"\n | \"completed\"\n | \"new\"\n | \"connected\"\n | \"failed\";\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 stunServer?: Address;\n turnServer?: Address;\n turnUsername?: string;\n turnPassword?: string;\n turnTransport?: \"udp\" | \"tcp\" | \"tls\";\n turnTlsOptions?: TlsConnectionOptions;\n /**\n * Preferred IP family of the TURN/UDP socket, applied only when turnServer\n * is a hostname. Ignored for an IP literal turnServer, whose own family\n * 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"]}
|
|
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,EAAC,4CAA4C,CAAC,CAAC;AAyHhE,MAAa,aAAa;IAWxB,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,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M,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"]}
|
|
@@ -22,6 +22,13 @@ export declare function normalizeTransactionOptions(retransmissionsOrOptions?: n
|
|
|
22
22
|
* `::1` even when the peer was configured as `0:0:0:0:0:0:0:1`.
|
|
23
23
|
*/
|
|
24
24
|
export declare function addressEquals(a: Address, b: Address): boolean;
|
|
25
|
+
/** Whether `message` carries MESSAGE-INTEGRITY or MESSAGE-INTEGRITY-SHA256. */
|
|
26
|
+
export declare function hasMessageIntegrity(message: Message): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* A long-term credential challenge (RFC 8489 §9.2.4): a 401 (Unauthenticated)
|
|
29
|
+
* or 438 (Stale Nonce) error response without MESSAGE-INTEGRITY.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isUnauthenticatedChallenge(message: Message): boolean;
|
|
25
32
|
export declare class Transaction {
|
|
26
33
|
private request;
|
|
27
34
|
private addr;
|
|
@@ -38,7 +45,9 @@ export declare class Transaction {
|
|
|
38
45
|
readonly expectedAddr: Address;
|
|
39
46
|
/**
|
|
40
47
|
* When set, protocol layers re-parse the wire response with this key so
|
|
41
|
-
* MESSAGE-INTEGRITY failures are rejected before responseReceived.
|
|
48
|
+
* MESSAGE-INTEGRITY failures are rejected before responseReceived. The one
|
|
49
|
+
* exception is a TURN long-term credential challenge (unsigned 401/438),
|
|
50
|
+
* which TurnProtocol passes to challengeReceived instead.
|
|
42
51
|
*/
|
|
43
52
|
readonly integrityKey?: Buffer;
|
|
44
53
|
private waitTimer?;
|
|
@@ -50,8 +59,28 @@ export declare class Transaction {
|
|
|
50
59
|
* remote address. Wrong address, missing MESSAGE-INTEGRITY (when required),
|
|
51
60
|
* or non-success class is rejected without completing the transaction
|
|
52
61
|
* (wrong address / unauthenticated responses are ignored so we keep waiting).
|
|
62
|
+
* An unsigned 401/438 challenge is not accepted here even for long-term
|
|
63
|
+
* credentials; only challengeReceived takes it.
|
|
53
64
|
*/
|
|
54
65
|
responseReceived: (message: Message, addr: Address) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Fail the transaction with TransactionChallenge on a long-term credential
|
|
68
|
+
* challenge: an unsigned 401/438 error response (RFC 8489 §9.2.4) to this
|
|
69
|
+
* request's method, from the expected remote address. Any other message is
|
|
70
|
+
* ignored. Only TurnProtocol calls this: short-term credential checks (ICE
|
|
71
|
+
* connectivity checks, consent) have no challenge and keep requiring
|
|
72
|
+
* MESSAGE-INTEGRITY through responseReceived.
|
|
73
|
+
*/
|
|
74
|
+
challengeReceived: (message: Message, addr: Address) => void;
|
|
75
|
+
/**
|
|
76
|
+
* Fail the transaction with TransactionIntegrityViolation: a response from
|
|
77
|
+
* the expected remote address failed MESSAGE-INTEGRITY validation on a
|
|
78
|
+
* reliable transport, where it cannot be a retransmission race
|
|
79
|
+
* (RFC 8489 §9.2.5).
|
|
80
|
+
*/
|
|
81
|
+
integrityViolated: (addr: Address) => void;
|
|
82
|
+
/** Whether a response from `addr` may settle this transaction. */
|
|
83
|
+
private accepts;
|
|
55
84
|
run: () => Promise<[Message, readonly [string, number]]>;
|
|
56
85
|
private attachAbortListener;
|
|
57
86
|
private failWithTimeout;
|