werift 0.26.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (552) hide show
  1. package/README.md +182 -8
  2. package/THIRD_PARTY_LICENSES_LIBWEBRTC.txt +58 -0
  3. package/lib/common/src/binary.d.ts +1 -3
  4. package/lib/common/src/binary.js +8 -6
  5. package/lib/common/src/binary.js.map +1 -1
  6. package/lib/common/src/binaryData.js +2 -1
  7. package/lib/common/src/binaryData.js.map +1 -1
  8. package/lib/common/src/event.d.ts +26 -0
  9. package/lib/common/src/event.js +87 -2
  10. package/lib/common/src/event.js.map +1 -1
  11. package/lib/common/src/log.js +5 -7
  12. package/lib/common/src/log.js.map +1 -1
  13. package/lib/common/src/network.d.ts +6 -1
  14. package/lib/common/src/network.js +8 -2
  15. package/lib/common/src/network.js.map +1 -1
  16. package/lib/common/src/transport.d.ts +12 -5
  17. package/lib/common/src/transport.js +13 -7
  18. package/lib/common/src/transport.js.map +1 -1
  19. package/lib/dtls/src/alert.d.ts +49 -0
  20. package/lib/dtls/src/alert.js +103 -0
  21. package/lib/dtls/src/alert.js.map +1 -0
  22. package/lib/dtls/src/client.js +15 -1
  23. package/lib/dtls/src/client.js.map +1 -1
  24. package/lib/dtls/src/context/cipher.d.ts +1 -1
  25. package/lib/dtls/src/context/cipher.js +6 -3
  26. package/lib/dtls/src/context/cipher.js.map +1 -1
  27. package/lib/dtls/src/context/dtls.d.ts +2 -0
  28. package/lib/dtls/src/context/dtls.js +11 -2
  29. package/lib/dtls/src/context/dtls.js.map +1 -1
  30. package/lib/dtls/src/context/transport.d.ts +17 -1
  31. package/lib/dtls/src/context/transport.js +40 -3
  32. package/lib/dtls/src/context/transport.js.map +1 -1
  33. package/lib/dtls/src/flight/client/flight1.js +2 -1
  34. package/lib/dtls/src/flight/client/flight1.js.map +1 -1
  35. package/lib/dtls/src/flight/client/flight5.js +8 -3
  36. package/lib/dtls/src/flight/client/flight5.js.map +1 -1
  37. package/lib/dtls/src/flight/flight.d.ts +6 -1
  38. package/lib/dtls/src/flight/flight.js +18 -5
  39. package/lib/dtls/src/flight/flight.js.map +1 -1
  40. package/lib/dtls/src/flight/server/flight4.js +4 -2
  41. package/lib/dtls/src/flight/server/flight4.js.map +1 -1
  42. package/lib/dtls/src/flight/server/flight6.js +6 -2
  43. package/lib/dtls/src/flight/server/flight6.js.map +1 -1
  44. package/lib/dtls/src/handshake/const.d.ts +17 -13
  45. package/lib/dtls/src/handshake/const.js +16 -14
  46. package/lib/dtls/src/handshake/const.js.map +1 -1
  47. package/lib/dtls/src/handshake/message/alert.js +4 -2
  48. package/lib/dtls/src/handshake/message/alert.js.map +1 -1
  49. package/lib/dtls/src/handshake/message/certificate.js +2 -1
  50. package/lib/dtls/src/handshake/message/certificate.js.map +1 -1
  51. package/lib/dtls/src/handshake/message/changeCipherSpec.js +2 -1
  52. package/lib/dtls/src/handshake/message/changeCipherSpec.js.map +1 -1
  53. package/lib/dtls/src/handshake/message/client/certificateVerify.js +4 -2
  54. package/lib/dtls/src/handshake/message/client/certificateVerify.js.map +1 -1
  55. package/lib/dtls/src/handshake/message/client/hello.js +14 -7
  56. package/lib/dtls/src/handshake/message/client/hello.js.map +1 -1
  57. package/lib/dtls/src/handshake/message/client/keyExchange.js +2 -1
  58. package/lib/dtls/src/handshake/message/client/keyExchange.js.map +1 -1
  59. package/lib/dtls/src/handshake/message/finished.js +2 -1
  60. package/lib/dtls/src/handshake/message/finished.js.map +1 -1
  61. package/lib/dtls/src/handshake/message/server/certificateRequest.js +6 -3
  62. package/lib/dtls/src/handshake/message/server/certificateRequest.js.map +1 -1
  63. package/lib/dtls/src/handshake/message/server/hello.js +12 -6
  64. package/lib/dtls/src/handshake/message/server/hello.js.map +1 -1
  65. package/lib/dtls/src/handshake/message/server/helloDone.js.map +1 -1
  66. package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js +4 -2
  67. package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js.map +1 -1
  68. package/lib/dtls/src/handshake/message/server/keyExchange.js +16 -8
  69. package/lib/dtls/src/handshake/message/server/keyExchange.js.map +1 -1
  70. package/lib/dtls/src/handshake/random.d.ts +2 -2
  71. package/lib/dtls/src/handshake/random.js +5 -2
  72. package/lib/dtls/src/handshake/random.js.map +1 -1
  73. package/lib/dtls/src/index.d.ts +3 -1
  74. package/lib/dtls/src/index.js +10 -1
  75. package/lib/dtls/src/index.js.map +1 -1
  76. package/lib/dtls/src/record/const.d.ts +52 -33
  77. package/lib/dtls/src/record/const.js +51 -36
  78. package/lib/dtls/src/record/const.js.map +1 -1
  79. package/lib/dtls/src/record/message/fragment.js +12 -6
  80. package/lib/dtls/src/record/message/fragment.js.map +1 -1
  81. package/lib/dtls/src/record/message/header.js +10 -5
  82. package/lib/dtls/src/record/message/header.js.map +1 -1
  83. package/lib/dtls/src/record/message/plaintext.js +4 -2
  84. package/lib/dtls/src/record/message/plaintext.js.map +1 -1
  85. package/lib/dtls/src/record/receive.d.ts +6 -0
  86. package/lib/dtls/src/record/receive.js +50 -19
  87. package/lib/dtls/src/record/receive.js.map +1 -1
  88. package/lib/dtls/src/server.js +19 -1
  89. package/lib/dtls/src/server.js.map +1 -1
  90. package/lib/dtls/src/socket.d.ts +134 -2
  91. package/lib/dtls/src/socket.js +326 -8
  92. package/lib/dtls/src/socket.js.map +1 -1
  93. package/lib/ice/src/candidate.d.ts +1 -1
  94. package/lib/ice/src/candidate.js +24 -12
  95. package/lib/ice/src/candidate.js.map +1 -1
  96. package/lib/ice/src/candidateError.d.ts +155 -0
  97. package/lib/ice/src/candidateError.js +246 -0
  98. package/lib/ice/src/candidateError.js.map +1 -0
  99. package/lib/ice/src/candidateGatherer.d.ts +127 -0
  100. package/lib/ice/src/candidateGatherer.js +745 -0
  101. package/lib/ice/src/candidateGatherer.js.map +1 -0
  102. package/lib/ice/src/consent.d.ts +49 -0
  103. package/lib/ice/src/consent.js +258 -0
  104. package/lib/ice/src/consent.js.map +1 -0
  105. package/lib/ice/src/dns/lookup.d.ts +10 -1
  106. package/lib/ice/src/dns/lookup.js +42 -7
  107. package/lib/ice/src/dns/lookup.js.map +1 -1
  108. package/lib/ice/src/exceptions.d.ts +21 -5
  109. package/lib/ice/src/exceptions.js +58 -13
  110. package/lib/ice/src/exceptions.js.map +1 -1
  111. package/lib/ice/src/ice.d.ts +254 -58
  112. package/lib/ice/src/ice.js +979 -945
  113. package/lib/ice/src/ice.js.map +1 -1
  114. package/lib/ice/src/iceBase.d.ts +328 -14
  115. package/lib/ice/src/iceBase.js +254 -38
  116. package/lib/ice/src/iceBase.js.map +1 -1
  117. package/lib/ice/src/index.d.ts +1 -0
  118. package/lib/ice/src/index.js +1 -0
  119. package/lib/ice/src/index.js.map +1 -1
  120. package/lib/ice/src/internal/checkMessages.d.ts +41 -0
  121. package/lib/ice/src/internal/checkMessages.js +63 -0
  122. package/lib/ice/src/internal/checkMessages.js.map +1 -0
  123. package/lib/ice/src/internal/defaultRoute.d.ts +20 -0
  124. package/lib/ice/src/internal/defaultRoute.js +134 -0
  125. package/lib/ice/src/internal/defaultRoute.js.map +1 -0
  126. package/lib/ice/src/internal/hostInterfaces.d.ts +17 -0
  127. package/lib/ice/src/internal/hostInterfaces.js +77 -0
  128. package/lib/ice/src/internal/hostInterfaces.js.map +1 -0
  129. package/lib/ice/src/internal/hostPreference.d.ts +24 -0
  130. package/lib/ice/src/internal/hostPreference.js +38 -0
  131. package/lib/ice/src/internal/hostPreference.js.map +1 -0
  132. package/lib/ice/src/internal/resolveHostAddresses.d.ts +56 -8
  133. package/lib/ice/src/internal/resolveHostAddresses.js +127 -24
  134. package/lib/ice/src/internal/resolveHostAddresses.js.map +1 -1
  135. package/lib/ice/src/internal/selectAddresses.d.ts +27 -0
  136. package/lib/ice/src/internal/selectAddresses.js +37 -18
  137. package/lib/ice/src/internal/selectAddresses.js.map +1 -1
  138. package/lib/ice/src/nomination/regularNomination.d.ts +200 -0
  139. package/lib/ice/src/nomination/regularNomination.js +311 -0
  140. package/lib/ice/src/nomination/regularNomination.js.map +1 -0
  141. package/lib/ice/src/nomination/selectionReplacement.d.ts +138 -0
  142. package/lib/ice/src/nomination/selectionReplacement.js +371 -0
  143. package/lib/ice/src/nomination/selectionReplacement.js.map +1 -0
  144. package/lib/ice/src/provisional.d.ts +139 -0
  145. package/lib/ice/src/provisional.js +468 -0
  146. package/lib/ice/src/provisional.js.map +1 -0
  147. package/lib/ice/src/stun/protocol.d.ts +9 -2
  148. package/lib/ice/src/stun/protocol.js +16 -17
  149. package/lib/ice/src/stun/protocol.js.map +1 -1
  150. package/lib/ice/src/stun/tcpProtocol.d.ts +1 -1
  151. package/lib/ice/src/stun/tcpProtocol.js +7 -7
  152. package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
  153. package/lib/ice/src/stun/transaction.d.ts +30 -1
  154. package/lib/ice/src/stun/transaction.js +90 -19
  155. package/lib/ice/src/stun/transaction.js.map +1 -1
  156. package/lib/ice/src/turn/credential.d.ts +49 -0
  157. package/lib/ice/src/turn/credential.js +78 -0
  158. package/lib/ice/src/turn/credential.js.map +1 -0
  159. package/lib/ice/src/turn/protocol.d.ts +31 -10
  160. package/lib/ice/src/turn/protocol.js +127 -51
  161. package/lib/ice/src/turn/protocol.js.map +1 -1
  162. package/lib/ice/src/types/model.d.ts +16 -5
  163. package/lib/ice/src/types/model.js.map +1 -1
  164. package/lib/ice-server/src/stun/attributes.d.ts +2 -0
  165. package/lib/ice-server/src/stun/attributes.js +11 -1
  166. package/lib/ice-server/src/stun/attributes.js.map +1 -1
  167. package/lib/ice-server/src/stun/const.d.ts +44 -17
  168. package/lib/ice-server/src/stun/const.js +31 -19
  169. package/lib/ice-server/src/stun/const.js.map +1 -1
  170. package/lib/ice-server/src/stun/message.d.ts +29 -4
  171. package/lib/ice-server/src/stun/message.js +115 -24
  172. package/lib/ice-server/src/stun/message.js.map +1 -1
  173. package/lib/index.mjs +35121 -22337
  174. package/lib/nonstandard/index.mjs +3169 -1399
  175. package/lib/polyfill/dom.mjs +24650 -12365
  176. package/lib/polyfill/index.mjs +24650 -12365
  177. package/lib/rtp/src/codec/assertPayload.d.ts +4 -0
  178. package/lib/rtp/src/codec/assertPayload.js +12 -0
  179. package/lib/rtp/src/codec/assertPayload.js.map +1 -0
  180. package/lib/rtp/src/codec/av1.js +2 -0
  181. package/lib/rtp/src/codec/av1.js.map +1 -1
  182. package/lib/rtp/src/codec/h264.js +35 -43
  183. package/lib/rtp/src/codec/h264.js.map +1 -1
  184. package/lib/rtp/src/codec/vp8.js +11 -5
  185. package/lib/rtp/src/codec/vp8.js.map +1 -1
  186. package/lib/rtp/src/codec/vp9.js +12 -0
  187. package/lib/rtp/src/codec/vp9.js.map +1 -1
  188. package/lib/rtp/src/extra/container/mp4/container.js +2 -1
  189. package/lib/rtp/src/extra/container/mp4/container.js.map +1 -1
  190. package/lib/rtp/src/extra/container/mp4/exp-golomb.js +2 -1
  191. package/lib/rtp/src/extra/container/mp4/exp-golomb.js.map +1 -1
  192. package/lib/rtp/src/extra/container/mp4/h264.d.ts +21 -17
  193. package/lib/rtp/src/extra/container/mp4/h264.js +26 -24
  194. package/lib/rtp/src/extra/container/mp4/h264.js.map +1 -1
  195. package/lib/rtp/src/extra/container/ogg/index.d.ts +1 -0
  196. package/lib/rtp/src/extra/container/ogg/index.js +1 -0
  197. package/lib/rtp/src/extra/container/ogg/index.js.map +1 -1
  198. package/lib/rtp/src/extra/container/ogg/writer.d.ts +90 -0
  199. package/lib/rtp/src/extra/container/ogg/writer.js +300 -0
  200. package/lib/rtp/src/extra/container/ogg/writer.js.map +1 -0
  201. package/lib/rtp/src/extra/container/webm/ebml/ebml.js +6 -3
  202. package/lib/rtp/src/extra/container/webm/ebml/ebml.js.map +1 -1
  203. package/lib/rtp/src/extra/processor/depacketizer.d.ts +5 -0
  204. package/lib/rtp/src/extra/processor/depacketizer.js +28 -2
  205. package/lib/rtp/src/extra/processor/depacketizer.js.map +1 -1
  206. package/lib/rtp/src/extra/processor/dtx.js +4 -2
  207. package/lib/rtp/src/extra/processor/dtx.js.map +1 -1
  208. package/lib/rtp/src/extra/processor/index.d.ts +2 -0
  209. package/lib/rtp/src/extra/processor/index.js +2 -0
  210. package/lib/rtp/src/extra/processor/index.js.map +1 -1
  211. package/lib/rtp/src/extra/processor/jitterBuffer.d.ts +29 -6
  212. package/lib/rtp/src/extra/processor/jitterBuffer.js +101 -111
  213. package/lib/rtp/src/extra/processor/jitterBuffer.js.map +1 -1
  214. package/lib/rtp/src/extra/processor/jitterBufferTransformer.js +2 -1
  215. package/lib/rtp/src/extra/processor/jitterBufferTransformer.js.map +1 -1
  216. package/lib/rtp/src/extra/processor/lipsync.d.ts +63 -0
  217. package/lib/rtp/src/extra/processor/lipsync.js +202 -51
  218. package/lib/rtp/src/extra/processor/lipsync.js.map +1 -1
  219. package/lib/rtp/src/extra/processor/mp4.d.ts +0 -6
  220. package/lib/rtp/src/extra/processor/mp4.js +6 -3
  221. package/lib/rtp/src/extra/processor/mp4.js.map +1 -1
  222. package/lib/rtp/src/extra/processor/mute.js +4 -2
  223. package/lib/rtp/src/extra/processor/mute.js.map +1 -1
  224. package/lib/rtp/src/extra/processor/nack.js +4 -2
  225. package/lib/rtp/src/extra/processor/nack.js.map +1 -1
  226. package/lib/rtp/src/extra/processor/ntpTime.js +4 -6
  227. package/lib/rtp/src/extra/processor/ntpTime.js.map +1 -1
  228. package/lib/rtp/src/extra/processor/ogg.d.ts +72 -0
  229. package/lib/rtp/src/extra/processor/ogg.js +221 -0
  230. package/lib/rtp/src/extra/processor/ogg.js.map +1 -0
  231. package/lib/rtp/src/extra/processor/oggCallback.d.ts +21 -0
  232. package/lib/rtp/src/extra/processor/oggCallback.js +97 -0
  233. package/lib/rtp/src/extra/processor/oggCallback.js.map +1 -0
  234. package/lib/rtp/src/extra/processor/rtpCallback.js +2 -1
  235. package/lib/rtp/src/extra/processor/rtpCallback.js.map +1 -1
  236. package/lib/rtp/src/extra/processor/rtpStream.js +2 -1
  237. package/lib/rtp/src/extra/processor/rtpStream.js.map +1 -1
  238. package/lib/rtp/src/extra/processor/rtpTime.js +2 -1
  239. package/lib/rtp/src/extra/processor/rtpTime.js.map +1 -1
  240. package/lib/rtp/src/extra/processor/webm.js +14 -7
  241. package/lib/rtp/src/extra/processor/webm.js.map +1 -1
  242. package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
  243. package/lib/rtp/src/index.d.ts +8 -0
  244. package/lib/rtp/src/index.js +8 -0
  245. package/lib/rtp/src/index.js.map +1 -1
  246. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.d.ts +4 -0
  247. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js +4 -0
  248. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js.map +1 -1
  249. package/lib/rtp/src/rtcp/rtcp.js +8 -4
  250. package/lib/rtp/src/rtcp/rtcp.js.map +1 -1
  251. package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.d.ts +58 -0
  252. package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js +143 -0
  253. package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js.map +1 -0
  254. package/lib/rtp/src/rtcp/rtpfb/twcc.d.ts +35 -13
  255. package/lib/rtp/src/rtcp/rtpfb/twcc.js +132 -54
  256. package/lib/rtp/src/rtcp/rtpfb/twcc.js.map +1 -1
  257. package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.d.ts +13 -0
  258. package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js +29 -0
  259. package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js.map +1 -0
  260. package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.d.ts +41 -0
  261. package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js +89 -0
  262. package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js.map +1 -0
  263. package/lib/rtp/src/rtcp/sr.js +1 -0
  264. package/lib/rtp/src/rtcp/sr.js.map +1 -1
  265. package/lib/rtp/src/rtp/continuity.d.ts +49 -0
  266. package/lib/rtp/src/rtp/continuity.js +120 -0
  267. package/lib/rtp/src/rtp/continuity.js.map +1 -0
  268. package/lib/rtp/src/rtp/headerExtension.js +41 -21
  269. package/lib/rtp/src/rtp/headerExtension.js.map +1 -1
  270. package/lib/rtp/src/rtp/padding.d.ts +17 -0
  271. package/lib/rtp/src/rtp/padding.js +37 -0
  272. package/lib/rtp/src/rtp/padding.js.map +1 -0
  273. package/lib/rtp/src/rtp/red/encoder.d.ts +10 -0
  274. package/lib/rtp/src/rtp/red/encoder.js +14 -1
  275. package/lib/rtp/src/rtp/red/encoder.js.map +1 -1
  276. package/lib/rtp/src/rtp/red/packet.js +24 -8
  277. package/lib/rtp/src/rtp/red/packet.js.map +1 -1
  278. package/lib/rtp/src/rtp/rtp.d.ts +24 -1
  279. package/lib/rtp/src/rtp/rtp.js +70 -29
  280. package/lib/rtp/src/rtp/rtp.js.map +1 -1
  281. package/lib/rtp/src/rtp/rtx.js +3 -0
  282. package/lib/rtp/src/rtp/rtx.js.map +1 -1
  283. package/lib/rtp/src/rtp/sendHeaderExtensions.d.ts +36 -0
  284. package/lib/rtp/src/rtp/sendHeaderExtensions.js +85 -0
  285. package/lib/rtp/src/rtp/sendHeaderExtensions.js.map +1 -0
  286. package/lib/rtp/src/rtp/timelineRewriter.d.ts +178 -0
  287. package/lib/rtp/src/rtp/timelineRewriter.js +417 -0
  288. package/lib/rtp/src/rtp/timelineRewriter.js.map +1 -0
  289. package/lib/rtp/src/srtp/cipher/ctr.js +4 -2
  290. package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
  291. package/lib/rtp/src/srtp/cipher/index.js +8 -4
  292. package/lib/rtp/src/srtp/cipher/index.js.map +1 -1
  293. package/lib/rtp/src/srtp/context/context.js +6 -3
  294. package/lib/rtp/src/srtp/context/context.js.map +1 -1
  295. package/lib/rtp/src/srtp/context/srtcp.d.ts +1 -1
  296. package/lib/rtp/src/srtp/context/srtcp.js +33 -0
  297. package/lib/rtp/src/srtp/context/srtcp.js.map +1 -1
  298. package/lib/rtp/src/srtp/context/srtp.d.ts +1 -1
  299. package/lib/rtp/src/srtp/context/srtp.js +34 -10
  300. package/lib/rtp/src/srtp/context/srtp.js.map +1 -1
  301. package/lib/rtp/src/srtp/error.d.ts +8 -0
  302. package/lib/rtp/src/srtp/error.js +13 -1
  303. package/lib/rtp/src/srtp/error.js.map +1 -1
  304. package/lib/rtp/src/srtp/packet.js +4 -1
  305. package/lib/rtp/src/srtp/packet.js.map +1 -1
  306. package/lib/rtp/src/srtp/replay.d.ts +24 -0
  307. package/lib/rtp/src/srtp/replay.js +75 -0
  308. package/lib/rtp/src/srtp/replay.js.map +1 -0
  309. package/lib/rtp/src/srtp/session.js +2 -1
  310. package/lib/rtp/src/srtp/session.js.map +1 -1
  311. package/lib/rtp/src/srtp/srtcp.js +2 -1
  312. package/lib/rtp/src/srtp/srtcp.js.map +1 -1
  313. package/lib/rtp/src/srtp/srtp.js +2 -1
  314. package/lib/rtp/src/srtp/srtp.js.map +1 -1
  315. package/lib/rtp/src/util.js +2 -1
  316. package/lib/rtp/src/util.js.map +1 -1
  317. package/lib/sctp/src/chunk.d.ts +5 -0
  318. package/lib/sctp/src/chunk.js +31 -8
  319. package/lib/sctp/src/chunk.js.map +1 -1
  320. package/lib/sctp/src/const.d.ts +25 -17
  321. package/lib/sctp/src/const.js +23 -19
  322. package/lib/sctp/src/const.js.map +1 -1
  323. package/lib/sctp/src/param.d.ts +6 -2
  324. package/lib/sctp/src/param.js +22 -8
  325. package/lib/sctp/src/param.js.map +1 -1
  326. package/lib/sctp/src/sctp.d.ts +85 -0
  327. package/lib/sctp/src/sctp.js +707 -126
  328. package/lib/sctp/src/sctp.js.map +1 -1
  329. package/lib/sctp/src/transport.js +4 -2
  330. package/lib/sctp/src/transport.js.map +1 -1
  331. package/lib/webrtc/src/api/compatibilityOptions.d.ts +33 -0
  332. package/lib/webrtc/src/api/compatibilityOptions.js +33 -0
  333. package/lib/webrtc/src/api/compatibilityOptions.js.map +1 -0
  334. package/lib/webrtc/src/api/peerConfig.d.ts +385 -28
  335. package/lib/webrtc/src/api/peerConfig.js +121 -14
  336. package/lib/webrtc/src/api/peerConfig.js.map +1 -1
  337. package/lib/webrtc/src/api/peerConnectionEvents.d.ts +77 -1
  338. package/lib/webrtc/src/api/peerConnectionEvents.js +105 -1
  339. package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -1
  340. package/lib/webrtc/src/dataChannel.d.ts +10 -0
  341. package/lib/webrtc/src/dataChannel.js +24 -4
  342. package/lib/webrtc/src/dataChannel.js.map +1 -1
  343. package/lib/webrtc/src/helper.d.ts +8 -0
  344. package/lib/webrtc/src/helper.js +40 -4
  345. package/lib/webrtc/src/helper.js.map +1 -1
  346. package/lib/webrtc/src/media/codecCompatibility.d.ts +87 -1
  347. package/lib/webrtc/src/media/codecCompatibility.js +338 -12
  348. package/lib/webrtc/src/media/codecCompatibility.js.map +1 -1
  349. package/lib/webrtc/src/media/index.d.ts +10 -0
  350. package/lib/webrtc/src/media/index.js +70 -0
  351. package/lib/webrtc/src/media/index.js.map +1 -1
  352. package/lib/webrtc/src/media/receiver/nack.d.ts +43 -10
  353. package/lib/webrtc/src/media/receiver/nack.js +246 -88
  354. package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
  355. package/lib/webrtc/src/media/receiver/receiverTwcc.d.ts +61 -1
  356. package/lib/webrtc/src/media/receiver/receiverTwcc.js +218 -63
  357. package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
  358. package/lib/webrtc/src/media/router.d.ts +241 -40
  359. package/lib/webrtc/src/media/router.js +676 -205
  360. package/lib/webrtc/src/media/router.js.map +1 -1
  361. package/lib/webrtc/src/media/routing/pendingRoutes.d.ts +26 -0
  362. package/lib/webrtc/src/media/routing/pendingRoutes.js +48 -0
  363. package/lib/webrtc/src/media/routing/pendingRoutes.js.map +1 -0
  364. package/lib/webrtc/src/media/routing/ridRouting.d.ts +37 -0
  365. package/lib/webrtc/src/media/routing/ridRouting.js +74 -0
  366. package/lib/webrtc/src/media/routing/ridRouting.js.map +1 -0
  367. package/lib/webrtc/src/media/routing/routeTable.d.ts +60 -0
  368. package/lib/webrtc/src/media/routing/routeTable.js +95 -0
  369. package/lib/webrtc/src/media/routing/routeTable.js.map +1 -0
  370. package/lib/webrtc/src/media/routing/rtcpRouting.d.ts +34 -0
  371. package/lib/webrtc/src/media/routing/rtcpRouting.js +165 -0
  372. package/lib/webrtc/src/media/routing/rtcpRouting.js.map +1 -0
  373. package/lib/webrtc/src/media/routing/unknownSsrc.d.ts +55 -0
  374. package/lib/webrtc/src/media/routing/unknownSsrc.js +117 -0
  375. package/lib/webrtc/src/media/routing/unknownSsrc.js.map +1 -0
  376. package/lib/webrtc/src/media/rtpReceiver.d.ts +252 -2
  377. package/lib/webrtc/src/media/rtpReceiver.js +833 -44
  378. package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
  379. package/lib/webrtc/src/media/rtpSender.d.ts +191 -70
  380. package/lib/webrtc/src/media/rtpSender.js +631 -448
  381. package/lib/webrtc/src/media/rtpSender.js.map +1 -1
  382. package/lib/webrtc/src/media/rtpTransceiver.d.ts +19 -3
  383. package/lib/webrtc/src/media/rtpTransceiver.js +74 -9
  384. package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
  385. package/lib/webrtc/src/media/sender/bandwidthEstimator.d.ts +249 -0
  386. package/lib/webrtc/src/media/sender/bandwidthEstimator.js +144 -0
  387. package/lib/webrtc/src/media/sender/bandwidthEstimator.js.map +1 -0
  388. package/lib/webrtc/src/media/sender/createBandwidthEstimator.d.ts +20 -0
  389. package/lib/webrtc/src/media/sender/createBandwidthEstimator.js +26 -0
  390. package/lib/webrtc/src/media/sender/createBandwidthEstimator.js.map +1 -0
  391. package/lib/webrtc/src/media/sender/estimatorBinding.d.ts +70 -0
  392. package/lib/webrtc/src/media/sender/estimatorBinding.js +175 -0
  393. package/lib/webrtc/src/media/sender/estimatorBinding.js.map +1 -0
  394. package/lib/webrtc/src/media/sender/estimators/disabledBwe.d.ts +18 -0
  395. package/lib/webrtc/src/media/sender/estimators/disabledBwe.js +44 -0
  396. package/lib/webrtc/src/media/sender/estimators/disabledBwe.js.map +1 -0
  397. package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.d.ts +79 -0
  398. package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.js +289 -0
  399. package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.js.map +1 -0
  400. package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.d.ts +87 -0
  401. package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.js +429 -0
  402. package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.js.map +1 -0
  403. package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.d.ts +21 -0
  404. package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.js +84 -0
  405. package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.js.map +1 -0
  406. package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.d.ts +37 -0
  407. package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.js +74 -0
  408. package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.js.map +1 -0
  409. package/lib/webrtc/src/media/sender/estimators/gcc/constants.d.ts +383 -0
  410. package/lib/webrtc/src/media/sender/estimators/gcc/constants.js +408 -0
  411. package/lib/webrtc/src/media/sender/estimators/gcc/constants.js.map +1 -0
  412. package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.d.ts +406 -0
  413. package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.js +1391 -0
  414. package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.js.map +1 -0
  415. package/lib/webrtc/src/media/sender/estimators/gcc/index.d.ts +19 -0
  416. package/lib/webrtc/src/media/sender/estimators/gcc/index.js +75 -0
  417. package/lib/webrtc/src/media/sender/estimators/gcc/index.js.map +1 -0
  418. package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.d.ts +68 -0
  419. package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.js +201 -0
  420. package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.js.map +1 -0
  421. package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.d.ts +26 -0
  422. package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.js +72 -0
  423. package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.js.map +1 -0
  424. package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.d.ts +41 -0
  425. package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.js +99 -0
  426. package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.js.map +1 -0
  427. package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.d.ts +247 -0
  428. package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.js +1042 -0
  429. package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.js.map +1 -0
  430. package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.d.ts +26 -0
  431. package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.js +132 -0
  432. package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.js.map +1 -0
  433. package/lib/webrtc/src/media/sender/estimators/gcc/probeController.d.ts +305 -0
  434. package/lib/webrtc/src/media/sender/estimators/gcc/probeController.js +1073 -0
  435. package/lib/webrtc/src/media/sender/estimators/gcc/probeController.js.map +1 -0
  436. package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.d.ts +60 -0
  437. package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.js +151 -0
  438. package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.js.map +1 -0
  439. package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.d.ts +44 -0
  440. package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.js +246 -0
  441. package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.js.map +1 -0
  442. package/lib/webrtc/src/media/sender/estimators/index.d.ts +7 -0
  443. package/lib/webrtc/src/media/sender/estimators/index.js +19 -0
  444. package/lib/webrtc/src/media/sender/estimators/index.js.map +1 -0
  445. package/lib/webrtc/src/media/sender/estimators/lightweightBwe.d.ts +64 -0
  446. package/lib/webrtc/src/media/sender/estimators/lightweightBwe.js +216 -0
  447. package/lib/webrtc/src/media/sender/estimators/lightweightBwe.js.map +1 -0
  448. package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.d.ts +117 -0
  449. package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.js +250 -0
  450. package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.js.map +1 -0
  451. package/lib/webrtc/src/media/sender/outgoingQueue.d.ts +40 -0
  452. package/lib/webrtc/src/media/sender/outgoingQueue.js +153 -0
  453. package/lib/webrtc/src/media/sender/outgoingQueue.js.map +1 -0
  454. package/lib/webrtc/src/media/sender/padding.d.ts +45 -0
  455. package/lib/webrtc/src/media/sender/padding.js +134 -0
  456. package/lib/webrtc/src/media/sender/padding.js.map +1 -0
  457. package/lib/webrtc/src/media/sender/pendingRtp.d.ts +35 -0
  458. package/lib/webrtc/src/media/sender/pendingRtp.js +120 -0
  459. package/lib/webrtc/src/media/sender/pendingRtp.js.map +1 -0
  460. package/lib/webrtc/src/media/sender/rtpWire.d.ts +13 -0
  461. package/lib/webrtc/src/media/sender/rtpWire.js +38 -0
  462. package/lib/webrtc/src/media/sender/rtpWire.js.map +1 -0
  463. package/lib/webrtc/src/media/sender/sendPacer.d.ts +27 -0
  464. package/lib/webrtc/src/media/sender/sendPacer.js +110 -0
  465. package/lib/webrtc/src/media/sender/sendPacer.js.map +1 -0
  466. package/lib/webrtc/src/media/sender/senderBWE.d.ts +8 -33
  467. package/lib/webrtc/src/media/sender/senderBWE.js +5 -154
  468. package/lib/webrtc/src/media/sender/senderBWE.js.map +1 -1
  469. package/lib/webrtc/src/media/sender/senderReportHistory.d.ts +51 -0
  470. package/lib/webrtc/src/media/sender/senderReportHistory.js +111 -0
  471. package/lib/webrtc/src/media/sender/senderReportHistory.js.map +1 -0
  472. package/lib/webrtc/src/media/sender/senderStats.d.ts +101 -0
  473. package/lib/webrtc/src/media/sender/senderStats.js +317 -0
  474. package/lib/webrtc/src/media/sender/senderStats.js.map +1 -0
  475. package/lib/webrtc/src/media/track.d.ts +29 -2
  476. package/lib/webrtc/src/media/track.js +32 -5
  477. package/lib/webrtc/src/media/track.js.map +1 -1
  478. package/lib/webrtc/src/negotiation/bundleTopology.d.ts +1 -5
  479. package/lib/webrtc/src/negotiation/bundleTopology.js +15 -11
  480. package/lib/webrtc/src/negotiation/bundleTopology.js.map +1 -1
  481. package/lib/webrtc/src/negotiation/descriptionValidation.js +12 -6
  482. package/lib/webrtc/src/negotiation/descriptionValidation.js.map +1 -1
  483. package/lib/webrtc/src/negotiation/negotiationNeeded.js +2 -1
  484. package/lib/webrtc/src/negotiation/negotiationNeeded.js.map +1 -1
  485. package/lib/webrtc/src/negotiation/remoteCandidates.js +10 -5
  486. package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -1
  487. package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +24 -7
  488. package/lib/webrtc/src/negotiation/remoteMediaApplication.js +67 -27
  489. package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -1
  490. package/lib/webrtc/src/negotiation/transceiverPairing.d.ts +1 -0
  491. package/lib/webrtc/src/negotiation/transceiverPairing.js +62 -0
  492. package/lib/webrtc/src/negotiation/transceiverPairing.js.map +1 -0
  493. package/lib/webrtc/src/negotiation/transportActivation.d.ts +8 -1
  494. package/lib/webrtc/src/negotiation/transportActivation.js +40 -8
  495. package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -1
  496. package/lib/webrtc/src/negotiationTransaction.d.ts +43 -5
  497. package/lib/webrtc/src/negotiationTransaction.js +129 -13
  498. package/lib/webrtc/src/negotiationTransaction.js.map +1 -1
  499. package/lib/webrtc/src/nonstandard/dummyMedia.js +2 -1
  500. package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
  501. package/lib/webrtc/src/nonstandard/navigator.js +4 -3
  502. package/lib/webrtc/src/nonstandard/navigator.js.map +1 -1
  503. package/lib/webrtc/src/nonstandard/recorder/index.d.ts +32 -8
  504. package/lib/webrtc/src/nonstandard/recorder/index.js +81 -20
  505. package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
  506. package/lib/webrtc/src/nonstandard/recorder/writer/index.d.ts +9 -7
  507. package/lib/webrtc/src/nonstandard/recorder/writer/index.js +2 -1
  508. package/lib/webrtc/src/nonstandard/recorder/writer/index.js.map +1 -1
  509. package/lib/webrtc/src/nonstandard/recorder/writer/ogg.d.ts +32 -0
  510. package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js +185 -0
  511. package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js.map +1 -0
  512. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +8 -1
  513. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
  514. package/lib/webrtc/src/nonstandard/userMedia.js +2 -1
  515. package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
  516. package/lib/webrtc/src/peerConnection.d.ts +108 -6
  517. package/lib/webrtc/src/peerConnection.js +357 -36
  518. package/lib/webrtc/src/peerConnection.js.map +1 -1
  519. package/lib/webrtc/src/polyfill/globals.d.ts +2 -1
  520. package/lib/webrtc/src/polyfill/globals.js.map +1 -1
  521. package/lib/webrtc/src/polyfill/install.js +2 -0
  522. package/lib/webrtc/src/polyfill/install.js.map +1 -1
  523. package/lib/webrtc/src/polyfill/mediaDevices.js +2 -1
  524. package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
  525. package/lib/webrtc/src/sctpManager.d.ts +46 -14
  526. package/lib/webrtc/src/sctpManager.js +92 -25
  527. package/lib/webrtc/src/sctpManager.js.map +1 -1
  528. package/lib/webrtc/src/sdp.d.ts +69 -0
  529. package/lib/webrtc/src/sdp.js +151 -20
  530. package/lib/webrtc/src/sdp.js.map +1 -1
  531. package/lib/webrtc/src/sdpManager.d.ts +85 -4
  532. package/lib/webrtc/src/sdpManager.js +214 -14
  533. package/lib/webrtc/src/sdpManager.js.map +1 -1
  534. package/lib/webrtc/src/secureTransportManager.d.ts +89 -4
  535. package/lib/webrtc/src/secureTransportManager.js +184 -26
  536. package/lib/webrtc/src/secureTransportManager.js.map +1 -1
  537. package/lib/webrtc/src/transceiverManager.d.ts +82 -4
  538. package/lib/webrtc/src/transceiverManager.js +239 -41
  539. package/lib/webrtc/src/transceiverManager.js.map +1 -1
  540. package/lib/webrtc/src/transport/dtls.d.ts +147 -1
  541. package/lib/webrtc/src/transport/dtls.js +446 -50
  542. package/lib/webrtc/src/transport/dtls.js.map +1 -1
  543. package/lib/webrtc/src/transport/ice.d.ts +71 -90
  544. package/lib/webrtc/src/transport/ice.js +250 -42
  545. package/lib/webrtc/src/transport/ice.js.map +1 -1
  546. package/lib/webrtc/src/transport/sctp.d.ts +25 -0
  547. package/lib/webrtc/src/transport/sctp.js +153 -22
  548. package/lib/webrtc/src/transport/sctp.js.map +1 -1
  549. package/lib/webrtc/src/utils.d.ts +69 -3
  550. package/lib/webrtc/src/utils.js +105 -16
  551. package/lib/webrtc/src/utils.js.map +1 -1
  552. package/package.json +9 -6
