werift 0.25.2 → 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/asn1.d.ts +42 -0
- package/lib/common/src/asn1.js +163 -0
- package/lib/common/src/asn1.js.map +1 -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/index.d.ts +6 -5
- package/lib/common/src/index.js +6 -5
- package/lib/common/src/index.js.map +1 -1
- package/lib/common/src/log.d.ts +12 -1
- package/lib/common/src/log.js +142 -12
- package/lib/common/src/log.js.map +1 -1
- package/lib/common/src/network.js.map +1 -1
- package/lib/common/src/queue.d.ts +41 -0
- package/lib/common/src/queue.js +146 -0
- package/lib/common/src/queue.js.map +1 -0
- package/lib/common/src/transport.d.ts +15 -2
- package/lib/common/src/transport.js +108 -19
- package/lib/common/src/transport.js.map +1 -1
- package/lib/dtls/src/cipher/create.js.map +1 -1
- package/lib/dtls/src/cipher/ec.js +8 -8
- package/lib/dtls/src/cipher/ec.js.map +1 -1
- package/lib/dtls/src/cipher/namedCurve.js +6 -7
- package/lib/dtls/src/cipher/namedCurve.js.map +1 -1
- package/lib/dtls/src/cipher/prf.d.ts +2 -2
- package/lib/dtls/src/cipher/prf.js +29 -8
- package/lib/dtls/src/cipher/prf.js.map +1 -1
- package/lib/dtls/src/cipher/suites/aead.d.ts +1 -1
- package/lib/dtls/src/context/certificate.d.ts +32 -0
- package/lib/dtls/src/context/certificate.js +54 -0
- package/lib/dtls/src/context/certificate.js.map +1 -0
- package/lib/dtls/src/context/cipher.d.ts +13 -7
- package/lib/dtls/src/context/cipher.js +58 -106
- 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.d.ts +4 -0
- package/lib/dtls/src/context/transport.js +16 -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 +16 -5
- package/lib/dtls/src/flight/flight.js.map +1 -1
- package/lib/dtls/src/flight/server/flight2.js.map +1 -1
- package/lib/dtls/src/flight/server/flight4.d.ts +2 -1
- package/lib/dtls/src/flight/server/flight4.js +12 -4
- 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/extensions/signature.d.ts +1 -1
- package/lib/dtls/src/handshake/extensions/signature.js.map +1 -1
- package/lib/dtls/src/handshake/message/alert.js +5 -3
- package/lib/dtls/src/handshake/message/alert.js.map +1 -1
- package/lib/dtls/src/handshake/message/certificate.js +3 -2
- package/lib/dtls/src/handshake/message/certificate.js.map +1 -1
- package/lib/dtls/src/handshake/message/changeCipherSpec.js +4 -4
- package/lib/dtls/src/handshake/message/changeCipherSpec.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/certificateVerify.d.ts +1 -1
- package/lib/dtls/src/handshake/message/client/certificateVerify.js +5 -3
- package/lib/dtls/src/handshake/message/client/certificateVerify.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/hello.js +15 -8
- package/lib/dtls/src/handshake/message/client/hello.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/keyExchange.js +3 -2
- 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.d.ts +1 -1
- package/lib/dtls/src/handshake/message/server/certificateRequest.js +7 -4
- package/lib/dtls/src/handshake/message/server/certificateRequest.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/hello.d.ts +1 -1
- package/lib/dtls/src/handshake/message/server/hello.js +14 -8
- package/lib/dtls/src/handshake/message/server/hello.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/helloDone.js +1 -1
- package/lib/dtls/src/handshake/message/server/helloDone.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js +5 -3
- package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/keyExchange.d.ts +1 -1
- package/lib/dtls/src/handshake/message/server/keyExchange.js +17 -9
- package/lib/dtls/src/handshake/message/server/keyExchange.js.map +1 -1
- package/lib/dtls/src/handshake/random.d.ts +1 -1
- package/lib/dtls/src/handshake/random.js +7 -4
- package/lib/dtls/src/handshake/random.js.map +1 -1
- package/lib/dtls/src/imports/common.d.ts +1 -0
- package/lib/dtls/src/imports/common.js +1 -0
- package/lib/dtls/src/imports/common.js.map +1 -1
- package/lib/dtls/src/index.d.ts +2 -2
- package/lib/dtls/src/index.js +2 -2
- package/lib/dtls/src/index.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.d.ts +1 -1
- package/lib/dtls/src/record/message/fragment.js +15 -9
- package/lib/dtls/src/record/message/fragment.js.map +1 -1
- package/lib/dtls/src/record/message/header.js +12 -7
- 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/server.js +1 -1
- package/lib/dtls/src/server.js.map +1 -1
- package/lib/dtls/src/socket.d.ts +2 -2
- package/lib/dtls/src/socket.js +6 -4
- 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 +46 -0
- package/lib/ice/src/exceptions.js +92 -5
- package/lib/ice/src/exceptions.js.map +1 -1
- package/lib/ice/src/helper.d.ts +1 -1
- package/lib/ice/src/ice.d.ts +191 -5
- package/lib/ice/src/ice.js +1048 -156
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/iceBase.d.ts +174 -10
- package/lib/ice/src/iceBase.js +165 -12
- package/lib/ice/src/iceBase.js.map +1 -1
- package/lib/ice/src/index.d.ts +5 -5
- package/lib/ice/src/index.js +5 -5
- package/lib/ice/src/index.js.map +1 -1
- package/lib/ice/src/internal/resolveHostAddresses.d.ts +26 -0
- package/lib/ice/src/internal/resolveHostAddresses.js +45 -0
- package/lib/ice/src/internal/resolveHostAddresses.js.map +1 -0
- package/lib/ice/src/stun/protocol.d.ts +3 -1
- package/lib/ice/src/stun/protocol.js +16 -0
- package/lib/ice/src/stun/protocol.js.map +1 -1
- package/lib/ice/src/stun/tcpProtocol.d.ts +2 -0
- package/lib/ice/src/stun/tcpProtocol.js +16 -1
- package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
- package/lib/ice/src/stun/transaction.d.ts +35 -1
- package/lib/ice/src/stun/transaction.js +93 -18
- 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 +97 -7
- package/lib/ice/src/turn/protocol.js +357 -55
- package/lib/ice/src/turn/protocol.js.map +1 -1
- package/lib/ice/src/utils.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 +3 -1
- package/lib/ice-server/src/stun/message.js +41 -6
- package/lib/ice-server/src/stun/message.js.map +1 -1
- package/lib/ice-server/src/turn/auth.d.ts +1 -1
- package/lib/index.mjs +25252 -12664
- package/lib/nonstandard/index.mjs +11015 -8906
- package/lib/polyfill/dom.mjs +30779 -18386
- package/lib/polyfill/index.mjs +30779 -18386
- 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.d.ts +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/container.d.ts +1 -1
- package/lib/rtp/src/extra/container/webm/ebml/ebml.d.ts +6 -0
- package/lib/rtp/src/extra/container/webm/ebml/ebml.js +26 -4
- package/lib/rtp/src/extra/container/webm/ebml/ebml.js.map +1 -1
- package/lib/rtp/src/extra/processor/depacketizer.d.ts +6 -1
- package/lib/rtp/src/extra/processor/depacketizer.js +29 -3
- package/lib/rtp/src/extra/processor/depacketizer.js.map +1 -1
- package/lib/rtp/src/extra/processor/depacketizerCallback.d.ts +1 -11
- package/lib/rtp/src/extra/processor/depacketizerTransformer.d.ts +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/dtxCallback.d.ts +1 -11
- 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/interface.d.ts +16 -11
- package/lib/rtp/src/extra/processor/interface.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/jitterBufferCallback.d.ts +1 -11
- package/lib/rtp/src/extra/processor/jitterBufferTransformer.d.ts +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 +7 -4
- 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.d.ts +1 -1
- package/lib/rtp/src/extra/processor/nack.js +5 -3
- package/lib/rtp/src/extra/processor/nack.js.map +1 -1
- package/lib/rtp/src/extra/processor/nackHandlerCallback.d.ts +1 -11
- 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/ntpTimeCallback.d.ts +1 -11
- 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/rtcpCallback.d.ts +1 -1
- package/lib/rtp/src/extra/processor/rtcpCallback.js.map +1 -1
- package/lib/rtp/src/extra/processor/rtpCallback.d.ts +1 -1
- package/lib/rtp/src/extra/processor/rtpCallback.js +3 -2
- package/lib/rtp/src/extra/processor/rtpCallback.js.map +1 -1
- package/lib/rtp/src/extra/processor/rtpStream.d.ts +2 -2
- 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/rtpTimeCallback.d.ts +1 -11
- package/lib/rtp/src/extra/processor/webm.d.ts +27 -0
- package/lib/rtp/src/extra/processor/webm.js +57 -23
- package/lib/rtp/src/extra/processor/webm.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmCallback.js +6 -1
- package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmStream.js.map +1 -1
- package/lib/rtp/src/helper.d.ts +2 -2
- package/lib/rtp/src/helper.js +2 -6
- package/lib/rtp/src/helper.js.map +1 -1
- package/lib/rtp/src/index.d.ts +10 -2
- package/lib/rtp/src/index.js +10 -2
- 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 +6 -1
- package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js.map +1 -1
- package/lib/rtp/src/rtcp/rtcp.js +9 -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.d.ts +4 -3
- package/lib/rtp/src/rtcp/sr.js +4 -2
- 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.d.ts +2 -2
- package/lib/rtp/src/srtp/cipher/ctr.js +5 -3
- package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
- package/lib/rtp/src/srtp/cipher/gcm.d.ts +1 -1
- package/lib/rtp/src/srtp/cipher/gcm.js +1 -1
- package/lib/rtp/src/srtp/cipher/gcm.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.d.ts +29 -1
- package/lib/rtp/src/srtp/context/context.js +84 -27
- 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 +36 -4
- 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/index.d.ts +4 -3
- package/lib/sctp/src/index.js +10 -8
- package/lib/sctp/src/index.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 +91 -2
- package/lib/sctp/src/sctp.js +700 -134
- 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 +307 -0
- package/lib/webrtc/src/api/peerConfig.js +291 -0
- package/lib/webrtc/src/api/peerConfig.js.map +1 -0
- package/lib/webrtc/src/api/peerConnectionEvents.d.ts +36 -0
- package/lib/webrtc/src/api/peerConnectionEvents.js +44 -0
- package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -0
- package/lib/webrtc/src/dataChannel.d.ts +11 -1
- package/lib/webrtc/src/dataChannel.js +25 -5
- package/lib/webrtc/src/dataChannel.js.map +1 -1
- package/lib/webrtc/src/index.d.ts +2 -2
- package/lib/webrtc/src/index.js +2 -2
- package/lib/webrtc/src/index.js.map +1 -1
- package/lib/webrtc/src/media/index.d.ts +11 -1
- package/lib/webrtc/src/media/index.js +71 -1
- package/lib/webrtc/src/media/index.js.map +1 -1
- package/lib/webrtc/src/media/receiver/nack.js +5 -5
- 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 +130 -6
- package/lib/webrtc/src/media/router.js +325 -29
- package/lib/webrtc/src/media/router.js.map +1 -1
- package/lib/webrtc/src/media/rtpReceiver.d.ts +137 -14
- package/lib/webrtc/src/media/rtpReceiver.js +420 -44
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpSender.d.ts +232 -65
- package/lib/webrtc/src/media/rtpSender.js +784 -448
- package/lib/webrtc/src/media/rtpSender.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +95 -4
- package/lib/webrtc/src/media/rtpTransceiver.js +121 -9
- 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 -32
- package/lib/webrtc/src/media/sender/senderBWE.js +5 -142
- 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 +21 -3
- package/lib/webrtc/src/media/track.js +24 -6
- package/lib/webrtc/src/media/track.js.map +1 -1
- package/lib/webrtc/src/negotiation/bundleTopology.d.ts +103 -0
- package/lib/webrtc/src/negotiation/bundleTopology.js +384 -0
- package/lib/webrtc/src/negotiation/bundleTopology.js.map +1 -0
- package/lib/webrtc/src/negotiation/descriptionValidation.d.ts +51 -0
- package/lib/webrtc/src/negotiation/descriptionValidation.js +267 -0
- package/lib/webrtc/src/negotiation/descriptionValidation.js.map +1 -0
- package/lib/webrtc/src/negotiation/iceRestartRequest.d.ts +21 -0
- package/lib/webrtc/src/negotiation/iceRestartRequest.js +61 -0
- package/lib/webrtc/src/negotiation/iceRestartRequest.js.map +1 -0
- package/lib/webrtc/src/negotiation/internalState.d.ts +34 -0
- package/lib/webrtc/src/negotiation/internalState.js +21 -0
- package/lib/webrtc/src/negotiation/internalState.js.map +1 -0
- package/lib/webrtc/src/negotiation/negotiationNeeded.d.ts +44 -0
- package/lib/webrtc/src/negotiation/negotiationNeeded.js +119 -0
- package/lib/webrtc/src/negotiation/negotiationNeeded.js.map +1 -0
- package/lib/webrtc/src/negotiation/remoteCandidates.d.ts +86 -0
- package/lib/webrtc/src/negotiation/remoteCandidates.js +349 -0
- package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -0
- package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +71 -0
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js +414 -0
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -0
- package/lib/webrtc/src/negotiation/transportActivation.d.ts +59 -0
- package/lib/webrtc/src/negotiation/transportActivation.js +356 -0
- package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -0
- package/lib/webrtc/src/negotiationTransaction.d.ts +240 -0
- package/lib/webrtc/src/negotiationTransaction.js +604 -0
- package/lib/webrtc/src/negotiationTransaction.js.map +1 -0
- package/lib/webrtc/src/nonstandard/dummyMedia.js +2 -1
- package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
- package/lib/webrtc/src/nonstandard/index.d.ts +1 -1
- package/lib/webrtc/src/nonstandard/index.js +1 -1
- package/lib/webrtc/src/nonstandard/index.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 +10 -8
- 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.d.ts +2 -2
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +10 -3
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.d.ts +2 -2
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia.d.ts +2 -2
- package/lib/webrtc/src/nonstandard/userMedia.js +4 -3
- package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +176 -238
- package/lib/webrtc/src/peerConnection.js +1042 -913
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/polyfill/api.d.ts +5 -5
- package/lib/webrtc/src/polyfill/api.js.map +1 -1
- package/lib/webrtc/src/polyfill/index.js.map +1 -1
- package/lib/webrtc/src/polyfill/install.js +1 -1
- package/lib/webrtc/src/polyfill/install.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/polyfill/registers/mp4Webm.js.map +1 -1
- package/lib/webrtc/src/polyfill/registers/rtpRtcp.js.map +1 -1
- package/lib/webrtc/src/polyfill/selectSettings.js.map +1 -1
- package/lib/webrtc/src/polyfill/sourceIo.js.map +1 -1
- package/lib/webrtc/src/sctpManager.d.ts +97 -1
- package/lib/webrtc/src/sctpManager.js +189 -9
- 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/sdpManager.d.ts +55 -11
- package/lib/webrtc/src/sdpManager.js +364 -87
- package/lib/webrtc/src/sdpManager.js.map +1 -1
- package/lib/webrtc/src/secureTransportManager.d.ts +89 -28
- package/lib/webrtc/src/secureTransportManager.js +232 -53
- package/lib/webrtc/src/secureTransportManager.js.map +1 -1
- package/lib/webrtc/src/transceiverManager.d.ts +62 -18
- package/lib/webrtc/src/transceiverManager.js +272 -107
- package/lib/webrtc/src/transceiverManager.js.map +1 -1
- package/lib/webrtc/src/transport/dtls.d.ts +64 -3
- package/lib/webrtc/src/transport/dtls.js +166 -42
- package/lib/webrtc/src/transport/dtls.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +199 -28
- package/lib/webrtc/src/transport/ice.js +666 -71
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/lib/webrtc/src/transport/iceCandidateAttribute.d.ts +98 -0
- package/lib/webrtc/src/transport/iceCandidateAttribute.js +129 -0
- package/lib/webrtc/src/transport/iceCandidateAttribute.js.map +1 -0
- package/lib/webrtc/src/transport/sctp.d.ts +6 -1
- package/lib/webrtc/src/transport/sctp.js +149 -37
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/lib/webrtc/src/utils.d.ts +39 -6
- package/lib/webrtc/src/utils.js +57 -17
- package/lib/webrtc/src/utils.js.map +1 -1
- package/package.json +16 -15
package/lib/ice/src/ice.js
CHANGED
|
@@ -34,14 +34,16 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.Connection = void 0;
|
|
37
|
+
const timers = __importStar(require("node:timers/promises"));
|
|
37
38
|
const crypto_1 = require("crypto");
|
|
38
39
|
const net_1 = require("net");
|
|
39
|
-
const timers = __importStar(require("node:timers/promises"));
|
|
40
|
-
const common_1 = require("./imports/common");
|
|
41
40
|
const candidate_1 = require("./candidate");
|
|
42
41
|
const lookup_1 = require("./dns/lookup");
|
|
42
|
+
const exceptions_1 = require("./exceptions");
|
|
43
43
|
const helper_1 = require("./helper");
|
|
44
44
|
const iceBase_1 = require("./iceBase");
|
|
45
|
+
const common_1 = require("./imports/common");
|
|
46
|
+
const resolveHostAddresses_1 = require("./internal/resolveHostAddresses");
|
|
45
47
|
const const_1 = require("./stun/const");
|
|
46
48
|
const message_1 = require("./stun/message");
|
|
47
49
|
const protocol_1 = require("./stun/protocol");
|
|
@@ -57,7 +59,7 @@ class Connection {
|
|
|
57
59
|
enumerable: true,
|
|
58
60
|
configurable: true,
|
|
59
61
|
writable: true,
|
|
60
|
-
value:
|
|
62
|
+
value: void 0
|
|
61
63
|
});
|
|
62
64
|
Object.defineProperty(this, "localUsername", {
|
|
63
65
|
enumerable: true,
|
|
@@ -101,17 +103,23 @@ class Connection {
|
|
|
101
103
|
writable: true,
|
|
102
104
|
value: []
|
|
103
105
|
});
|
|
104
|
-
|
|
106
|
+
/**
|
|
107
|
+
* STUN servers gathering queries: the configured ones (see
|
|
108
|
+
* normalizeIceServerOptions), or the built-in default when none is
|
|
109
|
+
* configured and useDefaultStunServer is not false.
|
|
110
|
+
*/
|
|
111
|
+
Object.defineProperty(this, "stunServers", {
|
|
105
112
|
enumerable: true,
|
|
106
113
|
configurable: true,
|
|
107
114
|
writable: true,
|
|
108
|
-
value:
|
|
115
|
+
value: []
|
|
109
116
|
});
|
|
110
|
-
|
|
117
|
+
/** TURN servers gathering allocates on, one allocation each. */
|
|
118
|
+
Object.defineProperty(this, "turnServers", {
|
|
111
119
|
enumerable: true,
|
|
112
120
|
configurable: true,
|
|
113
121
|
writable: true,
|
|
114
|
-
value:
|
|
122
|
+
value: []
|
|
115
123
|
});
|
|
116
124
|
Object.defineProperty(this, "options", {
|
|
117
125
|
enumerable: true,
|
|
@@ -125,24 +133,77 @@ class Connection {
|
|
|
125
133
|
writable: true,
|
|
126
134
|
value: false
|
|
127
135
|
});
|
|
136
|
+
/**
|
|
137
|
+
* End-of-candidates arrived while earlier candidates were still resolving
|
|
138
|
+
* (mDNS). No candidate is accepted any more; `remoteCandidatesEnd` follows
|
|
139
|
+
* once those resolutions settle.
|
|
140
|
+
*/
|
|
141
|
+
Object.defineProperty(this, "remoteCandidatesEndRequested", {
|
|
142
|
+
enumerable: true,
|
|
143
|
+
configurable: true,
|
|
144
|
+
writable: true,
|
|
145
|
+
value: false
|
|
146
|
+
});
|
|
147
|
+
/**
|
|
148
|
+
* mDNS resolutions of remote candidates that arrived before
|
|
149
|
+
* end-of-candidates. close() (and restart()) closes `lookup`, which rejects
|
|
150
|
+
* them at once.
|
|
151
|
+
*/
|
|
152
|
+
Object.defineProperty(this, "remoteResolutions", {
|
|
153
|
+
enumerable: true,
|
|
154
|
+
configurable: true,
|
|
155
|
+
writable: true,
|
|
156
|
+
value: new Set()
|
|
157
|
+
});
|
|
128
158
|
Object.defineProperty(this, "localCandidatesEnd", {
|
|
129
159
|
enumerable: true,
|
|
130
160
|
configurable: true,
|
|
131
161
|
writable: true,
|
|
132
162
|
value: false
|
|
133
163
|
});
|
|
164
|
+
/** connect() began this generation's checks (their outcome sets the state). */
|
|
165
|
+
Object.defineProperty(this, "checksBegun", {
|
|
166
|
+
enumerable: true,
|
|
167
|
+
configurable: true,
|
|
168
|
+
writable: true,
|
|
169
|
+
value: false
|
|
170
|
+
});
|
|
134
171
|
Object.defineProperty(this, "generation", {
|
|
135
172
|
enumerable: true,
|
|
136
173
|
configurable: true,
|
|
137
174
|
writable: true,
|
|
138
175
|
value: -1
|
|
139
176
|
});
|
|
177
|
+
/**
|
|
178
|
+
* Counts every reset of the remote generation: a local ICE restart and a
|
|
179
|
+
* remote-only one. Remote-side work (a candidate's mDNS lookup, the wait
|
|
180
|
+
* for end-of-candidates, consent, a nomination in flight) belongs to the
|
|
181
|
+
* value it started with. A remote-only restart leaves `generation` (the
|
|
182
|
+
* local gathering's) alone.
|
|
183
|
+
*/
|
|
184
|
+
Object.defineProperty(this, "remoteGeneration", {
|
|
185
|
+
enumerable: true,
|
|
186
|
+
configurable: true,
|
|
187
|
+
writable: true,
|
|
188
|
+
value: 0
|
|
189
|
+
});
|
|
190
|
+
/**
|
|
191
|
+
* Local credentials STUN requests may use, by ufrag: the current ones, the
|
|
192
|
+
* generation the last restart replaced and a staged (provisional) one.
|
|
193
|
+
*/
|
|
140
194
|
Object.defineProperty(this, "userHistory", {
|
|
141
195
|
enumerable: true,
|
|
142
196
|
configurable: true,
|
|
143
197
|
writable: true,
|
|
144
198
|
value: {}
|
|
145
199
|
});
|
|
200
|
+
/** restart() ran once (the constructor's first generation exists). */
|
|
201
|
+
Object.defineProperty(this, "restarted", {
|
|
202
|
+
enumerable: true,
|
|
203
|
+
configurable: true,
|
|
204
|
+
writable: true,
|
|
205
|
+
value: false
|
|
206
|
+
});
|
|
146
207
|
Object.defineProperty(this, "tieBreaker", {
|
|
147
208
|
enumerable: true,
|
|
148
209
|
configurable: true,
|
|
@@ -155,6 +216,14 @@ class Connection {
|
|
|
155
216
|
writable: true,
|
|
156
217
|
value: "new"
|
|
157
218
|
});
|
|
219
|
+
/** close() ran; unlike `state`, a restart does not reset it. */
|
|
220
|
+
Object.defineProperty(this, "closed", {
|
|
221
|
+
enumerable: true,
|
|
222
|
+
configurable: true,
|
|
223
|
+
writable: true,
|
|
224
|
+
value: false
|
|
225
|
+
});
|
|
226
|
+
/** Resolves remote mDNS candidates; closed (pending lookups cancelled) by restart() and close(). */
|
|
158
227
|
Object.defineProperty(this, "lookup", {
|
|
159
228
|
enumerable: true,
|
|
160
229
|
configurable: true,
|
|
@@ -180,12 +249,70 @@ class Connection {
|
|
|
180
249
|
writable: true,
|
|
181
250
|
value: false
|
|
182
251
|
});
|
|
252
|
+
/**
|
|
253
|
+
* Aborted when the remote generation ends (restart, restartRemote, close):
|
|
254
|
+
* every check and nomination transaction of that generation stops with it.
|
|
255
|
+
*
|
|
256
|
+
* Every STUN request of the agent and what cancels it (a late result of an
|
|
257
|
+
* ended generation changes no state of the generation that replaced it):
|
|
258
|
+
* - `checkStart` (live check): its handle (`pair.handle`: checklist
|
|
259
|
+
* completed, replaced, other remote ufrag dropped) and this signal; an
|
|
260
|
+
* aborted check changes nothing.
|
|
261
|
+
* - `retryCheck` (487 role conflict / 401 retry): the handle of the check
|
|
262
|
+
* it replaces and this signal (the retry is a `checkStart`).
|
|
263
|
+
* - regular nomination in `checkStart` (toward an ICE-lite peer): the
|
|
264
|
+
* check's signal; `isStaleNomination` guards `nominating`, the pair state
|
|
265
|
+
* and `checkComplete`.
|
|
266
|
+
* - `nominateTcpPair`: this signal; `isStaleNomination`.
|
|
267
|
+
* - `checkProvisional` / `nominateProvisional`: `generation.checks`
|
|
268
|
+
* (`endProvisional()`, a replacement pranswer, close); `belongs()`.
|
|
269
|
+
* - `queryConsent`: a per-request `AbortController` and
|
|
270
|
+
* `stopConsentLifecycle()`; `consentSessionId`.
|
|
271
|
+
* - `serverReflexiveCandidate` (gathering): `protocol.close()`; otherwise
|
|
272
|
+
* it ends by its retransmission timeout, and `stale()` drops the
|
|
273
|
+
* candidate of an ended gather.
|
|
274
|
+
* - TURN client requests: the `closing` signal and `TurnProtocol.close()`.
|
|
275
|
+
* Regression tests: `tests/ice/check-cancel.test.ts`.
|
|
276
|
+
*/
|
|
277
|
+
Object.defineProperty(this, "remoteChecks", {
|
|
278
|
+
enumerable: true,
|
|
279
|
+
configurable: true,
|
|
280
|
+
writable: true,
|
|
281
|
+
value: new AbortController()
|
|
282
|
+
});
|
|
183
283
|
Object.defineProperty(this, "checkListDone", {
|
|
184
284
|
enumerable: true,
|
|
185
285
|
configurable: true,
|
|
186
286
|
writable: true,
|
|
187
287
|
value: false
|
|
188
288
|
});
|
|
289
|
+
/** Resolves when the agent closes: work that awaits the network stops waiting. */
|
|
290
|
+
Object.defineProperty(this, "closedSignal", {
|
|
291
|
+
enumerable: true,
|
|
292
|
+
configurable: true,
|
|
293
|
+
writable: true,
|
|
294
|
+
value: void 0
|
|
295
|
+
});
|
|
296
|
+
Object.defineProperty(this, "signalClosed", {
|
|
297
|
+
enumerable: true,
|
|
298
|
+
configurable: true,
|
|
299
|
+
writable: true,
|
|
300
|
+
value: void 0
|
|
301
|
+
});
|
|
302
|
+
/** Aborted by close(): a TURN allocation still running is released. */
|
|
303
|
+
Object.defineProperty(this, "closing", {
|
|
304
|
+
enumerable: true,
|
|
305
|
+
configurable: true,
|
|
306
|
+
writable: true,
|
|
307
|
+
value: new AbortController()
|
|
308
|
+
});
|
|
309
|
+
/**
|
|
310
|
+
* Results for connect(). Known constraint (as in develop): a restart
|
|
311
|
+
* replaces the queue, so a connect() still waiting on the old one never
|
|
312
|
+
* settles (the agent is still collected). It cannot simply return, since
|
|
313
|
+
* the caller (webrtc's `TransactionActivation`) treats a returned start as
|
|
314
|
+
* a connected ICE transport.
|
|
315
|
+
*/
|
|
189
316
|
Object.defineProperty(this, "checkListState", {
|
|
190
317
|
enumerable: true,
|
|
191
318
|
configurable: true,
|
|
@@ -248,6 +375,23 @@ class Connection {
|
|
|
248
375
|
writable: true,
|
|
249
376
|
value: void 0
|
|
250
377
|
});
|
|
378
|
+
/** ICE restart generation checked beside the selected current pair. */
|
|
379
|
+
Object.defineProperty(this, "provisional", {
|
|
380
|
+
enumerable: true,
|
|
381
|
+
configurable: true,
|
|
382
|
+
writable: true,
|
|
383
|
+
value: void 0
|
|
384
|
+
});
|
|
385
|
+
/**
|
|
386
|
+
* Server-reflexive candidates each UDP socket advertised in its last
|
|
387
|
+
* gathering (one per distinct mapping its STUN servers returned).
|
|
388
|
+
*/
|
|
389
|
+
Object.defineProperty(this, "reflexiveBySocket", {
|
|
390
|
+
enumerable: true,
|
|
391
|
+
configurable: true,
|
|
392
|
+
writable: true,
|
|
393
|
+
value: new WeakMap()
|
|
394
|
+
});
|
|
251
395
|
Object.defineProperty(this, "onData", {
|
|
252
396
|
enumerable: true,
|
|
253
397
|
configurable: true,
|
|
@@ -354,7 +498,7 @@ class Connection {
|
|
|
354
498
|
break;
|
|
355
499
|
}
|
|
356
500
|
const pairId = nominated.id;
|
|
357
|
-
const generation = this.
|
|
501
|
+
const generation = this.remoteGeneration;
|
|
358
502
|
const remotePassword = this.remotePassword;
|
|
359
503
|
const { localUsername, remoteUsername, iceControlling } = this;
|
|
360
504
|
const request = this.buildRequest({
|
|
@@ -397,7 +541,7 @@ class Connection {
|
|
|
397
541
|
if (this.nominated?.id !== pairId) {
|
|
398
542
|
return;
|
|
399
543
|
}
|
|
400
|
-
if (this.
|
|
544
|
+
if (this.remoteGeneration !== generation) {
|
|
401
545
|
return;
|
|
402
546
|
}
|
|
403
547
|
if (this.remotePassword !== remotePassword) {
|
|
@@ -456,11 +600,18 @@ class Connection {
|
|
|
456
600
|
enumerable: true,
|
|
457
601
|
configurable: true,
|
|
458
602
|
writable: true,
|
|
459
|
-
value: (pair) => (0, helper_1.cancelable)(async (r) => {
|
|
603
|
+
value: (pair) => (0, helper_1.cancelable)(async (r, _f, onCancel) => {
|
|
460
604
|
// """
|
|
461
605
|
// Starts a check.
|
|
462
606
|
// """
|
|
463
607
|
log("check start", pair.toJSON());
|
|
608
|
+
// Resolving the handle (the checklist completed or was replaced) stops
|
|
609
|
+
// the request's retransmissions too.
|
|
610
|
+
const checks = new AbortController();
|
|
611
|
+
onCancel.once(() => checks.abort());
|
|
612
|
+
// The remote generation ending (restart / close) stops it as well.
|
|
613
|
+
const signal = AbortSignal.any([checks.signal, this.remoteChecks.signal]);
|
|
614
|
+
const remoteGeneration = this.remoteGeneration;
|
|
464
615
|
pair.updateState(iceBase_1.CandidatePairState.IN_PROGRESS);
|
|
465
616
|
const result = {};
|
|
466
617
|
const { remotePassword, remoteUsername, generation } = this;
|
|
@@ -478,7 +629,7 @@ class Connection {
|
|
|
478
629
|
const startTime = performance.now();
|
|
479
630
|
try {
|
|
480
631
|
pair.requestsSent++;
|
|
481
|
-
const [response, addr] = await pair.protocol.request(request, pair.remoteAddr, Buffer.from(remotePassword, "utf8"), this.checkRequestOptions(pair));
|
|
632
|
+
const [response, addr] = await pair.protocol.request(request, pair.remoteAddr, Buffer.from(remotePassword, "utf8"), { ...this.checkRequestOptions(pair), signal });
|
|
482
633
|
pair.responsesReceived++;
|
|
483
634
|
// Calculate RTT
|
|
484
635
|
const endTime = performance.now();
|
|
@@ -498,6 +649,12 @@ class Connection {
|
|
|
498
649
|
result.addr = addr;
|
|
499
650
|
}
|
|
500
651
|
catch (error) {
|
|
652
|
+
// A cancelled check (its handle resolved, or the agent closed and
|
|
653
|
+
// cancelled its transactions) changes nothing.
|
|
654
|
+
if (signal.aborted || error instanceof exceptions_1.TransactionCancelled) {
|
|
655
|
+
r();
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
501
658
|
const exc = error;
|
|
502
659
|
// 7.1.3.1. Failure Cases
|
|
503
660
|
log("failure case", request.toJSON(), exc.response ? JSON.stringify(exc.response.toJSON(), null, 2) : error, {
|
|
@@ -513,13 +670,13 @@ class Connection {
|
|
|
513
670
|
else if (request.attributesKeys.includes("ICE-CONTROLLING")) {
|
|
514
671
|
this.switchRole(false);
|
|
515
672
|
}
|
|
516
|
-
await this.
|
|
673
|
+
await this.retryCheck(pair, onCancel);
|
|
517
674
|
r();
|
|
518
675
|
return;
|
|
519
676
|
}
|
|
520
677
|
if (exc.response?.getAttributeValue("ERROR-CODE")[0] === 401) {
|
|
521
678
|
log("retry 401", pair.toJSON());
|
|
522
|
-
await this.
|
|
679
|
+
await this.retryCheck(pair, onCancel);
|
|
523
680
|
r();
|
|
524
681
|
return;
|
|
525
682
|
}
|
|
@@ -560,13 +717,26 @@ class Connection {
|
|
|
560
717
|
});
|
|
561
718
|
try {
|
|
562
719
|
pair.requestsSent++;
|
|
563
|
-
await pair.protocol.request(request, pair.remoteAddr, Buffer.from(this.remotePassword, "utf8"), this.checkRequestOptions(pair));
|
|
720
|
+
await pair.protocol.request(request, pair.remoteAddr, Buffer.from(this.remotePassword, "utf8"), { ...this.checkRequestOptions(pair), signal });
|
|
564
721
|
pair.responsesReceived++;
|
|
565
722
|
}
|
|
566
723
|
catch (error) {
|
|
724
|
+
// A nomination of a generation that ended (or a cancelled check)
|
|
725
|
+
// must not touch the state of the generation that replaced it.
|
|
726
|
+
if (signal.aborted ||
|
|
727
|
+
error instanceof exceptions_1.TransactionCancelled ||
|
|
728
|
+
this.isStaleNomination(pair, remoteGeneration)) {
|
|
729
|
+
r();
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
567
732
|
this.nominating = false;
|
|
568
733
|
pair.updateState(iceBase_1.CandidatePairState.FAILED);
|
|
569
734
|
this.checkComplete(pair);
|
|
735
|
+
r();
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
if (this.isStaleNomination(pair, remoteGeneration)) {
|
|
739
|
+
r();
|
|
570
740
|
return;
|
|
571
741
|
}
|
|
572
742
|
pair.nominated = true;
|
|
@@ -586,6 +756,10 @@ class Connection {
|
|
|
586
756
|
}
|
|
587
757
|
}
|
|
588
758
|
});
|
|
759
|
+
this._iceControlling = _iceControlling;
|
|
760
|
+
this.closedSignal = new Promise((resolve) => {
|
|
761
|
+
this.signalClosed = resolve;
|
|
762
|
+
});
|
|
589
763
|
this.options = {
|
|
590
764
|
...iceBase_1.defaultOptions,
|
|
591
765
|
...options,
|
|
@@ -607,40 +781,51 @@ class Connection {
|
|
|
607
781
|
* Link headers) and must take effect before the next gather pass.
|
|
608
782
|
*/
|
|
609
783
|
setIceServers(options) {
|
|
610
|
-
//
|
|
611
|
-
//
|
|
612
|
-
this.options =
|
|
613
|
-
...this.options,
|
|
614
|
-
stunServer: options.stunServer,
|
|
615
|
-
turnServer: options.turnServer,
|
|
616
|
-
turnUsername: options.turnUsername,
|
|
617
|
-
turnPassword: options.turnPassword,
|
|
618
|
-
turnTransport: options.turnTransport,
|
|
619
|
-
};
|
|
620
|
-
if (options.forceTurn !== undefined) {
|
|
621
|
-
this.options.forceTurn = options.forceTurn;
|
|
622
|
-
}
|
|
623
|
-
if (options.useTcp !== undefined) {
|
|
624
|
-
this.options.useTcp = options.useTcp;
|
|
625
|
-
}
|
|
626
|
-
if (options.turnTlsOptions !== undefined) {
|
|
627
|
-
this.options.turnTlsOptions = options.turnTlsOptions;
|
|
628
|
-
}
|
|
629
|
-
if (options.turnUdpFamily !== undefined) {
|
|
630
|
-
this.options.turnUdpFamily = options.turnUdpFamily;
|
|
631
|
-
}
|
|
784
|
+
// Server fields are assigned even when undefined, so a STUN-only update
|
|
785
|
+
// or an unset TLS / address-family option leaves nothing behind.
|
|
786
|
+
this.options = (0, iceBase_1.mergeIceServerOptions)(this.options, options);
|
|
632
787
|
this.applyStunTurnServersFromOptions();
|
|
633
788
|
log("Connection ice servers updated", this.options);
|
|
634
789
|
}
|
|
635
790
|
/**
|
|
636
|
-
* Derive Connection.
|
|
791
|
+
* Derive Connection.stunServers / turnServers from this.options.
|
|
637
792
|
* Shared by the constructor and setIceServers so both paths validate and
|
|
638
793
|
* default identically.
|
|
639
794
|
*/
|
|
640
795
|
applyStunTurnServersFromOptions() {
|
|
641
|
-
this.
|
|
642
|
-
|
|
643
|
-
|
|
796
|
+
const { stunServers, turnServers } = (0, iceBase_1.normalizeIceServerOptions)(this.options);
|
|
797
|
+
this.stunServers =
|
|
798
|
+
stunServers.length > 0 || this.options.useDefaultStunServer === false
|
|
799
|
+
? stunServers
|
|
800
|
+
: [DEFAULT_STUN_SERVER];
|
|
801
|
+
this.turnServers = turnServers;
|
|
802
|
+
}
|
|
803
|
+
/** @deprecated The first of {@link Connection.stunServers}. */
|
|
804
|
+
get stunServer() {
|
|
805
|
+
return this.stunServers[0];
|
|
806
|
+
}
|
|
807
|
+
/** @deprecated Replaces {@link Connection.stunServers} with this one server (none for undefined). */
|
|
808
|
+
set stunServer(server) {
|
|
809
|
+
this.stunServers = server ? [server] : [];
|
|
810
|
+
}
|
|
811
|
+
/** @deprecated The address of the first of {@link Connection.turnServers}. */
|
|
812
|
+
get turnServer() {
|
|
813
|
+
return this.turnServers[0]?.address;
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* @deprecated Replaces {@link Connection.turnServers} with this one server
|
|
817
|
+
* and the deprecated turnUsername / turnPassword / turnTransport options
|
|
818
|
+
* (none for undefined).
|
|
819
|
+
*/
|
|
820
|
+
set turnServer(server) {
|
|
821
|
+
this.turnServers = server
|
|
822
|
+
? (0, iceBase_1.normalizeIceServerOptions)({
|
|
823
|
+
turnServer: server,
|
|
824
|
+
turnUsername: this.options.turnUsername,
|
|
825
|
+
turnPassword: this.options.turnPassword,
|
|
826
|
+
turnTransport: this.options.turnTransport,
|
|
827
|
+
}).turnServers
|
|
828
|
+
: [];
|
|
644
829
|
}
|
|
645
830
|
get iceControlling() {
|
|
646
831
|
return this._iceControlling;
|
|
@@ -662,6 +847,10 @@ class Connection {
|
|
|
662
847
|
}
|
|
663
848
|
async restart() {
|
|
664
849
|
this.generation++;
|
|
850
|
+
this.remoteGeneration++;
|
|
851
|
+
const previous = this.restarted
|
|
852
|
+
? { [this.localUsername]: this.localPassword }
|
|
853
|
+
: {};
|
|
665
854
|
this.localUsername = (0, helper_1.randomString)(4);
|
|
666
855
|
this.localPassword = (0, helper_1.randomString)(22);
|
|
667
856
|
if (this.options.localPasswordPrefix) {
|
|
@@ -669,18 +858,30 @@ class Connection {
|
|
|
669
858
|
this.options.localPasswordPrefix +
|
|
670
859
|
this.localPassword.slice(this.options.localPasswordPrefix.length);
|
|
671
860
|
}
|
|
672
|
-
|
|
861
|
+
// Only the replaced generation's credentials stay beside the new ones
|
|
862
|
+
// (a check the remote peer sent before it applied the restart is still
|
|
863
|
+
// answered); older generations and staged credentials are dropped, so
|
|
864
|
+
// the history does not grow with every restart.
|
|
865
|
+
this.userHistory = {
|
|
866
|
+
...previous,
|
|
867
|
+
[this.localUsername]: this.localPassword,
|
|
868
|
+
};
|
|
869
|
+
this.restarted = true;
|
|
673
870
|
this.remoteUsername = "";
|
|
674
871
|
this.remotePassword = "";
|
|
675
872
|
this.localCandidates = [];
|
|
676
873
|
this._remoteCandidates = [];
|
|
677
874
|
this.remoteCandidatesEnd = false;
|
|
875
|
+
this.remoteCandidatesEndRequested = false;
|
|
876
|
+
this.remoteResolutions.clear();
|
|
678
877
|
this.localCandidatesEnd = false;
|
|
878
|
+
this.checksBegun = false;
|
|
679
879
|
this.state = "new";
|
|
680
880
|
this.lookup?.close?.();
|
|
681
881
|
this.lookup = undefined;
|
|
682
882
|
this.nominated = undefined;
|
|
683
883
|
this.nominating = false;
|
|
884
|
+
this.cancelChecks();
|
|
684
885
|
this.checkList = [];
|
|
685
886
|
this.checkListDone = false;
|
|
686
887
|
this.checkListState = new helper_1.PQueue();
|
|
@@ -697,6 +898,384 @@ class Connection {
|
|
|
697
898
|
}
|
|
698
899
|
// Tear down consent timers/transactions; new credentials require a new session.
|
|
699
900
|
this.stopConsentLifecycle();
|
|
901
|
+
this.endProvisional();
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Only the remote side restarted (new remote credentials in an answer to an
|
|
905
|
+
* offer that kept the local ones): the remote generation, its checks and
|
|
906
|
+
* the selected pair start over; local credentials and candidates stay.
|
|
907
|
+
*/
|
|
908
|
+
restartRemote() {
|
|
909
|
+
this.remoteGeneration++;
|
|
910
|
+
this.remoteUsername = "";
|
|
911
|
+
this.remotePassword = "";
|
|
912
|
+
this._remoteCandidates = [];
|
|
913
|
+
this.remoteCandidatesEnd = false;
|
|
914
|
+
this.remoteCandidatesEndRequested = false;
|
|
915
|
+
this.remoteResolutions.clear();
|
|
916
|
+
this.checksBegun = false;
|
|
917
|
+
this.state = "new";
|
|
918
|
+
this.nominated = undefined;
|
|
919
|
+
this.nominating = false;
|
|
920
|
+
this.cancelChecks();
|
|
921
|
+
this.checkList = [];
|
|
922
|
+
this.checkListDone = false;
|
|
923
|
+
this.checkListState = new helper_1.PQueue();
|
|
924
|
+
this.earlyChecks = [];
|
|
925
|
+
this.earlyChecksDone = false;
|
|
926
|
+
this.stopConsentLifecycle();
|
|
927
|
+
this.endProvisional();
|
|
928
|
+
}
|
|
929
|
+
/**
|
|
930
|
+
* Stop the checks and nominations in flight for the checklist a restart
|
|
931
|
+
* replaces (or close ends), and start a signal for the next generation.
|
|
932
|
+
*/
|
|
933
|
+
cancelChecks() {
|
|
934
|
+
this.remoteChecks.abort();
|
|
935
|
+
this.remoteChecks = new AbortController();
|
|
936
|
+
for (const pair of this.checkList)
|
|
937
|
+
pair.handle?.resolve?.();
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* Drop the provisional generation and stop the checks still in flight for
|
|
941
|
+
* it (their retransmissions would outlive it).
|
|
942
|
+
*/
|
|
943
|
+
endProvisional() {
|
|
944
|
+
this.provisional?.checks.abort();
|
|
945
|
+
this.provisional = undefined;
|
|
946
|
+
}
|
|
947
|
+
/** Accept provisional checks without changing the selected current pair. */
|
|
948
|
+
stageLocalCredentials(usernameFragment, password, gatherOptions) {
|
|
949
|
+
this.userHistory[usernameFragment] = password;
|
|
950
|
+
this.endProvisional();
|
|
951
|
+
this.provisional = {
|
|
952
|
+
localUsername: usernameFragment,
|
|
953
|
+
localPassword: password,
|
|
954
|
+
gatherOptions,
|
|
955
|
+
remoteCandidates: [],
|
|
956
|
+
remoteCandidatesEnd: false,
|
|
957
|
+
remoteCandidatesEndRequested: false,
|
|
958
|
+
resolutions: new Set(),
|
|
959
|
+
revision: 0,
|
|
960
|
+
pairs: [],
|
|
961
|
+
started: false,
|
|
962
|
+
checks: new AbortController(),
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
discardStagedLocalCredentials(usernameFragment) {
|
|
966
|
+
if (this.provisional?.localUsername === usernameFragment) {
|
|
967
|
+
this.endProvisional();
|
|
968
|
+
}
|
|
969
|
+
if (usernameFragment !== this.localUsername) {
|
|
970
|
+
delete this.userHistory[usernameFragment];
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
/** Remote credentials of the provisional generation (pranswer). */
|
|
974
|
+
setProvisionalRemoteParams({ usernameFragment, password, }) {
|
|
975
|
+
const generation = this.provisional;
|
|
976
|
+
if (!generation)
|
|
977
|
+
return;
|
|
978
|
+
if (generation.remoteUsername === usernameFragment &&
|
|
979
|
+
generation.remotePassword === password) {
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
// A replacement pranswer starts a new provisional checklist; candidates
|
|
983
|
+
// still resolving for the replaced one are dropped by `revision`.
|
|
984
|
+
generation.remoteUsername = usernameFragment;
|
|
985
|
+
generation.remotePassword = password;
|
|
986
|
+
generation.remoteCandidates = [];
|
|
987
|
+
generation.remoteCandidatesEnd = false;
|
|
988
|
+
generation.remoteCandidatesEndRequested = false;
|
|
989
|
+
generation.resolutions.clear();
|
|
990
|
+
generation.revision++;
|
|
991
|
+
generation.checks.abort();
|
|
992
|
+
generation.checks = new AbortController();
|
|
993
|
+
generation.pairs = [];
|
|
994
|
+
generation.nominated = undefined;
|
|
995
|
+
generation.nominating = false;
|
|
996
|
+
}
|
|
997
|
+
async addProvisionalRemoteCandidate(remoteCandidate) {
|
|
998
|
+
const generation = this.provisional;
|
|
999
|
+
if (!generation || this.closed)
|
|
1000
|
+
return;
|
|
1001
|
+
const revision = generation.revision;
|
|
1002
|
+
const current = () => !this.closed &&
|
|
1003
|
+
this.provisional === generation &&
|
|
1004
|
+
generation.revision === revision;
|
|
1005
|
+
if (!remoteCandidate) {
|
|
1006
|
+
if (generation.remoteCandidatesEnd ||
|
|
1007
|
+
generation.remoteCandidatesEndRequested) {
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
// Candidates that arrived before end-of-candidates finish first.
|
|
1011
|
+
generation.remoteCandidatesEndRequested = true;
|
|
1012
|
+
if (generation.resolutions.size > 0) {
|
|
1013
|
+
await Promise.allSettled([...generation.resolutions]);
|
|
1014
|
+
if (!current())
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
generation.remoteCandidatesEnd = true;
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
// RFC 8838: a completed generation takes no further candidates.
|
|
1021
|
+
if (generation.remoteCandidatesEnd ||
|
|
1022
|
+
generation.remoteCandidatesEndRequested) {
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
if (remoteCandidate.host.includes(".local")) {
|
|
1026
|
+
try {
|
|
1027
|
+
if (!this.lookup) {
|
|
1028
|
+
this.lookup = new lookup_1.MdnsLookup();
|
|
1029
|
+
}
|
|
1030
|
+
const resolution = this.lookup.lookup(remoteCandidate.host);
|
|
1031
|
+
generation.resolutions.add(resolution);
|
|
1032
|
+
try {
|
|
1033
|
+
remoteCandidate.host = await resolution;
|
|
1034
|
+
}
|
|
1035
|
+
finally {
|
|
1036
|
+
generation.resolutions.delete(resolution);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
catch (error) {
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
// The generation may have been replaced or completed while resolving.
|
|
1043
|
+
if (!current() || generation.remoteCandidatesEnd)
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1046
|
+
try {
|
|
1047
|
+
(0, iceBase_1.validateRemoteCandidate)(remoteCandidate);
|
|
1048
|
+
}
|
|
1049
|
+
catch (error) {
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
if (!current() ||
|
|
1053
|
+
generation.remoteCandidates.some((c) => c.host === remoteCandidate.host &&
|
|
1054
|
+
c.port === remoteCandidate.port &&
|
|
1055
|
+
c.transport.toLowerCase() === remoteCandidate.transport.toLowerCase())) {
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1058
|
+
generation.remoteCandidates.push(remoteCandidate);
|
|
1059
|
+
for (const protocol of this.protocols) {
|
|
1060
|
+
this.tryProvisionalPair(generation, protocol, remoteCandidate);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
/** Start checks for the provisional generation; the selected pair is kept. */
|
|
1064
|
+
startProvisionalChecks() {
|
|
1065
|
+
const generation = this.provisional;
|
|
1066
|
+
if (!generation || generation.started)
|
|
1067
|
+
return;
|
|
1068
|
+
generation.started = true;
|
|
1069
|
+
for (const remoteCandidate of generation.remoteCandidates) {
|
|
1070
|
+
for (const protocol of this.protocols) {
|
|
1071
|
+
this.tryProvisionalPair(generation, protocol, remoteCandidate);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
for (const pair of generation.pairs) {
|
|
1075
|
+
void this.checkProvisional(generation, pair);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
get provisionalNominated() {
|
|
1079
|
+
return this.provisional?.nominated;
|
|
1080
|
+
}
|
|
1081
|
+
tryProvisionalPair(generation, protocol, remoteCandidate) {
|
|
1082
|
+
if (!protocol.localCandidate?.canPairWith(remoteCandidate) ||
|
|
1083
|
+
!this.allowsProvisional(generation, protocol) ||
|
|
1084
|
+
(protocol.localCandidate.transport.toLowerCase() === "tcp" &&
|
|
1085
|
+
protocol.localCandidate.tcptype === "passive" &&
|
|
1086
|
+
remoteCandidate.type !== "prflx") ||
|
|
1087
|
+
generation.pairs.some((pair) => pair.protocol === protocol &&
|
|
1088
|
+
pair.remoteCandidate === remoteCandidate)) {
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
const pair = new iceBase_1.CandidatePair(protocol, remoteCandidate, this.iceControlling);
|
|
1092
|
+
// The provisional checklist admits the same pairs as the live one.
|
|
1093
|
+
if (this.options.filterCandidatePair &&
|
|
1094
|
+
!this.options.filterCandidatePair(pair)) {
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
pair.updateState(iceBase_1.CandidatePairState.WAITING);
|
|
1098
|
+
generation.pairs.push(pair);
|
|
1099
|
+
if (generation.started)
|
|
1100
|
+
void this.checkProvisional(generation, pair);
|
|
1101
|
+
}
|
|
1102
|
+
async checkProvisional(generation, pair, retry = true) {
|
|
1103
|
+
const revision = generation.revision;
|
|
1104
|
+
// A check belongs to one checklist: a replacement pranswer (new revision)
|
|
1105
|
+
// or a replaced generation makes its outcome meaningless.
|
|
1106
|
+
const belongs = () => this.provisional === generation &&
|
|
1107
|
+
generation.revision === revision &&
|
|
1108
|
+
generation.pairs.includes(pair);
|
|
1109
|
+
if (
|
|
1110
|
+
// An ICE-lite agent only answers checks (RFC 8445 §2.5), in the
|
|
1111
|
+
// provisional generation as in the live one.
|
|
1112
|
+
this.iceLite ||
|
|
1113
|
+
!belongs() ||
|
|
1114
|
+
!generation.started ||
|
|
1115
|
+
!generation.remoteUsername ||
|
|
1116
|
+
!generation.remotePassword ||
|
|
1117
|
+
[
|
|
1118
|
+
iceBase_1.CandidatePairState.IN_PROGRESS,
|
|
1119
|
+
iceBase_1.CandidatePairState.SUCCEEDED,
|
|
1120
|
+
].includes(pair.state)) {
|
|
1121
|
+
return;
|
|
1122
|
+
}
|
|
1123
|
+
pair.updateState(iceBase_1.CandidatePairState.IN_PROGRESS);
|
|
1124
|
+
const nominate = this.iceControlling && !this.remoteIsLite;
|
|
1125
|
+
const request = this.buildRequest({
|
|
1126
|
+
nominate,
|
|
1127
|
+
localUsername: generation.localUsername,
|
|
1128
|
+
remoteUsername: generation.remoteUsername,
|
|
1129
|
+
iceControlling: this.iceControlling,
|
|
1130
|
+
localCandidate: pair.localCandidate,
|
|
1131
|
+
});
|
|
1132
|
+
try {
|
|
1133
|
+
pair.requestsSent++;
|
|
1134
|
+
const [, addr] = await pair.protocol.request(request, pair.remoteAddr, Buffer.from(generation.remotePassword, "utf8"), {
|
|
1135
|
+
retransmissions: pair.localCandidate.transport.toLowerCase() === "tcp" ? 0 : 4,
|
|
1136
|
+
signal: generation.checks.signal,
|
|
1137
|
+
});
|
|
1138
|
+
pair.responsesReceived++;
|
|
1139
|
+
if (!belongs())
|
|
1140
|
+
return;
|
|
1141
|
+
if (addr[0] !== pair.remoteAddr[0] || addr[1] !== pair.remoteAddr[1]) {
|
|
1142
|
+
pair.updateState(iceBase_1.CandidatePairState.FAILED);
|
|
1143
|
+
return;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
catch (error) {
|
|
1147
|
+
if (!belongs())
|
|
1148
|
+
return;
|
|
1149
|
+
const code = error.response?.getAttributeValue("ERROR-CODE")?.[0];
|
|
1150
|
+
pair.updateState(iceBase_1.CandidatePairState.FAILED);
|
|
1151
|
+
if (code === 487 && retry) {
|
|
1152
|
+
this.switchRole(request.attributesKeys.includes("ICE-CONTROLLED"));
|
|
1153
|
+
pair.updateState(iceBase_1.CandidatePairState.WAITING);
|
|
1154
|
+
return this.checkProvisional(generation, pair, false);
|
|
1155
|
+
}
|
|
1156
|
+
return;
|
|
1157
|
+
}
|
|
1158
|
+
if (nominate || pair.remoteNominated)
|
|
1159
|
+
pair.nominated = true;
|
|
1160
|
+
pair.updateState(iceBase_1.CandidatePairState.SUCCEEDED);
|
|
1161
|
+
if (!pair.nominated &&
|
|
1162
|
+
this.iceControlling &&
|
|
1163
|
+
!generation.nominated &&
|
|
1164
|
+
!generation.nominating) {
|
|
1165
|
+
// Regular nomination (the peer is ICE-lite, so the checks carried no
|
|
1166
|
+
// USE-CANDIDATE), as the live checklist does: nominate the first pair
|
|
1167
|
+
// that succeeded with a check that carries it.
|
|
1168
|
+
await this.nominateProvisional(generation, pair, belongs);
|
|
1169
|
+
}
|
|
1170
|
+
if (pair.nominated && !generation.nominated) {
|
|
1171
|
+
log("provisional nominated", pair.toJSON());
|
|
1172
|
+
generation.nominated = pair;
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
async nominateProvisional(generation, pair, belongs) {
|
|
1176
|
+
generation.nominating = true;
|
|
1177
|
+
const request = this.buildRequest({
|
|
1178
|
+
nominate: true,
|
|
1179
|
+
localUsername: generation.localUsername,
|
|
1180
|
+
remoteUsername: generation.remoteUsername,
|
|
1181
|
+
iceControlling: this.iceControlling,
|
|
1182
|
+
localCandidate: pair.localCandidate,
|
|
1183
|
+
});
|
|
1184
|
+
try {
|
|
1185
|
+
pair.requestsSent++;
|
|
1186
|
+
await pair.protocol.request(request, pair.remoteAddr, Buffer.from(generation.remotePassword, "utf8"), {
|
|
1187
|
+
retransmissions: pair.localCandidate.transport.toLowerCase() === "tcp" ? 0 : 4,
|
|
1188
|
+
// endProvisional / a replacement pranswer stops it with the checks.
|
|
1189
|
+
signal: generation.checks.signal,
|
|
1190
|
+
});
|
|
1191
|
+
pair.responsesReceived++;
|
|
1192
|
+
if (belongs())
|
|
1193
|
+
pair.nominated = true;
|
|
1194
|
+
}
|
|
1195
|
+
catch (error) {
|
|
1196
|
+
log("provisional regular nomination failed", error);
|
|
1197
|
+
}
|
|
1198
|
+
finally {
|
|
1199
|
+
if (belongs())
|
|
1200
|
+
generation.nominating = false;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
/** Incoming check for the provisional ufrag; never touches the current checklist. */
|
|
1204
|
+
checkIncomingProvisional(generation, message, addr, protocol) {
|
|
1205
|
+
// A socket the staged generation drops at the commit takes no pair.
|
|
1206
|
+
if (!this.allowsProvisional(generation, protocol))
|
|
1207
|
+
return;
|
|
1208
|
+
// Only checks from the remote credentials of the current checklist count
|
|
1209
|
+
// (a replacement pranswer replaced any earlier ones).
|
|
1210
|
+
const txUsername = message.getAttributeValue("USERNAME");
|
|
1211
|
+
const sender = typeof txUsername === "string"
|
|
1212
|
+
? decodeTxUsername(txUsername).localUsername
|
|
1213
|
+
: undefined;
|
|
1214
|
+
if (generation.remoteUsername && sender !== generation.remoteUsername) {
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
const [host, port] = addr;
|
|
1218
|
+
let remoteCandidate = generation.remoteCandidates.find((c) => c.host === host && c.port === port);
|
|
1219
|
+
if (!remoteCandidate) {
|
|
1220
|
+
remoteCandidate = new candidate_1.Candidate((0, helper_1.randomString)(10), 1, protocol.localCandidate?.transport ?? "udp", message.getAttributeValue("PRIORITY"), host, port, "prflx", undefined, undefined, protocol.localCandidate?.transport === "tcp"
|
|
1221
|
+
? (0, candidate_1.remoteTcpTypeForIncoming)(protocol.localCandidate.tcptype)
|
|
1222
|
+
: undefined, undefined, undefined);
|
|
1223
|
+
generation.remoteCandidates.push(remoteCandidate);
|
|
1224
|
+
}
|
|
1225
|
+
let pair = generation.pairs.find((p) => p.protocol === protocol && p.remoteCandidate === remoteCandidate);
|
|
1226
|
+
if (!pair) {
|
|
1227
|
+
pair = new iceBase_1.CandidatePair(protocol, remoteCandidate, this.iceControlling);
|
|
1228
|
+
pair.updateState(iceBase_1.CandidatePairState.WAITING);
|
|
1229
|
+
generation.pairs.push(pair);
|
|
1230
|
+
}
|
|
1231
|
+
pair.noteIncomingRequest(message.transactionIdHex);
|
|
1232
|
+
pair.requestsReceived++;
|
|
1233
|
+
pair.responsesSent++;
|
|
1234
|
+
if (message.attributesKeys.includes("USE-CANDIDATE") &&
|
|
1235
|
+
!this.iceControlling) {
|
|
1236
|
+
pair.remoteNominated = true;
|
|
1237
|
+
if (this.iceLite || pair.state === iceBase_1.CandidatePairState.SUCCEEDED) {
|
|
1238
|
+
pair.nominated = true;
|
|
1239
|
+
pair.updateState(iceBase_1.CandidatePairState.SUCCEEDED);
|
|
1240
|
+
generation.nominated ?? (generation.nominated = pair);
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
if (!this.iceLite &&
|
|
1244
|
+
[
|
|
1245
|
+
iceBase_1.CandidatePairState.WAITING,
|
|
1246
|
+
iceBase_1.CandidatePairState.FAILED,
|
|
1247
|
+
].includes(pair.state)) {
|
|
1248
|
+
void this.checkProvisional(generation, pair);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
/** Called after restart, before re-gathering the chosen generation. */
|
|
1252
|
+
commitLocalCredentials(usernameFragment, password) {
|
|
1253
|
+
// The credentials restart() generated were never signalled: these replace them.
|
|
1254
|
+
if (this.localUsername !== usernameFragment) {
|
|
1255
|
+
delete this.userHistory[this.localUsername];
|
|
1256
|
+
}
|
|
1257
|
+
this.localUsername = usernameFragment;
|
|
1258
|
+
this.localPassword = password;
|
|
1259
|
+
this.userHistory[usernameFragment] = password;
|
|
1260
|
+
for (const protocol of this.protocols) {
|
|
1261
|
+
if (protocol.localCandidate) {
|
|
1262
|
+
protocol.localCandidate.ufrag = usernameFragment;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
/**
|
|
1267
|
+
* Drop the remote candidates (and their pairs) that name a ufrag other than
|
|
1268
|
+
* `usernameFragment`: they belong to another remote generation and cannot
|
|
1269
|
+
* pass checks with its credentials. Candidates without a ufrag stay.
|
|
1270
|
+
*/
|
|
1271
|
+
dropOtherRemoteGenerations(usernameFragment) {
|
|
1272
|
+
const stale = (candidate) => !!candidate.ufrag && candidate.ufrag !== usernameFragment;
|
|
1273
|
+
this._remoteCandidates = this._remoteCandidates.filter((candidate) => !stale(candidate));
|
|
1274
|
+
for (const pair of this.checkList) {
|
|
1275
|
+
if (stale(pair.remoteCandidate))
|
|
1276
|
+
pair.handle?.resolve?.();
|
|
1277
|
+
}
|
|
1278
|
+
this.checkList = this.checkList.filter((pair) => !stale(pair.remoteCandidate));
|
|
700
1279
|
}
|
|
701
1280
|
resetNominatedPair() {
|
|
702
1281
|
log("resetNominatedPair");
|
|
@@ -712,9 +1291,31 @@ class Connection {
|
|
|
712
1291
|
this.remotePassword = password;
|
|
713
1292
|
}
|
|
714
1293
|
// 4.1.1 Gathering Candidates
|
|
1294
|
+
/**
|
|
1295
|
+
* Gather the local candidates of the current generation.
|
|
1296
|
+
*
|
|
1297
|
+
* After an ICE restart everything the kept sockets already advertised is
|
|
1298
|
+
* advertised again synchronously, before this method first awaits: the host
|
|
1299
|
+
* candidates and the server-reflexive address each kept socket had. Only
|
|
1300
|
+
* work that needs a server follows (a fresh STUN query, a new TURN
|
|
1301
|
+
* allocation), so a caller may let it finish in the background.
|
|
1302
|
+
*/
|
|
715
1303
|
async gatherCandidates() {
|
|
716
1304
|
if (!this.localCandidatesStart) {
|
|
717
1305
|
this.localCandidatesStart = true;
|
|
1306
|
+
const generation = this.generation;
|
|
1307
|
+
// An ICE restart allocates TURN afresh, which is how a restart recovers
|
|
1308
|
+
// from an allocation that died: the previous one leaves the generation.
|
|
1309
|
+
const previousTurn = this.protocols.filter((protocol) => protocol.localCandidate?.type === "relay");
|
|
1310
|
+
// The generation keeps only the sockets a fresh gathering with the
|
|
1311
|
+
// current options would open: a relay-only policy or useTcp turned off
|
|
1312
|
+
// since the previous generation closes the kept host (UDP / TCP)
|
|
1313
|
+
// sockets, so they are neither advertised, paired nor reachable.
|
|
1314
|
+
const excluded = this.protocols.filter((protocol) => !previousTurn.includes(protocol) &&
|
|
1315
|
+
!!protocol.localCandidate &&
|
|
1316
|
+
!(0, iceBase_1.isCandidateAllowedByGatherOptions)(protocol.localCandidate, this.options));
|
|
1317
|
+
this.protocols = this.protocols.filter((protocol) => !previousTurn.includes(protocol) && !excluded.includes(protocol));
|
|
1318
|
+
void Promise.allSettled([...previousTurn, ...excluded].map((protocol) => protocol.close()));
|
|
718
1319
|
// ICE restart keeps transport protocols; re-advertise their host candidates
|
|
719
1320
|
// with the new generation / ufrag before gathering additional addresses.
|
|
720
1321
|
for (const protocol of this.protocols) {
|
|
@@ -722,26 +1323,80 @@ class Connection {
|
|
|
722
1323
|
protocol.localCandidate.generation = this.generation;
|
|
723
1324
|
protocol.localCandidate.ufrag = this.localUsername;
|
|
724
1325
|
this.appendLocalCandidate(protocol.localCandidate);
|
|
1326
|
+
for (const reflexive of this.reflexiveBySocket.get(protocol) ?? []) {
|
|
1327
|
+
this.appendLocalCandidate(this.withGeneration(reflexive));
|
|
1328
|
+
}
|
|
725
1329
|
}
|
|
726
1330
|
}
|
|
727
|
-
|
|
728
|
-
|
|
1331
|
+
// A family bound to an explicit interface address gathers only that
|
|
1332
|
+
// address, so the advertised host candidate is the socket's address.
|
|
1333
|
+
const address = (0, resolveHostAddresses_1.resolveHostAddresses)({
|
|
1334
|
+
enumerated: (0, utils_1.getHostAddresses)(this.options.useIpv4, this.options.useIpv6, {
|
|
1335
|
+
useLinkLocalAddress: this.options.useLinkLocalAddress,
|
|
1336
|
+
}),
|
|
1337
|
+
interfaceAddresses: this.options.interfaceAddresses,
|
|
1338
|
+
additionalHostAddresses: this.options.additionalHostAddresses,
|
|
1339
|
+
useIpv4: this.options.useIpv4,
|
|
1340
|
+
useIpv6: this.options.useIpv6,
|
|
1341
|
+
log,
|
|
729
1342
|
});
|
|
730
|
-
const
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
await Promise.allSettled(candidatePromises);
|
|
1343
|
+
const candidatePromises = this.getCandidatePromises(address, this.options.stunGatherTimeout, generation);
|
|
1344
|
+
// close() ends the gathering at once: the continuations above close
|
|
1345
|
+
// whatever a server query still opens for a closed agent.
|
|
1346
|
+
await Promise.race([
|
|
1347
|
+
Promise.allSettled(candidatePromises),
|
|
1348
|
+
this.closedSignal,
|
|
1349
|
+
]);
|
|
1350
|
+
// A later ICE restart (or close) owns the agent now: this gathering
|
|
1351
|
+
// neither completes that generation nor touches its state.
|
|
1352
|
+
if (!this.isGathering(generation))
|
|
1353
|
+
return;
|
|
742
1354
|
this.localCandidatesEnd = true;
|
|
743
1355
|
}
|
|
744
|
-
|
|
1356
|
+
// Gathering that finishes after connectivity checks began (an ICE restart
|
|
1357
|
+
// keeps gathering from its servers) must not overwrite their state: the
|
|
1358
|
+
// agent stays "new" while checking, and only the checks' outcome moves it.
|
|
1359
|
+
if (this.state === "new" && !this.checksBegun)
|
|
1360
|
+
this.setState("completed");
|
|
1361
|
+
}
|
|
1362
|
+
/**
|
|
1363
|
+
* Whether gathering started for `generation` still belongs to the agent:
|
|
1364
|
+
* no ICE restart replaced the generation and the agent is not closed.
|
|
1365
|
+
*/
|
|
1366
|
+
isGathering(generation) {
|
|
1367
|
+
return this.generation === generation && this.state !== "closed";
|
|
1368
|
+
}
|
|
1369
|
+
/**
|
|
1370
|
+
* Whether the provisional generation may use `protocol`: the staged
|
|
1371
|
+
* generation drops the sockets its gather options exclude at the commit,
|
|
1372
|
+
* so its checks never use them. A kept TURN allocation serves it only when
|
|
1373
|
+
* the generation still uses that TURN server, credential and transport (any of its
|
|
1374
|
+
* TURN servers): one whose server was removed or replaced (a credential
|
|
1375
|
+
* rotation) is not part of it.
|
|
1376
|
+
*/
|
|
1377
|
+
allowsProvisional(generation, protocol) {
|
|
1378
|
+
const options = generation.gatherOptions ?? this.options;
|
|
1379
|
+
if (!protocol.localCandidate ||
|
|
1380
|
+
!(0, iceBase_1.isCandidateAllowedByGatherOptions)(protocol.localCandidate, options)) {
|
|
1381
|
+
return false;
|
|
1382
|
+
}
|
|
1383
|
+
if (protocol instanceof protocol_2.StunOverTurnProtocol) {
|
|
1384
|
+
const { configuredServer, username, password } = protocol.turn;
|
|
1385
|
+
return (0, iceBase_1.normalizeIceServerOptions)(options).turnServers.some((server) => configuredServer[0] === server.address[0] &&
|
|
1386
|
+
configuredServer[1] === server.address[1] &&
|
|
1387
|
+
username === server.username &&
|
|
1388
|
+
password === server.password &&
|
|
1389
|
+
protocol.configuredTransport === server.transport);
|
|
1390
|
+
}
|
|
1391
|
+
return true;
|
|
1392
|
+
}
|
|
1393
|
+
/** A copy of `candidate` labelled with the current generation and ufrag. */
|
|
1394
|
+
withGeneration(candidate) {
|
|
1395
|
+
return new candidate_1.Candidate(candidate.foundation, candidate.component, candidate.transport, candidate.priority, candidate.host, candidate.port, candidate.type, candidate.relatedAddress, candidate.relatedPort, candidate.tcptype, this.generation, this.localUsername);
|
|
1396
|
+
}
|
|
1397
|
+
/** Whether gathering contacts a STUN or TURN server (more than re-advertising sockets). */
|
|
1398
|
+
get gathersFromServers() {
|
|
1399
|
+
return this.stunServers.length > 0 || this.turnServers.length > 0;
|
|
745
1400
|
}
|
|
746
1401
|
appendLocalCandidate(candidate) {
|
|
747
1402
|
this.localCandidates.push(candidate);
|
|
@@ -757,11 +1412,22 @@ class Connection {
|
|
|
757
1412
|
// 相手にとってのremoteは自分にとってのlocal
|
|
758
1413
|
const { remoteUsername: localUsername } = decodeTxUsername(txUsername);
|
|
759
1414
|
const localPassword = this.userHistory[localUsername] ?? this.localPassword;
|
|
1415
|
+
// A check for the staged generation on a socket it drops at the commit
|
|
1416
|
+
// (a host socket under a relay-only policy, a TURN allocation whose
|
|
1417
|
+
// server was removed or replaced) is not answered: the socket is not
|
|
1418
|
+
// part of that generation.
|
|
1419
|
+
const staged = this.provisional;
|
|
1420
|
+
if (staged &&
|
|
1421
|
+
localUsername === staged.localUsername &&
|
|
1422
|
+
localUsername !== this.localUsername &&
|
|
1423
|
+
!this.allowsProvisional(staged, protocol)) {
|
|
1424
|
+
return;
|
|
1425
|
+
}
|
|
760
1426
|
const { iceControlling } = this;
|
|
761
1427
|
// 7.2.1.1. Detecting and Repairing Role Conflicts
|
|
762
1428
|
if (iceControlling && msg.attributesKeys.includes("ICE-CONTROLLING")) {
|
|
763
1429
|
if (this.tieBreaker >= msg.getAttributeValue("ICE-CONTROLLING")) {
|
|
764
|
-
this.respondError(msg, addr, protocol, [487, "Role Conflict"]);
|
|
1430
|
+
this.respondError(msg, addr, protocol, [487, "Role Conflict"], localPassword);
|
|
765
1431
|
return;
|
|
766
1432
|
}
|
|
767
1433
|
else {
|
|
@@ -772,7 +1438,7 @@ class Connection {
|
|
|
772
1438
|
msg.attributesKeys.includes("ICE-CONTROLLED")) {
|
|
773
1439
|
if (this.iceLite ||
|
|
774
1440
|
this.tieBreaker < msg.getAttributeValue("ICE-CONTROLLED")) {
|
|
775
|
-
this.respondError(msg, addr, protocol, [487, "Role Conflict"]);
|
|
1441
|
+
this.respondError(msg, addr, protocol, [487, "Role Conflict"], localPassword);
|
|
776
1442
|
return;
|
|
777
1443
|
}
|
|
778
1444
|
else {
|
|
@@ -793,6 +1459,13 @@ class Connection {
|
|
|
793
1459
|
protocol.sendStun(response, addr).catch((e) => {
|
|
794
1460
|
log("sendStun error", e);
|
|
795
1461
|
});
|
|
1462
|
+
const provisional = this.provisional;
|
|
1463
|
+
if (provisional &&
|
|
1464
|
+
localUsername === provisional.localUsername &&
|
|
1465
|
+
localUsername !== this.localUsername) {
|
|
1466
|
+
this.checkIncomingProvisional(provisional, msg, addr, protocol);
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
796
1469
|
if (this.checkList.length === 0 && !this.earlyChecksDone) {
|
|
797
1470
|
this.earlyChecks.push([msg, addr, protocol]);
|
|
798
1471
|
}
|
|
@@ -838,53 +1511,93 @@ class Connection {
|
|
|
838
1511
|
this.stopConsentLifecycle();
|
|
839
1512
|
this.setState("failed");
|
|
840
1513
|
}
|
|
841
|
-
getCandidatePromises(addresses, timeout = 5) {
|
|
1514
|
+
getCandidatePromises(addresses, timeout = 5, generation = this.generation) {
|
|
842
1515
|
const candidatePromises = [];
|
|
843
|
-
|
|
844
|
-
|
|
1516
|
+
// Each continuation below runs after an await: a socket or allocation it
|
|
1517
|
+
// opened for a replaced generation (or a closed agent) is closed, and
|
|
1518
|
+
// nothing is added to the current one.
|
|
1519
|
+
const stale = () => !this.isGathering(generation);
|
|
1520
|
+
const { stunServers, turnServers } = this;
|
|
1521
|
+
const { interfaceAddresses } = this.options;
|
|
845
1522
|
const gatherIceLite = this.iceLite;
|
|
846
|
-
const gatherRelayOnly =
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
1523
|
+
const gatherRelayOnly = (0, iceBase_1.isRelayOnlyGathering)(this.options);
|
|
1524
|
+
// TCP host candidates are kept per address like the UDP ones, but on
|
|
1525
|
+
// their own: a restart that turned useTcp on gathers them for addresses
|
|
1526
|
+
// whose UDP sockets were kept.
|
|
1527
|
+
const tcpAddresses = addresses.filter((address) => !this.protocols.some((protocol) => protocol.localCandidate?.transport.toLowerCase() === "tcp" &&
|
|
1528
|
+
protocol.localIp === address));
|
|
851
1529
|
addresses = addresses.filter((address) => {
|
|
852
1530
|
// ice restartで同じアドレスが追加されるのを防ぐ
|
|
853
1531
|
if (this.protocols.find((protocol) => protocol.localIp === address)) {
|
|
854
1532
|
return false;
|
|
855
1533
|
}
|
|
1534
|
+
// A family bound to an interface address has one UDP host socket; its
|
|
1535
|
+
// localIp is the bound address, whose notation may differ (IPv6).
|
|
1536
|
+
if ((0, common_1.interfaceAddress)(socketTypeOf(address), interfaceAddresses) ===
|
|
1537
|
+
address &&
|
|
1538
|
+
this.protocols.some((protocol) => protocol instanceof protocol_1.StunProtocol &&
|
|
1539
|
+
protocol.localCandidate?.type === "host" &&
|
|
1540
|
+
(0, net_1.isIPv4)(protocol.localCandidate.host) === (0, net_1.isIPv4)(address))) {
|
|
1541
|
+
return false;
|
|
1542
|
+
}
|
|
856
1543
|
return true;
|
|
857
1544
|
});
|
|
1545
|
+
// An ICE restart keeps its UDP sockets. They are not re-created above, but
|
|
1546
|
+
// their server-reflexive address is part of the new generation too, so
|
|
1547
|
+
// the STUN query below runs for them as well.
|
|
1548
|
+
const reusedStunProtocols = this.protocols.filter((protocol) => protocol instanceof protocol_1.StunProtocol &&
|
|
1549
|
+
protocol.localCandidate?.type === "host" &&
|
|
1550
|
+
protocol.localCandidate.transport === "udp");
|
|
858
1551
|
const localStunPromises = gatherRelayOnly
|
|
859
1552
|
? []
|
|
860
1553
|
: addresses.map(async (address) => {
|
|
861
1554
|
// # create transport
|
|
862
1555
|
const protocol = new protocol_1.StunProtocol();
|
|
863
1556
|
this.ensureProtocol(protocol);
|
|
1557
|
+
const boundInterface = (0, common_1.interfaceAddress)(socketTypeOf(address), interfaceAddresses);
|
|
864
1558
|
try {
|
|
865
|
-
await protocol.connectionMade((0, net_1.isIPv4)(address), this.options.portRange,
|
|
866
|
-
|
|
1559
|
+
await protocol.connectionMade((0, net_1.isIPv4)(address), this.options.portRange, interfaceAddresses);
|
|
1560
|
+
if (stale()) {
|
|
1561
|
+
await protocol.close();
|
|
1562
|
+
return;
|
|
1563
|
+
}
|
|
1564
|
+
// # add host candidate
|
|
1565
|
+
// A socket bound to an interface address advertises that address:
|
|
1566
|
+
// the peer sends its checks there. A wildcard socket advertises
|
|
1567
|
+
// the gathered address (never 0.0.0.0 / ::).
|
|
1568
|
+
const [boundHost, boundPort] = protocol.getExtraInfo();
|
|
1569
|
+
let candidateHost = address;
|
|
1570
|
+
if (boundInterface) {
|
|
1571
|
+
candidateHost = stripZoneId(boundHost);
|
|
1572
|
+
if (candidateHost !== address) {
|
|
1573
|
+
log("host address differs from the bound interface address; advertise the bound one", address, candidateHost);
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
const candidateAddress = [candidateHost, boundPort];
|
|
1577
|
+
protocol.localIp = candidateHost;
|
|
867
1578
|
this.protocols.push(protocol);
|
|
868
1579
|
log("protocol", protocol.localIp);
|
|
869
|
-
// # add host candidate
|
|
870
|
-
const candidateAddress = [
|
|
871
|
-
address,
|
|
872
|
-
protocol.getExtraInfo()[1],
|
|
873
|
-
];
|
|
874
1580
|
protocol.localCandidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("host", "udp", candidateAddress[0]), 1, "udp", (0, candidate_1.candidatePriority)("host", { transport: "udp" }), candidateAddress[0], candidateAddress[1], "host", undefined, undefined, undefined, this.generation, this.localUsername);
|
|
875
1581
|
this.pairLocalProtocol(protocol);
|
|
876
1582
|
this.appendLocalCandidate(protocol.localCandidate);
|
|
877
1583
|
return protocol;
|
|
878
1584
|
}
|
|
879
1585
|
catch (error) {
|
|
880
|
-
|
|
1586
|
+
if (boundInterface) {
|
|
1587
|
+
// No host candidate for this family: advertising another
|
|
1588
|
+
// address than the socket's would mislead the peer.
|
|
1589
|
+
log("failed to bind UDP socket to interface address", boundInterface, error);
|
|
1590
|
+
}
|
|
1591
|
+
else {
|
|
1592
|
+
log("error protocol STUN", error);
|
|
1593
|
+
}
|
|
881
1594
|
}
|
|
882
1595
|
});
|
|
883
1596
|
if (!gatherRelayOnly) {
|
|
884
1597
|
candidatePromises.push(...localStunPromises.map((localPromise) => localPromise.then((protocol) => protocol?.localCandidate)));
|
|
885
1598
|
}
|
|
886
1599
|
if (!gatherRelayOnly && this.options.useTcp) {
|
|
887
|
-
const tcpCandidatePromises =
|
|
1600
|
+
const tcpCandidatePromises = tcpAddresses.map(async (address) => {
|
|
888
1601
|
// Passive candidates open a listening TCP server; skip them when the
|
|
889
1602
|
// agent only makes outbound connections (tcpPassive === false). Active
|
|
890
1603
|
// candidates below still dial out, so direct TCP egress is unaffected.
|
|
@@ -892,6 +1605,10 @@ class Connection {
|
|
|
892
1605
|
const passiveProtocol = new tcpProtocol_1.TcpPassiveProtocol();
|
|
893
1606
|
this.ensureProtocol(passiveProtocol);
|
|
894
1607
|
await passiveProtocol.connectionMade(address, this.options.portRange);
|
|
1608
|
+
if (stale()) {
|
|
1609
|
+
await passiveProtocol.close();
|
|
1610
|
+
return;
|
|
1611
|
+
}
|
|
895
1612
|
passiveProtocol.localIp = address;
|
|
896
1613
|
passiveProtocol.localCandidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("host", "tcp", address), 1, "tcp", (0, candidate_1.candidatePriority)("host", {
|
|
897
1614
|
transport: "tcp",
|
|
@@ -904,6 +1621,10 @@ class Connection {
|
|
|
904
1621
|
const activeProtocol = new tcpProtocol_1.TcpActiveProtocol();
|
|
905
1622
|
this.ensureProtocol(activeProtocol);
|
|
906
1623
|
await activeProtocol.connectionMade(address);
|
|
1624
|
+
if (stale()) {
|
|
1625
|
+
await activeProtocol.close();
|
|
1626
|
+
return;
|
|
1627
|
+
}
|
|
907
1628
|
activeProtocol.localIp = address;
|
|
908
1629
|
activeProtocol.localCandidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("host", "tcp", address), 1, "tcp", (0, candidate_1.candidatePriority)("host", {
|
|
909
1630
|
transport: "tcp",
|
|
@@ -916,80 +1637,149 @@ class Connection {
|
|
|
916
1637
|
});
|
|
917
1638
|
candidatePromises.push(...tcpCandidatePromises);
|
|
918
1639
|
}
|
|
919
|
-
|
|
1640
|
+
// A server-reflexive query of one socket to one STUN server, bounded by
|
|
1641
|
+
// the STUN gather timeout; an unanswered one yields nothing.
|
|
1642
|
+
const queryReflexive = async (protocol, server) => {
|
|
1643
|
+
let timer;
|
|
1644
|
+
const candidate = await Promise.race([
|
|
1645
|
+
(0, iceBase_1.serverReflexiveCandidate)(protocol, server).catch((error) => {
|
|
1646
|
+
log("query STUN server", server, error);
|
|
1647
|
+
return undefined;
|
|
1648
|
+
}),
|
|
1649
|
+
new Promise((resolve) => {
|
|
1650
|
+
timer = setTimeout(() => resolve(undefined), timeout * 1000);
|
|
1651
|
+
}),
|
|
1652
|
+
]);
|
|
1653
|
+
clearTimeout(timer);
|
|
1654
|
+
return candidate;
|
|
1655
|
+
};
|
|
1656
|
+
// RFC 8445 §5.1.3: a mapping equal to one the socket already advertised
|
|
1657
|
+
// (same base, same transport address) is redundant.
|
|
1658
|
+
const sameMapping = (a, b) => a.host === b.host && a.port === b.port;
|
|
1659
|
+
if (!gatherIceLite && !gatherRelayOnly && stunServers.length > 0) {
|
|
1660
|
+
// Sockets kept across an ICE restart query every STUN server again.
|
|
1661
|
+
// The mappings they already advertised are in the new generation from
|
|
1662
|
+
// the start; a different fresh mapping (the NAT rebound) is added to
|
|
1663
|
+
// it, and the fresh mappings replace the kept ones for the next restart.
|
|
1664
|
+
const reusedReflexivePromises = reusedStunProtocols
|
|
1665
|
+
.filter((protocol) => (0, net_1.isIPv4)(protocol.localCandidate.host))
|
|
1666
|
+
.map(async (protocol) => {
|
|
1667
|
+
const previous = this.reflexiveBySocket.get(protocol) ?? [];
|
|
1668
|
+
const advertised = [...previous];
|
|
1669
|
+
const fresh = [];
|
|
1670
|
+
await Promise.all(stunServers.map(async (server) => {
|
|
1671
|
+
const candidate = await queryReflexive(protocol, server);
|
|
1672
|
+
if (!candidate || stale())
|
|
1673
|
+
return;
|
|
1674
|
+
if (!fresh.some((known) => sameMapping(known, candidate))) {
|
|
1675
|
+
fresh.push(candidate);
|
|
1676
|
+
}
|
|
1677
|
+
if (advertised.some((known) => sameMapping(known, candidate))) {
|
|
1678
|
+
return;
|
|
1679
|
+
}
|
|
1680
|
+
advertised.push(candidate);
|
|
1681
|
+
this.appendLocalCandidate(candidate);
|
|
1682
|
+
}));
|
|
1683
|
+
if (stale())
|
|
1684
|
+
return;
|
|
1685
|
+
if (fresh.length > 0)
|
|
1686
|
+
this.reflexiveBySocket.set(protocol, fresh);
|
|
1687
|
+
return fresh.length > 0 ? fresh : previous;
|
|
1688
|
+
})
|
|
1689
|
+
.map((promise) => promise.catch((error) => {
|
|
1690
|
+
log("query STUN server", error);
|
|
1691
|
+
}));
|
|
1692
|
+
candidatePromises.push(...reusedReflexivePromises);
|
|
1693
|
+
// Every new IPv4 socket queries every STUN server in parallel.
|
|
920
1694
|
const stunCandidatePromises = localStunPromises.map(async (protocolPromise) => {
|
|
921
1695
|
const protocol = await protocolPromise;
|
|
922
|
-
if (!protocol
|
|
1696
|
+
if (!protocol?.localCandidate ||
|
|
1697
|
+
!(0, net_1.isIPv4)(protocol.localCandidate.host))
|
|
923
1698
|
return;
|
|
924
|
-
const
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
if (candidate) {
|
|
932
|
-
this.appendLocalCandidate(candidate);
|
|
933
|
-
}
|
|
934
|
-
clearTimeout(timer);
|
|
935
|
-
r(candidate);
|
|
936
|
-
}
|
|
937
|
-
else {
|
|
938
|
-
clearTimeout(timer);
|
|
939
|
-
r();
|
|
1699
|
+
const advertised = [];
|
|
1700
|
+
await Promise.all(stunServers.map(async (server) => {
|
|
1701
|
+
const candidate = await queryReflexive(protocol, server);
|
|
1702
|
+
if (!candidate || stale())
|
|
1703
|
+
return;
|
|
1704
|
+
if (advertised.some((known) => sameMapping(known, candidate))) {
|
|
1705
|
+
return;
|
|
940
1706
|
}
|
|
941
|
-
|
|
1707
|
+
advertised.push(candidate);
|
|
1708
|
+
this.reflexiveBySocket.set(protocol, advertised);
|
|
1709
|
+
this.appendLocalCandidate(candidate);
|
|
1710
|
+
})).catch((error) => {
|
|
942
1711
|
log("query STUN server", error);
|
|
943
1712
|
});
|
|
944
|
-
return
|
|
1713
|
+
return advertised;
|
|
945
1714
|
});
|
|
946
1715
|
candidatePromises.push(...stunCandidatePromises);
|
|
947
1716
|
}
|
|
948
|
-
if (!gatherIceLite
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
1717
|
+
if (!gatherIceLite) {
|
|
1718
|
+
// Every TURN server gets its own allocation, made with its own
|
|
1719
|
+
// credential and transport; one that fails does not stop the others.
|
|
1720
|
+
const turnCandidatePromises = turnServers.map((server) => this.gatherRelayCandidate(server, gatherRelayOnly, stale).catch((error) => {
|
|
1721
|
+
log("query TURN server", server.address, error);
|
|
1722
|
+
}));
|
|
1723
|
+
candidatePromises.push(...turnCandidatePromises);
|
|
1724
|
+
}
|
|
1725
|
+
return candidatePromises;
|
|
1726
|
+
}
|
|
1727
|
+
/**
|
|
1728
|
+
* Allocate on one TURN server and add its relay candidate. A UDP
|
|
1729
|
+
* allocation that fails falls back to TCP on the same server. An
|
|
1730
|
+
* allocation that completes for a replaced generation (or a closed agent)
|
|
1731
|
+
* is released.
|
|
1732
|
+
*/
|
|
1733
|
+
async gatherRelayCandidate(server, relayOnly, stale) {
|
|
1734
|
+
const { address, username, password, transport } = server;
|
|
1735
|
+
const protocol = await (0, protocol_2.createStunOverTurnClient)({ address, username, password }, {
|
|
1736
|
+
portRange: this.options.portRange,
|
|
1737
|
+
interfaceAddresses: this.options.interfaceAddresses,
|
|
1738
|
+
transport,
|
|
1739
|
+
tlsOptions: this.options.turnTlsOptions,
|
|
1740
|
+
connectTimeoutMs: (this.options.turnConnectTimeout ?? 8) * 1000,
|
|
1741
|
+
udpFamily: this.options.turnUdpFamily,
|
|
1742
|
+
signal: this.closing.signal,
|
|
1743
|
+
}).catch(async (e) => {
|
|
1744
|
+
// close() cancelled the allocation: no TCP fallback.
|
|
1745
|
+
if (transport === "udp" && !this.closing.signal.aborted) {
|
|
1746
|
+
return await (0, protocol_2.createStunOverTurnClient)({ address, username, password }, {
|
|
956
1747
|
portRange: this.options.portRange,
|
|
957
1748
|
interfaceAddresses: this.options.interfaceAddresses,
|
|
958
|
-
transport:
|
|
959
|
-
tlsOptions: this.options.turnTlsOptions,
|
|
1749
|
+
transport: "tcp",
|
|
960
1750
|
connectTimeoutMs: (this.options.turnConnectTimeout ?? 8) * 1000,
|
|
961
|
-
|
|
962
|
-
}).catch(async (e) => {
|
|
963
|
-
if (turnTransport === "udp") {
|
|
964
|
-
return await (0, protocol_2.createStunOverTurnClient)({
|
|
965
|
-
address: turnServer,
|
|
966
|
-
username: turnUsername,
|
|
967
|
-
password: turnPassword,
|
|
968
|
-
}, {
|
|
969
|
-
portRange: this.options.portRange,
|
|
970
|
-
interfaceAddresses: this.options.interfaceAddresses,
|
|
971
|
-
transport: "tcp",
|
|
972
|
-
connectTimeoutMs: (this.options.turnConnectTimeout ?? 8) * 1000,
|
|
973
|
-
});
|
|
974
|
-
}
|
|
975
|
-
else {
|
|
976
|
-
throw e;
|
|
977
|
-
}
|
|
1751
|
+
signal: this.closing.signal,
|
|
978
1752
|
});
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
});
|
|
990
|
-
candidatePromises.push(turnCandidatePromise);
|
|
1753
|
+
}
|
|
1754
|
+
else {
|
|
1755
|
+
throw e;
|
|
1756
|
+
}
|
|
1757
|
+
});
|
|
1758
|
+
if (stale()) {
|
|
1759
|
+
// The allocation never joins a generation: release it (and its
|
|
1760
|
+
// refresh timer) instead of keeping a second one alive.
|
|
1761
|
+
await protocol.close();
|
|
1762
|
+
return;
|
|
991
1763
|
}
|
|
992
|
-
|
|
1764
|
+
protocol.configuredTransport = transport;
|
|
1765
|
+
this.ensureProtocol(protocol);
|
|
1766
|
+
this.protocols.push(protocol);
|
|
1767
|
+
const candidateAddress = protocol.turn.relayedAddress;
|
|
1768
|
+
// The related address of a relay candidate is the address the TURN
|
|
1769
|
+
// server saw the agent at. A relay-only policy hides the agent's
|
|
1770
|
+
// addresses from the peer, so it advertises the unspecified address
|
|
1771
|
+
// and port 9 instead (RFC 8839 §5.1), in SDP and trickle alike.
|
|
1772
|
+
const relatedAddress = relayOnly
|
|
1773
|
+
? [(0, net_1.isIPv4)(candidateAddress[0]) ? "0.0.0.0" : "::", 9]
|
|
1774
|
+
: protocol.turn.mappedAddress;
|
|
1775
|
+
log("turn candidateAddress", candidateAddress);
|
|
1776
|
+
protocol.localCandidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("relay", "udp", candidateAddress[0]), 1, "udp", (0, candidate_1.candidatePriority)("relay"), candidateAddress[0], candidateAddress[1], "relay", relatedAddress[0], relatedAddress[1], undefined, this.generation, this.localUsername);
|
|
1777
|
+
// An allocation that completes after the remote candidates arrived
|
|
1778
|
+
// (early signaling, or an ICE restart that allocates afresh) pairs
|
|
1779
|
+
// with them; a connect() already running schedules the new pairs.
|
|
1780
|
+
this.pairLocalProtocol(protocol);
|
|
1781
|
+
this.appendLocalCandidate(protocol.localCandidate);
|
|
1782
|
+
return protocol.localCandidate;
|
|
993
1783
|
}
|
|
994
1784
|
async connect() {
|
|
995
1785
|
// """
|
|
@@ -1007,6 +1797,7 @@ class Connection {
|
|
|
1007
1797
|
if (!this.remoteUsername || !this.remotePassword) {
|
|
1008
1798
|
throw new Error("Remote username or password is missing");
|
|
1009
1799
|
}
|
|
1800
|
+
this.checksBegun = true;
|
|
1010
1801
|
// # 5.7.1. Forming Candidate Pairs
|
|
1011
1802
|
for (const c of this.remoteCandidates) {
|
|
1012
1803
|
this.pairRemoteCandidate(c);
|
|
@@ -1091,7 +1882,7 @@ class Connection {
|
|
|
1091
1882
|
// # find the highest-priority pair that is in the waiting state
|
|
1092
1883
|
const pair = this.checkList
|
|
1093
1884
|
.filter((pair) => {
|
|
1094
|
-
if (this.options
|
|
1885
|
+
if ((0, iceBase_1.isRelayOnlyGathering)(this.options) &&
|
|
1095
1886
|
pair.protocol.type === protocol_1.StunProtocol.type)
|
|
1096
1887
|
return false;
|
|
1097
1888
|
return true;
|
|
@@ -1110,8 +1901,10 @@ class Connection {
|
|
|
1110
1901
|
return true;
|
|
1111
1902
|
}
|
|
1112
1903
|
}
|
|
1113
|
-
// # if we expect more candidates, keep going
|
|
1114
|
-
|
|
1904
|
+
// # if we expect more candidates, keep going: remote ones until
|
|
1905
|
+
// end-of-candidates, local ones until this generation's gathering ends
|
|
1906
|
+
// (a relay candidate of an ICE restart can follow the remote ones).
|
|
1907
|
+
if (!this.remoteCandidatesEnd || !this.localCandidatesEnd) {
|
|
1115
1908
|
return !this.checkListDone;
|
|
1116
1909
|
}
|
|
1117
1910
|
return false;
|
|
@@ -1176,7 +1969,17 @@ class Connection {
|
|
|
1176
1969
|
// """
|
|
1177
1970
|
// Close the connection.
|
|
1178
1971
|
// """
|
|
1972
|
+
this.closed = true;
|
|
1179
1973
|
this.setState("closed");
|
|
1974
|
+
this.signalClosed();
|
|
1975
|
+
this.closing.abort();
|
|
1976
|
+
this.cancelChecks();
|
|
1977
|
+
this.endProvisional();
|
|
1978
|
+
// Before the first await: a pending mDNS lookup is cancelled here, so no
|
|
1979
|
+
// response arriving while the protocols close adds a remote candidate.
|
|
1980
|
+
this.lookup?.close?.();
|
|
1981
|
+
this.lookup = undefined;
|
|
1982
|
+
this.remoteResolutions.clear();
|
|
1180
1983
|
// # stop consent freshness tests
|
|
1181
1984
|
this.stopConsentLifecycle();
|
|
1182
1985
|
// # stop check list
|
|
@@ -1193,34 +1996,70 @@ class Connection {
|
|
|
1193
1996
|
}
|
|
1194
1997
|
this.protocols = [];
|
|
1195
1998
|
this.localCandidates = [];
|
|
1196
|
-
this.lookup?.close?.();
|
|
1197
|
-
this.lookup = undefined;
|
|
1198
1999
|
}
|
|
1199
2000
|
setState(state) {
|
|
1200
2001
|
this.state = state;
|
|
1201
2002
|
this.stateChanged.execute(state);
|
|
1202
2003
|
}
|
|
2004
|
+
/**
|
|
2005
|
+
* Known constraint (as in develop): candidates are not deduplicated. A
|
|
2006
|
+
* description applied again in the same generation (BUNDLE split and
|
|
2007
|
+
* merge after an ICE restart) adds its candidates and pairs a second time,
|
|
2008
|
+
* until the next restart. Deduplicating here alone breaks the pairs a
|
|
2009
|
+
* provisional generation dropped and the repeated add rebuilds; a fix needs
|
|
2010
|
+
* the pairing and provisional lifecycle together.
|
|
2011
|
+
*/
|
|
1203
2012
|
async addRemoteCandidate(remoteCandidate) {
|
|
1204
2013
|
// """
|
|
1205
2014
|
// Add a remote candidate or signal end-of-candidates.
|
|
1206
2015
|
// To signal end-of-candidates, pass `None`.
|
|
1207
2016
|
// :param remote_candidate: A :class:`Candidate` instance or `None`.
|
|
1208
2017
|
// """
|
|
2018
|
+
// A closed agent takes no candidate (and opens no mDNS socket).
|
|
2019
|
+
if (this.closed)
|
|
2020
|
+
return;
|
|
1209
2021
|
if (!remoteCandidate) {
|
|
2022
|
+
if (this.remoteCandidatesEnd || this.remoteCandidatesEndRequested) {
|
|
2023
|
+
return;
|
|
2024
|
+
}
|
|
2025
|
+
// Candidates that arrived before end-of-candidates finish first.
|
|
2026
|
+
this.remoteCandidatesEndRequested = true;
|
|
2027
|
+
if (this.remoteResolutions.size > 0) {
|
|
2028
|
+
const generation = this.remoteGeneration;
|
|
2029
|
+
await Promise.allSettled([...this.remoteResolutions]);
|
|
2030
|
+
if (this.remoteGeneration !== generation || this.closed)
|
|
2031
|
+
return;
|
|
2032
|
+
}
|
|
1210
2033
|
this.remoteCandidatesEnd = true;
|
|
1211
2034
|
return;
|
|
1212
2035
|
}
|
|
2036
|
+
// RFC 8838: a completed generation takes no further candidates.
|
|
2037
|
+
if (this.remoteCandidatesEnd || this.remoteCandidatesEndRequested) {
|
|
2038
|
+
return;
|
|
2039
|
+
}
|
|
1213
2040
|
if (remoteCandidate.host.includes(".local")) {
|
|
2041
|
+
const generation = this.remoteGeneration;
|
|
1214
2042
|
try {
|
|
1215
2043
|
if (!this.lookup) {
|
|
1216
2044
|
this.lookup = new lookup_1.MdnsLookup();
|
|
1217
2045
|
}
|
|
1218
|
-
const
|
|
1219
|
-
|
|
2046
|
+
const resolution = this.lookup.lookup(remoteCandidate.host);
|
|
2047
|
+
this.remoteResolutions.add(resolution);
|
|
2048
|
+
try {
|
|
2049
|
+
remoteCandidate.host = await resolution;
|
|
2050
|
+
}
|
|
2051
|
+
finally {
|
|
2052
|
+
this.remoteResolutions.delete(resolution);
|
|
2053
|
+
}
|
|
1220
2054
|
}
|
|
1221
2055
|
catch (error) {
|
|
1222
2056
|
return;
|
|
1223
2057
|
}
|
|
2058
|
+
// An ICE restart, completion or close while resolving ends this candidate's generation.
|
|
2059
|
+
if (this.remoteGeneration !== generation ||
|
|
2060
|
+
this.remoteCandidatesEnd ||
|
|
2061
|
+
this.closed)
|
|
2062
|
+
return;
|
|
1224
2063
|
}
|
|
1225
2064
|
try {
|
|
1226
2065
|
(0, iceBase_1.validateRemoteCandidate)(remoteCandidate);
|
|
@@ -1292,14 +2131,24 @@ class Connection {
|
|
|
1292
2131
|
// concludes the ICE processing for that component. See Section 8.
|
|
1293
2132
|
// So disallow overwriting of the pair nominated for that component
|
|
1294
2133
|
if (pair.nominated &&
|
|
1295
|
-
// remote
|
|
1296
|
-
(
|
|
1297
|
-
|
|
1298
|
-
|
|
2134
|
+
// The pair belongs to the live remote generation: it is in the
|
|
2135
|
+
// current checklist (a restart resets it, so a check still in flight
|
|
2136
|
+
// from a discarded generation cannot select its pair) and its remote
|
|
2137
|
+
// candidate names the live remote ufrag, if it names one. The SDP
|
|
2138
|
+
// `generation` attribute counts the peer's own restarts and is not
|
|
2139
|
+
// comparable with the local generation (a remote-only restart, or a
|
|
2140
|
+
// peer that numbers differently).
|
|
2141
|
+
this.checkList.includes(pair) &&
|
|
2142
|
+
(pair.remoteCandidate.ufrag == undefined ||
|
|
2143
|
+
pair.remoteCandidate.ufrag === this.remoteUsername) &&
|
|
1299
2144
|
this.nominated == undefined) {
|
|
1300
2145
|
log("nominated", pair.toJSON());
|
|
1301
2146
|
this.nominated = pair;
|
|
1302
2147
|
this.nominating = false;
|
|
2148
|
+
// RFC 7675 section 5.1: the successful connectivity check that
|
|
2149
|
+
// selected the pair is its initial consent, so data may flow at once
|
|
2150
|
+
// instead of waiting for the consent lifecycle to start.
|
|
2151
|
+
this.consentFresh = true;
|
|
1303
2152
|
this.pruneTcpConnections(pair);
|
|
1304
2153
|
// After resetNominatedPair / renomination while already connected,
|
|
1305
2154
|
// restart consent freshness on the new selected pair.
|
|
@@ -1313,7 +2162,10 @@ class Connection {
|
|
|
1313
2162
|
// nominated pairs for that media stream.
|
|
1314
2163
|
for (const p of this.checkList) {
|
|
1315
2164
|
if (p.component === pair.component &&
|
|
1316
|
-
[
|
|
2165
|
+
[
|
|
2166
|
+
iceBase_1.CandidatePairState.WAITING,
|
|
2167
|
+
iceBase_1.CandidatePairState.FROZEN,
|
|
2168
|
+
].includes(p.state)) {
|
|
1317
2169
|
p.updateState(iceBase_1.CandidatePairState.FAILED);
|
|
1318
2170
|
}
|
|
1319
2171
|
}
|
|
@@ -1344,7 +2196,10 @@ class Connection {
|
|
|
1344
2196
|
return;
|
|
1345
2197
|
}
|
|
1346
2198
|
{
|
|
1347
|
-
const list = [
|
|
2199
|
+
const list = [
|
|
2200
|
+
iceBase_1.CandidatePairState.SUCCEEDED,
|
|
2201
|
+
iceBase_1.CandidatePairState.FAILED,
|
|
2202
|
+
];
|
|
1348
2203
|
if (this.checkList.find(({ state }) => !list.includes(state))) {
|
|
1349
2204
|
return;
|
|
1350
2205
|
}
|
|
@@ -1355,13 +2210,27 @@ class Connection {
|
|
|
1355
2210
|
return;
|
|
1356
2211
|
}
|
|
1357
2212
|
}
|
|
1358
|
-
|
|
2213
|
+
// RFC 8838 §8: with trickle ICE the check list fails only once neither
|
|
2214
|
+
// side can add candidates any more; a relay candidate still being gathered
|
|
2215
|
+
// (or a remote one before end-of-candidates) may yet pair and succeed.
|
|
2216
|
+
if (!this.checkListDone &&
|
|
2217
|
+
this.localCandidatesEnd &&
|
|
2218
|
+
this.remoteCandidatesEnd) {
|
|
1359
2219
|
log("ICE failed");
|
|
1360
2220
|
this.checkListState.put(new Promise((r) => {
|
|
1361
2221
|
r(iceBase_1.ICE_FAILED);
|
|
1362
2222
|
}));
|
|
1363
2223
|
}
|
|
1364
2224
|
}
|
|
2225
|
+
/**
|
|
2226
|
+
* 487 / 401 retry of a check: the retry is cancelled with the check it
|
|
2227
|
+
* replaces (its handle) and, through checkStart, with the generation.
|
|
2228
|
+
*/
|
|
2229
|
+
async retryCheck(pair, onCancel) {
|
|
2230
|
+
const retry = this.checkStart(pair);
|
|
2231
|
+
onCancel.once(() => retry.resolve());
|
|
2232
|
+
await retry.awaitable;
|
|
2233
|
+
}
|
|
1365
2234
|
isTcpPair(pair) {
|
|
1366
2235
|
return pair.localCandidate.transport.toLowerCase() === "tcp";
|
|
1367
2236
|
}
|
|
@@ -1418,7 +2287,7 @@ class Connection {
|
|
|
1418
2287
|
}
|
|
1419
2288
|
nominateTcpPair(pair) {
|
|
1420
2289
|
this.nominating = true;
|
|
1421
|
-
const
|
|
2290
|
+
const generation = this.remoteGeneration;
|
|
1422
2291
|
const request = this.buildRequest({
|
|
1423
2292
|
nominate: true,
|
|
1424
2293
|
localUsername: pair.localCandidate.ufrag ?? this.localUsername,
|
|
@@ -1428,7 +2297,7 @@ class Connection {
|
|
|
1428
2297
|
});
|
|
1429
2298
|
pair.requestsSent++;
|
|
1430
2299
|
pair.protocol
|
|
1431
|
-
.request(request, pair.remoteAddr, Buffer.from(this.remotePassword, "utf8"), this.checkRequestOptions(pair))
|
|
2300
|
+
.request(request, pair.remoteAddr, Buffer.from(this.remotePassword, "utf8"), { ...this.checkRequestOptions(pair), signal: this.remoteChecks.signal })
|
|
1432
2301
|
.then(() => {
|
|
1433
2302
|
if (this.isStaleNomination(pair, generation)) {
|
|
1434
2303
|
return;
|
|
@@ -1450,7 +2319,7 @@ class Connection {
|
|
|
1450
2319
|
/** The agent was closed or restarted while the nomination was in flight. */
|
|
1451
2320
|
isStaleNomination(pair, generation) {
|
|
1452
2321
|
return (this.state === "closed" ||
|
|
1453
|
-
this.
|
|
2322
|
+
this.remoteGeneration !== generation ||
|
|
1454
2323
|
!this.checkList.includes(pair));
|
|
1455
2324
|
}
|
|
1456
2325
|
addPair(pair) {
|
|
@@ -1491,7 +2360,10 @@ class Connection {
|
|
|
1491
2360
|
pair.noteIncomingRequest(message.transactionIdHex);
|
|
1492
2361
|
pair.requestsReceived++;
|
|
1493
2362
|
pair.responsesSent++;
|
|
1494
|
-
pair
|
|
2363
|
+
// The pair's local candidate is the protocol's shared candidate of the
|
|
2364
|
+
// current generation. A late check addressed to an earlier ufrag (consent
|
|
2365
|
+
// on the old pair during an ICE restart) must not relabel it, or the next
|
|
2366
|
+
// description would advertise it under that old ufrag.
|
|
1495
2367
|
log("Triggered Checks", message.toJSON(), pair.toJSON(), {
|
|
1496
2368
|
localUsername: this.localUsername,
|
|
1497
2369
|
remoteUsername: this.remoteUsername,
|
|
@@ -1510,7 +2382,10 @@ class Connection {
|
|
|
1510
2382
|
return;
|
|
1511
2383
|
}
|
|
1512
2384
|
// 7.2.1.4. Triggered Checks
|
|
1513
|
-
if ([
|
|
2385
|
+
if ([
|
|
2386
|
+
iceBase_1.CandidatePairState.WAITING,
|
|
2387
|
+
iceBase_1.CandidatePairState.FAILED,
|
|
2388
|
+
].includes(pair.state)) {
|
|
1514
2389
|
pair.handle = this.checkStart(pair);
|
|
1515
2390
|
}
|
|
1516
2391
|
// 7.2.1.5. Updating the Nominated Flag
|
|
@@ -1538,7 +2413,16 @@ class Connection {
|
|
|
1538
2413
|
this.addPair(pair);
|
|
1539
2414
|
}
|
|
1540
2415
|
}
|
|
2416
|
+
/**
|
|
2417
|
+
* Pair a local candidate gathered after remote candidates arrived (a late
|
|
2418
|
+
* TURN allocation, a slow host socket) with them.
|
|
2419
|
+
*/
|
|
1541
2420
|
pairLocalProtocol(protocol) {
|
|
2421
|
+
// RFC 8445 §8.1.2: once a pair is selected, the check list takes no more
|
|
2422
|
+
// Waiting pairs, so a candidate gathered later starts no check.
|
|
2423
|
+
if (this.nominated || this.checkListDone || this.state === "closed") {
|
|
2424
|
+
return;
|
|
2425
|
+
}
|
|
1542
2426
|
for (const remoteCandidate of this.remoteCandidates) {
|
|
1543
2427
|
this.tryPair(protocol, remoteCandidate);
|
|
1544
2428
|
}
|
|
@@ -1574,11 +2458,16 @@ class Connection {
|
|
|
1574
2458
|
}
|
|
1575
2459
|
}
|
|
1576
2460
|
}
|
|
1577
|
-
respondError(request, addr, protocol, errorCode
|
|
2461
|
+
respondError(request, addr, protocol, errorCode,
|
|
2462
|
+
/**
|
|
2463
|
+
* The password of the local ufrag the request is addressed to: a check
|
|
2464
|
+
* for a staged (provisional) generation is verified with its password.
|
|
2465
|
+
*/
|
|
2466
|
+
localPassword = this.localPassword) {
|
|
1578
2467
|
const response = new message_1.Message(request.messageMethod, const_1.classes.ERROR, request.transactionId);
|
|
1579
2468
|
response
|
|
1580
2469
|
.setAttribute("ERROR-CODE", errorCode)
|
|
1581
|
-
.addMessageIntegrity(Buffer.from(
|
|
2470
|
+
.addMessageIntegrity(Buffer.from(localPassword, "utf8"))
|
|
1582
2471
|
.addFingerprint();
|
|
1583
2472
|
protocol.sendStun(response, addr).catch((e) => {
|
|
1584
2473
|
log("sendStun error", e);
|
|
@@ -1593,4 +2482,7 @@ const decodeTxUsername = (txUsername) => {
|
|
|
1593
2482
|
const [remoteUsername, localUsername] = txUsername.split(":");
|
|
1594
2483
|
return { remoteUsername, localUsername };
|
|
1595
2484
|
};
|
|
2485
|
+
const socketTypeOf = (address) => ((0, net_1.isIPv4)(address) ? "udp4" : "udp6");
|
|
2486
|
+
/** Candidates carry no IPv6 zone id (e.g. `fe80::1%eth0`). */
|
|
2487
|
+
const stripZoneId = (address) => address.split("%")[0];
|
|
1596
2488
|
//# sourceMappingURL=ice.js.map
|