diff --git a/index.js b/index.js index 427f419..675cd43 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -require("dotenv").config({quiet:true}) +require("dotenv").config({ quiet: true }) const ws = require("ws"); // const conn = new ws("wss://saubeo.solutions/demo/rdio-scanner/"); @@ -123,7 +123,7 @@ conn.on("message", (data) => { let msg = data.toString() let parsed = JSON.parse(msg) // console.log("Received message:", parsed); - switch(parsed[0]) { + switch (parsed[0]) { case "CFG": // Config RX const config = parsed[1]; const lfmFilter = buildFullLfmFilter(config); @@ -152,45 +152,62 @@ conn.on("message", (data) => { console.log(`New Call ${globalSystems[parsed[1].system][parsed[1].talkgroup].name} call #${parsed[1].id}`); const tgName = globalSystems[parsed[1].system][parsed[1].talkgroup].name; fs.writeFileSync(`./temp/${parsed[1].audioName}`, Buffer.from(parsed[1].audio.data)); - decodeTwoTone(`./temp/${parsed[1].audioName}`).then((result) => { - console.log(`Two-tone detection result for ${tgName}:`, result); - // Two tone result will be array of objects for each detected twotone activation. .detected is array of two frequencies, one for each tone. Create a counter for each pair of frequencies detected. Make a message to send to discord with the tone names, so if 2 copies of RC EMS are sent, send "RC EMS (2x)" instead. For multiple, send "RC EMS (2x), RC Fire (1x)" etc. - const toneCounts = {}; - for (const activation of result) { - const detected = activation.detected; - const key = `${detected[0]}:${detected[1]}`; - if (toneCounts[key]) { - toneCounts[key]++; - } else { - toneCounts[key] = 1; + // decodeTwoTone(`./temp/${parsed[1].audioName}`).then((result) => { + // console.log(`Two-tone detection result for ${tgName}:`, result); + // // Two tone result will be array of objects for each detected twotone activation. .detected is array of two frequencies, one for each tone. Create a counter for each pair of frequencies detected. Make a message to send to discord with the tone names, so if 2 copies of RC EMS are sent, send "RC EMS (2x)" instead. For multiple, send "RC EMS (2x), RC Fire (1x)" etc. + // const toneCounts = {}; + // for (const activation of result) { + // const detected = activation.detected; + // const key = `${detected[0]}:${detected[1]}`; + // if (toneCounts[key]) { + // toneCounts[key]++; + // } else { + // toneCounts[key] = 1; + // } + // } + // const toneMessages = []; + // for (const key in toneCounts) { + // const name = knownTones[key] || key; + // const count = toneCounts[key]; + // toneMessages.push(count > 1 ? `${name} (${count}x)` : name); + // } + // const message = toneMessages.join(", "); + // console.log(`Two-tone summary for ${tgName}:`, message); + // hook.send({ + // // Username is tg name + // username: globalSystems[parsed[1].system][parsed[1].talkgroup].name, + // content: `${message}`, + // // Upload audio file + // files: [{ + // attachment: `./temp/${parsed[1].audioName}`, + // name: parsed[1].audioName + // }] + // }).then(() => { + // // Delete the audio file after sending to Discord + // fs.unlink(`./temp/${parsed[1].audioName}`, (err) => { + // if (err) { + // console.error(`Error deleting audio file: ${err}`); + // } + // }); + // }) + // }); // TwoTone breaks on my server. Will fix later (I think i need py 3.12 not 3.13) + hook.send({ + // Username is tg name + username: globalSystems[parsed[1].system][parsed[1].talkgroup].name, + // content: `${message}`, + // Upload audio file + files: [{ + attachment: `./temp/${parsed[1].audioName}`, + name: parsed[1].audioName + }] + }).then(() => { + // Delete the audio file after sending to Discord + fs.unlink(`./temp/${parsed[1].audioName}`, (err) => { + if (err) { + console.error(`Error deleting audio file: ${err}`); } - } - const toneMessages = []; - for (const key in toneCounts) { - const name = knownTones[key] || key; - const count = toneCounts[key]; - toneMessages.push(count > 1 ? `${name} (${count}x)` : name); - } - const message = toneMessages.join(", "); - console.log(`Two-tone summary for ${tgName}:`, message); - hook.send({ - // Username is tg name - username: globalSystems[parsed[1].system][parsed[1].talkgroup].name, - content: `${message}`, - // Upload audio file - files: [{ - attachment: `./temp/${parsed[1].audioName}`, - name: parsed[1].audioName - }] - }).then(() => { - // Delete the audio file after sending to Discord - fs.unlink(`./temp/${parsed[1].audioName}`, (err) => { - if (err) { - console.error(`Error deleting audio file: ${err}`); - } - }); - }) - }); + }); + }) break; default: console.log("Unknown message:", JSON.stringify(parsed));