werift 0.25.2 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (568) hide show
  1. package/README.md +63 -0
  2. package/THIRD_PARTY_LICENSES_LIBWEBRTC.txt +58 -0
  3. package/lib/common/src/asn1.d.ts +42 -0
  4. package/lib/common/src/asn1.js +163 -0
  5. package/lib/common/src/asn1.js.map +1 -0
  6. package/lib/common/src/binary.d.ts +1 -3
  7. package/lib/common/src/binary.js +8 -6
  8. package/lib/common/src/binary.js.map +1 -1
  9. package/lib/common/src/binaryData.js +2 -1
  10. package/lib/common/src/binaryData.js.map +1 -1
  11. package/lib/common/src/index.d.ts +6 -5
  12. package/lib/common/src/index.js +6 -5
  13. package/lib/common/src/index.js.map +1 -1
  14. package/lib/common/src/log.d.ts +12 -1
  15. package/lib/common/src/log.js +142 -12
  16. package/lib/common/src/log.js.map +1 -1
  17. package/lib/common/src/network.js.map +1 -1
  18. package/lib/common/src/queue.d.ts +41 -0
  19. package/lib/common/src/queue.js +146 -0
  20. package/lib/common/src/queue.js.map +1 -0
  21. package/lib/common/src/transport.d.ts +15 -2
  22. package/lib/common/src/transport.js +108 -19
  23. package/lib/common/src/transport.js.map +1 -1
  24. package/lib/dtls/src/cipher/create.js.map +1 -1
  25. package/lib/dtls/src/cipher/ec.js +8 -8
  26. package/lib/dtls/src/cipher/ec.js.map +1 -1
  27. package/lib/dtls/src/cipher/namedCurve.js +6 -7
  28. package/lib/dtls/src/cipher/namedCurve.js.map +1 -1
  29. package/lib/dtls/src/cipher/prf.d.ts +2 -2
  30. package/lib/dtls/src/cipher/prf.js +29 -8
  31. package/lib/dtls/src/cipher/prf.js.map +1 -1
  32. package/lib/dtls/src/cipher/suites/aead.d.ts +1 -1
  33. package/lib/dtls/src/context/certificate.d.ts +32 -0
  34. package/lib/dtls/src/context/certificate.js +54 -0
  35. package/lib/dtls/src/context/certificate.js.map +1 -0
  36. package/lib/dtls/src/context/cipher.d.ts +13 -7
  37. package/lib/dtls/src/context/cipher.js +58 -106
  38. package/lib/dtls/src/context/cipher.js.map +1 -1
  39. package/lib/dtls/src/context/dtls.js +4 -2
  40. package/lib/dtls/src/context/dtls.js.map +1 -1
  41. package/lib/dtls/src/context/transport.d.ts +4 -0
  42. package/lib/dtls/src/context/transport.js +16 -1
  43. package/lib/dtls/src/context/transport.js.map +1 -1
  44. package/lib/dtls/src/flight/client/flight1.js +2 -1
  45. package/lib/dtls/src/flight/client/flight1.js.map +1 -1
  46. package/lib/dtls/src/flight/client/flight5.js +4 -2
  47. package/lib/dtls/src/flight/client/flight5.js.map +1 -1
  48. package/lib/dtls/src/flight/flight.d.ts +1 -1
  49. package/lib/dtls/src/flight/flight.js +16 -5
  50. package/lib/dtls/src/flight/flight.js.map +1 -1
  51. package/lib/dtls/src/flight/server/flight2.js.map +1 -1
  52. package/lib/dtls/src/flight/server/flight4.d.ts +2 -1
  53. package/lib/dtls/src/flight/server/flight4.js +12 -4
  54. package/lib/dtls/src/flight/server/flight4.js.map +1 -1
  55. package/lib/dtls/src/flight/server/flight6.js +2 -1
  56. package/lib/dtls/src/flight/server/flight6.js.map +1 -1
  57. package/lib/dtls/src/handshake/const.d.ts +17 -13
  58. package/lib/dtls/src/handshake/const.js +16 -14
  59. package/lib/dtls/src/handshake/const.js.map +1 -1
  60. package/lib/dtls/src/handshake/extensions/signature.d.ts +1 -1
  61. package/lib/dtls/src/handshake/extensions/signature.js.map +1 -1
  62. package/lib/dtls/src/handshake/message/alert.js +5 -3
  63. package/lib/dtls/src/handshake/message/alert.js.map +1 -1
  64. package/lib/dtls/src/handshake/message/certificate.js +3 -2
  65. package/lib/dtls/src/handshake/message/certificate.js.map +1 -1
  66. package/lib/dtls/src/handshake/message/changeCipherSpec.js +4 -4
  67. package/lib/dtls/src/handshake/message/changeCipherSpec.js.map +1 -1
  68. package/lib/dtls/src/handshake/message/client/certificateVerify.d.ts +1 -1
  69. package/lib/dtls/src/handshake/message/client/certificateVerify.js +5 -3
  70. package/lib/dtls/src/handshake/message/client/certificateVerify.js.map +1 -1
  71. package/lib/dtls/src/handshake/message/client/hello.js +15 -8
  72. package/lib/dtls/src/handshake/message/client/hello.js.map +1 -1
  73. package/lib/dtls/src/handshake/message/client/keyExchange.js +3 -2
  74. package/lib/dtls/src/handshake/message/client/keyExchange.js.map +1 -1
  75. package/lib/dtls/src/handshake/message/finished.js +2 -1
  76. package/lib/dtls/src/handshake/message/finished.js.map +1 -1
  77. package/lib/dtls/src/handshake/message/server/certificateRequest.d.ts +1 -1
  78. package/lib/dtls/src/handshake/message/server/certificateRequest.js +7 -4
  79. package/lib/dtls/src/handshake/message/server/certificateRequest.js.map +1 -1
  80. package/lib/dtls/src/handshake/message/server/hello.d.ts +1 -1
  81. package/lib/dtls/src/handshake/message/server/hello.js +14 -8
  82. package/lib/dtls/src/handshake/message/server/hello.js.map +1 -1
  83. package/lib/dtls/src/handshake/message/server/helloDone.js +1 -1
  84. package/lib/dtls/src/handshake/message/server/helloDone.js.map +1 -1
  85. package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js +5 -3
  86. package/lib/dtls/src/handshake/message/server/helloVerifyRequest.js.map +1 -1
  87. package/lib/dtls/src/handshake/message/server/keyExchange.d.ts +1 -1
  88. package/lib/dtls/src/handshake/message/server/keyExchange.js +17 -9
  89. package/lib/dtls/src/handshake/message/server/keyExchange.js.map +1 -1
  90. package/lib/dtls/src/handshake/random.d.ts +1 -1
  91. package/lib/dtls/src/handshake/random.js +7 -4
  92. package/lib/dtls/src/handshake/random.js.map +1 -1
  93. package/lib/dtls/src/imports/common.d.ts +1 -0
  94. package/lib/dtls/src/imports/common.js +1 -0
  95. package/lib/dtls/src/imports/common.js.map +1 -1
  96. package/lib/dtls/src/index.d.ts +2 -2
  97. package/lib/dtls/src/index.js +2 -2
  98. package/lib/dtls/src/index.js.map +1 -1
  99. package/lib/dtls/src/record/const.d.ts +43 -33
  100. package/lib/dtls/src/record/const.js +43 -36
  101. package/lib/dtls/src/record/const.js.map +1 -1
  102. package/lib/dtls/src/record/message/fragment.d.ts +1 -1
  103. package/lib/dtls/src/record/message/fragment.js +15 -9
  104. package/lib/dtls/src/record/message/fragment.js.map +1 -1
  105. package/lib/dtls/src/record/message/header.js +12 -7
  106. package/lib/dtls/src/record/message/header.js.map +1 -1
  107. package/lib/dtls/src/record/message/plaintext.js +4 -2
  108. package/lib/dtls/src/record/message/plaintext.js.map +1 -1
  109. package/lib/dtls/src/record/receive.js +2 -2
  110. package/lib/dtls/src/record/receive.js.map +1 -1
  111. package/lib/dtls/src/server.js +1 -1
  112. package/lib/dtls/src/server.js.map +1 -1
  113. package/lib/dtls/src/socket.d.ts +2 -2
  114. package/lib/dtls/src/socket.js +6 -4
  115. package/lib/dtls/src/socket.js.map +1 -1
  116. package/lib/ice/src/candidate.d.ts +1 -1
  117. package/lib/ice/src/candidate.js +24 -12
  118. package/lib/ice/src/candidate.js.map +1 -1
  119. package/lib/ice/src/dns/lookup.d.ts +10 -1
  120. package/lib/ice/src/dns/lookup.js +42 -7
  121. package/lib/ice/src/dns/lookup.js.map +1 -1
  122. package/lib/ice/src/exceptions.d.ts +46 -0
  123. package/lib/ice/src/exceptions.js +92 -5
  124. package/lib/ice/src/exceptions.js.map +1 -1
  125. package/lib/ice/src/helper.d.ts +1 -1
  126. package/lib/ice/src/ice.d.ts +191 -5
  127. package/lib/ice/src/ice.js +1048 -156
  128. package/lib/ice/src/ice.js.map +1 -1
  129. package/lib/ice/src/iceBase.d.ts +174 -10
  130. package/lib/ice/src/iceBase.js +165 -12
  131. package/lib/ice/src/iceBase.js.map +1 -1
  132. package/lib/ice/src/index.d.ts +5 -5
  133. package/lib/ice/src/index.js +5 -5
  134. package/lib/ice/src/index.js.map +1 -1
  135. package/lib/ice/src/internal/resolveHostAddresses.d.ts +26 -0
  136. package/lib/ice/src/internal/resolveHostAddresses.js +45 -0
  137. package/lib/ice/src/internal/resolveHostAddresses.js.map +1 -0
  138. package/lib/ice/src/stun/protocol.d.ts +3 -1
  139. package/lib/ice/src/stun/protocol.js +16 -0
  140. package/lib/ice/src/stun/protocol.js.map +1 -1
  141. package/lib/ice/src/stun/tcpProtocol.d.ts +2 -0
  142. package/lib/ice/src/stun/tcpProtocol.js +16 -1
  143. package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
  144. package/lib/ice/src/stun/transaction.d.ts +35 -1
  145. package/lib/ice/src/stun/transaction.js +93 -18
  146. package/lib/ice/src/stun/transaction.js.map +1 -1
  147. package/lib/ice/src/turn/credential.d.ts +49 -0
  148. package/lib/ice/src/turn/credential.js +78 -0
  149. package/lib/ice/src/turn/credential.js.map +1 -0
  150. package/lib/ice/src/turn/protocol.d.ts +97 -7
  151. package/lib/ice/src/turn/protocol.js +357 -55
  152. package/lib/ice/src/turn/protocol.js.map +1 -1
  153. package/lib/ice/src/utils.js.map +1 -1
  154. package/lib/ice-server/src/stun/attributes.d.ts +2 -0
  155. package/lib/ice-server/src/stun/attributes.js +7 -1
  156. package/lib/ice-server/src/stun/attributes.js.map +1 -1
  157. package/lib/ice-server/src/stun/const.d.ts +24 -16
  158. package/lib/ice-server/src/stun/const.js +22 -18
  159. package/lib/ice-server/src/stun/const.js.map +1 -1
  160. package/lib/ice-server/src/stun/message.d.ts +3 -1
  161. package/lib/ice-server/src/stun/message.js +41 -6
  162. package/lib/ice-server/src/stun/message.js.map +1 -1
  163. package/lib/ice-server/src/turn/auth.d.ts +1 -1
  164. package/lib/index.mjs +25252 -12664
  165. package/lib/nonstandard/index.mjs +11015 -8906
  166. package/lib/polyfill/dom.mjs +30779 -18386
  167. package/lib/polyfill/index.mjs +30779 -18386
  168. package/lib/rtp/src/codec/assertPayload.d.ts +4 -0
  169. package/lib/rtp/src/codec/assertPayload.js +12 -0
  170. package/lib/rtp/src/codec/assertPayload.js.map +1 -0
  171. package/lib/rtp/src/codec/av1.js +2 -0
  172. package/lib/rtp/src/codec/av1.js.map +1 -1
  173. package/lib/rtp/src/codec/h264.d.ts +1 -1
  174. package/lib/rtp/src/codec/h264.js +35 -43
  175. package/lib/rtp/src/codec/h264.js.map +1 -1
  176. package/lib/rtp/src/codec/vp8.js +11 -5
  177. package/lib/rtp/src/codec/vp8.js.map +1 -1
  178. package/lib/rtp/src/codec/vp9.js +12 -0
  179. package/lib/rtp/src/codec/vp9.js.map +1 -1
  180. package/lib/rtp/src/extra/container/mp4/container.js +2 -1
  181. package/lib/rtp/src/extra/container/mp4/container.js.map +1 -1
  182. package/lib/rtp/src/extra/container/mp4/exp-golomb.js +2 -1
  183. package/lib/rtp/src/extra/container/mp4/exp-golomb.js.map +1 -1
  184. package/lib/rtp/src/extra/container/mp4/h264.d.ts +21 -17
  185. package/lib/rtp/src/extra/container/mp4/h264.js +26 -24
  186. package/lib/rtp/src/extra/container/mp4/h264.js.map +1 -1
  187. package/lib/rtp/src/extra/container/ogg/index.d.ts +1 -0
  188. package/lib/rtp/src/extra/container/ogg/index.js +1 -0
  189. package/lib/rtp/src/extra/container/ogg/index.js.map +1 -1
  190. package/lib/rtp/src/extra/container/ogg/writer.d.ts +90 -0
  191. package/lib/rtp/src/extra/container/ogg/writer.js +300 -0
  192. package/lib/rtp/src/extra/container/ogg/writer.js.map +1 -0
  193. package/lib/rtp/src/extra/container/webm/container.d.ts +1 -1
  194. package/lib/rtp/src/extra/container/webm/ebml/ebml.d.ts +6 -0
  195. package/lib/rtp/src/extra/container/webm/ebml/ebml.js +26 -4
  196. package/lib/rtp/src/extra/container/webm/ebml/ebml.js.map +1 -1
  197. package/lib/rtp/src/extra/processor/depacketizer.d.ts +6 -1
  198. package/lib/rtp/src/extra/processor/depacketizer.js +29 -3
  199. package/lib/rtp/src/extra/processor/depacketizer.js.map +1 -1
  200. package/lib/rtp/src/extra/processor/depacketizerCallback.d.ts +1 -11
  201. package/lib/rtp/src/extra/processor/depacketizerTransformer.d.ts +1 -1
  202. package/lib/rtp/src/extra/processor/dtx.js +4 -2
  203. package/lib/rtp/src/extra/processor/dtx.js.map +1 -1
  204. package/lib/rtp/src/extra/processor/dtxCallback.d.ts +1 -11
  205. package/lib/rtp/src/extra/processor/index.d.ts +2 -0
  206. package/lib/rtp/src/extra/processor/index.js +2 -0
  207. package/lib/rtp/src/extra/processor/index.js.map +1 -1
  208. package/lib/rtp/src/extra/processor/interface.d.ts +16 -11
  209. package/lib/rtp/src/extra/processor/interface.js.map +1 -1
  210. package/lib/rtp/src/extra/processor/jitterBuffer.d.ts +29 -6
  211. package/lib/rtp/src/extra/processor/jitterBuffer.js +101 -111
  212. package/lib/rtp/src/extra/processor/jitterBuffer.js.map +1 -1
  213. package/lib/rtp/src/extra/processor/jitterBufferCallback.d.ts +1 -11
  214. package/lib/rtp/src/extra/processor/jitterBufferTransformer.d.ts +1 -1
  215. package/lib/rtp/src/extra/processor/jitterBufferTransformer.js +2 -1
  216. package/lib/rtp/src/extra/processor/jitterBufferTransformer.js.map +1 -1
  217. package/lib/rtp/src/extra/processor/lipsync.d.ts +63 -0
  218. package/lib/rtp/src/extra/processor/lipsync.js +202 -51
  219. package/lib/rtp/src/extra/processor/lipsync.js.map +1 -1
  220. package/lib/rtp/src/extra/processor/mp4.d.ts +0 -6
  221. package/lib/rtp/src/extra/processor/mp4.js +7 -4
  222. package/lib/rtp/src/extra/processor/mp4.js.map +1 -1
  223. package/lib/rtp/src/extra/processor/mute.js +4 -2
  224. package/lib/rtp/src/extra/processor/mute.js.map +1 -1
  225. package/lib/rtp/src/extra/processor/nack.d.ts +1 -1
  226. package/lib/rtp/src/extra/processor/nack.js +5 -3
  227. package/lib/rtp/src/extra/processor/nack.js.map +1 -1
  228. package/lib/rtp/src/extra/processor/nackHandlerCallback.d.ts +1 -11
  229. package/lib/rtp/src/extra/processor/ntpTime.js +4 -6
  230. package/lib/rtp/src/extra/processor/ntpTime.js.map +1 -1
  231. package/lib/rtp/src/extra/processor/ntpTimeCallback.d.ts +1 -11
  232. package/lib/rtp/src/extra/processor/ogg.d.ts +72 -0
  233. package/lib/rtp/src/extra/processor/ogg.js +221 -0
  234. package/lib/rtp/src/extra/processor/ogg.js.map +1 -0
  235. package/lib/rtp/src/extra/processor/oggCallback.d.ts +21 -0
  236. package/lib/rtp/src/extra/processor/oggCallback.js +97 -0
  237. package/lib/rtp/src/extra/processor/oggCallback.js.map +1 -0
  238. package/lib/rtp/src/extra/processor/rtcpCallback.d.ts +1 -1
  239. package/lib/rtp/src/extra/processor/rtcpCallback.js.map +1 -1
  240. package/lib/rtp/src/extra/processor/rtpCallback.d.ts +1 -1
  241. package/lib/rtp/src/extra/processor/rtpCallback.js +3 -2
  242. package/lib/rtp/src/extra/processor/rtpCallback.js.map +1 -1
  243. package/lib/rtp/src/extra/processor/rtpStream.d.ts +2 -2
  244. package/lib/rtp/src/extra/processor/rtpStream.js +2 -1
  245. package/lib/rtp/src/extra/processor/rtpStream.js.map +1 -1
  246. package/lib/rtp/src/extra/processor/rtpTime.js +2 -1
  247. package/lib/rtp/src/extra/processor/rtpTime.js.map +1 -1
  248. package/lib/rtp/src/extra/processor/rtpTimeCallback.d.ts +1 -11
  249. package/lib/rtp/src/extra/processor/webm.d.ts +27 -0
  250. package/lib/rtp/src/extra/processor/webm.js +57 -23
  251. package/lib/rtp/src/extra/processor/webm.js.map +1 -1
  252. package/lib/rtp/src/extra/processor/webmCallback.js +6 -1
  253. package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
  254. package/lib/rtp/src/extra/processor/webmStream.js.map +1 -1
  255. package/lib/rtp/src/helper.d.ts +2 -2
  256. package/lib/rtp/src/helper.js +2 -6
  257. package/lib/rtp/src/helper.js.map +1 -1
  258. package/lib/rtp/src/index.d.ts +10 -2
  259. package/lib/rtp/src/index.js +10 -2
  260. package/lib/rtp/src/index.js.map +1 -1
  261. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.d.ts +4 -0
  262. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js +6 -1
  263. package/lib/rtp/src/rtcp/psfb/fullIntraRequest.js.map +1 -1
  264. package/lib/rtp/src/rtcp/rtcp.js +9 -4
  265. package/lib/rtp/src/rtcp/rtcp.js.map +1 -1
  266. package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.d.ts +58 -0
  267. package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js +143 -0
  268. package/lib/rtp/src/rtcp/rtpfb/transportWideSequence.js.map +1 -0
  269. package/lib/rtp/src/rtcp/rtpfb/twcc.d.ts +35 -13
  270. package/lib/rtp/src/rtcp/rtpfb/twcc.js +132 -54
  271. package/lib/rtp/src/rtcp/rtpfb/twcc.js.map +1 -1
  272. package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.d.ts +13 -0
  273. package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js +29 -0
  274. package/lib/rtp/src/rtcp/rtpfb/twccReceiveTiming.js.map +1 -0
  275. package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.d.ts +41 -0
  276. package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js +89 -0
  277. package/lib/rtp/src/rtcp/rtpfb/twccReferenceTime.js.map +1 -0
  278. package/lib/rtp/src/rtcp/sr.d.ts +4 -3
  279. package/lib/rtp/src/rtcp/sr.js +4 -2
  280. package/lib/rtp/src/rtcp/sr.js.map +1 -1
  281. package/lib/rtp/src/rtp/continuity.d.ts +36 -0
  282. package/lib/rtp/src/rtp/continuity.js +100 -0
  283. package/lib/rtp/src/rtp/continuity.js.map +1 -0
  284. package/lib/rtp/src/rtp/headerExtension.js +41 -21
  285. package/lib/rtp/src/rtp/headerExtension.js.map +1 -1
  286. package/lib/rtp/src/rtp/padding.d.ts +17 -0
  287. package/lib/rtp/src/rtp/padding.js +37 -0
  288. package/lib/rtp/src/rtp/padding.js.map +1 -0
  289. package/lib/rtp/src/rtp/red/encoder.d.ts +10 -0
  290. package/lib/rtp/src/rtp/red/encoder.js +14 -1
  291. package/lib/rtp/src/rtp/red/encoder.js.map +1 -1
  292. package/lib/rtp/src/rtp/red/packet.js +24 -8
  293. package/lib/rtp/src/rtp/red/packet.js.map +1 -1
  294. package/lib/rtp/src/rtp/rtp.d.ts +24 -1
  295. package/lib/rtp/src/rtp/rtp.js +70 -29
  296. package/lib/rtp/src/rtp/rtp.js.map +1 -1
  297. package/lib/rtp/src/rtp/rtx.js +3 -0
  298. package/lib/rtp/src/rtp/rtx.js.map +1 -1
  299. package/lib/rtp/src/rtp/sendHeaderExtensions.d.ts +36 -0
  300. package/lib/rtp/src/rtp/sendHeaderExtensions.js +85 -0
  301. package/lib/rtp/src/rtp/sendHeaderExtensions.js.map +1 -0
  302. package/lib/rtp/src/srtp/cipher/ctr.d.ts +2 -2
  303. package/lib/rtp/src/srtp/cipher/ctr.js +5 -3
  304. package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
  305. package/lib/rtp/src/srtp/cipher/gcm.d.ts +1 -1
  306. package/lib/rtp/src/srtp/cipher/gcm.js +1 -1
  307. package/lib/rtp/src/srtp/cipher/gcm.js.map +1 -1
  308. package/lib/rtp/src/srtp/cipher/index.js +8 -4
  309. package/lib/rtp/src/srtp/cipher/index.js.map +1 -1
  310. package/lib/rtp/src/srtp/context/context.d.ts +29 -1
  311. package/lib/rtp/src/srtp/context/context.js +84 -27
  312. package/lib/rtp/src/srtp/context/context.js.map +1 -1
  313. package/lib/rtp/src/srtp/context/srtcp.d.ts +1 -1
  314. package/lib/rtp/src/srtp/context/srtcp.js +33 -0
  315. package/lib/rtp/src/srtp/context/srtcp.js.map +1 -1
  316. package/lib/rtp/src/srtp/context/srtp.d.ts +1 -1
  317. package/lib/rtp/src/srtp/context/srtp.js +36 -4
  318. package/lib/rtp/src/srtp/context/srtp.js.map +1 -1
  319. package/lib/rtp/src/srtp/error.d.ts +8 -0
  320. package/lib/rtp/src/srtp/error.js +13 -1
  321. package/lib/rtp/src/srtp/error.js.map +1 -1
  322. package/lib/rtp/src/srtp/packet.js +4 -1
  323. package/lib/rtp/src/srtp/packet.js.map +1 -1
  324. package/lib/rtp/src/srtp/replay.d.ts +24 -0
  325. package/lib/rtp/src/srtp/replay.js +75 -0
  326. package/lib/rtp/src/srtp/replay.js.map +1 -0
  327. package/lib/rtp/src/srtp/session.js +2 -1
  328. package/lib/rtp/src/srtp/session.js.map +1 -1
  329. package/lib/rtp/src/srtp/srtcp.js +2 -1
  330. package/lib/rtp/src/srtp/srtcp.js.map +1 -1
  331. package/lib/rtp/src/srtp/srtp.js +2 -1
  332. package/lib/rtp/src/srtp/srtp.js.map +1 -1
  333. package/lib/rtp/src/util.js +2 -1
  334. package/lib/rtp/src/util.js.map +1 -1
  335. package/lib/sctp/src/chunk.d.ts +5 -0
  336. package/lib/sctp/src/chunk.js +31 -8
  337. package/lib/sctp/src/chunk.js.map +1 -1
  338. package/lib/sctp/src/const.d.ts +25 -17
  339. package/lib/sctp/src/const.js +23 -19
  340. package/lib/sctp/src/const.js.map +1 -1
  341. package/lib/sctp/src/index.d.ts +4 -3
  342. package/lib/sctp/src/index.js +10 -8
  343. package/lib/sctp/src/index.js.map +1 -1
  344. package/lib/sctp/src/param.d.ts +6 -2
  345. package/lib/sctp/src/param.js +22 -8
  346. package/lib/sctp/src/param.js.map +1 -1
  347. package/lib/sctp/src/sctp.d.ts +91 -2
  348. package/lib/sctp/src/sctp.js +700 -134
  349. package/lib/sctp/src/sctp.js.map +1 -1
  350. package/lib/sctp/src/transport.js +4 -2
  351. package/lib/sctp/src/transport.js.map +1 -1
  352. package/lib/webrtc/src/api/peerConfig.d.ts +307 -0
  353. package/lib/webrtc/src/api/peerConfig.js +291 -0
  354. package/lib/webrtc/src/api/peerConfig.js.map +1 -0
  355. package/lib/webrtc/src/api/peerConnectionEvents.d.ts +36 -0
  356. package/lib/webrtc/src/api/peerConnectionEvents.js +44 -0
  357. package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -0
  358. package/lib/webrtc/src/dataChannel.d.ts +11 -1
  359. package/lib/webrtc/src/dataChannel.js +25 -5
  360. package/lib/webrtc/src/dataChannel.js.map +1 -1
  361. package/lib/webrtc/src/index.d.ts +2 -2
  362. package/lib/webrtc/src/index.js +2 -2
  363. package/lib/webrtc/src/index.js.map +1 -1
  364. package/lib/webrtc/src/media/index.d.ts +11 -1
  365. package/lib/webrtc/src/media/index.js +71 -1
  366. package/lib/webrtc/src/media/index.js.map +1 -1
  367. package/lib/webrtc/src/media/receiver/nack.js +5 -5
  368. package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
  369. package/lib/webrtc/src/media/receiver/receiverTwcc.d.ts +61 -1
  370. package/lib/webrtc/src/media/receiver/receiverTwcc.js +218 -63
  371. package/lib/webrtc/src/media/receiver/receiverTwcc.js.map +1 -1
  372. package/lib/webrtc/src/media/router.d.ts +130 -6
  373. package/lib/webrtc/src/media/router.js +325 -29
  374. package/lib/webrtc/src/media/router.js.map +1 -1
  375. package/lib/webrtc/src/media/rtpReceiver.d.ts +137 -14
  376. package/lib/webrtc/src/media/rtpReceiver.js +420 -44
  377. package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
  378. package/lib/webrtc/src/media/rtpSender.d.ts +232 -65
  379. package/lib/webrtc/src/media/rtpSender.js +784 -448
  380. package/lib/webrtc/src/media/rtpSender.js.map +1 -1
  381. package/lib/webrtc/src/media/rtpTransceiver.d.ts +95 -4
  382. package/lib/webrtc/src/media/rtpTransceiver.js +121 -9
  383. package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
  384. package/lib/webrtc/src/media/sender/bandwidthEstimator.d.ts +249 -0
  385. package/lib/webrtc/src/media/sender/bandwidthEstimator.js +144 -0
  386. package/lib/webrtc/src/media/sender/bandwidthEstimator.js.map +1 -0
  387. package/lib/webrtc/src/media/sender/createBandwidthEstimator.d.ts +20 -0
  388. package/lib/webrtc/src/media/sender/createBandwidthEstimator.js +26 -0
  389. package/lib/webrtc/src/media/sender/createBandwidthEstimator.js.map +1 -0
  390. package/lib/webrtc/src/media/sender/estimatorBinding.d.ts +70 -0
  391. package/lib/webrtc/src/media/sender/estimatorBinding.js +175 -0
  392. package/lib/webrtc/src/media/sender/estimatorBinding.js.map +1 -0
  393. package/lib/webrtc/src/media/sender/estimators/disabledBwe.d.ts +18 -0
  394. package/lib/webrtc/src/media/sender/estimators/disabledBwe.js +44 -0
  395. package/lib/webrtc/src/media/sender/estimators/disabledBwe.js.map +1 -0
  396. package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.d.ts +79 -0
  397. package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.js +289 -0
  398. package/lib/webrtc/src/media/sender/estimators/gcc/acknowledgedBitrateEstimator.js.map +1 -0
  399. package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.d.ts +87 -0
  400. package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.js +429 -0
  401. package/lib/webrtc/src/media/sender/estimators/gcc/aimdRateControl.js.map +1 -0
  402. package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.d.ts +21 -0
  403. package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.js +84 -0
  404. package/lib/webrtc/src/media/sender/estimators/gcc/alrDetector.js.map +1 -0
  405. package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.d.ts +37 -0
  406. package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.js +74 -0
  407. package/lib/webrtc/src/media/sender/estimators/gcc/bandwidthLimitedCause.js.map +1 -0
  408. package/lib/webrtc/src/media/sender/estimators/gcc/constants.d.ts +383 -0
  409. package/lib/webrtc/src/media/sender/estimators/gcc/constants.js +408 -0
  410. package/lib/webrtc/src/media/sender/estimators/gcc/constants.js.map +1 -0
  411. package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.d.ts +406 -0
  412. package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.js +1391 -0
  413. package/lib/webrtc/src/media/sender/estimators/gcc/gccBwe.js.map +1 -0
  414. package/lib/webrtc/src/media/sender/estimators/gcc/index.d.ts +19 -0
  415. package/lib/webrtc/src/media/sender/estimators/gcc/index.js +75 -0
  416. package/lib/webrtc/src/media/sender/estimators/gcc/index.js.map +1 -0
  417. package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.d.ts +68 -0
  418. package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.js +201 -0
  419. package/lib/webrtc/src/media/sender/estimators/gcc/interArrivalDelta.js.map +1 -0
  420. package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.d.ts +26 -0
  421. package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.js +72 -0
  422. package/lib/webrtc/src/media/sender/estimators/gcc/intervalBudget.js.map +1 -0
  423. package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.d.ts +41 -0
  424. package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.js +99 -0
  425. package/lib/webrtc/src/media/sender/estimators/gcc/linkCapacityEstimator.js.map +1 -0
  426. package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.d.ts +247 -0
  427. package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.js +1042 -0
  428. package/lib/webrtc/src/media/sender/estimators/gcc/lossBasedBwe.js.map +1 -0
  429. package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.d.ts +26 -0
  430. package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.js +132 -0
  431. package/lib/webrtc/src/media/sender/estimators/gcc/overuseDetector.js.map +1 -0
  432. package/lib/webrtc/src/media/sender/estimators/gcc/probeController.d.ts +305 -0
  433. package/lib/webrtc/src/media/sender/estimators/gcc/probeController.js +1073 -0
  434. package/lib/webrtc/src/media/sender/estimators/gcc/probeController.js.map +1 -0
  435. package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.d.ts +60 -0
  436. package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.js +151 -0
  437. package/lib/webrtc/src/media/sender/estimators/gcc/rttBasedBackoff.js.map +1 -0
  438. package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.d.ts +44 -0
  439. package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.js +246 -0
  440. package/lib/webrtc/src/media/sender/estimators/gcc/trendlineEstimator.js.map +1 -0
  441. package/lib/webrtc/src/media/sender/estimators/index.d.ts +7 -0
  442. package/lib/webrtc/src/media/sender/estimators/index.js +19 -0
  443. package/lib/webrtc/src/media/sender/estimators/index.js.map +1 -0
  444. package/lib/webrtc/src/media/sender/estimators/lightweightBwe.d.ts +64 -0
  445. package/lib/webrtc/src/media/sender/estimators/lightweightBwe.js +216 -0
  446. package/lib/webrtc/src/media/sender/estimators/lightweightBwe.js.map +1 -0
  447. package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.d.ts +117 -0
  448. package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.js +250 -0
  449. package/lib/webrtc/src/media/sender/estimators/twccFeedbackAdapter.js.map +1 -0
  450. package/lib/webrtc/src/media/sender/outgoingQueue.d.ts +40 -0
  451. package/lib/webrtc/src/media/sender/outgoingQueue.js +153 -0
  452. package/lib/webrtc/src/media/sender/outgoingQueue.js.map +1 -0
  453. package/lib/webrtc/src/media/sender/padding.d.ts +45 -0
  454. package/lib/webrtc/src/media/sender/padding.js +134 -0
  455. package/lib/webrtc/src/media/sender/padding.js.map +1 -0
  456. package/lib/webrtc/src/media/sender/pendingRtp.d.ts +35 -0
  457. package/lib/webrtc/src/media/sender/pendingRtp.js +120 -0
  458. package/lib/webrtc/src/media/sender/pendingRtp.js.map +1 -0
  459. package/lib/webrtc/src/media/sender/rtpWire.d.ts +13 -0
  460. package/lib/webrtc/src/media/sender/rtpWire.js +38 -0
  461. package/lib/webrtc/src/media/sender/rtpWire.js.map +1 -0
  462. package/lib/webrtc/src/media/sender/sendPacer.d.ts +27 -0
  463. package/lib/webrtc/src/media/sender/sendPacer.js +110 -0
  464. package/lib/webrtc/src/media/sender/sendPacer.js.map +1 -0
  465. package/lib/webrtc/src/media/sender/senderBWE.d.ts +8 -32
  466. package/lib/webrtc/src/media/sender/senderBWE.js +5 -142
  467. package/lib/webrtc/src/media/sender/senderBWE.js.map +1 -1
  468. package/lib/webrtc/src/media/sender/senderStats.d.ts +100 -0
  469. package/lib/webrtc/src/media/sender/senderStats.js +322 -0
  470. package/lib/webrtc/src/media/sender/senderStats.js.map +1 -0
  471. package/lib/webrtc/src/media/track.d.ts +21 -3
  472. package/lib/webrtc/src/media/track.js +24 -6
  473. package/lib/webrtc/src/media/track.js.map +1 -1
  474. package/lib/webrtc/src/negotiation/bundleTopology.d.ts +103 -0
  475. package/lib/webrtc/src/negotiation/bundleTopology.js +384 -0
  476. package/lib/webrtc/src/negotiation/bundleTopology.js.map +1 -0
  477. package/lib/webrtc/src/negotiation/descriptionValidation.d.ts +51 -0
  478. package/lib/webrtc/src/negotiation/descriptionValidation.js +267 -0
  479. package/lib/webrtc/src/negotiation/descriptionValidation.js.map +1 -0
  480. package/lib/webrtc/src/negotiation/iceRestartRequest.d.ts +21 -0
  481. package/lib/webrtc/src/negotiation/iceRestartRequest.js +61 -0
  482. package/lib/webrtc/src/negotiation/iceRestartRequest.js.map +1 -0
  483. package/lib/webrtc/src/negotiation/internalState.d.ts +34 -0
  484. package/lib/webrtc/src/negotiation/internalState.js +21 -0
  485. package/lib/webrtc/src/negotiation/internalState.js.map +1 -0
  486. package/lib/webrtc/src/negotiation/negotiationNeeded.d.ts +44 -0
  487. package/lib/webrtc/src/negotiation/negotiationNeeded.js +119 -0
  488. package/lib/webrtc/src/negotiation/negotiationNeeded.js.map +1 -0
  489. package/lib/webrtc/src/negotiation/remoteCandidates.d.ts +86 -0
  490. package/lib/webrtc/src/negotiation/remoteCandidates.js +349 -0
  491. package/lib/webrtc/src/negotiation/remoteCandidates.js.map +1 -0
  492. package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +71 -0
  493. package/lib/webrtc/src/negotiation/remoteMediaApplication.js +414 -0
  494. package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -0
  495. package/lib/webrtc/src/negotiation/transportActivation.d.ts +59 -0
  496. package/lib/webrtc/src/negotiation/transportActivation.js +356 -0
  497. package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -0
  498. package/lib/webrtc/src/negotiationTransaction.d.ts +240 -0
  499. package/lib/webrtc/src/negotiationTransaction.js +604 -0
  500. package/lib/webrtc/src/negotiationTransaction.js.map +1 -0
  501. package/lib/webrtc/src/nonstandard/dummyMedia.js +2 -1
  502. package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
  503. package/lib/webrtc/src/nonstandard/index.d.ts +1 -1
  504. package/lib/webrtc/src/nonstandard/index.js +1 -1
  505. package/lib/webrtc/src/nonstandard/index.js.map +1 -1
  506. package/lib/webrtc/src/nonstandard/navigator.js +4 -3
  507. package/lib/webrtc/src/nonstandard/navigator.js.map +1 -1
  508. package/lib/webrtc/src/nonstandard/recorder/index.d.ts +32 -8
  509. package/lib/webrtc/src/nonstandard/recorder/index.js +81 -20
  510. package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
  511. package/lib/webrtc/src/nonstandard/recorder/writer/index.d.ts +10 -8
  512. package/lib/webrtc/src/nonstandard/recorder/writer/index.js +2 -1
  513. package/lib/webrtc/src/nonstandard/recorder/writer/index.js.map +1 -1
  514. package/lib/webrtc/src/nonstandard/recorder/writer/ogg.d.ts +32 -0
  515. package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js +185 -0
  516. package/lib/webrtc/src/nonstandard/recorder/writer/ogg.js.map +1 -0
  517. package/lib/webrtc/src/nonstandard/recorder/writer/webm.d.ts +2 -2
  518. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +10 -3
  519. package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
  520. package/lib/webrtc/src/nonstandard/userMedia/packetizer.d.ts +2 -2
  521. package/lib/webrtc/src/nonstandard/userMedia/packetizer.js.map +1 -1
  522. package/lib/webrtc/src/nonstandard/userMedia.d.ts +2 -2
  523. package/lib/webrtc/src/nonstandard/userMedia.js +4 -3
  524. package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
  525. package/lib/webrtc/src/peerConnection.d.ts +176 -238
  526. package/lib/webrtc/src/peerConnection.js +1042 -913
  527. package/lib/webrtc/src/peerConnection.js.map +1 -1
  528. package/lib/webrtc/src/polyfill/api.d.ts +5 -5
  529. package/lib/webrtc/src/polyfill/api.js.map +1 -1
  530. package/lib/webrtc/src/polyfill/index.js.map +1 -1
  531. package/lib/webrtc/src/polyfill/install.js +1 -1
  532. package/lib/webrtc/src/polyfill/install.js.map +1 -1
  533. package/lib/webrtc/src/polyfill/mediaDevices.js +2 -1
  534. package/lib/webrtc/src/polyfill/mediaDevices.js.map +1 -1
  535. package/lib/webrtc/src/polyfill/registers/mp4Webm.js.map +1 -1
  536. package/lib/webrtc/src/polyfill/registers/rtpRtcp.js.map +1 -1
  537. package/lib/webrtc/src/polyfill/selectSettings.js.map +1 -1
  538. package/lib/webrtc/src/polyfill/sourceIo.js.map +1 -1
  539. package/lib/webrtc/src/sctpManager.d.ts +97 -1
  540. package/lib/webrtc/src/sctpManager.js +189 -9
  541. package/lib/webrtc/src/sctpManager.js.map +1 -1
  542. package/lib/webrtc/src/sdp.js +12 -6
  543. package/lib/webrtc/src/sdp.js.map +1 -1
  544. package/lib/webrtc/src/sdpManager.d.ts +55 -11
  545. package/lib/webrtc/src/sdpManager.js +364 -87
  546. package/lib/webrtc/src/sdpManager.js.map +1 -1
  547. package/lib/webrtc/src/secureTransportManager.d.ts +89 -28
  548. package/lib/webrtc/src/secureTransportManager.js +232 -53
  549. package/lib/webrtc/src/secureTransportManager.js.map +1 -1
  550. package/lib/webrtc/src/transceiverManager.d.ts +62 -18
  551. package/lib/webrtc/src/transceiverManager.js +272 -107
  552. package/lib/webrtc/src/transceiverManager.js.map +1 -1
  553. package/lib/webrtc/src/transport/dtls.d.ts +64 -3
  554. package/lib/webrtc/src/transport/dtls.js +166 -42
  555. package/lib/webrtc/src/transport/dtls.js.map +1 -1
  556. package/lib/webrtc/src/transport/ice.d.ts +199 -28
  557. package/lib/webrtc/src/transport/ice.js +666 -71
  558. package/lib/webrtc/src/transport/ice.js.map +1 -1
  559. package/lib/webrtc/src/transport/iceCandidateAttribute.d.ts +98 -0
  560. package/lib/webrtc/src/transport/iceCandidateAttribute.js +129 -0
  561. package/lib/webrtc/src/transport/iceCandidateAttribute.js.map +1 -0
  562. package/lib/webrtc/src/transport/sctp.d.ts +6 -1
  563. package/lib/webrtc/src/transport/sctp.js +149 -37
  564. package/lib/webrtc/src/transport/sctp.js.map +1 -1
  565. package/lib/webrtc/src/utils.d.ts +39 -6
  566. package/lib/webrtc/src/utils.js +57 -17
  567. package/lib/webrtc/src/utils.js.map +1 -1
  568. package/package.json +16 -15
