client

package
v0.62.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 14 Imported by: 0

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
}
Example (NavigationWorkflow)

Example_navigationWorkflow demonstrates a complete workflow

config := &Config{Host: "192.168.1.100", Port: 8090}
client := NewClient(config)

// 1. Search for content
fmt.Println("Searching for Taylor Swift...")

searchResults, err := client.SearchPandoraStations("user123", "Taylor Swift")
if err != nil {
	log.Fatal(err)
}

fmt.Printf("Found %d total results\n", searchResults.GetResultCount())

// 2. Show different types of results
songs := searchResults.GetSongs()
artists := searchResults.GetArtists()
stations := searchResults.GetStations()

fmt.Printf("Songs: %d, Artists: %d, Stations: %d\n",
	len(songs), len(artists), len(stations))

// 3. Find an artist to create a station from
if len(artists) > 0 {
	artist := artists[0]
	fmt.Printf("Creating station from artist: %s (Token: %s)\n",
		artist.Name, artist.Token)

	// Note: In a real scenario, you'd call AddStation here
	// This would immediately start playing the new station
	fmt.Printf("Would add station: %s Radio\n", artist.Name)
}

// 4. Browse existing Pandora stations
fmt.Println("\nBrowsing existing Pandora stations...")

pandoraStations, err := client.GetPandoraStations("user123")
if err != nil {
	fmt.Printf("Could not get Pandora stations: %v\n", err)
	return
}

fmt.Printf("Found %d existing stations\n", len(pandoraStations.Items))

// 5. Show how to remove a station (if any exist)
if len(pandoraStations.Items) > 0 {
	station := pandoraStations.Items[0]
	if station.ContentItem != nil {
		fmt.Printf("Could remove station: %s\n", station.GetDisplayName())
		// err := client.RemoveStation(station.ContentItem)
	}
}
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

Examples

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 NewClient

func NewClient(config *Config) *Client

NewClient creates a new SoundTouch API client

func NewClientFromHost

func NewClientFromHost(host string) *Client

NewClientFromHost creates a new client with just a host address

func (*Client) AddAmazonMusicAccount added in v0.9.0

func (c *Client) AddAmazonMusicAccount(user, password string) error

AddAmazonMusicAccount adds an Amazon Music account

func (*Client) AddDeezerAccount added in v0.9.0

func (c *Client) AddDeezerAccount(user, password string) error

AddDeezerAccount adds a Deezer Premium account

func (*Client) AddIHeartRadioAccount added in v0.9.0

func (c *Client) AddIHeartRadioAccount(user, password string) error

AddIHeartRadioAccount adds an iHeartRadio account

func (*Client) AddPandoraAccount added in v0.9.0

func (c *Client) AddPandoraAccount(user, password string) error

AddPandoraAccount adds a Pandora account

func (*Client) AddSpotifyAccount added in v0.9.0

func (c *Client) AddSpotifyAccount(user, password string) error

AddSpotifyAccount adds a Spotify Premium account

func (*Client) AddStation added in v0.7.0

func (c *Client) AddStation(source, sourceAccount, token, name string) error

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

func (c *Client) AddStoredMusicAccount(user, displayName string) error

AddStoredMusicAccount adds a STORED_MUSIC (NAS/UPnP) account

func (*Client) AddToZone

func (c *Client) AddToZone(deviceID, ipAddress string) error

AddToZone adds a device to an existing zone

func (*Client) AddZoneSlave added in v0.6.0

func (c *Client) AddZoneSlave(masterDeviceID, slaveDeviceID, slaveIP string) error

AddZoneSlave adds a single device to an existing zone using the official /addZoneSlave endpoint

func (*Client) AddZoneSlaveByDeviceID added in v0.6.0

func (c *Client) AddZoneSlaveByDeviceID(masterDeviceID, slaveDeviceID string) error

AddZoneSlaveByDeviceID adds a single device to an existing zone by device ID only

func (*Client) BaseURL

func (c *Client) BaseURL() string

BaseURL returns the base URL for this client

func (*Client) CreateZone

func (c *Client) CreateZone(masterDeviceID string, memberDeviceIDs []string) error

CreateZone creates a new multiroom zone with the specified master and members

func (*Client) CreateZoneWithIPs

func (c *Client) CreateZoneWithIPs(masterDeviceID string, members map[string]string) error

CreateZoneWithIPs creates a new multiroom zone with device IDs and IP addresses

func (*Client) DecreaseBalance

func (c *Client) DecreaseBalance(amount int) (*models.Balance, error)

