antoine-pous / node-teamspeak3-client

😱 A TeamSpeak3 ServerQuery client with anti-ban feature, prepared statements and a lot of cool stuffs
ISC License
5 stars 0 forks source link

Promise / Await #4

Closed XeroxDev closed 6 years ago

XeroxDev commented 7 years ago

Hey!

Is there a way to use await for the query's, because I think it's better then 1000 callbacks stacked into another. And can you maybe add more informations like: isConnected?

Exampel:

let tsconnect = await TS3Client.connect(host, port, whitelisted);
if(tsconnect.isConnected == false)
    socket.emit("error", tsconnected.msg) //Error!: Wrong username or password
else
   await TS3Client.TS3Client.execute('login', [login, pass]);

and it is better for multiple event handlings.

Or can you give me more examples, how I can do better Event-Handling without these 1000 callbacks?

Kind regards XeroxDev

antoine-pous commented 7 years ago

I've never tried to use my package with promise, i'll made some tests and come back later with required enhancements and examples ;)

XeroxDev commented 7 years ago

Wow, nice!

And thanks for this fast answer! :)

XeroxDev commented 7 years ago

And a list with all on("cliententerview") events would be nice.

Edit: Nevermind, found a small list :D

antoine-pous commented 7 years ago

I don't understand your last message, all events are available into the PDF provided with the server. I can add a list to the README but the client don't use a stored list, if the TeamSpeak devs add a new notice it will be supported without any client update.

I'm currently testing the promise implementation, it should be released this week.

XeroxDev commented 7 years ago

I don't understand your last message, all events are available into the PDF provided with the server. I can add a list to the README but the client don't use a stored list, if the TeamSpeak devs add a new notice it will be supported without any client update.

I already found a list. But thanks :D

I'm currently testing the promise implementation, it should be released this week.

Ok, nice. I'm happy about this.

antoine-pous commented 6 years ago

I finally had some time to develop the client, and it become fairly stable.

As soon as I still have a little time I write unit tests and publish it ;)

Here is a small example:

import QueryClient, {iError, iHost} from "@ts3/query-client";

let host: string = '127.0.0.1';
let port: number = 10011;
let user: string = "serveradmin";
let pass: string = "fernand";

let shutdown = (i: number = 1) => {
    console.log(`Process exit ${i}`);
    process.exit(i);
};

let TS3Client = new QueryClient;

TS3Client.on("connect", (host, port) => {
    console.log(`connected to ${host}:${port}!`)
});

TS3Client.on("error", (error) => {
   console.log(error);
});

(async () => {

    await TS3Client.connect(host, port).catch((e: iError) => {
        console.log(e.id, e.msg);
        shutdown();
    });

    let logged = await TS3Client.send(`login ${user} ${pass}`);

    if(!logged) return shutdown();

    console.log('Logged in!');

})();
XeroxDev commented 6 years ago

Wow, very pretty nice! ❤

antoine-pous commented 6 years ago

I've released a first version without units tests for testing purpose, take a look at v3 branch, this is clearly a pre-release ;)

You can install it with npm install antoine-pous/node-teamspeak3-client#v3, feel free to open tickets if you found any issue ;)