wsbroadcast

package
v0.0.0-...-75e333b Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

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

func (*Client) CanSend

func (c *Client) CanSend(channel string) bool

CanSend checks if the client is subscribed to a channel

type HandlerFunc

type HandlerFunc func(map[string]bool, chan interface{})

HandlerFunc is used for callbacks sends a list of channels the client registered to and a return channel

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(availableChannels []string) *Hub

NewHub Create a new hub for the handler

func (*Hub) Broadcast

func (h *Hub) Broadcast(channel string, m interface{})

Broadcast message to the clients

func (*Hub) OnRegister

func (h *Hub) OnRegister(f HandlerFunc)

OnRegister calls a handler when a client registers.

func (*Hub) Run

func (h *Hub) Run()

Run the hub

func (*Hub) ServeWs

func (h *Hub) ServeWs(w http.ResponseWriter, r *http.Request)

ServeWs handles websocket requests from the peer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL