werift 0.25.2 → 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 (314) 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 +16273 -10807
  123. package/lib/nonstandard/index.mjs +8644 -7911
  124. package/lib/polyfill/dom.mjs +22435 -16965
  125. package/lib/polyfill/index.mjs +22435 -16965
  126. package/lib/rtp/src/codec/h264.d.ts +1 -1
  127. package/lib/rtp/src/codec/h264.js.map +1 -1
  128. package/lib/rtp/src/extra/container/webm/container.d.ts +1 -1
  129. package/lib/rtp/src/extra/container/webm/ebml/ebml.d.ts +6 -0
  130. package/lib/rtp/src/extra/container/webm/ebml/ebml.js +20 -1
  131. package/lib/rtp/src/extra/container/webm/ebml/ebml.js.map +1 -1
  132. package/lib/rtp/src/extra/processor/depacketizer.d.ts +1 -1
  133. package/lib/rtp/src/extra/processor/depacketizer.js +1 -1
  134. package/lib/rtp/src/extra/processor/depacketizer.js.map +1 -1
  135. package/lib/rtp/src/extra/processor/depacketizerCallback.d.ts +1 -11
  136. package/lib/rtp/src/extra/processor/depacketizerTransformer.d.ts +1 -1
  137. package/lib/rtp/src/extra/processor/dtxCallback.d.ts +1 -11
  138. package/lib/rtp/src/extra/processor/interface.d.ts +16 -11
  139. package/lib/rtp/src/extra/processor/interface.js.map +1 -1
  140. package/lib/rtp/src/extra/processor/jitterBufferCallback.d.ts +1 -11
  141. package/lib/rtp/src/extra/processor/jitterBufferTransformer.d.ts +1 -1
  142. package/lib/rtp/src/extra/processor/mp4.js +1 -1
  143. package/lib/rtp/src/extra/processor/mp4.js.map +1 -1
  144. package/lib/rtp/src/extra/processor/nack.d.ts +1 -1
  145. package/lib/rtp/src/extra/processor/nack.js +1 -1
  146. package/lib/rtp/src/extra/processor/nack.js.map +1 -1
  147. package/lib/rtp/src/extra/processor/nackHandlerCallback.d.ts +1 -11
  148. package/lib/rtp/src/extra/processor/ntpTime.js.map +1 -1
  149. package/lib/rtp/src/extra/processor/ntpTimeCallback.d.ts +1 -11
  150. package/lib/rtp/src/extra/processor/rtcpCallback.d.ts +1 -1
  151. package/lib/rtp/src/extra/processor/rtcpCallback.js.map +1 -1
  152. package/lib/rtp/src/extra/processor/rtpCallback.d.ts +1 -1
  153. package/lib/rtp/src/extra/processor/rtpCallback.js +1 -1
  154. package/lib/rtp/src/extra/processor/rtpCallback.js.map +1 -1
  155. package/lib/rtp/src/extra/processor/rtpStream.d.ts +2 -2
  156. package/lib/rtp/src/extra/processor/rtpStream.js.map +1 -1
  157. package/lib/rtp/src/extra/processor/rtpTime.js.map +1 -1
  158. package/lib/rtp/src/extra/processor/rtpTimeCallback.d.ts +1 -11
  159. package/lib/rtp/src/extra/processor/webm.d.ts +27 -0
  160. package/lib/rtp/src/extra/processor/webm.js +43 -16
  161. package/lib/rtp/src/extra/processor/webm.js.map +1 -1
  162. package/lib/rtp/src/extra/processor/webmCallback.js +6 -1
  163. package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
  164. package/lib/rtp/src/extra/processor/webmStream.js.map +1 -1
  165. package/lib/rtp/src/helper.d.ts +2 -2
  166. package/lib/rtp/src/helper.js +2 -6
  167. package/lib/rtp/src/helper.js.map +1 -1
  168. package/lib/rtp/src/index.d.ts +3 -2
  169. package/lib/rtp/src/index.js +3 -2
  170. package/lib/rtp/src/index.js.map +1 -1
  171. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js +2 -1
  172. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js.map +1 -1
  173. package/lib/rtp/src/rtcp/rtcp.js +2 -1
  174. package/lib/rtp/src/rtcp/rtcp.js.map +1 -1
  175. package/lib/rtp/src/rtcp/sr.d.ts +4 -3
  176. package/lib/rtp/src/rtcp/sr.js +3 -2
  177. package/lib/rtp/src/rtcp/sr.js.map +1 -1
  178. package/lib/rtp/src/srtp/cipher/ctr.d.ts +2 -2
  179. package/lib/rtp/src/srtp/cipher/ctr.js +1 -1
  180. package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
  181. package/lib/rtp/src/srtp/cipher/gcm.d.ts +1 -1
  182. package/lib/rtp/src/srtp/cipher/gcm.js +1 -1
  183. package/lib/rtp/src/srtp/cipher/gcm.js.map +1 -1
  184. package/lib/rtp/src/srtp/context/context.d.ts +29 -1
  185. package/lib/rtp/src/srtp/context/context.js +78 -24
  186. package/lib/rtp/src/srtp/context/context.js.map +1 -1
  187. package/lib/rtp/src/srtp/context/srtp.js +23 -15
  188. package/lib/rtp/src/srtp/context/srtp.js.map +1 -1
  189. package/lib/sctp/src/index.d.ts +4 -3
  190. package/lib/sctp/src/index.js +10 -8
  191. package/lib/sctp/src/index.js.map +1 -1
  192. package/lib/sctp/src/sctp.d.ts +11 -2
  193. package/lib/sctp/src/sctp.js +47 -28
  194. package/lib/sctp/src/sctp.js.map +1 -1
  195. package/lib/webrtc/src/api/peerConfig.d.ts +264 -0
  196. package/lib/webrtc/src/api/peerConfig.js +250 -0
  197. package/lib/webrtc/src/api/peerConfig.js.map +1 -0
  198. package/lib/webrtc/src/api/peerConnectionEvents.d.ts +36 -0
  199. package/lib/webrtc/src/api/peerConnectionEvents.js +44 -0
  200. package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -0
  201. package/lib/webrtc/src/dataChannel.d.ts +1 -1
  202. package/lib/webrtc/src/dataChannel.js +1 -1
  203. package/lib/webrtc/src/dataChannel.js.map +1 -1
  204. package/lib/webrtc/src/index.d.ts +2 -2
  205. package/lib/webrtc/src/index.js +2 -2
  206. package/lib/webrtc/src/index.js.map +1 -1
  207. package/lib/webrtc/src/media/index.d.ts +1 -1
  208. package/lib/webrtc/src/media/index.js +1 -1
  209. package/lib/webrtc/src/media/index.js.map +1 -1
  210. package/lib/webrtc/src/media/receiver/nack.js +3 -4
  211. package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
  212. package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
  213. package/lib/webrtc/src/media/router.d.ts +116 -5
  214. package/lib/webrtc/src/media/router.js +281 -29
  215. package/lib/webrtc/src/media/router.js.map +1 -1
  216. package/lib/webrtc/src/media/rtpReceiver.d.ts +107 -12
  217. package/lib/webrtc/src/media/rtpReceiver.js +255 -28
  218. package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
  219. package/lib/webrtc/src/media/rtpSender.d.ts +56 -3
  220. package/lib/webrtc/src/media/rtpSender.js +180 -21
  221. package/lib/webrtc/src/media/rtpSender.js.map +1 -1
  222. package/lib/webrtc/src/media/rtpTransceiver.d.ts +94 -1
  223. package/lib/webrtc/src/media/rtpTransceiver.js +111 -2
  224. package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
  225. package/lib/webrtc/src/media/sender/senderBWE.d.ts +2 -1
  226. package/lib/webrtc/src/media/sender/senderBWE.js +22 -10
  227. package/lib/webrtc/src/media/sender/senderBWE.js.map +1 -1
  228. package/lib/webrtc/src/media/track.d.ts +1 -1
  229. package/lib/webrtc/src/media/track.js +1 -1
  230. package/lib/webrtc/src/media/track.js.map +1 -1
  231. package/lib/webrtc/src/negotiation/bundleTopology.d.ts +107 -0
  232. package/lib/webrtc/src/negotiation/bundleTopology.js +380 -0
  233. package/lib/webrtc/src/negotiation/bundleTopology.js.map +1 -0
  234. package/lib/webrtc/src/negotiation/descriptionValidation.d.ts +51 -0
  235. package/lib/webrtc/src/negotiation/descriptionValidation.js +261 -0
  236. package/lib/webrtc/src/negotiation/descriptionValidation.js.map +1 -0
  237. package/lib/webrtc/src/negotiation/iceRestartRequest.d.ts +21 -0
  238. package/lib/webrtc/src/negotiation/iceRestartRequest.js +61 -0
  239. package/lib/webrtc/src/negotiation/iceRestartRequest.js.map +1 -0
  240. package/lib/webrtc/src/negotiation/internalState.d.ts +34 -0
  241. package/lib/webrtc/src/negotiation/internalState.js +21 -0
  242. package/lib/webrtc/src/negotiation/internalState.js.map +1 -0
  243. package/lib/webrtc/src/negotiation/negotiationNeeded.d.ts +44 -0
  244. package/lib/webrtc/src/negotiation/negotiationNeeded.js +118 -0
  245. package/lib/webrtc/src/negotiation/negotiationNeeded.js.map +1 -0
  246. package/lib/webrtc/src/negotiation/remoteCandidates.d.ts +86 -0
  247. package/lib/webrtc/src/negotiation/remoteCandidates.js +344 -0
  248. package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -0
  249. package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +71 -0
  250. package/lib/webrtc/src/negotiation/remoteMediaApplication.js +398 -0
  251. package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -0
  252. package/lib/webrtc/src/negotiation/transportActivation.d.ts +59 -0
  253. package/lib/webrtc/src/negotiation/transportActivation.js +345 -0
  254. package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -0
  255. package/lib/webrtc/src/negotiationTransaction.d.ts +233 -0
  256. package/lib/webrtc/src/negotiationTransaction.js +591 -0
  257. package/lib/webrtc/src/negotiationTransaction.js.map +1 -0
  258. package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
  259. package/lib/webrtc/src/nonstandard/index.d.ts +1 -1
  260. package/lib/webrtc/src/nonstandard/index.js +1 -1
  261. package/lib/webrtc/src/nonstandard/index.js.map +1 -1
  262. package/lib/webrtc/src/nonstandard/navigator.js.map +1 -1
  263. package/lib/webrtc/src/nonstandard/recorder/writer/index.d.ts +1 -1
  264. package/lib/webrtc/src/nonstandard/recorder/writer/index.js.map +1 -1
  265. package/lib/webrtc/src/nonstandard/recorder/writer/webm.d.ts +2 -2
  266. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +2 -2
  267. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
  268. package/lib/webrtc/src/nonstandard/userMedia/packetizer.d.ts +2 -2
  269. package/lib/webrtc/src/nonstandard/userMedia/packetizer.js.map +1 -1
  270. package/lib/webrtc/src/nonstandard/userMedia.d.ts +2 -2
  271. package/lib/webrtc/src/nonstandard/userMedia.js +2 -2
  272. package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
  273. package/lib/webrtc/src/peerConnection.d.ts +132 -237
  274. package/lib/webrtc/src/peerConnection.js +971 -908
  275. package/lib/webrtc/src/peerConnection.js.map +1 -1
  276. package/lib/webrtc/src/polyfill/api.d.ts +5 -5
  277. package/lib/webrtc/src/polyfill/api.js.map +1 -1
  278. package/lib/webrtc/src/polyfill/index.js.map +1 -1
  279. package/lib/webrtc/src/polyfill/install.js +1 -1
  280. package/lib/webrtc/src/polyfill/install.js.map +1 -1
  281. package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
  282. package/lib/webrtc/src/polyfill/registers/mp4Webm.js.map +1 -1
  283. package/lib/webrtc/src/polyfill/registers/rtpRtcp.js.map +1 -1
  284. package/lib/webrtc/src/polyfill/selectSettings.js.map +1 -1
  285. package/lib/webrtc/src/polyfill/sourceIo.js.map +1 -1
  286. package/lib/webrtc/src/sctpManager.d.ts +66 -2
  287. package/lib/webrtc/src/sctpManager.js +122 -5
  288. package/lib/webrtc/src/sctpManager.js.map +1 -1
  289. package/lib/webrtc/src/sdp.js.map +1 -1
  290. package/lib/webrtc/src/sdpManager.d.ts +55 -11
  291. package/lib/webrtc/src/sdpManager.js +364 -87
  292. package/lib/webrtc/src/sdpManager.js.map +1 -1
  293. package/lib/webrtc/src/secureTransportManager.d.ts +38 -25
  294. package/lib/webrtc/src/secureTransportManager.js +130 -34
  295. package/lib/webrtc/src/secureTransportManager.js.map +1 -1
  296. package/lib/webrtc/src/transceiverManager.d.ts +62 -18
  297. package/lib/webrtc/src/transceiverManager.js +264 -104
  298. package/lib/webrtc/src/transceiverManager.js.map +1 -1
  299. package/lib/webrtc/src/transport/dtls.d.ts +11 -2
  300. package/lib/webrtc/src/transport/dtls.js +37 -13
  301. package/lib/webrtc/src/transport/dtls.js.map +1 -1
  302. package/lib/webrtc/src/transport/ice.d.ts +254 -7
  303. package/lib/webrtc/src/transport/ice.js +608 -52
  304. package/lib/webrtc/src/transport/ice.js.map +1 -1
  305. package/lib/webrtc/src/transport/iceCandidateAttribute.d.ts +98 -0
  306. package/lib/webrtc/src/transport/iceCandidateAttribute.js +129 -0
  307. package/lib/webrtc/src/transport/iceCandidateAttribute.js.map +1 -0
  308. package/lib/webrtc/src/transport/sctp.d.ts +4 -1
  309. package/lib/webrtc/src/transport/sctp.js +83 -17
  310. package/lib/webrtc/src/transport/sctp.js.map +1 -1
  311. package/lib/webrtc/src/utils.d.ts +3 -3
  312. package/lib/webrtc/src/utils.js +1 -1
  313. package/lib/webrtc/src/utils.js.map +1 -1
  314. package/package.json +13 -14
