webostv

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 16 Imported by: 0

README

webostv : A Go Package

webostv banner

Go Reference

A Go port of PyWebOSTV, a library to remote control LG WebOS TVs.

Features

  • SSDP Discovery of TVs on the network.
  • WebSocket-based connection and registration (pairing).
  • Media Controls (volume, playback, etc.).
  • System Controls (notification, power off, etc.).
  • Application Controls (list apps, launch, close).
  • TV Controls (channel change, program info).
  • Input Controls (mouse movement, button clicks).
  • Subscription support (volume, etc.).

Installation

go get github.com/suapapa/go_webostv

Usage

See example/main.go for a complete example.

Basic Connection
client := webostv.NewClient("192.168.1.10", false)
err := client.Connect()
if err != nil {
    log.Fatal(err)
}

store := make(map[string]string) // Persist this to avoid re-pairing
statusChan, errChan := client.Register(store)
// Handle statusChan and errChan
Media Control
media := &webostv.MediaControl{Control: webostv.Control{Client: client}}
media.VolumeUp()
Input Control (Mouse/Buttons)
input := &webostv.InputControl{Control: webostv.Control{Client: client}}
err := input.ConnectInput()
if err == nil {
    input.Move(10, 10, 0)
    input.Click()
    input.DisconnectInput()
}

Credits

  • This library is a port of PyWebOSTV.
  • Credits to the original author Srivatsan Iyer and contributors.

Documentation

Index

Constants

View Source
const (
	// DefaultHandshakeTimeout is the default timeout for websocket handshake.
	DefaultHandshakeTimeout = 10 * time.Second
	// DefaultWriteWait is the default time to wait for a message to be written.
	DefaultWriteWait = 10 * time.Second
)
View Source
const (
	// SSDPService is the SSDP service type for WebOS TVs.
	SSDPService = "urn:schemas-upnp-org:device:MediaRenderer:1"
)
View Source
const (
	Signature = "eyJhbGdvcml0aG0iOiJSU0EtU0hBMjU2Iiwia2V5SWQiOiJ0ZXN0LXNpZ25pbm" +
		"ctY2VydCIsInNpZ25hdHVyZVZlcnNpb24iOjF9.hrVRgjCwXVvE2OOSpDZ58hR" +
		"+59aFNwYDyjQgKk3auukd7pcegmE2CzPCa0bJ0ZsRAcKkCTJrWo5iDzNhMBWRy" +
		"aMOv5zWSrthlf7G128qvIlpMT0YNY+n/FaOHE73uLrS/g7swl3/qH/BGFG2Hu4" +
		"RlL48eb3lLKqTt2xKHdCs6Cd4RMfJPYnzgvI4BNrFUKsjkcu+WD4OO2A27Pq1n" +
		"50cMchmcaXadJhGrOqH5YmHdOCj5NSHzJYrsW0HPlpuAx/ECMeIZYDh6RMqaFM" +
		"2DXzdKX9NmmyqzJ3o/0lkk/N97gfVRLW5hA29yeAwaCViZNCP8iC9aO0q9fQoj" +
		"oa7NQnAtw=="
)

Variables

