werift 0.26.0 → 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 (437) hide show
  1. package/README.md +63 -0
  2. package/THIRD_PARTY_LICENSES_LIBWEBRTC.txt +58 -0
  3. package/lib/common/src/binary.d.ts +1 -3
  4. package/lib/common/src/binary.js +8 -6
  5. package/lib/common/src/binary.js.map +1 -1
  6. package/lib/common/src/binaryData.js +2 -1
  7. package/lib/common/src/binaryData.js.map +1 -1
  8. package/lib/common/src/log.js +5 -7
  9. package/lib/common/src/log.js.map +1 -1
  10. package/lib/common/src/transport.js +10 -5
  11. package/lib/common/src/transport.js.map +1 -1
  12. package/lib/dtls/src/context/cipher.d.ts +1 -1
  13. package/lib/dtls/src/context/cipher.js +6 -3
  14. package/lib/dtls/src/context/cipher.js.map +1 -1
  15. package/lib/dtls/src/context/dtls.js +4 -2
  16. package/lib/dtls/src/context/dtls.js.map +1 -1
  17. package/lib/dtls/src/context/transport.js +2 -1
  18. package/lib/dtls/src/context/transport.js.map +1 -1
  19. package/lib/dtls/src/flight/client/flight1.js +2 -1
  20. package/lib/dtls/src/flight/client/flight1.js.map +1 -1
  21. package/lib/dtls/src/flight/client/flight5.js +4 -2
  22. package/lib/dtls/src/flight/client/flight5.js.map +1 -1
  23. package/lib/dtls/src/flight/flight.d.ts +1 -1
  24. package/lib/dtls/src/flight/flight.js +8 -4
  25. package/lib/dtls/src/flight/flight.js.map +1 -1
  26. package/lib/dtls/src/flight/server/flight4.js +4 -2
  27. package/lib/dtls/src/flight/server/flight4.js.map +1 -1
  28. package/lib/dtls/src/flight/server/flight6.js +2 -1
  29. package/lib/dtls/src/flight/server/flight6.js.map +1 -1
  30. package/lib/dtls/src/handshake/const.d.ts +17 -13
  31. package/lib/dtls/src/handshake/const.js +16 -14
  32. package/lib/dtls/src/handshake/const.js.map +1 -1
  33. package/lib/dtls/src/handshake/message/alert.js +4 -2
  34. package/lib/dtls/src/handshake/message/alert.js.map +1 -1
  35. package/lib/dtls/src/handshake/message/certificate.js +2 -1
  36. package/lib/dtls/src/handshake/message/certificate.js.map +1 -1
  37. package/lib/dtls/src/handshake/message/changeCipherSpec.js +2 -1
  38. package/lib/dtls/src/handshake/message/changeCipherSpec.js.map +1 -1
  39. package/lib/dtls/src/handshake/message/client/certificateVerify.js +4 -2
  40. package/lib/dtls/src/handshake/message/client/certificateVerify.js.map +1 -1
  41. package/lib/dtls/src/handshake/message/client/hello.js +14 -7
  42. package/lib/dtls/src/handshake/message/client/hello.js.map +1 -1
  43. package/lib/dtls/src/handshake/message/client/keyExchange.js +2 -1
  44. package/lib/dtls/src/handshake/message/client/keyExchange.js.map +1 -1
  45. package/lib/dtls/src/handshake/message/finished.js +2 -1
  46. package/lib/dtls/src/handshake/message/finished.js.map +1 -1
  47. package/lib/dtls/src/handshake/message/server/certificateRequest.js +6 -3
  48. package/lib/dtls/src/handshake/message/server/certificateRequest.js.map +1 -1
  49. package/lib/dtls/src/handshake/message/server/hello.js +12 -6
  50. package/lib/dtls/src/handshake/message/server/hello.js.map +1 -1
  51. package/lib/dtls/src/handshake/message/server/helloDone.js.map +1 -1
  52. package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js +4 -2
  53. package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js.map +1 -1
  54. package/lib/dtls/src/handshake/message/server/keyExchange.js +16 -8
  55. package/lib/dtls/src/handshake/message/server/keyExchange.js.map +1 -1
  56. package/lib/dtls/src/handshake/random.d.ts +2 -2
  57. package/lib/dtls/src/handshake/random.js +5 -2
  58. package/lib/dtls/src/handshake/random.js.map +1 -1
  59. package/lib/dtls/src/record/const.d.ts +43 -33
  60. package/lib/dtls/src/record/const.js +43 -36
  61. package/lib/dtls/src/record/const.js.map +1 -1
  62. package/lib/dtls/src/record/message/fragment.js +12 -6
  63. package/lib/dtls/src/record/message/fragment.js.map +1 -1
  64. package/lib/dtls/src/record/message/header.js +10 -5
  65. package/lib/dtls/src/record/message/header.js.map +1 -1
  66. package/lib/dtls/src/record/message/plaintext.js +4 -2
  67. package/lib/dtls/src/record/message/plaintext.js.map +1 -1
  68. package/lib/dtls/src/record/receive.js +2 -2
  69. package/lib/dtls/src/record/receive.js.map +1 -1
  70. package/lib/dtls/src/socket.js +4 -2
  71. package/lib/dtls/src/socket.js.map +1 -1
  72. package/lib/ice/src/candidate.d.ts +1 -1
  73. package/lib/ice/src/candidate.js +24 -12
  74. package/lib/ice/src/candidate.js.map +1 -1
  75. package/lib/ice/src/dns/lookup.d.ts +10 -1
  76. package/lib/ice/src/dns/lookup.js +42 -7
  77. package/lib/ice/src/dns/lookup.js.map +1 -1
  78. package/lib/ice/src/exceptions.d.ts +21 -5
  79. package/lib/ice/src/exceptions.js +58 -13
  80. package/lib/ice/src/exceptions.js.map +1 -1
  81. package/lib/ice/src/ice.d.ts +52 -8
  82. package/lib/ice/src/ice.js +288 -152
  83. package/lib/ice/src/ice.js.map +1 -1
  84. package/lib/ice/src/iceBase.d.ts +126 -11
  85. package/lib/ice/src/iceBase.js +165 -12
  86. package/lib/ice/src/iceBase.js.map +1 -1
  87. package/lib/ice/src/stun/transaction.d.ts +30 -1
  88. package/lib/ice/src/stun/transaction.js +86 -17
  89. package/lib/ice/src/stun/transaction.js.map +1 -1
  90. package/lib/ice/src/turn/credential.d.ts +49 -0
  91. package/lib/ice/src/turn/credential.js +78 -0
  92. package/lib/ice/src/turn/credential.js.map +1 -0
  93. package/lib/ice/src/turn/protocol.d.ts +29 -8
  94. package/lib/ice/src/turn/protocol.js +121 -48
  95. package/lib/ice/src/turn/protocol.js.map +1 -1
  96. package/lib/ice-server/src/stun/attributes.d.ts +2 -0
  97. package/lib/ice-server/src/stun/attributes.js +7 -1
  98. package/lib/ice-server/src/stun/attributes.js.map +1 -1
  99. package/lib/ice-server/src/stun/const.d.ts +24 -16
  100. package/lib/ice-server/src/stun/const.js +22 -18
  101. package/lib/ice-server/src/stun/const.js.map +1 -1
  102. package/lib/ice-server/src/stun/message.d.ts +1 -3
  103. package/lib/ice-server/src/stun/message.js +13 -9
  104. package/lib/ice-server/src/stun/message.js.map +1 -1
  105. package/lib/index.mjs +9770 -2648
  106. package/lib/nonstandard/index.mjs +2428 -1052
  107. package/lib/polyfill/dom.mjs +8738 -1815
  108. package/lib/polyfill/index.mjs +8738 -1815
  109. package/lib/rtp/src/codec/assertPayload.d.ts +4 -0
  110. package/lib/rtp/src/codec/assertPayload.js +12 -0
  111. package/lib/rtp/src/codec/assertPayload.js.map +1 -0
  112. package/lib/rtp/src/codec/av1.js +2 -0
  113. package/lib/rtp/src/codec/av1.js.map +1 -1
  114. package/lib/rtp/src/codec/h264.js +35 -43
  115. package/lib/rtp/src/codec/h264.js.map +1 -1
  116. package/lib/rtp/src/codec/vp8.js +11 -5
  117. package/lib/rtp/src/codec/vp8.js.map +1 -1
  118. package/lib/rtp/src/codec/vp9.js +12 -0
  119. package/lib/rtp/src/codec/vp9.js.map +1 -1
  120. package/lib/rtp/src/extra/container/mp4/container.js +2 -1
  121. package/lib/rtp/src/extra/container/mp4/container.js.map +1 -1
  122. package/lib/rtp/src/extra/container/mp4/exp-golomb.js +2 -1
  123. package/lib/rtp/src/extra/container/mp4/exp-golomb.js.map +1 -1
  124. package/lib/rtp/src/extra/container/mp4/h264.d.ts +21 -17
  125. package/lib/rtp/src/extra/container/mp4/h264.js +26 -24
  126. package/lib/rtp/src/extra/container/mp4/h264.js.map +1 -1
  127. package/lib/rtp/src/extra/container/ogg/index.d.ts +1 -0
  128. package/lib/rtp/src/extra/container/ogg/index.js +1 -0
  129. package/lib/rtp/src/extra/container/ogg/index.js.map +1 -1
  130. package/lib/rtp/src/extra/container/ogg/writer.d.ts +90 -0
  131. package/lib/rtp/src/extra/container/ogg/writer.js +300 -0
  132. package/lib/rtp/src/extra/container/ogg/writer.js.map +1 -0
  133. package/lib/rtp/src/extra/container/webm/ebml/ebml.js +6 -3
  134. package/lib/rtp/src/extra/container/webm/ebml/ebml.js.map +1 -1
  135. package/lib/rtp/src/extra/processor/depacketizer.d.ts +5 -0
  136. package/lib/rtp/src/extra/processor/depacketizer.js +28 -2
  137. package/lib/rtp/src/extra/processor/depacketizer.js.map +1 -1
  138. package/lib/rtp/src/extra/processor/dtx.js +4 -2
  139. package/lib/rtp/src/extra/processor/dtx.js.map +1 -1
  140. package/lib/rtp/src/extra/processor/index.d.ts +2 -0
  141. package/lib/rtp/src/extra/processor/index.js +2 -0
  142. package/lib/rtp/src/extra/processor/index.js.map +1 -1
  143. package/lib/rtp/src/extra/processor/jitterBuffer.d.ts +29 -6
  144. package/lib/rtp/src/extra/processor/jitterBuffer.js +101 -111
  145. package/lib/rtp/src/extra/processor/jitterBuffer.js.map +1 -1
  146. package/lib/rtp/src/extra/processor/jitterBufferTransformer.js +2 -1
  147. package/lib/rtp/src/extra/processor/jitterBufferTransformer.js.map +1 -1
  148. package/lib/rtp/src/extra/processor/lipsync.d.ts +63 -0
  149. package/lib/rtp/src/extra/processor/lipsync.js +202 -51
  150. package/lib/rtp/src/extra/processor/lipsync.js.map +1 -1
  151. package/lib/rtp/src/extra/processor/mp4.d.ts +0 -6
  152. package/lib/rtp/src/extra/processor/mp4.js +6 -3
  153. package/lib/rtp/src/extra/processor/mp4.js.map +1 -1
  154. package/lib/rtp/src/extra/processor/mute.js +4 -2
  155. package/lib/rtp/src/extra/processor/mute.js.map +1 -1
  156. package/lib/rtp/src/extra/processor/nack.js +4 -2
  157. package/lib/rtp/src/extra/processor/nack.js.map +1 -1
  158. package/lib/rtp/src/extra/processor/ntpTime.js +4 -6
  159. package/lib/rtp/src/extra/processor/ntpTime.js.map +1 -1
  160. package/lib/rtp/src/extra/processor/ogg.d.ts +72 -0
  161. package/lib/rtp/src/extra/processor/ogg.js +221 -0
  162. package/lib/rtp/src/extra/processor/ogg.js.map +1 -0
  163. package/lib/rtp/src/extra/processor/oggCallback.d.ts +21 -0
  164. package/lib/rtp/src/extra/processor/oggCallback.js +97 -0
  165. package/lib/rtp/src/extra/processor/oggCallback.js.map +1 -0
  166. package/lib/rtp/src/extra/processor/rtpCallback.js +2 -1
  167. package/lib/rtp/src/extra/processor/rtpCallback.js.map +1 -1
  168. package/lib/rtp/src/extra/processor/rtpStream.js +2 -1
  169. package/lib/rtp/src/extra/processor/rtpStream.js.map +1 -1
  170. package/lib/rtp/src/extra/processor/rtpTime.js +2 -1
  171. package/lib/rtp/src/extra/processor/rtpTime.js.map +1 -1
  172. package/lib/rtp/src/extra/processor/webm.js +14 -7
  173. package/lib/rtp/src/extra/processor/webm.js.map +1 -1
  174. package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
  175. package/lib/rtp/src/index.d.ts +7 -0
  176. package/lib/rtp/src/index.js +7 -0
  177. package/lib/rtp/src/index.js.map +1 -1
  178. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.d.ts +4 -0
  179. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js +4 -0
  180. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js.map +1 -1
  181. package/lib/rtp/src/rtcp/rtcp.js +8 -4
  182. package/lib/rtp/src/rtcp/rtcp.js.map +1 -1
  183. package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.d.ts +58 -0
  184. package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js +143 -0
  185. package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js.map +1 -0
  186. package/lib/rtp/src/rtcp/rtpfb/twcc.d.ts +35 -13
  187. package/lib/rtp/src/rtcp/rtpfb/twcc.js +132 -54
  188. package/lib/rtp/src/rtcp/rtpfb/twcc.js.map +1 -1
  189. package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.d.ts +13 -0
  190. package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js +29 -0
  191. package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js.map +1 -0
  192. package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.d.ts +41 -0
  193. package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js +89 -0
  194. package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js.map +1 -0
  195. package/lib/rtp/src/rtcp/sr.js +1 -0
  196. package/lib/rtp/src/rtcp/sr.js.map +1 -1
  197. package/lib/rtp/src/rtp/continuity.d.ts +36 -0
  198. package/lib/rtp/src/rtp/continuity.js +100 -0
  199. package/lib/rtp/src/rtp/continuity.js.map +1 -0
  200. package/lib/rtp/src/rtp/headerExtension.js +41 -21
  201. package/lib/rtp/src/rtp/headerExtension.js.map +1 -1
  202. package/lib/rtp/src/rtp/padding.d.ts +17 -0
  203. package/lib/rtp/src/rtp/padding.js +37 -0
  204. package/lib/rtp/src/rtp/padding.js.map +1 -0
  205. package/lib/rtp/src/rtp/red/encoder.d.ts +10 -0
  206. package/lib/rtp/src/rtp/red/encoder.js +14 -1
  207. package/lib/rtp/src/rtp/red/encoder.js.map +1 -1
  208. package/lib/rtp/src/rtp/red/packet.js +24 -8
  209. package/lib/rtp/src/rtp/red/packet.js.map +1 -1
  210. package/lib/rtp/src/rtp/rtp.d.ts +24 -1
  211. package/lib/rtp/src/rtp/rtp.js +70 -29
  212. package/lib/rtp/src/rtp/rtp.js.map +1 -1
  213. package/lib/rtp/src/rtp/rtx.js +3 -0
  214. package/lib/rtp/src/rtp/rtx.js.map +1 -1
  215. package/lib/rtp/src/rtp/sendHeaderExtensions.d.ts +36 -0
  216. package/lib/rtp/src/rtp/sendHeaderExtensions.js +85 -0
  217. package/lib/rtp/src/rtp/sendHeaderExtensions.js.map +1 -0
  218. package/lib/rtp/src/srtp/cipher/ctr.js +4 -2
  219. package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
  220. package/lib/rtp/src/srtp/cipher/index.js +8 -4
  221. package/lib/rtp/src/srtp/cipher/index.js.map +1 -1
  222. package/lib/rtp/src/srtp/context/context.js +6 -3
  223. package/lib/rtp/src/srtp/context/context.js.map +1 -1
  224. package/lib/rtp/src/srtp/context/srtcp.d.ts +1 -1
  225. package/lib/rtp/src/srtp/context/srtcp.js +33 -0
  226. package/lib/rtp/src/srtp/context/srtcp.js.map +1 -1
  227. package/lib/rtp/src/srtp/context/srtp.d.ts +1 -1
  228. package/lib/rtp/src/srtp/context/srtp.js +34 -10
  229. package/lib/rtp/src/srtp/context/srtp.js.map +1 -1
  230. package/lib/rtp/src/srtp/error.d.ts +8 -0
  231. package/lib/rtp/src/srtp/error.js +13 -1
  232. package/lib/rtp/src/srtp/error.js.map +1 -1
  233. package/lib/rtp/src/srtp/packet.js +4 -1
  234. package/lib/rtp/src/srtp/packet.js.map +1 -1
  235. package/lib/rtp/src/srtp/replay.d.ts +24 -0
  236. package/lib/rtp/src/srtp/replay.js +75 -0
  237. package/lib/rtp/src/srtp/replay.js.map +1 -0
  238. package/lib/rtp/src/srtp/session.js +2 -1
  239. package/lib/rtp/src/srtp/session.js.map +1 -1
  240. package/lib/rtp/src/srtp/srtcp.js +2 -1
  241. package/lib/rtp/src/srtp/srtcp.js.map +1 -1
  242. package/lib/rtp/src/srtp/srtp.js +2 -1
  243. package/lib/rtp/src/srtp/srtp.js.map +1 -1
  244. package/lib/rtp/src/util.js +2 -1
  245. package/lib/rtp/src/util.js.map +1 -1
  246. package/lib/sctp/src/chunk.d.ts +5 -0
  247. package/lib/sctp/src/chunk.js +31 -8
  248. package/lib/sctp/src/chunk.js.map +1 -1
  249. package/lib/sctp/src/const.d.ts +25 -17
  250. package/lib/sctp/src/const.js +23 -19
  251. package/lib/sctp/src/const.js.map +1 -1
  252. package/lib/sctp/src/param.d.ts +6 -2
  253. package/lib/sctp/src/param.js +22 -8
  254. package/lib/sctp/src/param.js.map +1 -1
  255. package/lib/sctp/src/sctp.d.ts +80 -0
  256. package/lib/sctp/src/sctp.js +655 -108
  257. package/lib/sctp/src/sctp.js.map +1 -1
  258. package/lib/sctp/src/transport.js +4 -2
  259. package/lib/sctp/src/transport.js.map +1 -1
  260. package/lib/webrtc/src/api/peerConfig.d.ts +48 -5
  261. package/lib/webrtc/src/api/peerConfig.js +41 -0
  262. package/lib/webrtc/src/api/peerConfig.js.map +1 -1
  263. package/lib/webrtc/src/dataChannel.d.ts +10 -0
  264. package/lib/webrtc/src/dataChannel.js +24 -4
  265. package/lib/webrtc/src/dataChannel.js.map +1 -1
  266. package/lib/webrtc/src/media/index.d.ts +10 -0
  267. package/lib/webrtc/src/media/index.js +70 -0
  268. package/lib/webrtc/src/media/index.js.map +1 -1
  269. package/lib/webrtc/src/media/receiver/nack.js +2 -1
  270. package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
  271. package/lib/webrtc/src/media/receiver/receiverTwcc.d.ts +61 -1
  272. package/lib/webrtc/src/media/receiver/receiverTwcc.js +218 -63
  273. package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
  274. package/lib/webrtc/src/media/router.d.ts +14 -1
  275. package/lib/webrtc/src/media/router.js +46 -2
  276. package/lib/webrtc/src/media/router.js.map +1 -1
  277. package/lib/webrtc/src/media/rtpReceiver.d.ts +30 -2
  278. package/lib/webrtc/src/media/rtpReceiver.js +175 -26
  279. package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
  280. package/lib/webrtc/src/media/rtpSender.d.ts +184 -70
  281. package/lib/webrtc/src/media/rtpSender.js +626 -449
  282. package/lib/webrtc/src/media/rtpSender.js.map +1 -1
  283. package/lib/webrtc/src/media/rtpTransceiver.d.ts +1 -3
  284. package/lib/webrtc/src/media/rtpTransceiver.js +10 -7
  285. package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
  286. package/lib/webrtc/src/media/sender/bandwidthEstimator.d.ts +249 -0
  287. package/lib/webrtc/src/media/sender/bandwidthEstimator.js +144 -0
  288. package/lib/webrtc/src/media/sender/bandwidthEstimator.js.map +1 -0
  289. package/lib/webrtc/src/media/sender/createBandwidthEstimator.d.ts +20 -0
  290. package/lib/webrtc/src/media/sender/createBandwidthEstimator.js +26 -0
  291. package/lib/webrtc/src/media/sender/createBandwidthEstimator.js.map +1 -0
  292. package/lib/webrtc/src/media/sender/estimatorBinding.d.ts +70 -0
  293. package/lib/webrtc/src/media/sender/estimatorBinding.js +175 -0
  294. package/lib/webrtc/src/media/sender/estimatorBinding.js.map +1 -0
  295. package/lib/webrtc/src/media/sender/estimators/disabledBwe.d.ts +18 -0
  296. package/lib/webrtc/src/media/sender/estimators/disabledBwe.js +44 -0
  297. package/lib/webrtc/src/media/sender/estimators/disabledBwe.js.map +1 -0
  298. package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.d.ts +79 -0
  299. package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.js +289 -0
  300. package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.js.map +1 -0
  301. package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.d.ts +87 -0
  302. package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.js +429 -0
  303. package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.js.map +1 -0
  304. package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.d.ts +21 -0
  305. package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.js +84 -0
  306. package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.js.map +1 -0
  307. package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.d.ts +37 -0
  308. package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.js +74 -0
  309. package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.js.map +1 -0
  310. package/lib/webrtc/src/media/sender/estimators/gcc/constants.d.ts +383 -0
  311. package/lib/webrtc/src/media/sender/estimators/gcc/constants.js +408 -0
  312. package/lib/webrtc/src/media/sender/estimators/gcc/constants.js.map +1 -0
  313. package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.d.ts +406 -0
  314. package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.js +1391 -0
  315. package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.js.map +1 -0
  316. package/lib/webrtc/src/media/sender/estimators/gcc/index.d.ts +19 -0
  317. package/lib/webrtc/src/media/sender/estimators/gcc/index.js +75 -0
  318. package/lib/webrtc/src/media/sender/estimators/gcc/index.js.map +1 -0
  319. package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.d.ts +68 -0
  320. package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.js +201 -0
  321. package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.js.map +1 -0
  322. package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.d.ts +26 -0
  323. package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.js +72 -0
  324. package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.js.map +1 -0
  325. package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.d.ts +41 -0
  326. package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.js +99 -0
  327. package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.js.map +1 -0
  328. package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.d.ts +247 -0
  329. package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.js +1042 -0
  330. package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.js.map +1 -0
  331. package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.d.ts +26 -0
  332. package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.js +132 -0
  333. package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.js.map +1 -0
  334. package/lib/webrtc/src/media/sender/estimators/gcc/probeController.d.ts +305 -0
  335. package/lib/webrtc/src/media/sender/estimators/gcc/probeController.js +1073 -0
  336. package/lib/webrtc/src/media/sender/estimators/gcc/probeController.js.map +1 -0
  337. package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.d.ts +60 -0
  338. package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.js +151 -0
  339. package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.js.map +1 -0
  340. package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.d.ts +44 -0
  341. package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.js +246 -0
  342. package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.js.map +1 -0
  343. package/lib/webrtc/src/media/sender/estimators/index.d.ts +7 -0
  344. package/lib/webrtc/src/media/sender/estimators/index.js +19 -0
  345. package/lib/webrtc/src/media/sender/estimators/index.js.map +1 -0
  346. package/lib/webrtc/src/media/sender/estimators/lightweightBwe.d.ts +64 -0
  347. package/lib/webrtc/src/media/sender/estimators/lightweightBwe.js +216 -0
  348. package/lib/webrtc/src/media/sender/estimators/lightweightBwe.js.map +1 -0
  349. package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.d.ts +117 -0
  350. package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.js +250 -0
  351. package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.js.map +1 -0
  352. package/lib/webrtc/src/media/sender/outgoingQueue.d.ts +40 -0
  353. package/lib/webrtc/src/media/sender/outgoingQueue.js +153 -0
  354. package/lib/webrtc/src/media/sender/outgoingQueue.js.map +1 -0
  355. package/lib/webrtc/src/media/sender/padding.d.ts +45 -0
  356. package/lib/webrtc/src/media/sender/padding.js +134 -0
  357. package/lib/webrtc/src/media/sender/padding.js.map +1 -0
  358. package/lib/webrtc/src/media/sender/pendingRtp.d.ts +35 -0
  359. package/lib/webrtc/src/media/sender/pendingRtp.js +120 -0
  360. package/lib/webrtc/src/media/sender/pendingRtp.js.map +1 -0
  361. package/lib/webrtc/src/media/sender/rtpWire.d.ts +13 -0
  362. package/lib/webrtc/src/media/sender/rtpWire.js +38 -0
  363. package/lib/webrtc/src/media/sender/rtpWire.js.map +1 -0
  364. package/lib/webrtc/src/media/sender/sendPacer.d.ts +27 -0
  365. package/lib/webrtc/src/media/sender/sendPacer.js +110 -0
  366. package/lib/webrtc/src/media/sender/sendPacer.js.map +1 -0
  367. package/lib/webrtc/src/media/sender/senderBWE.d.ts +8 -33
  368. package/lib/webrtc/src/media/sender/senderBWE.js +5 -154
  369. package/lib/webrtc/src/media/sender/senderBWE.js.map +1 -1
  370. package/lib/webrtc/src/media/sender/senderStats.d.ts +100 -0
  371. package/lib/webrtc/src/media/sender/senderStats.js +322 -0
  372. package/lib/webrtc/src/media/sender/senderStats.js.map +1 -0
  373. package/lib/webrtc/src/media/track.d.ts +20 -2
  374. package/lib/webrtc/src/media/track.js +23 -5
  375. package/lib/webrtc/src/media/track.js.map +1 -1
  376. package/lib/webrtc/src/negotiation/bundleTopology.d.ts +1 -5
  377. package/lib/webrtc/src/negotiation/bundleTopology.js +15 -11
  378. package/lib/webrtc/src/negotiation/bundleTopology.js.map +1 -1
  379. package/lib/webrtc/src/negotiation/descriptionValidation.js +12 -6
  380. package/lib/webrtc/src/negotiation/descriptionValidation.js.map +1 -1
  381. package/lib/webrtc/src/negotiation/negotiationNeeded.js +2 -1
  382. package/lib/webrtc/src/negotiation/negotiationNeeded.js.map +1 -1
  383. package/lib/webrtc/src/negotiation/remoteCandidates.js +10 -5
  384. package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -1
  385. package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +1 -1
  386. package/lib/webrtc/src/negotiation/remoteMediaApplication.js +22 -6
  387. package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -1
  388. package/lib/webrtc/src/negotiation/transportActivation.js +19 -8
  389. package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -1
  390. package/lib/webrtc/src/negotiationTransaction.d.ts +8 -1
  391. package/lib/webrtc/src/negotiationTransaction.js +18 -5
  392. package/lib/webrtc/src/negotiationTransaction.js.map +1 -1
  393. package/lib/webrtc/src/nonstandard/dummyMedia.js +2 -1
  394. package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
  395. package/lib/webrtc/src/nonstandard/navigator.js +4 -3
  396. package/lib/webrtc/src/nonstandard/navigator.js.map +1 -1
  397. package/lib/webrtc/src/nonstandard/recorder/index.d.ts +32 -8
  398. package/lib/webrtc/src/nonstandard/recorder/index.js +81 -20
  399. package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
  400. package/lib/webrtc/src/nonstandard/recorder/writer/index.d.ts +9 -7
  401. package/lib/webrtc/src/nonstandard/recorder/writer/index.js +2 -1
  402. package/lib/webrtc/src/nonstandard/recorder/writer/index.js.map +1 -1
  403. package/lib/webrtc/src/nonstandard/recorder/writer/ogg.d.ts +32 -0
  404. package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js +185 -0
  405. package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js.map +1 -0
  406. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +8 -1
  407. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
  408. package/lib/webrtc/src/nonstandard/userMedia.js +2 -1
  409. package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
  410. package/lib/webrtc/src/peerConnection.d.ts +44 -1
  411. package/lib/webrtc/src/peerConnection.js +74 -8
  412. package/lib/webrtc/src/peerConnection.js.map +1 -1
  413. package/lib/webrtc/src/polyfill/mediaDevices.js +2 -1
  414. package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
  415. package/lib/webrtc/src/sctpManager.d.ts +46 -14
  416. package/lib/webrtc/src/sctpManager.js +88 -25
  417. package/lib/webrtc/src/sctpManager.js.map +1 -1
  418. package/lib/webrtc/src/sdp.js +12 -6
  419. package/lib/webrtc/src/sdp.js.map +1 -1
  420. package/lib/webrtc/src/secureTransportManager.d.ts +52 -4
  421. package/lib/webrtc/src/secureTransportManager.js +106 -23
  422. package/lib/webrtc/src/secureTransportManager.js.map +1 -1
  423. package/lib/webrtc/src/transceiverManager.js +8 -3
  424. package/lib/webrtc/src/transceiverManager.js.map +1 -1
  425. package/lib/webrtc/src/transport/dtls.d.ts +53 -1
  426. package/lib/webrtc/src/transport/dtls.js +131 -31
  427. package/lib/webrtc/src/transport/dtls.js.map +1 -1
  428. package/lib/webrtc/src/transport/ice.d.ts +10 -86
  429. package/lib/webrtc/src/transport/ice.js +70 -31
  430. package/lib/webrtc/src/transport/ice.js.map +1 -1
  431. package/lib/webrtc/src/transport/sctp.d.ts +2 -0
  432. package/lib/webrtc/src/transport/sctp.js +66 -20
  433. package/lib/webrtc/src/transport/sctp.js.map +1 -1
  434. package/lib/webrtc/src/utils.d.ts +36 -3
  435. package/lib/webrtc/src/utils.js +56 -16
  436. package/lib/webrtc/src/utils.js.map +1 -1
  437. package/package.json +8 -6
