musicflow

package module
v0.0.0-...-d92b261 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2021 License: MIT Imports: 12 Imported by: 0

README

musicflow

Speaks the LG Music Flow protocol. This package and its commands can be used to control LG speakers that are controllable via the Music Flow app.

The API is mostly implemented, more can be added as needed.

The actual wire protocol is implemented by github.com/mafredri/goodspeaker.

Usage

As a module.

go get -u github.com/mafredri/musicflow

Tool for controlling the speakers.

go get -u github.com/mafredri/musicflow/cmd/mufloctl
mufloctl -addr soundbar.local -nightmode=false

Run as wasm (node):

env GOOS=js GOARCH=wasm go build github.com/mafredri/musicflow/cmd/mufloctl -o mufloctl.wasm

/usr/local/opt/go/libexec/misc/wasm/go_js_wasm_exec mufloctl.wasm -addr soundbar.local

Documentation

Index

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 Music Flow Player client.

func Dial

func Dial(ctx context.Context, addr string, opts ...DialOption) (*Client, error)

Dial connects to the Music Flow speaker and returns a Client that implements the API.

func NewClient

func NewClient(conn io.ReadWriteCloser) *Client

NewClient returns a new Music Flow Player client that uses the provided connection. Use Dial for more options.

func (*Client) AlarmCreate

func (c *Client) AlarmCreate(ctx context.Context, a api.Alarm) (id int, err error)

AlarmCreate creates a new alarm.

func (*Client) AlarmDelete

func (c *Client) AlarmDelete(ctx context.Context, a api.Alarm) error

AlarmDelete deletes the alarm.

func (*Client) AlarmState

func (c *Client) AlarmState(ctx context.Context) (on bool, err error)

AlarmState returns true if an alarm is active right now.

func (*Client) Alarms

func (c *Client) Alarms(ctx context.Context) ([]api.Alarm, error)

Alarms lists all alarms.

func (*Client) Close

func (c *Client) Close() error

func (*Client) Equalizer

func (c *Client) Equalizer(ctx context.Context, eq ...EqualizerSetting) error

Equalizer sets the provided equalizer settings.

func (*Client) EqualizerInfo

func (c *Client) EqualizerInfo(ctx context.Context) (*api.EqualizerInfo, error)

EqualizerInfo returns information on what's playing.

func (*Client) Function

func (c *Client) Function(ctx context.Context, f api.Function) error

Function activates the provided function.

func (*Client) FunctionInfo

func (c *Client) FunctionInfo(ctx context.Context) (*api.FunctionInfo, error)

FunctionInfo sets the provided equalizer settings.

func (*Client) Mute

func (c *Client) Mute(ctx context.Context, on bool) error

Mute the speaker.

func (*Client) NetworkInfo

func (c *Client) NetworkInfo(ctx context.Context) (*api.NetworkInfo, error)

NetworkInfo returns the network information.

WARNING: Returns WiFi password in plain text.

func (*Client) NightMode

func (c *Client) NightMode(ctx context.Context, on bool) error

NightMode sets the nightmode on or off.

func (*Client) OnBroadcast

func (c *Client) OnBroadcast(fn func(message string, data []byte))

OnBroadcast sets the handler for broadcasted messages.

func (*Client) PlayInfo

func (c *Client) PlayInfo(ctx context.Context) (*api.PlayInfo, error)

PlayInfo returns information on what's playing.

func (*Client) ProductInfo

func (c *Client) ProductInfo(ctx context.Context, now time.Time, setTime bool) (*api.ProductInfo, error)

ProductInfo returns the product info and optionally sets the time on the soundbar.

func (*Client) Send

func (c *Client) Send(ctx context.Context, req Request, reply interface{}, opts ...SendOption) error

Send a request to the Music Flow device.

func (*Client) SetName

func (c *Client) SetName(ctx context.Context, name string) error

SetName sets the speakers name.

func (*Client) Settings

func (c *Client) Settings(ctx context.Context) (*api.Settings, error)

Settings returns the system version information.

func (*Client) SleepAfter

func (c *Client) SleepAfter(ctx context.Context, minutes int) error

SleepAfter sets the sleep timer. Set -1 to disable.

func (*Client) SystemVersion

func (c *Client) SystemVersion(ctx context.Context) (*api.SystemVersion, error)

SystemVersion returns the system version information.

func (*Client) TestTone

func (c *Client) TestTone(ctx context.Context) error

TestTone plays the test tone.

func (*Client) Volume

func (c *Client) Volume(ctx context.Context, volume, fadetime int) error

Volume sets the volume.

func (*Client) WooferLevel

func (c *Client) WooferLevel(ctx context.Context, level int) error

WooferLevel sets the woofer level.

type DialOption

type DialOption func(*dialOptions)

A DialOption sets custom options for Dial.

func WithGoodspeakerOption

func WithGoodspeakerOption(opt ...goodspeaker.Option) DialOption

WithGoodspeakerOption sets the option(s) passed to the goodspeaker package.

func WithLogger

func WithLogger(log Logger) DialOption

type EqualizerSetting

type EqualizerSetting func(context.Context, *Client) error

EqualizerSetting represents an equalizer setting.

func RestoreEqualizerSettings

func RestoreEqualizerSettings() EqualizerSetting

RestoreEqualizerSettings restores the previously saved equalizer settings.

func SaveEqualizerSettings

func SaveEqualizerSettings() EqualizerSetting

SaveEqualizerSettings saves the current equalizer settings as default.

func SetBass

func SetBass(value int) EqualizerSetting

SetBass sets the bass level.

func SetEqualizer

func SetEqualizer(value api.Equalizer) EqualizerSetting

SetEqualizer sets the equalizer.

func SetLeftRightBalance

func SetLeftRightBalance(value int) EqualizerSetting

SetLeftRightBalance sets the left right balance.

func SetTreble

func SetTreble(value int) EqualizerSetting

SetTreble sets treble.

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
}

type Request

type Request struct {
	Data    interface{} `json:"data,omitempty"`
	Message string      `json:"msg"`
}

Request to the speaker.

func (Request) String

func (r Request) String() string

type Response

type Response struct {
	Data    json.RawMessage `json:"data,omitempty"`
	Message string          `json:"msg"`
	Result  string          `json:"result,omitempty"`
}

Response from the speaker.

func (Response) String

func (r Response) String() string

type SendOption

type SendOption func(*sendOptions)

func WaitFor

func WaitFor(message string, result string) SendOption

WaitFor allows Send to wait for a different response message than the request. Result is usually be "OK", or empty for events. If the response result differs from this value, Send will return an error.

Directories

Path Synopsis
Package api contains the types and request/reply/event payloads associated with the JSON protocol used by Music Flow Player apps.
Package api contains the types and request/reply/event payloads associated with the JSON protocol used by Music Flow Player apps.
cmd

Jump to

Keyboard shortcuts

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