View Source
var (
	ErrConnectionClosed = errors.New("connection closed")
	ErrTimeout          = errors.New("timeout")
	ErrInvalidResponse  = errors.New("invalid response from TV")
)
View Source
var RegistrationPayload = map[string]interface{}{
	"forcePairing": false,
	"manifest": map[string]interface{}{
		"appVersion":      "1.1",
		"manifestVersion": 1,
		"permissions": []string{
			"LAUNCH", "LAUNCH_WEBAPP", "APP_TO_APP", "CLOSE", "TEST_OPEN", "TEST_PROTECTED",
			"CONTROL_AUDIO", "CONTROL_DISPLAY", "CONTROL_INPUT_JOYSTICK", "CONTROL_INPUT_MEDIA_RECORDING",
			"CONTROL_INPUT_MEDIA_PLAYBACK", "CONTROL_INPUT_TV", "CONTROL_POWER", "READ_APP_STATUS",
			"READ_CURRENT_CHANNEL", "READ_INPUT_DEVICE_LIST", "READ_NETWORK_STATE", "READ_RUNNING_APPS",
			"READ_TV_CHANNEL_LIST", "WRITE_NOTIFICATION_TOAST", "READ_POWER_STATE", "READ_COUNTRY_INFO",
			"READ_SETTINGS", "CONTROL_TV_SCREEN", "CONTROL_TV_STANBY", "CONTROL_FAVORITE_GROUP",
			"CONTROL_USER_INFO", "CHECK_BLUETOOTH_DEVICE", "CONTROL_BLUETOOTH", "CONTROL_TIMER_INFO",
			"STB_INTERNAL_CONNECTION", "CONTROL_RECORDING", "READ_RECORDING_STATE", "WRITE_RECORDING_LIST",
			"READ_RECORDING_LIST", "READ_RECORDING_SCHEDULE", "WRITE_RECORDING_SCHEDULE", "READ_STORAGE_DEVICE_LIST",
			"READ_TV_PROGRAM_INFO", "CONTROL_BOX_CHANNEL", "READ_TV_ACR_AUTH_TOKEN", "READ_TV_CONTENT_STATE",
			"READ_TV_CURRENT_TIME", "ADD_LAUNCHER_CHANNEL", "SET_CHANNEL_SKIP", "RELEASE_CHANNEL_SKIP",
			"CONTROL_CHANNEL_BLOCK", "DELETE_SELECT_CHANNEL", "CONTROL_CHANNEL_GROUP", "SCAN_TV_CHANNELS",
			"CONTROL_TV_POWER", "CONTROL_WOL",
		},
		"signatures": []map[string]interface{}{
			{
				"signature":        Signature,
				"signatureVersion": 1,
			},
		},
		"signed": map[string]interface{}{
			"appId":   "com.lge.test",
			"created": "20140509",
			"localizedAppNames": map[string]string{
				"":       "LG Remote App",
				"ko-KR":  "리모컨 앱",
				"zxx-XX": "ЛГ Rэмotэ AПП",
			},
			"localizedVendorNames": map[string]string{
				"": "LG Electronics",
			},
			"permissions": []string{
				"TEST_SECURE", "CONTROL_INPUT_TEXT", "CONTROL_MOUSE_AND_KEYBOARD", "READ_INSTALLED_APPS",
				"READ_LGE_SDX", "READ_NOTIFICATIONS", "SEARCH", "WRITE_SETTINGS", "WRITE_SETTINGS",
				"WRITE_NOTIFICATION_ALERT", "CONTROL_POWER", "READ_CURRENT_CHANNEL", "READ_RUNNING_APPS",
				"READ_UPDATE_INFO", "UPDATE_FROM_REMOTE_APP", "READ_LGE_TV_INPUT_EVENTS", "READ_TV_CURRENT_TIME",
			},
			"serial":   "2f930e2d2cfe083771f68e4fe7bb07",
			"vendorId": "com.lge",
		},
	},
	"pairingType": "PROMPT",
}

Functions

This section is empty.

Types

type Application

type Application struct {
	ID    string                 `json:"id"`
	Title string                 `json:"title"`
	Icon  string                 `json:"icon"`
	Data  map[string]interface{} `json:"-"`
}

Application represents a WebOS application.

func (Application) String

func (a Application) String() string

type ApplicationControl

type ApplicationControl struct {
	Control
}

ApplicationControl provides methods to manage applications.

func (*ApplicationControl) Close

func (a *ApplicationControl) Close(ctx context.Context, appID string) error

func (*ApplicationControl) GetForegroundApp added in v0.1.0

func (a *ApplicationControl) GetForegroundApp(ctx context.Context) (string, error)

func (*ApplicationControl) Launch

func (a *ApplicationControl) Launch(
	ctx context.Context,
	appID string,
	contentID string,
	params map[string]interface{},
) error

