websocket

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 12 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 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 ConnectTimeout

func ConnectTimeout(d time.Duration) Option

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

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 ExpectContinueTimeout

func ExpectContinueTimeout(d time.Duration) Option

ExpectContinueTimeout sets the expect continue timeout for the WS connection. If this is not set, the default is 1 second.

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 IdleConnTimeout

func IdleConnTimeout(d time.Duration) Option

IdleConnTimeout sets the idle connection timeout for the WS connection. If this is not set, the default is 10 seconds.

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 PingInterval

func PingInterval(d time.Duration) Option

PingInterval sets the time expected between PINGs for the WS connection. If this is not set, the default is 30 seconds.

func PingTimeout

func PingTimeout(d time.Duration) Option

PingTimeout 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 TLSHandshakeTimeout

func TLSHandshakeTimeout(d time.Duration) Option

TLSHandshakeTimeout sets the TLS handshake timeout for the WS connection. If this is not set, the default is 10 seconds.

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) 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