@@ -0,0 +1,380 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BundleTopology = void 0;
4
+ const src_1 = require("../../../sctp/src");
5
+ const errors_1 = require("../errors");
6
+ /**
7
+ * BUNDLE ownership of a negotiation: which transport each m-line uses for a
8
+ * proposal. Every BUNDLE group counts (RFC 8843 allows several); the tag of a
9
+ * group owns the transport its members share. A proposal that changes the
10
+ * topology (split, merge, new owner) gets its transports prepared in the
11
+ * negotiation transaction and switches only at the commit.
12
+ *
13
+ * - For a first negotiation and for answers, each offered group shares one
14
+ * transport and an m-line outside every group gets its own, whatever
15
+ * `bundlePolicy` is. A re-offer or pranswer on a live session keeps every
16
+ * current owner on its transport, so moving an established member out of
17
+ * its group (RFC 8843 section 7.5) is staged, not rejected.
18
+ * - A split prepares a separate ICE/DTLS transport for the new owner while the
19
+ * shared one stays connected. The new owner is a new DTLS association
20
+ * (offered `actpass`); each transport takes the DTLS role of its own m-line.
21
+ * The m-line that moves away brings its new ufrag to its own transport; the
22
+ * transport it leaves is not restarted.
23
+ * - An answer leaves an m-line it rejects out of its group (RFC 8843 section
24
+ * 7.3.3); werift's port-0 `inactive` m-lines are not rejections and stay.
25
+ */
26
+ class BundleTopology {
27
+ constructor(sdp, transceivers, sctp, negotiation,
28
+ /** A new transport with its own ICE credentials. */
29
+ createTransport,
30
+ /** The PeerConnection was closed (checked after every await). */
31
+ isClosed = () => false) {
32
+ Object.defineProperty(this, "sdp", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: sdp
37
+ });
38
+ Object.defineProperty(this, "transceivers", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: transceivers
43
+ });
44
+ Object.defineProperty(this, "sctp", {
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true,
48
+ value: sctp
49
+ });
50
+ Object.defineProperty(this, "negotiation", {
51
+ enumerable: true,
52
+ configurable: true,
53
+ writable: true,
54
+ value: negotiation
55
+ });
56
+ Object.defineProperty(this, "createTransport", {
57
+ enumerable: true,
58
+ configurable: true,
59
+ writable: true,
60
+ value: createTransport
61
+ });
62
+ Object.defineProperty(this, "isClosed", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: isClosed
67
+ });
68
+ }
69
+ /**
70
+ * After an await while preparing transports: a close() that ran meanwhile
71
+ * already disposed the negotiation, so the transports this preparation
72
+ * created are stopped here and it fails instead of creating more.
73
+ */
74
+ async assertOpen(created) {
75
+ if (!this.isClosed())
76
+ return;
77
+ await Promise.allSettled(created.map((transport) => transport.stop()));
78
+ throw (0, errors_1.createWebRtcDomException)("InvalidStateError", "RTCPeerConnection is closed");
79
+ }
80
+ /**
81
+ * BUNDLE tag (first MID) of the group of `description` that contains `mid`.
82
+ * Every group counts, not only the first one.
83
+ */
84
+ bundleTagOf(description, mid) {
85
+ if (this.sdp.bundlePolicy === "disable" || mid == undefined)
86
+ return;
87
+ return description.group.find((group) => group.semantic === "BUNDLE" && group.items.includes(mid))?.items[0];
88
+ }
89
+ /** `mid` is a BUNDLE member that shares its group tag's transport. */
90
+ isBundledNonTag(description, mid) {
91
+ const tag = this.bundleTagOf(description, mid);
92
+ return tag !== undefined && tag !== mid;
93
+ }
94
+ /** The transport prepared for `mid` by the pending proposal, else its live one. */
95
+ currentTransportForMid(mid) {
96
+ return (this.negotiation.transportByMid.get(mid) ??
97
+ this.transceivers.getTransceivers().find((t) => t.mid === mid)
98
+ ?.dtlsTransport ??
99
+ (this.sctp.sctpTransport?.mid === mid
100
+ ? this.sctp.sctpTransport.dtlsTransport
101
+ : undefined));
102
+ }
103
+ /**
104
+ * The transports `description` puts its accepted m-lines on: each m-line's
105
+ * BUNDLE owner (group tag, else itself), on the transport prepared for the
106
+ * proposal or else its live one.
107
+ */
108
+ transportsOf(description) {
109
+ const transports = new Set();
110
+ for (const media of description.media) {
111
+ const mid = media.rtp.muxId;
112
+ if (media.port === 0 || !mid)
113
+ continue;
114
+ const owner = this.bundleTagOf(description, mid) ?? mid;
115
+ const transport = this.negotiation.transportByMid.get(owner) ??
116
+ this.liveTransportForMid(owner);
117
+ if (transport)
118
+ transports.add(transport);
119
+ }
120
+ return transports;
121
+ }
122
+ liveTransportForMid(mid) {
123
+ return this.liveTransportByMid().get(mid);
124
+ }
125
+ liveTransportByMid() {
126
+ const byMid = new Map();
127
+ for (const transceiver of this.transceivers.getTransceivers()) {
128
+ if (transceiver.mid)
129
+ byMid.set(transceiver.mid, transceiver.dtlsTransport);
130
+ }
131
+ const sctp = this.sctp.sctpTransport;
132
+ if (sctp?.mid)
133
+ byMid.set(sctp.mid, sctp.dtlsTransport);
134
+ return byMid;
135
+ }
136
+ /**
137
+ * Prepare the transports a local offer needs without touching the pending
138
+ * transaction. A replacement offer is staged here first, so a failure (for
139
+ * example ICE gathering of a new BUNDLE owner) stops only what was staged
140
+ * and leaves the previous pending offer, its transports and the signaling
141
+ * state as they were. `assigned` are the transports of transceivers the
142
+ * offer associates that are not associated yet (it is not applied yet).
143
+ * Only the new transports are kept: an owner that reuses a live transport
144
+ * takes the one it is bound to when the offer is installed.
145
+ */
146
+ async stageLocalOffer(offer, assigned = new Map()) {
147
+ const currentByMid = this.liveTransportByMid();
148
+ for (const [mid, transport] of assigned) {
149
+ if (!currentByMid.has(mid))
150
+ currentByMid.set(mid, transport);
151
+ }
152
+ // Until the peer has accepted BUNDLE in the committed session, an offered
153
+ // group is only a proposal under max-compat / balanced: a member keeps
154
+ // its own transport and candidates and the answer that accepts the group
155
+ // merges them (RFC 8843 section 7.2). It shares its tag's transport in
156
+ // the offer under max-bundle, once the peer bundles, or when it already
157
+ // does (or has no transport of its own yet).
158
+ const peerBundles = !!this.sdp.currentRemoteDescription?.group.some((group) => group.semantic === "BUNDLE");
159
+ const ownerByMid = new Map();
160
+ for (const media of offer.media) {
161
+ const mid = media.rtp.muxId;
162
+ if (media.port === 0 || !mid)
163
+ continue;
164
+ const tag = this.bundleTagOf(offer, mid) ?? mid;
165
+ const own = currentByMid.get(mid);
166
+ const shared = tag === mid ||
167
+ this.sdp.bundlePolicy === "max-bundle" ||
168
+ peerBundles ||
169
+ !own ||
170
+ own === currentByMid.get(tag);
171
+ ownerByMid.set(mid, shared ? tag : mid);
172
+ }
173
+ // Select one transport per proposed owner, starting with the transport
174
+ // already bound to the BUNDLE tag. Every member then follows that owner.
175
+ const ownerTransport = new Map();
176
+ const used = new Set();
177
+ const created = [];
178
+ try {
179
+ for (const owner of new Set(ownerByMid.values())) {
180
+ let transport = currentByMid.get(owner);
181
+ let pendingOnly = false;
182
+ if (!transport || used.has(transport)) {
183
+ transport = this.createTransport();
184
+ created.push(transport);
185
+ pendingOnly = true;
186
+ await transport.iceTransport.gather();
187
+ await this.assertOpen(created);
188
+ }
189
+ used.add(transport);
190
+ ownerTransport.set(owner, { transport, pendingOnly });
191
+ }
192
+ }
193
+ catch (error) {
194
+ await Promise.allSettled(created.map((transport) => transport.stop()));
195
+ throw error;
196
+ }
197
+ return [...ownerByMid].map(([mid, owner]) => ({
198
+ mid,
199
+ owner,
200
+ ...ownerTransport.get(owner),
201
+ }));
202
+ }
203
+ /** Hand staged local-offer transports to the pending transaction. */
204
+ installLocalOffer(offer, staged) {
205
+ const live = this.liveTransportByMid();
206
+ for (const { mid, owner, transport: stagedTransport, pendingOnly, } of staged) {
207
+ if (pendingOnly) {
208
+ this.negotiation.prepareTransport(offer, mid, stagedTransport, true);
209
+ this.negotiation.prepareTransport(offer, mid, stagedTransport);
210
+ continue;
211
+ }
212
+ // The live transport the owner is bound to now (retiring a first
213
+ // negotiation's provisional connection may have replaced it).
214
+ const transport = live.get(owner) ?? stagedTransport;
215
+ this.negotiation.prepareTransport(offer, mid, transport);
216
+ }
217
+ }
218
+ /**
219
+ * Decide which live transport each proposed BUNDLE owner of a re-offer would
220
+ * reuse. `undefined` means the owner needs a new pending transport.
221
+ */
222
+ planPending(offer) {
223
+ const ownerByMid = new Map();
224
+ for (const media of offer.media) {
225
+ if (media.port === 0 || !media.rtp.muxId)
226
+ continue;
227
+ if ((media.kind === "audio" || media.kind === "video") &&
228
+ this.transceivers
229
+ .getTransceivers()
230
+ .find((transceiver) => transceiver.mid === media.rtp.muxId)?.codecs
231
+ .length === 0)
232
+ continue;
233
+ ownerByMid.set(media.rtp.muxId, this.bundleTagOf(offer, media.rtp.muxId) ?? media.rtp.muxId);
234
+ }
235
+ const currentByMid = this.liveTransportByMid();
236
+ // An ICE restart alone keeps the owner's DTLS transport; its new ICE
237
+ // generation is staged on that transport's ICE connection.
238
+ const owners = new Map();
239
+ const used = new Set();
240
+ for (const owner of new Set(ownerByMid.values())) {
241
+ const transport = currentByMid.get(owner);
242
+ if (!transport || used.has(transport)) {
243
+ owners.set(owner, {});
244
+ }
245
+ else {
246
+ owners.set(owner, { reuse: transport });
247
+ used.add(transport);
248
+ }
249
+ }
250
+ return { ownerByMid, owners };
251
+ }
252
+ /** Reject a re-offer whose topology would move a connected SCTP association. */
253
+ assertPendingSctpBinding(offer) {
254
+ const sctp = this.sctp.sctpTransport;
255
+ if (!this.sdp.currentRemoteDescription ||
256
+ !sctp?.mid ||
257
+ sctp.sctp?.associationState !== src_1.SCTP_STATE.ESTABLISHED)
258
+ return;
259
+ const { ownerByMid, owners } = this.planPending(offer);
260
+ const owner = ownerByMid.get(sctp.mid);
261
+ if (owner === undefined)
262
+ return;
263
+ if (owners.get(owner)?.reuse !== sctp.dtlsTransport) {
264
+ throw (0, errors_1.createWebRtcDomException)("InvalidModificationError", "Moving a connected SCTP association to another DTLS transport is unsupported");
265
+ }
266
+ }
267
+ /** Keep a re-offer's proposed BUNDLE owners separate from the live bindings. */
268
+ async preparePending() {
269
+ const offer = this.sdp.pendingRemoteDescription;
270
+ if (!offer ||
271
+ offer.type !== "offer" ||
272
+ this.negotiation.preparedDescription === offer)
273
+ return;
274
+ if (!this.sdp.currentRemoteDescription)
275
+ return;
276
+ this.assertPendingSctpBinding(offer);
277
+ const { ownerByMid, owners } = this.planPending(offer);
278
+ const created = [];
279
+ try {
280
+ const ownerTransports = new Map();
281
+ for (const [owner, plan] of owners) {
282
+ let transport = plan.reuse;
283
+ if (!transport) {
284
+ transport = this.createTransport();
285
+ created.push(transport);
286
+ this.negotiation.prepareTransport(offer, owner, transport, true);
287
+ await transport.iceTransport.gather();
288
+ await this.assertOpen(created);
289
+ }
290
+ ownerTransports.set(owner, transport);
291
+ }
292
+ for (const [mid, owner] of ownerByMid) {
293
+ this.negotiation.prepareTransport(offer, mid, ownerTransports.get(owner));
294
+ }
295
+ }
296
+ catch (error) {
297
+ await this.negotiation.discardPreparedTransports();
298
+ throw error;
299
+ }
300
+ }
301
+ /** The answer commits: every m-line moves to the transport prepared for it. */
302
+ applyPending(answer) {
303
+ const transports = this.negotiation.transportByMid;
304
+ if (transports.size === 0)
305
+ return;
306
+ for (const transceiver of this.transceivers.getTransceivers()) {
307
+ const transport = transceiver.mid && transports.get(transceiver.mid);
308
+ if (transport)
309
+ transceiver.setDtlsTransport(transport);
310
+ }
311
+ const sctp = this.sctp.sctpTransport;
312
+ // An answer that rejects the application m-line negotiates no transport
313
+ // for it: the SCTP transport stays where it runs (as in develop).
314
+ const rejected = !!answer &&
315
+ answer.media.find((media) => media.rtp.muxId === sctp?.mid)?.port === 0;
316
+ if (sctp?.mid && !rejected) {
317
+ // SCTP goes straight to the transport of its owner in the answer: a
318
+ // detour over its own prepared transport would replace the
319
+ // association (also one a first pranswer already connected).
320
+ const owner = (answer && this.bundleTagOf(answer, sctp.mid)) ?? sctp.mid;
321
+ const transport = transports.get(owner) ??
322
+ (owner !== sctp.mid
323
+ ? this.transceivers.getTransceivers().find((t) => t.mid === owner)
324
+ ?.dtlsTransport
325
+ : undefined);
326
+ if (transport)
327
+ sctp.setDtlsTransport(transport);
328
+ }
329
+ }
330
+ /**
331
+ * remote answer / pranswer の検証 (offerer 側、状態を変更する前に実行する)。
332
+ * local offer で 1 つの transport を共有した m-line を、answer が同じ BUNDLE group に置かずに
333
+ * 異なる ICE credentials で受け入れることはできない (RFC 8843 7.3.2)。共有 transport は分割できず、
334
+ * 新しい transport を作ると offer で渡した ICE credentials とも一致しなくなる。
335
+ * group の記述が MID と一致しなくても remote の ICE credentials が同じなら、同じ transport のまま扱う。
336
+ */
337
+ assertAnswerKeepsSharedTransports(answer, signalingState) {
338
+ if (!["answer", "pranswer"].includes(answer.type) ||
339
+ !["have-local-offer", "have-remote-pranswer"].includes(signalingState) ||
340
+ this.sdp.bundlePolicy === "disable") {
341
+ return;
342
+ }
343
+ const answerGroups = answer.group.filter((g) => g.semantic === "BUNDLE");
344
+ const byTransport = new Map();
345
+ const sctp = this.sctp.sctpTransport;
346
+ for (const media of answer.media) {
347
+ const mid = media.rtp.muxId;
348
+ if (media.port === 0 || mid == undefined) {
349
+ continue;
350
+ }
351
+ const owner = media.kind === "application"
352
+ ? sctp?.mid === mid
353
+ ? sctp
354
+ : undefined
355
+ : this.transceivers
356
+ .getTransceivers()
357
+ .find((t) => t.mid === mid && !t.stopped);
358
+ // local offer 用に準備した transport があれば、それが offer での所有 transport
359
+ const transport = this.negotiation.transportByMid.get(mid) ?? owner?.dtlsTransport;
360
+ if (!transport) {
361
+ continue;
362
+ }
363
+ const current = {
364
+ group: answerGroups.find((g) => g.items.includes(mid)),
365
+ credentials: `${media.iceParams?.usernameFragment}:${media.iceParams?.password}`,
366
+ };
367
+ const first = byTransport.get(transport);
368
+ if (!first) {
369
+ byTransport.set(transport, current);
370
+ continue;
371
+ }
372
+ const sameGroup = !!current.group && current.group === first.group;
373
+ if (!sameGroup && current.credentials !== first.credentials) {
374
+ throw (0, errors_1.createWebRtcDomException)("InvalidAccessError", `mid=${mid} shares a transport in the local offer but the remote ${answer.type} moves it out of that BUNDLE group`);
375
+ }
376
+ }
377
+ }
378
+ }
379
+ exports.BundleTopology = BundleTopology;
380
+ //# sourceMappingURL=bundleTopology.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundleTopology.js","sourceRoot":"","sources":["../../../../src/negotiation/bundleTopology.ts"],"names":[],"mappings":";;;AAAA,2CAA+C;AAC/C,sCAAqD;AASrD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,cAAc;IACzB,YACmB,GAAe,EACf,YAAgC,EAChC,IAA0B,EAC1B,WAAmC;IACpD,oDAAoD;IACnC,eAAuC;IACxD,iEAAiE;IAChD,WAA0B,GAAG,EAAE,CAAC,KAAK;QAPtD;;;;mBAAiB,GAAG;WAAY;QAChC;;;;mBAAiB,YAAY;WAAoB;QACjD;;;;mBAAiB,I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C,SAAS,EAAE,gBAAgB,IAAI,KAAK,CAAC,SAAS,EAAE,QAAQ,EAAE;aACjF,CAAC;YACF,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YACzC,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,WAAW,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;gBACpC,SAAS;YACX,CAAC;YACD,MAAM,SAAS,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,CAAC;YACnE,IAAI,CAAC,SAAS,IAAI,OAAO,CAAC,WAAW,KAAK,KAAK,CAAC,WAAW,EAAE,CAAC;gBAC5D,MAAM,IAAA,iCAAwB,EAC5B,oBAAoB,EACpB,OAAO,GAAG,yDAAyD,MAAM,CAAC,IAAI,oCAAoC,CACnH,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAzXD,wCAyXC","sourcesContent":["import { SCTP_STATE } from \"../../../sctp/src\";\nimport { createWebRtcDomException } from \"../errors\";\nimport type { TransceiverManager } from \"../media\";\nimport type { NegotiationTransaction } from \"../negotiationTransaction\";\nimport type { SctpTransportManager } from \"../sctpManager\";\nimport type { GroupDescription, SessionDescription } from \"../sdp\";\nimport type { SDPManager } from \"../sdpManager\";\nimport type { RTCDtlsTransport } from \"../transport/dtls\";\nimport type { RTCSignalingState } from \"../types/domain\";\n\n/**\n * BUNDLE ownership of a negotiation: which transport each m-line uses for a\n * proposal. Every BUNDLE group counts (RFC 8843 allows several); the tag of a\n * group owns the transport its members share. A proposal that changes the\n * topology (split, merge, new owner) gets its transports prepared in the\n * negotiation transaction and switches only at the commit.\n *\n * - For a first negotiation and for answers, each offered group shares one\n * transport and an m-line outside every group gets its own, whatever\n * `bundlePolicy` is. A re-offer or pranswer on a live session keeps every\n * current owner on its transport, so moving an established member out of\n * its group (RFC 8843 section 7.5) is staged, not rejected.\n * - A split prepares a separate ICE/DTLS transport for the new owner while the\n * shared one stays connected. The new owner is a new DTLS association\n * (offered `actpass`); each transport takes the DTLS role of its own m-line.\n * The m-line that moves away brings its new ufrag to its own transport; the\n * transport it leaves is not restarted.\n * - An answer leaves an m-line it rejects out of its group (RFC 8843 section\n * 7.3.3); werift's port-0 `inactive` m-lines are not rejections and stay.\n */\nexport class BundleTopology {\n constructor(\n private readonly sdp: SDPManager,\n private readonly transceivers: TransceiverManager,\n private readonly sctp: SctpTransportManager,\n private readonly negotiation: NegotiationTransaction,\n /** A new transport with its own ICE credentials. */\n private readonly createTransport: () => RTCDtlsTransport,\n /** The PeerConnection was closed (checked after every await). */\n private readonly isClosed: () => boolean = () => false,\n ) {}\n\n /**\n * After an await while preparing transports: a close() that ran meanwhile\n * already disposed the negotiation, so the transports this preparation\n * created are stopped here and it fails instead of creating more.\n */\n private async assertOpen(created: RTCDtlsTransport[]) {\n if (!this.isClosed()) return;\n await Promise.allSettled(created.map((transport) => transport.stop()));\n throw createWebRtcDomException(\n \"InvalidStateError\",\n \"RTCPeerConnection is closed\",\n );\n }\n\n /**\n * BUNDLE tag (first MID) of the group of `description` that contains `mid`.\n * Every group counts, not only the first one.\n */\n bundleTagOf(description: SessionDescription, mid?: string | null) {\n if (this.sdp.bundlePolicy === \"disable\" || mid == undefined) return;\n return description.group.find(\n (group) => group.semantic === \"BUNDLE\" && group.items.includes(mid),\n )?.items[0];\n }\n\n /** `mid` is a BUNDLE member that shares its group tag's transport. */\n isBundledNonTag(description: SessionDescription, mid?: string | null) {\n const tag = this.bundleTagOf(description, mid);\n return tag !== undefined && tag !== mid;\n }\n\n /** The transport prepared for `mid` by the pending proposal, else its live one. */\n currentTransportForMid(mid: string) {\n return (\n this.negotiation.transportByMid.get(mid) ??\n this.transceivers.getTransceivers().find((t) => t.mid === mid)\n ?.dtlsTransport ??\n (this.sctp.sctpTransport?.mid === mid\n ? this.sctp.sctpTransport.dtlsTransport\n : undefined)\n );\n }\n\n /**\n * The transports `description` puts its accepted m-lines on: each m-line's\n * BUNDLE owner (group tag, else itself), on the transport prepared for the\n * proposal or else its live one.\n */\n transportsOf(description: SessionDescription) {\n const transports = new Set<RTCDtlsTransport>();\n for (const media of description.media) {\n const mid = media.rtp.muxId;\n if (media.port === 0 || !mid) continue;\n const owner = this.bundleTagOf(description, mid) ?? mid;\n const transport =\n this.negotiation.transportByMid.get(owner) ??\n this.liveTransportForMid(owner);\n if (transport) transports.add(transport);\n }\n return transports;\n }\n\n liveTransportForMid(mid: string) {\n return this.liveTransportByMid().get(mid);\n }\n\n private liveTransportByMid() {\n const byMid = new Map<string, RTCDtlsTransport>();\n for (const transceiver of this.transceivers.getTransceivers()) {\n if (transceiver.mid)\n byMid.set(transceiver.mid, transceiver.dtlsTransport);\n }\n const sctp = this.sctp.sctpTransport;\n if (sctp?.mid) byMid.set(sctp.mid, sctp.dtlsTransport);\n return byMid;\n }\n\n /**\n * Prepare the transports a local offer needs without touching the pending\n * transaction. A replacement offer is staged here first, so a failure (for\n * example ICE gathering of a new BUNDLE owner) stops only what was staged\n * and leaves the previous pending offer, its transports and the signaling\n * state as they were. `assigned` are the transports of transceivers the\n * offer associates that are not associated yet (it is not applied yet).\n * Only the new transports are kept: an owner that reuses a live transport\n * takes the one it is bound to when the offer is installed.\n */\n async stageLocalOffer(\n offer: SessionDescription,\n assigned: ReadonlyMap<string, RTCDtlsTransport> = new Map(),\n ) {\n const currentByMid = this.liveTransportByMid();\n for (const [mid, transport] of assigned) {\n if (!currentByMid.has(mid)) currentByMid.set(mid, transport);\n }\n // Until the peer has accepted BUNDLE in the committed session, an offered\n // group is only a proposal under max-compat / balanced: a member keeps\n // its own transport and candidates and the answer that accepts the group\n // merges them (RFC 8843 section 7.2). It shares its tag's transport in\n // the offer under max-bundle, once the peer bundles, or when it already\n // does (or has no transport of its own yet).\n const peerBundles = !!this.sdp.currentRemoteDescription?.group.some(\n (group) => group.semantic === \"BUNDLE\",\n );\n const ownerByMid = new Map<string, string>();\n for (const media of offer.media) {\n const mid = media.rtp.muxId;\n if (media.port === 0 || !mid) continue;\n const tag = this.bundleTagOf(offer, mid) ?? mid;\n const own = currentByMid.get(mid);\n const shared =\n tag === mid ||\n this.sdp.bundlePolicy === \"max-bundle\" ||\n peerBundles ||\n !own ||\n own === currentByMid.get(tag);\n ownerByMid.set(mid, shared ? tag : mid);\n }\n\n // Select one transport per proposed owner, starting with the transport\n // already bound to the BUNDLE tag. Every member then follows that owner.\n const ownerTransport = new Map<\n string,\n { transport: RTCDtlsTransport; pendingOnly: boolean }\n >();\n const used = new Set<RTCDtlsTransport>();\n const created: RTCDtlsTransport[] = [];\n try {\n for (const owner of new Set(ownerByMid.values())) {\n let transport = currentByMid.get(owner);\n let pendingOnly = false;\n if (!transport || used.has(transport)) {\n transport = this.createTransport();\n created.push(transport);\n pendingOnly = true;\n await transport.iceTransport.gather();\n await this.assertOpen(created);\n }\n used.add(transport);\n ownerTransport.set(owner, { transport, pendingOnly });\n }\n } catch (error) {\n await Promise.allSettled(created.map((transport) => transport.stop()));\n throw error;\n }\n\n return [...ownerByMid].map(([mid, owner]) => ({\n mid,\n owner,\n ...ownerTransport.get(owner)!,\n }));\n }\n\n /** Hand staged local-offer transports to the pending transaction. */\n installLocalOffer(\n offer: SessionDescription,\n staged: Awaited<ReturnType<BundleTopology[\"stageLocalOffer\"]>>,\n ) {\n const live = this.liveTransportByMid();\n for (const {\n mid,\n owner,\n transport: stagedTransport,\n pendingOnly,\n } of staged) {\n if (pendingOnly) {\n this.negotiation.prepareTransport(offer, mid, stagedTransport, true);\n this.negotiation.prepareTransport(offer, mid, stagedTransport);\n continue;\n }\n // The live transport the owner is bound to now (retiring a first\n // negotiation's provisional connection may have replaced it).\n const transport = live.get(owner) ?? stagedTransport;\n this.negotiation.prepareTransport(offer, mid, transport);\n }\n }\n\n /**\n * Decide which live transport each proposed BUNDLE owner of a re-offer would\n * reuse. `undefined` means the owner needs a new pending transport.\n */\n planPending(offer: SessionDescription) {\n const ownerByMid = new Map<string, string>();\n for (const media of offer.media) {\n if (media.port === 0 || !media.rtp.muxId) continue;\n if (\n (media.kind === \"audio\" || media.kind === \"video\") &&\n this.transceivers\n .getTransceivers()\n .find((transceiver) => transceiver.mid === media.rtp.muxId)?.codecs\n .length === 0\n )\n continue;\n ownerByMid.set(\n media.rtp.muxId,\n this.bundleTagOf(offer, media.rtp.muxId) ?? media.rtp.muxId,\n );\n }\n const currentByMid = this.liveTransportByMid();\n // An ICE restart alone keeps the owner's DTLS transport; its new ICE\n // generation is staged on that transport's ICE connection.\n const owners = new Map<string, { reuse?: RTCDtlsTransport }>();\n const used = new Set<RTCDtlsTransport>();\n for (const owner of new Set(ownerByMid.values())) {\n const transport = currentByMid.get(owner);\n if (!transport || used.has(transport)) {\n owners.set(owner, {});\n } else {\n owners.set(owner, { reuse: transport });\n used.add(transport);\n }\n }\n return { ownerByMid, owners };\n }\n\n /** Reject a re-offer whose topology would move a connected SCTP association. */\n assertPendingSctpBinding(offer: SessionDescription) {\n const sctp = this.sctp.sctpTransport;\n if (\n !this.sdp.currentRemoteDescription ||\n !sctp?.mid ||\n sctp.sctp?.associationState !== SCTP_STATE.ESTABLISHED\n )\n return;\n const { ownerByMid, owners } = this.planPending(offer);\n const owner = ownerByMid.get(sctp.mid);\n if (owner === undefined) return;\n if (owners.get(owner)?.reuse !== sctp.dtlsTransport) {\n throw createWebRtcDomException(\n \"InvalidModificationError\",\n \"Moving a connected SCTP association to another DTLS transport is unsupported\",\n );\n }\n }\n\n /** Keep a re-offer's proposed BUNDLE owners separate from the live bindings. */\n async preparePending() {\n const offer = this.sdp.pendingRemoteDescription;\n if (\n !offer ||\n offer.type !== \"offer\" ||\n this.negotiation.preparedDescription === offer\n )\n return;\n if (!this.sdp.currentRemoteDescription) return;\n\n this.assertPendingSctpBinding(offer);\n const { ownerByMid, owners } = this.planPending(offer);\n const created: RTCDtlsTransport[] = [];\n try {\n const ownerTransports = new Map<string, RTCDtlsTransport>();\n for (const [owner, plan] of owners) {\n let transport = plan.reuse;\n if (!transport) {\n transport = this.createTransport();\n created.push(transport);\n this.negotiation.prepareTransport(offer, owner, transport, true);\n await transport.iceTransport.gather();\n await this.assertOpen(created);\n }\n ownerTransports.set(owner, transport);\n }\n for (const [mid, owner] of ownerByMid) {\n this.negotiation.prepareTransport(\n offer,\n mid,\n ownerTransports.get(owner)!,\n );\n }\n } catch (error) {\n await this.negotiation.discardPreparedTransports();\n throw error;\n }\n }\n\n /** The answer commits: every m-line moves to the transport prepared for it. */\n applyPending(answer?: SessionDescription) {\n const transports = this.negotiation.transportByMid;\n if (transports.size === 0) return;\n for (const transceiver of this.transceivers.getTransceivers()) {\n const transport = transceiver.mid && transports.get(transceiver.mid);\n if (transport) transceiver.setDtlsTransport(transport);\n }\n const sctp = this.sctp.sctpTransport;\n // An answer that rejects the application m-line negotiates no transport\n // for it: the SCTP transport stays where it runs (as in develop).\n const rejected =\n !!answer &&\n answer.media.find((media) => media.rtp.muxId === sctp?.mid)?.port === 0;\n if (sctp?.mid && !rejected) {\n // SCTP goes straight to the transport of its owner in the answer: a\n // detour over its own prepared transport would replace the\n // association (also one a first pranswer already connected).\n const owner = (answer && this.bundleTagOf(answer, sctp.mid)) ?? sctp.mid;\n const transport =\n transports.get(owner) ??\n (owner !== sctp.mid\n ? this.transceivers.getTransceivers().find((t) => t.mid === owner)\n ?.dtlsTransport\n : undefined);\n if (transport) sctp.setDtlsTransport(transport);\n }\n }\n\n /**\n * remote answer / pranswer の検証 (offerer 側、状態を変更する前に実行する)。\n * local offer で 1 つの transport を共有した m-line を、answer が同じ BUNDLE group に置かずに\n * 異なる ICE credentials で受け入れることはできない (RFC 8843 7.3.2)。共有 transport は分割できず、\n * 新しい transport を作ると offer で渡した ICE credentials とも一致しなくなる。\n * group の記述が MID と一致しなくても remote の ICE credentials が同じなら、同じ transport のまま扱う。\n */\n assertAnswerKeepsSharedTransports(\n answer: SessionDescription,\n signalingState: RTCSignalingState,\n ) {\n if (\n ![\"answer\", \"pranswer\"].includes(answer.type) ||\n ![\"have-local-offer\", \"have-remote-pranswer\"].includes(signalingState) ||\n this.sdp.bundlePolicy === \"disable\"\n ) {\n return;\n }\n const answerGroups = answer.group.filter((g) => g.semantic === \"BUNDLE\");\n const byTransport = new Map<\n RTCDtlsTransport,\n { group?: GroupDescription; credentials: string }\n >();\n const sctp = this.sctp.sctpTransport;\n for (const media of answer.media) {\n const mid = media.rtp.muxId;\n if (media.port === 0 || mid == undefined) {\n continue;\n }\n const owner =\n media.kind === \"application\"\n ? sctp?.mid === mid\n ? sctp\n : undefined\n : this.transceivers\n .getTransceivers()\n .find((t) => t.mid === mid && !t.stopped);\n // local offer 用に準備した transport があれば、それが offer での所有 transport\n const transport =\n this.negotiation.transportByMid.get(mid) ?? owner?.dtlsTransport;\n if (!transport) {\n continue;\n }\n const current = {\n group: answerGroups.find((g) => g.items.includes(mid)),\n credentials: `${media.iceParams?.usernameFragment}:${media.iceParams?.password}`,\n };\n const first = byTransport.get(transport);\n if (!first) {\n byTransport.set(transport, current);\n continue;\n }\n const sameGroup = !!current.group && current.group === first.group;\n if (!sameGroup && current.credentials !== first.credentials) {\n throw createWebRtcDomException(\n \"InvalidAccessError\",\n `mid=${mid} shares a transport in the local offer but the remote ${answer.type} moves it out of that BUNDLE group`,\n );\n }\n }\n }\n}\n"]}
@@ -0,0 +1,51 @@
1
+ import type { PeerConfig } from "../api/peerConfig";
2
+ import { type TransceiverManager } from "../media";
3
+ import type { NegotiationTransaction } from "../negotiationTransaction";
4
+ import type { SctpTransportManager } from "../sctpManager";
5
+ import type { SessionDescription } from "../sdp";
6
+ import type { SDPManager } from "../sdpManager";
7
+ import type { RTCDtlsTransport } from "../transport/dtls";
8
+ import type { RTCSignalingState } from "../types/domain";
9
+ import type { BundleTopology } from "./bundleTopology";
10
+ /**
11
+ * Validation of a description before any transaction or live state changes.
12
+ * A description that fails here leaves the signaling state, both
13
+ * descriptions and every transport as they were.
14
+ */
15
+ export declare class DescriptionValidation {
16
+ private readonly config;
17
+ private readonly sdp;
18
+ private readonly transceivers;
19
+ private readonly sctp;
20
+ private readonly negotiation;
21
+ private readonly topology;
22
+ constructor(config: PeerConfig, sdp: SDPManager, transceivers: TransceiverManager, sctp: SctpTransportManager, negotiation: NegotiationTransaction, topology: BundleTopology);
23
+ /**
24
+ * A local description must use the ICE credentials of the transports
25
+ * prepared for it and keep the DTLS role of a live association.
26
+ */
27
+ /**
28
+ * Validate a local description without changing anything. `transportForMid`
29
+ * resolves the transport of an m-line the description associates with a
30
+ * transceiver that is not associated yet.
31
+ */
32
+ validateLocal(description: SessionDescription, transportForMid?: (mid: string) => RTCDtlsTransport | undefined): void;
33
+ /**
34
+ * A remote description: common codecs with the pending local offer, shared
35
+ * transports, media kinds, SCTP port, codecs, DTLS fingerprint and role, and
36
+ * SCTP binding are all checked before any state changes.
37
+ */
38
+ /**
39
+ * A new MID on an existing m-line recycles it (JSEP 5.2.2). An m-line the
40
+ * current session did not reject belongs to a local transceiver; only a
41
+ * stopped one gives its slot up, an inactive one the application keeps
42
+ * does not.
43
+ */
44
+ private assertRecyclesOnlyStoppedMLines;
45
+ validateRemote(remoteSdp: SessionDescription, signalingState: RTCSignalingState): void;
46
+ /**
47
+ * Local codecs an answer m-line without a recorded local offer is checked
48
+ * against: the configured codecs (a sender track's codec is not adopted).
49
+ */
50
+ private localCodecsFor;
51
+ }