werift 0.25.1 → 0.26.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 (371) hide show
  1. package/lib/common/src/asn1.d.ts +42 -0
  2. package/lib/common/src/asn1.js +163 -0
  3. package/lib/common/src/asn1.js.map +1 -0
  4. package/lib/common/src/binaryData.js.map +1 -1
  5. package/lib/common/src/index.d.ts +6 -5
  6. package/lib/common/src/index.js +6 -5
  7. package/lib/common/src/index.js.map +1 -1
  8. package/lib/common/src/log.d.ts +12 -1
  9. package/lib/common/src/log.js +137 -5
  10. package/lib/common/src/log.js.map +1 -1
  11. package/lib/common/src/network.js.map +1 -1
  12. package/lib/common/src/queue.d.ts +41 -0
  13. package/lib/common/src/queue.js +146 -0
  14. package/lib/common/src/queue.js.map +1 -0
  15. package/lib/common/src/transport.d.ts +15 -2
  16. package/lib/common/src/transport.js +98 -14
  17. package/lib/common/src/transport.js.map +1 -1
  18. package/lib/dtls/src/cipher/create.js.map +1 -1
  19. package/lib/dtls/src/cipher/ec.js +8 -8
  20. package/lib/dtls/src/cipher/ec.js.map +1 -1
  21. package/lib/dtls/src/cipher/namedCurve.js +6 -7
  22. package/lib/dtls/src/cipher/namedCurve.js.map +1 -1
  23. package/lib/dtls/src/cipher/prf.d.ts +2 -2
  24. package/lib/dtls/src/cipher/prf.js +29 -8
  25. package/lib/dtls/src/cipher/prf.js.map +1 -1
  26. package/lib/dtls/src/cipher/suites/aead.d.ts +1 -1
  27. package/lib/dtls/src/context/certificate.d.ts +32 -0
  28. package/lib/dtls/src/context/certificate.js +54 -0
  29. package/lib/dtls/src/context/certificate.js.map +1 -0
  30. package/lib/dtls/src/context/cipher.d.ts +12 -6
  31. package/lib/dtls/src/context/cipher.js +52 -103
  32. package/lib/dtls/src/context/cipher.js.map +1 -1
  33. package/lib/dtls/src/context/transport.d.ts +4 -0
  34. package/lib/dtls/src/context/transport.js +14 -0
  35. package/lib/dtls/src/context/transport.js.map +1 -1
  36. package/lib/dtls/src/flight/client/flight5.js.map +1 -1
  37. package/lib/dtls/src/flight/flight.js +8 -1
  38. package/lib/dtls/src/flight/flight.js.map +1 -1
  39. package/lib/dtls/src/flight/server/flight2.js.map +1 -1
  40. package/lib/dtls/src/flight/server/flight4.d.ts +2 -1
  41. package/lib/dtls/src/flight/server/flight4.js +8 -2
  42. package/lib/dtls/src/flight/server/flight4.js.map +1 -1
  43. package/lib/dtls/src/handshake/extensions/signature.d.ts +1 -1
  44. package/lib/dtls/src/handshake/extensions/signature.js.map +1 -1
  45. package/lib/dtls/src/handshake/message/alert.js +1 -1
  46. package/lib/dtls/src/handshake/message/alert.js.map +1 -1
  47. package/lib/dtls/src/handshake/message/certificate.js +1 -1
  48. package/lib/dtls/src/handshake/message/certificate.js.map +1 -1
  49. package/lib/dtls/src/handshake/message/changeCipherSpec.js +2 -3
  50. package/lib/dtls/src/handshake/message/changeCipherSpec.js.map +1 -1
  51. package/lib/dtls/src/handshake/message/client/certificateVerify.d.ts +1 -1
  52. package/lib/dtls/src/handshake/message/client/certificateVerify.js +1 -1
  53. package/lib/dtls/src/handshake/message/client/certificateVerify.js.map +1 -1
  54. package/lib/dtls/src/handshake/message/client/hello.js +1 -1
  55. package/lib/dtls/src/handshake/message/client/hello.js.map +1 -1
  56. package/lib/dtls/src/handshake/message/client/keyExchange.js +1 -1
  57. package/lib/dtls/src/handshake/message/client/keyExchange.js.map +1 -1
  58. package/lib/dtls/src/handshake/message/server/certificateRequest.d.ts +1 -1
  59. package/lib/dtls/src/handshake/message/server/certificateRequest.js +1 -1
  60. package/lib/dtls/src/handshake/message/server/certificateRequest.js.map +1 -1
  61. package/lib/dtls/src/handshake/message/server/hello.d.ts +1 -1
  62. package/lib/dtls/src/handshake/message/server/hello.js +2 -2
  63. package/lib/dtls/src/handshake/message/server/hello.js.map +1 -1
  64. package/lib/dtls/src/handshake/message/server/helloDone.js +1 -1
  65. package/lib/dtls/src/handshake/message/server/helloDone.js.map +1 -1
  66. package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js +1 -1
  67. package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js.map +1 -1
  68. package/lib/dtls/src/handshake/message/server/keyExchange.d.ts +1 -1
  69. package/lib/dtls/src/handshake/message/server/keyExchange.js +1 -1
  70. package/lib/dtls/src/handshake/message/server/keyExchange.js.map +1 -1
  71. package/lib/dtls/src/handshake/random.d.ts +2 -2
  72. package/lib/dtls/src/handshake/random.js +2 -2
  73. package/lib/dtls/src/handshake/random.js.map +1 -1
  74. package/lib/dtls/src/imports/common.d.ts +1 -0
  75. package/lib/dtls/src/imports/common.js +1 -0
  76. package/lib/dtls/src/imports/common.js.map +1 -1
  77. package/lib/dtls/src/index.d.ts +2 -2
  78. package/lib/dtls/src/index.js +2 -2
  79. package/lib/dtls/src/index.js.map +1 -1
  80. package/lib/dtls/src/record/message/fragment.d.ts +1 -1
  81. package/lib/dtls/src/record/message/fragment.js +3 -3
  82. package/lib/dtls/src/record/message/fragment.js.map +1 -1
  83. package/lib/dtls/src/record/message/header.js +2 -2
  84. package/lib/dtls/src/record/message/header.js.map +1 -1
  85. package/lib/dtls/src/server.js +1 -1
  86. package/lib/dtls/src/server.js.map +1 -1
  87. package/lib/dtls/src/socket.d.ts +2 -2
  88. package/lib/dtls/src/socket.js +2 -2
  89. package/lib/dtls/src/socket.js.map +1 -1
  90. package/lib/ice/src/exceptions.d.ts +30 -0
  91. package/lib/ice/src/exceptions.js +43 -1
  92. package/lib/ice/src/exceptions.js.map +1 -1
  93. package/lib/ice/src/helper.d.ts +1 -1
  94. package/lib/ice/src/ice.d.ts +142 -0
  95. package/lib/ice/src/ice.js +809 -53
  96. package/lib/ice/src/ice.js.map +1 -1
  97. package/lib/ice/src/iceBase.d.ts +49 -0
  98. package/lib/ice/src/iceBase.js.map +1 -1
  99. package/lib/ice/src/index.d.ts +5 -5
  100. package/lib/ice/src/index.js +5 -5
  101. package/lib/ice/src/index.js.map +1 -1
  102. package/lib/ice/src/internal/resolveHostAddresses.d.ts +26 -0
  103. package/lib/ice/src/internal/resolveHostAddresses.js +45 -0
  104. package/lib/ice/src/internal/resolveHostAddresses.js.map +1 -0
  105. package/lib/ice/src/stun/protocol.d.ts +3 -1
  106. package/lib/ice/src/stun/protocol.js +16 -0
  107. package/lib/ice/src/stun/protocol.js.map +1 -1
  108. package/lib/ice/src/stun/tcpProtocol.d.ts +2 -0
  109. package/lib/ice/src/stun/tcpProtocol.js +16 -1
  110. package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
  111. package/lib/ice/src/stun/transaction.d.ts +5 -0
  112. package/lib/ice/src/stun/transaction.js +7 -1
  113. package/lib/ice/src/stun/transaction.js.map +1 -1
  114. package/lib/ice/src/turn/protocol.d.ts +73 -4
  115. package/lib/ice/src/turn/protocol.js +241 -12
  116. package/lib/ice/src/turn/protocol.js.map +1 -1
  117. package/lib/ice/src/utils.js.map +1 -1
  118. package/lib/ice-server/src/stun/message.d.ts +5 -1
  119. package/lib/ice-server/src/stun/message.js +33 -2
  120. package/lib/ice-server/src/stun/message.js.map +1 -1
  121. package/lib/ice-server/src/turn/auth.d.ts +1 -1
  122. package/lib/index.mjs +24263 -16477
  123. package/lib/nonstandard/index.mjs +9272 -6178
  124. package/lib/polyfill/dom.mjs +24872 -20543
  125. package/lib/polyfill/index.mjs +24872 -20543
  126. package/lib/rtp/src/codec/av1.d.ts +61 -1
  127. package/lib/rtp/src/codec/av1.js +332 -33
  128. package/lib/rtp/src/codec/av1.js.map +1 -1
  129. package/lib/rtp/src/codec/base.d.ts +49 -1
  130. package/lib/rtp/src/codec/base.js +81 -1
  131. package/lib/rtp/src/codec/base.js.map +1 -1
  132. package/lib/rtp/src/codec/g711.d.ts +37 -0
  133. package/lib/rtp/src/codec/g711.js +109 -0
  134. package/lib/rtp/src/codec/g711.js.map +1 -0
  135. package/lib/rtp/src/codec/g722.d.ts +31 -0
  136. package/lib/rtp/src/codec/g722.js +82 -0
  137. package/lib/rtp/src/codec/g722.js.map +1 -0
  138. package/lib/rtp/src/codec/h264.d.ts +81 -7
  139. package/lib/rtp/src/codec/h264.js +382 -21
  140. package/lib/rtp/src/codec/h264.js.map +1 -1
  141. package/lib/rtp/src/codec/h265.d.ts +101 -0
  142. package/lib/rtp/src/codec/h265.js +615 -0
  143. package/lib/rtp/src/codec/h265.js.map +1 -0
  144. package/lib/rtp/src/codec/index.d.ts +6 -1
  145. package/lib/rtp/src/codec/index.js +25 -0
  146. package/lib/rtp/src/codec/index.js.map +1 -1
  147. package/lib/rtp/src/codec/mp4a.d.ts +88 -0
  148. package/lib/rtp/src/codec/mp4a.js +386 -0
  149. package/lib/rtp/src/codec/mp4a.js.map +1 -0
  150. package/lib/rtp/src/codec/opus.d.ts +14 -2
  151. package/lib/rtp/src/codec/opus.js +32 -2
  152. package/lib/rtp/src/codec/opus.js.map +1 -1
  153. package/lib/rtp/src/codec/telephoneEvent.d.ts +102 -0
  154. package/lib/rtp/src/codec/telephoneEvent.js +176 -0
  155. package/lib/rtp/src/codec/telephoneEvent.js.map +1 -0
  156. package/lib/rtp/src/codec/vp8.d.ts +26 -1
  157. package/lib/rtp/src/codec/vp8.js +76 -2
  158. package/lib/rtp/src/codec/vp8.js.map +1 -1
  159. package/lib/rtp/src/codec/vp9.d.ts +25 -1
  160. package/lib/rtp/src/codec/vp9.js +64 -2
  161. package/lib/rtp/src/codec/vp9.js.map +1 -1
  162. package/lib/rtp/src/const.d.ts +1 -0
  163. package/lib/rtp/src/const.js +5 -0
  164. package/lib/rtp/src/const.js.map +1 -0
  165. package/lib/rtp/src/extra/container/mp4/container.js +4 -1
  166. package/lib/rtp/src/extra/container/mp4/container.js.map +1 -1
  167. package/lib/rtp/src/extra/container/mp4/h264.d.ts +26 -0
  168. package/lib/rtp/src/extra/container/mp4/h264.js +54 -0
  169. package/lib/rtp/src/extra/container/mp4/h264.js.map +1 -1
  170. package/lib/rtp/src/extra/container/webm/container.d.ts +1 -1
  171. package/lib/rtp/src/extra/container/webm/ebml/ebml.d.ts +6 -0
  172. package/lib/rtp/src/extra/container/webm/ebml/ebml.js +20 -1
  173. package/lib/rtp/src/extra/container/webm/ebml/ebml.js.map +1 -1
  174. package/lib/rtp/src/extra/processor/depacketizer.d.ts +1 -1
  175. package/lib/rtp/src/extra/processor/depacketizer.js +1 -1
  176. package/lib/rtp/src/extra/processor/depacketizer.js.map +1 -1
  177. package/lib/rtp/src/extra/processor/depacketizerCallback.d.ts +1 -11
  178. package/lib/rtp/src/extra/processor/depacketizerTransformer.d.ts +1 -1
  179. package/lib/rtp/src/extra/processor/dtxCallback.d.ts +1 -11
  180. package/lib/rtp/src/extra/processor/interface.d.ts +16 -11
  181. package/lib/rtp/src/extra/processor/interface.js.map +1 -1
  182. package/lib/rtp/src/extra/processor/jitterBufferCallback.d.ts +1 -11
  183. package/lib/rtp/src/extra/processor/jitterBufferTransformer.d.ts +1 -1
  184. package/lib/rtp/src/extra/processor/mp4.d.ts +16 -0
  185. package/lib/rtp/src/extra/processor/mp4.js +55 -21
  186. package/lib/rtp/src/extra/processor/mp4.js.map +1 -1
  187. package/lib/rtp/src/extra/processor/nack.d.ts +1 -1
  188. package/lib/rtp/src/extra/processor/nack.js +1 -1
  189. package/lib/rtp/src/extra/processor/nack.js.map +1 -1
  190. package/lib/rtp/src/extra/processor/nackHandlerCallback.d.ts +1 -11
  191. package/lib/rtp/src/extra/processor/ntpTime.js.map +1 -1
  192. package/lib/rtp/src/extra/processor/ntpTimeCallback.d.ts +1 -11
  193. package/lib/rtp/src/extra/processor/rtcpCallback.d.ts +1 -1
  194. package/lib/rtp/src/extra/processor/rtcpCallback.js.map +1 -1
  195. package/lib/rtp/src/extra/processor/rtpCallback.d.ts +1 -1
  196. package/lib/rtp/src/extra/processor/rtpCallback.js +1 -1
  197. package/lib/rtp/src/extra/processor/rtpCallback.js.map +1 -1
  198. package/lib/rtp/src/extra/processor/rtpStream.d.ts +2 -2
  199. package/lib/rtp/src/extra/processor/rtpStream.js.map +1 -1
  200. package/lib/rtp/src/extra/processor/rtpTime.js.map +1 -1
  201. package/lib/rtp/src/extra/processor/rtpTimeCallback.d.ts +1 -11
  202. package/lib/rtp/src/extra/processor/webm.d.ts +27 -0
  203. package/lib/rtp/src/extra/processor/webm.js +43 -16
  204. package/lib/rtp/src/extra/processor/webm.js.map +1 -1
  205. package/lib/rtp/src/extra/processor/webmCallback.js +6 -1
  206. package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
  207. package/lib/rtp/src/extra/processor/webmStream.js.map +1 -1
  208. package/lib/rtp/src/helper.d.ts +2 -2
  209. package/lib/rtp/src/helper.js +2 -6
  210. package/lib/rtp/src/helper.js.map +1 -1
  211. package/lib/rtp/src/index.d.ts +4 -2
  212. package/lib/rtp/src/index.js +4 -2
  213. package/lib/rtp/src/index.js.map +1 -1
  214. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js +2 -1
  215. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js.map +1 -1
  216. package/lib/rtp/src/rtcp/rtcp.js +2 -1
  217. package/lib/rtp/src/rtcp/rtcp.js.map +1 -1
  218. package/lib/rtp/src/rtcp/sr.d.ts +4 -3
  219. package/lib/rtp/src/rtcp/sr.js +3 -2
  220. package/lib/rtp/src/rtcp/sr.js.map +1 -1
  221. package/lib/rtp/src/rtp/mediaClock.d.ts +283 -0
  222. package/lib/rtp/src/rtp/mediaClock.js +655 -0
  223. package/lib/rtp/src/rtp/mediaClock.js.map +1 -0
  224. package/lib/rtp/src/srtp/cipher/ctr.d.ts +2 -2
  225. package/lib/rtp/src/srtp/cipher/ctr.js +1 -1
  226. package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
  227. package/lib/rtp/src/srtp/cipher/gcm.d.ts +1 -1
  228. package/lib/rtp/src/srtp/cipher/gcm.js +1 -1
  229. package/lib/rtp/src/srtp/cipher/gcm.js.map +1 -1
  230. package/lib/rtp/src/srtp/context/context.d.ts +29 -1
  231. package/lib/rtp/src/srtp/context/context.js +78 -24
  232. package/lib/rtp/src/srtp/context/context.js.map +1 -1
  233. package/lib/rtp/src/srtp/context/srtp.js +23 -15
  234. package/lib/rtp/src/srtp/context/srtp.js.map +1 -1
  235. package/lib/rtp/src/util.d.ts +59 -6
  236. package/lib/rtp/src/util.js +88 -10
  237. package/lib/rtp/src/util.js.map +1 -1
  238. package/lib/sctp/src/index.d.ts +4 -3
  239. package/lib/sctp/src/index.js +10 -8
  240. package/lib/sctp/src/index.js.map +1 -1
  241. package/lib/sctp/src/sctp.d.ts +11 -2
  242. package/lib/sctp/src/sctp.js +47 -28
  243. package/lib/sctp/src/sctp.js.map +1 -1
  244. package/lib/webrtc/src/api/peerConfig.d.ts +264 -0
  245. package/lib/webrtc/src/api/peerConfig.js +250 -0
  246. package/lib/webrtc/src/api/peerConfig.js.map +1 -0
  247. package/lib/webrtc/src/api/peerConnectionEvents.d.ts +36 -0
  248. package/lib/webrtc/src/api/peerConnectionEvents.js +44 -0
  249. package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -0
  250. package/lib/webrtc/src/dataChannel.d.ts +1 -1
  251. package/lib/webrtc/src/dataChannel.js +1 -1
  252. package/lib/webrtc/src/dataChannel.js.map +1 -1
  253. package/lib/webrtc/src/index.d.ts +2 -2
  254. package/lib/webrtc/src/index.js +2 -2
  255. package/lib/webrtc/src/index.js.map +1 -1
  256. package/lib/webrtc/src/media/codec.d.ts +18 -0
  257. package/lib/webrtc/src/media/codec.js +43 -2
  258. package/lib/webrtc/src/media/codec.js.map +1 -1
  259. package/lib/webrtc/src/media/codecCompatibility.d.ts +5 -0
  260. package/lib/webrtc/src/media/codecCompatibility.js +15 -4
  261. package/lib/webrtc/src/media/codecCompatibility.js.map +1 -1
  262. package/lib/webrtc/src/media/index.d.ts +1 -1
  263. package/lib/webrtc/src/media/index.js +1 -1
  264. package/lib/webrtc/src/media/index.js.map +1 -1
  265. package/lib/webrtc/src/media/receiver/nack.js +3 -4
  266. package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
  267. package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
  268. package/lib/webrtc/src/media/router.d.ts +116 -5
  269. package/lib/webrtc/src/media/router.js +281 -29
  270. package/lib/webrtc/src/media/router.js.map +1 -1
  271. package/lib/webrtc/src/media/rtpReceiver.d.ts +107 -12
  272. package/lib/webrtc/src/media/rtpReceiver.js +255 -28
  273. package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
  274. package/lib/webrtc/src/media/rtpSender.d.ts +56 -3
  275. package/lib/webrtc/src/media/rtpSender.js +180 -21
  276. package/lib/webrtc/src/media/rtpSender.js.map +1 -1
  277. package/lib/webrtc/src/media/rtpTransceiver.d.ts +94 -1
  278. package/lib/webrtc/src/media/rtpTransceiver.js +111 -2
  279. package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
  280. package/lib/webrtc/src/media/sender/senderBWE.d.ts +2 -1
  281. package/lib/webrtc/src/media/sender/senderBWE.js +22 -10
  282. package/lib/webrtc/src/media/sender/senderBWE.js.map +1 -1
  283. package/lib/webrtc/src/media/track.d.ts +1 -1
  284. package/lib/webrtc/src/media/track.js +1 -1
  285. package/lib/webrtc/src/media/track.js.map +1 -1
  286. package/lib/webrtc/src/negotiation/bundleTopology.d.ts +107 -0
  287. package/lib/webrtc/src/negotiation/bundleTopology.js +380 -0
  288. package/lib/webrtc/src/negotiation/bundleTopology.js.map +1 -0
  289. package/lib/webrtc/src/negotiation/descriptionValidation.d.ts +51 -0
  290. package/lib/webrtc/src/negotiation/descriptionValidation.js +261 -0
  291. package/lib/webrtc/src/negotiation/descriptionValidation.js.map +1 -0
  292. package/lib/webrtc/src/negotiation/iceRestartRequest.d.ts +21 -0
  293. package/lib/webrtc/src/negotiation/iceRestartRequest.js +61 -0
  294. package/lib/webrtc/src/negotiation/iceRestartRequest.js.map +1 -0
  295. package/lib/webrtc/src/negotiation/internalState.d.ts +34 -0
  296. package/lib/webrtc/src/negotiation/internalState.js +21 -0
  297. package/lib/webrtc/src/negotiation/internalState.js.map +1 -0
  298. package/lib/webrtc/src/negotiation/negotiationNeeded.d.ts +44 -0
  299. package/lib/webrtc/src/negotiation/negotiationNeeded.js +118 -0
  300. package/lib/webrtc/src/negotiation/negotiationNeeded.js.map +1 -0
  301. package/lib/webrtc/src/negotiation/remoteCandidates.d.ts +86 -0
  302. package/lib/webrtc/src/negotiation/remoteCandidates.js +344 -0
  303. package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -0
  304. package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +71 -0
  305. package/lib/webrtc/src/negotiation/remoteMediaApplication.js +398 -0
  306. package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -0
  307. package/lib/webrtc/src/negotiation/transportActivation.d.ts +59 -0
  308. package/lib/webrtc/src/negotiation/transportActivation.js +345 -0
  309. package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -0
  310. package/lib/webrtc/src/negotiationTransaction.d.ts +233 -0
  311. package/lib/webrtc/src/negotiationTransaction.js +591 -0
  312. package/lib/webrtc/src/negotiationTransaction.js.map +1 -0
  313. package/lib/webrtc/src/nonstandard/dummyMedia.js +20 -6
  314. package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
  315. package/lib/webrtc/src/nonstandard/index.d.ts +1 -1
  316. package/lib/webrtc/src/nonstandard/index.js +1 -1
  317. package/lib/webrtc/src/nonstandard/index.js.map +1 -1
  318. package/lib/webrtc/src/nonstandard/navigator.js.map +1 -1
  319. package/lib/webrtc/src/nonstandard/recorder/writer/index.d.ts +1 -1
  320. package/lib/webrtc/src/nonstandard/recorder/writer/index.js.map +1 -1
  321. package/lib/webrtc/src/nonstandard/recorder/writer/webm.d.ts +2 -2
  322. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +2 -2
  323. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
  324. package/lib/webrtc/src/nonstandard/userMedia/packetizer.d.ts +4 -4
  325. package/lib/webrtc/src/nonstandard/userMedia/packetizer.js +61 -306
  326. package/lib/webrtc/src/nonstandard/userMedia/packetizer.js.map +1 -1
  327. package/lib/webrtc/src/nonstandard/userMedia.d.ts +4 -2
  328. package/lib/webrtc/src/nonstandard/userMedia.js +43 -9
  329. package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
  330. package/lib/webrtc/src/peerConnection.d.ts +132 -237
  331. package/lib/webrtc/src/peerConnection.js +971 -906
  332. package/lib/webrtc/src/peerConnection.js.map +1 -1
  333. package/lib/webrtc/src/polyfill/api.d.ts +5 -5
  334. package/lib/webrtc/src/polyfill/api.js.map +1 -1
  335. package/lib/webrtc/src/polyfill/index.js.map +1 -1
  336. package/lib/webrtc/src/polyfill/install.js +1 -1
  337. package/lib/webrtc/src/polyfill/install.js.map +1 -1
  338. package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
  339. package/lib/webrtc/src/polyfill/registers/mp4Webm.js.map +1 -1
  340. package/lib/webrtc/src/polyfill/registers/rtpRtcp.js.map +1 -1
  341. package/lib/webrtc/src/polyfill/selectSettings.js.map +1 -1
  342. package/lib/webrtc/src/polyfill/sourceIo.js.map +1 -1
  343. package/lib/webrtc/src/sctpManager.d.ts +66 -2
  344. package/lib/webrtc/src/sctpManager.js +122 -5
  345. package/lib/webrtc/src/sctpManager.js.map +1 -1
  346. package/lib/webrtc/src/sdp.js.map +1 -1
  347. package/lib/webrtc/src/sdpManager.d.ts +55 -11
  348. package/lib/webrtc/src/sdpManager.js +367 -89
  349. package/lib/webrtc/src/sdpManager.js.map +1 -1
  350. package/lib/webrtc/src/secureTransportManager.d.ts +38 -25
  351. package/lib/webrtc/src/secureTransportManager.js +130 -34
  352. package/lib/webrtc/src/secureTransportManager.js.map +1 -1
  353. package/lib/webrtc/src/transceiverManager.d.ts +62 -18
  354. package/lib/webrtc/src/transceiverManager.js +266 -105
  355. package/lib/webrtc/src/transceiverManager.js.map +1 -1
  356. package/lib/webrtc/src/transport/dtls.d.ts +11 -2
  357. package/lib/webrtc/src/transport/dtls.js +37 -13
  358. package/lib/webrtc/src/transport/dtls.js.map +1 -1
  359. package/lib/webrtc/src/transport/ice.d.ts +254 -7
  360. package/lib/webrtc/src/transport/ice.js +608 -52
  361. package/lib/webrtc/src/transport/ice.js.map +1 -1
  362. package/lib/webrtc/src/transport/iceCandidateAttribute.d.ts +98 -0
  363. package/lib/webrtc/src/transport/iceCandidateAttribute.js +129 -0
  364. package/lib/webrtc/src/transport/iceCandidateAttribute.js.map +1 -0
  365. package/lib/webrtc/src/transport/sctp.d.ts +4 -1
  366. package/lib/webrtc/src/transport/sctp.js +83 -17
  367. package/lib/webrtc/src/transport/sctp.js.map +1 -1
  368. package/lib/webrtc/src/utils.d.ts +3 -3
  369. package/lib/webrtc/src/utils.js +1 -1
  370. package/lib/webrtc/src/utils.js.map +1 -1
  371. package/package.json +13 -14
@@ -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,57 @@ 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 old selected pair is dropped
81
+ * at the commit, so RTP pauses until the new generation nominates.
50
82
  */
51
83
  class RTCIceTransport {
52
84
  constructor(iceGather) {
@@ -92,12 +124,83 @@ class RTCIceTransport {
92
124
  writable: true,
93
125
  value: void 0
94
126
  });
127
+ /**
128
+ * Connectivity checks were started for the current generation. A restart
129
+ * resets it; the state alone cannot tell (an agent that finished gathering
130
+ * reports "completed" before any check ran).
131
+ * @internal
132
+ */
133
+ Object.defineProperty(this, "checksStarted", {
134
+ enumerable: true,
135
+ configurable: true,
136
+ writable: true,
137
+ value: false
138
+ });
95
139
  Object.defineProperty(this, "renominating", {
96
140
  enumerable: true,
97
141
  configurable: true,
98
142
  writable: true,
99
143
  value: false
100
144
  });
145
+ /**
146
+ * The restart generation selected for the description being created or
147
+ * applied (the one createOffer / createAnswer put in its SDP, or the one an
148
+ * applied description carries).
149
+ */
150
+ Object.defineProperty(this, "stagedLocalRestart", {
151
+ enumerable: true,
152
+ configurable: true,
153
+ writable: true,
154
+ value: void 0
155
+ });
156
+ /**
157
+ * The restart generations the latest created offer and the latest created
158
+ * answer carry, by ufrag (their generation records). One stays registered
159
+ * until a newer description of the same kind replaces it (unless an
160
+ * applied description still carries it) or the transport stops, whatever
161
+ * is applied, rolled back or committed meanwhile; applying a description
162
+ * that carries it selects it (an ICE restart to those credentials on the
163
+ * kept sockets).
164
+ */
165
+ Object.defineProperty(this, "localGenerations", {
166
+ enumerable: true,
167
+ configurable: true,
168
+ writable: true,
169
+ value: new Map()
170
+ });
171
+ /**
172
+ * The staged generation an applied description (pending local offer, or a
173
+ * remote offer being answered) carries. It stays until that description is
174
+ * committed, replaced or rolled back; an unapplied createOffer cannot drop it.
175
+ */
176
+ Object.defineProperty(this, "appliedLocalRestart", {
177
+ enumerable: true,
178
+ configurable: true,
179
+ writable: true,
180
+ value: void 0
181
+ });
182
+ /**
183
+ * Gatherer events of an ICE restart committed by a local answer, held until
184
+ * that answer is applied (`emitCommittedCandidates`), in their order: the
185
+ * re-advertised candidates first, then what the servers add and
186
+ * end-of-candidates.
187
+ */
188
+ Object.defineProperty(this, "heldCandidateEvents", {
189
+ enumerable: true,
190
+ configurable: true,
191
+ writable: true,
192
+ value: void 0
193
+ });
194
+ /**
195
+ * ICE servers set (setConfiguration) after this transport gathered. They
196
+ * apply to the next gathering, that is the next ICE restart (JSEP 4.1.18).
197
+ */
198
+ Object.defineProperty(this, "nextGatherIceServers", {
199
+ enumerable: true,
200
+ configurable: true,
201
+ writable: true,
202
+ value: void 0
203
+ });
101
204
  Object.defineProperty(this, "events", {
102
205
  enumerable: true,
103
206
  configurable: true,
@@ -173,7 +276,10 @@ class RTCIceTransport {
173
276
  this.setState(state);
174
277
  });
175
278
  this.iceGather.onIceCandidate = (candidate) => {
176
- this.onIceCandidate.execute(candidate);
279
+ if (this.heldCandidateEvents)
280
+ this.heldCandidateEvents.push(candidate);
281
+ else
282
+ this.onIceCandidate.execute(candidate);
177
283
  };
178
284
  this.iceGather.onGatheringStateChange.subscribe(() => {
179
285
  this.ongatheringstatechange?.();
@@ -193,10 +299,290 @@ class RTCIceTransport {
193
299
  return this.iceGather.gatheringState;
194
300
  }
195
301
  get localCandidates() {
196
- return this.iceGather.localCandidates;
302
+ return this.describedLocalGeneration().candidates;
303
+ }
304
+ /** Whether the local description may carry `a=end-of-candidates`. */
305
+ get localCandidatesComplete() {
306
+ return this.describedLocalGeneration().complete;
307
+ }
308
+ /**
309
+ * The local ICE generation a description carries: its credentials,
310
+ * candidates and whether they are complete. A description being created
311
+ * carries a staged restart. One already applied (refreshed when the live
312
+ * generation gathers more) carries the staged restart only if it applied
313
+ * it; a later createOffer() that staged another generation without applying
314
+ * it does not change an applied description.
315
+ * @internal
316
+ */
317
+ describedLocalGeneration({ applied = false } = {}) {
318
+ const staged = this.stagedLocalRestart;
319
+ if (!staged || (applied && staged !== this.appliedLocalRestart)) {
320
+ return {
321
+ parameters: this.iceGather.localParameters,
322
+ candidates: this.iceGather.localCandidates,
323
+ // The gatherer signals end-of-candidates (and the description that
324
+ // records it refreshes) just before its state becomes "complete".
325
+ complete: this.gatheringState === "complete" ||
326
+ this.connection.localCandidatesEnd,
327
+ };
328
+ }
329
+ const pending = this.stagedGatherPending();
330
+ return {
331
+ parameters: new RTCIceParameters({
332
+ iceLite: this.connection.iceLite,
333
+ usernameFragment: staged.usernameFragment,
334
+ password: staged.password,
335
+ }),
336
+ candidates: pending
337
+ ? staged.candidates.filter((candidate) => candidate.type !== "relay")
338
+ : staged.candidates,
339
+ complete: this.gatheringState === "complete" && !pending,
340
+ };
341
+ }
342
+ /**
343
+ * A staged restart whose generation keeps gathering from its servers after
344
+ * the commit; its relay candidates and end-of-candidates come then.
345
+ */
346
+ stagedGatherPending() {
347
+ const staged = this.stagedLocalRestart;
348
+ if (!staged)
349
+ return false;
350
+ if (staged.emitted)
351
+ return !!staged.endDeferred;
352
+ return !!this.nextGatherIceServers || !!this.connection.gathersFromServers;
197
353
  }
198
354
  get localParameters() {
199
- return this.iceGather.localParameters;
355
+ return this.describedLocalGeneration().parameters;
356
+ }
357
+ /**
358
+ * Prepare an ICE generation for SDP without touching the selected pair.
359
+ * `answering` is the remote offer an answer is created for.
360
+ */
361
+ stageLocalRestart({ answering, replacing, } = {}) {
362
+ // The generation a description of this kind already carries is reused,
363
+ // whatever was selected since: a new offer reuses the one of the pending
364
+ // applied offer (JSEP 5.2.1) unless restartIce() asked to replace it, and
365
+ // an answer created again for the same remote offer reuses the one the
366
+ // earlier answer carries (JSEP 5.3.1).
367
+ const applied = this.appliedLocalRestart;
368
+ const reused = answering
369
+ ? [...this.localGenerations.values()].find((generation) => generation.answering === answering)
370
+ : applied && !replacing?.has(applied.usernameFragment)
371
+ ? applied
372
+ : undefined;
373
+ if (reused) {
374
+ this.selectGeneration(reused);
375
+ return;
376
+ }
377
+ this.unselectLocalRestart();
378
+ const usernameFragment = (0, crypto_1.randomBytes)(6).toString("base64url");
379
+ const random = (0, crypto_1.randomBytes)(24).toString("base64url");
380
+ // The configured prefix (icePasswordPrefix) marks every generation's
381
+ // password, as the agent's own restart does.
382
+ const prefix = this.connection.options.localPasswordPrefix ?? "";
383
+ const password = prefix + random.slice(prefix.length);
384
+ const candidates = this.iceGather.localCandidates.map((candidate) => {
385
+ 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), {
386
+ relatedAddress: candidate.relatedAddress,
387
+ relatedPort: candidate.relatedPort,
388
+ tcpType: candidate.tcpType,
389
+ });
390
+ return copy;
391
+ });
392
+ const generation = {
393
+ usernameFragment,
394
+ password,
395
+ candidates,
396
+ emitted: false,
397
+ answering,
398
+ createdBy: answering ? "answer" : "offer",
399
+ };
400
+ // The previous description of this kind is no longer the latest one.
401
+ for (const [ufrag, previous] of this.localGenerations) {
402
+ if (previous.createdBy === generation.createdBy &&
403
+ previous !== this.appliedLocalRestart) {
404
+ this.localGenerations.delete(ufrag);
405
+ }
406
+ }
407
+ this.localGenerations.set(usernameFragment, generation);
408
+ this.stagedLocalRestart = generation;
409
+ // Existing sockets can respond to provisional STUN checks for the new
410
+ // ufrag while the old generation continues to carry media.
411
+ this.connection.stageLocalCredentials?.(usernameFragment, password);
412
+ }
413
+ /**
414
+ * The local generation a description with these credentials carries:
415
+ * `"live"` for the agent's current credentials, the restart generation the
416
+ * latest created offer or answer carries, or `undefined` when the
417
+ * credentials belong to no generation the transport can take.
418
+ * @internal
419
+ */
420
+ localGenerationFor(usernameFragment, password) {
421
+ const live = this.iceGather.localParameters;
422
+ if (live.usernameFragment === usernameFragment &&
423
+ live.password === password) {
424
+ return "live";
425
+ }
426
+ const generation = this.localGenerations.get(usernameFragment);
427
+ if (generation?.password === password)
428
+ return generation;
429
+ return undefined;
430
+ }
431
+ /**
432
+ * Select the local generation an applied description carries (see
433
+ * `localGenerationFor`). Returns false if the credentials belong to none.
434
+ * @internal
435
+ */
436
+ selectLocalGeneration(usernameFragment, password) {
437
+ const generation = this.localGenerationFor(usernameFragment, password);
438
+ if (!generation)
439
+ return false;
440
+ if (generation === "live") {
441
+ this.unselectLocalRestart();
442
+ return true;
443
+ }
444
+ this.selectGeneration(generation);
445
+ return true;
446
+ }
447
+ selectGeneration(generation) {
448
+ if (this.stagedLocalRestart === generation)
449
+ return;
450
+ this.unselectLocalRestart();
451
+ this.stagedLocalRestart = generation;
452
+ this.connection.stageLocalCredentials?.(generation.usernameFragment, generation.password);
453
+ }
454
+ /** Stop answering checks for the selected generation; it stays registered. */
455
+ unselectLocalRestart() {
456
+ const staged = this.stagedLocalRestart;
457
+ if (!staged)
458
+ return;
459
+ this.connection.discardStagedLocalCredentials?.(staged.usernameFragment);
460
+ this.stagedLocalRestart = undefined;
461
+ }
462
+ get hasStagedRestart() {
463
+ return !!this.stagedLocalRestart;
464
+ }
465
+ /** Feed a pranswer's ICE generation to the provisional checklist. */
466
+ setProvisionalRemoteParams(remoteParameters) {
467
+ if (!this.stagedLocalRestart)
468
+ return;
469
+ this.connection.setProvisionalRemoteParams?.(remoteParameters);
470
+ }
471
+ addProvisionalRemoteCandidate(candidate) {
472
+ if (!this.stagedLocalRestart)
473
+ return;
474
+ return this.connection.addProvisionalRemoteCandidate?.(candidate ? candidateToIce(candidate) : undefined);
475
+ }
476
+ /**
477
+ * Hand a remote candidate (`undefined`: end-of-candidates) to the ICE agent
478
+ * without waiting for it. A host candidate is added synchronously; an mDNS
479
+ * name may take seconds to resolve, and the agent itself orders that
480
+ * resolution against end-of-candidates and generation changes, so the
481
+ * description operation queue must not wait for it.
482
+ */
483
+ deliverRemoteCandidate(candidate) {
484
+ void Promise.resolve(this.addRemoteCandidate(candidate)).catch((error) => log("addRemoteCandidate failed", error));
485
+ }
486
+ /** `deliverRemoteCandidate` for the provisional (pranswer) generation. */
487
+ deliverProvisionalRemoteCandidate(candidate) {
488
+ void Promise.resolve(this.addProvisionalRemoteCandidate(candidate)).catch((error) => log("addProvisionalRemoteCandidate failed", error));
489
+ }
490
+ startProvisionalChecks() {
491
+ if (!this.stagedLocalRestart)
492
+ return;
493
+ this.connection.startProvisionalChecks?.();
494
+ }
495
+ emitStagedCandidates() {
496
+ const staged = this.stagedLocalRestart;
497
+ if (!staged || staged.emitted)
498
+ return;
499
+ const candidates = this.localCandidates;
500
+ staged.endDeferred = this.stagedGatherPending();
501
+ staged.emitted = true;
502
+ for (const candidate of candidates) {
503
+ // A copy: the listener rewrites the event's foundation and m-line,
504
+ // while these candidates still render the local description.
505
+ this.onIceCandidate.execute(Object.assign(Object.create(Object.getPrototypeOf(candidate)), candidate));
506
+ }
507
+ if (!staged.endDeferred)
508
+ this.onIceCandidate.execute(undefined);
509
+ }
510
+ rollbackLocalRestart() {
511
+ this.appliedLocalRestart = undefined;
512
+ // A description applying this generation again signals its candidates
513
+ // again (the remote side rolled back too).
514
+ if (this.stagedLocalRestart)
515
+ this.stagedLocalRestart.emitted = false;
516
+ this.unselectLocalRestart();
517
+ }
518
+ /** The staged generation now belongs to an applied description. */
519
+ markLocalRestartApplied() {
520
+ this.appliedLocalRestart = this.stagedLocalRestart;
521
+ }
522
+ /** Drop only what an unapplied createOffer staged; keep the applied one. */
523
+ discardUnappliedLocalRestart() {
524
+ const staged = this.stagedLocalRestart;
525
+ const applied = this.appliedLocalRestart;
526
+ if (!staged || staged === applied)
527
+ return;
528
+ this.unselectLocalRestart();
529
+ if (applied) {
530
+ this.stagedLocalRestart = applied;
531
+ this.connection.stageLocalCredentials?.(applied.usernameFragment, applied.password);
532
+ }
533
+ }
534
+ /**
535
+ * Called unconditionally on every answer; actually restarts ICE only if
536
+ * this transport has a staged local restart. No-op otherwise.
537
+ */
538
+ async commitLocalRestartIfStaged() {
539
+ const staged = this.stagedLocalRestart;
540
+ if (!staged)
541
+ return;
542
+ // The description already finalized this generation's candidates with
543
+ // end-of-candidates: it only re-advertises the kept sockets, and a server
544
+ // change waits for the next restart. Otherwise the generation keeps
545
+ // gathering from its servers (a fresh STUN mapping, a new TURN allocation)
546
+ // after the commit and trickles what they add.
547
+ const regather = this.stagedGatherPending();
548
+ this.restart(false, regather);
549
+ if (this.connection.commitLocalCredentials) {
550
+ this.connection.commitLocalCredentials(staged.usernameFragment, staged.password);
551
+ }
552
+ else {
553
+ this.connection.localUsername = staged.usernameFragment;
554
+ this.connection.localPassword = staged.password;
555
+ }
556
+ this.stagedLocalRestart = undefined;
557
+ this.appliedLocalRestart = undefined;
558
+ // A local answer signals its candidates after it is applied.
559
+ if (!staged.emitted)
560
+ this.heldCandidateEvents = [];
561
+ // The generation is live now. Its registration stays with the
562
+ // description that carries it (a later commit of another generation does
563
+ // not end it): applying that description again restarts to it, and its
564
+ // candidates are signalled again then.
565
+ staged.emitted = false;
566
+ staged.endDeferred = undefined;
567
+ // The kept sockets are re-advertised synchronously; nothing here waits
568
+ // for a server, so the commit never holds the new generation's checks.
569
+ const gathering = this.gather();
570
+ if (regather) {
571
+ void gathering.catch((error) => log("restart gathering failed", error));
572
+ }
573
+ else {
574
+ await gathering;
575
+ }
576
+ }
577
+ /** Signal the candidates an ICE restart committed by a local answer gathered. */
578
+ emitCommittedCandidates() {
579
+ const held = this.heldCandidateEvents;
580
+ if (!held)
581
+ return;
582
+ this.heldCandidateEvents = undefined;
583
+ for (const candidate of held) {
584
+ this.onIceCandidate.execute(candidate);
585
+ }
200
586
  }
201
587
  getRemoteCandidates() {
202
588
  return this.connection.remoteCandidates
@@ -231,6 +617,10 @@ class RTCIceTransport {
231
617
  });
232
618
  }
233
619
  setState(state, emitEvent = true) {
620
+ // closed is final: checks that stop() interrupted must not report
621
+ // "failed" (or anything else) afterwards.
622
+ if (this.state === "closed")
623
+ return;
234
624
  if (state !== this.state) {
235
625
  this.state = state;
236
626
  this.onStateChange.execute(state);
@@ -244,9 +634,20 @@ class RTCIceTransport {
244
634
  return this.iceGather.gather();
245
635
  }
246
636
  setIceServers(options) {
637
+ this.nextGatherIceServers = undefined;
247
638
  this.iceGather.setIceServers(options);
248
639
  }
249
- setRemoteParams(remoteParameters, renomination = false) {
640
+ /** Keep ICE servers for the next gathering (an ICE restart). */
641
+ deferIceServers(options) {
642
+ this.nextGatherIceServers = options;
643
+ }
644
+ /**
645
+ * `keepLocalCredentials`: the remote credentials come from an answer or
646
+ * pranswer, so the local ones are fixed by the applied local offer. Changed
647
+ * remote credentials restart the checks for the new remote generation
648
+ * without new local credentials (nothing would describe them to the peer).
649
+ */
650
+ setRemoteParams(remoteParameters, renomination = false, { keepLocalCredentials = false } = {}) {
250
651
  if (renomination) {
251
652
  this.renominating = true;
252
653
  }
@@ -257,8 +658,15 @@ class RTCIceTransport {
257
658
  if (this.renominating) {
258
659
  log("renomination", remoteParameters);
259
660
  this.connection.resetNominatedPair();
661
+ // The kept checklist holds only the new remote generation's
662
+ // candidates (and ones without a ufrag, as develop kept them).
663
+ this.connection.dropOtherRemoteGenerations?.(remoteParameters.usernameFragment);
260
664
  this.renominating = false;
261
665
  }
666
+ else if (keepLocalCredentials && this.connection.restartRemote) {
667
+ log("remote restart", remoteParameters);
668
+ this.resetRemoteGeneration();
669
+ }
262
670
  else {
263
671
  log("restart", remoteParameters);
264
672
  this.restart();
@@ -266,15 +674,33 @@ class RTCIceTransport {
266
674
  }
267
675
  this.connection.setRemoteParams(remoteParameters);
268
676
  }
269
- restart() {
677
+ /**
678
+ * Internal: drop the remote generation and its checks, keeping the local
679
+ * credentials and candidates a description already carries (a remote-only
680
+ * restart, or a proposal transport a replacement pranswer left unused).
681
+ */
682
+ resetRemoteGeneration() {
683
+ if (!this.connection.restartRemote)
684
+ return;
685
+ this.connection.restartRemote();
686
+ this.setState("new");
687
+ this.waitStart = undefined;
688
+ this.checksStarted = false;
689
+ }
690
+ restart(notifyNegotiation = true, applyNextGatherIceServers = true) {
270
691
  this.iceRestarts++;
271
692
  this.connection.restart();
693
+ const servers = this.nextGatherIceServers;
694
+ if (servers && applyNextGatherIceServers)
695
+ this.setIceServers(servers);
272
696
  this.setState("new");
273
697
  // Use setGatheringState so onGatheringStateChange fires and the
274
698
  // SecureTransportManager aggregate iceGatheringState stays in sync.
275
699
  this.iceGather.setGatheringState("new");
276
700
  this.waitStart = undefined;
277
- this.onNegotiationNeeded.execute();
701
+ this.checksStarted = false;
702
+ if (notifyNegotiation)
703
+ this.onNegotiationNeeded.execute();
278
704
  }
279
705
  async start() {
280
706
  if (this.state === "closed") {
@@ -286,7 +712,9 @@ class RTCIceTransport {
286
712
  if (this.waitStart) {
287
713
  await this.waitStart.asPromise();
288
714
  }
289
- this.waitStart = new common_1.Event();
715
+ const waitStart = new common_1.Event();
716
+ this.waitStart = waitStart;
717
+ this.checksStarted = true;
290
718
  this.setState("checking");
291
719
  try {
292
720
  await this.connection.connect();
@@ -295,11 +723,34 @@ class RTCIceTransport {
295
723
  this.setState("failed");
296
724
  throw error;
297
725
  }
298
- this.waitStart.execute();
299
- this.waitStart.complete();
300
- this.waitStart = undefined;
726
+ finally {
727
+ // A failed start releases its waiters too.
728
+ if (!waitStart.ended) {
729
+ waitStart.execute();
730
+ waitStart.complete();
731
+ }
732
+ if (this.waitStart === waitStart)
733
+ this.waitStart = undefined;
734
+ }
735
+ }
736
+ /**
737
+ * Settles when the checks a running start() makes finish (at once if none run).
738
+ * @internal
739
+ */
740
+ async checksSettled() {
741
+ const waitStart = this.waitStart;
742
+ if (waitStart)
743
+ await waitStart.asPromise();
301
744
  }
302
745
  async stop() {
746
+ this.localGenerations.clear();
747
+ // Whoever awaits the checks of this transport settles now (checksSettled).
748
+ const waitStart = this.waitStart;
749
+ this.waitStart = undefined;
750
+ if (waitStart && !waitStart.ended) {
751
+ waitStart.execute();
752
+ waitStart.complete();
753
+ }
303
754
  if (this.state !== "closed") {
304
755
  this.setState("closed", false);
305
756
  await this.connection.close();
@@ -438,7 +889,14 @@ class RTCIceGatherer {
438
889
  async gather() {
439
890
  if (this.gatheringState === "new") {
440
891
  this.setState("gathering");
892
+ const generation = this.connection.generation;
441
893
  await this.connection.gatherCandidates();
894
+ // Gathering an ICE restart (or close) replaced in the meantime does not
895
+ // complete the new generation: that one signals its own end.
896
+ if (this.connection.generation !== generation ||
897
+ this.connection.state === "closed") {
898
+ return;
899
+ }
442
900
  this.onIceCandidate(undefined);
443
901
  this.setState("complete");
444
902
  }
@@ -483,13 +941,37 @@ function candidateFromIce(c) {
483
941
  function candidateToIce(x) {
484
942
  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
943
  }
944
+ /** Module-private key for handing already parsed fields to the constructor. */
945
+ const parsedFields = Symbol("RTCIceCandidate.parsedFields");
946
+ /** Create an `RTCIceCandidate` whose fields come from typed values, without reparsing. */
947
+ function createRTCIceCandidate(init, fields) {
948
+ return new RTCIceCandidate({
949
+ ...init,
950
+ [parsedFields]: fields,
951
+ });
952
+ }
953
+ /**
954
+ * Browser-shaped ICE candidate. Besides the signaling fields it exposes the
955
+ * readonly fields of the W3C interface parsed from the candidate a-line
956
+ * (`foundation`, `component`, `priority`, `address`, `protocol`, `port`,
957
+ * `type`, `tcpType`, `relatedAddress`, `relatedPort`). Which candidates give
958
+ * `null` fields is specified on {@link RTCIceCandidateFields}. Candidates
959
+ * werift creates carry them without reparsing; `toJSON()` keeps only the
960
+ * signaling fields (RTCIceCandidateInit). `relayProtocol` and `url` are not
961
+ * implemented.
962
+ */
486
963
  class RTCIceCandidate {
487
- constructor(props) {
964
+ /**
965
+ * Like the browser constructor, only the `RTCIceCandidateInit` members are
966
+ * read; the parsed fields always come from `init.candidate` (`""` when
967
+ * omitted).
968
+ */
969
+ constructor(init = {}) {
488
970
  Object.defineProperty(this, "candidate", {
489
971
  enumerable: true,
490
972
  configurable: true,
491
973
  writable: true,
492
- value: void 0
974
+ value: ""
493
975
  });
494
976
  Object.defineProperty(this, "sdpMid", {
495
977
  enumerable: true,
@@ -509,12 +991,84 @@ class RTCIceCandidate {
509
991
  writable: true,
510
992
  value: void 0
511
993
  });
512
- Object.assign(this, props);
994
+ Object.defineProperty(this, "foundation", {
995
+ enumerable: true,
996
+ configurable: true,
997
+ writable: true,
998
+ value: void 0
999
+ });
1000
+ Object.defineProperty(this, "component", {
1001
+ enumerable: true,
1002
+ configurable: true,
1003
+ writable: true,
1004
+ value: void 0
1005
+ });
1006
+ Object.defineProperty(this, "priority", {
1007
+ enumerable: true,
1008
+ configurable: true,
1009
+ writable: true,
1010
+ value: void 0
1011
+ });
1012
+ Object.defineProperty(this, "address", {
1013
+ enumerable: true,
1014
+ configurable: true,
1015
+ writable: true,
1016
+ value: void 0
1017
+ });
1018
+ Object.defineProperty(this, "protocol", {
1019
+ enumerable: true,
1020
+ configurable: true,
1021
+ writable: true,
1022
+ value: void 0
1023
+ });
1024
+ Object.defineProperty(this, "port", {
1025
+ enumerable: true,
1026
+ configurable: true,
1027
+ writable: true,
1028
+ value: void 0
1029
+ });
1030
+ Object.defineProperty(this, "type", {
1031
+ enumerable: true,
1032
+ configurable: true,
1033
+ writable: true,
1034
+ value: void 0
1035
+ });
1036
+ Object.defineProperty(this, "tcpType", {
1037
+ enumerable: true,
1038
+ configurable: true,
1039
+ writable: true,
1040
+ value: void 0
1041
+ });
1042
+ Object.defineProperty(this, "relatedAddress", {
1043
+ enumerable: true,
1044
+ configurable: true,
1045
+ writable: true,
1046
+ value: void 0
1047
+ });
1048
+ Object.defineProperty(this, "relatedPort", {
1049
+ enumerable: true,
1050
+ configurable: true,
1051
+ writable: true,
1052
+ value: void 0
1053
+ });
1054
+ const { sdpMid, sdpMLineIndex, usernameFragment } = init;
1055
+ const candidate = init.candidate ?? "";
1056
+ const fields = init[parsedFields] ??
1057
+ (0, iceCandidateAttribute_1.candidateFieldsFromValues)((0, iceCandidateAttribute_1.parseCandidateAttribute)(candidate));
1058
+ Object.assign(this, fields, {
1059
+ candidate,
1060
+ sdpMid,
1061
+ sdpMLineIndex,
1062
+ usernameFragment,
1063
+ });
513
1064
  }
1065
+ /**
1066
+ * Same as `new RTCIceCandidate({ candidate: sdp })`, plus `usernameFragment`
1067
+ * taken from the `ufrag` extension attribute of a valid candidate.
1068
+ */
514
1069
  static fromSdp(sdp) {
515
- const ice = src_1.Candidate.fromSdp(sdp);
516
- const candidate = candidateFromIce(ice);
517
- return candidate.toJSON();
1070
+ const values = (0, iceCandidateAttribute_1.parseCandidateAttribute)(sdp);
1071
+ return createRTCIceCandidate({ candidate: sdp, usernameFragment: values?.ufrag }, (0, iceCandidateAttribute_1.candidateFieldsFromValues)(values));
518
1072
  }
519
1073
  static isThis(o) {
520
1074
  if (typeof o?.candidate === "string")
@@ -622,28 +1176,30 @@ class IceCandidate {
622
1176
  value: void 0
623
1177
  });
624
1178
  }
1179
+ /** The parsed fields are validated from these typed values, not by reparsing. */
625
1180
  toJSON() {
626
- return new RTCIceCandidate({
1181
+ return createRTCIceCandidate({
627
1182
  candidate: (0, sdp_1.candidateToSdp)(this),
628
1183
  sdpMLineIndex: this.sdpMLineIndex,
629
1184
  sdpMid: this.sdpMid,
630
1185
  usernameFragment: this.ufrag,
631
- });
1186
+ }, (0, iceCandidateAttribute_1.candidateFieldsFromValues)(this));
632
1187
  }
1188
+ /**
1189
+ * Returns `undefined` when `data.candidate` is empty or violates the grammar
1190
+ * documented on {@link RTCIceCandidateFields}.
1191
+ */
633
1192
  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) { }
1193
+ const values = (0, iceCandidateAttribute_1.parseCandidateAttribute)(data.candidate ?? "");
1194
+ if (!values)
1195
+ return;
1196
+ const candidate = new IceCandidate(values.component, values.foundation, values.ip, values.port, values.priority, values.protocol, values.type, values.generation, values.ufrag);
1197
+ candidate.relatedAddress = values.relatedAddress;
1198
+ candidate.relatedPort = values.relatedPort;
1199
+ candidate.tcpType = values.tcpType;
1200
+ candidate.sdpMLineIndex = data.sdpMLineIndex ?? undefined;
1201
+ candidate.sdpMid = data.sdpMid ?? undefined;
1202
+ return candidate;
647
1203
  }
648
1204
  }
649
1205
  exports.IceCandidate = IceCandidate;