From a1d91fcba108a59c440f0675dd5106422cf3ff7e Mon Sep 17 00:00:00 2001 From: xengineering Date: Thu, 3 Oct 2024 18:16:08 +0200 Subject: 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 --- config.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 config.go (limited to 'config.go') 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 +} -- cgit v1.2.3-70-g09d2