@lakutata/webrtc 0.0.0-stage → 3.1.1

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 (1094) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +509 -2
  3. package/README.zh-CN.md +399 -0
  4. package/THIRD_PARTY_NOTICES.md +652 -0
  5. package/dist/cjs/client/SignalingConnection.d.ts +81 -0
  6. package/dist/cjs/client/SignalingConnection.js +67 -0
  7. package/dist/cjs/cluster/Cluster.d.ts +503 -0
  8. package/dist/cjs/cluster/Cluster.js +546 -0
  9. package/dist/cjs/cluster/ClusterFrames.d.ts +24 -0
  10. package/dist/cjs/cluster/ClusterFrames.js +90 -0
  11. package/dist/cjs/cluster/ClusterTURN.d.ts +63 -0
  12. package/dist/cjs/cluster/ClusterTURN.js +78 -0
  13. package/dist/cjs/cluster/Rendezvous.d.ts +8 -0
  14. package/dist/cjs/cluster/Rendezvous.js +23 -0
  15. package/dist/cjs/cluster/transports/ClusterTransport.d.ts +34 -0
  16. package/dist/cjs/cluster/transports/ClusterTransport.js +2 -0
  17. package/dist/cjs/cluster/transports/LoadClient.d.ts +6 -0
  18. package/dist/cjs/cluster/transports/LoadClient.js +80 -0
  19. package/dist/cjs/cluster/transports/MemoryClusterTransport.d.ts +13 -0
  20. package/dist/cjs/cluster/transports/MemoryClusterTransport.js +47 -0
  21. package/dist/cjs/cluster/transports/NATSClusterTransport.d.ts +23 -0
  22. package/dist/cjs/cluster/transports/NATSClusterTransport.js +70 -0
  23. package/dist/cjs/cluster/transports/RedisClusterTransport.d.ts +23 -0
  24. package/dist/cjs/cluster/transports/RedisClusterTransport.js +77 -0
  25. package/dist/cjs/exceptions/ClusterRequestException.d.ts +11 -0
  26. package/dist/cjs/exceptions/ClusterRequestException.js +18 -0
  27. package/dist/cjs/exceptions/ClusterTimeoutException.d.ts +10 -0
  28. package/dist/cjs/exceptions/ClusterTimeoutException.js +17 -0
  29. package/dist/cjs/exceptions/ClusterTransportNotFoundException.d.ts +11 -0
  30. package/dist/cjs/exceptions/ClusterTransportNotFoundException.js +18 -0
  31. package/dist/cjs/exceptions/SignalingClientRequiredException.d.ts +12 -0
  32. package/dist/cjs/exceptions/SignalingClientRequiredException.js +19 -0
  33. package/dist/cjs/exceptions/SignalingConnectionException.d.ts +12 -0
  34. package/dist/cjs/exceptions/SignalingConnectionException.js +19 -0
  35. package/dist/cjs/exceptions/SignalingDeniedException.d.ts +11 -0
  36. package/dist/cjs/exceptions/SignalingDeniedException.js +18 -0
  37. package/dist/cjs/exceptions/SignalingLimitException.d.ts +11 -0
  38. package/dist/cjs/exceptions/SignalingLimitException.js +18 -0
  39. package/dist/cjs/exceptions/SignalingNotAMemberException.d.ts +11 -0
  40. package/dist/cjs/exceptions/SignalingNotAMemberException.js +18 -0
  41. package/dist/cjs/exceptions/WHEPDeniedException.d.ts +15 -0
  42. package/dist/cjs/exceptions/WHEPDeniedException.js +22 -0
  43. package/dist/cjs/exceptions/WHEPLimitException.d.ts +15 -0
  44. package/dist/cjs/exceptions/WHEPLimitException.js +22 -0
  45. package/dist/cjs/exceptions/WHEPMediaTypeException.d.ts +15 -0
  46. package/dist/cjs/exceptions/WHEPMediaTypeException.js +22 -0
  47. package/dist/cjs/exceptions/WHEPOfferException.d.ts +16 -0
  48. package/dist/cjs/exceptions/WHEPOfferException.js +23 -0
  49. package/dist/cjs/exceptions/WHEPSessionNotFoundException.d.ts +15 -0
  50. package/dist/cjs/exceptions/WHEPSessionNotFoundException.js +22 -0
  51. package/dist/cjs/exceptions/WHIPDeniedException.d.ts +15 -0
  52. package/dist/cjs/exceptions/WHIPDeniedException.js +22 -0
  53. package/dist/cjs/exceptions/WHIPLimitException.d.ts +15 -0
  54. package/dist/cjs/exceptions/WHIPLimitException.js +22 -0
  55. package/dist/cjs/exceptions/WHIPMediaTypeException.d.ts +15 -0
  56. package/dist/cjs/exceptions/WHIPMediaTypeException.js +22 -0
  57. package/dist/cjs/exceptions/WHIPOfferException.d.ts +16 -0
  58. package/dist/cjs/exceptions/WHIPOfferException.js +23 -0
  59. package/dist/cjs/exceptions/WHIPSessionNotFoundException.d.ts +15 -0
  60. package/dist/cjs/exceptions/WHIPSessionNotFoundException.js +22 -0
  61. package/dist/cjs/exports/Client.d.ts +11 -0
  62. package/dist/cjs/exports/Client.js +29 -0
  63. package/dist/cjs/exports/WebRTC.d.ts +48 -0
  64. package/dist/cjs/exports/WebRTC.js +72 -0
  65. package/dist/cjs/lib/common/binary.d.ts +51 -0
  66. package/dist/cjs/lib/common/binary.js +264 -0
  67. package/dist/cjs/lib/common/binaryData.d.ts +116 -0
  68. package/dist/cjs/lib/common/binaryData.js +400 -0
  69. package/dist/cjs/lib/common/crc.d.ts +4 -0
  70. package/dist/cjs/lib/common/crc.js +122 -0
  71. package/dist/cjs/lib/common/deque.d.ts +36 -0
  72. package/dist/cjs/lib/common/deque.js +89 -0
  73. package/dist/cjs/lib/common/event.d.ts +48 -0
  74. package/dist/cjs/lib/common/event.js +207 -0
  75. package/dist/cjs/lib/common/index.d.ts +11 -0
  76. package/dist/cjs/lib/common/index.js +50 -0
  77. package/dist/cjs/lib/common/log.d.ts +47 -0
  78. package/dist/cjs/lib/common/log.js +62 -0
  79. package/dist/cjs/lib/common/network.d.ts +10 -0
  80. package/dist/cjs/lib/common/network.js +60 -0
  81. package/dist/cjs/lib/common/number.d.ts +13 -0
  82. package/dist/cjs/lib/common/number.js +43 -0
  83. package/dist/cjs/lib/common/promise.d.ts +21 -0
  84. package/dist/cjs/lib/common/promise.js +70 -0
  85. package/dist/cjs/lib/common/transport.d.ts +104 -0
  86. package/dist/cjs/lib/common/transport.js +441 -0
  87. package/dist/cjs/lib/common/type.d.ts +3 -0
  88. package/dist/cjs/lib/common/type.js +2 -0
  89. package/dist/cjs/lib/dtls/cipher/const.d.ts +42 -0
  90. package/dist/cjs/lib/dtls/cipher/const.js +33 -0
  91. package/dist/cjs/lib/dtls/cipher/create.d.ts +21 -0
  92. package/dist/cjs/lib/dtls/cipher/create.js +105 -0
  93. package/dist/cjs/lib/dtls/cipher/ec.d.ts +28 -0
  94. package/dist/cjs/lib/dtls/cipher/ec.js +44 -0
  95. package/dist/cjs/lib/dtls/cipher/key-exchange.d.ts +43 -0
  96. package/dist/cjs/lib/dtls/cipher/key-exchange.js +113 -0
  97. package/dist/cjs/lib/dtls/cipher/namedCurve.d.ts +7 -0
  98. package/dist/cjs/lib/dtls/cipher/namedCurve.js +27 -0
  99. package/dist/cjs/lib/dtls/cipher/prf.d.ts +17 -0
  100. package/dist/cjs/lib/dtls/cipher/prf.js +92 -0
  101. package/dist/cjs/lib/dtls/cipher/suites/abstract.d.ts +40 -0
  102. package/dist/cjs/lib/dtls/cipher/suites/abstract.js +41 -0
  103. package/dist/cjs/lib/dtls/cipher/suites/aead.d.ts +28 -0
  104. package/dist/cjs/lib/dtls/cipher/suites/aead.js +132 -0
  105. package/dist/cjs/lib/dtls/cipher/suites/null.d.ts +24 -0
  106. package/dist/cjs/lib/dtls/cipher/suites/null.js +41 -0
  107. package/dist/cjs/lib/dtls/cipher/utils.d.ts +18 -0
  108. package/dist/cjs/lib/dtls/cipher/utils.js +70 -0
  109. package/dist/cjs/lib/dtls/cipher/x509.d.ts +33 -0
  110. package/dist/cjs/lib/dtls/cipher/x509.js +100 -0
  111. package/dist/cjs/lib/dtls/client.d.ts +7 -0
  112. package/dist/cjs/lib/dtls/client.js +76 -0
  113. package/dist/cjs/lib/dtls/context/cipher.d.ts +42 -0
  114. package/dist/cjs/lib/dtls/context/cipher.js +87 -0
  115. package/dist/cjs/lib/dtls/context/dtls.d.ts +38 -0
  116. package/dist/cjs/lib/dtls/context/dtls.js +49 -0
  117. package/dist/cjs/lib/dtls/context/srtp.d.ts +5 -0
  118. package/dist/cjs/lib/dtls/context/srtp.js +12 -0
  119. package/dist/cjs/lib/dtls/context/transport.d.ts +8 -0
  120. package/dist/cjs/lib/dtls/context/transport.js +17 -0
  121. package/dist/cjs/lib/dtls/flight/client/flight1.d.ts +10 -0
  122. package/dist/cjs/lib/dtls/flight/client/flight1.js +26 -0
  123. package/dist/cjs/lib/dtls/flight/client/flight3.d.ts +8 -0
  124. package/dist/cjs/lib/dtls/flight/client/flight3.js +25 -0
  125. package/dist/cjs/lib/dtls/flight/client/flight5.d.ts +18 -0
  126. package/dist/cjs/lib/dtls/flight/client/flight5.js +206 -0
  127. package/dist/cjs/lib/dtls/flight/flight.d.ts +18 -0
  128. package/dist/cjs/lib/dtls/flight/flight.js +68 -0
  129. package/dist/cjs/lib/dtls/flight/server/flight2.d.ts +6 -0
  130. package/dist/cjs/lib/dtls/flight/server/flight2.js +126 -0
  131. package/dist/cjs/lib/dtls/flight/server/flight4.d.ts +17 -0
  132. package/dist/cjs/lib/dtls/flight/server/flight4.js +87 -0
  133. package/dist/cjs/lib/dtls/flight/server/flight6.d.ts +13 -0
  134. package/dist/cjs/lib/dtls/flight/server/flight6.js +111 -0
  135. package/dist/cjs/lib/dtls/handshake/binary.d.ts +16 -0
  136. package/dist/cjs/lib/dtls/handshake/binary.js +20 -0
  137. package/dist/cjs/lib/dtls/handshake/const.d.ts +13 -0
  138. package/dist/cjs/lib/dtls/handshake/const.js +17 -0
  139. package/dist/cjs/lib/dtls/handshake/extensions/ellipticCurves.d.ts +17 -0
  140. package/dist/cjs/lib/dtls/handshake/extensions/ellipticCurves.js +40 -0
  141. package/dist/cjs/lib/dtls/handshake/extensions/extendedMasterSecret.d.ts +3 -0
  142. package/dist/cjs/lib/dtls/handshake/extensions/extendedMasterSecret.js +7 -0
  143. package/dist/cjs/lib/dtls/handshake/extensions/renegotiationIndication.d.ts +18 -0
  144. package/dist/cjs/lib/dtls/handshake/extensions/renegotiationIndication.js +34 -0
  145. package/dist/cjs/lib/dtls/handshake/extensions/signature.d.ts +26 -0
  146. package/dist/cjs/lib/dtls/handshake/extensions/signature.js +39 -0
  147. package/dist/cjs/lib/dtls/handshake/extensions/useSrtp.d.ts +19 -0
  148. package/dist/cjs/lib/dtls/handshake/extensions/useSrtp.js +65 -0
  149. package/dist/cjs/lib/dtls/handshake/message/alert.d.ts +12 -0
  150. package/dist/cjs/lib/dtls/handshake/message/alert.js +24 -0
  151. package/dist/cjs/lib/dtls/handshake/message/certificate.d.ts +17 -0
  152. package/dist/cjs/lib/dtls/handshake/message/certificate.js +35 -0
  153. package/dist/cjs/lib/dtls/handshake/message/changeCipherSpec.d.ts +11 -0
  154. package/dist/cjs/lib/dtls/handshake/message/changeCipherSpec.js +24 -0
  155. package/dist/cjs/lib/dtls/handshake/message/client/certificateVerify.d.ts +20 -0
  156. package/dist/cjs/lib/dtls/handshake/message/client/certificateVerify.js +35 -0
  157. package/dist/cjs/lib/dtls/handshake/message/client/hello.d.ts +50 -0
  158. package/dist/cjs/lib/dtls/handshake/message/client/hello.js +48 -0
  159. package/dist/cjs/lib/dtls/handshake/message/client/keyExchange.d.ts +17 -0
  160. package/dist/cjs/lib/dtls/handshake/message/client/keyExchange.js +33 -0
  161. package/dist/cjs/lib/dtls/handshake/message/finished.d.ts +13 -0
  162. package/dist/cjs/lib/dtls/handshake/message/finished.js +26 -0
  163. package/dist/cjs/lib/dtls/handshake/message/server/certificateRequest.d.ts +31 -0
  164. package/dist/cjs/lib/dtls/handshake/message/server/certificateRequest.js +38 -0
  165. package/dist/cjs/lib/dtls/handshake/message/server/hello.d.ts +33 -0
  166. package/dist/cjs/lib/dtls/handshake/message/server/hello.js +57 -0
  167. package/dist/cjs/lib/dtls/handshake/message/server/helloDone.d.ts +12 -0
  168. package/dist/cjs/lib/dtls/handshake/message/server/helloDone.js +30 -0
  169. package/dist/cjs/lib/dtls/handshake/message/server/helloVerifyRequest.d.ts +32 -0
  170. package/dist/cjs/lib/dtls/handshake/message/server/helloVerifyRequest.js +42 -0
  171. package/dist/cjs/lib/dtls/handshake/message/server/keyExchange.d.ts +32 -0
  172. package/dist/cjs/lib/dtls/handshake/message/server/keyExchange.js +49 -0
  173. package/dist/cjs/lib/dtls/handshake/random.d.ts +13 -0
  174. package/dist/cjs/lib/dtls/handshake/random.js +29 -0
  175. package/dist/cjs/lib/dtls/helper.d.ts +4 -0
  176. package/dist/cjs/lib/dtls/helper.js +30 -0
  177. package/dist/cjs/lib/dtls/imports/common.d.ts +1 -0
  178. package/dist/cjs/lib/dtls/imports/common.js +17 -0
  179. package/dist/cjs/lib/dtls/imports/rtp.d.ts +1 -0
  180. package/dist/cjs/lib/dtls/imports/rtp.js +17 -0
  181. package/dist/cjs/lib/dtls/index.d.ts +7 -0
  182. package/dist/cjs/lib/dtls/index.js +117 -0
  183. package/dist/cjs/lib/dtls/record/antiReplayWindow.d.ts +27 -0
  184. package/dist/cjs/lib/dtls/record/antiReplayWindow.js +102 -0
  185. package/dist/cjs/lib/dtls/record/builder.d.ts +9 -0
  186. package/dist/cjs/lib/dtls/record/builder.js +27 -0
  187. package/dist/cjs/lib/dtls/record/const.d.ts +33 -0
  188. package/dist/cjs/lib/dtls/record/const.js +38 -0
  189. package/dist/cjs/lib/dtls/record/message/fragment.d.ts +26 -0
  190. package/dist/cjs/lib/dtls/record/message/fragment.js +96 -0
  191. package/dist/cjs/lib/dtls/record/message/header.d.ts +38 -0
  192. package/dist/cjs/lib/dtls/record/message/header.js +34 -0
  193. package/dist/cjs/lib/dtls/record/message/plaintext.d.ts +14 -0
  194. package/dist/cjs/lib/dtls/record/message/plaintext.js +63 -0
  195. package/dist/cjs/lib/dtls/record/receive.d.ts +9 -0
  196. package/dist/cjs/lib/dtls/record/receive.js +91 -0
  197. package/dist/cjs/lib/dtls/server.d.ts +6 -0
  198. package/dist/cjs/lib/dtls/server.js +78 -0
  199. package/dist/cjs/lib/dtls/socket.d.ts +52 -0
  200. package/dist/cjs/lib/dtls/socket.js +188 -0
  201. package/dist/cjs/lib/dtls/typings/domain.d.ts +20 -0
  202. package/dist/cjs/lib/dtls/typings/domain.js +2 -0
  203. package/dist/cjs/lib/dtls/util/binary.d.ts +2 -0
  204. package/dist/cjs/lib/dtls/util/binary.js +8 -0
  205. package/dist/cjs/lib/ice/candidate.d.ts +35 -0
  206. package/dist/cjs/lib/ice/candidate.js +198 -0
  207. package/dist/cjs/lib/ice/dns/lookup.d.ts +16 -0
  208. package/dist/cjs/lib/ice/dns/lookup.js +133 -0
  209. package/dist/cjs/lib/ice/dns/mdns.d.ts +38 -0
  210. package/dist/cjs/lib/ice/dns/mdns.js +145 -0
  211. package/dist/cjs/lib/ice/exceptions.d.ts +24 -0
  212. package/dist/cjs/lib/ice/exceptions.js +41 -0
  213. package/dist/cjs/lib/ice/helper.d.ts +17 -0
  214. package/dist/cjs/lib/ice/helper.js +74 -0
  215. package/dist/cjs/lib/ice/ice.d.ts +182 -0
  216. package/dist/cjs/lib/ice/ice.js +1584 -0
  217. package/dist/cjs/lib/ice/iceBase.d.ts +214 -0
  218. package/dist/cjs/lib/ice/iceBase.js +182 -0
  219. package/dist/cjs/lib/ice/imports/common.d.ts +1 -0
  220. package/dist/cjs/lib/ice/imports/common.js +17 -0
  221. package/dist/cjs/lib/ice/index.d.ts +12 -0
  222. package/dist/cjs/lib/ice/index.js +30 -0
  223. package/dist/cjs/lib/ice/internal/selectAddresses.d.ts +9 -0
  224. package/dist/cjs/lib/ice/internal/selectAddresses.js +39 -0
  225. package/dist/cjs/lib/ice/stun/attributes.d.ts +1 -0
  226. package/dist/cjs/lib/ice/stun/attributes.js +17 -0
  227. package/dist/cjs/lib/ice/stun/const.d.ts +8 -0
  228. package/dist/cjs/lib/ice/stun/const.js +25 -0
  229. package/dist/cjs/lib/ice/stun/message.d.ts +1 -0
  230. package/dist/cjs/lib/ice/stun/message.js +17 -0
  231. package/dist/cjs/lib/ice/stun/protocol.d.ts +30 -0
  232. package/dist/cjs/lib/ice/stun/protocol.js +125 -0
  233. package/dist/cjs/lib/ice/stun/tcpFrame.d.ts +5 -0
  234. package/dist/cjs/lib/ice/stun/tcpFrame.js +25 -0
  235. package/dist/cjs/lib/ice/stun/tcpProtocol.d.ts +57 -0
  236. package/dist/cjs/lib/ice/stun/tcpProtocol.js +323 -0
  237. package/dist/cjs/lib/ice/stun/transaction.d.ts +75 -0
  238. package/dist/cjs/lib/ice/stun/transaction.js +239 -0
  239. package/dist/cjs/lib/ice/turn/frame.d.ts +1 -0
  240. package/dist/cjs/lib/ice/turn/frame.js +17 -0
  241. package/dist/cjs/lib/ice/turn/protocol.d.ts +170 -0
  242. package/dist/cjs/lib/ice/turn/protocol.js +638 -0
  243. package/dist/cjs/lib/ice/types/model.d.ts +56 -0
  244. package/dist/cjs/lib/ice/types/model.js +2 -0
  245. package/dist/cjs/lib/ice/utils.d.ts +13 -0
  246. package/dist/cjs/lib/ice/utils.js +84 -0
  247. package/dist/cjs/lib/peer/const.d.ts +36 -0
  248. package/dist/cjs/lib/peer/const.js +53 -0
  249. package/dist/cjs/lib/peer/dataChannel.d.ts +69 -0
  250. package/dist/cjs/lib/peer/dataChannel.js +133 -0
  251. package/dist/cjs/lib/peer/errors.d.ts +11 -0
  252. package/dist/cjs/lib/peer/errors.js +23 -0
  253. package/dist/cjs/lib/peer/helper.d.ts +20 -0
  254. package/dist/cjs/lib/peer/helper.js +84 -0
  255. package/dist/cjs/lib/peer/imports/common.d.ts +1 -0
  256. package/dist/cjs/lib/peer/imports/common.js +17 -0
  257. package/dist/cjs/lib/peer/imports/dtls.d.ts +1 -0
  258. package/dist/cjs/lib/peer/imports/dtls.js +17 -0
  259. package/dist/cjs/lib/peer/imports/ice.d.ts +1 -0
  260. package/dist/cjs/lib/peer/imports/ice.js +17 -0
  261. package/dist/cjs/lib/peer/imports/rtp.d.ts +1 -0
  262. package/dist/cjs/lib/peer/imports/rtp.js +17 -0
  263. package/dist/cjs/lib/peer/index.d.ts +14 -0
  264. package/dist/cjs/lib/peer/index.js +30 -0
  265. package/dist/cjs/lib/peer/media/codec.d.ts +15 -0
  266. package/dist/cjs/lib/peer/media/codec.js +80 -0
  267. package/dist/cjs/lib/peer/media/codecCompatibility.d.ts +23 -0
  268. package/dist/cjs/lib/peer/media/codecCompatibility.js +137 -0
  269. package/dist/cjs/lib/peer/media/extension/rtcpFeedback.d.ts +6 -0
  270. package/dist/cjs/lib/peer/media/extension/rtcpFeedback.js +13 -0
  271. package/dist/cjs/lib/peer/media/extension/rtpExtension.d.ts +9 -0
  272. package/dist/cjs/lib/peer/media/extension/rtpExtension.js +52 -0
  273. package/dist/cjs/lib/peer/media/index.d.ts +12 -0
  274. package/dist/cjs/lib/peer/media/index.js +28 -0
  275. package/dist/cjs/lib/peer/media/parameters.d.ts +65 -0
  276. package/dist/cjs/lib/peer/media/parameters.js +60 -0
  277. package/dist/cjs/lib/peer/media/receiver/nack.d.ts +23 -0
  278. package/dist/cjs/lib/peer/media/receiver/nack.js +104 -0
  279. package/dist/cjs/lib/peer/media/receiver/receiverTwcc.d.ts +47 -0
  280. package/dist/cjs/lib/peer/media/receiver/receiverTwcc.js +179 -0
  281. package/dist/cjs/lib/peer/media/receiver/statistics.d.ts +22 -0
  282. package/dist/cjs/lib/peer/media/receiver/statistics.js +71 -0
  283. package/dist/cjs/lib/peer/media/router.d.ts +25 -0
  284. package/dist/cjs/lib/peer/media/router.js +166 -0
  285. package/dist/cjs/lib/peer/media/rtpReceiver.d.ts +90 -0
  286. package/dist/cjs/lib/peer/media/rtpReceiver.js +407 -0
  287. package/dist/cjs/lib/peer/media/rtpSender.d.ts +209 -0
  288. package/dist/cjs/lib/peer/media/rtpSender.js +826 -0
  289. package/dist/cjs/lib/peer/media/rtpTransceiver.d.ts +117 -0
  290. package/dist/cjs/lib/peer/media/rtpTransceiver.js +245 -0
  291. package/dist/cjs/lib/peer/media/sender/cumulativeResult.d.ts +19 -0
  292. package/dist/cjs/lib/peer/media/sender/cumulativeResult.js +61 -0
  293. package/dist/cjs/lib/peer/media/sender/senderBWE.d.ts +32 -0
  294. package/dist/cjs/lib/peer/media/sender/senderBWE.js +99 -0
  295. package/dist/cjs/lib/peer/media/stats.d.ts +293 -0
  296. package/dist/cjs/lib/peer/media/stats.js +90 -0
  297. package/dist/cjs/lib/peer/media/track.d.ts +67 -0
  298. package/dist/cjs/lib/peer/media/track.js +216 -0
  299. package/dist/cjs/lib/peer/peerConnection.d.ts +458 -0
  300. package/dist/cjs/lib/peer/peerConnection.js +1591 -0
  301. package/dist/cjs/lib/peer/sctpManager.d.ts +28 -0
  302. package/dist/cjs/lib/peer/sctpManager.js +138 -0
  303. package/dist/cjs/lib/peer/sdp.d.ts +97 -0
  304. package/dist/cjs/lib/peer/sdp.js +628 -0
  305. package/dist/cjs/lib/peer/sdpManager.d.ts +116 -0
  306. package/dist/cjs/lib/peer/sdpManager.js +573 -0
  307. package/dist/cjs/lib/peer/secureTransportManager.d.ts +96 -0
  308. package/dist/cjs/lib/peer/secureTransportManager.js +472 -0
  309. package/dist/cjs/lib/peer/transceiverManager.d.ts +151 -0
  310. package/dist/cjs/lib/peer/transceiverManager.js +767 -0
  311. package/dist/cjs/lib/peer/transport/dtls.d.ts +95 -0
  312. package/dist/cjs/lib/peer/transport/dtls.js +571 -0
  313. package/dist/cjs/lib/peer/transport/ice.d.ts +143 -0
  314. package/dist/cjs/lib/peer/transport/ice.js +436 -0
  315. package/dist/cjs/lib/peer/transport/sctp.d.ts +56 -0
  316. package/dist/cjs/lib/peer/transport/sctp.js +387 -0
  317. package/dist/cjs/lib/peer/types/domain.d.ts +5 -0
  318. package/dist/cjs/lib/peer/types/domain.js +19 -0
  319. package/dist/cjs/lib/peer/types/util.d.ts +2 -0
  320. package/dist/cjs/lib/peer/types/util.js +2 -0
  321. package/dist/cjs/lib/peer/utils.d.ts +73 -0
  322. package/dist/cjs/lib/peer/utils.js +306 -0
  323. package/dist/cjs/lib/rtp/codec/av1.d.ts +56 -0
  324. package/dist/cjs/lib/rtp/codec/av1.js +209 -0
  325. package/dist/cjs/lib/rtp/codec/base.d.ts +8 -0
  326. package/dist/cjs/lib/rtp/codec/base.js +15 -0
  327. package/dist/cjs/lib/rtp/codec/h264.d.ts +32 -0
  328. package/dist/cjs/lib/rtp/codec/h264.js +122 -0
  329. package/dist/cjs/lib/rtp/codec/index.d.ts +16 -0
  330. package/dist/cjs/lib/rtp/codec/index.js +84 -0
  331. package/dist/cjs/lib/rtp/codec/leb128.d.ts +5 -0
  332. package/dist/cjs/lib/rtp/codec/leb128.js +23 -0
  333. package/dist/cjs/lib/rtp/codec/opus.d.ts +9 -0
  334. package/dist/cjs/lib/rtp/codec/opus.js +25 -0
  335. package/dist/cjs/lib/rtp/codec/vp8.d.ts +27 -0
  336. package/dist/cjs/lib/rtp/codec/vp8.js +109 -0
  337. package/dist/cjs/lib/rtp/codec/vp9.d.ts +46 -0
  338. package/dist/cjs/lib/rtp/codec/vp9.js +161 -0
  339. package/dist/cjs/lib/rtp/const.d.ts +1 -0
  340. package/dist/cjs/lib/rtp/const.js +4 -0
  341. package/dist/cjs/lib/rtp/helper.d.ts +8 -0
  342. package/dist/cjs/lib/rtp/helper.js +36 -0
  343. package/dist/cjs/lib/rtp/imports/common.d.ts +1 -0
  344. package/dist/cjs/lib/rtp/imports/common.js +17 -0
  345. package/dist/cjs/lib/rtp/index.d.ts +25 -0
  346. package/dist/cjs/lib/rtp/index.js +41 -0
  347. package/dist/cjs/lib/rtp/rtcp/header.d.ts +13 -0
  348. package/dist/cjs/lib/rtp/rtcp/header.js +50 -0
  349. package/dist/cjs/lib/rtp/rtcp/psfb/fullIntraRequest.d.ts +16 -0
  350. package/dist/cjs/lib/rtp/rtcp/psfb/fullIntraRequest.js +34 -0
  351. package/dist/cjs/lib/rtp/rtcp/psfb/index.d.ts +14 -0
  352. package/dist/cjs/lib/rtp/rtcp/psfb/index.js +39 -0
  353. package/dist/cjs/lib/rtp/rtcp/psfb/pictureLossIndication.d.ts +10 -0
  354. package/dist/cjs/lib/rtp/rtcp/psfb/pictureLossIndication.js +20 -0
  355. package/dist/cjs/lib/rtp/rtcp/psfb/remb.d.ts +16 -0
  356. package/dist/cjs/lib/rtp/rtcp/psfb/remb.js +53 -0
  357. package/dist/cjs/lib/rtp/rtcp/rr.d.ts +32 -0
  358. package/dist/cjs/lib/rtp/rtcp/rr.js +73 -0
  359. package/dist/cjs/lib/rtp/rtcp/rtcp.d.ts +10 -0
  360. package/dist/cjs/lib/rtp/rtcp/rtcp.js +58 -0
  361. package/dist/cjs/lib/rtp/rtcp/rtpfb/const.d.ts +1 -0
  362. package/dist/cjs/lib/rtp/rtcp/rtpfb/const.js +4 -0
  363. package/dist/cjs/lib/rtp/rtcp/rtpfb/index.d.ts +14 -0
  364. package/dist/cjs/lib/rtp/rtcp/rtpfb/index.js +35 -0
  365. package/dist/cjs/lib/rtp/rtcp/rtpfb/nack.d.ts +17 -0
  366. package/dist/cjs/lib/rtp/rtcp/rtpfb/nack.js +77 -0
  367. package/dist/cjs/lib/rtp/rtcp/rtpfb/twcc.d.ts +71 -0
  368. package/dist/cjs/lib/rtp/rtcp/rtpfb/twcc.js +352 -0
  369. package/dist/cjs/lib/rtp/rtcp/sdes.d.ts +26 -0
  370. package/dist/cjs/lib/rtp/rtcp/sdes.js +97 -0
  371. package/dist/cjs/lib/rtp/rtcp/sr.d.ts +41 -0
  372. package/dist/cjs/lib/rtp/rtcp/sr.js +110 -0
  373. package/dist/cjs/lib/rtp/rtp/headerExtension.d.ts +72 -0
  374. package/dist/cjs/lib/rtp/rtp/headerExtension.js +117 -0
  375. package/dist/cjs/lib/rtp/rtp/red/encoder.d.ts +13 -0
  376. package/dist/cjs/lib/rtp/rtp/red/encoder.js +44 -0
  377. package/dist/cjs/lib/rtp/rtp/red/handler.d.ts +6 -0
  378. package/dist/cjs/lib/rtp/rtp/red/handler.js +59 -0
  379. package/dist/cjs/lib/rtp/rtp/red/packet.d.ts +26 -0
  380. package/dist/cjs/lib/rtp/rtp/red/packet.js +112 -0
  381. package/dist/cjs/lib/rtp/rtp/rtp.d.ts +44 -0
  382. package/dist/cjs/lib/rtp/rtp/rtp.js +271 -0
  383. package/dist/cjs/lib/rtp/rtp/rtx.d.ts +3 -0
  384. package/dist/cjs/lib/rtp/rtp/rtx.js +29 -0
  385. package/dist/cjs/lib/rtp/srtp/cipher/ctr.d.ts +16 -0
  386. package/dist/cjs/lib/rtp/srtp/cipher/ctr.js +107 -0
  387. package/dist/cjs/lib/rtp/srtp/cipher/gcm.d.ts +17 -0
  388. package/dist/cjs/lib/rtp/srtp/cipher/gcm.js +145 -0
  389. package/dist/cjs/lib/rtp/srtp/cipher/index.d.ts +13 -0
  390. package/dist/cjs/lib/rtp/srtp/cipher/index.js +24 -0
  391. package/dist/cjs/lib/rtp/srtp/const.d.ts +6 -0
  392. package/dist/cjs/lib/rtp/srtp/const.js +26 -0
  393. package/dist/cjs/lib/rtp/srtp/context/context.d.ts +45 -0
  394. package/dist/cjs/lib/rtp/srtp/context/context.js +180 -0
  395. package/dist/cjs/lib/rtp/srtp/context/srtcp.d.ts +8 -0
  396. package/dist/cjs/lib/rtp/srtp/context/srtcp.js +25 -0
  397. package/dist/cjs/lib/rtp/srtp/context/srtp.d.ts +9 -0
  398. package/dist/cjs/lib/rtp/srtp/context/srtp.js +41 -0
  399. package/dist/cjs/lib/rtp/srtp/error.d.ts +3 -0
  400. package/dist/cjs/lib/rtp/srtp/error.js +10 -0
  401. package/dist/cjs/lib/rtp/srtp/packet.d.ts +5 -0
  402. package/dist/cjs/lib/rtp/srtp/packet.js +47 -0
  403. package/dist/cjs/lib/rtp/srtp/session.d.ts +19 -0
  404. package/dist/cjs/lib/rtp/srtp/session.js +13 -0
  405. package/dist/cjs/lib/rtp/srtp/srtcp.d.ts +8 -0
  406. package/dist/cjs/lib/rtp/srtp/srtcp.js +21 -0
  407. package/dist/cjs/lib/rtp/srtp/srtp.d.ts +9 -0
  408. package/dist/cjs/lib/rtp/srtp/srtp.js +20 -0
  409. package/dist/cjs/lib/rtp/transport.d.ts +15 -0
  410. package/dist/cjs/lib/rtp/transport.js +23 -0
  411. package/dist/cjs/lib/rtp/util.d.ts +11 -0
  412. package/dist/cjs/lib/rtp/util.js +28 -0
  413. package/dist/cjs/lib/sctp/chunk.d.ts +164 -0
  414. package/dist/cjs/lib/sctp/chunk.js +542 -0
  415. package/dist/cjs/lib/sctp/const.d.ts +17 -0
  416. package/dist/cjs/lib/sctp/const.js +22 -0
  417. package/dist/cjs/lib/sctp/helper.d.ts +5 -0
  418. package/dist/cjs/lib/sctp/helper.js +14 -0
  419. package/dist/cjs/lib/sctp/imports/common.d.ts +1 -0
  420. package/dist/cjs/lib/sctp/imports/common.js +17 -0
  421. package/dist/cjs/lib/sctp/index.d.ts +6 -0
  422. package/dist/cjs/lib/sctp/index.js +20 -0
  423. package/dist/cjs/lib/sctp/param.d.ts +40 -0
  424. package/dist/cjs/lib/sctp/param.js +132 -0
  425. package/dist/cjs/lib/sctp/sctp.d.ts +210 -0
  426. package/dist/cjs/lib/sctp/sctp.js +1467 -0
  427. package/dist/cjs/lib/sctp/transport.d.ts +15 -0
  428. package/dist/cjs/lib/sctp/transport.js +28 -0
  429. package/dist/cjs/lib/turn/index.d.ts +9 -0
  430. package/dist/cjs/lib/turn/index.js +25 -0
  431. package/dist/cjs/lib/turn/node/server.d.ts +21 -0
  432. package/dist/cjs/lib/turn/node/server.js +94 -0
  433. package/dist/cjs/lib/turn/node/turnServer.d.ts +91 -0
  434. package/dist/cjs/lib/turn/node/turnServer.js +565 -0
  435. package/dist/cjs/lib/turn/protocol.d.ts +47 -0
  436. package/dist/cjs/lib/turn/protocol.js +116 -0
  437. package/dist/cjs/lib/turn/stun/attributes.d.ts +37 -0
  438. package/dist/cjs/lib/turn/stun/attributes.js +208 -0
  439. package/dist/cjs/lib/turn/stun/const.d.ts +28 -0
  440. package/dist/cjs/lib/turn/stun/const.js +87 -0
  441. package/dist/cjs/lib/turn/stun/ip.d.ts +12 -0
  442. package/dist/cjs/lib/turn/stun/ip.js +87 -0
  443. package/dist/cjs/lib/turn/stun/message.d.ts +37 -0
  444. package/dist/cjs/lib/turn/stun/message.js +180 -0
  445. package/dist/cjs/lib/turn/turn/auth.d.ts +1 -0
  446. package/dist/cjs/lib/turn/turn/auth.js +9 -0
  447. package/dist/cjs/lib/turn/turn/frame.d.ts +13 -0
  448. package/dist/cjs/lib/turn/turn/frame.js +68 -0
  449. package/dist/cjs/lib/turn/turn/protocol.d.ts +147 -0
  450. package/dist/cjs/lib/turn/turn/protocol.js +785 -0
  451. package/dist/cjs/package.json +1 -0
  452. package/dist/cjs/peer/Endpoints.d.ts +75 -0
  453. package/dist/cjs/peer/Endpoints.js +154 -0
  454. package/dist/cjs/peer/EngineConfig.d.ts +20 -0
  455. package/dist/cjs/peer/EngineConfig.js +36 -0
  456. package/dist/cjs/peer/EngineConnection.d.ts +22 -0
  457. package/dist/cjs/peer/EngineConnection.js +27 -0
  458. package/dist/cjs/peer/Events.d.ts +55 -0
  459. package/dist/cjs/peer/Events.js +85 -0
  460. package/dist/cjs/peer/MediaCodecs.d.ts +27 -0
  461. package/dist/cjs/peer/MediaCodecs.js +53 -0
  462. package/dist/cjs/peer/MediaTrack.d.ts +212 -0
  463. package/dist/cjs/peer/MediaTrack.js +313 -0
  464. package/dist/cjs/peer/PeerChannel.d.ts +248 -0
  465. package/dist/cjs/peer/PeerChannel.js +319 -0
  466. package/dist/cjs/peer/PeerConnection.d.ts +603 -0
  467. package/dist/cjs/peer/PeerConnection.js +697 -0
  468. package/dist/cjs/peer/PeerThreadChannel.d.ts +112 -0
  469. package/dist/cjs/peer/PeerThreadChannel.js +273 -0
  470. package/dist/cjs/peer/PeerThreadProtocol.d.ts +325 -0
  471. package/dist/cjs/peer/PeerThreadProtocol.js +2 -0
  472. package/dist/cjs/peer/PeerThreads.d.ts +114 -0
  473. package/dist/cjs/peer/PeerThreads.js +268 -0
  474. package/dist/cjs/peer/PeerWorker.d.ts +6 -0
  475. package/dist/cjs/peer/PeerWorker.js +461 -0
  476. package/dist/cjs/peer/PeerWorkerCode.d.ts +5 -0
  477. package/dist/cjs/peer/PeerWorkerCode.js +4 -0
  478. package/dist/cjs/peer/RemoteConnection.d.ts +314 -0
  479. package/dist/cjs/peer/RemoteConnection.js +913 -0
  480. package/dist/cjs/peer/RtpPacket.d.ts +112 -0
  481. package/dist/cjs/peer/RtpPacket.js +92 -0
  482. package/dist/cjs/peer/RtpTransceiver.d.ts +167 -0
  483. package/dist/cjs/peer/RtpTransceiver.js +235 -0
  484. package/dist/cjs/peer/SignalingClient.d.ts +236 -0
  485. package/dist/cjs/peer/SignalingClient.js +285 -0
  486. package/dist/cjs/protocol/SignalingProtocol.d.ts +266 -0
  487. package/dist/cjs/protocol/SignalingProtocol.js +65 -0
  488. package/dist/cjs/service/WebRTCServiceEntrypoint.d.ts +158 -0
  489. package/dist/cjs/service/WebRTCServiceEntrypoint.js +356 -0
  490. package/dist/cjs/sfu/SFU.d.ts +356 -0
  491. package/dist/cjs/sfu/SFU.js +763 -0
  492. package/dist/cjs/sfu/SFUAccess.d.ts +48 -0
  493. package/dist/cjs/sfu/SFUAccess.js +15 -0
  494. package/dist/cjs/sfu/SFUClusterLeg.d.ts +101 -0
  495. package/dist/cjs/sfu/SFUClusterLeg.js +106 -0
  496. package/dist/cjs/sfu/SFURoom.d.ts +148 -0
  497. package/dist/cjs/sfu/SFURoom.js +1300 -0
  498. package/dist/cjs/sfu/SFUWorker.d.ts +13 -0
  499. package/dist/cjs/sfu/SFUWorker.js +168 -0
  500. package/dist/cjs/sfu/SFUWorkerChannel.d.ts +204 -0
  501. package/dist/cjs/sfu/SFUWorkerChannel.js +105 -0
  502. package/dist/cjs/sfu/SFUWorkerCode.d.ts +5 -0
  503. package/dist/cjs/sfu/SFUWorkerCode.js +4 -0
  504. package/dist/cjs/sfu/SFUWorkers.d.ts +247 -0
  505. package/dist/cjs/sfu/SFUWorkers.js +552 -0
  506. package/dist/cjs/shared/ChunkedChannel.d.ts +122 -0
  507. package/dist/cjs/shared/ChunkedChannel.js +182 -0
  508. package/dist/cjs/shared/Connections.d.ts +231 -0
  509. package/dist/cjs/shared/Connections.js +2 -0
  510. package/dist/cjs/shared/Emitter.d.ts +50 -0
  511. package/dist/cjs/shared/Emitter.js +80 -0
  512. package/dist/cjs/shared/Peer.d.ts +182 -0
  513. package/dist/cjs/shared/Peer.js +509 -0
  514. package/dist/cjs/shared/PeerServiceProxy.d.ts +173 -0
  515. package/dist/cjs/shared/PeerServiceProxy.js +304 -0
  516. package/dist/cjs/shared/Room.d.ts +143 -0
  517. package/dist/cjs/shared/Room.js +515 -0
  518. package/dist/cjs/shared/SignalingError.d.ts +40 -0
  519. package/dist/cjs/shared/SignalingError.js +48 -0
  520. package/dist/cjs/shared/SignalingSession.d.ts +97 -0
  521. package/dist/cjs/shared/SignalingSession.js +347 -0
  522. package/dist/cjs/shared/Transports.d.ts +139 -0
  523. package/dist/cjs/shared/Transports.js +285 -0
  524. package/dist/cjs/signaling/MediaServers.d.ts +40 -0
  525. package/dist/cjs/signaling/MediaServers.js +16 -0
  526. package/dist/cjs/signaling/Signaling.d.ts +573 -0
  527. package/dist/cjs/signaling/Signaling.js +945 -0
  528. package/dist/cjs/signaling/SignalingController.d.ts +128 -0
  529. package/dist/cjs/signaling/SignalingController.js +229 -0
  530. package/dist/cjs/turn/TURNCredentials.d.ts +49 -0
  531. package/dist/cjs/turn/TURNCredentials.js +49 -0
  532. package/dist/cjs/turn/TURNIceServers.d.ts +11 -0
  533. package/dist/cjs/turn/TURNIceServers.js +25 -0
  534. package/dist/cjs/turn/TURNServer.d.ts +309 -0
  535. package/dist/cjs/turn/TURNServer.js +331 -0
  536. package/dist/cjs/turn/TURNWorker.d.ts +42 -0
  537. package/dist/cjs/turn/TURNWorker.js +52 -0
  538. package/dist/cjs/turn/TURNWorkerCode.d.ts +5 -0
  539. package/dist/cjs/turn/TURNWorkerCode.js +4 -0
  540. package/dist/cjs/turn/TURNWorkers.d.ts +52 -0
  541. package/dist/cjs/turn/TURNWorkers.js +211 -0
  542. package/dist/cjs/whep/WHEP.d.ts +386 -0
  543. package/dist/cjs/whep/WHEP.js +426 -0
  544. package/dist/cjs/whep/WHEPController.d.ts +134 -0
  545. package/dist/cjs/whep/WHEPController.js +301 -0
  546. package/dist/cjs/whip/WHIP.d.ts +426 -0
  547. package/dist/cjs/whip/WHIP.js +470 -0
  548. package/dist/cjs/whip/WHIPController.d.ts +132 -0
  549. package/dist/cjs/whip/WHIPController.js +299 -0
  550. package/dist/esm/client/SignalingConnection.js +63 -0
  551. package/dist/esm/cluster/Cluster.js +542 -0
  552. package/dist/esm/cluster/ClusterFrames.js +85 -0
  553. package/dist/esm/cluster/ClusterTURN.js +73 -0
  554. package/dist/esm/cluster/Rendezvous.js +20 -0
  555. package/dist/esm/cluster/transports/ClusterTransport.js +1 -0
  556. package/dist/esm/cluster/transports/LoadClient.js +44 -0
  557. package/dist/esm/cluster/transports/MemoryClusterTransport.js +43 -0
  558. package/dist/esm/cluster/transports/NATSClusterTransport.js +66 -0
  559. package/dist/esm/cluster/transports/RedisClusterTransport.js +73 -0
  560. package/dist/esm/exceptions/ClusterRequestException.js +14 -0
  561. package/dist/esm/exceptions/ClusterTimeoutException.js +13 -0
  562. package/dist/esm/exceptions/ClusterTransportNotFoundException.js +14 -0
  563. package/dist/esm/exceptions/SignalingClientRequiredException.js +15 -0
  564. package/dist/esm/exceptions/SignalingConnectionException.js +15 -0
  565. package/dist/esm/exceptions/SignalingDeniedException.js +14 -0
  566. package/dist/esm/exceptions/SignalingLimitException.js +14 -0
  567. package/dist/esm/exceptions/SignalingNotAMemberException.js +14 -0
  568. package/dist/esm/exceptions/WHEPDeniedException.js +18 -0
  569. package/dist/esm/exceptions/WHEPLimitException.js +18 -0
  570. package/dist/esm/exceptions/WHEPMediaTypeException.js +18 -0
  571. package/dist/esm/exceptions/WHEPOfferException.js +19 -0
  572. package/dist/esm/exceptions/WHEPSessionNotFoundException.js +18 -0
  573. package/dist/esm/exceptions/WHIPDeniedException.js +18 -0
  574. package/dist/esm/exceptions/WHIPLimitException.js +18 -0
  575. package/dist/esm/exceptions/WHIPMediaTypeException.js +18 -0
  576. package/dist/esm/exceptions/WHIPOfferException.js +19 -0
  577. package/dist/esm/exceptions/WHIPSessionNotFoundException.js +18 -0
  578. package/dist/esm/exports/Client.js +5 -0
  579. package/dist/esm/exports/WebRTC.js +41 -0
  580. package/dist/esm/lib/common/binary.js +244 -0
  581. package/dist/esm/lib/common/binaryData.js +392 -0
  582. package/dist/esm/lib/common/crc.js +118 -0
  583. package/dist/esm/lib/common/deque.js +85 -0
  584. package/dist/esm/lib/common/event.js +202 -0
  585. package/dist/esm/lib/common/index.js +11 -0
  586. package/dist/esm/lib/common/log.js +55 -0
  587. package/dist/esm/lib/common/network.js +52 -0
  588. package/dist/esm/lib/common/number.js +31 -0
  589. package/dist/esm/lib/common/promise.js +64 -0
  590. package/dist/esm/lib/common/transport.js +401 -0
  591. package/dist/esm/lib/common/type.js +1 -0
  592. package/dist/esm/lib/dtls/cipher/const.js +30 -0
  593. package/dist/esm/lib/dtls/cipher/create.js +98 -0
  594. package/dist/esm/lib/dtls/cipher/ec.js +37 -0
  595. package/dist/esm/lib/dtls/cipher/key-exchange.js +103 -0
  596. package/dist/esm/lib/dtls/cipher/namedCurve.js +24 -0
  597. package/dist/esm/lib/dtls/cipher/prf.js +79 -0
  598. package/dist/esm/lib/dtls/cipher/suites/abstract.js +37 -0
  599. package/dist/esm/lib/dtls/cipher/suites/aead.js +96 -0
  600. package/dist/esm/lib/dtls/cipher/suites/null.js +35 -0
  601. package/dist/esm/lib/dtls/cipher/utils.js +34 -0
  602. package/dist/esm/lib/dtls/cipher/x509.js +94 -0
  603. package/dist/esm/lib/dtls/client.js +72 -0
  604. package/dist/esm/lib/dtls/context/cipher.js +83 -0
  605. package/dist/esm/lib/dtls/context/dtls.js +45 -0
  606. package/dist/esm/lib/dtls/context/srtp.js +8 -0
  607. package/dist/esm/lib/dtls/context/transport.js +13 -0
  608. package/dist/esm/lib/dtls/flight/client/flight1.js +22 -0
  609. package/dist/esm/lib/dtls/flight/client/flight3.js +21 -0
  610. package/dist/esm/lib/dtls/flight/client/flight5.js +202 -0
  611. package/dist/esm/lib/dtls/flight/flight.js +64 -0
  612. package/dist/esm/lib/dtls/flight/server/flight2.js +122 -0
  613. package/dist/esm/lib/dtls/flight/server/flight4.js +83 -0
  614. package/dist/esm/lib/dtls/flight/server/flight6.js +107 -0
  615. package/dist/esm/lib/dtls/handshake/binary.js +17 -0
  616. package/dist/esm/lib/dtls/handshake/const.js +14 -0
  617. package/dist/esm/lib/dtls/handshake/extensions/ellipticCurves.js +36 -0
  618. package/dist/esm/lib/dtls/handshake/extensions/extendedMasterSecret.js +3 -0
  619. package/dist/esm/lib/dtls/handshake/extensions/renegotiationIndication.js +30 -0
  620. package/dist/esm/lib/dtls/handshake/extensions/signature.js +35 -0
  621. package/dist/esm/lib/dtls/handshake/extensions/useSrtp.js +61 -0
  622. package/dist/esm/lib/dtls/handshake/message/alert.js +20 -0
  623. package/dist/esm/lib/dtls/handshake/message/certificate.js +31 -0
  624. package/dist/esm/lib/dtls/handshake/message/changeCipherSpec.js +20 -0
  625. package/dist/esm/lib/dtls/handshake/message/client/certificateVerify.js +31 -0
  626. package/dist/esm/lib/dtls/handshake/message/client/hello.js +44 -0
  627. package/dist/esm/lib/dtls/handshake/message/client/keyExchange.js +29 -0
  628. package/dist/esm/lib/dtls/handshake/message/finished.js +22 -0
  629. package/dist/esm/lib/dtls/handshake/message/server/certificateRequest.js +34 -0
  630. package/dist/esm/lib/dtls/handshake/message/server/hello.js +53 -0
  631. package/dist/esm/lib/dtls/handshake/message/server/helloDone.js +26 -0
  632. package/dist/esm/lib/dtls/handshake/message/server/helloVerifyRequest.js +38 -0
  633. package/dist/esm/lib/dtls/handshake/message/server/keyExchange.js +45 -0
  634. package/dist/esm/lib/dtls/handshake/random.js +25 -0
  635. package/dist/esm/lib/dtls/helper.js +23 -0
  636. package/dist/esm/lib/dtls/imports/common.js +1 -0
  637. package/dist/esm/lib/dtls/imports/rtp.js +1 -0
  638. package/dist/esm/lib/dtls/index.js +97 -0
  639. package/dist/esm/lib/dtls/record/antiReplayWindow.js +98 -0
  640. package/dist/esm/lib/dtls/record/builder.js +22 -0
  641. package/dist/esm/lib/dtls/record/const.js +35 -0
  642. package/dist/esm/lib/dtls/record/message/fragment.js +92 -0
  643. package/dist/esm/lib/dtls/record/message/header.js +30 -0
  644. package/dist/esm/lib/dtls/record/message/plaintext.js +59 -0
  645. package/dist/esm/lib/dtls/record/receive.js +86 -0
  646. package/dist/esm/lib/dtls/server.js +74 -0
  647. package/dist/esm/lib/dtls/socket.js +184 -0
  648. package/dist/esm/lib/dtls/typings/domain.js +1 -0
  649. package/dist/esm/lib/dtls/util/binary.js +5 -0
  650. package/dist/esm/lib/ice/candidate.js +190 -0
  651. package/dist/esm/lib/ice/dns/lookup.js +95 -0
  652. package/dist/esm/lib/ice/dns/mdns.js +139 -0
  653. package/dist/esm/lib/ice/exceptions.js +34 -0
  654. package/dist/esm/lib/ice/helper.js +65 -0
  655. package/dist/esm/lib/ice/ice.js +1547 -0
  656. package/dist/esm/lib/ice/iceBase.js +172 -0
  657. package/dist/esm/lib/ice/imports/common.js +1 -0
  658. package/dist/esm/lib/ice/index.js +12 -0
  659. package/dist/esm/lib/ice/internal/selectAddresses.js +36 -0
  660. package/dist/esm/lib/ice/stun/attributes.js +1 -0
  661. package/dist/esm/lib/ice/stun/const.js +8 -0
  662. package/dist/esm/lib/ice/stun/message.js +1 -0
  663. package/dist/esm/lib/ice/stun/protocol.js +121 -0
  664. package/dist/esm/lib/ice/stun/tcpFrame.js +21 -0
  665. package/dist/esm/lib/ice/stun/tcpProtocol.js +318 -0
  666. package/dist/esm/lib/ice/stun/transaction.js +230 -0
  667. package/dist/esm/lib/ice/turn/frame.js +1 -0
  668. package/dist/esm/lib/ice/turn/protocol.js +630 -0
  669. package/dist/esm/lib/ice/types/model.js +1 -0
  670. package/dist/esm/lib/ice/utils.js +43 -0
  671. package/dist/esm/lib/peer/const.js +50 -0
  672. package/dist/esm/lib/peer/dataChannel.js +127 -0
  673. package/dist/esm/lib/peer/errors.js +17 -0
  674. package/dist/esm/lib/peer/helper.js +77 -0
  675. package/dist/esm/lib/peer/imports/common.js +1 -0
  676. package/dist/esm/lib/peer/imports/dtls.js +1 -0
  677. package/dist/esm/lib/peer/imports/ice.js +1 -0
  678. package/dist/esm/lib/peer/imports/rtp.js +1 -0
  679. package/dist/esm/lib/peer/index.js +14 -0
  680. package/dist/esm/lib/peer/media/codec.js +69 -0
  681. package/dist/esm/lib/peer/media/codecCompatibility.js +128 -0
  682. package/dist/esm/lib/peer/media/extension/rtcpFeedback.js +5 -0
  683. package/dist/esm/lib/peer/media/extension/rtpExtension.js +42 -0
  684. package/dist/esm/lib/peer/media/index.js +12 -0
  685. package/dist/esm/lib/peer/media/parameters.js +50 -0
  686. package/dist/esm/lib/peer/media/receiver/nack.js +100 -0
  687. package/dist/esm/lib/peer/media/receiver/receiverTwcc.js +175 -0
  688. package/dist/esm/lib/peer/media/receiver/statistics.js +67 -0
  689. package/dist/esm/lib/peer/media/router.js +162 -0
  690. package/dist/esm/lib/peer/media/rtpReceiver.js +403 -0
  691. package/dist/esm/lib/peer/media/rtpSender.js +822 -0
  692. package/dist/esm/lib/peer/media/rtpTransceiver.js +241 -0
  693. package/dist/esm/lib/peer/media/sender/cumulativeResult.js +57 -0
  694. package/dist/esm/lib/peer/media/sender/senderBWE.js +95 -0
  695. package/dist/esm/lib/peer/media/stats.js +81 -0
  696. package/dist/esm/lib/peer/media/track.js +208 -0
  697. package/dist/esm/lib/peer/peerConnection.js +1585 -0
  698. package/dist/esm/lib/peer/sctpManager.js +134 -0
  699. package/dist/esm/lib/peer/sdp.js +614 -0
  700. package/dist/esm/lib/peer/sdpManager.js +569 -0
  701. package/dist/esm/lib/peer/secureTransportManager.js +468 -0
  702. package/dist/esm/lib/peer/transceiverManager.js +763 -0
  703. package/dist/esm/lib/peer/transport/dtls.js +564 -0
  704. package/dist/esm/lib/peer/transport/ice.js +426 -0
  705. package/dist/esm/lib/peer/transport/sctp.js +382 -0
  706. package/dist/esm/lib/peer/types/domain.js +16 -0
  707. package/dist/esm/lib/peer/types/util.js +1 -0
  708. package/dist/esm/lib/peer/utils.js +286 -0
  709. package/dist/esm/lib/rtp/codec/av1.js +203 -0
  710. package/dist/esm/lib/rtp/codec/base.js +11 -0
  711. package/dist/esm/lib/rtp/codec/h264.js +118 -0
  712. package/dist/esm/lib/rtp/codec/index.js +66 -0
  713. package/dist/esm/lib/rtp/codec/leb128.js +20 -0
  714. package/dist/esm/lib/rtp/codec/opus.js +21 -0
  715. package/dist/esm/lib/rtp/codec/vp8.js +105 -0
  716. package/dist/esm/lib/rtp/codec/vp9.js +157 -0
  717. package/dist/esm/lib/rtp/const.js +1 -0
  718. package/dist/esm/lib/rtp/helper.js +29 -0
  719. package/dist/esm/lib/rtp/imports/common.js +1 -0
  720. package/dist/esm/lib/rtp/index.js +25 -0
  721. package/dist/esm/lib/rtp/rtcp/header.js +46 -0
  722. package/dist/esm/lib/rtp/rtcp/psfb/fullIntraRequest.js +30 -0
  723. package/dist/esm/lib/rtp/rtcp/psfb/index.js +35 -0
  724. package/dist/esm/lib/rtp/rtcp/psfb/pictureLossIndication.js +16 -0
  725. package/dist/esm/lib/rtp/rtcp/psfb/remb.js +49 -0
  726. package/dist/esm/lib/rtp/rtcp/rr.js +68 -0
  727. package/dist/esm/lib/rtp/rtcp/rtcp.js +53 -0
  728. package/dist/esm/lib/rtp/rtcp/rtpfb/const.js +1 -0
  729. package/dist/esm/lib/rtp/rtcp/rtpfb/index.js +31 -0
  730. package/dist/esm/lib/rtp/rtcp/rtpfb/nack.js +73 -0
  731. package/dist/esm/lib/rtp/rtcp/rtpfb/twcc.js +344 -0
  732. package/dist/esm/lib/rtp/rtcp/sdes.js +91 -0
  733. package/dist/esm/lib/rtp/rtcp/sr.js +104 -0
  734. package/dist/esm/lib/rtp/rtp/headerExtension.js +102 -0
  735. package/dist/esm/lib/rtp/rtp/red/encoder.js +40 -0
  736. package/dist/esm/lib/rtp/rtp/red/handler.js +55 -0
  737. package/dist/esm/lib/rtp/rtp/red/packet.js +107 -0
  738. package/dist/esm/lib/rtp/rtp/rtp.js +266 -0
  739. package/dist/esm/lib/rtp/rtp/rtx.js +25 -0
  740. package/dist/esm/lib/rtp/srtp/cipher/ctr.js +103 -0
  741. package/dist/esm/lib/rtp/srtp/cipher/gcm.js +141 -0
  742. package/dist/esm/lib/rtp/srtp/cipher/index.js +20 -0
  743. package/dist/esm/lib/rtp/srtp/const.js +21 -0
  744. package/dist/esm/lib/rtp/srtp/context/context.js +175 -0
  745. package/dist/esm/lib/rtp/srtp/context/srtcp.js +21 -0
  746. package/dist/esm/lib/rtp/srtp/context/srtp.js +37 -0
  747. package/dist/esm/lib/rtp/srtp/error.js +6 -0
  748. package/dist/esm/lib/rtp/srtp/packet.js +42 -0
  749. package/dist/esm/lib/rtp/srtp/session.js +9 -0
  750. package/dist/esm/lib/rtp/srtp/srtcp.js +17 -0
  751. package/dist/esm/lib/rtp/srtp/srtp.js +16 -0
  752. package/dist/esm/lib/rtp/transport.js +18 -0
  753. package/dist/esm/lib/rtp/util.js +24 -0
  754. package/dist/esm/lib/sctp/chunk.js +515 -0
  755. package/dist/esm/lib/sctp/const.js +19 -0
  756. package/dist/esm/lib/sctp/helper.js +10 -0
  757. package/dist/esm/lib/sctp/imports/common.js +1 -0
  758. package/dist/esm/lib/sctp/index.js +4 -0
  759. package/dist/esm/lib/sctp/param.js +126 -0
  760. package/dist/esm/lib/sctp/sctp.js +1459 -0
  761. package/dist/esm/lib/sctp/transport.js +23 -0
  762. package/dist/esm/lib/turn/index.js +9 -0
  763. package/dist/esm/lib/turn/node/server.js +89 -0
  764. package/dist/esm/lib/turn/node/turnServer.js +560 -0
  765. package/dist/esm/lib/turn/protocol.js +112 -0
  766. package/dist/esm/lib/turn/stun/attributes.js +198 -0
  767. package/dist/esm/lib/turn/stun/const.js +82 -0
  768. package/dist/esm/lib/turn/stun/ip.js +81 -0
  769. package/dist/esm/lib/turn/stun/message.js +174 -0
  770. package/dist/esm/lib/turn/turn/auth.js +6 -0
  771. package/dist/esm/lib/turn/turn/frame.js +61 -0
  772. package/dist/esm/lib/turn/turn/protocol.js +781 -0
  773. package/dist/esm/peer/Endpoints.js +143 -0
  774. package/dist/esm/peer/EngineConfig.js +33 -0
  775. package/dist/esm/peer/EngineConnection.js +22 -0
  776. package/dist/esm/peer/Events.js +81 -0
  777. package/dist/esm/peer/MediaCodecs.js +47 -0
  778. package/dist/esm/peer/MediaTrack.js +305 -0
  779. package/dist/esm/peer/PeerChannel.js +315 -0
  780. package/dist/esm/peer/PeerConnection.js +694 -0
  781. package/dist/esm/peer/PeerThreadChannel.js +266 -0
  782. package/dist/esm/peer/PeerThreadProtocol.js +1 -0
  783. package/dist/esm/peer/PeerThreads.js +264 -0
  784. package/dist/esm/peer/PeerWorker.js +458 -0
  785. package/dist/esm/peer/PeerWorkerCode.js +1 -0
  786. package/dist/esm/peer/RemoteConnection.js +905 -0
  787. package/dist/esm/peer/RtpPacket.js +86 -0
  788. package/dist/esm/peer/RtpTransceiver.js +225 -0
  789. package/dist/esm/peer/SignalingClient.js +249 -0
  790. package/dist/esm/protocol/SignalingProtocol.js +62 -0
  791. package/dist/esm/service/WebRTCServiceEntrypoint.js +352 -0
  792. package/dist/esm/sfu/SFU.js +759 -0
  793. package/dist/esm/sfu/SFUAccess.js +12 -0
  794. package/dist/esm/sfu/SFUClusterLeg.js +102 -0
  795. package/dist/esm/sfu/SFURoom.js +1296 -0
  796. package/dist/esm/sfu/SFUWorker.js +165 -0
  797. package/dist/esm/sfu/SFUWorkerChannel.js +101 -0
  798. package/dist/esm/sfu/SFUWorkerCode.js +1 -0
  799. package/dist/esm/sfu/SFUWorkers.js +547 -0
  800. package/dist/esm/shared/ChunkedChannel.js +178 -0
  801. package/dist/esm/shared/Connections.js +1 -0
  802. package/dist/esm/shared/Emitter.js +76 -0
  803. package/dist/esm/shared/Peer.js +505 -0
  804. package/dist/esm/shared/PeerServiceProxy.js +299 -0
  805. package/dist/esm/shared/Room.js +511 -0
  806. package/dist/esm/shared/SignalingError.js +43 -0
  807. package/dist/esm/shared/SignalingSession.js +343 -0
  808. package/dist/esm/shared/Transports.js +279 -0
  809. package/dist/esm/signaling/MediaServers.js +13 -0
  810. package/dist/esm/signaling/Signaling.js +941 -0
  811. package/dist/esm/signaling/SignalingController.js +225 -0
  812. package/dist/esm/turn/TURNCredentials.js +44 -0
  813. package/dist/esm/turn/TURNIceServers.js +22 -0
  814. package/dist/esm/turn/TURNServer.js +327 -0
  815. package/dist/esm/turn/TURNWorker.js +49 -0
  816. package/dist/esm/turn/TURNWorkerCode.js +1 -0
  817. package/dist/esm/turn/TURNWorkers.js +206 -0
  818. package/dist/esm/whep/WHEP.js +422 -0
  819. package/dist/esm/whep/WHEPController.js +298 -0
  820. package/dist/esm/whip/WHIP.js +466 -0
  821. package/dist/esm/whip/WHIPController.js +296 -0
  822. package/dist/types/client/SignalingConnection.d.ts +81 -0
  823. package/dist/types/cluster/Cluster.d.ts +503 -0
  824. package/dist/types/cluster/ClusterFrames.d.ts +24 -0
  825. package/dist/types/cluster/ClusterTURN.d.ts +63 -0
  826. package/dist/types/cluster/Rendezvous.d.ts +8 -0
  827. package/dist/types/cluster/transports/ClusterTransport.d.ts +34 -0
  828. package/dist/types/cluster/transports/LoadClient.d.ts +6 -0
  829. package/dist/types/cluster/transports/MemoryClusterTransport.d.ts +13 -0
  830. package/dist/types/cluster/transports/NATSClusterTransport.d.ts +23 -0
  831. package/dist/types/cluster/transports/RedisClusterTransport.d.ts +23 -0
  832. package/dist/types/exceptions/ClusterRequestException.d.ts +11 -0
  833. package/dist/types/exceptions/ClusterTimeoutException.d.ts +10 -0
  834. package/dist/types/exceptions/ClusterTransportNotFoundException.d.ts +11 -0
  835. package/dist/types/exceptions/SignalingClientRequiredException.d.ts +12 -0
  836. package/dist/types/exceptions/SignalingConnectionException.d.ts +12 -0
  837. package/dist/types/exceptions/SignalingDeniedException.d.ts +11 -0
  838. package/dist/types/exceptions/SignalingLimitException.d.ts +11 -0
  839. package/dist/types/exceptions/SignalingNotAMemberException.d.ts +11 -0
  840. package/dist/types/exceptions/WHEPDeniedException.d.ts +15 -0
  841. package/dist/types/exceptions/WHEPLimitException.d.ts +15 -0
  842. package/dist/types/exceptions/WHEPMediaTypeException.d.ts +15 -0
  843. package/dist/types/exceptions/WHEPOfferException.d.ts +16 -0
  844. package/dist/types/exceptions/WHEPSessionNotFoundException.d.ts +15 -0
  845. package/dist/types/exceptions/WHIPDeniedException.d.ts +15 -0
  846. package/dist/types/exceptions/WHIPLimitException.d.ts +15 -0
  847. package/dist/types/exceptions/WHIPMediaTypeException.d.ts +15 -0
  848. package/dist/types/exceptions/WHIPOfferException.d.ts +16 -0
  849. package/dist/types/exceptions/WHIPSessionNotFoundException.d.ts +15 -0
  850. package/dist/types/exports/Client.d.ts +11 -0
  851. package/dist/types/exports/WebRTC.d.ts +48 -0
  852. package/dist/types/lib/common/binary.d.ts +51 -0
  853. package/dist/types/lib/common/binaryData.d.ts +116 -0
  854. package/dist/types/lib/common/crc.d.ts +4 -0
  855. package/dist/types/lib/common/deque.d.ts +36 -0
  856. package/dist/types/lib/common/event.d.ts +48 -0
  857. package/dist/types/lib/common/index.d.ts +11 -0
  858. package/dist/types/lib/common/log.d.ts +47 -0
  859. package/dist/types/lib/common/network.d.ts +10 -0
  860. package/dist/types/lib/common/number.d.ts +13 -0
  861. package/dist/types/lib/common/promise.d.ts +21 -0
  862. package/dist/types/lib/common/transport.d.ts +104 -0
  863. package/dist/types/lib/common/type.d.ts +3 -0
  864. package/dist/types/lib/dtls/cipher/const.d.ts +42 -0
  865. package/dist/types/lib/dtls/cipher/create.d.ts +21 -0
  866. package/dist/types/lib/dtls/cipher/ec.d.ts +28 -0
  867. package/dist/types/lib/dtls/cipher/key-exchange.d.ts +43 -0
  868. package/dist/types/lib/dtls/cipher/namedCurve.d.ts +7 -0
  869. package/dist/types/lib/dtls/cipher/prf.d.ts +17 -0
  870. package/dist/types/lib/dtls/cipher/suites/abstract.d.ts +40 -0
  871. package/dist/types/lib/dtls/cipher/suites/aead.d.ts +28 -0
  872. package/dist/types/lib/dtls/cipher/suites/null.d.ts +24 -0
  873. package/dist/types/lib/dtls/cipher/utils.d.ts +18 -0
  874. package/dist/types/lib/dtls/cipher/x509.d.ts +33 -0
  875. package/dist/types/lib/dtls/client.d.ts +7 -0
  876. package/dist/types/lib/dtls/context/cipher.d.ts +42 -0
  877. package/dist/types/lib/dtls/context/dtls.d.ts +38 -0
  878. package/dist/types/lib/dtls/context/srtp.d.ts +5 -0
  879. package/dist/types/lib/dtls/context/transport.d.ts +8 -0
  880. package/dist/types/lib/dtls/flight/client/flight1.d.ts +10 -0
  881. package/dist/types/lib/dtls/flight/client/flight3.d.ts +8 -0
  882. package/dist/types/lib/dtls/flight/client/flight5.d.ts +18 -0
  883. package/dist/types/lib/dtls/flight/flight.d.ts +18 -0
  884. package/dist/types/lib/dtls/flight/server/flight2.d.ts +6 -0
  885. package/dist/types/lib/dtls/flight/server/flight4.d.ts +17 -0
  886. package/dist/types/lib/dtls/flight/server/flight6.d.ts +13 -0
  887. package/dist/types/lib/dtls/handshake/binary.d.ts +16 -0
  888. package/dist/types/lib/dtls/handshake/const.d.ts +13 -0
  889. package/dist/types/lib/dtls/handshake/extensions/ellipticCurves.d.ts +17 -0
  890. package/dist/types/lib/dtls/handshake/extensions/extendedMasterSecret.d.ts +3 -0
  891. package/dist/types/lib/dtls/handshake/extensions/renegotiationIndication.d.ts +18 -0
  892. package/dist/types/lib/dtls/handshake/extensions/signature.d.ts +26 -0
  893. package/dist/types/lib/dtls/handshake/extensions/useSrtp.d.ts +19 -0
  894. package/dist/types/lib/dtls/handshake/message/alert.d.ts +12 -0
  895. package/dist/types/lib/dtls/handshake/message/certificate.d.ts +17 -0
  896. package/dist/types/lib/dtls/handshake/message/changeCipherSpec.d.ts +11 -0
  897. package/dist/types/lib/dtls/handshake/message/client/certificateVerify.d.ts +20 -0
  898. package/dist/types/lib/dtls/handshake/message/client/hello.d.ts +50 -0
  899. package/dist/types/lib/dtls/handshake/message/client/keyExchange.d.ts +17 -0
  900. package/dist/types/lib/dtls/handshake/message/finished.d.ts +13 -0
  901. package/dist/types/lib/dtls/handshake/message/server/certificateRequest.d.ts +31 -0
  902. package/dist/types/lib/dtls/handshake/message/server/hello.d.ts +33 -0
  903. package/dist/types/lib/dtls/handshake/message/server/helloDone.d.ts +12 -0
  904. package/dist/types/lib/dtls/handshake/message/server/helloVerifyRequest.d.ts +32 -0
  905. package/dist/types/lib/dtls/handshake/message/server/keyExchange.d.ts +32 -0
  906. package/dist/types/lib/dtls/handshake/random.d.ts +13 -0
  907. package/dist/types/lib/dtls/helper.d.ts +4 -0
  908. package/dist/types/lib/dtls/imports/common.d.ts +1 -0
  909. package/dist/types/lib/dtls/imports/rtp.d.ts +1 -0
  910. package/dist/types/lib/dtls/index.d.ts +7 -0
  911. package/dist/types/lib/dtls/record/antiReplayWindow.d.ts +27 -0
  912. package/dist/types/lib/dtls/record/builder.d.ts +9 -0
  913. package/dist/types/lib/dtls/record/const.d.ts +33 -0
  914. package/dist/types/lib/dtls/record/message/fragment.d.ts +26 -0
  915. package/dist/types/lib/dtls/record/message/header.d.ts +38 -0
  916. package/dist/types/lib/dtls/record/message/plaintext.d.ts +14 -0
  917. package/dist/types/lib/dtls/record/receive.d.ts +9 -0
  918. package/dist/types/lib/dtls/server.d.ts +6 -0
  919. package/dist/types/lib/dtls/socket.d.ts +52 -0
  920. package/dist/types/lib/dtls/typings/domain.d.ts +20 -0
  921. package/dist/types/lib/dtls/util/binary.d.ts +2 -0
  922. package/dist/types/lib/ice/candidate.d.ts +35 -0
  923. package/dist/types/lib/ice/dns/lookup.d.ts +16 -0
  924. package/dist/types/lib/ice/dns/mdns.d.ts +38 -0
  925. package/dist/types/lib/ice/exceptions.d.ts +24 -0
  926. package/dist/types/lib/ice/helper.d.ts +17 -0
  927. package/dist/types/lib/ice/ice.d.ts +182 -0
  928. package/dist/types/lib/ice/iceBase.d.ts +214 -0
  929. package/dist/types/lib/ice/imports/common.d.ts +1 -0
  930. package/dist/types/lib/ice/index.d.ts +12 -0
  931. package/dist/types/lib/ice/internal/selectAddresses.d.ts +9 -0
  932. package/dist/types/lib/ice/stun/attributes.d.ts +1 -0
  933. package/dist/types/lib/ice/stun/const.d.ts +8 -0
  934. package/dist/types/lib/ice/stun/message.d.ts +1 -0
  935. package/dist/types/lib/ice/stun/protocol.d.ts +30 -0
  936. package/dist/types/lib/ice/stun/tcpFrame.d.ts +5 -0
  937. package/dist/types/lib/ice/stun/tcpProtocol.d.ts +57 -0
  938. package/dist/types/lib/ice/stun/transaction.d.ts +75 -0
  939. package/dist/types/lib/ice/turn/frame.d.ts +1 -0
  940. package/dist/types/lib/ice/turn/protocol.d.ts +170 -0
  941. package/dist/types/lib/ice/types/model.d.ts +56 -0
  942. package/dist/types/lib/ice/utils.d.ts +13 -0
  943. package/dist/types/lib/peer/const.d.ts +36 -0
  944. package/dist/types/lib/peer/dataChannel.d.ts +69 -0
  945. package/dist/types/lib/peer/errors.d.ts +11 -0
  946. package/dist/types/lib/peer/helper.d.ts +20 -0
  947. package/dist/types/lib/peer/imports/common.d.ts +1 -0
  948. package/dist/types/lib/peer/imports/dtls.d.ts +1 -0
  949. package/dist/types/lib/peer/imports/ice.d.ts +1 -0
  950. package/dist/types/lib/peer/imports/rtp.d.ts +1 -0
  951. package/dist/types/lib/peer/index.d.ts +14 -0
  952. package/dist/types/lib/peer/media/codec.d.ts +15 -0
  953. package/dist/types/lib/peer/media/codecCompatibility.d.ts +23 -0
  954. package/dist/types/lib/peer/media/extension/rtcpFeedback.d.ts +6 -0
  955. package/dist/types/lib/peer/media/extension/rtpExtension.d.ts +9 -0
  956. package/dist/types/lib/peer/media/index.d.ts +12 -0
  957. package/dist/types/lib/peer/media/parameters.d.ts +65 -0
  958. package/dist/types/lib/peer/media/receiver/nack.d.ts +23 -0
  959. package/dist/types/lib/peer/media/receiver/receiverTwcc.d.ts +47 -0
  960. package/dist/types/lib/peer/media/receiver/statistics.d.ts +22 -0
  961. package/dist/types/lib/peer/media/router.d.ts +25 -0
  962. package/dist/types/lib/peer/media/rtpReceiver.d.ts +90 -0
  963. package/dist/types/lib/peer/media/rtpSender.d.ts +209 -0
  964. package/dist/types/lib/peer/media/rtpTransceiver.d.ts +117 -0
  965. package/dist/types/lib/peer/media/sender/cumulativeResult.d.ts +19 -0
  966. package/dist/types/lib/peer/media/sender/senderBWE.d.ts +32 -0
  967. package/dist/types/lib/peer/media/stats.d.ts +293 -0
  968. package/dist/types/lib/peer/media/track.d.ts +67 -0
  969. package/dist/types/lib/peer/peerConnection.d.ts +458 -0
  970. package/dist/types/lib/peer/sctpManager.d.ts +28 -0
  971. package/dist/types/lib/peer/sdp.d.ts +97 -0
  972. package/dist/types/lib/peer/sdpManager.d.ts +116 -0
  973. package/dist/types/lib/peer/secureTransportManager.d.ts +96 -0
  974. package/dist/types/lib/peer/transceiverManager.d.ts +151 -0
  975. package/dist/types/lib/peer/transport/dtls.d.ts +95 -0
  976. package/dist/types/lib/peer/transport/ice.d.ts +143 -0
  977. package/dist/types/lib/peer/transport/sctp.d.ts +56 -0
  978. package/dist/types/lib/peer/types/domain.d.ts +5 -0
  979. package/dist/types/lib/peer/types/util.d.ts +2 -0
  980. package/dist/types/lib/peer/utils.d.ts +73 -0
  981. package/dist/types/lib/rtp/codec/av1.d.ts +56 -0
  982. package/dist/types/lib/rtp/codec/base.d.ts +8 -0
  983. package/dist/types/lib/rtp/codec/h264.d.ts +32 -0
  984. package/dist/types/lib/rtp/codec/index.d.ts +16 -0
  985. package/dist/types/lib/rtp/codec/leb128.d.ts +5 -0
  986. package/dist/types/lib/rtp/codec/opus.d.ts +9 -0
  987. package/dist/types/lib/rtp/codec/vp8.d.ts +27 -0
  988. package/dist/types/lib/rtp/codec/vp9.d.ts +46 -0
  989. package/dist/types/lib/rtp/const.d.ts +1 -0
  990. package/dist/types/lib/rtp/helper.d.ts +8 -0
  991. package/dist/types/lib/rtp/imports/common.d.ts +1 -0
  992. package/dist/types/lib/rtp/index.d.ts +25 -0
  993. package/dist/types/lib/rtp/rtcp/header.d.ts +13 -0
  994. package/dist/types/lib/rtp/rtcp/psfb/fullIntraRequest.d.ts +16 -0
  995. package/dist/types/lib/rtp/rtcp/psfb/index.d.ts +14 -0
  996. package/dist/types/lib/rtp/rtcp/psfb/pictureLossIndication.d.ts +10 -0
  997. package/dist/types/lib/rtp/rtcp/psfb/remb.d.ts +16 -0
  998. package/dist/types/lib/rtp/rtcp/rr.d.ts +32 -0
  999. package/dist/types/lib/rtp/rtcp/rtcp.d.ts +10 -0
  1000. package/dist/types/lib/rtp/rtcp/rtpfb/const.d.ts +1 -0
  1001. package/dist/types/lib/rtp/rtcp/rtpfb/index.d.ts +14 -0
  1002. package/dist/types/lib/rtp/rtcp/rtpfb/nack.d.ts +17 -0
  1003. package/dist/types/lib/rtp/rtcp/rtpfb/twcc.d.ts +71 -0
  1004. package/dist/types/lib/rtp/rtcp/sdes.d.ts +26 -0
  1005. package/dist/types/lib/rtp/rtcp/sr.d.ts +41 -0
  1006. package/dist/types/lib/rtp/rtp/headerExtension.d.ts +72 -0
  1007. package/dist/types/lib/rtp/rtp/red/encoder.d.ts +13 -0
  1008. package/dist/types/lib/rtp/rtp/red/handler.d.ts +6 -0
  1009. package/dist/types/lib/rtp/rtp/red/packet.d.ts +26 -0
  1010. package/dist/types/lib/rtp/rtp/rtp.d.ts +44 -0
  1011. package/dist/types/lib/rtp/rtp/rtx.d.ts +3 -0
  1012. package/dist/types/lib/rtp/srtp/cipher/ctr.d.ts +16 -0
  1013. package/dist/types/lib/rtp/srtp/cipher/gcm.d.ts +17 -0
  1014. package/dist/types/lib/rtp/srtp/cipher/index.d.ts +13 -0
  1015. package/dist/types/lib/rtp/srtp/const.d.ts +6 -0
  1016. package/dist/types/lib/rtp/srtp/context/context.d.ts +45 -0
  1017. package/dist/types/lib/rtp/srtp/context/srtcp.d.ts +8 -0
  1018. package/dist/types/lib/rtp/srtp/context/srtp.d.ts +9 -0
  1019. package/dist/types/lib/rtp/srtp/error.d.ts +3 -0
  1020. package/dist/types/lib/rtp/srtp/packet.d.ts +5 -0
  1021. package/dist/types/lib/rtp/srtp/session.d.ts +19 -0
  1022. package/dist/types/lib/rtp/srtp/srtcp.d.ts +8 -0
  1023. package/dist/types/lib/rtp/srtp/srtp.d.ts +9 -0
  1024. package/dist/types/lib/rtp/transport.d.ts +15 -0
  1025. package/dist/types/lib/rtp/util.d.ts +11 -0
  1026. package/dist/types/lib/sctp/chunk.d.ts +164 -0
  1027. package/dist/types/lib/sctp/const.d.ts +17 -0
  1028. package/dist/types/lib/sctp/helper.d.ts +5 -0
  1029. package/dist/types/lib/sctp/imports/common.d.ts +1 -0
  1030. package/dist/types/lib/sctp/index.d.ts +6 -0
  1031. package/dist/types/lib/sctp/param.d.ts +40 -0
  1032. package/dist/types/lib/sctp/sctp.d.ts +210 -0
  1033. package/dist/types/lib/sctp/transport.d.ts +15 -0
  1034. package/dist/types/lib/turn/index.d.ts +9 -0
  1035. package/dist/types/lib/turn/node/server.d.ts +21 -0
  1036. package/dist/types/lib/turn/node/turnServer.d.ts +91 -0
  1037. package/dist/types/lib/turn/protocol.d.ts +47 -0
  1038. package/dist/types/lib/turn/stun/attributes.d.ts +37 -0
  1039. package/dist/types/lib/turn/stun/const.d.ts +28 -0
  1040. package/dist/types/lib/turn/stun/ip.d.ts +12 -0
  1041. package/dist/types/lib/turn/stun/message.d.ts +37 -0
  1042. package/dist/types/lib/turn/turn/auth.d.ts +1 -0
  1043. package/dist/types/lib/turn/turn/frame.d.ts +13 -0
  1044. package/dist/types/lib/turn/turn/protocol.d.ts +147 -0
  1045. package/dist/types/peer/Endpoints.d.ts +75 -0
  1046. package/dist/types/peer/EngineConfig.d.ts +20 -0
  1047. package/dist/types/peer/EngineConnection.d.ts +22 -0
  1048. package/dist/types/peer/Events.d.ts +55 -0
  1049. package/dist/types/peer/MediaCodecs.d.ts +27 -0
  1050. package/dist/types/peer/MediaTrack.d.ts +212 -0
  1051. package/dist/types/peer/PeerChannel.d.ts +248 -0
  1052. package/dist/types/peer/PeerConnection.d.ts +603 -0
  1053. package/dist/types/peer/PeerThreadChannel.d.ts +112 -0
  1054. package/dist/types/peer/PeerThreadProtocol.d.ts +325 -0
  1055. package/dist/types/peer/PeerThreads.d.ts +114 -0
  1056. package/dist/types/peer/PeerWorker.d.ts +6 -0
  1057. package/dist/types/peer/PeerWorkerCode.d.ts +5 -0
  1058. package/dist/types/peer/RemoteConnection.d.ts +314 -0
  1059. package/dist/types/peer/RtpPacket.d.ts +112 -0
  1060. package/dist/types/peer/RtpTransceiver.d.ts +167 -0
  1061. package/dist/types/peer/SignalingClient.d.ts +236 -0
  1062. package/dist/types/protocol/SignalingProtocol.d.ts +266 -0
  1063. package/dist/types/service/WebRTCServiceEntrypoint.d.ts +158 -0
  1064. package/dist/types/sfu/SFU.d.ts +356 -0
  1065. package/dist/types/sfu/SFUAccess.d.ts +48 -0
  1066. package/dist/types/sfu/SFUClusterLeg.d.ts +101 -0
  1067. package/dist/types/sfu/SFURoom.d.ts +148 -0
  1068. package/dist/types/sfu/SFUWorker.d.ts +13 -0
  1069. package/dist/types/sfu/SFUWorkerChannel.d.ts +204 -0
  1070. package/dist/types/sfu/SFUWorkerCode.d.ts +5 -0
  1071. package/dist/types/sfu/SFUWorkers.d.ts +247 -0
  1072. package/dist/types/shared/ChunkedChannel.d.ts +122 -0
  1073. package/dist/types/shared/Connections.d.ts +231 -0
  1074. package/dist/types/shared/Emitter.d.ts +50 -0
  1075. package/dist/types/shared/Peer.d.ts +182 -0
  1076. package/dist/types/shared/PeerServiceProxy.d.ts +173 -0
  1077. package/dist/types/shared/Room.d.ts +143 -0
  1078. package/dist/types/shared/SignalingError.d.ts +40 -0
  1079. package/dist/types/shared/SignalingSession.d.ts +97 -0
  1080. package/dist/types/shared/Transports.d.ts +139 -0
  1081. package/dist/types/signaling/MediaServers.d.ts +40 -0
  1082. package/dist/types/signaling/Signaling.d.ts +573 -0
  1083. package/dist/types/signaling/SignalingController.d.ts +128 -0
  1084. package/dist/types/turn/TURNCredentials.d.ts +49 -0
  1085. package/dist/types/turn/TURNIceServers.d.ts +11 -0
  1086. package/dist/types/turn/TURNServer.d.ts +309 -0
  1087. package/dist/types/turn/TURNWorker.d.ts +42 -0
  1088. package/dist/types/turn/TURNWorkerCode.d.ts +5 -0
  1089. package/dist/types/turn/TURNWorkers.d.ts +52 -0
  1090. package/dist/types/whep/WHEP.d.ts +386 -0
  1091. package/dist/types/whep/WHEPController.d.ts +134 -0
  1092. package/dist/types/whip/WHIP.d.ts +426 -0
  1093. package/dist/types/whip/WHIPController.d.ts +132 -0
  1094. package/package.json +115 -4