func (*ApplicationControl) ListApps

func (a *ApplicationControl) ListApps(ctx context.Context) ([]Application, error)

type AudioOutputSource

type AudioOutputSource struct {
	Source string `json:"soundOutput"`
}

AudioOutputSource represents where the audio is played.

func (AudioOutputSource) String

func (a AudioOutputSource) String() string

type ChannelInfo added in v0.1.0

type ChannelInfo struct {
	ChannelID       string `json:"channelId"`
	ChannelName     string `json:"channelName"`
	ChannelNumber   string `json:"channelNumber"`
	ChannelModeName string `json:"channelModeName"`
	SignalChannelID string `json:"signalChannelId"`
	MajorNumber     int    `json:"majorNumber"`
	MinorNumber     int    `json:"minorNumber"`
	PhysicalNumber  int    `json:"physicalNumber"`
	SourceIndex     int    `json:"sourceIndex"`
	ChannelTypeId   int    `json:"channelTypeId"`
	ChannelTypeName string `json:"channelTypeName"`
	BinaryID        int    `json:"binaryId"`
	ProgramID       string `json:"programId"`
	ChannelType     string `json:"channelType"`
	SatelliteName   string `json:"satelliteName"`
	FavoriteGroup   string `json:"favoriteGroup"`
	Skipped         bool   `json:"skipped"`
	Locked          bool   `json:"locked"`
	Scrambled       bool   `json:"scrambled"`
	ServiceID       int    `json:"serviceId"`
	TransportID     int    `json:"transportId"`
	NetworkID       int    `json:"networkId"`
	ChannelMode     string `json:"channelMode"`
	DualChannel     bool   `json:"dualChannel"`
	TunerID         int    `json:"tunerId"`
	ProgramName     string `json:"programName"`
}

ChannelInfo contains information about a TV channel.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a WebOS TV client.

func Discover

func Discover(ctx context.Context, opts ...DiscoverOption) ([]*Client, error)

Discover searches for WebOS TVs on the network.

func NewClient

func NewClient(host string, opts ...Option) *Client

NewClient creates a new WebOS TV client.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection to the TV.

func (*Client) Connect

func (c *Client) Connect() error

Connect establishes a connection to the TV.

func (*Client) Register

func (c *Client) Register(ctx context.Context, store map[string]string) (<-chan RegistrationStatus, <-chan error)

Register performs the registration with the TV.

func (*Client) Request

func (c *Client) Request(ctx context.Context, uri string, payload interface{}) (*Message, error)

Request sends a request and waits for a single response.

func (*Client) SendMessage

func (c *Client) SendMessage(
	ctx context.Context,
	id string,
	requestType string,
	uri string,
	payload interface{},
) (<-chan *Message, string, error)

SendMessage sends a message to the TV. If id is empty, a new UUID is generated. Its protocol fields remain separate to preserve the public API.

func (*Client) Subscribe

func (c *Client) Subscribe(uri string, callback func(json.RawMessage)) (string, error)

Subscribe subscribes to a URI.

func (*Client) URL

func (c *Client) URL() string

URL returns the URL the client is connected to.

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(id string) error

Unsubscribe removes a subscription.

type Control

type Control struct {
	Client *Client
}

Control is the base struct for all controls.

type DiscoverOption added in v0.1.0

type DiscoverOption func(*DiscoverOptions)

DiscoverOption is a functional option for Discover.

func WithDiscoverySecure added in v0.1.0

func WithDiscoverySecure(secure bool) DiscoverOption

WithDiscoverySecure sets whether discovered clients should use a secure connection.

func WithSearchWait added in v0.1.0

func WithSearchWait(wait int) DiscoverOption

WithSearchWait sets how long to wait for SSDP responses in seconds.

type DiscoverOptions added in v0.1.0

type DiscoverOptions struct {
	Secure            bool
	SearchWait        int
	ValidationTimeout time.Duration
}

