chat

package
v0.0.0-...-e1d4b05 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JoinRequest

func JoinRequest(_ *goyave.Request) v.RuleSet

JoinRequest the query validation rules joining the chat room.

Types

type Client

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

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

type Hub

type Hub struct {
	goyave.Component
	// contains filtered or unexported fields
}

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

func NewHub

func NewHub() *Hub

NewHub create a new chat Hub.

func (*Hub) Broadcast

func (h *Hub) Broadcast(message []byte)

Broadcast send a message to all connected clients. This method is concurrently safe and doesn't do anything is the Hub's context is canceled.

func (*Hub) RegisterRoute

func (h *Hub) RegisterRoute(router *goyave.Router, handler goyave.Handler)

RegisterRoute regsiters the websocket route with validation.

func (*Hub) Run

func (h *Hub) Run()

Run the Hub loop. Should be run in a goroutine. This method should not be called more than once.

Registers a shutdown hook, ensuring the hub shutdowns properly and closes all active connections before goyave.Start() returns.

func (*Hub) Serve

func (h *Hub) Serve(c *websocket.Conn, request *goyave.Request) error

Serve is the websocket Handler for the chat clients.

Jump to

Keyboard shortcuts

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