Documentation
¶
Overview ¶
Package client provides a comprehensive HTTP client for controlling Bose SoundTouch devices.
This package implements the complete Bose SoundTouch Web API, enabling full programmatic control of SoundTouch speakers including playback control, volume management, source selection, multiroom zone management, and real-time event monitoring.
Basic Usage ¶
Create a client and control your SoundTouch device:
config := &client.Config{
Host: "192.168.1.100",
Port: 8090,
Timeout: 10 * time.Second,
}
client := client.NewClient(config)
// Get device information
info, err := client.GetInfo()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Device: %s (Type: %s)\n", info.Name, info.Type)
// Control playback
err = client.Play()
if err != nil {
log.Fatal(err)
}
// Adjust volume
err = client.SetVolume(50)
if err != nil {
log.Fatal(err)
}
Advanced Features ¶
The client supports all SoundTouch API endpoints:
// Get current playback status
nowPlaying, err := client.GetNowPlaying()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Now Playing: %s by %s\n", nowPlaying.Track, nowPlaying.Artist)
// Select audio source
err = client.SelectSource("SPOTIFY", "")
if err != nil {
log.Fatal(err)
}
// Control bass and balance
err = client.SetBass(3) // Range: -9 to +9
if err != nil {
log.Fatal(err)
}
err = client.SetBalance(-10) // Range: -50 (left) to +50 (right)
if err != nil {
log.Fatal(err)
}
Multiroom Zone Management ¶
Create and manage multiroom zones:
// Get current zone configuration
zone, err := client.GetZone()
if err != nil {
log.Fatal(err)
}
// Create a new zone with multiple speakers
newZone := &models.ZoneRequest{
Master: "192.168.1.100",
Members: []models.MemberEntry{
{IP: "192.168.1.101"},
{IP: "192.168.1.102"},
},
}
err = client.SetZone(newZone)
if err != nil {
log.Fatal(err)
}
Real-time Events ¶
Monitor device state changes using WebSocket connections:
ctx := context.Background()
events, err := client.SubscribeToEvents(ctx)
if err != nil {
log.Fatal(err)
}
for event := range events {
switch e := event.(type) {
case *models.NowPlayingUpdated:
fmt.Printf("Track changed: %s\n", e.Track)
case *models.VolumeUpdated:
fmt.Printf("Volume: %d\n", e.ActualVolume)
case *models.ConnectionStateUpdated:
fmt.Printf("Connection: %s\n", e.State)
}
}
Error Handling ¶
The client provides detailed error information:
err := client.SetVolume(150) // Invalid volume
if err != nil {
fmt.Printf("Error: %v\n", err) // Will indicate volume out of range
}
Configuration ¶
The Config struct supports various options:
config := &client.Config{
Host: "192.168.1.100",
Port: 8090,
Timeout: 15 * time.Second,
UserAgent: "MyApp/1.0",
}
Supported Operations ¶
- Device Information & Capabilities
- Playback Control (Play/Pause/Stop/Next/Previous/Key commands)
- Volume Control (Get/Set/Increment/Decrement)
- Bass Control (-9 to +9 range)
- Balance Control (-50 to +50 range)
- Source Selection (Spotify, Bluetooth, AUX, Radio, etc.)
- Preset Management (Get configured presets)
- Clock/Time Management
- Network Information
- Multiroom Zone Management
- Real-time WebSocket Event Monitoring
Example ¶
Example demonstrates basic device control operations.
package main
import (
"fmt"
"log"
"time"
"github.com/gesellix/bose-soundtouch/pkg/client"
)
func main() {
// Create a client for your SoundTouch device
config := &client.Config{
Host: "192.168.1.100",
Port: 8090,
Timeout: 10 * time.Second,
}
c := client.NewClient(config)
// Get device information
info, err := c.GetDeviceInfo()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Device: %s\n", info.Name)
// Control playback
err = c.Play()
if err != nil {
log.Fatal(err)
}
// Set volume to 50%
err = c.SetVolume(50)
if err != nil {
log.Fatal(err)
}
// Example output:
// Device: Living Room Speaker
}
Output:
Example (SearchAndPlayWorkflow) ¶
Example_searchAndPlayWorkflow demonstrates search -> add -> play workflow
config := &Config{Host: "192.168.1.100", Port: 8090}
client := NewClient(config)
searchTerm := "classic rock"
fmt.Printf("Searching for '%s'...\n", searchTerm)
// 1. Search for content
results, err := client.SearchTuneInStations(searchTerm)
if err != nil {
log.Fatal(err)
}
stations := results.GetStations()
if len(stations) == 0 {
fmt.Println("No stations found")
return
}
// 2. Show available stations
fmt.Printf("Found %d stations\n", len(stations))
for i, station := range stations[:minInt(5, len(stations))] {
fmt.Printf("%d. %s", i+1, station.GetDisplayName())
if station.Description != "" {
fmt.Printf(" - %s", station.Description)
}
fmt.Println()
}
// 3. In a real app, user would select one
selectedStation := stations[0]
fmt.Printf("\nSelected: %s\n", selectedStation.GetDisplayName())
// 4. For TuneIn, you might need to add it as a station first
// (depending on the service and how the API works)
if selectedStation.Token != "" {
fmt.Printf("Would add station with token: %s\n", selectedStation.Token)
// err := client.AddStation("TUNEIN", "", selectedStation.Token, selectedStation.Name)
}
fmt.Println("Station would now be playing!")
Index ¶
- type Client
- func (c *Client) AddAmazonMusicAccount(user, password string) error
- func (c *Client) AddDeezerAccount(user, password string) error
- func (c *Client) AddIHeartRadioAccount(user, password string) error
- func (c *Client) AddPandoraAccount(user, password string) error
- func (c *Client) AddSpotifyAccount(user, password string) error
- func (c *Client) AddStation(source, sourceAccount, token, name string) error
- func (c *Client) AddStoredMusicAccount(user, displayName string) error
- func (c *Client) AddToZone(deviceID, ipAddress string) error
- func (c *Client) AddZoneSlave(masterDeviceID, slaveDeviceID, slaveIP string) error
- func (c *Client) AddZoneSlaveByDeviceID(masterDeviceID, slaveDeviceID string) error
- func (c *Client) BaseURL() string
- func (c *Client) CreateZone(masterDeviceID string, memberDeviceIDs []string) error
- func (c *Client) CreateZoneWithIPs(masterDeviceID string, members map[string]string) error
- func (c *Client) DecreaseBalance(amount int) (*models.Balance, error)
- func (c *Client) DecreaseBass(amount int) (*models.Bass, error)
- func (c *Client) DecreaseVolume(amount int) (*models.Volume, error)
- func (c *Client) DisableClockDisplay() error
- func (c *Client) DissolveZone() error
- func (c *Client) EnableClockDisplay() error
- func (c *Client) GetAudioDSPControls() (*models.AudioDSPControls, error)
- func (c *Client) GetAudioProductLevelControls() (*models.AudioProductLevelControls, error)
- func (c *Client) GetAudioProductToneControls() (*models.AudioProductToneControls, error)
- func (c *Client) GetBalance() (*models.Balance, error)
- func (c *Client) GetBass() (*models.Bass, error)
- func (c *Client) GetBassCapabilities() (*models.BassCapabilities, error)
- func (c *Client) GetCapabilities() (*models.Capabilities, error)
- func (c *Client) GetClockDisplay() (*models.ClockDisplay, error)
- func (c *Client) GetClockTime() (*models.ClockTime, error)
- func (c *Client) GetDeviceInfo() (*models.DeviceInfo, error)
- func (c *Client) GetName() (*models.Name, error)
- func (c *Client) GetNetworkInfo() (*models.NetworkInformation, error)
- func (c *Client) GetNextAvailablePresetSlot() (int, error)
- func (c *Client) GetNowPlaying() (*models.NowPlaying, error)
- func (c *Client) GetPandoraStations(sourceAccount string) (*models.NavigateResponse, error)
- func (c *Client) GetPresets() (*models.Presets, error)
- func (c *Client) GetRecents() (*models.RecentsResponse, error)
- func (c *Client) GetServiceAvailability() (*models.ServiceAvailability, error)
- func (c *Client) GetSources() (*models.Sources, error)
- func (c *Client) GetStoredMusicLibrary(sourceAccount string) (*models.NavigateResponse, error)
- func (c *Client) GetSupportedURLs() (*models.SupportedURLsResponse, error)
- func (c *Client) GetTrackInfo() (*models.NowPlaying, error)
- func (c *Client) GetTuneInStations(sourceAccount string) (*models.NavigateResponse, error)
- func (c *Client) GetVolume() (*models.Volume, error)
- func (c *Client) GetZone() (*models.ZoneInfo, error)
- func (c *Client) GetZoneMembers() ([]string, error)
- func (c *Client) GetZoneStatus() (models.ZoneStatus, error)
- func (c *Client) Host() string
- func (c *Client) IncreaseBalance(amount int) (*models.Balance, error)
- func (c *Client) IncreaseBass(amount int) (*models.Bass, error)
- func (c *Client) IncreaseVolume(amount int) (*models.Volume, error)
- func (c *Client) Introspect(source, sourceAccount string) (*models.IntrospectResponse, error)
- func (c *Client) IntrospectSpotify(sourceAccount string) (*models.IntrospectResponse, error)
- func (c *Client) IsCurrentContentPresetable() (bool, error)
- func (c *Client) IsInZone() (bool, error)
- func (c *Client) Navigate(source, sourceAccount string, startItem, numItems int) (*models.NavigateResponse, error)
- func (c *Client) NavigateContainer(source, sourceAccount string, startItem, numItems int, ...) (*models.NavigateResponse, error)
- func (c *Client) NavigateWithMenu(source, sourceAccount, menu, sort string, startItem, numItems int) (*models.NavigateResponse, error)
- func (c *Client) NewWebSocketClient(config *WebSocketConfig) *WebSocketClient
- func (c *Client) NextTrack() error
- func (c *Client) NotifySourcesUpdated(deviceID string) error
- func (c *Client) Pause() error
- func (c *Client) Ping() error
- func (c *Client) Play() error
- func (c *Client) PlayCustom(playInfo *models.PlayInfo) error
- func (c *Client) PlayNotification(path string) error
- func (c *Client) PlayNotificationBeep() error
- func (c *Client) PlayTTS(text, appKey, language string, volume ...int) error
- func (c *Client) PlayURL(url, appKey, service, message, reason string, volume ...int) error
- func (c *Client) PrevTrack() error
- func (c *Client) RemoveAmazonMusicAccount(user string) error
- func (c *Client) RemoveDeezerAccount(user string) error
- func (c *Client) RemoveFromZone(deviceID string) error
- func (c *Client) RemoveIHeartRadioAccount(user string) error
- func (c *Client) RemoveMusicServiceAccount(credentials *models.MusicServiceCredentials) error
- func (c *Client) RemovePandoraAccount(user string) error
- func (c *Client) RemovePreset(id int) error
- func (c *Client) RemoveSpotifyAccount(user string) error
- func (c *Client) RemoveStation(contentItem *models.ContentItem) error
- func (c *Client) RemoveStoredMusicAccount(user, displayName string) error
- func (c *Client) RemoveZoneSlave(masterDeviceID, slaveDeviceID, slaveIP string) error
- func (c *Client) RemoveZoneSlaveByDeviceID(masterDeviceID, slaveDeviceID string) error
- func (c *Client) RequestToken() (*models.BearerToken, error)
- func (c *Client) SearchPandoraStations(sourceAccount, searchTerm string) (*models.SearchStationResponse, error)
- func (c *Client) SearchSpotifyContent(sourceAccount, searchTerm string) (*models.SearchStationResponse, error)
- func (c *Client) SearchStation(source, sourceAccount, searchTerm string) (*models.SearchStationResponse, error)
- func (c *Client) SearchTuneInStations(searchTerm string) (*models.SearchStationResponse, error)
- func (c *Client) SelectAux() error
- func (c *Client) SelectBluetooth() error
- func (c *Client) SelectContentItem(contentItem *models.ContentItem) error
- func (c *Client) SelectLocalInternetRadio(location, sourceAccount, itemName, containerArt string) error
- func (c *Client) SelectLocalMusic(location, sourceAccount, itemName, containerArt string) error
- func (c *Client) SelectPandora(sourceAccount string) error
- func (c *Client) SelectPreset(presetNumber int) error
- func (c *Client) SelectSource(source, sourceAccount string) error
- func (c *Client) SelectSourceFromItem(sourceItem *models.SourceItem) error
- func (c *Client) SelectSpotify(sourceAccount string) error
- func (c *Client) SelectStoredMusic(location, sourceAccount, itemName, containerArt string) error
- func (c *Client) SelectTuneIn(sourceAccount string) error
- func (c *Client) SendKey(keyValue string) error
- func (c *Client) SendKeyPress(keyValue string) error
- func (c *Client) SendKeyPressOnly(keyValue string) error
- func (c *Client) SendKeyRelease(keyValue string) error
- func (c *Client) SendKeyReleaseOnly(keyValue string) error
- func (c *Client) SetAdvancedBass(level int) error
- func (c *Client) SetAdvancedTreble(level int) error
- func (c *Client) SetAudioDSPControls(audioMode string, videoSyncDelay int) error
- func (c *Client) SetAudioMode(mode string) error
- func (c *Client) SetAudioProductLevelControls(frontCenter, rearSurround *int) error
- func (c *Client) SetAudioProductToneControls(bass, treble *int) error
- func (c *Client) SetBalance(level int) error
- func (c *Client) SetBalanceSafe(level int) error
- func (c *Client) SetBass(level int) error
- func (c *Client) SetBassSafe(level int) error
- func (c *Client) SetClockDisplay(request *models.ClockDisplayRequest) error
- func (c *Client) SetClockDisplayBrightness(brightness int) error
- func (c *Client) SetClockDisplayFormat(format models.ClockFormat) error
- func (c *Client) SetClockTime(request *models.ClockTimeRequest) error
- func (c *Client) SetClockTimeNow() error
- func (c *Client) SetFrontCenterSpeakerLevel(level int) error
- func (c *Client) SetMusicServiceAccount(credentials *models.MusicServiceCredentials) error
- func (c *Client) SetMusicServiceOAuthAccount(credentials *models.OAuthCredentials) error
- func (c *Client) SetName(name string) error
- func (c *Client) SetRearSurroundSpeakersLevel(level int) error
- func (c *Client) SetVideoSyncAudioDelay(delay int) error
- func (c *Client) SetVolume(level int) error
- func (c *Client) SetVolumeSafe(level int) error
- func (c *Client) SetZone(zoneRequest *models.ZoneRequest) error
- func (c *Client) Stop() error
- func (c *Client) StoreCurrentAsPreset(id int) error
- func (c *Client) StorePreset(id int, contentItem *models.ContentItem) error
- func (c *Client) VolumeDown() error
- func (c *Client) VolumeUp() error
- type Config
- type DefaultLogger
- type Logger
- type WebSocketClient
- func (ws *WebSocketClient) Connect() error
- func (ws *WebSocketClient) ConnectWithConfig(config *WebSocketConfig) error
- func (ws *WebSocketClient) Disconnect() error
- func (ws *WebSocketClient) IsConnected() bool
- func (ws *WebSocketClient) OnBassUpdated(handler models.TypedEventHandler[*models.BassUpdatedEvent])
- func (ws *WebSocketClient) OnConnectionState(handler models.TypedEventHandler[*models.ConnectionStateUpdatedEvent])
- func (ws *WebSocketClient) OnNowPlaying(handler models.TypedEventHandler[*models.NowPlayingUpdatedEvent])
- func (ws *WebSocketClient) OnPresetUpdated(handler models.TypedEventHandler[*models.PresetUpdatedEvent])
- func (ws *WebSocketClient) OnSpecialMessage(handler models.SpecialMessageHandler)
- func (ws *WebSocketClient) OnUnknownEvent(handler models.EventHandler)
- func (ws *WebSocketClient) OnVolumeUpdated(handler models.TypedEventHandler[*models.VolumeUpdatedEvent])
- func (ws *WebSocketClient) OnZoneUpdated(handler models.TypedEventHandler[*models.ZoneUpdatedEvent])
- func (ws *WebSocketClient) PairWithAccount(accountID, userAuthToken string) error
- func (ws *WebSocketClient) SendMessage(message []byte) error
- func (ws *WebSocketClient) SetHandlers(handlers *models.WebSocketEventHandlers)
- func (ws *WebSocketClient) UnPairFromAccount() error
- func (ws *WebSocketClient) Wait()
- type WebSocketConfig
Examples ¶
- Package
- Package (NavigationWorkflow)
- Package (SearchAndPlayWorkflow)
- Client.AddStation
- Client.GetCapabilities
- Client.GetNowPlaying
- Client.GetPresets
- Client.GetRecents
- Client.GetSupportedURLs (Concept)
- Client.Introspect
- Client.IntrospectSpotify
- Client.Navigate
- Client.NavigateContainer
- Client.NewWebSocketClient
- Client.SearchStation
- Client.SelectSource
- Client.SendKey
- Client.SetBalance
- Client.SetBass
- Client.SetVolume
- Client.SetZone
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a SoundTouch API client
func NewClientFromHost ¶
NewClientFromHost creates a new client with just a host address
func (*Client) AddAmazonMusicAccount ¶ added in v0.9.0
AddAmazonMusicAccount adds an Amazon Music account
func (*Client) AddDeezerAccount ¶ added in v0.9.0
AddDeezerAccount adds a Deezer Premium account
func (*Client) AddIHeartRadioAccount ¶ added in v0.9.0
AddIHeartRadioAccount adds an iHeartRadio account
func (*Client) AddPandoraAccount ¶ added in v0.9.0
AddPandoraAccount adds a Pandora account
func (*Client) AddSpotifyAccount ¶ added in v0.9.0
AddSpotifyAccount adds a Spotify Premium account
func (*Client) AddStation ¶ added in v0.7.0
AddStation adds a station to a music service collection and immediately starts playing it
Example ¶
ExampleClient_AddStation demonstrates adding a station and playing it
config := &Config{Host: "192.168.1.100", Port: 8090}
client := NewClient(config)
// First, search for content to get a token
results, err := client.SearchPandoraStations("user123", "classic rock")
if err != nil {
log.Fatal(err)
}
// Find an artist to create a station from
artists := results.GetArtists()
if len(artists) == 0 {
fmt.Println("No artists found")
return
}
artist := artists[0]
stationName := artist.Name + " Radio"
// Add the station (this immediately starts playing it)
err = client.AddStation("PANDORA", "user123", artist.Token, stationName)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Added and started playing: %s\n", stationName)
func (*Client) AddStoredMusicAccount ¶ added in v0.9.0
AddStoredMusicAccount adds a STORED_MUSIC (NAS/UPnP) account
func (*Client) AddZoneSlave ¶ added in v0.6.0
AddZoneSlave adds a single device to an existing zone using the official /addZoneSlave endpoint
func (*Client) AddZoneSlaveByDeviceID ¶ added in v0.6.0
AddZoneSlaveByDeviceID adds a single device to an existing zone by device ID only
func (*Client) CreateZone ¶
CreateZone creates a new multiroom zone with the specified master and members
func (*Client) CreateZoneWithIPs ¶
CreateZoneWithIPs creates a new multiroom zone with device IDs and IP addresses
func (*Client) DecreaseBalance ¶
DecreaseBalance decreases balance by the specified amount (with safety limits)
func (*Client) DecreaseBass ¶
DecreaseBass decreases bass by the specified amount (with safety limits)
func (*Client) DecreaseVolume ¶
DecreaseVolume decreases volume by the specified amount (with safety limits)
func (*Client) DisableClockDisplay ¶
DisableClockDisplay disables the clock display
func (*Client) DissolveZone ¶
DissolveZone dissolves the current zone, making all devices standalone
func (*Client) EnableClockDisplay ¶
EnableClockDisplay enables the clock display with default settings
func (*Client) GetAudioDSPControls ¶ added in v0.6.0
func (c *Client) GetAudioDSPControls() (*models.AudioDSPControls, error)
GetAudioDSPControls retrieves the current DSP audio controls Only available if audiodspcontrols is listed in the reply to GET /capabilities
func (*Client) GetAudioProductLevelControls ¶ added in v0.6.0
func (c *Client) GetAudioProductLevelControls() (*models.AudioProductLevelControls, error)
GetAudioProductLevelControls retrieves the current speaker level controls Only available if audioproductlevelcontrols is listed in the reply to GET /capabilities
func (*Client) GetAudioProductToneControls ¶ added in v0.6.0
func (c *Client) GetAudioProductToneControls() (*models.AudioProductToneControls, error)
GetAudioProductToneControls retrieves the current advanced tone controls (bass/treble) Only available if audioproducttonecontrols is listed in the reply to GET /capabilities
func (*Client) GetBalance ¶
GetBalance retrieves the current balance level from the /balance endpoint
func (*Client) GetBassCapabilities ¶
func (c *Client) GetBassCapabilities() (*models.BassCapabilities, error)
GetBassCapabilities retrieves the bass capabilities for the device
func (*Client) GetCapabilities ¶
func (c *Client) GetCapabilities() (*models.Capabilities, error)
GetCapabilities retrieves device capabilities from the /capabilities endpoint
Example ¶
ExampleClient_GetCapabilities demonstrates how to check device capabilities.
package main
import (
"fmt"
"log"
"github.com/gesellix/bose-soundtouch/pkg/client"
)
func main() {
config := &client.Config{Host: "192.168.1.100"}
c := client.NewClient(config)
capabilities, err := c.GetCapabilities()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Device supports %d capabilities\n", len(capabilities.Capability))
for _, capability := range capabilities.Capability {
fmt.Printf("- %s (URL: %s)\n", capability.Name, capability.URL)
}
// Example output:
// Device supports 5 capabilities
// - VOLUME (/volume)
// - BASS (/bass)
// - SOURCES (/sources)
// - PRESETS (/presets)
// - ZONE (/getZone)
}
Output:
func (*Client) GetClockDisplay ¶
func (c *Client) GetClockDisplay() (*models.ClockDisplay, error)
GetClockDisplay retrieves clock display settings from the /clockDisplay endpoint
func (*Client) GetClockTime ¶
GetClockTime retrieves the device's current time from the /clockTime endpoint
func (*Client) GetDeviceInfo ¶
func (c *Client) GetDeviceInfo() (*models.DeviceInfo, error)
GetDeviceInfo retrieves device information from the /info endpoint
func (*Client) GetNetworkInfo ¶
func (c *Client) GetNetworkInfo() (*models.NetworkInformation, error)
GetNetworkInfo retrieves network information from the /networkInfo endpoint
func (*Client) GetNextAvailablePresetSlot ¶
GetNextAvailablePresetSlot returns the next available preset slot (1-6), or error if all are used
func (*Client) GetNowPlaying ¶
func (c *Client) GetNowPlaying() (*models.NowPlaying, error)
GetNowPlaying retrieves current playback information from the /now_playing endpoint
Example ¶
ExampleClient_GetNowPlaying demonstrates how to get current playback information.
package main
import (
"fmt"
"log"
"github.com/gesellix/bose-soundtouch/pkg/client"
)
func main() {
config := &client.Config{Host: "192.168.1.100"}
c := client.NewClient(config)
nowPlaying, err := c.GetNowPlaying()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Track: %s\n", nowPlaying.Track)
fmt.Printf("Artist: %s\n", nowPlaying.Artist)
fmt.Printf("Album: %s\n", nowPlaying.Album)
fmt.Printf("Source: %s\n", nowPlaying.Source)
// Example output:
// Track: Bohemian Rhapsody
// Artist: Queen
// Album: A Night at the Opera
// Source: SPOTIFY
}
Output:
func (*Client) GetPandoraStations ¶ added in v0.7.0
func (c *Client) GetPandoraStations(sourceAccount string) (*models.NavigateResponse, error)
GetPandoraStations gets all Pandora radio stations for an account
func (*Client) GetPresets ¶
GetPresets retrieves configured presets from the /presets endpoint
Example ¶
ExampleClient_GetPresets demonstrates how to retrieve configured presets.
package main
import (
"fmt"
"log"
"github.com/gesellix/bose-soundtouch/pkg/client"
)
func main() {
config := &client.Config{Host: "192.168.1.100"}
c := client.NewClient(config)
presets, err := c.GetPresets()
if err != nil {
log.Fatal(err)
}
for _, preset := range presets.Preset {
fmt.Printf("Preset %d: %s (%s)\n", preset.ID, preset.GetDisplayName(), preset.GetSource())
}
// Example output:
// Preset 1: Morning Jazz (SPOTIFY)
// Preset 2: Classic Rock (SPOTIFY)
// Preset 3: NPR News (INTERNET_RADIO)
}
Output:
func (*Client) GetRecents ¶ added in v0.9.0
func (c *Client) GetRecents() (*models.RecentsResponse, error)
GetRecents retrieves recently played content from the device
Example ¶
ExampleClient_GetRecents demonstrates how to use the GetRecents method
config := &Config{
Host: "192.168.1.100",
Port: 8090,
}
client := NewClient(config)
// Get recent items
response, err := client.GetRecents()
if err != nil {
panic(err)
}
if response.IsEmpty() {
println("No recent items found")
return
}
// Show most recent item
mostRecent := response.GetMostRecent()
if mostRecent != nil {
println("Most recent:", mostRecent.GetDisplayName())
println("Source:", mostRecent.GetSource())
if mostRecent.IsPresetable() {
println("Can be saved as preset")
}
}
// Show Spotify items
spotifyItems := response.GetSpotifyItems()
if len(spotifyItems) > 0 {
println("Recent Spotify tracks:")
for _, item := range spotifyItems {
println("-", item.GetDisplayName())
}
}
// Show only tracks (no stations or playlists)
tracks := response.GetTracks()
println("Total tracks in recent items:", len(tracks))
func (*Client) GetServiceAvailability ¶ added in v0.7.0
func (c *Client) GetServiceAvailability() (*models.ServiceAvailability, error)
GetServiceAvailability retrieves service availability status from the /serviceAvailability endpoint
func (*Client) GetSources ¶
GetSources retrieves available audio sources from the /sources endpoint
func (*Client) GetStoredMusicLibrary ¶ added in v0.7.0
func (c *Client) GetStoredMusicLibrary(sourceAccount string) (*models.NavigateResponse, error)
GetStoredMusicLibrary browses stored music library
func (*Client) GetSupportedURLs ¶ added in v0.7.0
func (c *Client) GetSupportedURLs() (*models.SupportedURLsResponse, error)
GetSupportedURLs retrieves all supported endpoints from the /supportedURLs endpoint
Example (Concept) ¶
package main
import (
"fmt"
"log"
"github.com/gesellix/bose-soundtouch/pkg/client"
)
func main() {
// Example of how to use GetSupportedURLs() method
// Note: This example shows the concept but doesn't execute to avoid requiring a real device
config := &client.Config{Host: "192.168.1.100"}
c := client.NewClient(config)
supportedURLs, err := c.GetSupportedURLs()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Device %s supports %d endpoints\n", supportedURLs.DeviceID, supportedURLs.GetURLCount())
fmt.Printf("Core functionality: %v\n", supportedURLs.HasCorePlaybackSupport())
fmt.Printf("Multiroom support: %v\n", supportedURLs.HasMultiroomSupport())
fmt.Printf("Streaming support: %v\n", supportedURLs.HasStreamingSupport())
// Check specific endpoints
if supportedURLs.HasURL("/audiodspcontrols") {
fmt.Println("Device supports advanced audio controls")
}
// Expected output with a real device:
// Device 08DF1F0BA325 supports 103 endpoints
// Core functionality: true
// Multiroom support: true
// Streaming support: true
// Device supports advanced audio controls
}
Output:
func (*Client) GetTrackInfo ¶
func (c *Client) GetTrackInfo() (*models.NowPlaying, error)
GetTrackInfo retrieves track information (duplicate of GetNowPlaying per official API) WARNING: This endpoint times out on real devices despite being documented in the official API. Use GetNowPlaying() instead for reliable track information.
func (*Client) GetTuneInStations ¶ added in v0.7.0
func (c *Client) GetTuneInStations(sourceAccount string) (*models.NavigateResponse, error)
GetTuneInStations browses TuneIn stations/content
func (*Client) GetZoneMembers ¶
GetZoneMembers returns all devices in the current zone
func (*Client) GetZoneStatus ¶
func (c *Client) GetZoneStatus() (models.ZoneStatus, error)
GetZoneStatus returns the zone status for this device
func (*Client) IncreaseBalance ¶
IncreaseBalance increases balance by the specified amount (with safety limits)
func (*Client) IncreaseBass ¶
IncreaseBass increases bass by the specified amount (with safety limits)
func (*Client) IncreaseVolume ¶
IncreaseVolume increases volume by the specified amount (with safety limits)
func (*Client) Introspect ¶ added in v0.9.0
func (c *Client) Introspect(source, sourceAccount string) (*models.IntrospectResponse, error)
Introspect retrieves introspect data for a specified music service
Example ¶
ExampleClient_Introspect demonstrates how to use the Introspect method
config := &Config{
Host: "192.168.1.100",
Port: 8090,
}
client := NewClient(config)
// Get introspect data for Spotify
response, err := client.Introspect("SPOTIFY", "")
if err != nil {
panic(err)
}
// Check service state
if response.IsActive() {
println("Spotify service is active")
if response.IsPlaying {
println("Currently playing:", response.CurrentURI)
}
} else {
println("Spotify service is inactive")
}
// Check capabilities
if response.SupportsSeek() {
println("Seek is supported")
}
if response.SupportsSkipPrevious() {
println("Skip previous is supported")
}
func (*Client) IntrospectSpotify ¶ added in v0.9.0
func (c *Client) IntrospectSpotify(sourceAccount string) (*models.IntrospectResponse, error)
IntrospectSpotify is a convenience method to get introspect data for Spotify
Example ¶
ExampleClient_IntrospectSpotify demonstrates the Spotify convenience method
config := &Config{
Host: "192.168.1.100",
Port: 8090,
}
client := NewClient(config)
// Get Spotify introspect data using convenience method
response, err := client.IntrospectSpotify("")
if err != nil {
panic(err)
}
// Display user and subscription info
if response.HasUser() {
println("Spotify user:", response.User)
}
if response.HasSubscription() {
println("Subscription type:", response.SubscriptionType)
}
// Check shuffle state
if response.IsShuffleEnabled() {
println("Shuffle is enabled")
} else {
println("Shuffle is disabled")
}
func (*Client) IsCurrentContentPresetable ¶
IsCurrentContentPresetable checks if the currently playing content can be saved as a preset
func (*Client) Navigate ¶ added in v0.7.0
func (c *Client) Navigate(source, sourceAccount string, startItem, numItems int) (*models.NavigateResponse, error)
Navigate browses content within a source (e.g., browse music libraries, stations)
func (*Client) NavigateContainer ¶ added in v0.7.0
func (c *Client) NavigateContainer(source, sourceAccount string, startItem, numItems int, containerItem *models.ContentItem) (*models.NavigateResponse, error)
NavigateContainer browses a specific container/directory within a source
func (*Client) NavigateWithMenu ¶ added in v0.7.0
func (c *Client) NavigateWithMenu(source, sourceAccount, menu, sort string, startItem, numItems int) (*models.NavigateResponse, error)
NavigateWithMenu browses content with menu and sort parameters (e.g., Pandora stations)
func (*Client) NewWebSocketClient ¶
func (c *Client) NewWebSocketClient(config *WebSocketConfig) *WebSocketClient
NewWebSocketClient creates a new WebSocket client for the given SoundTouch client
Example ¶
ExampleClient_NewWebSocketClient demonstrates WebSocket client creation.
package main
import (
"fmt"
"log"
"github.com/gesellix/bose-soundtouch/pkg/client"
)
func main() {
config := &client.Config{Host: "192.168.1.100"}
c := client.NewClient(config)
// Create WebSocket client for real-time events
wsClient := c.NewWebSocketClient(nil)
// Connect to device WebSocket
err := wsClient.Connect()
if err != nil {
log.Fatal(err)
}
defer func() {
_ = wsClient.Disconnect()
}()
fmt.Printf("WebSocket connected: %t\n", wsClient.IsConnected())
// Example output:
// WebSocket connected: true
}
Output:
func (*Client) NotifySourcesUpdated ¶ added in v0.57.0
NotifySourcesUpdated notifies the device that sources have been updated in Marge
func (*Client) PlayCustom ¶ added in v0.8.0
PlayCustom plays custom content using a PlayInfo configuration
func (*Client) PlayNotification ¶ added in v0.12.0
PlayNotification plays a notification. If a non-empty local path is provided, it will be sent as XML body to play that specific device-local PCM file. When path is empty, the device's default beep is triggered.
func (*Client) PlayNotificationBeep ¶ added in v0.8.0
PlayNotificationBeep plays a notification beep on the device
func (*Client) PlayTTS ¶ added in v0.8.0
PlayTTS plays a Text-To-Speech message using Google TTS on the speaker
func (*Client) RemoveAmazonMusicAccount ¶ added in v0.9.0
RemoveAmazonMusicAccount removes an Amazon Music account
func (*Client) RemoveDeezerAccount ¶ added in v0.9.0
RemoveDeezerAccount removes a Deezer account
func (*Client) RemoveFromZone ¶
RemoveFromZone removes a device from the current zone
func (*Client) RemoveIHeartRadioAccount ¶ added in v0.9.0
RemoveIHeartRadioAccount removes an iHeartRadio account
func (*Client) RemoveMusicServiceAccount ¶ added in v0.9.0
func (c *Client) RemoveMusicServiceAccount(credentials *models.MusicServiceCredentials) error
RemoveMusicServiceAccount removes an existing music service account
func (*Client) RemovePandoraAccount ¶ added in v0.9.0
RemovePandoraAccount removes a Pandora account
func (*Client) RemovePreset ¶ added in v0.7.0
RemovePreset deletes a preset from the SoundTouch device
func (*Client) RemoveSpotifyAccount ¶ added in v0.9.0
RemoveSpotifyAccount removes a Spotify account
func (*Client) RemoveStation ¶ added in v0.7.0
func (c *Client) RemoveStation(contentItem *models.ContentItem) error
RemoveStation removes a station from a music service collection
func (*Client) RemoveStoredMusicAccount ¶ added in v0.9.0
RemoveStoredMusicAccount removes a STORED_MUSIC account
func (*Client) RemoveZoneSlave ¶ added in v0.6.0
RemoveZoneSlave removes a single device from an existing zone using the official /removeZoneSlave endpoint
func (*Client) RemoveZoneSlaveByDeviceID ¶ added in v0.6.0
RemoveZoneSlaveByDeviceID removes a single device from an existing zone by device ID only
func (*Client) RequestToken ¶ added in v0.7.0
func (c *Client) RequestToken() (*models.BearerToken, error)
RequestToken generates a new bearer token from the device
func (*Client) SearchPandoraStations ¶ added in v0.7.0
func (c *Client) SearchPandoraStations(sourceAccount, searchTerm string) (*models.SearchStationResponse, error)
SearchPandoraStations searches for Pandora stations by artist/song name
func (*Client) SearchSpotifyContent ¶ added in v0.7.0
func (c *Client) SearchSpotifyContent(sourceAccount, searchTerm string) (*models.SearchStationResponse, error)
SearchSpotifyContent searches for Spotify content (playlists, tracks, etc.)
func (*Client) SearchStation ¶ added in v0.7.0
func (c *Client) SearchStation(source, sourceAccount, searchTerm string) (*models.SearchStationResponse, error)
SearchStation searches for stations/content within a music service
Example ¶
ExampleClient_SearchStation demonstrates searching for radio stations
config := &Config{Host: "192.168.1.100", Port: 8090}
client := NewClient(config)
// Search for jazz stations on TuneIn
results, err := client.SearchTuneInStations("jazz")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Found %d search results\n", results.GetResultCount())
// Show stations found
stations := results.GetStations()
for _, station := range stations {
fmt.Printf("Station: %s\n", station.GetDisplayName())
if station.Description != "" {
fmt.Printf(" Description: %s\n", station.Description)
}
}
func (*Client) SearchTuneInStations ¶ added in v0.7.0
func (c *Client) SearchTuneInStations(searchTerm string) (*models.SearchStationResponse, error)
SearchTuneInStations searches for TuneIn stations/content
func (*Client) SelectBluetooth ¶
SelectBluetooth is a convenience method to select Bluetooth source
func (*Client) SelectContentItem ¶ added in v0.9.0
func (c *Client) SelectContentItem(contentItem *models.ContentItem) error
SelectContentItem selects content using a ContentItem directly. This method allows full control over all ContentItem properties including complex location parameters for LOCAL_INTERNET_RADIO streamUrl format.
Example usage for LOCAL_INTERNET_RADIO with streamUrl:
contentItem := &models.ContentItem{
Source: "LOCAL_INTERNET_RADIO",
Type: "stationurl",
Location: "http://contentapi.gmuth.de/station.php?name=MyStation&streamUrl=https://stream.example.com/radio",
IsPresetable: true,
ItemName: "My Radio Station",
ContainerArt: "https://example.com/art.png",
}
err := client.SelectContentItem(contentItem)
func (*Client) SelectLocalInternetRadio ¶ added in v0.9.0
func (c *Client) SelectLocalInternetRadio(location, sourceAccount, itemName, containerArt string) error
SelectLocalInternetRadio is a convenience method to select LOCAL_INTERNET_RADIO content. For simple direct stream URLs, use streamURL parameter. For complex streamUrl format (with proxy), use the location parameter with full URL.
Example 1 - Direct stream:
err := client.SelectLocalInternetRadio("https://stream.example.com/radio", "", "My Radio", "")
Example 2 - StreamUrl format with proxy:
location := "http://contentapi.gmuth.de/station.php?name=MyStation&streamUrl=https://stream.example.com/radio" err := client.SelectLocalInternetRadio(location, "", "My Radio", "https://example.com/art.png")
func (*Client) SelectLocalMusic ¶ added in v0.9.0
SelectLocalMusic is a convenience method to select LOCAL_MUSIC content. This is used for SoundTouch App Media Server content on local computers.
Example:
err := client.SelectLocalMusic("album:983", "3f205110-4a57-4e91-810a-123456789012", "Welcome to the New", "http://192.168.1.14:8085/v1/albums/983/image")
func (*Client) SelectPandora ¶
SelectPandora is a convenience method to select Pandora source
func (*Client) SelectPreset ¶
SelectPreset sends a preset key command (1-6)
func (*Client) SelectSource ¶
SelectSource selects an audio source using the /select endpoint
Example ¶
ExampleClient_SelectSource demonstrates how to change audio sources.
package main
import (
"fmt"
"log"
"github.com/gesellix/bose-soundtouch/pkg/client"
)
func main() {
config := &client.Config{Host: "192.168.1.100"}
c := client.NewClient(config)
// Switch to Spotify
err := c.SelectSource("SPOTIFY", "")
if err != nil {
log.Fatal(err)
}
// Switch to Bluetooth
err = c.SelectSource("BLUETOOTH", "")
if err != nil {
log.Fatal(err)
}
// Switch to AUX input
err = c.SelectSource("AUX", "")
if err != nil {
log.Fatal(err)
}
fmt.Println("Source changed successfully")
// Example output:
// Source changed successfully
}
Output:
func (*Client) SelectSourceFromItem ¶
func (c *Client) SelectSourceFromItem(sourceItem *models.SourceItem) error
SelectSourceFromItem selects an audio source using a SourceItem
func (*Client) SelectSpotify ¶
SelectSpotify is a convenience method to select Spotify source
func (*Client) SelectStoredMusic ¶ added in v0.9.0
SelectStoredMusic is a convenience method to select STORED_MUSIC content. This is used for UPnP/DLNA media servers and NAS libraries.
Example:
err := client.SelectStoredMusic("6_a2874b5d_4f83d999", "d09708a1-5953-44bc-a413-123456789012/0", "Christmas Album", "")
func (*Client) SelectTuneIn ¶
SelectTuneIn is a convenience method to select TuneIn source
func (*Client) SendKey ¶
SendKey sends a key press command to the device (press followed by release)
Example ¶
ExampleClient_SendKey demonstrates sending key commands.
package main
import (
"fmt"
"log"
"github.com/gesellix/bose-soundtouch/pkg/client"
)
func main() {
config := &client.Config{Host: "192.168.1.100"}
c := client.NewClient(config)
// Send various key commands
commands := []string{"PLAY", "PAUSE", "NEXT_TRACK", "PREV_TRACK", "MUTE"}
for _, cmd := range commands {
err := c.SendKey(cmd)
if err != nil {
log.Printf("Failed to send %s: %v", cmd, err)
continue
}
fmt.Printf("Sent command: %s\n", cmd)
}
// Example output:
// Sent command: PLAY
// Sent command: PAUSE
// Sent command: NEXT_TRACK
// Sent command: PREV_TRACK
// Sent command: MUTE
}
Output:
func (*Client) SendKeyPress ¶
SendKeyPress sends a key press command (alias for SendKey - sends press+release)
func (*Client) SendKeyPressOnly ¶
SendKeyPressOnly sends only the key press state (without release)
func (*Client) SendKeyRelease ¶
SendKeyRelease sends a key release command
func (*Client) SendKeyReleaseOnly ¶
SendKeyReleaseOnly sends only the key release state (alias for SendKeyRelease)
func (*Client) SetAdvancedBass ¶ added in v0.6.0
SetAdvancedBass sets only the advanced bass control
func (*Client) SetAdvancedTreble ¶ added in v0.6.0
SetAdvancedTreble sets only the advanced treble control
func (*Client) SetAudioDSPControls ¶ added in v0.6.0
SetAudioDSPControls sets the DSP audio controls Only available if audiodspcontrols is listed in the reply to GET /capabilities
func (*Client) SetAudioMode ¶ added in v0.6.0
SetAudioMode sets only the audio mode (leaving video sync delay unchanged)
func (*Client) SetAudioProductLevelControls ¶ added in v0.6.0
SetAudioProductLevelControls sets the speaker level controls
func (*Client) SetAudioProductToneControls ¶ added in v0.6.0
SetAudioProductToneControls sets the advanced tone controls (bass and/or treble)
func (*Client) SetBalance ¶
SetBalance sets the balance level using the /balance endpoint
Example ¶
ExampleClient_SetBalance demonstrates balance control.
package main
import (
"fmt"
"log"
"github.com/gesellix/bose-soundtouch/pkg/client"
)
func main() {
config := &client.Config{Host: "192.168.1.100"}
c := client.NewClient(config)
// Set balance slightly to the right (range: -50 to +50)
err := c.SetBalance(10)
if err != nil {
log.Fatal(err)
}
// Get current balance
balance, err := c.GetBalance()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Balance: %d\n", balance.ActualBalance)
// Example output:
// Balance: 10
}
Output:
func (*Client) SetBalanceSafe ¶
SetBalanceSafe sets balance with validation and clamping
func (*Client) SetBass ¶
SetBass sets the bass level using the /bass endpoint
Example ¶
ExampleClient_SetBass demonstrates bass control.
package main
import (
"fmt"
"log"
"github.com/gesellix/bose-soundtouch/pkg/client"
)
func main() {
config := &client.Config{Host: "192.168.1.100"}
c := client.NewClient(config)
// Set bass to +3 (range: -9 to +9)
err := c.SetBass(3)
if err != nil {
log.Fatal(err)
}
// Get current bass level
bass, err := c.GetBass()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Bass level: %d\n", bass.ActualBass)
// Example output:
// Bass level: 3
}
Output:
func (*Client) SetBassSafe ¶
SetBassSafe sets bass with validation and clamping
func (*Client) SetClockDisplay ¶
func (c *Client) SetClockDisplay(request *models.ClockDisplayRequest) error
SetClockDisplay configures clock display settings via the /clockDisplay endpoint
func (*Client) SetClockDisplayBrightness ¶
SetClockDisplayBrightness sets the clock display brightness (0-100)
func (*Client) SetClockDisplayFormat ¶
func (c *Client) SetClockDisplayFormat(format models.ClockFormat) error
SetClockDisplayFormat sets the clock display format (12/24 hour)
func (*Client) SetClockTime ¶
func (c *Client) SetClockTime(request *models.ClockTimeRequest) error
SetClockTime sets the device's time via the /clockTime endpoint
func (*Client) SetClockTimeNow ¶
SetClockTimeNow sets the device's time to the current system time
func (*Client) SetFrontCenterSpeakerLevel ¶ added in v0.6.0
SetFrontCenterSpeakerLevel sets only the front-center speaker level
func (*Client) SetMusicServiceAccount ¶ added in v0.9.0
func (c *Client) SetMusicServiceAccount(credentials *models.MusicServiceCredentials) error
SetMusicServiceAccount adds or updates a music service account
func (*Client) SetMusicServiceOAuthAccount ¶ added in v0.57.0
func (c *Client) SetMusicServiceOAuthAccount(credentials *models.OAuthCredentials) error
SetMusicServiceOAuthAccount adds or updates a music service account using OAuth credentials
func (*Client) SetRearSurroundSpeakersLevel ¶ added in v0.6.0
SetRearSurroundSpeakersLevel sets only the rear-surround speakers level
func (*Client) SetVideoSyncAudioDelay ¶ added in v0.6.0
SetVideoSyncAudioDelay sets only the video sync audio delay (leaving audio mode unchanged)
func (*Client) SetVolume ¶
SetVolume sets the volume level using the /volume endpoint
Example ¶
ExampleClient_SetVolume demonstrates volume control with validation.
package main
import (
"fmt"
"log"
"github.com/gesellix/bose-soundtouch/pkg/client"
)
func main() {
config := &client.Config{Host: "192.168.1.100"}
c := client.NewClient(config)
// Set volume to 75%
err := c.SetVolume(75)
if err != nil {
log.Fatal(err)
}
// Get current volume
volume, err := c.GetVolume()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Volume: %d\n", volume.ActualVolume)
fmt.Printf("Muted: %t\n", volume.MuteEnabled)
// Example output:
// Volume: 75
// Muted: false
}
Output:
func (*Client) SetVolumeSafe ¶
SetVolumeSafe sets volume with validation and clamping
func (*Client) SetZone ¶
func (c *Client) SetZone(zoneRequest *models.ZoneRequest) error
SetZone configures multiroom zone settings
Example ¶
ExampleClient_SetZone demonstrates multiroom zone management.
package main
import (
"fmt"
"log"
"github.com/gesellix/bose-soundtouch/pkg/client"
"github.com/gesellix/bose-soundtouch/pkg/models"
)
func main() {
config := &client.Config{Host: "192.168.1.100"}
c := client.NewClient(config)
// Create a zone with multiple speakers
zone := &models.ZoneRequest{
Master: "192.168.1.100",
Members: []models.MemberEntry{
{IP: "192.168.1.101"},
{IP: "192.168.1.102"},
},
}
err := c.SetZone(zone)
if err != nil {
log.Fatal(err)
}
fmt.Println("Zone created successfully")
// Example output:
// Zone created successfully
}
Output:
func (*Client) StoreCurrentAsPreset ¶ added in v0.7.0
StoreCurrentAsPreset saves currently playing content as preset
func (*Client) StorePreset ¶ added in v0.7.0
func (c *Client) StorePreset(id int, contentItem *models.ContentItem) error
StorePreset saves content as a preset on the SoundTouch device
func (*Client) VolumeDown ¶
VolumeDown sends a VOLUME_DOWN key command
type Config ¶
Config holds configuration for the SoundTouch client
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a default client configuration
type DefaultLogger ¶
type DefaultLogger struct{}
DefaultLogger uses standard log package
func (DefaultLogger) Printf ¶
func (d DefaultLogger) Printf(format string, v ...interface{})
Printf implements the Logger interface by printing formatted messages with a WebSocket prefix.
type Logger ¶
type Logger interface {
Printf(format string, v ...interface{})
}
Logger interface for WebSocket logging
type WebSocketClient ¶
type WebSocketClient struct {
// contains filtered or unexported fields
}
WebSocketClient handles WebSocket connections to SoundTouch devices
func (*WebSocketClient) Connect ¶
func (ws *WebSocketClient) Connect() error
Connect establishes a WebSocket connection to the SoundTouch device
func (*WebSocketClient) ConnectWithConfig ¶
func (ws *WebSocketClient) ConnectWithConfig(config *WebSocketConfig) error
ConnectWithConfig establishes a WebSocket connection with custom configuration
func (*WebSocketClient) Disconnect ¶
func (ws *WebSocketClient) Disconnect() error
Disconnect closes the WebSocket connection
func (*WebSocketClient) IsConnected ¶
func (ws *WebSocketClient) IsConnected() bool
IsConnected returns true if the WebSocket is connected
func (*WebSocketClient) OnBassUpdated ¶
func (ws *WebSocketClient) OnBassUpdated(handler models.TypedEventHandler[*models.BassUpdatedEvent])
OnBassUpdated sets a handler for bass update events
func (*WebSocketClient) OnConnectionState ¶
func (ws *WebSocketClient) OnConnectionState(handler models.TypedEventHandler[*models.ConnectionStateUpdatedEvent])
OnConnectionState sets a handler for connection state events
func (*WebSocketClient) OnNowPlaying ¶
func (ws *WebSocketClient) OnNowPlaying(handler models.TypedEventHandler[*models.NowPlayingUpdatedEvent])
OnNowPlaying sets a handler for now playing events
func (*WebSocketClient) OnPresetUpdated ¶
func (ws *WebSocketClient) OnPresetUpdated(handler models.TypedEventHandler[*models.PresetUpdatedEvent])
OnPresetUpdated sets a handler for preset update events
func (*WebSocketClient) OnSpecialMessage ¶ added in v0.5.4
func (ws *WebSocketClient) OnSpecialMessage(handler models.SpecialMessageHandler)
OnSpecialMessage sets a handler for special (non-updates) messages
func (*WebSocketClient) OnUnknownEvent ¶
func (ws *WebSocketClient) OnUnknownEvent(handler models.EventHandler)
OnUnknownEvent sets a handler for unknown events
func (*WebSocketClient) OnVolumeUpdated ¶
func (ws *WebSocketClient) OnVolumeUpdated(handler models.TypedEventHandler[*models.VolumeUpdatedEvent])
OnVolumeUpdated sets a handler for volume update events
func (*WebSocketClient) OnZoneUpdated ¶
func (ws *WebSocketClient) OnZoneUpdated(handler models.TypedEventHandler[*models.ZoneUpdatedEvent])
OnZoneUpdated sets a handler for zone update events
func (*WebSocketClient) PairWithAccount ¶ added in v0.53.0
func (ws *WebSocketClient) PairWithAccount(accountID, userAuthToken string) error
PairWithAccount sends a request to pair the device with a specific account
func (*WebSocketClient) SendMessage ¶
func (ws *WebSocketClient) SendMessage(message []byte) error
SendMessage sends a message to the WebSocket (if needed for future functionality)
func (*WebSocketClient) SetHandlers ¶
func (ws *WebSocketClient) SetHandlers(handlers *models.WebSocketEventHandlers)
SetHandlers sets the event handlers for different WebSocket event types
func (*WebSocketClient) UnPairFromAccount ¶ added in v0.53.0
func (ws *WebSocketClient) UnPairFromAccount() error
UnPairFromAccount sends a request to unpair the device from its account
func (*WebSocketClient) Wait ¶
func (ws *WebSocketClient) Wait()
Wait blocks until the WebSocket connection is closed or context is cancelled
type WebSocketConfig ¶
type WebSocketConfig struct {
// ReconnectInterval defines how long to wait between reconnection attempts
ReconnectInterval time.Duration
// MaxReconnectAttempts defines maximum number of reconnection attempts (0 = unlimited)
MaxReconnectAttempts int
// PingInterval defines how often to send ping messages to keep connection alive
PingInterval time.Duration
// PongTimeout defines how long to wait for pong response
PongTimeout time.Duration
// ReadBufferSize defines the WebSocket read buffer size
ReadBufferSize int
// WriteBufferSize defines the WebSocket write buffer size
WriteBufferSize int
// Logger for WebSocket events (nil = default logger)
Logger Logger
}
WebSocketConfig holds configuration for WebSocket client
func DefaultWebSocketConfig ¶
func DefaultWebSocketConfig() *WebSocketConfig
DefaultWebSocketConfig returns a default WebSocket configuration