DecreaseBalance decreases balance by the specified amount (with safety limits)

func (*Client) DecreaseBass

func (c *Client) DecreaseBass(amount int) (*models.Bass, error)

DecreaseBass decreases bass by the specified amount (with safety limits)

func (*Client) DecreaseVolume

func (c *Client) DecreaseVolume(amount int) (*models.Volume, error)

DecreaseVolume decreases volume by the specified amount (with safety limits)

func (*Client) DisableClockDisplay

func (c *Client) DisableClockDisplay() error

DisableClockDisplay disables the clock display

func (*Client) DissolveZone

func (c *Client) DissolveZone() error

DissolveZone dissolves the current zone, making all devices standalone

func (*Client) EnableClockDisplay

func (c *Client) EnableClockDisplay() error

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

func (c *Client) GetBalance() (*models.Balance, error)

GetBalance retrieves the current balance level from the /balance endpoint

func (*Client) GetBass

func (c *Client) GetBass() (*models.Bass, error)

GetBass retrieves the current bass level from the /bass 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)
}

func (*Client) GetClockDisplay

func (c *Client) GetClockDisplay() (*models.ClockDisplay, error)

GetClockDisplay retrieves clock display settings from the /clockDisplay endpoint

func (*Client) GetClockTime

func (c *Client) GetClockTime() (*models.ClockTime, error)

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) GetName

func (c *Client) GetName() (*models.Name, error)

GetName retrieves the device name from the /name endpoint

func (*Client) GetNetworkInfo

func (c *Client) GetNetworkInfo() (*models.NetworkInformation, error)

GetNetworkInfo retrieves network information from the /networkInfo endpoint

func (*Client) GetNextAvailablePresetSlot

func (c *Client) GetNextAvailablePresetSlot() (int, error)

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
}

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

func (c *Client) GetPresets() (*models.Presets, error)

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)
}

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

func (c *Client) GetSources() (*models.Sources, error)

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
}

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) GetVolume

func (c *Client) GetVolume() (*models.Volume, error)

GetVolume retrieves the current volume level from the /volume endpoint

func (*Client) GetZone

func (c *Client) GetZone() (*models.ZoneInfo, error)

GetZone gets the current multiroom zone configuration

func (*Client) GetZoneMembers

func (c *Client) GetZoneMembers() ([]string, error)

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) Host

func (c *Client) Host() string

Host returns the host for this client

func (*Client) IncreaseBalance

func (c *Client) IncreaseBalance(amount int) (*models.Balance, error)

IncreaseBalance increases balance by the specified amount (with safety limits)

func (*Client) IncreaseBass

func (c *Client) IncreaseBass(amount int) (*models.Bass, error)

IncreaseBass increases bass by the specified amount (with safety limits)

func (*Client) IncreaseVolume

func (c *Client) IncreaseVolume(amount int) (*models.Volume, error)

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

func (c *Client) IsCurrentContentPresetable() (bool, error)

IsCurrentContentPresetable checks if the currently playing content can be saved as a preset

func (*Client) IsInZone

func (c *Client) IsInZone() (bool, error)

IsInZone checks if this device is part of a multiroom zone

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)

Example

ExampleClient_Navigate demonstrates basic navigation of content sources

config := &Config{Host: "192.168.1.100", Port: 8090}
client := NewClient(config)

// Navigate TuneIn content
response, err := client.Navigate("TUNEIN", "", 1, 10)
if err != nil {
	log.Fatal(err)
}

fmt.Printf("Found %d items in TuneIn\n", response.TotalItems)

for _, item := range response.Items {
	fmt.Printf("- %s (%s)\n", item.GetDisplayName(), item.Type)
}

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

Example

ExampleClient_NavigateContainer demonstrates browsing into directories

config := &Config{Host: "192.168.1.100", Port: 8090}
client := NewClient(config)

// First, get the stored music library root
musicLibrary, err := client.GetStoredMusicLibrary("device123/0")
if err != nil {
	log.Fatal(err)
}

fmt.Printf("Music library has %d items\n", musicLibrary.TotalItems)

// Find a directory to browse into
directories := musicLibrary.GetDirectories()
if len(directories) == 0 {
	fmt.Println("No directories found")
	return
}

// Browse into the first directory
directory := directories[0]
fmt.Printf("Browsing into: %s\n", directory.GetDisplayName())

contents, err := client.NavigateContainer(
	"STORED_MUSIC",
	"device123/0",
	1, 100,
	directory.ContentItem,
)
if err != nil {
	log.Fatal(err)
}

