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']); } });