TeaSpeak-Client/native/serverconnection/test/js/main.ts
2020-03-02 14:33:34 +01:00

148 lines
5.6 KiB
TypeScript

/// <reference path="../../exports/exports.d.ts" />
console.log("HELLO WORLD");
module.paths.push("../../build/linux_x64");
module.paths.push("../../build/win32_x64");
//LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.5
const os = require('os');
//process.dlopen(module, '/usr/lib/x86_64-linux-gnu/libasan.so.5',
// os.constants.dlopen.RTLD_NOW);
import * as fs from "fs";
const original_require = require;
require = (module => original_require(__dirname + "/../../../build/win32_x64/" + module + ".node")) as any;
import * as handle from "teaclient_connection";
require = original_require;
const connection_list = [];
const connection = handle.spawn_server_connection();
const client_list = [];
//process.exit(0);
connection.callback_command = (command, args, switches) => {
//console.log("Got command %s: %o (%o)", command, args, switches);
if(command === "notifycliententerview") {
for(const client_args of args) {
console.log(client_args["clid"]);
const client = connection._voice_connection.register_client(parseInt(client_args["clid"]));
console.log("Registered voice client %o", client);
client_list.push(client);
console.log("Applying volume of 0.2");
client.set_volume(0.2);
const stream = client.get_stream();
console.log("Client buffer latency: %d/%d: %o", stream.get_buffer_latency(), stream.get_buffer_max_latency(), stream);
stream.set_buffer_latency(0.02);
stream.set_buffer_max_latency(0.2);
client.callback_playback = () => {
console.log("Client %d started speaking", client.client_id);
};
client.callback_stopped = () => {
console.log("Client %d stopped speaking", client.client_id);
};
client.callback_state_changed = state => {
console.log("Client %d change state to %d (%s)", client.client_id, state, handle.PlayerState[state]);
};
}
}
};
connection.callback_disconnect = reason => {
console.log("Got disconnect: %s", reason);
};
const do_connect = () => {
connection.connect({
timeout: 5000,
remote_port: 9987,
//remote_host: "188.40.240.20", /* twerion */
remote_host: "127.0.0.1",
//remote_host: "ts.teaspeak.de",
//remote_host: "51.68.181.92",
//remote_host: "94.130.236.135",
//remote_host: "54.36.232.11", /* the beast */
//remote_host: "79.133.54.207", /* gommehd.net */
callback: error => {
console.log("Connected with state: %o (%s) ", error, connection.error_message(error));
if(error == 0) {
console.dir(handle.ServerType);
console.log("Server type: %o|%o", connection.server_type, handle.ServerType[connection.server_type]);
connection.send_command("clientinit", [
{
"client_key_offset": 2030434,
/*
"client_version": "1.0.0",
"client_platform": "nodejs/linux",
*/
"client_version": "3.1.8 [Build: 1516614607]",
"client_platform": "Windows",
"client_version_sign": "gDEgQf/BiOQZdAheKccM1XWcMUj2OUQqt75oFuvF2c0MQMXyv88cZQdUuckKbcBRp7RpmLInto4PIgd7mPO7BQ==",
"client_nickname": "TeaClient Native Module Test",
"client_input_hardware":true,
"client_output_hardware":true,
"client_default_channel":"",
"client_default_channel_password":"",
"client_server_password":"",
"client_meta_data":"",
"client_nickname_phonetic":"",
"client_default_token":"",
"hwid":"123,456123123123",
return_code:91
}
], []);
}
},
identity_key: "MG4DAgeAAgEgAiBC9JsqB1am6vowj2obomMyxm1GLk8qyRoxpBkAdiVYxwIgWksaSk7eyVQovZwPZBuiYHARz/xQD5zBUBK6e63V7hICIQCZ2glHe3kV62iIRKpkV2lzZGZtfBPRMbwIcU9aE1EVsg==",
teamspeak: true /* used here to speed up the handshake process :) */
});
connection.callback_voice_data = (buffer, client_id, codec_id, flag_head, packet_id) => {
console.log("Having data!");
connection.send_voice_data(buffer, codec_id, flag_head);
};
connection.callback_disconnect = error => {
console.log("Disconnect: %s", error);
};
connection.callback_command = (command, arguments1, switches) => {
console.log("Command: %s: %0", command, arguments1);
if(command === "channellistfinished") {
setInterval(() => {
console.log("XXX");
connection.send_command("channelcreate", [{"channel_name": Math.random() + " :D"}], []);
}, 10);
}
};
connection._voice_connection.register_client(7);
};
do_connect();
connection.callback_voice_data = (buffer, client_id, codec_id, flag_head, packet_id) => {
console.log("Received voice of length %d from client %d in codec %d (Head: %o | ID: %d)", buffer.byteLength, client_id, codec_id, flag_head, packet_id);
connection.send_voice_data(buffer, codec_id, flag_head);
};
setInterval(() => {
if("gc" in global) {
console.log("GC");
global.gc();
}
}, 1000);
/* keep the object alive */
setTimeout(() => {
connection.connected();
}, 1000);
connection_list.push(connection);