client

package
v0.54.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const UnknownStatusCode = -1

code is setnt to this when code is unknown

Variables

This section is empty.

Functions

func NewWsClient

func NewWsClient(p WebsocketClientProtocol, wsURL string)

TODO make this do things

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
}

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

Creates a websocket client with default options

func (*BaseWebsocketClient) OnClose

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

called when a connection is closed

func (*BaseWebsocketClient) OnConnect

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

called on connect, sets the connection object

func (*BaseWebsocketClient) OnConnecting

func (w *BaseWebsocketClient) OnConnecting()

called when connection is established

func (*BaseWebsocketClient) OnOpen

func (w *BaseWebsocketClient) OnOpen()

called when the connection is opened

func (*BaseWebsocketClient) OnWsMessage

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

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)

send a binary message

func (*BaseWebsocketClient) SharedSeed

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

get 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