ts3_remote_ham/daemon.js

30 lines
1.0 KiB
JavaScript
Raw Normal View History

2022-03-02 10:54:02 +01:00
import { spawn } from 'child_process';
import * as fs from 'fs';
import ClientQuery from "./ClientQuery.js";
const apikey = fs.readFileSync('./apikey.txt').toString();
let client = new ClientQuery();
let socket = await client.connect('127.0.0.1', '25639', apikey);
// client.request('sendtextmessage targetmode=2 msg=Node.JS').then( res =>{ console.log(res.toString()) });
await new Promise(r => setTimeout(r, 50));
let speakingUsers = {};
let whoamiData = client.parse((await client.request('whoami')).toString());
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
spawn('/home/omega/Documents/ts3_remote/ptt_daemon', ['/dev/mhuxd/fsk1', '1']);
} else {
// nobody is speaking
spawn('/home/omega/Documents/ts3_remote/ptt_daemon', ['/dev/mhuxd/fsk1', '0']);
}
});