werift 0.27.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +299 -8
- package/lib/common/src/event.d.ts +26 -0
- package/lib/common/src/event.js +87 -2
- package/lib/common/src/event.js.map +1 -1
- package/lib/common/src/network.d.ts +6 -1
- package/lib/common/src/network.js +8 -2
- package/lib/common/src/network.js.map +1 -1
- package/lib/common/src/transport.d.ts +51 -10
- package/lib/common/src/transport.js +35 -9
- package/lib/common/src/transport.js.map +1 -1
- package/lib/dtls/src/alert.d.ts +49 -0
- package/lib/dtls/src/alert.js +103 -0
- package/lib/dtls/src/alert.js.map +1 -0
- package/lib/dtls/src/carrier/direct.d.ts +67 -0
- package/lib/dtls/src/carrier/direct.js +226 -0
- package/lib/dtls/src/carrier/direct.js.map +1 -0
- package/lib/dtls/src/carrier/types.d.ts +81 -0
- package/lib/dtls/src/carrier/types.js +7 -0
- package/lib/dtls/src/carrier/types.js.map +1 -0
- package/lib/dtls/src/cipher/const.d.ts +6 -0
- package/lib/dtls/src/cipher/const.js +13 -2
- package/lib/dtls/src/cipher/const.js.map +1 -1
- package/lib/dtls/src/cipher/prf.js +11 -2
- package/lib/dtls/src/cipher/prf.js.map +1 -1
- package/lib/dtls/src/cipher/tls13/aead.d.ts +41 -0
- package/lib/dtls/src/cipher/tls13/aead.js +128 -0
- package/lib/dtls/src/cipher/tls13/aead.js.map +1 -0
- package/lib/dtls/src/cipher/tls13/hkdf.d.ts +30 -0
- package/lib/dtls/src/cipher/tls13/hkdf.js +76 -0
- package/lib/dtls/src/cipher/tls13/hkdf.js.map +1 -0
- package/lib/dtls/src/cipher/tls13/keySchedule.d.ts +70 -0
- package/lib/dtls/src/cipher/tls13/keySchedule.js +114 -0
- package/lib/dtls/src/cipher/tls13/keySchedule.js.map +1 -0
- package/lib/dtls/src/cipher/tls13/signature.d.ts +30 -0
- package/lib/dtls/src/cipher/tls13/signature.js +149 -0
- package/lib/dtls/src/cipher/tls13/signature.js.map +1 -0
- package/lib/dtls/src/client.d.ts +253 -0
- package/lib/dtls/src/client.js +1269 -14
- package/lib/dtls/src/client.js.map +1 -1
- package/lib/dtls/src/context/dtls.d.ts +47 -0
- package/lib/dtls/src/context/dtls.js +121 -0
- package/lib/dtls/src/context/dtls.js.map +1 -1
- package/lib/dtls/src/context/transport.d.ts +30 -1
- package/lib/dtls/src/context/transport.js +67 -3
- package/lib/dtls/src/context/transport.js.map +1 -1
- package/lib/dtls/src/engine/v1_3/connection-base.d.ts +520 -0
- package/lib/dtls/src/engine/v1_3/connection-base.js +1644 -0
- package/lib/dtls/src/engine/v1_3/connection-base.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/connection.d.ts +181 -0
- package/lib/dtls/src/engine/v1_3/connection.js +680 -0
- package/lib/dtls/src/engine/v1_3/connection.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/early-data-buffer.d.ts +38 -0
- package/lib/dtls/src/engine/v1_3/early-data-buffer.js +166 -0
- package/lib/dtls/src/engine/v1_3/early-data-buffer.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/certificate.d.ts +4 -0
- package/lib/dtls/src/engine/v1_3/flight/certificate.js +62 -0
- package/lib/dtls/src/engine/v1_3/flight/certificate.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight1.d.ts +8 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight1.js +119 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight1.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight4.d.ts +8 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight4.js +251 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight4.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight5.d.ts +5 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight5.js +99 -0
- package/lib/dtls/src/engine/v1_3/flight/client/flight5.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/dispatch.d.ts +12 -0
- package/lib/dtls/src/engine/v1_3/flight/dispatch.js +138 -0
- package/lib/dtls/src/engine/v1_3/flight/dispatch.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/extensions.d.ts +13 -0
- package/lib/dtls/src/engine/v1_3/flight/extensions.js +46 -0
- package/lib/dtls/src/engine/v1_3/flight/extensions.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/finished.d.ts +6 -0
- package/lib/dtls/src/engine/v1_3/flight/finished.js +16 -0
- package/lib/dtls/src/engine/v1_3/flight/finished.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/post-hs.d.ts +12 -0
- package/lib/dtls/src/engine/v1_3/flight/post-hs.js +94 -0
- package/lib/dtls/src/engine/v1_3/flight/post-hs.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight2.d.ts +21 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight2.js +227 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight2.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight4.d.ts +6 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight4.js +455 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight4.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight5.d.ts +5 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight5.js +48 -0
- package/lib/dtls/src/engine/v1_3/flight/server/flight5.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/flight-tx.d.ts +119 -0
- package/lib/dtls/src/engine/v1_3/flight-tx.js +782 -0
- package/lib/dtls/src/engine/v1_3/flight-tx.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/host.d.ts +86 -0
- package/lib/dtls/src/engine/v1_3/host.js +11 -0
- package/lib/dtls/src/engine/v1_3/host.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/record-rx.d.ts +77 -0
- package/lib/dtls/src/engine/v1_3/record-rx.js +818 -0
- package/lib/dtls/src/engine/v1_3/record-rx.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/transcript.d.ts +22 -0
- package/lib/dtls/src/engine/v1_3/transcript.js +65 -0
- package/lib/dtls/src/engine/v1_3/transcript.js.map +1 -0
- package/lib/dtls/src/engine/v1_3/types.d.ts +169 -0
- package/lib/dtls/src/engine/v1_3/types.js +113 -0
- package/lib/dtls/src/engine/v1_3/types.js.map +1 -0
- package/lib/dtls/src/flight/client/flight1.d.ts +7 -1
- package/lib/dtls/src/flight/client/flight1.js +9 -3
- package/lib/dtls/src/flight/client/flight1.js.map +1 -1
- package/lib/dtls/src/flight/client/flight3.d.ts +8 -0
- package/lib/dtls/src/flight/client/flight3.js +24 -4
- package/lib/dtls/src/flight/client/flight3.js.map +1 -1
- package/lib/dtls/src/flight/client/flight5.js +17 -2
- package/lib/dtls/src/flight/client/flight5.js.map +1 -1
- package/lib/dtls/src/flight/flight.d.ts +21 -0
- package/lib/dtls/src/flight/flight.js +119 -9
- package/lib/dtls/src/flight/flight.js.map +1 -1
- package/lib/dtls/src/flight/server/commitClientHello.d.ts +35 -0
- package/lib/dtls/src/flight/server/commitClientHello.js +149 -0
- package/lib/dtls/src/flight/server/commitClientHello.js.map +1 -0
- package/lib/dtls/src/flight/server/flight2.d.ts +12 -3
- package/lib/dtls/src/flight/server/flight2.js +29 -105
- package/lib/dtls/src/flight/server/flight2.js.map +1 -1
- package/lib/dtls/src/flight/server/flight4.js +14 -2
- package/lib/dtls/src/flight/server/flight4.js.map +1 -1
- package/lib/dtls/src/flight/server/flight6.js +12 -1
- package/lib/dtls/src/flight/server/flight6.js.map +1 -1
- package/lib/dtls/src/handshake/const.d.ts +10 -0
- package/lib/dtls/src/handshake/const.js +10 -0
- package/lib/dtls/src/handshake/const.js.map +1 -1
- package/lib/dtls/src/handshake/extensions/cookie.d.ts +113 -0
- package/lib/dtls/src/handshake/extensions/cookie.js +326 -0
- package/lib/dtls/src/handshake/extensions/cookie.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/ids.d.ts +7 -0
- package/lib/dtls/src/handshake/extensions/ids.js +11 -0
- package/lib/dtls/src/handshake/extensions/ids.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/keyShare.d.ts +28 -0
- package/lib/dtls/src/handshake/extensions/keyShare.js +156 -0
- package/lib/dtls/src/handshake/extensions/keyShare.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/signatureAlgorithms.d.ts +27 -0
- package/lib/dtls/src/handshake/extensions/signatureAlgorithms.js +67 -0
- package/lib/dtls/src/handshake/extensions/signatureAlgorithms.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/supportedVersions.d.ts +20 -0
- package/lib/dtls/src/handshake/extensions/supportedVersions.js +90 -0
- package/lib/dtls/src/handshake/extensions/supportedVersions.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/unique.d.ts +7 -0
- package/lib/dtls/src/handshake/extensions/unique.js +19 -0
- package/lib/dtls/src/handshake/extensions/unique.js.map +1 -0
- package/lib/dtls/src/handshake/extensions/useSrtp.d.ts +26 -3
- package/lib/dtls/src/handshake/extensions/useSrtp.js +68 -12
- package/lib/dtls/src/handshake/extensions/useSrtp.js.map +1 -1
- package/lib/dtls/src/handshake/message/tls13/ack.d.ts +50 -0
- package/lib/dtls/src/handshake/message/tls13/ack.js +107 -0
- package/lib/dtls/src/handshake/message/tls13/ack.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/certificate.d.ts +17 -0
- package/lib/dtls/src/handshake/message/tls13/certificate.js +112 -0
- package/lib/dtls/src/handshake/message/tls13/certificate.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/certificateRequest.d.ts +17 -0
- package/lib/dtls/src/handshake/message/tls13/certificateRequest.js +99 -0
- package/lib/dtls/src/handshake/message/tls13/certificateRequest.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/certificateVerify.d.ts +21 -0
- package/lib/dtls/src/handshake/message/tls13/certificateVerify.js +77 -0
- package/lib/dtls/src/handshake/message/tls13/certificateVerify.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/encryptedExtensions.d.ts +19 -0
- package/lib/dtls/src/handshake/message/tls13/encryptedExtensions.js +56 -0
- package/lib/dtls/src/handshake/message/tls13/encryptedExtensions.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/keyUpdate.d.ts +13 -0
- package/lib/dtls/src/handshake/message/tls13/keyUpdate.js +54 -0
- package/lib/dtls/src/handshake/message/tls13/keyUpdate.js.map +1 -0
- package/lib/dtls/src/handshake/message/tls13/newSessionTicket.d.ts +33 -0
- package/lib/dtls/src/handshake/message/tls13/newSessionTicket.js +158 -0
- package/lib/dtls/src/handshake/message/tls13/newSessionTicket.js.map +1 -0
- package/lib/dtls/src/handshake/random.d.ts +14 -0
- package/lib/dtls/src/handshake/random.js +24 -0
- package/lib/dtls/src/handshake/random.js.map +1 -1
- package/lib/dtls/src/handshake/validation.d.ts +26 -0
- package/lib/dtls/src/handshake/validation.js +32 -0
- package/lib/dtls/src/handshake/validation.js.map +1 -0
- package/lib/dtls/src/index.d.ts +8 -1
- package/lib/dtls/src/index.js +125 -44
- package/lib/dtls/src/index.js.map +1 -1
- package/lib/dtls/src/internal.d.ts +7 -0
- package/lib/dtls/src/internal.js +57 -0
- package/lib/dtls/src/internal.js.map +1 -0
- package/lib/dtls/src/peer.d.ts +49 -0
- package/lib/dtls/src/peer.js +54 -0
- package/lib/dtls/src/peer.js.map +1 -0
- package/lib/dtls/src/record/antiReplayWindow.d.ts +33 -0
- package/lib/dtls/src/record/antiReplayWindow.js +119 -0
- package/lib/dtls/src/record/antiReplayWindow.js.map +1 -0
- package/lib/dtls/src/record/const.d.ts +15 -0
- package/lib/dtls/src/record/const.js +15 -1
- package/lib/dtls/src/record/const.js.map +1 -1
- package/lib/dtls/src/record/message/fragment.d.ts +0 -2
- package/lib/dtls/src/record/message/fragment.js +36 -17
- package/lib/dtls/src/record/message/fragment.js.map +1 -1
- package/lib/dtls/src/record/message/reassembler.d.ts +62 -0
- package/lib/dtls/src/record/message/reassembler.js +249 -0
- package/lib/dtls/src/record/message/reassembler.js.map +1 -0
- package/lib/dtls/src/record/receive.d.ts +6 -0
- package/lib/dtls/src/record/receive.js +58 -19
- package/lib/dtls/src/record/receive.js.map +1 -1
- package/lib/dtls/src/record/v1_3/header.d.ts +34 -0
- package/lib/dtls/src/record/v1_3/header.js +95 -0
- package/lib/dtls/src/record/v1_3/header.js.map +1 -0
- package/lib/dtls/src/record/v1_3/record.d.ts +133 -0
- package/lib/dtls/src/record/v1_3/record.js +370 -0
- package/lib/dtls/src/record/v1_3/record.js.map +1 -0
- package/lib/dtls/src/retransmission.d.ts +26 -0
- package/lib/dtls/src/retransmission.js +39 -0
- package/lib/dtls/src/retransmission.js.map +1 -0
- package/lib/dtls/src/server.d.ts +38 -0
- package/lib/dtls/src/server.js +382 -17
- package/lib/dtls/src/server.js.map +1 -1
- package/lib/dtls/src/socket.d.ts +487 -11
- package/lib/dtls/src/socket.js +1359 -70
- package/lib/dtls/src/socket.js.map +1 -1
- package/lib/dtls/src/version.d.ts +89 -0
- package/lib/dtls/src/version.js +204 -0
- package/lib/dtls/src/version.js.map +1 -0
- package/lib/ice/src/candidateError.d.ts +155 -0
- package/lib/ice/src/candidateError.js +246 -0
- package/lib/ice/src/candidateError.js.map +1 -0
- package/lib/ice/src/candidateGatherer.d.ts +127 -0
- package/lib/ice/src/candidateGatherer.js +745 -0
- package/lib/ice/src/candidateGatherer.js.map +1 -0
- package/lib/ice/src/consent.d.ts +126 -0
- package/lib/ice/src/consent.js +470 -0
- package/lib/ice/src/consent.js.map +1 -0
- package/lib/ice/src/dns/lookup.d.ts +10 -0
- package/lib/ice/src/dns/lookup.js +130 -3
- package/lib/ice/src/dns/lookup.js.map +1 -1
- package/lib/ice/src/exceptions.d.ts +9 -0
- package/lib/ice/src/exceptions.js +14 -1
- package/lib/ice/src/exceptions.js.map +1 -1
- package/lib/ice/src/failover.d.ts +270 -0
- package/lib/ice/src/failover.js +674 -0
- package/lib/ice/src/failover.js.map +1 -0
- package/lib/ice/src/gatheringError.d.ts +28 -0
- package/lib/ice/src/gatheringError.js +17 -0
- package/lib/ice/src/gatheringError.js.map +1 -0
- package/lib/ice/src/ice.d.ts +486 -78
- package/lib/ice/src/ice.js +2415 -1129
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/iceBase.d.ts +404 -14
- package/lib/ice/src/iceBase.js +251 -38
- package/lib/ice/src/iceBase.js.map +1 -1
- package/lib/ice/src/index.d.ts +3 -0
- package/lib/ice/src/index.js +5 -1
- package/lib/ice/src/index.js.map +1 -1
- package/lib/ice/src/internal/checkMessages.d.ts +41 -0
- package/lib/ice/src/internal/checkMessages.js +63 -0
- package/lib/ice/src/internal/checkMessages.js.map +1 -0
- package/lib/ice/src/internal/datagram.d.ts +37 -0
- package/lib/ice/src/internal/datagram.js +45 -0
- package/lib/ice/src/internal/datagram.js.map +1 -0
- package/lib/ice/src/internal/defaultRoute.d.ts +20 -0
- package/lib/ice/src/internal/defaultRoute.js +134 -0
- package/lib/ice/src/internal/defaultRoute.js.map +1 -0
- package/lib/ice/src/internal/hostInterfaces.d.ts +28 -0
- package/lib/ice/src/internal/hostInterfaces.js +89 -0
- package/lib/ice/src/internal/hostInterfaces.js.map +1 -0
- package/lib/ice/src/internal/hostPreference.d.ts +24 -0
- package/lib/ice/src/internal/hostPreference.js +38 -0
- package/lib/ice/src/internal/hostPreference.js.map +1 -0
- package/lib/ice/src/internal/resolveHostAddresses.d.ts +56 -8
- package/lib/ice/src/internal/resolveHostAddresses.js +127 -24
- package/lib/ice/src/internal/resolveHostAddresses.js.map +1 -1
- package/lib/ice/src/internal/selectAddresses.d.ts +27 -0
- package/lib/ice/src/internal/selectAddresses.js +37 -18
- package/lib/ice/src/internal/selectAddresses.js.map +1 -1
- package/lib/ice/src/internal/sped-bind.d.ts +44 -0
- package/lib/ice/src/internal/sped-bind.js +53 -0
- package/lib/ice/src/internal/sped-bind.js.map +1 -0
- package/lib/ice/src/internal/sped-binding-cache.d.ts +27 -0
- package/lib/ice/src/internal/sped-binding-cache.js +102 -0
- package/lib/ice/src/internal/sped-binding-cache.js.map +1 -0
- package/lib/ice/src/internal/sped.d.ts +15 -0
- package/lib/ice/src/internal/sped.js +62 -0
- package/lib/ice/src/internal/sped.js.map +1 -0
- package/lib/ice/src/nomination/regularNomination.d.ts +200 -0
- package/lib/ice/src/nomination/regularNomination.js +311 -0
- package/lib/ice/src/nomination/regularNomination.js.map +1 -0
- package/lib/ice/src/nomination/selectionController.d.ts +111 -0
- package/lib/ice/src/nomination/selectionController.js +172 -0
- package/lib/ice/src/nomination/selectionController.js.map +1 -0
- package/lib/ice/src/nomination/selectionReplacement.d.ts +178 -0
- package/lib/ice/src/nomination/selectionReplacement.js +429 -0
- package/lib/ice/src/nomination/selectionReplacement.js.map +1 -0
- package/lib/ice/src/provisional.d.ts +139 -0
- package/lib/ice/src/provisional.js +468 -0
- package/lib/ice/src/provisional.js.map +1 -0
- package/lib/ice/src/sped/draft00/codec.d.ts +20 -0
- package/lib/ice/src/sped/draft00/codec.js +59 -0
- package/lib/ice/src/sped/draft00/codec.js.map +1 -0
- package/lib/ice/src/sped/draft00/constants.d.ts +14 -0
- package/lib/ice/src/sped/draft00/constants.js +18 -0
- package/lib/ice/src/sped/draft00/constants.js.map +1 -0
- package/lib/ice/src/sped/draft00/index.d.ts +6 -0
- package/lib/ice/src/sped/draft00/index.js +26 -0
- package/lib/ice/src/sped/draft00/index.js.map +1 -0
- package/lib/ice/src/sped/draft00/mtu.d.ts +38 -0
- package/lib/ice/src/sped/draft00/mtu.js +96 -0
- package/lib/ice/src/sped/draft00/mtu.js.map +1 -0
- package/lib/ice/src/sped/draft00/session.d.ts +86 -0
- package/lib/ice/src/sped/draft00/session.js +353 -0
- package/lib/ice/src/sped/draft00/session.js.map +1 -0
- package/lib/ice/src/sped/draft00/types.d.ts +16 -0
- package/lib/ice/src/sped/draft00/types.js +3 -0
- package/lib/ice/src/sped/draft00/types.js.map +1 -0
- package/lib/ice/src/sped/runtime.d.ts +188 -0
- package/lib/ice/src/sped/runtime.js +643 -0
- package/lib/ice/src/sped/runtime.js.map +1 -0
- package/lib/ice/src/stun/protocol.d.ts +38 -2
- package/lib/ice/src/stun/protocol.js +107 -21
- package/lib/ice/src/stun/protocol.js.map +1 -1
- package/lib/ice/src/stun/rawAttributeValue.d.ts +1 -0
- package/lib/ice/src/stun/rawAttributeValue.js +6 -0
- package/lib/ice/src/stun/rawAttributeValue.js.map +1 -0
- package/lib/ice/src/stun/tcpProtocol.d.ts +2 -1
- package/lib/ice/src/stun/tcpProtocol.js +21 -9
- package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
- package/lib/ice/src/stun/transaction.d.ts +4 -0
- package/lib/ice/src/stun/transaction.js +27 -2
- package/lib/ice/src/stun/transaction.js.map +1 -1
- package/lib/ice/src/turn/protocol.d.ts +23 -4
- package/lib/ice/src/turn/protocol.js +99 -11
- package/lib/ice/src/turn/protocol.js.map +1 -1
- package/lib/ice/src/types/model.d.ts +25 -5
- package/lib/ice/src/types/model.js.map +1 -1
- package/lib/ice/src/utils.d.ts +13 -0
- package/lib/ice/src/utils.js +13 -0
- package/lib/ice/src/utils.js.map +1 -1
- package/lib/ice-server/src/stun/attributes.js +4 -0
- package/lib/ice-server/src/stun/attributes.js.map +1 -1
- package/lib/ice-server/src/stun/const.d.ts +20 -1
- package/lib/ice-server/src/stun/const.js +9 -1
- package/lib/ice-server/src/stun/const.js.map +1 -1
- package/lib/ice-server/src/stun/message.d.ts +43 -3
- package/lib/ice-server/src/stun/message.js +258 -40
- package/lib/ice-server/src/stun/message.js.map +1 -1
- package/lib/ice-server/src/stun/rawAttributeValue.d.ts +6 -0
- package/lib/ice-server/src/stun/rawAttributeValue.js +12 -0
- package/lib/ice-server/src/stun/rawAttributeValue.js.map +1 -0
- package/lib/index.mjs +47427 -25303
- package/lib/nonstandard/index.mjs +3076 -1318
- package/lib/polyfill/dom.mjs +40430 -18730
- package/lib/polyfill/index.mjs +40333 -18639
- package/lib/rtp/src/extra/processor/fsRetry.d.ts +20 -0
- package/lib/rtp/src/extra/processor/fsRetry.js +73 -0
- package/lib/rtp/src/extra/processor/fsRetry.js.map +1 -0
- package/lib/rtp/src/extra/processor/webm.d.ts +6 -0
- package/lib/rtp/src/extra/processor/webm.js +6 -2
- package/lib/rtp/src/extra/processor/webm.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmCallback.d.ts +11 -0
- package/lib/rtp/src/extra/processor/webmCallback.js +23 -31
- package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmFileWriter.d.ts +24 -0
- package/lib/rtp/src/extra/processor/webmFileWriter.js +94 -0
- package/lib/rtp/src/extra/processor/webmFileWriter.js.map +1 -0
- package/lib/rtp/src/index.d.ts +1 -0
- package/lib/rtp/src/index.js +1 -0
- package/lib/rtp/src/index.js.map +1 -1
- package/lib/rtp/src/rtp/continuity.d.ts +14 -1
- package/lib/rtp/src/rtp/continuity.js +24 -4
- package/lib/rtp/src/rtp/continuity.js.map +1 -1
- package/lib/rtp/src/rtp/timelineRewriter.d.ts +178 -0
- package/lib/rtp/src/rtp/timelineRewriter.js +417 -0
- package/lib/rtp/src/rtp/timelineRewriter.js.map +1 -0
- package/lib/sctp/src/chunk.d.ts +5 -0
- package/lib/sctp/src/chunk.js +10 -0
- package/lib/sctp/src/chunk.js.map +1 -1
- package/lib/sctp/src/index.d.ts +1 -1
- package/lib/sctp/src/index.js +4 -1
- package/lib/sctp/src/index.js.map +1 -1
- package/lib/sctp/src/sctp.d.ts +86 -5
- package/lib/sctp/src/sctp.js +354 -75
- package/lib/sctp/src/sctp.js.map +1 -1
- package/lib/webrtc/src/api/compatibilityOptions.d.ts +43 -0
- package/lib/webrtc/src/api/compatibilityOptions.js +43 -0
- package/lib/webrtc/src/api/compatibilityOptions.js.map +1 -0
- package/lib/webrtc/src/api/peerConfig.d.ts +547 -36
- package/lib/webrtc/src/api/peerConfig.js +187 -26
- package/lib/webrtc/src/api/peerConfig.js.map +1 -1
- package/lib/webrtc/src/api/peerConnectionEvents.d.ts +87 -2
- package/lib/webrtc/src/api/peerConnectionEvents.js +105 -1
- package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -1
- package/lib/webrtc/src/dataChannel.d.ts +122 -10
- package/lib/webrtc/src/dataChannel.js +214 -20
- package/lib/webrtc/src/dataChannel.js.map +1 -1
- package/lib/webrtc/src/helper.d.ts +8 -0
- package/lib/webrtc/src/helper.js +40 -4
- package/lib/webrtc/src/helper.js.map +1 -1
- package/lib/webrtc/src/media/codecCompatibility.d.ts +87 -1
- package/lib/webrtc/src/media/codecCompatibility.js +338 -12
- package/lib/webrtc/src/media/codecCompatibility.js.map +1 -1
- package/lib/webrtc/src/media/domEventTarget.d.ts +55 -0
- package/lib/webrtc/src/media/domEventTarget.js +216 -0
- package/lib/webrtc/src/media/domEventTarget.js.map +1 -0
- package/lib/webrtc/src/media/index.d.ts +2 -0
- package/lib/webrtc/src/media/index.js +1 -0
- package/lib/webrtc/src/media/index.js.map +1 -1
- package/lib/webrtc/src/media/parameters.d.ts +5 -0
- package/lib/webrtc/src/media/parameters.js +10 -0
- package/lib/webrtc/src/media/parameters.js.map +1 -1
- package/lib/webrtc/src/media/receiver/nack.d.ts +43 -10
- package/lib/webrtc/src/media/receiver/nack.js +245 -88
- package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
- package/lib/webrtc/src/media/receiver/receiverTwcc.d.ts +10 -0
- package/lib/webrtc/src/media/receiver/receiverTwcc.js +4 -10
- package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
- package/lib/webrtc/src/media/router.d.ts +245 -51
- package/lib/webrtc/src/media/router.js +702 -237
- package/lib/webrtc/src/media/router.js.map +1 -1
- package/lib/webrtc/src/media/routing/pendingRoutes.d.ts +26 -0
- package/lib/webrtc/src/media/routing/pendingRoutes.js +48 -0
- package/lib/webrtc/src/media/routing/pendingRoutes.js.map +1 -0
- package/lib/webrtc/src/media/routing/ridRouting.d.ts +37 -0
- package/lib/webrtc/src/media/routing/ridRouting.js +74 -0
- package/lib/webrtc/src/media/routing/ridRouting.js.map +1 -0
- package/lib/webrtc/src/media/routing/routeTable.d.ts +60 -0
- package/lib/webrtc/src/media/routing/routeTable.js +95 -0
- package/lib/webrtc/src/media/routing/routeTable.js.map +1 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.d.ts +34 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.js +165 -0
- package/lib/webrtc/src/media/routing/rtcpRouting.js.map +1 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.d.ts +55 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.js +117 -0
- package/lib/webrtc/src/media/routing/unknownSsrc.js.map +1 -0
- package/lib/webrtc/src/media/rtpReceiver.d.ts +277 -5
- package/lib/webrtc/src/media/rtpReceiver.js +826 -36
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpSender.d.ts +8 -1
- package/lib/webrtc/src/media/rtpSender.js +13 -6
- package/lib/webrtc/src/media/rtpSender.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +47 -11
- package/lib/webrtc/src/media/rtpTransceiver.js +95 -11
- package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
- package/lib/webrtc/src/media/sender/senderReportHistory.d.ts +51 -0
- package/lib/webrtc/src/media/sender/senderReportHistory.js +111 -0
- package/lib/webrtc/src/media/sender/senderReportHistory.js.map +1 -0
- package/lib/webrtc/src/media/sender/senderStats.d.ts +6 -5
- package/lib/webrtc/src/media/sender/senderStats.js +14 -19
- package/lib/webrtc/src/media/sender/senderStats.js.map +1 -1
- package/lib/webrtc/src/media/stats.d.ts +13 -0
- package/lib/webrtc/src/media/stats.js.map +1 -1
- package/lib/webrtc/src/media/track.d.ts +112 -11
- package/lib/webrtc/src/media/track.js +250 -19
- package/lib/webrtc/src/media/track.js.map +1 -1
- package/lib/webrtc/src/media/trackConstraints.d.ts +80 -0
- package/lib/webrtc/src/media/trackConstraints.js +141 -0
- package/lib/webrtc/src/media/trackConstraints.js.map +1 -0
- package/lib/webrtc/src/negotiation/internalState.d.ts +0 -4
- package/lib/webrtc/src/negotiation/internalState.js +0 -11
- package/lib/webrtc/src/negotiation/internalState.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.d.ts +20 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.js +29 -1
- package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -1
- package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +23 -6
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js +46 -22
- package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -1
- package/lib/webrtc/src/negotiation/transceiverPairing.d.ts +1 -0
- package/lib/webrtc/src/negotiation/transceiverPairing.js +62 -0
- package/lib/webrtc/src/negotiation/transceiverPairing.js.map +1 -0
- package/lib/webrtc/src/negotiation/transportActivation.d.ts +12 -1
- package/lib/webrtc/src/negotiation/transportActivation.js +133 -11
- package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -1
- package/lib/webrtc/src/negotiationTransaction.d.ts +57 -5
- package/lib/webrtc/src/negotiationTransaction.js +134 -10
- package/lib/webrtc/src/negotiationTransaction.js.map +1 -1
- package/lib/webrtc/src/nonstandard/dummyMedia.d.ts +6 -0
- package/lib/webrtc/src/nonstandard/dummyMedia.js +14 -19
- package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
- package/lib/webrtc/src/nonstandard/navigator.d.ts +1 -1
- package/lib/webrtc/src/nonstandard/recorder/index.js +5 -1
- package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.d.ts +6 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +31 -2
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.d.ts +16 -0
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.js +25 -0
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia.js +6 -13
- package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +106 -11
- package/lib/webrtc/src/peerConnection.js +370 -36
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/polyfill/api.d.ts +2 -1
- package/lib/webrtc/src/polyfill/api.js +3 -3
- package/lib/webrtc/src/polyfill/api.js.map +1 -1
- package/lib/webrtc/src/polyfill/dom.d.ts +21 -7
- package/lib/webrtc/src/polyfill/dom.js +15 -0
- package/lib/webrtc/src/polyfill/dom.js.map +1 -1
- package/lib/webrtc/src/polyfill/globals.d.ts +8 -3
- package/lib/webrtc/src/polyfill/globals.js.map +1 -1
- package/lib/webrtc/src/polyfill/index.d.ts +1 -1
- package/lib/webrtc/src/polyfill/index.js +1 -1
- package/lib/webrtc/src/polyfill/index.js.map +1 -1
- package/lib/webrtc/src/polyfill/install.d.ts +5 -1
- package/lib/webrtc/src/polyfill/install.js +4 -2
- package/lib/webrtc/src/polyfill/install.js.map +1 -1
- package/lib/webrtc/src/polyfill/mediaDevices.js +28 -4
- package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
- package/lib/webrtc/src/polyfill/peerConnectionConfig.d.ts +6 -0
- package/lib/webrtc/src/polyfill/peerConnectionConfig.js +15 -4
- package/lib/webrtc/src/polyfill/peerConnectionConfig.js.map +1 -1
- package/lib/webrtc/src/polyfill/selectSettings.d.ts +4 -14
- package/lib/webrtc/src/polyfill/selectSettings.js +10 -106
- package/lib/webrtc/src/polyfill/selectSettings.js.map +1 -1
- package/lib/webrtc/src/polyfill/sourceIo.d.ts +1 -2
- package/lib/webrtc/src/polyfill/sourceIo.js +6 -6
- package/lib/webrtc/src/polyfill/sourceIo.js.map +1 -1
- package/lib/webrtc/src/sctpManager.d.ts +31 -18
- package/lib/webrtc/src/sctpManager.js +162 -38
- package/lib/webrtc/src/sctpManager.js.map +1 -1
- package/lib/webrtc/src/sdp.d.ts +107 -2
- package/lib/webrtc/src/sdp.js +223 -17
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/sdpManager.d.ts +101 -10
- package/lib/webrtc/src/sdpManager.js +236 -14
- package/lib/webrtc/src/sdpManager.js.map +1 -1
- package/lib/webrtc/src/secureTransportManager.d.ts +49 -3
- package/lib/webrtc/src/secureTransportManager.js +166 -12
- package/lib/webrtc/src/secureTransportManager.js.map +1 -1
- package/lib/webrtc/src/transceiverManager.d.ts +87 -6
- package/lib/webrtc/src/transceiverManager.js +272 -51
- package/lib/webrtc/src/transceiverManager.js.map +1 -1
- package/lib/webrtc/src/transport/dtls-application-gate.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-application-gate.js +143 -0
- package/lib/webrtc/src/transport/dtls-application-gate.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-attempt.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-attempt.js +79 -0
- package/lib/webrtc/src/transport/dtls-attempt.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-certificate.d.ts +24 -0
- package/lib/webrtc/src/transport/dtls-certificate.js +98 -0
- package/lib/webrtc/src/transport/dtls-certificate.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-fingerprint.d.ts +7 -0
- package/lib/webrtc/src/transport/dtls-fingerprint.js +66 -0
- package/lib/webrtc/src/transport/dtls-fingerprint.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-ice-transport.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-ice-transport.js +123 -0
- package/lib/webrtc/src/transport/dtls-ice-transport.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-media-queue.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-media-queue.js +95 -0
- package/lib/webrtc/src/transport/dtls-media-queue.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-readiness.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-readiness.js +173 -0
- package/lib/webrtc/src/transport/dtls-readiness.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-sped-handshake.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-sped-handshake.js +146 -0
- package/lib/webrtc/src/transport/dtls-sped-handshake.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-srtp.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-srtp.js +133 -0
- package/lib/webrtc/src/transport/dtls-srtp.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-stats.d.ts +1 -0
- package/lib/webrtc/src/transport/dtls-stats.js +134 -0
- package/lib/webrtc/src/transport/dtls-stats.js.map +1 -0
- package/lib/webrtc/src/transport/dtls-types.d.ts +23 -0
- package/lib/webrtc/src/transport/dtls-types.js +11 -0
- package/lib/webrtc/src/transport/dtls-types.js.map +1 -0
- package/lib/webrtc/src/transport/dtls.d.ts +236 -47
- package/lib/webrtc/src/transport/dtls.js +1198 -441
- package/lib/webrtc/src/transport/dtls.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +95 -5
- package/lib/webrtc/src/transport/ice.js +323 -21
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/lib/webrtc/src/transport/iceCandidateAttribute.d.ts +4 -2
- package/lib/webrtc/src/transport/iceCandidateAttribute.js.map +1 -1
- package/lib/webrtc/src/transport/sctp.d.ts +149 -2
- package/lib/webrtc/src/transport/sctp.js +826 -128
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/lib/webrtc/src/transport/sped.d.ts +139 -0
- package/lib/webrtc/src/transport/sped.js +757 -0
- package/lib/webrtc/src/transport/sped.js.map +1 -0
- package/lib/webrtc/src/types/util.d.ts +6 -0
- package/lib/webrtc/src/types/util.js.map +1 -1
- package/lib/webrtc/src/utils.d.ts +34 -1
- package/lib/webrtc/src/utils.js +52 -3
- package/lib/webrtc/src/utils.js.map +1 -1
- package/lib/webrtc/src/webidl.d.ts +15 -0
- package/lib/webrtc/src/webidl.js +34 -0
- package/lib/webrtc/src/webidl.js.map +1 -0
- package/package.json +8 -3
- package/lib/webrtc/src/polyfill/rtcSessionDescription.d.ts +0 -18
- package/lib/webrtc/src/polyfill/rtcSessionDescription.js +0 -36
- package/lib/webrtc/src/polyfill/rtcSessionDescription.js.map +0 -1
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RTCSctpCapabilities = exports.RTCSctpTransport = exports.DEFAULT_MAX_MESSAGE_SIZE = void 0;
|
|
3
|
+
exports.RTCSctpCapabilities = exports.RTCSctpTransport = exports.PASSIVE_INIT_FALLBACK_MS = exports.DEFAULT_MAX_MESSAGE_SIZE = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
5
|
const src_1 = require("../../../sctp/src");
|
|
6
|
+
const sctp_1 = require("../../../sctp/src/sctp");
|
|
6
7
|
const const_1 = require("../const");
|
|
7
8
|
const dataChannel_1 = require("../dataChannel");
|
|
9
|
+
const errors_1 = require("../errors");
|
|
10
|
+
const helper_1 = require("../helper");
|
|
8
11
|
const common_1 = require("../imports/common");
|
|
9
12
|
const log = (0, common_1.debug)("werift:packages/webrtc/src/transport/sctp.ts");
|
|
10
13
|
exports.DEFAULT_MAX_MESSAGE_SIZE = 65536;
|
|
14
|
+
/**
|
|
15
|
+
* How long the DTLS client (passive SCTP side) waits for the peer's INIT
|
|
16
|
+
* after DTLS authentication before sending INIT itself. A peer that picks
|
|
17
|
+
* the SCTP initiator by the ICE role (older werift) may wait as well; well
|
|
18
|
+
* below the SCTP initial RTO (3 s), so a lost INIT also recovers sooner.
|
|
19
|
+
*/
|
|
20
|
+
exports.PASSIVE_INIT_FALLBACK_MS = 1000;
|
|
21
|
+
/**
|
|
22
|
+
* Stream IDs a data channel may use: 0..65534 (W3C webrtc-pc, RFC 8831 section 6.5).
|
|
23
|
+
* @see tests/issue/815.test.ts "a reservation beyond the negotiated stream limit is given back and fails"
|
|
24
|
+
*/
|
|
25
|
+
const DATA_CHANNEL_ID_LIMIT = 65535;
|
|
11
26
|
class RTCSctpTransport {
|
|
12
27
|
constructor(port = 5000, maxMessageSize = exports.DEFAULT_MAX_MESSAGE_SIZE, sctpOptions = {}) {
|
|
13
28
|
Object.defineProperty(this, "port", {
|
|
@@ -52,6 +67,37 @@ class RTCSctpTransport {
|
|
|
52
67
|
writable: true,
|
|
53
68
|
value: (0, crypto_1.randomUUID)().toString()
|
|
54
69
|
});
|
|
70
|
+
/**
|
|
71
|
+
* `connecting` until the association is established, then `connected`;
|
|
72
|
+
* `closed` once the association closed (the peer ended it, or the DTLS
|
|
73
|
+
* transport closed / failed). {@link RTCSctpTransport.stop} (e.g.
|
|
74
|
+
* `RTCPeerConnection.close()`) moves to `closed` without statechange.
|
|
75
|
+
* A new association (renegotiation) starts again from `connecting`.
|
|
76
|
+
*/
|
|
77
|
+
Object.defineProperty(this, "state", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
configurable: true,
|
|
80
|
+
writable: true,
|
|
81
|
+
value: "connecting"
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(this, "onStateChange", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
configurable: true,
|
|
86
|
+
writable: true,
|
|
87
|
+
value: new common_1.Event()
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(this, "onstatechange", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
configurable: true,
|
|
92
|
+
writable: true,
|
|
93
|
+
value: void 0
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(this, "events", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
configurable: true,
|
|
98
|
+
writable: true,
|
|
99
|
+
value: new helper_1.EventTarget()
|
|
100
|
+
});
|
|
55
101
|
Object.defineProperty(this, "mid", {
|
|
56
102
|
enumerable: true,
|
|
57
103
|
configurable: true,
|
|
@@ -95,11 +141,26 @@ class RTCSctpTransport {
|
|
|
95
141
|
writable: true,
|
|
96
142
|
value: new common_1.FifoQueue()
|
|
97
143
|
});
|
|
98
|
-
|
|
144
|
+
/**
|
|
145
|
+
* @see tests/datachannel/closeDelivery.test.ts "messages sent before close() while connecting reach the peer, then both ends close"
|
|
146
|
+
*/
|
|
147
|
+
Object.defineProperty(this, "closeAfterFlush", {
|
|
99
148
|
enumerable: true,
|
|
100
149
|
configurable: true,
|
|
101
150
|
writable: true,
|
|
102
|
-
value:
|
|
151
|
+
value: new Set()
|
|
152
|
+
});
|
|
153
|
+
/**
|
|
154
|
+
* In-band channels created here whose DATA_CHANNEL_OPEN is not sent yet;
|
|
155
|
+
* their stream ID, if any, is a reservation.
|
|
156
|
+
* @see tests/issue/815.test.ts "a rollback gives back the IDs a pranswer reserved"
|
|
157
|
+
* @see tests/issue/815.test.ts "a move to a DTLS transport with a decided role assigns its parity; a reset association waits for the next negotiation"
|
|
158
|
+
*/
|
|
159
|
+
Object.defineProperty(this, "unannounced", {
|
|
160
|
+
enumerable: true,
|
|
161
|
+
configurable: true,
|
|
162
|
+
writable: true,
|
|
163
|
+
value: new Set()
|
|
103
164
|
});
|
|
104
165
|
Object.defineProperty(this, "eventDisposer", {
|
|
105
166
|
enumerable: true,
|
|
@@ -107,6 +168,80 @@ class RTCSctpTransport {
|
|
|
107
168
|
writable: true,
|
|
108
169
|
value: []
|
|
109
170
|
});
|
|
171
|
+
Object.defineProperty(this, "stopping", {
|
|
172
|
+
enumerable: true,
|
|
173
|
+
configurable: true,
|
|
174
|
+
writable: true,
|
|
175
|
+
value: false
|
|
176
|
+
});
|
|
177
|
+
/** Associations whose start began before DTLS peer authentication. */
|
|
178
|
+
Object.defineProperty(this, "preAuthenticationStarts", {
|
|
179
|
+
enumerable: true,
|
|
180
|
+
configurable: true,
|
|
181
|
+
writable: true,
|
|
182
|
+
value: new WeakSet()
|
|
183
|
+
});
|
|
184
|
+
/**
|
|
185
|
+
* Closing channels' streams and which reset direction is done.
|
|
186
|
+
* @see tests/issue/815.reset.test.ts "close fires on neither end before both directions of the stream are reset"
|
|
187
|
+
*/
|
|
188
|
+
Object.defineProperty(this, "closingStreams", {
|
|
189
|
+
enumerable: true,
|
|
190
|
+
configurable: true,
|
|
191
|
+
writable: true,
|
|
192
|
+
value: new Map()
|
|
193
|
+
});
|
|
194
|
+
/**
|
|
195
|
+
* @internal
|
|
196
|
+
* How long a channel waits for the peer to reset its side. 5 s covers one
|
|
197
|
+
* retransmission of a lost reset request (SCTP RTO.Initial 3 s, RFC 9260
|
|
198
|
+
* section 16).
|
|
199
|
+
* @see tests/issue/815.reset.test.ts "a legacy peer that does not reset its side (ordered=%s, no data from it): close fires after reverseResetTimeout and the ID stays in use"
|
|
200
|
+
*/
|
|
201
|
+
Object.defineProperty(this, "reverseResetTimeout", {
|
|
202
|
+
enumerable: true,
|
|
203
|
+
configurable: true,
|
|
204
|
+
writable: true,
|
|
205
|
+
value: 5000
|
|
206
|
+
});
|
|
207
|
+
/**
|
|
208
|
+
* @internal
|
|
209
|
+
* The initial `binaryType` of a channel the remote peer announces
|
|
210
|
+
* (`PeerConfig.dataChannelBinaryType`, read when the channel is created).
|
|
211
|
+
*/
|
|
212
|
+
Object.defineProperty(this, "defaultBinaryType", {
|
|
213
|
+
enumerable: true,
|
|
214
|
+
configurable: true,
|
|
215
|
+
writable: true,
|
|
216
|
+
value: () => "nodebuffer"
|
|
217
|
+
});
|
|
218
|
+
/**
|
|
219
|
+
* Streams closed by {@link RTCSctpTransport.reverseResetTimeout}: in use
|
|
220
|
+
* until the peer's reset arrives or the association ends.
|
|
221
|
+
* @see tests/issue/815.reset.test.ts "a peer reset arriving after reverseResetTimeout closes nothing and frees the ID"
|
|
222
|
+
*/
|
|
223
|
+
Object.defineProperty(this, "awaitingPeerReset", {
|
|
224
|
+
enumerable: true,
|
|
225
|
+
configurable: true,
|
|
226
|
+
writable: true,
|
|
227
|
+
value: new Set()
|
|
228
|
+
});
|
|
229
|
+
Object.defineProperty(this, "addEventListener", {
|
|
230
|
+
enumerable: true,
|
|
231
|
+
configurable: true,
|
|
232
|
+
writable: true,
|
|
233
|
+
value: (type, listener, options) => {
|
|
234
|
+
this.events.addEventListener(type, listener, options);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
Object.defineProperty(this, "removeEventListener", {
|
|
238
|
+
enumerable: true,
|
|
239
|
+
configurable: true,
|
|
240
|
+
writable: true,
|
|
241
|
+
value: (type, listener) => {
|
|
242
|
+
this.events.removeEventListener(type, listener);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
110
245
|
Object.defineProperty(this, "datachannelReceive", {
|
|
111
246
|
enumerable: true,
|
|
112
247
|
configurable: true,
|
|
@@ -125,7 +260,27 @@ class RTCSctpTransport {
|
|
|
125
260
|
log("DATA_CHANNEL_OPEN data.length not enough");
|
|
126
261
|
return;
|
|
127
262
|
}
|
|
128
|
-
|
|
263
|
+
const existing = this.dataChannels[streamId];
|
|
264
|
+
if (existing && !existing.isCreatedByRemote) {
|
|
265
|
+
// Test: tests/issue/815.test.ts "is not acknowledged and the stream is reset, so neither channel stays connecting"
|
|
266
|
+
log("DATA_CHANNEL_OPEN on a stream ID in local use, rejected", {
|
|
267
|
+
streamId,
|
|
268
|
+
label: existing.label,
|
|
269
|
+
});
|
|
270
|
+
this.rejectOpenOnStreamInUse(existing);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (!existing &&
|
|
274
|
+
streamId % 2 === this.idParity &&
|
|
275
|
+
!this.peerMayUseIceRoleParity) {
|
|
276
|
+
// Test: tests/issue/815.test.ts "issue 815: a DATA_CHANNEL_OPEN violating the odd/even rule on an unused stream"
|
|
277
|
+
log("DATA_CHANNEL_OPEN violating the odd/even rule, rejected", {
|
|
278
|
+
streamId,
|
|
279
|
+
});
|
|
280
|
+
this.resetStream(streamId);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (!existing) {
|
|
129
284
|
// !BBHLHH — 12 byte DCEP OPEN header (big-endian)
|
|
130
285
|
const channelType = data.readUInt8(1);
|
|
131
286
|
const reliability = data.readUInt32BE(4);
|
|
@@ -155,20 +310,27 @@ class RTCSctpTransport {
|
|
|
155
310
|
protocol,
|
|
156
311
|
id: streamId,
|
|
157
312
|
});
|
|
158
|
-
const channel = new dataChannel_1.RTCDataChannel(this, parameters, false);
|
|
313
|
+
const channel = new dataChannel_1.RTCDataChannel(this, parameters, false, this.defaultBinaryType());
|
|
159
314
|
channel.isCreatedByRemote = true;
|
|
160
315
|
this.dataChannels[streamId] = channel;
|
|
161
|
-
|
|
162
|
-
|
|
316
|
+
// Test: tests/datachannel/closeDelivery.test.ts "close() in the datachannel handler: the opener gets the ACK first, no error, both ends close"
|
|
317
|
+
this.sendDataChannelAck(channel);
|
|
318
|
+
// Test: tests/issue/815.notification.test.ts "datachannel: later listeners run and the channel opens on both ends"
|
|
319
|
+
this.onDataChannel.executeIsolated((error) => log("onDataChannel listener failed", error), channel);
|
|
320
|
+
if (channel.readyState === "connecting") {
|
|
321
|
+
channel.setReadyState("open");
|
|
322
|
+
}
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
else if (existing.readyState !== "open") {
|
|
326
|
+
// Test: tests/issue/815.reset.test.ts "a DATA_CHANNEL_OPEN on the stream of a closing remote channel is not acknowledged"
|
|
327
|
+
log("DATA_CHANNEL_OPEN on a closing stream, ignored", streamId);
|
|
328
|
+
return;
|
|
163
329
|
}
|
|
164
330
|
else {
|
|
165
331
|
log("datachannel already opened", "retransmit ack");
|
|
166
332
|
}
|
|
167
|
-
|
|
168
|
-
const ack = Buffer.allocUnsafe(1);
|
|
169
|
-
ack.writeUInt8(const_1.DATA_CHANNEL_ACK, 0);
|
|
170
|
-
this.dataChannelQueue.push([channel, const_1.WEBRTC_DCEP, ack]);
|
|
171
|
-
this.dataChannelFlush();
|
|
333
|
+
this.sendDataChannelAck(existing);
|
|
172
334
|
}
|
|
173
335
|
break;
|
|
174
336
|
case const_1.DATA_CHANNEL_ACK:
|
|
@@ -176,9 +338,13 @@ class RTCSctpTransport {
|
|
|
176
338
|
log("DATA_CHANNEL_ACK", streamId, ppId);
|
|
177
339
|
const channel = this.dataChannels[streamId];
|
|
178
340
|
if (!channel) {
|
|
179
|
-
|
|
341
|
+
// Test: tests/issue/815.notification.test.ts "the receive callback ignores an ACK of an unknown stream and an unknown PPID"
|
|
342
|
+
log("DATA_CHANNEL_ACK for an unknown stream ID, ignored", streamId);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (channel.readyState === "connecting") {
|
|
346
|
+
channel.setReadyState("open");
|
|
180
347
|
}
|
|
181
|
-
channel.setReadyState("open");
|
|
182
348
|
}
|
|
183
349
|
break;
|
|
184
350
|
}
|
|
@@ -197,33 +363,74 @@ class RTCSctpTransport {
|
|
|
197
363
|
case const_1.WEBRTC_BINARY_EMPTY:
|
|
198
364
|
return Buffer.from([]);
|
|
199
365
|
default:
|
|
200
|
-
|
|
366
|
+
return undefined;
|
|
201
367
|
}
|
|
202
368
|
})();
|
|
203
|
-
//
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
369
|
+
// Test: tests/issue/815.notification.test.ts "the receive callback ignores an ACK of an unknown stream and an unknown PPID"
|
|
370
|
+
if (msg === undefined) {
|
|
371
|
+
log("message with an unknown PPID, ignored", { streamId, ppId });
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
// W3C webrtc-pc "Receiving messages on a data channel" step 3.
|
|
375
|
+
// Test: tests/issue/815.reset.test.ts "a message arriving while closing is discarded (W3C: not open discards it)"
|
|
376
|
+
if (channel.readyState === "closing" ||
|
|
377
|
+
channel.readyState === "closed") {
|
|
378
|
+
log("message on a closing data channel, discarded", streamId);
|
|
379
|
+
return;
|
|
210
380
|
}
|
|
381
|
+
// Test: tests/datachannel/bufferedAmount.test.ts "empty string and empty Buffer arrive in order, bufferedAmount stays 0, stats count them"
|
|
382
|
+
channel.messagesReceived++;
|
|
383
|
+
channel.bytesReceived +=
|
|
384
|
+
ppId === const_1.WEBRTC_STRING_EMPTY || ppId === const_1.WEBRTC_BINARY_EMPTY
|
|
385
|
+
? 0
|
|
386
|
+
: data.length;
|
|
387
|
+
// Test: tests/issue/815.notification.test.ts "message: later listeners and later messages are delivered"
|
|
388
|
+
const onError = (error) => log("message listener failed", error);
|
|
389
|
+
channel.onMessage.executeIsolated(onError, msg);
|
|
390
|
+
// Test: tests/datachannel/bufferedAmount.test.ts "onmessage receives the same message event object as the message listeners"
|
|
391
|
+
// binaryType: converted once, the same object for both surfaces.
|
|
392
|
+
// Test: tests/datachannel/binaryType.test.ts "$binaryType: $name arrives byte for byte"
|
|
393
|
+
const event = {
|
|
394
|
+
type: "message",
|
|
395
|
+
data: (0, dataChannel_1.convertDataChannelMessage)(msg, channel.binaryType),
|
|
396
|
+
};
|
|
397
|
+
channel.emitIsolated(onError, "message", event);
|
|
398
|
+
(0, helper_1.notifySafely)(log, "onmessage", () => channel.onmessage?.(event));
|
|
211
399
|
}
|
|
212
400
|
}
|
|
213
401
|
}
|
|
214
402
|
});
|
|
403
|
+
/**
|
|
404
|
+
* What {@link RTCDataChannel.send} calls; use that instead.
|
|
405
|
+
* @see tests/datachannel/bufferedAmount.test.ts "empty string and empty Buffer arrive in order, bufferedAmount stays 0, stats count them"
|
|
406
|
+
*/
|
|
215
407
|
Object.defineProperty(this, "datachannelSend", {
|
|
216
408
|
enumerable: true,
|
|
217
409
|
configurable: true,
|
|
218
410
|
writable: true,
|
|
219
411
|
value: (channel, data) => {
|
|
220
|
-
const userData = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
221
412
|
const size = (0, dataChannel_1.getDataChannelMessageSize)(data);
|
|
222
413
|
this.assertSendableMessageSize(size);
|
|
223
|
-
channel.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
:
|
|
414
|
+
channel.changeBufferedAmount(size);
|
|
415
|
+
const isString = typeof data === "string";
|
|
416
|
+
if (size === 0) {
|
|
417
|
+
// Test: tests/datachannel/bufferedAmount.test.ts "empty string and empty Buffer arrive in order, bufferedAmount stays 0, stats count them"
|
|
418
|
+
this.dataChannelQueue.push([
|
|
419
|
+
channel,
|
|
420
|
+
isString ? const_1.WEBRTC_STRING_EMPTY : const_1.WEBRTC_BINARY_EMPTY,
|
|
421
|
+
Buffer.from([0]),
|
|
422
|
+
0,
|
|
423
|
+
]);
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
const userData = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
427
|
+
this.dataChannelQueue.push([
|
|
428
|
+
channel,
|
|
429
|
+
isString ? const_1.WEBRTC_STRING : const_1.WEBRTC_BINARY,
|
|
430
|
+
userData,
|
|
431
|
+
size,
|
|
432
|
+
]);
|
|
433
|
+
}
|
|
227
434
|
if (this.sctp.associationState !== src_1.SCTP_STATE.ESTABLISHED) {
|
|
228
435
|
log("sctp not established", this.sctp.associationState);
|
|
229
436
|
}
|
|
@@ -238,6 +445,22 @@ class RTCSctpTransport {
|
|
|
238
445
|
get transport() {
|
|
239
446
|
return this.dtlsTransport;
|
|
240
447
|
}
|
|
448
|
+
/**
|
|
449
|
+
* Change the state and notify. Each notification is isolated: an
|
|
450
|
+
* exception a listener throws is logged and never interrupts the caller
|
|
451
|
+
* (stop() and its ABORT, closing the data channels).
|
|
452
|
+
*/
|
|
453
|
+
setState(state, emitEvent = true) {
|
|
454
|
+
if (state === this.state)
|
|
455
|
+
return;
|
|
456
|
+
this.state = state;
|
|
457
|
+
// Per subscriber, so a throwing subscriber cannot skip a later one.
|
|
458
|
+
this.onStateChange.executeIsolated((error) => log("onStateChange listener failed", error), state);
|
|
459
|
+
if (emitEvent) {
|
|
460
|
+
(0, helper_1.notifySafely)(log, "onstatechange", () => this.onstatechange?.());
|
|
461
|
+
this.events.emitIsolated((error) => log("statechange listener failed", error), "statechange");
|
|
462
|
+
}
|
|
463
|
+
}
|
|
241
464
|
setDtlsTransport(dtlsTransport) {
|
|
242
465
|
if (this.dtlsTransport && this.dtlsTransport.id === dtlsTransport.id) {
|
|
243
466
|
return;
|
|
@@ -248,14 +471,14 @@ class RTCSctpTransport {
|
|
|
248
471
|
* @internal
|
|
249
472
|
* Discard the current association (ABORT, attached channels close) and
|
|
250
473
|
* bind a new, unstarted one (on the same DTLS transport by default).
|
|
251
|
-
* Channels
|
|
252
|
-
* association
|
|
474
|
+
* Channels whose DATA_CHANNEL_OPEN was not sent stay, without stream ID.
|
|
475
|
+
* @see tests/issue/815.test.ts "a move to a DTLS transport with a decided role assigns its parity; a reset association waits for the next negotiation"
|
|
253
476
|
*/
|
|
254
477
|
async resetAssociation(dtlsTransport = this.dtlsTransport) {
|
|
478
|
+
this.releaseUnannouncedStreamIds();
|
|
255
479
|
await this.stop();
|
|
256
|
-
this.dataChannelQueue = this.dataChannelQueue.filter(([channel]) => channel
|
|
257
|
-
this.
|
|
258
|
-
this.bindAssociation(dtlsTransport);
|
|
480
|
+
this.dataChannelQueue = this.dataChannelQueue.filter(([channel]) => this.unannounced.has(channel));
|
|
481
|
+
this.bindAssociation(dtlsTransport, { assignIds: false });
|
|
259
482
|
}
|
|
260
483
|
/**
|
|
261
484
|
* @internal
|
|
@@ -266,59 +489,361 @@ class RTCSctpTransport {
|
|
|
266
489
|
this.sctp.state !== "new" ||
|
|
267
490
|
this.sctp.associationState !== src_1.SCTP_STATE.CLOSED);
|
|
268
491
|
}
|
|
269
|
-
|
|
270
|
-
|
|
492
|
+
/**
|
|
493
|
+
* `assignIds`: unannounced channels take stream IDs from the bound DTLS
|
|
494
|
+
* transport's role at once.
|
|
495
|
+
* @see tests/issue/815.test.ts "a move to a DTLS transport with a decided role assigns its parity; a reset association waits for the next negotiation"
|
|
496
|
+
*/
|
|
497
|
+
bindAssociation(dtlsTransport, { assignIds = true } = {}) {
|
|
498
|
+
this.disposeSctpListeners();
|
|
499
|
+
this.clearClosingStreams();
|
|
500
|
+
this.closeAfterFlush.clear();
|
|
271
501
|
this.dtlsTransport = dtlsTransport;
|
|
272
|
-
|
|
502
|
+
this.stopping = false;
|
|
503
|
+
this.stopped = false;
|
|
504
|
+
this.createSctpAssociation();
|
|
505
|
+
if (assignIds) {
|
|
506
|
+
this.releaseUnannouncedStreamIds();
|
|
507
|
+
this.assignPendingStreamIds();
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
disposeSctpListeners() {
|
|
511
|
+
this.eventDisposer.forEach((dispose) => dispose());
|
|
512
|
+
this.eventDisposer = [];
|
|
513
|
+
}
|
|
514
|
+
createSctpAssociation() {
|
|
515
|
+
this.disposeSctpListeners();
|
|
516
|
+
this.clearClosingStreams();
|
|
273
517
|
this.stopped = false;
|
|
518
|
+
this.setState("connecting", false);
|
|
274
519
|
this.sctp = new src_1.SCTP(new BridgeDtls(this.dtlsTransport), this.port, this.sctpOptions);
|
|
520
|
+
const association = this.sctp;
|
|
275
521
|
this.eventDisposer = [
|
|
276
522
|
...[
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
if (!dc)
|
|
282
|
-
return;
|
|
283
|
-
// todo fix
|
|
284
|
-
dc.setReadyState("closing");
|
|
285
|
-
dc.setReadyState("closed");
|
|
286
|
-
delete this.dataChannels[id];
|
|
287
|
-
});
|
|
288
|
-
}),
|
|
289
|
-
this.sctp.stateChanged.connected.subscribe(() => {
|
|
523
|
+
association.onReceive.subscribe(this.datachannelReceive),
|
|
524
|
+
association.onReconfigStreams.subscribe((ids, direction) => this.onStreamsReset(ids, direction)),
|
|
525
|
+
association.stateChanged.connected.subscribe(() => {
|
|
526
|
+
this.setState("connected");
|
|
290
527
|
Object.values(this.dataChannels).forEach((channel) => {
|
|
291
|
-
|
|
528
|
+
// Test: tests/datachannel/closeDelivery.test.ts "messages sent before close() while connecting reach the peer, then both ends close"
|
|
529
|
+
if (channel.negotiated && channel.readyState === "connecting") {
|
|
292
530
|
channel.setReadyState("open");
|
|
293
531
|
}
|
|
294
532
|
});
|
|
295
533
|
this.dataChannelFlush();
|
|
296
534
|
}),
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
this.
|
|
535
|
+
association.stateChanged.closed.subscribe(() => {
|
|
536
|
+
if (!this.stopped)
|
|
537
|
+
this.setState("closed");
|
|
538
|
+
this.clearClosingStreams();
|
|
539
|
+
this.closeAfterFlush.clear();
|
|
540
|
+
// An explicit stop() closes the channels registered on this
|
|
541
|
+
// association only; channels whose OPEN is still queued outlive it
|
|
542
|
+
// (rollback re-announces them on the next association).
|
|
543
|
+
if (this.stopping) {
|
|
544
|
+
this.closeDataChannels({ clearQueue: false, includeQueued: false });
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
// Keep pre-establishment channels and queued DCEP available for a
|
|
548
|
+
// retry. Once an association was established, closing it closes them.
|
|
549
|
+
if (!association.hadEstablished)
|
|
550
|
+
return;
|
|
551
|
+
this.closeDataChannels();
|
|
302
552
|
}),
|
|
553
|
+
...(() => {
|
|
554
|
+
// A pre-established early association cannot make progress after
|
|
555
|
+
// permission is revoked. Cancel it immediately instead of waiting
|
|
556
|
+
// for SCTP T1 retransmissions to expire; authenticated retry will
|
|
557
|
+
// create a fresh association through SctpTransportManager.
|
|
558
|
+
// SCTP refuses once COOKIE_ECHO / COOKIE_ACK was handed off (the
|
|
559
|
+
// peer may be ESTABLISHED and never re-INIT). Such a start is kept;
|
|
560
|
+
// a cancelled attempt may have dropped the peer's in-flight reply,
|
|
561
|
+
// so retransmit now rather than at the next T1 expiry.
|
|
562
|
+
//
|
|
563
|
+
// The cancel applies only to the early attempt itself:
|
|
564
|
+
// - a start made after DTLS peer authentication is not early, and
|
|
565
|
+
// an early start becomes ordinary once DTLS authenticates; both
|
|
566
|
+
// must survive SPED resets / ICE restarts;
|
|
567
|
+
// - only the DTLS server (the active INIT sender) sends SCTP under
|
|
568
|
+
// the early permission. The DTLS client's passive association
|
|
569
|
+
// is merely armed early; cancelling it would discard the cookie
|
|
570
|
+
// key of an INIT_ACK it already sent, so the peer's COOKIE_ECHO
|
|
571
|
+
// could never be accepted.
|
|
572
|
+
const cancelEarlyStart = () => {
|
|
573
|
+
if (this.sctp !== association)
|
|
574
|
+
return;
|
|
575
|
+
const earlyAttempt = this.preAuthenticationStarts.has(association) &&
|
|
576
|
+
this.dtlsTransport.role === "server" &&
|
|
577
|
+
// An early start still pending once DTLS authenticated no
|
|
578
|
+
// longer depends on the early permission: its retransmissions
|
|
579
|
+
// are ordinary authenticated sends.
|
|
580
|
+
this.dtlsTransport.state !== "connected";
|
|
581
|
+
if (earlyAttempt &&
|
|
582
|
+
association.cancelStart(new sctp_1.SCTPStartCancelledError())) {
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
// The start is kept (not early, or already committed). The reset
|
|
586
|
+
// may have dropped an in-flight reply, so retransmit the pending
|
|
587
|
+
// INIT / COOKIE_ECHO now instead of at the next T1 expiry
|
|
588
|
+
// (no-op when nothing is pending, e.g. the passive side).
|
|
589
|
+
association.retransmitStartNow();
|
|
590
|
+
};
|
|
591
|
+
return [
|
|
592
|
+
this.dtlsTransport.onEarlyApplicationSendRevoked?.subscribe(cancelEarlyStart),
|
|
593
|
+
this.dtlsTransport.onEarlyApplicationAttemptCancelled?.subscribe(cancelEarlyStart),
|
|
594
|
+
].flatMap((subscription) => (subscription ? [subscription] : []));
|
|
595
|
+
})(),
|
|
303
596
|
this.dtlsTransport.onStateChange.subscribe((state) => {
|
|
304
|
-
if (state === "
|
|
305
|
-
|
|
597
|
+
if (state === "connected") {
|
|
598
|
+
// A start kept across a cancel/revoke can proceed now; don't wait
|
|
599
|
+
// for the next T1 expiry.
|
|
600
|
+
if (this.sctp === association)
|
|
601
|
+
association.retransmitStartNow();
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
if (state === "failed" || state === "closed") {
|
|
605
|
+
// A stopped transport is left to stop():
|
|
606
|
+
// RTCPeerConnection.close() marks DTLS closed synchronously,
|
|
607
|
+
// before stop() sends the SCTP ABORT, and closing the association
|
|
608
|
+
// here would skip that ABORT.
|
|
609
|
+
if (this.stopped)
|
|
610
|
+
return;
|
|
611
|
+
// DTLS failure is terminal for this SCTP association. Do not
|
|
612
|
+
// preserve queued DCEP/data for a retry after authentication has
|
|
613
|
+
// failed, and close every channel immediately.
|
|
614
|
+
this.stopping = true;
|
|
615
|
+
// The channels' close notification sees the transport closed.
|
|
616
|
+
this.setState("closed");
|
|
617
|
+
// Close queued pre-establishment channels before SCTP removes its
|
|
618
|
+
// state listeners; otherwise their DCEP entries are lost without
|
|
619
|
+
// a DataChannel close event.
|
|
620
|
+
this.closeDataChannels();
|
|
621
|
+
association.setState(src_1.SCTP_STATE.CLOSED);
|
|
622
|
+
this.disposeSctpListeners();
|
|
306
623
|
}
|
|
307
624
|
}),
|
|
625
|
+
// Test: tests/issue/815.test.ts "issue 815: data channel stream IDs follow the DTLS role"
|
|
626
|
+
// Test: tests/issue/815.test.ts "the DTLS start resolving auto assigns the IDs of the role it took"
|
|
627
|
+
this.dtlsTransport.onRoleChange.subscribe(() => {
|
|
628
|
+
this.releaseUnannouncedStreamIds();
|
|
629
|
+
this.assignPendingStreamIds();
|
|
630
|
+
}),
|
|
308
631
|
].map((e) => e.unSubscribe),
|
|
309
|
-
() => (
|
|
632
|
+
() => (association.onSackReceived = async () => { }),
|
|
310
633
|
];
|
|
311
|
-
|
|
312
|
-
this.dataChannelFlush();
|
|
634
|
+
association.onSackReceived = async () => {
|
|
635
|
+
await this.dataChannelFlush();
|
|
313
636
|
};
|
|
314
637
|
}
|
|
638
|
+
/** @internal Prepare a fresh association after INIT/T1 failure. */
|
|
639
|
+
prepareForStart() {
|
|
640
|
+
if (this.stopping) {
|
|
641
|
+
throw new Error("SCTP transport is stopped");
|
|
642
|
+
}
|
|
643
|
+
if (this.sctp.state === "closed") {
|
|
644
|
+
this.createSctpAssociation();
|
|
645
|
+
}
|
|
646
|
+
return this.sctp;
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* RFC 8831 section 6.7: the first reset of a stream makes its channel
|
|
650
|
+
* `closing`; it is `closed`, its ID released just before, once both
|
|
651
|
+
* directions are reset.
|
|
652
|
+
* @see tests/issue/815.reset.test.ts "issue 815: a stream ID reused after a close (RFC 8831 section 6.7 reset in both directions)"
|
|
653
|
+
* @see tests/issue/815.notification.test.ts "closed by $closedBy: a close listener re-creates a channel on the only free ID"
|
|
654
|
+
*/
|
|
655
|
+
onStreamsReset(ids, direction) {
|
|
656
|
+
for (const id of ids) {
|
|
657
|
+
if (direction === "incoming" && this.awaitingPeerReset.delete(id)) {
|
|
658
|
+
// Test: tests/issue/815.reset.test.ts "a peer reset arriving after reverseResetTimeout closes nothing and frees the ID"
|
|
659
|
+
this.sctp.reconfigQueue = this.sctp.reconfigQueue.filter((streamId) => streamId !== id);
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
// Test: tests/issue/815.test.ts "issue 815: a DATA_CHANNEL_OPEN violating the odd/even rule on an unused stream"
|
|
663
|
+
const dc = this.dataChannels[id];
|
|
664
|
+
if (!dc)
|
|
665
|
+
continue;
|
|
666
|
+
let reset = this.closingStreams.get(id);
|
|
667
|
+
if (!reset) {
|
|
668
|
+
reset = { outgoing: false, incoming: false };
|
|
669
|
+
this.closingStreams.set(id, reset);
|
|
670
|
+
}
|
|
671
|
+
reset[direction] = true;
|
|
672
|
+
if (dc.readyState !== "closing") {
|
|
673
|
+
dc.setReadyState("closing");
|
|
674
|
+
// Test: tests/issue/815.notification.test.ts "a closing listener closing the PeerConnection ends the channel once"
|
|
675
|
+
if (this.dataChannels[id] !== dc || dc.readyState === "closed") {
|
|
676
|
+
continue;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
if (direction === "incoming")
|
|
680
|
+
this.answerIncomingReset(id, reset);
|
|
681
|
+
this.completeClose(id, dc, reset);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Reset our side of a stream the peer reset, exactly once.
|
|
686
|
+
* @see tests/issue/815.reset.test.ts "issue 815: a stream ID reused after a close (RFC 8831 section 6.7 reset in both directions)"
|
|
687
|
+
*/
|
|
688
|
+
answerIncomingReset(id, reset) {
|
|
689
|
+
const inFlight = !!this.sctp.reconfigRequest?.streams.includes(id);
|
|
690
|
+
if (reset.outgoing || inFlight) {
|
|
691
|
+
// Test: tests/issue/815.notification.test.ts "closed by both ends at once: a close listener re-creates a channel that opens"
|
|
692
|
+
this.sctp.reconfigQueue = this.sctp.reconfigQueue.filter((streamId) => streamId !== id);
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
this.resetStream(id);
|
|
696
|
+
}
|
|
697
|
+
completeClose(id, dc, reset) {
|
|
698
|
+
if (reset.outgoing && reset.incoming) {
|
|
699
|
+
clearTimeout(reset.fallback);
|
|
700
|
+
this.closingStreams.delete(id);
|
|
701
|
+
delete this.dataChannels[id];
|
|
702
|
+
this.unannounced.delete(dc);
|
|
703
|
+
dc.setReadyState("closed");
|
|
704
|
+
}
|
|
705
|
+
else if (reset.outgoing && !reset.fallback) {
|
|
706
|
+
reset.fallback = setTimeout(() => {
|
|
707
|
+
if (this.closingStreams.get(id) !== reset)
|
|
708
|
+
return;
|
|
709
|
+
log("the peer did not reset its side of the stream", id);
|
|
710
|
+
// Test: tests/issue/815.reset.test.ts "a peer reset arriving after reverseResetTimeout closes nothing and frees the ID"
|
|
711
|
+
this.awaitingPeerReset.add(id);
|
|
712
|
+
reset.incoming = true;
|
|
713
|
+
this.completeClose(id, dc, reset);
|
|
714
|
+
}, this.reverseResetTimeout);
|
|
715
|
+
reset.fallback.unref?.();
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
clearClosingStreams() {
|
|
719
|
+
for (const { fallback } of this.closingStreams.values()) {
|
|
720
|
+
clearTimeout(fallback);
|
|
721
|
+
}
|
|
722
|
+
this.closingStreams.clear();
|
|
723
|
+
// Test: tests/issue/815.reset.test.ts "pc.close() while waiting for the peer's reset closes the channel once and leaves no timer"
|
|
724
|
+
this.awaitingPeerReset.clear();
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* The SCTP INIT side: the DTLS server, not the ICE role.
|
|
728
|
+
* @see tests/issue/815.test.ts "#815 report: reversed ICE / DTLS roles with channels from both ends do not collide"
|
|
729
|
+
*/
|
|
315
730
|
get isServer() {
|
|
316
|
-
|
|
317
|
-
|
|
731
|
+
return this.dtlsTransport.role === "server";
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* RFC 8832 section 6: DTLS client even, server odd; none while `auto`.
|
|
735
|
+
* @see tests/issue/815.test.ts "issue 815: data channel stream IDs follow the DTLS role"
|
|
736
|
+
*/
|
|
737
|
+
/**
|
|
738
|
+
* werift up to 0.28.0 picks its stream ID parity by the ICE role (controlling
|
|
739
|
+
* odd), not by the DTLS role. With the ICE and DTLS roles reversed, such a
|
|
740
|
+
* peer opens its channels on this side's parity, so an OPEN on an unused
|
|
741
|
+
* stream of this parity is accepted instead of reset. An RFC 8832 peer never
|
|
742
|
+
* uses this parity, so this changes nothing for it.
|
|
743
|
+
* @see tests/integrate/legacySctpRole.test.ts "$name: 旧 werift が開いた DataChannel を受け入れ、label どおりに届く"
|
|
744
|
+
*/
|
|
745
|
+
get peerMayUseIceRoleParity() {
|
|
746
|
+
const parity = this.idParity;
|
|
747
|
+
if (parity === undefined)
|
|
748
|
+
return false;
|
|
749
|
+
const iceRole = this.dtlsTransport.iceRoleAtStart ?? this.dtlsTransport.iceTransport.role;
|
|
750
|
+
return (parity === 1) !== (iceRole === "controlling");
|
|
751
|
+
}
|
|
752
|
+
get idParity() {
|
|
753
|
+
switch (this.dtlsTransport?.role) {
|
|
754
|
+
case "client":
|
|
755
|
+
return 0;
|
|
756
|
+
case "server":
|
|
757
|
+
return 1;
|
|
758
|
+
default:
|
|
759
|
+
return undefined;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Exclusive upper bound of a stream ID: 65535, or what SCTP negotiated.
|
|
764
|
+
* @see tests/issue/815.test.ts "a reservation beyond the negotiated stream limit is given back and fails"
|
|
765
|
+
*/
|
|
766
|
+
get streamIdLimit() {
|
|
767
|
+
const negotiated = this.sctp?.maxChannels;
|
|
768
|
+
return negotiated === undefined
|
|
769
|
+
? DATA_CHANNEL_ID_LIMIT
|
|
770
|
+
: Math.min(negotiated, DATA_CHANNEL_ID_LIMIT);
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* The lowest free stream ID of `parity`.
|
|
774
|
+
* @see tests/issue/815.test.ts "auto IDs skip negotiated channels of either parity and reuse closed IDs"
|
|
775
|
+
*/
|
|
776
|
+
allocateStreamId(parity) {
|
|
777
|
+
const limit = this.streamIdLimit;
|
|
778
|
+
const free = (id) => !this.dataChannels[id] && !this.awaitingPeerReset.has(id);
|
|
779
|
+
for (let id = parity; id < limit; id += 2) {
|
|
780
|
+
if (free(id))
|
|
781
|
+
return id;
|
|
782
|
+
}
|
|
783
|
+
return undefined;
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* @internal
|
|
787
|
+
* Reserve a stream ID for every unannounced channel without one, from the
|
|
788
|
+
* DTLS role; none left is an `OperationError` (W3C 4.4.1.6 step 2.2.6).
|
|
789
|
+
* @see tests/issue/815.test.ts "a channel waiting for an ID closes with OperationError when none is left"
|
|
790
|
+
*/
|
|
791
|
+
assignPendingStreamIds() {
|
|
792
|
+
const parity = this.idParity;
|
|
793
|
+
if (parity === undefined)
|
|
794
|
+
return;
|
|
795
|
+
const limit = this.streamIdLimit;
|
|
796
|
+
for (const channel of [...this.unannounced]) {
|
|
797
|
+
// Test: tests/issue/815.test.ts "a channel closed by an error handler is not given an ID"
|
|
798
|
+
if (!this.unannounced.has(channel) ||
|
|
799
|
+
channel.readyState === "closed" ||
|
|
800
|
+
channel.readyState === "closing") {
|
|
801
|
+
continue;
|
|
802
|
+
}
|
|
803
|
+
if (channel.id != undefined) {
|
|
804
|
+
// Test: tests/issue/815.test.ts "a reservation beyond the negotiated stream limit is given back and fails"
|
|
805
|
+
if (channel.id < limit)
|
|
806
|
+
continue;
|
|
807
|
+
if (this.dataChannels[channel.id] === channel) {
|
|
808
|
+
delete this.dataChannels[channel.id];
|
|
809
|
+
}
|
|
810
|
+
channel.setId(undefined);
|
|
811
|
+
}
|
|
812
|
+
const id = this.allocateStreamId(parity);
|
|
813
|
+
if (id === undefined) {
|
|
814
|
+
this.unannounced.delete(channel);
|
|
815
|
+
this.dataChannelQueue = this.dataChannelQueue.filter(([queued]) => queued !== channel);
|
|
816
|
+
channel.failWithError((0, errors_1.createWebRtcDomException)("OperationError", "No data channel stream ID is available"));
|
|
817
|
+
continue;
|
|
818
|
+
}
|
|
819
|
+
this.dataChannels[id] = channel;
|
|
820
|
+
channel.setId(id);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* @internal
|
|
825
|
+
* Give back the reservations of unannounced channels.
|
|
826
|
+
* @see tests/issue/815.test.ts "a %s gives the IDs back and the next answer, keeping the DTLS role, assigns them again"
|
|
827
|
+
*/
|
|
828
|
+
releaseUnannouncedStreamIds() {
|
|
829
|
+
for (const channel of this.unannounced) {
|
|
830
|
+
if (channel.id == undefined)
|
|
831
|
+
continue;
|
|
832
|
+
if (this.dataChannels[channel.id] === channel) {
|
|
833
|
+
delete this.dataChannels[channel.id];
|
|
834
|
+
}
|
|
835
|
+
channel.setId(undefined);
|
|
836
|
+
}
|
|
318
837
|
}
|
|
319
838
|
channelByLabel(label) {
|
|
320
839
|
return Object.values(this.dataChannels).find((d) => d.label === label);
|
|
321
840
|
}
|
|
841
|
+
sendDataChannelAck(channel) {
|
|
842
|
+
const ack = Buffer.allocUnsafe(1);
|
|
843
|
+
ack.writeUInt8(const_1.DATA_CHANNEL_ACK, 0);
|
|
844
|
+
this.dataChannelQueue.push([channel, const_1.WEBRTC_DCEP, ack]);
|
|
845
|
+
this.dataChannelFlush();
|
|
846
|
+
}
|
|
322
847
|
dataChannelAddNegotiated(channel) {
|
|
323
848
|
if (channel.id == undefined) {
|
|
324
849
|
throw new Error();
|
|
@@ -326,6 +851,10 @@ class RTCSctpTransport {
|
|
|
326
851
|
if (this.dataChannels[channel.id]) {
|
|
327
852
|
throw new Error();
|
|
328
853
|
}
|
|
854
|
+
if (this.awaitingPeerReset.has(channel.id)) {
|
|
855
|
+
// Test: tests/issue/815.reset.test.ts "a legacy peer that does not reset its side (ordered=%s, no data from it): close fires after reverseResetTimeout and the ID stays in use"
|
|
856
|
+
throw (0, errors_1.createWebRtcDomException)("OperationError", `Stream ${channel.id} waits for the peer to reset it`);
|
|
857
|
+
}
|
|
329
858
|
this.dataChannels[channel.id] = channel;
|
|
330
859
|
if (this.sctp.associationState === src_1.SCTP_STATE.ESTABLISHED) {
|
|
331
860
|
channel.setReadyState("open");
|
|
@@ -337,11 +866,21 @@ class RTCSctpTransport {
|
|
|
337
866
|
// Their 16-bit limit is enforced by the RTCDataChannel constructor.
|
|
338
867
|
const label = Buffer.from(channel.label, "utf8");
|
|
339
868
|
const protocol = Buffer.from(channel.protocol, "utf8");
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
869
|
+
// Test: tests/issue/815.test.ts "an in-band channel reaching the transport with an id is an internal error"
|
|
870
|
+
if (channel.id != undefined) {
|
|
871
|
+
throw new Error("internal: an in-band data channel gets its stream ID from the DTLS role");
|
|
872
|
+
}
|
|
873
|
+
// Test: tests/issue/815.test.ts "a channel waiting for an ID closes with OperationError when none is left"
|
|
874
|
+
const parity = this.idParity;
|
|
875
|
+
if (parity !== undefined) {
|
|
876
|
+
const id = this.allocateStreamId(parity);
|
|
877
|
+
if (id === undefined) {
|
|
878
|
+
throw (0, errors_1.createWebRtcDomException)("OperationError", "No data channel stream ID is available");
|
|
879
|
+
}
|
|
880
|
+
this.dataChannels[id] = channel;
|
|
881
|
+
channel.setId(id);
|
|
344
882
|
}
|
|
883
|
+
this.unannounced.add(channel);
|
|
345
884
|
const priority = 0;
|
|
346
885
|
// RFC 8832 5.1: the reliability mode and the unordered bit (0x80) are
|
|
347
886
|
// independent, so a partially reliable channel keeps its unordered bit.
|
|
@@ -377,43 +916,33 @@ class RTCSctpTransport {
|
|
|
377
916
|
this.dataChannelQueue.push([channel, const_1.WEBRTC_DCEP, send]);
|
|
378
917
|
this.dataChannelFlush();
|
|
379
918
|
}
|
|
919
|
+
/**
|
|
920
|
+
* Hand the queued DCEP and user messages to SCTP once the association is
|
|
921
|
+
* established; a channel still without stream ID stays queued.
|
|
922
|
+
* @see tests/issue/815.test.ts "issue 815: data channel stream IDs follow the DTLS role"
|
|
923
|
+
* @see tests/datachannel/closeDelivery.test.ts "messages sent before close() while connecting reach the peer, then both ends close"
|
|
924
|
+
*/
|
|
380
925
|
dataChannelFlush() {
|
|
381
|
-
// """
|
|
382
|
-
// Try to flush buffered data to the SCTP layer.
|
|
383
|
-
// We wait until the association is established, as we need to know
|
|
384
|
-
// whether we are a client or a server to correctly assign an odd/even ID
|
|
385
|
-
// to the data channels.
|
|
386
|
-
// """
|
|
387
926
|
if (this.sctp.associationState != src_1.SCTP_STATE.ESTABLISHED)
|
|
388
927
|
return;
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
this.dataChannelId ?? (this.dataChannelId = this.isServer ? 0 : 1);
|
|
928
|
+
this.assignPendingStreamIds();
|
|
929
|
+
const waiting = new common_1.FifoQueue();
|
|
392
930
|
// Hands every queued message to SCTP synchronously (SCTP.send enqueues
|
|
393
931
|
// before its first await) and tracks completion per message, so repeated
|
|
394
932
|
// datachannelSend() calls never spawn concurrent flush loops.
|
|
395
933
|
while (this.dataChannelQueue.length > 0) {
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
934
|
+
const item = this.dataChannelQueue.shift();
|
|
935
|
+
const [channel, protocol, userData] = item;
|
|
936
|
+
if (channel.readyState === "closed")
|
|
937
|
+
continue;
|
|
938
|
+
const streamId = channel.id;
|
|
939
|
+
if (streamId == undefined) {
|
|
940
|
+
waiting.push(item);
|
|
402
941
|
continue;
|
|
403
|
-
}
|
|
404
|
-
let streamId = channel.id;
|
|
405
|
-
if (streamId === undefined) {
|
|
406
|
-
// An association the remote established before start() decides the
|
|
407
|
-
// parity here (RFC 8832: DTLS client even; ICE controlling is server).
|
|
408
|
-
this.dataChannelId ?? (this.dataChannelId = this.isServer ? 0 : 1);
|
|
409
|
-
streamId = this.dataChannelId;
|
|
410
|
-
while (Object.keys(this.dataChannels).includes(streamId.toString())) {
|
|
411
|
-
streamId += 2;
|
|
412
|
-
}
|
|
413
|
-
this.dataChannels[streamId] = channel;
|
|
414
|
-
channel.setId(streamId);
|
|
415
942
|
}
|
|
416
943
|
if (protocol === const_1.WEBRTC_DCEP) {
|
|
944
|
+
if (userData[0] === const_1.DATA_CHANNEL_OPEN)
|
|
945
|
+
this.unannounced.delete(channel);
|
|
417
946
|
this.sctp
|
|
418
947
|
.send(streamId, protocol, userData, {
|
|
419
948
|
ordered: true,
|
|
@@ -426,21 +955,67 @@ class RTCSctpTransport {
|
|
|
426
955
|
const expiry = channel.maxPacketLifeTime !== null
|
|
427
956
|
? Date.now() + channel.maxPacketLifeTime
|
|
428
957
|
: undefined;
|
|
958
|
+
const bufferedBytes = item[3] ?? userData.length;
|
|
429
959
|
this.sctp
|
|
430
960
|
.send(streamId, protocol, userData, {
|
|
431
961
|
expiry,
|
|
432
962
|
maxRetransmits: channel.maxRetransmits ?? undefined,
|
|
433
963
|
ordered: channel.ordered,
|
|
434
964
|
})
|
|
435
|
-
.
|
|
965
|
+
.then((result) => {
|
|
966
|
+
// Test: tests/datachannel/bufferedAmount.test.ts "messages abandoned by maxPacketLifeTime before they were sent are subtracted and notified"
|
|
967
|
+
// Test: tests/datachannel/bufferedAmount.test.ts "pc.close() keeps bufferedAmount and fires no bufferedamountlow"
|
|
968
|
+
if (result !== src_1.SctpSendResult.discarded && bufferedBytes > 0) {
|
|
969
|
+
channel.changeBufferedAmount(-bufferedBytes);
|
|
970
|
+
}
|
|
971
|
+
}, (err) => {
|
|
436
972
|
log("send data failed", err.message);
|
|
437
973
|
})
|
|
438
|
-
.then(() => channel.addBufferedAmount(-userData.length))
|
|
439
974
|
.catch((err) => {
|
|
440
975
|
log("update bufferedAmount failed", err.message);
|
|
441
976
|
});
|
|
442
977
|
}
|
|
443
978
|
}
|
|
979
|
+
if (waiting.length > 0)
|
|
980
|
+
this.dataChannelQueue = waiting;
|
|
981
|
+
for (const channel of this.closeAfterFlush) {
|
|
982
|
+
if (channel.id == undefined)
|
|
983
|
+
continue;
|
|
984
|
+
this.closeAfterFlush.delete(channel);
|
|
985
|
+
if (channel.readyState !== "closing")
|
|
986
|
+
continue;
|
|
987
|
+
this.resetStream(channel.id);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* Close retained channels even when SCTP removed its state listeners.
|
|
992
|
+
* @see tests/issue/815.test.ts "a throwing close listener of a registered channel skips no listener, channel or teardown"
|
|
993
|
+
* @see tests/issue/815.notification.test.ts "association closed by the peer: a channel created in a close callback stays registered until pc.close()"
|
|
994
|
+
* @see tests/issue/815.test.ts "pc.close() notifies close of a reserved, unannounced channel after the transports closed"
|
|
995
|
+
*/
|
|
996
|
+
closeDataChannels({ clearQueue = true, includeQueued = true, } = {}) {
|
|
997
|
+
const channels = new Set([
|
|
998
|
+
...Object.values(this.dataChannels),
|
|
999
|
+
...(includeQueued
|
|
1000
|
+
? this.dataChannelQueue.toArray().map(([channel]) => channel)
|
|
1001
|
+
: []),
|
|
1002
|
+
]);
|
|
1003
|
+
if (clearQueue)
|
|
1004
|
+
this.dataChannelQueue.clear();
|
|
1005
|
+
else
|
|
1006
|
+
this.dataChannelQueue = this.dataChannelQueue.filter(([queued]) => !channels.has(queued));
|
|
1007
|
+
this.dataChannels = {};
|
|
1008
|
+
for (const channel of channels) {
|
|
1009
|
+
this.unannounced.delete(channel);
|
|
1010
|
+
if (channel.readyState === "closed")
|
|
1011
|
+
continue;
|
|
1012
|
+
try {
|
|
1013
|
+
channel.setReadyState("closed");
|
|
1014
|
+
}
|
|
1015
|
+
catch (error) {
|
|
1016
|
+
log("datachannel close callback failed", error);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
444
1019
|
}
|
|
445
1020
|
assertSendableMessageSize(size) {
|
|
446
1021
|
if (this.remoteMaxMessageSize !== 0 && size > this.remoteMaxMessageSize) {
|
|
@@ -460,70 +1035,193 @@ class RTCSctpTransport {
|
|
|
460
1035
|
this.sctp.setRemotePort(port);
|
|
461
1036
|
}
|
|
462
1037
|
async start(remotePort) {
|
|
463
|
-
this.
|
|
1038
|
+
this.prepareForStart();
|
|
1039
|
+
// RTCDtlsTransport.state is "connected" only after SDP fingerprint
|
|
1040
|
+
// authentication, so anything earlier is an early (pre-auth) start.
|
|
1041
|
+
if (this.dtlsTransport.state !== "connected") {
|
|
1042
|
+
this.preAuthenticationStarts.add(this.sctp);
|
|
1043
|
+
}
|
|
1044
|
+
// SCTP's `isServer` flag means passive COOKIE-WAIT peer. WARP assigns the
|
|
1045
|
+
// active INIT sender to the DTLS server, independently of the ICE role.
|
|
1046
|
+
this.sctp.isServer = !this.isServer;
|
|
1047
|
+
if (!this.isServer) {
|
|
1048
|
+
this.schedulePassiveInitFallback(this.sctp);
|
|
1049
|
+
}
|
|
464
1050
|
await this.sctp.start(remotePort);
|
|
465
1051
|
}
|
|
466
1052
|
/**
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
1053
|
+
* DTLS client: if the peer's INIT has not arrived
|
|
1054
|
+
* {@link PASSIVE_INIT_FALLBACK_MS} after DTLS authentication, send INIT
|
|
1055
|
+
* ourselves (SCTP answers a colliding INIT, RFC 9260 §5.2.1). Never before
|
|
1056
|
+
* authentication: the DTLS client has no early send permission.
|
|
471
1057
|
*/
|
|
1058
|
+
schedulePassiveInitFallback(association) {
|
|
1059
|
+
let timer;
|
|
1060
|
+
const arm = () => {
|
|
1061
|
+
if (timer)
|
|
1062
|
+
return;
|
|
1063
|
+
timer = setTimeout(() => {
|
|
1064
|
+
if (this.sctp !== association || this.stopping)
|
|
1065
|
+
return;
|
|
1066
|
+
association.startPassiveFallbackInit().catch((error) => {
|
|
1067
|
+
log("passive fallback INIT failed", error.message);
|
|
1068
|
+
});
|
|
1069
|
+
}, exports.PASSIVE_INIT_FALLBACK_MS);
|
|
1070
|
+
};
|
|
1071
|
+
if (this.dtlsTransport.state === "connected") {
|
|
1072
|
+
arm();
|
|
1073
|
+
}
|
|
1074
|
+
else {
|
|
1075
|
+
const subscription = this.dtlsTransport.onStateChange.subscribe((state) => {
|
|
1076
|
+
if (state !== "connected")
|
|
1077
|
+
return;
|
|
1078
|
+
subscription.unSubscribe();
|
|
1079
|
+
arm();
|
|
1080
|
+
});
|
|
1081
|
+
this.eventDisposer.push(subscription.unSubscribe);
|
|
1082
|
+
}
|
|
1083
|
+
// The association is replaced or the transport stops: drop the timer.
|
|
1084
|
+
this.eventDisposer.push(() => clearTimeout(timer));
|
|
1085
|
+
}
|
|
1086
|
+
/** @internal Start once; an established or already started association stays intact. */
|
|
472
1087
|
async ensureStarted(remotePort) {
|
|
473
|
-
if (this.sctp.started ||
|
|
1088
|
+
if (this.sctp.started ||
|
|
1089
|
+
this.sctp.state === "connected" ||
|
|
1090
|
+
this.sctp.state === "closed") {
|
|
474
1091
|
return;
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
return;
|
|
478
|
-
await this.sctp.start(remotePort);
|
|
1092
|
+
}
|
|
1093
|
+
await this.start(remotePort);
|
|
479
1094
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
1095
|
+
/**
|
|
1096
|
+
* @internal
|
|
1097
|
+
* The synchronous part of {@link RTCSctpTransport.stop}: `closed` without
|
|
1098
|
+
* statechange, and nothing received afterwards reaches the application.
|
|
1099
|
+
* `RTCPeerConnection.close()` calls it before its first await.
|
|
1100
|
+
*/
|
|
1101
|
+
markStopped() {
|
|
1102
|
+
this.stopping = true;
|
|
1103
|
+
this.stopped = true;
|
|
1104
|
+
this.setState("closed", false);
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* @internal
|
|
1108
|
+
* `RTCPeerConnection.close()`, after stop(): close the channels whose
|
|
1109
|
+
* DATA_CHANNEL_OPEN was not sent (stop() keeps them for a rollback).
|
|
1110
|
+
* @see tests/issue/815.test.ts "pc.close() notifies close of a channel without an ID after SCTP / DTLS / the PeerConnection closed"
|
|
1111
|
+
* @see tests/issue/815.test.ts "pc.close() notifies close of a reserved, unannounced channel after the transports closed"
|
|
1112
|
+
*/
|
|
1113
|
+
closeUnannouncedChannels() {
|
|
1114
|
+
const channels = [...this.unannounced];
|
|
1115
|
+
this.unannounced.clear();
|
|
1116
|
+
this.dataChannelQueue = this.dataChannelQueue.filter(([queued]) => !channels.includes(queued));
|
|
1117
|
+
for (const channel of channels) {
|
|
1118
|
+
if (channel.id != undefined &&
|
|
1119
|
+
this.dataChannels[channel.id] === channel) {
|
|
1120
|
+
delete this.dataChannels[channel.id];
|
|
1121
|
+
}
|
|
1122
|
+
// Test: tests/issue/815.test.ts "pc.close() closes every pending channel even if a close listener throws"
|
|
1123
|
+
channel.setReadyState("closed");
|
|
1124
|
+
}
|
|
483
1125
|
}
|
|
484
1126
|
async stop() {
|
|
485
|
-
this.
|
|
1127
|
+
const closedAlready = this.sctp.state === "closed";
|
|
1128
|
+
this.markStopped();
|
|
486
1129
|
this.dtlsTransport.dataReceiver = () => { };
|
|
487
1130
|
this.discardUnsentMessages();
|
|
488
|
-
|
|
1131
|
+
try {
|
|
1132
|
+
await this.sctp.stop();
|
|
1133
|
+
}
|
|
1134
|
+
finally {
|
|
1135
|
+
// An association already CLOSED emits no closed event again.
|
|
1136
|
+
if (closedAlready) {
|
|
1137
|
+
this.closeDataChannels({ clearQueue: false, includeQueued: false });
|
|
1138
|
+
}
|
|
1139
|
+
this.disposeSctpListeners();
|
|
1140
|
+
}
|
|
489
1141
|
}
|
|
490
1142
|
// Messages not yet handed to SCTP belong to the stopped association and must
|
|
491
|
-
// not leak into a later one. User messages are dropped
|
|
492
|
-
//
|
|
493
|
-
//
|
|
494
|
-
//
|
|
1143
|
+
// not leak into a later one. User messages are dropped; DATA_CHANNEL_OPEN is
|
|
1144
|
+
// kept only for channels still alive, so a channel that outlives the
|
|
1145
|
+
// transport (e.g. rollback) can be announced, while closed channels and
|
|
1146
|
+
// stale ACKs go.
|
|
1147
|
+
// Test: tests/transport/sctp.test.ts "stop discards unsent messages and keeps them in bufferedAmount"
|
|
495
1148
|
discardUnsentMessages() {
|
|
496
1149
|
const kept = new common_1.FifoQueue();
|
|
497
1150
|
for (const item of this.dataChannelQueue.toArray()) {
|
|
498
1151
|
const [channel, protocol, userData] = item;
|
|
499
|
-
if (protocol
|
|
500
|
-
|
|
501
|
-
}
|
|
502
|
-
else if (userData[0] === const_1.DATA_CHANNEL_OPEN &&
|
|
1152
|
+
if (protocol === const_1.WEBRTC_DCEP &&
|
|
1153
|
+
userData[0] === const_1.DATA_CHANNEL_OPEN &&
|
|
503
1154
|
channel.readyState !== "closed" &&
|
|
504
1155
|
channel.readyState !== "closing") {
|
|
505
1156
|
kept.push(item);
|
|
506
1157
|
}
|
|
507
1158
|
}
|
|
508
1159
|
this.dataChannelQueue = kept;
|
|
1160
|
+
this.closeAfterFlush.clear();
|
|
1161
|
+
for (const channel of this.unannounced) {
|
|
1162
|
+
if (channel.readyState === "closed" || channel.readyState === "closing") {
|
|
1163
|
+
this.unannounced.delete(channel);
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
509
1166
|
}
|
|
1167
|
+
/**
|
|
1168
|
+
* Reset our outgoing stream (RFC 8831 section 6.7), which closes the
|
|
1169
|
+
* peer's channel on it.
|
|
1170
|
+
* @see tests/issue/815.test.ts "issue 815: a DATA_CHANNEL_OPEN violating the odd/even rule on an unused stream"
|
|
1171
|
+
*/
|
|
1172
|
+
resetStream(streamId) {
|
|
1173
|
+
if (!this.sctp.reconfigQueue.includes(streamId)) {
|
|
1174
|
+
this.sctp.reconfigQueue.push(streamId);
|
|
1175
|
+
}
|
|
1176
|
+
if (this.sctp.reconfigQueue.length === 1) {
|
|
1177
|
+
this.sctp.transmitReconfigRequest();
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
/**
|
|
1181
|
+
* RFC 8832 section 6: an OPEN on a stream in use is not acknowledged and
|
|
1182
|
+
* the stream's channel closes (both ends claimed it).
|
|
1183
|
+
* @see tests/issue/815.test.ts "is not acknowledged and the stream is reset, so neither channel stays connecting"
|
|
1184
|
+
*/
|
|
1185
|
+
rejectOpenOnStreamInUse(channel) {
|
|
1186
|
+
if (this.unannounced.delete(channel)) {
|
|
1187
|
+
this.dataChannelQueue = this.dataChannelQueue.filter(([queued]) => queued !== channel);
|
|
1188
|
+
}
|
|
1189
|
+
this.dataChannelClose(channel);
|
|
1190
|
+
}
|
|
1191
|
+
/**
|
|
1192
|
+
* What {@link RTCDataChannel.close} calls; use that instead.
|
|
1193
|
+
* @see tests/datachannel/closeDelivery.test.ts "close() right after a burst (%o): every message arrives in order before close fires on the sender"
|
|
1194
|
+
* @see tests/datachannel/closeDelivery.test.ts "messages sent before close() while connecting reach the peer, then both ends close"
|
|
1195
|
+
* @see tests/datachannel/closeDelivery.test.ts "pc.close() before the association is established closes the channel and drops its messages"
|
|
1196
|
+
* @see tests/datachannel/closeDelivery.test.ts "an in-band channel closed before its DATA_CHANNEL_OPEN is sent closes at once and sends nothing"
|
|
1197
|
+
*/
|
|
510
1198
|
dataChannelClose(channel) {
|
|
511
1199
|
if (!["closing", "closed"].includes(channel.readyState)) {
|
|
512
|
-
channel.setReadyState("closing");
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
1200
|
+
channel.setReadyState("closing", { notifyClosing: false });
|
|
1201
|
+
// Test: tests/datachannel/closeDelivery.test.ts "pc.close() inside a stateChange subscriber of close() leaves the channel closed without error"
|
|
1202
|
+
if (channel.readyState !== "closing")
|
|
1203
|
+
return;
|
|
1204
|
+
const associationEnded = this.stopped || this.sctp.state === "closed";
|
|
1205
|
+
if (this.sctp.associationState === src_1.SCTP_STATE.ESTABLISHED &&
|
|
1206
|
+
!this.unannounced.has(channel)) {
|
|
1207
|
+
this.dataChannelFlush();
|
|
1208
|
+
this.resetStream(channel.id);
|
|
1209
|
+
}
|
|
1210
|
+
else if (!associationEnded &&
|
|
1211
|
+
!this.unannounced.has(channel) &&
|
|
1212
|
+
channel.id != undefined &&
|
|
1213
|
+
this.dataChannels[channel.id] === channel) {
|
|
1214
|
+
// Test: tests/datachannel/closeDelivery.test.ts "messages sent before close() while connecting reach the peer, then both ends close"
|
|
1215
|
+
this.closeAfterFlush.add(channel);
|
|
521
1216
|
}
|
|
522
1217
|
else {
|
|
523
|
-
|
|
1218
|
+
// Test: tests/issue/815.test.ts "closing one channel before negotiation keeps the OPEN of another (queue filtered by identity)"
|
|
1219
|
+
this.dataChannelQueue = this.dataChannelQueue.filter((queueItem) => queueItem[0] !== channel);
|
|
1220
|
+
this.unannounced.delete(channel);
|
|
524
1221
|
// Remove any pending reconfiguration requests for this channel
|
|
525
1222
|
this.sctp.reconfigQueue = this.sctp.reconfigQueue.filter((streamId) => streamId !== channel.id);
|
|
526
|
-
if (channel.id
|
|
1223
|
+
if (channel.id != undefined &&
|
|
1224
|
+
this.dataChannels[channel.id] === channel) {
|
|
527
1225
|
delete this.dataChannels[channel.id];
|
|
528
1226
|
}
|
|
529
1227
|
channel.setReadyState("closed");
|