werift 0.25.2 → 0.27.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 (568) hide show
  1. package/README.md +63 -0
  2. package/THIRD_PARTY_LICENSES_LIBWEBRTC.txt +58 -0
  3. package/lib/common/src/asn1.d.ts +42 -0
  4. package/lib/common/src/asn1.js +163 -0
  5. package/lib/common/src/asn1.js.map +1 -0
  6. package/lib/common/src/binary.d.ts +1 -3
  7. package/lib/common/src/binary.js +8 -6
  8. package/lib/common/src/binary.js.map +1 -1
  9. package/lib/common/src/binaryData.js +2 -1
  10. package/lib/common/src/binaryData.js.map +1 -1
  11. package/lib/common/src/index.d.ts +6 -5
  12. package/lib/common/src/index.js +6 -5
  13. package/lib/common/src/index.js.map +1 -1
  14. package/lib/common/src/log.d.ts +12 -1
  15. package/lib/common/src/log.js +142 -12
  16. package/lib/common/src/log.js.map +1 -1
  17. package/lib/common/src/network.js.map +1 -1
  18. package/lib/common/src/queue.d.ts +41 -0
  19. package/lib/common/src/queue.js +146 -0
  20. package/lib/common/src/queue.js.map +1 -0
  21. package/lib/common/src/transport.d.ts +15 -2
  22. package/lib/common/src/transport.js +108 -19
  23. package/lib/common/src/transport.js.map +1 -1
  24. package/lib/dtls/src/cipher/create.js.map +1 -1
  25. package/lib/dtls/src/cipher/ec.js +8 -8
  26. package/lib/dtls/src/cipher/ec.js.map +1 -1
  27. package/lib/dtls/src/cipher/namedCurve.js +6 -7
  28. package/lib/dtls/src/cipher/namedCurve.js.map +1 -1
  29. package/lib/dtls/src/cipher/prf.d.ts +2 -2
  30. package/lib/dtls/src/cipher/prf.js +29 -8
  31. package/lib/dtls/src/cipher/prf.js.map +1 -1
  32. package/lib/dtls/src/cipher/suites/aead.d.ts +1 -1
  33. package/lib/dtls/src/context/certificate.d.ts +32 -0
  34. package/lib/dtls/src/context/certificate.js +54 -0
  35. package/lib/dtls/src/context/certificate.js.map +1 -0
  36. package/lib/dtls/src/context/cipher.d.ts +13 -7
  37. package/lib/dtls/src/context/cipher.js +58 -106
  38. package/lib/dtls/src/context/cipher.js.map +1 -1
  39. package/lib/dtls/src/context/dtls.js +4 -2
  40. package/lib/dtls/src/context/dtls.js.map +1 -1
  41. package/lib/dtls/src/context/transport.d.ts +4 -0
  42. package/lib/dtls/src/context/transport.js +16 -1
  43. package/lib/dtls/src/context/transport.js.map +1 -1
  44. package/lib/dtls/src/flight/client/flight1.js +2 -1
  45. package/lib/dtls/src/flight/client/flight1.js.map +1 -1
  46. package/lib/dtls/src/flight/client/flight5.js +4 -2
  47. package/lib/dtls/src/flight/client/flight5.js.map +1 -1
  48. package/lib/dtls/src/flight/flight.d.ts +1 -1
  49. package/lib/dtls/src/flight/flight.js +16 -5
  50. package/lib/dtls/src/flight/flight.js.map +1 -1
  51. package/lib/dtls/src/flight/server/flight2.js.map +1 -1
  52. package/lib/dtls/src/flight/server/flight4.d.ts +2 -1
  53. package/lib/dtls/src/flight/server/flight4.js +12 -4
  54. package/lib/dtls/src/flight/server/flight4.js.map +1 -1
  55. package/lib/dtls/src/flight/server/flight6.js +2 -1
  56. package/lib/dtls/src/flight/server/flight6.js.map +1 -1
  57. package/lib/dtls/src/handshake/const.d.ts +17 -13
  58. package/lib/dtls/src/handshake/const.js +16 -14
  59. package/lib/dtls/src/handshake/const.js.map +1 -1
  60. package/lib/dtls/src/handshake/extensions/signature.d.ts +1 -1
  61. package/lib/dtls/src/handshake/extensions/signature.js.map +1 -1
  62. package/lib/dtls/src/handshake/message/alert.js +5 -3
  63. package/lib/dtls/src/handshake/message/alert.js.map +1 -1
  64. package/lib/dtls/src/handshake/message/certificate.js +3 -2
  65. package/lib/dtls/src/handshake/message/certificate.js.map +1 -1
  66. package/lib/dtls/src/handshake/message/changeCipherSpec.js +4 -4
  67. package/lib/dtls/src/handshake/message/changeCipherSpec.js.map +1 -1
  68. package/lib/dtls/src/handshake/message/client/certificateVerify.d.ts +1 -1
  69. package/lib/dtls/src/handshake/message/client/certificateVerify.js +5 -3
  70. package/lib/dtls/src/handshake/message/client/certificateVerify.js.map +1 -1
  71. package/lib/dtls/src/handshake/message/client/hello.js +15 -8
  72. package/lib/dtls/src/handshake/message/client/hello.js.map +1 -1
  73. package/lib/dtls/src/handshake/message/client/keyExchange.js +3 -2
  74. package/lib/dtls/src/handshake/message/client/keyExchange.js.map +1 -1
  75. package/lib/dtls/src/handshake/message/finished.js +2 -1
  76. package/lib/dtls/src/handshake/message/finished.js.map +1 -1
  77. package/lib/dtls/src/handshake/message/server/certificateRequest.d.ts +1 -1
  78. package/lib/dtls/src/handshake/message/server/certificateRequest.js +7 -4
  79. package/lib/dtls/src/handshake/message/server/certificateRequest.js.map +1 -1
  80. package/lib/dtls/src/handshake/message/server/hello.d.ts +1 -1
  81. package/lib/dtls/src/handshake/message/server/hello.js +14 -8
  82. package/lib/dtls/src/handshake/message/server/hello.js.map +1 -1
  83. package/lib/dtls/src/handshake/message/server/helloDone.js +1 -1
  84. package/lib/dtls/src/handshake/message/server/helloDone.js.map +1 -1
  85. package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js +5 -3
  86. package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js.map +1 -1
  87. package/lib/dtls/src/handshake/message/server/keyExchange.d.ts +1 -1
  88. package/lib/dtls/src/handshake/message/server/keyExchange.js +17 -9
  89. package/lib/dtls/src/handshake/message/server/keyExchange.js.map +1 -1
  90. package/lib/dtls/src/handshake/random.d.ts +1 -1
  91. package/lib/dtls/src/handshake/random.js +7 -4
  92. package/lib/dtls/src/handshake/random.js.map +1 -1
  93. package/lib/dtls/src/imports/common.d.ts +1 -0
  94. package/lib/dtls/src/imports/common.js +1 -0
  95. package/lib/dtls/src/imports/common.js.map +1 -1
  96. package/lib/dtls/src/index.d.ts +2 -2
  97. package/lib/dtls/src/index.js +2 -2
  98. package/lib/dtls/src/index.js.map +1 -1
  99. package/lib/dtls/src/record/const.d.ts +43 -33
  100. package/lib/dtls/src/record/const.js +43 -36
  101. package/lib/dtls/src/record/const.js.map +1 -1
  102. package/lib/dtls/src/record/message/fragment.d.ts +1 -1
  103. package/lib/dtls/src/record/message/fragment.js +15 -9
  104. package/lib/dtls/src/record/message/fragment.js.map +1 -1
  105. package/lib/dtls/src/record/message/header.js +12 -7
  106. package/lib/dtls/src/record/message/header.js.map +1 -1
  107. package/lib/dtls/src/record/message/plaintext.js +4 -2
  108. package/lib/dtls/src/record/message/plaintext.js.map +1 -1
  109. package/lib/dtls/src/record/receive.js +2 -2
  110. package/lib/dtls/src/record/receive.js.map +1 -1
  111. package/lib/dtls/src/server.js +1 -1
  112. package/lib/dtls/src/server.js.map +1 -1
  113. package/lib/dtls/src/socket.d.ts +2 -2
  114. package/lib/dtls/src/socket.js +6 -4
  115. package/lib/dtls/src/socket.js.map +1 -1
  116. package/lib/ice/src/candidate.d.ts +1 -1
  117. package/lib/ice/src/candidate.js +24 -12
  118. package/lib/ice/src/candidate.js.map +1 -1
  119. package/lib/ice/src/dns/lookup.d.ts +10 -1
  120. package/lib/ice/src/dns/lookup.js +42 -7
  121. package/lib/ice/src/dns/lookup.js.map +1 -1
  122. package/lib/ice/src/exceptions.d.ts +46 -0
  123. package/lib/ice/src/exceptions.js +92 -5
  124. package/lib/ice/src/exceptions.js.map +1 -1
  125. package/lib/ice/src/helper.d.ts +1 -1
  126. package/lib/ice/src/ice.d.ts +191 -5
  127. package/lib/ice/src/ice.js +1048 -156
  128. package/lib/ice/src/ice.js.map +1 -1
  129. package/lib/ice/src/iceBase.d.ts +174 -10
  130. package/lib/ice/src/iceBase.js +165 -12
  131. package/lib/ice/src/iceBase.js.map +1 -1
  132. package/lib/ice/src/index.d.ts +5 -5
  133. package/lib/ice/src/index.js +5 -5
  134. package/lib/ice/src/index.js.map +1 -1
  135. package/lib/ice/src/internal/resolveHostAddresses.d.ts +26 -0
  136. package/lib/ice/src/internal/resolveHostAddresses.js +45 -0
  137. package/lib/ice/src/internal/resolveHostAddresses.js.map +1 -0
  138. package/lib/ice/src/stun/protocol.d.ts +3 -1
  139. package/lib/ice/src/stun/protocol.js +16 -0
  140. package/lib/ice/src/stun/protocol.js.map +1 -1
  141. package/lib/ice/src/stun/tcpProtocol.d.ts +2 -0
  142. package/lib/ice/src/stun/tcpProtocol.js +16 -1
  143. package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
  144. package/lib/ice/src/stun/transaction.d.ts +35 -1
  145. package/lib/ice/src/stun/transaction.js +93 -18
  146. package/lib/ice/src/stun/transaction.js.map +1 -1
  147. package/lib/ice/src/turn/credential.d.ts +49 -0
  148. package/lib/ice/src/turn/credential.js +78 -0
  149. package/lib/ice/src/turn/credential.js.map +1 -0
  150. package/lib/ice/src/turn/protocol.d.ts +97 -7
  151. package/lib/ice/src/turn/protocol.js +357 -55
  152. package/lib/ice/src/turn/protocol.js.map +1 -1
  153. package/lib/ice/src/utils.js.map +1 -1
  154. package/lib/ice-server/src/stun/attributes.d.ts +2 -0
  155. package/lib/ice-server/src/stun/attributes.js +7 -1
  156. package/lib/ice-server/src/stun/attributes.js.map +1 -1
  157. package/lib/ice-server/src/stun/const.d.ts +24 -16
  158. package/lib/ice-server/src/stun/const.js +22 -18
  159. package/lib/ice-server/src/stun/const.js.map +1 -1
  160. package/lib/ice-server/src/stun/message.d.ts +3 -1
  161. package/lib/ice-server/src/stun/message.js +41 -6
  162. package/lib/ice-server/src/stun/message.js.map +1 -1
  163. package/lib/ice-server/src/turn/auth.d.ts +1 -1
  164. package/lib/index.mjs +25252 -12664
  165. package/lib/nonstandard/index.mjs +11015 -8906
  166. package/lib/polyfill/dom.mjs +30779 -18386
  167. package/lib/polyfill/index.mjs +30779 -18386
  168. package/lib/rtp/src/codec/assertPayload.d.ts +4 -0
  169. package/lib/rtp/src/codec/assertPayload.js +12 -0
  170. package/lib/rtp/src/codec/assertPayload.js.map +1 -0
  171. package/lib/rtp/src/codec/av1.js +2 -0
  172. package/lib/rtp/src/codec/av1.js.map +1 -1
  173. package/lib/rtp/src/codec/h264.d.ts +1 -1
  174. package/lib/rtp/src/codec/h264.js +35 -43
  175. package/lib/rtp/src/codec/h264.js.map +1 -1
  176. package/lib/rtp/src/codec/vp8.js +11 -5
  177. package/lib/rtp/src/codec/vp8.js.map +1 -1
  178. package/lib/rtp/src/codec/vp9.js +12 -0
  179. package/lib/rtp/src/codec/vp9.js.map +1 -1
  180. package/lib/rtp/src/extra/container/mp4/container.js +2 -1
  181. package/lib/rtp/src/extra/container/mp4/container.js.map +1 -1
  182. package/lib/rtp/src/extra/container/mp4/exp-golomb.js +2 -1
  183. package/lib/rtp/src/extra/container/mp4/exp-golomb.js.map +1 -1
  184. package/lib/rtp/src/extra/container/mp4/h264.d.ts +21 -17
  185. package/lib/rtp/src/extra/container/mp4/h264.js +26 -24
  186. package/lib/rtp/src/extra/container/mp4/h264.js.map +1 -1
  187. package/lib/rtp/src/extra/container/ogg/index.d.ts +1 -0
  188. package/lib/rtp/src/extra/container/ogg/index.js +1 -0
  189. package/lib/rtp/src/extra/container/ogg/index.js.map +1 -1
  190. package/lib/rtp/src/extra/container/ogg/writer.d.ts +90 -0
  191. package/lib/rtp/src/extra/container/ogg/writer.js +300 -0
  192. package/lib/rtp/src/extra/container/ogg/writer.js.map +1 -0
  193. package/lib/rtp/src/extra/container/webm/container.d.ts +1 -1
  194. package/lib/rtp/src/extra/container/webm/ebml/ebml.d.ts +6 -0
  195. package/lib/rtp/src/extra/container/webm/ebml/ebml.js +26 -4
  196. package/lib/rtp/src/extra/container/webm/ebml/ebml.js.map +1 -1
  197. package/lib/rtp/src/extra/processor/depacketizer.d.ts +6 -1
  198. package/lib/rtp/src/extra/processor/depacketizer.js +29 -3
  199. package/lib/rtp/src/extra/processor/depacketizer.js.map +1 -1
  200. package/lib/rtp/src/extra/processor/depacketizerCallback.d.ts +1 -11
  201. package/lib/rtp/src/extra/processor/depacketizerTransformer.d.ts +1 -1
  202. package/lib/rtp/src/extra/processor/dtx.js +4 -2
  203. package/lib/rtp/src/extra/processor/dtx.js.map +1 -1
  204. package/lib/rtp/src/extra/processor/dtxCallback.d.ts +1 -11
  205. package/lib/rtp/src/extra/processor/index.d.ts +2 -0
  206. package/lib/rtp/src/extra/processor/index.js +2 -0
  207. package/lib/rtp/src/extra/processor/index.js.map +1 -1
  208. package/lib/rtp/src/extra/processor/interface.d.ts +16 -11
  209. package/lib/rtp/src/extra/processor/interface.js.map +1 -1
  210. package/lib/rtp/src/extra/processor/jitterBuffer.d.ts +29 -6
  211. package/lib/rtp/src/extra/processor/jitterBuffer.js +101 -111
  212. package/lib/rtp/src/extra/processor/jitterBuffer.js.map +1 -1
  213. package/lib/rtp/src/extra/processor/jitterBufferCallback.d.ts +1 -11
  214. package/lib/rtp/src/extra/processor/jitterBufferTransformer.d.ts +1 -1
  215. package/lib/rtp/src/extra/processor/jitterBufferTransformer.js +2 -1
  216. package/lib/rtp/src/extra/processor/jitterBufferTransformer.js.map +1 -1
  217. package/lib/rtp/src/extra/processor/lipsync.d.ts +63 -0
  218. package/lib/rtp/src/extra/processor/lipsync.js +202 -51
  219. package/lib/rtp/src/extra/processor/lipsync.js.map +1 -1
  220. package/lib/rtp/src/extra/processor/mp4.d.ts +0 -6
  221. package/lib/rtp/src/extra/processor/mp4.js +7 -4
  222. package/lib/rtp/src/extra/processor/mp4.js.map +1 -1
  223. package/lib/rtp/src/extra/processor/mute.js +4 -2
  224. package/lib/rtp/src/extra/processor/mute.js.map +1 -1
  225. package/lib/rtp/src/extra/processor/nack.d.ts +1 -1
  226. package/lib/rtp/src/extra/processor/nack.js +5 -3
  227. package/lib/rtp/src/extra/processor/nack.js.map +1 -1
  228. package/lib/rtp/src/extra/processor/nackHandlerCallback.d.ts +1 -11
  229. package/lib/rtp/src/extra/processor/ntpTime.js +4 -6
  230. package/lib/rtp/src/extra/processor/ntpTime.js.map +1 -1
  231. package/lib/rtp/src/extra/processor/ntpTimeCallback.d.ts +1 -11
  232. package/lib/rtp/src/extra/processor/ogg.d.ts +72 -0
  233. package/lib/rtp/src/extra/processor/ogg.js +221 -0
  234. package/lib/rtp/src/extra/processor/ogg.js.map +1 -0
  235. package/lib/rtp/src/extra/processor/oggCallback.d.ts +21 -0
  236. package/lib/rtp/src/extra/processor/oggCallback.js +97 -0
  237. package/lib/rtp/src/extra/processor/oggCallback.js.map +1 -0
  238. package/lib/rtp/src/extra/processor/rtcpCallback.d.ts +1 -1
  239. package/lib/rtp/src/extra/processor/rtcpCallback.js.map +1 -1
  240. package/lib/rtp/src/extra/processor/rtpCallback.d.ts +1 -1
  241. package/lib/rtp/src/extra/processor/rtpCallback.js +3 -2
  242. package/lib/rtp/src/extra/processor/rtpCallback.js.map +1 -1
  243. package/lib/rtp/src/extra/processor/rtpStream.d.ts +2 -2
  244. package/lib/rtp/src/extra/processor/rtpStream.js +2 -1
  245. package/lib/rtp/src/extra/processor/rtpStream.js.map +1 -1
  246. package/lib/rtp/src/extra/processor/rtpTime.js +2 -1
  247. package/lib/rtp/src/extra/processor/rtpTime.js.map +1 -1
  248. package/lib/rtp/src/extra/processor/rtpTimeCallback.d.ts +1 -11
  249. package/lib/rtp/src/extra/processor/webm.d.ts +27 -0
  250. package/lib/rtp/src/extra/processor/webm.js +57 -23
  251. package/lib/rtp/src/extra/processor/webm.js.map +1 -1
  252. package/lib/rtp/src/extra/processor/webmCallback.js +6 -1
  253. package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
  254. package/lib/rtp/src/extra/processor/webmStream.js.map +1 -1
  255. package/lib/rtp/src/helper.d.ts +2 -2
  256. package/lib/rtp/src/helper.js +2 -6
  257. package/lib/rtp/src/helper.js.map +1 -1
  258. package/lib/rtp/src/index.d.ts +10 -2
  259. package/lib/rtp/src/index.js +10 -2
  260. package/lib/rtp/src/index.js.map +1 -1
  261. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.d.ts +4 -0
  262. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js +6 -1
  263. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js.map +1 -1
  264. package/lib/rtp/src/rtcp/rtcp.js +9 -4
  265. package/lib/rtp/src/rtcp/rtcp.js.map +1 -1
  266. package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.d.ts +58 -0
  267. package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js +143 -0
  268. package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js.map +1 -0
  269. package/lib/rtp/src/rtcp/rtpfb/twcc.d.ts +35 -13
  270. package/lib/rtp/src/rtcp/rtpfb/twcc.js +132 -54
  271. package/lib/rtp/src/rtcp/rtpfb/twcc.js.map +1 -1
  272. package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.d.ts +13 -0
  273. package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js +29 -0
  274. package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js.map +1 -0
  275. package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.d.ts +41 -0
  276. package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js +89 -0
  277. package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js.map +1 -0
  278. package/lib/rtp/src/rtcp/sr.d.ts +4 -3
  279. package/lib/rtp/src/rtcp/sr.js +4 -2
  280. package/lib/rtp/src/rtcp/sr.js.map +1 -1
  281. package/lib/rtp/src/rtp/continuity.d.ts +36 -0
  282. package/lib/rtp/src/rtp/continuity.js +100 -0
  283. package/lib/rtp/src/rtp/continuity.js.map +1 -0
  284. package/lib/rtp/src/rtp/headerExtension.js +41 -21
  285. package/lib/rtp/src/rtp/headerExtension.js.map +1 -1
  286. package/lib/rtp/src/rtp/padding.d.ts +17 -0
  287. package/lib/rtp/src/rtp/padding.js +37 -0
  288. package/lib/rtp/src/rtp/padding.js.map +1 -0
  289. package/lib/rtp/src/rtp/red/encoder.d.ts +10 -0
  290. package/lib/rtp/src/rtp/red/encoder.js +14 -1
  291. package/lib/rtp/src/rtp/red/encoder.js.map +1 -1
  292. package/lib/rtp/src/rtp/red/packet.js +24 -8
  293. package/lib/rtp/src/rtp/red/packet.js.map +1 -1
  294. package/lib/rtp/src/rtp/rtp.d.ts +24 -1
  295. package/lib/rtp/src/rtp/rtp.js +70 -29
  296. package/lib/rtp/src/rtp/rtp.js.map +1 -1
  297. package/lib/rtp/src/rtp/rtx.js +3 -0
  298. package/lib/rtp/src/rtp/rtx.js.map +1 -1
  299. package/lib/rtp/src/rtp/sendHeaderExtensions.d.ts +36 -0
  300. package/lib/rtp/src/rtp/sendHeaderExtensions.js +85 -0
  301. package/lib/rtp/src/rtp/sendHeaderExtensions.js.map +1 -0
  302. package/lib/rtp/src/srtp/cipher/ctr.d.ts +2 -2
  303. package/lib/rtp/src/srtp/cipher/ctr.js +5 -3
  304. package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
  305. package/lib/rtp/src/srtp/cipher/gcm.d.ts +1 -1
  306. package/lib/rtp/src/srtp/cipher/gcm.js +1 -1
  307. package/lib/rtp/src/srtp/cipher/gcm.js.map +1 -1
  308. package/lib/rtp/src/srtp/cipher/index.js +8 -4
  309. package/lib/rtp/src/srtp/cipher/index.js.map +1 -1
  310. package/lib/rtp/src/srtp/context/context.d.ts +29 -1
  311. package/lib/rtp/src/srtp/context/context.js +84 -27
  312. package/lib/rtp/src/srtp/context/context.js.map +1 -1
  313. package/lib/rtp/src/srtp/context/srtcp.d.ts +1 -1
  314. package/lib/rtp/src/srtp/context/srtcp.js +33 -0
  315. package/lib/rtp/src/srtp/context/srtcp.js.map +1 -1
  316. package/lib/rtp/src/srtp/context/srtp.d.ts +1 -1
  317. package/lib/rtp/src/srtp/context/srtp.js +36 -4
  318. package/lib/rtp/src/srtp/context/srtp.js.map +1 -1
  319. package/lib/rtp/src/srtp/error.d.ts +8 -0
  320. package/lib/rtp/src/srtp/error.js +13 -1
  321. package/lib/rtp/src/srtp/error.js.map +1 -1
  322. package/lib/rtp/src/srtp/packet.js +4 -1
  323. package/lib/rtp/src/srtp/packet.js.map +1 -1
  324. package/lib/rtp/src/srtp/replay.d.ts +24 -0
  325. package/lib/rtp/src/srtp/replay.js +75 -0
  326. package/lib/rtp/src/srtp/replay.js.map +1 -0
  327. package/lib/rtp/src/srtp/session.js +2 -1
  328. package/lib/rtp/src/srtp/session.js.map +1 -1
  329. package/lib/rtp/src/srtp/srtcp.js +2 -1
  330. package/lib/rtp/src/srtp/srtcp.js.map +1 -1
  331. package/lib/rtp/src/srtp/srtp.js +2 -1
  332. package/lib/rtp/src/srtp/srtp.js.map +1 -1
  333. package/lib/rtp/src/util.js +2 -1
  334. package/lib/rtp/src/util.js.map +1 -1
  335. package/lib/sctp/src/chunk.d.ts +5 -0
  336. package/lib/sctp/src/chunk.js +31 -8
  337. package/lib/sctp/src/chunk.js.map +1 -1
  338. package/lib/sctp/src/const.d.ts +25 -17
  339. package/lib/sctp/src/const.js +23 -19
  340. package/lib/sctp/src/const.js.map +1 -1
  341. package/lib/sctp/src/index.d.ts +4 -3
  342. package/lib/sctp/src/index.js +10 -8
  343. package/lib/sctp/src/index.js.map +1 -1
  344. package/lib/sctp/src/param.d.ts +6 -2
  345. package/lib/sctp/src/param.js +22 -8
  346. package/lib/sctp/src/param.js.map +1 -1
  347. package/lib/sctp/src/sctp.d.ts +91 -2
  348. package/lib/sctp/src/sctp.js +700 -134
  349. package/lib/sctp/src/sctp.js.map +1 -1
  350. package/lib/sctp/src/transport.js +4 -2
  351. package/lib/sctp/src/transport.js.map +1 -1
  352. package/lib/webrtc/src/api/peerConfig.d.ts +307 -0
  353. package/lib/webrtc/src/api/peerConfig.js +291 -0
  354. package/lib/webrtc/src/api/peerConfig.js.map +1 -0
  355. package/lib/webrtc/src/api/peerConnectionEvents.d.ts +36 -0
  356. package/lib/webrtc/src/api/peerConnectionEvents.js +44 -0
  357. package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -0
  358. package/lib/webrtc/src/dataChannel.d.ts +11 -1
  359. package/lib/webrtc/src/dataChannel.js +25 -5
  360. package/lib/webrtc/src/dataChannel.js.map +1 -1
  361. package/lib/webrtc/src/index.d.ts +2 -2
  362. package/lib/webrtc/src/index.js +2 -2
  363. package/lib/webrtc/src/index.js.map +1 -1
  364. package/lib/webrtc/src/media/index.d.ts +11 -1
  365. package/lib/webrtc/src/media/index.js +71 -1
  366. package/lib/webrtc/src/media/index.js.map +1 -1
  367. package/lib/webrtc/src/media/receiver/nack.js +5 -5
  368. package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
  369. package/lib/webrtc/src/media/receiver/receiverTwcc.d.ts +61 -1
  370. package/lib/webrtc/src/media/receiver/receiverTwcc.js +218 -63
  371. package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
  372. package/lib/webrtc/src/media/router.d.ts +130 -6
  373. package/lib/webrtc/src/media/router.js +325 -29
  374. package/lib/webrtc/src/media/router.js.map +1 -1
  375. package/lib/webrtc/src/media/rtpReceiver.d.ts +137 -14
  376. package/lib/webrtc/src/media/rtpReceiver.js +420 -44
  377. package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
  378. package/lib/webrtc/src/media/rtpSender.d.ts +232 -65
  379. package/lib/webrtc/src/media/rtpSender.js +784 -448
  380. package/lib/webrtc/src/media/rtpSender.js.map +1 -1
  381. package/lib/webrtc/src/media/rtpTransceiver.d.ts +95 -4
  382. package/lib/webrtc/src/media/rtpTransceiver.js +121 -9
  383. package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
  384. package/lib/webrtc/src/media/sender/bandwidthEstimator.d.ts +249 -0
  385. package/lib/webrtc/src/media/sender/bandwidthEstimator.js +144 -0
  386. package/lib/webrtc/src/media/sender/bandwidthEstimator.js.map +1 -0
  387. package/lib/webrtc/src/media/sender/createBandwidthEstimator.d.ts +20 -0
  388. package/lib/webrtc/src/media/sender/createBandwidthEstimator.js +26 -0
  389. package/lib/webrtc/src/media/sender/createBandwidthEstimator.js.map +1 -0
  390. package/lib/webrtc/src/media/sender/estimatorBinding.d.ts +70 -0
  391. package/lib/webrtc/src/media/sender/estimatorBinding.js +175 -0
  392. package/lib/webrtc/src/media/sender/estimatorBinding.js.map +1 -0
  393. package/lib/webrtc/src/media/sender/estimators/disabledBwe.d.ts +18 -0
  394. package/lib/webrtc/src/media/sender/estimators/disabledBwe.js +44 -0
  395. package/lib/webrtc/src/media/sender/estimators/disabledBwe.js.map +1 -0
  396. package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.d.ts +79 -0
  397. package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.js +289 -0
  398. package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.js.map +1 -0
  399. package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.d.ts +87 -0
  400. package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.js +429 -0
  401. package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.js.map +1 -0
  402. package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.d.ts +21 -0
  403. package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.js +84 -0
  404. package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.js.map +1 -0
  405. package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.d.ts +37 -0
  406. package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.js +74 -0
  407. package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.js.map +1 -0
  408. package/lib/webrtc/src/media/sender/estimators/gcc/constants.d.ts +383 -0
  409. package/lib/webrtc/src/media/sender/estimators/gcc/constants.js +408 -0
  410. package/lib/webrtc/src/media/sender/estimators/gcc/constants.js.map +1 -0
  411. package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.d.ts +406 -0
  412. package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.js +1391 -0
  413. package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.js.map +1 -0
  414. package/lib/webrtc/src/media/sender/estimators/gcc/index.d.ts +19 -0
  415. package/lib/webrtc/src/media/sender/estimators/gcc/index.js +75 -0
  416. package/lib/webrtc/src/media/sender/estimators/gcc/index.js.map +1 -0
  417. package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.d.ts +68 -0
  418. package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.js +201 -0
  419. package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.js.map +1 -0
  420. package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.d.ts +26 -0
  421. package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.js +72 -0
  422. package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.js.map +1 -0
  423. package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.d.ts +41 -0
  424. package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.js +99 -0
  425. package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.js.map +1 -0
  426. package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.d.ts +247 -0
  427. package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.js +1042 -0
  428. package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.js.map +1 -0
  429. package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.d.ts +26 -0
  430. package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.js +132 -0
  431. package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.js.map +1 -0
  432. package/lib/webrtc/src/media/sender/estimators/gcc/probeController.d.ts +305 -0
  433. package/lib/webrtc/src/media/sender/estimators/gcc/probeController.js +1073 -0
  434. package/lib/webrtc/src/media/sender/estimators/gcc/probeController.js.map +1 -0
  435. package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.d.ts +60 -0
  436. package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.js +151 -0
  437. package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.js.map +1 -0
  438. package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.d.ts +44 -0
  439. package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.js +246 -0
  440. package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.js.map +1 -0
  441. package/lib/webrtc/src/media/sender/estimators/index.d.ts +7 -0
  442. package/lib/webrtc/src/media/sender/estimators/index.js +19 -0
  443. package/lib/webrtc/src/media/sender/estimators/index.js.map +1 -0
  444. package/lib/webrtc/src/media/sender/estimators/lightweightBwe.d.ts +64 -0
  445. package/lib/webrtc/src/media/sender/estimators/lightweightBwe.js +216 -0
  446. package/lib/webrtc/src/media/sender/estimators/lightweightBwe.js.map +1 -0
  447. package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.d.ts +117 -0
  448. package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.js +250 -0
  449. package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.js.map +1 -0
  450. package/lib/webrtc/src/media/sender/outgoingQueue.d.ts +40 -0
  451. package/lib/webrtc/src/media/sender/outgoingQueue.js +153 -0
  452. package/lib/webrtc/src/media/sender/outgoingQueue.js.map +1 -0
  453. package/lib/webrtc/src/media/sender/padding.d.ts +45 -0
  454. package/lib/webrtc/src/media/sender/padding.js +134 -0
  455. package/lib/webrtc/src/media/sender/padding.js.map +1 -0
  456. package/lib/webrtc/src/media/sender/pendingRtp.d.ts +35 -0
  457. package/lib/webrtc/src/media/sender/pendingRtp.js +120 -0
  458. package/lib/webrtc/src/media/sender/pendingRtp.js.map +1 -0
  459. package/lib/webrtc/src/media/sender/rtpWire.d.ts +13 -0
  460. package/lib/webrtc/src/media/sender/rtpWire.js +38 -0
  461. package/lib/webrtc/src/media/sender/rtpWire.js.map +1 -0
  462. package/lib/webrtc/src/media/sender/sendPacer.d.ts +27 -0
  463. package/lib/webrtc/src/media/sender/sendPacer.js +110 -0
  464. package/lib/webrtc/src/media/sender/sendPacer.js.map +1 -0
  465. package/lib/webrtc/src/media/sender/senderBWE.d.ts +8 -32
  466. package/lib/webrtc/src/media/sender/senderBWE.js +5 -142
  467. package/lib/webrtc/src/media/sender/senderBWE.js.map +1 -1
  468. package/lib/webrtc/src/media/sender/senderStats.d.ts +100 -0
  469. package/lib/webrtc/src/media/sender/senderStats.js +322 -0
  470. package/lib/webrtc/src/media/sender/senderStats.js.map +1 -0
  471. package/lib/webrtc/src/media/track.d.ts +21 -3
  472. package/lib/webrtc/src/media/track.js +24 -6
  473. package/lib/webrtc/src/media/track.js.map +1 -1
  474. package/lib/webrtc/src/negotiation/bundleTopology.d.ts +103 -0
  475. package/lib/webrtc/src/negotiation/bundleTopology.js +384 -0
  476. package/lib/webrtc/src/negotiation/bundleTopology.js.map +1 -0
  477. package/lib/webrtc/src/negotiation/descriptionValidation.d.ts +51 -0
  478. package/lib/webrtc/src/negotiation/descriptionValidation.js +267 -0
  479. package/lib/webrtc/src/negotiation/descriptionValidation.js.map +1 -0
  480. package/lib/webrtc/src/negotiation/iceRestartRequest.d.ts +21 -0
  481. package/lib/webrtc/src/negotiation/iceRestartRequest.js +61 -0
  482. package/lib/webrtc/src/negotiation/iceRestartRequest.js.map +1 -0
  483. package/lib/webrtc/src/negotiation/internalState.d.ts +34 -0
  484. package/lib/webrtc/src/negotiation/internalState.js +21 -0
  485. package/lib/webrtc/src/negotiation/internalState.js.map +1 -0
  486. package/lib/webrtc/src/negotiation/negotiationNeeded.d.ts +44 -0
  487. package/lib/webrtc/src/negotiation/negotiationNeeded.js +119 -0
  488. package/lib/webrtc/src/negotiation/negotiationNeeded.js.map +1 -0
  489. package/lib/webrtc/src/negotiation/remoteCandidates.d.ts +86 -0
  490. package/lib/webrtc/src/negotiation/remoteCandidates.js +349 -0
  491. package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -0
  492. package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +71 -0
  493. package/lib/webrtc/src/negotiation/remoteMediaApplication.js +414 -0
  494. package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -0
  495. package/lib/webrtc/src/negotiation/transportActivation.d.ts +59 -0
  496. package/lib/webrtc/src/negotiation/transportActivation.js +356 -0
  497. package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -0
  498. package/lib/webrtc/src/negotiationTransaction.d.ts +240 -0
  499. package/lib/webrtc/src/negotiationTransaction.js +604 -0
  500. package/lib/webrtc/src/negotiationTransaction.js.map +1 -0
  501. package/lib/webrtc/src/nonstandard/dummyMedia.js +2 -1
  502. package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
  503. package/lib/webrtc/src/nonstandard/index.d.ts +1 -1
  504. package/lib/webrtc/src/nonstandard/index.js +1 -1
  505. package/lib/webrtc/src/nonstandard/index.js.map +1 -1
  506. package/lib/webrtc/src/nonstandard/navigator.js +4 -3
  507. package/lib/webrtc/src/nonstandard/navigator.js.map +1 -1
  508. package/lib/webrtc/src/nonstandard/recorder/index.d.ts +32 -8
  509. package/lib/webrtc/src/nonstandard/recorder/index.js +81 -20
  510. package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
  511. package/lib/webrtc/src/nonstandard/recorder/writer/index.d.ts +10 -8
  512. package/lib/webrtc/src/nonstandard/recorder/writer/index.js +2 -1
  513. package/lib/webrtc/src/nonstandard/recorder/writer/index.js.map +1 -1
  514. package/lib/webrtc/src/nonstandard/recorder/writer/ogg.d.ts +32 -0
  515. package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js +185 -0
  516. package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js.map +1 -0
  517. package/lib/webrtc/src/nonstandard/recorder/writer/webm.d.ts +2 -2
  518. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +10 -3
  519. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
  520. package/lib/webrtc/src/nonstandard/userMedia/packetizer.d.ts +2 -2
  521. package/lib/webrtc/src/nonstandard/userMedia/packetizer.js.map +1 -1
  522. package/lib/webrtc/src/nonstandard/userMedia.d.ts +2 -2
  523. package/lib/webrtc/src/nonstandard/userMedia.js +4 -3
  524. package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
  525. package/lib/webrtc/src/peerConnection.d.ts +176 -238
  526. package/lib/webrtc/src/peerConnection.js +1042 -913
  527. package/lib/webrtc/src/peerConnection.js.map +1 -1
  528. package/lib/webrtc/src/polyfill/api.d.ts +5 -5
  529. package/lib/webrtc/src/polyfill/api.js.map +1 -1
  530. package/lib/webrtc/src/polyfill/index.js.map +1 -1
  531. package/lib/webrtc/src/polyfill/install.js +1 -1
  532. package/lib/webrtc/src/polyfill/install.js.map +1 -1
  533. package/lib/webrtc/src/polyfill/mediaDevices.js +2 -1
  534. package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
  535. package/lib/webrtc/src/polyfill/registers/mp4Webm.js.map +1 -1
  536. package/lib/webrtc/src/polyfill/registers/rtpRtcp.js.map +1 -1
  537. package/lib/webrtc/src/polyfill/selectSettings.js.map +1 -1
  538. package/lib/webrtc/src/polyfill/sourceIo.js.map +1 -1
  539. package/lib/webrtc/src/sctpManager.d.ts +97 -1
  540. package/lib/webrtc/src/sctpManager.js +189 -9
  541. package/lib/webrtc/src/sctpManager.js.map +1 -1
  542. package/lib/webrtc/src/sdp.js +12 -6
  543. package/lib/webrtc/src/sdp.js.map +1 -1
  544. package/lib/webrtc/src/sdpManager.d.ts +55 -11
  545. package/lib/webrtc/src/sdpManager.js +364 -87
  546. package/lib/webrtc/src/sdpManager.js.map +1 -1
  547. package/lib/webrtc/src/secureTransportManager.d.ts +89 -28
  548. package/lib/webrtc/src/secureTransportManager.js +232 -53
  549. package/lib/webrtc/src/secureTransportManager.js.map +1 -1
  550. package/lib/webrtc/src/transceiverManager.d.ts +62 -18
  551. package/lib/webrtc/src/transceiverManager.js +272 -107
  552. package/lib/webrtc/src/transceiverManager.js.map +1 -1
  553. package/lib/webrtc/src/transport/dtls.d.ts +64 -3
  554. package/lib/webrtc/src/transport/dtls.js +166 -42
  555. package/lib/webrtc/src/transport/dtls.js.map +1 -1
  556. package/lib/webrtc/src/transport/ice.d.ts +199 -28
  557. package/lib/webrtc/src/transport/ice.js +666 -71
  558. package/lib/webrtc/src/transport/ice.js.map +1 -1
  559. package/lib/webrtc/src/transport/iceCandidateAttribute.d.ts +98 -0
  560. package/lib/webrtc/src/transport/iceCandidateAttribute.js +129 -0
  561. package/lib/webrtc/src/transport/iceCandidateAttribute.js.map +1 -0
  562. package/lib/webrtc/src/transport/sctp.d.ts +6 -1
  563. package/lib/webrtc/src/transport/sctp.js +149 -37
  564. package/lib/webrtc/src/transport/sctp.js.map +1 -1
  565. package/lib/webrtc/src/utils.d.ts +39 -6
  566. package/lib/webrtc/src/utils.js +57 -17
  567. package/lib/webrtc/src/utils.js.map +1 -1
  568. package/package.json +16 -15
