ts3_remote_ham/daemon.js
2023-03-01 19:28:02 +01:00

37 lines
1.1 KiB
JavaScript

import * as fs from 'fs';
import ClientQuery from "./ClientQuery.js";
import flrig from './providers/flrig.js';
import mhuxd from './providers/mhuxd.js';
const apikey = fs.readFileSync('./apikey.txt').toString();
const client = new ClientQuery();
try {
await client.connect('127.0.0.1', '25639', apikey);
} catch (error) {
console.error('Cannot connect to TS3 query. Is TeamSpeak running?', error);
}
// client.request('sendtextmessage targetmode=2 msg=Node.JS').then( res =>{ console.log(res.toString()) });
await new Promise(r => setTimeout(r, 50));
const speakingUsers = {};
const whoamiData = client.parse((await client.request('whoami')).toString());
const provider = flrig();
client.notifyOn('notifytalkstatuschange', '', data => {
let args = client.parse(data.toString());
if (args.clid === whoamiData.clid)
return;
speakingUsers[args.clid] = parseInt(args.status) === 1;
if (Object.values(speakingUsers).find(el => el)) {
// someone is speaking
provider.pttDown();
} else {
// nobody is speaking
provider.pttUp();
}
});