Documentation
¶
Index ¶
- Constants
- Variables
- type DisconnectError
- type ReConnectSettings
- type WsDialer
- func (dialer *WsDialer) Close() error
- func (dialer *WsDialer) Closed() <-chan struct{}
- func (dialer *WsDialer) Dial(ctx context.Context) error
- func (dialer *WsDialer) IsClosed() bool
- func (dialer *WsDialer) ReadMessage() (int, []byte, error)
- func (dialer *WsDialer) WriteMessage(messageType int, data []byte) error
Constants ¶
View Source
const ( // DefaultTimeout of websocker dialer DefaultTimeout = 30 * time.Second )
Variables ¶
View Source
var ( // DefaultBackoff of reconnection DefaultBackoff = []float64{0.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0} )
Functions ¶
This section is empty.
Types ¶
type DisconnectError ¶
type DisconnectError struct {
Type string
}
DisconnectError is sent on websocket disconnect
func (DisconnectError) Error ¶
func (err DisconnectError) Error() string
Error implements error interface
type ReConnectSettings ¶
type ReConnectSettings struct {
// AutoReconnect, set to automatically try to reconnect when disconnected, will be set to false on "Close"
AutoReconnect bool
// Backoff scheme in seconds for reconnecting websocket if "AutoReconnect" set to true. Defaults to
Backoff []float64
// OnReconnectStart triggers when reconnect start (only with AutoReconnect set)
OnReconnectStart func()
// OnReconnectDone triggers when reconnect is considered successful or failed
// err : error during last attempt (nil of successful)
// attempts: amount of attempts including successful attempt tried
// timeSpent: total duration spent trying to re-connect
OnReconnectDone func(err error, attempts int, timeSpent time.Duration)
// GetContext context used to abort waiting during backoff and as a mother context to dial, defaults to background context
GetContext func() context.Context
// SetPending reconnect
SetPending func()
// UnsetPending reconnect
UnsetPending func()
}
ReConnectSettings settings for automatically reconnecting websocket
type WsDialer ¶
type WsDialer struct {
gobwas.Dialer
net.Conn
// Type of websocket, will be used by DisconnectError
Type string
// Reconnect settings
Reconnect ReConnectSettings
// OnUnexpectedDisconnect triggers on disconnect of websocket
OnUnexpectedDisconnect func()
// contains filtered or unexported fields
}
WsDialer wraps gobwas websocket dialer
func New ¶
func New(url *neturl.URL, httpHeader http.Header, cookieJar http.CookieJar, timeout time.Duration, allowUntrusted bool, wstype string) (*WsDialer, error)
New Create new websocket dialer, use type to define a specific type which would be reported when getting a DisconnectError
func (*WsDialer) Closed ¶
func (dialer *WsDialer) Closed() <-chan struct{}
Closed returns chan which will be closed when Close() is triggered
func (*WsDialer) ReadMessage ¶
ReadMessage Read one entire message from websocket
Click to show internal directories.
Click to hide internal directories.