connection

package
v0.0.0-...-4aa7fb6 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection struct {
	OnConnect    func(*Connection)
	OnDisconnect func(*Connection, error)
	// contains filtered or unexported fields
}

Connection represents a websocket connection to a LG TV

func NewConnection

func NewConnection(url string, t Timeouts) *Connection

NewConnection creates a new connection to a LG TV with the specified timeouts

func (*Connection) Close

func (c *Connection) Close() error

Close sends a close control message and disconnects from the LG TV

func (*Connection) Connect

func (c *Connection) Connect() error

Connect tries to establish a connection to the LG TV

func (*Connection) IsConnected

func (c *Connection) IsConnected() bool

IsConnected returns whether or not a connection to the LG TV is established

func (*Connection) Register

func (c *Connection) Register(id int, key string, permissions []string) error

Register sends registration request to the LG TV

func (*Connection) Request

func (c *Connection) Request(id int, uri string, payload interface{}, result interface{}) error

Request sends a request to the LG TV and waits for the response

func (*Connection) Subscribe

func (c *Connection) Subscribe(id int, uri string) (chan Response, error)

Subscribe sends a subscription request to the LG TV

type Response

type Response struct {
	ID      int             `json:"id"`
	Type    string          `json:"type"`
	Error   string          `json:"error"`
	Payload json.RawMessage `json:"payload"`
}

Response represents websocket response from the LG TV

type Timeouts

type Timeouts struct {
	Read     time.Duration
	Write    time.Duration
	Ping     time.Duration
	Response time.Duration
	Register time.Duration
}

Timeouts defines various timeouts for the connection

func DefaultTimeouts

func DefaultTimeouts() Timeouts

DefaultTimeouts returns the default timeouts

Jump to

Keyboard shortcuts

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