Multivit4min / TS3-NodeJS-Library

TeamSpeak 3 Server Query Library supports SSH and RAW Query
https://multivit4min.github.io/TS3-NodeJS-Library/
MIT License
149 stars 18 forks source link

ClientDisconnect event emits data not covered by typings #129

Closed tipakA closed 4 years ago

tipakA commented 4 years ago

Describe the bug I've been using this function for handling clientdisconnect event:

function clientDisconnectEvent(bot: tipakBot, data: ClientDisconnect) {
  if (data.client?.isQuery()) return;
  console.log('Client disconnected');
}

and noticed that from time to time it errors with

TypeError: _a.isQuery is not a function

// emitted from this transpiled JS code
if ((_a = data.client) === null || _a === void 0 ? void 0 : _a.isQuery())

Then i've put it in try/catch block to log whole data object with the error, and all i am getting in such case is { clid: '1271' }.

According to typings, data.client should be TeamSpeakClient | undefined, but it clearly is not any of those, as both null check and function fail.

To Reproduce

TeamSpeak.on('clientdisconnect', data => {
  try {
    if (data.client?.isQuery()) return;
  } catch (e) {
    console.log(e);
    console.log(data.client);
  }
  console.log('Client disconnected');
}

As far as i'm aware, this only happens when a certain query client disconnects from my server, i don't really know what is so special about this one. Additionally, for unknown reasons, it does not happen every time.

Expected behavior Null check works properly, or typings cover data emitted under data.client, so you can write your function around it

Versions used

Additional context I am aware that object logged in the catch is not full object emitted, yet it still contains something as client, that is not TeamSpeakClient

Multivit4min commented 4 years ago

This is because the library might not have fetched the Client via the clientlist command. This happens most times when the query connects to get data like serverinfo and immediately disconnects again.

TeamSpeak Query will emit the clientconnect and clientdisconnect event very late where the query has actually already left again But yeah i see what i did wrong there, i still emit the client as an object with only the clid property set

will fix that and set the client property as undefined

Multivit4min commented 4 years ago

I have released a new version on npm 3.0.9 which should fix this issue