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
@@ -4,11 +4,12 @@ exports.RTCIceParameters = exports.IceCandidate = exports.RTCIceCandidate = expo
4
4
  exports.candidateFromIce = candidateFromIce;
5
5
  exports.candidateToIce = candidateToIce;
6
6
  const crypto_1 = require("crypto");
7
- const common_1 = require("../imports/common");
8
7
  const src_1 = require("../../../ice/src");
9
8
  const helper_1 = require("../helper");
9
+ const common_1 = require("../imports/common");
10
10
  const stats_1 = require("../media/stats");
11
11
  const sdp_1 = require("../sdp");
12
+ const iceCandidateAttribute_1 = require("./iceCandidateAttribute");
12
13
  const log = (0, common_1.debug)("werift:packages/webrtc/src/transport/ice.ts");
13
14
  function mapCandidatePairState(state) {
14
15
  switch (state) {
@@ -27,26 +28,63 @@ function mapCandidatePairState(state) {
27
28
  }
28
29
  }
29
30
  /**
30
- * +------------+
31
- | |
32
- |disconnected|
33
- | |
34
- +------------+
35
- ^ ^
36
- | |
37
- +------+ +----------+ +-----------+ +----------+
38
- | | | | | | | |
39
- | new | ---> | checking | ---> | connected | ---> | completed|
40
- | | | | | | | |
41
- +------+ +----+-----+ +-----------+ +----------+
42
- |
43
- |
44
- v
45
- +-------+
46
- | |
47
- | failed|
48
- | |
49
- +-------+
31
+ * ICE generations of one transport. An ICE restart (new ufrag/pwd without a
32
+ * BUNDLE topology change) keeps the transport, its sockets and its DTLS
33
+ * association: no role renegotiation, no second handshake (RFC 8842, JSEP).
34
+ * Only a BUNDLE owner change creates a separate pending transport.
35
+ *
36
+ * Restart generations are registered by ufrag (`localGenerationFor`): the
37
+ * latest created offer and the latest created answer each keep theirs until a
38
+ * newer description of the same kind replaces it, whatever is applied, rolled
39
+ * back or committed meanwhile. Applying a description selects the generation
40
+ * its SDP carries, and the final answer switches exactly that one. A new offer
41
+ * reuses the applied pending offer's generation (JSEP 5.2.1) unless
42
+ * `restartIce()` asked to replace it; an answer created again reuses the
43
+ * earlier answer's (JSEP 5.3.1).
44
+ *
45
+ * Provisional generation: while a restart of an established transport is
46
+ * negotiated, a second checklist runs beside the live one on the same sockets.
47
+ * It only exchanges STUN checks; RTP and DataChannel stay on the live selected
48
+ * pair, and it follows the live checklist's rules (pair filter, ICE-lite,
49
+ * nomination, staged-password error responses).
50
+ *
51
+ * - Created when the restart credentials are staged (`stageLocalRestart`): by
52
+ * `createOffer()` while a `restartIce()` request stands, or by
53
+ * `createAnswer()` for a remote offer that changes a live transport's ufrag.
54
+ * It then answers checks for that ufrag.
55
+ * - Fed by the pranswer with the peer's credentials, candidates and
56
+ * end-of-candidates (`setProvisionalRemoteParams`,
57
+ * `addProvisionalRemoteCandidate`); a replacement pranswer restarts it.
58
+ * - Checks start when the pranswer is applied (`startProvisionalChecks`); the
59
+ * controlling side nominates a provisional pair, but the live selected pair
60
+ * and send target never change. A response for an earlier checklist is
61
+ * ignored.
62
+ * - Ends at the final answer, which recreates the live agent with the staged
63
+ * credentials and checks the answered generation from scratch, or at
64
+ * rollback / a replacement offer / selecting another generation, which
65
+ * stops its checks and keeps the live generation.
66
+ *
67
+ * A first negotiation and transports created for a proposal have no
68
+ * provisional generation; they connect normally from the pranswer. The
69
+ * staged-credential methods of `IceConnection` are optional: without them a
70
+ * restart still happens at the final answer, without provisional checks.
71
+ *
72
+ * A restart generation's candidates are fixed when its description is
73
+ * created (host candidates of the kept sockets and their server-reflexive
74
+ * addresses) and are re-advertised at the commit without waiting. With STUN
75
+ * or TURN servers the description carries neither the relay candidate nor
76
+ * end-of-candidates: after the commit the generation gathers again (a new TURN
77
+ * allocation replaces and closes the previous one) and trickles them. A
78
+ * restart's background gathering that a later restart or `close()` replaced
79
+ * signals nothing more. ICE server settings changed after gathering take
80
+ * effect at the next restart (JSEP 4.1.18): the restart generation carries
81
+ * only the kept candidates a fresh gathering with them would produce (none
82
+ * but relay for a relay-only policy, no TCP host candidates without useTcp),
83
+ * in its description and at the commit alike. Settings changed after the
84
+ * description was created still apply to that restart's gathering at the
85
+ * commit: a kept socket they exclude is closed then, so a candidate the
86
+ * description announced for it fails its checks. The old selected pair is
87
+ * dropped at the commit, so RTP pauses until the new generation nominates.
50
88
  */
51
89
  class RTCIceTransport {
52
90
  constructor(iceGather) {
@@ -54,7 +92,7 @@ class RTCIceTransport {
54
92
  enumerable: true,
55
93
  configurable: true,
56
94
  writable: true,
57
- value: iceGather
95
+ value: void 0
58
96
  });
59
97
  Object.defineProperty(this, "id", {
60
98
  enumerable: true,
@@ -92,12 +130,89 @@ class RTCIceTransport {
92
130
  writable: true,
93
131
  value: void 0
94
132
  });
133
+ Object.defineProperty(this, "startPromise", {
134
+ enumerable: true,
135
+ configurable: true,
136
+ writable: true,
137
+ value: void 0
138
+ });
139
+ /**
140
+ * Connectivity checks were started for the current generation. A restart
141
+ * resets it; the state alone cannot tell (an agent that finished gathering
142
+ * reports "completed" before any check ran).
143
+ * @internal
144
+ */
145
+ Object.defineProperty(this, "checksStarted", {
146
+ enumerable: true,
147
+ configurable: true,
148
+ writable: true,
149
+ value: false
150
+ });
95
151
  Object.defineProperty(this, "renominating", {
96
152
  enumerable: true,
97
153
  configurable: true,
98
154
  writable: true,
99
155
  value: false
100
156
  });
157
+ /**
158
+ * The restart generation selected for the description being created or
159
+ * applied (the one createOffer / createAnswer put in its SDP, or the one an
160
+ * applied description carries).
161
+ */
162
+ Object.defineProperty(this, "stagedLocalRestart", {
163
+ enumerable: true,
164
+ configurable: true,
165
+ writable: true,
166
+ value: void 0
167
+ });
168
+ /**
169
+ * The restart generations the latest created offer and the latest created
170
+ * answer carry, by ufrag (their generation records). One stays registered
171
+ * until a newer description of the same kind replaces it (unless an
172
+ * applied description still carries it) or the transport stops, whatever
173
+ * is applied, rolled back or committed meanwhile; applying a description
174
+ * that carries it selects it (an ICE restart to those credentials on the
175
+ * kept sockets).
176
+ */
177
+ Object.defineProperty(this, "localGenerations", {
178
+ enumerable: true,
179
+ configurable: true,
180
+ writable: true,
181
+ value: new Map()
182
+ });
183
+ /**
184
+ * The staged generation an applied description (pending local offer, or a
185
+ * remote offer being answered) carries. It stays until that description is
186
+ * committed, replaced or rolled back; an unapplied createOffer cannot drop it.
187
+ */
188
+ Object.defineProperty(this, "appliedLocalRestart", {
189
+ enumerable: true,
190
+ configurable: true,
191
+ writable: true,
192
+ value: void 0
193
+ });
194
+ /**
195
+ * Gatherer events of an ICE restart committed by a local answer, held until
196
+ * that answer is applied (`emitCommittedCandidates`), in their order: the
197
+ * re-advertised candidates first, then what the servers add and
198
+ * end-of-candidates.
199
+ */
200
+ Object.defineProperty(this, "heldCandidateEvents", {
201
+ enumerable: true,
202
+ configurable: true,
203
+ writable: true,
204
+ value: void 0
205
+ });
206
+ /**
207
+ * ICE servers set (setConfiguration) after this transport gathered. They
208
+ * apply to the next gathering, that is the next ICE restart (JSEP 4.1.18).
209
+ */
210
+ Object.defineProperty(this, "nextGatherIceServers", {
211
+ enumerable: true,
212
+ configurable: true,
213
+ writable: true,
214
+ value: void 0
215
+ });
101
216
  Object.defineProperty(this, "events", {
102
217
  enumerable: true,
103
218
  configurable: true,
@@ -168,12 +283,16 @@ class RTCIceTransport {
168
283
  }
169
284
  }
170
285
  });
286
+ this.iceGather = iceGather;
171
287
  this.connection = this.iceGather.connection;
172
288
  this.connection.stateChanged.subscribe((state) => {
173
289
  this.setState(state);
174
290
  });
175
291
  this.iceGather.onIceCandidate = (candidate) => {
176
- this.onIceCandidate.execute(candidate);
292
+ if (this.heldCandidateEvents)
293
+ this.heldCandidateEvents.push(candidate);
294
+ else
295
+ this.onIceCandidate.execute(candidate);
177
296
  };
178
297
  this.iceGather.onGatheringStateChange.subscribe(() => {
179
298
  this.ongatheringstatechange?.();
@@ -193,10 +312,301 @@ class RTCIceTransport {
193
312
  return this.iceGather.gatheringState;
194
313
  }
195
314
  get localCandidates() {
196
- return this.iceGather.localCandidates;
315
+ return this.describedLocalGeneration().candidates;
316
+ }
317
+ /** Whether the local description may carry `a=end-of-candidates`. */
318
+ get localCandidatesComplete() {
319
+ return this.describedLocalGeneration().complete;
320
+ }
321
+ /**
322
+ * The local ICE generation a description carries: its credentials,
323
+ * candidates and whether they are complete. A description being created
324
+ * carries a staged restart. One already applied (refreshed when the live
325
+ * generation gathers more) carries the staged restart only if it applied
326
+ * it; a later createOffer() that staged another generation without applying
327
+ * it does not change an applied description.
328
+ * @internal
329
+ */
330
+ describedLocalGeneration({ applied = false } = {}) {
331
+ const staged = this.stagedLocalRestart;
332
+ if (!staged || (applied && staged !== this.appliedLocalRestart)) {
333
+ return {
334
+ parameters: this.iceGather.localParameters,
335
+ candidates: this.iceGather.localCandidates,
336
+ // The gatherer signals end-of-candidates (and the description that
337
+ // records it refreshes) just before its state becomes "complete".
338
+ complete: this.gatheringState === "complete" ||
339
+ this.connection.localCandidatesEnd,
340
+ };
341
+ }
342
+ const pending = this.stagedGatherPending();
343
+ return {
344
+ parameters: new RTCIceParameters({
345
+ iceLite: this.connection.iceLite,
346
+ usernameFragment: staged.usernameFragment,
347
+ password: staged.password,
348
+ }),
349
+ candidates: pending
350
+ ? staged.candidates.filter((candidate) => candidate.type !== "relay")
351
+ : staged.candidates,
352
+ complete: this.gatheringState === "complete" && !pending,
353
+ };
354
+ }
355
+ /**
356
+ * A staged restart whose generation keeps gathering from its servers after
357
+ * the commit; its relay candidates and end-of-candidates come then.
358
+ */
359
+ stagedGatherPending() {
360
+ const staged = this.stagedLocalRestart;
361
+ if (!staged)
362
+ return false;
363
+ if (staged.emitted)
364
+ return !!staged.endDeferred;
365
+ return !!this.nextGatherIceServers || !!this.connection.gathersFromServers;
197
366
  }
198
367
  get localParameters() {
199
- return this.iceGather.localParameters;
368
+ return this.describedLocalGeneration().parameters;
369
+ }
370
+ /**
371
+ * Prepare an ICE generation for SDP without touching the selected pair.
372
+ * `answering` is the remote offer an answer is created for.
373
+ */
374
+ stageLocalRestart({ answering, replacing, } = {}) {
375
+ // The generation a description of this kind already carries is reused,
376
+ // whatever was selected since: a new offer reuses the one of the pending
377
+ // applied offer (JSEP 5.2.1) unless restartIce() asked to replace it, and
378
+ // an answer created again for the same remote offer reuses the one the
379
+ // earlier answer carries (JSEP 5.3.1).
380
+ const applied = this.appliedLocalRestart;
381
+ const reused = answering
382
+ ? [...this.localGenerations.values()].find((generation) => generation.answering === answering)
383
+ : applied && !replacing?.has(applied.usernameFragment)
384
+ ? applied
385
+ : undefined;
386
+ if (reused) {
387
+ this.selectGeneration(reused);
388
+ return;
389
+ }
390
+ this.unselectLocalRestart();
391
+ const usernameFragment = (0, crypto_1.randomBytes)(6).toString("base64url");
392
+ const random = (0, crypto_1.randomBytes)(24).toString("base64url");
393
+ // The configured prefix (icePasswordPrefix) marks every generation's
394
+ // password, as the agent's own restart does.
395
+ const prefix = this.connection.options.localPasswordPrefix ?? "";
396
+ const password = prefix + random.slice(prefix.length);
397
+ // The generation gathers with the options set for it (a relay-only
398
+ // policy, useTcp turned off), so it carries only the kept candidates a
399
+ // fresh gathering with them would produce; the agent re-advertises the
400
+ // same ones at the commit.
401
+ const iceServers = this.nextGatherIceServers;
402
+ const gatherOptions = iceServers
403
+ ? (0, src_1.mergeIceServerOptions)(this.connection.options, iceServers)
404
+ : this.connection.options;
405
+ const candidates = this.iceGather.localCandidates
406
+ .filter((candidate) => (0, src_1.isCandidateAllowedByGatherOptions)({ type: candidate.type, transport: candidate.protocol }, gatherOptions))
407
+ .map((candidate) => {
408
+ const copy = Object.assign(new IceCandidate(candidate.component, candidate.foundation, candidate.ip, candidate.port, candidate.priority, candidate.protocol, candidate.type, this.connection.generation + 1, usernameFragment), {
409
+ relatedAddress: candidate.relatedAddress,
410
+ relatedPort: candidate.relatedPort,
411
+ tcpType: candidate.tcpType,
412
+ });
413
+ return copy;
414
+ });
415
+ const generation = {
416
+ usernameFragment,
417
+ password,
418
+ candidates,
419
+ emitted: false,
420
+ answering,
421
+ createdBy: answering ? "answer" : "offer",
422
+ gatherOptions,
423
+ };
424
+ // The previous description of this kind is no longer the latest one.
425
+ for (const [ufrag, previous] of this.localGenerations) {
426
+ if (previous.createdBy === generation.createdBy &&
427
+ previous !== this.appliedLocalRestart) {
428
+ this.localGenerations.delete(ufrag);
429
+ }
430
+ }
431
+ this.localGenerations.set(usernameFragment, generation);
432
+ this.stagedLocalRestart = generation;
433
+ // Existing sockets can respond to provisional STUN checks for the new
434
+ // ufrag while the old generation continues to carry media.
435
+ this.connection.stageLocalCredentials?.(usernameFragment, password, gatherOptions);
436
+ }
437
+ /**
438
+ * The local generation a description with these credentials carries:
439
+ * `"live"` for the agent's current credentials, the restart generation the
440
+ * latest created offer or answer carries, or `undefined` when the
441
+ * credentials belong to no generation the transport can take.
442
+ * @internal
443
+ */
444
+ localGenerationFor(usernameFragment, password) {
445
+ const live = this.iceGather.localParameters;
446
+ if (live.usernameFragment === usernameFragment &&
447
+ live.password === password) {
448
+ return "live";
449
+ }
450
+ const generation = this.localGenerations.get(usernameFragment);
451
+ if (generation?.password === password)
452
+ return generation;
453
+ return undefined;
454
+ }
455
+ /**
456
+ * Select the local generation an applied description carries (see
457
+ * `localGenerationFor`). Returns false if the credentials belong to none.
458
+ * @internal
459
+ */
460
+ selectLocalGeneration(usernameFragment, password) {
461
+ const generation = this.localGenerationFor(usernameFragment, password);
462
+ if (!generation)
463
+ return false;
464
+ if (generation === "live") {
465
+ this.unselectLocalRestart();
466
+ return true;
467
+ }
468
+ this.selectGeneration(generation);
469
+ return true;
470
+ }
471
+ selectGeneration(generation) {
472
+ if (this.stagedLocalRestart === generation)
473
+ return;
474
+ this.unselectLocalRestart();
475
+ this.stagedLocalRestart = generation;
476
+ this.connection.stageLocalCredentials?.(generation.usernameFragment, generation.password, generation.gatherOptions);
477
+ }
478
+ /** Stop answering checks for the selected generation; it stays registered. */
479
+ unselectLocalRestart() {
480
+ const staged = this.stagedLocalRestart;
481
+ if (!staged)
482
+ return;
483
+ this.connection.discardStagedLocalCredentials?.(staged.usernameFragment);
484
+ this.stagedLocalRestart = undefined;
485
+ }
486
+ get hasStagedRestart() {
487
+ return !!this.stagedLocalRestart;
488
+ }
489
+ /** Feed a pranswer's ICE generation to the provisional checklist. */
490
+ setProvisionalRemoteParams(remoteParameters) {
491
+ if (!this.stagedLocalRestart)
492
+ return;
493
+ this.connection.setProvisionalRemoteParams?.(remoteParameters);
494
+ }
495
+ addProvisionalRemoteCandidate(candidate) {
496
+ if (!this.stagedLocalRestart)
497
+ return;
498
+ return this.connection.addProvisionalRemoteCandidate?.(candidate ? candidateToIce(candidate) : undefined);
499
+ }
500
+ /**
501
+ * Hand a remote candidate (`undefined`: end-of-candidates) to the ICE agent
502
+ * without waiting for it. A host candidate is added synchronously; an mDNS
503
+ * name may take seconds to resolve, and the agent itself orders that
504
+ * resolution against end-of-candidates and generation changes, so the
505
+ * description operation queue must not wait for it.
506
+ */
507
+ deliverRemoteCandidate(candidate) {
508
+ void Promise.resolve(this.addRemoteCandidate(candidate)).catch((error) => log("addRemoteCandidate failed", error));
509
+ }
510
+ /** `deliverRemoteCandidate` for the provisional (pranswer) generation. */
511
+ deliverProvisionalRemoteCandidate(candidate) {
512
+ void Promise.resolve(this.addProvisionalRemoteCandidate(candidate)).catch((error) => log("addProvisionalRemoteCandidate failed", error));
513
+ }
514
+ startProvisionalChecks() {
515
+ if (!this.stagedLocalRestart)
516
+ return;
517
+ this.connection.startProvisionalChecks?.();
518
+ }
519
+ emitStagedCandidates() {
520
+ const staged = this.stagedLocalRestart;
521
+ if (!staged || staged.emitted)
522
+ return;
523
+ const candidates = this.localCandidates;
524
+ staged.endDeferred = this.stagedGatherPending();
525
+ staged.emitted = true;
526
+ for (const candidate of candidates) {
527
+ // A copy: the listener rewrites the event's foundation and m-line,
528
+ // while these candidates still render the local description.
529
+ this.onIceCandidate.execute(Object.assign(Object.create(Object.getPrototypeOf(candidate)), candidate));
530
+ }
531
+ if (!staged.endDeferred)
532
+ this.onIceCandidate.execute(undefined);
533
+ }
534
+ rollbackLocalRestart() {
535
+ this.appliedLocalRestart = undefined;
536
+ // A description applying this generation again signals its candidates
537
+ // again (the remote side rolled back too).
538
+ if (this.stagedLocalRestart)
539
+ this.stagedLocalRestart.emitted = false;
540
+ this.unselectLocalRestart();
541
+ }
542
+ /** The staged generation now belongs to an applied description. */
543
+ markLocalRestartApplied() {
544
+ this.appliedLocalRestart = this.stagedLocalRestart;
545
+ }
546
+ /** Drop only what an unapplied createOffer staged; keep the applied one. */
547
+ discardUnappliedLocalRestart() {
548
+ const staged = this.stagedLocalRestart;
549
+ const applied = this.appliedLocalRestart;
550
+ if (!staged || staged === applied)
551
+ return;
552
+ this.unselectLocalRestart();
553
+ if (applied) {
554
+ this.stagedLocalRestart = applied;
555
+ this.connection.stageLocalCredentials?.(applied.usernameFragment, applied.password, applied.gatherOptions);
556
+ }
557
+ }
558
+ /**
559
+ * Called unconditionally on every answer; actually restarts ICE only if
560
+ * this transport has a staged local restart. No-op otherwise.
561
+ */
562
+ async commitLocalRestartIfStaged() {
563
+ const staged = this.stagedLocalRestart;
564
+ if (!staged)
565
+ return;
566
+ // The description already finalized this generation's candidates with
567
+ // end-of-candidates: it only re-advertises the kept sockets, and a server
568
+ // change waits for the next restart. Otherwise the generation keeps
569
+ // gathering from its servers (a fresh STUN mapping, a new TURN allocation)
570
+ // after the commit and trickles what they add.
571
+ const regather = this.stagedGatherPending();
572
+ this.restart(false, regather);
573
+ if (this.connection.commitLocalCredentials) {
574
+ this.connection.commitLocalCredentials(staged.usernameFragment, staged.password);
575
+ }
576
+ else {
577
+ this.connection.localUsername = staged.usernameFragment;
578
+ this.connection.localPassword = staged.password;
579
+ }
580
+ this.stagedLocalRestart = undefined;
581
+ this.appliedLocalRestart = undefined;
582
+ // A local answer signals its candidates after it is applied.
583
+ if (!staged.emitted)
584
+ this.heldCandidateEvents = [];
585
+ // The generation is live now. Its registration stays with the
586
+ // description that carries it (a later commit of another generation does
587
+ // not end it): applying that description again restarts to it, and its
588
+ // candidates are signalled again then.
589
+ staged.emitted = false;
590
+ staged.endDeferred = undefined;
591
+ // The kept sockets are re-advertised synchronously; nothing here waits
592
+ // for a server, so the commit never holds the new generation's checks.
593
+ const gathering = this.gather();
594
+ if (regather) {
595
+ void gathering.catch((error) => log("restart gathering failed", error));
596
+ }
597
+ else {
598
+ await gathering;
599
+ }
600
+ }
601
+ /** Signal the candidates an ICE restart committed by a local answer gathered. */
602
+ emitCommittedCandidates() {
603
+ const held = this.heldCandidateEvents;
604
+ if (!held)
605
+ return;
606
+ this.heldCandidateEvents = undefined;
607
+ for (const candidate of held) {
608
+ this.onIceCandidate.execute(candidate);
609
+ }
200
610
  }
201
611
  getRemoteCandidates() {
202
612
  return this.connection.remoteCandidates
@@ -231,6 +641,10 @@ class RTCIceTransport {
231
641
  });
232
642
  }
233
643
  setState(state, emitEvent = true) {
644
+ // closed is final: checks that stop() interrupted must not report
645
+ // "failed" (or anything else) afterwards.
646
+ if (this.state === "closed")
647
+ return;
234
648
  if (state !== this.state) {
235
649
  this.state = state;
236
650
  this.onStateChange.execute(state);
@@ -244,9 +658,20 @@ class RTCIceTransport {
244
658
  return this.iceGather.gather();
245
659
  }
246
660
  setIceServers(options) {
661
+ this.nextGatherIceServers = undefined;
247
662
  this.iceGather.setIceServers(options);
248
663
  }
249
- setRemoteParams(remoteParameters, renomination = false) {
664
+ /** Keep ICE servers for the next gathering (an ICE restart). */
665
+ deferIceServers(options) {
666
+ this.nextGatherIceServers = options;
667
+ }
668
+ /**
669
+ * `keepLocalCredentials`: the remote credentials come from an answer or
670
+ * pranswer, so the local ones are fixed by the applied local offer. Changed
671
+ * remote credentials restart the checks for the new remote generation
672
+ * without new local credentials (nothing would describe them to the peer).
673
+ */
674
+ setRemoteParams(remoteParameters, renomination = false, { keepLocalCredentials = false } = {}) {
250
675
  if (renomination) {
251
676
  this.renominating = true;
252
677
  }
@@ -257,8 +682,15 @@ class RTCIceTransport {
257
682
  if (this.renominating) {
258
683
  log("renomination", remoteParameters);
259
684
  this.connection.resetNominatedPair();
685
+ // The kept checklist holds only the new remote generation's
686
+ // candidates (and ones without a ufrag, as develop kept them).
687
+ this.connection.dropOtherRemoteGenerations?.(remoteParameters.usernameFragment);
260
688
  this.renominating = false;
261
689
  }
690
+ else if (keepLocalCredentials && this.connection.restartRemote) {
691
+ log("remote restart", remoteParameters);
692
+ this.resetRemoteGeneration();
693
+ }
262
694
  else {
263
695
  log("restart", remoteParameters);
264
696
  this.restart();
@@ -266,15 +698,35 @@ class RTCIceTransport {
266
698
  }
267
699
  this.connection.setRemoteParams(remoteParameters);
268
700
  }
269
- restart() {
701
+ /**
702
+ * Internal: drop the remote generation and its checks, keeping the local
703
+ * credentials and candidates a description already carries (a remote-only
704
+ * restart, or a proposal transport a replacement pranswer left unused).
705
+ */
706
+ resetRemoteGeneration() {
707
+ if (!this.connection.restartRemote)
708
+ return;
709
+ this.connection.restartRemote();
710
+ this.setState("new");
711
+ this.waitStart = undefined;
712
+ this.startPromise = undefined;
713
+ this.checksStarted = false;
714
+ }
715
+ restart(notifyNegotiation = true, applyNextGatherIceServers = true) {
270
716
  this.iceRestarts++;
271
717
  this.connection.restart();
718
+ const servers = this.nextGatherIceServers;
719
+ if (servers && applyNextGatherIceServers)
720
+ this.setIceServers(servers);
272
721
  this.setState("new");
273
722
  // Use setGatheringState so onGatheringStateChange fires and the
274
723
  // SecureTransportManager aggregate iceGatheringState stays in sync.
275
724
  this.iceGather.setGatheringState("new");
276
725
  this.waitStart = undefined;
277
- this.onNegotiationNeeded.execute();
726
+ this.startPromise = undefined;
727
+ this.checksStarted = false;
728
+ if (notifyNegotiation)
729
+ this.onNegotiationNeeded.execute();
278
730
  }
279
731
  async start() {
280
732
  if (this.state === "closed") {
@@ -283,23 +735,51 @@ class RTCIceTransport {
283
735
  if (!this.connection.remotePassword || !this.connection.remoteUsername) {
284
736
  throw new Error("remoteParams missing");
285
737
  }
286
- if (this.waitStart) {
287
- await this.waitStart.asPromise();
288
- }
289
- this.waitStart = new common_1.Event();
738
+ // Concurrent callers for the same generation share the active checks and
739
+ // their result. Waiting for the event and then continuing would start a
740
+ // second connection attempt after the first one settles.
741
+ if (this.startPromise)
742
+ return this.startPromise;
743
+ const waitStart = new common_1.Event();
744
+ this.waitStart = waitStart;
745
+ this.checksStarted = true;
290
746
  this.setState("checking");
291
- try {
292
- await this.connection.connect();
293
- }
294
- catch (error) {
747
+ const startPromise = Promise.resolve()
748
+ .then(() => this.connection.connect())
749
+ .catch((error) => {
295
750
  this.setState("failed");
296
751
  throw error;
297
- }
298
- this.waitStart.execute();
299
- this.waitStart.complete();
300
- this.waitStart = undefined;
752
+ })
753
+ .finally(() => {
754
+ // A failed start releases its waiters too.
755
+ waitStart.execute();
756
+ waitStart.complete();
757
+ if (this.waitStart === waitStart)
758
+ this.waitStart = undefined;
759
+ if (this.startPromise === startPromise)
760
+ this.startPromise = undefined;
761
+ });
762
+ this.startPromise = startPromise;
763
+ return startPromise;
764
+ }
765
+ /**
766
+ * Settles when the checks a running start() makes finish (at once if none run).
767
+ * @internal
768
+ */
769
+ async checksSettled() {
770
+ const waitStart = this.waitStart;
771
+ if (waitStart)
772
+ await waitStart.asPromise();
301
773
  }
302
774
  async stop() {
775
+ this.localGenerations.clear();
776
+ // Whoever awaits the checks of this transport settles now (checksSettled).
777
+ const waitStart = this.waitStart;
778
+ this.waitStart = undefined;
779
+ if (waitStart && !waitStart.ended) {
780
+ waitStart.execute();
781
+ waitStart.complete();
782
+ }
303
783
  if (this.state !== "closed") {
304
784
  this.setState("closed", false);
305
785
  await this.connection.close();
@@ -404,7 +884,7 @@ class RTCIceGatherer {
404
884
  enumerable: true,
405
885
  configurable: true,
406
886
  writable: true,
407
- value: options
887
+ value: void 0
408
888
  });
409
889
  Object.defineProperty(this, "onIceCandidate", {
410
890
  enumerable: true,
@@ -430,6 +910,7 @@ class RTCIceGatherer {
430
910
  writable: true,
431
911
  value: new common_1.Event()
432
912
  });
913
+ this.options = options;
433
914
  this.connection = new src_1.Connection(false, this.options);
434
915
  this.connection.onIceCandidate.subscribe((candidate) => {
435
916
  this.onIceCandidate(candidateFromIce(candidate));
@@ -438,7 +919,14 @@ class RTCIceGatherer {
438
919
  async gather() {
439
920
  if (this.gatheringState === "new") {
440
921
  this.setState("gathering");
922
+ const generation = this.connection.generation;
441
923
  await this.connection.gatherCandidates();
924
+ // Gathering an ICE restart (or close) replaced in the meantime does not
925
+ // complete the new generation: that one signals its own end.
926
+ if (this.connection.generation !== generation ||
927
+ this.connection.state === "closed") {
928
+ return;
929
+ }
442
930
  this.onIceCandidate(undefined);
443
931
  this.setState("complete");
444
932
  }
@@ -483,13 +971,37 @@ function candidateFromIce(c) {
483
971
  function candidateToIce(x) {
484
972
  return new src_1.Candidate(x.foundation, x.component, x.protocol, x.priority, x.ip, x.port, x.type, x.relatedAddress, x.relatedPort, x.tcpType, x.generation, x.ufrag);
485
973
  }
974
+ /** Module-private key for handing already parsed fields to the constructor. */
975
+ const parsedFields = Symbol("RTCIceCandidate.parsedFields");
976
+ /** Create an `RTCIceCandidate` whose fields come from typed values, without reparsing. */
977
+ function createRTCIceCandidate(init, fields) {
978
+ return new RTCIceCandidate({
979
+ ...init,
980
+ [parsedFields]: fields,
981
+ });
982
+ }
983
+ /**
984
+ * Browser-shaped ICE candidate. Besides the signaling fields it exposes the
985
+ * readonly fields of the W3C interface parsed from the candidate a-line
986
+ * (`foundation`, `component`, `priority`, `address`, `protocol`, `port`,
987
+ * `type`, `tcpType`, `relatedAddress`, `relatedPort`). Which candidates give
988
+ * `null` fields is specified on {@link RTCIceCandidateFields}. Candidates
989
+ * werift creates carry them without reparsing; `toJSON()` keeps only the
990
+ * signaling fields (RTCIceCandidateInit). `relayProtocol` and `url` are not
991
+ * implemented.
992
+ */
486
993
  class RTCIceCandidate {
487
- constructor(props) {
994
+ /**
995
+ * Like the browser constructor, only the `RTCIceCandidateInit` members are
996
+ * read; the parsed fields always come from `init.candidate` (`""` when
997
+ * omitted).
998
+ */
999
+ constructor(init = {}) {
488
1000
  Object.defineProperty(this, "candidate", {
489
1001
  enumerable: true,
490
1002
  configurable: true,
491
1003
  writable: true,
492
- value: void 0
1004
+ value: ""
493
1005
  });
494
1006
  Object.defineProperty(this, "sdpMid", {
495
1007
  enumerable: true,
@@ -509,12 +1021,84 @@ class RTCIceCandidate {
509
1021
  writable: true,
510
1022
  value: void 0
511
1023
  });
512
- Object.assign(this, props);
1024
+ Object.defineProperty(this, "foundation", {
1025
+ enumerable: true,
1026
+ configurable: true,
1027
+ writable: true,
1028
+ value: void 0
1029
+ });
1030
+ Object.defineProperty(this, "component", {
1031
+ enumerable: true,
1032
+ configurable: true,
1033
+ writable: true,
1034
+ value: void 0
1035
+ });
1036
+ Object.defineProperty(this, "priority", {
1037
+ enumerable: true,
1038
+ configurable: true,
1039
+ writable: true,
1040
+ value: void 0
1041
+ });
1042
+ Object.defineProperty(this, "address", {
1043
+ enumerable: true,
1044
+ configurable: true,
1045
+ writable: true,
1046
+ value: void 0
1047
+ });
1048
+ Object.defineProperty(this, "protocol", {
1049
+ enumerable: true,
1050
+ configurable: true,
1051
+ writable: true,
1052
+ value: void 0
1053
+ });
1054
+ Object.defineProperty(this, "port", {
1055
+ enumerable: true,
1056
+ configurable: true,
1057
+ writable: true,
1058
+ value: void 0
1059
+ });
1060
+ Object.defineProperty(this, "type", {
1061
+ enumerable: true,
1062
+ configurable: true,
1063
+ writable: true,
1064
+ value: void 0
1065
+ });
1066
+ Object.defineProperty(this, "tcpType", {
1067
+ enumerable: true,
1068
+ configurable: true,
1069
+ writable: true,
1070
+ value: void 0
1071
+ });
1072
+ Object.defineProperty(this, "relatedAddress", {
1073
+ enumerable: true,
1074
+ configurable: true,
1075
+ writable: true,
1076
+ value: void 0
1077
+ });
1078
+ Object.defineProperty(this, "relatedPort", {
1079
+ enumerable: true,
1080
+ configurable: true,
1081
+ writable: true,
1082
+ value: void 0
1083
+ });
1084
+ const { sdpMid, sdpMLineIndex, usernameFragment } = init;
1085
+ const candidate = init.candidate ?? "";
1086
+ const fields = init[parsedFields] ??
1087
+ (0, iceCandidateAttribute_1.candidateFieldsFromValues)((0, iceCandidateAttribute_1.parseCandidateAttribute)(candidate));
1088
+ Object.assign(this, fields, {
1089
+ candidate,
1090
+ sdpMid,
1091
+ sdpMLineIndex,
1092
+ usernameFragment,
1093
+ });
513
1094
  }
1095
+ /**
1096
+ * Same as `new RTCIceCandidate({ candidate: sdp })`, plus `usernameFragment`
1097
+ * taken from the `ufrag` extension attribute of a valid candidate.
1098
+ */
514
1099
  static fromSdp(sdp) {
515
- const ice = src_1.Candidate.fromSdp(sdp);
516
- const candidate = candidateFromIce(ice);
517
- return candidate.toJSON();
1100
+ const values = (0, iceCandidateAttribute_1.parseCandidateAttribute)(sdp);
1101
+ return createRTCIceCandidate({ candidate: sdp, usernameFragment: values?.ufrag }, (0, iceCandidateAttribute_1.candidateFieldsFromValues)(values));
518
1102
  }
519
1103
  static isThis(o) {
520
1104
  if (typeof o?.candidate === "string")
@@ -536,55 +1120,55 @@ class IceCandidate {
536
1120
  enumerable: true,
537
1121
  configurable: true,
538
1122
  writable: true,
539
- value: component
1123
+ value: void 0
540
1124
  });
541
1125
  Object.defineProperty(this, "foundation", {
542
1126
  enumerable: true,
543
1127
  configurable: true,
544
1128
  writable: true,
545
- value: foundation
1129
+ value: void 0
546
1130
  });
547
1131
  Object.defineProperty(this, "ip", {
548
1132
  enumerable: true,
549
1133
  configurable: true,
550
1134
  writable: true,
551
- value: ip
1135
+ value: void 0
552
1136
  });
553
1137
  Object.defineProperty(this, "port", {
554
1138
  enumerable: true,
555
1139
  configurable: true,
556
1140
  writable: true,
557
- value: port
1141
+ value: void 0
558
1142
  });
559
1143
  Object.defineProperty(this, "priority", {
560
1144
  enumerable: true,
561
1145
  configurable: true,
562
1146
  writable: true,
563
- value: priority
1147
+ value: void 0
564
1148
  });
565
1149
  Object.defineProperty(this, "protocol", {
566
1150
  enumerable: true,
567
1151
  configurable: true,
568
1152
  writable: true,
569
- value: protocol
1153
+ value: void 0
570
1154
  });
571
1155
  Object.defineProperty(this, "type", {
572
1156
  enumerable: true,
573
1157
  configurable: true,
574
1158
  writable: true,
575
- value: type
1159
+ value: void 0
576
1160
  });
577
1161
  Object.defineProperty(this, "generation", {
578
1162
  enumerable: true,
579
1163
  configurable: true,
580
1164
  writable: true,
581
- value: generation
1165
+ value: void 0
582
1166
  });
583
1167
  Object.defineProperty(this, "ufrag", {
584
1168
  enumerable: true,
585
1169
  configurable: true,
586
1170
  writable: true,
587
- value: ufrag
1171
+ value: void 0
588
1172
  });
589
1173
  // """
590
1174
  // The :class:`RTCIceCandidate` interface represents a candidate Interactive
@@ -621,29 +1205,40 @@ class IceCandidate {
621
1205
  writable: true,
622
1206
  value: void 0
623
1207
  });
1208
+ this.component = component;
1209
+ this.foundation = foundation;
1210
+ this.ip = ip;
1211
+ this.port = port;
1212
+ this.priority = priority;
1213
+ this.protocol = protocol;
1214
+ this.type = type;
1215
+ this.generation = generation;
1216
+ this.ufrag = ufrag;
624
1217
  }
1218
+ /** The parsed fields are validated from these typed values, not by reparsing. */
625
1219
  toJSON() {
626
- return new RTCIceCandidate({
1220
+ return createRTCIceCandidate({
627
1221
  candidate: (0, sdp_1.candidateToSdp)(this),
628
1222
  sdpMLineIndex: this.sdpMLineIndex,
629
1223
  sdpMid: this.sdpMid,
630
1224
  usernameFragment: this.ufrag,
631
- });
1225
+ }, (0, iceCandidateAttribute_1.candidateFieldsFromValues)(this));
632
1226
  }
1227
+ /**
1228
+ * Returns `undefined` when `data.candidate` is empty or violates the grammar
1229
+ * documented on {@link RTCIceCandidateFields}.
1230
+ */
633
1231
  static fromJSON(data) {
634
- try {
635
- if (!data.candidate) {
636
- throw new Error("candidate is required");
637
- }
638
- const normalizedCandidate = data.candidate.startsWith("candidate:")
639
- ? data.candidate.slice("candidate:".length)
640
- : data.candidate;
641
- const candidate = (0, sdp_1.candidateFromSdp)(normalizedCandidate);
642
- candidate.sdpMLineIndex = data.sdpMLineIndex ?? undefined;
643
- candidate.sdpMid = data.sdpMid ?? undefined;
644
- return candidate;
645
- }
646
- catch (error) { }
1232
+ const values = (0, iceCandidateAttribute_1.parseCandidateAttribute)(data.candidate ?? "");
1233
+ if (!values)
1234
+ return;
1235
+ const candidate = new IceCandidate(values.component, values.foundation, values.ip, values.port, values.priority, values.protocol, values.type, values.generation, values.ufrag);
1236
+ candidate.relatedAddress = values.relatedAddress;
1237
+ candidate.relatedPort = values.relatedPort;
1238
+ candidate.tcpType = values.tcpType;
1239
+ candidate.sdpMLineIndex = data.sdpMLineIndex ?? undefined;
1240
+ candidate.sdpMid = data.sdpMid ?? undefined;
1241
+ return candidate;
647
1242
  }
648
1243
  }
649
1244
  exports.IceCandidate = IceCandidate;