ws_client

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2021 License: MIT Imports: 9 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

func NewBaseWebsocketClient

func NewBaseWebsocketClient() *BaseWebsocketClient

func (*BaseWebsocketClient) OnClose

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

func (*BaseWebsocketClient) OnConnect

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

func (*BaseWebsocketClient) OnConnecting

func (w *BaseWebsocketClient) OnConnecting()

do nothing

func (*BaseWebsocketClient) OnOpen

func (w *BaseWebsocketClient) OnOpen()

func (*BaseWebsocketClient) OnWsMessage

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

func (*BaseWebsocketClient) Send

func (*BaseWebsocketClient) SendBin

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

func (*BaseWebsocketClient) SharedSeed

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

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
}

this 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