websockets

package
v0.0.0-...-692e367 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TextMessage   = websocket.TextMessage
	BinaryMessage = websocket.BinaryMessage
	CloseMessage  = websocket.CloseMessage
	PingMessage   = websocket.PingMessage
	PongMessage   = websocket.PongMessage
)

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

View Source
const (
	RequestHeaders = "x-http-req-headers"
)

Variables

View Source
var (
	ErrEventNotSupported = errors.New("this event type is not supported")
)

Functions

This section is empty.

Types

type Client

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

Client is a websocket client, basically a frontend visitor

func NewClient

func NewClient(ctx context.Context, log logger.Logger, conn *websocket.Conn, manager *Manager) *Client

NewClient is used to initialize a new Client with all required values initialized

func (*Client) WriteJSON

func (c *Client) WriteJSON(i interface{}) error

WriteJSON writes the JSON encoding of v to the connection.

func (*Client) WriteMessage

func (c *Client) WriteMessage(messageType int, data []byte) error

WriteMessage is a helper method for getting a writer using NextWriter.

type ClientList

type ClientList map[*Client]bool

type Event

type Event struct {
	Type    string          `json:"type"`
	Payload json.RawMessage `json:"payload"`
}

type EventHandler

type EventHandler func(ctx context.Context, event Event, c *Client) error

type Manager

type Manager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Manager is used to hold references to all Clients Registered, and Broadcasting etc

func NewManager

func NewManager(log logger.Logger) *Manager

NewManager is used to initialize all the values inside the manager

func (*Manager) AddEventHandler

func (m *Manager) AddEventHandler(event string, handler EventHandler)

AddEventHandler configures and adds all handlers

func (*Manager) ServeWS

func (m *Manager) ServeWS(w http.ResponseWriter, r *http.Request)

ServeWS is an HTTP Handler that the has the Manager that allows connections

Jump to

Keyboard shortcuts

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