websocket

package
v0.4.15 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMisconfiguredWS = errors.New("misconfigured WS")
	ErrClosed          = errors.New("websocket closed")
	ErrInvalidMsgType  = errors.New("invalid message type")
)

Functions

This section is empty.

Types

type Egress added in v0.1.0

type Egress interface {
	// HandleWrp is called whenever a message targets something other than this device.
	HandleWrp(m wrp.Message) error
}

Egress interface is the egress route used to handle wrp messages that targets something other than this device

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is a functional option type for WS.

func AddConnectListener

func AddConnectListener(listener event.ConnectListener, cancel ...*event.CancelFunc) Option

AddConnectListener adds a connect listener to the WS connection.

func AddDisconnectListener

func AddDisconnectListener(listener event.DisconnectListener, cancel ...*event.CancelFunc) Option

AddDisconnectListener adds a disconnect listener to the WS connection.

func AddHeartbeatListener

func AddHeartbeatListener(listener event.HeartbeatListener, cancel ...*event.CancelFunc) Option

AddHeartbeatListener adds a heartbeat listener to the WS connection.

func AddMessageListener

func AddMessageListener(listener event.MsgListener, cancel ...*event.CancelFunc) Option

AddMessageListener adds a message listener to the WS connection. The listener will be called for every message received from the WS.

func AdditionalHeaders

func AdditionalHeaders(headers http.Header) Option

AdditionalHeaders sets the additional headers for the WS connection.

func ConveyDecorator added in v0.1.0

func ConveyDecorator(f func(http.Header) error) Option

func CredentialsDecorator

func CredentialsDecorator(f func(http.Header) error) Option

CredentialsDecorator provides the credentials decorator for the WS connection.

func DeviceID

func DeviceID(id wrp.DeviceID) Option

DeviceID sets the device ID for the WS connection.

func FetchURL

func FetchURL(f func(context.Context) (string, error)) Option

FetchURL sets the FetchURL for the WS connection.

func FetchURLTimeout

func FetchURLTimeout(d time.Duration) Option

FetchURLTimeout sets the FetchURLTimeout for the WS connection. If this is not set, the default is 30 seconds.

func HTTPClient added in v0.1.0

func HTTPClient(c arrangehttp.ClientConfig) Option

HTTPClient is the configuration for the HTTP client used for connection attempts.

func HTTPClientWithForceSets added in v0.1.0

func HTTPClientWithForceSets(c arrangehttp.ClientConfig) Option

HTTPClientWithForceSets is the configuration for the HTTP client with recommended force sets, used for connection attempts.

func InactivityTimeout added in v0.1.0

func InactivityTimeout(d time.Duration) Option

InactivityTimeout sets inactivity timeout for the WS connection.

func KeepAliveInterval

func KeepAliveInterval(d time.Duration) Option

KeepAliveInterval sets the keep alive interval for the WS connection. If this is not set, the default is 30 seconds.

func MaxMessageBytes

func MaxMessageBytes(bytes int64) Option

MaxMessageBytes sets the maximum message size sent or received in bytes.

func NowFunc

func NowFunc(f func() time.Time) Option

NowFunc sets the now function for the WS connection.

func Once

func Once(once ...bool) Option

Once sets whether or not to only attempt to connect once.

func PingWriteTimeout added in v0.1.0

func PingWriteTimeout(d time.Duration) Option

PingWriteTimeout sets the maximum time allowed between PINGs for the WS connection before the connection is closed. If this is not set, the default is 90 seconds.

func RetryPolicy

func RetryPolicy(pf retry.PolicyFactory) Option

RetryPolicy sets the retry policy factory used for delaying between retry attempts for reconnection.

func SendTimeout added in v0.1.0

func SendTimeout(d time.Duration) Option

SendTimeout sets the send timeout for the WS connection.

func URL

func URL(url string) Option

URL sets the URL for the WS connection.

func WithIPv4

func WithIPv4(with ...bool) Option

WithIPv4 sets whether or not to allow IPv4 for the WS connection. If this is not set, the default is true.

func WithIPv6

func WithIPv6(with ...bool) Option

WithIPv6 sets whether or not to allow IPv6 for the WS connection. If this is not set, the default is true.

type Websocket

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

func New

func New(opts ...Option) (*Websocket, error)

New creates a new WS connection with the given options.

func (*Websocket) AddMessageListener added in v0.1.0

func (ws *Websocket) AddMessageListener(listener event.MsgListener) event.CancelFunc

AddMessageListener adds a message listener to the WS connection. The listener will be called for every message received from the WS.

func (*Websocket) HandleWrp added in v0.1.0

func (ws *Websocket) HandleWrp(m wrp.Message) error

func (*Websocket) Send

func (ws *Websocket) Send(ctx context.Context, msg wrp.Message) error

Send sends the provided WRP message through the existing websocket. This call synchronously blocks until the write is complete.

func (*Websocket) Start

func (ws *Websocket) Start()

Start starts the websocket connection and a long running goroutine to maintain the connection.

func (*Websocket) Stop

func (ws *Websocket) Stop()

Stop stops the websocket connection.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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