@honeybbq/teamspeak 0.0.1 → 1.0.0-beta.7

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 (393) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +726 -2
  3. package/dist/client/abort.d.ts +5 -0
  4. package/dist/client/abort.d.ts.map +1 -0
  5. package/dist/client/abort.js +23 -0
  6. package/dist/client/abort.js.map +1 -0
  7. package/dist/client/address.d.ts +17 -0
  8. package/dist/client/address.d.ts.map +1 -0
  9. package/dist/client/address.js +66 -0
  10. package/dist/client/address.js.map +1 -0
  11. package/dist/client/api/voice.d.ts +24 -0
  12. package/dist/client/api/voice.d.ts.map +1 -0
  13. package/dist/client/api/voice.js +33 -0
  14. package/dist/client/api/voice.js.map +1 -0
  15. package/dist/client/capabilities.d.ts +68 -0
  16. package/dist/client/capabilities.d.ts.map +1 -0
  17. package/dist/client/capabilities.js +59 -0
  18. package/dist/client/capabilities.js.map +1 -0
  19. package/dist/client/client.d.ts +196 -0
  20. package/dist/client/client.d.ts.map +1 -0
  21. package/dist/client/client.js +1523 -0
  22. package/dist/client/client.js.map +1 -0
  23. package/dist/client/commands.d.ts +66 -0
  24. package/dist/client/commands.d.ts.map +1 -0
  25. package/dist/client/commands.js +162 -0
  26. package/dist/client/commands.js.map +1 -0
  27. package/dist/client/crypto/crypt-ops.d.ts +7 -0
  28. package/dist/client/crypto/crypt-ops.d.ts.map +1 -0
  29. package/dist/client/crypto/crypt-ops.js +2 -0
  30. package/dist/client/crypto/crypt-ops.js.map +1 -0
  31. package/dist/client/crypto/crypt.d.ts +37 -0
  32. package/dist/client/crypto/crypt.d.ts.map +1 -0
  33. package/dist/client/crypto/crypt.js +203 -0
  34. package/dist/client/crypto/crypt.js.map +1 -0
  35. package/dist/client/crypto/eax.d.ts +12 -0
  36. package/dist/client/crypto/eax.d.ts.map +1 -0
  37. package/dist/client/crypto/eax.js +118 -0
  38. package/dist/client/crypto/eax.js.map +1 -0
  39. package/dist/client/crypto/identity.d.ts +97 -0
  40. package/dist/client/crypto/identity.d.ts.map +1 -0
  41. package/dist/client/crypto/identity.js +412 -0
  42. package/dist/client/crypto/identity.js.map +1 -0
  43. package/dist/client/crypto/index.d.ts +7 -0
  44. package/dist/client/crypto/index.d.ts.map +1 -0
  45. package/dist/client/crypto/index.js +5 -0
  46. package/dist/client/crypto/index.js.map +1 -0
  47. package/dist/client/crypto/primitives.d.ts +43 -0
  48. package/dist/client/crypto/primitives.d.ts.map +1 -0
  49. package/dist/client/crypto/primitives.js +116 -0
  50. package/dist/client/crypto/primitives.js.map +1 -0
  51. package/dist/client/diagnostics.d.ts +45 -0
  52. package/dist/client/diagnostics.d.ts.map +1 -0
  53. package/dist/client/diagnostics.js +30 -0
  54. package/dist/client/diagnostics.js.map +1 -0
  55. package/dist/client/discovery/index.d.ts +2 -0
  56. package/dist/client/discovery/index.d.ts.map +1 -0
  57. package/dist/client/discovery/index.js +2 -0
  58. package/dist/client/discovery/index.js.map +1 -0
  59. package/dist/client/discovery/resolver.d.ts +26 -0
  60. package/dist/client/discovery/resolver.d.ts.map +1 -0
  61. package/dist/client/discovery/resolver.js +275 -0
  62. package/dist/client/discovery/resolver.js.map +1 -0
  63. package/dist/client/errors.d.ts +82 -0
  64. package/dist/client/errors.d.ts.map +1 -0
  65. package/dist/client/errors.js +201 -0
  66. package/dist/client/errors.js.map +1 -0
  67. package/dist/client/events.d.ts +3 -0
  68. package/dist/client/events.d.ts.map +1 -0
  69. package/dist/client/events.js +8 -0
  70. package/dist/client/events.js.map +1 -0
  71. package/dist/client/handshake/crypt-handshake.d.ts +17 -0
  72. package/dist/client/handshake/crypt-handshake.d.ts.map +1 -0
  73. package/dist/client/handshake/crypt-handshake.js +128 -0
  74. package/dist/client/handshake/crypt-handshake.js.map +1 -0
  75. package/dist/client/handshake/crypt-init2.d.ts +7 -0
  76. package/dist/client/handshake/crypt-init2.d.ts.map +1 -0
  77. package/dist/client/handshake/crypt-init2.js +37 -0
  78. package/dist/client/handshake/crypt-init2.js.map +1 -0
  79. package/dist/client/handshake/index.d.ts +4 -0
  80. package/dist/client/handshake/index.d.ts.map +1 -0
  81. package/dist/client/handshake/index.js +4 -0
  82. package/dist/client/handshake/index.js.map +1 -0
  83. package/dist/client/handshake/license.d.ts +35 -0
  84. package/dist/client/handshake/license.d.ts.map +1 -0
  85. package/dist/client/handshake/license.js +169 -0
  86. package/dist/client/handshake/license.js.map +1 -0
  87. package/dist/client/handshake.d.ts +27 -0
  88. package/dist/client/handshake.d.ts.map +1 -0
  89. package/dist/client/handshake.js +126 -0
  90. package/dist/client/handshake.js.map +1 -0
  91. package/dist/client/helpers.d.ts +6 -0
  92. package/dist/client/helpers.d.ts.map +1 -0
  93. package/dist/client/helpers.js +13 -0
  94. package/dist/client/helpers.js.map +1 -0
  95. package/dist/client/hooks.d.ts +7 -0
  96. package/dist/client/hooks.d.ts.map +1 -0
  97. package/dist/client/hooks.js +28 -0
  98. package/dist/client/hooks.js.map +1 -0
  99. package/dist/client/index.d.ts +26 -0
  100. package/dist/client/index.d.ts.map +1 -0
  101. package/dist/client/index.js +28 -0
  102. package/dist/client/index.js.map +1 -0
  103. package/dist/client/reconnect.d.ts +12 -0
  104. package/dist/client/reconnect.d.ts.map +1 -0
  105. package/dist/client/reconnect.js +44 -0
  106. package/dist/client/reconnect.js.map +1 -0
  107. package/dist/client/throttle.d.ts +20 -0
  108. package/dist/client/throttle.d.ts.map +1 -0
  109. package/dist/client/throttle.js +83 -0
  110. package/dist/client/throttle.js.map +1 -0
  111. package/dist/client/trace.d.ts +223 -0
  112. package/dist/client/trace.d.ts.map +1 -0
  113. package/dist/client/trace.js +13 -0
  114. package/dist/client/trace.js.map +1 -0
  115. package/dist/client/transfer.d.ts +111 -0
  116. package/dist/client/transfer.d.ts.map +1 -0
  117. package/dist/client/transfer.js +243 -0
  118. package/dist/client/transfer.js.map +1 -0
  119. package/dist/client/transport/generation-window.d.ts +30 -0
  120. package/dist/client/transport/generation-window.d.ts.map +1 -0
  121. package/dist/client/transport/generation-window.js +97 -0
  122. package/dist/client/transport/generation-window.js.map +1 -0
  123. package/dist/client/transport/handler.d.ts +61 -0
  124. package/dist/client/transport/handler.d.ts.map +1 -0
  125. package/dist/client/transport/handler.js +793 -0
  126. package/dist/client/transport/handler.js.map +1 -0
  127. package/dist/client/transport/index.d.ts +6 -0
  128. package/dist/client/transport/index.d.ts.map +1 -0
  129. package/dist/client/transport/index.js +5 -0
  130. package/dist/client/transport/index.js.map +1 -0
  131. package/dist/client/transport/packet.d.ts +36 -0
  132. package/dist/client/transport/packet.d.ts.map +1 -0
  133. package/dist/client/transport/packet.js +55 -0
  134. package/dist/client/transport/packet.js.map +1 -0
  135. package/dist/client/transport/quicklz.d.ts +24 -0
  136. package/dist/client/transport/quicklz.d.ts.map +1 -0
  137. package/dist/client/transport/quicklz.js +179 -0
  138. package/dist/client/transport/quicklz.js.map +1 -0
  139. package/dist/client/types.d.ts +226 -0
  140. package/dist/client/types.d.ts.map +1 -0
  141. package/dist/client/types.js +39 -0
  142. package/dist/client/types.js.map +1 -0
  143. package/dist/core/api/channels.d.ts +182 -0
  144. package/dist/core/api/channels.d.ts.map +1 -0
  145. package/dist/core/api/channels.js +155 -0
  146. package/dist/core/api/channels.js.map +1 -0
  147. package/dist/core/api/clients.d.ts +304 -0
  148. package/dist/core/api/clients.d.ts.map +1 -0
  149. package/dist/core/api/clients.js +260 -0
  150. package/dist/core/api/clients.js.map +1 -0
  151. package/dist/core/api/command.d.ts +305 -0
  152. package/dist/core/api/command.d.ts.map +1 -0
  153. package/dist/core/api/command.js +363 -0
  154. package/dist/core/api/command.js.map +1 -0
  155. package/dist/core/api/files.d.ts +153 -0
  156. package/dist/core/api/files.d.ts.map +1 -0
  157. package/dist/core/api/files.js +181 -0
  158. package/dist/core/api/files.js.map +1 -0
  159. package/dist/core/api/groups.d.ts +248 -0
  160. package/dist/core/api/groups.d.ts.map +1 -0
  161. package/dist/core/api/groups.js +271 -0
  162. package/dist/core/api/groups.js.map +1 -0
  163. package/dist/core/api/moderation.d.ts +205 -0
  164. package/dist/core/api/moderation.d.ts.map +1 -0
  165. package/dist/core/api/moderation.js +209 -0
  166. package/dist/core/api/moderation.js.map +1 -0
  167. package/dist/core/api/parse.d.ts +16 -0
  168. package/dist/core/api/parse.d.ts.map +1 -0
  169. package/dist/core/api/parse.js +40 -0
  170. package/dist/core/api/parse.js.map +1 -0
  171. package/dist/core/api/server.d.ts +310 -0
  172. package/dist/core/api/server.d.ts.map +1 -0
  173. package/dist/core/api/server.js +290 -0
  174. package/dist/core/api/server.js.map +1 -0
  175. package/dist/core/command/command.d.ts +20 -0
  176. package/dist/core/command/command.d.ts.map +1 -0
  177. package/dist/core/command/command.js +112 -0
  178. package/dist/core/command/command.js.map +1 -0
  179. package/dist/core/command/ids.d.ts +125 -0
  180. package/dist/core/command/ids.d.ts.map +1 -0
  181. package/dist/core/command/ids.js +85 -0
  182. package/dist/core/command/ids.js.map +1 -0
  183. package/dist/core/command/parser.d.ts +17 -0
  184. package/dist/core/command/parser.d.ts.map +1 -0
  185. package/dist/core/command/parser.js +65 -0
  186. package/dist/core/command/parser.js.map +1 -0
  187. package/dist/core/command/request.d.ts +61 -0
  188. package/dist/core/command/request.d.ts.map +1 -0
  189. package/dist/core/command/request.js +64 -0
  190. package/dist/core/command/request.js.map +1 -0
  191. package/dist/core/command/responses.d.ts +59 -0
  192. package/dist/core/command/responses.d.ts.map +1 -0
  193. package/dist/core/command/responses.js +74 -0
  194. package/dist/core/command/responses.js.map +1 -0
  195. package/dist/core/command-name.d.ts +333 -0
  196. package/dist/core/command-name.d.ts.map +1 -0
  197. package/dist/core/command-name.js +331 -0
  198. package/dist/core/command-name.js.map +1 -0
  199. package/dist/core/enums.d.ts +146 -0
  200. package/dist/core/enums.d.ts.map +1 -0
  201. package/dist/core/enums.js +132 -0
  202. package/dist/core/enums.js.map +1 -0
  203. package/dist/core/errorcode.d.ts +413 -0
  204. package/dist/core/errorcode.d.ts.map +1 -0
  205. package/dist/core/errorcode.js +410 -0
  206. package/dist/core/errorcode.js.map +1 -0
  207. package/dist/core/errors.d.ts +111 -0
  208. package/dist/core/errors.d.ts.map +1 -0
  209. package/dist/core/errors.js +233 -0
  210. package/dist/core/errors.js.map +1 -0
  211. package/dist/core/events.d.ts +207 -0
  212. package/dist/core/events.d.ts.map +1 -0
  213. package/dist/core/events.js +6 -0
  214. package/dist/core/events.js.map +1 -0
  215. package/dist/core/helpers.d.ts +42 -0
  216. package/dist/core/helpers.d.ts.map +1 -0
  217. package/dist/core/helpers.js +156 -0
  218. package/dist/core/helpers.js.map +1 -0
  219. package/dist/core/index.d.ts +35 -0
  220. package/dist/core/index.d.ts.map +1 -0
  221. package/dist/core/index.js +34 -0
  222. package/dist/core/index.js.map +1 -0
  223. package/dist/core/internal.d.ts +23 -0
  224. package/dist/core/internal.d.ts.map +1 -0
  225. package/dist/core/internal.js +20 -0
  226. package/dist/core/internal.js.map +1 -0
  227. package/dist/core/middleware.d.ts +14 -0
  228. package/dist/core/middleware.d.ts.map +1 -0
  229. package/dist/core/middleware.js +18 -0
  230. package/dist/core/middleware.js.map +1 -0
  231. package/dist/core/notification-name.d.ts +154 -0
  232. package/dist/core/notification-name.d.ts.map +1 -0
  233. package/dist/core/notification-name.js +152 -0
  234. package/dist/core/notification-name.js.map +1 -0
  235. package/dist/core/notifications.d.ts +43 -0
  236. package/dist/core/notifications.d.ts.map +1 -0
  237. package/dist/core/notifications.js +116 -0
  238. package/dist/core/notifications.js.map +1 -0
  239. package/dist/core/permission-name.d.ts +533 -0
  240. package/dist/core/permission-name.d.ts.map +1 -0
  241. package/dist/core/permission-name.js +531 -0
  242. package/dist/core/permission-name.js.map +1 -0
  243. package/dist/core/permission.d.ts +31 -0
  244. package/dist/core/permission.d.ts.map +1 -0
  245. package/dist/core/permission.js +20 -0
  246. package/dist/core/permission.js.map +1 -0
  247. package/dist/core/property-name.d.ts +403 -0
  248. package/dist/core/property-name.d.ts.map +1 -0
  249. package/dist/core/property-name.js +405 -0
  250. package/dist/core/property-name.js.map +1 -0
  251. package/dist/core/reason.d.ts +39 -0
  252. package/dist/core/reason.d.ts.map +1 -0
  253. package/dist/core/reason.js +36 -0
  254. package/dist/core/reason.js.map +1 -0
  255. package/dist/core/reconnect.d.ts +59 -0
  256. package/dist/core/reconnect.d.ts.map +1 -0
  257. package/dist/core/reconnect.js +55 -0
  258. package/dist/core/reconnect.js.map +1 -0
  259. package/dist/core/types.d.ts +110 -0
  260. package/dist/core/types.d.ts.map +1 -0
  261. package/dist/core/types.js +27 -0
  262. package/dist/core/types.js.map +1 -0
  263. package/dist/query/client.d.ts +194 -0
  264. package/dist/query/client.d.ts.map +1 -0
  265. package/dist/query/client.js +967 -0
  266. package/dist/query/client.js.map +1 -0
  267. package/dist/query/errors.d.ts +61 -0
  268. package/dist/query/errors.d.ts.map +1 -0
  269. package/dist/query/errors.js +100 -0
  270. package/dist/query/errors.js.map +1 -0
  271. package/dist/query/index.d.ts +36 -0
  272. package/dist/query/index.d.ts.map +1 -0
  273. package/dist/query/index.js +34 -0
  274. package/dist/query/index.js.map +1 -0
  275. package/dist/query/knownhosts.d.ts +61 -0
  276. package/dist/query/knownhosts.d.ts.map +1 -0
  277. package/dist/query/knownhosts.js +223 -0
  278. package/dist/query/knownhosts.js.map +1 -0
  279. package/dist/query/lines.d.ts +14 -0
  280. package/dist/query/lines.d.ts.map +1 -0
  281. package/dist/query/lines.js +29 -0
  282. package/dist/query/lines.js.map +1 -0
  283. package/dist/query/options.d.ts +187 -0
  284. package/dist/query/options.d.ts.map +1 -0
  285. package/dist/query/options.js +213 -0
  286. package/dist/query/options.js.map +1 -0
  287. package/dist/query/reconnect.d.ts +29 -0
  288. package/dist/query/reconnect.d.ts.map +1 -0
  289. package/dist/query/reconnect.js +87 -0
  290. package/dist/query/reconnect.js.map +1 -0
  291. package/dist/query/ssh.d.ts +345 -0
  292. package/dist/query/ssh.d.ts.map +1 -0
  293. package/dist/query/ssh.js +241 -0
  294. package/dist/query/ssh.js.map +1 -0
  295. package/dist/query/stream.d.ts +38 -0
  296. package/dist/query/stream.d.ts.map +1 -0
  297. package/dist/query/stream.js +70 -0
  298. package/dist/query/stream.js.map +1 -0
  299. package/dist/query/tcp.d.ts +38 -0
  300. package/dist/query/tcp.d.ts.map +1 -0
  301. package/dist/query/tcp.js +53 -0
  302. package/dist/query/tcp.js.map +1 -0
  303. package/dist/query/transport.d.ts +36 -0
  304. package/dist/query/transport.d.ts.map +1 -0
  305. package/dist/query/transport.js +2 -0
  306. package/dist/query/transport.js.map +1 -0
  307. package/dist/query/web.d.ts +54 -0
  308. package/dist/query/web.d.ts.map +1 -0
  309. package/dist/query/web.js +146 -0
  310. package/dist/query/web.js.map +1 -0
  311. package/dist/versions/index.d.ts +3094 -0
  312. package/dist/versions/index.d.ts.map +1 -0
  313. package/dist/versions/index.js +9237 -0
  314. package/dist/versions/index.js.map +1 -0
  315. package/package.json +118 -4
  316. package/src/client/abort.ts +24 -0
  317. package/src/client/address.ts +74 -0
  318. package/src/client/api/voice.ts +61 -0
  319. package/src/client/capabilities.ts +106 -0
  320. package/src/client/client.ts +1809 -0
  321. package/src/client/commands.ts +193 -0
  322. package/src/client/crypto/crypt-ops.ts +6 -0
  323. package/src/client/crypto/crypt.ts +275 -0
  324. package/src/client/crypto/eax.ts +152 -0
  325. package/src/client/crypto/identity.ts +484 -0
  326. package/src/client/crypto/index.ts +21 -0
  327. package/src/client/crypto/primitives.ts +141 -0
  328. package/src/client/diagnostics.ts +58 -0
  329. package/src/client/discovery/index.ts +1 -0
  330. package/src/client/discovery/resolver.ts +325 -0
  331. package/src/client/errors.ts +217 -0
  332. package/src/client/events.ts +12 -0
  333. package/src/client/handshake/crypt-handshake.ts +157 -0
  334. package/src/client/handshake/crypt-init2.ts +48 -0
  335. package/src/client/handshake/index.ts +3 -0
  336. package/src/client/handshake/license.ts +208 -0
  337. package/src/client/handshake.ts +150 -0
  338. package/src/client/helpers.ts +10 -0
  339. package/src/client/hooks.ts +30 -0
  340. package/src/client/index.ts +93 -0
  341. package/src/client/reconnect.ts +43 -0
  342. package/src/client/throttle.ts +92 -0
  343. package/src/client/trace.ts +237 -0
  344. package/src/client/transfer.ts +436 -0
  345. package/src/client/transport/generation-window.ts +108 -0
  346. package/src/client/transport/handler.ts +926 -0
  347. package/src/client/transport/index.ts +14 -0
  348. package/src/client/transport/packet.ts +69 -0
  349. package/src/client/transport/quicklz.ts +209 -0
  350. package/src/client/types.ts +268 -0
  351. package/src/core/api/channels.ts +396 -0
  352. package/src/core/api/clients.ts +654 -0
  353. package/src/core/api/command.ts +563 -0
  354. package/src/core/api/files.ts +405 -0
  355. package/src/core/api/groups.ts +622 -0
  356. package/src/core/api/moderation.ts +525 -0
  357. package/src/core/api/parse.ts +52 -0
  358. package/src/core/api/server.ts +709 -0
  359. package/src/core/command/command.ts +125 -0
  360. package/src/core/command/ids.ts +149 -0
  361. package/src/core/command/parser.ts +68 -0
  362. package/src/core/command/request.ts +119 -0
  363. package/src/core/command/responses.ts +114 -0
  364. package/src/core/command-name.ts +334 -0
  365. package/src/core/enums.ts +167 -0
  366. package/src/core/errorcode.ts +412 -0
  367. package/src/core/errors.ts +258 -0
  368. package/src/core/events.ts +219 -0
  369. package/src/core/helpers.ts +161 -0
  370. package/src/core/index.ts +126 -0
  371. package/src/core/internal.ts +23 -0
  372. package/src/core/middleware.ts +24 -0
  373. package/src/core/notification-name.ts +155 -0
  374. package/src/core/notifications.ts +157 -0
  375. package/src/core/permission-name.ts +538 -0
  376. package/src/core/permission.ts +34 -0
  377. package/src/core/property-name.ts +411 -0
  378. package/src/core/reason.ts +38 -0
  379. package/src/core/reconnect.ts +98 -0
  380. package/src/core/types.ts +138 -0
  381. package/src/query/client.ts +1132 -0
  382. package/src/query/errors.ts +108 -0
  383. package/src/query/index.ts +65 -0
  384. package/src/query/knownhosts.ts +257 -0
  385. package/src/query/lines.ts +28 -0
  386. package/src/query/options.ts +388 -0
  387. package/src/query/reconnect.ts +84 -0
  388. package/src/query/ssh.ts +614 -0
  389. package/src/query/stream.ts +91 -0
  390. package/src/query/tcp.ts +85 -0
  391. package/src/query/transport.ts +35 -0
  392. package/src/query/web.ts +195 -0
  393. package/src/versions/index.ts +10774 -0
