Documentation ¶
Index ¶
- Variables
- type Client
- func (c *Client) Close() error
- func (c *Client) CloseAndReconnect() (err error)
- func (c *Client) Closed() bool
- func (c *Client) Connect()
- func (c *Client) Connected() bool
- func (c *Client) Dial()
- func (c *Client) GetBackoff() *backoff.Backoff
- func (c *Client) GetVerbose() bool
- func (c *Client) ReadJSON(v interface{}) (err error)
- func (c *Client) ReadMessage() (messageType int, message []byte, err error)
- func (c *Client) ReadMessages() error
- func (c *Client) SetKeepAliveTimeout(interval time.Duration)
- func (c *Client) WriteJSON(v interface{}) (err error)
- func (c *Client) WriteMessage(messageType int, data []byte) (err error)
- type Config
- type OnConnectedHandler
- type OnMessageHandler
Constants ¶
This section is empty.
Variables ¶
var ErrNotConnected = errors.New("websocket: not connected")
ErrNotConnected is returned when the application read/writes a message and the connection is closed
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // RecIntvlMin specifies the initial reconnecting interval, // default to 2 seconds. RecIntvlMin time.Duration // RecIntvlMax specifies the maximum reconnecting interval, // default to 30 seconds. RecIntvlMax time.Duration // RecIntvlFactor specifies the rate of increase of the reconnection // interval, default to 1.5. RecIntvlFactor float64 // Backoff holds the previous attributes in order to allow the reconnection // mechanism to work. Backoff *backoff.Backoff // HandshakeTimeout specifies the duration for the handshake to complete, // default to 2 seconds. HandshakeTimeout time.Duration // Verbose suppress connecting/reconnecting messages. Verbose bool // Conn represents the underlying websocket connection. Conn *websocket.Conn // Dialer represents the mechanism used to perform the connection. Dialer *websocket.Dialer // OnConnected represents the handler dispatched when the connection is opened. OnConnected OnConnectedHandler // OnMessage represents the handler dispatched when a message is read. OnMessage OnMessageHandler // contains filtered or unexported fields }
Client type represents a Reconnecting WebSocket connection.
func (*Client) Close ¶
Close closes the underlying network connection without sending or waiting for a close frame.
func (*Client) CloseAndReconnect ¶
CloseAndReconnect will try to reconnect.
func (*Client) Connect ¶
func (c *Client) Connect()
Connect performs the connection. This function should be executed by a goroutine.
func (*Client) Dial ¶
func (c *Client) Dial()
Dial establishes a new client connection. The URL url specifies the host and request URI. Use requestHeader to specify the origin (Origin), sub-protocols (Sec-WebSocket-Protocol) and cookies (Cookie).
func (*Client) GetBackoff ¶
GetBackoff retrieves the backoff associated with the connection.
func (*Client) GetVerbose ¶
GetVerbose returns `Verbose`, a boolean used to define if the client should suppress connection/reconnection messages or not. False by default.
func (*Client) ReadJSON ¶
ReadJSON reads the next JSON-encoded message from the connection and stores it in the value pointed to by v.
See the documentation for the encoding/json Unmarshal function for details about the conversion of JSON to a Go value.
If the connection is closed ErrNotConnected is returned
func (*Client) ReadMessage ¶
ReadMessage is a helper method for reading a message from the underlying connection. If the connection is closed ErrNotConnected is returned
func (*Client) ReadMessages ¶
ReadMessages reads messages while the connection is active
func (*Client) SetKeepAliveTimeout ¶
SetKeepAliveTimeout sets the interval for the keep alive message
type Config ¶
type Config interface { Auth() *auth.Authentication BaseUrl() string }
type OnConnectedHandler ¶
OnConnectedHandler is a handler that is dispatched when the client reads a message from the websocket. This can be the authentication message and/or something else.
type OnMessageHandler ¶
OnMessageHandler is a handler that is dispatched when the client reads a message from the websocket.