[JS] NodeJS Teamspeak Plugin SDK Wrapper Base

bindik

VIP
May 10, 2016
40
24
55
Early note: This is just PoC base, example. Not full project.

Hi, i wanted to make teamspeak plugins in NodeJS, because its simple, fast. My experience in c/c++ is kinda weak. So i have decided to do it myself, create some kind of wrapper around teamspeak events, functions to communicate between node thread and teamspeak plugin. I have decided to not release full work but just the base so you can do it yourself. My work is based on NearJS library which i forked and fixed things like thread safe method calling (it was crashing after few minutes of running), changed strings to objects in hostcalls.

Big credits to guy called hemirt aka c++ mastermind who helped, explained and done a lot for me
https://github.com/hemirt

My NearJS repo.

https://github.com/eskejpo/NearJS

(tested on linux debian, didnt try it on windows)


0. First of all you need to download and compile nodejs (v48 version 6.11.4) as shared library (.so) so you will get something like libnode.so.48
Build node.js v6.11.4 LTS
$ git clone https://github.com/nodejs/node.git
$ cd node && git checkout tags/v6.11.4
$ ./configure --shared
$ make

# or ./configure --shared --debug
# for gdb/lldb debugging

$ cp out/Release/obj.target/libnode.so.48 /usr/lib/
$ ln -s /usr/lib/libnode.so.48 /usr/lib/libnode.so



1. Copy compiled libnode.so.48 to folder of your choosing
2. Now git clone my repo

Code:
git clone https://github.com/eskejpo/NearJS
3. Compile it,but dont forget to modify your location for nodejs includes
3.1 (i forgot :D) Download libuv 1.19.1 and include it
Code:
clang++ near.cpp -c -o near.o --std=c++11 -I/home/nodejs/node/deps/v8/include -I/home/nodejs/node/src -g -I/home/nodejs/libuv-1.19.1/include/ -fPIC
4. Copy near.o to your plugin folder
5. Download plugin sdk, rename plugin.c -> plugin.cpp (clang hates .c)
6. Replace code with this super simple, proof of concept example.


https://gist.github.com/eskejpo/9bf019d1193fc10a1c2e31ee15f2253b

7. Compile it, dont forget to modify addresses to includes, objects, shared libraries or whatever
Code:
clang++ -std=c++1y -shared -O2 -Wall -DLINUX -fPIC plugin.cpp -lpthread /home/nodejs/libnode.so.48 /home/nearjs/near.o -I/home/near/include/ -I/home/plugin/include -I/home/nodejs/node/deps/v8/include -I/home/nodejs/node/src  -o /home/nodejs/client/plugins/nodejs.so

8. put appka.js right near teamspeak client binary like /home/teamspeakclient/appka.js
(scroll at bottom of post)

You should be all done, keep reading if you want to know more

//You need to register all methods before starting nodejs thread
Code:
nearSetMethod("requestClientPoke", esc_requestClientPoke);
example for method, output of method needs to be stringified json object, use some kind of library (not included in example)
Code:
static void esc_requestClientPoke(NearArguments args) {
    json::JSON obj;
    if(ts3Functions.requestClientPoke(args[0]->IntegerValue(),args[1]->IntegerValue(),std::string(*v8::String::Utf8Value(args[2]->ToString())).c_str(),std::string(*v8::String::Utf8Value(args[3]->ToString())).c_str()) == ERROR_ok){
        obj["status"] = true;
        //or error code
    }else{
        obj["status"] = false;
    }
    //output needs to be stringified object,nearjs in c++ will parse it into proper V8 object, and you will get proper strings, arrays, objects, integers in nodejs itself
    nearReturn(args, "stringified object here");
}

in case of sending teamspeak events to nodejs
Code:
int ts3plugin_onTextMessageEvent(uint64 serverConnectionHandlerID, anyID targetMode, anyID toID, anyID fromID, const char* fromName, const char* fromUniqueIdentifier, const char* message, int ffIgnored) {
    //here i use some kind of 3rd party json library, its great
    //i recommend you to use some, if u dont just output some kind of string like u saw above
    json::JSON obj;

    obj["serverConnectionHandlerID"] = serverConnectionHandlerID;
    obj["targetMode"] = targetMode;
    obj["toID"] = toID;
    obj["fromID"] = fromID;
    obj["fromName"] = fromName;
    obj["fromUniqueIdentifier"] = fromUniqueIdentifier;
    obj["message"] = message;
    obj["ffIgnored"] = ffIgnored;

    std::stringstream ss;
    ss << obj;

    //again, the output needs to be stringified object
    addMessage("onTextMessageEvent", ss.str());

    return 0;
}

appka.js
Code:
setInterval(function(){
    //this needs to be here
    //its keeping nodejs thread alive
    //it needs to tick fast, works as tickrate
}, 10)

escbot.on("onTextMessageEvent", function(data){
    //1 = serverhandlerid
    //connect with start parameters or make your own function to connect, ez

    escbot.requestClientPoke(1, data.userid, "poke message .. ")
})

Please note, i am not giving any kind of support, help. This is really just an example. I wrote script for myself that parsed and rewrote teamspeak functions, evenst to right form so i didnt have to do it manually, i wont share it.
I have created music bot, room creation bot based on this.
 
Last edited:

Asphyxia

Owner
Administrator
Apr 25, 2015
1,844
2
2,197
327
This is an awesome PoC release, thanks for contributing. Great work! If you are close to hemirt (friends), do you reckon you could bring him into our community? I am sure that with the collaboration of quite a few individuals around here, we could make our own all-inclusive VoIP solution that could benefit quite a few growing security/privacy conscious markets including:
  • Gamers or home users
  • Healthcare
  • Government
  • Private business (target being marketable to Fortune 500 companies)
Having skillful developers like yourself and hemirt working with other developers is a great way to build teams and even potentially start amazing businesses greater than ourselves.
 

bindik

VIP
May 10, 2016
40
24
55
It all depends, its his decision. I told him about this and he decides. Back to the topic, if anyone is interested in this project, wants to develop it, has ideas how to improve performance, or has experience with node,v8 feel free to pm. Also as i am pretty bad in c++ feel free to fix my stupid solutions, mistakes.
 
Last edited:
Top