DiscoverOptions contains options for TV discovery.

type InputControl

type InputControl struct {
	Control
	// contains filtered or unexported fields
}

InputControl provides methods for mouse and keyboard input.

func (*InputControl) Back

func (i *InputControl) Back() error

func (*InputControl) Blue

func (i *InputControl) Blue() error

func (*InputControl) Button

func (i *InputControl) Button(name string) error

func (*InputControl) ChannelDown

func (i *InputControl) ChannelDown() error

func (*InputControl) ChannelUp

func (i *InputControl) ChannelUp() error

func (*InputControl) Click

func (i *InputControl) Click() error

func (*InputControl) ConnectInput

func (i *InputControl) ConnectInput(ctx context.Context) error

func (*InputControl) Dash

func (i *InputControl) Dash() error

func (*InputControl) Delete

func (i *InputControl) Delete(ctx context.Context, count int) error

func (*InputControl) DisconnectInput

func (i *InputControl) DisconnectInput() error

func (*InputControl) Down

func (i *InputControl) Down() error

func (*InputControl) Enter

func (i *InputControl) Enter(ctx context.Context) error

func (*InputControl) Exit

func (i *InputControl) Exit() error

func (*InputControl) FastForward

func (i *InputControl) FastForward() error

func (*InputControl) Green

func (i *InputControl) Green() error

func (*InputControl) Home

func (i *InputControl) Home() error

func (*InputControl) Info

func (i *InputControl) Info() error

func (*InputControl) Left

func (i *InputControl) Left() error

func (*InputControl) Menu

func (i *InputControl) Menu() error

func (*InputControl) Move

func (i *InputControl) Move(dx, dy int, drag int) error

func (*InputControl) Mute

func (i *InputControl) Mute() error

func (*InputControl) OK

func (i *InputControl) OK() error

func (*InputControl) Pause

func (i *InputControl) Pause() error

func (*InputControl) Play

func (i *InputControl) Play() error

func (*InputControl) Red

func (i *InputControl) Red() error

func (*InputControl) Rewind

func (i *InputControl) Rewind() error

func (*InputControl) Right

func (i *InputControl) Right() error

func (*InputControl) Scroll

func (i *InputControl) Scroll(dx, dy int) error

func (*InputControl) Stop

func (i *InputControl) Stop() error

func (*InputControl) Type

func (i *InputControl) Type(ctx context.Context, text string) error

func (*InputControl) Up

func (i *InputControl) Up() error

func (*InputControl) VolumeDown

func (i *InputControl) VolumeDown() error

func (*InputControl) VolumeUp

func (i *InputControl) VolumeUp() error

func (*InputControl) Yellow

func (i *InputControl) Yellow() error

type InputSource

type InputSource struct {
	ID    string                 `json:"id"`
	Label string                 `json:"label"`
	Data  map[string]interface{} `json:"-"`
}

InputSource represents a TV input source (e.g., HDMI1).

func (InputSource) String

func (i InputSource) String() string

type MediaControl

type MediaControl struct {
	Control
}

MediaControl provides methods to control media and volume.

func (*MediaControl) FastForward

func (m *MediaControl) FastForward(ctx context.Context) error

func (*MediaControl) GetAudioOutput

func (m *MediaControl) GetAudioOutput(ctx context.Context) (*AudioOutputSource, error)

func (*MediaControl) GetVolume

func (m *MediaControl) GetVolume(ctx context.Context) (*VolumeInfo, error)

func (*MediaControl) Mute

func (m *MediaControl) Mute(ctx context.Context, mute bool) error

func (*MediaControl) Pause

func (m *MediaControl) Pause(ctx context.Context) error

func (*MediaControl) Play

func (m *MediaControl) Play(ctx context.Context) error

func (*MediaControl) Rewind

func (m *MediaControl) Rewind(ctx context.Context) error

func (*MediaControl) SetAudioOutput

func (m *MediaControl) SetAudioOutput(ctx context.Context, output string) error

