Coder Social home page Coder Social logo

node-teamspeak's Introduction

node-teamspeak

This is a tiny CommonJS-module which allows you to connect to any TeamSpeak (R)-3-Server which has the ServerQuery-API enabled. Using the ServerQuery-API, you can do everything a normal TeamSpeak-user can do (except sending and receiving voice data) automatically via JavaScript (e. g. listing clients logged in on the server).

The ServerQuery-specification is available here.

How to install

Node:

npm install node-teamspeak

Example Usage

After registering a ServerQuery-account using your TeamSpeak-Client, you can login using node-teamspeak (Alternatively, you can login as the root account "ServerAdmin" which is created during the installation of the server). The following code prints out a JSON-array containing all clients that are currently connected to the first virtual server:

var TeamSpeakClient = require("node-teamspeak"),
	util = require("util");

var cl = new TeamSpeakClient("##SERVERIP###");
cl.send("login", {client_login_name: "##USERNAME##", client_login_password: "##PASSWORD##"}, function(err, response, rawResponse){
	cl.send("use", {sid: 1}, function(err, response, rawResponse){
		cl.send("clientlist", function(err, response, rawResponse){
			console.log(util.inspect(response));
		});
	});
});

Usage information

  • TeamSpeakClient.send is the main method that executes a command. An array with options, an object with parameters and a callback-function can be passed to the send-function. The callback-function takes two parameters: err (which contains an object like {id: 1, msg: "failed"} if there was an error) and response, which is an object which contains the answer sent by the server (if there was any).
  • Every TeamSpeakClient-instance is an EventEmitter. You can install listeners to the "connect", "close" and the "error"-event. The error-event will only be fired if there was socket-error, not if a sent command failed.
  • If you want to register to notifications sent by the TeamSpeak-Server, you can send a normal command "servernotifyregister" (consider specification). Any event sent by the server that starts with "notify" is then fired as an event (e. g. as soon as a "notifyclientmove"-notification is sent by the server, the TeamSpeakClient-instance fires the "clientmove"-event with only one parameter which is an object containing the given parameters).

node-teamspeak's People

Contributors

ahmed-90 avatar cowboy avatar eluinhost avatar minorityman avatar nikeee avatar timklge avatar zyberspace avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-teamspeak's Issues

wrong name pw and ban

Hi i use your simple code and conect to my own ts..
i use a if(err) console.log(err)
and i get a err : invalid login name or password.
and i get clientlist response.
So i how get first login error but client list response is run after.
+When i run again my node server . i get a ban 600s
Why i get ban?

2014-12-08 16:57:13.374200|INFO |Query | | query from 1 127.0.0.1:49596 attempted to login with account "Node-bot" and failed!
2014-12-08 16:58:01.624200|INFO |Query | | query from 2 127.0.0.1:49635 attempted to login with account "Node-bot" and failed!
2014-12-08 16:58:11.828200|INFO |Query | | query from 3 127.0.0.1:49637 attempted to login with account "Node-bot" and failed!

How do I send parameters?

How is it exactly I send a parameter with the send function?

Working code

cl.send("clientlist", function(err, response, rawResponse) {
        console.log(util.inspect(response));
        console.log(err);
      });

Doesn't work

cl.send("clientlist -times", function(err, response, rawResponse) {
        console.log(util.inspect(response));
        console.log(err);
      });

Functions not synchronous

Hey I#m currectly working on an MEAN-Stack project and using node-teamspeak for pulling some information about specific clients. The problem is I cant return a valid result, because the function are asyncronous.

Maybe some one knows a better solution or add this functionality to the repo.

Here the code:

function CompareTeamspeakClients(forumUsers) {
  var deferred = Q.defer();
  var cl = new TeamSpeakClient("127.0.0.1");
  

  cl.send("login", {client_login_name: "serveradmin", client_login_password: "M+h8YzUA"}, function(err, response, rawResponse){
    if (err) deferred.reject(err);

    cl.send("use", {port: 9987}, function(err, response, rawResponse){
      if (err) deferred.reject(err);

      forumUsers.forEach(function(user, index){
        cl.send("clientdbfind", ["uid"], {pattern: user.tsid}, function(err, response, rawResponse){
          if (err) {
            deferred.reject(err);
          } else {
            cl.send("clientdbinfo", {cldbid: response.cldbid}, function(err, response, rawResponse){
              if (err) deferred.reject(err);
              
              forumUsers[index]['tsdbid'] = response.client_database_id;
              forumUsers[index]['tsnickname'] = response.client_nickname;
              forumUsers[index]['tslastconnected'] = response.client_lastconnected;
            });
          }
        });
      });
    });
  });
  
  deferred.resolve(forumUsers);

  return deferred.promise;
}

Thanks

Crash on QUIT command (and other disconnecting events)

When using the QUIT command, or having a connection timeout, this error happens.

C:\####\node_modules\node-teamspeak\index.js:140 executing.response = response; ^ TypeError: Cannot set property 'response' of null at LineInputStream. (C:\Users\zeroZshadow\Desktop\AdminRequest\no de_modules\node-teamspeak\index.js:140:24) at LineInputStream.EventEmitter.emit (events.js:95:17) at LineInputStream._events.line (C:\Users\zeroZshadow\Desktop\AdminRequest\n ode_modules\node-teamspeak\node_modules\line-input-stream\lib\line-input-stream. js:8:8) at Array.forEach (native) at Socket. (C:\Users\zeroZshadow\Desktop\AdminRequest\node_module s\node-teamspeak\node_modules\line-input-stream\lib\line-input-stream.js:41:10) at Socket.EventEmitter.emit (events.js:117:20) at _stream_readable.js:910:16 at process._tickCallback (node.js:415:13)

channelinfo not work

Hello, I can't run channelinfo on each

cl.send("channellist", function(err, response, rawResponse){                        
    response.forEach(function (one) {
        cl.send("channelinfo", {cid: one.cid}, function(err, response, rawResponse) {
                console.log(util.inspect(response)); // null
        });
    });
});

and I have a problem with "Error: This socket has been ended by the other party"

                  [2,3,4,5,6,10,11].map(function(el) {
                            cl.send("channelinfo", {cid: el}, function(e, r, ra) {
                                if(r && r.channel_name){
                                    console.log(r.channel_name, el);
                                }
                            });
                        })
                        cl.send('quit');

result:

I20160106-18:51:51.815(2)? administrations 2
I20160106-18:51:51.854(2)? SS 3
I20160106-18:51:51.894(2)? KITHEI 4
I20160106-18:51:51.934(2)? CS:GO 5
I20160106-18:51:51.974(2)? MIXUA 6
I20160106-18:51:51.975(2)? { [Error: This socket has been ended by the other party] code: 'EPIPE' }

npm publish

I really need the fix for #4 in my project.
As a workaround i am now using the github-repo directly, but getting back to npm and the ability to use version range would be really nice.

So it would be really cool, if you could finally publish the latest changes of node-teamspeak. :) (The version on npm is already 11 months old)

Support

Hello, I'm new in NodeJS, so how can I register guest users when they enter to a specific channel?

Connect to several instances

Hi, how to organize connection to several instances of ts3 ?
There is code, but it does not work correctly.

var query={};
var servers={ FB:
    {ip: fbip,
        query: fbquery,
        username: 'serveradmin',
        password: fbpass },
    OVH:
        { ip: ovhip,
            query: ovhquery,
            username: 'serveradmin',
            password: ovhpass }
        };
createConnections();
function createConnections() {
    for (const key in servers) {
        if (servers.hasOwnProperty(key)) {
            query[key] =new client(servers[key].ip, servers[key].query);//Обращаемся к серверу
            query[key].on('error', function (err) {
                console.log('Error on connection to: ' + `${key}`.red, err.code, ' ', err.address + ':' + err.port);
            });
            query[key].send('login', {//Авторизация
                client_login_name: 'serveradmin',
                client_login_password: servers[key].password
            }, function (err, response) {
                if (err) {
                    console.log(err)
                } else {
                    console.log('Successful connect to: ' + key);
                }
            });
            setInterval(function () {
                query[key].send('hostinfo',function (err,response) {
                    console.log('Info from: '+key,response.instance_uptime+'\n');
                });
            },1000);
        }
    }
}

OVH and FB it is different instances with different uptime
default

Reconnect function error

Hi,

I'm trying to implement auto reconnect function for a Bot am building

am doing it like this:

// Reconnect to server
TeamSpeakClient.prototype.reconnect = function() {
     socket.connect(port || 10011, host || 'localhost');
};

it works fine and i see it reconnects on the server but then i get this error:

PATH2myProject\node_modules\node-teamspeak\index.js:174
                executing.error = response;
                                ^