@@ -1,15 +1,66 @@
1
1
  import type { SCTPOptions } from "../../sctp/src";
2
- import { Event } from "./imports/common";
3
2
  import { RTCDataChannel } from "./dataChannel";
3
+ import { Event } from "./imports/common";
4
4
  import { type RTCStats } from "./media/stats";
5
5
  import type { MediaDescription } from "./sdp";
6
+ import type { RTCDtlsTransport } from "./transport/dtls";
6
7
  import { RTCSctpTransport } from "./transport/sctp";
8
+ /** The SCTP binding of a PeerConnection, for a negotiation rollback baseline. */
9
+ export type SctpNegotiationState = ReturnType<SctpTransportManager["snapshotNegotiationState"]>;
10
+ /**
11
+ * The SCTP transport of a PeerConnection and its application m-line.
12
+ *
13
+ * - Rejection of the application m-line (port 0) keeps the SCTP transport:
14
+ * it stays bound to its MID and the next offer offers the application again
15
+ * with that MID (W3C would set `sctpTransport` to null). A rejecting remote
16
+ * offer or pranswer is provisional and leaves the association alone, and
17
+ * so does any rejection of an association the rollback baseline negotiated.
18
+ * A final answer with port 0 (RFC 8841 section 10.4), local or remote,
19
+ * aborts an association the proposal started (a pranswer or the remote
20
+ * INIT) and releases the remote port on that peer (`rejectApplication`).
21
+ * Channels on it close; the other peer closes its own when it applies the
22
+ * same answer. The commit does not move the transport to
23
+ * a transport the answer did not negotiate for it. An answer to an offer
24
+ * whose application m-line has port 0 has port 0 (RFC 3264 section 6).
25
+ * - The position (MID, index, rejected) is recorded by the current
26
+ * description, not by this object. An unbound transport takes a rejected
27
+ * position with a new MID; an offer that does so moves the transport to that
28
+ * MID (restored by rollback). A MID only an unapplied `createOffer`
29
+ * reserved follows the MID of the peer's offer.
30
+ * - At the final answer SCTP moves straight to its owner's DTLS transport in
31
+ * the answer. SCTP starts after every answer or pranswer that negotiates the
32
+ * application m-line (JSEP 5.11), also on an already connected DTLS
33
+ * transport: an `m=application` a renegotiation adds to a connected session
34
+ * starts without touching ICE or DTLS and without moving `connectionState`.
35
+ * Its client / server side follows the ICE role at the DTLS start. Starting
36
+ * is idempotent (`RTCSctpTransport.ensureStarted`): an established
37
+ * association, also one the remote INIT established first, a handshaking
38
+ * one and a closed one never start again, so a final answer keeping the
39
+ * pranswer's sctp-port continues it. A final answer changing the sctp-port
40
+ * is rejected in validation.
41
+ * - Rollback keeps an application-owned transport (`detachFromDescription`
42
+ * clears what the description set), whether it is in the baseline or was
43
+ * added during the transaction, and stops one a description created. When
44
+ * the baseline has no negotiated remote port, an association that left its
45
+ * initial state under the proposal (started by a pranswer, or established
46
+ * from the remote INIT) is pending-only: it is aborted and an
47
+ * application-owned transport gets a new, unstarted association on the same
48
+ * DTLS transport. Its channels with a stream ID close; channels still
49
+ * waiting for one stay `connecting` for the next negotiation.
50
+ * - `sctp.mtu` is configuration: every transport, also a pending one, is built
51
+ * with it, and moving to another DTLS transport keeps it.
52
+ */
7
53
  export declare class SctpTransportManager {
8
54
  sctpTransport?: RTCSctpTransport;
9
55
  sctpRemotePort?: number;
10
56
  dataChannelsOpened: number;
11
57
  dataChannelsClosed: number;
12
58
  private dataChannels;
59
+ /**
60
+ * SCTP transports that carry a `createDataChannel` call. They are
61
+ * application state: negotiation rollback keeps them instead of stopping.
62
+ */
63
+ private readonly applicationOwned;
13
64
  readonly onDataChannel: Event<[RTCDataChannel]>;
14
65
  constructor();
15
66
  createSctpTransport(maxMessageSize?: number, sctpOptions?: SCTPOptions): RTCSctpTransport;
@@ -21,7 +72,52 @@ export declare class SctpTransportManager {
21
72
  negotiated: boolean;
22
73
  id?: number;
23
74
  }>): RTCDataChannel;