@@ -0,0 +1,745 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CandidateGatherer = void 0;
4
+ const net_1 = require("net");
5
+ const candidate_1 = require("./candidate");
6
+ const candidateError_1 = require("./candidateError");
7
+ const exceptions_1 = require("./exceptions");
8
+ const iceBase_1 = require("./iceBase");
9
+ const common_1 = require("./imports/common");
10
+ const defaultRoute_1 = require("./internal/defaultRoute");
11
+ const hostPreference_1 = require("./internal/hostPreference");
12
+ const resolveHostAddresses_1 = require("./internal/resolveHostAddresses");
13
+ const protocol_1 = require("./stun/protocol");
14
+ const tcpProtocol_1 = require("./stun/tcpProtocol");
15
+ const protocol_2 = require("./turn/protocol");
16
+ const log = (0, common_1.debug)("werift-ice : packages/ice/src/candidateGatherer.ts : log");
17
+ /**
18
+ * Candidate gathering of one agent (RFC 8445 §5.1.1): a UDP socket per host
19
+ * address (kept across ICE restarts), TCP passive / active candidates
20
+ * (RFC 6544), server-reflexive candidates from every STUN server (through
21
+ * the host sockets and, in default mode, a wildcard socket per family), and
22
+ * a relay candidate from every TURN server. Failed STUN / TURN servers are
23
+ * reported through the host (`emitCandidateError`).
24
+ */
25
+ class CandidateGatherer {
26
+ constructor(host) {
27
+ /**
28
+ * Server-reflexive candidates each UDP socket advertised in its last
29
+ * gathering (one per distinct mapping its STUN servers returned).
30
+ */
31
+ Object.defineProperty(this, "reflexiveBySocket", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: new WeakMap()
36
+ });
37
+ /**
38
+ * The wildcard UDP socket of each family (default mode with a STUN server).
39
+ * It advertises no host candidate; its first server-reflexive candidate is
40
+ * its local candidate. Kept across ICE restarts like the host sockets.
41
+ */
42
+ Object.defineProperty(this, "wildcardProtocols", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: new Map()
47
+ });
48
+ Object.defineProperty(this, "host", {
49
+ enumerable: true,
50
+ configurable: true,
51
+ writable: true,
52
+ value: void 0
53
+ });
54
+ this.host = host;
55
+ }
56
+ /**
57
+ * The gathering work of one generation.
58
+ *
59
+ * - `primary`: what gathering waits for. The host sockets, the TURN
60
+ * allocations and the server-reflexive queries of the representative
61
+ * sockets: the wildcard socket of each family and the host socket of
62
+ * the default-route address (every host socket when the family has
63
+ * neither).
64
+ * - `background`: the server-reflexive queries of the other host sockets,
65
+ * complete once `primary` has settled. Their candidates trickle after
66
+ * gathering returns; end-of-candidates (`localCandidatesEnd`) waits for
67
+ * them. A network interface whose address cannot reach the STUN server
68
+ * so no longer delays gathering.
69
+ */
70
+ candidatePromises(hostAddresses, timeout = 5, generation = this.host.generation(), defaultRoutes = Promise.resolve([])) {
71
+ const primary = [];
72
+ // Filled while the primary work runs; complete once it has settled.
73
+ const background = [];
74
+ // Each continuation below runs after an await: a socket or allocation it
75
+ // opened for a replaced generation (or a closed agent) is closed, and
76
+ // nothing is added to the current one.
77
+ const stale = () => !this.host.isGathering(generation);
78
+ const stunServers = this.host.stunServers();
79
+ const turnServers = this.host.turnServers();
80
+ const { interfaceAddresses } = this.host.options();
81
+ const gatherIceLite = this.host.iceLite();
82
+ const gatherRelayOnly = (0, iceBase_1.isRelayOnlyGathering)(this.host.options());
83
+ // Local preferences over the whole host list (the sockets an ICE restart
84
+ // keeps included), so they stay distinct across generations.
85
+ const localPreferenceOf = defaultRoutes.then((routes) => {
86
+ const preferences = (0, hostPreference_1.hostLocalPreferences)(hostAddresses, routes);
87
+ return new Map(hostAddresses.map(({ address }, i) => [
88
+ (0, resolveHostAddresses_1.normalizeIp)(address),
89
+ preferences[i],
90
+ ]));
91
+ });
92
+ // TCP host candidates are kept per address like the UDP ones, but on
93
+ // their own: a restart that turned useTcp on gathers them for addresses
94
+ // whose UDP sockets were kept.
95
+ const tcpAddresses = hostAddresses
96
+ .map(({ address }) => address)
97
+ .filter((address) => !this.host
98
+ .protocols()
99
+ .some((protocol) => protocol.localCandidate?.transport.toLowerCase() === "tcp" &&
100
+ protocol.localIp === address));
101
+ const addresses = hostAddresses.filter(({ address }) => {
102
+ // ice restartで同じアドレスが追加されるのを防ぐ
103
+ // (localIp is the bound address, whose IPv6 notation may differ)
104
+ if (this.host
105
+ .protocols()
106
+ .find((protocol) => protocol.localIp !== undefined &&
107
+ (0, resolveHostAddresses_1.normalizeIp)(protocol.localIp) === (0, resolveHostAddresses_1.normalizeIp)(address))) {
108
+ return false;
109
+ }
110
+ // A family bound to an interface address has one UDP host socket; its
111
+ // localIp is the bound address, whose notation may differ (IPv6).
112
+ if ((0, common_1.interfaceAddress)(socketTypeOf(address), interfaceAddresses) ===
113
+ address &&
114
+ this.host
115
+ .protocols()
116
+ .some((protocol) => protocol instanceof protocol_1.StunProtocol &&
117
+ protocol.localCandidate?.type === "host" &&
118
+ (0, net_1.isIPv4)(protocol.localCandidate.host) === (0, net_1.isIPv4)(address))) {
119
+ return false;
120
+ }
121
+ return true;
122
+ });
123
+ // An ICE restart keeps its UDP sockets. They are not re-created above, but
124
+ // their server-reflexive address is part of the new generation too, so
125
+ // the STUN query below runs for them as well.
126
+ const reusedStunProtocols = this.host
127
+ .protocols()
128
+ .filter((protocol) => protocol instanceof protocol_1.StunProtocol &&
129
+ protocol.localCandidate?.type === "host" &&
130
+ protocol.localCandidate.transport === "udp");
131
+ const localStunPromises = gatherRelayOnly
132
+ ? []
133
+ : addresses.map(async ({ address, bind, bindAddress }) => {
134
+ // # create transport
135
+ const protocol = new protocol_1.StunProtocol();
136
+ this.host.ensureProtocol(protocol);
137
+ // An explicit interface address or an enumerated local address is
138
+ // bound to, so packets of the socket leave from the advertised
139
+ // address (a wildcard socket's source follows the routing table).
140
+ const boundInterface = bind === resolveHostAddresses_1.HostAddressBind.explicit
141
+ ? (0, common_1.interfaceAddress)(socketTypeOf(address), interfaceAddresses)
142
+ : bind === resolveHostAddresses_1.HostAddressBind.enumerated
143
+ ? bindAddress
144
+ : undefined;
145
+ try {
146
+ await protocol.connectionMade((0, net_1.isIPv4)(address), this.host.options().portRange, interfaceAddresses, bind === resolveHostAddresses_1.HostAddressBind.enumerated ? { bindAddress } : {});
147
+ const localPreference = (await localPreferenceOf).get((0, resolveHostAddresses_1.normalizeIp)(address));
148
+ if (stale()) {
149
+ await protocol.close();
150
+ return;
151
+ }
152
+ // # add host candidate
153
+ // A socket bound to an address advertises the bound address: the
154
+ // peer sends its checks there and the socket's packets leave from
155
+ // it. A wildcard socket advertises the gathered address (never
156
+ // 0.0.0.0 / ::).
157
+ const [boundHost, boundPort] = protocol.getExtraInfo();
158
+ let candidateHost = address;
159
+ if (boundInterface) {
160
+ candidateHost = stripZoneId(boundHost);
161
+ if ((0, resolveHostAddresses_1.normalizeIp)(candidateHost) !== (0, resolveHostAddresses_1.normalizeIp)(address)) {
162
+ log("host address differs from the bound interface address; advertise the bound one", address, candidateHost);
163
+ }
164
+ }
165
+ const candidateAddress = [candidateHost, boundPort];
166
+ protocol.localIp = candidateHost;
167
+ this.host.protocols().push(protocol);
168
+ log("protocol", protocol.localIp);
169
+ protocol.localCandidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("host", "udp", candidateAddress[0]), 1, "udp", (0, candidate_1.candidatePriority)("host", {
170
+ transport: "udp",
171
+ localPreference,
172
+ }), candidateAddress[0], candidateAddress[1], "host", undefined, undefined, undefined, this.host.generation(), this.host.localUsername());
173
+ this.host.pairLocalProtocol(protocol);
174
+ this.host.appendLocalCandidate(protocol.localCandidate);
175
+ return protocol;
176
+ }
177
+ catch (error) {
178
+ if (boundInterface) {
179
+ // No host candidate for this address: advertising it from
180
+ // another (wildcard) socket would mislead the peer. Candidates
181
+ // of the other addresses are gathered independently.
182
+ log("failed to bind UDP socket to host address", boundInterface, error);
183
+ }
184
+ else {
185
+ log("error protocol STUN", error);
186
+ }
187
+ }
188
+ });
189
+ if (!gatherRelayOnly) {
190
+ primary.push(...localStunPromises.map((localPromise) => localPromise.then((protocol) => protocol?.localCandidate)));
191
+ }
192
+ if (!gatherRelayOnly && this.host.options().useTcp) {
193
+ const tcpCandidatePromises = tcpAddresses.map(async (address) => {
194
+ // Passive candidates open a listening TCP server; skip them when the
195
+ // agent only makes outbound connections (tcpPassive === false). Active
196
+ // candidates below still dial out, so direct TCP egress is unaffected.
197
+ if (this.host.options().tcpPassive !== false) {
198
+ const passiveProtocol = new tcpProtocol_1.TcpPassiveProtocol();
199
+ this.host.ensureProtocol(passiveProtocol);
200
+ await passiveProtocol.connectionMade(address, this.host.options().portRange);
201
+ if (stale()) {
202
+ await passiveProtocol.close();
203
+ return;
204
+ }
205
+ passiveProtocol.localIp = address;
206
+ passiveProtocol.localCandidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("host", "tcp", address), 1, "tcp", (0, candidate_1.candidatePriority)("host", {
207
+ transport: "tcp",
208
+ tcptype: "passive",
209
+ }), address, passiveProtocol.listeningPort, "host", undefined, undefined, "passive", this.host.generation(), this.host.localUsername());
210
+ this.host.protocols().push(passiveProtocol);
211
+ this.host.appendLocalCandidate(passiveProtocol.localCandidate);
212
+ }
213
+ if (!gatherIceLite) {
214
+ const activeProtocol = new tcpProtocol_1.TcpActiveProtocol();
215
+ this.host.ensureProtocol(activeProtocol);
216
+ await activeProtocol.connectionMade(address);
217
+ if (stale()) {
218
+ await activeProtocol.close();
219
+ return;
220
+ }
221
+ activeProtocol.localIp = address;
222
+ activeProtocol.localCandidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("host", "tcp", address), 1, "tcp", (0, candidate_1.candidatePriority)("host", {
223
+ transport: "tcp",
224
+ tcptype: "active",
225
+ }), address, 9, "host", undefined, undefined, "active", this.host.generation(), this.host.localUsername());
226
+ this.host.protocols().push(activeProtocol);
227
+ this.host.pairLocalProtocol(activeProtocol);
228
+ this.host.appendLocalCandidate(activeProtocol.localCandidate);
229
+ }
230
+ });
231
+ primary.push(...tcpCandidatePromises);
232
+ }
233
+ // The application's names of the STUN servers this gathering queries;
234
+ // the built-in default one, in no configuration, gets a synthesized URL.
235
+ const defaultStunServer = this.host.defaultStunServer();
236
+ const stunServerUrls = [
237
+ ...(this.host.options().stunServerUrls ?? []),
238
+ ...(defaultStunServer ? [defaultStunServer] : []),
239
+ ];
240
+ const stunServerRef = (server) => {
241
+ const urls = [
242
+ ...new Set(stunServerUrls
243
+ .filter((entry) => entry?.address?.[0] === server[0] &&
244
+ entry.address[1] === server[1])
245
+ .map((entry) => entry.url)),
246
+ ];
247
+ return urls.length > 0
248
+ ? { kind: "stun", address: server, urls }
249
+ : { kind: "stun", address: server };
250
+ };
251
+ const stunContext = { kind: "stun" };
252
+ const stunOutcomes = new Map();
253
+ const hostStunPathCount = reusedStunProtocols.filter((protocol) => (0, net_1.isIPv4)(protocol.localCandidate.host)).length + localStunPromises.length;
254
+ const defaultMode = !interfaceAddresses?.udp4 && !interfaceAddresses?.udp6;
255
+ const wildcardFamilies = [4, 6].filter((family) => defaultMode &&
256
+ (family === 4
257
+ ? this.host.options().useIpv4
258
+ : this.host.options().useIpv6) &&
259
+ this.reflexiveServersOf(family).length > 0);
260
+ for (const server of stunServers) {
261
+ const wildcardPaths = wildcardFamilies.filter((family) => this.reflexiveServersOf(family).some((candidate) => candidate[0] === server[0] && candidate[1] === server[1])).length;
262
+ stunOutcomes.set(server, {
263
+ pending: hostStunPathCount + wildcardPaths,
264
+ reached: false,
265
+ });
266
+ }
267
+ const settleStunServer = (server, outcome) => {
268
+ const state = stunOutcomes.get(server);
269
+ if (!state || state.pending === 0)
270
+ return;
271
+ state.pending--;
272
+ if (outcome === "reached")
273
+ state.reached = true;
274
+ else if (outcome && outcome !== "skipped") {
275
+ if (!state.unreached || (!state.unreached.local && outcome.local)) {
276
+ state.unreached = outcome;
277
+ }
278
+ }
279
+ if (state.pending === 0 && !state.reached && state.unreached) {
280
+ this.host.emitCandidateError(stale, generation, stunServerRef(server), state.unreached.failure, state.unreached.local);
281
+ }
282
+ };
283
+ /**
284
+ * One counted path toward `servers`: settles every one of them `query`
285
+ * did not settle (a socket that does not query: an IPv6 socket, one
286
+ * that failed to open, a stale generation). Called synchronously while
287
+ * the paths are set up, so stunPaths holds every path.
288
+ */
289
+ const stunPaths = [];
290
+ const settlingStunServers = (query, servers = stunServers) => {
291
+ const settled = new Set();
292
+ const path = (async () => {
293
+ try {
294
+ return await query(settled);
295
+ }
296
+ finally {
297
+ for (const server of servers) {
298
+ if (!settled.has(server))
299
+ settleStunServer(server, "skipped");
300
+ }
301
+ }
302
+ })();
303
+ stunPaths.push(path.catch(() => undefined));
304
+ return path;
305
+ };
306
+ /**
307
+ * Backstop once every path ended: a server still pending (a path that
308
+ * was counted but never settled it) is judged now, so its 701 is not
309
+ * lost to a counting mismatch.
310
+ */
311
+ const judgeRemainingStunServers = () => {
312
+ void Promise.allSettled(stunPaths).then(() => {
313
+ for (const [server, state] of stunOutcomes) {
314
+ if (state.pending === 0)
315
+ continue;
316
+ log("STUN server still pending after every path ended", server);
317
+ state.pending = 1;
318
+ settleStunServer(server, "skipped");
319
+ }
320
+ });
321
+ };
322
+ // A server-reflexive query of one socket to one STUN server, bounded by
323
+ // the STUN gather timeout; an unanswered or failed one yields nothing.
324
+ // The first of its failure and the timeout decides, a late result is
325
+ // ignored; the outcome settles the server for this socket (above).
326
+ const queryReflexive = async (protocol, server, settled) => {
327
+ const local = protocol.localCandidate
328
+ ? {
329
+ address: protocol.localCandidate.host,
330
+ port: protocol.localCandidate.port,
331
+ }
332
+ : undefined;
333
+ // The first of the query's outcome and the timeout settles it.
334
+ let settledQuery = false;
335
+ // Assigned in the callbacks below (not narrowed by the initializer).
336
+ let outcome = "skipped";
337
+ const fail = (failure) => {
338
+ if (failure.errorCode === candidateError_1.IceCandidateErrorCode.SERVER_NOT_REACHED) {
339
+ outcome = { failure, local };
340
+ return;
341
+ }
342
+ // The server answered: it was reached, its error is reported now.
343
+ outcome = "reached";
344
+ this.host.emitCandidateError(stale, generation, stunServerRef(server), failure, local);
345
+ };
346
+ let timer;
347
+ const candidate = await Promise.race([
348
+ (0, iceBase_1.queryServerReflexiveCandidate)(protocol, server, this.wildcardBaseOf(protocol)).then((candidate) => {
349
+ if (!settledQuery)
350
+ outcome = "reached";
351
+ settledQuery = true;
352
+ return candidate;
353
+ }, (error) => {
354
+ log("query STUN server", server, error);
355
+ if (!settledQuery) {
356
+ settledQuery = true;
357
+ const failure = (0, candidateError_1.classifyGatherError)(error, stunContext);
358
+ if (failure)
359
+ fail(failure);
360
+ // Answers without a reportable STUN error still prove reachability.
361
+ else if ((0, candidateError_1.isServerAnswer)(error))
362
+ outcome = "reached";
363
+ }
364
+ return undefined;
365
+ }),
366
+ new Promise((resolve) => {
367
+ timer = setTimeout(() => {
368
+ if (settledQuery)
369
+ return;
370
+ settledQuery = true;
371
+ log("query STUN server timed out", server);
372
+ fail({
373
+ errorCode: candidateError_1.IceCandidateErrorCode.SERVER_NOT_REACHED,
374
+ errorText: "STUN binding request timed out",
375
+ });
376
+ resolve(undefined);
377
+ }, timeout * 1000);
378
+ }),
379
+ ]);
380
+ clearTimeout(timer);
381
+ if (outcome === "reached") {
382
+ this.host.emitServerReached(stale, generation, stunServerRef(server));
383
+ }
384
+ if (settled) {
385
+ settled.add(server);
386
+ settleStunServer(server, outcome);
387
+ }
388
+ return candidate;
389
+ };
390
+ // RFC 8445 §5.1.3: a mapping equal to one the socket already advertised
391
+ // (same base, same transport address) is redundant.
392
+ const sameMapping = (a, b) => a.host === b.host && a.port === b.port;
393
+ if (!gatherIceLite && !gatherRelayOnly && stunServers.length > 0) {
394
+ // # wildcard sockets
395
+ // In the default mode (no interfaceAddresses) every family with a STUN
396
+ // server gets one more UDP socket bound to the wildcard address. It
397
+ // advertises no host candidate; the OS picks its route, so it maps
398
+ // even when the only way out is an interface the host sockets do not
399
+ // cover, and it receives whatever reaches its port (a DNAT to another
400
+ // local address, an address added after gathering).
401
+ const wildcardReady = new Map();
402
+ for (const family of wildcardFamilies) {
403
+ const kept = this.wildcardProtocols.get(family);
404
+ if (kept && this.host.protocols().includes(kept)) {
405
+ // Kept across an ICE restart: queried again with the reused sockets.
406
+ wildcardReady.set(family, Promise.resolve(true));
407
+ continue;
408
+ }
409
+ // One still opening for a replaced generation is not reused.
410
+ if (kept) {
411
+ this.wildcardProtocols.delete(family);
412
+ void kept.close().catch(() => { });
413
+ }
414
+ const wildcardServers = this.reflexiveServersOf(family);
415
+ const query = settlingStunServers((settled) => this.gatherWildcardReflexive(family, (protocol, server) => queryReflexive(protocol, server, settled), sameMapping, stale), wildcardServers);
416
+ wildcardReady.set(family, query.then(({ bound }) => bound));
417
+ primary.push(query);
418
+ }
419
+ // Sockets kept across an ICE restart query every STUN server again.
420
+ // The mappings they already advertised are in the new generation from
421
+ // the start; a different fresh mapping (the NAT rebound) is added to
422
+ // it, and the fresh mappings replace the kept ones for the next restart.
423
+ const reflexiveOfReused = (protocol) => settlingStunServers(async (settled) => {
424
+ const previous = this.reflexiveBySocket.get(protocol) ?? [];
425
+ const advertised = [...previous];
426
+ const fresh = [];
427
+ await Promise.all(this.reflexiveServersOf(protocol).map(async (server) => {
428
+ const candidate = await queryReflexive(protocol, server, settled);
429
+ if (!candidate || stale())
430
+ return;
431
+ if (!fresh.some((known) => sameMapping(known, candidate))) {
432
+ fresh.push(candidate);
433
+ }
434
+ if (advertised.some((known) => sameMapping(known, candidate)))
435
+ return;
436
+ advertised.push(candidate);
437
+ this.host.appendLocalCandidate(candidate);
438
+ }));
439
+ if (stale())
440
+ return;
441
+ if (fresh.length > 0)
442
+ this.reflexiveBySocket.set(protocol, fresh);
443
+ return fresh.length > 0 ? fresh : previous;
444
+ }, this.reflexiveServersOf(protocol)).catch((error) => {
445
+ log("query reused STUN socket", error);
446
+ });
447
+ // The queries of a new socket; its path (settlingStunServers) is
448
+ // opened before the socket is, see newHosts.
449
+ const reflexiveOfNew = async (protocol, settled) => {
450
+ const advertised = [];
451
+ await Promise.all(stunServers.map(async (server) => {
452
+ const candidate = await queryReflexive(protocol, server, settled);
453
+ if (!candidate || stale())
454
+ return;
455
+ if (advertised.some((known) => sameMapping(known, candidate)))
456
+ return;
457
+ advertised.push(candidate);
458
+ this.reflexiveBySocket.set(protocol, advertised);
459
+ this.host.appendLocalCandidate(candidate);
460
+ })).catch((error) => {
461
+ log("query new STUN socket", error);
462
+ });
463
+ return advertised;
464
+ };
465
+ // A kept wildcard socket is a representative: gathering waits for it.
466
+ const reusedWildcards = [...this.wildcardProtocols.values()].filter((protocol) => this.host.protocols().includes(protocol));
467
+ primary.push(...reusedWildcards.map(reflexiveOfReused));
468
+ const track = (protocol, query) => {
469
+ const entry = { protocol, query, settled: false };
470
+ void query.finally(() => {
471
+ entry.settled = true;
472
+ });
473
+ return entry;
474
+ };
475
+ const reusedHosts = reusedStunProtocols
476
+ .filter((protocol) => (0, net_1.isIPv4)(protocol.localCandidate.host))
477
+ .map((protocol) => track(protocol, reflexiveOfReused(protocol)));
478
+ // Every new socket is counted for every STUN server (stunOutcomes),
479
+ // so its path opens now, before the socket does: a socket that does
480
+ // not query (IPv6, failed to open) settles them as skipped.
481
+ const newHosts = Promise.all(localStunPromises.map((protocolPromise) => {
482
+ let resolveEntry;
483
+ const entry = new Promise((resolve) => {
484
+ resolveEntry = resolve;
485
+ });
486
+ settlingStunServers(async (settled) => {
487
+ const protocol = await Promise.resolve(protocolPromise).catch(() => undefined);
488
+ if (!protocol?.localCandidate ||
489
+ !(0, net_1.isIPv4)(protocol.localCandidate.host)) {
490
+ resolveEntry(undefined);
491
+ return;
492
+ }
493
+ const query = reflexiveOfNew(protocol, settled);
494
+ resolveEntry(track(protocol, query));
495
+ await query;
496
+ }).catch((error) => {
497
+ resolveEntry(undefined);
498
+ log("query new STUN socket", error);
499
+ });
500
+ return entry;
501
+ }));
502
+ judgeRemainingStunServers();
503
+ primary.push((async () => {
504
+ const queries = [
505
+ ...reusedHosts,
506
+ ...(await newHosts).filter((entry) => entry !== undefined),
507
+ ];
508
+ const routes = (await defaultRoutes).map(resolveHostAddresses_1.normalizeIp);
509
+ const defaultRouteQueries = queries.filter(({ protocol }) => routes.includes((0, resolveHostAddresses_1.normalizeIp)(protocol.localCandidate.host)));
510
+ const representative = defaultRouteQueries.length > 0 || (await wildcardReady.get(4))
511
+ ? defaultRouteQueries
512
+ : queries;
513
+ // Filled before this primary work settles: gatherCandidates()
514
+ // reads it then.
515
+ background.push(...queries.filter((entry) => !representative.includes(entry)));
516
+ await Promise.allSettled(representative.map(({ query }) => query));
517
+ })());
518
+ }
519
+ if (!gatherIceLite) {
520
+ // Every TURN server gets its own allocation, made with its own
521
+ // credential and transport; one that fails does not stop the others.
522
+ // A TURN allocation has its own UDP socket, bound to the wildcard
523
+ // address unless interfaceAddresses binds the family: the OS picks
524
+ // its route as for the wildcard STUN socket.
525
+ const turnCandidatePromises = turnServers.map((server) => this.gatherRelayCandidate(server, gatherRelayOnly, stale, generation).catch((error) => {
526
+ log("query TURN server", server.address, error);
527
+ }));
528
+ primary.push(...turnCandidatePromises);
529
+ }
530
+ return { primary, background };
531
+ }
532
+ /**
533
+ * Open the wildcard socket of `family` and query the STUN servers from it.
534
+ * Its first server-reflexive candidate becomes the socket's local
535
+ * candidate: the socket joins the agent and pairs with the remote
536
+ * candidates (its checks leave through the NAT mapping it advertised).
537
+ * A socket that maps nothing is closed.
538
+ */
539
+ async gatherWildcardReflexive(family, queryReflexive, sameMapping, stale) {
540
+ const protocol = new protocol_1.StunProtocol();
541
+ try {
542
+ // No interfaceAddresses / bindAddress: the wildcard address.
543
+ await protocol.connectionMade(family === 4, this.host.options().portRange);
544
+ }
545
+ catch (error) {
546
+ log("failed to bind the wildcard UDP socket", family, error);
547
+ return { bound: false };
548
+ }
549
+ if (stale()) {
550
+ await protocol.close();
551
+ return { bound: true };
552
+ }
553
+ this.wildcardProtocols.set(family, protocol);
554
+ const advertised = [];
555
+ await Promise.all(this.reflexiveServersOf(family).map(async (server) => {
556
+ const candidate = await queryReflexive(protocol, server);
557
+ if (!candidate || stale() || !this.isWildcardProtocol(protocol))
558
+ return;
559
+ if (advertised.some((known) => sameMapping(known, candidate))) {
560
+ return;
561
+ }
562
+ advertised.push(candidate);
563
+ this.reflexiveBySocket.set(protocol, advertised);
564
+ if (!protocol.localCandidate) {
565
+ protocol.localCandidate = candidate;
566
+ protocol.localIp = family === 4 ? "0.0.0.0" : "::";
567
+ this.host.ensureProtocol(protocol);
568
+ this.host.protocols().push(protocol);
569
+ this.host.pairLocalProtocol(protocol);
570
+ }
571
+ this.host.appendLocalCandidate(candidate);
572
+ }));
573
+ if (!protocol.localCandidate) {
574
+ if (this.wildcardProtocols.get(family) === protocol) {
575
+ this.wildcardProtocols.delete(family);
576
+ }
577
+ await protocol.close();
578
+ }
579
+ return { bound: true };
580
+ }
581
+ /** Whether `protocol` is a wildcard socket (advertises no host candidate). */
582
+ isWildcardProtocol(protocol) {
583
+ for (const wildcard of this.wildcardProtocols.values()) {
584
+ if (wildcard === protocol)
585
+ return true;
586
+ }
587
+ return false;
588
+ }
589
+ /**
590
+ * Whether the wildcard socket should check `remoteCandidate`: only a path
591
+ * no host socket covers. When the OS routes to the remote address from an
592
+ * address a UDP host socket is bound to, that socket checks the same path
593
+ * (through a NAT as its own server-reflexive address), while the wildcard
594
+ * socket's packets would leave from an address it does not advertise and
595
+ * make the peer learn a peer-reflexive candidate. Without a route the
596
+ * socket cannot reach the address either.
597
+ */
598
+ async wildcardPathUncovered(remoteCandidate) {
599
+ const source = await (0, defaultRoute_1.getRouteSourceAddress)(remoteCandidate.host);
600
+ if (!source)
601
+ return false;
602
+ return !this.host
603
+ .protocols()
604
+ .some((protocol) => protocol instanceof protocol_1.StunProtocol &&
605
+ protocol.localCandidate?.type === "host" &&
606
+ protocol.localCandidate.transport === "udp" &&
607
+ (0, resolveHostAddresses_1.normalizeIp)(protocol.localCandidate.host) === (0, resolveHostAddresses_1.normalizeIp)(source));
608
+ }
609
+ /** The base of a wildcard socket's server-reflexive candidates. */
610
+ wildcardBaseOf(protocol) {
611
+ if (!this.isWildcardProtocol(protocol))
612
+ return undefined;
613
+ const [host, port] = protocol.getExtraInfo();
614
+ return {
615
+ host: (0, net_1.isIPv6)(stripZoneId(host)) ? "::" : "0.0.0.0",
616
+ port,
617
+ transport: "udp",
618
+ component: 1,
619
+ };
620
+ }
621
+ /**
622
+ * The STUN servers a socket (or the wildcard socket of a family) queries:
623
+ * every server for IPv4 (as the IPv4 host sockets always did), only the
624
+ * IPv6 literal servers for the IPv6 wildcard socket.
625
+ */
626
+ reflexiveServersOf(target) {
627
+ const family = typeof target === "number"
628
+ ? target
629
+ : this.isWildcardProtocol(target) &&
630
+ (0, net_1.isIPv6)(stripZoneId(target.getExtraInfo()[0]))
631
+ ? 6
632
+ : 4;
633
+ return family === 4
634
+ ? this.host.stunServers()
635
+ : this.host.stunServers().filter(([host]) => (0, net_1.isIPv6)(host));
636
+ }
637
+ /**
638
+ * Allocate on one TURN server and add its relay candidate. A UDP
639
+ * allocation that fails falls back to TCP on the same server. An
640
+ * allocation that completes for a replaced generation (or a closed agent)
641
+ * is released. A failed allocation (both attempts, for the fallback) is
642
+ * reported once (onIceCandidateError) before it rejects.
643
+ */
644
+ async gatherRelayCandidate(server, relayOnly, stale, generation = this.host.generation()) {
645
+ const { address, username, password, transport } = server;
646
+ // Failures of the attempts at this server (UDP, then TCP fallback), and
647
+ // whether any attempt got an answer from it (reached, even without a
648
+ // STUN error code to report).
649
+ const failures = [];
650
+ let answered = false;
651
+ const recordFailure = (error, attemptTransport) => {
652
+ if ((0, candidateError_1.isServerAnswer)(error))
653
+ answered = true;
654
+ failures.push((0, candidateError_1.classifyGatherError)(error, {
655
+ kind: "turn",
656
+ transport: attemptTransport,
657
+ // Masked out of the server's reason phrase.
658
+ secrets: [username, password],
659
+ }));
660
+ };
661
+ const ref = {
662
+ kind: "turn",
663
+ address,
664
+ transport,
665
+ ...(server.urls ? { urls: [...server.urls] } : {}),
666
+ };
667
+ const protocol = await (0, protocol_2.createStunOverTurnClient)({ address, username, password }, {
668
+ portRange: this.host.options().portRange,
669
+ interfaceAddresses: this.host.options().interfaceAddresses,
670
+ transport,
671
+ tlsOptions: this.host.options().turnTlsOptions,
672
+ connectTimeoutMs: (this.host.options().turnConnectTimeout ?? 8) * 1000,
673
+ udpFamily: this.host.options().turnUdpFamily,
674
+ signal: this.host.closing(),
675
+ })
676
+ .catch(async (e) => {
677
+ recordFailure(e, transport);
678
+ // close() cancelled the allocation: no TCP fallback.
679
+ if (transport === "udp" && !this.host.closing().aborted) {
680
+ return await (0, protocol_2.createStunOverTurnClient)({ address, username, password }, {
681
+ portRange: this.host.options().portRange,
682
+ interfaceAddresses: this.host.options().interfaceAddresses,
683
+ transport: "tcp",
684
+ connectTimeoutMs: (this.host.options().turnConnectTimeout ?? 8) * 1000,
685
+ signal: this.host.closing(),
686
+ }).catch((fallbackError) => {
687
+ recordFailure(fallbackError, "tcp");
688
+ throw fallbackError;
689
+ });
690
+ }
691
+ throw e;
692
+ })
693
+ .catch((error) => {
694
+ // A cancelled attempt (close) is not a failure of the server.
695
+ if (error instanceof exceptions_1.TransactionCancelled ||
696
+ this.host.closing().aborted) {
697
+ throw error;
698
+ }
699
+ const reported = (0, candidateError_1.pickReportedGatherError)(failures);
700
+ const reachedServer = answered ||
701
+ (reported !== undefined &&
702
+ reported.errorCode !== candidateError_1.IceCandidateErrorCode.SERVER_NOT_REACHED);
703
+ // A server that answered is never reported as 701 (an attempt that
704
+ // was not answered does not make it unreached).
705
+ if (reported &&
706
+ (reported.errorCode !== candidateError_1.IceCandidateErrorCode.SERVER_NOT_REACHED ||
707
+ !reachedServer)) {
708
+ this.host.emitCandidateError(stale, generation, ref, reported);
709
+ }
710
+ if (reachedServer)
711
+ this.host.emitServerReached(stale, generation, ref);
712
+ throw error;
713
+ });
714
+ if (stale()) {
715
+ // The allocation never joins a generation: release it (and its
716
+ // refresh timer) instead of keeping a second one alive.
717
+ await protocol.close();
718
+ return;
719
+ }
720
+ this.host.emitServerReached(stale, generation, ref);
721
+ protocol.configuredTransport = transport;
722
+ this.host.ensureProtocol(protocol);
723
+ this.host.protocols().push(protocol);
724
+ const candidateAddress = protocol.turn.relayedAddress;
725
+ // The related address of a relay candidate is the address the TURN
726
+ // server saw the agent at. A relay-only policy hides the agent's
727
+ // addresses from the peer, so it advertises the unspecified address
728
+ // and port 9 instead (RFC 8839 §5.1), in SDP and trickle alike.
729
+ const relatedAddress = relayOnly
730
+ ? [(0, net_1.isIPv4)(candidateAddress[0]) ? "0.0.0.0" : "::", 9]
731
+ : protocol.turn.mappedAddress;
732
+ log("turn candidateAddress", candidateAddress);
733
+ protocol.localCandidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("relay", "udp", candidateAddress[0]), 1, "udp", (0, candidate_1.candidatePriority)("relay"), candidateAddress[0], candidateAddress[1], "relay", relatedAddress[0], relatedAddress[1], undefined, this.host.generation(), this.host.localUsername());
734
+ // An allocation that completes after the remote candidates arrived
735
+ // (early signaling, or an ICE restart that allocates afresh) pairs
736
+ // with them; a connect() already running schedules the new pairs.
737
+ this.host.pairLocalProtocol(protocol);
738
+ this.host.appendLocalCandidate(protocol.localCandidate);
739
+ return protocol.localCandidate;
740
+ }
741
+ }
742
+ exports.CandidateGatherer = CandidateGatherer;
743
+ const socketTypeOf = (address) => ((0, net_1.isIPv4)(address) ? "udp4" : "udp6");
744
+ const stripZoneId = (address) => address.split("%")[0];
745
+ //# sourceMappingURL=candidateGatherer.js.map