webos

package module
v0.0.0-...-44d3445 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2019 License: MIT Imports: 10 Imported by: 2

README ¶

Go WebOS 📺

A small Go library for interaction with webOS enabled TVs. Tested on LG webOS TV UH668V (webOS version 05.30.20).

Go Report Card

dialer := websocket.Dialer{
    HandshakeTimeout: 10 * time.Second,
    // the TV uses a self-signed certificate
    TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
    NetDial: (&net.Dialer{Timeout: time.Second * 5}).Dial,
}

tv, err := webos.NewTV(&dialer, "<tv-ipv4-address>")
if err != nil {
    log.Fatalf("could not dial TV: %v", err)
}
defer tv.Close()

// the MessageHandler must be started to read responses from the TV
go tv.MessageHandler()

// AuthorisePrompt shows the authorisation prompt on the TV screen
key, err := tv.AuthorisePrompt()
if err != nil {
    log.Fatalf("could not authorise using prompt: %v", err)
}

// the key returned can be used for future request to the TV using the 
// AuthoriseClientKey(<key>) method, instead of AuthorisePrompt()
fmt.Println("Client Key:", key)

// see commands.go for available methods
tv.Notification("📺👌")

See examples for usage.

🌟 Inspired by lgtv.js, go-lgtv and webostv.

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

View Source
var (
	// Protocol is the protocol used to connect to the TV.
	Protocol = "wss"

	// Port is the port used to connect to the TV.
	Port = 3001
)

Functions ¶

This section is empty.

Types ¶

type App ¶

type App struct {
	ReturnValue bool
	AppID       string
	WindowID    string
	ProcessID   string
	Running     bool
	Visible     bool
}

App represents an applications in the TVs responses.

type Command ¶

type Command string

Command is the type used by tv.Command to interact with the TV.

const (
	// APIServiceListCommand lists the API services available on the TV.
	APIServiceListCommand Command = "ssap://api/getServiceList"

	// ApplicationManagerForegroundAppCommand returns information about the forgeground app.
	ApplicationManagerForegroundAppCommand Command = "ssap://com.webos.applicationManager/getForegroundAppInfo"

	// AudioGetVolumeCommand returns information about the TV's configured audio output volume.
	AudioGetVolumeCommand Command = "ssap://audio/getVolume"

	// AudioSetVolumeCommand sets the TV's configured audio output volume.
	AudioSetVolumeCommand Command = "ssap://audio/setVolume"

	// AudioVolumeDownCommand decrements the TV's configured audio output volume.
	AudioVolumeDownCommand Command = "ssap://audio/volumeDown"

	// AudioVolumeStatusCommand returns information about the TV's configured audio output volume.
	// Same as AudioGetVolumeCommand.
	AudioVolumeStatusCommand Command = "ssap://audio/getVolume"

	// AudioVolumeUpCommand increments the TV's configured audio output volume.
	AudioVolumeUpCommand Command = "ssap://audio/volumeUp"

	// AudioVolumeSetMuteCommand sets/toggles muting the TV's configured audio output.
	AudioVolumeSetMuteCommand Command = "ssap://audio/setMute"

	// MediaControlFastForwardCommand fast forwards the current media.
	MediaControlFastForwardCommand Command = "ssap://media.controls/fastForward"

	// MediaControlPauseCommand pauses the current media.
	MediaControlPauseCommand Command = "ssap://media.controls/pause"

	// MediaControlPlayCommand plays or resumes the current media.
	MediaControlPlayCommand Command = "ssap://media.controls/play"

	// MediaControlRewindCommand rewinds the current media.
	MediaControlRewindCommand Command = "ssap://media.controls/rewind"

	// MediaControlStopCommand stops the current media.
	MediaControlStopCommand Command = "ssap://media.controls/stop"

	// SystemLauncherCloseCommand closes a given application.
	SystemLauncherCloseCommand Command = "ssap://system.launcher/close"

	// SystemLauncherGetAppStateCommand returns information about the given application state.
	SystemLauncherGetAppStateCommand Command = "ssap://system.launcher/getAppState"

	// SystemLauncherLaunchCommand launches the given application.
	SystemLauncherLaunchCommand Command = "ssap://system.launcher/launch"

	// SystemLauncherOpenCommand opens a previously launched application.
	SystemLauncherOpenCommand Command = "ssap://system.launcher/open"

	// SystemNotificationsCreateToastCommand creates a "toast" notification.
	SystemNotificationsCreateToastCommand Command = "ssap://system.notifications/createToast"

	// SystemTurnOffCommand turns the TV off.
	SystemTurnOffCommand Command = "ssap://system/turnOff"

	// TVChannelDownCommand changes the channel down.
	TVChannelDownCommand Command = "ssap://tv/channelDown"

	// TVChannelListCommand returns information about the available channels.
	TVChannelListCommand Command = "ssap://tv/getChannelList"

	// TVChannelUpCommand changes the channel up.
	TVChannelUpCommand Command = "ssap://tv/channelUp"

	// TVCurrentChannelCommand returns information about the current channel.
	TVCurrentChannelCommand Command = "ssap://tv/getCurrentChannel"

	// TVCurrentChannelProgramCommand returns information about the current program playing on
	// the current channel.
	TVCurrentChannelProgramCommand Command = "ssap://tv/getChannelProgramInfo"

	GetPointerInputSocketCommand Command = "ssap://com.webos.service.networkinput/getPointerInputSocket"

	KeyEnterCommand Command = "ssap://com.webos.service.ime/sendEnterKey"
)

