@honeybbq/teamspeak-client 0.1.1 → 0.2.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.
package/dist/index.mjs CHANGED
@@ -1,16 +1,16 @@
1
1
  import { n as e, r as t, t as n } from "./types-CGKgXvpG.js";
2
- import { C as r, S as i, _ as a, b as o, d as s, g as c, h as l, l as u, o as d, p as f, r as p, u as m, v as ee, w as h, x as g, y as _ } from "./primitives-BIAYfJ2Y.js";
2
+ import { C as r, S as i, _ as a, b as o, d as s, g as c, h as l, l as u, o as d, p as ee, r as f, u as p, v as m, w as h, x as g, y as _ } from "./primitives-BIAYfJ2Y.js";
3
3
  import { t as v } from "./crypto-VC7n6YJb.js";
4
4
  import { t as y } from "./resolver-DDZWomrF.js";
5
5
  import { a as b, t as x } from "./handler-C_JhqGTd.js";
6
6
  import { i as S, n as C, t as w } from "./command-caXc4h0n.js";
7
- import { n as T } from "./crypt-handshake-CHmvZ2qs.js";
8
- import { t as E } from "./crypt-init2-DWX7Tp-_.js";
9
- import { t as D } from "./parser-CJjP3LlO.js";
10
- import { createHash as O } from "node:crypto";
11
- import { createConnection as k } from "node:net";
7
+ import { n as te } from "./crypt-handshake-CHmvZ2qs.js";
8
+ import { t as T } from "./crypt-init2-DWX7Tp-_.js";
9
+ import { t as E } from "./parser-CJjP3LlO.js";
10
+ import { createHash as D } from "node:crypto";
11
+ import { createConnection as O } from "node:net";
12
12
  //#region src/commands.ts
