websocket

package
v0.0.0-...-9113921 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultHandshakeTimeout      = 30 * time.Second
	DefaultWriteTimeout          = 10 * time.Second
	DefaultReadTimeout           = 20 * time.Second
	DefaultAutoReconnectMaxDelay = 1 * time.Minute

	InitialAutoReconnectDelay       = 1 * time.Second
	AutoReconnectBackoffCoefficient = 1.5
)

Variables

View Source
var ErrClosing = errors.New("closing")

Functions

This section is empty.

Types

type ConnectedEvent

type ConnectedEvent struct {
	URL string
}

ConnectedEvent is emitted when the WebSocket connection is established.

func (*ConnectedEvent) String

func (e *ConnectedEvent) String() string

type ConnectingEvent

type ConnectingEvent struct {
	URL string
}

ConnectingEvent is emitted when a new connection is being established.

func (*ConnectingEvent) String

func (e *ConnectingEvent) String() string

type DisconnectedEvent

type DisconnectedEvent struct {
	URL string
	Err error
}

DisconnectedEvent is emitted when the WebSocket connection is lost.

func (*DisconnectedEvent) String

func (e *DisconnectedEvent) String() string

type ObjectStream

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

ObjectStream implements jsonrpc2.ObjectStream that uses a WebSocket. It extends jsonrpc2/websocket.ObjectStream with read/write timeouts.

func NewObjectStream

func NewObjectStream(conn *websocket.Conn, writeTimeout, readTimeout time.Duration) *ObjectStream

func (*ObjectStream) Close

func (stream *ObjectStream) Close() error

func (*ObjectStream) ReadObject

func (stream *ObjectStream) ReadObject(v interface{}) error

func (*ObjectStream) WriteObject

func (stream *ObjectStream) WriteObject(v interface{}) error

type Option

type Option func(*Transport)

Option represents an option that can be passed into the transport constructor.

func SetAutoReconnectEnabled

func SetAutoReconnectEnabled(enabled bool) Option

SetAutoReconnectEnabled can be used to enable automatic reconnection to the RPC endpoint. Exponential backoff is used when the connection cannot be established repetitively.

See SetAutoReconnectMaxDelay to set the maximum delay between the reconnection attempts.

func SetAutoReconnectMaxDelay

func SetAutoReconnectMaxDelay(delay time.Duration) Option

SetAutoReconnectMaxDelay can be used to set the maximum delay between the reconnection attempts.

This option only takes effect when the auto-reconnect mode is enabled.

The default value is 5 minutes.

func SetDialTimeout

func SetDialTimeout(timeout time.Duration) Option

SetDialTimeout can be used to set the timeout when establishing a new connection.

This function is deprecated, please use SetHandshakeTimeout.

func SetHandshakeTimeout

func SetHandshakeTimeout(timeout time.Duration) Option

SetHandshakeTimeout can be used to set the timeout for WebSocket handshake.

func SetMonitor

func SetMonitor(monitorChan chan<- interface{}) Option

SetMonitor can be used to set the monitoring channel that can be used to watch connection-related state changes.

All channel send operations are happening synchronously, so not receiving messages from the channel will lead to the whole thing getting stuck completely.

This option only takes effect when the auto-reconnect mode is enabled.

The channel is closed when the transport is closed.

func SetReadTimeout

func SetReadTimeout(timeout time.Duration) Option

SetReadTimeout sets the connection read timeout. The timeout is implemented using net.Conn.SetReadDeadline.

func SetReadWriteTimeout

func SetReadWriteTimeout(timeout time.Duration) Option

SetReadWriteTimeout sets the connection read and write timeout. The timeout is implemented using net.Conn.SetDeadline.

func SetWriteTimeout

func SetWriteTimeout(timeout time.Duration) Option

SetWriteTimeout sets the connection read timeout. The timeout is implemented using net.Conn.SetWriteDeadline.

type Transport

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

Transport implements a CallCloser accessing the Steem RPC endpoint over WebSocket.

func NewTransport

func NewTransport(urls []string, options ...Option) (*Transport, error)

NewTransport creates a new transport that connects to the given WebSocket URLs.

It is possible to specify multiple WebSocket endpoint URLs. In case the transport is configured to reconnect automatically, the URL to connect to is rotated on every connect attempt using round-robin.

func (*Transport) Call

func (t *Transport) Call(method string, params, result interface{}) error

Call implements interfaces.CallCloser.

func (*Transport) Close

func (t *Transport) Close() error

Close implements interfaces.CallCloser.

Jump to

Keyboard shortcuts

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