werift 0.28.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.
Files changed (492) hide show
  1. package/README.md +182 -2
  2. package/lib/common/src/transport.d.ts +39 -5
  3. package/lib/common/src/transport.js +32 -7
  4. package/lib/common/src/transport.js.map +1 -1
  5. package/lib/dtls/src/carrier/direct.d.ts +67 -0
  6. package/lib/dtls/src/carrier/direct.js +226 -0
  7. package/lib/dtls/src/carrier/direct.js.map +1 -0
  8. package/lib/dtls/src/carrier/types.d.ts +81 -0
  9. package/lib/dtls/src/carrier/types.js +7 -0
  10. package/lib/dtls/src/carrier/types.js.map +1 -0
  11. package/lib/dtls/src/cipher/const.d.ts +6 -0
  12. package/lib/dtls/src/cipher/const.js +13 -2
  13. package/lib/dtls/src/cipher/const.js.map +1 -1
  14. package/lib/dtls/src/cipher/prf.js +11 -2
  15. package/lib/dtls/src/cipher/prf.js.map +1 -1
  16. package/lib/dtls/src/cipher/tls13/aead.d.ts +41 -0
  17. package/lib/dtls/src/cipher/tls13/aead.js +128 -0
  18. package/lib/dtls/src/cipher/tls13/aead.js.map +1 -0
  19. package/lib/dtls/src/cipher/tls13/hkdf.d.ts +30 -0
  20. package/lib/dtls/src/cipher/tls13/hkdf.js +76 -0
  21. package/lib/dtls/src/cipher/tls13/hkdf.js.map +1 -0
  22. package/lib/dtls/src/cipher/tls13/keySchedule.d.ts +70 -0
  23. package/lib/dtls/src/cipher/tls13/keySchedule.js +114 -0
  24. package/lib/dtls/src/cipher/tls13/keySchedule.js.map +1 -0
  25. package/lib/dtls/src/cipher/tls13/signature.d.ts +30 -0
  26. package/lib/dtls/src/cipher/tls13/signature.js +149 -0
  27. package/lib/dtls/src/cipher/tls13/signature.js.map +1 -0
  28. package/lib/dtls/src/client.d.ts +253 -0
  29. package/lib/dtls/src/client.js +1257 -16
  30. package/lib/dtls/src/client.js.map +1 -1
  31. package/lib/dtls/src/context/dtls.d.ts +45 -0
  32. package/lib/dtls/src/context/dtls.js +114 -0
  33. package/lib/dtls/src/context/dtls.js.map +1 -1
  34. package/lib/dtls/src/context/transport.d.ts +13 -0
  35. package/lib/dtls/src/context/transport.js +29 -1
  36. package/lib/dtls/src/context/transport.js.map +1 -1
  37. package/lib/dtls/src/engine/v1_3/connection-base.d.ts +520 -0
  38. package/lib/dtls/src/engine/v1_3/connection-base.js +1644 -0
  39. package/lib/dtls/src/engine/v1_3/connection-base.js.map +1 -0
  40. package/lib/dtls/src/engine/v1_3/connection.d.ts +181 -0
  41. package/lib/dtls/src/engine/v1_3/connection.js +680 -0
  42. package/lib/dtls/src/engine/v1_3/connection.js.map +1 -0
  43. package/lib/dtls/src/engine/v1_3/early-data-buffer.d.ts +38 -0
  44. package/lib/dtls/src/engine/v1_3/early-data-buffer.js +166 -0
  45. package/lib/dtls/src/engine/v1_3/early-data-buffer.js.map +1 -0
  46. package/lib/dtls/src/engine/v1_3/flight/certificate.d.ts +4 -0
  47. package/lib/dtls/src/engine/v1_3/flight/certificate.js +62 -0
  48. package/lib/dtls/src/engine/v1_3/flight/certificate.js.map +1 -0
  49. package/lib/dtls/src/engine/v1_3/flight/client/flight1.d.ts +8 -0
  50. package/lib/dtls/src/engine/v1_3/flight/client/flight1.js +119 -0
  51. package/lib/dtls/src/engine/v1_3/flight/client/flight1.js.map +1 -0
  52. package/lib/dtls/src/engine/v1_3/flight/client/flight4.d.ts +8 -0
  53. package/lib/dtls/src/engine/v1_3/flight/client/flight4.js +251 -0
  54. package/lib/dtls/src/engine/v1_3/flight/client/flight4.js.map +1 -0
  55. package/lib/dtls/src/engine/v1_3/flight/client/flight5.d.ts +5 -0
  56. package/lib/dtls/src/engine/v1_3/flight/client/flight5.js +99 -0
  57. package/lib/dtls/src/engine/v1_3/flight/client/flight5.js.map +1 -0
  58. package/lib/dtls/src/engine/v1_3/flight/dispatch.d.ts +12 -0
  59. package/lib/dtls/src/engine/v1_3/flight/dispatch.js +138 -0
  60. package/lib/dtls/src/engine/v1_3/flight/dispatch.js.map +1 -0
  61. package/lib/dtls/src/engine/v1_3/flight/extensions.d.ts +13 -0
  62. package/lib/dtls/src/engine/v1_3/flight/extensions.js +46 -0
  63. package/lib/dtls/src/engine/v1_3/flight/extensions.js.map +1 -0
  64. package/lib/dtls/src/engine/v1_3/flight/finished.d.ts +6 -0
  65. package/lib/dtls/src/engine/v1_3/flight/finished.js +16 -0
  66. package/lib/dtls/src/engine/v1_3/flight/finished.js.map +1 -0
  67. package/lib/dtls/src/engine/v1_3/flight/post-hs.d.ts +12 -0
  68. package/lib/dtls/src/engine/v1_3/flight/post-hs.js +94 -0
  69. package/lib/dtls/src/engine/v1_3/flight/post-hs.js.map +1 -0
  70. package/lib/dtls/src/engine/v1_3/flight/server/flight2.d.ts +21 -0
  71. package/lib/dtls/src/engine/v1_3/flight/server/flight2.js +227 -0
  72. package/lib/dtls/src/engine/v1_3/flight/server/flight2.js.map +1 -0
  73. package/lib/dtls/src/engine/v1_3/flight/server/flight4.d.ts +6 -0
  74. package/lib/dtls/src/engine/v1_3/flight/server/flight4.js +455 -0
  75. package/lib/dtls/src/engine/v1_3/flight/server/flight4.js.map +1 -0
  76. package/lib/dtls/src/engine/v1_3/flight/server/flight5.d.ts +5 -0
  77. package/lib/dtls/src/engine/v1_3/flight/server/flight5.js +48 -0
  78. package/lib/dtls/src/engine/v1_3/flight/server/flight5.js.map +1 -0
  79. package/lib/dtls/src/engine/v1_3/flight-tx.d.ts +119 -0
  80. package/lib/dtls/src/engine/v1_3/flight-tx.js +782 -0
  81. package/lib/dtls/src/engine/v1_3/flight-tx.js.map +1 -0
  82. package/lib/dtls/src/engine/v1_3/host.d.ts +86 -0
  83. package/lib/dtls/src/engine/v1_3/host.js +11 -0
  84. package/lib/dtls/src/engine/v1_3/host.js.map +1 -0
  85. package/lib/dtls/src/engine/v1_3/record-rx.d.ts +77 -0
  86. package/lib/dtls/src/engine/v1_3/record-rx.js +818 -0
  87. package/lib/dtls/src/engine/v1_3/record-rx.js.map +1 -0
  88. package/lib/dtls/src/engine/v1_3/transcript.d.ts +22 -0
  89. package/lib/dtls/src/engine/v1_3/transcript.js +65 -0
  90. package/lib/dtls/src/engine/v1_3/transcript.js.map +1 -0
  91. package/lib/dtls/src/engine/v1_3/types.d.ts +169 -0
  92. package/lib/dtls/src/engine/v1_3/types.js +113 -0
  93. package/lib/dtls/src/engine/v1_3/types.js.map +1 -0
  94. package/lib/dtls/src/flight/client/flight1.d.ts +7 -1
  95. package/lib/dtls/src/flight/client/flight1.js +9 -3
  96. package/lib/dtls/src/flight/client/flight1.js.map +1 -1
  97. package/lib/dtls/src/flight/client/flight3.d.ts +8 -0
  98. package/lib/dtls/src/flight/client/flight3.js +24 -4
  99. package/lib/dtls/src/flight/client/flight3.js.map +1 -1
  100. package/lib/dtls/src/flight/client/flight5.js +13 -1
  101. package/lib/dtls/src/flight/client/flight5.js.map +1 -1
  102. package/lib/dtls/src/flight/flight.d.ts +16 -0
  103. package/lib/dtls/src/flight/flight.js +109 -8
  104. package/lib/dtls/src/flight/flight.js.map +1 -1
  105. package/lib/dtls/src/flight/server/commitClientHello.d.ts +35 -0
  106. package/lib/dtls/src/flight/server/commitClientHello.js +149 -0
  107. package/lib/dtls/src/flight/server/commitClientHello.js.map +1 -0
  108. package/lib/dtls/src/flight/server/flight2.d.ts +12 -3
  109. package/lib/dtls/src/flight/server/flight2.js +29 -105
  110. package/lib/dtls/src/flight/server/flight2.js.map +1 -1
  111. package/lib/dtls/src/flight/server/flight4.js +14 -2
  112. package/lib/dtls/src/flight/server/flight4.js.map +1 -1
  113. package/lib/dtls/src/flight/server/flight6.js +8 -0
  114. package/lib/dtls/src/flight/server/flight6.js.map +1 -1
  115. package/lib/dtls/src/handshake/const.d.ts +10 -0
  116. package/lib/dtls/src/handshake/const.js +10 -0
  117. package/lib/dtls/src/handshake/const.js.map +1 -1
  118. package/lib/dtls/src/handshake/extensions/cookie.d.ts +113 -0
  119. package/lib/dtls/src/handshake/extensions/cookie.js +326 -0
  120. package/lib/dtls/src/handshake/extensions/cookie.js.map +1 -0
  121. package/lib/dtls/src/handshake/extensions/ids.d.ts +7 -0
  122. package/lib/dtls/src/handshake/extensions/ids.js +11 -0
  123. package/lib/dtls/src/handshake/extensions/ids.js.map +1 -0
  124. package/lib/dtls/src/handshake/extensions/keyShare.d.ts +28 -0
  125. package/lib/dtls/src/handshake/extensions/keyShare.js +156 -0
  126. package/lib/dtls/src/handshake/extensions/keyShare.js.map +1 -0
  127. package/lib/dtls/src/handshake/extensions/signatureAlgorithms.d.ts +27 -0
  128. package/lib/dtls/src/handshake/extensions/signatureAlgorithms.js +67 -0
  129. package/lib/dtls/src/handshake/extensions/signatureAlgorithms.js.map +1 -0
  130. package/lib/dtls/src/handshake/extensions/supportedVersions.d.ts +20 -0
  131. package/lib/dtls/src/handshake/extensions/supportedVersions.js +90 -0
  132. package/lib/dtls/src/handshake/extensions/supportedVersions.js.map +1 -0
  133. package/lib/dtls/src/handshake/extensions/unique.d.ts +7 -0
  134. package/lib/dtls/src/handshake/extensions/unique.js +19 -0
  135. package/lib/dtls/src/handshake/extensions/unique.js.map +1 -0
  136. package/lib/dtls/src/handshake/extensions/useSrtp.d.ts +26 -3
  137. package/lib/dtls/src/handshake/extensions/useSrtp.js +68 -12
  138. package/lib/dtls/src/handshake/extensions/useSrtp.js.map +1 -1
  139. package/lib/dtls/src/handshake/message/tls13/ack.d.ts +50 -0
  140. package/lib/dtls/src/handshake/message/tls13/ack.js +107 -0
  141. package/lib/dtls/src/handshake/message/tls13/ack.js.map +1 -0
  142. package/lib/dtls/src/handshake/message/tls13/certificate.d.ts +17 -0
  143. package/lib/dtls/src/handshake/message/tls13/certificate.js +112 -0
  144. package/lib/dtls/src/handshake/message/tls13/certificate.js.map +1 -0
  145. package/lib/dtls/src/handshake/message/tls13/certificateRequest.d.ts +17 -0
  146. package/lib/dtls/src/handshake/message/tls13/certificateRequest.js +99 -0
  147. package/lib/dtls/src/handshake/message/tls13/certificateRequest.js.map +1 -0
  148. package/lib/dtls/src/handshake/message/tls13/certificateVerify.d.ts +21 -0
  149. package/lib/dtls/src/handshake/message/tls13/certificateVerify.js +77 -0
  150. package/lib/dtls/src/handshake/message/tls13/certificateVerify.js.map +1 -0
  151. package/lib/dtls/src/handshake/message/tls13/encryptedExtensions.d.ts +19 -0
  152. package/lib/dtls/src/handshake/message/tls13/encryptedExtensions.js +56 -0
  153. package/lib/dtls/src/handshake/message/tls13/encryptedExtensions.js.map +1 -0
  154. package/lib/dtls/src/handshake/message/tls13/keyUpdate.d.ts +13 -0
  155. package/lib/dtls/src/handshake/message/tls13/keyUpdate.js +54 -0
  156. package/lib/dtls/src/handshake/message/tls13/keyUpdate.js.map +1 -0
  157. package/lib/dtls/src/handshake/message/tls13/newSessionTicket.d.ts +33 -0
  158. package/lib/dtls/src/handshake/message/tls13/newSessionTicket.js +158 -0
  159. package/lib/dtls/src/handshake/message/tls13/newSessionTicket.js.map +1 -0
  160. package/lib/dtls/src/handshake/random.d.ts +14 -0
  161. package/lib/dtls/src/handshake/random.js +24 -0
  162. package/lib/dtls/src/handshake/random.js.map +1 -1
  163. package/lib/dtls/src/handshake/validation.d.ts +26 -0
  164. package/lib/dtls/src/handshake/validation.js +32 -0
  165. package/lib/dtls/src/handshake/validation.js.map +1 -0
  166. package/lib/dtls/src/index.d.ts +6 -1
  167. package/lib/dtls/src/index.js +116 -44
  168. package/lib/dtls/src/index.js.map +1 -1
  169. package/lib/dtls/src/internal.d.ts +7 -0
  170. package/lib/dtls/src/internal.js +57 -0
  171. package/lib/dtls/src/internal.js.map +1 -0
  172. package/lib/dtls/src/peer.d.ts +49 -0
  173. package/lib/dtls/src/peer.js +54 -0
  174. package/lib/dtls/src/peer.js.map +1 -0
  175. package/lib/dtls/src/record/antiReplayWindow.d.ts +33 -0
  176. package/lib/dtls/src/record/antiReplayWindow.js +119 -0
  177. package/lib/dtls/src/record/antiReplayWindow.js.map +1 -0
  178. package/lib/dtls/src/record/const.d.ts +6 -0
  179. package/lib/dtls/src/record/const.js +6 -0
  180. package/lib/dtls/src/record/const.js.map +1 -1
  181. package/lib/dtls/src/record/message/fragment.d.ts +0 -2
  182. package/lib/dtls/src/record/message/fragment.js +36 -17
  183. package/lib/dtls/src/record/message/fragment.js.map +1 -1
  184. package/lib/dtls/src/record/message/reassembler.d.ts +62 -0
  185. package/lib/dtls/src/record/message/reassembler.js +249 -0
  186. package/lib/dtls/src/record/message/reassembler.js.map +1 -0
  187. package/lib/dtls/src/record/receive.js +24 -16
  188. package/lib/dtls/src/record/receive.js.map +1 -1
  189. package/lib/dtls/src/record/v1_3/header.d.ts +34 -0
  190. package/lib/dtls/src/record/v1_3/header.js +95 -0
  191. package/lib/dtls/src/record/v1_3/header.js.map +1 -0
  192. package/lib/dtls/src/record/v1_3/record.d.ts +133 -0
  193. package/lib/dtls/src/record/v1_3/record.js +370 -0
  194. package/lib/dtls/src/record/v1_3/record.js.map +1 -0
  195. package/lib/dtls/src/retransmission.d.ts +26 -0
  196. package/lib/dtls/src/retransmission.js +39 -0
  197. package/lib/dtls/src/retransmission.js.map +1 -0
  198. package/lib/dtls/src/server.d.ts +38 -0
  199. package/lib/dtls/src/server.js +367 -20
  200. package/lib/dtls/src/server.js.map +1 -1
  201. package/lib/dtls/src/socket.d.ts +379 -35
  202. package/lib/dtls/src/socket.js +1105 -132
  203. package/lib/dtls/src/socket.js.map +1 -1
  204. package/lib/dtls/src/version.d.ts +89 -0
  205. package/lib/dtls/src/version.js +204 -0
  206. package/lib/dtls/src/version.js.map +1 -0
  207. package/lib/ice/src/consent.d.ts +78 -1
  208. package/lib/ice/src/consent.js +236 -24
  209. package/lib/ice/src/consent.js.map +1 -1
  210. package/lib/ice/src/dns/lookup.d.ts +10 -0
  211. package/lib/ice/src/dns/lookup.js +130 -3
  212. package/lib/ice/src/dns/lookup.js.map +1 -1
  213. package/lib/ice/src/exceptions.d.ts +9 -0
  214. package/lib/ice/src/exceptions.js +14 -1
  215. package/lib/ice/src/exceptions.js.map +1 -1
  216. package/lib/ice/src/failover.d.ts +270 -0
  217. package/lib/ice/src/failover.js +674 -0
  218. package/lib/ice/src/failover.js.map +1 -0
  219. package/lib/ice/src/gatheringError.d.ts +28 -0
  220. package/lib/ice/src/gatheringError.js +17 -0
  221. package/lib/ice/src/gatheringError.js.map +1 -0
  222. package/lib/ice/src/ice.d.ts +265 -9
  223. package/lib/ice/src/ice.js +1624 -236
  224. package/lib/ice/src/ice.js.map +1 -1
  225. package/lib/ice/src/iceBase.d.ts +197 -6
  226. package/lib/ice/src/iceBase.js +157 -7
  227. package/lib/ice/src/iceBase.js.map +1 -1
  228. package/lib/ice/src/index.d.ts +2 -0
  229. package/lib/ice/src/index.js +4 -1
  230. package/lib/ice/src/index.js.map +1 -1
  231. package/lib/ice/src/internal/datagram.d.ts +37 -0
  232. package/lib/ice/src/internal/datagram.js +45 -0
  233. package/lib/ice/src/internal/datagram.js.map +1 -0
  234. package/lib/ice/src/internal/hostInterfaces.d.ts +13 -2
  235. package/lib/ice/src/internal/hostInterfaces.js +16 -4
  236. package/lib/ice/src/internal/hostInterfaces.js.map +1 -1
  237. package/lib/ice/src/internal/sped-bind.d.ts +44 -0
  238. package/lib/ice/src/internal/sped-bind.js +53 -0
  239. package/lib/ice/src/internal/sped-bind.js.map +1 -0
  240. package/lib/ice/src/internal/sped-binding-cache.d.ts +27 -0
  241. package/lib/ice/src/internal/sped-binding-cache.js +102 -0
  242. package/lib/ice/src/internal/sped-binding-cache.js.map +1 -0
  243. package/lib/ice/src/internal/sped.d.ts +15 -0
  244. package/lib/ice/src/internal/sped.js +62 -0
  245. package/lib/ice/src/internal/sped.js.map +1 -0
  246. package/lib/ice/src/nomination/selectionController.d.ts +111 -0
  247. package/lib/ice/src/nomination/selectionController.js +172 -0
  248. package/lib/ice/src/nomination/selectionController.js.map +1 -0
  249. package/lib/ice/src/nomination/selectionReplacement.d.ts +40 -0
  250. package/lib/ice/src/nomination/selectionReplacement.js +65 -7
  251. package/lib/ice/src/nomination/selectionReplacement.js.map +1 -1
  252. package/lib/ice/src/sped/draft00/codec.d.ts +20 -0
  253. package/lib/ice/src/sped/draft00/codec.js +59 -0
  254. package/lib/ice/src/sped/draft00/codec.js.map +1 -0
  255. package/lib/ice/src/sped/draft00/constants.d.ts +14 -0
  256. package/lib/ice/src/sped/draft00/constants.js +18 -0
  257. package/lib/ice/src/sped/draft00/constants.js.map +1 -0
  258. package/lib/ice/src/sped/draft00/index.d.ts +6 -0
  259. package/lib/ice/src/sped/draft00/index.js +26 -0
  260. package/lib/ice/src/sped/draft00/index.js.map +1 -0
  261. package/lib/ice/src/sped/draft00/mtu.d.ts +38 -0
  262. package/lib/ice/src/sped/draft00/mtu.js +96 -0
  263. package/lib/ice/src/sped/draft00/mtu.js.map +1 -0
  264. package/lib/ice/src/sped/draft00/session.d.ts +86 -0
  265. package/lib/ice/src/sped/draft00/session.js +353 -0
  266. package/lib/ice/src/sped/draft00/session.js.map +1 -0
  267. package/lib/ice/src/sped/draft00/types.d.ts +16 -0
  268. package/lib/ice/src/sped/draft00/types.js +3 -0
  269. package/lib/ice/src/sped/draft00/types.js.map +1 -0
  270. package/lib/ice/src/sped/runtime.d.ts +188 -0
  271. package/lib/ice/src/sped/runtime.js +643 -0
  272. package/lib/ice/src/sped/runtime.js.map +1 -0
  273. package/lib/ice/src/stun/protocol.d.ts +29 -0
  274. package/lib/ice/src/stun/protocol.js +91 -4
  275. package/lib/ice/src/stun/protocol.js.map +1 -1
  276. package/lib/ice/src/stun/rawAttributeValue.d.ts +1 -0
  277. package/lib/ice/src/stun/rawAttributeValue.js +6 -0
  278. package/lib/ice/src/stun/rawAttributeValue.js.map +1 -0
  279. package/lib/ice/src/stun/tcpProtocol.d.ts +1 -0
  280. package/lib/ice/src/stun/tcpProtocol.js +14 -2
  281. package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
  282. package/lib/ice/src/stun/transaction.d.ts +4 -0
  283. package/lib/ice/src/stun/transaction.js +23 -0
  284. package/lib/ice/src/stun/transaction.js.map +1 -1
  285. package/lib/ice/src/turn/protocol.d.ts +21 -2
  286. package/lib/ice/src/turn/protocol.js +93 -8
  287. package/lib/ice/src/turn/protocol.js.map +1 -1
  288. package/lib/ice/src/types/model.d.ts +9 -0
  289. package/lib/ice/src/types/model.js.map +1 -1
  290. package/lib/ice/src/utils.d.ts +13 -0
  291. package/lib/ice/src/utils.js +13 -0
  292. package/lib/ice/src/utils.js.map +1 -1
  293. package/lib/ice-server/src/stun/message.d.ts +15 -2
  294. package/lib/ice-server/src/stun/message.js +156 -25
  295. package/lib/ice-server/src/stun/message.js.map +1 -1
  296. package/lib/ice-server/src/stun/rawAttributeValue.d.ts +6 -0
  297. package/lib/ice-server/src/stun/rawAttributeValue.js +12 -0
  298. package/lib/ice-server/src/stun/rawAttributeValue.js.map +1 -0
  299. package/lib/index.mjs +19568 -3106
  300. package/lib/nonstandard/index.mjs +2539 -1175
  301. package/lib/polyfill/dom.mjs +33210 -16872
  302. package/lib/polyfill/index.mjs +33345 -17013
  303. package/lib/rtp/src/extra/processor/fsRetry.d.ts +20 -0
  304. package/lib/rtp/src/extra/processor/fsRetry.js +73 -0
  305. package/lib/rtp/src/extra/processor/fsRetry.js.map +1 -0
  306. package/lib/rtp/src/extra/processor/webm.d.ts +6 -0
  307. package/lib/rtp/src/extra/processor/webm.js +6 -2
  308. package/lib/rtp/src/extra/processor/webm.js.map +1 -1
  309. package/lib/rtp/src/extra/processor/webmCallback.d.ts +11 -0
  310. package/lib/rtp/src/extra/processor/webmCallback.js +23 -31
  311. package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
  312. package/lib/rtp/src/extra/processor/webmFileWriter.d.ts +24 -0
  313. package/lib/rtp/src/extra/processor/webmFileWriter.js +94 -0
  314. package/lib/rtp/src/extra/processor/webmFileWriter.js.map +1 -0
  315. package/lib/sctp/src/chunk.d.ts +5 -0
  316. package/lib/sctp/src/chunk.js +10 -0
  317. package/lib/sctp/src/chunk.js.map +1 -1
  318. package/lib/sctp/src/index.d.ts +1 -1
  319. package/lib/sctp/src/index.js +4 -1
  320. package/lib/sctp/src/index.js.map +1 -1
  321. package/lib/sctp/src/sctp.d.ts +81 -5
  322. package/lib/sctp/src/sctp.js +273 -28
  323. package/lib/sctp/src/sctp.js.map +1 -1
  324. package/lib/webrtc/src/api/compatibilityOptions.d.ts +11 -1
  325. package/lib/webrtc/src/api/compatibilityOptions.js +11 -1
  326. package/lib/webrtc/src/api/compatibilityOptions.js.map +1 -1
  327. package/lib/webrtc/src/api/peerConfig.d.ts +210 -13
  328. package/lib/webrtc/src/api/peerConfig.js +100 -5
  329. package/lib/webrtc/src/api/peerConfig.js.map +1 -1
  330. package/lib/webrtc/src/api/peerConnectionEvents.d.ts +10 -1
  331. package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -1
  332. package/lib/webrtc/src/dataChannel.d.ts +122 -10
  333. package/lib/webrtc/src/dataChannel.js +214 -20
  334. package/lib/webrtc/src/dataChannel.js.map +1 -1
  335. package/lib/webrtc/src/media/domEventTarget.d.ts +55 -0
  336. package/lib/webrtc/src/media/domEventTarget.js +216 -0
  337. package/lib/webrtc/src/media/domEventTarget.js.map +1 -0
  338. package/lib/webrtc/src/media/index.d.ts +2 -0
  339. package/lib/webrtc/src/media/index.js +1 -0
  340. package/lib/webrtc/src/media/index.js.map +1 -1
  341. package/lib/webrtc/src/media/parameters.d.ts +5 -0
  342. package/lib/webrtc/src/media/parameters.js +10 -0
  343. package/lib/webrtc/src/media/parameters.js.map +1 -1
  344. package/lib/webrtc/src/media/receiver/receiverTwcc.d.ts +10 -0
  345. package/lib/webrtc/src/media/receiver/receiverTwcc.js +4 -10
  346. package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
  347. package/lib/webrtc/src/media/router.d.ts +6 -0
  348. package/lib/webrtc/src/media/router.js +39 -1
  349. package/lib/webrtc/src/media/router.js.map +1 -1
  350. package/lib/webrtc/src/media/rtpReceiver.d.ts +56 -6
  351. package/lib/webrtc/src/media/rtpReceiver.js +165 -15
  352. package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
  353. package/lib/webrtc/src/media/rtpSender.d.ts +1 -1
  354. package/lib/webrtc/src/media/rtpSender.js +4 -3
  355. package/lib/webrtc/src/media/rtpSender.js.map +1 -1
  356. package/lib/webrtc/src/media/rtpTransceiver.d.ts +29 -11
  357. package/lib/webrtc/src/media/rtpTransceiver.js +31 -9
  358. package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
  359. package/lib/webrtc/src/media/stats.d.ts +13 -0
  360. package/lib/webrtc/src/media/stats.js.map +1 -1
  361. package/lib/webrtc/src/media/track.d.ts +103 -11
  362. package/lib/webrtc/src/media/track.js +241 -19
  363. package/lib/webrtc/src/media/track.js.map +1 -1
  364. package/lib/webrtc/src/media/trackConstraints.d.ts +80 -0
  365. package/lib/webrtc/src/media/trackConstraints.js +141 -0
  366. package/lib/webrtc/src/media/trackConstraints.js.map +1 -0
  367. package/lib/webrtc/src/negotiation/internalState.d.ts +0 -4
  368. package/lib/webrtc/src/negotiation/internalState.js +0 -11
  369. package/lib/webrtc/src/negotiation/internalState.js.map +1 -1
  370. package/lib/webrtc/src/negotiation/remoteCandidates.d.ts +20 -1
  371. package/lib/webrtc/src/negotiation/remoteCandidates.js +29 -1
  372. package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -1
  373. package/lib/webrtc/src/negotiation/transportActivation.d.ts +4 -0
  374. package/lib/webrtc/src/negotiation/transportActivation.js +112 -11
  375. package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -1
  376. package/lib/webrtc/src/negotiationTransaction.d.ts +25 -4
  377. package/lib/webrtc/src/negotiationTransaction.js +27 -6
  378. package/lib/webrtc/src/negotiationTransaction.js.map +1 -1
  379. package/lib/webrtc/src/nonstandard/dummyMedia.d.ts +6 -0
  380. package/lib/webrtc/src/nonstandard/dummyMedia.js +14 -19
  381. package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
  382. package/lib/webrtc/src/nonstandard/navigator.d.ts +1 -1
  383. package/lib/webrtc/src/nonstandard/recorder/index.js +5 -1
  384. package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
  385. package/lib/webrtc/src/nonstandard/recorder/writer/webm.d.ts +6 -1
  386. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +31 -2
  387. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
  388. package/lib/webrtc/src/nonstandard/userMedia/packetizer.d.ts +16 -0
  389. package/lib/webrtc/src/nonstandard/userMedia/packetizer.js +25 -0
  390. package/lib/webrtc/src/nonstandard/userMedia/packetizer.js.map +1 -1
  391. package/lib/webrtc/src/nonstandard/userMedia.js +6 -13
  392. package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
  393. package/lib/webrtc/src/peerConnection.d.ts +44 -8
  394. package/lib/webrtc/src/peerConnection.js +88 -9
  395. package/lib/webrtc/src/peerConnection.js.map +1 -1
  396. package/lib/webrtc/src/polyfill/api.d.ts +2 -1
  397. package/lib/webrtc/src/polyfill/api.js +3 -3
  398. package/lib/webrtc/src/polyfill/api.js.map +1 -1
  399. package/lib/webrtc/src/polyfill/dom.d.ts +21 -7
  400. package/lib/webrtc/src/polyfill/dom.js +15 -0
  401. package/lib/webrtc/src/polyfill/dom.js.map +1 -1
  402. package/lib/webrtc/src/polyfill/globals.d.ts +6 -2
  403. package/lib/webrtc/src/polyfill/globals.js.map +1 -1
  404. package/lib/webrtc/src/polyfill/index.d.ts +1 -1
  405. package/lib/webrtc/src/polyfill/index.js +1 -1
  406. package/lib/webrtc/src/polyfill/index.js.map +1 -1
  407. package/lib/webrtc/src/polyfill/install.d.ts +5 -1
  408. package/lib/webrtc/src/polyfill/install.js +2 -2
  409. package/lib/webrtc/src/polyfill/install.js.map +1 -1
  410. package/lib/webrtc/src/polyfill/mediaDevices.js +28 -4
  411. package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
  412. package/lib/webrtc/src/polyfill/peerConnectionConfig.d.ts +6 -0
  413. package/lib/webrtc/src/polyfill/peerConnectionConfig.js +15 -4
  414. package/lib/webrtc/src/polyfill/peerConnectionConfig.js.map +1 -1
  415. package/lib/webrtc/src/polyfill/selectSettings.d.ts +4 -14
  416. package/lib/webrtc/src/polyfill/selectSettings.js +10 -106
  417. package/lib/webrtc/src/polyfill/selectSettings.js.map +1 -1
  418. package/lib/webrtc/src/polyfill/sourceIo.d.ts +1 -2
  419. package/lib/webrtc/src/polyfill/sourceIo.js +6 -6
  420. package/lib/webrtc/src/polyfill/sourceIo.js.map +1 -1
  421. package/lib/webrtc/src/sctpManager.d.ts +31 -18
  422. package/lib/webrtc/src/sctpManager.js +158 -38
  423. package/lib/webrtc/src/sctpManager.js.map +1 -1
  424. package/lib/webrtc/src/sdp.d.ts +38 -2
  425. package/lib/webrtc/src/sdp.js +84 -3
  426. package/lib/webrtc/src/sdp.js.map +1 -1
  427. package/lib/webrtc/src/sdpManager.d.ts +19 -9
  428. package/lib/webrtc/src/sdpManager.js +26 -4
  429. package/lib/webrtc/src/sdpManager.js.map +1 -1
  430. package/lib/webrtc/src/secureTransportManager.d.ts +11 -2
  431. package/lib/webrtc/src/secureTransportManager.js +84 -5
  432. package/lib/webrtc/src/secureTransportManager.js.map +1 -1
  433. package/lib/webrtc/src/transceiverManager.d.ts +5 -2
  434. package/lib/webrtc/src/transceiverManager.js +42 -14
  435. package/lib/webrtc/src/transceiverManager.js.map +1 -1
  436. package/lib/webrtc/src/transport/dtls-application-gate.d.ts +1 -0
  437. package/lib/webrtc/src/transport/dtls-application-gate.js +143 -0
  438. package/lib/webrtc/src/transport/dtls-application-gate.js.map +1 -0
  439. package/lib/webrtc/src/transport/dtls-attempt.d.ts +1 -0
  440. package/lib/webrtc/src/transport/dtls-attempt.js +79 -0
  441. package/lib/webrtc/src/transport/dtls-attempt.js.map +1 -0
  442. package/lib/webrtc/src/transport/dtls-certificate.d.ts +24 -0
  443. package/lib/webrtc/src/transport/dtls-certificate.js +98 -0
  444. package/lib/webrtc/src/transport/dtls-certificate.js.map +1 -0
  445. package/lib/webrtc/src/transport/dtls-fingerprint.d.ts +7 -0
  446. package/lib/webrtc/src/transport/dtls-fingerprint.js +66 -0
  447. package/lib/webrtc/src/transport/dtls-fingerprint.js.map +1 -0
  448. package/lib/webrtc/src/transport/dtls-ice-transport.d.ts +1 -0
  449. package/lib/webrtc/src/transport/dtls-ice-transport.js +123 -0
  450. package/lib/webrtc/src/transport/dtls-ice-transport.js.map +1 -0
  451. package/lib/webrtc/src/transport/dtls-media-queue.d.ts +1 -0
  452. package/lib/webrtc/src/transport/dtls-media-queue.js +95 -0
  453. package/lib/webrtc/src/transport/dtls-media-queue.js.map +1 -0
  454. package/lib/webrtc/src/transport/dtls-readiness.d.ts +1 -0
  455. package/lib/webrtc/src/transport/dtls-readiness.js +173 -0
  456. package/lib/webrtc/src/transport/dtls-readiness.js.map +1 -0
  457. package/lib/webrtc/src/transport/dtls-sped-handshake.d.ts +1 -0
  458. package/lib/webrtc/src/transport/dtls-sped-handshake.js +146 -0
  459. package/lib/webrtc/src/transport/dtls-sped-handshake.js.map +1 -0
  460. package/lib/webrtc/src/transport/dtls-srtp.d.ts +1 -0
  461. package/lib/webrtc/src/transport/dtls-srtp.js +133 -0
  462. package/lib/webrtc/src/transport/dtls-srtp.js.map +1 -0
  463. package/lib/webrtc/src/transport/dtls-stats.d.ts +1 -0
  464. package/lib/webrtc/src/transport/dtls-stats.js +134 -0
  465. package/lib/webrtc/src/transport/dtls-stats.js.map +1 -0
  466. package/lib/webrtc/src/transport/dtls-types.d.ts +23 -0
  467. package/lib/webrtc/src/transport/dtls-types.js +11 -0
  468. package/lib/webrtc/src/transport/dtls-types.js.map +1 -0
  469. package/lib/webrtc/src/transport/dtls.d.ts +150 -55
  470. package/lib/webrtc/src/transport/dtls.js +1017 -556
  471. package/lib/webrtc/src/transport/dtls.js.map +1 -1
  472. package/lib/webrtc/src/transport/ice.d.ts +35 -2
  473. package/lib/webrtc/src/transport/ice.js +147 -14
  474. package/lib/webrtc/src/transport/ice.js.map +1 -1
  475. package/lib/webrtc/src/transport/iceCandidateAttribute.d.ts +4 -2
  476. package/lib/webrtc/src/transport/iceCandidateAttribute.js.map +1 -1
  477. package/lib/webrtc/src/transport/sctp.d.ts +126 -2
  478. package/lib/webrtc/src/transport/sctp.js +747 -134
  479. package/lib/webrtc/src/transport/sctp.js.map +1 -1
  480. package/lib/webrtc/src/transport/sped.d.ts +139 -0
  481. package/lib/webrtc/src/transport/sped.js +757 -0
  482. package/lib/webrtc/src/transport/sped.js.map +1 -0
  483. package/lib/webrtc/src/types/util.d.ts +6 -0
  484. package/lib/webrtc/src/types/util.js.map +1 -1
  485. package/lib/webrtc/src/utils.d.ts +1 -1
  486. package/lib/webrtc/src/webidl.d.ts +15 -0
  487. package/lib/webrtc/src/webidl.js +34 -0
  488. package/lib/webrtc/src/webidl.js.map +1 -0
  489. package/package.json +7 -3
  490. package/lib/webrtc/src/polyfill/rtcSessionDescription.d.ts +0 -18
  491. package/lib/webrtc/src/polyfill/rtcSessionDescription.js +0 -36
  492. package/lib/webrtc/src/polyfill/rtcSessionDescription.js.map +0 -1
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Package-private Binding Response replay cache for SPED handshake.
3
+ * Not re-exported from `src/index.ts`.
4
+ *
5
+ * Exact Response bytes must be replayed for STUN retransmits (same transaction
6
+ * id) so L1 round-robin does not change the payload. Entries are TTL'd to the
7
+ * STUN transaction lifetime, LRU-capped, and only stored while SPED is
8
+ * embedding.
9
+ */
10
+ export declare const SPED_BINDING_RESPONSE_CACHE_MAX = 32;
11
+ export declare class SpedBindingResponseCache {
12
+ private readonly entries;
13
+ private readonly inFlight;
14
+ get size(): number;
15
+ get(txHex: string, now?: number): Buffer | undefined;
16
+ set(txHex: string, bytes: Buffer, ttlMs: number, now?: number): void;
17
+ clearEntries(): void;
18
+ clear(): void;
19
+ prune(now?: number): void;
20
+ getInFlight(txHex: string): Promise<Buffer | undefined> | undefined;
21
+ begin(txHex: string): {
22
+ promise: Promise<Buffer | undefined>;
23
+ finish: (bytes: Buffer | undefined) => void;
24
+ };
25
+ abortInFlight(): void;
26
+ private evictOverflow;
27
+ }
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ /**
3
+ * Package-private Binding Response replay cache for SPED handshake.
4
+ * Not re-exported from `src/index.ts`.
5
+ *
6
+ * Exact Response bytes must be replayed for STUN retransmits (same transaction
7
+ * id) so L1 round-robin does not change the payload. Entries are TTL'd to the
8
+ * STUN transaction lifetime, LRU-capped, and only stored while SPED is
9
+ * embedding.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SpedBindingResponseCache = exports.SPED_BINDING_RESPONSE_CACHE_MAX = void 0;
13
+ exports.SPED_BINDING_RESPONSE_CACHE_MAX = 32;
14
+ class SpedBindingResponseCache {
15
+ constructor() {
16
+ Object.defineProperty(this, "entries", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: new Map()
21
+ });
22
+ Object.defineProperty(this, "inFlight", {
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true,
26
+ value: new Map()
27
+ });
28
+ }
29
+ get size() {
30
+ this.prune();
31
+ return this.entries.size;
32
+ }
33
+ get(txHex, now = Date.now()) {
34
+ this.prune(now);
35
+ const entry = this.entries.get(txHex);
36
+ if (!entry) {
37
+ return undefined;
38
+ }
39
+ this.entries.delete(txHex);
40
+ this.entries.set(txHex, entry);
41
+ return entry.bytes;
42
+ }
43
+ set(txHex, bytes, ttlMs, now = Date.now()) {
44
+ this.prune(now);
45
+ this.entries.delete(txHex);
46
+ this.entries.set(txHex, { bytes, expiresAt: now + ttlMs });
47
+ this.evictOverflow();
48
+ }
49
+ clearEntries() {
50
+ this.entries.clear();
51
+ }
52
+ clear() {
53
+ this.clearEntries();
54
+ this.abortInFlight();
55
+ }
56
+ prune(now = Date.now()) {
57
+ for (const [key, entry] of this.entries) {
58
+ if (entry.expiresAt <= now) {
59
+ this.entries.delete(key);
60
+ }
61
+ }
62
+ }
63
+ getInFlight(txHex) {
64
+ return this.inFlight.get(txHex)?.promise;
65
+ }
66
+ begin(txHex) {
67
+ let settle;
68
+ const promise = new Promise((resolve) => {
69
+ settle = resolve;
70
+ });
71
+ const slot = { promise, settle };
72
+ this.inFlight.set(txHex, slot);
73
+ return {
74
+ promise,
75
+ finish: (bytes) => {
76
+ if (this.inFlight.get(txHex) !== slot) {
77
+ return;
78
+ }
79
+ this.inFlight.delete(txHex);
80
+ settle(bytes);
81
+ },
82
+ };
83
+ }
84
+ abortInFlight() {
85
+ const pending = [...this.inFlight.values()];
86
+ this.inFlight.clear();
87
+ for (const slot of pending) {
88
+ slot.settle(undefined);
89
+ }
90
+ }
91
+ evictOverflow() {
92
+ while (this.entries.size > exports.SPED_BINDING_RESPONSE_CACHE_MAX) {
93
+ const oldest = this.entries.keys().next().value;
94
+ if (oldest === undefined) {
95
+ break;
96
+ }
97
+ this.entries.delete(oldest);
98
+ }
99
+ }
100
+ }
101
+ exports.SpedBindingResponseCache = SpedBindingResponseCache;
102
+ //# sourceMappingURL=sped-binding-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sped-binding-cache.js","sourceRoot":"","sources":["../../../../../ice/src/internal/sped-binding-cache.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAEU,QAAA,+BAA+B,GAAG,EAAE,CAAC;AAYlD,MAAa,wBAAwB;IAArC;QACmB;;;;mBAAU,IAAI,GAAG,EAAsB;WAAC;QACxC;;;;mBAAW,IAAI,GAAG,EAAwB;WAAC;IAqF9D,CAAC;IAnFC,IAAI,IAAI;QACN,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,GAAG,CAAC,KAAa,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;QACjC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAChB,MAAM,KAA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CACF;AAvFD,4DAuFC","sourcesContent":["/**\n * Package-private Binding Response replay cache for SPED handshake.\n * Not re-exported from `src/index.ts`.\n *\n * Exact Response bytes must be replayed for STUN retransmits (same transaction\n * id) so L1 round-robin does not change the payload. Entries are TTL'd to the\n * STUN transaction lifetime, LRU-capped, and only stored while SPED is\n * embedding.\n */\n\nexport const SPED_BINDING_RESPONSE_CACHE_MAX = 32;\n\ntype CacheEntry = {\n bytes: Buffer;\n expiresAt: number;\n};\n\ntype InFlightSlot = {\n promise: Promise<Buffer | undefined>;\n settle: (bytes: Buffer | undefined) => void;\n};\n\nexport class SpedBindingResponseCache {\n private readonly entries = new Map<string, CacheEntry>();\n private readonly inFlight = new Map<string, InFlightSlot>();\n\n get size(): number {\n this.prune();\n return this.entries.size;\n }\n\n get(txHex: string, now = Date.now()): Buffer | undefined {\n this.prune(now);\n const entry = this.entries.get(txHex);\n if (!entry) {\n return undefined;\n }\n this.entries.delete(txHex);\n this.entries.set(txHex, entry);\n return entry.bytes;\n }\n\n set(txHex: string, bytes: Buffer, ttlMs: number, now = Date.now()): void {\n this.prune(now);\n this.entries.delete(txHex);\n this.entries.set(txHex, { bytes, expiresAt: now + ttlMs });\n this.evictOverflow();\n }\n\n clearEntries(): void {\n this.entries.clear();\n }\n\n clear(): void {\n this.clearEntries();\n this.abortInFlight();\n }\n\n prune(now = Date.now()): void {\n for (const [key, entry] of this.entries) {\n if (entry.expiresAt <= now) {\n this.entries.delete(key);\n }\n }\n }\n\n getInFlight(txHex: string): Promise<Buffer | undefined> | undefined {\n return this.inFlight.get(txHex)?.promise;\n }\n\n begin(txHex: string): {\n promise: Promise<Buffer | undefined>;\n finish: (bytes: Buffer | undefined) => void;\n } {\n let settle!: (bytes: Buffer | undefined) => void;\n const promise = new Promise<Buffer | undefined>((resolve) => {\n settle = resolve;\n });\n const slot: InFlightSlot = { promise, settle };\n this.inFlight.set(txHex, slot);\n return {\n promise,\n finish: (bytes) => {\n if (this.inFlight.get(txHex) !== slot) {\n return;\n }\n this.inFlight.delete(txHex);\n settle(bytes);\n },\n };\n }\n\n abortInFlight(): void {\n const pending = [...this.inFlight.values()];\n this.inFlight.clear();\n for (const slot of pending) {\n slot.settle(undefined);\n }\n }\n\n private evictOverflow(): void {\n while (this.entries.size > SPED_BINDING_RESPONSE_CACHE_MAX) {\n const oldest = this.entries.keys().next().value;\n if (oldest === undefined) {\n break;\n }\n this.entries.delete(oldest);\n }\n }\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import { SpedSession } from "../sped/draft00/session";
2
+ import { type SpedHooks, SpedRuntime } from "../sped/runtime";
3
+ export { DTLS_IN_STUN_ACK, DTLS_IN_STUN_DATA, decodeSpedAck, decodeSpedData, encodeSpedAck, encodeSpedData, spedDataCrc32, } from "../sped/draft00";
4
+ export { SpedSession } from "../sped/draft00/session";
5
+ export type { SpedDirectHandshakeReadiness, SpedHooks } from "../sped/runtime";
6
+ export { isSpedEligiblePair, isSpedEligibleProtocol, sameCandidatePair, } from "../sped/runtime";
7
+ export interface SpedHandle {
8
+ session: SpedSession;
9
+ runtime: SpedRuntime;
10
+ onFlightCreated: (packets: readonly Buffer[], options?: {
11
+ fromCarrier?: boolean;
12
+ }) => void;
13
+ onHandshakeComplete: () => void;
14
+ }
15
+ export declare function attachSpedToConnection(connection: Connection, hooks: SpedHooks): SpedHandle;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sameCandidatePair = exports.isSpedEligibleProtocol = exports.isSpedEligiblePair = exports.SpedSession = exports.spedDataCrc32 = exports.encodeSpedData = exports.encodeSpedAck = exports.decodeSpedData = exports.decodeSpedAck = exports.DTLS_IN_STUN_DATA = exports.DTLS_IN_STUN_ACK = void 0;
4
+ exports.attachSpedToConnection = attachSpedToConnection;
5
+ const session_1 = require("../sped/draft00/session");
6
+ const runtime_1 = require("../sped/runtime");
7
+ const sped_bind_1 = require("./sped-bind");
8
+ var draft00_1 = require("../sped/draft00");
9
+ Object.defineProperty(exports, "DTLS_IN_STUN_ACK", { enumerable: true, get: function () { return draft00_1.DTLS_IN_STUN_ACK; } });
10
+ Object.defineProperty(exports, "DTLS_IN_STUN_DATA", { enumerable: true, get: function () { return draft00_1.DTLS_IN_STUN_DATA; } });
11
+ Object.defineProperty(exports, "decodeSpedAck", { enumerable: true, get: function () { return draft00_1.decodeSpedAck; } });
12
+ Object.defineProperty(exports, "decodeSpedData", { enumerable: true, get: function () { return draft00_1.decodeSpedData; } });
13
+ Object.defineProperty(exports, "encodeSpedAck", { enumerable: true, get: function () { return draft00_1.encodeSpedAck; } });
14
+ Object.defineProperty(exports, "encodeSpedData", { enumerable: true, get: function () { return draft00_1.encodeSpedData; } });
15
+ Object.defineProperty(exports, "spedDataCrc32", { enumerable: true, get: function () { return draft00_1.spedDataCrc32; } });
16
+ var session_2 = require("../sped/draft00/session");
17
+ Object.defineProperty(exports, "SpedSession", { enumerable: true, get: function () { return session_2.SpedSession; } });
18
+ var runtime_2 = require("../sped/runtime");
19
+ Object.defineProperty(exports, "isSpedEligiblePair", { enumerable: true, get: function () { return runtime_2.isSpedEligiblePair; } });
20
+ Object.defineProperty(exports, "isSpedEligibleProtocol", { enumerable: true, get: function () { return runtime_2.isSpedEligibleProtocol; } });
21
+ Object.defineProperty(exports, "sameCandidatePair", { enumerable: true, get: function () { return runtime_2.sameCandidatePair; } });
22
+ function attachSpedToConnection(connection, hooks) {
23
+ const session = new session_1.SpedSession(connection.generation);
24
+ const runtime = new runtime_1.SpedRuntime(session, {
25
+ ...hooks,
26
+ onHandshakeComplete: () => {
27
+ connection.forgetSpedBindingResponseCache();
28
+ hooks.onHandshakeComplete?.();
29
+ },
30
+ inject: async (bytes, peer, generation) => {
31
+ runtime.markCarrierInject();
32
+ try {
33
+ if (connection.generation !== generation) {
34
+ return;
35
+ }
36
+ await Promise.resolve();
37
+ if (connection.generation !== generation) {
38
+ return;
39
+ }
40
+ await hooks.inject(bytes, peer, generation);
41
+ }
42
+ finally {
43
+ runtime.clearCarrierInject();
44
+ }
45
+ },
46
+ });
47
+ runtime.syncPathMtuFromConnection(connection);
48
+ (0, sped_bind_1.markConnectionSpedEnabled)(connection);
49
+ (0, sped_bind_1.setConnectionSpedRuntime)(connection, runtime);
50
+ return {
51
+ session,
52
+ runtime,
53
+ onFlightCreated: (packets, options) => {
54
+ if (options?.fromCarrier && runtime.isStaleCarrierFlight()) {
55
+ return;
56
+ }
57
+ session.replaceL1(packets);
58
+ },
59
+ onHandshakeComplete: () => runtime.completeHandshake(),
60
+ };
61
+ }
62
+ //# sourceMappingURL=sped.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sped.js","sourceRoot":"","sources":["../../../../../ice/src/internal/sped.ts"],"names":[],"mappings":";;;AAwCA,wDAyCC;AA3ED,qDAAsD;AACtD,6CAA8D;AAC9D,2CAGqB;AAErB,2CAQyB;AAPvB,2GAAA,gBAAgB,OAAA;AAChB,4GAAA,iBAAiB,OAAA;AACjB,wGAAA,aAAa,OAAA;AACb,yGAAA,cAAc,OAAA;AACd,wGAAA,aAAa,OAAA;AACb,yGAAA,cAAc,OAAA;AACd,wGAAA,aAAa,OAAA;AAEf,mDAAsD;AAA7C,sGAAA,WAAW,OAAA;AAEpB,2CAIyB;AAHvB,6GAAA,kBAAkB,OAAA;AAClB,iHAAA,sBAAsB,OAAA;AACtB,4GAAA,iBAAiB,OAAA;AAanB,SAAgB,sBAAsB,CACpC,UAAsB,EACtB,KAAgB;IAEhB,MAAM,OAAO,GAAG,IAAI,qBAAW,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IACvD,MAAM,OAAO,GAAG,IAAI,qBAAW,CAAC,OAAO,EAAE;QACvC,GAAG,KAAK;QACR,mBAAmB,EAAE,GAAG,EAAE;YACxB,UAAU,CAAC,8BAA8B,EAAE,CAAC;YAC5C,KAAK,CAAC,mBAAmB,EAAE,EAAE,CAAC;QAChC,CAAC;QACD,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE;YACxC,OAAO,CAAC,iBAAiB,EAAE,CAAC;YAC5B,IAAI,CAAC;gBACH,IAAI,UAAU,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;oBACzC,OAAO;gBACT,CAAC;gBACD,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;gBACxB,IAAI,UAAU,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;oBACzC,OAAO;gBACT,CAAC;gBACD,MAAM,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;YAC9C,CAAC;oBAAS,CAAC;gBACT,OAAO,CAAC,kBAAkB,EAAE,CAAC;YAC/B,CAAC;QACH,CAAC;KACF,CAAC,CAAC;IACH,OAAO,CAAC,yBAAyB,CAAC,UAAU,CAAC,CAAC;IAC9C,IAAA,qCAAyB,EAAC,UAAU,CAAC,CAAC;IACtC,IAAA,oCAAwB,EAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC9C,OAAO;QACL,OAAO;QACP,OAAO;QACP,eAAe,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;YACpC,IAAI,OAAO,EAAE,WAAW,IAAI,OAAO,CAAC,oBAAoB,EAAE,EAAE,CAAC;gBAC3D,OAAO;YACT,CAAC;YACD,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;QACD,mBAAmB,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,iBAAiB,EAAE;KACvD,CAAC;AACJ,CAAC","sourcesContent":["/**\n * @internal\n * Package-private SPED attachment for RTCPeerConnection and ice tests.\n * Not re-exported from `src/index.ts`.\n */\nimport type { Connection } from \"../ice\";\nimport { SpedSession } from \"../sped/draft00/session\";\nimport { type SpedHooks, SpedRuntime } from \"../sped/runtime\";\nimport {\n markConnectionSpedEnabled,\n setConnectionSpedRuntime,\n} from \"./sped-bind\";\n\nexport {\n DTLS_IN_STUN_ACK,\n DTLS_IN_STUN_DATA,\n decodeSpedAck,\n decodeSpedData,\n encodeSpedAck,\n encodeSpedData,\n spedDataCrc32,\n} from \"../sped/draft00\";\nexport { SpedSession } from \"../sped/draft00/session\";\nexport type { SpedDirectHandshakeReadiness, SpedHooks } from \"../sped/runtime\";\nexport {\n isSpedEligiblePair,\n isSpedEligibleProtocol,\n sameCandidatePair,\n} from \"../sped/runtime\";\n\nexport interface SpedHandle {\n session: SpedSession;\n runtime: SpedRuntime;\n onFlightCreated: (\n packets: readonly Buffer[],\n options?: { fromCarrier?: boolean },\n ) => void;\n onHandshakeComplete: () => void;\n}\n\nexport function attachSpedToConnection(\n connection: Connection,\n hooks: SpedHooks,\n): SpedHandle {\n const session = new SpedSession(connection.generation);\n const runtime = new SpedRuntime(session, {\n ...hooks,\n onHandshakeComplete: () => {\n connection.forgetSpedBindingResponseCache();\n hooks.onHandshakeComplete?.();\n },\n inject: async (bytes, peer, generation) => {\n runtime.markCarrierInject();\n try {\n if (connection.generation !== generation) {\n return;\n }\n await Promise.resolve();\n if (connection.generation !== generation) {\n return;\n }\n await hooks.inject(bytes, peer, generation);\n } finally {\n runtime.clearCarrierInject();\n }\n },\n });\n runtime.syncPathMtuFromConnection(connection);\n markConnectionSpedEnabled(connection);\n setConnectionSpedRuntime(connection, runtime);\n return {\n session,\n runtime,\n onFlightCreated: (packets, options) => {\n if (options?.fromCarrier && runtime.isStaleCarrierFlight()) {\n return;\n }\n session.replaceL1(packets);\n },\n onHandshakeComplete: () => runtime.completeHandshake(),\n };\n}\n"]}
@@ -0,0 +1,111 @@
1
+ import { notReceivingSince, type PairLiveness } from "../failover";
2
+ import { type CandidatePair } from "../iceBase";
3
+ /** What `shouldSwitch` knows about a pair. */
4
+ export type SwitchPairState = {
5
+ /** A response to a check came back and the pair is not unwritable (`isWritable`). */
6
+ writable: boolean;
7
+ /** The last response, request or application data received on the pair (ms). */
8
+ lastReceived: number;
9
+ /**
10
+ * When the first of the consecutive unanswered checks of the pair was
11
+ * counted (ms, `PairLiveness.missedSince`); undefined while its last check
12
+ * was answered.
13
+ */
14
+ missedSince?: number;
15
+ /** The smoothed RTT (seconds, `CandidatePair.smoothedRtt`); undefined: not known yet. */
16
+ rtt?: number;
17
+ };
18
+ /**
19
+ * Why a pair wins over the selected one (`shouldSwitch`):
20
+ * - `writable`: the selection is not writable;
21
+ * - `receiving`: the selection has not been receiving for
22
+ * `RECEIVING_SWITCHING_DELAY`, the pair is receiving;
23
+ * - `priority`: the pair outranks the selection;
24
+ * - `rtt`: equal otherwise, the pair's smoothed RTT is at least
25
+ * `RTT_SWITCH_MIN_IMPROVEMENT` lower.
26
+ */
27
+ export type SwitchReason = "writable" | "receiving" | "priority" | "rtt";
28
+ export type SwitchDecision = {
29
+ /** The pair wins over the selection; undefined: the selection stays. */
30
+ reason?: SwitchReason;
31
+ /**
32
+ * When (ms) to decide again while a receiving switch is held back
33
+ * (libwebrtc's recheck event).
34
+ * @see tests/ice/selection-controller.test.ts "a pair that wins only by receiving waits RECEIVING_SWITCHING_DELAY and asks for a recheck"
35
+ */
36
+ recheckAt?: number;
37
+ };
38
+ export { notReceivingSince };
39
+ /**
40
+ * Whether the controlling agent moves the selection from `selected` to
41
+ * `candidate` (`priority` > 0: `candidate` outranks it), as libwebrtc's
42
+ * `BasicIceController::ShouldSwitchConnection`: writable, receiving (held for
43
+ * `RECEIVING_SWITCHING_DELAY`), priority, then the smoothed RTT. The network
44
+ * cost libwebrtc compares before the priority is unknown in Node.js.
45
+ * @see tests/ice/selection-controller.test.ts "state comes before priority and priority before RTT"
46
+ * @see tests/ice/selection-controller.test.ts "a pair that wins only by receiving waits RECEIVING_SWITCHING_DELAY and asks for a recheck"
47
+ * @see tests/ice/selection-controller.test.ts "silence alone (no unanswered check) is not 'not receiving'; a receiving selection beats a pair that is not"
48
+ * @see tests/ice/selection-controller.test.ts "a late unanswered check starts the hold at the check, and a recovery in the hold keeps the selection"
49
+ * @see tests/ice/selection-controller.test.ts "equal priority: moves only to a pair whose smoothed RTT is at least 10 ms lower"
50
+ */
51
+ export declare function shouldSwitch({ selected, candidate, priority, now, receivingSwitchingDelay, receivingTimeout, minRttImprovement, }: {
52
+ selected: SwitchPairState;
53
+ candidate: SwitchPairState;
54
+ priority: number;
55
+ now: number;
56
+ receivingSwitchingDelay?: number;
57
+ receivingTimeout?: number;
58
+ minRttImprovement?: number;
59
+ }): SwitchDecision;
60
+ /** What the agent supplies to its `SelectionController`. */
61
+ export type SelectionControllerHost = {
62
+ /**
63
+ * The controller applies now: a controlling full agent with
64
+ * semi-aggressive nomination or renomination within the failover scope,
65
+ * a selection that is up (failover handles one that stopped answering)
66
+ * and no nominating check in flight.
67
+ */
68
+ active: () => boolean;
69
+ selected: () => CandidatePair | undefined;
70
+ /** The pairs the selection may move to (the monitored backups). */
71
+ candidates: () => readonly CandidatePair[];
72
+ /** The liveness the failover monitor keeps for `pair`. */
73
+ liveness: (pair: CandidatePair) => PairLiveness | undefined;
74
+ writable: (pair: CandidatePair, now: number) => boolean;
75
+ /** `IceOptions.failover` thresholds (`receivingTimeout`, `receivingSwitchingDelay`). */
76
+ thresholds?: () => {
77
+ receivingTimeout: number;
78
+ receivingSwitchingDelay: number;
79
+ };
80
+ /** `pair` may be nominated (not on a path the agent failed over from). */
81
+ allows: (pair: CandidatePair) => boolean;
82
+ /** > 0 when `pair` outranks `other` (pair priority). */
83
+ comparePriority: (pair: CandidatePair, other: CandidatePair) => number;
84
+ /** Nominate `pair` to replace the selection for `reason`. */
85
+ switchTo: (pair: CandidatePair, reason: "receiving" | "rtt") => void;
86
+ };
87
+ /**
88
+ * The controlling agent's moves of the selected pair by receiving state and
89
+ * RTT (`shouldSwitch`), as libwebrtc's ICE controller.
90
+ * @see tests/ice/selection-controller.test.ts "equal priority: the selection moves to the pair whose RTT is 11 ms lower, nominating it"
91
+ * @see tests/ice/selection-controller.test.ts "receiving: a selection that recovers within RECEIVING_SWITCHING_DELAY stays; one that does not moves after it"
92
+ * @see tests/ice/selection-controller.test.ts "the hold is counted from the unanswered check: no switch right after it, the recheck at its end switches"
93
+ * @see tests/ice/selection-controller.test.ts "controlled: the agent does not switch by RTT itself (it follows the peer's nominations)"
94
+ */
95
+ export declare class SelectionController {
96
+ private recheck?;
97
+ private readonly host;
98
+ constructor(host: SelectionControllerHost);
99
+ /** Decide whether the selection moves, and nominate the pair it moves to. */
100
+ evaluate(): void;
101
+ /** Stop the pending recheck (restart, close, the failover monitor reset). */
102
+ stop(): void;
103
+ /**
104
+ * Whether `a` is a better target than `b`: receiving, priority, then RTT.
105
+ * @see tests/ice/selection-controller.test.ts "a receiving backup of lower priority wins over a silent one of equal priority and lower RTT"
106
+ * @see tests/ice/selection-controller.test.ts "among receiving backups the higher priority wins, then the lower RTT"
107
+ */
108
+ private betterTarget;
109
+ private scheduleRecheck;
110
+ private clearRecheck;
111
+ }
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SelectionController = exports.notReceivingSince = void 0;
4
+ exports.shouldSwitch = shouldSwitch;
5
+ const failover_1 = require("../failover");
6
+ Object.defineProperty(exports, "notReceivingSince", { enumerable: true, get: function () { return failover_1.notReceivingSince; } });
7
+ const iceBase_1 = require("../iceBase");
8
+ const common_1 = require("../imports/common");
9
+ const log = (0, common_1.debug)("werift-ice : packages/ice/src/nomination/selectionController.ts : log");
10
+ /**
11
+ * Whether the controlling agent moves the selection from `selected` to
12
+ * `candidate` (`priority` > 0: `candidate` outranks it), as libwebrtc's
13
+ * `BasicIceController::ShouldSwitchConnection`: writable, receiving (held for
14
+ * `RECEIVING_SWITCHING_DELAY`), priority, then the smoothed RTT. The network
15
+ * cost libwebrtc compares before the priority is unknown in Node.js.
16
+ * @see tests/ice/selection-controller.test.ts "state comes before priority and priority before RTT"
17
+ * @see tests/ice/selection-controller.test.ts "a pair that wins only by receiving waits RECEIVING_SWITCHING_DELAY and asks for a recheck"
18
+ * @see tests/ice/selection-controller.test.ts "silence alone (no unanswered check) is not 'not receiving'; a receiving selection beats a pair that is not"
19
+ * @see tests/ice/selection-controller.test.ts "a late unanswered check starts the hold at the check, and a recovery in the hold keeps the selection"
20
+ * @see tests/ice/selection-controller.test.ts "equal priority: moves only to a pair whose smoothed RTT is at least 10 ms lower"
21
+ */
22
+ function shouldSwitch({ selected, candidate, priority, now, receivingSwitchingDelay = iceBase_1.RECEIVING_SWITCHING_DELAY, receivingTimeout = iceBase_1.WEAK_CONNECTION_RECEIVE_TIMEOUT, minRttImprovement = iceBase_1.RTT_SWITCH_MIN_IMPROVEMENT, }) {
23
+ if (!candidate.writable)
24
+ return {};
25
+ if (!selected.writable)
26
+ return { reason: "writable" };
27
+ let recheckAt;
28
+ const selectedSince = (0, failover_1.notReceivingSince)(selected, now, receivingTimeout);
29
+ const candidateSince = (0, failover_1.notReceivingSince)(candidate, now, receivingTimeout);
30
+ if (selectedSince === undefined && candidateSince !== undefined)
31
+ return {};
32
+ if (selectedSince !== undefined && candidateSince === undefined) {
33
+ if (now - selectedSince >= receivingSwitchingDelay) {
34
+ return { reason: "receiving" };
35
+ }
36
+ recheckAt = selectedSince + receivingSwitchingDelay;
37
+ }
38
+ if (priority > 0)
39
+ return { reason: "priority", recheckAt };
40
+ if (priority < 0)
41
+ return { recheckAt };
42
+ if (candidate.rtt !== undefined &&
43
+ selected.rtt !== undefined &&
44
+ candidate.rtt * 1000 <= selected.rtt * 1000 - minRttImprovement) {
45
+ return { reason: "rtt", recheckAt };
46
+ }
47
+ return { recheckAt };
48
+ }
49
+ /**
50
+ * The controlling agent's moves of the selected pair by receiving state and
51
+ * RTT (`shouldSwitch`), as libwebrtc's ICE controller.
52
+ * @see tests/ice/selection-controller.test.ts "equal priority: the selection moves to the pair whose RTT is 11 ms lower, nominating it"
53
+ * @see tests/ice/selection-controller.test.ts "receiving: a selection that recovers within RECEIVING_SWITCHING_DELAY stays; one that does not moves after it"
54
+ * @see tests/ice/selection-controller.test.ts "the hold is counted from the unanswered check: no switch right after it, the recheck at its end switches"
55
+ * @see tests/ice/selection-controller.test.ts "controlled: the agent does not switch by RTT itself (it follows the peer's nominations)"
56
+ */
57
+ class SelectionController {
58
+ constructor(host) {
59
+ Object.defineProperty(this, "recheck", {
60
+ enumerable: true,
61
+ configurable: true,
62
+ writable: true,
63
+ value: void 0
64
+ });
65
+ Object.defineProperty(this, "host", {
66
+ enumerable: true,
67
+ configurable: true,
68
+ writable: true,
69
+ value: void 0
70
+ });
71
+ this.host = host;
72
+ }
73
+ /** Decide whether the selection moves, and nominate the pair it moves to. */
74
+ evaluate() {
75
+ this.clearRecheck();
76
+ if (!this.host.active())
77
+ return;
78
+ const selected = this.host.selected();
79
+ if (!selected)
80
+ return;
81
+ const selectedLiveness = this.host.liveness(selected);
82
+ if (!selectedLiveness)
83
+ return;
84
+ const now = Date.now();
85
+ const thresholds = this.host.thresholds?.();
86
+ const selectedState = {
87
+ writable: this.host.writable(selected, now),
88
+ lastReceived: selectedLiveness.lastReceived,
89
+ missedSince: selectedLiveness.missedSince,
90
+ rtt: selected.smoothedRtt,
91
+ };
92
+ let best;
93
+ let recheckAt;
94
+ for (const pair of this.host.candidates()) {
95
+ if (pair === selected || !this.host.allows(pair))
96
+ continue;
97
+ const liveness = this.host.liveness(pair);
98
+ if (!liveness)
99
+ continue;
100
+ const candidateState = {
101
+ writable: this.host.writable(pair, now),
102
+ lastReceived: liveness.lastReceived,
103
+ missedSince: liveness.missedSince,
104
+ rtt: pair.smoothedRtt,
105
+ };
106
+ const decision = shouldSwitch({
107
+ selected: selectedState,
108
+ candidate: candidateState,
109
+ priority: this.host.comparePriority(pair, selected),
110
+ now,
111
+ receivingTimeout: thresholds?.receivingTimeout,
112
+ receivingSwitchingDelay: thresholds?.receivingSwitchingDelay,
113
+ });
114
+ if (decision.recheckAt !== undefined) {
115
+ recheckAt = Math.min(recheckAt ?? Infinity, decision.recheckAt);
116
+ }
117
+ // Test: tests/ice/selection-controller.test.ts "a backup that wins by priority or over an unwritable selection is left to SelectionReplacement and the failover"
118
+ const reason = decision.reason;
119
+ if (reason !== "receiving" && reason !== "rtt")
120
+ continue;
121
+ const receiving = (0, failover_1.notReceivingSince)(candidateState, now, thresholds?.receivingTimeout) ===
122
+ undefined;
123
+ if (!best || this.betterTarget({ pair, receiving }, best)) {
124
+ best = { pair, reason, receiving };
125
+ }
126
+ }
127
+ if (best) {
128
+ log("switch selection", best.reason, best.pair.toJSON(), {
129
+ selected: selected.toJSON(),
130
+ rtt: best.pair.smoothedRtt,
131
+ selectedRtt: selected.smoothedRtt,
132
+ });
133
+ this.host.switchTo(best.pair, best.reason);
134
+ return;
135
+ }
136
+ if (recheckAt !== undefined)
137
+ this.scheduleRecheck(recheckAt);
138
+ }
139
+ /** Stop the pending recheck (restart, close, the failover monitor reset). */
140
+ stop() {
141
+ this.clearRecheck();
142
+ }
143
+ /**
144
+ * Whether `a` is a better target than `b`: receiving, priority, then RTT.
145
+ * @see tests/ice/selection-controller.test.ts "a receiving backup of lower priority wins over a silent one of equal priority and lower RTT"
146
+ * @see tests/ice/selection-controller.test.ts "among receiving backups the higher priority wins, then the lower RTT"
147
+ */
148
+ betterTarget(a, b) {
149
+ if (a.receiving !== b.receiving)
150
+ return a.receiving;
151
+ const priority = this.host.comparePriority(a.pair, b.pair);
152
+ if (priority !== 0)
153
+ return priority > 0;
154
+ return (a.pair.smoothedRtt ?? Infinity) < (b.pair.smoothedRtt ?? Infinity);
155
+ }
156
+ scheduleRecheck(at) {
157
+ this.recheck = {
158
+ at,
159
+ timer: setTimeout(() => {
160
+ this.recheck = undefined;
161
+ this.evaluate();
162
+ }, Math.max(0, at - Date.now())),
163
+ };
164
+ }
165
+ clearRecheck() {
166
+ if (this.recheck)
167
+ clearTimeout(this.recheck.timer);
168
+ this.recheck = undefined;
169
+ }
170
+ }
171
+ exports.SelectionController = SelectionController;
172
+ //# sourceMappingURL=selectionController.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectionController.js","sourceRoot":"","sources":["../../../../../ice/src/nomination/selectionController.ts"],"names":[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AI,CAAC,OAAO,GAAG;YACb,EAAE;YACF,KAAK,EAAE,UAAU,CACf,GAAG,EAAE;gBACH,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;gBACzB,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,CAAC,EACD,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAC7B;SACF,CAAC;IACJ,CAAC;IAEO,YAAY;QAClB,IAAI,IAAI,CAAC,OAAO;YAAE,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACnD,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;IAC3B,CAAC;CACF;AA7GD,kDA6GC","sourcesContent":["import { notReceivingSince, type PairLiveness } from \"../failover\";\nimport {\n type CandidatePair,\n RECEIVING_SWITCHING_DELAY,\n RTT_SWITCH_MIN_IMPROVEMENT,\n WEAK_CONNECTION_RECEIVE_TIMEOUT,\n} from \"../iceBase\";\nimport { debug } from \"../imports/common\";\n\nconst log = debug(\n \"werift-ice : packages/ice/src/nomination/selectionController.ts : log\",\n);\n\n/** What `shouldSwitch` knows about a pair. */\nexport type SwitchPairState = {\n /** A response to a check came back and the pair is not unwritable (`isWritable`). */\n writable: boolean;\n /** The last response, request or application data received on the pair (ms). */\n lastReceived: number;\n /**\n * When the first of the consecutive unanswered checks of the pair was\n * counted (ms, `PairLiveness.missedSince`); undefined while its last check\n * was answered.\n */\n missedSince?: number;\n /** The smoothed RTT (seconds, `CandidatePair.smoothedRtt`); undefined: not known yet. */\n rtt?: number;\n};\n\n/**\n * Why a pair wins over the selected one (`shouldSwitch`):\n * - `writable`: the selection is not writable;\n * - `receiving`: the selection has not been receiving for\n * `RECEIVING_SWITCHING_DELAY`, the pair is receiving;\n * - `priority`: the pair outranks the selection;\n * - `rtt`: equal otherwise, the pair's smoothed RTT is at least\n * `RTT_SWITCH_MIN_IMPROVEMENT` lower.\n */\nexport type SwitchReason = \"writable\" | \"receiving\" | \"priority\" | \"rtt\";\n\nexport type SwitchDecision = {\n /** The pair wins over the selection; undefined: the selection stays. */\n reason?: SwitchReason;\n /**\n * When (ms) to decide again while a receiving switch is held back\n * (libwebrtc's recheck event).\n * @see tests/ice/selection-controller.test.ts \"a pair that wins only by receiving waits RECEIVING_SWITCHING_DELAY and asks for a recheck\"\n */\n recheckAt?: number;\n};\n\nexport { notReceivingSince };\n\n/**\n * Whether the controlling agent moves the selection from `selected` to\n * `candidate` (`priority` > 0: `candidate` outranks it), as libwebrtc's\n * `BasicIceController::ShouldSwitchConnection`: writable, receiving (held for\n * `RECEIVING_SWITCHING_DELAY`), priority, then the smoothed RTT. The network\n * cost libwebrtc compares before the priority is unknown in Node.js.\n * @see tests/ice/selection-controller.test.ts \"state comes before priority and priority before RTT\"\n * @see tests/ice/selection-controller.test.ts \"a pair that wins only by receiving waits RECEIVING_SWITCHING_DELAY and asks for a recheck\"\n * @see tests/ice/selection-controller.test.ts \"silence alone (no unanswered check) is not 'not receiving'; a receiving selection beats a pair that is not\"\n * @see tests/ice/selection-controller.test.ts \"a late unanswered check starts the hold at the check, and a recovery in the hold keeps the selection\"\n * @see tests/ice/selection-controller.test.ts \"equal priority: moves only to a pair whose smoothed RTT is at least 10 ms lower\"\n */\nexport function shouldSwitch({\n selected,\n candidate,\n priority,\n now,\n receivingSwitchingDelay = RECEIVING_SWITCHING_DELAY,\n receivingTimeout = WEAK_CONNECTION_RECEIVE_TIMEOUT,\n minRttImprovement = RTT_SWITCH_MIN_IMPROVEMENT,\n}: {\n selected: SwitchPairState;\n candidate: SwitchPairState;\n priority: number;\n now: number;\n receivingSwitchingDelay?: number;\n receivingTimeout?: number;\n minRttImprovement?: number;\n}): SwitchDecision {\n if (!candidate.writable) return {};\n if (!selected.writable) return { reason: \"writable\" };\n\n let recheckAt: number | undefined;\n const selectedSince = notReceivingSince(selected, now, receivingTimeout);\n const candidateSince = notReceivingSince(candidate, now, receivingTimeout);\n if (selectedSince === undefined && candidateSince !== undefined) return {};\n if (selectedSince !== undefined && candidateSince === undefined) {\n if (now - selectedSince >= receivingSwitchingDelay) {\n return { reason: \"receiving\" };\n }\n recheckAt = selectedSince + receivingSwitchingDelay;\n }\n\n if (priority > 0) return { reason: \"priority\", recheckAt };\n if (priority < 0) return { recheckAt };\n\n if (\n candidate.rtt !== undefined &&\n selected.rtt !== undefined &&\n candidate.rtt * 1000 <= selected.rtt * 1000 - minRttImprovement\n ) {\n return { reason: \"rtt\", recheckAt };\n }\n return { recheckAt };\n}\n\n/** What the agent supplies to its `SelectionController`. */\nexport type SelectionControllerHost = {\n /**\n * The controller applies now: a controlling full agent with\n * semi-aggressive nomination or renomination within the failover scope,\n * a selection that is up (failover handles one that stopped answering)\n * and no nominating check in flight.\n */\n active: () => boolean;\n selected: () => CandidatePair | undefined;\n /** The pairs the selection may move to (the monitored backups). */\n candidates: () => readonly CandidatePair[];\n /** The liveness the failover monitor keeps for `pair`. */\n liveness: (pair: CandidatePair) => PairLiveness | undefined;\n writable: (pair: CandidatePair, now: number) => boolean;\n /** `IceOptions.failover` thresholds (`receivingTimeout`, `receivingSwitchingDelay`). */\n thresholds?: () => {\n receivingTimeout: number;\n receivingSwitchingDelay: number;\n };\n /** `pair` may be nominated (not on a path the agent failed over from). */\n allows: (pair: CandidatePair) => boolean;\n /** > 0 when `pair` outranks `other` (pair priority). */\n comparePriority: (pair: CandidatePair, other: CandidatePair) => number;\n /** Nominate `pair` to replace the selection for `reason`. */\n switchTo: (pair: CandidatePair, reason: \"receiving\" | \"rtt\") => void;\n};\n\n/**\n * The controlling agent's moves of the selected pair by receiving state and\n * RTT (`shouldSwitch`), as libwebrtc's ICE controller.\n * @see tests/ice/selection-controller.test.ts \"equal priority: the selection moves to the pair whose RTT is 11 ms lower, nominating it\"\n * @see tests/ice/selection-controller.test.ts \"receiving: a selection that recovers within RECEIVING_SWITCHING_DELAY stays; one that does not moves after it\"\n * @see tests/ice/selection-controller.test.ts \"the hold is counted from the unanswered check: no switch right after it, the recheck at its end switches\"\n * @see tests/ice/selection-controller.test.ts \"controlled: the agent does not switch by RTT itself (it follows the peer's nominations)\"\n */\nexport class SelectionController {\n private recheck?: { at: number; timer: ReturnType<typeof setTimeout> };\n private readonly host: SelectionControllerHost;\n\n constructor(host: SelectionControllerHost) {\n this.host = host;\n }\n\n /** Decide whether the selection moves, and nominate the pair it moves to. */\n evaluate() {\n this.clearRecheck();\n if (!this.host.active()) return;\n const selected = this.host.selected();\n if (!selected) return;\n const selectedLiveness = this.host.liveness(selected);\n if (!selectedLiveness) return;\n const now = Date.now();\n const thresholds = this.host.thresholds?.();\n const selectedState: SwitchPairState = {\n writable: this.host.writable(selected, now),\n lastReceived: selectedLiveness.lastReceived,\n missedSince: selectedLiveness.missedSince,\n rtt: selected.smoothedRtt,\n };\n\n let best:\n | { pair: CandidatePair; reason: \"receiving\" | \"rtt\"; receiving: boolean }\n | undefined;\n let recheckAt: number | undefined;\n for (const pair of this.host.candidates()) {\n if (pair === selected || !this.host.allows(pair)) continue;\n const liveness = this.host.liveness(pair);\n if (!liveness) continue;\n const candidateState: SwitchPairState = {\n writable: this.host.writable(pair, now),\n lastReceived: liveness.lastReceived,\n missedSince: liveness.missedSince,\n rtt: pair.smoothedRtt,\n };\n const decision = shouldSwitch({\n selected: selectedState,\n candidate: candidateState,\n priority: this.host.comparePriority(pair, selected),\n now,\n receivingTimeout: thresholds?.receivingTimeout,\n receivingSwitchingDelay: thresholds?.receivingSwitchingDelay,\n });\n if (decision.recheckAt !== undefined) {\n recheckAt = Math.min(recheckAt ?? Infinity, decision.recheckAt);\n }\n // Test: tests/ice/selection-controller.test.ts \"a backup that wins by priority or over an unwritable selection is left to SelectionReplacement and the failover\"\n const reason = decision.reason;\n if (reason !== \"receiving\" && reason !== \"rtt\") continue;\n const receiving =\n notReceivingSince(candidateState, now, thresholds?.receivingTimeout) ===\n undefined;\n if (!best || this.betterTarget({ pair, receiving }, best)) {\n best = { pair, reason, receiving };\n }\n }\n if (best) {\n log(\"switch selection\", best.reason, best.pair.toJSON(), {\n selected: selected.toJSON(),\n rtt: best.pair.smoothedRtt,\n selectedRtt: selected.smoothedRtt,\n });\n this.host.switchTo(best.pair, best.reason);\n return;\n }\n if (recheckAt !== undefined) this.scheduleRecheck(recheckAt);\n }\n\n /** Stop the pending recheck (restart, close, the failover monitor reset). */\n stop() {\n this.clearRecheck();\n }\n\n /**\n * Whether `a` is a better target than `b`: receiving, priority, then RTT.\n * @see tests/ice/selection-controller.test.ts \"a receiving backup of lower priority wins over a silent one of equal priority and lower RTT\"\n * @see tests/ice/selection-controller.test.ts \"among receiving backups the higher priority wins, then the lower RTT\"\n */\n private betterTarget(\n a: { pair: CandidatePair; receiving: boolean },\n b: { pair: CandidatePair; receiving: boolean },\n ) {\n if (a.receiving !== b.receiving) return a.receiving;\n const priority = this.host.comparePriority(a.pair, b.pair);\n if (priority !== 0) return priority > 0;\n return (a.pair.smoothedRtt ?? Infinity) < (b.pair.smoothedRtt ?? Infinity);\n }\n\n private scheduleRecheck(at: number) {\n this.recheck = {\n at,\n timer: setTimeout(\n () => {\n this.recheck = undefined;\n this.evaluate();\n },\n Math.max(0, at - Date.now()),\n ),\n };\n }\n\n private clearRecheck() {\n if (this.recheck) clearTimeout(this.recheck.timer);\n this.recheck = undefined;\n }\n}\n"]}
@@ -37,6 +37,31 @@ export type SelectionHost = {
37
37
  isStaleNomination: (pair: CandidatePair, generation: number) => boolean;
38
38
  /** 487: the peer is controlling and wins; the agent becomes controlled. */
39
39
  roleConflict: () => void;
40
+ /**
41
+ * Failover: `pair` may be nominated to move the selection up (its socket
42
+ * is not one the agent failed over from and has not recovered yet, and it
43
+ * is not known to be unwritable). Unset: every pair.
44
+ */
45
+ allows?: (pair: CandidatePair) => boolean;
46
+ /**
47
+ * Failover (controlling): the nominated `pair` replaces the selection
48
+ * whatever its priority (the selection stopped answering, or it is the
49
+ * failover nomination's pair).
50
+ */
51
+ failoverReplaces?: (pair: CandidatePair) => boolean;
52
+ /** The nominating check of `pair` ended (any outcome, or aborted). */
53
+ nominationEnded?: (pair: CandidatePair) => void;
54
+ /**
55
+ * Failover applies (`Connection.failoverEnabled`): the retries of failed
56
+ * pairs that outrank the selection go on every last delay (16 s) instead
57
+ * of stopping after `OUTRANKING_RETRY_DELAYS_MS`.
58
+ */
59
+ retriesForever?: () => boolean;
60
+ /**
61
+ * Controlled agent: the selected pair stopped answering (failover), so a
62
+ * nomination of the peer equal to the selection's replaces it.
63
+ */
64
+ selectionDown?: () => boolean;
40
65
  };
41
66
  /**
42
67
  * Semi-aggressive nomination and renomination (as libwebrtc): how a selection
@@ -83,6 +108,14 @@ export declare class SelectionReplacement {
83
108
  * failed too). Each pair waits for one retry at a time.
84
109
  */
85
110
  scheduleRetries(): void;
111
+ /**
112
+ * Failover (controlling): the selection stopped answering and no backup
113
+ * is writable, so the failed pairs that outrank it are checked at once
114
+ * instead of waiting for their next retry (libwebrtc pings at its strong
115
+ * interval when no connection is writable). One check per pair at a time:
116
+ * a pair being checked is not Failed.
117
+ */
118
+ checkFailedOutranking(): void;
86
119
  /** `pair` failed, outranks `selected` and may replace it. */
87
120
  private retriesOutranking;
88
121
  /** A retry of `scheduleRetries` is due: check `pair` again. */
@@ -120,6 +153,13 @@ export declare class SelectionReplacement {
120
153
  * needs one. One such check at a time; its outcome re-evaluates.
121
154
  */
122
155
  evaluate(): void;
156
+ /**
157
+ * Failover (controlling): nominate `pair` now (USE-CANDIDATE, or the next
158
+ * NOMINATION value), whatever its priority; its success moves the
159
+ * selection (`replaces` with `failoverReplaces`).
160
+ */
161
+ nominate(pair: CandidatePair): void;
162
+ private allows;
123
163
  private nominateSelection;
124
164
  abort(): void;
125
165
  /**