werift 0.25.2 → 0.26.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/lib/common/src/asn1.d.ts +42 -0
- package/lib/common/src/asn1.js +163 -0
- package/lib/common/src/asn1.js.map +1 -0
- package/lib/common/src/binaryData.js.map +1 -1
- package/lib/common/src/index.d.ts +6 -5
- package/lib/common/src/index.js +6 -5
- package/lib/common/src/index.js.map +1 -1
- package/lib/common/src/log.d.ts +12 -1
- package/lib/common/src/log.js +137 -5
- package/lib/common/src/log.js.map +1 -1
- package/lib/common/src/network.js.map +1 -1
- package/lib/common/src/queue.d.ts +41 -0
- package/lib/common/src/queue.js +146 -0
- package/lib/common/src/queue.js.map +1 -0
- package/lib/common/src/transport.d.ts +15 -2
- package/lib/common/src/transport.js +98 -14
- package/lib/common/src/transport.js.map +1 -1
- package/lib/dtls/src/cipher/create.js.map +1 -1
- package/lib/dtls/src/cipher/ec.js +8 -8
- package/lib/dtls/src/cipher/ec.js.map +1 -1
- package/lib/dtls/src/cipher/namedCurve.js +6 -7
- package/lib/dtls/src/cipher/namedCurve.js.map +1 -1
- package/lib/dtls/src/cipher/prf.d.ts +2 -2
- package/lib/dtls/src/cipher/prf.js +29 -8
- package/lib/dtls/src/cipher/prf.js.map +1 -1
- package/lib/dtls/src/cipher/suites/aead.d.ts +1 -1
- package/lib/dtls/src/context/certificate.d.ts +32 -0
- package/lib/dtls/src/context/certificate.js +54 -0
- package/lib/dtls/src/context/certificate.js.map +1 -0
- package/lib/dtls/src/context/cipher.d.ts +12 -6
- package/lib/dtls/src/context/cipher.js +52 -103
- package/lib/dtls/src/context/cipher.js.map +1 -1
- package/lib/dtls/src/context/transport.d.ts +4 -0
- package/lib/dtls/src/context/transport.js +14 -0
- package/lib/dtls/src/context/transport.js.map +1 -1
- package/lib/dtls/src/flight/client/flight5.js.map +1 -1
- package/lib/dtls/src/flight/flight.js +8 -1
- package/lib/dtls/src/flight/flight.js.map +1 -1
- package/lib/dtls/src/flight/server/flight2.js.map +1 -1
- package/lib/dtls/src/flight/server/flight4.d.ts +2 -1
- package/lib/dtls/src/flight/server/flight4.js +8 -2
- package/lib/dtls/src/flight/server/flight4.js.map +1 -1
- package/lib/dtls/src/handshake/extensions/signature.d.ts +1 -1
- package/lib/dtls/src/handshake/extensions/signature.js.map +1 -1
- package/lib/dtls/src/handshake/message/alert.js +1 -1
- package/lib/dtls/src/handshake/message/alert.js.map +1 -1
- package/lib/dtls/src/handshake/message/certificate.js +1 -1
- package/lib/dtls/src/handshake/message/certificate.js.map +1 -1
- package/lib/dtls/src/handshake/message/changeCipherSpec.js +2 -3
- package/lib/dtls/src/handshake/message/changeCipherSpec.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/certificateVerify.d.ts +1 -1
- package/lib/dtls/src/handshake/message/client/certificateVerify.js +1 -1
- package/lib/dtls/src/handshake/message/client/certificateVerify.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/hello.js +1 -1
- package/lib/dtls/src/handshake/message/client/hello.js.map +1 -1
- package/lib/dtls/src/handshake/message/client/keyExchange.js +1 -1
- package/lib/dtls/src/handshake/message/client/keyExchange.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/certificateRequest.d.ts +1 -1
- package/lib/dtls/src/handshake/message/server/certificateRequest.js +1 -1
- package/lib/dtls/src/handshake/message/server/certificateRequest.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/hello.d.ts +1 -1
- package/lib/dtls/src/handshake/message/server/hello.js +2 -2
- package/lib/dtls/src/handshake/message/server/hello.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/helloDone.js +1 -1
- package/lib/dtls/src/handshake/message/server/helloDone.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js +1 -1
- package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js.map +1 -1
- package/lib/dtls/src/handshake/message/server/keyExchange.d.ts +1 -1
- package/lib/dtls/src/handshake/message/server/keyExchange.js +1 -1
- 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 +2 -2
- package/lib/dtls/src/handshake/random.js.map +1 -1
- package/lib/dtls/src/imports/common.d.ts +1 -0
- package/lib/dtls/src/imports/common.js +1 -0
- package/lib/dtls/src/imports/common.js.map +1 -1
- package/lib/dtls/src/index.d.ts +2 -2
- package/lib/dtls/src/index.js +2 -2
- package/lib/dtls/src/index.js.map +1 -1
- package/lib/dtls/src/record/message/fragment.d.ts +1 -1
- package/lib/dtls/src/record/message/fragment.js +3 -3
- package/lib/dtls/src/record/message/fragment.js.map +1 -1
- package/lib/dtls/src/record/message/header.js +2 -2
- package/lib/dtls/src/record/message/header.js.map +1 -1
- package/lib/dtls/src/server.js +1 -1
- package/lib/dtls/src/server.js.map +1 -1
- package/lib/dtls/src/socket.d.ts +2 -2
- package/lib/dtls/src/socket.js +2 -2
- package/lib/dtls/src/socket.js.map +1 -1
- package/lib/ice/src/exceptions.d.ts +30 -0
- package/lib/ice/src/exceptions.js +43 -1
- package/lib/ice/src/exceptions.js.map +1 -1
- package/lib/ice/src/helper.d.ts +1 -1
- package/lib/ice/src/ice.d.ts +142 -0
- package/lib/ice/src/ice.js +809 -53
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/iceBase.d.ts +49 -0
- package/lib/ice/src/iceBase.js.map +1 -1
- package/lib/ice/src/index.d.ts +5 -5
- package/lib/ice/src/index.js +5 -5
- package/lib/ice/src/index.js.map +1 -1
- package/lib/ice/src/internal/resolveHostAddresses.d.ts +26 -0
- package/lib/ice/src/internal/resolveHostAddresses.js +45 -0
- package/lib/ice/src/internal/resolveHostAddresses.js.map +1 -0
- package/lib/ice/src/stun/protocol.d.ts +3 -1
- package/lib/ice/src/stun/protocol.js +16 -0
- package/lib/ice/src/stun/protocol.js.map +1 -1
- package/lib/ice/src/stun/tcpProtocol.d.ts +2 -0
- package/lib/ice/src/stun/tcpProtocol.js +16 -1
- package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
- package/lib/ice/src/stun/transaction.d.ts +5 -0
- package/lib/ice/src/stun/transaction.js +7 -1
- package/lib/ice/src/stun/transaction.js.map +1 -1
- package/lib/ice/src/turn/protocol.d.ts +73 -4
- package/lib/ice/src/turn/protocol.js +241 -12
- package/lib/ice/src/turn/protocol.js.map +1 -1
- package/lib/ice/src/utils.js.map +1 -1
- package/lib/ice-server/src/stun/message.d.ts +5 -1
- package/lib/ice-server/src/stun/message.js +33 -2
- package/lib/ice-server/src/stun/message.js.map +1 -1
- package/lib/ice-server/src/turn/auth.d.ts +1 -1
- package/lib/index.mjs +16273 -10807
- package/lib/nonstandard/index.mjs +8644 -7911
- package/lib/polyfill/dom.mjs +22435 -16965
- package/lib/polyfill/index.mjs +22435 -16965
- package/lib/rtp/src/codec/h264.d.ts +1 -1
- package/lib/rtp/src/codec/h264.js.map +1 -1
- package/lib/rtp/src/extra/container/webm/container.d.ts +1 -1
- package/lib/rtp/src/extra/container/webm/ebml/ebml.d.ts +6 -0
- package/lib/rtp/src/extra/container/webm/ebml/ebml.js +20 -1
- package/lib/rtp/src/extra/container/webm/ebml/ebml.js.map +1 -1
- package/lib/rtp/src/extra/processor/depacketizer.d.ts +1 -1
- package/lib/rtp/src/extra/processor/depacketizer.js +1 -1
- package/lib/rtp/src/extra/processor/depacketizer.js.map +1 -1
- package/lib/rtp/src/extra/processor/depacketizerCallback.d.ts +1 -11
- package/lib/rtp/src/extra/processor/depacketizerTransformer.d.ts +1 -1
- package/lib/rtp/src/extra/processor/dtxCallback.d.ts +1 -11
- package/lib/rtp/src/extra/processor/interface.d.ts +16 -11
- package/lib/rtp/src/extra/processor/interface.js.map +1 -1
- package/lib/rtp/src/extra/processor/jitterBufferCallback.d.ts +1 -11
- package/lib/rtp/src/extra/processor/jitterBufferTransformer.d.ts +1 -1
- package/lib/rtp/src/extra/processor/mp4.js +1 -1
- package/lib/rtp/src/extra/processor/mp4.js.map +1 -1
- package/lib/rtp/src/extra/processor/nack.d.ts +1 -1
- package/lib/rtp/src/extra/processor/nack.js +1 -1
- package/lib/rtp/src/extra/processor/nack.js.map +1 -1
- package/lib/rtp/src/extra/processor/nackHandlerCallback.d.ts +1 -11
- package/lib/rtp/src/extra/processor/ntpTime.js.map +1 -1
- package/lib/rtp/src/extra/processor/ntpTimeCallback.d.ts +1 -11
- package/lib/rtp/src/extra/processor/rtcpCallback.d.ts +1 -1
- package/lib/rtp/src/extra/processor/rtcpCallback.js.map +1 -1
- package/lib/rtp/src/extra/processor/rtpCallback.d.ts +1 -1
- package/lib/rtp/src/extra/processor/rtpCallback.js +1 -1
- package/lib/rtp/src/extra/processor/rtpCallback.js.map +1 -1
- package/lib/rtp/src/extra/processor/rtpStream.d.ts +2 -2
- package/lib/rtp/src/extra/processor/rtpStream.js.map +1 -1
- package/lib/rtp/src/extra/processor/rtpTime.js.map +1 -1
- package/lib/rtp/src/extra/processor/rtpTimeCallback.d.ts +1 -11
- package/lib/rtp/src/extra/processor/webm.d.ts +27 -0
- package/lib/rtp/src/extra/processor/webm.js +43 -16
- package/lib/rtp/src/extra/processor/webm.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmCallback.js +6 -1
- package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmStream.js.map +1 -1
- package/lib/rtp/src/helper.d.ts +2 -2
- package/lib/rtp/src/helper.js +2 -6
- package/lib/rtp/src/helper.js.map +1 -1
- package/lib/rtp/src/index.d.ts +3 -2
- package/lib/rtp/src/index.js +3 -2
- package/lib/rtp/src/index.js.map +1 -1
- package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js +2 -1
- package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js.map +1 -1
- package/lib/rtp/src/rtcp/rtcp.js +2 -1
- package/lib/rtp/src/rtcp/rtcp.js.map +1 -1
- package/lib/rtp/src/rtcp/sr.d.ts +4 -3
- package/lib/rtp/src/rtcp/sr.js +3 -2
- package/lib/rtp/src/rtcp/sr.js.map +1 -1
- package/lib/rtp/src/srtp/cipher/ctr.d.ts +2 -2
- package/lib/rtp/src/srtp/cipher/ctr.js +1 -1
- package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
- package/lib/rtp/src/srtp/cipher/gcm.d.ts +1 -1
- package/lib/rtp/src/srtp/cipher/gcm.js +1 -1
- package/lib/rtp/src/srtp/cipher/gcm.js.map +1 -1
- package/lib/rtp/src/srtp/context/context.d.ts +29 -1
- package/lib/rtp/src/srtp/context/context.js +78 -24
- package/lib/rtp/src/srtp/context/context.js.map +1 -1
- package/lib/rtp/src/srtp/context/srtp.js +23 -15
- package/lib/rtp/src/srtp/context/srtp.js.map +1 -1
- package/lib/sctp/src/index.d.ts +4 -3
- package/lib/sctp/src/index.js +10 -8
- package/lib/sctp/src/index.js.map +1 -1
- package/lib/sctp/src/sctp.d.ts +11 -2
- package/lib/sctp/src/sctp.js +47 -28
- package/lib/sctp/src/sctp.js.map +1 -1
- package/lib/webrtc/src/api/peerConfig.d.ts +264 -0
- package/lib/webrtc/src/api/peerConfig.js +250 -0
- package/lib/webrtc/src/api/peerConfig.js.map +1 -0
- package/lib/webrtc/src/api/peerConnectionEvents.d.ts +36 -0
- package/lib/webrtc/src/api/peerConnectionEvents.js +44 -0
- package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -0
- package/lib/webrtc/src/dataChannel.d.ts +1 -1
- package/lib/webrtc/src/dataChannel.js +1 -1
- package/lib/webrtc/src/dataChannel.js.map +1 -1
- package/lib/webrtc/src/index.d.ts +2 -2
- package/lib/webrtc/src/index.js +2 -2
- package/lib/webrtc/src/index.js.map +1 -1
- package/lib/webrtc/src/media/index.d.ts +1 -1
- package/lib/webrtc/src/media/index.js +1 -1
- package/lib/webrtc/src/media/index.js.map +1 -1
- package/lib/webrtc/src/media/receiver/nack.js +3 -4
- package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
- package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
- package/lib/webrtc/src/media/router.d.ts +116 -5
- package/lib/webrtc/src/media/router.js +281 -29
- package/lib/webrtc/src/media/router.js.map +1 -1
- package/lib/webrtc/src/media/rtpReceiver.d.ts +107 -12
- package/lib/webrtc/src/media/rtpReceiver.js +255 -28
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpSender.d.ts +56 -3
- package/lib/webrtc/src/media/rtpSender.js +180 -21
- package/lib/webrtc/src/media/rtpSender.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +94 -1
- package/lib/webrtc/src/media/rtpTransceiver.js +111 -2
- package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
- package/lib/webrtc/src/media/sender/senderBWE.d.ts +2 -1
- package/lib/webrtc/src/media/sender/senderBWE.js +22 -10
- package/lib/webrtc/src/media/sender/senderBWE.js.map +1 -1
- package/lib/webrtc/src/media/track.d.ts +1 -1
- package/lib/webrtc/src/media/track.js +1 -1
- package/lib/webrtc/src/media/track.js.map +1 -1
- package/lib/webrtc/src/negotiation/bundleTopology.d.ts +107 -0
- package/lib/webrtc/src/negotiation/bundleTopology.js +380 -0
- package/lib/webrtc/src/negotiation/bundleTopology.js.map +1 -0
- package/lib/webrtc/src/negotiation/descriptionValidation.d.ts +51 -0
- package/lib/webrtc/src/negotiation/descriptionValidation.js +261 -0
- package/lib/webrtc/src/negotiation/descriptionValidation.js.map +1 -0
- package/lib/webrtc/src/negotiation/iceRestartRequest.d.ts +21 -0
- package/lib/webrtc/src/negotiation/iceRestartRequest.js +61 -0
- package/lib/webrtc/src/negotiation/iceRestartRequest.js.map +1 -0
- package/lib/webrtc/src/negotiation/internalState.d.ts +34 -0
- package/lib/webrtc/src/negotiation/internalState.js +21 -0
- package/lib/webrtc/src/negotiation/internalState.js.map +1 -0
- package/lib/webrtc/src/negotiation/negotiationNeeded.d.ts +44 -0
- package/lib/webrtc/src/negotiation/negotiationNeeded.js +118 -0
- package/lib/webrtc/src/negotiation/negotiationNeeded.js.map +1 -0
- package/lib/webrtc/src/negotiation/remoteCandidates.d.ts +86 -0
- package/lib/webrtc/src/negotiation/remoteCandidates.js +344 -0
- package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -0
- package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +71 -0
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js +398 -0
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -0
- package/lib/webrtc/src/negotiation/transportActivation.d.ts +59 -0
- package/lib/webrtc/src/negotiation/transportActivation.js +345 -0
- package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -0
- package/lib/webrtc/src/negotiationTransaction.d.ts +233 -0
- package/lib/webrtc/src/negotiationTransaction.js +591 -0
- package/lib/webrtc/src/negotiationTransaction.js.map +1 -0
- package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
- package/lib/webrtc/src/nonstandard/index.d.ts +1 -1
- package/lib/webrtc/src/nonstandard/index.js +1 -1
- package/lib/webrtc/src/nonstandard/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/navigator.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/index.d.ts +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.d.ts +2 -2
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +2 -2
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.d.ts +2 -2
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia.d.ts +2 -2
- package/lib/webrtc/src/nonstandard/userMedia.js +2 -2
- package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +132 -237
- package/lib/webrtc/src/peerConnection.js +971 -908
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/polyfill/api.d.ts +5 -5
- package/lib/webrtc/src/polyfill/api.js.map +1 -1
- package/lib/webrtc/src/polyfill/index.js.map +1 -1
- package/lib/webrtc/src/polyfill/install.js +1 -1
- package/lib/webrtc/src/polyfill/install.js.map +1 -1
- package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
- package/lib/webrtc/src/polyfill/registers/mp4Webm.js.map +1 -1
- package/lib/webrtc/src/polyfill/registers/rtpRtcp.js.map +1 -1
- package/lib/webrtc/src/polyfill/selectSettings.js.map +1 -1
- package/lib/webrtc/src/polyfill/sourceIo.js.map +1 -1
- package/lib/webrtc/src/sctpManager.d.ts +66 -2
- package/lib/webrtc/src/sctpManager.js +122 -5
- package/lib/webrtc/src/sctpManager.js.map +1 -1
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/sdpManager.d.ts +55 -11
- package/lib/webrtc/src/sdpManager.js +364 -87
- package/lib/webrtc/src/sdpManager.js.map +1 -1
- package/lib/webrtc/src/secureTransportManager.d.ts +38 -25
- package/lib/webrtc/src/secureTransportManager.js +130 -34
- package/lib/webrtc/src/secureTransportManager.js.map +1 -1
- package/lib/webrtc/src/transceiverManager.d.ts +62 -18
- package/lib/webrtc/src/transceiverManager.js +264 -104
- package/lib/webrtc/src/transceiverManager.js.map +1 -1
- package/lib/webrtc/src/transport/dtls.d.ts +11 -2
- package/lib/webrtc/src/transport/dtls.js +37 -13
- package/lib/webrtc/src/transport/dtls.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +254 -7
- package/lib/webrtc/src/transport/ice.js +608 -52
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/lib/webrtc/src/transport/iceCandidateAttribute.d.ts +98 -0
- package/lib/webrtc/src/transport/iceCandidateAttribute.js +129 -0
- package/lib/webrtc/src/transport/iceCandidateAttribute.js.map +1 -0
- package/lib/webrtc/src/transport/sctp.d.ts +4 -1
- package/lib/webrtc/src/transport/sctp.js +83 -17
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/lib/webrtc/src/utils.d.ts +3 -3
- package/lib/webrtc/src/utils.js +1 -1
- package/lib/webrtc/src/utils.js.map +1 -1
- package/package.json +13 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../../../ice/src/stun/transaction.ts"],"names":[],"mappings":";;;AAyBA,sDAaC;AAMD,kEAmBC;AAOD,sCAEC;AA2MD,0DAaC;AAhSD,uCAA2C;AAC3C,uCAA+C;AAE/C,8CAA+D;AAE/D,8CAIuB;AAEvB,mCAAwD;AAGxD,MAAM,GAAG,GAAG,IAAA,cAAK,EAAC,iDAAiD,CAAC,CAAC;AAErE;;;;;;;;GAQG;AACI,KAAK,UAAU,qBAAqB,CACzC,IAAa,EACb,SAAoB,CAAC;IAErB,MAAM,aAAa,GAAG,IAAA,eAAI,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,IAAI,aAAa,EAAE,CAAC;QAClB,IAAI,MAAM,KAAK,CAAC,IAAI,aAAa,KAAK,MAAM,EAAE,CAAC;YAC7C,MAAM,IAAI,kCAAqB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,mBAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IACrD,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC;AAED;;;GAGG;AACH,SAAgB,2BAA2B,CACzC,wBAA6D,EAC7D,aAAyC;IAEzC,IACE,wBAAwB,KAAK,IAAI;QACjC,OAAO,wBAAwB,KAAK,QAAQ,EAC5C,CAAC;QACD,OAAO,wBAAwB,CAAC;IAClC,CAAC;IACD,oFAAoF;IACpF,MAAM,eAAe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CAAC,OAAO,CAAC,CAAC;YACvD,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QAC3B,CAAC;IACH,CAAC;CACF;AA3LD,kCA2LC;AAED;;;GAGG;AACH,SAAgB,uBAAuB,CACrC,YAAgC,EAChC,wBAA6D,EAC7D,aAAyC;IAEzC,MAAM,OAAO,GAAG,2BAA2B,CACzC,wBAAwB,EACxB,aAAa,CACd,CAAC;IACF,IAAI,YAAY,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;QAC1C,OAAO,CAAC,YAAY,GAAG,YAAY,CAAC;IACtC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { promises as dns } from \"node:dns\";\nimport { SocketAddress, isIP } from \"node:net\";\n\nimport { type Address, Event, debug } from \"../imports/common\";\n\nimport {\n AddressFamilyMismatch,\n TransactionFailed,\n TransactionTimeout,\n} from \"../exceptions\";\nimport type { Protocol, TransactionRequestOptions } from \"../types/model\";\nimport { RETRY_MAX, RETRY_RTO, classes } from \"./const\";\nimport type { Message } from \"./message\";\n\nconst log = debug(\"werift-ice:packages/ice/src/stun/transaction.ts\");\n\n/**\n * Resolve a request target to a concrete IP before creating a Transaction so\n * response source-address checks match the UDP peer address (hostname ≠ IP).\n *\n * `family` is the family of the socket that will carry the request: a\n * hostname resolves only in that family, and an IP literal of the other\n * family throws AddressFamilyMismatch instead of retransmitting into a send\n * that cannot succeed. Family 0 means unknown: no preference, no check.\n */\nexport async function resolveRequestAddress(\n addr: Address,\n family: 0 | 4 | 6 = 0,\n): Promise<Address> {\n const literalFamily = isIP(addr[0]);\n if (literalFamily) {\n if (family !== 0 && literalFamily !== family) {\n throw new AddressFamilyMismatch(addr, family);\n }\n return addr;\n }\n const looked = await dns.lookup(addr[0], { family });\n return [looked.address, addr[1]];\n}\n\n/**\n * Normalize legacy positional args and the options-object form into one shape.\n * Existing callers pass `(retransmissions?, onRequestSent?)`.\n */\nexport function normalizeTransactionOptions(\n retransmissionsOrOptions?: number | TransactionRequestOptions,\n onRequestSent?: (attempt: number) => void,\n): TransactionRequestOptions {\n if (\n retransmissionsOrOptions !== null &&\n typeof retransmissionsOrOptions === \"object\"\n ) {\n return retransmissionsOrOptions;\n }\n // After the object branch, only number | undefined remains (legacy positional API).\n const retransmissions =\n typeof retransmissionsOrOptions === \"number\"\n ? retransmissionsOrOptions\n : undefined;\n return {\n retransmissions,\n onRequestSent,\n };\n}\n\n/**\n * Compare ICE transport addresses (host, port).\n * IPv6 literals are compared in canonical form because the socket reports\n * `::1` even when the peer was configured as `0:0:0:0:0:0:0:1`.\n */\nexport function addressEquals(a: Address, b: Address): boolean {\n return a[1] === b[1] && canonicalHost(a[0]) === canonicalHost(b[0]);\n}\n\n// Only used for comparison; never for the address a packet is sent to,\n// since SocketAddress drops the zone id (`fe80::1%eth0`).\nfunction canonicalHost(host: string): string {\n return isIP(host) === 6\n ? new SocketAddress({ address: host, family: \"ipv6\" }).address\n : host;\n}\n\nexport class Transaction {\n private timeoutDelay: number;\n ended = false;\n private tries = 0;\n private readonly triesMax: number;\n private readonly onResponse = new Event<[Message, Address]>();\n private readonly onRequestSent?: (attempt: number) => void;\n private readonly signal?: AbortSignal;\n private readonly failOnSendError: boolean;\n /** Remote address this transaction was sent to; responses must match. */\n readonly expectedAddr: Address;\n /**\n * When set, protocol layers re-parse the wire response with this key so\n * MESSAGE-INTEGRITY failures are rejected before responseReceived.\n */\n readonly integrityKey?: Buffer;\n private waitTimer?: ReturnType<typeof setTimeout>;\n private waitResolve?: () => void;\n private onAbort?: () => void;\n\n constructor(\n private request: Message,\n private addr: Address,\n private protocol: Protocol,\n retransmissionsOrOptions?: number | TransactionRequestOptions,\n onRequestSent?: (attempt: number) => void,\n ) {\n const options = normalizeTransactionOptions(\n retransmissionsOrOptions,\n onRequestSent,\n );\n // triesMax = initial send + retransmissions\n this.triesMax = 1 + (options.retransmissions ?? RETRY_MAX);\n // responseTimeout is independent of retransmission count (RFC 7675 / 8445)\n this.timeoutDelay = options.responseTimeout ?? RETRY_RTO;\n this.onRequestSent = options.onRequestSent;\n this.signal = options.signal;\n this.failOnSendError = options.failOnSendError ?? false;\n this.expectedAddr = addr;\n this.integrityKey = options.integrityKey;\n }\n\n /**\n * Accept a matching authenticated non-error response from the expected\n * remote address. Wrong address, missing MESSAGE-INTEGRITY (when required),\n * or non-success class is rejected without completing the transaction\n * (wrong address / unauthenticated responses are ignored so we keep waiting).\n */\n responseReceived = (message: Message, addr: Address) => {\n if (this.ended || this.onResponse.length === 0) {\n return;\n }\n\n // RFC 7675 / ICE: only responses from the request's transport address.\n if (!addressEquals(this.expectedAddr, addr)) {\n log(\n \"ignore STUN response from unexpected address\",\n addr,\n \"expected\",\n this.expectedAddr,\n );\n return;\n }\n\n // RFC 7675 authenticated consent: integrityKey requires MESSAGE-INTEGRITY.\n // Wire HMAC is verified by protocol layers via parseMessage(data, key);\n // this presence check is defense-in-depth if responseReceived is called\n // with a constructed Message that skipped the wire re-parse path.\n if (this.integrityKey) {\n const hasIntegrity =\n message.attributesKeys.includes(\"MESSAGE-INTEGRITY\") ||\n message.attributesKeys.includes(\"MESSAGE-INTEGRITY-SHA256\");\n if (!hasIntegrity) {\n log(\n \"ignore unauthenticated STUN response (MESSAGE-INTEGRITY required)\",\n );\n return;\n }\n }\n\n if (message.messageClass === classes.RESPONSE) {\n this.onResponse.execute(message, addr);\n this.onResponse.complete();\n } else {\n // ERROR class or other non-success\n this.onResponse.error(new TransactionFailed(message, addr));\n }\n };\n\n run = async () => {\n try {\n if (this.signal?.aborted) {\n throw new TransactionTimeout();\n }\n this.attachAbortListener();\n this.retry().catch((e) => {\n log(\"retry failed\", e);\n });\n const res = await this.onResponse.asPromise();\n return res;\n } catch (error) {\n throw error;\n } finally {\n this.cancel();\n }\n };\n\n private attachAbortListener() {\n if (!this.signal) {\n return;\n }\n this.onAbort = () => {\n this.failWithTimeout();\n };\n this.signal.addEventListener(\"abort\", this.onAbort, { once: true });\n }\n\n private failWithTimeout() {\n this.fail(new TransactionTimeout());\n }\n\n private fail(error: Error) {\n if (this.ended) {\n return;\n }\n this.ended = true;\n this.clearWait();\n if (this.onResponse.length > 0) {\n this.onResponse.error(error);\n }\n }\n\n private clearWait() {\n if (this.waitTimer !== undefined) {\n clearTimeout(this.waitTimer);\n this.waitTimer = undefined;\n }\n const resolve = this.waitResolve;\n this.waitResolve = undefined;\n resolve?.();\n }\n\n private wait(ms: number): Promise<void> {\n return new Promise((resolve) => {\n if (this.ended || this.signal?.aborted) {\n resolve();\n return;\n }\n this.waitResolve = resolve;\n this.waitTimer = setTimeout(() => {\n this.waitTimer = undefined;\n this.waitResolve = undefined;\n resolve();\n }, ms);\n });\n }\n\n private retry = async () => {\n while (this.tries < this.triesMax && !this.ended) {\n this.onRequestSent?.(this.tries);\n this.protocol.sendStun(this.request, this.addr).catch((e) => {\n log(\"send stun failed\", e);\n if (this.failOnSendError) {\n this.fail(e);\n }\n });\n await this.wait(this.timeoutDelay);\n if (this.ended) {\n break;\n }\n this.timeoutDelay *= 2;\n this.tries++;\n }\n if (this.tries >= this.triesMax && !this.ended) {\n log(`retry failed times:${this.tries} maxLimit:${this.triesMax}`);\n this.failWithTimeout();\n }\n };\n\n cancel() {\n this.ended = true;\n this.clearWait();\n if (this.signal && this.onAbort) {\n this.signal.removeEventListener(\"abort\", this.onAbort);\n this.onAbort = undefined;\n }\n }\n}\n\n/**\n * Build Transaction options for Protocol.request, folding integrityKey into\n * options so response path can re-verify MESSAGE-INTEGRITY.\n */\nexport function buildTransactionOptions(\n integrityKey: Buffer | undefined,\n retransmissionsOrOptions?: number | TransactionRequestOptions,\n onRequestSent?: (attempt: number) => void,\n): TransactionRequestOptions {\n const options = normalizeTransactionOptions(\n retransmissionsOrOptions,\n onRequestSent,\n );\n if (integrityKey && !options.integrityKey) {\n options.integrityKey = integrityKey;\n }\n return options;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../../../ice/src/stun/transaction.ts"],"names":[],"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,aAAyC;IAEzC,MAAM,OAAO,GAAG,2BAA2B,CACzC,wBAAwB,EACxB,aAAa,CACd,CAAC;IACF,IAAI,YAAY,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;QAC1C,OAAO,CAAC,YAAY,GAAG,YAAY,CAAC;IACtC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { promises as dns } from \"node:dns\";\nimport { isIP, SocketAddress } from \"node:net\";\nimport {\n AddressFamilyMismatch,\n TransactionCancelled,\n TransactionFailed,\n TransactionTimeout,\n} from \"../exceptions\";\nimport { type Address, debug, Event } from \"../imports/common\";\nimport type { Protocol, TransactionRequestOptions } from \"../types/model\";\nimport { classes, RETRY_MAX, RETRY_RTO } from \"./const\";\nimport type { Message } from \"./message\";\n\nconst log = debug(\"werift-ice:packages/ice/src/stun/transaction.ts\");\n\n/**\n * Resolve a request target to a concrete IP before creating a Transaction so\n * response source-address checks match the UDP peer address (hostname ≠ IP).\n *\n * `family` is the family of the socket that will carry the request: a\n * hostname resolves only in that family, and an IP literal of the other\n * family throws AddressFamilyMismatch instead of retransmitting into a send\n * that cannot succeed. Family 0 means unknown: no preference, no check.\n */\nexport async function resolveRequestAddress(\n addr: Address,\n family: 0 | 4 | 6 = 0,\n): Promise<Address> {\n const literalFamily = isIP(addr[0]);\n if (literalFamily) {\n if (family !== 0 && literalFamily !== family) {\n throw new AddressFamilyMismatch(addr, family);\n }\n return addr;\n }\n const looked = await dns.lookup(addr[0], { family });\n return [looked.address, addr[1]];\n}\n\n/**\n * Normalize legacy positional args and the options-object form into one shape.\n * Existing callers pass `(retransmissions?, onRequestSent?)`.\n */\nexport function normalizeTransactionOptions(\n retransmissionsOrOptions?: number | TransactionRequestOptions,\n onRequestSent?: (attempt: number) => void,\n): TransactionRequestOptions {\n if (\n retransmissionsOrOptions !== null &&\n typeof retransmissionsOrOptions === \"object\"\n ) {\n return retransmissionsOrOptions;\n }\n // After the object branch, only number | undefined remains (legacy positional API).\n const retransmissions =\n typeof retransmissionsOrOptions === \"number\"\n ? retransmissionsOrOptions\n : undefined;\n return {\n retransmissions,\n onRequestSent,\n };\n}\n\n/**\n * Compare ICE transport addresses (host, port).\n * IPv6 literals are compared in canonical form because the socket reports\n * `::1` even when the peer was configured as `0:0:0:0:0:0:0:1`.\n */\nexport function addressEquals(a: Address, b: Address): boolean {\n return a[1] === b[1] && canonicalHost(a[0]) === canonicalHost(b[0]);\n}\n\n// Only used for comparison; never for the address a packet is sent to,\n// since SocketAddress drops the zone id (`fe80::1%eth0`).\nfunction canonicalHost(host: string): string {\n return isIP(host) === 6\n ? new SocketAddress({ address: host, family: \"ipv6\" }).address\n : host;\n}\n\nexport class Transaction {\n private timeoutDelay: number;\n ended = false;\n private tries = 0;\n private readonly triesMax: number;\n private readonly onResponse = new Event<[Message, Address]>();\n private readonly onRequestSent?: (attempt: number) => void;\n private readonly signal?: AbortSignal;\n private readonly failOnSendError: boolean;\n /** Remote address this transaction was sent to; responses must match. */\n readonly expectedAddr: Address;\n /**\n * When set, protocol layers re-parse the wire response with this key so\n * MESSAGE-INTEGRITY failures are rejected before responseReceived.\n */\n readonly integrityKey?: Buffer;\n private waitTimer?: ReturnType<typeof setTimeout>;\n private waitResolve?: () => void;\n private onAbort?: () => void;\n\n constructor(\n private request: Message,\n private addr: Address,\n private protocol: Protocol,\n retransmissionsOrOptions?: number | TransactionRequestOptions,\n onRequestSent?: (attempt: number) => void,\n ) {\n const options = normalizeTransactionOptions(\n retransmissionsOrOptions,\n onRequestSent,\n );\n // triesMax = initial send + retransmissions\n this.triesMax = 1 + (options.retransmissions ?? RETRY_MAX);\n // responseTimeout is independent of retransmission count (RFC 7675 / 8445)\n this.timeoutDelay = options.responseTimeout ?? RETRY_RTO;\n this.onRequestSent = options.onRequestSent;\n this.signal = options.signal;\n this.failOnSendError = options.failOnSendError ?? false;\n this.expectedAddr = addr;\n this.integrityKey = options.integrityKey;\n }\n\n /**\n * Accept a matching authenticated non-error response from the expected\n * remote address. Wrong address, missing MESSAGE-INTEGRITY (when required),\n * or non-success class is rejected without completing the transaction\n * (wrong address / unauthenticated responses are ignored so we keep waiting).\n */\n responseReceived = (message: Message, addr: Address) => {\n if (this.ended || this.onResponse.length === 0) {\n return;\n }\n\n // RFC 7675 / ICE: only responses from the request's transport address.\n if (!addressEquals(this.expectedAddr, addr)) {\n log(\n \"ignore STUN response from unexpected address\",\n addr,\n \"expected\",\n this.expectedAddr,\n );\n return;\n }\n\n // RFC 7675 authenticated consent: integrityKey requires MESSAGE-INTEGRITY.\n // Wire HMAC is verified by protocol layers via parseMessage(data, key);\n // this presence check is defense-in-depth if responseReceived is called\n // with a constructed Message that skipped the wire re-parse path.\n if (this.integrityKey) {\n const hasIntegrity =\n message.attributesKeys.includes(\"MESSAGE-INTEGRITY\") ||\n message.attributesKeys.includes(\"MESSAGE-INTEGRITY-SHA256\");\n if (!hasIntegrity) {\n log(\n \"ignore unauthenticated STUN response (MESSAGE-INTEGRITY required)\",\n );\n return;\n }\n }\n\n if (message.messageClass === classes.RESPONSE) {\n this.onResponse.execute(message, addr);\n this.onResponse.complete();\n } else {\n // ERROR class or other non-success\n this.onResponse.error(new TransactionFailed(message, addr));\n }\n };\n\n run = async () => {\n try {\n if (this.signal?.aborted) {\n throw new TransactionTimeout();\n }\n this.attachAbortListener();\n this.retry().catch((e) => {\n log(\"retry failed\", e);\n });\n const res = await this.onResponse.asPromise();\n return res;\n } catch (error) {\n throw error;\n } finally {\n this.cancel();\n }\n };\n\n private attachAbortListener() {\n if (!this.signal) {\n return;\n }\n this.onAbort = () => {\n this.failWithTimeout();\n };\n this.signal.addEventListener(\"abort\", this.onAbort, { once: true });\n }\n\n private failWithTimeout() {\n this.fail(new TransactionTimeout());\n }\n\n private fail(error: Error) {\n if (this.ended) {\n return;\n }\n this.ended = true;\n this.clearWait();\n if (this.onResponse.length > 0) {\n this.onResponse.error(error);\n }\n }\n\n private clearWait() {\n if (this.waitTimer !== undefined) {\n clearTimeout(this.waitTimer);\n this.waitTimer = undefined;\n }\n const resolve = this.waitResolve;\n this.waitResolve = undefined;\n resolve?.();\n }\n\n private wait(ms: number): Promise<void> {\n return new Promise((resolve) => {\n if (this.ended || this.signal?.aborted) {\n resolve();\n return;\n }\n this.waitResolve = resolve;\n this.waitTimer = setTimeout(() => {\n this.waitTimer = undefined;\n this.waitResolve = undefined;\n resolve();\n }, ms);\n });\n }\n\n private retry = async () => {\n while (this.tries < this.triesMax && !this.ended) {\n this.onRequestSent?.(this.tries);\n this.protocol.sendStun(this.request, this.addr).catch((e) => {\n log(\"send stun failed\", e);\n if (this.failOnSendError) {\n this.fail(e);\n }\n });\n await this.wait(this.timeoutDelay);\n if (this.ended) {\n break;\n }\n this.timeoutDelay *= 2;\n this.tries++;\n }\n if (this.tries >= this.triesMax && !this.ended) {\n log(`retry failed times:${this.tries} maxLimit:${this.triesMax}`);\n this.failWithTimeout();\n }\n };\n\n /**\n * End the transaction. A `run()` still waiting for a response rejects with\n * `TransactionCancelled`, so whoever awaits it (and its timers) settles\n * instead of waiting forever on a closed protocol.\n */\n cancel() {\n this.fail(new TransactionCancelled());\n this.ended = true;\n this.clearWait();\n if (this.signal && this.onAbort) {\n this.signal.removeEventListener(\"abort\", this.onAbort);\n this.onAbort = undefined;\n }\n }\n}\n\n/**\n * Build Transaction options for Protocol.request, folding integrityKey into\n * options so response path can re-verify MESSAGE-INTEGRITY.\n */\nexport function buildTransactionOptions(\n integrityKey: Buffer | undefined,\n retransmissionsOrOptions?: number | TransactionRequestOptions,\n onRequestSent?: (attempt: number) => void,\n): TransactionRequestOptions {\n const options = normalizeTransactionOptions(\n retransmissionsOrOptions,\n onRequestSent,\n );\n if (integrityKey && !options.integrityKey) {\n options.integrityKey = integrityKey;\n }\n return options;\n}\n"]}
|
|
@@ -3,6 +3,14 @@ import { type Address, Event, type InterfaceAddresses, type TlsConnectionOptions
|
|
|
3
3
|
import { Message } from "../stun/message";
|
|
4
4
|
import { Transaction } from "../stun/transaction";
|
|
5
5
|
import type { Protocol, TransactionRequestOptions } from "../types/model";
|
|
6
|
+
export { TurnRedirectError, type TurnRedirectFailureReason, } from "../exceptions";
|
|
7
|
+
/**
|
|
8
|
+
* Opens a new stream transport to the TURN server named by a 300 (Try
|
|
9
|
+
* Alternate) ALTERNATE-SERVER. `alternateDomain` is the ALTERNATE-DOMAIN
|
|
10
|
+
* attribute, if any, which a TLS transport must validate the certificate
|
|
11
|
+
* against (RFC 8489 §10).
|
|
12
|
+
*/
|
|
13
|
+
export type TurnStreamReconnect = (server: Address, alternateDomain: string | undefined) => Promise<Transport>;
|
|
6
14
|
/** Channel binding state for a single peer transport address. */
|
|
7
15
|
export interface TurnChannel {
|
|
8
16
|
number: number;
|
|
@@ -27,7 +35,11 @@ export declare class StunOverTurnProtocol implements Protocol {
|
|
|
27
35
|
close(): Promise<void>;
|
|
28
36
|
}
|
|
29
37
|
export declare class TurnProtocol implements Protocol {
|
|
30
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* TURN server the allocation is made on; the host may be a hostname.
|
|
40
|
+
* Starts as the configured server and becomes the ALTERNATE-SERVER when
|
|
41
|
+
* an Allocate is redirected with 300 (Try Alternate).
|
|
42
|
+
*/
|
|
31
43
|
server: Address;
|
|
32
44
|
username: string;
|
|
33
45
|
password: string;
|
|
@@ -36,6 +48,17 @@ export declare class TurnProtocol implements Protocol {
|
|
|
36
48
|
options: {
|
|
37
49
|
/**sec */
|
|
38
50
|
channelRefreshTime?: number;
|
|
51
|
+
/**
|
|
52
|
+
* 300 (Try Alternate) redirects followed for one Allocate.
|
|
53
|
+
* Defaults to 3.
|
|
54
|
+
*/
|
|
55
|
+
maxAllocateRedirects?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Reconnects a TCP/TLS transport to an ALTERNATE-SERVER. Without it, a
|
|
58
|
+
* redirect over a stream transport fails with TurnRedirectError
|
|
59
|
+
* ("unsupported-transport"). UDP needs no reconnect.
|
|
60
|
+
*/
|
|
61
|
+
reconnect?: TurnStreamReconnect;
|
|
39
62
|
};
|
|
40
63
|
static type: string;
|
|
41
64
|
readonly type: string;
|
|
@@ -51,6 +74,8 @@ export declare class TurnProtocol implements Protocol {
|
|
|
51
74
|
transactions: {
|
|
52
75
|
[hexId: string]: Transaction;
|
|
53
76
|
};
|
|
77
|
+
/** close() ran: no new transaction starts. */
|
|
78
|
+
private closed;
|
|
54
79
|
private refreshHandle?;
|
|
55
80
|
private channelNumber;
|
|
56
81
|
private channelByAddr;
|
|
@@ -78,13 +103,46 @@ export declare class TurnProtocol implements Protocol {
|
|
|
78
103
|
/** Concrete TURN server address the allocation lives on, once selected. */
|
|
79
104
|
private pinnedServerEndpoint?;
|
|
80
105
|
private serverEndpointSelection?;
|
|
106
|
+
/** TURN server as configured, before any 300 (Try Alternate) redirect. */
|
|
107
|
+
readonly configuredServer: Address;
|
|
81
108
|
constructor(
|
|
82
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* TURN server the allocation is made on; the host may be a hostname.
|
|
111
|
+
* Starts as the configured server and becomes the ALTERNATE-SERVER when
|
|
112
|
+
* an Allocate is redirected with 300 (Try Alternate).
|
|
113
|
+
*/
|
|
83
114
|
server: Address, username: string, password: string, lifetime: number, transport: Transport, options?: {
|
|
84
115
|
/**sec */
|
|
85
116
|
channelRefreshTime?: number;
|
|
117
|
+
/**
|
|
118
|
+
* 300 (Try Alternate) redirects followed for one Allocate.
|
|
119
|
+
* Defaults to 3.
|
|
120
|
+
*/
|
|
121
|
+
maxAllocateRedirects?: number;
|
|
122
|
+
/**
|
|
123
|
+
* Reconnects a TCP/TLS transport to an ALTERNATE-SERVER. Without it, a
|
|
124
|
+
* redirect over a stream transport fails with TurnRedirectError
|
|
125
|
+
* ("unsupported-transport"). UDP needs no reconnect.
|
|
126
|
+
*/
|
|
127
|
+
reconnect?: TurnStreamReconnect;
|
|
86
128
|
});
|
|
87
129
|
connectionMade(): Promise<void>;
|
|
130
|
+
private attachTransport;
|
|
131
|
+
/**
|
|
132
|
+
* Allocate on the current server, following 300 (Try Alternate) to the
|
|
133
|
+
* ALTERNATE-SERVER with the same transport protocol and credentials
|
|
134
|
+
* (RFC 8656 §7.4, RFC 8489 §10). Only Allocate is redirected: an existing
|
|
135
|
+
* allocation lives on one server, so Refresh, CreatePermission and
|
|
136
|
+
* ChannelBind never move.
|
|
137
|
+
*/
|
|
138
|
+
private allocate;
|
|
139
|
+
/**
|
|
140
|
+
* Point the client at an ALTERNATE-SERVER. Authentication state belongs to
|
|
141
|
+
* the previous server, so the alternate starts again with an
|
|
142
|
+
* unauthenticated Allocate and its own 401 realm/nonce; username and
|
|
143
|
+
* password are kept.
|
|
144
|
+
*/
|
|
145
|
+
private switchServer;
|
|
88
146
|
private handleChannelData;
|
|
89
147
|
private handleSTUNMessage;
|
|
90
148
|
private dataReceived;
|
|
@@ -135,6 +193,12 @@ export declare class TurnProtocol implements Protocol {
|
|
|
135
193
|
private ensureChannel;
|
|
136
194
|
private channelBind;
|
|
137
195
|
sendStun(message: Message, addr: Address): Promise<void>;
|
|
196
|
+
/**
|
|
197
|
+
* Release the client: its transactions, refresh timer and socket. Known
|
|
198
|
+
* constraint (as in develop): the allocation is not deleted on the server
|
|
199
|
+
* (no Refresh with lifetime 0), so the server keeps it until its lifetime
|
|
200
|
+
* ends.
|
|
201
|
+
*/
|
|
138
202
|
close(): Promise<void>;
|
|
139
203
|
}
|
|
140
204
|
export interface TurnClientConfig {
|
|
@@ -157,7 +221,12 @@ export interface TurnClientOptions {
|
|
|
157
221
|
* own family always selects the socket. Defaults to 4.
|
|
158
222
|
*/
|
|
159
223
|
udpFamily?: 4 | 6;
|
|
224
|
+
/**
|
|
225
|
+
* Aborting it while the allocation runs closes the client (its socket and
|
|
226
|
+
* transactions) and rejects with `TransactionCancelled`.
|
|
227
|
+
*/
|
|
228
|
+
signal?: AbortSignal;
|
|
160
229
|
}
|
|
161
|
-
export declare function createTurnClient({ address, username, password }: TurnClientConfig, { lifetime, portRange, interfaceAddresses, ssl, tlsOptions, transport: transportType, connectTimeoutMs, udpFamily, }?: TurnClientOptions): Promise<TurnProtocol>;
|
|
230
|
+
export declare function createTurnClient({ address, username, password }: TurnClientConfig, { lifetime, portRange, interfaceAddresses, ssl, tlsOptions, transport: transportType, connectTimeoutMs, udpFamily, signal, }?: TurnClientOptions): Promise<TurnProtocol>;
|
|
162
231
|
export declare function createStunOverTurnClient(config: TurnClientConfig, options?: TurnClientOptions): Promise<StunOverTurnProtocol>;
|
|
163
|
-
export declare function makeIntegrityKey(username: string, realm: string, password: string):
|
|
232
|
+
export declare function makeIntegrityKey(username: string, realm: string, password: string): NonSharedBuffer;
|
|
@@ -1,10 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TurnProtocol = exports.StunOverTurnProtocol = void 0;
|
|
36
|
+
exports.TurnProtocol = exports.StunOverTurnProtocol = exports.TurnRedirectError = void 0;
|
|
4
37
|
exports.createTurnClient = createTurnClient;
|
|
5
38
|
exports.createStunOverTurnClient = createStunOverTurnClient;
|
|
6
39
|
exports.makeIntegrityKey = makeIntegrityKey;
|
|
7
40
|
const node_net_1 = require("node:net");
|
|
41
|
+
const tls = __importStar(require("node:tls"));
|
|
8
42
|
const promises_1 = require("timers/promises");
|
|
9
43
|
const auth_1 = require("../../../ice-server/src/turn/auth");
|
|
10
44
|
const exceptions_1 = require("../exceptions");
|
|
@@ -18,6 +52,10 @@ const log = (0, common_1.debug)("werift-ice:packages/ice/src/turn/protocol.ts");
|
|
|
18
52
|
const DEFAULT_CHANNEL_REFRESH_TIME = 500;
|
|
19
53
|
const DEFAULT_ALLOCATION_LIFETIME = 600;
|
|
20
54
|
const UDP_TRANSPORT = 0x11000000;
|
|
55
|
+
/** 300 (Try Alternate) redirects followed for one Allocate before giving up. */
|
|
56
|
+
const DEFAULT_MAX_ALLOCATE_REDIRECTS = 3;
|
|
57
|
+
var exceptions_2 = require("../exceptions");
|
|
58
|
+
Object.defineProperty(exports, "TurnRedirectError", { enumerable: true, get: function () { return exceptions_2.TurnRedirectError; } });
|
|
21
59
|
function isStreamTransport(transport) {
|
|
22
60
|
return transport.type === "tcp" || transport.type === "tls";
|
|
23
61
|
}
|
|
@@ -154,7 +192,11 @@ Object.defineProperty(StunOverTurnProtocol, "type", {
|
|
|
154
192
|
});
|
|
155
193
|
class TurnProtocol {
|
|
156
194
|
constructor(
|
|
157
|
-
/**
|
|
195
|
+
/**
|
|
196
|
+
* TURN server the allocation is made on; the host may be a hostname.
|
|
197
|
+
* Starts as the configured server and becomes the ALTERNATE-SERVER when
|
|
198
|
+
* an Allocate is redirected with 300 (Try Alternate).
|
|
199
|
+
*/
|
|
158
200
|
server, username, password, lifetime, transport, options = {}) {
|
|
159
201
|
Object.defineProperty(this, "server", {
|
|
160
202
|
enumerable: true,
|
|
@@ -258,6 +300,13 @@ class TurnProtocol {
|
|
|
258
300
|
writable: true,
|
|
259
301
|
value: {}
|
|
260
302
|
});
|
|
303
|
+
/** close() ran: no new transaction starts. */
|
|
304
|
+
Object.defineProperty(this, "closed", {
|
|
305
|
+
enumerable: true,
|
|
306
|
+
configurable: true,
|
|
307
|
+
writable: true,
|
|
308
|
+
value: false
|
|
309
|
+
});
|
|
261
310
|
Object.defineProperty(this, "refreshHandle", {
|
|
262
311
|
enumerable: true,
|
|
263
312
|
configurable: true,
|
|
@@ -350,6 +399,13 @@ class TurnProtocol {
|
|
|
350
399
|
writable: true,
|
|
351
400
|
value: void 0
|
|
352
401
|
});
|
|
402
|
+
/** TURN server as configured, before any 300 (Try Alternate) redirect. */
|
|
403
|
+
Object.defineProperty(this, "configuredServer", {
|
|
404
|
+
enumerable: true,
|
|
405
|
+
configurable: true,
|
|
406
|
+
writable: true,
|
|
407
|
+
value: void 0
|
|
408
|
+
});
|
|
353
409
|
Object.defineProperty(this, "refresh", {
|
|
354
410
|
enumerable: true,
|
|
355
411
|
configurable: true,
|
|
@@ -393,18 +449,13 @@ class TurnProtocol {
|
|
|
393
449
|
});
|
|
394
450
|
}
|
|
395
451
|
});
|
|
452
|
+
this.configuredServer = server;
|
|
396
453
|
this.channelRefreshTime =
|
|
397
454
|
this.options.channelRefreshTime ?? DEFAULT_CHANNEL_REFRESH_TIME;
|
|
398
455
|
}
|
|
399
456
|
async connectionMade() {
|
|
400
|
-
this.
|
|
401
|
-
|
|
402
|
-
};
|
|
403
|
-
const request = new message_1.Message(const_1.methods.ALLOCATE, const_1.classes.REQUEST);
|
|
404
|
-
request
|
|
405
|
-
.setAttribute("LIFETIME", this.lifetime)
|
|
406
|
-
.setAttribute("REQUESTED-TRANSPORT", UDP_TRANSPORT);
|
|
407
|
-
const [response] = await this.requestWithRetry(request, this.server).catch((e) => {
|
|
457
|
+
this.attachTransport();
|
|
458
|
+
const [response] = await this.allocate().catch((e) => {
|
|
408
459
|
log("connect error", e);
|
|
409
460
|
throw e;
|
|
410
461
|
});
|
|
@@ -412,8 +463,106 @@ class TurnProtocol {
|
|
|
412
463
|
this.mappedAddress = response.getAttributeValue("XOR-MAPPED-ADDRESS");
|
|
413
464
|
const exp = response.getAttributeValue("LIFETIME");
|
|
414
465
|
log("connect", this.relayedAddress, this.mappedAddress, { exp });
|
|
466
|
+
// close() ran while the response was in flight: no refresh starts.
|
|
467
|
+
if (this.closed)
|
|
468
|
+
throw new exceptions_1.TransactionCancelled();
|
|
415
469
|
this.refresh(exp);
|
|
416
470
|
}
|
|
471
|
+
attachTransport() {
|
|
472
|
+
this.transport.onData = (data, addr) => {
|
|
473
|
+
this.dataReceived(data, addr);
|
|
474
|
+
};
|
|
475
|
+
this.transport.onError?.subscribe((error) => {
|
|
476
|
+
log("transport error", error);
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Allocate on the current server, following 300 (Try Alternate) to the
|
|
481
|
+
* ALTERNATE-SERVER with the same transport protocol and credentials
|
|
482
|
+
* (RFC 8656 §7.4, RFC 8489 §10). Only Allocate is redirected: an existing
|
|
483
|
+
* allocation lives on one server, so Refresh, CreatePermission and
|
|
484
|
+
* ChannelBind never move.
|
|
485
|
+
*/
|
|
486
|
+
async allocate() {
|
|
487
|
+
const maxRedirects = this.options.maxAllocateRedirects ?? DEFAULT_MAX_ALLOCATE_REDIRECTS;
|
|
488
|
+
/** Servers this Allocate has been sent to, to detect redirect loops. */
|
|
489
|
+
const tried = [];
|
|
490
|
+
for (let redirects = 0;; redirects++) {
|
|
491
|
+
// A fresh request per server: a redirected request may already carry
|
|
492
|
+
// MESSAGE-INTEGRITY for the previous server's realm and nonce.
|
|
493
|
+
const request = new message_1.Message(const_1.methods.ALLOCATE, const_1.classes.REQUEST)
|
|
494
|
+
.setAttribute("LIFETIME", this.lifetime)
|
|
495
|
+
.setAttribute("REQUESTED-TRANSPORT", UDP_TRANSPORT);
|
|
496
|
+
try {
|
|
497
|
+
return await this.requestWithRetry(request, this.server);
|
|
498
|
+
}
|
|
499
|
+
catch (error) {
|
|
500
|
+
const alternate = tryAlternateOf(error, this.transport.addressFamily);
|
|
501
|
+
if (!alternate) {
|
|
502
|
+
throw error;
|
|
503
|
+
}
|
|
504
|
+
// The request has resolved the configured host, so its endpoint is
|
|
505
|
+
// known here: a redirect to the resolved IP of a host name is a loop.
|
|
506
|
+
tried.push(this.server);
|
|
507
|
+
if (this.pinnedServerEndpoint) {
|
|
508
|
+
tried.push(this.pinnedServerEndpoint);
|
|
509
|
+
}
|
|
510
|
+
const failed = error;
|
|
511
|
+
const fail = (reason) => new exceptions_1.TurnRedirectError(reason, this.server, alternate.server, failed);
|
|
512
|
+
if (!alternate.server) {
|
|
513
|
+
throw new exceptions_1.TurnRedirectError("missing-alternate", this.server, undefined, failed);
|
|
514
|
+
}
|
|
515
|
+
if (tried.some((addr) => (0, transaction_1.addressEquals)(addr, alternate.server))) {
|
|
516
|
+
throw fail("loop");
|
|
517
|
+
}
|
|
518
|
+
if (redirects >= maxRedirects) {
|
|
519
|
+
throw fail("too-many-redirects");
|
|
520
|
+
}
|
|
521
|
+
if (isStreamTransport(this.transport) && !this.options.reconnect) {
|
|
522
|
+
throw fail("unsupported-transport");
|
|
523
|
+
}
|
|
524
|
+
log("allocate redirected", this.server, "->", alternate);
|
|
525
|
+
await this.switchServer(alternate);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Point the client at an ALTERNATE-SERVER. Authentication state belongs to
|
|
531
|
+
* the previous server, so the alternate starts again with an
|
|
532
|
+
* unauthenticated Allocate and its own 401 realm/nonce; username and
|
|
533
|
+
* password are kept.
|
|
534
|
+
*/
|
|
535
|
+
async switchServer({ server, domain }) {
|
|
536
|
+
let endpoint;
|
|
537
|
+
if (isStreamTransport(this.transport)) {
|
|
538
|
+
const previous = this.transport;
|
|
539
|
+
previous.onData = () => { };
|
|
540
|
+
await previous.close();
|
|
541
|
+
const reconnected = await this.options.reconnect(server, domain);
|
|
542
|
+
// close() ran while reconnecting: it saw only the closed previous
|
|
543
|
+
// transport, so the new connection is released here.
|
|
544
|
+
if (this.closed) {
|
|
545
|
+
reconnected.onData = () => { };
|
|
546
|
+
await reconnected.close();
|
|
547
|
+
throw new exceptions_1.TransactionCancelled();
|
|
548
|
+
}
|
|
549
|
+
this.transport = reconnected;
|
|
550
|
+
this.tcpBuffer = Buffer.alloc(0);
|
|
551
|
+
this.attachTransport();
|
|
552
|
+
endpoint = this.transport.remoteAddress ?? server;
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
// ALTERNATE-SERVER is an IP literal. One of the other family cannot be
|
|
556
|
+
// reached from this socket (AddressFamilyMismatch).
|
|
557
|
+
endpoint = await (0, transaction_1.resolveRequestAddress)(server, this.transport.addressFamily ?? 0);
|
|
558
|
+
}
|
|
559
|
+
this.server = server;
|
|
560
|
+
this.pinnedServerEndpoint = endpoint;
|
|
561
|
+
this.serverEndpointSelection = Promise.resolve(endpoint);
|
|
562
|
+
this.nonce = undefined;
|
|
563
|
+
this.realm = undefined;
|
|
564
|
+
this.integrityKey = undefined;
|
|
565
|
+
}
|
|
417
566
|
handleChannelData(data) {
|
|
418
567
|
const decoded = (0, frame_1.decodeChannelData)(data);
|
|
419
568
|
const addr = decoded && this.addrByChannel[decoded.channelNumber];
|
|
@@ -507,6 +656,9 @@ class TurnProtocol {
|
|
|
507
656
|
// callers pass explicit options. Peer consent goes through StunOverTurnProtocol.
|
|
508
657
|
// Prefer the TURN session integrity key for response verification.
|
|
509
658
|
const resolvedAddr = await this.resolveRequestTarget(addr);
|
|
659
|
+
// close() ran during the lookup: no transaction starts on a closed client.
|
|
660
|
+
if (this.closed)
|
|
661
|
+
throw new exceptions_1.TransactionCancelled();
|
|
510
662
|
const options = (0, transaction_1.buildTransactionOptions)(this.integrityKey, retransmissionsOrOptions, onRequestSent);
|
|
511
663
|
const transaction = new transaction_1.Transaction(request, resolvedAddr, this, options);
|
|
512
664
|
this.transactions[request.transactionIdHex] = transaction;
|
|
@@ -751,7 +903,20 @@ class TurnProtocol {
|
|
|
751
903
|
async sendStun(message, addr) {
|
|
752
904
|
await this.send(message.bytes, addr);
|
|
753
905
|
}
|
|
906
|
+
/**
|
|
907
|
+
* Release the client: its transactions, refresh timer and socket. Known
|
|
908
|
+
* constraint (as in develop): the allocation is not deleted on the server
|
|
909
|
+
* (no Refresh with lifetime 0), so the server keeps it until its lifetime
|
|
910
|
+
* ends.
|
|
911
|
+
*/
|
|
754
912
|
async close() {
|
|
913
|
+
if (this.closed)
|
|
914
|
+
return;
|
|
915
|
+
this.closed = true;
|
|
916
|
+
// An allocation, refresh or ChannelBind still waiting settles now.
|
|
917
|
+
for (const transaction of Object.values(this.transactions)) {
|
|
918
|
+
transaction.cancel();
|
|
919
|
+
}
|
|
755
920
|
this.refreshHandle?.resolve?.();
|
|
756
921
|
await this.transport.close();
|
|
757
922
|
}
|
|
@@ -783,7 +948,7 @@ function selectTurnUdpSocketType(address, udpFamily) {
|
|
|
783
948
|
}
|
|
784
949
|
return (udpFamily ?? 4) === 6 ? "udp6" : "udp4";
|
|
785
950
|
}
|
|
786
|
-
async function createTurnClient({ address, username, password }, { lifetime, portRange, interfaceAddresses, ssl, tlsOptions, transport: transportType, connectTimeoutMs, udpFamily, } = {}) {
|
|
951
|
+
async function createTurnClient({ address, username, password }, { lifetime, portRange, interfaceAddresses, ssl, tlsOptions, transport: transportType, connectTimeoutMs, udpFamily, signal, } = {}) {
|
|
787
952
|
lifetime ?? (lifetime = DEFAULT_ALLOCATION_LIFETIME);
|
|
788
953
|
transportType ?? (transportType = ssl ? "tls" : "udp");
|
|
789
954
|
const transport = transportType === "udp"
|
|
@@ -794,9 +959,29 @@ async function createTurnClient({ address, username, password }, { lifetime, por
|
|
|
794
959
|
: transportType === "tcp"
|
|
795
960
|
? await common_1.TcpTransport.init(address, { connectTimeoutMs })
|
|
796
961
|
: await common_1.TlsTransport.init(address, tlsOptions, { connectTimeoutMs });
|
|
797
|
-
const turn = new TurnProtocol(address, username, password, lifetime, transport
|
|
962
|
+
const turn = new TurnProtocol(address, username, password, lifetime, transport, {
|
|
963
|
+
reconnect: transportType === "udp"
|
|
964
|
+
? undefined
|
|
965
|
+
: (alternate, alternateDomain) => transportType === "tcp"
|
|
966
|
+
? common_1.TcpTransport.init(alternate, { connectTimeoutMs })
|
|
967
|
+
: common_1.TlsTransport.init(alternate, alternateTlsOptions(address, alternateDomain, tlsOptions), { connectTimeoutMs }),
|
|
968
|
+
});
|
|
969
|
+
// The owner (an ICE agent) closed while the allocation runs: release the
|
|
970
|
+
// socket and its retransmissions now instead of after the allocation.
|
|
971
|
+
const abort = () => {
|
|
972
|
+
turn
|
|
973
|
+
.close()
|
|
974
|
+
.catch((error) => log("failed to close aborted TURN client", error));
|
|
975
|
+
};
|
|
976
|
+
if (signal?.aborted)
|
|
977
|
+
abort();
|
|
978
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
798
979
|
try {
|
|
980
|
+
if (signal?.aborted)
|
|
981
|
+
throw new exceptions_1.TransactionCancelled();
|
|
799
982
|
await turn.connectionMade();
|
|
983
|
+
if (signal?.aborted)
|
|
984
|
+
throw new exceptions_1.TransactionCancelled();
|
|
800
985
|
}
|
|
801
986
|
catch (error) {
|
|
802
987
|
try {
|
|
@@ -807,6 +992,9 @@ async function createTurnClient({ address, username, password }, { lifetime, por
|
|
|
807
992
|
}
|
|
808
993
|
throw error;
|
|
809
994
|
}
|
|
995
|
+
finally {
|
|
996
|
+
signal?.removeEventListener("abort", abort);
|
|
997
|
+
}
|
|
810
998
|
return turn;
|
|
811
999
|
}
|
|
812
1000
|
async function createStunOverTurnClient(config, options = {}) {
|
|
@@ -814,6 +1002,47 @@ async function createStunOverTurnClient(config, options = {}) {
|
|
|
814
1002
|
const turnTransport = new StunOverTurnProtocol(turn);
|
|
815
1003
|
return turnTransport;
|
|
816
1004
|
}
|
|
1005
|
+
/**
|
|
1006
|
+
* TLS options for a connection to an ALTERNATE-SERVER (an IP literal). The
|
|
1007
|
+
* certificate is validated against ALTERNATE-DOMAIN when present, otherwise
|
|
1008
|
+
* against the name the original server would have been validated with
|
|
1009
|
+
* (RFC 8489 §10): `tlsOptions.servername`, else the configured host.
|
|
1010
|
+
*/
|
|
1011
|
+
function alternateTlsOptions(configured, alternateDomain, tlsOptions = {}) {
|
|
1012
|
+
const identity = alternateDomain ?? tlsOptions.servername ?? configured[0];
|
|
1013
|
+
const checkServerIdentity = tlsOptions.checkServerIdentity ?? tls.checkServerIdentity;
|
|
1014
|
+
return {
|
|
1015
|
+
...tlsOptions,
|
|
1016
|
+
// SNI cannot carry an IP literal.
|
|
1017
|
+
servername: (0, node_net_1.isIP)(identity) ? undefined : identity,
|
|
1018
|
+
checkServerIdentity: (_host, cert) => checkServerIdentity(identity, cert),
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
/**
|
|
1022
|
+
* The redirect target of a 300 (Try Alternate) error response, or undefined
|
|
1023
|
+
* for any other error. `server` is undefined when ALTERNATE-SERVER is
|
|
1024
|
+
* missing.
|
|
1025
|
+
*/
|
|
1026
|
+
function tryAlternateOf(error, addressFamily) {
|
|
1027
|
+
if (!(error instanceof exceptions_1.TransactionFailed)) {
|
|
1028
|
+
return undefined;
|
|
1029
|
+
}
|
|
1030
|
+
const [errorCode] = error.response.getAttributeValue("ERROR-CODE") ?? [];
|
|
1031
|
+
if (errorCode !== 300) {
|
|
1032
|
+
return undefined;
|
|
1033
|
+
}
|
|
1034
|
+
// A response may carry one ALTERNATE-SERVER per address family (RFC 8489
|
|
1035
|
+
// §10): take the first one this transport can reach, else the first.
|
|
1036
|
+
const servers = error.response.alternateServers;
|
|
1037
|
+
const reachable = servers.find(([host]) => addressFamily === undefined || ipFamily(host) === addressFamily);
|
|
1038
|
+
return {
|
|
1039
|
+
server: reachable ?? servers[0],
|
|
1040
|
+
domain: error.response.getAttributeValue("ALTERNATE-DOMAIN"),
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
function ipFamily(host) {
|
|
1044
|
+
return host.includes(":") ? 6 : 4;
|
|
1045
|
+
}
|
|
817
1046
|
function makeIntegrityKey(username, realm, password) {
|
|
818
1047
|
return (0, auth_1.makeTurnIntegrityKey)(username, realm, password);
|
|
819
1048
|
}
|