75
+ /**
76
+ * Count a channel (created here or announced by the remote peer) and keep
77
+ * it for getStats until it closes. The listener goes with it: a closed
78
+ * channel the application still holds must not keep the manager reachable.
79
+ */
80
+ private track;
81
+ isApplicationOwned(transport: RTCSctpTransport): boolean;
82
+ /** Internal: the SCTP binding a negotiation may change, for a rollback baseline. */
83
+ snapshotNegotiationState(): {
84
+ transport: RTCSctpTransport | undefined;
85
+ dtlsTransport: RTCDtlsTransport | undefined;
86
+ remotePort: number | undefined;
87
+ mid: string | undefined;
88
+ mLineIndex: number | undefined;
89
+ remoteMaxMessageSize: number | undefined;
90
+ };
91
+ /** Internal: return to a negotiation baseline taken by `snapshotNegotiationState`. */
92
+ restoreNegotiationState(state: SctpNegotiationState): Promise<void>;
93
+ /**
94
+ * Internal: a final answer rejected the application m-line (port 0, RFC
95
+ * 8841 section 10.4). The association a pranswer started closes; the
96
+ * transport waits unbound for a later negotiation.
97
+ */
98
+ rejectApplication(): Promise<void>;
99
+ /**
100
+ * Internal: an SCTP transport that no description bound yet goes back to
101
+ * the MID / m-line index of `state` (see TransceiverManager's
102
+ * `revertUnappliedAssociations`).
103
+ */
104
+ revertUnappliedAssociation(state: SctpNegotiationState): void;
105
+ /** Drop what a rolled-back description set on a kept SCTP transport. */
106
+ detachFromDescription(transport: RTCSctpTransport): void;
107
+ /**
108
+ * Start the association of the negotiated application m-line and wait
109
+ * until it is established. Safe to call any number of times: an
110
+ * established (also passively established) or handshaking association is
111
+ * not started again, and a closed one is not waited for. The wait is
112
+ * bounded even if the remote never answers: the INIT retries (T1) give up
113
+ * and the association emits `closed`.
114
+ */
24
115
  connectSctp(): Promise<void>;
