ts3_remote_ham/daemon.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-03-02 10:54:02 +01:00
import * as fs from 'fs';
import ClientQuery from "./ClientQuery.js";
2023-03-01 19:28:02 +01:00
import flrig from './providers/flrig.js';
import mhuxd from './providers/mhuxd.js';
2022-03-02 10:54:02 +01:00
const apikey = fs.readFileSync('./apikey.txt').toString();
2023-03-01 19:28:02 +01:00
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);
}
2022-03-02 10:54:02 +01:00
// client.request('sendtextmessage targetmode=2 msg=Node.JS').then( res =>{ console.log(res.toString()) });
await new Promise(r => setTimeout(r, 50));
2023-03-01 19:28:02 +01:00
const speakingUsers = {};
const whoamiData = client.parse((await client.request('whoami')).toString());
2022-03-02 10:54:02 +01:00
2023-03-01 19:28:02 +01:00
const provider = flrig();
2022-03-02 10:54:02 +01:00
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
2023-03-01 19:28:02 +01:00
provider.pttDown();
2022-03-02 10:54:02 +01:00
} else {
// nobody is speaking
2023-03-01 19:28:02 +01:00
provider.pttUp();
2022-03-02 10:54:02 +01:00
}
2023-03-01 19:28:02 +01:00
});