summaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-10-03 18:16:08 +0200
committerxengineering <me@xengineering.eu>2024-10-06 20:13:28 +0200
commita1d91fcba108a59c440f0675dd5106422cf3ff7e (patch)
treef40aea2e6cda586da1a294b1200b55f2424c199d /config.go
parentbb34d5f69ca4ad66754dd9833b9d7efee41ba4f2 (diff)
downloadsoundbox-app-a1d91fcba108a59c440f0675dd5106422cf3ff7e.tar
soundbox-app-a1d91fcba108a59c440f0675dd5106422cf3ff7e.tar.zst
soundbox-app-a1d91fcba108a59c440f0675dd5106422cf3ff7e.zip
Switch from local playback to soundbox streaming
This commit replaces the local playback of the received audio content by forwarding it to one or multiple soundbox devices. For this purpose the soundbox-go[1] library is used. The target devices cannot be selected via the GUI. Thus all devices are specified in the ~/.config/soundbox/config.json file. The format has to be looked up based on the code. Further documentation will follow. [1]: https://xengineering.eu/git/soundbox-go
Diffstat (limited to 'config.go')
-rw-r--r--config.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/config.go b/config.go
new file mode 100644
index 0000000..5bdd48c
--- /dev/null
+++ b/config.go
@@ -0,0 +1,47 @@
+package main
+
+import (
+ "encoding/json"
+ "io"
+ "os"
+ "path/filepath"
+)
+
+const configPathRelative = `.config/soundbox/config.json`
+
+type SoundboxConfig struct {
+ Name string `json:"name"`
+ Mac string `json:"mac"`
+}
+
+type GlobalConfig struct {
+ Soundboxes []SoundboxConfig `json:"soundboxes"`
+}
+
+func loadConfig() (GlobalConfig, error) {
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return GlobalConfig{}, err
+ }
+
+ path := filepath.Join(home, configPathRelative)
+
+ file, err := os.Open(path)
+ if err != nil {
+ return GlobalConfig{}, err
+ }
+ defer file.Close()
+
+ bytes, err := io.ReadAll(file)
+ if err != nil {
+ return GlobalConfig{}, err
+ }
+
+ var config GlobalConfig
+ err = json.Unmarshal(bytes, &config)
+ if err != nil {
+ return GlobalConfig{}, err
+ }
+
+ return config, nil
+}