38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
import * as fs from 'fs';
|
|
import ClientQuery from "./ClientQuery.js";
|
|
import flrig from './providers/flrig.js';
|
|
import serial from './providers/serial.js';
|
|
import config from './config.js';
|
|
|
|
const client = new ClientQuery();
|
|
try {
|
|
await client.connect(config.teamspeak.host, config.teamspeak.port, config.teamspeak.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, serial
|
|
}[config.provider](config.providerOptions);
|
|
|
|
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();
|
|
}
|
|
});
|