Documentation
¶
Index ¶
- Constants
- func NewWsClient(p WebsocketClientProtocol, wsURL string)
- type BaseWebsocketClient
- func (w *BaseWebsocketClient) OnClose(wasClean bool, code int, reason string)
- func (w *BaseWebsocketClient) OnConnect(conn *websocket.Conn, r *http.Response)
- func (w *BaseWebsocketClient) OnConnecting()
- func (w *BaseWebsocketClient) OnOpen()
- func (w *BaseWebsocketClient) OnWsMessage(payload []byte, isBinary bool)
- func (w *BaseWebsocketClient) Send(msg base.MoneysocketMessage) error
- func (w *BaseWebsocketClient) SendBin(msg []byte) (err error)
- func (w *BaseWebsocketClient) SharedSeed() *beacon.SharedSeed
- type WebsocketClientProtocol
Constants ¶
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
}
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 ¶
func (w *BaseWebsocketClient) Send(msg base.MoneysocketMessage) error
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
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.