type Input ¶

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

func NewInput ¶

func NewInput(uri string) (*Input, error)

NewInput dials the socket and returns a pointer to a new Input.

func (*Input) Close ¶

func (input *Input) Close() error

Close closes the websocket connection.

func (*Input) SendButton ¶

func (input *Input) SendButton(name string) error

SendButton

type Message ¶

type Message struct {
	Type    MessageType `json:"type,omitempty"`
	ID      string      `json:"id,omitempty"`
	URI     Command     `json:"uri,omitempty"`
	Payload Payload     `json:"payload,omitempty"`
	Error   string      `json:"error,omitempty"`
}

Message represents the JSON message format used in request and responses to and from the TV.

func (Message) Validate ¶

func (m Message) Validate() error

Validate validates the Message.

Only used for response (type: response || registered) types.

type MessageType ¶

type MessageType string

MessageType is the type sent to and returned by the TV in the `type` field.

const (
	// ErrorMessageType is returned by the TV when an error has occurred.
	ErrorMessageType MessageType = "error"

	// RegisterMessageType is sent to the TV in a registration request.
	RegisterMessageType MessageType = "register"

	// RegisteredMessageType is returned by the TV in response to a registration request.
	RegisteredMessageType MessageType = "registered"

	// RequestMessageType is sent to the TV when issuing Commands.
	RequestMessageType MessageType = "request"

	// ResponseMessageType is returned by the TV in response to a request.
	ResponseMessageType MessageType = "response"
)

type Payload ¶

type Payload map[string]interface{}

Payload represents the Payload contained in the Message body.

func (Payload) Validate ¶

func (p Payload) Validate() error

Validate valides the Payload.

type Service ¶

type Service struct {
	Name    string
	Version float32
}

Service represents services in the TVs responses.

type ServiceList ¶

type ServiceList struct {
	Services []Service
}

ServiceList represents an array of Service types in the TVs responses.

type TV ¶

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

TV represents the TV. It contains the websocket connection, necessary channels used for communication and methods used for interaction with the TV.

func NewTV ¶

func NewTV(dialer *websocket.Dialer, ip string) (*TV, error)

NewTV dials the socket and returns a pointer to a new TV.

func (*TV) AppStatus ¶

func (tv *TV) AppStatus(app string) (*App, error)

AppStatus returns information about the given app status.

func (*TV) AuthoriseClientKey ¶

func (tv *TV) AuthoriseClientKey(key string) error

AuthoriseClientKey autorises with the TV using an existing client key.

func (*TV) AuthorisePrompt ¶

func (tv *TV) AuthorisePrompt() (string, error)

AuthorisePrompt autorises with the TV using the PROMPT method.

func (*TV) ChannelDown ¶

func (tv *TV) ChannelDown() error

ChannelDown decrements the current channel.

func (*TV) ChannelList ¶

func (tv *TV) ChannelList() (Message, error)