116
+ /**
117
+ * A renegotiation pranswer / answer keeps the association (and its port)
118
+ * but updates the data max message size it negotiates.
119
+ */
120
+ updateRemoteMaxMessageSize(remoteMedia: MediaDescription): void;
25
121
  setRemoteSCTP(remoteMedia: MediaDescription, mLineIndex: number): void;
26
122
  close(): Promise<void>;
27
123
  getStats(timestamp?: number): Promise<RTCStats[]>;
@@ -1,12 +1,55 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SctpTransportManager = void 0;
4
+ const dataChannel_1 = require("./dataChannel");
4
5
  const errors_1 = require("./errors");
5
6
  const common_1 = require("./imports/common");
6
- const dataChannel_1 = require("./dataChannel");
7
7
  const stats_1 = require("./media/stats");
8
8
  const sctp_1 = require("./transport/sctp");
9
9
  const log = (0, common_1.debug)("werift:packages/webrtc/src/transport/sctpManager.ts");
10
+ /**
11
+ * The SCTP transport of a PeerConnection and its application m-line.
12
+ *
13
+ * - Rejection of the application m-line (port 0) keeps the SCTP transport:
14
+ * it stays bound to its MID and the next offer offers the application again
15
+ * with that MID (W3C would set `sctpTransport` to null). A rejecting remote
16
+ * offer or pranswer is provisional and leaves the association alone, and
17
+ * so does any rejection of an association the rollback baseline negotiated.
18
+ * A final answer with port 0 (RFC 8841 section 10.4), local or remote,
19
+ * aborts an association the proposal started (a pranswer or the remote
20
+ * INIT) and releases the remote port on that peer (`rejectApplication`).
21
+ * Channels on it close; the other peer closes its own when it applies the
22
+ * same answer. The commit does not move the transport to
23
+ * a transport the answer did not negotiate for it. An answer to an offer
24
+ * whose application m-line has port 0 has port 0 (RFC 3264 section 6).
25
+ * - The position (MID, index, rejected) is recorded by the current
26
+ * description, not by this object. An unbound transport takes a rejected
27
+ * position with a new MID; an offer that does so moves the transport to that
28
+ * MID (restored by rollback). A MID only an unapplied `createOffer`
29
+ * reserved follows the MID of the peer's offer.
30
+ * - At the final answer SCTP moves straight to its owner's DTLS transport in
31
+ * the answer. SCTP starts after every answer or pranswer that negotiates the
32
+ * application m-line (JSEP 5.11), also on an already connected DTLS
33
+ * transport: an `m=application` a renegotiation adds to a connected session
34
+ * starts without touching ICE or DTLS and without moving `connectionState`.
35
+ * Its client / server side follows the ICE role at the DTLS start. Starting
36
+ * is idempotent (`RTCSctpTransport.ensureStarted`): an established
37
+ * association, also one the remote INIT established first, a handshaking
38
+ * one and a closed one never start again, so a final answer keeping the
39
+ * pranswer's sctp-port continues it. A final answer changing the sctp-port
40
+ * is rejected in validation.
41
+ * - Rollback keeps an application-owned transport (`detachFromDescription`
42
+ * clears what the description set), whether it is in the baseline or was
43
+ * added during the transaction, and stops one a description created. When
44
+ * the baseline has no negotiated remote port, an association that left its
45
+ * initial state under the proposal (started by a pranswer, or established
46
+ * from the remote INIT) is pending-only: it is aborted and an
47
+ * application-owned transport gets a new, unstarted association on the same
48
+ * DTLS transport. Its channels with a stream ID close; channels still
49
+ * waiting for one stay `connecting` for the next negotiation.
50
+ * - `sctp.mtu` is configuration: every transport, also a pending one, is built
51
+ * with it, and moving to another DTLS transport keeps it.
52
+ */
10
53
  class SctpTransportManager {
11
54
  constructor() {
12
55
  Object.defineProperty(this, "sctpTransport", {
@@ -39,6 +82,16 @@ class SctpTransportManager {
39
82
  writable: true,
40
83
  value: []
41
84
  });
85
+ /**
86
+ * SCTP transports that carry a `createDataChannel` call. They are
87
+ * application state: negotiation rollback keeps them instead of stopping.
88
+ */
89
+ Object.defineProperty(this, "applicationOwned", {
90
+ enumerable: true,
91
+ configurable: true,
92
+ writable: true,
93
+ value: new WeakSet()
94
+ });
42
95
  Object.defineProperty(this, "onDataChannel", {
43
96
  enumerable: true,
44
97
  configurable: true,
@@ -50,8 +103,7 @@ class SctpTransportManager {
50
103
  const sctp = new sctp_1.RTCSctpTransport(5000, maxMessageSize, sctpOptions);
51
104
  sctp.mid = undefined;
52
105
  sctp.onDataChannel.subscribe((channel) => {
53
- this.dataChannelsOpened++;
54
- this.dataChannels.push(channel);
106
+ this.track(channel);
55
107
  this.onDataChannel.execute(channel);
56
108
  });
57
109
  this.sctpTransport = sctp;
@@ -77,6 +129,7 @@ class SctpTransportManager {
77
129
  if (!this.sctpTransport) {
78
130
  this.sctpTransport = this.createSctpTransport();
79
131
  }
132
+ this.applicationOwned.add(this.sctpTransport);
80
133
  const parameters = new dataChannel_1.RTCDataChannelParameters({
81
134
  id: settings.id,
82
135
  label,
@@ -87,10 +140,20 @@ class SctpTransportManager {
87
140
  protocol: settings.protocol,
88
141
  });
89
142
  const channel = new dataChannel_1.RTCDataChannel(this.sctpTransport, parameters);
143
+ this.track(channel);
144
+ return channel;
145
+ }
146
+ /**
147
+ * Count a channel (created here or announced by the remote peer) and keep
148
+ * it for getStats until it closes. The listener goes with it: a closed
149
+ * channel the application still holds must not keep the manager reachable.
150
+ */
151
+ track(channel) {
90
152
  this.dataChannelsOpened++;
91
153
  this.dataChannels.push(channel);
92
- channel.stateChange.subscribe((state) => {
154
+ const { unSubscribe } = channel.stateChange.subscribe((state) => {
93
155
  if (state === "closed") {
156
+ unSubscribe();
94
157
  this.dataChannelsClosed++;
95
158
  const index = this.dataChannels.indexOf(channel);
96
159
  if (index !== -1) {
@@ -98,15 +161,132 @@ class SctpTransportManager {
98
161
  }
99
162
  }
100
163
  });
101
- return channel;
102
164
  }
165
+ isApplicationOwned(transport) {
166
+ return this.applicationOwned.has(transport);
167
+ }
168
+ /** Internal: the SCTP binding a negotiation may change, for a rollback baseline. */
169
+ snapshotNegotiationState() {
170
+ const transport = this.sctpTransport;
171
+ return {
172
+ transport,
173
+ dtlsTransport: transport?.dtlsTransport,
174
+ remotePort: this.sctpRemotePort,
175
+ mid: transport?.mid,
176
+ mLineIndex: transport?.mLineIndex,
177
+ remoteMaxMessageSize: transport?.remoteMaxMessageSize,
178
+ };
179
+ }
180
+ /** Internal: return to a negotiation baseline taken by `snapshotNegotiationState`. */
181
+ async restoreNegotiationState(state) {
182
+ const current = this.sctpTransport;
183
+ const added = current !== state.transport ? current : undefined;
184
+ // createDataChannel is an application operation: its SCTP transport
185
+ // survives rollback, unbound from the rolled-back m-line, so the next
186
+ // offer carries m=application again. A transport a description created
187
+ // is description state and is torn down.
188
+ const keepAdded = !!added && this.isApplicationOwned(added);
189
+ if (added && !keepAdded) {
190
+ await added.stop();
191
+ }
192
+ // Without a negotiated binding in the baseline, an association that ran
193
+ // under the pending description (started by a pranswer, or established
194
+ // passively from the remote INIT) is pending-only: it is discarded and a
195
+ // new, unstarted one waits for the next negotiation. Attached channels
196
+ // close; unattached ones stay queued.
197
+ const kept = keepAdded ? added : state.transport;
198
+ if (kept && state.remotePort === undefined && kept.associationActive) {
199
+ await kept.resetAssociation(kept === state.transport ? state.dtlsTransport : undefined);
200
+ }
201
+ this.sctpTransport = kept;
202
+ if (state.transport &&
203
+ state.dtlsTransport &&
204
+ state.transport.dtlsTransport !== state.dtlsTransport) {
205
+ state.transport.setDtlsTransport(state.dtlsTransport);
206
+ }
207
+ if (added && keepAdded)
208
+ this.detachFromDescription(added);
209
+ this.sctpRemotePort = state.remotePort;
210
+ if (state.transport) {
211
+ state.transport.mid = state.mid;
212
+ state.transport.mLineIndex = state.mLineIndex;
213
+ if (state.remoteMaxMessageSize !== undefined) {
214
+ state.transport.remoteMaxMessageSize = state.remoteMaxMessageSize;
215
+ }
216
+ }
217
+ }
218
+ /**
219
+ * Internal: a final answer rejected the application m-line (port 0, RFC
220
+ * 8841 section 10.4). The association a pranswer started closes; the
221
+ * transport waits unbound for a later negotiation.
222
+ */
223
+ async rejectApplication() {
224
+ const transport = this.sctpTransport;
225
+ if (!transport)
226
+ return;
227
+ if (transport.associationActive)
228
+ await transport.resetAssociation();
229
+ this.sctpRemotePort = undefined;
230
+ this.detachFromDescription(transport);
231
+ }
232
+ /**
233
+ * Internal: an SCTP transport that no description bound yet goes back to
234
+ * the MID / m-line index of `state` (see TransceiverManager's
235
+ * `revertUnappliedAssociations`).
236
+ */
237
+ revertUnappliedAssociation(state) {
238
+ const transport = this.sctpTransport;
239
+ if (transport &&
240
+ transport === state.transport &&
241
+ this.sctpRemotePort === undefined) {
242
+ transport.mid = state.mid;
243
+ transport.mLineIndex = state.mLineIndex;
244
+ }
245
+ }
246
+ /** Drop what a rolled-back description set on a kept SCTP transport. */
247
+ detachFromDescription(transport) {
248
+ transport.mid = undefined;
249
+ transport.mLineIndex = undefined;
250
+ transport.remoteMaxMessageSize = sctp_1.DEFAULT_MAX_MESSAGE_SIZE;
251
+ }
252
+ /**
253
+ * Start the association of the negotiated application m-line and wait
254
+ * until it is established. Safe to call any number of times: an
255
+ * established (also passively established) or handshaking association is
256
+ * not started again, and a closed one is not waited for. The wait is
257
+ * bounded even if the remote never answers: the INIT retries (T1) give up
258
+ * and the association emits `closed`.
259
+ */
103
260
  async connectSctp() {
104
- if (!this.sctpTransport || !this.sctpRemotePort) {
261
+ const transport = this.sctpTransport;
262
+ if (!transport || !this.sctpRemotePort) {
263
+ return;
264
+ }
265
+ const { sctp } = transport;
266
+ if (sctp.state === "closed") {
267
+ log("sctp closed");
105
268
  return;
106
269
  }
107
- await this.sctpTransport.start(this.sctpRemotePort);
108
- await this.sctpTransport.sctp.stateChanged.connected.asPromise();
109
- log("sctp connected");
270
+ // Subscribe before starting so a transition during start is not missed.
271
+ const settled = sctp.state === "connected"
272
+ ? undefined
273
+ : Promise.race([
274
+ sctp.stateChanged.connected.asPromise(),
275
+ sctp.stateChanged.closed.asPromise(),
276
+ ]);
277
+ await transport.ensureStarted(this.sctpRemotePort);
278
+ // The state may have settled while starting.
279
+ if (settled && !["connected", "closed"].includes(sctp.state)) {
280
+ await settled;
281
+ }
282
+ log("sctp", sctp.state);
283
+ }
284
+ /**
285
+ * A renegotiation pranswer / answer keeps the association (and its port)
286
+ * but updates the data max message size it negotiates.
287
+ */
288
+ updateRemoteMaxMessageSize(remoteMedia) {
289
+ this.sctpTransport?.setRemoteMaxMessageSize(remoteMedia.sctpCapabilities?.maxMessageSize);
110
290
  }
111
291
  setRemoteSCTP(remoteMedia, mLineIndex) {
112
292
  if (!this.sctpTransport) {
@@ -1 +1 @@
1
- {"version":3,"file":"sctpManager.js","sourceRoot":"","sources":["../../../src/sctpManager.ts"],"names":[],"mappings":";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X,OAAO,GAAG,KAAK,EACf,CAAC;QACD,MAAM,IAAA,8BAAqB,EAAC,GAAG,IAAI,4BAA4B,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { SCTPOptions } from \"../../sctp/src\";\nimport { createWebRtcTypeError } from \"./errors\";\nimport { Event, debug } from \"./imports/common\";\n\nimport { RTCDataChannel, RTCDataChannelParameters } from \"./dataChannel\";\nimport {\n type RTCDataChannelStats,\n type RTCStats,\n generateStatsId,\n getStatsTimestamp,\n} from \"./media/stats\";\nimport type { MediaDescription } from \"./sdp\";\nimport { RTCSctpTransport } from \"./transport/sctp\";\n\nconst log = debug(\"werift:packages/webrtc/src/transport/sctpManager.ts\");\n\nexport class SctpTransportManager {\n sctpTransport?: RTCSctpTransport;\n sctpRemotePort?: number;\n dataChannelsOpened = 0;\n dataChannelsClosed = 0;\n private dataChannels: RTCDataChannel[] = [];\n\n readonly onDataChannel = new Event<[RTCDataChannel]>();\n\n constructor() {}\n\n createSctpTransport(maxMessageSize?: number, sctpOptions?: SCTPOptions) {\n const sctp = new RTCSctpTransport(5000, maxMessageSize, sctpOptions);\n sctp.mid = undefined;\n sctp.onDataChannel.subscribe((channel) => {\n this.dataChannelsOpened++;\n this.dataChannels.push(channel);\n this.onDataChannel.execute(channel);\n });\n\n this.sctpTransport = sctp;\n\n return sctp;\n }\n\n createDataChannel(\n label: string,\n options: Partial<{\n maxPacketLifeTime?: number;\n protocol: string;\n maxRetransmits?: number;\n ordered: boolean;\n negotiated: boolean;\n id?: number;\n }> = {},\n ): RTCDataChannel {\n const maxPacketLifeTime = coerceUnsignedShortOption(\n options.maxPacketLifeTime,\n \"maxPacketLifeTime\",\n );\n const maxRetransmits = coerceUnsignedShortOption(\n options.maxRetransmits,\n \"maxRetransmits\",\n );\n const base: typeof options = {\n protocol: \"\",\n ordered: true,\n negotiated: false,\n };\n const settings: Required<typeof base> = {\n ...base,\n ...options,\n maxPacketLifeTime,\n maxRetransmits,\n } as any;\n\n if (settings.maxPacketLifeTime != null && settings.maxRetransmits != null) {\n throw createWebRtcTypeError(\n \"maxPacketLifeTime and maxRetransmits cannot both be set\",\n );\n }\n\n if (!this.sctpTransport) {\n this.sctpTransport = this.createSctpTransport();\n }\n\n const parameters = new RTCDataChannelParameters({\n id: settings.id,\n label,\n maxPacketLifeTime: settings.maxPacketLifeTime,\n maxRetransmits: settings.maxRetransmits,\n negotiated: settings.negotiated,\n ordered: settings.ordered,\n protocol: settings.protocol,\n });\n\n const channel = new RTCDataChannel(this.sctpTransport, parameters);\n this.dataChannelsOpened++;\n this.dataChannels.push(channel);\n channel.stateChange.subscribe((state) => {\n if (state === \"closed\") {\n this.dataChannelsClosed++;\n const index = this.dataChannels.indexOf(channel);\n if (index !== -1) {\n this.dataChannels.splice(index, 1);\n }\n }\n });\n return channel;\n }\n\n async connectSctp() {\n if (!this.sctpTransport || !this.sctpRemotePort) {\n return;\n }\n\n await this.sctpTransport.start(this.sctpRemotePort);\n await this.sctpTransport.sctp.stateChanged.connected.asPromise();\n log(\"sctp connected\");\n }\n\n setRemoteSCTP(remoteMedia: MediaDescription, mLineIndex: number) {\n if (!this.sctpTransport) {\n return;\n }\n\n // # configure sctp\n this.sctpTransport.setRemoteMaxMessageSize(\n remoteMedia.sctpCapabilities?.maxMessageSize,\n );\n this.sctpRemotePort = remoteMedia.sctpPort;\n if (!this.sctpRemotePort) {\n throw new Error(\"sctpRemotePort not exist\");\n }\n\n this.sctpTransport.setRemotePort(this.sctpRemotePort);\n this.sctpTransport.mLineIndex = mLineIndex;\n if (!this.sctpTransport.mid) {\n this.sctpTransport.mid = remoteMedia.rtp.muxId;\n }\n }\n\n async close() {\n if (this.sctpTransport) {\n await this.sctpTransport.stop();\n // UdpTransport.send は既知アドレスでは callback を待たない。呼び出し側が\n // 直後に ICE ソケットを閉じると queued な AbortChunk が落ちるので、1 tick 譲る。\n await new Promise<void>((resolve) => setImmediate(resolve));\n }\n\n this.onDataChannel.allUnsubscribe();\n }\n\n async getStats(timestamp = getStatsTimestamp()): Promise<RTCStats[]> {\n const stats: RTCStats[] = [];\n\n for (const channel of this.dataChannels) {\n const channelStats: RTCDataChannelStats = {\n type: \"data-channel\",\n id: generateStatsId(\"data-channel\", channel.id ?? channel.statsId),\n timestamp,\n label: channel.label,\n protocol: channel.protocol,\n dataChannelIdentifier: channel.id ?? undefined,\n state: channel.readyState,\n messagesSent: channel.messagesSent || 0,\n bytesSent: channel.bytesSent || 0,\n messagesReceived: channel.messagesReceived || 0,\n bytesReceived: channel.bytesReceived || 0,\n };\n stats.push(channelStats);\n }\n\n return stats;\n }\n}\n\nfunction coerceUnsignedShortOption(\n value: unknown,\n name: string,\n): number | undefined {\n if (value === undefined) {\n return undefined;\n }\n\n const coerced = Number(value);\n if (\n !Number.isFinite(coerced) ||\n !Number.isInteger(coerced) ||\n coerced < 0 ||\n coerced > 65535\n ) {\n throw createWebRtcTypeError(`${name} must be an unsigned short`);\n }\n\n return coerced;\n}\n"]}
1
+ {"version":3,"file":"sctpManager.js","sourceRoot":"","sources":["../../../src/sctpManager.ts"],"names":[],"mappings":";;;AACA,+CAAyE;AACzE,qCAAiD;AACjD,6CAAgD;AAChD,yCAKuB;AAGvB,2CAA8E;AAE9E,MAAM,GAAG,GAAG,IAAA,cAAK,EAAC,qDAAqD,CAAC,CAAC;AAOzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAa,oBAAoB;IAc/B;QAbA;;;;;WAAiC;QACjC;;;;;WAAwB;QACxB;;;;mBAAqB,CAAC;WAAC;QACvB;;;;mBAAqB,CAAC;WAAC;QACf;;;;mBAAiC,EAAE;WAAC;QAC5C;;;WAGG;QACc;;;;mBAAmB,IAAI,OAAO,EAAoB;WAAC;QAE3D;;;;mBAAgB,IAAI,cAAK,EAAoB;WAAC;IAExC,CAAC;IAEhB,mBAAmB,CAAC,cAAuB,EAAE,WAAyB;QACpE,MAAM,IAAI,GA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IAAI,OAAO,CAAC,OAAO,CAAC;gBAClE,SAAS;gBACT,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,qBAAqB,EAAE,OAAO,CAAC,EAAE,IAAI,SAAS;gBAC9C,KAAK,EAAE,OAAO,CAAC,UAAU;gBACzB,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,CAAC;gBACvC,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,CAAC;gBACjC,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,IAAI,CAAC;gBAC/C,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,CAAC;aAC1C,CAAC;YACF,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC3B,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA7SD,oDA6SC;AAED,SAAS,yBAAyB,CAChC,KAAc,EACd,IAAY;IAEZ,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9B,IACE,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;QACzB,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC;QAC1B,OAAO,GAAG,CAAC;QACX,OAAO,GAAG,KAAK,EACf,CAAC;QACD,MAAM,IAAA,8BAAqB,EAAC,GAAG,IAAI,4BAA4B,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { SCTPOptions } from \"../../sctp/src\";\nimport { RTCDataChannel, RTCDataChannelParameters } from \"./dataChannel\";\nimport { createWebRtcTypeError } from \"./errors\";\nimport { debug, Event } from \"./imports/common\";\nimport {\n generateStatsId,\n getStatsTimestamp,\n type RTCDataChannelStats,\n type RTCStats,\n} from \"./media/stats\";\nimport type { MediaDescription } from \"./sdp\";\nimport type { RTCDtlsTransport } from \"./transport/dtls\";\nimport { DEFAULT_MAX_MESSAGE_SIZE, RTCSctpTransport } from \"./transport/sctp\";\n\nconst log = debug(\"werift:packages/webrtc/src/transport/sctpManager.ts\");\n\n/** The SCTP binding of a PeerConnection, for a negotiation rollback baseline. */\nexport type SctpNegotiationState = ReturnType<\n SctpTransportManager[\"snapshotNegotiationState\"]\n>;\n\n/**\n * The SCTP transport of a PeerConnection and its application m-line.\n *\n * - Rejection of the application m-line (port 0) keeps the SCTP transport:\n * it stays bound to its MID and the next offer offers the application again\n * with that MID (W3C would set `sctpTransport` to null). A rejecting remote\n * offer or pranswer is provisional and leaves the association alone, and\n * so does any rejection of an association the rollback baseline negotiated.\n * A final answer with port 0 (RFC 8841 section 10.4), local or remote,\n * aborts an association the proposal started (a pranswer or the remote\n * INIT) and releases the remote port on that peer (`rejectApplication`).\n * Channels on it close; the other peer closes its own when it applies the\n * same answer. The commit does not move the transport to\n * a transport the answer did not negotiate for it. An answer to an offer\n * whose application m-line has port 0 has port 0 (RFC 3264 section 6).\n * - The position (MID, index, rejected) is recorded by the current\n * description, not by this object. An unbound transport takes a rejected\n * position with a new MID; an offer that does so moves the transport to that\n * MID (restored by rollback). A MID only an unapplied `createOffer`\n * reserved follows the MID of the peer's offer.\n * - At the final answer SCTP moves straight to its owner's DTLS transport in\n * the answer. SCTP starts after every answer or pranswer that negotiates the\n * application m-line (JSEP 5.11), also on an already connected DTLS\n * transport: an `m=application` a renegotiation adds to a connected session\n * starts without touching ICE or DTLS and without moving `connectionState`.\n * Its client / server side follows the ICE role at the DTLS start. Starting\n * is idempotent (`RTCSctpTransport.ensureStarted`): an established\n * association, also one the remote INIT established first, a handshaking\n * one and a closed one never start again, so a final answer keeping the\n * pranswer's sctp-port continues it. A final answer changing the sctp-port\n * is rejected in validation.\n * - Rollback keeps an application-owned transport (`detachFromDescription`\n * clears what the description set), whether it is in the baseline or was\n * added during the transaction, and stops one a description created. When\n * the baseline has no negotiated remote port, an association that left its\n * initial state under the proposal (started by a pranswer, or established\n * from the remote INIT) is pending-only: it is aborted and an\n * application-owned transport gets a new, unstarted association on the same\n * DTLS transport. Its channels with a stream ID close; channels still\n * waiting for one stay `connecting` for the next negotiation.\n * - `sctp.mtu` is configuration: every transport, also a pending one, is built\n * with it, and moving to another DTLS transport keeps it.\n */\nexport class SctpTransportManager {\n sctpTransport?: RTCSctpTransport;\n sctpRemotePort?: number;\n dataChannelsOpened = 0;\n dataChannelsClosed = 0;\n private dataChannels: RTCDataChannel[] = [];\n /**\n * SCTP transports that carry a `createDataChannel` call. They are\n * application state: negotiation rollback keeps them instead of stopping.\n */\n private readonly applicationOwned = new WeakSet<RTCSctpTransport>();\n\n readonly onDataChannel = new Event<[RTCDataChannel]>();\n\n constructor() {}\n\n createSctpTransport(maxMessageSize?: number, sctpOptions?: SCTPOptions) {\n const sctp = new RTCSctpTransport(5000, maxMessageSize, sctpOptions);\n sctp.mid = undefined;\n sctp.onDataChannel.subscribe((channel) => {\n this.track(channel);\n this.onDataChannel.execute(channel);\n });\n\n this.sctpTransport = sctp;\n\n return sctp;\n }\n\n createDataChannel(\n label: string,\n options: Partial<{\n maxPacketLifeTime?: number;\n protocol: string;\n maxRetransmits?: number;\n ordered: boolean;\n negotiated: boolean;\n id?: number;\n }> = {},\n ): RTCDataChannel {\n const maxPacketLifeTime = coerceUnsignedShortOption(\n options.maxPacketLifeTime,\n \"maxPacketLifeTime\",\n );\n const maxRetransmits = coerceUnsignedShortOption(\n options.maxRetransmits,\n \"maxRetransmits\",\n );\n const base: typeof options = {\n protocol: \"\",\n ordered: true,\n negotiated: false,\n };\n const settings: Required<typeof base> = {\n ...base,\n ...options,\n maxPacketLifeTime,\n maxRetransmits,\n } as any;\n\n if (settings.maxPacketLifeTime != null && settings.maxRetransmits != null) {\n throw createWebRtcTypeError(\n \"maxPacketLifeTime and maxRetransmits cannot both be set\",\n );\n }\n\n if (!this.sctpTransport) {\n this.sctpTransport = this.createSctpTransport();\n }\n this.applicationOwned.add(this.sctpTransport);\n\n const parameters = new RTCDataChannelParameters({\n id: settings.id,\n label,\n maxPacketLifeTime: settings.maxPacketLifeTime,\n maxRetransmits: settings.maxRetransmits,\n negotiated: settings.negotiated,\n ordered: settings.ordered,\n protocol: settings.protocol,\n });\n\n const channel = new RTCDataChannel(this.sctpTransport, parameters);\n this.track(channel);\n return channel;\n }\n\n /**\n * Count a channel (created here or announced by the remote peer) and keep\n * it for getStats until it closes. The listener goes with it: a closed\n * channel the application still holds must not keep the manager reachable.\n */\n private track(channel: RTCDataChannel) {\n this.dataChannelsOpened++;\n this.dataChannels.push(channel);\n const { unSubscribe } = channel.stateChange.subscribe((state) => {\n if (state === \"closed\") {\n unSubscribe();\n this.dataChannelsClosed++;\n const index = this.dataChannels.indexOf(channel);\n if (index !== -1) {\n this.dataChannels.splice(index, 1);\n }\n }\n });\n }\n\n isApplicationOwned(transport: RTCSctpTransport) {\n return this.applicationOwned.has(transport);\n }\n\n /** Internal: the SCTP binding a negotiation may change, for a rollback baseline. */\n snapshotNegotiationState() {\n const transport = this.sctpTransport;\n return {\n transport,\n dtlsTransport: transport?.dtlsTransport as RTCDtlsTransport | undefined,\n remotePort: this.sctpRemotePort,\n mid: transport?.mid,\n mLineIndex: transport?.mLineIndex,\n remoteMaxMessageSize: transport?.remoteMaxMessageSize,\n };\n }\n\n /** Internal: return to a negotiation baseline taken by `snapshotNegotiationState`. */\n async restoreNegotiationState(state: SctpNegotiationState) {\n const current = this.sctpTransport;\n const added = current !== state.transport ? current : undefined;\n // createDataChannel is an application operation: its SCTP transport\n // survives rollback, unbound from the rolled-back m-line, so the next\n // offer carries m=application again. A transport a description created\n // is description state and is torn down.\n const keepAdded = !!added && this.isApplicationOwned(added);\n if (added && !keepAdded) {\n await added.stop();\n }\n // Without a negotiated binding in the baseline, an association that ran\n // under the pending description (started by a pranswer, or established\n // passively from the remote INIT) is pending-only: it is discarded and a\n // new, unstarted one waits for the next negotiation. Attached channels\n // close; unattached ones stay queued.\n const kept = keepAdded ? added : state.transport;\n if (kept && state.remotePort === undefined && kept.associationActive) {\n await kept.resetAssociation(\n kept === state.transport ? state.dtlsTransport : undefined,\n );\n }\n this.sctpTransport = kept;\n if (\n state.transport &&\n state.dtlsTransport &&\n state.transport.dtlsTransport !== state.dtlsTransport\n ) {\n state.transport.setDtlsTransport(state.dtlsTransport);\n }\n if (added && keepAdded) this.detachFromDescription(added);\n this.sctpRemotePort = state.remotePort;\n if (state.transport) {\n state.transport.mid = state.mid;\n state.transport.mLineIndex = state.mLineIndex;\n if (state.remoteMaxMessageSize !== undefined) {\n state.transport.remoteMaxMessageSize = state.remoteMaxMessageSize;\n }\n }\n }\n\n /**\n * Internal: a final answer rejected the application m-line (port 0, RFC\n * 8841 section 10.4). The association a pranswer started closes; the\n * transport waits unbound for a later negotiation.\n */\n async rejectApplication() {\n const transport = this.sctpTransport;\n if (!transport) return;\n if (transport.associationActive) await transport.resetAssociation();\n this.sctpRemotePort = undefined;\n this.detachFromDescription(transport);\n }\n\n /**\n * Internal: an SCTP transport that no description bound yet goes back to\n * the MID / m-line index of `state` (see TransceiverManager's\n * `revertUnappliedAssociations`).\n */\n revertUnappliedAssociation(state: SctpNegotiationState) {\n const transport = this.sctpTransport;\n if (\n transport &&\n transport === state.transport &&\n this.sctpRemotePort === undefined\n ) {\n transport.mid = state.mid;\n transport.mLineIndex = state.mLineIndex;\n }\n }\n\n /** Drop what a rolled-back description set on a kept SCTP transport. */\n detachFromDescription(transport: RTCSctpTransport) {\n transport.mid = undefined;\n transport.mLineIndex = undefined;\n transport.remoteMaxMessageSize = DEFAULT_MAX_MESSAGE_SIZE;\n }\n\n /**\n * Start the association of the negotiated application m-line and wait\n * until it is established. Safe to call any number of times: an\n * established (also passively established) or handshaking association is\n * not started again, and a closed one is not waited for. The wait is\n * bounded even if the remote never answers: the INIT retries (T1) give up\n * and the association emits `closed`.\n */\n async connectSctp() {\n const transport = this.sctpTransport;\n if (!transport || !this.sctpRemotePort) {\n return;\n }\n const { sctp } = transport;\n if (sctp.state === \"closed\") {\n log(\"sctp closed\");\n return;\n }\n // Subscribe before starting so a transition during start is not missed.\n const settled =\n sctp.state === \"connected\"\n ? undefined\n : Promise.race([\n sctp.stateChanged.connected.asPromise(),\n sctp.stateChanged.closed.asPromise(),\n ]);\n\n await transport.ensureStarted(this.sctpRemotePort);\n // The state may have settled while starting.\n if (settled && ![\"connected\", \"closed\"].includes(sctp.state)) {\n await settled;\n }\n log(\"sctp\", sctp.state);\n }\n\n /**\n * A renegotiation pranswer / answer keeps the association (and its port)\n * but updates the data max message size it negotiates.\n */\n updateRemoteMaxMessageSize(remoteMedia: MediaDescription) {\n this.sctpTransport?.setRemoteMaxMessageSize(\n remoteMedia.sctpCapabilities?.maxMessageSize,\n );\n }\n\n setRemoteSCTP(remoteMedia: MediaDescription, mLineIndex: number) {\n if (!this.sctpTransport) {\n return;\n }\n\n // # configure sctp\n this.sctpTransport.setRemoteMaxMessageSize(\n remoteMedia.sctpCapabilities?.maxMessageSize,\n );\n this.sctpRemotePort = remoteMedia.sctpPort;\n if (!this.sctpRemotePort) {\n throw new Error(\"sctpRemotePort not exist\");\n }\n\n this.sctpTransport.setRemotePort(this.sctpRemotePort);\n this.sctpTransport.mLineIndex = mLineIndex;\n if (!this.sctpTransport.mid) {\n this.sctpTransport.mid = remoteMedia.rtp.muxId;\n }\n }\n\n async close() {\n if (this.sctpTransport) {\n await this.sctpTransport.stop();\n // UdpTransport.send は既知アドレスでは callback を待たない。呼び出し側が\n // 直後に ICE ソケットを閉じると queued な AbortChunk が落ちるので、1 tick 譲る。\n await new Promise<void>((resolve) => setImmediate(resolve));\n }\n\n this.onDataChannel.allUnsubscribe();\n }\n\n async getStats(timestamp = getStatsTimestamp()): Promise<RTCStats[]> {\n const stats: RTCStats[] = [];\n\n for (const channel of this.dataChannels) {\n const channelStats: RTCDataChannelStats = {\n type: \"data-channel\",\n id: generateStatsId(\"data-channel\", channel.id ?? channel.statsId),\n timestamp,\n label: channel.label,\n protocol: channel.protocol,\n dataChannelIdentifier: channel.id ?? undefined,\n state: channel.readyState,\n messagesSent: channel.messagesSent || 0,\n bytesSent: channel.bytesSent || 0,\n messagesReceived: channel.messagesReceived || 0,\n bytesReceived: channel.bytesReceived || 0,\n };\n stats.push(channelStats);\n }\n\n return stats;\n }\n}\n\nfunction coerceUnsignedShortOption(\n value: unknown,\n name: string,\n): number | undefined {\n if (value === undefined) {\n return undefined;\n }\n\n const coerced = Number(value);\n if (\n !Number.isFinite(coerced) ||\n !Number.isInteger(coerced) ||\n coerced < 0 ||\n coerced > 65535\n ) {\n throw createWebRtcTypeError(`${name} must be an unsigned short`);\n }\n\n return coerced;\n}\n"]}
@@ -431,25 +431,25 @@ class MediaDescription {
431
431
  enumerable: true,
432
432
  configurable: true,
433
433
  writable: true,
434
- value: kind
434
+ value: void 0
435
435
  });
436
436
  Object.defineProperty(this, "port", {
437
437
  enumerable: true,
438
438
  configurable: true,
439
439
  writable: true,
440
- value: port
440
+ value: void 0
441
441
  });
442
442
  Object.defineProperty(this, "profile", {
443
443
  enumerable: true,
444
444
  configurable: true,
445
445
  writable: true,
446
- value: profile
446
+ value: void 0
447
447
  });
448
448
  Object.defineProperty(this, "fmt", {
449
449
  enumerable: true,
450
450
  configurable: true,
451
451
  writable: true,
452
- value: fmt
452
+ value: void 0
453
453
  });
454
454
  // rtp
455
455
  Object.defineProperty(this, "host", {
@@ -567,6 +567,10 @@ class MediaDescription {
567
567
  writable: true,
568
568
  value: []
569
569
  });
570
+ this.kind = kind;
571
+ this.port = port;
572
+ this.profile = profile;
573
+ this.fmt = fmt;
570
574
  }
571
575
  get msid() {
572
576
  return this.msids[0];
@@ -682,14 +686,16 @@ class GroupDescription {
682
686
  enumerable: true,
683
687
  configurable: true,
684
688
  writable: true,
685
- value: semantic
689
+ value: void 0
686
690
  });
687
691
  Object.defineProperty(this, "items", {
688
692
  enumerable: true,
689
693
  configurable: true,
690
694
  writable: true,
691
- value: items
695
+ value: void 0
692
696
  });
697
+ this.semantic = semantic;
698
+ this.items = items;
693
699
  }
694
700
  get str() {
695
701
  return `${this.semantic} ${this.items.join(" ")}`;