websockethub

package
Version: v0.0.0-...-fa26ab0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: Apache-2.0, BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TextMessage denotes a text data message. The text message payload is
	// interpreted as UTF-8 encoded text data.
	TextMessage = 1

	// BinaryMessage denotes a binary data message.
	BinaryMessage = 2

	// CloseMessage denotes a close control message. The optional message
	// payload contains a numeric code and text. Use the FormatCloseMessage
	// function to format a close message payload.
	CloseMessage = 8

	// PingMessage denotes a ping control message. The optional message payload
	// is UTF-8 encoded text.
	PingMessage = 9

	// PongMessage denotes a pong control message. The optional message payload
	// is UTF-8 encoded text.
	PongMessage = 10
)

The message types are defined in RFC 6455, section 11.8.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {

	// a channel which is closed when the websocket client is disconnected.
	ExitSignal chan struct{}

	// channel of inbound messages.
	// this will be created by the user if receiving messages is needed.
	ReceiveChan chan *WebsocketMsg

	// FilterCallback is used to filter messages to clients on BroadcastMsg
	FilterCallback func(c *Client, data interface{}) bool
	// contains filtered or unexported fields
}

Client is a middleman between the node and the websocket connection.

func (*Client) Send

func (c *Client) Send(msg interface{}, dontDrop ...bool)

Send sends a message to the client

type Hub

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

Hub maintains the set of active clients and broadcasts messages to the clients.

func NewHub

func NewHub(logger *logger.Logger, upgrader *websocket.Upgrader, broadcastQueueSize int, clientSendChannelSize int) *Hub

func (*Hub) BroadcastMsg

func (h *Hub) BroadcastMsg(data interface{}, dontDrop ...bool)

BroadcastMsg sends a message to all clients.

func (*Hub) Run

func (h *Hub) Run(shutdownSignal <-chan struct{})

Run starts the hub.

func (*Hub) ServeWebsocket

func (h *Hub) ServeWebsocket(w http.ResponseWriter, r *http.Request, onCreate func(client *Client), onConnect func(client *Client))

ServeWebsocket handles websocket requests from the peer. onCreate gets called when the client is created. onConnect gets called when the client was registered.

type WebsocketMsg

type WebsocketMsg struct {
	// MsgType is the type of the message based on RFC 6455.
	MsgType int
	// Data is the received data of the message.
	Data []byte
}

WebsocketMsg is a message received via websocket.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL