ws

package
v0.0.0-...-21a16ac Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthFunc

type AuthFunc = func(r *http.Request) error

type Client

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

func (*Client) Send

func (c *Client) Send(b []byte)

Send the specified bytes to the web socket connection by placing the bytes on the send channel. The writer() pump will pick up these bytes and send them on the web socket connection.

func (*Client) UserId

func (c *Client) UserId() string

Get the user id of this client

type ClientInitHandler

type ClientInitHandler = func(ctx context.Context, c *Client) error

type ClientMessageHandler

type ClientMessageHandler = func(ctx context.Context, m []byte, c *Client)

type Hub

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

The Hub maintain all web socket clients. When started (using Run()), the Hub will pass messages from the message channel to the corresponding recipient. The SendTo() func can be used to place messages on the message channel.

func NewHub

func NewHub() *Hub

func (*Hub) Run

func (h *Hub) Run()

Starts the Hub (and blocks). It will pull messages and send them to the corresponding client.

func (*Hub) SendTo

func (h *Hub) SendTo(recipient string, body []byte)

Sends bytes to a recipient (user id) by putting a message on the messages channel. If the Hub is running (using Run()), the messages will be passed to the corresponding Client.

type Message

type Message struct {
	Recipient string
	Body      []byte
}

type WsEndpoint

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

func NewEndpoint

func NewEndpoint(authFunc AuthFunc, hub *Hub, handler WsHandler, origins []string) *WsEndpoint

func (*WsEndpoint) ServeHTTP

func (e *WsEndpoint) ServeHTTP(w http.ResponseWriter, r *http.Request)

type WsHandler

type WsHandler interface {
	HandleInit(ctx context.Context, c *Client) error
	HandleMessage(ctx context.Context, m []byte, c *Client)
}

Jump to

Keyboard shortcuts

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