func (*MediaControl) SetVolume

func (m *MediaControl) SetVolume(ctx context.Context, volume int) error

func (*MediaControl) Stop

func (m *MediaControl) Stop(ctx context.Context) error

func (*MediaControl) SubscribeVolume

func (m *MediaControl) SubscribeVolume(callback func(*VolumeInfo)) (string, error)

func (*MediaControl) VolumeDown

func (m *MediaControl) VolumeDown(ctx context.Context) error

func (*MediaControl) VolumeUp

func (m *MediaControl) VolumeUp(ctx context.Context) error

type Message

type Message struct {
	Type    string          `json:"type"`
	ID      string          `json:"id"`
	URI     string          `json:"uri,omitempty"`
	Payload json.RawMessage `json:"payload,omitempty"`
}

Message is the basic unit of communication with WebOS TV.

type Option added in v0.1.0

type Option func(*clientOptions)

Option is a functional option for Client.

func WithHandshakeTimeout added in v0.1.0

func WithHandshakeTimeout(d time.Duration) Option

WithHandshakeTimeout sets the timeout for the websocket handshake.

func WithSecure added in v0.1.0

func WithSecure(secure bool) Option

WithSecure sets whether to use a secure (WSS) connection.

type RegistrationStatus

type RegistrationStatus int

RegistrationStatus represents the status during the registration process.

const (
	Prompted RegistrationStatus = iota + 1
	Registered
)

type SWInformation added in v0.1.0

type SWInformation struct {
	ProductBaseVersion string `json:"product_base_version"`
	ModelName          string `json:"model_name"`
	SDKVersion         string `json:"sdk_version"`
	FirmwareVersion    string `json:"firmware_version"`
	BoardType          string `json:"board_type"`
	OTAID              string `json:"ota_id"`
}

SWInformation contains software information.

type SourceControl

type SourceControl struct {
	Control
}

SourceControl provides methods to manage input sources.

func (*SourceControl) ListSources

func (s *SourceControl) ListSources(ctx context.Context) ([]InputSource, error)

func (*SourceControl) SetSource

func (s *SourceControl) SetSource(ctx context.Context, sourceID string) error

type SystemControl

type SystemControl struct {
	Control
}

SystemControl provides methods for system-level operations.

func (*SystemControl) Info

func (s *SystemControl) Info(ctx context.Context) (*SWInformation, error)

func (*SystemControl) Notify

func (s *SystemControl) Notify(ctx context.Context, message string, iconBytes []byte, iconExt string) error

func (*SystemControl) PowerOff

func (s *SystemControl) PowerOff(ctx context.Context) error

func (*SystemControl) ScreenOff

func (s *SystemControl) ScreenOff(ctx context.Context) error

func (*SystemControl) ScreenOn

func (s *SystemControl) ScreenOn(ctx context.Context) error

type TvControl

type TvControl struct {
	Control
}

TvControl provides methods for TV channel management.

func (*TvControl) ChannelDown

func (t *TvControl) ChannelDown(ctx context.Context) error

func (*TvControl) ChannelList

func (t *TvControl) ChannelList(ctx context.Context) ([]ChannelInfo, error)

func (*TvControl) ChannelUp

func (t *TvControl) ChannelUp(ctx context.Context) error

func (*TvControl) GetCurrentChannel

func (t *TvControl) GetCurrentChannel(ctx context.Context) (*ChannelInfo, error)

func (*TvControl) SetChannel added in v0.1.0

func (t *TvControl) SetChannel(ctx context.Context, channelID string) error

type VolumeInfo added in v0.1.0

type VolumeInfo struct {
	Volume       int    `json:"volume"`
	Mute         bool   `json:"mute"`
	Scenario     string `json:"scenario"`
	SubScenario  string `json:"subScenario"`
	SoundOutput  string `json:"soundOutput"`
	Action       string `json:"action"` // used in subscriptions
	ChangeReason string `json:"changeReason"`
}

VolumeInfo contains volume related information.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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