TeaSpeak-Client/native/serverconnection/test/js/main.ts

182 lines
6.9 KiB
TypeScript
Raw Normal View History

2019-10-25 19:51:40 -04:00
/// <reference path="../../exports/exports.d.ts" />
console.log("HELLO WORLD");
module.paths.push("../../build/linux_x64");
2020-02-13 18:42:56 -05:00
module.paths.push("../../build/win32_x64");
2019-10-25 19:51:40 -04:00
//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;
2020-02-13 18:42:56 -05:00
require = (module => original_require(__dirname + "/../../../build/win32_x64/" + module + ".node")) as any;
2019-10-25 19:51:40 -04:00
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);
};
2020-04-16 07:12:00 -04:00
const do_connect = (connection) => {
2019-10-25 19:51:40 -04:00
connection.connect({
timeout: 5000,
remote_port: 9987,
2019-10-25 19:51:40 -04:00
//remote_host: "188.40.240.20", /* twerion */
2020-04-08 06:17:21 -04:00
remote_host: "127.0.0.1",
//remote_host: "ts.teaspeak.de",
2019-10-25 19:51:40 -04:00
//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) {
connection.send_command("handshakebegin", [{intention: 0, authentication_method: 2, client_nickname: "Native client test" }], []);
2019-10-25 19:51:40 -04:00
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
2019-10-25 19:51:40 -04:00
}
], []);
}
},
identity_key: "MG4DAgeAAgEgAiBC9JsqB1am6vowj2obomMyxm1GLk8qyRoxpBkAdiVYxwIgWksaSk7eyVQovZwPZBuiYHARz/xQD5zBUBK6e63V7hICIQCZ2glHe3kV62iIRKpkV2lzZGZtfBPRMbwIcU9aE1EVsg==",
teamspeak: false /* used here to speed up the handshake process :) */
2019-10-25 19:51:40 -04:00
});
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);
};
2019-10-25 19:51:40 -04:00
connection.callback_command = (command, arguments1, switches) => {
if(command === "notifyservergrouppermlist") {
console.log("Received perm list");
return;
} else if(command === "notifyservergroupclientlist") {
console.log("Perm group");
return;
} else if(command === "notifypermissionlist") {
console.log("Received permission list");
return;
} else if(command == "notifycliententerview") {
console.log("Enter client: %o", arguments1);
return;
} else if(command === "error") {
console.log("Received error: %o", arguments1);
return;
}
console.log("Command %s: %o", command, arguments1);
if(command === "channellistfinished") {
//115
//connection.send_command("clientgetvariables", [{ clid: 1 }], []);
//connection.send_command("channelsubscribeall", [], []);
connection.send_command("playlistsonglist", [{ playlist_id: '12' }], []);
/*
setInterval(() => {
connection.send_command("servergroupclientlist", [{ sgid: 2 }], []);
connection.send_command("servergrouppermlist", [{ sgid: 2 }], []);
}, 1000);
*/
}
};
2019-10-25 19:51:40 -04:00
connection._voice_connection.register_client(7);
};
2020-04-16 07:12:00 -04:00
do_connect(connection);
let _connections = [];
let i = 0;
let ii = setInterval(() => {
if(i++ > 35)
clearInterval(ii);
const c = handle.spawn_server_connection();
_connections.push(c);
do_connect(c);
}, 500);
2019-10-25 19:51:40 -04:00
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(() => {
2020-02-02 11:51:06 -05:00
if("gc" in global) {
console.log("GC");
global.gc();
}
2019-10-25 19:51:40 -04:00
}, 1000);
/* keep the object alive */
setTimeout(() => {
connection.connected();
2020-04-16 07:12:00 -04:00
_connections.forEach(e => e.current_ping());
2019-10-25 19:51:40 -04:00
}, 1000);
connection_list.push(connection);