@@ -0,0 +1,93 @@
1
+ /**
2
+ * A clean-room TeamSpeak client: it connects over the voice protocol, the way
3
+ * the TeamSpeak application does.
4
+ *
5
+ * Only what belongs to the voice protocol is exported here. The typed commands,
6
+ * ids and errors every client shares come from `@honeybbq/teamspeak`.
7
+ *
8
+ * @module @honeybbq/teamspeak/client
9
+ */
10
+
11
+ // The client
12
+ export { Client } from "./client.js";
13
+ export { EventName } from "./types.js";
14
+
15
+ export type {
16
+ EventMap,
17
+ EventMiddleware,
18
+ ServerEvent,
19
+ ServerEventName,
20
+ VoiceOptions,
21
+ WhisperTargets,
22
+ AddrResolver,
23
+ ClientOptions,
24
+ ResolvedAddr,
25
+ DatagramSocket,
26
+ SocketFactory,
27
+ FileTransferSocketFactory,
28
+ } from "./types.js";
29
+
30
+ export {
31
+ FileTransferError,
32
+ HandshakeError,
33
+ InvalidAddressError,
34
+ InvalidIdentityError,
35
+ RemovedError,
36
+ ConnectionTimeoutError,
37
+ } from "./errors.js";
38
+
39
+ // Commands only the voice protocol has.
40
+ export * from "./api/voice.js";
41
+
42
+ // File transfer data
43
+ export { dialFileTransfer, uploadFileData, downloadFileData } from "./transfer.js";
44
+ export type {
45
+ FileTransferOptions,
46
+ FileTransferTrace,
47
+ FileTransferStage,
48
+ FileTransferDialStartInfo,
49
+ FileTransferDialDoneInfo,
50
+ FileTransferProgressInfo,
51
+ FileTransferDoneInfo,
52
+ FileTransferFailedInfo,
53
+ } from "./transfer.js";
54
+
55
+ // Tracing a connection attempt
56
+ export { ConnectPhase } from "./trace.js";
57
+ export type {
58
+ ClientTrace,
59
+ ResolveStartInfo,
60
+ ResolveDoneInfo,
61
+ ConnectStartInfo,
62
+ ConnectDoneInfo,
63
+ HandshakeDoneInfo,
64
+ SessionStartInfo,
65
+ WelcomeDoneInfo,
66
+ AttemptFailedInfo,
67
+ ReconnectScheduledInfo,
68
+ DisconnectStartInfo,
69
+ DisconnectDoneInfo,
70
+ SessionEndInfo,
71
+ ReconnectStoppedInfo,
72
+ } from "./trace.js";
73
+
74
+ // Server capabilities, read from the handshake
75
+ export { unknownServerCapabilities } from "./capabilities.js";
76
+ export type { ServerCapabilities } from "./capabilities.js";
77
+
78
+ // Tracing points for diagnostics_channel subscribers
79
+ export { commandChannel, incomingChannel } from "./diagnostics.js";
80
+ export type { CommandTrace, IncomingTrace } from "./diagnostics.js";
81
+
82
+ // Reconnection policy
83
+ export { defaultShouldRetry } from "./reconnect.js";
84
+
85
+ // Identity
86
+ export {
87
+ Identity,
88
+ parseIdentity,
89
+ generateIdentity,
90
+ generateIdentitySync,
91
+ uidFromPublicKey,
92
+ } from "./crypto/index.js";
93
+ export type { UIDAlgorithm } from "./crypto/index.js";
@@ -0,0 +1,43 @@
1
+ import { ErrorCode, Reason, ServerError, AlreadyConnectedError } from "@honeybbq/teamspeak";
2
+ import { InvalidAddressError, RemovedError } from "./errors.js";
3
+
4
+ /**
5
+ * Server errors where retrying cannot help.
6
+ *
7
+ * Deliberately a short list of codes known to be refusals, rather than "any
8
+ * ServerError". The server also answers transiently: after a dropped
9
+ * connection it still holds the old session, and a reconnect with the same
10
+ * identity is refused with 521 "too many clones already connected" until it
11
+ * reaps the zombie — a condition that clears itself and is worth retrying.
12
+ *
13
+ * The asymmetry is deliberate. Retrying a permanent failure costs a few bounded
14
+ * attempts; not retrying a transient one means never recovering.
15
+ */
16
+ const PERMANENT_SERVER_ERRORS: ReadonlySet<number> = new Set([
17
+ ErrorCode.ConnectFailedBanned,
18
+ ErrorCode.BanFlooding,
19
+ ErrorCode.ServerInvalidPassword,
20
+ ErrorCode.ChannelInvalidPassword,
21
+ ErrorCode.PermissionsClientInsufficient,
22
+ ]);
23
+
24
+ /**
25
+ * Whether a failure is worth another attempt.
26
+ *
27
+ * Transport failures are retried; so is a server that stopped, and a server
28
+ * error other than the known refusals — a ban, flooding, a wrong server or
29
+ * channel password, missing permissions — since some, such as 521 "too many
30
+ * clones" right after a drop, clear by themselves. A kick or a ban is not:
31
+ * someone removed the client on purpose. Nor is an AlreadyConnectedError: the
32
+ * client was connected by other means; nor an InvalidAddressError.
33
+ */
34
+ export function defaultShouldRetry(error: Error | undefined): boolean {
35
+ // The client is connected, or connecting, already: there is nothing to retry.
36
+ if (error instanceof AlreadyConnectedError) return false;
37
+ // An address that cannot be one stays that way.
38
+ if (error instanceof InvalidAddressError) return false;
39
+ if (error instanceof RemovedError) {
40
+ return error.reason !== Reason.KickServer && error.reason !== Reason.KickServerBan;
41
+ }
42
+ return !(error instanceof ServerError && PERMANENT_SERVER_ERRORS.has(error.code));
43
+ }
@@ -0,0 +1,92 @@
1
+ interface Waiter {
2
+ readonly resolve: () => void;
3
+ readonly signal: AbortSignal | undefined;
4
+ readonly onAbort: () => void;
5
+ }
6
+
7
+ /**
8
+ * Token-bucket limiter for outbound TS3 commands.
9
+ * Mirrors Go's commandThrottle.
10
+ *
11
+ * Waiters are released in the order they arrived: each used to poll for a
12
+ * token on its own timer, so a command that came later could take the turn of
13
+ * one that had waited longer, and the commands went out of order.
14
+ */
15
+ export class CommandThrottle {
16
+ static readonly TOKEN_RATE = 4.0; // tokens per second
17
+ static readonly TOKEN_MAX = 8.0; // bucket capacity
18
+
19
+ #tokens = 5.0;
20
+ #lastUpdate = performance.now();
21
+ readonly #waiters: Waiter[] = [];
22
+ #timer: ReturnType<typeof setTimeout> | undefined;
23
+
24
+ /**
25
+ * Wait for a token, behind every earlier waiter. Aborting `signal` rejects
26
+ * with its reason and gives the place in line up; the abort listener is
27
+ * removed however the wait ends.
28
+ */
29
+ wait(signal?: AbortSignal): Promise<void> {
30
+ if (signal?.aborted) return Promise.reject(signal.reason);
31
+ this.#refill();
32
+ if (this.#waiters.length === 0 && this.#tokens >= 1.0) {
33
+ this.#tokens -= 1.0;
34
+ return Promise.resolve();
35
+ }
36
+ return new Promise<void>((resolve, reject) => {
37
+ const waiter: Waiter = {
38
+ resolve,
39
+ signal,
40
+ onAbort: () => {
41
+ const index = this.#waiters.indexOf(waiter);
42
+ if (index >= 0) this.#waiters.splice(index, 1);
43
+ if (this.#waiters.length === 0) this.#stopTimer();
44
+ reject(signal!.reason);
45
+ },
46
+ };
47
+ signal?.addEventListener("abort", waiter.onAbort, { once: true });
48
+ this.#waiters.push(waiter);
49
+ this.#schedule();
50
+ });
51
+ }
52
+
53
+ #refill(): void {
54
+ const now = performance.now();
55
+ const elapsed = (now - this.#lastUpdate) / 1000;
56
+ this.#tokens = Math.min(
57
+ this.#tokens + elapsed * CommandThrottle.TOKEN_RATE,
58
+ CommandThrottle.TOKEN_MAX,
59
+ );
60
+ this.#lastUpdate = now;
61
+ }
62
+
63
+ /** Arm the timer for when the next token is due, unless it already is. */
64
+ #schedule(): void {
65
+ if (this.#timer !== undefined || this.#waiters.length === 0) return;
66
+ const waitMs =
67
+ this.#tokens >= 1.0
68
+ ? 0
69
+ : Math.ceil(((1.0 - this.#tokens) / CommandThrottle.TOKEN_RATE) * 1000) + 10;
70
+ this.#timer = setTimeout(() => {
71
+ this.#timer = undefined;
72
+ this.#release();
73
+ }, waitMs);
74
+ }
75
+
76
+ #stopTimer(): void {
77
+ clearTimeout(this.#timer);
78
+ this.#timer = undefined;
79
+ }
80
+
81
+ /** Hand the tokens there are to the waiters at the head of the line. */
82
+ #release(): void {
83
+ this.#refill();
84
+ while (this.#waiters.length > 0 && this.#tokens >= 1.0) {
85
+ this.#tokens -= 1.0;
86
+ const waiter = this.#waiters.shift()!;
87
+ waiter.signal?.removeEventListener("abort", waiter.onAbort);
88
+ waiter.resolve();
89
+ }
90
+ this.#schedule();
91
+ }
92
+ }
@@ -0,0 +1,237 @@
1
+ import type { ChannelID, ClientID } from "@honeybbq/teamspeak";
2
+ import type { ServerCapabilities } from "./capabilities.js";
3
+ import type { ResolvedAddr } from "./types.js";
4
+
5
+ /** The values of the table below, before freezing. */
6
+ const connectPhaseValues = {
7
+ /** Opening the socket, or the address was not usable once resolved. */
8
+ Open: "open",
9
+ /** The handshake, from the first packet until the shared secret exists. */
10
+ Handshake: "handshake",
11
+ /** After the handshake, waiting for the server to accept the client: a wrong password, a ban or an invalid nickname end here. */
12
+ Join: "join",
13
+ } as const;
14
+ /** Where a connection attempt can fail; see {@link AttemptFailedInfo}. */
15
+ export const ConnectPhase: typeof connectPhaseValues =
16
+ /* @__PURE__ */ Object.freeze(connectPhaseValues);
17
+ /**
18
+ * One of {@link ConnectPhase}. May gain members in a minor release: a
19
+ * `switch` over it needs a default case.
20
+ */
21
+ export type ConnectPhase = (typeof ConnectPhase)[keyof typeof ConnectPhase];
22
+
23
+ /** What every milestone of one connection attempt says about the attempt. */
24
+ interface AttemptInfo {
25
+ /**
26
+ * The attempt's number, from 1. The attempt `connect()` starts is 1; a
27
+ * reconnection attempt carries the retry number the reconnect policy uses,
28
+ * the one `shouldRetry` and the backoff see.
29
+ */
30
+ readonly attempt: number;
31
+ /** Whether the reconnect loop started this attempt rather than a call to `connect()`. */
32
+ readonly reconnect: boolean;
33
+ }
34
+
35
+ /** The address is about to be resolved. */
36
+ export interface ResolveStartInfo extends AttemptInfo {
37
+ /** The address as the client was given it. */
38
+ readonly addr: string;
39
+ }
40
+
41
+ /** The address has been resolved, or the lookup failed and the address is used as given. */
42
+ export interface ResolveDoneInfo extends AttemptInfo {
43
+ /** The address as the client was given it. */
44
+ readonly addr: string;
45
+ /** The `host:port` that will be dialled. */
46
+ readonly target: string;
47
+ /** What the resolver reports as the source of the answer dialled; may be empty. */
48
+ readonly source: string;
49
+ /** Every answer the resolver gave, in order; empty when the address is used as given. */
50
+ readonly candidates: readonly ResolvedAddr[];
51
+ /** Why the lookup failed, when the address is used as given; `undefined` otherwise. */
52
+ readonly error: unknown;
53
+ /** How long the resolution took, in milliseconds. */
54
+ readonly durationMs: number;
55
+ }
56
+
57
+ /** The socket is about to be opened. */
58
+ export interface ConnectStartInfo extends AttemptInfo {
59
+ /** The `host:port` being dialled. */
60
+ readonly target: string;
61
+ }
62
+
63
+ /** The socket is open; the first handshake packet has not been sent yet. */
64
+ export interface ConnectDoneInfo extends AttemptInfo {
65
+ /** The `host:port` being dialled. */
66
+ readonly target: string;
67
+ /** The local socket's `host:port`; empty when the socket does not say. */
68
+ readonly localAddr: string;
69
+ /** Milliseconds since `connectStart`. */
70
+ readonly durationMs: number;
71
+ }
72
+
73
+ /** The encrypted session exists; `clientinit` has not been sent yet. */
74
+ export interface HandshakeDoneInfo extends AttemptInfo {
75
+ /** Milliseconds since `connectStart`. */
76
+ readonly durationMs: number;
77
+ /** The level of the RSA puzzle the server demanded; 0 if it sent none. */
78
+ readonly puzzleLevel: number;
79
+ /** Milliseconds spent solving the puzzle. */
80
+ readonly puzzleDurationMs: number;
81
+ /**
82
+ * The packets sent again from `connectStart` to now, for want of an
83
+ * acknowledgement: the Init1 steps and the handshake's command packets.
84
+ */
85
+ readonly resends: number;
86
+ /**
87
+ * The server's public key exactly as it sent it, base64, so that a caller can
88
+ * pin a server's identity.
89
+ */
90
+ readonly serverPublicKey: string;
91
+ }
92
+
93
+ /** The server accepted the client, which is now connected. */
94
+ export interface SessionStartInfo extends AttemptInfo {
95
+ /** The client's ID on the server, the same as `client.clientID`. */
96
+ readonly clientID: ClientID;
97
+ /**
98
+ * The nickname the server accepted (`acn`), which differs from the one asked
99
+ * for when that was taken. The one asked for when the server did not say.
100
+ */
101
+ readonly nickname: string;
102
+ /** The client's talk power (`client_talk_power`); 0 when the server did not say. */
103
+ readonly talkPower: number;
104
+ /**
105
+ * Every parameter of `initserver`, unescaped, except those that could carry a
106
+ * secret: `client_server_password`, `client_default_channel_password`,
107
+ * `client_default_token` and `client_key_offset`. Frozen.
108
+ */
109
+ readonly initServer: Readonly<Record<string, string>>;
110
+ /** What the server said about itself in this handshake. */
111
+ readonly capabilities: ServerCapabilities;
112
+ /** Milliseconds since `connectStart`. */
113
+ readonly durationMs: number;
114
+ }
115
+
116
+ /** The server's welcome sequence ended: the channel list and the clients already there have arrived. */
117
+ export interface WelcomeDoneInfo extends AttemptInfo {
118
+ /**
119
+ * The channel the client is in at the end of the welcome: where it landed,
120
+ * which differs from the default channel asked for when that was refused.
121
+ */
122
+ readonly channelID: ChannelID;
123
+ /** How many channel rows the welcome delivered. */
124
+ readonly channels: number;
125
+ /** How many clients are in view at the end of the welcome, this client included. */
126
+ readonly clients: number;
127
+ /** Milliseconds since `connectStart`. */
128
+ readonly durationMs: number;
129
+ }
130
+
131
+ /** An attempt ended without a session. */
132
+ export interface AttemptFailedInfo extends AttemptInfo {
133
+ /** Where the attempt failed. */
134
+ readonly phase: ConnectPhase;
135
+ /** Why: the error `connect()` rejects with, or the one that ended the reconnection attempt. */
136
+ readonly error: unknown;
137
+ /** The `host:port` being dialled; empty when the attempt failed before `resolveDone`. */
138
+ readonly target: string;
139
+ /** Milliseconds since `resolveStart`. */
140
+ readonly durationMs: number;
141
+ }
142
+
143
+ /** The reconnect loop will retry, after a wait. */
144
+ export interface ReconnectScheduledInfo {
145
+ /** The attempt that will follow, numbered as in {@link ResolveStartInfo.attempt}. */
146
+ readonly attempt: number;
147
+ /** How long the loop waits first, in milliseconds. */
148
+ readonly delayMs: number;
149
+ /** The error that ended the previous connection or attempt. */
150
+ readonly cause: unknown;
151
+ }
152
+
153
+ /** A connected session is about to be left with `disconnect()`. It has no fields yet. */
154
+ export interface DisconnectStartInfo {}
155
+
156
+ /** The goodbye of `disconnect()` is over. */
157
+ export interface DisconnectDoneInfo {
158
+ /** Whether the server acknowledged the goodbye before the goodbye timeout. */
159
+ readonly acknowledged: boolean;
160
+ /** Milliseconds since `disconnectStart`. */
161
+ readonly durationMs: number;
162
+ }
163
+
164
+ /** A session that had a `sessionStart` has ended, however it ended. */
165
+ export interface SessionEndInfo {
166
+ /** The client's ID on the server during the session. */
167
+ readonly clientID: ClientID;
168
+ /**
169
+ * `undefined` after `disconnect()`, and otherwise the cause the
170
+ * `disconnected` event gets.
171
+ */
172
+ readonly error: unknown;
173
+ /** Milliseconds since `sessionStart`. */
174
+ readonly durationMs: number;
175
+ /** The number of the attempt that started the session. */
176
+ readonly attempt: number;
177
+ /** Whether the reconnect loop started the attempt that started the session. */
178
+ readonly reconnect: boolean;
179
+ }
180
+
181
+ /** The reconnect loop ended without a session. */
182
+ export interface ReconnectStoppedInfo {
183
+ /** How many reconnection attempts the loop made. */
184
+ readonly attempts: number;
185
+ /**
186
+ * The error `shouldRetry` declined, or the last attempt's when the attempts
187
+ * ran out; `undefined` when `disconnect()` stopped the loop.
188
+ */
189
+ readonly cause: unknown;
190
+ }
191
+
192
+ /**
193
+ * Hooks that observe a client for timing, metrics, logs or a progress
194
+ * display: the milestones of every connection attempt, the end of a session,
195
+ * and the reconnect loop. Every hook is optional.
196
+ *
197
+ * A hook is called synchronously, at the moment of the milestone, and the
198
+ * client waits for it to return: keep it quick, and hand slow work to your own
199
+ * task. What it returns is ignored, and a returned promise is never awaited. A
200
+ * hook that throws, or whose promise rejects, is reported the way a throwing
201
+ * event listener is, and the client carries on. A hook may read the
202
+ * client's state. It must not call `connect()` or `disconnect()`: to give up
203
+ * on an attempt, abort the signal passed to `connect()`, and to leave once
204
+ * connected, call `disconnect()` from a `connected` listener.
205
+ *
206
+ * Every attempt ends with exactly one of `sessionStart` and `attemptFailed`,
207
+ * and every session that started with exactly one `sessionEnd`. The hooks are
208
+ * read when the client is made, from a copy of this object.
209
+ */
210
+ export interface ClientTrace {
211
+ /** Before the address is resolved. */
212
+ readonly resolveStart?: (info: ResolveStartInfo) => void;
213
+ /** After the address is resolved, also when it fell back to the address as given. */
214
+ readonly resolveDone?: (info: ResolveDoneInfo) => void;
215
+ /** Right before the socket is opened. */
216
+ readonly connectStart?: (info: ConnectStartInfo) => void;
217
+ /** Once the socket is open, before the first handshake packet is sent. */
218
+ readonly connectDone?: (info: ConnectDoneInfo) => void;
219
+ /** When the shared secret is derived, before `clientinit` is sent. */
220
+ readonly handshakeDone?: (info: HandshakeDoneInfo) => void;
221
+ /** When the server accepts the client: before `connect()` resolves and before `connected` is delivered. */
222
+ readonly sessionStart?: (info: SessionStartInfo) => void;
223
+ /** When the server's welcome sequence ends; at most once per attempt, and only after `sessionStart`. */
224
+ readonly welcomeDone?: (info: WelcomeDoneInfo) => void;
225
+ /** When an attempt ends without `sessionStart`, for any reason, an abort or `disconnect()` included. */
226
+ readonly attemptFailed?: (info: AttemptFailedInfo) => void;
227
+ /** When `disconnect()` begins saying goodbye to a connected session. */
228
+ readonly disconnectStart?: (info: DisconnectStartInfo) => void;
229
+ /** When that goodbye is over. */
230
+ readonly disconnectDone?: (info: DisconnectDoneInfo) => void;
231
+ /** When a session ends, however it ends; before `disconnected` is queued. */
232
+ readonly sessionEnd?: (info: SessionEndInfo) => void;
233
+ /** When the reconnect loop has decided to retry and is about to wait. */
234
+ readonly reconnectScheduled?: (info: ReconnectScheduledInfo) => void;
235
+ /** When the reconnect loop ends without a session. */
236
+ readonly reconnectStopped?: (info: ReconnectStoppedInfo) => void;
237
+ }