Documentation
¶
Index ¶
- Variables
- type Client
- type ClientConnectionEvent
- type ClientID
- type Events
- type Hub
- func (h *Hub) BroadcastMsg(ctx context.Context, data interface{}, dontDrop ...bool) error
- func (h *Hub) Clients() int
- func (h *Hub) Events() *Events
- func (h *Hub) Register(client *Client) error
- func (h *Hub) Run(ctx context.Context)
- func (h *Hub) ServeWebsocket(w http.ResponseWriter, r *http.Request, onCreate func(client *Client), ...) error
- func (h *Hub) Stopped() bool
- func (h *Hub) Unregister(client *Client) error
- type WebsocketMsg
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrClientDisconnected = errors.New("client was disconnected") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
*logger.WrappedLogger
// 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.
type ClientConnectionEvent ¶
type ClientConnectionEvent struct {
ID ClientID
}
type Events ¶
type Events struct {
// A ClientConnected event is triggered, when a new client has connected to the websocket hub.
ClientConnected *event.Event[*ClientConnectionEvent]
// A ClientDisconnected event is triggered, when a client has disconnected from the websocket hub.
ClientDisconnected *event.Event[*ClientConnectionEvent]
}
Events contains all the events that are triggered by the websocket hub.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub maintains the set of active clients and broadcasts messages to the clients.
func (*Hub) BroadcastMsg ¶
BroadcastMsg sends a message to all clients.
func (*Hub) ServeWebsocket ¶
func (h *Hub) ServeWebsocket( w http.ResponseWriter, r *http.Request, onCreate func(client *Client), onConnect func(client *Client), onDisconnect func(client *Client)) error
ServeWebsocket handles websocket requests from the peer. onCreate gets called when the client is created. onConnect gets called when the client was registered.
func (*Hub) Unregister ¶
type WebsocketMsg ¶
type WebsocketMsg struct {
// MsgType is the type of the message based on RFC 6455.
MsgType websocket.MessageType
// Data is the received data of the message.
Data []byte
}
WebsocketMsg is a message received via websocket.
Click to show internal directories.
Click to hide internal directories.