werift 0.26.0 → 0.28.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 +182 -8
- package/THIRD_PARTY_LICENSES_LIBWEBRTC.txt +58 -0
- package/lib/common/src/binary.d.ts +1 -3
- package/lib/common/src/binary.js +8 -6
- package/lib/common/src/binary.js.map +1 -1
- package/lib/common/src/binaryData.js +2 -1
- package/lib/common/src/binaryData.js.map +1 -1
- package/lib/common/src/event.d.ts +26 -0
- package/lib/common/src/event.js +87 -2
- package/lib/common/src/event.js.map +1 -1
- package/lib/common/src/log.js +5 -7
- package/lib/common/src/log.js.map +1 -1
- package/lib/common/src/network.d.ts +6 -1
- package/lib/common/src/network.js +8 -2
- package/lib/common/src/network.js.map +1 -1
- package/lib/common/src/transport.d.ts +12 -5
- package/lib/common/src/transport.js +13 -7
- package/lib/common/src/transport.js.map +1 -1
- package/lib/dtls/src/alert.d.ts +49 -0
- package/lib/dtls/src/alert.js +103 -0
- package/lib/dtls/src/alert.js.map +1 -0
- package/lib/dtls/src/client.js +15 -1
- package/lib/dtls/src/client.js.map +1 -1
- package/lib/dtls/src/context/cipher.d.ts +1 -1
- package/lib/dtls/src/context/cipher.js +6 -3
- package/lib/dtls/src/context/cipher.js.map +1 -1
- package/lib/dtls/src/context/dtls.d.ts +2 -0
- package/lib/dtls/src/context/dtls.js +11 -2
- package/lib/dtls/src/context/dtls.js.map +1 -1
- package/lib/dtls/src/context/transport.d.ts +17 -1
- package/lib/dtls/src/context/transport.js +40 -3
- 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 +8 -3
- package/lib/dtls/src/flight/client/flight5.js.map +1 -1
- package/lib/dtls/src/flight/flight.d.ts +6 -1
- package/lib/dtls/src/flight/flight.js +18 -5
- package/lib/dtls/src/flight/flight.js.map +1 -1
- package/lib/dtls/src/flight/server/flight4.js +4 -2
- package/lib/dtls/src/flight/server/flight4.js.map +1 -1
- package/lib/dtls/src/flight/server/flight6.js +6 -2
- package/lib/dtls/src/flight/server/flight6.js.map +1 -1
- package/lib/dtls/src/handshake/const.d.ts +17 -13
- package/lib/dtls/src/handshake/const.js +16 -14
- package/lib/dtls/src/handshake/const.js.map +1 -1
- package/lib/dtls/src/handshake/message/alert.js +4 -2
- package/lib/dtls/src/handshake/message/alert.js.map +1 -1
- package/lib/dtls/src/handshake/message/certificate.js +2 -1
- package/lib/dtls/src/handshake/message/certificate.js.map +1 -1
- package/lib/dtls/src/handshake/message/changeCipherSpec.js +2 -1
- package/lib/dtls/src/handshake/message/changeCipherSpec.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/certificateVerify.js +4 -2
- package/lib/dtls/src/handshake/message/client/certificateVerify.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/hello.js +14 -7
- package/lib/dtls/src/handshake/message/client/hello.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/keyExchange.js +2 -1
- package/lib/dtls/src/handshake/message/client/keyExchange.js.map +1 -1
- package/lib/dtls/src/handshake/message/finished.js +2 -1
- package/lib/dtls/src/handshake/message/finished.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/certificateRequest.js +6 -3
- package/lib/dtls/src/handshake/message/server/certificateRequest.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/hello.js +12 -6
- package/lib/dtls/src/handshake/message/server/hello.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/helloDone.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js +4 -2
- package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/keyExchange.js +16 -8
- package/lib/dtls/src/handshake/message/server/keyExchange.js.map +1 -1
- package/lib/dtls/src/handshake/random.d.ts +2 -2
- package/lib/dtls/src/handshake/random.js +5 -2
- package/lib/dtls/src/handshake/random.js.map +1 -1
- package/lib/dtls/src/index.d.ts +3 -1
- package/lib/dtls/src/index.js +10 -1
- package/lib/dtls/src/index.js.map +1 -1
- package/lib/dtls/src/record/const.d.ts +52 -33
- package/lib/dtls/src/record/const.js +51 -36
- package/lib/dtls/src/record/const.js.map +1 -1
- package/lib/dtls/src/record/message/fragment.js +12 -6
- package/lib/dtls/src/record/message/fragment.js.map +1 -1
- package/lib/dtls/src/record/message/header.js +10 -5
- package/lib/dtls/src/record/message/header.js.map +1 -1
- package/lib/dtls/src/record/message/plaintext.js +4 -2
- package/lib/dtls/src/record/message/plaintext.js.map +1 -1
- package/lib/dtls/src/record/receive.d.ts +6 -0
- package/lib/dtls/src/record/receive.js +50 -19
- package/lib/dtls/src/record/receive.js.map +1 -1
- package/lib/dtls/src/server.js +19 -1
- package/lib/dtls/src/server.js.map +1 -1
- package/lib/dtls/src/socket.d.ts +134 -2
- package/lib/dtls/src/socket.js +326 -8
- 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/candidateError.d.ts +155 -0
- package/lib/ice/src/candidateError.js +246 -0
- package/lib/ice/src/candidateError.js.map +1 -0
- package/lib/ice/src/candidateGatherer.d.ts +127 -0
- package/lib/ice/src/candidateGatherer.js +745 -0
- package/lib/ice/src/candidateGatherer.js.map +1 -0
- package/lib/ice/src/consent.d.ts +49 -0
- package/lib/ice/src/consent.js +258 -0
- package/lib/ice/src/consent.js.map +1 -0
- package/lib/ice/src/dns/lookup.d.ts +10 -1
- package/lib/ice/src/dns/lookup.js +42 -7
- package/lib/ice/src/dns/lookup.js.map +1 -1
- package/lib/ice/src/exceptions.d.ts +21 -5
- package/lib/ice/src/exceptions.js +58 -13
- package/lib/ice/src/exceptions.js.map +1 -1
- package/lib/ice/src/ice.d.ts +254 -58
- package/lib/ice/src/ice.js +979 -945
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/iceBase.d.ts +328 -14
- package/lib/ice/src/iceBase.js +254 -38
- package/lib/ice/src/iceBase.js.map +1 -1
- package/lib/ice/src/index.d.ts +1 -0
- package/lib/ice/src/index.js +1 -0
- package/lib/ice/src/index.js.map +1 -1
- package/lib/ice/src/internal/checkMessages.d.ts +41 -0
- package/lib/ice/src/internal/checkMessages.js +63 -0
- package/lib/ice/src/internal/checkMessages.js.map +1 -0
- package/lib/ice/src/internal/defaultRoute.d.ts +20 -0
- package/lib/ice/src/internal/defaultRoute.js +134 -0
- package/lib/ice/src/internal/defaultRoute.js.map +1 -0
- package/lib/ice/src/internal/hostInterfaces.d.ts +17 -0
- package/lib/ice/src/internal/hostInterfaces.js +77 -0
- package/lib/ice/src/internal/hostInterfaces.js.map +1 -0
- package/lib/ice/src/internal/hostPreference.d.ts +24 -0
- package/lib/ice/src/internal/hostPreference.js +38 -0
- package/lib/ice/src/internal/hostPreference.js.map +1 -0
- package/lib/ice/src/internal/resolveHostAddresses.d.ts +56 -8
- package/lib/ice/src/internal/resolveHostAddresses.js +127 -24
- package/lib/ice/src/internal/resolveHostAddresses.js.map +1 -1
- package/lib/ice/src/internal/selectAddresses.d.ts +27 -0
- package/lib/ice/src/internal/selectAddresses.js +37 -18
- package/lib/ice/src/internal/selectAddresses.js.map +1 -1
- package/lib/ice/src/nomination/regularNomination.d.ts +200 -0
- package/lib/ice/src/nomination/regularNomination.js +311 -0
- package/lib/ice/src/nomination/regularNomination.js.map +1 -0
- package/lib/ice/src/nomination/selectionReplacement.d.ts +138 -0
- package/lib/ice/src/nomination/selectionReplacement.js +371 -0
- package/lib/ice/src/nomination/selectionReplacement.js.map +1 -0
- package/lib/ice/src/provisional.d.ts +139 -0
- package/lib/ice/src/provisional.js +468 -0
- package/lib/ice/src/provisional.js.map +1 -0
- package/lib/ice/src/stun/protocol.d.ts +9 -2
- package/lib/ice/src/stun/protocol.js +16 -17
- package/lib/ice/src/stun/protocol.js.map +1 -1
- package/lib/ice/src/stun/tcpProtocol.d.ts +1 -1
- package/lib/ice/src/stun/tcpProtocol.js +7 -7
- package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
- package/lib/ice/src/stun/transaction.d.ts +30 -1
- package/lib/ice/src/stun/transaction.js +90 -19
- 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 +31 -10
- package/lib/ice/src/turn/protocol.js +127 -51
- package/lib/ice/src/turn/protocol.js.map +1 -1
- package/lib/ice/src/types/model.d.ts +16 -5
- package/lib/ice/src/types/model.js.map +1 -1
- package/lib/ice-server/src/stun/attributes.d.ts +2 -0
- package/lib/ice-server/src/stun/attributes.js +11 -1
- package/lib/ice-server/src/stun/attributes.js.map +1 -1
- package/lib/ice-server/src/stun/const.d.ts +44 -17
- package/lib/ice-server/src/stun/const.js +31 -19
- package/lib/ice-server/src/stun/const.js.map +1 -1
- package/lib/ice-server/src/stun/message.d.ts +29 -4
- package/lib/ice-server/src/stun/message.js +115 -24
- package/lib/ice-server/src/stun/message.js.map +1 -1
- package/lib/index.mjs +35121 -22337
- package/lib/nonstandard/index.mjs +3169 -1399
- package/lib/polyfill/dom.mjs +24650 -12365
- package/lib/polyfill/index.mjs +24650 -12365
- package/lib/rtp/src/codec/assertPayload.d.ts +4 -0
- package/lib/rtp/src/codec/assertPayload.js +12 -0
- package/lib/rtp/src/codec/assertPayload.js.map +1 -0
- package/lib/rtp/src/codec/av1.js +2 -0
- package/lib/rtp/src/codec/av1.js.map +1 -1
- package/lib/rtp/src/codec/h264.js +35 -43
- package/lib/rtp/src/codec/h264.js.map +1 -1
- package/lib/rtp/src/codec/vp8.js +11 -5
- package/lib/rtp/src/codec/vp8.js.map +1 -1
- package/lib/rtp/src/codec/vp9.js +12 -0
- package/lib/rtp/src/codec/vp9.js.map +1 -1
- package/lib/rtp/src/extra/container/mp4/container.js +2 -1
- package/lib/rtp/src/extra/container/mp4/container.js.map +1 -1
- package/lib/rtp/src/extra/container/mp4/exp-golomb.js +2 -1
- package/lib/rtp/src/extra/container/mp4/exp-golomb.js.map +1 -1
- package/lib/rtp/src/extra/container/mp4/h264.d.ts +21 -17
- package/lib/rtp/src/extra/container/mp4/h264.js +26 -24
- package/lib/rtp/src/extra/container/mp4/h264.js.map +1 -1
- package/lib/rtp/src/extra/container/ogg/index.d.ts +1 -0
- package/lib/rtp/src/extra/container/ogg/index.js +1 -0
- package/lib/rtp/src/extra/container/ogg/index.js.map +1 -1
- package/lib/rtp/src/extra/container/ogg/writer.d.ts +90 -0
- package/lib/rtp/src/extra/container/ogg/writer.js +300 -0
- package/lib/rtp/src/extra/container/ogg/writer.js.map +1 -0
- package/lib/rtp/src/extra/container/webm/ebml/ebml.js +6 -3
- package/lib/rtp/src/extra/container/webm/ebml/ebml.js.map +1 -1
- package/lib/rtp/src/extra/processor/depacketizer.d.ts +5 -0
- package/lib/rtp/src/extra/processor/depacketizer.js +28 -2
- package/lib/rtp/src/extra/processor/depacketizer.js.map +1 -1
- package/lib/rtp/src/extra/processor/dtx.js +4 -2
- package/lib/rtp/src/extra/processor/dtx.js.map +1 -1
- package/lib/rtp/src/extra/processor/index.d.ts +2 -0
- package/lib/rtp/src/extra/processor/index.js +2 -0
- package/lib/rtp/src/extra/processor/index.js.map +1 -1
- package/lib/rtp/src/extra/processor/jitterBuffer.d.ts +29 -6
- package/lib/rtp/src/extra/processor/jitterBuffer.js +101 -111
- package/lib/rtp/src/extra/processor/jitterBuffer.js.map +1 -1
- package/lib/rtp/src/extra/processor/jitterBufferTransformer.js +2 -1
- package/lib/rtp/src/extra/processor/jitterBufferTransformer.js.map +1 -1
- package/lib/rtp/src/extra/processor/lipsync.d.ts +63 -0
- package/lib/rtp/src/extra/processor/lipsync.js +202 -51
- package/lib/rtp/src/extra/processor/lipsync.js.map +1 -1
- package/lib/rtp/src/extra/processor/mp4.d.ts +0 -6
- package/lib/rtp/src/extra/processor/mp4.js +6 -3
- package/lib/rtp/src/extra/processor/mp4.js.map +1 -1
- package/lib/rtp/src/extra/processor/mute.js +4 -2
- package/lib/rtp/src/extra/processor/mute.js.map +1 -1
- package/lib/rtp/src/extra/processor/nack.js +4 -2
- package/lib/rtp/src/extra/processor/nack.js.map +1 -1
- package/lib/rtp/src/extra/processor/ntpTime.js +4 -6
- package/lib/rtp/src/extra/processor/ntpTime.js.map +1 -1
- package/lib/rtp/src/extra/processor/ogg.d.ts +72 -0
- package/lib/rtp/src/extra/processor/ogg.js +221 -0
- package/lib/rtp/src/extra/processor/ogg.js.map +1 -0
- package/lib/rtp/src/extra/processor/oggCallback.d.ts +21 -0
- package/lib/rtp/src/extra/processor/oggCallback.js +97 -0
- package/lib/rtp/src/extra/processor/oggCallback.js.map +1 -0
- package/lib/rtp/src/extra/processor/rtpCallback.js +2 -1
- package/lib/rtp/src/extra/processor/rtpCallback.js.map +1 -1
- package/lib/rtp/src/extra/processor/rtpStream.js +2 -1
- package/lib/rtp/src/extra/processor/rtpStream.js.map +1 -1
- package/lib/rtp/src/extra/processor/rtpTime.js +2 -1
- package/lib/rtp/src/extra/processor/rtpTime.js.map +1 -1
- package/lib/rtp/src/extra/processor/webm.js +14 -7
- package/lib/rtp/src/extra/processor/webm.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
- package/lib/rtp/src/index.d.ts +8 -0
- package/lib/rtp/src/index.js +8 -0
- package/lib/rtp/src/index.js.map +1 -1
- package/lib/rtp/src/rtcp/psfb/fullIntraRequest.d.ts +4 -0
- package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js +4 -0
- package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js.map +1 -1
- package/lib/rtp/src/rtcp/rtcp.js +8 -4
- package/lib/rtp/src/rtcp/rtcp.js.map +1 -1
- package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.d.ts +58 -0
- package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js +143 -0
- package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js.map +1 -0
- package/lib/rtp/src/rtcp/rtpfb/twcc.d.ts +35 -13
- package/lib/rtp/src/rtcp/rtpfb/twcc.js +132 -54
- package/lib/rtp/src/rtcp/rtpfb/twcc.js.map +1 -1
- package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.d.ts +13 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js +29 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js.map +1 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.d.ts +41 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js +89 -0
- package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js.map +1 -0
- package/lib/rtp/src/rtcp/sr.js +1 -0
- package/lib/rtp/src/rtcp/sr.js.map +1 -1
- package/lib/rtp/src/rtp/continuity.d.ts +49 -0
- package/lib/rtp/src/rtp/continuity.js +120 -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/rtp/timelineRewriter.d.ts +178 -0
- package/lib/rtp/src/rtp/timelineRewriter.js +417 -0
- package/lib/rtp/src/rtp/timelineRewriter.js.map +1 -0
- package/lib/rtp/src/srtp/cipher/ctr.js +4 -2
- package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
- package/lib/rtp/src/srtp/cipher/index.js +8 -4
- package/lib/rtp/src/srtp/cipher/index.js.map +1 -1
- package/lib/rtp/src/srtp/context/context.js +6 -3
- package/lib/rtp/src/srtp/context/context.js.map +1 -1
- package/lib/rtp/src/srtp/context/srtcp.d.ts +1 -1
- package/lib/rtp/src/srtp/context/srtcp.js +33 -0
- package/lib/rtp/src/srtp/context/srtcp.js.map +1 -1
- package/lib/rtp/src/srtp/context/srtp.d.ts +1 -1
- package/lib/rtp/src/srtp/context/srtp.js +34 -10
- package/lib/rtp/src/srtp/context/srtp.js.map +1 -1
- package/lib/rtp/src/srtp/error.d.ts +8 -0
- package/lib/rtp/src/srtp/error.js +13 -1
- package/lib/rtp/src/srtp/error.js.map +1 -1
- package/lib/rtp/src/srtp/packet.js +4 -1
- package/lib/rtp/src/srtp/packet.js.map +1 -1
- package/lib/rtp/src/srtp/replay.d.ts +24 -0
- package/lib/rtp/src/srtp/replay.js +75 -0
- package/lib/rtp/src/srtp/replay.js.map +1 -0
- package/lib/rtp/src/srtp/session.js +2 -1
- package/lib/rtp/src/srtp/session.js.map +1 -1
- package/lib/rtp/src/srtp/srtcp.js +2 -1
- package/lib/rtp/src/srtp/srtcp.js.map +1 -1
- package/lib/rtp/src/srtp/srtp.js +2 -1
- package/lib/rtp/src/srtp/srtp.js.map +1 -1
- package/lib/rtp/src/util.js +2 -1
- package/lib/rtp/src/util.js.map +1 -1
- package/lib/sctp/src/chunk.d.ts +5 -0
- package/lib/sctp/src/chunk.js +31 -8
- package/lib/sctp/src/chunk.js.map +1 -1
- package/lib/sctp/src/const.d.ts +25 -17
- package/lib/sctp/src/const.js +23 -19
- package/lib/sctp/src/const.js.map +1 -1
- package/lib/sctp/src/param.d.ts +6 -2
- package/lib/sctp/src/param.js +22 -8
- package/lib/sctp/src/param.js.map +1 -1
- package/lib/sctp/src/sctp.d.ts +85 -0
- package/lib/sctp/src/sctp.js +707 -126
- 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/compatibilityOptions.d.ts +33 -0
- package/lib/webrtc/src/api/compatibilityOptions.js +33 -0
- package/lib/webrtc/src/api/compatibilityOptions.js.map +1 -0
- package/lib/webrtc/src/api/peerConfig.d.ts +385 -28
- package/lib/webrtc/src/api/peerConfig.js +121 -14
- package/lib/webrtc/src/api/peerConfig.js.map +1 -1
- package/lib/webrtc/src/api/peerConnectionEvents.d.ts +77 -1
- package/lib/webrtc/src/api/peerConnectionEvents.js +105 -1
- package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -1
- package/lib/webrtc/src/dataChannel.d.ts +10 -0
- package/lib/webrtc/src/dataChannel.js +24 -4
- package/lib/webrtc/src/dataChannel.js.map +1 -1
- package/lib/webrtc/src/helper.d.ts +8 -0
- package/lib/webrtc/src/helper.js +40 -4
- package/lib/webrtc/src/helper.js.map +1 -1
- package/lib/webrtc/src/media/codecCompatibility.d.ts +87 -1
- package/lib/webrtc/src/media/codecCompatibility.js +338 -12
- package/lib/webrtc/src/media/codecCompatibility.js.map +1 -1
- package/lib/webrtc/src/media/index.d.ts +10 -0
- package/lib/webrtc/src/media/index.js +70 -0
- package/lib/webrtc/src/media/index.js.map +1 -1
- package/lib/webrtc/src/media/receiver/nack.d.ts +43 -10
- package/lib/webrtc/src/media/receiver/nack.js +246 -88
- 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 +241 -40
- package/lib/webrtc/src/media/router.js +676 -205
- package/lib/webrtc/src/media/router.js.map +1 -1
- package/lib/webrtc/src/media/routing/pendingRoutes.d.ts +26 -0
- package/lib/webrtc/src/media/routing/pendingRoutes.js +48 -0
- package/lib/webrtc/src/media/routing/pendingRoutes.js.map +1 -0
- package/lib/webrtc/src/media/routing/ridRouting.d.ts +37 -0
- package/lib/webrtc/src/media/routing/ridRouting.js +74 -0
- package/lib/webrtc/src/media/routing/ridRouting.js.map +1 -0
- package/lib/webrtc/src/media/routing/routeTable.d.ts +60 -0
- package/lib/webrtc/src/media/routing/routeTable.js +95 -0
- package/lib/webrtc/src/media/routing/routeTable.js.map +1 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.d.ts +34 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.js +165 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.js.map +1 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.d.ts +55 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.js +117 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.js.map +1 -0
- package/lib/webrtc/src/media/rtpReceiver.d.ts +252 -2
- package/lib/webrtc/src/media/rtpReceiver.js +833 -44
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpSender.d.ts +191 -70
- package/lib/webrtc/src/media/rtpSender.js +631 -448
- package/lib/webrtc/src/media/rtpSender.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +19 -3
- package/lib/webrtc/src/media/rtpTransceiver.js +74 -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 -33
- package/lib/webrtc/src/media/sender/senderBWE.js +5 -154
- package/lib/webrtc/src/media/sender/senderBWE.js.map +1 -1
- package/lib/webrtc/src/media/sender/senderReportHistory.d.ts +51 -0
- package/lib/webrtc/src/media/sender/senderReportHistory.js +111 -0
- package/lib/webrtc/src/media/sender/senderReportHistory.js.map +1 -0
- package/lib/webrtc/src/media/sender/senderStats.d.ts +101 -0
- package/lib/webrtc/src/media/sender/senderStats.js +317 -0
- package/lib/webrtc/src/media/sender/senderStats.js.map +1 -0
- package/lib/webrtc/src/media/track.d.ts +29 -2
- package/lib/webrtc/src/media/track.js +32 -5
- package/lib/webrtc/src/media/track.js.map +1 -1
- package/lib/webrtc/src/negotiation/bundleTopology.d.ts +1 -5
- package/lib/webrtc/src/negotiation/bundleTopology.js +15 -11
- package/lib/webrtc/src/negotiation/bundleTopology.js.map +1 -1
- package/lib/webrtc/src/negotiation/descriptionValidation.js +12 -6
- package/lib/webrtc/src/negotiation/descriptionValidation.js.map +1 -1
- package/lib/webrtc/src/negotiation/negotiationNeeded.js +2 -1
- package/lib/webrtc/src/negotiation/negotiationNeeded.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.js +10 -5
- package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +24 -7
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js +67 -27
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -1
- package/lib/webrtc/src/negotiation/transceiverPairing.d.ts +1 -0
- package/lib/webrtc/src/negotiation/transceiverPairing.js +62 -0
- package/lib/webrtc/src/negotiation/transceiverPairing.js.map +1 -0
- package/lib/webrtc/src/negotiation/transportActivation.d.ts +8 -1
- package/lib/webrtc/src/negotiation/transportActivation.js +40 -8
- package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -1
- package/lib/webrtc/src/negotiationTransaction.d.ts +43 -5
- package/lib/webrtc/src/negotiationTransaction.js +129 -13
- package/lib/webrtc/src/negotiationTransaction.js.map +1 -1
- package/lib/webrtc/src/nonstandard/dummyMedia.js +2 -1
- package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
- package/lib/webrtc/src/nonstandard/navigator.js +4 -3
- package/lib/webrtc/src/nonstandard/navigator.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/index.d.ts +32 -8
- package/lib/webrtc/src/nonstandard/recorder/index.js +81 -20
- package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/index.d.ts +9 -7
- package/lib/webrtc/src/nonstandard/recorder/writer/index.js +2 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/ogg.d.ts +32 -0
- package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js +185 -0
- package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js.map +1 -0
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +8 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia.js +2 -1
- package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +108 -6
- package/lib/webrtc/src/peerConnection.js +357 -36
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/polyfill/globals.d.ts +2 -1
- package/lib/webrtc/src/polyfill/globals.js.map +1 -1
- package/lib/webrtc/src/polyfill/install.js +2 -0
- 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/sctpManager.d.ts +46 -14
- package/lib/webrtc/src/sctpManager.js +92 -25
- package/lib/webrtc/src/sctpManager.js.map +1 -1
- package/lib/webrtc/src/sdp.d.ts +69 -0
- package/lib/webrtc/src/sdp.js +151 -20
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/sdpManager.d.ts +85 -4
- package/lib/webrtc/src/sdpManager.js +214 -14
- package/lib/webrtc/src/sdpManager.js.map +1 -1
- package/lib/webrtc/src/secureTransportManager.d.ts +89 -4
- package/lib/webrtc/src/secureTransportManager.js +184 -26
- package/lib/webrtc/src/secureTransportManager.js.map +1 -1
- package/lib/webrtc/src/transceiverManager.d.ts +82 -4
- package/lib/webrtc/src/transceiverManager.js +239 -41
- package/lib/webrtc/src/transceiverManager.js.map +1 -1
- package/lib/webrtc/src/transport/dtls.d.ts +147 -1
- package/lib/webrtc/src/transport/dtls.js +446 -50
- package/lib/webrtc/src/transport/dtls.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +71 -90
- package/lib/webrtc/src/transport/ice.js +250 -42
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/lib/webrtc/src/transport/sctp.d.ts +25 -0
- package/lib/webrtc/src/transport/sctp.js +153 -22
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/lib/webrtc/src/utils.d.ts +69 -3
- package/lib/webrtc/src/utils.js +105 -16
- package/lib/webrtc/src/utils.js.map +1 -1
- package/package.json +9 -6
package/lib/ice/src/iceBase.js
CHANGED
|
@@ -5,10 +5,18 @@ exports.consentResponseTimeoutMs = consentResponseTimeoutMs;
|
|
|
5
5
|
exports.validateRemoteCandidate = validateRemoteCandidate;
|
|
6
6
|
exports.sortCandidatePairs = sortCandidatePairs;
|
|
7
7
|
exports.candidatePairPriority = candidatePairPriority;
|
|
8
|
+
exports.compareCandidatePairPriority = compareCandidatePairPriority;
|
|
9
|
+
exports.queryServerReflexiveCandidate = queryServerReflexiveCandidate;
|
|
8
10
|
exports.serverReflexiveCandidate = serverReflexiveCandidate;
|
|
9
11
|
exports.validateAddress = validateAddress;
|
|
12
|
+
exports.normalizeIceServerOptions = normalizeIceServerOptions;
|
|
13
|
+
exports.mergeIceServerOptions = mergeIceServerOptions;
|
|
14
|
+
exports.isRelayOnlyGathering = isRelayOnlyGathering;
|
|
15
|
+
exports.hasTurnServer = hasTurnServer;
|
|
16
|
+
exports.isCandidateAllowedByGatherOptions = isCandidateAllowedByGatherOptions;
|
|
10
17
|
const crypto_1 = require("crypto");
|
|
11
18
|
const candidate_1 = require("./candidate");
|
|
19
|
+
const candidateError_1 = require("./candidateError");
|
|
12
20
|
const common_1 = require("./imports/common");
|
|
13
21
|
const const_1 = require("./stun/const");
|
|
14
22
|
const message_1 = require("./stun/message");
|
|
@@ -32,19 +40,19 @@ class CandidatePair {
|
|
|
32
40
|
enumerable: true,
|
|
33
41
|
configurable: true,
|
|
34
42
|
writable: true,
|
|
35
|
-
value:
|
|
43
|
+
value: void 0
|
|
36
44
|
});
|
|
37
45
|
Object.defineProperty(this, "remoteCandidate", {
|
|
38
46
|
enumerable: true,
|
|
39
47
|
configurable: true,
|
|
40
48
|
writable: true,
|
|
41
|
-
value:
|
|
49
|
+
value: void 0
|
|
42
50
|
});
|
|
43
51
|
Object.defineProperty(this, "iceControlling", {
|
|
44
52
|
enumerable: true,
|
|
45
53
|
configurable: true,
|
|
46
54
|
writable: true,
|
|
47
|
-
value:
|
|
55
|
+
value: void 0
|
|
48
56
|
});
|
|
49
57
|
Object.defineProperty(this, "id", {
|
|
50
58
|
enumerable: true,
|
|
@@ -70,12 +78,34 @@ class CandidatePair {
|
|
|
70
78
|
writable: true,
|
|
71
79
|
value: false
|
|
72
80
|
});
|
|
81
|
+
/**
|
|
82
|
+
* The largest nomination the peer sent for this pair while this agent was
|
|
83
|
+
* controlled: the NOMINATION attribute's value (renomination), or 1 for
|
|
84
|
+
* USE-CANDIDATE. The controlled agent selects the nominated pair with the
|
|
85
|
+
* largest value, the higher-priority one between equal values.
|
|
86
|
+
*/
|
|
87
|
+
Object.defineProperty(this, "remoteNomination", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
configurable: true,
|
|
90
|
+
writable: true,
|
|
91
|
+
value: 0
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* The NOMINATION value this agent (controlling, renomination) sent for the
|
|
95
|
+
* pair and the peer answered; 0 when it did not renominate the pair.
|
|
96
|
+
*/
|
|
97
|
+
Object.defineProperty(this, "nomination", {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
configurable: true,
|
|
100
|
+
writable: true,
|
|
101
|
+
value: 0
|
|
102
|
+
});
|
|
73
103
|
// 5.7.4. Computing States
|
|
74
104
|
Object.defineProperty(this, "_state", {
|
|
75
105
|
enumerable: true,
|
|
76
106
|
configurable: true,
|
|
77
107
|
writable: true,
|
|
78
|
-
value: CandidatePairState.FROZEN
|
|
108
|
+
value: exports.CandidatePairState.FROZEN
|
|
79
109
|
});
|
|
80
110
|
// Statistics tracking
|
|
81
111
|
Object.defineProperty(this, "packetsSent", {
|
|
@@ -168,6 +198,9 @@ class CandidatePair {
|
|
|
168
198
|
writable: true,
|
|
169
199
|
value: new Set()
|
|
170
200
|
});
|
|
201
|
+
this.protocol = protocol;
|
|
202
|
+
this.remoteCandidate = remoteCandidate;
|
|
203
|
+
this.iceControlling = iceControlling;
|
|
171
204
|
}
|
|
172
205
|
updateState(state) {
|
|
173
206
|
this._state = state;
|
|
@@ -233,14 +266,16 @@ function consentResponseTimeoutMs(rttSeconds) {
|
|
|
233
266
|
}
|
|
234
267
|
return Math.max(exports.CONSENT_RESPONSE_TIMEOUT_MIN, Math.round(rttSeconds * 1000 * 2 + 200));
|
|
235
268
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
269
|
+
/**
|
|
270
|
+
* @enum
|
|
271
|
+
*/
|
|
272
|
+
exports.CandidatePairState = {
|
|
273
|
+
FROZEN: 0,
|
|
274
|
+
WAITING: 1,
|
|
275
|
+
IN_PROGRESS: 2,
|
|
276
|
+
SUCCEEDED: 3,
|
|
277
|
+
FAILED: 4,
|
|
278
|
+
};
|
|
244
279
|
exports.defaultOptions = {
|
|
245
280
|
iceLite: false,
|
|
246
281
|
useTcp: false,
|
|
@@ -257,39 +292,66 @@ function validateRemoteCandidate(candidate) {
|
|
|
257
292
|
return candidate;
|
|
258
293
|
}
|
|
259
294
|
function sortCandidatePairs(pairs, iceControlling) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
295
|
+
// Highest priority first; pairs of equal priority keep their order.
|
|
296
|
+
return pairs.sort((a, b) => compareCandidatePairPriority(b.localCandidate, b.remoteCandidate, a.localCandidate, a.remoteCandidate, iceControlling));
|
|
297
|
+
}
|
|
298
|
+
/** RFC 8445 §6.1.2.3: G is the controlling agent's candidate priority, D the controlled one's. */
|
|
299
|
+
function pairPriorityTerms(local, remote, iceControlling) {
|
|
300
|
+
const G = iceControlling ? local.priority : remote.priority;
|
|
301
|
+
const D = iceControlling ? remote.priority : local.priority;
|
|
302
|
+
return { min: Math.min(G, D), max: Math.max(G, D), tie: G > D ? 1 : 0 };
|
|
264
303
|
}
|
|
265
304
|
// 5.7.2. Computing Pair Priority and Ordering Pairs
|
|
305
|
+
/**
|
|
306
|
+
* `2^32 * MIN(G,D) + 2 * MAX(G,D) + (G > D ? 1 : 0)` (RFC 8445 §6.1.2.3).
|
|
307
|
+
* The value can exceed `Number.MAX_SAFE_INTEGER`, so it is approximate;
|
|
308
|
+
* order pairs with `compareCandidatePairPriority`, which is exact.
|
|
309
|
+
*/
|
|
266
310
|
function candidatePairPriority(local, remote, iceControlling) {
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
return (1 << 32) * Math.min(G, D) + 2 * Math.max(G, D) + (G > D ? 1 : 0);
|
|
311
|
+
const { min, max, tie } = pairPriorityTerms(local, remote, iceControlling);
|
|
312
|
+
return 2 ** 32 * min + 2 * max + tie;
|
|
270
313
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
314
|
+
/**
|
|
315
|
+
* Exact comparison of two pair priorities (RFC 8445 §6.1.2.3): negative
|
|
316
|
+
* when pair `a` has the lower priority, positive when the higher, 0 when equal.
|
|
317
|
+
*/
|
|
318
|
+
function compareCandidatePairPriority(aLocal, aRemote, bLocal, bRemote, iceControlling) {
|
|
319
|
+
const a = pairPriorityTerms(aLocal, aRemote, iceControlling);
|
|
320
|
+
const b = pairPriorityTerms(bLocal, bRemote, iceControlling);
|
|
321
|
+
return a.min - b.min || a.max - b.max || a.tie - b.tie;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Query `stunServer` from `protocol` for a server-reflexive candidate.
|
|
325
|
+
* Unlike {@link serverReflexiveCandidate} it rejects with the reason of a
|
|
326
|
+
* failure. `base` is used for wildcard sockets that advertise no host
|
|
327
|
+
* candidate themselves.
|
|
328
|
+
*/
|
|
329
|
+
async function queryServerReflexiveCandidate(protocol, stunServer, base) {
|
|
330
|
+
const localCandidate = base ?? protocol.localCandidate;
|
|
331
|
+
if (!localCandidate) {
|
|
332
|
+
throw new Error("protocol has no local candidate");
|
|
333
|
+
}
|
|
276
334
|
const request = new message_1.Message(const_1.methods.BINDING, const_1.classes.REQUEST);
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
throw new Error("not exist");
|
|
282
|
-
}
|
|
283
|
-
const candidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("srflx", localCandidate.transport, localCandidate.host), localCandidate.component, localCandidate.transport, (0, candidate_1.candidatePriority)("srflx", {
|
|
284
|
-
transport: localCandidate.transport,
|
|
285
|
-
tcptype: localCandidate.tcptype,
|
|
286
|
-
}), response.getAttributeValue("XOR-MAPPED-ADDRESS")[0], response.getAttributeValue("XOR-MAPPED-ADDRESS")[1], "srflx", localCandidate.host, localCandidate.port, localCandidate.tcptype);
|
|
287
|
-
return candidate;
|
|
335
|
+
const [response] = await protocol.request(request, stunServer);
|
|
336
|
+
const mapped = response.getAttributeValue("XOR-MAPPED-ADDRESS");
|
|
337
|
+
if (!mapped) {
|
|
338
|
+
throw new candidateError_1.MissingMappedAddressError(stunServer);
|
|
288
339
|
}
|
|
289
|
-
|
|
290
|
-
|
|
340
|
+
return new candidate_1.Candidate((0, candidate_1.candidateFoundation)("srflx", localCandidate.transport, localCandidate.host), localCandidate.component, localCandidate.transport, (0, candidate_1.candidatePriority)("srflx", {
|
|
341
|
+
transport: localCandidate.transport,
|
|
342
|
+
tcptype: localCandidate.tcptype,
|
|
343
|
+
}), mapped[0], mapped[1], "srflx", localCandidate.host, localCandidate.port, localCandidate.tcptype);
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Query a STUN server for a server-reflexive candidate. This compatibility
|
|
347
|
+
* helper resolves `undefined` on failure; use
|
|
348
|
+
* {@link queryServerReflexiveCandidate} when the failure reason is needed.
|
|
349
|
+
*/
|
|
350
|
+
async function serverReflexiveCandidate(protocol, stunServer, base) {
|
|
351
|
+
return queryServerReflexiveCandidate(protocol, stunServer, base).catch((error) => {
|
|
291
352
|
log("error serverReflexiveCandidate", error);
|
|
292
|
-
|
|
353
|
+
return undefined;
|
|
354
|
+
});
|
|
293
355
|
}
|
|
294
356
|
function validateAddress(addr) {
|
|
295
357
|
if (addr && Number.isNaN(addr[1])) {
|
|
@@ -297,4 +359,158 @@ function validateAddress(addr) {
|
|
|
297
359
|
}
|
|
298
360
|
return addr;
|
|
299
361
|
}
|
|
362
|
+
/** A STUN/TURN server address: validated (see {@link validateAddress}) or undefined. */
|
|
363
|
+
function validServerAddress(addr) {
|
|
364
|
+
if (!Array.isArray(addr))
|
|
365
|
+
return undefined;
|
|
366
|
+
const validated = validateAddress(addr);
|
|
367
|
+
if (!validated)
|
|
368
|
+
return undefined;
|
|
369
|
+
const [host, port] = validated;
|
|
370
|
+
if (typeof host !== "string" || host === "")
|
|
371
|
+
return undefined;
|
|
372
|
+
if (typeof port !== "number" || !Number.isFinite(port))
|
|
373
|
+
return undefined;
|
|
374
|
+
return validated;
|
|
375
|
+
}
|
|
376
|
+
const sameAddress = (a, b) => a[0] === b[0] && a[1] === b[1];
|
|
377
|
+
/**
|
|
378
|
+
* The STUN and TURN servers `options` configure, the one place the singular
|
|
379
|
+
* (deprecated) and plural fields are merged:
|
|
380
|
+
*
|
|
381
|
+
* - order: the singular server first, then the plural list in its order;
|
|
382
|
+
* - duplicates (the same STUN address; the same TURN address, transport and
|
|
383
|
+
* credential) are kept once, at their first position;
|
|
384
|
+
* - an invalid address (see {@link validateAddress}) is dropped, and so is a
|
|
385
|
+
* TURN server without username or password (it cannot allocate);
|
|
386
|
+
* - a TURN transport left unset is "udp";
|
|
387
|
+
* - the `urls` of merged TURN duplicates are merged (in order, once each).
|
|
388
|
+
*
|
|
389
|
+
* The built-in default STUN server is not added here; Connection falls back
|
|
390
|
+
* to it when the result has no STUN server.
|
|
391
|
+
*/
|
|
392
|
+
function normalizeIceServerOptions(options) {
|
|
393
|
+
const stunServers = [];
|
|
394
|
+
for (const server of [options.stunServer, ...(options.stunServers ?? [])]) {
|
|
395
|
+
if (server === undefined)
|
|
396
|
+
continue;
|
|
397
|
+
const address = validServerAddress(server);
|
|
398
|
+
if (!address) {
|
|
399
|
+
log("invalid STUN server ignored", server);
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
if (stunServers.some((existing) => sameAddress(existing, address))) {
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
stunServers.push(address);
|
|
406
|
+
}
|
|
407
|
+
const turnServers = [];
|
|
408
|
+
const configured = [
|
|
409
|
+
...(options.turnServer !== undefined
|
|
410
|
+
? [
|
|
411
|
+
{
|
|
412
|
+
address: options.turnServer,
|
|
413
|
+
username: options.turnUsername,
|
|
414
|
+
password: options.turnPassword,
|
|
415
|
+
transport: options.turnTransport,
|
|
416
|
+
},
|
|
417
|
+
]
|
|
418
|
+
: []),
|
|
419
|
+
...(options.turnServers ?? []),
|
|
420
|
+
];
|
|
421
|
+
for (const server of configured) {
|
|
422
|
+
const address = validServerAddress(server?.address);
|
|
423
|
+
if (!address) {
|
|
424
|
+
log("invalid TURN server ignored", server?.address);
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
const { username, password } = server;
|
|
428
|
+
if (!username || !password) {
|
|
429
|
+
log("TURN server without username / credential ignored", address);
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
const urls = Array.isArray(server.urls)
|
|
433
|
+
? server.urls.filter((url) => typeof url === "string")
|
|
434
|
+
: undefined;
|
|
435
|
+
const entry = {
|
|
436
|
+
address,
|
|
437
|
+
username,
|
|
438
|
+
password,
|
|
439
|
+
transport: server.transport ?? "udp",
|
|
440
|
+
...(urls ? { urls: [...new Set(urls)] } : {}),
|
|
441
|
+
};
|
|
442
|
+
const existing = turnServers.find((known) => sameAddress(known.address, entry.address) &&
|
|
443
|
+
known.transport === entry.transport &&
|
|
444
|
+
known.username === entry.username &&
|
|
445
|
+
known.password === entry.password);
|
|
446
|
+
if (existing) {
|
|
447
|
+
// One allocation serves both: it answers to every name of them.
|
|
448
|
+
if (entry.urls) {
|
|
449
|
+
existing.urls = [...new Set([...(existing.urls ?? []), ...entry.urls])];
|
|
450
|
+
}
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
turnServers.push(entry);
|
|
454
|
+
}
|
|
455
|
+
return { stunServers, turnServers };
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* `current` with an ICE server update applied (Connection.setIceServers): the
|
|
459
|
+
* STUN/TURN fields, singular and plural, are replaced, an undefined one
|
|
460
|
+
* included, so a STUN-only update cannot leave a previous TURN
|
|
461
|
+
* host/credential behind; forceTurn and useTcp change only when given.
|
|
462
|
+
*/
|
|
463
|
+
function mergeIceServerOptions(current, update) {
|
|
464
|
+
return {
|
|
465
|
+
...current,
|
|
466
|
+
stunServer: update.stunServer,
|
|
467
|
+
stunServers: update.stunServers,
|
|
468
|
+
stunServerUrls: update.stunServerUrls,
|
|
469
|
+
turnServer: update.turnServer,
|
|
470
|
+
turnServers: update.turnServers,
|
|
471
|
+
turnUsername: update.turnUsername,
|
|
472
|
+
turnPassword: update.turnPassword,
|
|
473
|
+
turnTransport: update.turnTransport,
|
|
474
|
+
turnTlsOptions: update.turnTlsOptions,
|
|
475
|
+
turnUdpFamily: update.turnUdpFamily,
|
|
476
|
+
forceTurn: update.forceTurn ?? current.forceTurn,
|
|
477
|
+
useTcp: update.useTcp ?? current.useTcp,
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Whether a generation gathered with `options` is relay-only: forceTurn (the
|
|
482
|
+
* "relay" ICE transport policy). The policy holds whatever the TURN settings
|
|
483
|
+
* are: without a usable TURN server / credential (or for an ICE-lite agent,
|
|
484
|
+
* which gathers no relay candidate) the generation has no candidate at all
|
|
485
|
+
* rather than falling back to host / server-reflexive ones, so the local and
|
|
486
|
+
* public addresses are neither advertised nor used for checks.
|
|
487
|
+
*/
|
|
488
|
+
function isRelayOnlyGathering(options) {
|
|
489
|
+
return !!options.forceTurn;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Whether `options` carry at least one usable TURN server with its
|
|
493
|
+
* credential, the ones a gathering with them allocates relay candidates from.
|
|
494
|
+
*/
|
|
495
|
+
function hasTurnServer(options) {
|
|
496
|
+
return normalizeIceServerOptions(options).turnServers.length > 0;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Whether `candidate`, kept from an earlier generation (an ICE restart keeps
|
|
500
|
+
* the sockets), may be advertised and paired in a generation gathered with
|
|
501
|
+
* `options`. A fresh gathering with the same options would not have produced
|
|
502
|
+
* a host / server-reflexive candidate for a relay-only policy, a TCP host
|
|
503
|
+
* candidate without useTcp, nor a relay candidate without a TURN server;
|
|
504
|
+
* the kept ones are held back the same way.
|
|
505
|
+
*/
|
|
506
|
+
function isCandidateAllowedByGatherOptions(candidate, options) {
|
|
507
|
+
if (candidate.type === "relay")
|
|
508
|
+
return hasTurnServer(options);
|
|
509
|
+
if (isRelayOnlyGathering(options))
|
|
510
|
+
return false;
|
|
511
|
+
if (candidate.transport.toLowerCase() === "tcp" && !options.useTcp) {
|
|
512
|
+
return false;
|
|
513
|
+
}
|
|
514
|
+
return true;
|
|
515
|
+
}
|
|
300
516
|
//# sourceMappingURL=iceBase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iceBase.js","sourceRoot":"","sources":["../../../../ice/src/iceBase.ts"],"names":[],"mappings":";;;AA2OA,4DAYC;AA+FD,0DASC;AAED,gDAsBC;AAGD,sDAQC;AAED,4DA0CC;AAED,0CAKC;AArbD,mCAAoC;AACpC,2CAAgF;AAGhF,6CAM0B;AAC1B,wCAAgD;AAChD,4CAAyC;AAGzC,MAAM,GAAG,GAAG,IAAA,cAAK,EAAC,4CAA4C,CAAC,CAAC;AAsGhE,MAAa,aAAa;IAOxB,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAmBD,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,IAAI;QACN,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;YAC5B,cAAc,EAAE,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE;YAC3C,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE;SAC9C,CAAC;IACJ,CAAC;IAED,YACS,QAAkB,EAClB,eAA0B,EAC1B,cAAuB;QAF9B;;;;mBAAO,QAAQ;WAAU;QACzB;;;;mBAAO,eAAe;WAAW;QACjC;;;;mBAAO,cAAc;WAAS;QA1CvB;;;;mBAAK,IAAA,mBAAU,GAAE,CAAC,QAAQ,EAAE;WAAC;QACtC;;;;;WAA0B;QAC1B;;;;mBAAY,KAAK;WAAC;QAClB;;;;mBAAkB,KAAK;WAAC;QACxB,2BAA2B;QACnB;;;;mBAAS,kB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AAC,EAAE,CAAC;QAClC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { randomUUID } from \"crypto\";\nimport { Candidate, candidateFoundation, candidatePriority } from \"./candidate\";\nimport type { MdnsLookup } from \"./dns/lookup\";\nimport type { Cancelable } from \"./helper\";\nimport {\n type Address,\n debug,\n type Event,\n type InterfaceAddresses,\n type TlsConnectionOptions,\n} from \"./imports/common\";\nimport { classes, methods } from \"./stun/const\";\nimport { Message } from \"./stun/message\";\nimport type { Protocol } from \"./types/model\";\n\nconst log = debug(\"werift-ice : packages/ice/src/ice.ts : log\");\n\nexport interface IceConnection {\n iceLite: boolean;\n iceControlling: boolean;\n localUsername: string;\n localPassword: string;\n remotePassword: string;\n remoteUsername: string;\n remoteIsLite: boolean;\n checkList: CandidatePair[];\n localCandidates: Candidate[];\n remoteCandidates: Candidate[];\n candidatePairs: CandidatePair[];\n stunServer?: Address;\n turnServer?: Address;\n generation: number;\n options: IceOptions;\n remoteCandidatesEnd: boolean;\n localCandidatesEnd: boolean;\n state: IceState;\n lookup?: MdnsLookup;\n nominated?: CandidatePair;\n\n readonly onData: Event<[Buffer]>;\n readonly stateChanged: Event<[IceState]>;\n readonly onIceCandidate: Event<[Candidate]>;\n\n restart(): void;\n /**\n * Optional staged-restart and provisional-generation support. An\n * implementation without them still restarts ICE at the final answer, but\n * cannot answer or run checks for the new generation during pranswer.\n */\n stageLocalCredentials?(usernameFragment: string, password: string): void;\n discardStagedLocalCredentials?(usernameFragment: string): void;\n commitLocalCredentials?(usernameFragment: string, password: string): void;\n /**\n * The remote side alone restarted (new remote credentials in an answer):\n * drop the remote generation and its checks, keep the local credentials\n * and gathered candidates.\n */\n restartRemote?(): void;\n setProvisionalRemoteParams?(params: {\n usernameFragment: string;\n password: string;\n }): void;\n addProvisionalRemoteCandidate?(\n candidate: Candidate | undefined,\n ): Promise<void>;\n startProvisionalChecks?(): void;\n readonly provisionalNominated?: CandidatePair;\n\n setIceServers(options: Partial<IceOptions>): void;\n\n setRemoteParams(params: {\n iceLite: boolean;\n usernameFragment: string;\n password: string;\n }): void;\n\n /**\n * Gather the current generation's candidates. After an ICE restart the\n * candidates the kept sockets advertised are re-advertised synchronously;\n * only server work (STUN, TURN) is awaited.\n */\n gatherCandidates(): Promise<void>;\n\n /** Whether gathering contacts a STUN or TURN server. */\n readonly gathersFromServers?: boolean;\n\n connect(): Promise<void>;\n\n close(): Promise<void>;\n\n addRemoteCandidate(remoteCandidate: Candidate | undefined): Promise<void>;\n\n send(data: Buffer): Promise<void>;\n\n getDefaultCandidate(): Candidate | undefined;\n resetNominatedPair(): void;\n /** Drop remote candidates and pairs that name another remote ufrag. */\n dropOtherRemoteGenerations?(usernameFragment: string): void;\n}\n\nexport interface CandidatePairStats {\n packetsSent: number;\n packetsReceived: number;\n bytesSent: number;\n bytesReceived: number;\n rtt?: number;\n totalRoundTripTime: number;\n roundTripTimeMeasurements: number;\n requestsReceived: number;\n requestsSent: number;\n responsesReceived: number;\n responsesSent: number;\n retransmissionsReceived: number;\n retransmissionsSent: number;\n consentRequestsSent: number;\n}\n\nexport class CandidatePair implements CandidatePairStats {\n readonly id = randomUUID().toString();\n handle?: Cancelable<void>;\n nominated = false;\n remoteNominated = false;\n // 5.7.4. Computing States\n private _state = CandidatePairState.FROZEN;\n get state() {\n return this._state;\n }\n\n // Statistics tracking\n packetsSent = 0;\n packetsReceived = 0;\n bytesSent = 0;\n bytesReceived = 0;\n rtt?: number;\n totalRoundTripTime = 0;\n roundTripTimeMeasurements = 0;\n requestsReceived = 0;\n requestsSent = 0;\n responsesReceived = 0;\n responsesSent = 0;\n retransmissionsReceived = 0;\n retransmissionsSent = 0;\n consentRequestsSent = 0;\n private readonly requestTransactionIds = new Set<string>();\n\n toJSON() {\n return this.json;\n }\n\n get json() {\n return {\n protocol: this.protocol.type,\n localCandidate: this.localCandidate.toSdp(),\n remoteCandidate: this.remoteCandidate.toSdp(),\n };\n }\n\n constructor(\n public protocol: Protocol,\n public remoteCandidate: Candidate,\n public iceControlling: boolean,\n ) {}\n\n updateState(state: CandidatePairState) {\n this._state = state;\n }\n\n get localCandidate() {\n if (!this.protocol.localCandidate) {\n throw new Error(\"localCandidate not exist\");\n }\n return this.protocol.localCandidate;\n }\n\n get remoteAddr(): Address {\n return [this.remoteCandidate.host, this.remoteCandidate.port];\n }\n\n get component() {\n return this.localCandidate.component;\n }\n\n get priority() {\n return candidatePairPriority(\n this.localCandidate,\n this.remoteCandidate,\n this.iceControlling,\n );\n }\n\n get foundation() {\n return this.localCandidate.foundation;\n }\n\n noteIncomingRequest(transactionId: string) {\n const isRetransmission = this.requestTransactionIds.has(transactionId);\n if (!isRetransmission) {\n this.requestTransactionIds.add(transactionId);\n return false;\n }\n this.retransmissionsReceived++;\n return true;\n }\n}\n\nexport const ICE_COMPLETED = 1 as const;\nexport const ICE_FAILED = 2 as const;\n\n/** Basic consent check period in seconds (RFC 7675). Actual interval is 0.8–1.2× this. */\nexport const CONSENT_INTERVAL = 5;\n\n/**\n * @deprecated Consent expiry is based on {@link CONSENT_TIMEOUT} (30s after the\n * last valid response), not a consecutive failure count. Kept for API compatibility.\n */\nexport const CONSENT_FAILURES = 6;\n\n/** RFC 7675: consent expires this many seconds after the last valid response. */\nexport const CONSENT_TIMEOUT = 30;\n\n/**\n * Default single-shot response wait for consent requests (ms) when RTT is unknown.\n * Independent of retransmission count. Downstream ICE-lite peers typically\n * answer in 150–300ms; 1s is a conservative default used by interop patches.\n */\nexport const CONSENT_RESPONSE_TIMEOUT = 1000;\n\n/** RFC 8445 §14.3: ICE RTO must not be less than 500ms. */\nexport const CONSENT_RESPONSE_TIMEOUT_MIN = 500;\n\n/**\n * Compute consent response wait from pair RTT (seconds).\n * Uses 2×RTT + 200ms jitter margin, floored at {@link CONSENT_RESPONSE_TIMEOUT_MIN}.\n * Falls back to {@link CONSENT_RESPONSE_TIMEOUT} when RTT is unavailable.\n */\nexport function consentResponseTimeoutMs(rttSeconds?: number): number {\n if (\n rttSeconds === undefined ||\n !Number.isFinite(rttSeconds) ||\n rttSeconds <= 0\n ) {\n return CONSENT_RESPONSE_TIMEOUT;\n }\n return Math.max(\n CONSENT_RESPONSE_TIMEOUT_MIN,\n Math.round(rttSeconds * 1000 * 2 + 200),\n );\n}\n\nexport enum CandidatePairState {\n FROZEN = 0,\n WAITING = 1,\n IN_PROGRESS = 2,\n SUCCEEDED = 3,\n FAILED = 4,\n}\n\nexport type IceState =\n | \"disconnected\"\n | \"closed\"\n | \"completed\"\n | \"new\"\n | \"connected\"\n | \"failed\";\n\nexport interface IceOptions {\n /** Advertise and operate as an ICE lite agent. */\n iceLite: boolean;\n useTcp: boolean;\n /**\n * Gather passive TCP host candidates (opens a listening TCP server per\n * interface). Defaults to true. Send-only agents that never accept inbound\n * connections can set this false to avoid the listener while still gathering\n * active TCP candidates.\n */\n tcpPassive?: boolean;\n /**\n * Seconds to wait for server-reflexive candidates while gathering.\n * Defaults to 5. Where UDP is blocked these STUN queries are never answered,\n * so the wait always runs to the timeout; agents that must not stall on such\n * networks can lower it.\n */\n stunGatherTimeout?: number;\n /**\n * Seconds to wait for a TURN TCP/TLS connection to be established.\n * Defaults to 8.\n */\n turnConnectTimeout?: number;\n stunServer?: Address;\n turnServer?: Address;\n turnUsername?: string;\n turnPassword?: string;\n turnTransport?: \"udp\" | \"tcp\" | \"tls\";\n turnTlsOptions?: TlsConnectionOptions;\n /**\n * Preferred IP family of the TURN/UDP socket, applied only when turnServer\n * is a hostname. Ignored for an IP literal turnServer, whose own family\n * always selects the socket. Defaults to 4.\n */\n turnUdpFamily?: 4 | 6;\n forceTurn?: boolean;\n localPasswordPrefix?: string;\n useIpv4: boolean;\n useIpv6: boolean;\n useLinkLocalAddress?: boolean;\n portRange?: [number, number];\n /**\n * Local addresses to bind the UDP host sockets to, per family.\n *\n * The address given for a family (`udp4` / `udp6`) is the only host\n * address of that family: its UDP host candidate advertises the address and\n * port the socket is actually bound to, even when the address is not among\n * the enumerated network interfaces (loopback, tun, ...), and its TCP host\n * candidates use it too. Other enumerated addresses of that family are not\n * gathered. If the bind fails, the family has no UDP host candidate.\n *\n * A family left unspecified while the other one is set gathers no\n * enumerated addresses (only its `additionalHostAddresses`). Without any\n * family set, every enumerated address is gathered over wildcard sockets.\n */\n interfaceAddresses?: InterfaceAddresses;\n /**\n * Host addresses gathered in addition to the enumerated ones. For a family\n * bound by `interfaceAddresses`, addresses other than the bound one are\n * ignored.\n */\n additionalHostAddresses?: string[];\n filterStunResponse?: (\n message: Message,\n addr: Address,\n protocol: Protocol,\n ) => boolean;\n filterCandidatePair?: (pair: CandidatePair) => boolean;\n}\n\nexport const defaultOptions: IceOptions = {\n iceLite: false,\n useTcp: false,\n useIpv4: true,\n useIpv6: true,\n};\n\nexport function validateRemoteCandidate(candidate: Candidate) {\n // \"\"\"\n // Check the remote candidate is supported.\n // \"\"\"\n if (![\"host\", \"relay\", \"srflx\"].includes(candidate.type))\n throw new Error(`Unexpected candidate type \"${candidate.type}\"`);\n\n // ipaddress.ip_address(candidate.host)\n return candidate;\n}\n\nexport function sortCandidatePairs(\n pairs: {\n localCandidate: Pick<Candidate, \"priority\">;\n remoteCandidate: Pick<Candidate, \"priority\">;\n }[],\n iceControlling: boolean,\n) {\n return pairs\n .sort(\n (a, b) =>\n candidatePairPriority(\n a.localCandidate,\n a.remoteCandidate,\n iceControlling,\n ) -\n candidatePairPriority(\n b.localCandidate,\n b.remoteCandidate,\n iceControlling,\n ),\n )\n .reverse();\n}\n\n// 5.7.2. Computing Pair Priority and Ordering Pairs\nexport function candidatePairPriority(\n local: Pick<Candidate, \"priority\">,\n remote: Pick<Candidate, \"priority\">,\n iceControlling: boolean,\n) {\n const G = (iceControlling && local.priority) || remote.priority;\n const D = (iceControlling && remote.priority) || local.priority;\n return (1 << 32) * Math.min(G, D) + 2 * Math.max(G, D) + (G > D ? 1 : 0);\n}\n\nexport async function serverReflexiveCandidate(\n protocol: Protocol,\n stunServer: Address,\n) {\n // \"\"\"\n // Query STUN server to obtain a server-reflexive candidate.\n // \"\"\"\n\n // # perform STUN query\n const request = new Message(methods.BINDING, classes.REQUEST);\n try {\n const [response] = await protocol.request(request, stunServer);\n\n const localCandidate = protocol.localCandidate;\n if (!localCandidate) {\n throw new Error(\"not exist\");\n }\n\n const candidate = new Candidate(\n candidateFoundation(\n \"srflx\",\n localCandidate.transport,\n localCandidate.host,\n ),\n localCandidate.component,\n localCandidate.transport,\n candidatePriority(\"srflx\", {\n transport: localCandidate.transport,\n tcptype: localCandidate.tcptype,\n }),\n response.getAttributeValue(\"XOR-MAPPED-ADDRESS\")[0],\n response.getAttributeValue(\"XOR-MAPPED-ADDRESS\")[1],\n \"srflx\",\n localCandidate.host,\n localCandidate.port,\n localCandidate.tcptype,\n );\n return candidate;\n } catch (error) {\n // todo fix\n log(\"error serverReflexiveCandidate\", error);\n }\n}\n\nexport function validateAddress(addr?: Address): Address | undefined {\n if (addr && Number.isNaN(addr[1])) {\n return [addr[0], 443];\n }\n return addr;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"iceBase.js","sourceRoot":"","sources":["../../../../ice/src/iceBase.ts"],"names":[],"mappings":";;;AA0TA,4DAYC;AAkRD,0DASC;AAED,gDAiBC;AAmBD,sDAOC;AAMD,oEAUC;AAQD,sEAmCC;AAOD,4DAYC;AAED,0CAKC;AA6CD,8DAsEC;AAQD,sDAmBC;AAUD,oDAEC;AAMD,sCAEC;AAUD,8EAYC;AA35BD,mCAAoC;AACpC,2CAAgF;AAChF,qDAI0B;AAG1B,6CAM0B;AAC1B,wCAA2E;AAC3E,4CAAyC;AAGzC,MAAM,GAAG,GAAG,IAAA,cAAK,EAAC,4CAA4C,CAAC,CAAC;AA4JhE,MAAa,aAAa;IAuBxB,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAmBD,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,C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,CAAC,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IAChD,IAAI,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,KAAK,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACnE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { randomUUID } from \"crypto\";\nimport { Candidate, candidateFoundation, candidatePriority } from \"./candidate\";\nimport {\n type IceCandidateErrorInfo,\n type IceServerReachedInfo,\n MissingMappedAddressError,\n} from \"./candidateError\";\nimport type { MdnsLookup } from \"./dns/lookup\";\nimport type { Cancelable } from \"./helper\";\nimport {\n type Address,\n debug,\n type Event,\n type InterfaceAddresses,\n type TlsConnectionOptions,\n} from \"./imports/common\";\nimport { classes, type MessageIntegrityMode, methods } from \"./stun/const\";\nimport { Message } from \"./stun/message\";\nimport type { Protocol } from \"./types/model\";\n\nconst log = debug(\"werift-ice : packages/ice/src/ice.ts : log\");\n\nexport interface IceConnection {\n iceLite: boolean;\n iceControlling: boolean;\n localUsername: string;\n localPassword: string;\n remotePassword: string;\n remoteUsername: string;\n remoteIsLite: boolean;\n /**\n * The peer advertised `a=ice-options:renomination`. With\n * {@link IceOptions.renomination} the controlling agent then nominates with\n * the NOMINATION attribute (see `renomination`).\n */\n remoteRenomination?: boolean;\n /**\n * The remote `a=ice-options` tokens (RFC 8839 §5.6), e.g. `trickle`,\n * `ice2`. Informational: werift already follows RFC 8445, so no token\n * changes how checks or nomination run.\n */\n remoteIceOptions?: string[];\n /** The remote declared `ice2`: an RFC 8445 agent (RFC 8445 §10). */\n readonly remoteIce2?: boolean;\n checkList: CandidatePair[];\n localCandidates: Candidate[];\n remoteCandidates: Candidate[];\n candidatePairs: CandidatePair[];\n /**\n * STUN servers gathering queries, normalized from the options (see\n * {@link normalizeIceServerOptions}). Optional so that other\n * implementations of this interface keep compiling.\n */\n stunServers?: Address[];\n /** TURN servers gathering allocates on, each with its own credential. */\n turnServers?: TurnServerOptions[];\n /** @deprecated The first of {@link IceConnection.stunServers}. */\n stunServer?: Address;\n /** @deprecated The address of the first of {@link IceConnection.turnServers}. */\n turnServer?: Address;\n generation: number;\n options: IceOptions;\n remoteCandidatesEnd: boolean;\n localCandidatesEnd: boolean;\n /**\n * Resolves when `localCandidatesEnd` becomes true after `gatherCandidates()`\n * returned (server-reflexive queries that continue in the background), or\n * when the generation ends. Optional so that other implementations of this\n * interface keep compiling; without it gathering ends when\n * `gatherCandidates()` returns.\n */\n waitForLocalCandidatesEnd?(): Promise<void>;\n state: IceState;\n lookup?: MdnsLookup;\n nominated?: CandidatePair;\n\n readonly onData: Event<[Buffer]>;\n readonly stateChanged: Event<[IceState]>;\n readonly onIceCandidate: Event<[Candidate]>;\n /**\n * A STUN or TURN server of the current generation's gathering gave no\n * candidate (see {@link IceCandidateErrorInfo}). Optional so that other\n * implementations of this interface keep compiling.\n */\n readonly onIceCandidateError?: Event<[IceCandidateErrorInfo]>;\n /**\n * A STUN or TURN server of the current generation's gathering answered\n * (see {@link IceServerReachedInfo}). Optional like onIceCandidateError.\n */\n readonly onIceServerReached?: Event<[IceServerReachedInfo]>;\n\n restart(): void;\n /** Record the remote `a=ice-options` tokens (see remoteIceOptions). */\n setRemoteIceOptions?(options: string[]): void;\n /**\n * Optional staged-restart and provisional-generation support. An\n * implementation without them still restarts ICE at the final answer, but\n * cannot answer or run checks for the new generation during pranswer.\n */\n /**\n * `gatherOptions`: the options the staged generation gathers with (an ICE\n * server update applied at the commit); its provisional checks use only\n * the sockets those options allow. Defaults to the current options.\n */\n stageLocalCredentials?(\n usernameFragment: string,\n password: string,\n gatherOptions?: Partial<IceOptions>,\n ): void;\n discardStagedLocalCredentials?(usernameFragment: string): void;\n commitLocalCredentials?(usernameFragment: string, password: string): void;\n /**\n * The remote side alone restarted (new remote credentials in an answer):\n * drop the remote generation and its checks, keep the local credentials\n * and gathered candidates.\n */\n restartRemote?(): void;\n setProvisionalRemoteParams?(params: {\n usernameFragment: string;\n password: string;\n }): void;\n addProvisionalRemoteCandidate?(\n candidate: Candidate | undefined,\n ): Promise<void>;\n startProvisionalChecks?(): void;\n readonly provisionalNominated?: CandidatePair;\n\n setIceServers(options: Partial<IceOptions>): void;\n\n setRemoteParams(params: {\n iceLite: boolean;\n usernameFragment: string;\n password: string;\n }): void;\n\n /**\n * Gather the current generation's candidates. After an ICE restart the\n * candidates the kept sockets advertised are re-advertised synchronously;\n * only server work (STUN, TURN) is awaited.\n */\n gatherCandidates(): Promise<void>;\n\n /** Whether gathering contacts a STUN or TURN server. */\n readonly gathersFromServers?: boolean;\n\n connect(): Promise<void>;\n\n close(): Promise<void>;\n\n addRemoteCandidate(remoteCandidate: Candidate | undefined): Promise<void>;\n\n send(data: Buffer): Promise<void>;\n\n getDefaultCandidate(): Candidate | undefined;\n resetNominatedPair(): void;\n /** Drop remote candidates and pairs that name another remote ufrag. */\n dropOtherRemoteGenerations?(usernameFragment: string): void;\n}\n\nexport interface CandidatePairStats {\n packetsSent: number;\n packetsReceived: number;\n bytesSent: number;\n bytesReceived: number;\n rtt?: number;\n totalRoundTripTime: number;\n roundTripTimeMeasurements: number;\n requestsReceived: number;\n requestsSent: number;\n responsesReceived: number;\n responsesSent: number;\n retransmissionsReceived: number;\n retransmissionsSent: number;\n consentRequestsSent: number;\n}\n\nexport class CandidatePair implements CandidatePairStats {\n public protocol: Protocol;\n public remoteCandidate: Candidate;\n public iceControlling: boolean;\n\n readonly id = randomUUID().toString();\n handle?: Cancelable<void>;\n nominated = false;\n remoteNominated = false;\n /**\n * The largest nomination the peer sent for this pair while this agent was\n * controlled: the NOMINATION attribute's value (renomination), or 1 for\n * USE-CANDIDATE. The controlled agent selects the nominated pair with the\n * largest value, the higher-priority one between equal values.\n */\n remoteNomination = 0;\n /**\n * The NOMINATION value this agent (controlling, renomination) sent for the\n * pair and the peer answered; 0 when it did not renominate the pair.\n */\n nomination = 0;\n // 5.7.4. Computing States\n private _state: CandidatePairState = CandidatePairState.FROZEN;\n get state() {\n return this._state;\n }\n\n // Statistics tracking\n packetsSent = 0;\n packetsReceived = 0;\n bytesSent = 0;\n bytesReceived = 0;\n rtt?: number;\n totalRoundTripTime = 0;\n roundTripTimeMeasurements = 0;\n requestsReceived = 0;\n requestsSent = 0;\n responsesReceived = 0;\n responsesSent = 0;\n retransmissionsReceived = 0;\n retransmissionsSent = 0;\n consentRequestsSent = 0;\n private readonly requestTransactionIds = new Set<string>();\n\n toJSON() {\n return this.json;\n }\n\n get json() {\n return {\n protocol: this.protocol.type,\n localCandidate: this.localCandidate.toSdp(),\n remoteCandidate: this.remoteCandidate.toSdp(),\n };\n }\n\n constructor(\n protocol: Protocol,\n remoteCandidate: Candidate,\n iceControlling: boolean,\n ) {\n this.protocol = protocol;\n this.remoteCandidate = remoteCandidate;\n this.iceControlling = iceControlling;\n }\n\n updateState(state: CandidatePairState) {\n this._state = state;\n }\n\n get localCandidate() {\n if (!this.protocol.localCandidate) {\n throw new Error(\"localCandidate not exist\");\n }\n return this.protocol.localCandidate;\n }\n\n get remoteAddr(): Address {\n return [this.remoteCandidate.host, this.remoteCandidate.port];\n }\n\n get component() {\n return this.localCandidate.component;\n }\n\n get priority() {\n return candidatePairPriority(\n this.localCandidate,\n this.remoteCandidate,\n this.iceControlling,\n );\n }\n\n get foundation() {\n return this.localCandidate.foundation;\n }\n\n noteIncomingRequest(transactionId: string) {\n const isRetransmission = this.requestTransactionIds.has(transactionId);\n if (!isRetransmission) {\n this.requestTransactionIds.add(transactionId);\n return false;\n }\n this.retransmissionsReceived++;\n return true;\n }\n}\n\nexport const ICE_COMPLETED = 1 as const;\nexport const ICE_FAILED = 2 as const;\n\n/** Basic consent check period in seconds (RFC 7675). Actual interval is 0.8–1.2× this. */\nexport const CONSENT_INTERVAL = 5;\n\n/**\n * @deprecated Consent expiry is based on {@link CONSENT_TIMEOUT} (30s after the\n * last valid response), not a consecutive failure count. Kept for API compatibility.\n */\nexport const CONSENT_FAILURES = 6;\n\n/** RFC 7675: consent expires this many seconds after the last valid response. */\nexport const CONSENT_TIMEOUT = 30;\n\n/**\n * Default single-shot response wait for consent requests (ms) when RTT is unknown.\n * Independent of retransmission count. Downstream ICE-lite peers typically\n * answer in 150–300ms; 1s is a conservative default used by interop patches.\n */\nexport const CONSENT_RESPONSE_TIMEOUT = 1000;\n\n/** RFC 8445 §14.3: ICE RTO must not be less than 500ms. */\nexport const CONSENT_RESPONSE_TIMEOUT_MIN = 500;\n\n/**\n * Compute consent response wait from pair RTT (seconds).\n * Uses 2×RTT + 200ms jitter margin, floored at {@link CONSENT_RESPONSE_TIMEOUT_MIN}.\n * Falls back to {@link CONSENT_RESPONSE_TIMEOUT} when RTT is unavailable.\n */\nexport function consentResponseTimeoutMs(rttSeconds?: number): number {\n if (\n rttSeconds === undefined ||\n !Number.isFinite(rttSeconds) ||\n rttSeconds <= 0\n ) {\n return CONSENT_RESPONSE_TIMEOUT;\n }\n return Math.max(\n CONSENT_RESPONSE_TIMEOUT_MIN,\n Math.round(rttSeconds * 1000 * 2 + 200),\n );\n}\n\n/**\n * @enum\n */\nexport const CandidatePairState = {\n FROZEN: 0,\n WAITING: 1,\n IN_PROGRESS: 2,\n SUCCEEDED: 3,\n FAILED: 4,\n} as const;\nexport type CandidatePairState =\n (typeof CandidatePairState)[keyof typeof CandidatePairState];\n\nexport type IceState =\n | \"disconnected\"\n | \"closed\"\n | \"completed\"\n | \"new\"\n | \"connected\"\n | \"failed\";\n\n/** A TURN server and the credential and transport used for it. */\nexport type TurnServerOptions = {\n address: Address;\n username: string;\n password: string;\n /** Defaults to \"udp\" (with a TCP fallback when the UDP allocation fails). */\n transport?: \"udp\" | \"tcp\" | \"tls\";\n /**\n * The application's names (URLs) for this server. Metadata only: the\n * allocation does not use them. They are passed through unchanged to\n * {@link IceServerRef.urls} of `Connection.onIceCandidateError`, so a\n * failure can be matched to the configured server without exposing the\n * credential. Duplicates merged by {@link normalizeIceServerOptions} have\n * their urls merged.\n */\n urls?: string[];\n};\n\n/** A TURN server as gathering uses it (see {@link normalizeIceServerOptions}). */\nexport type NormalizedTurnServer = Required<Omit<TurnServerOptions, \"urls\">> &\n Pick<TurnServerOptions, \"urls\">;\n\n/**\n * The application's name (URL) of a STUN server, reported in\n * {@link IceServerRef.urls} of `Connection.onIceCandidateError`. Metadata\n * only; several entries may name the same address.\n */\nexport type StunServerUrl = { address: Address; url: string };\n\nexport interface IceOptions {\n /** Advertise and operate as an ICE lite agent. */\n iceLite: boolean;\n useTcp: boolean;\n /**\n * Gather passive TCP host candidates (opens a listening TCP server per\n * interface). Defaults to true. Send-only agents that never accept inbound\n * connections can set this false to avoid the listener while still gathering\n * active TCP candidates.\n */\n tcpPassive?: boolean;\n /**\n * Seconds to wait for server-reflexive candidates while gathering.\n * Defaults to 5. Where UDP is blocked these STUN queries are never answered,\n * so the wait always runs to the timeout; agents that must not stall on such\n * networks can lower it.\n *\n * `gatherCandidates()` waits only for the representative sockets' queries\n * (see `stunServers`); the other host sockets' queries continue up to this\n * timeout in the background and end-of-candidates follows them.\n */\n stunGatherTimeout?: number;\n /**\n * Seconds to wait for a TURN TCP/TLS connection to be established.\n * Defaults to 8.\n */\n turnConnectTimeout?: number;\n /**\n * With `nomination: \"regular\"`: milliseconds the controlling agent keeps\n * checking before it nominates (RFC 8445 §8.1.1 regular nomination). The\n * default semi-aggressive nomination does not wait. Counted from the later of the first\n * valid pair and the last pair added that outranks the best valid pair, so\n * a higher-priority candidate trickled shortly after a lower-priority one\n * succeeded can still be selected. Once both sides signalled\n * end-of-candidates and no higher-priority pair is still being checked, the\n * best valid pair is nominated at once. Defaults to 300; 0 nominates the\n * best valid pair as soon as one exists. A negative or non-finite value\n * falls back to the default.\n */\n nominationDelayMs?: number;\n /**\n * How the controlling agent nominates toward a full ICE peer when\n * renomination is not in use (see `renomination`).\n *\n * - `\"semi-aggressive\"` (default, as libwebrtc / Chrome): a check carries\n * USE-CANDIDATE while no pair is selected and for every pair that\n * outranks the selected one. The first pair whose check succeeds is\n * selected at once; checks of higher-priority pairs go on, and one that\n * succeeds later replaces the selection. Consent checks of the selected\n * pair carry USE-CANDIDATE as well.\n * - `\"regular\"`: RFC 8445 §8.1.1 regular nomination. Checks carry no\n * USE-CANDIDATE; after `nominationDelayMs` (or end-of-candidates) the\n * best valid pair is nominated once with a separate check and never\n * replaced.\n *\n * Toward an ICE-lite peer the first valid pair is nominated in either mode.\n */\n nomination?: \"semi-aggressive\" | \"regular\";\n /**\n * Renomination (draft-thatcher-ice-renomination, as libwebrtc implements\n * it). When enabled the agent advertises `a=ice-options:renomination`\n * (packages/webrtc). When the peer advertised it too, the controlling agent\n * nominates with the NOMINATION attribute (0xC001) and an increasing value\n * instead of USE-CANDIDATE: it nominates the first valid pair, keeps\n * checking higher-priority pairs and renominates a better one when its\n * check succeeds. This replaces `nomination` for that session.\n *\n * The controlled agent always honours the NOMINATION attribute: it selects\n * the pair with the largest value. Defaults to false.\n */\n renomination?: boolean;\n /**\n * STUN servers queried while gathering, in priority order. Every IPv4 UDP\n * host socket queries each of them in parallel; equal mappings are\n * advertised once, different ones (a NAT that maps per destination) each.\n *\n * Without `interfaceAddresses`, each family with a STUN server also gets a\n * UDP socket bound to the wildcard address that advertises no host\n * candidate: the OS picks its route (a full-tunnel VPN, an interface the\n * host sockets do not cover), and its server-reflexive candidates carry\n * the related address `0.0.0.0` / `::`. The IPv4 wildcard socket queries\n * every server, the IPv6 one only the IPv6 literal servers. It checks only\n * the remote candidates whose route leaves from an address no UDP host\n * socket is bound to, so a peer on a covered path learns no\n * peer-reflexive candidate from it.\n *\n * `gatherCandidates()` returns once the representative sockets answered or\n * `stunGatherTimeout` ran out: the wildcard sockets and the host socket of\n * the default-route address (every host socket when a family has neither).\n * The other host sockets' server-reflexive candidates trickle through\n * `onIceCandidate`, and `localCandidatesEnd` follows the last of them\n * (`waitForLocalCandidatesEnd()`), so an interface that cannot reach the\n * STUN server does not delay the description.\n *\n * Merged with the deprecated `stunServer`: the singular one comes first,\n * duplicates are dropped (see {@link normalizeIceServerOptions}).\n */\n stunServers?: Address[];\n /**\n * The application's names (URLs) of {@link IceOptions.stunServers}, by\n * address. Metadata only, reported in {@link IceServerRef.urls} of\n * `Connection.onIceCandidateError`; replaced together with the STUN\n * servers (see {@link mergeIceServerOptions}).\n */\n stunServerUrls?: StunServerUrl[];\n /**\n * TURN servers allocated on while gathering, in priority order. Each one\n * gets its own allocation with its own credential and transport; one that\n * fails or times out does not stop the others. Gathering ends when the\n * slowest allocation completes or fails (`turnConnectTimeout` bounds a\n * TCP/TLS connection, the STUN transaction timeout an unanswered request).\n * `turnTlsOptions`, `turnUdpFamily`, `turnConnectTimeout`, `portRange` and\n * `interfaceAddresses` apply to every TURN server.\n *\n * Merged with the deprecated `turnServer` / `turnUsername` /\n * `turnPassword` / `turnTransport`: the singular one comes first,\n * duplicates are dropped and an entry without username / password is\n * ignored (see {@link normalizeIceServerOptions}).\n */\n turnServers?: TurnServerOptions[];\n /** @deprecated Use {@link IceOptions.stunServers}. Kept as their first entry. */\n stunServer?: Address;\n /**\n * Whether the built-in public STUN server (stun.l.google.com:19302) is used\n * when no STUN server is given. Defaults to true; false gathers no\n * server-reflexive candidate unless a STUN server is set.\n */\n useDefaultStunServer?: boolean;\n /** @deprecated Use {@link IceOptions.turnServers}. Kept as their first entry. */\n turnServer?: Address;\n /** @deprecated Use {@link TurnServerOptions.username} of {@link IceOptions.turnServers}. */\n turnUsername?: string;\n /** @deprecated Use {@link TurnServerOptions.password} of {@link IceOptions.turnServers}. */\n turnPassword?: string;\n /** @deprecated Use {@link TurnServerOptions.transport} of {@link IceOptions.turnServers}. */\n turnTransport?: \"udp\" | \"tcp\" | \"tls\";\n /** Applied to every TLS TURN server. */\n turnTlsOptions?: TlsConnectionOptions;\n /**\n * Preferred IP family of a TURN/UDP socket, applied (to every TURN server)\n * only when the server is a hostname. Ignored for an IP literal server,\n * whose own family always selects the socket. Defaults to 4.\n */\n turnUdpFamily?: 4 | 6;\n forceTurn?: boolean;\n localPasswordPrefix?: string;\n useIpv4: boolean;\n useIpv6: boolean;\n useLinkLocalAddress?: boolean;\n portRange?: [number, number];\n /**\n * Local addresses to bind the UDP host sockets to, per family.\n *\n * The address given for a family (`udp4` / `udp6`) is the only host\n * address of that family: its UDP host candidate advertises the address and\n * port the socket is actually bound to, even when the address is not among\n * the enumerated network interfaces (loopback, tun, ...), and its TCP host\n * candidates use it too. Other enumerated addresses of that family are not\n * gathered. If the bind fails, the family has no UDP host candidate.\n *\n * A family left unspecified while the other one is set gathers no\n * enumerated addresses (only its `additionalHostAddresses`).\n *\n * Without any family set, every enumerated address gets its own UDP host\n * socket bound to that address (an IPv6 link-local one with its zone), so\n * the socket's packets leave from the advertised candidate address even on\n * a host with several network interfaces. An address whose bind fails, or\n * whose sends fail, loses only its own candidate; the other addresses are\n * unaffected. An `additionalHostAddresses` entry that is not assigned to a\n * local interface (a 1:1 NAT public address, for example) is gathered over\n * a wildcard socket. The enumerated addresses include costly networks (VPN\n * / tunnel interfaces: `ipsec`, `tun`, `utun`, `tap`) with a low local\n * preference; `vmnet` / `veth` interfaces are excluded. The default-route\n * address gets the highest local preference, so checks start with the path\n * the OS uses: the source address of the route to the first configured\n * STUN / TURN server that resolves in the family and has a route (UDP\n * `connect()`, no packet is sent). A family without such a server has no\n * default-route address: no other address (no public one) is probed in\n * its place, and its host candidates keep the gathering order. With a STUN\n * server, a wildcard socket per family maps the route the\n * OS picks (see `stunServers`).\n *\n * A family set to the wildcard address (`0.0.0.0` / `::`) gathers its\n * enumerated and additional addresses over wildcard sockets instead;\n * the wildcard address itself is never advertised.\n */\n interfaceAddresses?: InterfaceAddresses;\n /**\n * Host addresses gathered in addition to the enumerated ones. For a family\n * bound by `interfaceAddresses`, addresses other than the bound one are\n * ignored.\n */\n additionalHostAddresses?: string[];\n filterStunResponse?: (\n message: Message,\n addr: Address,\n protocol: Protocol,\n ) => boolean;\n filterCandidatePair?: (pair: CandidatePair) => boolean;\n /**\n * Integrity attributes of the connectivity checks and consent requests this\n * agent sends (short-term credentials, RFC 8489):\n * - `\"sha1\"` (default): MESSAGE-INTEGRITY only, what every browser accepts.\n * - `\"sha256\"`: MESSAGE-INTEGRITY-SHA256 only. A peer that does not know\n * the comprehension-required 0x001C attribute rejects such checks (420\n * or no answer), so use it only with a peer known to support it.\n * - `\"both\"`: MESSAGE-INTEGRITY followed by MESSAGE-INTEGRITY-SHA256.\n *\n * Received requests and responses are accepted with either algorithm, and\n * a response is always signed with the algorithm of its request\n * (MESSAGE-INTEGRITY-SHA256 when the request carried it, RFC 8489 §9.1.3).\n */\n messageIntegrity?: MessageIntegrityMode;\n}\n\nexport const defaultOptions: IceOptions = {\n iceLite: false,\n useTcp: false,\n useIpv4: true,\n useIpv6: true,\n};\n\nexport function validateRemoteCandidate(candidate: Candidate) {\n // \"\"\"\n // Check the remote candidate is supported.\n // \"\"\"\n if (![\"host\", \"relay\", \"srflx\"].includes(candidate.type))\n throw new Error(`Unexpected candidate type \"${candidate.type}\"`);\n\n // ipaddress.ip_address(candidate.host)\n return candidate;\n}\n\nexport function sortCandidatePairs(\n pairs: {\n localCandidate: Pick<Candidate, \"priority\">;\n remoteCandidate: Pick<Candidate, \"priority\">;\n }[],\n iceControlling: boolean,\n) {\n // Highest priority first; pairs of equal priority keep their order.\n return pairs.sort((a, b) =>\n compareCandidatePairPriority(\n b.localCandidate,\n b.remoteCandidate,\n a.localCandidate,\n a.remoteCandidate,\n iceControlling,\n ),\n );\n}\n\n/** RFC 8445 §6.1.2.3: G is the controlling agent's candidate priority, D the controlled one's. */\nfunction pairPriorityTerms(\n local: Pick<Candidate, \"priority\">,\n remote: Pick<Candidate, \"priority\">,\n iceControlling: boolean,\n) {\n const G = iceControlling ? local.priority : remote.priority;\n const D = iceControlling ? remote.priority : local.priority;\n return { min: Math.min(G, D), max: Math.max(G, D), tie: G > D ? 1 : 0 };\n}\n\n// 5.7.2. Computing Pair Priority and Ordering Pairs\n/**\n * `2^32 * MIN(G,D) + 2 * MAX(G,D) + (G > D ? 1 : 0)` (RFC 8445 §6.1.2.3).\n * The value can exceed `Number.MAX_SAFE_INTEGER`, so it is approximate;\n * order pairs with `compareCandidatePairPriority`, which is exact.\n */\nexport function candidatePairPriority(\n local: Pick<Candidate, \"priority\">,\n remote: Pick<Candidate, \"priority\">,\n iceControlling: boolean,\n) {\n const { min, max, tie } = pairPriorityTerms(local, remote, iceControlling);\n return 2 ** 32 * min + 2 * max + tie;\n}\n\n/**\n * Exact comparison of two pair priorities (RFC 8445 §6.1.2.3): negative\n * when pair `a` has the lower priority, positive when the higher, 0 when equal.\n */\nexport function compareCandidatePairPriority(\n aLocal: Pick<Candidate, \"priority\">,\n aRemote: Pick<Candidate, \"priority\">,\n bLocal: Pick<Candidate, \"priority\">,\n bRemote: Pick<Candidate, \"priority\">,\n iceControlling: boolean,\n) {\n const a = pairPriorityTerms(aLocal, aRemote, iceControlling);\n const b = pairPriorityTerms(bLocal, bRemote, iceControlling);\n return a.min - b.min || a.max - b.max || a.tie - b.tie;\n}\n\n/**\n * Query `stunServer` from `protocol` for a server-reflexive candidate.\n * Unlike {@link serverReflexiveCandidate} it rejects with the reason of a\n * failure. `base` is used for wildcard sockets that advertise no host\n * candidate themselves.\n */\nexport async function queryServerReflexiveCandidate(\n protocol: Protocol,\n stunServer: Address,\n base?: Pick<Candidate, \"host\" | \"port\" | \"transport\" | \"component\"> &\n Partial<Pick<Candidate, \"tcptype\">>,\n): Promise<Candidate> {\n const localCandidate = base ?? protocol.localCandidate;\n if (!localCandidate) {\n throw new Error(\"protocol has no local candidate\");\n }\n\n const request = new Message(methods.BINDING, classes.REQUEST);\n const [response] = await protocol.request(request, stunServer);\n const mapped = response.getAttributeValue(\"XOR-MAPPED-ADDRESS\") as\n | Address\n | undefined;\n if (!mapped) {\n throw new MissingMappedAddressError(stunServer);\n }\n\n return new Candidate(\n candidateFoundation(\"srflx\", localCandidate.transport, localCandidate.host),\n localCandidate.component,\n localCandidate.transport,\n candidatePriority(\"srflx\", {\n transport: localCandidate.transport,\n tcptype: localCandidate.tcptype,\n }),\n mapped[0],\n mapped[1],\n \"srflx\",\n localCandidate.host,\n localCandidate.port,\n localCandidate.tcptype,\n );\n}\n\n/**\n * Query a STUN server for a server-reflexive candidate. This compatibility\n * helper resolves `undefined` on failure; use\n * {@link queryServerReflexiveCandidate} when the failure reason is needed.\n */\nexport async function serverReflexiveCandidate(\n protocol: Protocol,\n stunServer: Address,\n base?: Pick<Candidate, \"host\" | \"port\" | \"transport\" | \"component\"> &\n Partial<Pick<Candidate, \"tcptype\">>,\n): Promise<Candidate | undefined> {\n return queryServerReflexiveCandidate(protocol, stunServer, base).catch(\n (error) => {\n log(\"error serverReflexiveCandidate\", error);\n return undefined;\n },\n );\n}\n\nexport function validateAddress(addr?: Address): Address | undefined {\n if (addr && Number.isNaN(addr[1])) {\n return [addr[0], 443];\n }\n return addr;\n}\n\n/** The STUN/TURN server fields of {@link IceOptions}, singular and plural. */\nexport type IceServerFields = Partial<\n Pick<\n IceOptions,\n | \"stunServer\"\n | \"stunServers\"\n | \"stunServerUrls\"\n | \"turnServer\"\n | \"turnServers\"\n | \"turnUsername\"\n | \"turnPassword\"\n | \"turnTransport\"\n >\n>;\n\n/** A STUN/TURN server address: validated (see {@link validateAddress}) or undefined. */\nfunction validServerAddress(addr: unknown): Address | undefined {\n if (!Array.isArray(addr)) return undefined;\n const validated = validateAddress(addr as unknown as Address);\n if (!validated) return undefined;\n const [host, port] = validated;\n if (typeof host !== \"string\" || host === \"\") return undefined;\n if (typeof port !== \"number\" || !Number.isFinite(port)) return undefined;\n return validated;\n}\n\nconst sameAddress = (a: Address, b: Address) => a[0] === b[0] && a[1] === b[1];\n\n/**\n * The STUN and TURN servers `options` configure, the one place the singular\n * (deprecated) and plural fields are merged:\n *\n * - order: the singular server first, then the plural list in its order;\n * - duplicates (the same STUN address; the same TURN address, transport and\n * credential) are kept once, at their first position;\n * - an invalid address (see {@link validateAddress}) is dropped, and so is a\n * TURN server without username or password (it cannot allocate);\n * - a TURN transport left unset is \"udp\";\n * - the `urls` of merged TURN duplicates are merged (in order, once each).\n *\n * The built-in default STUN server is not added here; Connection falls back\n * to it when the result has no STUN server.\n */\nexport function normalizeIceServerOptions(options: IceServerFields): {\n stunServers: Address[];\n turnServers: NormalizedTurnServer[];\n} {\n const stunServers: Address[] = [];\n for (const server of [options.stunServer, ...(options.stunServers ?? [])]) {\n if (server === undefined) continue;\n const address = validServerAddress(server);\n if (!address) {\n log(\"invalid STUN server ignored\", server);\n continue;\n }\n if (stunServers.some((existing) => sameAddress(existing, address))) {\n continue;\n }\n stunServers.push(address);\n }\n\n const turnServers: NormalizedTurnServer[] = [];\n const configured: Partial<TurnServerOptions>[] = [\n ...(options.turnServer !== undefined\n ? [\n {\n address: options.turnServer,\n username: options.turnUsername,\n password: options.turnPassword,\n transport: options.turnTransport,\n },\n ]\n : []),\n ...(options.turnServers ?? []),\n ];\n for (const server of configured) {\n const address = validServerAddress(server?.address);\n if (!address) {\n log(\"invalid TURN server ignored\", server?.address);\n continue;\n }\n const { username, password } = server;\n if (!username || !password) {\n log(\"TURN server without username / credential ignored\", address);\n continue;\n }\n const urls = Array.isArray(server.urls)\n ? server.urls.filter((url) => typeof url === \"string\")\n : undefined;\n const entry: NormalizedTurnServer = {\n address,\n username,\n password,\n transport: server.transport ?? \"udp\",\n ...(urls ? { urls: [...new Set(urls)] } : {}),\n };\n const existing = turnServers.find(\n (known) =>\n sameAddress(known.address, entry.address) &&\n known.transport === entry.transport &&\n known.username === entry.username &&\n known.password === entry.password,\n );\n if (existing) {\n // One allocation serves both: it answers to every name of them.\n if (entry.urls) {\n existing.urls = [...new Set([...(existing.urls ?? []), ...entry.urls])];\n }\n continue;\n }\n turnServers.push(entry);\n }\n return { stunServers, turnServers };\n}\n\n/**\n * `current` with an ICE server update applied (Connection.setIceServers): the\n * STUN/TURN fields, singular and plural, are replaced, an undefined one\n * included, so a STUN-only update cannot leave a previous TURN\n * host/credential behind; forceTurn and useTcp change only when given.\n */\nexport function mergeIceServerOptions<T extends Partial<IceOptions>>(\n current: T,\n update: Partial<IceOptions>,\n): T {\n return {\n ...current,\n stunServer: update.stunServer,\n stunServers: update.stunServers,\n stunServerUrls: update.stunServerUrls,\n turnServer: update.turnServer,\n turnServers: update.turnServers,\n turnUsername: update.turnUsername,\n turnPassword: update.turnPassword,\n turnTransport: update.turnTransport,\n turnTlsOptions: update.turnTlsOptions,\n turnUdpFamily: update.turnUdpFamily,\n forceTurn: update.forceTurn ?? current.forceTurn,\n useTcp: update.useTcp ?? current.useTcp,\n };\n}\n\n/**\n * Whether a generation gathered with `options` is relay-only: forceTurn (the\n * \"relay\" ICE transport policy). The policy holds whatever the TURN settings\n * are: without a usable TURN server / credential (or for an ICE-lite agent,\n * which gathers no relay candidate) the generation has no candidate at all\n * rather than falling back to host / server-reflexive ones, so the local and\n * public addresses are neither advertised nor used for checks.\n */\nexport function isRelayOnlyGathering(options: Pick<IceOptions, \"forceTurn\">) {\n return !!options.forceTurn;\n}\n\n/**\n * Whether `options` carry at least one usable TURN server with its\n * credential, the ones a gathering with them allocates relay candidates from.\n */\nexport function hasTurnServer(options: IceServerFields) {\n return normalizeIceServerOptions(options).turnServers.length > 0;\n}\n\n/**\n * Whether `candidate`, kept from an earlier generation (an ICE restart keeps\n * the sockets), may be advertised and paired in a generation gathered with\n * `options`. A fresh gathering with the same options would not have produced\n * a host / server-reflexive candidate for a relay-only policy, a TCP host\n * candidate without useTcp, nor a relay candidate without a TURN server;\n * the kept ones are held back the same way.\n */\nexport function isCandidateAllowedByGatherOptions(\n candidate: Pick<Candidate, \"type\" | \"transport\">,\n options: Pick<IceOptions, \"forceTurn\"> &\n Partial<Pick<IceOptions, \"useTcp\">> &\n IceServerFields,\n) {\n if (candidate.type === \"relay\") return hasTurnServer(options);\n if (isRelayOnlyGathering(options)) return false;\n if (candidate.transport.toLowerCase() === \"tcp\" && !options.useTcp) {\n return false;\n }\n return true;\n}\n"]}
|
package/lib/ice/src/index.d.ts
CHANGED
package/lib/ice/src/index.js
CHANGED
|
@@ -18,6 +18,7 @@ exports.randomPort = void 0;
|
|
|
18
18
|
var src_1 = require("../../common/src");
|
|
19
19
|
Object.defineProperty(exports, "randomPort", { enumerable: true, get: function () { return src_1.randomPort; } });
|
|
20
20
|
__exportStar(require("./candidate"), exports);
|
|
21
|
+
__exportStar(require("./candidateError"), exports);
|
|
21
22
|
__exportStar(require("./ice"), exports);
|
|
22
23
|
__exportStar(require("./iceBase"), exports);
|
|
23
24
|
__exportStar(require("./stun/const"), exports);
|
package/lib/ice/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../ice/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wCAA8C;AAArC,iGAAA,UAAU,OAAA;AACnB,8CAA4B;AAC5B,wCAAsB;AACtB,4CAA0B;AAC1B,+CAA6B;AAC7B,iDAA+B;AAC/B,kDAAgC;AAChC,kDAAgC;AAChC,qDAAmC;AACnC,kDAAgC;AAChC,gDAA8B;AAC9B,0CAAwB","sourcesContent":["export { randomPort } from \"../../common/src\";\nexport * from \"./candidate\";\nexport * from \"./ice\";\nexport * from \"./iceBase\";\nexport * from \"./stun/const\";\nexport * from \"./stun/message\";\nexport * from \"./stun/protocol\";\nexport * from \"./stun/tcpFrame\";\nexport * from \"./stun/tcpProtocol\";\nexport * from \"./turn/protocol\";\nexport * from \"./types/model\";\nexport * from \"./utils\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../ice/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wCAA8C;AAArC,iGAAA,UAAU,OAAA;AACnB,8CAA4B;AAC5B,mDAAiC;AACjC,wCAAsB;AACtB,4CAA0B;AAC1B,+CAA6B;AAC7B,iDAA+B;AAC/B,kDAAgC;AAChC,kDAAgC;AAChC,qDAAmC;AACnC,kDAAgC;AAChC,gDAA8B;AAC9B,0CAAwB","sourcesContent":["export { randomPort } from \"../../common/src\";\nexport * from \"./candidate\";\nexport * from \"./candidateError\";\nexport * from \"./ice\";\nexport * from \"./iceBase\";\nexport * from \"./stun/const\";\nexport * from \"./stun/message\";\nexport * from \"./stun/protocol\";\nexport * from \"./stun/tcpFrame\";\nexport * from \"./stun/tcpProtocol\";\nexport * from \"./turn/protocol\";\nexport * from \"./types/model\";\nexport * from \"./utils\";\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Candidate } from "../candidate";
|
|
2
|
+
import { type MessageIntegrityMode } from "../stun/const";
|
|
3
|
+
import { Message } from "../stun/message";
|
|
4
|
+
/** STUN helpers of the connectivity checks (RFC 8445 §7.2, §7.3). */
|
|
5
|
+
/**
|
|
6
|
+
* Integrity attribute of a response to `request` (RFC 8489 §9.1.3): a request
|
|
7
|
+
* carrying MESSAGE-INTEGRITY-SHA256 is answered with MESSAGE-INTEGRITY-SHA256,
|
|
8
|
+
* any other with MESSAGE-INTEGRITY.
|
|
9
|
+
*/
|
|
10
|
+
export declare const responseIntegrityMode: (request: Message) => MessageIntegrityMode;
|
|
11
|
+
export declare const encodeTxUsername: ({ remoteUsername, localUsername, }: {
|
|
12
|
+
remoteUsername: string;
|
|
13
|
+
localUsername: string;
|
|
14
|
+
}) => string;
|
|
15
|
+
export declare const decodeTxUsername: (txUsername: string) => {
|
|
16
|
+
remoteUsername: string;
|
|
17
|
+
localUsername: string;
|
|
18
|
+
};
|
|
19
|
+
/** The peer answered with 487 (Role Conflict). */
|
|
20
|
+
export declare const isRoleConflict: (error: unknown) => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The nomination a peer's check carries: the NOMINATION value
|
|
23
|
+
* (renomination), else 1 for USE-CANDIDATE, else 0. A NOMINATION of 0 is
|
|
24
|
+
* invalid and nominates nothing (as in libwebrtc).
|
|
25
|
+
*/
|
|
26
|
+
export declare const receivedNomination: (message: Message) => number;
|
|
27
|
+
export type CheckRequestParams = {
|
|
28
|
+
/** USE-CANDIDATE (controlling only). */
|
|
29
|
+
nominate: boolean;
|
|
30
|
+
/** Renomination: the NOMINATION value to send (controlling only). */
|
|
31
|
+
nomination?: number;
|
|
32
|
+
remoteUsername: string;
|
|
33
|
+
localUsername: string;
|
|
34
|
+
iceControlling: boolean;
|
|
35
|
+
/** The local candidate of the pair: the PRIORITY of a peer-reflexive one. */
|
|
36
|
+
localCandidate?: Candidate;
|
|
37
|
+
/** ICE-CONTROLLING / ICE-CONTROLLED tie-breaker of the agent. */
|
|
38
|
+
tieBreaker: bigint;
|
|
39
|
+
};
|
|
40
|
+
/** A connectivity check (RFC 8445 §7.2.2): a Binding request of the agent. */
|
|
41
|
+
export declare const buildCheckRequest: ({ nominate, nomination, remoteUsername, localUsername, iceControlling, localCandidate, tieBreaker, }: CheckRequestParams) => Message;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildCheckRequest = exports.receivedNomination = exports.isRoleConflict = exports.decodeTxUsername = exports.encodeTxUsername = exports.responseIntegrityMode = void 0;
|
|
4
|
+
const candidate_1 = require("../candidate");
|
|
5
|
+
const const_1 = require("../stun/const");
|
|
6
|
+
const message_1 = require("../stun/message");
|
|
7
|
+
/** STUN helpers of the connectivity checks (RFC 8445 §7.2, §7.3). */
|
|
8
|
+
/**
|
|
9
|
+
* Integrity attribute of a response to `request` (RFC 8489 §9.1.3): a request
|
|
10
|
+
* carrying MESSAGE-INTEGRITY-SHA256 is answered with MESSAGE-INTEGRITY-SHA256,
|
|
11
|
+
* any other with MESSAGE-INTEGRITY.
|
|
12
|
+
*/
|
|
13
|
+
const responseIntegrityMode = (request) => request.integrityAlgorithm === "sha256" ? "sha256" : "sha1";
|
|
14
|
+
exports.responseIntegrityMode = responseIntegrityMode;
|
|
15
|
+
const encodeTxUsername = ({ remoteUsername, localUsername, }) => {
|
|
16
|
+
return `${remoteUsername}:${localUsername}`;
|
|
17
|
+
};
|
|
18
|
+
exports.encodeTxUsername = encodeTxUsername;
|
|
19
|
+
const decodeTxUsername = (txUsername) => {
|
|
20
|
+
const [remoteUsername, localUsername] = txUsername.split(":");
|
|
21
|
+
return { remoteUsername, localUsername };
|
|
22
|
+
};
|
|
23
|
+
exports.decodeTxUsername = decodeTxUsername;
|
|
24
|
+
/** The peer answered with 487 (Role Conflict). */
|
|
25
|
+
const isRoleConflict = (error) => error?.response?.getAttributeValue("ERROR-CODE")?.[0] === 487;
|
|
26
|
+
exports.isRoleConflict = isRoleConflict;
|
|
27
|
+
/**
|
|
28
|
+
* The nomination a peer's check carries: the NOMINATION value
|
|
29
|
+
* (renomination), else 1 for USE-CANDIDATE, else 0. A NOMINATION of 0 is
|
|
30
|
+
* invalid and nominates nothing (as in libwebrtc).
|
|
31
|
+
*/
|
|
32
|
+
const receivedNomination = (message) => {
|
|
33
|
+
if (message.attributesKeys.includes("NOMINATION")) {
|
|
34
|
+
const value = message.getAttributeValue("NOMINATION");
|
|
35
|
+
return typeof value === "number" && value > 0 ? value : 0;
|
|
36
|
+
}
|
|
37
|
+
return message.attributesKeys.includes("USE-CANDIDATE") ? 1 : 0;
|
|
38
|
+
};
|
|
39
|
+
exports.receivedNomination = receivedNomination;
|
|
40
|
+
/** A connectivity check (RFC 8445 §7.2.2): a Binding request of the agent. */
|
|
41
|
+
const buildCheckRequest = ({ nominate, nomination, remoteUsername, localUsername, iceControlling, localCandidate, tieBreaker, }) => {
|
|
42
|
+
const txUsername = (0, exports.encodeTxUsername)({ remoteUsername, localUsername });
|
|
43
|
+
const request = new message_1.Message(const_1.methods.BINDING, const_1.classes.REQUEST);
|
|
44
|
+
request.setAttribute("USERNAME", txUsername).setAttribute("PRIORITY", (0, candidate_1.candidatePriority)("prflx", {
|
|
45
|
+
transport: localCandidate?.transport,
|
|
46
|
+
tcptype: localCandidate?.tcptype,
|
|
47
|
+
}));
|
|
48
|
+
if (iceControlling) {
|
|
49
|
+
request.setAttribute("ICE-CONTROLLING", tieBreaker);
|
|
50
|
+
if (nominate) {
|
|
51
|
+
request.setAttribute("USE-CANDIDATE", null);
|
|
52
|
+
}
|
|
53
|
+
if (nomination !== undefined) {
|
|
54
|
+
request.setAttribute("NOMINATION", nomination);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
request.setAttribute("ICE-CONTROLLED", tieBreaker);
|
|
59
|
+
}
|
|
60
|
+
return request;
|
|
61
|
+
};
|
|
62
|
+
exports.buildCheckRequest = buildCheckRequest;
|
|
63
|
+
//# sourceMappingURL=checkMessages.js.map
|