@honeybbq/teamspeak-client 0.1.1 → 0.2.0

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