Documentation
¶
Index ¶
Constants ¶
View Source
const ( FlagMessage = "flag" FlagResponse = "flag_response" ConfigMessage = "config" ConfigResponse = "config_response" )
View Source
const (
ConnectionLifetime = 24 * time.Hour // Lifetime of the connection
)
Variables ¶
View Source
var ( ErrEventNotSupported = errors.New("this event type is not supported") ErrConnectionTimeout = errors.New("connection timeout exceeded") )
Functions ¶
func ConfigHandler ¶
func CookieAuthMiddleware ¶
func FlagHandler ¶
FlagHandler will send out a message to all other participants in the chat
func VerifyToken ¶
VerifyToken verifies the JWT token using the secret key
Types ¶
type Client ¶
type Client struct {
Connection *websocket.Conn
Manager *Manager
Egress chan []byte
Closed chan struct{}
ConnectionTimer *time.Timer
Number int
IsClosed bool
// contains filtered or unexported fields
}
Client represents a WebSocket client connection
func (*Client) CloseConnection ¶
CloseConnection safely closes a client connection and prevents goroutine leaks
func (*Client) PongHandler ¶
func (*Client) ReadMessages ¶
func (client *Client) ReadMessages()
func (*Client) WriteMessages ¶
func (client *Client) WriteMessages()
type ClientList ¶
ClientList maps clients to a boolean value indicating their status
type Event ¶
type Event struct {
Type string `json:"type"`
Payload json.RawMessage `json:"payload"`
}
type EventHandler ¶
EventHandler is a function type for handling WebSocket events
type Manager ¶
type Manager struct {
Clients ClientList
Handlers map[string]EventHandler
sync.RWMutex
}
Manager handles WebSocket clients and event routing
var GlobalManager *Manager // WebSocket manager
func NewManager ¶
func NewManager() *Manager
func (*Manager) GetNextClientNumber ¶
func (*Manager) RemoveClient ¶
func (*Manager) SetupEventHandlers ¶
func (m *Manager) SetupEventHandlers()
type NewMessageEvent ¶
NewMessageEvent represents a new message event
Click to show internal directories.
Click to hide internal directories.