// Show what's in the directory
tracks := contents.GetTracks()
subdirs := contents.GetDirectories()

fmt.Printf("Found %d tracks and %d subdirectories\n",
	len(tracks), len(subdirs))

// Show first few tracks
for i, track := range tracks[:minInt(3, len(tracks))] {
	fmt.Printf("%d. %s", i+1, track.GetDisplayName())

	if track.ArtistName != "" {
		fmt.Printf(" - %s", track.ArtistName)
	}

	fmt.Println()
}

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
}

func (*Client) NextTrack

func (c *Client) NextTrack() error

NextTrack sends a NEXT_TRACK key command

func (*Client) NotifySourcesUpdated added in v0.57.0

func (c *Client) NotifySourcesUpdated(deviceID string) error

NotifySourcesUpdated notifies the device that sources have been updated in Marge

func (*Client) Pause

func (c *Client) Pause() error

Pause sends a PAUSE key command

func (*Client) Ping

func (c *Client) Ping() error

Ping checks if the device is reachable by calling /info

func (*Client) Play

func (c *Client) Play() error

Play sends a PLAY key command

func (*Client) PlayCustom added in v0.8.0

func (c *Client) PlayCustom(playInfo *models.PlayInfo) error

PlayCustom plays custom content using a PlayInfo configuration

func (*Client) PlayNotification added in v0.12.0

func (c *Client) PlayNotification(path string) error

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

func (c *Client) PlayNotificationBeep() error

PlayNotificationBeep plays a notification beep on the device

func (*Client) PlayTTS added in v0.8.0

func (c *Client) PlayTTS(text, appKey, language string, volume ...int) error

PlayTTS plays a Text-To-Speech message using Google TTS on the speaker

func (*Client) PlayURL added in v0.8.0

func (c *Client) PlayURL(url, appKey, service, message, reason string, volume ...int) error

PlayURL plays audio content from a URL on the speaker

func (*Client) PrevTrack

func (c *Client) PrevTrack() error

PrevTrack sends a PREV_TRACK key command

func (*Client) RemoveAmazonMusicAccount added in v0.9.0

func (c *Client) RemoveAmazonMusicAccount(user string) error

RemoveAmazonMusicAccount removes an Amazon Music account

func (*Client) RemoveDeezerAccount added in v0.9.0

func (c *Client) RemoveDeezerAccount(user string) error

RemoveDeezerAccount removes a Deezer account

func (*Client) RemoveFromZone

func (c *Client) RemoveFromZone(deviceID string) error

RemoveFromZone removes a device from the current zone

func (*Client) RemoveIHeartRadioAccount added in v0.9.0

func (c *Client) RemoveIHeartRadioAccount(user string) error

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

func (c *Client) RemovePandoraAccount(user string) error

RemovePandoraAccount removes a Pandora account

func (*Client) RemovePreset added in v0.7.0

func (c *Client) RemovePreset(id int) error

RemovePreset deletes a preset from the SoundTouch device

func (*Client) RemoveSpotifyAccount added in v0.9.0

func (c *Client) RemoveSpotifyAccount(user string) error

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

func (c *Client) RemoveStoredMusicAccount(user, displayName string) error

RemoveStoredMusicAccount removes a STORED_MUSIC account

func (*Client) RemoveZoneSlave added in v0.6.0

func (c *Client) RemoveZoneSlave(masterDeviceID, slaveDeviceID, slaveIP string) error

RemoveZoneSlave removes a single device from an existing zone using the official /removeZoneSlave endpoint

func (*Client) RemoveZoneSlaveByDeviceID added in v0.6.0

func (c *Client) RemoveZoneSlaveByDeviceID(masterDeviceID, slaveDeviceID string) error

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) SelectAux

func (c *Client) SelectAux() error

SelectAux is a convenience method to select AUX input

func (*Client) SelectBluetooth

func (c *Client) SelectBluetooth() error

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

func (c *Client) SelectLocalMusic(location, sourceAccount, itemName, containerArt string) error

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

func (c *Client) SelectPandora(sourceAccount string) error

SelectPandora is a convenience method to select Pandora source

func (*Client) SelectPreset

func (c *Client) SelectPreset(presetNumber int) error

SelectPreset sends a preset key command (1-6)

func (*Client) SelectSource

func (c *Client) SelectSource(source, sourceAccount string) error

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
}

func (*Client) SelectSourceFromItem