ChannelList returns information about available channels.

@todo implement a ChannelList type. This doesn't work on my TV.

func (*TV) ChannelUp ¶

func (tv *TV) ChannelUp() error

ChannelUp increments the current channel.

func (*TV) Close ¶

func (tv *TV) Close() error

Close closes the websocket connection to the TV.

func (*TV) CloseApp ¶

func (tv *TV) CloseApp(app string) error

CloseApp closes the given app.

func (*TV) Command ¶

func (tv *TV) Command(uri Command, req Payload) (Message, error)

Command executes a Command on the TV.

func (*TV) CurrentApp ¶

func (tv *TV) CurrentApp() (*App, error)

CurrentApp returns information about the current app.

func (*TV) CurrentChannel ¶

func (tv *TV) CurrentChannel() (Message, error)

CurrentChannel returns information about the current channel.

@todo implement a Channel type. This doesn't work on my TV.

func (*TV) CurrentProgram ¶

func (tv *TV) CurrentProgram() (Message, error)

CurrentProgram returns information about the current program shown on the CurrentChannel.

@todo implement a Program type. This doesn't work on my TV.

func (*TV) FastForward ¶

func (tv *TV) FastForward() error

FastForward fast forwards the current media.

func (*TV) GetVolume ¶

func (tv *TV) GetVolume() (*Volume, error)

GetVolume returns information about the audio output volume.

func (*TV) KeyBack ¶

func (tv *TV) KeyBack() error

func (*TV) KeyDown ¶

func (tv *TV) KeyDown() error

func (*TV) KeyHome ¶

func (tv *TV) KeyHome() error

func (*TV) KeyLeft ¶

func (tv *TV) KeyLeft() error

func (*TV) KeyOk ¶

func (tv *TV) KeyOk() (Message, error)

func (*TV) KeyRight ¶

func (tv *TV) KeyRight() error

func (*TV) KeyUp ¶

func (tv *TV) KeyUp() error

func (*TV) LaunchApp ¶

func (tv *TV) LaunchApp(app string) error

LaunchApp launches an app.

func (*TV) MessageHandler ¶

func (tv *TV) MessageHandler() (err error)

MessageHandler listens to the TVs websocket and reads responses. Responses are read into a Message type and added to appropriate channel based on the Message.ID.

func (*TV) Mute ¶

func (tv *TV) Mute() error

Mute mutes the TV audio output.

func (*TV) Notification ¶

func (tv *TV) Notification(m string) error

Notification creates a "toast" notification.

func (*TV) OpenApp ¶

func (tv *TV) OpenApp(app string) error

OpenApp switches to a previously launched/backgrounded app.

func (*TV) Pause ¶

func (tv *TV) Pause() error

Pause pauses the current media.

func (*TV) Play ¶

func (tv *TV) Play() error

Play plays or resumes the current media.

func (*TV) Rewind ¶

func (tv *TV) Rewind() error

Rewind rewinds the current media.

func (*TV) ServiceList ¶

func (tv *TV) ServiceList() (*ServiceList, error)

ServiceList returns information about the available services.

func (*TV) SetVolume ¶

func (tv *TV) SetVolume(v int) error

SetVolume sets the audio output volume to v.

func (*TV) Shutdown ¶

func (tv *TV) Shutdown() error

Shutdown turns the TV off.

func (*TV) Stop ¶

func (tv *TV) Stop() error

Stop stops the current media.

func (*TV) Unmute ¶

func (tv *TV) Unmute() error

Unmute unmutes the TV audio output.

func (*TV) VolumeDown ¶

func (tv *TV) VolumeDown() error

VolumeDown decrements the audio output volume.

func (*TV) VolumeStatus ¶

func (tv *TV) VolumeStatus() (*Volume, error)

VolumeStatus returns information about the audio output volume.

func (*TV) VolumeUp ¶

func (tv *TV) VolumeUp() error

VolumeUp increments the audio output volume.

type Volume ¶

type Volume struct {
	ReturnValue bool
	Scenario    string
	Volume      int32
	Muted       bool
}

Volume represents the audio output volume in the TVs responses.

Directories ¶

Path Synopsis

Jump to

Keyboard shortcuts

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