@@ -37,12 +37,12 @@ exports.Connection = void 0;
37
37
  const timers = __importStar(require("node:timers/promises"));
38
38
  const crypto_1 = require("crypto");
39
39
  const net_1 = require("net");
40
- const common_1 = require("./imports/common");
41
40
  const candidate_1 = require("./candidate");
42
41
  const lookup_1 = require("./dns/lookup");
43
42
  const exceptions_1 = require("./exceptions");
44
43
  const helper_1 = require("./helper");
45
44
  const iceBase_1 = require("./iceBase");
45
+ const common_1 = require("./imports/common");
46
46
  const resolveHostAddresses_1 = require("./internal/resolveHostAddresses");
47
47
  const const_1 = require("./stun/const");
48
48
  const message_1 = require("./stun/message");
@@ -59,7 +59,7 @@ class Connection {
59
59
  enumerable: true,
60
60
  configurable: true,
61
61
  writable: true,
62
- value: _iceControlling
62
+ value: void 0
63
63
  });
64
64
  Object.defineProperty(this, "localUsername", {
65
65
  enumerable: true,
@@ -103,17 +103,23 @@ class Connection {
103
103
  writable: true,
104
104
  value: []
105
105
  });
106
- Object.defineProperty(this, "stunServer", {
106
+ /**
107
+ * STUN servers gathering queries: the configured ones (see
108
+ * normalizeIceServerOptions), or the built-in default when none is
109
+ * configured and useDefaultStunServer is not false.
110
+ */
111
+ Object.defineProperty(this, "stunServers", {
107
112
  enumerable: true,
108
113
  configurable: true,
109
114
  writable: true,
110
- value: void 0
115
+ value: []
111
116
  });
112
- Object.defineProperty(this, "turnServer", {
117
+ /** TURN servers gathering allocates on, one allocation each. */
118
+ Object.defineProperty(this, "turnServers", {
113
119
  enumerable: true,
114
120
  configurable: true,
115
121
  writable: true,
116
- value: void 0
122
+ value: []
117
123
  });
118
124
  Object.defineProperty(this, "options", {
119
125
  enumerable: true,
@@ -138,7 +144,11 @@ class Connection {
138
144
  writable: true,
139
145
  value: false
140
146
  });
141
- /** mDNS resolutions of remote candidates that arrived before end-of-candidates. */
147
+ /**
148
+ * mDNS resolutions of remote candidates that arrived before
149
+ * end-of-candidates. close() (and restart()) closes `lookup`, which rejects
150
+ * them at once.
151
+ */
142
152
  Object.defineProperty(this, "remoteResolutions", {
143
153
  enumerable: true,
144
154
  configurable: true,
@@ -206,6 +216,14 @@ class Connection {
206
216
  writable: true,
207
217
  value: "new"
208
218
  });
219
+ /** close() ran; unlike `state`, a restart does not reset it. */
220
+ Object.defineProperty(this, "closed", {
221
+ enumerable: true,
222
+ configurable: true,
223
+ writable: true,
224
+ value: false
225
+ });
226
+ /** Resolves remote mDNS candidates; closed (pending lookups cancelled) by restart() and close(). */
209
227
  Object.defineProperty(this, "lookup", {
210
228
  enumerable: true,
211
229
  configurable: true,
@@ -364,7 +382,10 @@ class Connection {
364
382
  writable: true,
365
383
  value: void 0
366
384
  });
367
- /** Last server-reflexive candidate each UDP socket advertised. */
385
+ /**
386
+ * Server-reflexive candidates each UDP socket advertised in its last
387
+ * gathering (one per distinct mapping its STUN servers returned).
388
+ */
368
389
  Object.defineProperty(this, "reflexiveBySocket", {
369
390
  enumerable: true,
370
391
  configurable: true,
@@ -735,6 +756,7 @@ class Connection {
735
756
  }
736
757
  }
737
758
  });
759
+ this._iceControlling = _iceControlling;
738
760
  this.closedSignal = new Promise((resolve) => {
739
761
  this.signalClosed = resolve;
740
762
  });
@@ -759,40 +781,51 @@ class Connection {
759
781
  * Link headers) and must take effect before the next gather pass.
760
782
  */
761
783
  setIceServers(options) {
762
- // Explicitly assign server fields even when undefined so a STUN-only
763
- // update cannot leave a previous TURN host/credential in options.
764
- this.options = {
765
- ...this.options,
766
- stunServer: options.stunServer,
767
- turnServer: options.turnServer,
768
- turnUsername: options.turnUsername,
769
- turnPassword: options.turnPassword,
770
- turnTransport: options.turnTransport,
771
- };
772
- if (options.forceTurn !== undefined) {
773
- this.options.forceTurn = options.forceTurn;
774
- }
775
- if (options.useTcp !== undefined) {
776
- this.options.useTcp = options.useTcp;
777
- }
778
- if (options.turnTlsOptions !== undefined) {
779
- this.options.turnTlsOptions = options.turnTlsOptions;
780
- }
781
- if (options.turnUdpFamily !== undefined) {
782
- this.options.turnUdpFamily = options.turnUdpFamily;
783
- }
784
+ // Server fields are assigned even when undefined, so a STUN-only update
785
+ // or an unset TLS / address-family option leaves nothing behind.
786
+ this.options = (0, iceBase_1.mergeIceServerOptions)(this.options, options);
784
787
  this.applyStunTurnServersFromOptions();
785
788
  log("Connection ice servers updated", this.options);
786
789
  }
787
790
  /**
788
- * Derive Connection.stunServer / turnServer from this.options.
791
+ * Derive Connection.stunServers / turnServers from this.options.
789
792
  * Shared by the constructor and setIceServers so both paths validate and
790
793
  * default identically.
791
794
  */
792
795
  applyStunTurnServersFromOptions() {
793
- this.stunServer =
794
- (0, iceBase_1.validateAddress)(this.options.stunServer) ?? DEFAULT_STUN_SERVER;
795
- this.turnServer = (0, iceBase_1.validateAddress)(this.options.turnServer);
796
+ const { stunServers, turnServers } = (0, iceBase_1.normalizeIceServerOptions)(this.options);
797
+ this.stunServers =
798
+ stunServers.length > 0 || this.options.useDefaultStunServer === false
799
+ ? stunServers
800
+ : [DEFAULT_STUN_SERVER];
801
+ this.turnServers = turnServers;
802
+ }
803
+ /** @deprecated The first of {@link Connection.stunServers}. */
804
+ get stunServer() {
805
+ return this.stunServers[0];
806
+ }
807
+ /** @deprecated Replaces {@link Connection.stunServers} with this one server (none for undefined). */
808
+ set stunServer(server) {
809
+ this.stunServers = server ? [server] : [];
810
+ }
811
+ /** @deprecated The address of the first of {@link Connection.turnServers}. */
812
+ get turnServer() {
813
+ return this.turnServers[0]?.address;
814
+ }
815
+ /**
816
+ * @deprecated Replaces {@link Connection.turnServers} with this one server
817
+ * and the deprecated turnUsername / turnPassword / turnTransport options
818
+ * (none for undefined).
819
+ */
820
+ set turnServer(server) {
821
+ this.turnServers = server
822
+ ? (0, iceBase_1.normalizeIceServerOptions)({
823
+ turnServer: server,
824
+ turnUsername: this.options.turnUsername,
825
+ turnPassword: this.options.turnPassword,
826
+ turnTransport: this.options.turnTransport,
827
+ }).turnServers
828
+ : [];
796
829
  }
797
830
  get iceControlling() {
798
831
  return this._iceControlling;
@@ -912,12 +945,13 @@ class Connection {
912
945
  this.provisional = undefined;
913
946
  }
914
947
  /** Accept provisional checks without changing the selected current pair. */
915
- stageLocalCredentials(usernameFragment, password) {
948
+ stageLocalCredentials(usernameFragment, password, gatherOptions) {
916
949
  this.userHistory[usernameFragment] = password;
917
950
  this.endProvisional();
918
951
  this.provisional = {
919
952
  localUsername: usernameFragment,
920
953
  localPassword: password,
954
+ gatherOptions,
921
955
  remoteCandidates: [],
922
956
  remoteCandidatesEnd: false,
923
957
  remoteCandidatesEndRequested: false,
@@ -962,10 +996,12 @@ class Connection {
962
996
  }
963
997
  async addProvisionalRemoteCandidate(remoteCandidate) {
964
998
  const generation = this.provisional;
965
- if (!generation)
999
+ if (!generation || this.closed)
966
1000
  return;
967
1001
  const revision = generation.revision;
968
- const current = () => this.provisional === generation && generation.revision === revision;
1002
+ const current = () => !this.closed &&
1003
+ this.provisional === generation &&
1004
+ generation.revision === revision;
969
1005
  if (!remoteCandidate) {
970
1006
  if (generation.remoteCandidatesEnd ||
971
1007
  generation.remoteCandidatesEndRequested) {
@@ -1044,6 +1080,7 @@ class Connection {
1044
1080
  }
1045
1081
  tryProvisionalPair(generation, protocol, remoteCandidate) {
1046
1082
  if (!protocol.localCandidate?.canPairWith(remoteCandidate) ||
1083
+ !this.allowsProvisional(generation, protocol) ||
1047
1084
  (protocol.localCandidate.transport.toLowerCase() === "tcp" &&
1048
1085
  protocol.localCandidate.tcptype === "passive" &&
1049
1086
  remoteCandidate.type !== "prflx") ||
@@ -1077,7 +1114,10 @@ class Connection {
1077
1114
  !generation.started ||
1078
1115
  !generation.remoteUsername ||
1079
1116
  !generation.remotePassword ||
1080
- [iceBase_1.CandidatePairState.IN_PROGRESS, iceBase_1.CandidatePairState.SUCCEEDED].includes(pair.state)) {
1117
+ [
1118
+ iceBase_1.CandidatePairState.IN_PROGRESS,
1119
+ iceBase_1.CandidatePairState.SUCCEEDED,
1120
+ ].includes(pair.state)) {
1081
1121
  return;
1082
1122
  }
1083
1123
  pair.updateState(iceBase_1.CandidatePairState.IN_PROGRESS);
@@ -1162,6 +1202,9 @@ class Connection {
1162
1202
  }
1163
1203
  /** Incoming check for the provisional ufrag; never touches the current checklist. */
1164
1204
  checkIncomingProvisional(generation, message, addr, protocol) {
1205
+ // A socket the staged generation drops at the commit takes no pair.
1206
+ if (!this.allowsProvisional(generation, protocol))
1207
+ return;
1165
1208
  // Only checks from the remote credentials of the current checklist count
1166
1209
  // (a replacement pranswer replaced any earlier ones).
1167
1210
  const txUsername = message.getAttributeValue("USERNAME");
@@ -1198,7 +1241,10 @@ class Connection {
1198
1241
  }
1199
1242
  }
1200
1243
  if (!this.iceLite &&
1201
- [iceBase_1.CandidatePairState.WAITING, iceBase_1.CandidatePairState.FAILED].includes(pair.state)) {
1244
+ [
1245
+ iceBase_1.CandidatePairState.WAITING,
1246
+ iceBase_1.CandidatePairState.FAILED,
1247
+ ].includes(pair.state)) {
1202
1248
  void this.checkProvisional(generation, pair);
1203
1249
  }
1204
1250
  }
@@ -1261,8 +1307,15 @@ class Connection {
1261
1307
  // An ICE restart allocates TURN afresh, which is how a restart recovers
1262
1308
  // from an allocation that died: the previous one leaves the generation.
1263
1309
  const previousTurn = this.protocols.filter((protocol) => protocol.localCandidate?.type === "relay");
1264
- this.protocols = this.protocols.filter((protocol) => !previousTurn.includes(protocol));
1265
- void Promise.allSettled(previousTurn.map((protocol) => protocol.close()));
1310
+ // The generation keeps only the sockets a fresh gathering with the
1311
+ // current options would open: a relay-only policy or useTcp turned off
1312
+ // since the previous generation closes the kept host (UDP / TCP)
1313
+ // sockets, so they are neither advertised, paired nor reachable.
1314
+ const excluded = this.protocols.filter((protocol) => !previousTurn.includes(protocol) &&
1315
+ !!protocol.localCandidate &&
1316
+ !(0, iceBase_1.isCandidateAllowedByGatherOptions)(protocol.localCandidate, this.options));
1317
+ this.protocols = this.protocols.filter((protocol) => !previousTurn.includes(protocol) && !excluded.includes(protocol));
1318
+ void Promise.allSettled([...previousTurn, ...excluded].map((protocol) => protocol.close()));
1266
1319
  // ICE restart keeps transport protocols; re-advertise their host candidates
1267
1320
  // with the new generation / ufrag before gathering additional addresses.
1268
1321
  for (const protocol of this.protocols) {
@@ -1270,8 +1323,7 @@ class Connection {
1270
1323
  protocol.localCandidate.generation = this.generation;
1271
1324
  protocol.localCandidate.ufrag = this.localUsername;
1272
1325
  this.appendLocalCandidate(protocol.localCandidate);
1273
- const reflexive = this.reflexiveBySocket.get(protocol);
1274
- if (reflexive) {
1326
+ for (const reflexive of this.reflexiveBySocket.get(protocol) ?? []) {
1275
1327
  this.appendLocalCandidate(this.withGeneration(reflexive));
1276
1328
  }
1277
1329
  }
@@ -1314,13 +1366,37 @@ class Connection {
1314
1366
  isGathering(generation) {
1315
1367
  return this.generation === generation && this.state !== "closed";
1316
1368
  }
1369
+ /**
1370
+ * Whether the provisional generation may use `protocol`: the staged
1371
+ * generation drops the sockets its gather options exclude at the commit,
1372
+ * so its checks never use them. A kept TURN allocation serves it only when
1373
+ * the generation still uses that TURN server, credential and transport (any of its
1374
+ * TURN servers): one whose server was removed or replaced (a credential
1375
+ * rotation) is not part of it.
1376
+ */
1377
+ allowsProvisional(generation, protocol) {
1378
+ const options = generation.gatherOptions ?? this.options;
1379
+ if (!protocol.localCandidate ||
1380
+ !(0, iceBase_1.isCandidateAllowedByGatherOptions)(protocol.localCandidate, options)) {
1381
+ return false;
1382
+ }
1383
+ if (protocol instanceof protocol_2.StunOverTurnProtocol) {
1384
+ const { configuredServer, username, password } = protocol.turn;
1385
+ return (0, iceBase_1.normalizeIceServerOptions)(options).turnServers.some((server) => configuredServer[0] === server.address[0] &&
1386
+ configuredServer[1] === server.address[1] &&
1387
+ username === server.username &&
1388
+ password === server.password &&
1389
+ protocol.configuredTransport === server.transport);
1390
+ }
1391
+ return true;
1392
+ }
1317
1393
  /** A copy of `candidate` labelled with the current generation and ufrag. */
1318
1394
  withGeneration(candidate) {
1319
1395
  return new candidate_1.Candidate(candidate.foundation, candidate.component, candidate.transport, candidate.priority, candidate.host, candidate.port, candidate.type, candidate.relatedAddress, candidate.relatedPort, candidate.tcptype, this.generation, this.localUsername);
1320
1396
  }
1321
1397
  /** Whether gathering contacts a STUN or TURN server (more than re-advertising sockets). */
1322
1398
  get gathersFromServers() {
1323
- return !!this.stunServer || !!this.turnServer;
1399
+ return this.stunServers.length > 0 || this.turnServers.length > 0;
1324
1400
  }
1325
1401
  appendLocalCandidate(candidate) {
1326
1402
  this.localCandidates.push(candidate);
@@ -1336,6 +1412,17 @@ class Connection {
1336
1412
  // 相手にとってのremoteは自分にとってのlocal
1337
1413
  const { remoteUsername: localUsername } = decodeTxUsername(txUsername);
1338
1414
  const localPassword = this.userHistory[localUsername] ?? this.localPassword;
1415
+ // A check for the staged generation on a socket it drops at the commit
1416
+ // (a host socket under a relay-only policy, a TURN allocation whose
1417
+ // server was removed or replaced) is not answered: the socket is not
1418
+ // part of that generation.
1419
+ const staged = this.provisional;
1420
+ if (staged &&
1421
+ localUsername === staged.localUsername &&
1422
+ localUsername !== this.localUsername &&
1423
+ !this.allowsProvisional(staged, protocol)) {
1424
+ return;
1425
+ }
1339
1426
  const { iceControlling } = this;
1340
1427
  // 7.2.1.1. Detecting and Repairing Role Conflicts
1341
1428
  if (iceControlling && msg.attributesKeys.includes("ICE-CONTROLLING")) {
@@ -1430,14 +1517,15 @@ class Connection {
1430
1517
  // opened for a replaced generation (or a closed agent) is closed, and
1431
1518
  // nothing is added to the current one.
1432
1519
  const stale = () => !this.isGathering(generation);
1433
- const { stunServer, turnServer } = this;
1434
- const { turnUsername, turnPassword, interfaceAddresses } = this.options;
1520
+ const { stunServers, turnServers } = this;
1521
+ const { interfaceAddresses } = this.options;
1435
1522
  const gatherIceLite = this.iceLite;
1436
- const gatherRelayOnly = !gatherIceLite &&
1437
- this.options.forceTurn &&
1438
- turnServer &&
1439
- turnUsername &&
1440
- turnPassword;
1523
+ const gatherRelayOnly = (0, iceBase_1.isRelayOnlyGathering)(this.options);
1524
+ // TCP host candidates are kept per address like the UDP ones, but on
1525
+ // their own: a restart that turned useTcp on gathers them for addresses
1526
+ // whose UDP sockets were kept.
1527
+ const tcpAddresses = addresses.filter((address) => !this.protocols.some((protocol) => protocol.localCandidate?.transport.toLowerCase() === "tcp" &&
1528
+ protocol.localIp === address));
1441
1529
  addresses = addresses.filter((address) => {
1442
1530
  // ice restartで同じアドレスが追加されるのを防ぐ
1443
1531
  if (this.protocols.find((protocol) => protocol.localIp === address)) {
@@ -1509,7 +1597,7 @@ class Connection {
1509
1597
  candidatePromises.push(...localStunPromises.map((localPromise) => localPromise.then((protocol) => protocol?.localCandidate)));
1510
1598
  }
1511
1599
  if (!gatherRelayOnly && this.options.useTcp) {
1512
- const tcpCandidatePromises = addresses.map(async (address) => {
1600
+ const tcpCandidatePromises = tcpAddresses.map(async (address) => {
1513
1601
  // Passive candidates open a listening TCP server; skip them when the
1514
1602
  // agent only makes outbound connections (tcpPassive === false). Active
1515
1603
  // candidates below still dial out, so direct TCP egress is unaffected.
@@ -1549,119 +1637,149 @@ class Connection {
1549
1637
  });
1550
1638
  candidatePromises.push(...tcpCandidatePromises);
1551
1639
  }
1552
- if (!gatherIceLite && !gatherRelayOnly && stunServer) {
1553
- // Sockets kept across an ICE restart query STUN again. The mapping they
1554
- // already advertised is in the new generation from the start; a
1555
- // different fresh mapping (the NAT rebound) is added to it.
1640
+ // A server-reflexive query of one socket to one STUN server, bounded by
1641
+ // the STUN gather timeout; an unanswered one yields nothing.
1642
+ const queryReflexive = async (protocol, server) => {
1643
+ let timer;
1644
+ const candidate = await Promise.race([
1645
+ (0, iceBase_1.serverReflexiveCandidate)(protocol, server).catch((error) => {
1646
+ log("query STUN server", server, error);
1647
+ return undefined;
1648
+ }),
1649
+ new Promise((resolve) => {
1650
+ timer = setTimeout(() => resolve(undefined), timeout * 1000);
1651
+ }),
1652
+ ]);
1653
+ clearTimeout(timer);
1654
+ return candidate;
1655
+ };
1656
+ // RFC 8445 §5.1.3: a mapping equal to one the socket already advertised
1657
+ // (same base, same transport address) is redundant.
1658
+ const sameMapping = (a, b) => a.host === b.host && a.port === b.port;
1659
+ if (!gatherIceLite && !gatherRelayOnly && stunServers.length > 0) {
1660
+ // Sockets kept across an ICE restart query every STUN server again.
1661
+ // The mappings they already advertised are in the new generation from
1662
+ // the start; a different fresh mapping (the NAT rebound) is added to
1663
+ // it, and the fresh mappings replace the kept ones for the next restart.
1556
1664
  const reusedReflexivePromises = reusedStunProtocols
1557
1665
  .filter((protocol) => (0, net_1.isIPv4)(protocol.localCandidate.host))
1558
1666
  .map(async (protocol) => {
1559
- let timer;
1560
- const fresh = await Promise.race([
1561
- (0, iceBase_1.serverReflexiveCandidate)(protocol, stunServer).catch(() => undefined),
1562
- new Promise((resolve) => {
1563
- timer = setTimeout(() => resolve(undefined), timeout * 1000);
1564
- }),
1565
- ]);
1566
- clearTimeout(timer);
1667
+ const previous = this.reflexiveBySocket.get(protocol) ?? [];
1668
+ const advertised = [...previous];
1669
+ const fresh = [];
1670
+ await Promise.all(stunServers.map(async (server) => {
1671
+ const candidate = await queryReflexive(protocol, server);
1672
+ if (!candidate || stale())
1673
+ return;
1674
+ if (!fresh.some((known) => sameMapping(known, candidate))) {
1675
+ fresh.push(candidate);
1676
+ }
1677
+ if (advertised.some((known) => sameMapping(known, candidate))) {
1678
+ return;
1679
+ }
1680
+ advertised.push(candidate);
1681
+ this.appendLocalCandidate(candidate);
1682
+ }));
1567
1683
  if (stale())
1568
1684
  return;
1569
- const previous = this.reflexiveBySocket.get(protocol);
1570
- if (fresh &&
1571
- (fresh.host !== previous?.host || fresh.port !== previous?.port)) {
1685
+ if (fresh.length > 0)
1572
1686
  this.reflexiveBySocket.set(protocol, fresh);
1573
- this.appendLocalCandidate(fresh);
1574
- }
1575
- return fresh ?? previous;
1576
- });
1687
+ return fresh.length > 0 ? fresh : previous;
1688
+ })
1689
+ .map((promise) => promise.catch((error) => {
1690
+ log("query STUN server", error);
1691
+ }));
1577
1692
  candidatePromises.push(...reusedReflexivePromises);
1693
+ // Every new IPv4 socket queries every STUN server in parallel.
1578
1694
  const stunCandidatePromises = localStunPromises.map(async (protocolPromise) => {
1579
1695
  const protocol = await protocolPromise;
1580
- if (!protocol)
1696
+ if (!protocol?.localCandidate ||
1697
+ !(0, net_1.isIPv4)(protocol.localCandidate.host))
1581
1698
  return;
1582
- const stunCandidatePromise = new Promise(async (r, f) => {
1583
- const timer = setTimeout(f, timeout * 1000);
1584
- if (protocol.localCandidate?.host &&
1585
- (0, net_1.isIPv4)(protocol.localCandidate?.host)) {
1586
- const candidate = await (0, iceBase_1.serverReflexiveCandidate)(protocol, stunServer).catch((error) => {
1587
- log("error", error);
1588
- });
1589
- if (candidate && !stale()) {
1590
- this.reflexiveBySocket.set(protocol, candidate);
1591
- this.appendLocalCandidate(candidate);
1592
- }
1593
- clearTimeout(timer);
1594
- r(candidate);
1595
- }
1596
- else {
1597
- clearTimeout(timer);
1598
- r();
1699
+ const advertised = [];
1700
+ await Promise.all(stunServers.map(async (server) => {
1701
+ const candidate = await queryReflexive(protocol, server);
1702
+ if (!candidate || stale())
1703
+ return;
1704
+ if (advertised.some((known) => sameMapping(known, candidate))) {
1705
+ return;
1599
1706
  }
1600
- }).catch((error) => {
1707
+ advertised.push(candidate);
1708
+ this.reflexiveBySocket.set(protocol, advertised);
1709
+ this.appendLocalCandidate(candidate);
1710
+ })).catch((error) => {
1601
1711
  log("query STUN server", error);
1602
1712
  });
1603
- return stunCandidatePromise;
1713
+ return advertised;
1604
1714
  });
1605
1715
  candidatePromises.push(...stunCandidatePromises);
1606
1716
  }
1607
- if (!gatherIceLite && turnServer && turnUsername && turnPassword) {
1608
- const turnCandidatePromise = (async () => {
1609
- const turnTransport = this.options.turnTransport ?? "udp";
1610
- const protocol = await (0, protocol_2.createStunOverTurnClient)({
1611
- address: turnServer,
1612
- username: turnUsername,
1613
- password: turnPassword,
1614
- }, {
1717
+ if (!gatherIceLite) {
1718
+ // Every TURN server gets its own allocation, made with its own
1719
+ // credential and transport; one that fails does not stop the others.
1720
+ const turnCandidatePromises = turnServers.map((server) => this.gatherRelayCandidate(server, gatherRelayOnly, stale).catch((error) => {
1721
+ log("query TURN server", server.address, error);
1722
+ }));
1723
+ candidatePromises.push(...turnCandidatePromises);
1724
+ }
1725
+ return candidatePromises;
1726
+ }
1727
+ /**
1728
+ * Allocate on one TURN server and add its relay candidate. A UDP
1729
+ * allocation that fails falls back to TCP on the same server. An
1730
+ * allocation that completes for a replaced generation (or a closed agent)
1731
+ * is released.
1732
+ */
1733
+ async gatherRelayCandidate(server, relayOnly, stale) {
1734
+ const { address, username, password, transport } = server;
1735
+ const protocol = await (0, protocol_2.createStunOverTurnClient)({ address, username, password }, {
1736
+ portRange: this.options.portRange,
1737
+ interfaceAddresses: this.options.interfaceAddresses,
1738
+ transport,
1739
+ tlsOptions: this.options.turnTlsOptions,
1740
+ connectTimeoutMs: (this.options.turnConnectTimeout ?? 8) * 1000,
1741
+ udpFamily: this.options.turnUdpFamily,
1742
+ signal: this.closing.signal,
1743
+ }).catch(async (e) => {
1744
+ // close() cancelled the allocation: no TCP fallback.
1745
+ if (transport === "udp" && !this.closing.signal.aborted) {
1746
+ return await (0, protocol_2.createStunOverTurnClient)({ address, username, password }, {
1615
1747
  portRange: this.options.portRange,
1616
1748
  interfaceAddresses: this.options.interfaceAddresses,
1617
- transport: turnTransport,
1618
- tlsOptions: this.options.turnTlsOptions,
1749
+ transport: "tcp",
1619
1750
  connectTimeoutMs: (this.options.turnConnectTimeout ?? 8) * 1000,
1620
- udpFamily: this.options.turnUdpFamily,
1621
1751
  signal: this.closing.signal,
1622
- }).catch(async (e) => {
1623
- // close() cancelled the allocation: no TCP fallback.
1624
- if (turnTransport === "udp" && !this.closing.signal.aborted) {
1625
- return await (0, protocol_2.createStunOverTurnClient)({
1626
- address: turnServer,
1627
- username: turnUsername,
1628
- password: turnPassword,
1629
- }, {
1630
- portRange: this.options.portRange,
1631
- interfaceAddresses: this.options.interfaceAddresses,
1632
- transport: "tcp",
1633
- connectTimeoutMs: (this.options.turnConnectTimeout ?? 8) * 1000,
1634
- signal: this.closing.signal,
1635
- });
1636
- }
1637
- else {
1638
- throw e;
1639
- }
1640
1752
  });
1641
- if (stale()) {
1642
- // The allocation never joins a generation: release it (and its
1643
- // refresh timer) instead of keeping a second one alive.
1644
- await protocol.close();
1645
- return;
1646
- }
1647
- this.ensureProtocol(protocol);
1648
- this.protocols.push(protocol);
1649
- const candidateAddress = protocol.turn.relayedAddress;
1650
- const relatedAddress = protocol.turn.mappedAddress;
1651
- log("turn candidateAddress", candidateAddress);
1652
- protocol.localCandidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("relay", "udp", candidateAddress[0]), 1, "udp", (0, candidate_1.candidatePriority)("relay"), candidateAddress[0], candidateAddress[1], "relay", relatedAddress[0], relatedAddress[1], undefined, this.generation, this.localUsername);
1653
- // An allocation that completes after the remote candidates arrived
1654
- // (early signaling, or an ICE restart that allocates afresh) pairs
1655
- // with them; a connect() already running schedules the new pairs.
1656
- this.pairLocalProtocol(protocol);
1657
- this.appendLocalCandidate(protocol.localCandidate);
1658
- return protocol.localCandidate;
1659
- })().catch((error) => {
1660
- log("query TURN server", error);
1661
- });
1662
- candidatePromises.push(turnCandidatePromise);
1753
+ }
1754
+ else {
1755
+ throw e;
1756
+ }
1757
+ });
1758
+ if (stale()) {
1759
+ // The allocation never joins a generation: release it (and its
1760
+ // refresh timer) instead of keeping a second one alive.
1761
+ await protocol.close();
1762
+ return;
1663
1763
  }
1664
- return candidatePromises;
1764
+ protocol.configuredTransport = transport;
1765
+ this.ensureProtocol(protocol);
1766
+ this.protocols.push(protocol);
1767
+ const candidateAddress = protocol.turn.relayedAddress;
1768
+ // The related address of a relay candidate is the address the TURN
1769
+ // server saw the agent at. A relay-only policy hides the agent's
1770
+ // addresses from the peer, so it advertises the unspecified address
1771
+ // and port 9 instead (RFC 8839 §5.1), in SDP and trickle alike.
1772
+ const relatedAddress = relayOnly
1773
+ ? [(0, net_1.isIPv4)(candidateAddress[0]) ? "0.0.0.0" : "::", 9]
1774
+ : protocol.turn.mappedAddress;
1775
+ log("turn candidateAddress", candidateAddress);
1776
+ protocol.localCandidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("relay", "udp", candidateAddress[0]), 1, "udp", (0, candidate_1.candidatePriority)("relay"), candidateAddress[0], candidateAddress[1], "relay", relatedAddress[0], relatedAddress[1], undefined, this.generation, this.localUsername);
1777
+ // An allocation that completes after the remote candidates arrived
1778
+ // (early signaling, or an ICE restart that allocates afresh) pairs
1779
+ // with them; a connect() already running schedules the new pairs.
1780
+ this.pairLocalProtocol(protocol);
1781
+ this.appendLocalCandidate(protocol.localCandidate);
1782
+ return protocol.localCandidate;
1665
1783
  }
1666
1784
  async connect() {
1667
1785
  // """
@@ -1764,7 +1882,7 @@ class Connection {
1764
1882
  // # find the highest-priority pair that is in the waiting state
1765
1883
  const pair = this.checkList
1766
1884
  .filter((pair) => {
1767
- if (this.options.forceTurn &&
1885
+ if ((0, iceBase_1.isRelayOnlyGathering)(this.options) &&
1768
1886
  pair.protocol.type === protocol_1.StunProtocol.type)
1769
1887
  return false;
1770
1888
  return true;
@@ -1851,11 +1969,17 @@ class Connection {
1851
1969
  // """
1852
1970
  // Close the connection.
1853
1971
  // """
1972
+ this.closed = true;
1854
1973
  this.setState("closed");
1855
1974
  this.signalClosed();
1856
1975
  this.closing.abort();
1857
1976
  this.cancelChecks();
1858
1977
  this.endProvisional();
1978
+ // Before the first await: a pending mDNS lookup is cancelled here, so no
1979
+ // response arriving while the protocols close adds a remote candidate.
1980
+ this.lookup?.close?.();
1981
+ this.lookup = undefined;
1982
+ this.remoteResolutions.clear();
1859
1983
  // # stop consent freshness tests
1860
1984
  this.stopConsentLifecycle();
1861
1985
  // # stop check list
@@ -1872,8 +1996,6 @@ class Connection {
1872
1996
  }
1873
1997
  this.protocols = [];
1874
1998
  this.localCandidates = [];
1875
- this.lookup?.close?.();
1876
- this.lookup = undefined;
1877
1999
  }
1878
2000
  setState(state) {
1879
2001
  this.state = state;
@@ -1893,6 +2015,9 @@ class Connection {
1893
2015
  // To signal end-of-candidates, pass `None`.
1894
2016
  // :param remote_candidate: A :class:`Candidate` instance or `None`.
1895
2017
  // """
2018
+ // A closed agent takes no candidate (and opens no mDNS socket).
2019
+ if (this.closed)
2020
+ return;
1896
2021
  if (!remoteCandidate) {
1897
2022
  if (this.remoteCandidatesEnd || this.remoteCandidatesEndRequested) {
1898
2023
  return;
@@ -1902,7 +2027,7 @@ class Connection {
1902
2027
  if (this.remoteResolutions.size > 0) {
1903
2028
  const generation = this.remoteGeneration;
1904
2029
  await Promise.allSettled([...this.remoteResolutions]);
1905
- if (this.remoteGeneration !== generation)
2030
+ if (this.remoteGeneration !== generation || this.closed)
1906
2031
  return;
1907
2032
  }
1908
2033
  this.remoteCandidatesEnd = true;
@@ -1930,8 +2055,10 @@ class Connection {
1930
2055
  catch (error) {
1931
2056
  return;
1932
2057
  }
1933
- // An ICE restart or completion while resolving ends this candidate's generation.
1934
- if (this.remoteGeneration !== generation || this.remoteCandidatesEnd)
2058
+ // An ICE restart, completion or close while resolving ends this candidate's generation.
2059
+ if (this.remoteGeneration !== generation ||
2060
+ this.remoteCandidatesEnd ||
2061
+ this.closed)
1935
2062
  return;
1936
2063
  }
1937
2064
  try {
@@ -2035,7 +2162,10 @@ class Connection {
2035
2162
  // nominated pairs for that media stream.
2036
2163
  for (const p of this.checkList) {
2037
2164
  if (p.component === pair.component &&
2038
- [iceBase_1.CandidatePairState.WAITING, iceBase_1.CandidatePairState.FROZEN].includes(p.state)) {
2165
+ [
2166
+ iceBase_1.CandidatePairState.WAITING,
2167
+ iceBase_1.CandidatePairState.FROZEN,
2168
+ ].includes(p.state)) {
2039
2169
  p.updateState(iceBase_1.CandidatePairState.FAILED);
2040
2170
  }
2041
2171
  }
@@ -2066,7 +2196,10 @@ class Connection {
2066
2196
  return;
2067
2197
  }
2068
2198
  {
2069
- const list = [iceBase_1.CandidatePairState.SUCCEEDED, iceBase_1.CandidatePairState.FAILED];
2199
+ const list = [
2200
+ iceBase_1.CandidatePairState.SUCCEEDED,
2201
+ iceBase_1.CandidatePairState.FAILED,
2202
+ ];
2070
2203
  if (this.checkList.find(({ state }) => !list.includes(state))) {
2071
2204
  return;
2072
2205
  }
@@ -2249,7 +2382,10 @@ class Connection {
2249
2382
  return;
2250
2383
  }
2251
2384
  // 7.2.1.4. Triggered Checks
2252
- if ([iceBase_1.CandidatePairState.WAITING, iceBase_1.CandidatePairState.FAILED].includes(pair.state)) {
2385
+ if ([
2386
+ iceBase_1.CandidatePairState.WAITING,
2387
+ iceBase_1.CandidatePairState.FAILED,
2388
+ ].includes(pair.state)) {
2253
2389
  pair.handle = this.checkStart(pair);
2254
2390
  }
2255
2391
  // 7.2.1.5. Updating the Nominated Flag