TypeError: Cannot set property 'error' of null
    at LineInputStream.<anonymous> (D:\DEV\workspace\nodejs\A90Ts3\node_modules\node-teamspeak\index.js:174:21)
    at LineInputStream.emit (events.js:95:17)
    at LineInputStream._events.line (D:\DEV\workspace\nodejs\A90Ts3\node_modules\node-teamspeak\node_modules\line-input-stream\lib\line-input-stream.js:8:8)
    at Array.forEach (native)
    at Socket.<anonymous> (D:\DEV\workspace\nodejs\A90Ts3\node_modules\node-teamspeak\node_modules\line-input-stream\lib\line-input-stream.js:36:9)
    at Socket.emit (events.js:117:20)
    at Socket.<anonymous> (_stream_readable.js:748:14)
    at Socket.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:410:10)
    at emitReadable (_stream_readable.js:406:5)

i tried resetting the status = -2; to ignore the connection info again still not working
also did some debug it shows that its getting the welcome message twice:

TS3
TS3

Welcome to the TeamSpeak 3 ServerQuery interface, type "help" for a list of commands and "help <command>" for information on a specific command.

Welcome to the TeamSpeak 3 ServerQuery interface, type "help" for a list of commands and "help <command>" for information on a specific command.

am fairly new to Node so bear with me 😃
Thanks

How does it receive text messages?

I'm aware of using the 'servernotifyregister' event to register the query client to receive text messages, but where do I go to log them to the terminal?

client.send('severnotifyregister', {event: 'textchannel'}, function(err, response, rawResponse) {

});

This is what my code snippet looks like. If I have it console.log(response), I get undefined. That's expected as I assume the response is the immediate response from the server after the event's been executed. Can someone help me out?

Oh man, I'm a moron, it's right there at the bottom of the page. Sorry.

Unhandled 'error' event

For some time I can't use this anymore since it throws an error. I'm just doing cl.send("login", {client_login_name: server.login, client_login_password: server.password}, onServerResponse);. onServerReponse is never called.

node:events:490
      throw er; // Unhandled 'error' event
      ^

Error: connect ENETUNREACH 2a00:6020:4306:fec5:208:9bff:fec5:7f77:10011
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)
Emitted 'error' event on TeamSpeakClient instance at:
    at Socket.<anonymous> (/home/xxx/projects/scripts/query_ts/node_modules/node-teamspeak/index.js:145:8)
    at Socket.emit (node:events:512:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -101,
  code: 'ENETUNREACH',
  syscall: 'connect',
  address: '2a00:6020:4306:fec5:208:9bff:fec5:7f77',
  port: 10011
}

(I anonymized the server address)

Node.js v19.5.0

Register to notifications

Hello,
can I do something that waits for the connection of every user and reply with an "hello" to anyone just joined?
I see that I can "register to notifications", but can you provide an example?
Thanks.

Potential issue returning array or object

You return an array for response if the response parts count is greater than one, and an object if there is a single response.

What if the response is for something like channellist and there is a single channel? The code won't know to expect an object or an array because the response could be a single or multiple number of channels.

'clientinfo' command not working

Hey there,
i have a problem getting the 'clientinfo' query command to work.
First of all: i tried to execute this command manually and all worked fine, so this can't be a matter of permissions or anything. Every other command i tried so far worked also. This is my code:

var teamSpeakClient = require('node-teamspeak');

var config = require('../config.json');

var client = new teamSpeakClient(config.teamspeak.ip, config.teamspeak.port);

// Connect to TS3 Server
client.send('login', {
    client_login_name: config.teamspeak.username,
    client_login_password: config.teamspeak.password
}, function () {
    // Choose configured virtual server
    client.send('use', {sid: config.teamspeak.sid}, function () {
        // Change nickname
        client.send('clientupdate', {client_nickname: config.teamspeak.nickname}, function () {
            // Register server notifier
            client.send('servernotifyregister', {event: 'server'});
            client.send('servernotifyregister', {event: 'textprivate'});
        })
    });
});

// Listen on new connections from teamspeak clients
client.on('cliententerview', function (data) {
    // working
    client.send('sendtextmessage', {
        targetmode: 1,
        target: data.clid,
        msg: 'not relevant'
    });
    // not working, returns data = undefined
    client.send('clientinfo', {clid: data.clid}, function (data) {
        console.log(data);
    });
});

// Listen on received messages
client.on('textmessage', function (data) {
    if (data.invokerid !== data.target) {
        client.send('sendtextmessage', {
            targetmode: 1,
            target: data.invokerid,
            msg: 'not relevant'
        });
    }
});

Everything works fine except for the 'clientinfo' command (the 'data.clid' variable is correct),
which is undefined.

Thanks for your help,
PaddseL

EDIT: I'm dumb, sorry.
It's supposed to look like this, for anyone running in the same issue:

client.send('clientinfo', {clid: data.clid}, function (error, data) {
    if (!error) {
        console.log(data);
    }
});

