@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 @@
1
+ export const turnWorkerCode = "var rt=Object.defineProperty;var c=(n,e)=>rt(n,\"name\",{value:e,configurable:true});var st=require(\"node:util\");var W=require(\"node:worker_threads\");var Q;var it=new Set;function Re(n){const e=!!Q!==!!n;Q=n;if(e)for(const t of it)t(!!n)}c(Re,\"setDebugHandler\");function J(n){return(...e)=>{if(Q)Q(n,e)}}c(J,\"debug\");var je=require(\"node:crypto\");var ge=require(\"node:dgram\");var Qe=require(\"node:net\");var Je=require(\"node:os\");var Ze=require(\"node:tls\");var ot=3988292384;var ct=2197175160;function at(n){return typeof n!==\"string\"}c(at,\"isBufferLike\");function be(n){const e=new Array(256);for(let t=0;t<256;++t){let s=t;s=s&1?n^s>>>1:s>>>1;s=s&1?n^s>>>1:s>>>1;s=s&1?n^s>>>1:s>>>1;s=s&1?n^s>>>1:s>>>1;s=s&1?n^s>>>1:s>>>1;s=s&1?n^s>>>1:s>>>1;s=s&1?n^s>>>1:s>>>1;s=s&1?n^s>>>1:s>>>1;e[t]=s}return new Int32Array(e)}c(be,\"generateCRCTable\");function we(n){const e=new Int32Array(4096);let t;let s;let r;for(r=0;r<256;++r)e[r]=n[r];for(r=0;r<256;++r){s=n[r];for(t=256+r;t<4096;t+=256){s=e[t]=s>>>8^n[s&255]}}const i=[];for(r=1;r<16;++r){i[r-1]=e.subarray(r*256,r*256+256)}return i}c(we,\"generateSliceBy16Tables\");function dt(n,e,t){let s=e^-1;let r=0;const i=n.length;let o;let a;while(r<i){o=n.charCodeAt(r++);if(o<128){s=s>>>8^t[(s^o)&255]}else if(o<2048){s=s>>>8^t[(s^(192|o>>6&31))&255];s=s>>>8^t[(s^(128|o&63))&255]}else if(o>=55296&&o<57344){o=(o&1023)+64;a=n.charCodeAt(r++)&1023;s=s>>>8^t[(s^(240|o>>8&7))&255];s=s>>>8^t[(s^(128|o>>2&63))&255];s=s>>>8^t[(s^(128|a>>6&15|(o&3)<<4))&255];s=s>>>8^t[(s^(128|a&63))&255]}else{s=s>>>8^t[(s^(224|o>>12&15))&255];s=s>>>8^t[(s^(128|o>>6&63))&255];s=s>>>8^t[(s^(128|o&63))&255]}}return~s>>>0}c(dt,\"crcGenericString\");function ht(n,e,t,s){const[r,i,o,a,d,h,u,l,y,P,N,I,C,j,_]=s;let E=e^-1;let p=0;let oe=n.length-15;while(p<oe){E=_[n[p++]^E&255]^j[n[p++]^E>>>8&255]^C[n[p++]^E>>>16&255]^I[n[p++]^E>>>24]^N[n[p++]]^P[n[p++]]^y[n[p++]]^l[n[p++]]^u[n[p++]]^h[n[p++]]^d[n[p++]]^a[n[p++]]^o[n[p++]]^i[n[p++]]^r[n[p++]]^t[n[p++]]}for(oe+=15;p<oe;){E=E>>>8^t[(E^n[p++])&255]}return~E>>>0}c(ht,\"crcBuffer\");var ce=be(ot);var ut=we(ce);var lt=be(ct);var $t=we(lt);function Ie(n,e=0){if(at(n)){return ht(n,e,ce,ut)}return dt(n,e,ce)}c(Ie,\"crc32\");function G(n,e){return(...t)=>{try{const s=n(...t);if(s instanceof Promise)s.catch(e)}catch(s){e(s)}}}c(G,\"detached\");var ft=J(\"webrtc/common/transport\");var Te=4*1024*1024;function ae(n){try{if(n.getRecvBufferSize()<Te)n.setRecvBufferSize(Te)}catch(e){ft(\"the receive buffer cannot grow\",e)}}c(ae,\"growReceiveBuffer\");var de=class{static{c(this,\"BinaryWriter\")}constructor(){this.chunks=[];this.written=0}get bytes(){return this.written}writeBuffer(e){this.chunks.push(e);this.written+=e.length}writeUIntBE(e,t){const s=Buffer.allocUnsafe(t);switch(t){case 1:s.writeUInt8(e,0);break;case 2:s.writeUInt16BE(e,0);break;case 4:s.writeUInt32BE(e,0);break;default:s.writeUIntBE(e,0,t)}this.writeBuffer(s)}toBuffer(){return Buffer.concat(this.chunks,this.written)}};var Be=c(n=>typeof n===\"object\"&&n!==null,\"isObject\");var A=c(n=>Be(n)&&typeof n.encode===\"function\"&&typeof n.decode===\"function\",\"isType\");var Pe=c(n=>{if(!Be(n))return false;const e=Object.getPrototypeOf(n);return e===Object.prototype||e===null},\"isPlainObject\");var Se=c(n=>({node:n.node,current:n.current}),\"cloneContext\");var Ne=c((n,e)=>{if(!Pe(n)){throw new TypeError(e)}},\"assertSchema\");var pt=c((n,e,t,s)=>{if(A(e)){e.encode(n,t,s)}else{Ce(n,e,t,s)}},\"encodeCommon\");var Ce=c((n,e,t,s)=>{Ne(e,\"Argument `schema` should be a plain object.\");if(s.node===void 0){s.node=n}s.current=n;for(const r of Object.keys(e)){const i=e[r];const o=n[r];if(A(i)){i.encode(o,t,s)}else{Ce(o,i,t,s);s.current=n}}},\"encodeSchema\");var xe=c((n,e,t)=>{if(A(e)){return e.decode(n,t)}return De(n,e,t)},\"decodeCommon\");var De=c((n,e,t)=>{Ne(e,\"Argument #2 should be a plain object.\");const s=Object.create(null);if(t.node===void 0){t.node=s}t.current=s;for(const r of Object.keys(e)){const i=e[r];if(A(i)){s[r]=i.decode(n,t)}else{s[r]=De(n,i,t);t.current=s}}return s},\"decodeSchema\");var H=c(n=>({encode:c((e,t)=>t.writeUIntBE(e,n),\"encode\"),decode:c(e=>e.readUIntBE(n),\"decode\")}),\"createUIntBE\");var he=c(n=>{if(typeof n!==\"number\"&&!A(n)&&typeof n!==\"function\"){throw new TypeError(\"Unknown type of argument #1.\")}},\"assertLengthSpec\");var K=c((n,e,t)=>{if(n!==e){throw new Error(`${t} required length ${n} instead of ${e}`)}},\"checkLength\");var T=c((n,e)=>{if(typeof n!==\"number\"){throw new TypeError(e)}},\"checkLengthType\");function At(n){he(n);const e=\"Length of a buffer should be a number.\";return{encode(t,s,r){if(!Buffer.isBuffer(t)){throw new TypeError(\"Argument 1 should be a Buffer or a BinaryStream.\")}if(typeof n===\"number\"){K(n,t.length,\"Buffer\")}else if(A(n)){n.encode(t.length,s,r)}else{const i=n(r);T(i,e);K(i,t.length,\"Buffer\")}s.writeBuffer(t)},decode(t,s){let r;if(typeof n===\"number\"){r=n}else if(A(n)){r=n.decode(t,s)}else{r=n(s)}T(r,e);return t.readBuffer(r)}}}c(At,\"buffer\");function mt(n,e,t=\"count\"){if(!A(n)&&!Pe(n)){throw new TypeError(\"Argument #1 should be a valid type.\")}he(e);const s=t===\"bytes\";const r=\"Length of an array should be a number.\";return{encode(i,o,a){if(!Array.isArray(i)){throw new TypeError(\"Argument #1 should be an Array.\")}const d=Se(a);let h;if(typeof e===\"number\"){h=e}else if(A(e)){h=i.length}else{h=e(d);T(h,r)}const u=new de;for(const l of i){pt(l,n,u,d)}if(s){if(A(e)){h=u.bytes}K(u.bytes,h,\"Argument #1\")}else{K(h,i.length,\"Argument #1\")}if(A(e)){e.encode(h,o,d)}o.writeBuffer(u.toBuffer())},decode(i,o){const a=Se(o);let d;if(typeof e===\"number\"){d=e}else if(A(e)){d=e.decode(i,a)}else{d=e(a)}T(d,r);const h=[];if(s){const u=i.bytes;let l=0;while(l<d){h.push(xe(i,n,a));l=i.bytes-u}if(l>d){throw new Error(\"Incorrect length of an array.\")}}else{for(let u=0;u<d;u++){h.push(xe(i,n,a))}}return h}}}c(mt,\"array\");function Et(n,e=\"ascii\"){if(!Buffer.isEncoding(e)){throw new Error(\"Argument #2 should be an encoding name.\")}he(n);const t=\"Length of a buffer should be a number.\";return{encode(s,r,i){const o=Buffer.from(s.toString(),e);if(typeof n===\"number\"){if(o.length!==n){throw new Error(`Size of string should be ${n} in bytes.`)}}else if(A(n)){n.encode(o.length,r,i)}else{const a=n(i);T(a,t);K(a,o.length,\"Buffer\")}r.writeBuffer(o)},decode(s,r){let i;if(typeof n===\"number\"){i=n}else if(A(n)){i=n.decode(s,r);T(i,\"Size of a string should be a number.\")}else{i=n(r);T(i,t)}return s.readBuffer(i).toString(e)}}}c(Et,\"string\");var ls={uint8:H(1),uint16be:H(2),uint24be:H(3),uint32be:H(4),uint48be:H(6),buffer:At,array:mt,string:Et};var Y=require(\"node:crypto\");var D=554869826;var Oe=8;var ke=1398035790;var R=20;var ue=24;var le=1;var fe=2;var m;(function(n){n[n[\"REQUEST\"]=0]=\"REQUEST\";n[n[\"INDICATION\"]=16]=\"INDICATION\";n[n[\"RESPONSE\"]=256]=\"RESPONSE\";n[n[\"ERROR\"]=272]=\"ERROR\"})(m||(m={}));var f;(function(n){n[n[\"BINDING\"]=1]=\"BINDING\";n[n[\"SHARED_SECRET\"]=2]=\"SHARED_SECRET\";n[n[\"ALLOCATE\"]=3]=\"ALLOCATE\";n[n[\"REFRESH\"]=4]=\"REFRESH\";n[n[\"SEND\"]=6]=\"SEND\";n[n[\"DATA\"]=7]=\"DATA\";n[n[\"CREATE_PERMISSION\"]=8]=\"CREATE_PERMISSION\";n[n[\"CHANNEL_BIND\"]=9]=\"CHANNEL_BIND\"})(f||(f={}));function Z(n){return n>=0&&n<=32767}c(Z,\"isComprehensionRequiredAttribute\");function O(n){if(n.length<R){return false}if((n[0]&192)!==0){return false}if(n.readUInt32BE(4)!==D){return false}const e=n.readUInt16BE(2);if(e%4!==0){return false}return n.length===R+e}c(O,\"isStunMessage\");var k=require(\"node:net\");function pe(n){if((0,k.isIPv4)(n)){const r=Buffer.allocUnsafe(4);const i=n.split(\".\");for(let o=0;o<4;o++){r[o]=Number(i[o])&255}return r}if(!(0,k.isIPv6)(n)){throw new Error(`Invalid ip address: ${n}`)}const e=n.split(\":\",8);for(let r=0;r<e.length;r++){let i;if((0,k.isIPv4)(e[r])){i=pe(e[r]);e[r]=i.subarray(0,2).toString(\"hex\")}if(i&&++r<8){e.splice(r,0,i.subarray(2,4).toString(\"hex\"))}}if(e[0]===\"\"){while(e.length<8)e.unshift(\"0\")}else if(e[e.length-1]===\"\"){while(e.length<8)e.push(\"0\")}else if(e.length<8){let r=0;for(;r<e.length&&e[r]!==\"\";r++);const i=[];for(let o=9-e.length;o>0;o--){i.push(\"0\")}e.splice(r,1,...i)}const t=Buffer.allocUnsafe(16);let s=0;for(const r of e){const i=Number.parseInt(r,16)||0;t[s++]=i>>8&255;t[s++]=i&255}return t}c(pe,\"ipAddressToBuffer\");function Ae(n){if(n.length===4){return`${n[0]}.${n[1]}.${n[2]}.${n[3]}`}if(n.length!==16){throw new Error(`Invalid ip address buffer length: ${n.length}`)}const e=[];for(let s=0;s<16;s+=2){e.push(n.readUInt16BE(s).toString(16))}let t=e.join(\":\");t=t.replace(/(^|:)0(:0)*:0(:|$)/,\"$1::$3\");t=t.replace(/:{3,4}/,\"::\");return t}c(Ae,\"bufferToIpAddress\");function Ue(n){return(0,k.isIPv4)(n)}c(Ue,\"isIpV4Address\");function S(n){const[e]=n;const t=Ue(e)?le:fe;const s=Buffer.alloc(4);s.writeUInt8(0,0);s.writeUInt8(t,1);s.writeUInt16BE(n[1],2);return Buffer.concat([s,pe(e)])}c(S,\"packAddress\");function gt(n){if(n.length<4){throw new Error(\"STUN error code is less than 4 bytes\")}const e=n.readUInt8(2);const t=n.readUInt8(3);const s=n.slice(4).toString(\"utf8\");return[e*100+t,s]}c(gt,\"unpackErrorCode\");function x(n){if(n.length<4){throw new Error(\"STUN address length is less than 4 bytes\")}const e=n.readUInt8(1);const t=n.readUInt16BE(2);const s=n.slice(4);switch(e){case le:if(s.length!==4){throw new Error(\"STUN address has invalid length for IPv4\")}return[Ae(s),t];case fe:if(s.length!==16){throw new Error(\"STUN address has invalid length for IPv6\")}return[Ae(s),t];default:throw new Error(\"STUN address has unknown protocol\")}}c(x,\"unpackAddress\");var me=Buffer.alloc(6);me.writeUInt16BE(D>>16,0);me.writeUInt32BE(D,2);function ve(n,e){const t=[...me,...e];let s=n.slice(0,2);for(let r=2;r<n.length;r++){const i=n[r]^t[r-2];const o=Buffer.alloc(1);o.writeUIntBE(i,0,1);s=Buffer.concat([s,o])}return s}c(ve,\"xorAddress\");function q(n,e){return x(ve(n,e))}c(q,\"unpackXorAddress\");function Rt(n){const e=Buffer.alloc(4);e.writeUInt16BE(0,0);e.writeUInt8(Math.floor(n[0]/100),2);e.writeUInt8(n[0]%100,3);const t=Buffer.from(n[1],\"utf8\");return Buffer.concat([e,t])}c(Rt,\"packErrorCode\");function bt(n){const e=Buffer.alloc(n.length*2);n.forEach((t,s)=>{e.writeUInt16BE(t,s*2)});return e}c(bt,\"packUnknownAttributes\");function wt(n){if(n.length%2!==0){throw new Error(\"UNKNOWN-ATTRIBUTES must have an even length\")}const e=[];for(let t=0;t<n.length;t+=2){e.push(n.readUInt16BE(t))}return e}c(wt,\"unpackUnknownAttributes\");function z(n,e){return ve(S(n),e)}c(z,\"packXorAddress\");var U=c(n=>{const e=Buffer.alloc(4);e.writeUInt32BE(n,0);return e},\"packUnsigned\");var L=c(n=>n.readUInt32BE(0),\"unpackUnsigned\");var It=c(n=>{const e=Buffer.alloc(4);e.writeUInt16BE(n,0);return e},\"packUnsignedShort\");var Tt=c(n=>n.readUInt16BE(0),\"unpackUnsignedShort\");var Le=c(n=>{const e=Buffer.allocUnsafe(8);e.writeBigUInt64BE(n,0);return e},\"packUnsigned64\");var Me=c(n=>n.readBigUInt64BE(0),\"unpackUnsigned64\");var te=c(n=>Buffer.from(n,\"utf8\"),\"packString\");var ee=c(n=>n.toString(\"utf8\"),\"unpackString\");var St=c(n=>{if([...n].length>=128){throw new Error(\"SOFTWARE must be shorter than 128 characters\")}return te(n)},\"packSoftware\");var b=c(n=>n,\"packBytes\");var w=c(n=>n,\"unpackBytes\");var xt=c(()=>Buffer.alloc(0),\"packNone\");var Bt=c(()=>null,\"unpackNone\");var Fe=[[1,\"MAPPED-ADDRESS\",S,x],[3,\"CHANGE-REQUEST\",U,L],[4,\"SOURCE-ADDRESS\",S,x],[5,\"CHANGED-ADDRESS\",S,x],[6,\"USERNAME\",te,ee],[8,\"MESSAGE-INTEGRITY\",b,w],[9,\"ERROR-CODE\",Rt,gt],[10,\"UNKNOWN-ATTRIBUTES\",bt,wt],[12,\"CHANNEL-NUMBER\",It,Tt],[13,\"LIFETIME\",U,L],[18,\"XOR-PEER-ADDRESS\",z,q],[19,\"DATA\",b,w],[20,\"REALM\",te,ee],[21,\"NONCE\",b,w],[22,\"XOR-RELAYED-ADDRESS\",z,q],[23,\"REQUESTED-ADDRESS-FAMILY\",U,L],[24,\"EVEN-PORT\",b,w],[25,\"REQUESTED-TRANSPORT\",U,L],[28,\"MESSAGE-INTEGRITY-SHA256\",b,w],[29,\"PASSWORD-ALGORITHM\",b,w],[30,\"USERHASH\",b,w],[32,\"XOR-MAPPED-ADDRESS\",z,q],[34,\"RESERVATION-TOKEN\",b,w],[36,\"PRIORITY\",U,L],[37,\"USE-CANDIDATE\",xt,Bt],[32770,\"PASSWORD-ALGORITHMS\",b,w],[32771,\"ALTERNATE-DOMAIN\",te,ee],[32802,\"SOFTWARE\",St,ee],[32803,\"ALTERNATE-SERVER\",S,x],[32808,\"FINGERPRINT\",U,L],[32809,\"ICE-CONTROLLED\",Le,Me],[32810,\"ICE-CONTROLLING\",Le,Me],[32811,\"RESPONSE-ORIGIN\",S,x],[32812,\"OTHER-ADDRESS\",S,x]];var V=class{static{c(this,\"AttributeRepository\")}constructor(e=[]){this.attributes=e}getAttributes(){return this.attributes}setAttribute(e,t){const s=this.attributes.find(r=>r[0]===e);if(s){s[1]=t}else{this.attributes.push([e,t])}return this}getAttributeValue(e){const t=this.attributes.find(s=>s[0]===e);return t?.[1]}get attributesKeys(){return this.attributes.map(e=>e[0])}removeAttribute(e){this.attributes=this.attributes.filter(t=>t[0]!==e);return this}clear(){this.attributes=[]}};var _e=Fe.reduce((n,e)=>{n[e[0]]=e;return n},{});var Ge=Fe.reduce((n,e)=>{n[e[1]]=e;return n},{});function $(n,e){if(!O(n)){return void 0}const t=n.readUInt16BE(0);const s=Buffer.from(n.slice(R-12,R));const r=new V;const i=[];let o=false;for(let a=R;a<n.length;){if(a+4>n.length){return void 0}const d=n.readUInt16BE(a);const h=n.readUInt16BE(a+2);const u=a+4;const l=u+h;if(l>n.length){return void 0}const y=n.slice(u,l);const P=M(h);if(l+P>n.length){return void 0}const N=_e[d];if(N){const[,I,,C]=N;let j;try{j=C.name===q.name?C(y,s):C(y)}catch{return void 0}r.setAttribute(I,j);if(I===\"FINGERPRINT\"){const _=He(n.slice(0,a));if(r.getAttributeValue(\"FINGERPRINT\")!==_){return void 0}}else if(I===\"MESSAGE-INTEGRITY\"&&e){const _=Nt(n.slice(0,a),e);const E=r.getAttributeValue(\"MESSAGE-INTEGRITY\");if(!_.equals(E)){return void 0}o=true}}else{i.push({type:d,length:h,value:Buffer.from(y)})}a=l+P}if(e&&!o){return void 0}return new g(t&16111,t&272,s,r.getAttributes(),i)}c($,\"parseMessage\");var g=class extends V{static{c(this,\"Message\")}constructor(e,t,s=(0,Y.randomBytes)(12),r=[],i=[]){super(r);this.messageMethod=e;this.messageClass=t;this.transactionId=s;this.rawAttributes=i}toJSON(){return this.json}get json(){return{messageMethod:this.messageMethod,messageClass:this.messageClass,attributes:this.attributes,rawAttributes:this.rawAttributes.map(e=>({type:e.type,length:e.value.length}))}}get transactionIdHex(){return this.transactionId.toString(\"hex\")}appendRawAttribute(e,t){this.rawAttributes.push({type:e,value:Buffer.from(t)});return this}get unknownAttributeTypes(){return this.rawAttributes.map(e=>e.type)}get bytes(){const e=Buffer.concat(this.serializedAttributes.map(s=>Pt(s.type,s.value)));const t=Buffer.alloc(8);t.writeUInt16BE(this.messageMethod|this.messageClass,0);t.writeUInt16BE(e.length,2);t.writeUInt32BE(D,4);return Buffer.concat([t,this.transactionId,e])}addMessageIntegrity(e){this.removeAttribute(\"FINGERPRINT\").removeAttribute(\"MESSAGE-INTEGRITY\");this.setAttribute(\"MESSAGE-INTEGRITY\",this.messageIntegrity(e));return this}messageIntegrity(e){const t=Ee(this.bytes,this.bytes.length-R+ue);return Buffer.from((0,Y.createHmac)(\"sha1\",e).update(t).digest(\"hex\"),\"hex\")}addFingerprint(){this.removeAttribute(\"FINGERPRINT\");this.setAttribute(\"FINGERPRINT\",He(this.bytes));return this}get serializedAttributes(){const e=[];for(const t of this.attributesKeys){const s=this.getAttributeValue(t);const[r,,i]=Ge[t];const o=i.name===z.name?i(s,this.transactionId):i(s);e.push({type:r,value:o})}e.push(...this.rawAttributes.map(t=>({type:t.type,value:Buffer.from(t.value)})));return e}};function Pt(n,e){const t=e.length;const s=M(t);const r=Buffer.alloc(4);r.writeUInt16BE(n,0);r.writeUInt16BE(t,2);return Buffer.concat([r,e,Buffer.alloc(s)])}c(Pt,\"serializeAttribute\");var Ee=c((n,e)=>{const t=Buffer.alloc(n.length);n.copy(t,0,0,2);t.writeUInt16BE(e,2);n.copy(t,4,4);return t},\"setBodyLength\");function He(n){const e=Ee(n,n.length-R+Oe);return(Ie(e)^ke)>>>0}c(He,\"messageFingerprint\");function Nt(n,e){const t=Ee(n,n.length-R+ue);return Buffer.from((0,Y.createHmac)(\"sha1\",e).update(t).digest(\"hex\"),\"hex\")}c(Nt,\"messageIntegrity\");function M(n){const e=n%4;return e===0?0:4-e}c(M,\"paddingLength\");function v(n){return n.length>=4&&(n[0]&192)===64}c(v,\"isChannelData\");function Ke(n,e){const t=Buffer.alloc(4);t.writeUInt16BE(n,0);t.writeUInt16BE(e.length,2);return Buffer.concat([t,e])}c(Ke,\"encodeChannelData\");function qe(n){if(!v(n)||n.length<4){return void 0}const e=n.readUInt16BE(0);const t=n.readUInt16BE(2);if(n.length<4+t){return void 0}return{channelNumber:e,data:n.subarray(4,4+t)}}c(qe,\"decodeChannelData\");function ye(n){const e=M(n.length);return e>0?Buffer.concat([n,Buffer.alloc(e)]):n}c(ye,\"padTurnFrame\");function ze(n){const e=[];let t=0;let s=false;while(n.length-t>=4){let r;if(v(n.subarray(t))){const i=n.readUInt16BE(t+2);r=4+i+M(i)}else if((n[t]&192)===0){if(n.length-t<20){break}const i=n.readUInt16BE(t+2);r=20+i+M(i)}else{s=true;break}if(n.length-t<r){break}e.push(n.subarray(t,t+r));t+=r}return{frames:e,malformed:s,rest:n.subarray(t)}}c(ze,\"splitTurnTcpFrames\");var X=require(\"node:crypto\");var se=class{static{c(this,\"StunServerProtocol\")}constructor(e={}){this.software=e.software;this.fingerprint=e.fingerprint??\"if-present\";this.authenticateRequest=e.authenticateRequest}handleDatagram(e){if(!O(e.data)){return[{type:\"ignore\",reason:\"non-stun\"}]}const t=$(e.data);if(!t){return[{type:\"ignore\",reason:\"malformed\"}]}if(t.messageClass===m.INDICATION){return[{type:\"ignore\",reason:\"binding-indication\"}]}if(t.messageClass!==m.REQUEST){return[{type:\"ignore\",reason:\"non-request\"}]}const s={...e,message:t};const r=[...new Set(t.unknownAttributeTypes.filter(Z))].sort((o,a)=>o-a);if(r.length>0){return[this.sendAction(this.errorResponse(s,420,\"Unknown Attribute\",[[\"UNKNOWN-ATTRIBUTES\",r]]),e.remoteAddress)]}if(t.messageMethod!==f.BINDING){return[this.sendAction(this.errorResponse(s,400,\"Bad Request\"),e.remoteAddress)]}const i=this.authenticateRequest?.(s);if(i?.ok===false){return[this.sendAction(this.errorResponse(s,i.errorCode,i.reason,i.attributes),e.remoteAddress)]}return[this.sendAction(this.successResponse(s,i?.attributes),e.remoteAddress)]}sendAction(e,t){return{type:\"send\",data:e.bytes,remoteAddress:t}}successResponse(e,t=[]){const s=new g(f.BINDING,m.RESPONSE,e.message.transactionId);s.setAttribute(\"XOR-MAPPED-ADDRESS\",e.remoteAddress);this.addDefaultAttributes(s,e,t);return s}errorResponse(e,t,s,r=[]){const i=new g(e.message.messageMethod,m.ERROR,e.message.transactionId);i.setAttribute(\"ERROR-CODE\",[t,s]);this.addDefaultAttributes(i,e,r);return i}addDefaultAttributes(e,t,s){for(const[r,i]of s){e.setAttribute(r,i)}if(this.software){e.setAttribute(\"SOFTWARE\",this.software)}if(this.shouldAddFingerprint(t.message)){e.addFingerprint()}}shouldAddFingerprint(e){switch(this.fingerprint){case\"always\":return true;case\"if-present\":return e.getAttributeValue(\"FINGERPRINT\")!==void 0;default:return false}}};var Ve=require(\"node:crypto\");function Ye(n,e,t){return(0,Ve.createHash)(\"md5\").update(Buffer.from([n,e,t].join(\":\"))).digest()}c(Ye,\"makeTurnIntegrityKey\");var Ct=600;var Dt=300;var Ot=600;var kt=3600;var Ut=256;var Lt=17;var re=class{static{c(this,\"TurnServerProtocol\")}constructor(e={}){this.allocations=new Map;this.allocationIdByClientId=new Map;this.allocationIdByRelayId=new Map;this.nonces=new Map;this.tcpBuffers=new Map;this.realm=e.realm??\"lakutata\";this.software=e.software;this.fingerprint=e.fingerprint??\"if-present\";this.allocationLifetime=e.allocationLifetime??Ct;this.permissionLifetime=e.permissionLifetime??Dt;this.channelLifetime=e.channelLifetime??Ot;this.nonceLifetime=e.nonceLifetime??kt;this.maxAllocations=e.maxAllocations??Ut;this.allocationGate=e.allocationGate;this.getPassword=e.getPassword??(()=>void 0);this.nowProvider=e.now;this.bindingProtocol=new se({software:this.software,fingerprint:this.fingerprint})}get allocationCount(){return this.allocations.size}get nextTimeoutAt(){return this.computeNextTimeoutAt()}handleClientDatagram(e){if(v(e.data))return this.handleChannelData(e,this.now());return this.finalizeActions(this.handleClientPacket(e))}handleTcpChunk(e){const t=this.now();const s=[];const r=Buffer.concat([this.tcpBuffers.get(e.clientId)??Buffer.alloc(0),e.data]);const{frames:i,malformed:o,rest:a}=ze(r);if(o){this.tcpBuffers.delete(e.clientId);s.push({type:\"close-client\",clientId:e.clientId});return this.finalizeActions(s,t)}this.tcpBuffers.set(e.clientId,a);let d=false;for(const h of i){const u={clientId:e.clientId,data:h,remoteAddress:e.remoteAddress,localAddress:e.localAddress,transport:e.transport};if(v(h)){s.push(...this.handleChannelData(u,t));continue}d=true;s.push(...this.handleClientPacket(u))}return d?this.finalizeActions(s,t):s}handleRelayPacket(e){const t=this.now();const s=[];const r=this.liveAllocation(this.getRelayAllocation(e.relayId),t,s);if(!r||!r.relayedAddress){s.push({type:\"ignore\",reason:\"unknown-relay\"});return s}const i=this.getChannelBinding(r,e.remoteAddress,t);const o=this.getPermission(r,e.remoteAddress,t);if(!i&&!o){s.push({type:\"ignore\",reason:\"unknown-channel\"});return s}const a=i?Ke(i.number,e.data):new g(f.DATA,m.INDICATION).setAttribute(\"XOR-PEER-ADDRESS\",e.remoteAddress).setAttribute(\"DATA\",e.data).bytes;s.push(this.sendClient(r.client,a));return s}handleRelayBound(e){const t=this.now();const s=this.cleanupExpired(t);const r=this.allocations.get(e.allocationId);if(!r||r.relayId!==e.relayId){s.push({type:\"ignore\",reason:\"unknown-relay\"});return this.finalizeActions(s,t)}if(!r.pendingAllocate){s.push({type:\"ignore\",reason:\"unknown-relay\"});return this.finalizeActions(s,t)}r.relayedAddress=e.relayedAddress;r.expiresAt=t+r.lifetime*1e3;const i=r.pendingAllocate;r.pendingAllocate=void 0;const o=this.successResponse(i.message,f.ALLOCATE,[[\"XOR-RELAYED-ADDRESS\",e.relayedAddress],[\"XOR-MAPPED-ADDRESS\",r.mappedAddress],[\"LIFETIME\",r.lifetime]],i.integrityKey);s.push(this.sendClient(i.client,o.bytes));return this.finalizeActions(s,t)}handleRelayBindFailure(e){const t=this.now();const s=this.cleanupExpired(t);const r=this.allocations.get(e.allocationId);if(!r?.pendingAllocate){s.push({type:\"ignore\",reason:\"unknown-relay\"});return this.finalizeActions(s,t)}const i=r.pendingAllocate;this.deleteAllocation(r);const o=this.errorResponse(i.message,e.errorCode??508,e.reason??\"Insufficient Capacity\",[],i.integrityKey);s.push(this.sendClient(i.client,o.bytes));return this.finalizeActions(s,t)}handleClientClosed(e){const t=this.now();const s=this.cleanupExpired(t);this.tcpBuffers.delete(e.clientId);const r=this.getClientAllocation(e.clientId);if(r){s.push(...this.deleteAllocation(r))}return this.finalizeActions(s,t)}handleTimer(e=this.now()){return this.finalizeActions(this.cleanupExpired(e),e)}handleClientPacket(e){const t=this.now();if(v(e.data))return this.handleChannelData(e,t);const s=this.cleanupExpired(t);if(!O(e.data)){s.push({type:\"ignore\",reason:\"non-stun\"});return s}const r=$(e.data);if(!r){s.push({type:\"ignore\",reason:\"malformed\"});return s}if(r.messageClass===m.INDICATION){if(r.messageMethod===f.BINDING){s.push({type:\"ignore\",reason:\"binding-indication\"});return s}if(r.messageMethod!==f.SEND){s.push({type:\"ignore\",reason:\"unsupported-indication\"});return s}return[...s,...this.handleSendIndication(e,r,t)]}if(r.messageClass!==m.REQUEST){s.push({type:\"ignore\",reason:\"non-request\"});return s}const i=[...new Set(r.unknownAttributeTypes.filter(Z))].sort((o,a)=>o-a);if(i.length>0){s.push(this.sendClient(this.clientEndpoint(e),this.errorResponse(r,420,\"Unknown Attribute\",[[\"UNKNOWN-ATTRIBUTES\",i]]).bytes));return s}if(r.messageMethod===f.BINDING){return[...s,...this.handleBindingRequest(e)]}switch(r.messageMethod){case f.ALLOCATE:return[...s,...this.handleAllocateRequest(e,r,t)];case f.REFRESH:return[...s,...this.handleRefreshRequest(e,r,t)];case f.CREATE_PERMISSION:return[...s,...this.handleCreatePermissionRequest(e,r,t)];case f.CHANNEL_BIND:return[...s,...this.handleChannelBindRequest(e,r,t)];default:s.push(this.sendClient(this.clientEndpoint(e),this.errorResponse(r,400,\"Bad Request\").bytes));return s}}handleBindingRequest(e){const t=this.bindingProtocol.handleDatagram(e);return t.map(s=>this.mapBindingAction(e,s))}handleAllocateRequest(e,t,s){const r=this.authenticateRequest(e,t,f.ALLOCATE);if(\"response\"in r){return[this.sendClient(this.clientEndpoint(e),r.response.bytes)]}const i=t.getAttributeValue(\"REQUESTED-TRANSPORT\");if(i===void 0){return[this.sendClient(r,this.errorResponse(t,400,\"Bad Request\",[],r.integrityKey).bytes)]}if(i>>>24!==Lt){return[this.sendClient(r,this.errorResponse(t,442,\"Unsupported Transport Protocol\",[],r.integrityKey).bytes)]}const o=t.getAttributeValue(\"REQUESTED-ADDRESS-FAMILY\");if(o!==void 0&&o!==1){return[this.sendClient(r,this.errorResponse(t,440,\"Address Family not Supported\",[],r.integrityKey).bytes)]}if(t.getAttributeValue(\"EVEN-PORT\")!==void 0||t.getAttributeValue(\"RESERVATION-TOKEN\")!==void 0){return[this.sendClient(r,this.errorResponse(t,508,\"Insufficient Capacity\",[],r.integrityKey).bytes)]}if(this.getClientAllocation(e.clientId)){return[this.sendClient(r,this.errorResponse(t,437,\"Allocation Mismatch\",[],r.integrityKey).bytes)]}if(this.allocationGate?!this.allocationGate.reserve():this.allocations.size>=this.maxAllocations){return[this.sendClient(r,this.errorResponse(t,486,\"Allocation Quota Reached\",[],r.integrityKey).bytes)]}const a=(0,X.randomUUID)();const d=(0,X.randomUUID)();const h={id:a,relayId:d,username:r.username,integrityKey:r.integrityKey,client:this.clientEndpoint(r),mappedAddress:r.remoteAddress,lifetime:this.clampLifetime(t.getAttributeValue(\"LIFETIME\")),pendingAllocate:{client:this.clientEndpoint(r),integrityKey:r.integrityKey,message:t},permissions:new Map,channelsByNumber:new Map,channelsByPeer:new Map};this.allocations.set(a,h);this.allocationIdByClientId.set(r.clientId,a);this.allocationIdByRelayId.set(d,a);return[{type:\"bind-relay\",allocationId:a,relayId:d}]}handleRefreshRequest(e,t,s){const r=this.authenticateRequest(e,t,f.REFRESH);if(\"response\"in r){return[this.sendClient(this.clientEndpoint(e),r.response.bytes)]}const i=this.getClientAllocation(e.clientId);if(!i||i.username!==r.username){return[this.sendClient(r,this.errorResponse(t,437,\"Allocation Mismatch\",[],r.integrityKey).bytes)]}const o=t.getAttributeValue(\"LIFETIME\");if(o===0){const d=this.deleteAllocation(i);const h=this.successResponse(t,f.REFRESH,[[\"LIFETIME\",0]],r.integrityKey);return[this.sendClient(r,h.bytes),...d]}i.lifetime=this.clampLifetime(o);i.expiresAt=s+i.lifetime*1e3;const a=Math.max(0,Math.floor((i.expiresAt-s)/1e3));return[this.sendClient(r,this.successResponse(t,f.REFRESH,[[\"LIFETIME\",a]],r.integrityKey).bytes)]}handleCreatePermissionRequest(e,t,s){const r=this.authenticateRequest(e,t,f.CREATE_PERMISSION);if(\"response\"in r){return[this.sendClient(this.clientEndpoint(e),r.response.bytes)]}const i=this.getClientAllocation(e.clientId);if(!i||i.username!==r.username){return[this.sendClient(r,this.errorResponse(t,437,\"Allocation Mismatch\",[],r.integrityKey).bytes)]}const o=t.getAttributeValue(\"XOR-PEER-ADDRESS\");if(!o){return[this.sendClient(r,this.errorResponse(t,400,\"Bad Request\",[],r.integrityKey).bytes)]}if(!Xe(e.remoteAddress,o)){return[this.sendClient(r,this.errorResponse(t,443,\"Peer Address Family Mismatch\",[],r.integrityKey).bytes)]}this.setPermission(i,o,s);return[this.sendClient(r,this.successResponse(t,f.CREATE_PERMISSION,[],r.integrityKey).bytes)]}handleChannelBindRequest(e,t,s){const r=this.authenticateRequest(e,t,f.CHANNEL_BIND);if(\"response\"in r){return[this.sendClient(this.clientEndpoint(e),r.response.bytes)]}const i=this.getClientAllocation(e.clientId);if(!i||i.username!==r.username){return[this.sendClient(r,this.errorResponse(t,437,\"Allocation Mismatch\",[],r.integrityKey).bytes)]}const o=t.getAttributeValue(\"CHANNEL-NUMBER\");const a=t.getAttributeValue(\"XOR-PEER-ADDRESS\");if(!o||!a){return[this.sendClient(r,this.errorResponse(t,400,\"Bad Request\",[],r.integrityKey).bytes)]}if(o<16384||o>32767){return[this.sendClient(r,this.errorResponse(t,400,\"Bad Request\",[],r.integrityKey).bytes)]}if(!Xe(e.remoteAddress,a)){return[this.sendClient(r,this.errorResponse(t,443,\"Peer Address Family Mismatch\",[],r.integrityKey).bytes)]}const d=ne(a);const h=i.channelsByNumber.get(o);if(h&&ne(h.peerAddress)!==d){return[this.sendClient(r,this.errorResponse(t,400,\"Bad Request\",[],r.integrityKey).bytes)]}const u=i.channelsByPeer.get(d);if(u&&u.number!==o){return[this.sendClient(r,this.errorResponse(t,400,\"Bad Request\",[],r.integrityKey).bytes)]}this.setPermission(i,a,s);const l={peerAddress:a,number:o,expiresAt:s+this.channelLifetime*1e3};i.channelsByNumber.set(l.number,l);i.channelsByPeer.set(d,l);return[this.sendClient(r,this.successResponse(t,f.CHANNEL_BIND,[],r.integrityKey).bytes)]}handleSendIndication(e,t,s){const r=this.getClientAllocation(e.clientId);if(!r){return[{type:\"ignore\",reason:\"unknown-client\"}]}const i=t.getAttributeValue(\"XOR-PEER-ADDRESS\");const o=t.getAttributeValue(\"DATA\");if(!i||!Buffer.isBuffer(o)){return[{type:\"ignore\",reason:\"malformed\"}]}if(!this.getPermission(r,i,s)){return[{type:\"ignore\",reason:\"unknown-channel\"}]}return[{type:\"send-relay\",relayId:r.relayId,remoteAddress:i,data:o}]}authenticateRequest(e,t,s){const r=t.getAttributeValue(\"USERNAME\");const i=t.getAttributeValue(\"REALM\");const o=t.getAttributeValue(\"NONCE\");const a=t.getAttributeValue(\"MESSAGE-INTEGRITY\");if(!r||i!==this.realm||!o||!a){return{response:this.unauthorizedResponse(t,401,\"Unauthorized\")}}const d=this.nonces.get(o.toString(\"hex\"));if(!d||d.expiresAt<=this.now()){return{response:this.unauthorizedResponse(t,438,\"Stale Nonce\")}}const h=s===f.ALLOCATE?void 0:this.getClientAllocation(e.clientId);let u=h&&h.username===r?h.integrityKey:void 0;if(!u){const y=this.getPassword(r,this.realm);if(!y){return{response:this.unauthorizedResponse(t,401,\"Unauthorized\")}}u=Ye(r,this.realm,y)}const l=$(e.data,u);if(!l||l.messageMethod!==s){return{response:this.unauthorizedResponse(t,401,\"Unauthorized\")}}return{...e,integrityKey:u,message:l,username:r}}unauthorizedResponse(e,t,s){return this.errorResponse(e,t,s,[[\"REALM\",this.realm],[\"NONCE\",this.issueNonce()]])}successResponse(e,t,s=[],r){const i=new g(t,m.RESPONSE,e.transactionId);this.addResponseAttributes(i,e,s,r);return i}errorResponse(e,t,s,r=[],i){const o=new g(e.messageMethod,m.ERROR,e.transactionId);o.setAttribute(\"ERROR-CODE\",[t,s]);this.addResponseAttributes(o,e,r,i);return o}addResponseAttributes(e,t,s,r){for(const[i,o]of s){e.setAttribute(i,o)}if(this.software){e.setAttribute(\"SOFTWARE\",this.software)}if(r){e.addMessageIntegrity(r)}if(this.shouldAddFingerprint(t)){e.addFingerprint()}}shouldAddFingerprint(e){switch(this.fingerprint){case\"always\":return true;case\"if-present\":return e.getAttributeValue(\"FINGERPRINT\")!==void 0;default:return false}}issueNonce(){const e=(0,X.randomBytes)(16);this.nonces.set(e.toString(\"hex\"),{value:e,expiresAt:this.now()+this.nonceLifetime*1e3});return e}sendClient(e,t){return{type:\"send-client\",clientId:e.clientId,transport:e.transport,remoteAddress:e.remoteAddress,data:t}}mapBindingAction(e,t){if(t.type===\"send\"){return this.sendClient(this.clientEndpoint(e),t.data)}return t}clientEndpoint(e){return{clientId:e.clientId,transport:e.transport,remoteAddress:e.remoteAddress,localAddress:e.localAddress}}handleChannelData(e,t){const s=[];const r=qe(e.data);if(!r){s.push({type:\"ignore\",reason:\"malformed\"});return s}const i=this.liveAllocation(this.getClientAllocation(e.clientId),t,s);if(!i){s.push({type:\"ignore\",reason:\"unknown-client\"});return s}const o=i.channelsByNumber.get(r.channelNumber);if(!o||o.expiresAt<=t){if(o){this.removeChannelBinding(i,o)}s.push({type:\"ignore\",reason:\"unknown-channel\"});return s}s.push({type:\"send-relay\",relayId:i.relayId,remoteAddress:o.peerAddress,data:r.data});return s}liveAllocation(e,t,s){if(e?.expiresAt!==void 0&&e.expiresAt<=t){s.push(...this.deleteAllocation(e));return void 0}return e}getClientAllocation(e){const t=this.allocationIdByClientId.get(e);return t?this.allocations.get(t):void 0}getRelayAllocation(e){const t=this.allocationIdByRelayId.get(e);return t?this.allocations.get(t):void 0}setPermission(e,t,s){e.permissions.set($e(t),{peerAddress:t,expiresAt:s+this.permissionLifetime*1e3})}getPermission(e,t,s){const r=$e(t);const i=e.permissions.get(r);if(!i){return void 0}if(i.expiresAt<=s){e.permissions.delete(r);return void 0}return i}getChannelBinding(e,t,s){const r=ne(t);const i=e.channelsByPeer.get(r);if(!i){return void 0}if(i.expiresAt<=s){this.removeChannelBinding(e,i);return void 0}return i}removeChannelBinding(e,t){e.channelsByNumber.delete(t.number);e.channelsByPeer.delete(ne(t.peerAddress))}deleteAllocation(e){if(this.allocations.delete(e.id))this.allocationGate?.release();this.allocationIdByClientId.delete(e.client.clientId);this.allocationIdByRelayId.delete(e.relayId);return[{type:\"close-relay\",relayId:e.relayId}]}cleanupExpired(e){const t=[];for(const[s,r]of[...this.nonces]){if(r.expiresAt<=e){this.nonces.delete(s)}}for(const s of[...this.allocations.values()]){if(s.expiresAt&&s.expiresAt<=e){t.push(...this.deleteAllocation(s));continue}for(const[r,i]of[...s.permissions]){if(i.expiresAt<=e){s.permissions.delete(r)}}for(const r of[...s.channelsByNumber.values()]){if(r.expiresAt<=e){this.removeChannelBinding(s,r)}}}return t}computeNextTimeoutAt(){let e;for(const t of this.nonces.values()){e=e===void 0?t.expiresAt:Math.min(e,t.expiresAt)}for(const t of this.allocations.values()){if(t.expiresAt!==void 0){e=e===void 0?t.expiresAt:Math.min(e,t.expiresAt)}for(const s of t.permissions.values()){e=e===void 0?s.expiresAt:Math.min(e,s.expiresAt)}for(const s of t.channelsByNumber.values()){e=e===void 0?s.expiresAt:Math.min(e,s.expiresAt)}}return e}finalizeActions(e,t=this.now()){const s=this.computeNextTimeoutAt();if(s!==void 0){e.push({type:\"schedule-timeout\",at:Math.max(t,s)})}return e}clampLifetime(e){if(!e||e<=0){return this.allocationLifetime}return Math.min(e,this.allocationLifetime)}now(){return this.nowProvider?.()??Date.now()}};function ne(n){return`${n[0]}:${n[1]}`}c(ne,\"addressKey\");function $e(n){return n[0]}c($e,\"permissionKey\");function Xe(n,e){return We(n[0])===We(e[0])}c(Xe,\"hasSameAddressFamily\");function We(n){return n.includes(\":\")}c(We,\"isIpv6Address\");var F=J(\"webrtc/turn/server\");var ie=class{static{c(this,\"NodeTurnServer\")}constructor(e={}){this.tcpConnections=new Map;this.tlsConnections=new Map;this.relaySockets=new Map;this.relayBoundByPort=new Map;this.relayPorts=new Map;this.closed=false;const{host:t=\"0.0.0.0\",port:s=3478,relayAddress:r=t===\"0.0.0.0\"?\"127.0.0.1\":t,relayBindAddress:i=t,relayPortRange:o,udp:a=true,tcp:d=true,credentials:h,tls:u,getPassword:l,software:y=\"lakutata-webrtc\",reusePort:P=false,...N}=e;this.reusePort=P;this.host=t;this.port=s;this.udpEnabled=a;this.tcpEnabled=d;this.tlsEnabled=u!==void 0;this.tlsExternal=Boolean(u?.external);this.tlsOptions=u;this.tlsPort=u?.port??(s===0?0:5349);this.relayAddress=r;this.relayBindAddress=i;if(o&&o[0]>o[1]){throw new Error(`relayPortRange: the first port (${o[0]}) is above the last one (${o[1]})`)}this.relayPortRange=o;this.protocol=new re({software:y,getPassword:l??((I,C)=>h?.[I]),...N})}get address(){if(this.boundPort===void 0){return void 0}return[this.relayAddress,this.boundPort]}get tlsAddress(){if(this.boundTlsPort===void 0){return void 0}return[this.relayAddress,this.boundTlsPort]}async listen(){if(this.boundPort!==void 0||this.boundTlsPort!==void 0){return}this.closed=false;if(!this.udpEnabled&&!this.tcpEnabled&&!this.tlsEnabled){throw new Error(\"NodeTurnServer requires udp, tcp, or tls to be enabled\")}if(this.tcpEnabled&&this.tlsEnabled&&!this.tlsExternal&&this.tlsPort!==0&&this.tlsPort===this.port){throw new Error(\"NodeTurnServer cannot share the same port for tcp and tls\")}if(this.tlsEnabled&&!this.tlsExternal&&(!this.tlsOptions?.key||!this.tlsOptions?.cert)){throw new Error(\"NodeTurnServer tls requires both key and cert\")}const e=this.port===0&&this.udpEnabled&&this.tcpEnabled;const t=e?vt:1;for(let s=1;;s++){try{await this.listenTransports();break}catch(r){await this.closeListeners();if(Ft(r)&&s<t){continue}throw r}}this.updateTimer()}async listenTransports(){if(this.udpEnabled){await this.listenUdp()}if(this.tcpEnabled){await this.listenTcp(this.boundPort??this.port)}if(this.tlsEnabled){if(this.tlsExternal){if(this.tlsPort!==0){this.boundTlsPort=this.tlsPort}}else{await this.listenTls(this.tlsPort)}}}attachTlsSocket(e,t={}){if(!this.tlsEnabled){throw new Error(\"NodeTurnServer tls must be enabled before attaching sockets\")}this.handleStreamConnection(e,\"tls\",t)}async close(){this.closed=true;if(this.timer){clearTimeout(this.timer);this.timer=void 0}for(const t of this.tcpConnections.values()){t.destroy()}this.tcpConnections.clear();for(const t of this.tlsConnections.values()){t.destroy()}this.tlsConnections.clear();const e=[...this.relaySockets.values()].map(t=>new Promise(s=>{t.once(\"close\",s);t.close()}));this.relaySockets.clear();this.relayBoundByPort.clear();this.relayPorts.clear();await Promise.all([...e,this.closeListeners()])}async closeListeners(){const e=[];if(this.udpSocket){const t=this.udpSocket;this.udpSocket=void 0;e.push(new Promise(s=>{t.once(\"close\",s);t.close()}))}if(this.tcpServer){const t=this.tcpServer;this.tcpServer=void 0;e.push(new Promise(s=>{t.close(()=>s())}))}if(this.tlsServer){const t=this.tlsServer;this.tlsServer=void 0;e.push(new Promise(s=>{t.close(()=>s())}))}this.boundPort=void 0;this.boundTlsPort=void 0;await Promise.all(e)}async listenUdp(){const e=(0,ge.createSocket)({type:this.socketType(this.host),reusePort:this.reusePort});this.udpSocket=e;e.on(\"message\",G(async(t,s)=>{await this.executeActions(this.protocol.handleClientDatagram({clientId:Gt(s),data:t,remoteAddress:[B(s.address),s.port],localAddress:this.address,transport:\"udp\"}))},t=>F(\"client datagram failed\",t)));await new Promise((t,s)=>{e.once(\"error\",s);e.bind({address:this.host,port:this.port},()=>{e.off(\"error\",s);const r=e.address();if(typeof r===\"string\"){s(new Error(\"Expected UDP address info\"));return}this.boundPort=r.port;ae(e);t()})})}async listenTcp(e){const t=(0,Qe.createServer)(s=>{this.handleStreamConnection(s,\"tcp\")});this.tcpServer=t;await new Promise((s,r)=>{t.once(\"error\",r);t.listen({port:e,host:this.host,reusePort:this.reusePort},()=>{t.off(\"error\",r);const i=t.address();if(!i||typeof i===\"string\"){r(new Error(\"Expected TCP address info\"));return}this.boundPort=i.port;s()})})}async listenTls(e){const t=(0,Ze.createServer)(this.tlsOptions,s=>{this.handleStreamConnection(s,\"tls\")});this.tlsServer=t;await new Promise((s,r)=>{t.once(\"error\",r);t.listen({port:e,host:this.host,reusePort:this.reusePort},()=>{t.off(\"error\",r);const i=t.address();if(!i||typeof i===\"string\"){r(new Error(\"Expected TLS address info\"));return}this.boundTlsPort=i.port;s()})})}async executeActions(e){let t;for(const s of e){switch(s.type){case\"send-client\":await this.sendClient(s);break;case\"send-relay\":await this.sendRelay(s);break;case\"bind-relay\":await this.bindRelay(s.allocationId,s.relayId);break;case\"close-relay\":await this.closeRelay(s.relayId);break;case\"close-client\":this.closeClient(s.clientId);break;case\"schedule-timeout\":t=s.at;break;default:break}}if(t!==void 0)this.setTimer(t)}async sendClient(e){if(e.transport===\"tcp\"||e.transport===\"tls\"){const t=this.getStreamClient(e.transport,e.clientId);if(!t||t.destroyed){return}await new Promise((s,r)=>{t.write(ye(e.data),i=>{if(i){r(i);return}s()})}).catch(async s=>{if(!_t(s)){throw s}await this.executeActions(this.protocol.handleClientClosed({clientId:e.clientId}))});return}if(e.transport!==\"udp\"){return}if(!this.udpSocket){return}this.udpSocket.send(ye(e.data),e.remoteAddress[1],e.remoteAddress[0])}async sendRelay(e){const t=this.relaySockets.get(e.relayId);if(!t){return}t.send(e.data,e.remoteAddress[1],e.remoteAddress[0])}async bindRelaySocket(){const e=c(a=>new Promise((d,h)=>{const u=(0,ge.createSocket)(this.socketType(this.relayBindAddress));u.once(\"error\",l=>{try{u.close()}catch{}h(l)});u.bind({address:this.relayBindAddress,port:a},()=>{u.removeAllListeners(\"error\");ae(u);d(u)})}),\"bind\");if(!this.relayPortRange)return e(0);const[t,s]=this.relayPortRange;const r=s-t+1;const i=Math.floor(Math.random()*r);let o;for(let a=0;a<r;a++){try{return await e(t+(i+a)%r)}catch(d){o=d;if(d.code!==\"EADDRINUSE\")break}}throw o??new Error(\"no free port in the relay port range\")}async bindRelay(e,t){try{const s=await this.bindRelaySocket();this.relaySockets.set(t,s);s.on(\"error\",i=>F(\"relay socket error\",i));const r=s.address();if(typeof r===\"string\"){throw new Error(\"Expected relay UDP address info\")}this.relayBoundByPort.set(r.port,r);this.relayPorts.set(t,r.port);s.on(\"message\",G(async(i,o)=>{await this.executeActions(this.protocol.handleRelayPacket({relayId:t,data:i,remoteAddress:this.normalizeRelayRemoteAddress(o),localAddress:[this.relayAddress,r.port]}))},i=>F(\"relay datagram failed\",i)));await this.executeActions(this.protocol.handleRelayBound({allocationId:e,relayId:t,relayedAddress:[this.relayAddress,r.port]}))}catch(s){F(\"relay bind failed\",s);const r=this.relaySockets.get(t);this.relaySockets.delete(t);this.forgetRelayPort(t);try{r?.close()}catch{}await this.executeActions(this.protocol.handleRelayBindFailure({allocationId:e}))}}async closeRelay(e){const t=this.relaySockets.get(e);if(!t){return}this.relaySockets.delete(e);this.forgetRelayPort(e);await new Promise(s=>{t.once(\"close\",s);t.close()})}closeClient(e){const t=this.tcpConnections.get(e);if(t&&!t.destroyed){t.destroy();return}const s=this.tlsConnections.get(e);if(s&&!s.destroyed){s.destroy()}}updateTimer(){const e=this.protocol.nextTimeoutAt;if(e===void 0){if(this.timer)clearTimeout(this.timer);this.timer=void 0;return}this.setTimer(e)}setTimer(e){if(this.timer){clearTimeout(this.timer);this.timer=void 0}if(this.closed)return;this.timer=setTimeout(G(async()=>{this.timer=void 0;await this.executeActions(this.protocol.handleTimer())},t=>F(\"timer failed\",t)),Math.max(0,e-Date.now()))}normalizeRelayRemoteAddress(e){const t=B(e.address);const s=this.relayBoundByPort.get(e.port);if(s&&this.isRelaySocketAddress(s,t,e.port)){return[this.relayAddress,e.port]}return[t,e.port]}isRelaySocketAddress(e,t,s){if(e.port!==s){return false}const r=B(e.address);return r===t||(Mt(r)||this.isLocalInterfaceAddress(r))&&this.isLocalInterfaceAddress(t)}isLocalInterfaceAddress(e){if(e===this.relayAddress){return true}const t=Date.now();if(!this.interfaceAddresses||t-this.interfaceAddresses.at>1e3){const s=new Set;for(const r of Object.values((0,Je.networkInterfaces)()).flat()){if(r)s.add(B(r.address))}this.interfaceAddresses={at:t,addresses:s}}return this.interfaceAddresses.addresses.has(e)}forgetRelayPort(e){const t=this.relayPorts.get(e);this.relayPorts.delete(e);if(t!==void 0)this.relayBoundByPort.delete(t)}socketType(e){return e.includes(\":\")?\"udp6\":\"udp4\"}handleStreamConnection(e,t,s={}){const r=(0,je.randomUUID)();const i=s.localAddress??this.resolveStreamLocalAddress(e,t);if(t===\"tcp\"){this.tcpConnections.set(r,e)}else{this.tlsConnections.set(r,e)}const o=c(async a=>{await this.executeActions(this.protocol.handleTcpChunk({clientId:r,data:a,remoteAddress:[B(e.remoteAddress??\"\"),e.remotePort??0],localAddress:i,transport:t}))},\"handleData\");e.on(\"data\",a=>{void o(a)});e.on(\"close\",G(async()=>{if(t===\"tcp\"){this.tcpConnections.delete(r)}else{this.tlsConnections.delete(r)}await this.executeActions(this.protocol.handleClientClosed({clientId:r}))},a=>F(\"client close failed\",a)));e.on(\"error\",()=>{});if(s.initialData?.length){void o(s.initialData)}}getStreamClient(e,t){return e===\"tcp\"?this.tcpConnections.get(t):this.tlsConnections.get(t)}resolveStreamLocalAddress(e,t){if(e.localAddress&&e.localPort){return[B(e.localAddress),e.localPort]}return t===\"tcp\"?this.address:this.tlsAddress}};function B(n){return n.split(\"%\")[0]}c(B,\"normalizeAddress\");function Mt(n){return n===\"0.0.0.0\"||n===\"::\"}c(Mt,\"isWildcardAddress\");var vt=10;function Ft(n){return!!n&&typeof n===\"object\"&&\"code\"in n&&n.code===\"EADDRINUSE\"}c(Ft,\"isAddressInUseError\");function _t(n){const e=n&&typeof n===\"object\"&&\"code\"in n?n.code:void 0;return e===\"ECONNRESET\"||e===\"EPIPE\"||e===\"ERR_STREAM_DESTROYED\"}c(_t,\"isClosedTcpWriteError\");function Gt(n){return`udp:${B(n.address)}:${n.port}`}c(Gt,\"udpClientId\");var et=require(\"node:crypto\");function Ht(n,e){return(0,et.createHmac)(\"sha1\",n).update(e).digest(\"base64\")}c(Ht,\"turnPassword\");function tt(n,e,t=Date.now()){const s=e.indexOf(\":\");if(s<=0)return void 0;const r=Number(e.slice(0,s));if(!Number.isFinite(r)||r*1e3<t)return void 0;return Ht(n,e)}c(tt,\"turnPasswordIfValid\");function nt(){if(!W.parentPort)throw new Error(\"The TURN server serves in a worker thread only\");const n=W.parentPort;const e=W.workerData;const t=new Int32Array(e.allocations);const s=1+e.thread;const r=e.options.maxAllocations??Infinity;const i=new ie({...e.options,reusePort:true,getPassword:c(a=>e.users[a]??tt(e.secret,a),\"getPassword\"),allocationGate:{reserve:c(()=>{if(Atomics.add(t,0,1)<r){Atomics.add(t,s,1);return true}Atomics.sub(t,0,1);return false},\"reserve\"),release:c(()=>{Atomics.sub(t,0,1);Atomics.sub(t,s,1)},\"release\")}});const o=c(a=>n.postMessage(a),\"post\");n.on(\"message\",a=>{if(a.type===\"debug\"){Re(a.enabled?(d,h)=>o({type:\"log\",namespace:d,message:`[thread ${e.thread}] ${(0,st.format)(...h)}`}):void 0);return}i.close().then(()=>o({type:\"stopped\"}),()=>o({type:\"stopped\"}))});i.listen().then(()=>o({type:\"ready\",port:i.address?.[1],tlsPort:i.tlsAddress?.[1]}),a=>o({type:\"failed\",error:a instanceof Error?a.message:String(a)}))}c(nt,\"runTURNWorker\");nt();\n";
@@ -0,0 +1,206 @@
1
+ import { createSocket } from 'node:dgram';
2
+ import { createServer, isIPv6 } from 'node:net';
3
+ import { Worker } from 'node:worker_threads';
4
+ import { debug, debugHandlerWatchers, hasDebugHandler } from '../lib/common/log.js';
5
+ import { turnWorkerCode } from './TURNWorkerCode.js';
6
+ const log = debug('webrtc/turn/workers');
7
+ /**
8
+ * How long a thread asked to stop has to close its server, in milliseconds
9
+ */
10
+ const STOP_TIMEOUT = 5000;
11
+ /**
12
+ * Whether the listeners of several threads can share a port here, the system spreading the clients among them
13
+ * (SO_REUSEPORT): on Linux only (Bun lets the sockets of macOS share a port, but macOS gives all its datagrams to one
14
+ * of them), when two UDP sockets, then two TCP servers, bind to one port
15
+ * @param host The address the server listens on.
16
+ * @internal
17
+ */
18
+ export async function portsShareable(host) {
19
+ if (process.platform !== 'linux')
20
+ return false;
21
+ const sockets = [];
22
+ const servers = [];
23
+ const bindUdp = (port) => new Promise((resolve, reject) => {
24
+ const socket = createSocket({ type: isIPv6(host) ? 'udp6' : 'udp4', reusePort: true });
25
+ sockets.push(socket);
26
+ socket.once('error', reject);
27
+ socket.bind(port, host, () => resolve(socket.address().port));
28
+ });
29
+ const listenTcp = (port) => new Promise((resolve, reject) => {
30
+ const server = createServer();
31
+ servers.push(server);
32
+ server.once('error', reject);
33
+ server.listen({ port: port, host: host, reusePort: true }, () => resolve(server.address().port));
34
+ });
35
+ try {
36
+ await bindUdp(await bindUdp(0));
37
+ await listenTcp(await listenTcp(0));
38
+ return true;
39
+ }
40
+ catch {
41
+ return false;
42
+ }
43
+ finally {
44
+ for (const socket of sockets) {
45
+ try {
46
+ socket.close();
47
+ }
48
+ catch {
49
+ //Not bound
50
+ }
51
+ }
52
+ for (const server of servers)
53
+ server.close(() => undefined);
54
+ }
55
+ }
56
+ /**
57
+ * The worker threads of each TURN server serving in some (for the tests and the benchmarks)
58
+ * @internal
59
+ */
60
+ export const turnWorkers = new WeakMap();
61
+ /**
62
+ * The worker threads of a TURN server, sharing its ports (SO_REUSEPORT) and counting their allocations together
63
+ * @internal
64
+ */
65
+ export class TURNWorkers {
66
+ #slots;
67
+ #data;
68
+ #counts;
69
+ //The ports the threads bound, the first thread choosing them when the options give 0
70
+ #port;
71
+ #tlsPort;
72
+ #stopping = false;
73
+ //Tells the threads whether the main thread has a debug handler
74
+ #debugging = (set) => {
75
+ for (const slot of this.#slots)
76
+ slot.worker?.postMessage({ type: 'debug', enabled: set });
77
+ };
78
+ /**
79
+ * Prepare the threads.
80
+ * @param data What each thread is started with (they share one counter of allocations).
81
+ * @throws {Error} When the code of the threads was not built.
82
+ */
83
+ constructor(data) {
84
+ if (!turnWorkerCode)
85
+ throw new Error('The code of the worker threads of the TURN server is not built (scripts/workers.mjs)');
86
+ this.#data = data;
87
+ this.#counts = new Int32Array(data[0].allocations);
88
+ this.#slots = data.map((_, index) => ({ index: index, ran: false }));
89
+ }
90
+ /**
91
+ * Start the threads: the first one, then the others on the ports it bound.
92
+ * @throws {Error} When a thread cannot serve (a port in use).
93
+ */
94
+ async start() {
95
+ debugHandlerWatchers.add(this.#debugging);
96
+ const first = await this.#start(this.#slots[0]);
97
+ this.#port = first.port;
98
+ this.#tlsPort = first.tlsPort;
99
+ await Promise.all(this.#slots.slice(1).map((slot) => this.#start(slot)));
100
+ }
101
+ /**
102
+ * Stop the threads, each closing its server.
103
+ */
104
+ async stop() {
105
+ this.#stopping = true;
106
+ debugHandlerWatchers.delete(this.#debugging);
107
+ await Promise.all(this.#slots.map(async (slot) => {
108
+ const worker = slot.worker;
109
+ if (!worker)
110
+ return;
111
+ let timer;
112
+ await Promise.race([
113
+ new Promise((resolve) => {
114
+ worker.on('message', (message) => {
115
+ if (message.type === 'stopped')
116
+ resolve();
117
+ });
118
+ worker.postMessage({ type: 'stop' });
119
+ }),
120
+ new Promise((resolve) => {
121
+ timer = setTimeout(resolve, STOP_TIMEOUT);
122
+ })
123
+ ]);
124
+ clearTimeout(timer);
125
+ await worker.terminate();
126
+ }));
127
+ }
128
+ /**
129
+ * The allocations of all the threads.
130
+ */
131
+ get allocations() {
132
+ return Atomics.load(this.#counts, 0);
133
+ }
134
+ /**
135
+ * The allocations of each thread.
136
+ */
137
+ get threadAllocations() {
138
+ return this.#slots.map((slot) => Atomics.load(this.#counts, 1 + slot.index));
139
+ }
140
+ /**
141
+ * The port of STUN and TURN over UDP and TCP.
142
+ */
143
+ get port() {
144
+ return this.#port;
145
+ }
146
+ /**
147
+ * The port of TURN over TLS.
148
+ */
149
+ get tlsPort() {
150
+ return this.#tlsPort;
151
+ }
152
+ /**
153
+ * Start the thread of a slot, on the ports of the first one when they are known
154
+ * @param slot
155
+ * @returns The ports it bound.
156
+ */
157
+ #start(slot) {
158
+ const data = this.#data[slot.index];
159
+ const options = this.#port === undefined ? data.options : {
160
+ ...data.options,
161
+ port: this.#port,
162
+ ...data.options.tls && this.#tlsPort !== undefined ? { tls: { ...data.options.tls, port: this.#tlsPort } } : {}
163
+ };
164
+ const worker = new Worker(turnWorkerCode, { eval: true, workerData: { ...data, options: options } });
165
+ slot.worker = worker;
166
+ if (hasDebugHandler())
167
+ worker.postMessage({ type: 'debug', enabled: true });
168
+ const ready = new Promise((resolve, reject) => {
169
+ worker.on('message', (message) => {
170
+ switch (message.type) {
171
+ case 'ready':
172
+ slot.ran = true;
173
+ return resolve({ port: message.port, tlsPort: message.tlsPort });
174
+ case 'failed':
175
+ return reject(new Error(message.error));
176
+ case 'log':
177
+ return debug(message.namespace)(message.message);
178
+ }
179
+ });
180
+ worker.on('exit', () => reject(new Error('The worker thread of the TURN server stopped')));
181
+ });
182
+ worker.on('error', (error) => log('the worker thread %d failed: %O', slot.index, error));
183
+ worker.on('exit', (code) => {
184
+ if (!this.#stopping)
185
+ log('the worker thread %d stopped (exit code %d)', slot.index, code);
186
+ this.#exited(slot, worker);
187
+ });
188
+ return ready;
189
+ }
190
+ /**
191
+ * A thread stopped: its allocations are gone, and it is started again, unless it never served. Most clients of the
192
+ * other threads move too (the system spreads them over the threads left), and allocate again
193
+ * @param slot
194
+ * @param worker
195
+ */
196
+ #exited(slot, worker) {
197
+ if (slot.worker !== worker)
198
+ return;
199
+ slot.worker = undefined;
200
+ const own = Atomics.exchange(this.#counts, 1 + slot.index, 0);
201
+ Atomics.sub(this.#counts, 0, own);
202
+ if (this.#stopping || !slot.ran)
203
+ return;
204
+ this.#start(slot).catch((error) => log('the worker thread %d could not start again: %O', slot.index, error));
205
+ }
206
+ }