ts3_remote_ham/daemon.js

38 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';
2024-09-12 02:00:26 +02:00
import serial from './providers/serial.js';
import config from './config.js';
2022-03-02 10:54:02 +01:00
2023-03-01 19:28:02 +01:00
const client = new ClientQuery();
try {
2024-09-12 02:00:26 +02:00
await client.connect(config.teamspeak.host, config.teamspeak.port, config.teamspeak.apiKey);
2023-03-01 19:28:02 +01:00
} catch (error) {
2024-09-12 02:00:26 +02:00
console.error('Cannot connect to TS3 query. Is TeamSpeak running?', error);
2023-03-01 19:28:02 +01:00
}
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
2024-09-12 02:00:26 +02:00
const provider = {
flrig, serial
}[config.provider](config.providerOptions);
2022-03-02 10:54:02 +01:00
client.notifyOn('notifytalkstatuschange', '', data => {
2024-09-12 02:00:26 +02:00
let args = client.parse(data.toString());
if (args.clid === whoamiData.clid)
return;
2022-03-02 10:54:02 +01:00
2024-09-12 02:00:26 +02:00
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();
}
2023-03-01 19:28:02 +01:00
});