Skip to content

Commit

Permalink
Add enable and disable commands
Browse files Browse the repository at this point in the history
  • Loading branch information
globz-eu committed Jun 14, 2024
1 parent 7419339 commit ff1f38d
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 7 deletions.
5 changes: 4 additions & 1 deletion config.json.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"bootstrapServerUri": "http://bootstrap-server/device_name",
"currentGainTopic": "devices/device_name/microphone/currentGain",
"setGainTopic": "devices/device_name/microphone/doSetGain"
"setGainTopic": "devices/device_name/microphone/doSetGain",
"enableTopic": "devices/device_name/microphone/doEnable",
"disableTopic": "devices/device_name/microphone/doDisable",
"microphoneName": "Line In"
}
134 changes: 128 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"description": "",
"dependencies": {
"@artcom/bootstrap-client": "^4.6.2",
"node-windows": "^1.0.0-beta.8",
"win-audio": "^3.0.3"
},
"devDependencies": {
Expand Down
15 changes: 15 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const audio = require("win-audio")
const wincmd = require("node-windows")
const { setTimeout } = require("timers/promises")
const bootstrap = require("@artcom/bootstrap-client")
const fs = require("fs")
Expand All @@ -21,6 +22,20 @@ async function main() {
await mqttClient.publish(config.currentGainTopic, microphone.get())
}
})

mqttClient.subscribe(config.disableTopic, async () => {
logger.info("Disabling device")
wincmd.elevate(
`powershell.exe "Get-PnpDevice | Where-Object {$_.FriendlyName -like '${config.microphoneName} *'} | Disable-PnpDevice -Confirm:$false"`,
)
})

mqttClient.subscribe(config.enableTopic, () => {
logger.info("Enabling device")
wincmd.elevate(
`powershell.exe "Get-PnpDevice | Where-Object {$_.FriendlyName -like '${config.microphoneName} *'} | Enable-PnpDevice -Confirm:$false"`,
)
})
}

function readConfigFileArg() {
Expand Down

0 comments on commit ff1f38d

Please sign in to comment.