npm publish (again :D)

Hi, at the moment the latest version at npm is v1.04, but with this version, it is somehow not possible to have multiple Client-instances open in one project (yeah, i actually need this :D ).

But with the latest version from the repository it works just fine (v1.0.9), so could you pls publish it?

Also you should consider instant publishing every time you change the version in the package.json.
If you want to mark it as unstable first you can suffix it with -rc1, -rc2 and so on. But this would be even more trouble (like in time you need to spend).

Edit: If you really have no time to publish on npm when a new version is out, you could also add me as maintainer for this project on npm (npm owner add zyberspace), so i can do the publish thing for you.
But of course you need to trust me for this :P

Publish version 0.1.5 to npm

Hi, the latest version on npm i can find, is 0.1.3, but in your package.json on github it is 0.1.5.
Can you please publish the newest version to npm? Thanks! :)

Won't connect

var TeamSpeakClient = require("node-teamspeak"),
    util = require("util");

var cl = new TeamSpeakClient("62.104.20.199", 10118);
/*
cl.send("login",
    {
        client_login_name: "UserName",
        client_login_password: "Password"
    }, function(err, response, rawResponse){

    console.log("Test");

    cl.send("use", {sid: 1}, function(err, response, rawResponse){
        cl.send("clientlist", function(err, response, rawResponse){
            console.log(util.inspect(response));
        });
    });
});*/

cl.on('error', function(error) {
    console.log('error', error);
});

cl.on('close', function(queue) {
    console.log('close', queue);
});

cl.on('connect', function() {
    console.log('connect');
});

Any ideas? Tryed with & without login. No exceptions, no errors, no results.
Tried with IP/Port/Hostname.

After few minutes i'm getting an Timeout:

error { [Error: connect ETIMEDOUT] code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'connect' }
close []

Error on failing to connect

When trying to connect to an address not running a teamspeak server, the following error is thrown

events.js:72 throw er; // Unhandled 'error' event ^ Error: connect ECONNREFUSED at errnoException (net.js:901:11) at Object.afterConnect [as oncomplete](net.js:892:19)

TeamSpeak sends events like 'clientmoved' twice

Reproduce:

Serverquery

login user password
error id=0 msg=ok
use 1
error id=0 msg=ok
servernotifyregister event=server
error id=0 msg=ok
servernotifyregister event=channel id=0
error id=0 msg=ok

Switch channel once

notifyclientmoved ctid=830 reasonid=0 clid=9
notifyclientmoved ctid=830 reasonid=0 clid=9

This (of course) also affects node-teamspeak.

Possible solution: In index.js change

socket.on("connect", function(){
// ...
   } else if(s.indexOf("notify") === 0){
      s = s.substr("notify".length);
      response = parseResponse(s);
      self.emit(s.substr(0, s.indexOf(" ")), response);
    } else if(executing) {
// ...
});

to

var prevresponse = {};
socket.on("connect", function(){
// ...
   } else if(s.indexOf("notify") === 0){
      s = s.substr("notify".length);
      response = parseResponse(s);
      if(JSON.stringify(prevresponse) != JSON.stringify(response)){
         self.emit(s.substr(0, s.indexOf(" ")), response);
         self.emit('notification', s.substr(0, s.indexOf(" ")), response);    // notification on ALL notifications
      }
      prevresponse = response;
    } else if(executing) {
// ...
});

HELP command doesnt work

The HELP command doesnt work since it's response is multi lined

the assumption of

168  // Server answers with:
169  // [- One line containing the answer ]
170  // - "error id=XX msg=YY". ID is zero if command was executed successfully.

in index.js is incorrect for this command (possibly for more commands)

example with

160  reader.on("line", function(line){
161    console.log(line);
node startup.js
TS3 //Skipped because 1 of first 2 lines
Welcome to the TeamSpeak 3 ServerQuery interface, type "help" for a list of commands and "help <command>" for information on a specific command. //Skipped because 2 of first 2 lines
error id=0 msg=ok //logged in
error id=0 msg=ok //use (selecting ts instance)
Usage: channelinfo cid={channelID} //from here is what i get from the server

Displays detailed configuration information about a channel including ID,
topic, description, etc.

Example:
   channelinfo cid=1
   channel_name=Default\sChannel channel_topic=No\s[b]topic[\/b]\shere
   channel_description=Welcome ...
   error id=0 msg=ok

{ channel_description: 'Welcome', '...': '' } //result of the library
error id=0 msg=ok //End of help
error id=0 msg=ok //logout
error id=0 msg=ok //quit

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.