func (c *Client) SelectSourceFromItem(sourceItem *models.SourceItem) error

SelectSourceFromItem selects an audio source using a SourceItem

func (*Client) SelectSpotify

func (c *Client) SelectSpotify(sourceAccount string) error

SelectSpotify is a convenience method to select Spotify source

func (*Client) SelectStoredMusic added in v0.9.0

func (c *Client) SelectStoredMusic(location, sourceAccount, itemName, containerArt string) error

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

func (c *Client) SelectTuneIn(sourceAccount string) error

SelectTuneIn is a convenience method to select TuneIn source

func (*Client) SendKey

func (c *Client) SendKey(keyValue string) error

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
}

func (*Client) SendKeyPress

func (c *Client) SendKeyPress(keyValue string) error

SendKeyPress sends a key press command (alias for SendKey - sends press+release)

func (*Client) SendKeyPressOnly

func (c *Client) SendKeyPressOnly(keyValue string) error

SendKeyPressOnly sends only the key press state (without release)

func (*Client) SendKeyRelease

func (c *Client) SendKeyRelease(keyValue string) error

SendKeyRelease sends a key release command

func (*Client) SendKeyReleaseOnly

func (c *Client) SendKeyReleaseOnly(keyValue string) error

SendKeyReleaseOnly sends only the key release state (alias for SendKeyRelease)

func (*Client) SetAdvancedBass added in v0.6.0

func (c *Client) SetAdvancedBass(level int) error

SetAdvancedBass sets only the advanced bass control

func (*Client) SetAdvancedTreble added in v0.6.0

func (c *Client) SetAdvancedTreble(level int) error

SetAdvancedTreble sets only the advanced treble control

func (*Client) SetAudioDSPControls added in v0.6.0

func (c *Client) SetAudioDSPControls(audioMode string, videoSyncDelay int) error

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

func (c *Client) SetAudioMode(mode string) error

SetAudioMode sets only the audio mode (leaving video sync delay unchanged)

func (*Client) SetAudioProductLevelControls added in v0.6.0

func (c *Client) SetAudioProductLevelControls(frontCenter, rearSurround *int) error

SetAudioProductLevelControls sets the speaker level controls

func (*Client) SetAudioProductToneControls added in v0.6.0

func (c *Client) SetAudioProductToneControls(bass, treble *int) error

SetAudioProductToneControls sets the advanced tone controls (bass and/or treble)

func (*Client) SetBalance

func (c *Client) SetBalance(level int) error

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
}

func (*Client) SetBalanceSafe

func (c *Client) SetBalanceSafe(level int) error

SetBalanceSafe sets balance with validation and clamping

func (*Client) SetBass

func (c *Client) SetBass(level int) error

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
}

func (*Client) SetBassSafe

func (c *Client) SetBassSafe(level int) error

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

func (c *Client) SetClockDisplayBrightness(brightness int) error

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

func (c *Client) SetClockTimeNow() error

SetClockTimeNow sets the device's time to the current system time

func (*Client) SetFrontCenterSpeakerLevel added in v0.6.0

func (c *Client) SetFrontCenterSpeakerLevel(level int) error

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) SetName

func (c *Client) SetName(name string) error

SetName sets the device name

func (*Client) SetRearSurroundSpeakersLevel added in v0.6.0

func (c *Client) SetRearSurroundSpeakersLevel(level int) error

SetRearSurroundSpeakersLevel sets only the rear-surround speakers level

func (*Client) SetVideoSyncAudioDelay added in v0.6.0

func (c *Client) SetVideoSyncAudioDelay(delay int) error

SetVideoSyncAudioDelay sets only the video sync audio delay (leaving audio mode unchanged)

func (*Client) SetVolume

func (c *Client) SetVolume(level int) error

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
}

func (*Client) SetVolumeSafe

func (c *Client) SetVolumeSafe(level int) error

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
}

func (*Client) Stop

func (c *Client) Stop() error

Stop sends a STOP key command

func (*Client) StoreCurrentAsPreset added in v0.7.0

func (c *Client) StoreCurrentAsPreset(id int) error

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

func (c *Client) VolumeDown() error

VolumeDown sends a VOLUME_DOWN key command

func (*Client) VolumeUp

func (c *Client) VolumeUp() error

VolumeUp sends a VOLUME_UP key command

type Config

type Config struct {
	Host      string
	Port      int
	Timeout   time.Duration
	UserAgent string
}

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

OnConnectionState sets a handler for connection state events

func (*WebSocketClient) OnNowPlaying

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL