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
@@ -0,0 +1,591 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NegotiationTransaction = void 0;
4
+ /**
5
+ * Resources a pending proposal created or prepared. They belong to the
6
+ * proposal: replacement and rollback drop them, a checkpoint copies them.
7
+ */
8
+ class ProposalResources {
9
+ constructor() {
10
+ /** Transceivers a remote offer created. */
11
+ Object.defineProperty(this, "remoteCreated", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: new Set()
16
+ });
17
+ /** Transceivers whose m-line a remote offer recycled with a new MID. */
18
+ Object.defineProperty(this, "displaced", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: new Set()
23
+ });
24
+ /** Transport each MID uses under the proposal (BUNDLE topology). */
25
+ Object.defineProperty(this, "prepared", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: new Map()
30
+ });
31
+ /** Prepared transports no live binding uses yet. */
32
+ Object.defineProperty(this, "pendingOnly", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: new Set()
37
+ });
38
+ /** Transports a remote offer created to own a BUNDLE group or an m-line. */
39
+ Object.defineProperty(this, "owners", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: new Set()
44
+ });
45
+ /** Pending-only transports whose candidates were already emitted. */
46
+ Object.defineProperty(this, "emittedCandidates", {
47
+ enumerable: true,
48
+ configurable: true,
49
+ writable: true,
50
+ value: new Set()
51
+ });
52
+ /** The description the transports were prepared for. */
53
+ Object.defineProperty(this, "preparedFor", {
54
+ enumerable: true,
55
+ configurable: true,
56
+ writable: true,
57
+ value: void 0
58
+ });
59
+ }
60
+ /** Transports that only this proposal holds. */
61
+ get speculativeTransports() {
62
+ return [...this.pendingOnly, ...this.owners];
63
+ }
64
+ clear() {
65
+ this.assign(new ProposalResources());
66
+ }
67
+ copy() {
68
+ const copy = new ProposalResources();
69
+ copy.assign(this);
70
+ return copy;
71
+ }
72
+ assign(source) {
73
+ replaceSet(this.remoteCreated, source.remoteCreated);
74
+ replaceSet(this.displaced, source.displaced);
75
+ replaceSet(this.pendingOnly, source.pendingOnly);
76
+ replaceSet(this.owners, source.owners);
77
+ replaceSet(this.emittedCandidates, source.emittedCandidates);
78
+ this.prepared.clear();
79
+ for (const [mid, transport] of source.prepared) {
80
+ this.prepared.set(mid, transport);
81
+ }
82
+ this.preparedFor = source.preparedFor;
83
+ }
84
+ }
85
+ /** The DTLS transports a baseline binds (transceivers and SCTP). */
86
+ function baselineTransports(baseline) {
87
+ if (!baseline)
88
+ return [];
89
+ return [
90
+ ...[...baseline.transceivers.states.values()].map(({ transceiver }) => transceiver.dtlsTransport),
91
+ baseline.sctp.dtlsTransport,
92
+ ].filter((transport) => !!transport);
93
+ }
94
+ function replaceSet(target, source) {
95
+ const values = [...source];
96
+ target.clear();
97
+ for (const value of values)
98
+ target.add(value);
99
+ }
100
+ /** Remote ufrags of retired generations kept to reject late callbacks. */
101
+ const RETIRED_UFRAG_HISTORY = 64;
102
+ /**
103
+ * One owner for the reversible metadata of a PeerConnection negotiation.
104
+ *
105
+ * Invariant: the last pair of descriptions that reached `stable` is
106
+ * **current**. Its RTP routes, BUNDLE owners, ICE selected pair, DTLS session
107
+ * and SCTP association stay usable while another negotiation is pending.
108
+ * Packet-driven state (counters, consent, retransmission) belongs to the live
109
+ * transport and is never part of a snapshot.
110
+ *
111
+ * An applied offer opens the transaction. The state before it is the
112
+ * **rollback baseline**, captured once (first wins): a replacement offer or
113
+ * pranswer replaces only the **pending** proposal and its resources
114
+ * (`ProposalResources`, candidate buckets, provisional routes, new SCTP
115
+ * associations). The final answer is the only commit boundary; a pranswer may
116
+ * run provisional traffic without changing the current pair. An event already
117
+ * delivered to the application (track, candidate, DataChannel) is never
118
+ * retracted, and a repeated description does not deliver it again.
119
+ *
120
+ * Phases (owned here, driven by RTCPeerConnection):
121
+ *
122
+ * | Phase | Rule |
123
+ * | --- | --- |
124
+ * | begin | Capture the baseline once. `createOffer` in stable only records the snapshot its `setLocalDescription` adopts (`snapshotForOffer`); a remote offer captures its own. |
125
+ * | replace/update | Retire the previous proposal's pending-only resources and candidate buckets; keep the baseline and the delivered-event history. A byte-identical description is idempotent. |
126
+ * | validate | Every check (signaling transition, MIDs, BUNDLE, codecs, ICE credentials, DTLS role, SCTP port) runs before any live mutation (`DescriptionValidation`); a failure leaves the previous pending and current state untouched. |
127
+ * | prepare | New transports and media objects are allocated under the proposal; a failure stops only what it allocated. |
128
+ * | commit | Final answer only: switch BUNDLE routing, ICE generation, DTLS parameters, SCTP binding and RTP/router, then publish the current descriptions and `stable`. Nothing fallible runs after the switch; asynchronous connect work starts afterwards. |
129
+ * | rollback | Stop provisional communication, drop pending candidates and resources, restore the baseline and publish `stable`. Rolling back a first negotiation resets the connection states to `new`. |
130
+ * | cleanup | Stop orphan proposal resources; a transport created during the transaction that no binding holds at commit stops. |
131
+ *
132
+ * Signaling transitions (JSEP 3.2; `have-remote-pranswer` also accepts a
133
+ * replacement local offer, which first rolls back the remote pranswer):
134
+ *
135
+ * | State | Local input | Remote input |
136
+ * | --- | --- | --- |
137
+ * | stable | offer → have-local-offer | offer → have-remote-offer |
138
+ * | have-local-offer | offer, rollback → stable | pranswer → have-remote-pranswer; answer → stable; offer → implicit rollback, have-remote-offer |
139
+ * | have-remote-offer | pranswer → have-local-pranswer; answer → stable | offer; rollback → stable |
140
+ * | have-local-pranswer | pranswer; answer → stable | rollback → stable; offer → implicit rollback, have-remote-offer |
141
+ * | have-remote-pranswer | rollback → stable; offer → have-local-offer | pranswer; answer → stable |
142
+ *
143
+ * What a pending proposal may change, per subsystem (K = final answer
144
+ * commit, R = rollback):
145
+ *
146
+ * - RTP / router: new routing keys at once, conflicting ones staged until K
147
+ * (`RtpRouter`); codec and direction of current m-lines follow the
148
+ * effective-value rules. R restores the baseline tables.
149
+ * - BUNDLE: current owners keep their transports; a changed topology gets
150
+ * transports prepared for the proposal and switches at K (`BundleTopology`).
151
+ * - ICE: a restart is staged on the live transport, with a provisional
152
+ * generation during a pranswer (`RTCIceTransport`); K switches, R drops it.
153
+ * - DTLS: the current session and role are kept; only a new association (a
154
+ * BUNDLE split owner) handshakes during the proposal.
155
+ * - SCTP: the current association stays live; a new pending association may
156
+ * run at a pranswer and closes on R. A port change or move of an
157
+ * established association is rejected in validate.
158
+ * - Candidates / end-of-candidates: kept per generation (ufrag) and per
159
+ * proposal; replacement and R drop the pending buckets
160
+ * (`RemoteCandidates`).
161
+ *
162
+ * Which description each live value follows while pending (current,
163
+ * provisional at a pranswer, both, or reject) is tabulated and checked by
164
+ * `expectedLive` and `assertNegotiationInvariants` in
165
+ * tests/negotiation/harness/negotiationTransactionUtils.ts.
166
+ *
167
+ * Each component owns the snapshot of its reversible state and the rule for
168
+ * restoring it; this class only composes them. Add new negotiation state to
169
+ * its component's pair:
170
+ *
171
+ * | Component | Snapshot / restore | Kept across rollback |
172
+ * | --- | --- | --- |
173
+ * | `RTCRtpTransceiver` (with sender, receiver) | `snapshotNegotiationState` / `restoreNegotiationState` | an application `stop()` made during the transaction |
174
+ * | `RTCRtpReceiver` | `snapshotNegotiationState` / `restoreNegotiationState` | SSRCs learned from RID packets whose track survives |
175
+ * | `TransceiverManager` | `snapshotNegotiationState` / `restoreNegotiationState` | transceivers the application uses (`heldByApplication`) |
176
+ * | `RtpRouter` | `snapshotRoutes` / `restoreRoutes` | packet-learned SSRC routes, every live sender's route |
177
+ * | `SctpTransportManager` | `snapshotNegotiationState` / `restoreNegotiationState` | an application-created SCTP transport whose association never ran |
178
+ */
179
+ class NegotiationTransaction {
180
+ constructor(sdp, transceivers, router, sctp) {
181
+ Object.defineProperty(this, "sdp", {
182
+ enumerable: true,
183
+ configurable: true,
184
+ writable: true,
185
+ value: sdp
186
+ });
187
+ Object.defineProperty(this, "transceivers", {
188
+ enumerable: true,
189
+ configurable: true,
190
+ writable: true,
191
+ value: transceivers
192
+ });
193
+ Object.defineProperty(this, "router", {
194
+ enumerable: true,
195
+ configurable: true,
196
+ writable: true,
197
+ value: router
198
+ });
199
+ Object.defineProperty(this, "sctp", {
200
+ enumerable: true,
201
+ configurable: true,
202
+ writable: true,
203
+ value: sctp
204
+ });
205
+ Object.defineProperty(this, "baseline", {
206
+ enumerable: true,
207
+ configurable: true,
208
+ writable: true,
209
+ value: void 0
210
+ });
211
+ Object.defineProperty(this, "offerSnapshot", {
212
+ enumerable: true,
213
+ configurable: true,
214
+ writable: true,
215
+ value: void 0
216
+ });
217
+ Object.defineProperty(this, "resources", {
218
+ enumerable: true,
219
+ configurable: true,
220
+ writable: true,
221
+ value: new ProposalResources()
222
+ });
223
+ Object.defineProperty(this, "retiredRemoteUfrags", {
224
+ enumerable: true,
225
+ configurable: true,
226
+ writable: true,
227
+ value: new Set()
228
+ });
229
+ /**
230
+ * Transports created since the last commit. One that no binding holds at
231
+ * commit (e.g. a data channel's own transport that BUNDLE replaced) stops.
232
+ */
233
+ Object.defineProperty(this, "createdTransports", {
234
+ enumerable: true,
235
+ configurable: true,
236
+ writable: true,
237
+ value: new Set()
238
+ });
239
+ /** Negotiation state of each transceiver a remote offer created, at creation. */
240
+ Object.defineProperty(this, "createdStates", {
241
+ enumerable: true,
242
+ configurable: true,
243
+ writable: true,
244
+ value: new WeakMap()
245
+ });
246
+ Object.defineProperty(this, "revision", {
247
+ enumerable: true,
248
+ configurable: true,
249
+ writable: true,
250
+ value: 0
251
+ });
252
+ Object.defineProperty(this, "phase", {
253
+ enumerable: true,
254
+ configurable: true,
255
+ writable: true,
256
+ value: "idle"
257
+ });
258
+ }
259
+ // # lifecycle
260
+ /**
261
+ * `createOffer` in stable records the baseline it would roll back to, but
262
+ * does not open a transaction: nothing is pending until the offer is set.
263
+ */
264
+ snapshotForOffer() {
265
+ if (this.baseline)
266
+ return;
267
+ const fresh = this.capture();
268
+ if (!this.offerSnapshot) {
269
+ this.offerSnapshot = fresh;
270
+ return;
271
+ }
272
+ // Earlier createOffer calls were not applied: keep the state from before
273
+ // the first of them (their MIDs and m-line indexes are not negotiated),
274
+ // and only add transceivers the application created since.
275
+ const { order, states } = this.offerSnapshot.transceivers;
276
+ for (const [transceiver, state] of fresh.transceivers.states) {
277
+ if (!states.has(transceiver)) {
278
+ states.set(transceiver, state);
279
+ order.push(transceiver);
280
+ }
281
+ }
282
+ }
283
+ /**
284
+ * Open the transaction when a description is applied. A local offer uses
285
+ * the snapshot taken by the `createOffer` that produced it, so MIDs that
286
+ * createOffer assigned revert on rollback; anything else captures now.
287
+ */
288
+ begin({ fromCreatedOffer = false } = {}) {
289
+ if (!this.baseline && !fromCreatedOffer && this.offerSnapshot) {
290
+ // When a remote offer opens the transaction instead, what an unapplied
291
+ // createOffer associated goes back first.
292
+ this.transceivers.revertUnappliedAssociations(this.offerSnapshot.transceivers);
293
+ this.sctp.revertUnappliedAssociation(this.offerSnapshot.sctp);
294
+ }
295
+ if (!this.baseline) {
296
+ this.baseline =
297
+ (fromCreatedOffer ? this.offerSnapshot : undefined) ?? this.capture();
298
+ }
299
+ this.offerSnapshot = undefined;
300
+ this.revision++;
301
+ this.phase = "pending";
302
+ return this.revision;
303
+ }
304
+ /** A description was applied without committing: the proposal is pending. */
305
+ settle() {
306
+ if (this.baseline)
307
+ this.phase = "pending";
308
+ }
309
+ validate() {
310
+ this.phase = "validating";
311
+ }
312
+ prepare() {
313
+ this.phase = "preparing";
314
+ }
315
+ async commit() {
316
+ this.phase = "committing";
317
+ // Routes and decode entries a pending proposal could not take from the
318
+ // current session switch now, together with the descriptions.
319
+ this.router.commitStaged();
320
+ for (const transceiver of this.transceivers.getTransceivers()) {
321
+ transceiver.receiver.commitStagedReceive();
322
+ }
323
+ // The recycling offer is final: the displaced transceiver stops for good.
324
+ for (const transceiver of this.resources.displaced) {
325
+ if (!transceiver.stopped)
326
+ continue;
327
+ transceiver.setCurrentDirection("stopped");
328
+ transceiver.receiver.stop();
329
+ transceiver.sender.stop();
330
+ }
331
+ // Every transport the previous session or this transaction used is a
332
+ // candidate; those no live binding holds after the commit stop.
333
+ const candidates = new Set(this.createdTransports);
334
+ for (const { transceiver } of this.baseline?.transceivers.states.values() ??
335
+ []) {
336
+ candidates.add(transceiver.dtlsTransport);
337
+ }
338
+ if (this.baseline?.sctp.dtlsTransport) {
339
+ candidates.add(this.baseline.sctp.dtlsTransport);
340
+ }
341
+ this.createdTransports.clear();
342
+ this.cleanup();
343
+ const inUse = this.transportsInUse({ includeStopped: false });
344
+ await Promise.all([...candidates]
345
+ .filter((transport) => !inUse.has(transport))
346
+ .map((transport) => transport.stop()));
347
+ }
348
+ /**
349
+ * A pranswer replaced an earlier one: a transport the proposal prepared that
350
+ * neither a live binding nor the pranswer (`used`) puts an m-line on stops
351
+ * the checks the earlier pranswer started. It
352
+ * stays held (a final answer may still use it) with its local generation.
353
+ */
354
+ stopUnusedProposalChecks(used) {
355
+ const inUse = this.transportsInUse({ includeStopped: false });
356
+ for (const transport of used)
357
+ inUse.add(transport);
358
+ for (const transport of new Set([
359
+ ...this.createdTransports,
360
+ ...this.resources.speculativeTransports,
361
+ ])) {
362
+ if (inUse.has(transport))
363
+ continue;
364
+ if (["new", "closed"].includes(transport.iceTransport.state))
365
+ continue;
366
+ transport.iceTransport.resetRemoteGeneration();
367
+ }
368
+ }
369
+ /**
370
+ * A replacement proposal: back to the baseline, which stays for the new one.
371
+ * A transceiver the replaced remote offer created for a MID the replacing
372
+ * one describes again (same kind) is carried over in its created state, so
373
+ * the new offer associates the same object and nothing is notified twice.
374
+ */
375
+ async replace(next) {
376
+ if (!this.baseline)
377
+ return;
378
+ const describedAgain = (transceiver) => !!next?.media.some((media) => media.port !== 0 &&
379
+ media.kind === transceiver.kind &&
380
+ media.rtp.muxId === transceiver.mid);
381
+ const carried = new Set([...this.resources.remoteCreated].filter(describedAgain));
382
+ // A transceiver that existed before the transaction and that the
383
+ // replacing offer describes again keeps the track it already notified,
384
+ // so the replacement fires no second track event (W3C [[FiredDirection]]).
385
+ const notified = new Set(this.transceivers
386
+ .getTransceivers()
387
+ .filter((t) => !this.resources.remoteCreated.has(t) && describedAgain(t)));
388
+ await this.restoreState(this.baseline, this.resources.remoteCreated, this.resources.speculativeTransports, carried, notified);
389
+ this.resources.clear();
390
+ for (const transceiver of carried) {
391
+ this.resources.remoteCreated.add(transceiver);
392
+ }
393
+ this.revision++;
394
+ this.phase = "pending";
395
+ }
396
+ async rollback() {
397
+ if (!this.baseline)
398
+ return;
399
+ await this.restoreState(this.baseline, this.resources.remoteCreated, this.resources.speculativeTransports);
400
+ this.cleanup();
401
+ }
402
+ /**
403
+ * Record the state before one description operation mutates anything, so a
404
+ * failure inside that operation can undo exactly its own changes.
405
+ */
406
+ checkpoint() {
407
+ return { state: this.capture(), resources: this.resources.copy() };
408
+ }
409
+ /** Undo one failed description operation back to its checkpoint. */
410
+ async restoreCheckpoint(checkpoint) {
411
+ const before = checkpoint.resources;
412
+ const kept = new Set(before.speculativeTransports);
413
+ await this.restoreState(checkpoint.state, [...this.resources.remoteCreated].filter((transceiver) => !before.remoteCreated.has(transceiver)), this.resources.speculativeTransports.filter((transport) => !kept.has(transport)));
414
+ this.resources.assign(before);
415
+ this.phase = "pending";
416
+ }
417
+ /**
418
+ * PeerConnection close: stop every transport only the negotiation holds
419
+ * (created for a proposal, pending-only, BUNDLE owners, prepared for a
420
+ * topology), which no transceiver or SCTP binding would stop, then drop
421
+ * every reference.
422
+ */
423
+ async dispose() {
424
+ const transports = new Set([
425
+ ...this.createdTransports,
426
+ ...this.resources.speculativeTransports,
427
+ ...this.resources.prepared.values(),
428
+ // A transport only the rollback baseline still binds (a pending
429
+ // description moved its m-lines to another transport): no binding
430
+ // stops it at close.
431
+ ...baselineTransports(this.baseline),
432
+ ...baselineTransports(this.offerSnapshot),
433
+ ]);
434
+ this.createdTransports.clear();
435
+ this.offerSnapshot = undefined;
436
+ this.cleanup();
437
+ await Promise.allSettled([...transports].map((transport) => transport.stop()));
438
+ }
439
+ // # proposal resources
440
+ noteCreatedTransport(transport) {
441
+ this.createdTransports.add(transport);
442
+ // A stopped transport needs no cleanup; do not keep referencing it.
443
+ transport.onStateChange.subscribe((state) => {
444
+ if (state === "closed")
445
+ this.createdTransports.delete(transport);
446
+ });
447
+ }
448
+ rememberRemoteTransceiver(transceiver) {
449
+ this.resources.remoteCreated.add(transceiver);
450
+ // Before the offer negotiates anything on it: a rollback that keeps the
451
+ // transceiver (the application uses it) returns it to this state.
452
+ this.createdStates.set(transceiver, transceiver.snapshotNegotiationState());
453
+ }
454
+ rememberOwnerTransport(transport) {
455
+ this.resources.owners.add(transport);
456
+ }
457
+ rememberDisplacedTransceiver(transceiver) {
458
+ this.resources.displaced.add(transceiver);
459
+ }
460
+ get preparedDescription() {
461
+ return this.resources.preparedFor;
462
+ }
463
+ get transportByMid() {
464
+ return this.resources.prepared;
465
+ }
466
+ isPendingOnlyTransport(iceTransportId) {
467
+ return [...this.resources.pendingOnly].some((transport) => transport.iceTransport.id === iceTransportId);
468
+ }
469
+ takePreparedCandidateTransports() {
470
+ const { pendingOnly, emittedCandidates } = this.resources;
471
+ const transports = [...pendingOnly].filter((transport) => !emittedCandidates.has(transport.id));
472
+ for (const transport of transports) {
473
+ emittedCandidates.add(transport.id);
474
+ }
475
+ return transports;
476
+ }
477
+ prepareTransport(description, mid, transport, pendingOnly = false) {
478
+ this.resources.preparedFor = description;
479
+ this.resources.prepared.set(mid, transport);
480
+ if (pendingOnly)
481
+ this.resources.pendingOnly.add(transport);
482
+ }
483
+ async discardPreparedTransports() {
484
+ const { prepared, pendingOnly, emittedCandidates } = this.resources;
485
+ const stopping = [...pendingOnly];
486
+ prepared.clear();
487
+ pendingOnly.clear();
488
+ emittedCandidates.clear();
489
+ this.resources.preparedFor = undefined;
490
+ await Promise.allSettled(stopping.map((transport) => transport.stop()));
491
+ }
492
+ /**
493
+ * A remote pranswer or answer replaces every earlier remote pranswer of
494
+ * this offer: routes and receive values those staged are dropped before it
495
+ * applies, so the commit switches only to what the latest description
496
+ * carries.
497
+ */
498
+ discardStagedRemoteAnswer() {
499
+ this.router.discardProvisional();
500
+ this.router.restoreStaged({ ssrc: [], rid: [] });
501
+ for (const transceiver of this.transceivers.getTransceivers()) {
502
+ transceiver.receiver.discardStagedReceive();
503
+ }
504
+ }
505
+ // # retired ICE generations
506
+ retireRemoteGeneration(description) {
507
+ for (const media of description?.media ?? []) {
508
+ const ufrag = media.iceParams?.usernameFragment;
509
+ if (ufrag)
510
+ this.retiredRemoteUfrags.add(ufrag);
511
+ }
512
+ // A bounded history covers late callbacks without retaining every past
513
+ // negotiation for the lifetime of a long-running peer.
514
+ while (this.retiredRemoteUfrags.size > RETIRED_UFRAG_HISTORY) {
515
+ this.retiredRemoteUfrags.delete(this.retiredRemoteUfrags.values().next().value);
516
+ }
517
+ }
518
+ isRetiredRemoteUfrag(ufrag) {
519
+ return !!ufrag && this.retiredRemoteUfrags.has(ufrag);
520
+ }
521
+ // # state capture and restore
522
+ capture() {
523
+ return {
524
+ transceivers: this.transceivers.snapshotNegotiationState(),
525
+ routes: this.router.snapshotRoutes(),
526
+ sctp: this.sctp.snapshotNegotiationState(),
527
+ };
528
+ }
529
+ /**
530
+ * Put transceivers, routes and SCTP back to `baseline`. Transceivers in
531
+ * `added` and transports in `speculative` were created after it; those no
532
+ * restored owner uses stop.
533
+ */
534
+ async restoreState(baseline, added, speculative, carried = new Set(), notified = new Set()) {
535
+ const removedTransports = this.transceivers.restoreNegotiationState(baseline.transceivers, added, (transceiver) => this.createdStates.get(transceiver), carried, notified);
536
+ const live = this.transceivers.getTransceivers();
537
+ this.router.restoreRoutes(baseline.routes, {
538
+ endpoints: new Set(live.flatMap((t) => [t.sender, t.receiver])),
539
+ liveSenders: live
540
+ .filter((t) => !t.stopped && !t.stopping)
541
+ .map((t) => t.sender),
542
+ });
543
+ // The transport an SCTP transport the proposal created ran on (a remote
544
+ // offer's application m-line) stops with it unless something else uses it.
545
+ const proposedSctp = this.sctp.sctpTransport?.dtlsTransport;
546
+ await this.sctp.restoreNegotiationState(baseline.sctp);
547
+ const inUse = this.transportsInUse({ includeStopped: true });
548
+ for (const transport of new Set([
549
+ ...speculative,
550
+ ...removedTransports,
551
+ ...(proposedSctp ? [proposedSctp] : []),
552
+ ])) {
553
+ if (!inUse.has(transport))
554
+ await transport.stop();
555
+ }
556
+ }
557
+ /** Transports a transceiver (optionally a stopped one) or SCTP is bound to. */
558
+ transportsInUse({ includeStopped }) {
559
+ const inUse = new Set(this.transceivers
560
+ .getTransceivers()
561
+ .filter((transceiver) => includeStopped || !transceiver.stopped)
562
+ .map((transceiver) => transceiver.dtlsTransport));
563
+ const sctp = this.sctp.sctpTransport?.dtlsTransport;
564
+ if (sctp)
565
+ inUse.add(sctp);
566
+ return inUse;
567
+ }
568
+ cleanup() {
569
+ this.baseline = undefined;
570
+ this.resources.clear();
571
+ this.phase = "idle";
572
+ }
573
+ /** Internal test observation, never exposed on the public API. */
574
+ inspect() {
575
+ return {
576
+ phase: this.phase,
577
+ revision: this.revision,
578
+ currentLocal: this.sdp.currentLocalDescription,
579
+ currentRemote: this.sdp.currentRemoteDescription,
580
+ pendingLocal: this.sdp.pendingLocalDescription,
581
+ pendingRemote: this.sdp.pendingRemoteDescription,
582
+ baselineTransceivers: this.baseline?.transceivers.states.size ?? 0,
583
+ remoteCreated: this.resources.remoteCreated.size,
584
+ pendingTransports: this.resources.pendingOnly.size,
585
+ createdTransports: [...this.createdTransports],
586
+ hasOfferSnapshot: !!this.offerSnapshot,
587
+ };
588
+ }
589
+ }
590
+ exports.NegotiationTransaction = NegotiationTransaction;
591
+ //# sourceMappingURL=negotiationTransaction.js.map