client

package
v0.87.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const UnknownStatusCode = -1

UnknownStatusCode is sent to this when code is unknown.

Variables

This section is empty.

Functions

func NewWsClient

func NewWsClient(p WebsocketClientProtocol, wsURL string)

NewWsClient creates a websocket client.

Types

type BaseWebsocketClient

type BaseWebsocketClient struct {
	// See: https://git.io/JtPNQ, gorilla websockets do not suppor tconcurrent writers
	Mux            sync.Mutex
	Conn           *websocket.Conn
	BaseSharedSeed *beacon.SharedSeed
}

BaseWebsocketClient base websocket service you can wrap in a struct so you don't need to reimplement empty event listeners. It also provides a canonical way to send messages.

func NewBaseWebsocketClient

func NewBaseWebsocketClient() *BaseWebsocketClient

NewBaseWebsocketClient creates a websocket client with default options.

func (*BaseWebsocketClient) OnClose

func (w *BaseWebsocketClient) OnClose(wasClean bool, code int, reason string)

OnClose called when a connection is closed.

func (*BaseWebsocketClient) OnConnect

func (w *BaseWebsocketClient) OnConnect(conn *websocket.Conn, r *http.Response)

OnConnect called on connect, sets the connection object.

func (*BaseWebsocketClient) OnConnecting

func (w *BaseWebsocketClient) OnConnecting()

OnConnecting is called when connection is established.

func (*BaseWebsocketClient) OnOpen

func (w *BaseWebsocketClient) OnOpen()

OnOpen called when the connection is opened.

func (*BaseWebsocketClient) OnWsMessage

func (w *BaseWebsocketClient) OnWsMessage(payload []byte, isBinary bool)

OnWsMessage called when a ws message is received.

func (*BaseWebsocketClient) Send

Send a websocket message.

func (*BaseWebsocketClient) SendBin

func (w *BaseWebsocketClient) SendBin(msg []byte) (err error)

SendBin sends a binary message.

func (*BaseWebsocketClient) SharedSeed

func (w *BaseWebsocketClient) SharedSeed() *beacon.SharedSeed

SharedSeed gets the shared seed.

type WebsocketClientProtocol

type WebsocketClientProtocol interface {
	// calls when a new connection is made
	OnConnecting()
	// the client has connected
	OnConnect(conn *websocket.Conn, r *http.Response)
	// connection is open
	OnOpen()
	// handle incoming messages
	OnWsMessage(payload []byte, isBinary bool)
	// called when connection isclosed
	OnClose(wasClean bool, code int, reason string)

	// send a message
	Send(msg base.MoneysocketMessage) error
	// send a binary-encoded message
	SendBin(msg []byte) error
	// get the shared seed
	SharedSeed() *beacon.SharedSeed
	// contains filtered or unexported methods
}

WebsocketClientProtocol class attempts to emulate the twisted socket interface for usabilities sake and calls events on downstream nexuses.

Jump to

Keyboard shortcuts

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