reconws

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: GPL-3.0, AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ReconWs

type ReconWs struct {
	Connected       chan struct{} // allow notification of successful connection, helps with testing
	ConnectedAt     time.Time
	ForwardIncoming bool
	In              chan WsMessage
	Out             chan WsMessage
	Retry           RetryConfig
	URL             string
	ID              string
}

ReconWs represents a websocket client that will reconnect if the connection is closed connects (retrying/reconnecting if necessary) to websocket server at url

func New

func New() *ReconWs

New returns a pointer to a new reconnecting websocket client ReconWs

func (*ReconWs) Dial

func (r *ReconWs) Dial(ctx context.Context, urlStr string) error

Dial the websocket server once. If dial fails then return immediately If dial succeeds then handle message traffic until the context is cancelled

func (*ReconWs) Reconnect

func (r *ReconWs) Reconnect(ctx context.Context, url string)

Reconnect sets URL to connect to, and runs the client run this in a separate goroutine so that the connection can be ended from where it was initialised, by close((* ReconWs).Stop) does not implement the connected signal; use ReconnectAuth for that

func (*ReconWs) ReconnectAuth

func (r *ReconWs) ReconnectAuth(ctx context.Context, url, token string)

ReconnectAuth reconnects to a relay instance that uses an access server to gatekeep access to the websocket relay run this in a separate goroutine so that the connection can be ended from where it was initialised, by close((* ReconWs).Stop)

type RetryConfig

type RetryConfig struct {
	Factor  float64
	Jitter  bool
	Min     time.Duration
	Max     time.Duration
	Timeout time.Duration
}

RetryConfig represents the parameters for when to retry to connect

type WsMessage

type WsMessage struct {
	Data []byte
	Type int
	To   string
	From string
}

WsMessage represents a websocket message

Jump to

Keyboard shortcuts

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