chat

package
v0.0.0-...-2953744 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// JoinRequest the validation rules joining the chat room.
	JoinRequest = validation.RuleSet{
		"name": validation.List{"required", "string", "between:3,50"},
	}
)

Functions

This section is empty.

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 {
	// 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) 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