13
- var A = class {
13
+ var k = class {
14
14
  #e = /* @__PURE__ */ new Map();
15
15
  #t = 0;
16
16
  #n = [];
@@ -50,7 +50,7 @@ var A = class {
50
50
  this.#e.clear(), this.#n = [], this.#r = !1, this.#t = 0;
51
51
  }
52
52
  };
53
- function j(e) {
53
+ function A(e) {
54
54
  let t = e.id ?? "0", n = e.msg ?? "", i = e.return_code, a = null;
55
55
  t !== "0" && (a = new r(t, n));
56
56
  let o = null;
@@ -63,12 +63,12 @@ function j(e) {
63
63
  rc: o
64
64
  };
65
65
  }
66
- function M(e, t) {
66
+ function j(e, t) {
67
67
  return e.includes("return_code=") ? e : `${e} return_code=${t}`;
68
68
  }
69
69
  //#endregion
70
70
  //#region src/transfer.ts
71
- var N = class {
71
+ var M = class {
72
72
  #e = /* @__PURE__ */ new Map();
73
73
  #t = 0;
74
74
  register() {
@@ -89,9 +89,9 @@ var N = class {
89
89
  this.#e.clear(), this.#t = 0;
90
90
  }
91
91
  };
92
- function P(e, t, n) {
92
+ function N(e, t, n) {
93
93
  return new Promise((r, i) => {
94
- let a = k({
94
+ let a = O({
95
95
  host: e,
96
96
  port: t
97
97
  }, () => {
@@ -104,19 +104,19 @@ function P(e, t, n) {
104
104
  });
105
105
  });
106
106
  }
107
- async function F(e, t, n) {
108
- let r = await P(e, t.port, t.fileTransferKey);
107
+ async function P(e, t, n) {
108
+ let r = await N(e, t.port, t.fileTransferKey);
109
109
  await new Promise((e, t) => {
110
110
  n.pipe(r), r.on("finish", e), r.on("error", t);
111
111
  });
112
112
  }
113
- async function I(e, t, n) {
114
- let r = await P(e, t.port, t.fileTransferKey);
113
+ async function F(e, t, n) {
114
+ let r = await N(e, t.port, t.fileTransferKey);
115
115
  await new Promise((e, t) => {
116
116
  r.pipe(n), n.on("finish", e), r.on("error", t), n.on("error", t);
117
117
  });
118
118
  }
119
- function L(e, t, n, r, i, a) {
119
+ function I(e, t, n, r, i, a) {
120
120
  let o = t.startsWith("/") ? t : `/${t}`;
121
121
  return w("ftinitupload", {
122
122
  cid: String(e),
@@ -128,7 +128,7 @@ function L(e, t, n, r, i, a) {
128
128
  resume: "0"
129
129
  });
130
130
  }
131
- function R(e, t, n, r) {
131
+ function L(e, t, n, r) {
132
132
  let i = t.startsWith("/") ? t : `/${t}`;
133
133
  return w("ftinitdownload", {
134
134
  cid: String(e),
@@ -140,28 +140,28 @@ function R(e, t, n, r) {
140
140
  }
141
141
  //#endregion
142
142
  //#region src/events.ts
143
- function z(e, t) {
143
+ function R(e, t) {
144
144
  let n = t;
145
145
  for (let t = e.length - 1; t >= 0; t--) n = e[t](n);
146
146
  return n;
147
147
  }
148
- function B(e, t) {
148
+ function z(e, t) {
149
149
  let n = t;
150
150
  for (let t = e.length - 1; t >= 0; t--) n = e[t](n);
151
151
  return n;
152
152
  }
153
153
  //#endregion
154
154
  //#region src/handshake.ts
155
- function V(e, t) {
155
+ function B(e, t) {
156
156
  let n = t.alpha ?? "", r = t.beta ?? "", i = t.omega ?? "";
157
- e.crypt.initCrypto(n, r, i), e.logger.info("crypto initialized (P-256 path), sending clientinit"), G(e);
157
+ e.crypt.initCrypto(n, r, i), e.logger.info("crypto initialized (P-256 path), sending clientinit"), K(e);
158
158
  }
159
- function H(e, t) {
159
+ function V(e, t) {
160
160
  e.logger.info("received initivexpand2"), e.handler.receivedFinalInitAck();
161
- let n = t.l ?? "", r = t.omega ?? "", i = t.proof ?? "", a = t.beta ?? "", o = te(e, a);
162
- E(e.crypt, n, r, i, a, o), G(e);
161
+ let n = t.l ?? "", r = t.omega ?? "", i = t.proof ?? "", a = t.beta ?? "", o = U(e, a);
162
+ T(e.crypt, n, r, i, a, o), K(e);
163
163
  }
164
- function U(e, t) {
164
+ function H(e, t) {
165
165
  let n = t.aclid ?? t.clid ?? "", r = n ? parseInt(n, 10) : 0;
166
166
  r > 0 && (e.clid = r, e.handler.setClientID(r)), e.logger.info("connected to server", { selfId: e.clid }), e._markConnected(), setImmediate(() => {
167
167
  let t = w("clientupdate", {
@@ -171,8 +171,8 @@ function U(e, t) {
171
171
  e.sendCommandNoWait(t).catch(() => {});
172
172
  });
173
173
  }
174
- function te(e, t) {
175
- let [n, r] = p(), i = Buffer.from(n).toString("base64"), a = W(e, n, t), o = C("clientek", [["ek", i], ["proof", a]]);
174
+ function U(e, t) {
175
+ let [n, r] = f(), i = Buffer.from(n).toString("base64"), a = W(e, n, t), o = C("clientek", [["ek", i], ["proof", a]]);
176
176
  return e.handler.sendPacket(b.Command, Buffer.from(o), 0), r;
177
177
  }
178
178
  function W(e, t, n) {
@@ -182,27 +182,34 @@ function W(e, t, n) {
182
182
  return Buffer.from(a).toString("base64");
183
183
  }
184
184
  function G(e) {
185
- let t = e.crypt.identity.publicKeyBase64(), n = O("sha1").update(t).digest().toString("base64"), r = C("clientinit", [
185
+ return e === "" ? "" : D("sha1").update(e).digest().toString("base64");
186
+ }
187
+ function K(e) {
188
+ let t = q(e);
189
+ e.handler.sendPacket(b.Command, Buffer.from(t), 0);
190
+ }
191
+ function q(e) {
192
+ let t = e.crypt.identity.publicKeyBase64(), n = e.getClientInitOptions(), r = G(n.defaultChannelPassword), i = G(n.serverPassword), a = D("sha1").update(t).digest().toString("base64");
193
+ return C("clientinit", [
186
194
  ["client_nickname", e.nickname],
187
195
  ["client_version", "3.?.? [Build: 5680278000]"],
188
196
  ["client_platform", "Windows"],
189
197
  ["client_input_hardware", "1"],
190
198
  ["client_output_hardware", "1"],
191
- ["client_default_channel", ""],
192
- ["client_default_channel_password", ""],
193
- ["client_server_password", ""],
199
+ ["client_default_channel", n.defaultChannel],
200
+ ["client_default_channel_password", r],
201
+ ["client_server_password", i],
194
202
  ["client_meta_data", ""],
195
203
  ["client_version_sign", "DX5NIYLvfJEUjuIbCidnoeozxIDRRkpq3I9vVMBmE9L2qnekOoBzSenkzsg2lC9CMv8K5hkEzhr2TYUYSwUXCg=="],
196
204
  ["client_key_offset", String(e.crypt.identity.offset)],
197
205
  ["client_nickname_phonetic", ""],
198
206
  ["client_default_token", ""],
199
- ["hwid", n]
207
+ ["hwid", a]
200
208
  ]);
201
- e.handler.sendPacket(b.Command, Buffer.from(r), 0);
202
209
  }
203
210
  //#endregion
204
211
  //#region src/helpers.ts
205
- function K(e) {
212
+ function J(e) {
206
213
  if (e === "" || e === void 0) return 0n;
207
214
  try {
208
215
  return BigInt(e);
@@ -210,21 +217,21 @@ function K(e) {
210
217
  return 0n;
211
218
  }
212
219
  }
213
- function q(e) {
220
+ function Y(e) {
214
221
  let t = parseInt(e, 10);
215
222
  return isNaN(t) || t < 0 || t > 65535 ? 0 : t;
216
223
  }
217
- function J(e) {
224
+ function X(e) {
218
225
  let t = parseInt(e, 10);
219
226
  return isNaN(t) ? 0 : t;
220
227
  }
221
- function Y(e, t) {
228
+ function Z(e, t) {
222
229
  if (t === e) return !0;
223
230
  if (!t.startsWith(e)) return !1;
224
231
  let n = t.slice(e.length);
225
232
  return /^\d+$/.test(n);
226
233
  }
227
- function X(e) {
234
+ function Q(e) {
228
235
  let t = e.indexOf(" ");
229
236
  if (t < 0) return [e];
230
237
  let n = e.slice(0, t), r = e.slice(t + 1);
@@ -235,30 +242,30 @@ function X(e) {
235
242
  }
236
243
  //#endregion
237
244
  //#region src/notifications.ts
238
- function Z(e, t, n, r) {
245
+ function ne(e, t, n, r) {
239
246
  switch (e.name) {
240
- case "notifycliententerview": return Q(e, n, r);
241
- case "notifyclientleftview": return ne(e, t, n);
242
- case "notifyclientmoved": return re(e, n);
243
- case "notifytextmessage": return ie(e, n);
244
- case "notifyclientpoke": return se(e);
247
+ case "notifycliententerview": return re(e, n, r);
248
+ case "notifyclientleftview": return ie(e, t, n);
249
+ case "notifyclientmoved": return ae(e, n);
250
+ case "notifytextmessage": return oe(e, n);
251
+ case "notifyclientpoke": return ue(e);
245
252
  case "notifystartupload": return {
246
253
  kind: "startUpload",
247
- info: ae(e)
254
+ info: se(e)
248
255
  };
249
256
  case "notifystartdownload": return {
250
257
  kind: "startDownload",
251
- info: oe(e)
258
+ info: ce(e)
252
259
  };
253
260
  case "notifystatusfiletransfer": return {
254
261
  kind: "fileTransferStatus",
255
- info: $(e)
262
+ info: le(e)
256
263
  };
257
264
  default: return { kind: "unknown" };
258
265
  }
259
266
  }
260
- function Q(e, t, n) {
261
- let r = q(e.params.clid ?? ""), i = K(e.params.cid ?? ""), a = J(e.params.client_type ?? ""), o = e.params.client_servergroups ?? "", s = {
267
+ function re(e, t, n) {
268
+ let r = Y(e.params.clid ?? ""), i = J(e.params.cid ?? ""), a = X(e.params.client_type ?? ""), o = e.params.client_servergroups ?? "", s = {
262
269
  id: r,
263
270
  nickname: e.params.client_nickname ?? "",
264
271
  uid: e.params.client_unique_identifier ?? "",
@@ -271,21 +278,21 @@ function Q(e, t, n) {
271
278
  info: s
272
279
  };
273
280
  }
274
- function ne(e, t, n) {
275
- let r = q(e.params.clid ?? ""), i = J(e.params.reasonid ?? ""), a = r === t;
281
+ function ie(e, t, n) {
282
+ let r = Y(e.params.clid ?? ""), i = X(e.params.reasonid ?? ""), a = r === t;
276
283
  return r !== 0 && n.delete(r), {
277
284
  kind: "clientLeave",
278
285
  event: {
279
286
  id: r,
280
287
  reasonID: i,
281
288
  reasonMsg: e.params.reasonmsg ?? "",
282
- targetID: q(e.params.targetid ?? "")
289
+ targetID: Y(e.params.targetid ?? "")
283
290
  },
284
291
  isSelf: a
285
292
  };
286
293
  }
287
- function re(e, t) {
288
- let n = q(e.params.clid ?? ""), r = K(e.params.ctid ?? "");
294
+ function ae(e, t) {
295
+ let n = Y(e.params.clid ?? ""), r = J(e.params.ctid ?? "");
289
296
  if (n !== 0) {
290
297
  let e = t.get(n);
291
298
  e && t.set(n, {
@@ -298,20 +305,20 @@ function re(e, t) {
298
305
  event: {
299
306
  id: n,
300
307
  targetChannelID: r,
301
- reasonID: J(e.params.reasonid ?? ""),
302
- invokerID: q(e.params.invokerid ?? ""),
308
+ reasonID: X(e.params.reasonid ?? ""),
309
+ invokerID: Y(e.params.invokerid ?? ""),
303
310
  invokerName: e.params.invokername ?? "",
304
311
  invokerUID: e.params.invokeruid ?? ""
305
312
  }
306
313
  };
307
314
  }
308
- function ie(e, t) {
309
- let n = q(e.params.invokerid ?? ""), r = t.get(n);
315
+ function oe(e, t) {
316
+ let n = Y(e.params.invokerid ?? ""), r = t.get(n);
310
317
  return {
311
318
  kind: "textMessage",
312
319
  message: {
313
- targetMode: J(e.params.targetmode ?? ""),
314
- targetID: K(e.params.target ?? ""),
320
+ targetMode: X(e.params.targetmode ?? ""),
321
+ targetID: J(e.params.target ?? ""),
315
322
  invokerID: n,
316
323
  invokerName: e.params.invokername ?? "",
317
324
  invokerUID: e.params.invokeruid ?? r?.uid ?? "",
@@ -320,36 +327,36 @@ function ie(e, t) {
320
327
  }
321
328
  };
322
329
  }
323
- function ae(e) {
330
+ function se(e) {
324
331
  return {
325
- clientFileTransferID: q(e.params.clientftfid ?? ""),
326
- serverFileTransferID: q(e.params.serverftfid ?? ""),
332
+ clientFileTransferID: Y(e.params.clientftfid ?? ""),
333
+ serverFileTransferID: Y(e.params.serverftfid ?? ""),
327
334
  fileTransferKey: e.params.ftkey ?? "",
328
- port: q(e.params.port ?? ""),
329
- seekPosition: K(e.params.seekpos ?? "")
335
+ port: Y(e.params.port ?? ""),
336
+ seekPosition: J(e.params.seekpos ?? "")
330
337
  };
331
338
  }
332
- function oe(e) {
339
+ function ce(e) {
333
340
  return {
334
- clientFileTransferID: q(e.params.clientftfid ?? ""),
335
- serverFileTransferID: q(e.params.serverftfid ?? ""),
341
+ clientFileTransferID: Y(e.params.clientftfid ?? ""),
342
+ serverFileTransferID: Y(e.params.serverftfid ?? ""),
336
343
  fileTransferKey: e.params.ftkey ?? "",
337
- port: q(e.params.port ?? ""),
338
- size: K(e.params.size ?? "")
344
+ port: Y(e.params.port ?? ""),
345
+ size: J(e.params.size ?? "")
339
346
  };
340
347
  }
341
- function $(e) {
348
+ function le(e) {
342
349
  return {
343
- clientFileTransferID: q(e.params.clientftfid ?? ""),
344
- status: J(e.params.status ?? ""),
350
+ clientFileTransferID: Y(e.params.clientftfid ?? ""),
351
+ status: X(e.params.status ?? ""),
345
352
  message: e.params.msg ?? ""
346
353
  };
347
354
  }
348
- function se(e) {
355
+ function ue(e) {
349
356
  return {
350
357
  kind: "poked",
351
358
  event: {
352
- invokerID: q(e.params.invokerid ?? ""),
359
+ invokerID: Y(e.params.invokerid ?? ""),
353
360
  invokerName: S(e.params.invokername ?? ""),
354
361
  invokerUID: e.params.invokeruid ?? "",
355
362
  message: S(e.params.msg ?? "")
@@ -358,7 +365,7 @@ function se(e) {
358
365
  }
359
366
  //#endregion
360
367
  //#region src/throttle.ts
361
- var ce = class e {
368
+ var de = class e {
362
369
  static TOKEN_RATE = 4;
363
370
  static TOKEN_MAX = 8;
364
371
  #e = 5;
@@ -380,7 +387,17 @@ var ce = class e {
380
387
  });
381
388
  }
382
389
  }
383
- }, le = class {
390
+ };
391
+ //#endregion
392
+ //#region src/client.ts
393
+ function fe(e) {
394
+ return {
395
+ serverPassword: e.serverPassword ?? "",
396
+ defaultChannel: e.defaultChannel ?? "",
397
+ defaultChannelPassword: e.defaultChannelPassword ?? ""
398
+ };
399
+ }
400
+ var pe = class {
384
401
  crypt;
385
402
  handler;
386
403
  logger;
@@ -389,12 +406,12 @@ var ce = class e {
389
406
  #e;
390
407
  #t;
391
408
  #n;
392
- #r = n.Disconnected;
393
- #i = new ce();
394
- #a = new A();
395
- #o = new N();
396
- #s = /* @__PURE__ */ new Map();
397
- #c = [];
409
+ #r;
410
+ #i = n.Disconnected;
411
+ #a = new de();
412
+ #o = new k();
413
+ #s = new M();
414
+ #c = /* @__PURE__ */ new Map();
398
415
  #l = [];
399
416
  #u = [];
400
417
  #d = [];
@@ -406,108 +423,112 @@ var ce = class e {
406
423
  #_ = [];
407
424
  #v = [];
408
425
  #y = [];
409
- #b;
426
+ #b = [];
410
427
  #x;
428
+ #S;
411
429
  constructor(t, n, r, i = {}) {
412
- this.#e = t, this.#t = n, this.nickname = r, this.logger = i.logger ?? e, this.#n = i.resolver ?? new y(this.logger), this.crypt = new v(t), this.handler = new x(this.crypt, this.logger), this.handler.onPacket = (e) => this.#w(e), this.handler.onClosed = (e) => this.#N(e), i.commandMiddleware && this.#v.push(...i.commandMiddleware), i.eventMiddleware && this.#y.push(...i.eventMiddleware), this.#b = this.#P(), this.#x = this.#F();
430
+ this.#e = t, this.#t = n, this.nickname = r, this.logger = i.logger ?? e, this.#n = i.resolver ?? new y(this.logger), this.#r = fe(i), this.crypt = new v(t), this.handler = new x(this.crypt, this.logger), this.handler.onPacket = (e) => this.#T(e), this.handler.onClosed = (e) => this.#P(e), i.commandMiddleware && this.#y.push(...i.commandMiddleware), i.eventMiddleware && this.#b.push(...i.eventMiddleware), this.#x = this.#F(), this.#S = this.#I();
413
431
  }
414
432
  get status() {
433
+ return this.#i;
434
+ }
435
+ getClientInitOptions() {
415
436
  return this.#r;
416
437
  }
417
438
  async connect() {
418
- if (this.#r !== n.Disconnected) throw new l();
419
- this.#S(), this.#r = n.Connecting;
420
- let e = await this.#C();
439
+ if (this.#i !== n.Disconnected) throw new l();
440
+ this.#C(), this.#i = n.Connecting;
441
+ let e = await this.#w();
421
442
  this.logger.info("connecting to server", { address: e }), await this.handler.connect(e);
422
443
  }
423
444
  async disconnect() {
424
- if (this.#r === n.Disconnected) return;
425
- let e = this.#r === n.Connected;
426
- if (this.#r = n.Disconnected, this.logger.info("disconnecting from server"), e) try {
445
+ if (this.#i === n.Disconnected) return;
446
+ let e = this.#i === n.Connected;
447
+ if (this.#i = n.Disconnected, this.logger.info("disconnecting from server"), e) try {
427
448
  await this.execCommand("clientdisconnect reasonmsg=Shutdown", 1e3);
428
449
  } catch {}
429
450
  this.handler.close();
430
- let t = this.#g.slice();
451
+ let t = this.#_.slice();
431
452
  for (let e of t) setImmediate(() => e(void 0));
432
453
  }
433
454
  waitConnected(e) {
434
- return this.#r === n.Connected ? Promise.resolve() : new Promise((t, n) => {
435
- this.#c.push(t), e && e.addEventListener("abort", () => n(e.reason), { once: !0 });
455
+ return this.#i === n.Connected ? Promise.resolve() : new Promise((t, n) => {
456
+ this.#l.push(t), e && e.addEventListener("abort", () => n(e.reason), { once: !0 });
436
457
  });
437
458
  }
438
459
  async sendCommandNoWait(e) {
439
- await this.#i.wait(), await this.#b(e);
460
+ await this.#a.wait(), await this.#x(e);
440
461
  }
441
462
  async execCommand(e, t = 1e4) {
442
463
  await this.execCommandWithResponse(e, t);
443
464
  }
444
465
  async execCommandWithResponse(e, t = 1e4) {
445
- let [n, r] = this.#a.register(), i = M(e, n);
466
+ let [n, r] = this.#o.register(), i = j(e, n);
446
467
  try {
447
- await this.#i.wait(), await this.#b(i);
468
+ await this.#a.wait(), await this.#x(i);
448
469
  } catch (e) {
449
- throw this.#a.unregister(n), e;
470
+ throw this.#o.unregister(n), e;
450
471
  }
451
472
  let a = await Promise.race([r, new Promise((n, r) => setTimeout(() => r(new c(e)), t))]);
452
- if (this.#a.unregister(n), a.err) throw a.err;
473
+ if (this.#o.unregister(n), a.err) throw a.err;
453
474
  return a.data;
454
475
  }
455
476
  on(e, t) {
456
477
  switch (e) {
457
478
  case "textMessage":
458
- this.#l.push(t);
479
+ this.#u.push(t);
459
480
  break;
460
481
  case "clientEnter":
461
- this.#u.push(t);
482
+ this.#d.push(t);
462
483
  break;
463
484
  case "clientLeave":
464
- this.#d.push(t);
485
+ this.#f.push(t);
465
486
  break;
466
487
  case "clientMoved":
467
- this.#f.push(t);
488
+ this.#p.push(t);
468
489
  break;
469
490
  case "poked":
470
- this.#p.push(t);
491
+ this.#m.push(t);
471
492
  break;
472
493
  case "voiceData":
473
- this.#m.push(t);
494
+ this.#h.push(t);
474
495
  break;
475
496
  case "connected":
476
- this.#h.push(t);
497
+ this.#g.push(t);
477
498
  break;
478
499
  case "disconnected":
479
- this.#g.push(t);
500
+ this.#_.push(t);
480
501
  break;
481
502
  case "kicked":
482
- this.#_.push(t);
503
+ this.#v.push(t);
483
504
  break;
484
505
  }
485
506
  return this;
486
507
  }
487
508
  useCommandMiddleware(...e) {
488
- return this.#v.push(...e), this.#b = this.#P(), this;
509
+ return this.#y.push(...e), this.#x = this.#F(), this;
489
510
  }
490
511
  useEventMiddleware(...e) {
491
- return this.#y.push(...e), this.#x = this.#F(), this;
512
+ return this.#b.push(...e), this.#S = this.#I(), this;
492
513
  }
493
514
  clientID() {
494
515
  return this.clid;
495
516
  }
496
517
  channelID() {
497
- return this.#s.get(this.clid)?.channelID ?? 0n;
518
+ return this.#c.get(this.clid)?.channelID ?? 0n;
498
519
  }
499
520
  sendVoice(e, t) {
500
521
  this.handler.sendVoicePacket(e, t);
501
522
  }
502
523
  async fileTransferInitUpload(e, t, n, r, i = !1) {
503
- let [a, s] = this.#o.register(), c = L(e, t, n, r, a, i);
524
+ let [a, s] = this.#s.register(), c = I(e, t, n, r, a, i);
504
525
  try {
505
526
  await this.execCommand(c, 1e4);
506
527
  } catch (e) {
507
- throw this.#o.unregister(a), e;
528
+ throw this.#s.unregister(a), e;
508
529
  }
509
530
  let l = await Promise.race([s, new Promise((e, t) => setTimeout(() => t(new g()), 1e4))]);
510
- if (this.#o.unregister(a), "size" in l) throw new o("unexpected download response");
531
+ if (this.#s.unregister(a), "size" in l) throw new o("unexpected download response");
511
532
  if ("status" in l) {
512
533
  let e = l;
513
534
  throw new o(`${e.message} (status=${e.status})`);
@@ -515,14 +536,14 @@ var ce = class e {
515
536
  return l;
516
537
  }
517
538
  async fileTransferInitDownload(e, t, n) {
518
- let [r, i] = this.#o.register(), a = R(e, t, n, r);
539
+ let [r, i] = this.#s.register(), a = L(e, t, n, r);
519
540
  try {
520
541
  await this.execCommand(a, 1e4);
521
542
  } catch (e) {
522
- throw this.#o.unregister(r), e;
543
+ throw this.#s.unregister(r), e;
523
544
  }
524
545
  let s = await Promise.race([i, new Promise((e, t) => setTimeout(() => t(new g()), 1e4))]);
525
- if (this.#o.unregister(r), "seekPosition" in s) throw new o("unexpected upload response");
546
+ if (this.#s.unregister(r), "seekPosition" in s) throw new o("unexpected upload response");
526
547
  if ("status" in s) {
527
548
  let e = s;
528
549
  throw new o(`${e.message} (status=${e.status})`);
@@ -530,22 +551,22 @@ var ce = class e {
530
551
  return s;
531
552
  }
532
553
  uploadFileData(e, t, n) {
533
- return F(e, t, n);
554
+ return P(e, t, n);
534
555
  }
535
556
  downloadFileData(e, t, n) {
536
- return I(e, t, n);
557
+ return F(e, t, n);
537
558
  }
538
559
  _markConnected() {
539
- this.#r = n.Connected;
540
- for (let e of this.#c) e();
541
- this.#c = [];
542
- let e = this.#h.slice();
560
+ this.#i = n.Connected;
561
+ for (let e of this.#l) e();
562
+ this.#l = [];
563
+ let e = this.#g.slice();
543
564
  for (let t of e) setImmediate(() => t());
544
565
  }
545
- #S() {
546
- this.handler.close(), this.crypt = new v(this.#e), this.handler = new x(this.crypt, this.logger), this.handler.onPacket = (e) => this.#w(e), this.handler.onClosed = (e) => this.#N(e), this.#a.reset(), this.#o.reset(), this.#s.clear(), this.clid = 0, this.#b = this.#P();
566
+ #C() {
567
+ this.handler.close(), this.crypt = new v(this.#e), this.handler = new x(this.crypt, this.logger), this.handler.onPacket = (e) => this.#T(e), this.handler.onClosed = (e) => this.#P(e), this.#o.reset(), this.#s.reset(), this.#c.clear(), this.clid = 0, this.#x = this.#F();
547
568
  }
548
- async #C() {
569
+ async #w() {
549
570
  let e = this.#t.includes(":") ? this.#t : `${this.#t}:9987`;
550
571
  try {
551
572
  return (await this.#n.resolve(this.#t))[0]?.addr ?? e;
@@ -553,24 +574,24 @@ var ce = class e {
553
574
  return e;
554
575
  }
555
576
  }
556
- #w(e) {
557
- this.#T(e);
558
- }
559
577
  #T(e) {
578
+ this.#E(e);
579
+ }
580
+ #E(e) {
560
581
  let t = e.typeFlagged & 15;
561
582
  if (t === 8) {
562
- let t = T(this.crypt, e.data);
583
+ let t = te(this.crypt, e.data);
563
584
  t && this.handler.sendPacket(b.Init1, t, 0);
564
585
  return;
565
586
  }
566
587
  if ((t === 0 || t === 1) && e.data.length > 5) {
567
- this.#E(e.data);
588
+ this.#D(e.data);
568
589
  return;
569
590
  }
570
- (t === 2 || t === 3) && e.data.length > 0 && this.#D(Buffer.from(e.data).toString("utf8"));
591
+ (t === 2 || t === 3) && e.data.length > 0 && this.#O(Buffer.from(e.data).toString("utf8"));
571
592
  }
572
- #E(e) {
573
- if (this.#m.length === 0) return;
593
+ #D(e) {
594
+ if (this.#h.length === 0) return;
574
595
  let t = new DataView(e.buffer, e.byteOffset, e.byteLength).getUint16(2, !1);
575
596
  if (t === this.clid) return;
576
597
  let n = {
@@ -578,36 +599,36 @@ var ce = class e {
578
599
  codec: e[4],
579
600
  data: e.subarray(5)
580
601
  };
581
- for (let e of this.#m) setImmediate(() => e(n));
602
+ for (let e of this.#h) setImmediate(() => e(n));
582
603
  }
583
- #D(e) {
604
+ #O(e) {
584
605
  if (!e) return;
585
606
  let t = e.split(/[\n\0]/);
586
607
  for (let e of t) {
587
608
  let t = e.replace(/\r$/, "");
588
- if (t) for (let e of X(t)) this.#O(e);
609
+ if (t) for (let e of Q(t)) this.#k(e);
589
610
  }
590
611
  }
591
- #O(e) {
592
- let t = D(e);
612
+ #k(e) {
613
+ let t = E(e);
593
614
  if (!(!t || !t.name)) {
594
615
  if (t.name.startsWith("notify")) {
595
- let e = Z(t, this.clid, this.#s, this.nickname);
596
- this.#A(e, t.params);
616
+ let e = ne(t, this.clid, this.#c, this.nickname);
617
+ this.#j(e, t.params);
597
618
  return;
598
619
  }
599
620
  switch (t.name) {
600
621
  case "clientinitiv":
601
- V(this, t.params);
622
+ B(this, t.params);
602
623
  break;
603
624
  case "initivexpand2":
604
- H(this, t.params);
625
+ V(this, t.params);
605
626
  break;
606
627
  case "initserver":
607
- U(this, t.params);
628
+ H(this, t.params);
608
629
  break;
609
630
  case "error":
610
- this.#k(t.params);
631
+ this.#A(t.params);
611
632
  break;
612
633
  default: {
613
634
  let e = t.params;
@@ -618,91 +639,91 @@ var ce = class e {
618
639
  ...t.params
619
640
  };
620
641
  }
621
- this.#a.buffer(e);
642
+ this.#o.buffer(e);
622
643
  break;
623
644
  }
624
645
  }
625
646
  }
626
647
  }
627
- #k(e) {
628
- let { err: t, rc: n } = j(e);
629
- n === null ? this.#a.discardBuffer() : this.#a.resolve(n, t), (e.id ?? "0") === "3329" && setImmediate(() => this.disconnect().catch(() => {}));
648
+ #A(e) {
649
+ let { err: t, rc: n } = A(e);
650
+ n === null ? this.#o.discardBuffer() : this.#o.resolve(n, t), (e.id ?? "0") === "3329" && setImmediate(() => this.disconnect().catch(() => {}));
630
651
  }
631
- #A(e, t) {
652
+ #j(e, t) {
632
653
  switch (e.kind) {
633
654
  case "clientEnter": {
634
655
  let t = e.info;
635
- t.id !== 0 && Y(this.nickname, t.nickname) && (this.clid = t.id, this.handler.setClientID(t.id), this.#a.signalWelcomeComplete()), this.#j("clientEnter", t);
656
+ t.id !== 0 && Z(this.nickname, t.nickname) && (this.clid = t.id, this.handler.setClientID(t.id), this.#o.signalWelcomeComplete()), this.#M("clientEnter", t);
636
657
  break;
637
658
  }
638
659
  case "clientLeave":
639
- if (this.#j("clientLeave", e.event), e.isSelf && (e.event.reasonID === 4 || e.event.reasonID === 5)) {
660
+ if (this.#M("clientLeave", e.event), e.isSelf && (e.event.reasonID === 4 || e.event.reasonID === 5)) {
640
661
  let t = e.event.reasonMsg;
641
- for (let e of this.#_) setImmediate(() => e(t));
662
+ for (let e of this.#v) setImmediate(() => e(t));
642
663
  }
643
664
  break;
644
665
  case "clientMoved":
645
- this.#j("clientMoved", e.event);
666
+ this.#M("clientMoved", e.event);
646
667
  break;
647
668
  case "textMessage":
648
- this.#j("textMessage", e.message);
669
+ this.#M("textMessage", e.message);
649
670
  break;
650
671
  case "poked":
651
- this.#j("poked", e.event);
672
+ this.#M("poked", e.event);
652
673
  break;
653
674
  case "startUpload":
654
- this.#o.notify(e.info.clientFileTransferID, e.info);
675
+ this.#s.notify(e.info.clientFileTransferID, e.info);
655
676
  break;
656
677
  case "startDownload":
657
- this.#o.notify(e.info.clientFileTransferID, e.info);
678
+ this.#s.notify(e.info.clientFileTransferID, e.info);
658
679
  break;
659
680
  case "fileTransferStatus":
660
- this.#o.notify(e.info.clientFileTransferID, e.info);
681
+ this.#s.notify(e.info.clientFileTransferID, e.info);
661
682
  break;
662
683
  }
663
684
  }
664
- #j(e, t) {
665
- this.#x(t);
666
- }
667
685
  #M(e, t) {
686
+ this.#S(t);
687
+ }
688
+ #N(e, t) {
668
689
  switch (e) {
669
690
  case "textMessage":
670
- for (let e of this.#l) setImmediate(() => e(t));
691
+ for (let e of this.#u) setImmediate(() => e(t));
671
692
  break;
672
693
  case "clientEnter":
673
- for (let e of this.#u) setImmediate(() => e(t));
694
+ for (let e of this.#d) setImmediate(() => e(t));
674
695
  break;
675
696
  case "clientLeave":
676
- for (let e of this.#d) setImmediate(() => e(t));
697
+ for (let e of this.#f) setImmediate(() => e(t));
677
698
  break;
678
699
  case "clientMoved":
679
- for (let e of this.#f) setImmediate(() => e(t));
700
+ for (let e of this.#p) setImmediate(() => e(t));
680
701
  break;
681
702
  case "poked":
682
- for (let e of this.#p) setImmediate(() => e(t));
703
+ for (let e of this.#m) setImmediate(() => e(t));
683
704
  break;
684
705
  }
685
706
  }
686
- #N(e) {
687
- if (this.#r === n.Disconnected) return;
688
- this.#r = n.Disconnected;
689
- let t = this.#g.slice();
707
+ #P(e) {
708
+ if (this.#i === n.Disconnected) return;
709
+ this.#i = n.Disconnected;
710
+ let t = this.#_.slice();
690
711
  for (let n of t) setImmediate(() => n(e ?? void 0));
691
712
  }
692
- #P() {
693
- return z(this.#v, async (e) => {
713
+ #F() {
714
+ return R(this.#y, async (e) => {
694
715
  this.handler.sendPacket(b.Command, Buffer.from(e), 0);
695
716
  });
696
717
  }
697
- #F() {
698
- return B(this.#y, (e) => {
699
- typeof e == "object" && e && "invokerName" in e && "message" in e && "targetMode" in e ? this.#M("textMessage", e) : typeof e == "object" && e && "invokerName" in e && "message" in e && !("targetMode" in e) ? this.#M("poked", e) : typeof e == "object" && e && "id" in e && "uid" in e ? this.#M("clientEnter", e) : typeof e == "object" && e && "id" in e && "reasonID" in e && "targetChannelID" in e ? this.#M("clientMoved", e) : typeof e == "object" && e && "id" in e && "reasonID" in e && this.#M("clientLeave", e);
718
+ #I() {
719
+ return z(this.#b, (e) => {
720
+ typeof e == "object" && e && "invokerName" in e && "message" in e && "targetMode" in e ? this.#N("textMessage", e) : typeof e == "object" && e && "invokerName" in e && "message" in e && !("targetMode" in e) ? this.#N("poked", e) : typeof e == "object" && e && "id" in e && "uid" in e ? this.#N("clientEnter", e) : typeof e == "object" && e && "id" in e && "reasonID" in e && "targetChannelID" in e ? this.#N("clientMoved", e) : typeof e == "object" && e && "id" in e && "reasonID" in e && this.#N("clientLeave", e);
700
721
  });
701
722
  }
702
723
  };
703
724
  //#endregion
704
725
  //#region src/api.ts
705
- async function ue(e, t, n, r) {
726
+ async function $(e, t, n, r) {
706
727
  let i = C("sendtextmessage", [
707
728
  ["targetmode", String(t)],
708
729
  ["target", String(n)],
@@ -710,22 +731,22 @@ async function ue(e, t, n, r) {
710
731
  ]);
711
732
  await e.sendCommandNoWait(i);
712
733
  }
713
- async function de(e, t, n, r = "") {
734
+ async function me(e, t, n, r = "") {
714
735
  let i = [["clid", String(t)], ["cid", String(n)]];
715
736
  r && i.push(["cpw", r]);
716
737
  let a = C("clientmove", i);
717
738
  await e.execCommand(a, 1e4);
718
739
  }
719
- async function fe(e, t, n) {
740
+ async function he(e, t, n) {
720
741
  let r = C("clientpoke", [["clid", String(t)], ["msg", n]]);
721
742
  await e.execCommand(r, 1e4);
722
743
  }
723
- async function pe(e, t) {
744
+ async function ge(e, t) {
724
745
  let n = (await e.execCommandWithResponse(`clientinfo clid=${t}`, 5e3))[0];
725
746
  if (!n) throw Error(`no data returned for client ${t}`);
726
747
  return n;
727
748
  }
728
- async function me(e) {
749
+ async function _e(e) {
729
750
  return (await e.execCommandWithResponse("channellist", 5e3)).map((e) => ({
730
751
  id: BigInt(e.cid ?? "0"),
731
752
  parentID: BigInt(e.pid ?? "0"),
@@ -733,7 +754,7 @@ async function me(e) {
733
754
  description: ""
734
755
  }));
735
756
  }
736
- async function he(e) {
757
+ async function ve(e) {
737
758
  return (await e.execCommandWithResponse("clientlist -uid -away -voice -groups", 5e3)).map((e) => {
738
759
  let t = e.client_servergroups ?? "";
739
760
  return {
@@ -746,7 +767,7 @@ async function he(e) {
746
767
  };
747
768
  });
748
769
  }
749
- async function ge(e, t, n) {
770
+ async function ye(e, t, n) {
750
771
  if (n.length === 0) return;
751
772
  let r = n.join("|"), i = w("ftdeletefile", {
752
773
  cid: String(t),
@@ -756,6 +777,6 @@ async function ge(e, t, n) {
756
777
  await e.execCommand(i, 1e4);
757
778
  }
758
779
  //#endregion
759
- export { l as AlreadyConnectedError, le as Client, n as ClientStatus, c as CommandTimeoutError, a as CryptoInitError, ee as EAXTagMismatchError, _ as FakeSignatureMismatchError, o as FileTransferError, g as FileTransferTimeoutError, u as Identity, i as InvalidIdentityError, r as ServerError, h as TeamspeakError, de as clientMove, e as consoleLogger, P as dialFileTransfer, I as downloadFileData, ge as fileTransferDeleteFile, m as generateIdentity, pe as getClientInfo, s as getUidFromPublicKey, f as identityFromString, me as listChannels, he as listClients, t as noopLogger, fe as poke, ue as sendTextMessage, F as uploadFileData };
780
+ export { l as AlreadyConnectedError, pe as Client, n as ClientStatus, c as CommandTimeoutError, a as CryptoInitError, m as EAXTagMismatchError, _ as FakeSignatureMismatchError, o as FileTransferError, g as FileTransferTimeoutError, u as Identity, i as InvalidIdentityError, r as ServerError, h as TeamspeakError, me as clientMove, e as consoleLogger, N as dialFileTransfer, F as downloadFileData, ye as fileTransferDeleteFile, p as generateIdentity, ge as getClientInfo, s as getUidFromPublicKey, ee as identityFromString, _e as listChannels, ve as listClients, t as noopLogger, he as poke, $ as sendTextMessage, P as uploadFileData };
760
781
 
761
782
  //# sourceMappingURL=index.mjs.map