@@ -16,7 +16,17 @@ export interface IceConnection {
16
16
  localCandidates: Candidate[];
17
17
  remoteCandidates: Candidate[];
18
18
  candidatePairs: CandidatePair[];
19
+ /**
20
+ * STUN servers gathering queries, normalized from the options (see
21
+ * {@link normalizeIceServerOptions}). Optional so that other
22
+ * implementations of this interface keep compiling.
23
+ */
24
+ stunServers?: Address[];
25
+ /** TURN servers gathering allocates on, each with its own credential. */
26
+ turnServers?: TurnServerOptions[];
27
+ /** @deprecated The first of {@link IceConnection.stunServers}. */
19
28
  stunServer?: Address;
29
+ /** @deprecated The address of the first of {@link IceConnection.turnServers}. */
20
30
  turnServer?: Address;
21
31
  generation: number;
22
32
  options: IceOptions;
@@ -29,19 +39,54 @@ export interface IceConnection {
29
39
  readonly stateChanged: Event<[IceState]>;
30
40
  readonly onIceCandidate: Event<[Candidate]>;
31
41
  restart(): void;
42
+ /**
43
+ * Optional staged-restart and provisional-generation support. An
44
+ * implementation without them still restarts ICE at the final answer, but
45
+ * cannot answer or run checks for the new generation during pranswer.
46
+ */
47
+ /**
48
+ * `gatherOptions`: the options the staged generation gathers with (an ICE
49
+ * server update applied at the commit); its provisional checks use only
50
+ * the sockets those options allow. Defaults to the current options.
51
+ */
52
+ stageLocalCredentials?(usernameFragment: string, password: string, gatherOptions?: Partial<IceOptions>): void;
53
+ discardStagedLocalCredentials?(usernameFragment: string): void;
54
+ commitLocalCredentials?(usernameFragment: string, password: string): void;
55
+ /**
56
+ * The remote side alone restarted (new remote credentials in an answer):
57
+ * drop the remote generation and its checks, keep the local credentials
58
+ * and gathered candidates.
59
+ */
60
+ restartRemote?(): void;
61
+ setProvisionalRemoteParams?(params: {
62
+ usernameFragment: string;
63
+ password: string;
64
+ }): void;
65
+ addProvisionalRemoteCandidate?(candidate: Candidate | undefined): Promise<void>;
66
+ startProvisionalChecks?(): void;
67
+ readonly provisionalNominated?: CandidatePair;
32
68
  setIceServers(options: Partial<IceOptions>): void;
33
69
  setRemoteParams(params: {
34
70
  iceLite: boolean;
35
71
  usernameFragment: string;
36
72
  password: string;
37
73
  }): void;
74
+ /**
75
+ * Gather the current generation's candidates. After an ICE restart the
76
+ * candidates the kept sockets advertised are re-advertised synchronously;
77
+ * only server work (STUN, TURN) is awaited.
78
+ */
38
79
  gatherCandidates(): Promise<void>;
80
+ /** Whether gathering contacts a STUN or TURN server. */
81
+ readonly gathersFromServers?: boolean;
39
82
  connect(): Promise<void>;
40
83
  close(): Promise<void>;
41
84
  addRemoteCandidate(remoteCandidate: Candidate | undefined): Promise<void>;
42
85
  send(data: Buffer): Promise<void>;
43
86
  getDefaultCandidate(): Candidate | undefined;
44
87
  resetNominatedPair(): void;
88
+ /** Drop remote candidates and pairs that name another remote ufrag. */
89
+ dropOtherRemoteGenerations?(usernameFragment: string): void;
45
90
  }
46
91
  export interface CandidatePairStats {
47
92
  packetsSent: number;
@@ -128,14 +173,26 @@ export declare const CONSENT_RESPONSE_TIMEOUT_MIN = 500;
128
173
  * Falls back to {@link CONSENT_RESPONSE_TIMEOUT} when RTT is unavailable.
129
174
  */
130
175
  export declare function consentResponseTimeoutMs(rttSeconds?: number): number;
131
- export declare enum CandidatePairState {
132
- FROZEN = 0,
133
- WAITING = 1,
134
- IN_PROGRESS = 2,
135
- SUCCEEDED = 3,
136
- FAILED = 4
137
- }
176
+ /**
177
+ * @enum
178
+ */
179
+ export declare const CandidatePairState: {
180
+ readonly FROZEN: 0;
181
+ readonly WAITING: 1;
182
+ readonly IN_PROGRESS: 2;
183
+ readonly SUCCEEDED: 3;
184
+ readonly FAILED: 4;
185
+ };
186
+ export type CandidatePairState = (typeof CandidatePairState)[keyof typeof CandidatePairState];
138
187
  export type IceState = "disconnected" | "closed" | "completed" | "new" | "connected" | "failed";
188
+ /** A TURN server and the credential and transport used for it. */
189
+ export type TurnServerOptions = {
190
+ address: Address;
191
+ username: string;
192
+ password: string;
193
+ /** Defaults to "udp" (with a TCP fallback when the UDP allocation fails). */
194
+ transport?: "udp" | "tcp" | "tls";
195
+ };
139
196
  export interface IceOptions {
140
197
  /** Advertise and operate as an ICE lite agent. */
141
198
  iceLite: boolean;
@@ -159,16 +216,54 @@ export interface IceOptions {
159
216
  * Defaults to 8.
160
217
  */
161
218
  turnConnectTimeout?: number;
219
+ /**
220
+ * STUN servers queried while gathering, in priority order. Every IPv4 UDP
221
+ * host socket queries each of them in parallel; equal mappings are
222
+ * advertised once, different ones (a NAT that maps per destination) each.
223
+ * Gathering ends when the slowest server answers or `stunGatherTimeout`
224
+ * runs out.
225
+ *
226
+ * Merged with the deprecated `stunServer`: the singular one comes first,
227
+ * duplicates are dropped (see {@link normalizeIceServerOptions}).
228
+ */
229
+ stunServers?: Address[];
230
+ /**
231
+ * TURN servers allocated on while gathering, in priority order. Each one
232
+ * gets its own allocation with its own credential and transport; one that
233
+ * fails or times out does not stop the others. Gathering ends when the
234
+ * slowest allocation completes or fails (`turnConnectTimeout` bounds a
235
+ * TCP/TLS connection, the STUN transaction timeout an unanswered request).
236
+ * `turnTlsOptions`, `turnUdpFamily`, `turnConnectTimeout`, `portRange` and
237
+ * `interfaceAddresses` apply to every TURN server.
238
+ *
239
+ * Merged with the deprecated `turnServer` / `turnUsername` /
240
+ * `turnPassword` / `turnTransport`: the singular one comes first,
241
+ * duplicates are dropped and an entry without username / password is
242
+ * ignored (see {@link normalizeIceServerOptions}).
243
+ */
244
+ turnServers?: TurnServerOptions[];
245
+ /** @deprecated Use {@link IceOptions.stunServers}. Kept as their first entry. */
162
246
  stunServer?: Address;
247
+ /**
248
+ * Whether the built-in public STUN server (stun.l.google.com:19302) is used
249
+ * when no STUN server is given. Defaults to true; false gathers no
250
+ * server-reflexive candidate unless a STUN server is set.
251
+ */
252
+ useDefaultStunServer?: boolean;
253
+ /** @deprecated Use {@link IceOptions.turnServers}. Kept as their first entry. */
163
254
  turnServer?: Address;
255
+ /** @deprecated Use {@link TurnServerOptions.username} of {@link IceOptions.turnServers}. */
164
256
  turnUsername?: string;
257
+ /** @deprecated Use {@link TurnServerOptions.password} of {@link IceOptions.turnServers}. */
165
258
  turnPassword?: string;
259
+ /** @deprecated Use {@link TurnServerOptions.transport} of {@link IceOptions.turnServers}. */
166
260
  turnTransport?: "udp" | "tcp" | "tls";
261
+ /** Applied to every TLS TURN server. */
167
262
  turnTlsOptions?: TlsConnectionOptions;
168
263
  /**
169
- * Preferred IP family of the TURN/UDP socket, applied only when turnServer
170
- * is a hostname. Ignored for an IP literal turnServer, whose own family
171
- * always selects the socket. Defaults to 4.
264
+ * Preferred IP family of a TURN/UDP socket, applied (to every TURN server)
265
+ * only when the server is a hostname. Ignored for an IP literal server,
266
+ * whose own family always selects the socket. Defaults to 4.
172
267
  */
173
268
  turnUdpFamily?: 4 | 6;
174
269
  forceTurn?: boolean;
@@ -177,7 +272,26 @@ export interface IceOptions {
177
272
  useIpv6: boolean;
178
273
  useLinkLocalAddress?: boolean;
179
274
  portRange?: [number, number];
275
+ /**
276
+ * Local addresses to bind the UDP host sockets to, per family.
277
+ *
278
+ * The address given for a family (`udp4` / `udp6`) is the only host
279
+ * address of that family: its UDP host candidate advertises the address and
280
+ * port the socket is actually bound to, even when the address is not among
281
+ * the enumerated network interfaces (loopback, tun, ...), and its TCP host
282
+ * candidates use it too. Other enumerated addresses of that family are not
283
+ * gathered. If the bind fails, the family has no UDP host candidate.
284
+ *
285
+ * A family left unspecified while the other one is set gathers no
286
+ * enumerated addresses (only its `additionalHostAddresses`). Without any
287
+ * family set, every enumerated address is gathered over wildcard sockets.
288
+ */
180
289
  interfaceAddresses?: InterfaceAddresses;
290
+ /**
291
+ * Host addresses gathered in addition to the enumerated ones. For a family
292
+ * bound by `interfaceAddresses`, addresses other than the bound one are
293
+ * ignored.
294
+ */
181
295
  additionalHostAddresses?: string[];
182
296
  filterStunResponse?: (message: Message, addr: Address, protocol: Protocol) => boolean;
183
297
  filterCandidatePair?: (pair: CandidatePair) => boolean;
@@ -194,3 +308,53 @@ export declare function sortCandidatePairs(pairs: {
194
308
  export declare function candidatePairPriority(local: Pick<Candidate, "priority">, remote: Pick<Candidate, "priority">, iceControlling: boolean): number;
195
309
  export declare function serverReflexiveCandidate(protocol: Protocol, stunServer: Address): Promise<Candidate | undefined>;
196
310
  export declare function validateAddress(addr?: Address): Address | undefined;
311
+ /** The STUN/TURN server fields of {@link IceOptions}, singular and plural. */
312
+ export type IceServerFields = Partial<Pick<IceOptions, "stunServer" | "stunServers" | "turnServer" | "turnServers" | "turnUsername" | "turnPassword" | "turnTransport">>;
313
+ /**
314
+ * The STUN and TURN servers `options` configure, the one place the singular
315
+ * (deprecated) and plural fields are merged:
316
+ *
317
+ * - order: the singular server first, then the plural list in its order;
318
+ * - duplicates (the same STUN address; the same TURN address, transport and
319
+ * credential) are kept once, at their first position;
320
+ * - an invalid address (see {@link validateAddress}) is dropped, and so is a
321
+ * TURN server without username or password (it cannot allocate);
322
+ * - a TURN transport left unset is "udp".
323
+ *
324
+ * The built-in default STUN server is not added here; Connection falls back
325
+ * to it when the result has no STUN server.
326
+ */
327
+ export declare function normalizeIceServerOptions(options: IceServerFields): {
328
+ stunServers: Address[];
329
+ turnServers: Required<TurnServerOptions>[];
330
+ };
331
+ /**
332
+ * `current` with an ICE server update applied (Connection.setIceServers): the
333
+ * STUN/TURN fields, singular and plural, are replaced, an undefined one
334
+ * included, so a STUN-only update cannot leave a previous TURN
335
+ * host/credential behind; forceTurn and useTcp change only when given.
336
+ */
337
+ export declare function mergeIceServerOptions<T extends Partial<IceOptions>>(current: T, update: Partial<IceOptions>): T;
338
+ /**
339
+ * Whether a generation gathered with `options` is relay-only: forceTurn (the
340
+ * "relay" ICE transport policy). The policy holds whatever the TURN settings
341
+ * are: without a usable TURN server / credential (or for an ICE-lite agent,
342
+ * which gathers no relay candidate) the generation has no candidate at all
343
+ * rather than falling back to host / server-reflexive ones, so the local and
344
+ * public addresses are neither advertised nor used for checks.
345
+ */
346
+ export declare function isRelayOnlyGathering(options: Pick<IceOptions, "forceTurn">): boolean;
347
+ /**
348
+ * Whether `options` carry at least one usable TURN server with its
349
+ * credential, the ones a gathering with them allocates relay candidates from.
350
+ */
351
+ export declare function hasTurnServer(options: IceServerFields): boolean;
352
+ /**
353
+ * Whether `candidate`, kept from an earlier generation (an ICE restart keeps
354
+ * the sockets), may be advertised and paired in a generation gathered with
355
+ * `options`. A fresh gathering with the same options would not have produced
356
+ * a host / server-reflexive candidate for a relay-only policy, a TCP host
357
+ * candidate without useTcp, nor a relay candidate without a TURN server;
358
+ * the kept ones are held back the same way.
359
+ */
360
+ export declare function isCandidateAllowedByGatherOptions(candidate: Pick<Candidate, "type" | "transport">, options: Pick<IceOptions, "forceTurn"> & Partial<Pick<IceOptions, "useTcp">> & IceServerFields): boolean;
@@ -7,6 +7,11 @@ exports.sortCandidatePairs = sortCandidatePairs;
7
7
  exports.candidatePairPriority = candidatePairPriority;
8
8
  exports.serverReflexiveCandidate = serverReflexiveCandidate;
9
9
  exports.validateAddress = validateAddress;
10
+ exports.normalizeIceServerOptions = normalizeIceServerOptions;
11
+ exports.mergeIceServerOptions = mergeIceServerOptions;
12
+ exports.isRelayOnlyGathering = isRelayOnlyGathering;
13
+ exports.hasTurnServer = hasTurnServer;
14
+ exports.isCandidateAllowedByGatherOptions = isCandidateAllowedByGatherOptions;
10
15
  const crypto_1 = require("crypto");
11
16
  const candidate_1 = require("./candidate");
12
17
  const common_1 = require("./imports/common");
@@ -32,19 +37,19 @@ class CandidatePair {
32
37
  enumerable: true,
33
38
  configurable: true,
34
39
  writable: true,
35
- value: protocol
40
+ value: void 0
36
41
  });
37
42
  Object.defineProperty(this, "remoteCandidate", {
38
43
  enumerable: true,
39
44
  configurable: true,
40
45
  writable: true,
41
- value: remoteCandidate
46
+ value: void 0
42
47
  });
43
48
  Object.defineProperty(this, "iceControlling", {
44
49
  enumerable: true,
45
50
  configurable: true,
46
51
  writable: true,
47
- value: iceControlling
52
+ value: void 0
48
53
  });
49
54
  Object.defineProperty(this, "id", {
50
55
  enumerable: true,
@@ -75,7 +80,7 @@ class CandidatePair {
75
80
  enumerable: true,
76
81
  configurable: true,
77
82
  writable: true,
78
- value: CandidatePairState.FROZEN
83
+ value: exports.CandidatePairState.FROZEN
79
84
  });
80
85
  // Statistics tracking
81
86
  Object.defineProperty(this, "packetsSent", {
@@ -168,6 +173,9 @@ class CandidatePair {
168
173
  writable: true,
169
174
  value: new Set()
170
175
  });
176
+ this.protocol = protocol;
177
+ this.remoteCandidate = remoteCandidate;
178
+ this.iceControlling = iceControlling;
171
179
  }
172
180
  updateState(state) {
173
181
  this._state = state;
@@ -233,14 +241,16 @@ function consentResponseTimeoutMs(rttSeconds) {
233
241
  }
234
242
  return Math.max(exports.CONSENT_RESPONSE_TIMEOUT_MIN, Math.round(rttSeconds * 1000 * 2 + 200));
235
243
  }
236
- var CandidatePairState;
237
- (function (CandidatePairState) {
238
- CandidatePairState[CandidatePairState["FROZEN"] = 0] = "FROZEN";
239
- CandidatePairState[CandidatePairState["WAITING"] = 1] = "WAITING";
240
- CandidatePairState[CandidatePairState["IN_PROGRESS"] = 2] = "IN_PROGRESS";
241
- CandidatePairState[CandidatePairState["SUCCEEDED"] = 3] = "SUCCEEDED";
242
- CandidatePairState[CandidatePairState["FAILED"] = 4] = "FAILED";
243
- })(CandidatePairState || (exports.CandidatePairState = CandidatePairState = {}));
244
+ /**
245
+ * @enum
246
+ */
247
+ exports.CandidatePairState = {
248
+ FROZEN: 0,
249
+ WAITING: 1,
250
+ IN_PROGRESS: 2,
251
+ SUCCEEDED: 3,
252
+ FAILED: 4,
253
+ };
244
254
  exports.defaultOptions = {
245
255
  iceLite: false,
246
256
  useTcp: false,
@@ -297,4 +307,147 @@ function validateAddress(addr) {
297
307
  }
298
308
  return addr;
299
309
  }
310
+ /** A STUN/TURN server address: validated (see {@link validateAddress}) or undefined. */
311
+ function validServerAddress(addr) {
312
+ if (!Array.isArray(addr))
313
+ return undefined;
314
+ const validated = validateAddress(addr);
315
+ if (!validated)
316
+ return undefined;
317
+ const [host, port] = validated;
318
+ if (typeof host !== "string" || host === "")
319
+ return undefined;
320
+ if (typeof port !== "number" || !Number.isFinite(port))
321
+ return undefined;
322
+ return validated;
323
+ }
324
+ const sameAddress = (a, b) => a[0] === b[0] && a[1] === b[1];
325
+ /**
326
+ * The STUN and TURN servers `options` configure, the one place the singular
327
+ * (deprecated) and plural fields are merged:
328
+ *
329
+ * - order: the singular server first, then the plural list in its order;
330
+ * - duplicates (the same STUN address; the same TURN address, transport and
331
+ * credential) are kept once, at their first position;
332
+ * - an invalid address (see {@link validateAddress}) is dropped, and so is a
333
+ * TURN server without username or password (it cannot allocate);
334
+ * - a TURN transport left unset is "udp".
335
+ *
336
+ * The built-in default STUN server is not added here; Connection falls back
337
+ * to it when the result has no STUN server.
338
+ */
339
+ function normalizeIceServerOptions(options) {
340
+ const stunServers = [];
341
+ for (const server of [options.stunServer, ...(options.stunServers ?? [])]) {
342
+ if (server === undefined)
343
+ continue;
344
+ const address = validServerAddress(server);
345
+ if (!address) {
346
+ log("invalid STUN server ignored", server);
347
+ continue;
348
+ }
349
+ if (stunServers.some((existing) => sameAddress(existing, address))) {
350
+ continue;
351
+ }
352
+ stunServers.push(address);
353
+ }
354
+ const turnServers = [];
355
+ const configured = [
356
+ ...(options.turnServer !== undefined
357
+ ? [
358
+ {
359
+ address: options.turnServer,
360
+ username: options.turnUsername,
361
+ password: options.turnPassword,
362
+ transport: options.turnTransport,
363
+ },
364
+ ]
365
+ : []),
366
+ ...(options.turnServers ?? []),
367
+ ];
368
+ for (const server of configured) {
369
+ const address = validServerAddress(server?.address);
370
+ if (!address) {
371
+ log("invalid TURN server ignored", server?.address);
372
+ continue;
373
+ }
374
+ const { username, password } = server;
375
+ if (!username || !password) {
376
+ log("TURN server without username / credential ignored", address);
377
+ continue;
378
+ }
379
+ const entry = {
380
+ address,
381
+ username,
382
+ password,
383
+ transport: server.transport ?? "udp",
384
+ };
385
+ if (turnServers.some((existing) => sameAddress(existing.address, entry.address) &&
386
+ existing.transport === entry.transport &&
387
+ existing.username === entry.username &&
388
+ existing.password === entry.password)) {
389
+ continue;
390
+ }
391
+ turnServers.push(entry);
392
+ }
393
+ return { stunServers, turnServers };
394
+ }
395
+ /**
396
+ * `current` with an ICE server update applied (Connection.setIceServers): the
397
+ * STUN/TURN fields, singular and plural, are replaced, an undefined one
398
+ * included, so a STUN-only update cannot leave a previous TURN
399
+ * host/credential behind; forceTurn and useTcp change only when given.
400
+ */
401
+ function mergeIceServerOptions(current, update) {
402
+ return {
403
+ ...current,
404
+ stunServer: update.stunServer,
405
+ stunServers: update.stunServers,
406
+ turnServer: update.turnServer,
407
+ turnServers: update.turnServers,
408
+ turnUsername: update.turnUsername,
409
+ turnPassword: update.turnPassword,
410
+ turnTransport: update.turnTransport,
411
+ turnTlsOptions: update.turnTlsOptions,
412
+ turnUdpFamily: update.turnUdpFamily,
413
+ forceTurn: update.forceTurn ?? current.forceTurn,
414
+ useTcp: update.useTcp ?? current.useTcp,
415
+ };
416
+ }
417
+ /**
418
+ * Whether a generation gathered with `options` is relay-only: forceTurn (the
419
+ * "relay" ICE transport policy). The policy holds whatever the TURN settings
420
+ * are: without a usable TURN server / credential (or for an ICE-lite agent,
421
+ * which gathers no relay candidate) the generation has no candidate at all
422
+ * rather than falling back to host / server-reflexive ones, so the local and
423
+ * public addresses are neither advertised nor used for checks.
424
+ */
425
+ function isRelayOnlyGathering(options) {
426
+ return !!options.forceTurn;
427
+ }
428
+ /**
429
+ * Whether `options` carry at least one usable TURN server with its
430
+ * credential, the ones a gathering with them allocates relay candidates from.
431
+ */
432
+ function hasTurnServer(options) {
433
+ return normalizeIceServerOptions(options).turnServers.length > 0;
434
+ }
435
+ /**
436
+ * Whether `candidate`, kept from an earlier generation (an ICE restart keeps
437
+ * the sockets), may be advertised and paired in a generation gathered with
438
+ * `options`. A fresh gathering with the same options would not have produced
439
+ * a host / server-reflexive candidate for a relay-only policy, a TCP host
440
+ * candidate without useTcp, nor a relay candidate without a TURN server;
441
+ * the kept ones are held back the same way.
442
+ */
443
+ function isCandidateAllowedByGatherOptions(candidate, options) {
444
+ if (candidate.type === "relay")
445
+ return hasTurnServer(options);
446
+ if (isRelayOnlyGathering(options))
447
+ return false;
448
+ if (candidate.transport.toLowerCase() === "tcp" && !options.useTcp) {
449
+ return false;
450
+ }
451
+ return true;
452
+ }
300
453
  //# sourceMappingURL=iceBase.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"iceBase.js","sourceRoot":"","sources":["../../../../ice/src/iceBase.ts"],"names":[],"mappings":";;;AA0MA,4DAYC;AA4ED,0DASC;AAED,gDAsBC;AAGD,sDAQC;AAED,4DA0CC;AAED,0CAKC;AAjYD,mCAAoC;AACpC,2CAAgF;AAGhF,6CAM0B;AAC1B,wCAAgD;AAChD,4CAAyC;AAGzC,MAAM,GAAG,GAAG,IAAA,cAAK,EAAC,4CAA4C,CAAC,CAAC;AAqEhE,MAAa,aAAa;IAOxB,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAmBD,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,IAAI;QACN,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;YAC5B,cAAc,EAAE,IAAI,CAAC,cA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D,QAAQ,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,EACnD,OAAO,EACP,cAAc,CAAC,IAAI,EACnB,cAAc,CAAC,IAAI,EACnB,cAAc,CAAC,OAAO,CACvB,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,WAAW;QACX,GAAG,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC;AAED,SAAgB,eAAe,CAAC,IAAc;IAC5C,IAAI,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAClC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { randomUUID } from \"crypto\";\nimport { Candidate, candidateFoundation, candidatePriority } from \"./candidate\";\nimport type { MdnsLookup } from \"./dns/lookup\";\nimport type { Cancelable } from \"./helper\";\nimport {\n type Address,\n type Event,\n type InterfaceAddresses,\n type TlsConnectionOptions,\n debug,\n} from \"./imports/common\";\nimport { classes, methods } from \"./stun/const\";\nimport { Message } from \"./stun/message\";\nimport type { Protocol } from \"./types/model\";\n\nconst log = debug(\"werift-ice : packages/ice/src/ice.ts : log\");\n\nexport interface IceConnection {\n iceLite: boolean;\n iceControlling: boolean;\n localUsername: string;\n localPassword: string;\n remotePassword: string;\n remoteUsername: string;\n remoteIsLite: boolean;\n checkList: CandidatePair[];\n localCandidates: Candidate[];\n remoteCandidates: Candidate[];\n candidatePairs: CandidatePair[];\n stunServer?: Address;\n turnServer?: Address;\n generation: number;\n options: IceOptions;\n remoteCandidatesEnd: boolean;\n localCandidatesEnd: boolean;\n state: IceState;\n lookup?: MdnsLookup;\n nominated?: CandidatePair;\n\n readonly onData: Event<[Buffer]>;\n readonly stateChanged: Event<[IceState]>;\n readonly onIceCandidate: Event<[Candidate]>;\n\n restart(): void;\n\n setIceServers(options: Partial<IceOptions>): void;\n\n setRemoteParams(params: {\n iceLite: boolean;\n usernameFragment: string;\n password: string;\n }): void;\n\n gatherCandidates(): Promise<void>;\n\n connect(): Promise<void>;\n\n close(): Promise<void>;\n\n addRemoteCandidate(remoteCandidate: Candidate | undefined): Promise<void>;\n\n send(data: Buffer): Promise<void>;\n\n getDefaultCandidate(): Candidate | undefined;\n resetNominatedPair(): void;\n}\n\nexport interface CandidatePairStats {\n packetsSent: number;\n packetsReceived: number;\n bytesSent: number;\n bytesReceived: number;\n rtt?: number;\n totalRoundTripTime: number;\n roundTripTimeMeasurements: number;\n requestsReceived: number;\n requestsSent: number;\n responsesReceived: number;\n responsesSent: number;\n retransmissionsReceived: number;\n retransmissionsSent: number;\n consentRequestsSent: number;\n}\n\nexport class CandidatePair implements CandidatePairStats {\n readonly id = randomUUID().toString();\n handle?: Cancelable<void>;\n nominated = false;\n remoteNominated = false;\n // 5.7.4. Computing States\n private _state = CandidatePairState.FROZEN;\n get state() {\n return this._state;\n }\n\n // Statistics tracking\n packetsSent = 0;\n packetsReceived = 0;\n bytesSent = 0;\n bytesReceived = 0;\n rtt?: number;\n totalRoundTripTime = 0;\n roundTripTimeMeasurements = 0;\n requestsReceived = 0;\n requestsSent = 0;\n responsesReceived = 0;\n responsesSent = 0;\n retransmissionsReceived = 0;\n retransmissionsSent = 0;\n consentRequestsSent = 0;\n private readonly requestTransactionIds = new Set<string>();\n\n toJSON() {\n return this.json;\n }\n\n get json() {\n return {\n protocol: this.protocol.type,\n localCandidate: this.localCandidate.toSdp(),\n remoteCandidate: this.remoteCandidate.toSdp(),\n };\n }\n\n constructor(\n public protocol: Protocol,\n public remoteCandidate: Candidate,\n public iceControlling: boolean,\n ) {}\n\n updateState(state: CandidatePairState) {\n this._state = state;\n }\n\n get localCandidate() {\n if (!this.protocol.localCandidate) {\n throw new Error(\"localCandidate not exist\");\n }\n return this.protocol.localCandidate;\n }\n\n get remoteAddr(): Address {\n return [this.remoteCandidate.host, this.remoteCandidate.port];\n }\n\n get component() {\n return this.localCandidate.component;\n }\n\n get priority() {\n return candidatePairPriority(\n this.localCandidate,\n this.remoteCandidate,\n this.iceControlling,\n );\n }\n\n get foundation() {\n return this.localCandidate.foundation;\n }\n\n noteIncomingRequest(transactionId: string) {\n const isRetransmission = this.requestTransactionIds.has(transactionId);\n if (!isRetransmission) {\n this.requestTransactionIds.add(transactionId);\n return false;\n }\n this.retransmissionsReceived++;\n return true;\n }\n}\n\nexport const ICE_COMPLETED = 1 as const;\nexport const ICE_FAILED = 2 as const;\n\n/** Basic consent check period in seconds (RFC 7675). Actual interval is 0.8–1.2× this. */\nexport const CONSENT_INTERVAL = 5;\n\n/**\n * @deprecated Consent expiry is based on {@link CONSENT_TIMEOUT} (30s after the\n * last valid response), not a consecutive failure count. Kept for API compatibility.\n */\nexport const CONSENT_FAILURES = 6;\n\n/** RFC 7675: consent expires this many seconds after the last valid response. */\nexport const CONSENT_TIMEOUT = 30;\n\n/**\n * Default single-shot response wait for consent requests (ms) when RTT is unknown.\n * Independent of retransmission count. Downstream ICE-lite peers typically\n * answer in 150–300ms; 1s is a conservative default used by interop patches.\n */\nexport const CONSENT_RESPONSE_TIMEOUT = 1000;\n\n/** RFC 8445 §14.3: ICE RTO must not be less than 500ms. */\nexport const CONSENT_RESPONSE_TIMEOUT_MIN = 500;\n\n/**\n * Compute consent response wait from pair RTT (seconds).\n * Uses 2×RTT + 200ms jitter margin, floored at {@link CONSENT_RESPONSE_TIMEOUT_MIN}.\n * Falls back to {@link CONSENT_RESPONSE_TIMEOUT} when RTT is unavailable.\n */\nexport function consentResponseTimeoutMs(rttSeconds?: number): number {\n if (\n rttSeconds === undefined ||\n !Number.isFinite(rttSeconds) ||\n rttSeconds <= 0\n ) {\n return CONSENT_RESPONSE_TIMEOUT;\n }\n return Math.max(\n CONSENT_RESPONSE_TIMEOUT_MIN,\n Math.round(rttSeconds * 1000 * 2 + 200),\n );\n}\n\nexport enum CandidatePairState {\n FROZEN = 0,\n WAITING = 1,\n IN_PROGRESS = 2,\n SUCCEEDED = 3,\n FAILED = 4,\n}\n\nexport type IceState =\n | \"disconnected\"\n | \"closed\"\n | \"completed\"\n | \"new\"\n | \"connected\"\n | \"failed\";\n\nexport interface IceOptions {\n /** Advertise and operate as an ICE lite agent. */\n iceLite: boolean;\n useTcp: boolean;\n /**\n * Gather passive TCP host candidates (opens a listening TCP server per\n * interface). Defaults to true. Send-only agents that never accept inbound\n * connections can set this false to avoid the listener while still gathering\n * active TCP candidates.\n */\n tcpPassive?: boolean;\n /**\n * Seconds to wait for server-reflexive candidates while gathering.\n * Defaults to 5. Where UDP is blocked these STUN queries are never answered,\n * so the wait always runs to the timeout; agents that must not stall on such\n * networks can lower it.\n */\n stunGatherTimeout?: number;\n /**\n * Seconds to wait for a TURN TCP/TLS connection to be established.\n * Defaults to 8.\n */\n turnConnectTimeout?: number;\n stunServer?: Address;\n turnServer?: Address;\n turnUsername?: string;\n turnPassword?: string;\n turnTransport?: \"udp\" | \"tcp\" | \"tls\";\n turnTlsOptions?: TlsConnectionOptions;\n /**\n * Preferred IP family of the TURN/UDP socket, applied only when turnServer\n * is a hostname. Ignored for an IP literal turnServer, whose own family\n * always selects the socket. Defaults to 4.\n */\n turnUdpFamily?: 4 | 6;\n forceTurn?: boolean;\n localPasswordPrefix?: string;\n useIpv4: boolean;\n useIpv6: boolean;\n useLinkLocalAddress?: boolean;\n portRange?: [number, number];\n interfaceAddresses?: InterfaceAddresses;\n additionalHostAddresses?: string[];\n filterStunResponse?: (\n message: Message,\n addr: Address,\n protocol: Protocol,\n ) => boolean;\n filterCandidatePair?: (pair: CandidatePair) => boolean;\n}\n\nexport const defaultOptions: IceOptions = {\n iceLite: false,\n useTcp: false,\n useIpv4: true,\n useIpv6: true,\n};\n\nexport function validateRemoteCandidate(candidate: Candidate) {\n // \"\"\"\n // Check the remote candidate is supported.\n // \"\"\"\n if (![\"host\", \"relay\", \"srflx\"].includes(candidate.type))\n throw new Error(`Unexpected candidate type \"${candidate.type}\"`);\n\n // ipaddress.ip_address(candidate.host)\n return candidate;\n}\n\nexport function sortCandidatePairs(\n pairs: {\n localCandidate: Pick<Candidate, \"priority\">;\n remoteCandidate: Pick<Candidate, \"priority\">;\n }[],\n iceControlling: boolean,\n) {\n return pairs\n .sort(\n (a, b) =>\n candidatePairPriority(\n a.localCandidate,\n a.remoteCandidate,\n iceControlling,\n ) -\n candidatePairPriority(\n b.localCandidate,\n b.remoteCandidate,\n iceControlling,\n ),\n )\n .reverse();\n}\n\n// 5.7.2. Computing Pair Priority and Ordering Pairs\nexport function candidatePairPriority(\n local: Pick<Candidate, \"priority\">,\n remote: Pick<Candidate, \"priority\">,\n iceControlling: boolean,\n) {\n const G = (iceControlling && local.priority) || remote.priority;\n const D = (iceControlling && remote.priority) || local.priority;\n return (1 << 32) * Math.min(G, D) + 2 * Math.max(G, D) + (G > D ? 1 : 0);\n}\n\nexport async function serverReflexiveCandidate(\n protocol: Protocol,\n stunServer: Address,\n) {\n // \"\"\"\n // Query STUN server to obtain a server-reflexive candidate.\n // \"\"\"\n\n // # perform STUN query\n const request = new Message(methods.BINDING, classes.REQUEST);\n try {\n const [response] = await protocol.request(request, stunServer);\n\n const localCandidate = protocol.localCandidate;\n if (!localCandidate) {\n throw new Error(\"not exist\");\n }\n\n const candidate = new Candidate(\n candidateFoundation(\n \"srflx\",\n localCandidate.transport,\n localCandidate.host,\n ),\n localCandidate.component,\n localCandidate.transport,\n candidatePriority(\"srflx\", {\n transport: localCandidate.transport,\n tcptype: localCandidate.tcptype,\n }),\n response.getAttributeValue(\"XOR-MAPPED-ADDRESS\")[0],\n response.getAttributeValue(\"XOR-MAPPED-ADDRESS\")[1],\n \"srflx\",\n localCandidate.host,\n localCandidate.port,\n localCandidate.tcptype,\n );\n return candidate;\n } catch (error) {\n // todo fix\n log(\"error serverReflexiveCandidate\", error);\n }\n}\n\nexport function validateAddress(addr?: Address): Address | undefined {\n if (addr && Number.isNaN(addr[1])) {\n return [addr[0], 443];\n }\n return addr;\n}\n"]}
1
+ {"version":3,"file":"iceBase.js","sourceRoot":"","sources":["../../../../ice/src/iceBase.ts"],"names":[],"mappings":";;;AAsQA,4DAYC;AAmJD,0DASC;AAED,gDAsBC;AAGD,sDAQC;AAED,4DA0CC;AAED,0CAKC;AA2CD,8DA+DC;AAQD,sDAkBC;AAUD,oDAEC;AAMD,sCAEC;AAUD,8EAYC;AAlrBD,mCAAoC;AACpC,2CAAgF;AAGhF,6CAM0B;AAC1B,wCAAgD;AAChD,4CAAyC;AAGzC,MAAM,GAAG,GAAG,IAAA,cAAK,EAAC,4CAA4C,CAAC,CAAC;AAyHhE,MAAa,aAAa;IAWxB,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAmBD,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,IAAI;QACN,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;YAC5B,cAAc,EAAE,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE;YAC3C,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE;SAC9C,CAAC;IACJ,CAAC;IAED,YACE,QAAkB,EAClB,eAA0B,EAC1B,cAAuB;QA9ClB;;;;;WAAmB;QACnB;;;;;WAA2B;QAC3B;;;;;WAAwB;QAEtB;;;;mBAAK,IAAA,mBAAU,GAAE,CAAC,QAAQ,EAAE;WAAC;QACtC;;;;;WAA0B;QAC1B;;;;mBAAY,KAAK;WAAC;QAClB;;;;mBAAkB,KAAK;WAAC;QACxB,2BAA2B;QACnB;;;;mBAA6B,0BAAkB,CAAC,MAAM;WAAC;QAK/D,sBAAsB;QACtB;;;;mBAAc,CAAC;WAAC;QAChB;;;;mBAAkB,CAAC;WAAC;QACpB;;;;mBAAY,CAAC;WAAC;QACd;;;;mBAAgB,CAAC;WAAC;QAClB;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IAAI,SAAS,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC;IAC9D,IAAI,oBAAoB,CAAC,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IAChD,IAAI,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,KAAK,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACnE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { randomUUID } from \"crypto\";\nimport { Candidate, candidateFoundation, candidatePriority } from \"./candidate\";\nimport type { MdnsLookup } from \"./dns/lookup\";\nimport type { Cancelable } from \"./helper\";\nimport {\n type Address,\n debug,\n type Event,\n type InterfaceAddresses,\n type TlsConnectionOptions,\n} from \"./imports/common\";\nimport { classes, methods } from \"./stun/const\";\nimport { Message } from \"./stun/message\";\nimport type { Protocol } from \"./types/model\";\n\nconst log = debug(\"werift-ice : packages/ice/src/ice.ts : log\");\n\nexport interface IceConnection {\n iceLite: boolean;\n iceControlling: boolean;\n localUsername: string;\n localPassword: string;\n remotePassword: string;\n remoteUsername: string;\n remoteIsLite: boolean;\n checkList: CandidatePair[];\n localCandidates: Candidate[];\n remoteCandidates: Candidate[];\n candidatePairs: CandidatePair[];\n /**\n * STUN servers gathering queries, normalized from the options (see\n * {@link normalizeIceServerOptions}). Optional so that other\n * implementations of this interface keep compiling.\n */\n stunServers?: Address[];\n /** TURN servers gathering allocates on, each with its own credential. */\n turnServers?: TurnServerOptions[];\n /** @deprecated The first of {@link IceConnection.stunServers}. */\n stunServer?: Address;\n /** @deprecated The address of the first of {@link IceConnection.turnServers}. */\n turnServer?: Address;\n generation: number;\n options: IceOptions;\n remoteCandidatesEnd: boolean;\n localCandidatesEnd: boolean;\n state: IceState;\n lookup?: MdnsLookup;\n nominated?: CandidatePair;\n\n readonly onData: Event<[Buffer]>;\n readonly stateChanged: Event<[IceState]>;\n readonly onIceCandidate: Event<[Candidate]>;\n\n restart(): void;\n /**\n * Optional staged-restart and provisional-generation support. An\n * implementation without them still restarts ICE at the final answer, but\n * cannot answer or run checks for the new generation during pranswer.\n */\n /**\n * `gatherOptions`: the options the staged generation gathers with (an ICE\n * server update applied at the commit); its provisional checks use only\n * the sockets those options allow. Defaults to the current options.\n */\n stageLocalCredentials?(\n usernameFragment: string,\n password: string,\n gatherOptions?: Partial<IceOptions>,\n ): void;\n discardStagedLocalCredentials?(usernameFragment: string): void;\n commitLocalCredentials?(usernameFragment: string, password: string): void;\n /**\n * The remote side alone restarted (new remote credentials in an answer):\n * drop the remote generation and its checks, keep the local credentials\n * and gathered candidates.\n */\n restartRemote?(): void;\n setProvisionalRemoteParams?(params: {\n usernameFragment: string;\n password: string;\n }): void;\n addProvisionalRemoteCandidate?(\n candidate: Candidate | undefined,\n ): Promise<void>;\n startProvisionalChecks?(): void;\n readonly provisionalNominated?: CandidatePair;\n\n setIceServers(options: Partial<IceOptions>): void;\n\n setRemoteParams(params: {\n iceLite: boolean;\n usernameFragment: string;\n password: string;\n }): void;\n\n /**\n * Gather the current generation's candidates. After an ICE restart the\n * candidates the kept sockets advertised are re-advertised synchronously;\n * only server work (STUN, TURN) is awaited.\n */\n gatherCandidates(): Promise<void>;\n\n /** Whether gathering contacts a STUN or TURN server. */\n readonly gathersFromServers?: boolean;\n\n connect(): Promise<void>;\n\n close(): Promise<void>;\n\n addRemoteCandidate(remoteCandidate: Candidate | undefined): Promise<void>;\n\n send(data: Buffer): Promise<void>;\n\n getDefaultCandidate(): Candidate | undefined;\n resetNominatedPair(): void;\n /** Drop remote candidates and pairs that name another remote ufrag. */\n dropOtherRemoteGenerations?(usernameFragment: string): void;\n}\n\nexport interface CandidatePairStats {\n packetsSent: number;\n packetsReceived: number;\n bytesSent: number;\n bytesReceived: number;\n rtt?: number;\n totalRoundTripTime: number;\n roundTripTimeMeasurements: number;\n requestsReceived: number;\n requestsSent: number;\n responsesReceived: number;\n responsesSent: number;\n retransmissionsReceived: number;\n retransmissionsSent: number;\n consentRequestsSent: number;\n}\n\nexport class CandidatePair implements CandidatePairStats {\n public protocol: Protocol;\n public remoteCandidate: Candidate;\n public iceControlling: boolean;\n\n readonly id = randomUUID().toString();\n handle?: Cancelable<void>;\n nominated = false;\n remoteNominated = false;\n // 5.7.4. Computing States\n private _state: CandidatePairState = CandidatePairState.FROZEN;\n get state() {\n return this._state;\n }\n\n // Statistics tracking\n packetsSent = 0;\n packetsReceived = 0;\n bytesSent = 0;\n bytesReceived = 0;\n rtt?: number;\n totalRoundTripTime = 0;\n roundTripTimeMeasurements = 0;\n requestsReceived = 0;\n requestsSent = 0;\n responsesReceived = 0;\n responsesSent = 0;\n retransmissionsReceived = 0;\n retransmissionsSent = 0;\n consentRequestsSent = 0;\n private readonly requestTransactionIds = new Set<string>();\n\n toJSON() {\n return this.json;\n }\n\n get json() {\n return {\n protocol: this.protocol.type,\n localCandidate: this.localCandidate.toSdp(),\n remoteCandidate: this.remoteCandidate.toSdp(),\n };\n }\n\n constructor(\n protocol: Protocol,\n remoteCandidate: Candidate,\n iceControlling: boolean,\n ) {\n this.protocol = protocol;\n this.remoteCandidate = remoteCandidate;\n this.iceControlling = iceControlling;\n }\n\n updateState(state: CandidatePairState) {\n this._state = state;\n }\n\n get localCandidate() {\n if (!this.protocol.localCandidate) {\n throw new Error(\"localCandidate not exist\");\n }\n return this.protocol.localCandidate;\n }\n\n get remoteAddr(): Address {\n return [this.remoteCandidate.host, this.remoteCandidate.port];\n }\n\n get component() {\n return this.localCandidate.component;\n }\n\n get priority() {\n return candidatePairPriority(\n this.localCandidate,\n this.remoteCandidate,\n this.iceControlling,\n );\n }\n\n get foundation() {\n return this.localCandidate.foundation;\n }\n\n noteIncomingRequest(transactionId: string) {\n const isRetransmission = this.requestTransactionIds.has(transactionId);\n if (!isRetransmission) {\n this.requestTransactionIds.add(transactionId);\n return false;\n }\n this.retransmissionsReceived++;\n return true;\n }\n}\n\nexport const ICE_COMPLETED = 1 as const;\nexport const ICE_FAILED = 2 as const;\n\n/** Basic consent check period in seconds (RFC 7675). Actual interval is 0.8–1.2× this. */\nexport const CONSENT_INTERVAL = 5;\n\n/**\n * @deprecated Consent expiry is based on {@link CONSENT_TIMEOUT} (30s after the\n * last valid response), not a consecutive failure count. Kept for API compatibility.\n */\nexport const CONSENT_FAILURES = 6;\n\n/** RFC 7675: consent expires this many seconds after the last valid response. */\nexport const CONSENT_TIMEOUT = 30;\n\n/**\n * Default single-shot response wait for consent requests (ms) when RTT is unknown.\n * Independent of retransmission count. Downstream ICE-lite peers typically\n * answer in 150–300ms; 1s is a conservative default used by interop patches.\n */\nexport const CONSENT_RESPONSE_TIMEOUT = 1000;\n\n/** RFC 8445 §14.3: ICE RTO must not be less than 500ms. */\nexport const CONSENT_RESPONSE_TIMEOUT_MIN = 500;\n\n/**\n * Compute consent response wait from pair RTT (seconds).\n * Uses 2×RTT + 200ms jitter margin, floored at {@link CONSENT_RESPONSE_TIMEOUT_MIN}.\n * Falls back to {@link CONSENT_RESPONSE_TIMEOUT} when RTT is unavailable.\n */\nexport function consentResponseTimeoutMs(rttSeconds?: number): number {\n if (\n rttSeconds === undefined ||\n !Number.isFinite(rttSeconds) ||\n rttSeconds <= 0\n ) {\n return CONSENT_RESPONSE_TIMEOUT;\n }\n return Math.max(\n CONSENT_RESPONSE_TIMEOUT_MIN,\n Math.round(rttSeconds * 1000 * 2 + 200),\n );\n}\n\n/**\n * @enum\n */\nexport const CandidatePairState = {\n FROZEN: 0,\n WAITING: 1,\n IN_PROGRESS: 2,\n SUCCEEDED: 3,\n FAILED: 4,\n} as const;\nexport type CandidatePairState =\n (typeof CandidatePairState)[keyof typeof CandidatePairState];\n\nexport type IceState =\n | \"disconnected\"\n | \"closed\"\n | \"completed\"\n | \"new\"\n | \"connected\"\n | \"failed\";\n\n/** A TURN server and the credential and transport used for it. */\nexport type TurnServerOptions = {\n address: Address;\n username: string;\n password: string;\n /** Defaults to \"udp\" (with a TCP fallback when the UDP allocation fails). */\n transport?: \"udp\" | \"tcp\" | \"tls\";\n};\n\nexport interface IceOptions {\n /** Advertise and operate as an ICE lite agent. */\n iceLite: boolean;\n useTcp: boolean;\n /**\n * Gather passive TCP host candidates (opens a listening TCP server per\n * interface). Defaults to true. Send-only agents that never accept inbound\n * connections can set this false to avoid the listener while still gathering\n * active TCP candidates.\n */\n tcpPassive?: boolean;\n /**\n * Seconds to wait for server-reflexive candidates while gathering.\n * Defaults to 5. Where UDP is blocked these STUN queries are never answered,\n * so the wait always runs to the timeout; agents that must not stall on such\n * networks can lower it.\n */\n stunGatherTimeout?: number;\n /**\n * Seconds to wait for a TURN TCP/TLS connection to be established.\n * Defaults to 8.\n */\n turnConnectTimeout?: number;\n /**\n * STUN servers queried while gathering, in priority order. Every IPv4 UDP\n * host socket queries each of them in parallel; equal mappings are\n * advertised once, different ones (a NAT that maps per destination) each.\n * Gathering ends when the slowest server answers or `stunGatherTimeout`\n * runs out.\n *\n * Merged with the deprecated `stunServer`: the singular one comes first,\n * duplicates are dropped (see {@link normalizeIceServerOptions}).\n */\n stunServers?: Address[];\n /**\n * TURN servers allocated on while gathering, in priority order. Each one\n * gets its own allocation with its own credential and transport; one that\n * fails or times out does not stop the others. Gathering ends when the\n * slowest allocation completes or fails (`turnConnectTimeout` bounds a\n * TCP/TLS connection, the STUN transaction timeout an unanswered request).\n * `turnTlsOptions`, `turnUdpFamily`, `turnConnectTimeout`, `portRange` and\n * `interfaceAddresses` apply to every TURN server.\n *\n * Merged with the deprecated `turnServer` / `turnUsername` /\n * `turnPassword` / `turnTransport`: the singular one comes first,\n * duplicates are dropped and an entry without username / password is\n * ignored (see {@link normalizeIceServerOptions}).\n */\n turnServers?: TurnServerOptions[];\n /** @deprecated Use {@link IceOptions.stunServers}. Kept as their first entry. */\n stunServer?: Address;\n /**\n * Whether the built-in public STUN server (stun.l.google.com:19302) is used\n * when no STUN server is given. Defaults to true; false gathers no\n * server-reflexive candidate unless a STUN server is set.\n */\n useDefaultStunServer?: boolean;\n /** @deprecated Use {@link IceOptions.turnServers}. Kept as their first entry. */\n turnServer?: Address;\n /** @deprecated Use {@link TurnServerOptions.username} of {@link IceOptions.turnServers}. */\n turnUsername?: string;\n /** @deprecated Use {@link TurnServerOptions.password} of {@link IceOptions.turnServers}. */\n turnPassword?: string;\n /** @deprecated Use {@link TurnServerOptions.transport} of {@link IceOptions.turnServers}. */\n turnTransport?: \"udp\" | \"tcp\" | \"tls\";\n /** Applied to every TLS TURN server. */\n turnTlsOptions?: TlsConnectionOptions;\n /**\n * Preferred IP family of a TURN/UDP socket, applied (to every TURN server)\n * only when the server is a hostname. Ignored for an IP literal server,\n * whose own family always selects the socket. Defaults to 4.\n */\n turnUdpFamily?: 4 | 6;\n forceTurn?: boolean;\n localPasswordPrefix?: string;\n useIpv4: boolean;\n useIpv6: boolean;\n useLinkLocalAddress?: boolean;\n portRange?: [number, number];\n /**\n * Local addresses to bind the UDP host sockets to, per family.\n *\n * The address given for a family (`udp4` / `udp6`) is the only host\n * address of that family: its UDP host candidate advertises the address and\n * port the socket is actually bound to, even when the address is not among\n * the enumerated network interfaces (loopback, tun, ...), and its TCP host\n * candidates use it too. Other enumerated addresses of that family are not\n * gathered. If the bind fails, the family has no UDP host candidate.\n *\n * A family left unspecified while the other one is set gathers no\n * enumerated addresses (only its `additionalHostAddresses`). Without any\n * family set, every enumerated address is gathered over wildcard sockets.\n */\n interfaceAddresses?: InterfaceAddresses;\n /**\n * Host addresses gathered in addition to the enumerated ones. For a family\n * bound by `interfaceAddresses`, addresses other than the bound one are\n * ignored.\n */\n additionalHostAddresses?: string[];\n filterStunResponse?: (\n message: Message,\n addr: Address,\n protocol: Protocol,\n ) => boolean;\n filterCandidatePair?: (pair: CandidatePair) => boolean;\n}\n\nexport const defaultOptions: IceOptions = {\n iceLite: false,\n useTcp: false,\n useIpv4: true,\n useIpv6: true,\n};\n\nexport function validateRemoteCandidate(candidate: Candidate) {\n // \"\"\"\n // Check the remote candidate is supported.\n // \"\"\"\n if (![\"host\", \"relay\", \"srflx\"].includes(candidate.type))\n throw new Error(`Unexpected candidate type \"${candidate.type}\"`);\n\n // ipaddress.ip_address(candidate.host)\n return candidate;\n}\n\nexport function sortCandidatePairs(\n pairs: {\n localCandidate: Pick<Candidate, \"priority\">;\n remoteCandidate: Pick<Candidate, \"priority\">;\n }[],\n iceControlling: boolean,\n) {\n return pairs\n .sort(\n (a, b) =>\n candidatePairPriority(\n a.localCandidate,\n a.remoteCandidate,\n iceControlling,\n ) -\n candidatePairPriority(\n b.localCandidate,\n b.remoteCandidate,\n iceControlling,\n ),\n )\n .reverse();\n}\n\n// 5.7.2. Computing Pair Priority and Ordering Pairs\nexport function candidatePairPriority(\n local: Pick<Candidate, \"priority\">,\n remote: Pick<Candidate, \"priority\">,\n iceControlling: boolean,\n) {\n const G = (iceControlling && local.priority) || remote.priority;\n const D = (iceControlling && remote.priority) || local.priority;\n return (1 << 32) * Math.min(G, D) + 2 * Math.max(G, D) + (G > D ? 1 : 0);\n}\n\nexport async function serverReflexiveCandidate(\n protocol: Protocol,\n stunServer: Address,\n) {\n // \"\"\"\n // Query STUN server to obtain a server-reflexive candidate.\n // \"\"\"\n\n // # perform STUN query\n const request = new Message(methods.BINDING, classes.REQUEST);\n try {\n const [response] = await protocol.request(request, stunServer);\n\n const localCandidate = protocol.localCandidate;\n if (!localCandidate) {\n throw new Error(\"not exist\");\n }\n\n const candidate = new Candidate(\n candidateFoundation(\n \"srflx\",\n localCandidate.transport,\n localCandidate.host,\n ),\n localCandidate.component,\n localCandidate.transport,\n candidatePriority(\"srflx\", {\n transport: localCandidate.transport,\n tcptype: localCandidate.tcptype,\n }),\n response.getAttributeValue(\"XOR-MAPPED-ADDRESS\")[0],\n response.getAttributeValue(\"XOR-MAPPED-ADDRESS\")[1],\n \"srflx\",\n localCandidate.host,\n localCandidate.port,\n localCandidate.tcptype,\n );\n return candidate;\n } catch (error) {\n // todo fix\n log(\"error serverReflexiveCandidate\", error);\n }\n}\n\nexport function validateAddress(addr?: Address): Address | undefined {\n if (addr && Number.isNaN(addr[1])) {\n return [addr[0], 443];\n }\n return addr;\n}\n\n/** The STUN/TURN server fields of {@link IceOptions}, singular and plural. */\nexport type IceServerFields = Partial<\n Pick<\n IceOptions,\n | \"stunServer\"\n | \"stunServers\"\n | \"turnServer\"\n | \"turnServers\"\n | \"turnUsername\"\n | \"turnPassword\"\n | \"turnTransport\"\n >\n>;\n\n/** A STUN/TURN server address: validated (see {@link validateAddress}) or undefined. */\nfunction validServerAddress(addr: unknown): Address | undefined {\n if (!Array.isArray(addr)) return undefined;\n const validated = validateAddress(addr as unknown as Address);\n if (!validated) return undefined;\n const [host, port] = validated;\n if (typeof host !== \"string\" || host === \"\") return undefined;\n if (typeof port !== \"number\" || !Number.isFinite(port)) return undefined;\n return validated;\n}\n\nconst sameAddress = (a: Address, b: Address) => a[0] === b[0] && a[1] === b[1];\n\n/**\n * The STUN and TURN servers `options` configure, the one place the singular\n * (deprecated) and plural fields are merged:\n *\n * - order: the singular server first, then the plural list in its order;\n * - duplicates (the same STUN address; the same TURN address, transport and\n * credential) are kept once, at their first position;\n * - an invalid address (see {@link validateAddress}) is dropped, and so is a\n * TURN server without username or password (it cannot allocate);\n * - a TURN transport left unset is \"udp\".\n *\n * The built-in default STUN server is not added here; Connection falls back\n * to it when the result has no STUN server.\n */\nexport function normalizeIceServerOptions(options: IceServerFields): {\n stunServers: Address[];\n turnServers: Required<TurnServerOptions>[];\n} {\n const stunServers: Address[] = [];\n for (const server of [options.stunServer, ...(options.stunServers ?? [])]) {\n if (server === undefined) continue;\n const address = validServerAddress(server);\n if (!address) {\n log(\"invalid STUN server ignored\", server);\n continue;\n }\n if (stunServers.some((existing) => sameAddress(existing, address))) {\n continue;\n }\n stunServers.push(address);\n }\n\n const turnServers: Required<TurnServerOptions>[] = [];\n const configured: Partial<TurnServerOptions>[] = [\n ...(options.turnServer !== undefined\n ? [\n {\n address: options.turnServer,\n username: options.turnUsername,\n password: options.turnPassword,\n transport: options.turnTransport,\n },\n ]\n : []),\n ...(options.turnServers ?? []),\n ];\n for (const server of configured) {\n const address = validServerAddress(server?.address);\n if (!address) {\n log(\"invalid TURN server ignored\", server?.address);\n continue;\n }\n const { username, password } = server;\n if (!username || !password) {\n log(\"TURN server without username / credential ignored\", address);\n continue;\n }\n const entry: Required<TurnServerOptions> = {\n address,\n username,\n password,\n transport: server.transport ?? \"udp\",\n };\n if (\n turnServers.some(\n (existing) =>\n sameAddress(existing.address, entry.address) &&\n existing.transport === entry.transport &&\n existing.username === entry.username &&\n existing.password === entry.password,\n )\n ) {\n continue;\n }\n turnServers.push(entry);\n }\n return { stunServers, turnServers };\n}\n\n/**\n * `current` with an ICE server update applied (Connection.setIceServers): the\n * STUN/TURN fields, singular and plural, are replaced, an undefined one\n * included, so a STUN-only update cannot leave a previous TURN\n * host/credential behind; forceTurn and useTcp change only when given.\n */\nexport function mergeIceServerOptions<T extends Partial<IceOptions>>(\n current: T,\n update: Partial<IceOptions>,\n): T {\n return {\n ...current,\n stunServer: update.stunServer,\n stunServers: update.stunServers,\n turnServer: update.turnServer,\n turnServers: update.turnServers,\n turnUsername: update.turnUsername,\n turnPassword: update.turnPassword,\n turnTransport: update.turnTransport,\n turnTlsOptions: update.turnTlsOptions,\n turnUdpFamily: update.turnUdpFamily,\n forceTurn: update.forceTurn ?? current.forceTurn,\n useTcp: update.useTcp ?? current.useTcp,\n };\n}\n\n/**\n * Whether a generation gathered with `options` is relay-only: forceTurn (the\n * \"relay\" ICE transport policy). The policy holds whatever the TURN settings\n * are: without a usable TURN server / credential (or for an ICE-lite agent,\n * which gathers no relay candidate) the generation has no candidate at all\n * rather than falling back to host / server-reflexive ones, so the local and\n * public addresses are neither advertised nor used for checks.\n */\nexport function isRelayOnlyGathering(options: Pick<IceOptions, \"forceTurn\">) {\n return !!options.forceTurn;\n}\n\n/**\n * Whether `options` carry at least one usable TURN server with its\n * credential, the ones a gathering with them allocates relay candidates from.\n */\nexport function hasTurnServer(options: IceServerFields) {\n return normalizeIceServerOptions(options).turnServers.length > 0;\n}\n\n/**\n * Whether `candidate`, kept from an earlier generation (an ICE restart keeps\n * the sockets), may be advertised and paired in a generation gathered with\n * `options`. A fresh gathering with the same options would not have produced\n * a host / server-reflexive candidate for a relay-only policy, a TCP host\n * candidate without useTcp, nor a relay candidate without a TURN server;\n * the kept ones are held back the same way.\n */\nexport function isCandidateAllowedByGatherOptions(\n candidate: Pick<Candidate, \"type\" | \"transport\">,\n options: Pick<IceOptions, \"forceTurn\"> &\n Partial<Pick<IceOptions, \"useTcp\">> &\n IceServerFields,\n) {\n if (candidate.type === \"relay\") return hasTurnServer(options);\n if (isRelayOnlyGathering(options)) return false;\n if (candidate.transport.toLowerCase() === \"tcp\" && !options.useTcp) {\n return false;\n }\n return true;\n}\n"]}
@@ -1,12 +1,12 @@
1
1
  export { randomPort } from "../../common/src";
2
+ export * from "./candidate";
3
+ export * from "./ice";
4
+ export * from "./iceBase";
2
5
  export * from "./stun/const";
3
- export * from "./stun/tcpFrame";
4
- export * from "./stun/tcpProtocol";
5
6
  export * from "./stun/message";
6
7
  export * from "./stun/protocol";
8
+ export * from "./stun/tcpFrame";
9
+ export * from "./stun/tcpProtocol";
7
10
  export * from "./turn/protocol";
8
- export * from "./candidate";
9
- export * from "./ice";
10
11
  export * from "./types/model";
11
12
  export * from "./utils";
12
- export * from "./iceBase";
@@ -17,15 +17,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.randomPort = void 0;
18
18
  var src_1 = require("../../common/src");
19
19
  Object.defineProperty(exports, "randomPort", { enumerable: true, get: function () { return src_1.randomPort; } });
20
+ __exportStar(require("./candidate"), exports);
21
+ __exportStar(require("./ice"), exports);
22
+ __exportStar(require("./iceBase"), exports);
20
23
  __exportStar(require("./stun/const"), exports);
21
- __exportStar(require("./stun/tcpFrame"), exports);
22
- __exportStar(require("./stun/tcpProtocol"), exports);
23
24
  __exportStar(require("./stun/message"), exports);
24
25
  __exportStar(require("./stun/protocol"), exports);
26
+ __exportStar(require("./stun/tcpFrame"), exports);
27
+ __exportStar(require("./stun/tcpProtocol"), exports);
25
28
  __exportStar(require("./turn/protocol"), exports);
26
- __exportStar(require("./candidate"), exports);
27
- __exportStar(require("./ice"), exports);
28
29
  __exportStar(require("./types/model"), exports);
29
30
  __exportStar(require("./utils"), exports);
30
- __exportStar(require("./iceBase"), exports);
31
31
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../ice/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wCAA8C;AAArC,iGAAA,UAAU,OAAA;AAEnB,+CAA6B;AAC7B,kDAAgC;AAChC,qDAAmC;AACnC,iDAA+B;AAC/B,kDAAgC;AAChC,kDAAgC;AAChC,8CAA4B;AAC5B,wCAAsB;AACtB,gDAA8B;AAC9B,0CAAwB;AACxB,4CAA0B","sourcesContent":["export { randomPort } from \"../../common/src\";\n\nexport * from \"./stun/const\";\nexport * from \"./stun/tcpFrame\";\nexport * from \"./stun/tcpProtocol\";\nexport * from \"./stun/message\";\nexport * from \"./stun/protocol\";\nexport * from \"./turn/protocol\";\nexport * from \"./candidate\";\nexport * from \"./ice\";\nexport * from \"./types/model\";\nexport * from \"./utils\";\nexport * from \"./iceBase\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../ice/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wCAA8C;AAArC,iGAAA,UAAU,OAAA;AACnB,8CAA4B;AAC5B,wCAAsB;AACtB,4CAA0B;AAC1B,+CAA6B;AAC7B,iDAA+B;AAC/B,kDAAgC;AAChC,kDAAgC;AAChC,qDAAmC;AACnC,kDAAgC;AAChC,gDAA8B;AAC9B,0CAAwB","sourcesContent":["export { randomPort } from \"../../common/src\";\nexport * from \"./candidate\";\nexport * from \"./ice\";\nexport * from \"./iceBase\";\nexport * from \"./stun/const\";\nexport * from \"./stun/message\";\nexport * from \"./stun/protocol\";\nexport * from \"./stun/tcpFrame\";\nexport * from \"./stun/tcpProtocol\";\nexport * from \"./turn/protocol\";\nexport * from \"./types/model\";\nexport * from \"./utils\";\n"]}