@@ -0,0 +1,1584 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.Connection = void 0;
37
+ const node_crypto_1 = require("node:crypto");
38
+ const node_net_1 = require("node:net");
39
+ const timers = __importStar(require("node:timers/promises"));
40
+ const common_js_1 = require("./imports/common.js");
41
+ const candidate_js_1 = require("./candidate.js");
42
+ const lookup_js_1 = require("./dns/lookup.js");
43
+ const helper_js_1 = require("./helper.js");
44
+ const iceBase_js_1 = require("./iceBase.js");
45
+ const const_js_1 = require("./stun/const.js");
46
+ const message_js_1 = require("./stun/message.js");
47
+ const protocol_js_1 = require("./stun/protocol.js");
48
+ const tcpProtocol_js_1 = require("./stun/tcpProtocol.js");
49
+ const protocol_js_2 = require("./turn/protocol.js");
50
+ const utils_js_1 = require("./utils.js");
51
+ const log = (0, common_js_1.debug)('webrtc/ice/ice:log');
52
+ /**How long a transport to a TURN server is given before the next one is tried as well (ms) */
53
+ const RELAY_ATTEMPT_DELAY = 1000;
54
+ /**
55
+ * How long the checks wait without any pair, in milliseconds: the candidates of the other side may be names this side
56
+ * cannot resolve (mDNS), its checks still come once it has this side's description, and give its address as a peer
57
+ * reflexive candidate
58
+ */
59
+ const NO_PAIR_TIMEOUT = 30000;
60
+ /**The local preference of a relay candidate by the transport to its server: UDP first, then TCP, then TLS */
61
+ const RELAY_PREFERENCE = { udp: 65535, tcp: 49151, tls: 32767 };
62
+ /**
63
+ * The TURN servers of the options: the entries of a host are the transports of one server (an entry without a
64
+ * transport is UDP, then TCP when UDP fails).
65
+ */
66
+ function relayServersOf(options) {
67
+ const entries = [];
68
+ if (options.turnServer && options.turnUsername && options.turnPassword) {
69
+ entries.push({
70
+ address: options.turnServer,
71
+ username: options.turnUsername,
72
+ password: options.turnPassword,
73
+ transport: options.turnTransport
74
+ });
75
+ }
76
+ entries.push(...(options.turnServers ?? []));
77
+ const servers = new Map();
78
+ for (const entry of entries) {
79
+ const address = (0, iceBase_js_1.validateAddress)(entry.address);
80
+ if (!address || !entry.username || !entry.password)
81
+ continue;
82
+ const key = address[0].toLowerCase();
83
+ let server = servers.get(key);
84
+ if (!server) {
85
+ server = { key, attempts: [] };
86
+ servers.set(key, server);
87
+ }
88
+ const transports = entry.transport === undefined || entry.transport === 'udp' ? ['udp', 'tcp'] : [entry.transport];
89
+ for (const transport of transports) {
90
+ const known = server.attempts.some((attempt) => attempt.transport === transport &&
91
+ attempt.address[1] === address[1] &&
92
+ attempt.username === entry.username &&
93
+ attempt.password === entry.password);
94
+ if (!known)
95
+ server.attempts.push({ address, transport, username: entry.username, password: entry.password });
96
+ }
97
+ }
98
+ return [...servers.values()];
99
+ }
100
+ /** The STUN servers of the options, each once. */
101
+ function stunServersOf(options) {
102
+ const servers = [];
103
+ for (const server of [options.stunServer, ...(options.stunServers ?? [])]) {
104
+ const address = (0, iceBase_js_1.validateAddress)(server);
105
+ if (address && !servers.some(([host, port]) => host === address[0] && port === address[1]))
106
+ servers.push(address);
107
+ }
108
+ return servers;
109
+ }
110
+ class Connection {
111
+ constructor(_iceControlling, options) {
112
+ this._iceControlling = _iceControlling;
113
+ this.localUsername = (0, helper_js_1.randomString)(4);
114
+ this.localPassword = (0, helper_js_1.randomString)(22);
115
+ this.remoteIsLite = false;
116
+ this.remotePassword = '';
117
+ this.remoteUsername = '';
118
+ this.checkList = [];
119
+ this.localCandidates = [];
120
+ this.stunServers = [];
121
+ this.relayServers = [];
122
+ /**the relays by the host of their TURN server */
123
+ this.relays = new Map();
124
+ this.remoteCandidatesEnd = false;
125
+ this.localCandidatesEnd = false;
126
+ this.generation = -1;
127
+ this.userHistory = {};
128
+ this.tieBreaker = (0, node_crypto_1.randomBytes)(8).readBigUInt64BE(0);
129
+ this.state = 'new';
130
+ this._remoteCandidates = [];
131
+ this.nominating = false;
132
+ this.checkListDone = false;
133
+ this.checkListState = new helper_js_1.PQueue();
134
+ this.earlyChecks = [];
135
+ this.earlyChecksDone = false;
136
+ this.localCandidatesStart = false;
137
+ this.protocols = [];
138
+ /** RFC 7675 consent-to-send: application data may use the selected pair. */
139
+ this.consentFresh = false;
140
+ /** Invalidates in-flight consent callbacks on restart / close / replace / expire. */
141
+ this.consentSessionId = 0;
142
+ //The remote candidates whose mDNS names are being resolved: more pairs may come
143
+ this.resolvingRemoteCandidates = 0;
144
+ //Until when the checks wait for a first pair
145
+ this.noPairDeadline = 0;
146
+ this.onData = new common_js_1.Event();
147
+ this.stateChanged = new common_js_1.Event();
148
+ this.onIceCandidate = new common_js_1.Event();
149
+ // RFC 7675 consent freshness
150
+ this.queryConsent = () => {
151
+ if (this.iceLite) {
152
+ return;
153
+ }
154
+ // Invalidate any previous consent session before starting a new one.
155
+ this.stopConsentLifecycle();
156
+ const sessionId = this.consentSessionId;
157
+ this.consentFresh = true;
158
+ const handle = (0, helper_js_1.cancelable)(async (_, __, onCancel) => {
159
+ let canceled = false;
160
+ const cancelEvent = new AbortController();
161
+ const clearConsentExpiry = () => {
162
+ if (this.consentExpiryTimer === undefined) {
163
+ return;
164
+ }
165
+ clearTimeout(this.consentExpiryTimer);
166
+ this.consentExpiryTimer = undefined;
167
+ };
168
+ const refreshConsentExpiry = () => {
169
+ // Only the active session may refresh the shared expiry timer.
170
+ if (canceled || sessionId !== this.consentSessionId) {
171
+ return;
172
+ }
173
+ clearConsentExpiry();
174
+ this.consentExpiryTimer = setTimeout(() => {
175
+ this.consentExpiryTimer = undefined;
176
+ if (canceled || sessionId !== this.consentSessionId) {
177
+ return;
178
+ }
179
+ if (this.state === 'closed' || this.state === 'failed') {
180
+ return;
181
+ }
182
+ log('Consent to send expired');
183
+ // Expire independently of request cadence / failure count (RFC 7675).
184
+ this.consentFresh = false;
185
+ this.consentSessionId++;
186
+ this.consentRequestAbort?.abort();
187
+ this.consentRequestAbort = undefined;
188
+ if (this.queryConsentHandle === handle) {
189
+ this.queryConsentHandle = undefined;
190
+ }
191
+ canceled = true;
192
+ cancelEvent.abort();
193
+ // Transport stays available for ICE restart; explicit close() uses "closed".
194
+ this.setState('failed');
195
+ }, iceBase_js_1.CONSENT_TIMEOUT * 1000);
196
+ };
197
+ onCancel.once(() => {
198
+ canceled = true;
199
+ // Avoid clearing a replacement session's timer/handle.
200
+ if (sessionId === this.consentSessionId) {
201
+ clearConsentExpiry();
202
+ this.consentRequestAbort?.abort();
203
+ this.consentRequestAbort = undefined;
204
+ }
205
+ cancelEvent.abort();
206
+ if (this.queryConsentHandle === handle) {
207
+ this.queryConsentHandle = undefined;
208
+ }
209
+ });
210
+ // Initial ICE check success is the first valid consent response.
211
+ refreshConsentExpiry();
212
+ const randomizedConsentInterval = () => iceBase_js_1.CONSENT_INTERVAL * (0.8 + 0.4 * Math.random()) * 1000;
213
+ // Cadence is measured between request *starts*, not response completions.
214
+ let nextConsentAt = Date.now() + randomizedConsentInterval();
215
+ const isTerminalState = () => this.state === 'closed' || this.state === 'failed';
216
+ try {
217
+ while (!isTerminalState() &&
218
+ !canceled &&
219
+ sessionId === this.consentSessionId) {
220
+ await this.abortableDelay(Math.max(0, nextConsentAt - Date.now()), cancelEvent.signal);
221
+ if (canceled ||
222
+ isTerminalState() ||
223
+ sessionId !== this.consentSessionId) {
224
+ break;
225
+ }
226
+ // Fix next start time before awaiting any response (independent timers).
227
+ nextConsentAt = Date.now() + randomizedConsentInterval();
228
+ const nominated = this.nominated;
229
+ if (!nominated) {
230
+ break;
231
+ }
232
+ const pairId = nominated.id;
233
+ const generation = this.generation;
234
+ const remotePassword = this.remotePassword;
235
+ const { localUsername, remoteUsername, iceControlling } = this;
236
+ const request = this.buildRequest({
237
+ nominate: this.shouldNominateConsentRequest(nominated),
238
+ localUsername,
239
+ remoteUsername,
240
+ iceControlling,
241
+ localCandidate: nominated.localCandidate
242
+ });
243
+ this.consentRequestAbort?.abort();
244
+ const requestAbort = new AbortController();
245
+ this.consentRequestAbort = requestAbort;
246
+ nominated.consentRequestsSent++;
247
+ nominated.requestsSent++;
248
+ // RTT-aware wait (floor 500ms); independent of retransmissions: 0.
249
+ const responseTimeout = (0, iceBase_js_1.consentResponseTimeoutMs)(nominated.rtt);
250
+ const requestStartedAt = performance.now();
251
+ // Do not await here: response wait must not stretch the 4–6s cadence.
252
+ nominated.protocol
253
+ .request(request, nominated.remoteAddr, Buffer.from(remotePassword, 'utf8'), {
254
+ retransmissions: 0,
255
+ responseTimeout,
256
+ signal: requestAbort.signal,
257
+ onRequestSent: (attempt) => {
258
+ if (attempt > 0) {
259
+ nominated.retransmissionsSent++;
260
+ }
261
+ }
262
+ })
263
+ .then(() => {
264
+ // Accept only responses for the current pair / generation / session.
265
+ // Address / MESSAGE-INTEGRITY / response class are enforced in Transaction + protocol.
266
+ if (sessionId !== this.consentSessionId || canceled) {
267
+ return;
268
+ }
269
+ const state = this.state;
270
+ if (state === 'closed' || state === 'failed') {
271
+ return;
272
+ }
273
+ if (this.nominated?.id !== pairId) {
274
+ return;
275
+ }
276
+ if (this.generation !== generation) {
277
+ return;
278
+ }
279
+ if (this.remotePassword !== remotePassword) {
280
+ return;
281
+ }
282
+ const rtt = (performance.now() - requestStartedAt) / 1000; // seconds
283
+ nominated.rtt = rtt;
284
+ nominated.totalRoundTripTime += rtt;
285
+ nominated.roundTripTimeMeasurements++;
286
+ nominated.responsesReceived++;
287
+ this.consentFresh = true;
288
+ refreshConsentExpiry();
289
+ if (state === 'disconnected') {
290
+ this.setState('connected');
291
+ }
292
+ })
293
+ .catch((error) => {
294
+ // Individual request loss is expected; keep monitoring (RFC 7675).
295
+ if (sessionId === this.consentSessionId &&
296
+ this.nominated?.id === pairId) {
297
+ log('no stun response', error);
298
+ }
299
+ });
300
+ }
301
+ }
302
+ catch (error) {
303
+ // Abort during delay is normal on cancel / expire.
304
+ }
305
+ finally {
306
+ if (sessionId === this.consentSessionId) {
307
+ clearConsentExpiry();
308
+ }
309
+ }
310
+ });
311
+ this.queryConsentHandle = handle;
312
+ };
313
+ this.send = async (data) => {
314
+ // RFC 7675: after consent expiry, do not send application data on the 5-tuple.
315
+ if (!this.canSendApplicationData()) {
316
+ return;
317
+ }
318
+ const activePair = this.nominated;
319
+ await activePair.protocol.sendData(data, activePair.remoteAddr);
320
+ // Update statistics
321
+ activePair.packetsSent++;
322
+ activePair.bytesSent += data.length;
323
+ };
324
+ // 3. Terminology : Check
325
+ this.checkStart = (pair) => (0, helper_js_1.cancelable)(async (r) => {
326
+ // """
327
+ // Starts a check.
328
+ // """
329
+ log('check start', pair.toJSON());
330
+ pair.updateState(iceBase_js_1.CandidatePairState.IN_PROGRESS);
331
+ const result = {};
332
+ const { remotePassword, remoteUsername, generation } = this;
333
+ const localUsername = pair.localCandidate.ufrag ?? this.localUsername;
334
+ //Regular nomination (RFC 8445): the checks do not nominate, the controlling side nominates one pair afterwards.
335
+ //With USE-CANDIDATE on every check, each side selected the first pair succeeding on its side, and the two
336
+ //could select different pairs
337
+ const nominate = false;
338
+ const request = this.buildRequest({
339
+ nominate,
340
+ localUsername,
341
+ remoteUsername,
342
+ iceControlling: this.iceControlling,
343
+ localCandidate: pair.localCandidate
344
+ });
345
+ // Record start time for RTT calculation
346
+ const startTime = performance.now();
347
+ try {
348
+ pair.requestsSent++;
349
+ const [response, addr] = await pair.protocol.request(request, pair.remoteAddr, Buffer.from(remotePassword, 'utf8'), this.checkRequestOptions(pair));
350
+ pair.responsesReceived++;
351
+ // Calculate RTT
352
+ const endTime = performance.now();
353
+ const rtt = (endTime - startTime) / 1000; // Convert to seconds
354
+ // Update RTT statistics
355
+ pair.rtt = rtt;
356
+ pair.totalRoundTripTime += rtt;
357
+ pair.roundTripTimeMeasurements++;
358
+ log('response received', request.toJSON(), response.toJSON(), addr, {
359
+ localUsername,
360
+ remoteUsername,
361
+ remotePassword,
362
+ generation,
363
+ rtt
364
+ });
365
+ result.response = response;
366
+ result.addr = addr;
367
+ }
368
+ catch (error) {
369
+ const exc = error;
370
+ // 7.1.3.1. Failure Cases
371
+ log('failure case', request.toJSON(), exc.response ? JSON.stringify(exc.response.toJSON(), null, 2) : error, {
372
+ localUsername,
373
+ remoteUsername,
374
+ remotePassword,
375
+ generation
376
+ }, pair.remoteAddr);
377
+ if (exc.response?.getAttributeValue('ERROR-CODE')[0] === 487) {
378
+ if (request.attributesKeys.includes('ICE-CONTROLLED')) {
379
+ this.switchRole(true);
380
+ }
381
+ else if (request.attributesKeys.includes('ICE-CONTROLLING')) {
382
+ this.switchRole(false);
383
+ }
384
+ await this.checkStart(pair).awaitable;
385
+ r();
386
+ return;
387
+ }
388
+ if (exc.response?.getAttributeValue('ERROR-CODE')[0] === 401) {
389
+ log('retry 401', pair.toJSON());
390
+ await this.checkStart(pair).awaitable;
391
+ r();
392
+ return;
393
+ }
394
+ else {
395
+ // timeout
396
+ log('checkStart CandidatePairState.FAILED', pair.toJSON());
397
+ pair.updateState(iceBase_js_1.CandidatePairState.FAILED);
398
+ this.checkComplete(pair);
399
+ r();
400
+ return;
401
+ }
402
+ }
403
+ // # check remote address matches
404
+ if (result.addr[0] !== pair.remoteAddr[0] ||
405
+ result.addr[1] !== pair.remoteAddr[1]) {
406
+ pair.updateState(iceBase_js_1.CandidatePairState.FAILED);
407
+ this.checkComplete(pair);
408
+ r();
409
+ return;
410
+ }
411
+ // # success
412
+ if (nominate || pair.remoteNominated) {
413
+ // # nominated by agressive nomination or the remote party
414
+ pair.nominated = true;
415
+ }
416
+ else if (this.usesTcpRegularNomination(pair)) {
417
+ // # nominated later by nominateTcpPairIfReady (from checkComplete)
418
+ }
419
+ else if (this.iceControlling && !this.nominating && !this.nominated) {
420
+ // # perform regular nomination: one pair, the first succeeding
421
+ this.nominating = true;
422
+ const request = this.buildRequest({
423
+ nominate: true,
424
+ localUsername,
425
+ remoteUsername,
426
+ iceControlling: this.iceControlling,
427
+ localCandidate: pair.localCandidate
428
+ });
429
+ try {
430
+ pair.requestsSent++;
431
+ await pair.protocol.request(request, pair.remoteAddr, Buffer.from(this.remotePassword, 'utf8'), this.checkRequestOptions(pair));
432
+ pair.responsesReceived++;
433
+ }
434
+ catch (error) {
435
+ this.nominating = false;
436
+ pair.updateState(iceBase_js_1.CandidatePairState.FAILED);
437
+ this.checkComplete(pair);
438
+ return;
439
+ }
440
+ pair.nominated = true;
441
+ }
442
+ pair.updateState(iceBase_js_1.CandidatePairState.SUCCEEDED);
443
+ this.checkComplete(pair);
444
+ r();
445
+ });
446
+ this.pairRemoteCandidate = (remoteCandidate) => {
447
+ for (const protocol of this.protocols) {
448
+ this.tryPair(protocol, remoteCandidate);
449
+ }
450
+ };
451
+ this.options = {
452
+ ...iceBase_js_1.defaultOptions,
453
+ ...options
454
+ };
455
+ if (this.iceLite) {
456
+ this._iceControlling = false;
457
+ }
458
+ this.applyStunTurnServersFromOptions();
459
+ this.restart().catch((error) => log('restart failed', error));
460
+ log('new Connection', this.options);
461
+ }
462
+ /**
463
+ * Replace STUN/TURN servers after construction.
464
+ * Server-related fields are replaced (not partial-merged) so that removing
465
+ * TURN clears residual credentials. W3C setConfiguration replaces the ICE
466
+ * server list rather than merging additively.
467
+ *
468
+ * Used when servers are learned after the gatherer was built (e.g. WHIP
469
+ * Link headers) and must take effect before the next gather pass.
470
+ */
471
+ setIceServers(options) {
472
+ // Explicitly assign server fields even when undefined so a STUN-only
473
+ // update cannot leave a previous TURN host/credential in options.
474
+ this.options = {
475
+ ...this.options,
476
+ stunServer: options.stunServer,
477
+ turnServer: options.turnServer,
478
+ turnUsername: options.turnUsername,
479
+ turnPassword: options.turnPassword,
480
+ turnTransport: options.turnTransport,
481
+ stunServers: options.stunServers,
482
+ turnServers: options.turnServers
483
+ };
484
+ if (options.forceTurn !== undefined) {
485
+ this.options.forceTurn = options.forceTurn;
486
+ }
487
+ if (options.useTcp !== undefined) {
488
+ this.options.useTcp = options.useTcp;
489
+ }
490
+ if (options.turnTlsOptions !== undefined) {
491
+ this.options.turnTlsOptions = options.turnTlsOptions;
492
+ }
493
+ if (options.turnUdpFamily !== undefined) {
494
+ this.options.turnUdpFamily = options.turnUdpFamily;
495
+ }
496
+ this.applyStunTurnServersFromOptions();
497
+ log('Connection ice servers updated', this.options);
498
+ }
499
+ /**
500
+ * Derive Connection.stunServer / turnServer from this.options.
501
+ * Shared by the constructor and setIceServers so both paths validate and
502
+ * default identically.
503
+ */
504
+ applyStunTurnServersFromOptions() {
505
+ //No STUN server unless one is configured, as RTCPeerConnection (no request to a public server by default)
506
+ this.stunServers = stunServersOf(this.options);
507
+ this.relayServers = relayServersOf(this.options);
508
+ this.stunServer = this.stunServers[0];
509
+ this.turnServer = (0, iceBase_js_1.validateAddress)(this.options.turnServer) ?? this.relayServers[0]?.attempts[0]?.address;
510
+ }
511
+ get iceControlling() {
512
+ return this._iceControlling;
513
+ }
514
+ set iceControlling(value) {
515
+ if (this.iceLite) {
516
+ value = false;
517
+ }
518
+ // While a pair is selected, keep the negotiated role. ICE restart clears
519
+ // `nominated`, so offer/answer role and RFC 8445 role-conflict repair can
520
+ // reassign controlling/controlled for the new generation.
521
+ if (this.nominated) {
522
+ return;
523
+ }
524
+ this.applyIceControlling(value);
525
+ }
526
+ get iceLite() {
527
+ return this.options.iceLite;
528
+ }
529
+ async restart() {
530
+ this.generation++;
531
+ this.localUsername = (0, helper_js_1.randomString)(4);
532
+ this.localPassword = (0, helper_js_1.randomString)(22);
533
+ if (this.options.localPasswordPrefix) {
534
+ this.localPassword =
535
+ this.options.localPasswordPrefix +
536
+ this.localPassword.slice(this.options.localPasswordPrefix.length);
537
+ }
538
+ this.userHistory[this.localUsername] = this.localPassword;
539
+ this.remoteUsername = '';
540
+ this.remotePassword = '';
541
+ this.localCandidates = [];
542
+ this._remoteCandidates = [];
543
+ this.remoteCandidatesEnd = false;
544
+ this.localCandidatesEnd = false;
545
+ this.state = 'new';
546
+ this.lookup?.close?.();
547
+ this.lookup = undefined;
548
+ this.nominated = undefined;
549
+ this.nominating = false;
550
+ this.checkList = [];
551
+ this.checkListDone = false;
552
+ this.checkListState = new helper_js_1.PQueue();
553
+ this.earlyChecks = [];
554
+ this.earlyChecksDone = false;
555
+ this.localCandidatesStart = false;
556
+ // protocolsはincomingのearlyCheckに使うかもしれないので残す
557
+ for (const protocol of this.protocols) {
558
+ //The checks of the new session go to any address
559
+ protocol.disconnect?.();
560
+ if (protocol.localCandidate) {
561
+ protocol.localCandidate.refreshId();
562
+ protocol.localCandidate.generation = this.generation;
563
+ protocol.localCandidate.ufrag = this.localUsername;
564
+ }
565
+ }
566
+ // Tear down consent timers/transactions; new credentials require a new session.
567
+ this.stopConsentLifecycle();
568
+ }
569
+ resetNominatedPair() {
570
+ log('resetNominatedPair');
571
+ for (const protocol of this.protocols)
572
+ protocol.disconnect?.();
573
+ this.nominated = undefined;
574
+ this.nominating = false;
575
+ // Drop old pair's consent timers/transactions; restarted when a new pair is nominated.
576
+ this.stopConsentLifecycle();
577
+ }
578
+ setRemoteParams({ iceLite, usernameFragment, password }) {
579
+ log('setRemoteParams', { iceLite, usernameFragment, password });
580
+ this.remoteIsLite = iceLite;
581
+ this.remoteUsername = usernameFragment;
582
+ this.remotePassword = password;
583
+ }
584
+ // 4.1.1 Gathering Candidates
585
+ async gatherCandidates() {
586
+ if (!this.localCandidatesStart) {
587
+ this.localCandidatesStart = true;
588
+ // ICE restart keeps transport protocols; re-advertise their host candidates
589
+ // with the new generation / ufrag before gathering additional addresses.
590
+ // A relay is advertised again once its allocation is known to be still there.
591
+ const relays = [...this.relays.values()];
592
+ for (const protocol of this.protocols) {
593
+ if (protocol.localCandidate && !relays.includes(protocol)) {
594
+ protocol.localCandidate.generation = this.generation;
595
+ protocol.localCandidate.ufrag = this.localUsername;
596
+ this.appendLocalCandidate(protocol.localCandidate);
597
+ }
598
+ }
599
+ let address = (0, utils_js_1.getHostAddresses)(this.options.useIpv4, this.options.useIpv6, {
600
+ useLinkLocalAddress: this.options.useLinkLocalAddress
601
+ });
602
+ const { interfaceAddresses } = this.options;
603
+ if (interfaceAddresses) {
604
+ const filteredAddresses = address.filter((check) => Object.values(interfaceAddresses).includes(check));
605
+ if (filteredAddresses.length) {
606
+ address = filteredAddresses;
607
+ }
608
+ }
609
+ if (this.options.additionalHostAddresses) {
610
+ address = Array.from(new Set([...this.options.additionalHostAddresses, ...address]));
611
+ }
612
+ const candidatePromises = this.getCandidatePromises(address, this.options.stunGatherTimeout);
613
+ await Promise.allSettled(candidatePromises);
614
+ this.localCandidatesEnd = true;
615
+ }
616
+ this.setState('completed');
617
+ }
618
+ appendLocalCandidate(candidate) {
619
+ this.localCandidates.push(candidate);
620
+ this.onIceCandidate.execute(candidate);
621
+ }
622
+ /**
623
+ * Whether a candidate with the same address and base was gathered already
624
+ * (RFC 8445, section 5.1.3): a server reflexive address that is a host
625
+ * address, or that another STUN server gave too.
626
+ */
627
+ isRedundant(candidate) {
628
+ const baseOf = (other) => other.type === 'host' ? `${other.host}|${other.port}` : `${other.relatedAddress}|${other.relatedPort}`;
629
+ return this.localCandidates.some((other) => other.transport === candidate.transport &&
630
+ other.host === candidate.host &&
631
+ other.port === candidate.port &&
632
+ other.type !== 'relay' &&
633
+ baseOf(other) === baseOf(candidate));
634
+ }
635
+ /**
636
+ * A relay candidate from each TURN server. An ICE restart keeps the
637
+ * allocation of a server when the server still has it; the relays of the
638
+ * servers no longer configured are closed.
639
+ */
640
+ gatherRelayCandidates(servers) {
641
+ for (const [key, relay] of this.relays) {
642
+ if (!servers.some((server) => server.key === key))
643
+ this.dropRelay(key, relay);
644
+ }
645
+ return servers.map(async (server) => {
646
+ const existing = this.relays.get(server.key);
647
+ if (existing) {
648
+ if (await existing.turn.refreshAllocation()) {
649
+ if (this.relays.get(server.key) !== existing)
650
+ return;
651
+ existing.localCandidate.generation = this.generation;
652
+ existing.localCandidate.ufrag = this.localUsername;
653
+ this.appendLocalCandidate(existing.localCandidate);
654
+ return existing.localCandidate;
655
+ }
656
+ this.dropRelay(server.key, existing);
657
+ }
658
+ const { protocol, attempt } = await this.allocateRelay(server);
659
+ if (this.state === 'closed' || this.relays.has(server.key)) {
660
+ await protocol.close();
661
+ return;
662
+ }
663
+ this.ensureProtocol(protocol);
664
+ this.protocols.push(protocol);
665
+ this.relays.set(server.key, protocol);
666
+ const candidateAddress = protocol.turn.relayedAddress;
667
+ const relatedAddress = protocol.turn.mappedAddress;
668
+ log('turn candidateAddress', candidateAddress);
669
+ protocol.localCandidate = new candidate_js_1.Candidate((0, candidate_js_1.candidateFoundation)('relay', 'udp', candidateAddress[0], `${server.key}|${attempt.transport}`), 1, 'udp', (0, candidate_js_1.candidatePriority)('relay', RELAY_PREFERENCE[attempt.transport]), candidateAddress[0], candidateAddress[1], 'relay', relatedAddress[0], relatedAddress[1], undefined, this.generation, this.localUsername);
670
+ this.appendLocalCandidate(protocol.localCandidate);
671
+ return protocol.localCandidate;
672
+ }).map((promise) => promise.catch((error) => {
673
+ log('query TURN server', error);
674
+ }));
675
+ }
676
+ /**
677
+ * Allocate a relay on a TURN server: its transports are tried in order, the
678
+ * next one when the one before fails or has not answered within
679
+ * RELAY_ATTEMPT_DELAY; the first allocation made is kept, a later one is
680
+ * deleted.
681
+ */
682
+ allocateRelay(server) {
683
+ return new Promise((resolve, reject) => {
684
+ let next = 0;
685
+ let pending = 0;
686
+ let done = false;
687
+ let timer;
688
+ const start = () => {
689
+ clearTimeout(timer);
690
+ if (done || next >= server.attempts.length)
691
+ return;
692
+ const attempt = server.attempts[next++];
693
+ pending++;
694
+ timer = setTimeout(start, RELAY_ATTEMPT_DELAY);
695
+ (0, protocol_js_2.createStunOverTurnClient)({ address: attempt.address, username: attempt.username, password: attempt.password }, {
696
+ portRange: this.options.portRange,
697
+ interfaceAddresses: this.options.interfaceAddresses,
698
+ transport: attempt.transport,
699
+ tlsOptions: this.options.turnTlsOptions,
700
+ connectTimeoutMs: (this.options.turnConnectTimeout ?? 8) * 1000,
701
+ udpFamily: this.options.turnUdpFamily
702
+ }).then((protocol) => {
703
+ pending--;
704
+ if (done) {
705
+ protocol.close().catch((error) => log('close TURN relay', error));
706
+ return;
707
+ }
708
+ done = true;
709
+ clearTimeout(timer);
710
+ resolve({ protocol, attempt });
711
+ }, (error) => {
712
+ pending--;
713
+ log('TURN allocation failed', attempt.transport, attempt.address, error);
714
+ if (done)
715
+ return;
716
+ if (next < server.attempts.length) {
717
+ start();
718
+ }
719
+ else if (!pending) {
720
+ done = true;
721
+ reject(error);
722
+ }
723
+ });
724
+ };
725
+ start();
726
+ });
727
+ }
728
+ /** Stop using a relay and delete its allocation. */
729
+ dropRelay(key, relay) {
730
+ this.relays.delete(key);
731
+ this.protocols = this.protocols.filter((protocol) => protocol !== relay);
732
+ relay.close().catch((error) => log('close TURN relay', error));
733
+ }
734
+ ensureProtocol(protocol) {
735
+ protocol.onRequestReceived.subscribe((msg, addr) => {
736
+ if (msg.messageMethod !== const_js_1.methods.BINDING) {
737
+ this.respondError(msg, addr, protocol, [400, 'Bad Request']);
738
+ return;
739
+ }
740
+ const txUsername = msg.getAttributeValue('USERNAME');
741
+ // 相手にとってのremoteは自分にとってのlocal
742
+ const { remoteUsername: localUsername } = decodeTxUsername(txUsername);
743
+ const localPassword = this.userHistory[localUsername] ?? this.localPassword;
744
+ const { iceControlling } = this;
745
+ // 7.2.1.1. Detecting and Repairing Role Conflicts
746
+ if (iceControlling && msg.attributesKeys.includes('ICE-CONTROLLING')) {
747
+ if (this.tieBreaker >= msg.getAttributeValue('ICE-CONTROLLING')) {
748
+ this.respondError(msg, addr, protocol, [487, 'Role Conflict']);
749
+ return;
750
+ }
751
+ else {
752
+ this.switchRole(false);
753
+ }
754
+ }
755
+ else if (!iceControlling &&
756
+ msg.attributesKeys.includes('ICE-CONTROLLED')) {
757
+ if (this.iceLite ||
758
+ this.tieBreaker < msg.getAttributeValue('ICE-CONTROLLED')) {
759
+ this.respondError(msg, addr, protocol, [487, 'Role Conflict']);
760
+ return;
761
+ }
762
+ else {
763
+ this.switchRole(true);
764
+ return;
765
+ }
766
+ }
767
+ if (this.options.filterStunResponse &&
768
+ !this.options.filterStunResponse(msg, addr, protocol)) {
769
+ return;
770
+ }
771
+ // # send binding response
772
+ const response = new message_js_1.Message(const_js_1.methods.BINDING, const_js_1.classes.RESPONSE, msg.transactionId);
773
+ response
774
+ .setAttribute('XOR-MAPPED-ADDRESS', addr)
775
+ .addMessageIntegrity(Buffer.from(localPassword, 'utf8'))
776
+ .addFingerprint();
777
+ protocol.sendStun(response, addr).catch((e) => {
778
+ log('sendStun error', e);
779
+ });
780
+ if (this.checkList.length === 0 && !this.earlyChecksDone) {
781
+ this.earlyChecks.push([msg, addr, protocol]);
782
+ }
783
+ else {
784
+ this.checkIncoming(msg, addr, protocol);
785
+ }
786
+ });
787
+ protocol.onDataReceived.subscribe((data) => {
788
+ try {
789
+ // Update statistics for the nominated pair
790
+ const activePair = this.nominated;
791
+ if (activePair && activePair.protocol === protocol) {
792
+ activePair.packetsReceived++;
793
+ activePair.bytesReceived += data.length;
794
+ }
795
+ this.onData.execute(data);
796
+ }
797
+ catch (error) {
798
+ log('dataReceived', error);
799
+ }
800
+ });
801
+ protocol.onConnectionClosed?.subscribe((remoteAddr) => {
802
+ this.handleConnectionClosed(protocol, remoteAddr);
803
+ });
804
+ }
805
+ /**
806
+ * RFC 6544: the selected TCP connection is the only path for this component;
807
+ * once it is closed no application data or consent check can reach the peer,
808
+ * so fail the same way as a consent expiry instead of waiting for it.
809
+ */
810
+ handleConnectionClosed(protocol, remoteAddr) {
811
+ const nominated = this.nominated;
812
+ if (!nominated ||
813
+ nominated.protocol !== protocol ||
814
+ nominated.remoteAddr[0] !== remoteAddr[0] ||
815
+ nominated.remoteAddr[1] !== remoteAddr[1]) {
816
+ return;
817
+ }
818
+ if (this.state === 'closed' || this.state === 'failed') {
819
+ return;
820
+ }
821
+ log('selected tcp connection closed', nominated.toJSON());
822
+ this.stopConsentLifecycle();
823
+ this.setState('failed');
824
+ }
825
+ getCandidatePromises(addresses, timeout = 5) {
826
+ const candidatePromises = [];
827
+ const { stunServers, relayServers } = this;
828
+ const gatherIceLite = this.iceLite;
829
+ const gatherRelayOnly = !gatherIceLite && this.options.forceTurn && relayServers.length > 0;
830
+ //The UDP host candidates of the generations before (an ICE restart) are queried again with the STUN servers
831
+ const knownHostProtocols = this.protocols.filter((protocol) => protocol instanceof protocol_js_1.StunProtocol && !!protocol.localCandidate);
832
+ addresses = addresses.filter((address) => {
833
+ // ice restartで同じアドレスが追加されるのを防ぐ
834
+ if (this.protocols.find((protocol) => protocol.localIp === address)) {
835
+ return false;
836
+ }
837
+ return true;
838
+ });
839
+ const localStunPromises = gatherRelayOnly
840
+ ? []
841
+ : addresses.map(async (address) => {
842
+ // # create transport
843
+ const protocol = new protocol_js_1.StunProtocol();
844
+ this.ensureProtocol(protocol);
845
+ try {
846
+ await protocol.connectionMade((0, node_net_1.isIPv4)(address), this.options.portRange, this.options.interfaceAddresses);
847
+ protocol.localIp = address;
848
+ this.protocols.push(protocol);
849
+ log('protocol', protocol.localIp);
850
+ // # add host candidate
851
+ const candidateAddress = [
852
+ address,
853
+ protocol.getExtraInfo()[1]
854
+ ];
855
+ protocol.localCandidate = new candidate_js_1.Candidate((0, candidate_js_1.candidateFoundation)('host', 'udp', candidateAddress[0]), 1, 'udp', (0, candidate_js_1.candidatePriority)('host', { transport: 'udp' }), candidateAddress[0], candidateAddress[1], 'host', undefined, undefined, undefined, this.generation, this.localUsername);
856
+ this.pairLocalProtocol(protocol);
857
+ this.appendLocalCandidate(protocol.localCandidate);
858
+ return protocol;
859
+ }
860
+ catch (error) {
861
+ log('error protocol STUN', error);
862
+ }
863
+ });
864
+ if (!gatherRelayOnly) {
865
+ candidatePromises.push(...localStunPromises.map((localPromise) => localPromise.then((protocol) => protocol?.localCandidate)));
866
+ }
867
+ if (!gatherRelayOnly && this.options.useTcp) {
868
+ const tcpCandidatePromises = addresses.map(async (address) => {
869
+ // Passive candidates open a listening TCP server; skip them when the
870
+ // agent only makes outbound connections (tcpPassive === false). Active
871
+ // candidates below still dial out, so direct TCP egress is unaffected.
872
+ if (this.options.tcpPassive !== false) {
873
+ const passiveProtocol = new tcpProtocol_js_1.TcpPassiveProtocol();
874
+ this.ensureProtocol(passiveProtocol);
875
+ await passiveProtocol.connectionMade(address, this.options.portRange);
876
+ passiveProtocol.localIp = address;
877
+ passiveProtocol.localCandidate = new candidate_js_1.Candidate((0, candidate_js_1.candidateFoundation)('host', 'tcp', address), 1, 'tcp', (0, candidate_js_1.candidatePriority)('host', {
878
+ transport: 'tcp',
879
+ tcptype: 'passive'
880
+ }), address, passiveProtocol.listeningPort, 'host', undefined, undefined, 'passive', this.generation, this.localUsername);
881
+ this.protocols.push(passiveProtocol);
882
+ this.appendLocalCandidate(passiveProtocol.localCandidate);
883
+ }
884
+ if (!gatherIceLite) {
885
+ const activeProtocol = new tcpProtocol_js_1.TcpActiveProtocol();
886
+ this.ensureProtocol(activeProtocol);
887
+ await activeProtocol.connectionMade(address);
888
+ activeProtocol.localIp = address;
889
+ activeProtocol.localCandidate = new candidate_js_1.Candidate((0, candidate_js_1.candidateFoundation)('host', 'tcp', address), 1, 'tcp', (0, candidate_js_1.candidatePriority)('host', {
890
+ transport: 'tcp',
891
+ tcptype: 'active'
892
+ }), address, 9, 'host', undefined, undefined, 'active', this.generation, this.localUsername);
893
+ this.protocols.push(activeProtocol);
894
+ this.pairLocalProtocol(activeProtocol);
895
+ this.appendLocalCandidate(activeProtocol.localCandidate);
896
+ }
897
+ });
898
+ candidatePromises.push(...tcpCandidatePromises);
899
+ }
900
+ if (!gatherIceLite && !gatherRelayOnly && stunServers.length) {
901
+ const hostProtocols = [
902
+ ...knownHostProtocols.map((protocol) => Promise.resolve(protocol)),
903
+ ...localStunPromises
904
+ ];
905
+ const stunCandidatePromises = hostProtocols.flatMap((protocolPromise) => stunServers.map(async (stunServer) => {
906
+ const protocol = await protocolPromise;
907
+ if (!protocol)
908
+ return;
909
+ //The server reflexive candidate of an IPv4 host candidate; gathering waits for it at most timeout
910
+ //seconds (a late answer still adds its candidate, unless ICE restarted meanwhile)
911
+ const generation = this.generation;
912
+ const query = (async () => {
913
+ const host = protocol.localCandidate?.host;
914
+ if (!host || !(0, node_net_1.isIPv4)(host))
915
+ return;
916
+ const candidate = await (0, iceBase_js_1.serverReflexiveCandidate)(protocol, stunServer).catch((error) => {
917
+ log('error', error);
918
+ });
919
+ if (!candidate || generation !== this.generation || this.isRedundant(candidate))
920
+ return;
921
+ candidate.generation = this.generation;
922
+ candidate.ufrag = this.localUsername;
923
+ this.appendLocalCandidate(candidate);
924
+ return candidate;
925
+ })();
926
+ let timer;
927
+ const timeLimit = new Promise((_, f) => {
928
+ timer = setTimeout(() => f(new Error('STUN query timeout')), timeout * 1000);
929
+ });
930
+ return Promise.race([query, timeLimit])
931
+ .finally(() => clearTimeout(timer))
932
+ .catch((error) => {
933
+ log('query STUN server', error);
934
+ });
935
+ }));
936
+ candidatePromises.push(...stunCandidatePromises);
937
+ }
938
+ if (!gatherIceLite) {
939
+ candidatePromises.push(...this.gatherRelayCandidates(relayServers));
940
+ }
941
+ return candidatePromises;
942
+ }
943
+ async connect() {
944
+ // """
945
+ // Perform ICE handshake.
946
+ //
947
+ // This coroutine returns if a candidate pair was successfully nominated
948
+ // and raises an exception otherwise.
949
+ // """
950
+ log('start connect ice');
951
+ if (!this.localCandidatesEnd) {
952
+ if (!this.localCandidatesStart) {
953
+ throw new Error('Local candidates gathering was not performed');
954
+ }
955
+ }
956
+ if (!this.remoteUsername || !this.remotePassword) {
957
+ throw new Error('Remote username or password is missing');
958
+ }
959
+ // # 5.7.1. Forming Candidate Pairs
960
+ for (const c of this.remoteCandidates) {
961
+ this.pairRemoteCandidate(c);
962
+ }
963
+ this.sortCheckList();
964
+ if (!this.iceLite) {
965
+ this.unfreezeInitial();
966
+ }
967
+ log('earlyChecks', this.localPassword, this.earlyChecks.length);
968
+ // # handle early checks
969
+ for (const earlyCheck of this.earlyChecks) {
970
+ this.checkIncoming(...earlyCheck);
971
+ }
972
+ this.earlyChecks = [];
973
+ this.earlyChecksDone = true;
974
+ if (this.iceLite) {
975
+ if (!this.nominated) {
976
+ let res = iceBase_js_1.ICE_FAILED;
977
+ while (!this.checkListDone && this.state !== 'closed') {
978
+ res = await this.checkListState.get();
979
+ log('checkListState', res);
980
+ if (res === iceBase_js_1.ICE_COMPLETED) {
981
+ break;
982
+ }
983
+ }
984
+ if (res !== iceBase_js_1.ICE_COMPLETED && !this.nominated) {
985
+ throw new Error('ICE negotiation failed');
986
+ }
987
+ }
988
+ this.setState('connected');
989
+ return;
990
+ }
991
+ // # perform checks
992
+ // 5.8. Scheduling Checks
993
+ this.noPairDeadline = Date.now() + NO_PAIR_TIMEOUT;
994
+ for (;;) {
995
+ if (this.state === 'closed')
996
+ break;
997
+ if (!this.schedulingChecks())
998
+ break;
999
+ await timers.setTimeout(20);
1000
+ }
1001
+ // # wait for completion (closing the connection ends the wait)
1002
+ let res = iceBase_js_1.ICE_FAILED;
1003
+ while (this.checkList.length > 0 && res === iceBase_js_1.ICE_FAILED && this.state !== 'closed') {
1004
+ res = await this.checkListState.get();
1005
+ log('checkListState', res);
1006
+ }
1007
+ // # cancel remaining checks
1008
+ for (const check of this.checkList) {
1009
+ check.handle?.resolve?.();
1010
+ }
1011
+ if (res !== iceBase_js_1.ICE_COMPLETED) {
1012
+ throw new Error('ICE negotiation failed');
1013
+ }
1014
+ // # start consent freshness tests
1015
+ this.queryConsent();
1016
+ this.setState('connected');
1017
+ }
1018
+ unfreezeInitial() {
1019
+ // # unfreeze first pair for the first component
1020
+ const [firstPair] = this.checkList;
1021
+ if (!firstPair)
1022
+ return;
1023
+ if (firstPair.state === iceBase_js_1.CandidatePairState.FROZEN) {
1024
+ firstPair.updateState(iceBase_js_1.CandidatePairState.WAITING);
1025
+ }
1026
+ // # unfreeze pairs with same component but different foundations
1027
+ const seenFoundations = new Set(firstPair.localCandidate.foundation);
1028
+ for (const pair of this.checkList) {
1029
+ if (pair.component === firstPair.component &&
1030
+ !seenFoundations.has(pair.localCandidate.foundation) &&
1031
+ pair.state === iceBase_js_1.CandidatePairState.FROZEN) {
1032
+ pair.updateState(iceBase_js_1.CandidatePairState.WAITING);
1033
+ seenFoundations.add(pair.localCandidate.foundation);
1034
+ }
1035
+ }
1036
+ }
1037
+ // 5.8 Scheduling Checks
1038
+ schedulingChecks() {
1039
+ //A pair is being nominated: no other check meanwhile (they resume if the nomination fails)
1040
+ if (this.nominating && !this.nominated)
1041
+ return true;
1042
+ // Ordinary Check
1043
+ {
1044
+ // # find the highest-priority pair that is in the waiting state
1045
+ const pair = this.checkList
1046
+ .filter((pair) => {
1047
+ if (this.options.forceTurn &&
1048
+ pair.protocol.type === protocol_js_1.StunProtocol.type)
1049
+ return false;
1050
+ return true;
1051
+ })
1052
+ .find((pair) => pair.state === iceBase_js_1.CandidatePairState.WAITING);
1053
+ if (pair) {
1054
+ pair.handle = this.checkStart(pair);
1055
+ return true;
1056
+ }
1057
+ }
1058
+ {
1059
+ // # find the highest-priority pair that is in the frozen state
1060
+ const pair = this.checkList.find((pair) => pair.state === iceBase_js_1.CandidatePairState.FROZEN);
1061
+ if (pair) {
1062
+ pair.handle = this.checkStart(pair);
1063
+ return true;
1064
+ }
1065
+ }
1066
+ // # if we expect more candidates, keep going: their end has not come, some are being resolved, or there is no
1067
+ // pair yet (the checks of the other side may give one)
1068
+ if (!this.remoteCandidatesEnd || this.resolvingRemoteCandidates > 0 || (!this.checkList.length && Date.now() < this.noPairDeadline)) {
1069
+ return !this.checkListDone;
1070
+ }
1071
+ return false;
1072
+ }
1073
+ /**
1074
+ * Stop consent request cadence, expiry timer, and outstanding transactions.
1075
+ * Does not change ICE state by itself.
1076
+ */
1077
+ stopConsentLifecycle() {
1078
+ this.consentSessionId++;
1079
+ this.consentFresh = false;
1080
+ if (this.consentExpiryTimer !== undefined) {
1081
+ clearTimeout(this.consentExpiryTimer);
1082
+ this.consentExpiryTimer = undefined;
1083
+ }
1084
+ this.consentRequestAbort?.abort();
1085
+ this.consentRequestAbort = undefined;
1086
+ const handle = this.queryConsentHandle;
1087
+ this.queryConsentHandle = undefined;
1088
+ // Resolve after clearing the field so a stale onCancel cannot wipe a replacement.
1089
+ handle?.resolve?.();
1090
+ }
1091
+ /**
1092
+ * ICE-lite interop only (not required by RFC 7675): mirror libwebrtc
1093
+ * semi-aggressive nomination — attach USE-CANDIDATE when we are controlling,
1094
+ * the remote is ICE-lite, and the target is the current selected pair.
1095
+ */
1096
+ shouldNominateConsentRequest(pair) {
1097
+ return (this.iceControlling && this.remoteIsLite && this.nominated?.id === pair.id);
1098
+ }
1099
+ canSendApplicationData() {
1100
+ if (!this.nominated) {
1101
+ return false;
1102
+ }
1103
+ if (this.state === 'closed' || this.state === 'failed') {
1104
+ return false;
1105
+ }
1106
+ // Local ICE-lite does not run consent checks; full agents need fresh consent.
1107
+ if (this.iceLite) {
1108
+ return true;
1109
+ }
1110
+ return this.consentFresh;
1111
+ }
1112
+ abortableDelay(ms, signal) {
1113
+ return new Promise((resolve, reject) => {
1114
+ if (signal.aborted) {
1115
+ reject(new DOMException('The operation was aborted', 'AbortError'));
1116
+ return;
1117
+ }
1118
+ const timer = setTimeout(() => {
1119
+ signal.removeEventListener('abort', onAbort);
1120
+ resolve();
1121
+ }, ms);
1122
+ const onAbort = () => {
1123
+ clearTimeout(timer);
1124
+ reject(new DOMException('The operation was aborted', 'AbortError'));
1125
+ };
1126
+ signal.addEventListener('abort', onAbort, { once: true });
1127
+ });
1128
+ }
1129
+ async close() {
1130
+ // """
1131
+ // Close the connection.
1132
+ // """
1133
+ this.setState('closed');
1134
+ // # stop consent freshness tests
1135
+ this.stopConsentLifecycle();
1136
+ // # stop check list
1137
+ if (this.checkList && !this.checkListDone) {
1138
+ this.checkListState.put(new Promise((r) => {
1139
+ r(iceBase_js_1.ICE_FAILED);
1140
+ }));
1141
+ }
1142
+ this.nominated = undefined;
1143
+ const protocols = this.protocols;
1144
+ this.protocols = [];
1145
+ this.relays.clear();
1146
+ //Together: closing a relay waits for its server to delete the allocation
1147
+ await Promise.all(protocols.map(async (protocol) => {
1148
+ await protocol.close?.();
1149
+ }));
1150
+ this.localCandidates = [];
1151
+ this.lookup?.close?.();
1152
+ this.lookup = undefined;
1153
+ }
1154
+ setState(state) {
1155
+ this.state = state;
1156
+ this.stateChanged.execute(state);
1157
+ }
1158
+ async addRemoteCandidate(remoteCandidate) {
1159
+ // """
1160
+ // Add a remote candidate or signal end-of-candidates.
1161
+ // To signal end-of-candidates, pass `None`.
1162
+ // :param remote_candidate: A :class:`Candidate` instance or `None`.
1163
+ // """
1164
+ if (!remoteCandidate) {
1165
+ this.remoteCandidatesEnd = true;
1166
+ return;
1167
+ }
1168
+ //An mDNS name is resolved meanwhile, as the browsers do: a name nobody answers for (up to 10 seconds) does not
1169
+ //hold the descriptions and the candidates applied after it; the checks wait for it
1170
+ if (remoteCandidate.host.includes('.local')) {
1171
+ void this.resolveRemoteCandidate(remoteCandidate);
1172
+ return;
1173
+ }
1174
+ this.addResolvedRemoteCandidate(remoteCandidate);
1175
+ }
1176
+ /**
1177
+ * Resolve the mDNS name of a remote candidate, then add it, unless ICE restarted or closed meanwhile
1178
+ * @param remoteCandidate
1179
+ */
1180
+ async resolveRemoteCandidate(remoteCandidate) {
1181
+ const generation = this.generation;
1182
+ this.resolvingRemoteCandidates++;
1183
+ try {
1184
+ if (!this.lookup) {
1185
+ this.lookup = new lookup_js_1.MdnsLookup();
1186
+ }
1187
+ remoteCandidate.host = await this.lookup.lookup(remoteCandidate.host);
1188
+ }
1189
+ catch {
1190
+ return;
1191
+ }
1192
+ finally {
1193
+ this.resolvingRemoteCandidates--;
1194
+ }
1195
+ if (generation !== this.generation || this.state === 'closed')
1196
+ return;
1197
+ this.addResolvedRemoteCandidate(remoteCandidate);
1198
+ }
1199
+ /**
1200
+ * Add a remote candidate with an address, and pair it
1201
+ * @param remoteCandidate
1202
+ */
1203
+ addResolvedRemoteCandidate(remoteCandidate) {
1204
+ try {
1205
+ (0, iceBase_js_1.validateRemoteCandidate)(remoteCandidate);
1206
+ }
1207
+ catch (error) {
1208
+ return;
1209
+ }
1210
+ //Known already: each description applied gives its candidates again
1211
+ if (this._remoteCandidates.some((known) => known.host === remoteCandidate.host
1212
+ && known.port === remoteCandidate.port
1213
+ && known.component === remoteCandidate.component
1214
+ && known.type === remoteCandidate.type
1215
+ && known.transport.toLowerCase() === remoteCandidate.transport.toLowerCase())) {
1216
+ return;
1217
+ }
1218
+ log('addRemoteCandidate', remoteCandidate);
1219
+ this._remoteCandidates.push(remoteCandidate);
1220
+ this.pairRemoteCandidate(remoteCandidate);
1221
+ this.sortCheckList();
1222
+ }
1223
+ getDefaultCandidate() {
1224
+ const candidates = this.localCandidates.sort((a, b) => a.priority - b.priority);
1225
+ const [candidate] = candidates;
1226
+ return candidate;
1227
+ }
1228
+ // for test only
1229
+ set remoteCandidates(value) {
1230
+ if (this.remoteCandidatesEnd)
1231
+ throw new Error('Cannot set remote candidates after end-of-candidates.');
1232
+ this._remoteCandidates = [];
1233
+ for (const remoteCandidate of value) {
1234
+ try {
1235
+ (0, iceBase_js_1.validateRemoteCandidate)(remoteCandidate);
1236
+ }
1237
+ catch (error) {
1238
+ continue;
1239
+ }
1240
+ this._remoteCandidates.push(remoteCandidate);
1241
+ }
1242
+ this.remoteCandidatesEnd = true;
1243
+ }
1244
+ get remoteCandidates() {
1245
+ return this._remoteCandidates;
1246
+ }
1247
+ get candidatePairs() {
1248
+ return this.checkList;
1249
+ }
1250
+ sortCheckList() {
1251
+ (0, iceBase_js_1.sortCandidatePairs)(this.checkList, this.iceControlling);
1252
+ }
1253
+ findPair(protocol, remoteCandidate) {
1254
+ const pair = this.checkList.find((pair) => pair.protocol === protocol && pair.remoteCandidate === remoteCandidate);
1255
+ return pair;
1256
+ }
1257
+ applyIceControlling(iceControlling) {
1258
+ this._iceControlling = iceControlling;
1259
+ for (const pair of this.checkList) {
1260
+ pair.iceControlling = iceControlling;
1261
+ }
1262
+ }
1263
+ switchRole(iceControlling) {
1264
+ log('switch role', iceControlling);
1265
+ // Role conflicts must be repaired even after a prior generation or while
1266
+ // connectivity checks are in flight (RFC 8445 §7.2.5.1 / §7.3.1.1).
1267
+ if (this.iceLite) {
1268
+ iceControlling = false;
1269
+ }
1270
+ this.applyIceControlling(iceControlling);
1271
+ this.sortCheckList();
1272
+ }
1273
+ checkComplete(pair) {
1274
+ pair.handle = undefined;
1275
+ if (pair.state === iceBase_js_1.CandidatePairState.SUCCEEDED) {
1276
+ // Updating the Nominated Flag
1277
+ // https://www.rfc-editor.org/rfc/rfc8445#section-7.3.1.5,
1278
+ // Once the nominated flag is set for a component of a data stream, it
1279
+ // concludes the ICE processing for that component. See Section 8.
1280
+ // So disallow overwriting of the pair nominated for that component
1281
+ //A candidate of the current session of the other side: the candidates and the pairs of a session before are gone
1282
+ //(restart), and the generation a candidate gives is the one the other side counts (Chrome gives 0 always),
1283
+ //so only its ufrag, when given, tells
1284
+ if (pair.nominated &&
1285
+ (pair.remoteCandidate.ufrag == undefined || pair.remoteCandidate.ufrag === this.remoteUsername) &&
1286
+ this.nominated == undefined) {
1287
+ log('nominated', pair.toJSON());
1288
+ this.nominated = pair;
1289
+ this.nominating = false;
1290
+ this.pruneTcpConnections(pair);
1291
+ //Its socket sends only to the other side from now on, once the other side is seen using the pair
1292
+ pair.protocol.connectTo?.(pair.remoteAddr);
1293
+ // After resetNominatedPair / renomination while already connected,
1294
+ // restart consent freshness on the new selected pair.
1295
+ if (!this.iceLite &&
1296
+ (this.state === 'connected' || this.state === 'completed')) {
1297
+ this.queryConsent();
1298
+ }
1299
+ // 8.1.2. Updating States
1300
+ // The agent MUST remove all Waiting and Frozen pairs in the check
1301
+ // list and triggered check queue for the same component as the
1302
+ // nominated pairs for that media stream.
1303
+ for (const p of this.checkList) {
1304
+ if (p.component === pair.component &&
1305
+ [iceBase_js_1.CandidatePairState.WAITING, iceBase_js_1.CandidatePairState.FROZEN].includes(p.state)) {
1306
+ p.updateState(iceBase_js_1.CandidatePairState.FAILED);
1307
+ }
1308
+ }
1309
+ }
1310
+ // Once there is at least one nominated pair in the valid list for
1311
+ // every component of at least one media stream and the state of the
1312
+ // check list is Running:
1313
+ if (this.nominated) {
1314
+ if (!this.checkListDone) {
1315
+ log('ICE completed');
1316
+ this.checkListState.put(new Promise((r) => r(iceBase_js_1.ICE_COMPLETED)));
1317
+ this.checkListDone = true;
1318
+ }
1319
+ return;
1320
+ }
1321
+ log('not completed', pair.toJSON());
1322
+ // 7.1.3.2.3. Updating Pair States
1323
+ for (const p of this.checkList) {
1324
+ if (p.localCandidate.foundation === pair.localCandidate.foundation &&
1325
+ p.state === iceBase_js_1.CandidatePairState.FROZEN) {
1326
+ p.updateState(iceBase_js_1.CandidatePairState.WAITING);
1327
+ }
1328
+ }
1329
+ }
1330
+ this.nominateTcpPairIfReady();
1331
+ // A nomination request is still in flight; its result decides the outcome.
1332
+ if (this.nominating) {
1333
+ return;
1334
+ }
1335
+ {
1336
+ const list = [iceBase_js_1.CandidatePairState.SUCCEEDED, iceBase_js_1.CandidatePairState.FAILED];
1337
+ if (this.checkList.find(({ state }) => !list.includes(state))) {
1338
+ return;
1339
+ }
1340
+ }
1341
+ if (!this.iceControlling) {
1342
+ const target = iceBase_js_1.CandidatePairState.SUCCEEDED;
1343
+ if (this.checkList.find(({ state }) => state === target)) {
1344
+ return;
1345
+ }
1346
+ }
1347
+ if (!this.checkListDone) {
1348
+ log('ICE failed');
1349
+ this.checkListState.put(new Promise((r) => {
1350
+ r(iceBase_js_1.ICE_FAILED);
1351
+ }));
1352
+ }
1353
+ }
1354
+ isTcpPair(pair) {
1355
+ return pair.localCandidate.transport.toLowerCase() === 'tcp';
1356
+ }
1357
+ /**
1358
+ * Aggressive nomination lets each side settle on whichever TCP connection
1359
+ * finished first; the two sides can then pick different connections and
1360
+ * pruning destroys the peer's choice. For TCP the controlling agent instead
1361
+ * nominates exactly one valid pair (RFC 8445 §8.1.1 regular nomination).
1362
+ */
1363
+ usesTcpRegularNomination(pair) {
1364
+ return this.iceControlling && !this.remoteIsLite && this.isTcpPair(pair);
1365
+ }
1366
+ checkRequestOptions(pair) {
1367
+ const onRequestSent = (attempt) => {
1368
+ if (attempt > 0) {
1369
+ pair.retransmissionsSent++;
1370
+ }
1371
+ };
1372
+ if (this.isTcpPair(pair)) {
1373
+ // RFC 5389 §7.2.2: no retransmissions over a reliable transport.
1374
+ return {
1375
+ retransmissions: 0,
1376
+ responseTimeout: const_js_1.TCP_CHECK_RESPONSE_TIMEOUT_MS,
1377
+ onRequestSent
1378
+ };
1379
+ }
1380
+ return { retransmissions: 4, onRequestSent };
1381
+ }
1382
+ /**
1383
+ * Controlling side: nominate the highest-priority TCP pair once every
1384
+ * higher-priority TCP pair has finished its check, so the choice does not
1385
+ * depend on which connection happened to complete first.
1386
+ */
1387
+ nominateTcpPairIfReady() {
1388
+ if (!this.iceControlling ||
1389
+ this.remoteIsLite ||
1390
+ this.nominated ||
1391
+ this.nominating) {
1392
+ return;
1393
+ }
1394
+ for (const pair of this.checkList) {
1395
+ if (!this.isTcpPair(pair)) {
1396
+ continue;
1397
+ }
1398
+ if (pair.state === iceBase_js_1.CandidatePairState.SUCCEEDED) {
1399
+ this.nominateTcpPair(pair);
1400
+ return;
1401
+ }
1402
+ if (pair.state !== iceBase_js_1.CandidatePairState.FAILED) {
1403
+ // A higher-priority pair may still succeed.
1404
+ return;
1405
+ }
1406
+ }
1407
+ }
1408
+ nominateTcpPair(pair) {
1409
+ this.nominating = true;
1410
+ const { generation } = this;
1411
+ const request = this.buildRequest({
1412
+ nominate: true,
1413
+ localUsername: pair.localCandidate.ufrag ?? this.localUsername,
1414
+ remoteUsername: this.remoteUsername,
1415
+ iceControlling: this.iceControlling,
1416
+ localCandidate: pair.localCandidate
1417
+ });
1418
+ pair.requestsSent++;
1419
+ pair.protocol
1420
+ .request(request, pair.remoteAddr, Buffer.from(this.remotePassword, 'utf8'), this.checkRequestOptions(pair))
1421
+ .then(() => {
1422
+ if (this.isStaleNomination(pair, generation)) {
1423
+ return;
1424
+ }
1425
+ pair.responsesReceived++;
1426
+ pair.nominated = true;
1427
+ this.nominating = false;
1428
+ this.checkComplete(pair);
1429
+ }, (error) => {
1430
+ if (this.isStaleNomination(pair, generation)) {
1431
+ return;
1432
+ }
1433
+ log('tcp nomination failed', pair.toJSON(), error);
1434
+ this.nominating = false;
1435
+ pair.updateState(iceBase_js_1.CandidatePairState.FAILED);
1436
+ this.checkComplete(pair);
1437
+ });
1438
+ }
1439
+ /** The agent was closed or restarted while the nomination was in flight. */
1440
+ isStaleNomination(pair, generation) {
1441
+ return (this.state === 'closed' ||
1442
+ this.generation !== generation ||
1443
+ !this.checkList.includes(pair));
1444
+ }
1445
+ addPair(pair) {
1446
+ this.checkList.push(pair);
1447
+ this.sortCheckList();
1448
+ }
1449
+ // 7.2. STUN Server Procedures
1450
+ // 7.2.1.3、7.2.1.4、および7.2.1.5
1451
+ checkIncoming(message, addr, protocol) {
1452
+ // """
1453
+ // Handle a successful incoming check.
1454
+ // """
1455
+ const txUsername = message.getAttributeValue('USERNAME');
1456
+ const { remoteUsername: localUsername } = decodeTxUsername(txUsername);
1457
+ // find remote candidate
1458
+ let remoteCandidate;
1459
+ const [host, port] = addr;
1460
+ for (const c of this.remoteCandidates) {
1461
+ if (c.host === host && c.port === port) {
1462
+ remoteCandidate = c;
1463
+ break;
1464
+ }
1465
+ }
1466
+ if (!remoteCandidate) {
1467
+ // 7.2.1.3. Learning Peer Reflexive Candidates
1468
+ remoteCandidate = new candidate_js_1.Candidate((0, helper_js_1.randomString)(10), 1, protocol.localCandidate?.transport ?? 'udp', message.getAttributeValue('PRIORITY'), host, port, 'prflx', undefined, undefined, protocol.localCandidate?.transport === 'tcp'
1469
+ ? (0, candidate_js_1.remoteTcpTypeForIncoming)(protocol.localCandidate.tcptype)
1470
+ : undefined, undefined, undefined);
1471
+ this._remoteCandidates.push(remoteCandidate);
1472
+ }
1473
+ // find pair
1474
+ let pair = this.findPair(protocol, remoteCandidate);
1475
+ if (!pair) {
1476
+ pair = new iceBase_js_1.CandidatePair(protocol, remoteCandidate, this.iceControlling);
1477
+ pair.updateState(iceBase_js_1.CandidatePairState.WAITING);
1478
+ this.addPair(pair);
1479
+ }
1480
+ pair.noteIncomingRequest(message.transactionIdHex);
1481
+ pair.requestsReceived++;
1482
+ pair.responsesSent++;
1483
+ pair.localCandidate.ufrag = localUsername;
1484
+ log('Triggered Checks', message.toJSON(), pair.toJSON(), {
1485
+ localUsername: this.localUsername,
1486
+ remoteUsername: this.remoteUsername,
1487
+ localPassword: this.localPassword,
1488
+ remotePassword: this.remotePassword,
1489
+ generation: this.generation
1490
+ });
1491
+ if (this.iceLite) {
1492
+ if (message.attributesKeys.includes('USE-CANDIDATE') &&
1493
+ !this.iceControlling) {
1494
+ pair.remoteNominated = true;
1495
+ pair.nominated = true;
1496
+ pair.updateState(iceBase_js_1.CandidatePairState.SUCCEEDED);
1497
+ this.checkComplete(pair);
1498
+ }
1499
+ return;
1500
+ }
1501
+ // 7.2.1.4. Triggered Checks
1502
+ if ([iceBase_js_1.CandidatePairState.WAITING, iceBase_js_1.CandidatePairState.FAILED].includes(pair.state)) {
1503
+ pair.handle = this.checkStart(pair);
1504
+ }
1505
+ // 7.2.1.5. Updating the Nominated Flag
1506
+ if (message.attributesKeys.includes('USE-CANDIDATE') &&
1507
+ !this.iceControlling) {
1508
+ pair.remoteNominated = true;
1509
+ if (pair.state === iceBase_js_1.CandidatePairState.SUCCEEDED) {
1510
+ pair.nominated = true;
1511
+ this.checkComplete(pair);
1512
+ }
1513
+ }
1514
+ }
1515
+ tryPair(protocol, remoteCandidate) {
1516
+ if (protocol.localCandidate?.canPairWith(remoteCandidate) &&
1517
+ !(protocol.localCandidate.transport.toLowerCase() === 'tcp' &&
1518
+ protocol.localCandidate.tcptype === 'passive' &&
1519
+ remoteCandidate.type !== 'prflx') &&
1520
+ !this.findPair(protocol, remoteCandidate)) {
1521
+ const pair = new iceBase_js_1.CandidatePair(protocol, remoteCandidate, this.iceControlling);
1522
+ if (this.options.filterCandidatePair &&
1523
+ !this.options.filterCandidatePair(pair)) {
1524
+ return;
1525
+ }
1526
+ pair.updateState(iceBase_js_1.CandidatePairState.WAITING);
1527
+ this.addPair(pair);
1528
+ }
1529
+ }
1530
+ pairLocalProtocol(protocol) {
1531
+ for (const remoteCandidate of this.remoteCandidates) {
1532
+ this.tryPair(protocol, remoteCandidate);
1533
+ }
1534
+ }
1535
+ buildRequest({ nominate, remoteUsername, localUsername, iceControlling, localCandidate }) {
1536
+ const txUsername = encodeTxUsername({ remoteUsername, localUsername });
1537
+ const request = new message_js_1.Message(const_js_1.methods.BINDING, const_js_1.classes.REQUEST);
1538
+ request.setAttribute('USERNAME', txUsername).setAttribute('PRIORITY', (0, candidate_js_1.candidatePriority)('prflx', {
1539
+ transport: localCandidate?.transport,
1540
+ tcptype: localCandidate?.tcptype
1541
+ }));
1542
+ if (iceControlling) {
1543
+ request.setAttribute('ICE-CONTROLLING', this.tieBreaker);
1544
+ if (nominate) {
1545
+ request.setAttribute('USE-CANDIDATE', null);
1546
+ }
1547
+ }
1548
+ else {
1549
+ request.setAttribute('ICE-CONTROLLED', this.tieBreaker);
1550
+ }
1551
+ return request;
1552
+ }
1553
+ pruneTcpConnections(selectedPair) {
1554
+ for (const protocol of this.protocols) {
1555
+ if (protocol.localCandidate?.transport.toLowerCase() !== 'tcp') {
1556
+ continue;
1557
+ }
1558
+ if ('pruneForSelection' in protocol &&
1559
+ typeof protocol.pruneForSelection === 'function') {
1560
+ void protocol.pruneForSelection(protocol === selectedPair.protocol
1561
+ ? selectedPair.remoteAddr
1562
+ : undefined);
1563
+ }
1564
+ }
1565
+ }
1566
+ respondError(request, addr, protocol, errorCode) {
1567
+ const response = new message_js_1.Message(request.messageMethod, const_js_1.classes.ERROR, request.transactionId);
1568
+ response
1569
+ .setAttribute('ERROR-CODE', errorCode)
1570
+ .addMessageIntegrity(Buffer.from(this.localPassword, 'utf8'))
1571
+ .addFingerprint();
1572
+ protocol.sendStun(response, addr).catch((e) => {
1573
+ log('sendStun error', e);
1574
+ });
1575
+ }
1576
+ }
1577
+ exports.Connection = Connection;
1578
+ const encodeTxUsername = ({ remoteUsername, localUsername }) => {
1579
+ return `${remoteUsername}:${localUsername}`;
1580
+ };
1581
+ const decodeTxUsername = (txUsername) => {
1582
+ const [remoteUsername, localUsername] = txUsername.split(':');
1583
+ return { remoteUsername, localUsername };
1584
+ };