Documentation
ΒΆ
Index ΒΆ
- type Hub
- func (h *Hub) Broadcast(msg messages.BaseMessage)
- func (h *Hub) FindUsernameByUserID(userID string) (string, bool)
- func (h *Hub) GetCachedChatMessages() []models.ChatMessage
- func (h *Hub) GetConnectedUsers() []chat.UserStatusPayload
- func (h *Hub) RegisterClient(client interfaces.ClientInterface, clientID string)
- func (h *Hub) Run()
- func (h *Hub) SendMessage(msg messages.BaseMessage)
- func (h *Hub) UnregisterClient(client interfaces.ClientInterface, clientID string)
- func (h *Hub) Whisper(msg messages.BaseMessage)
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type Hub ΒΆ
type Hub struct { Connections map[string]interfaces.ClientInterface Messages chan messages.BaseMessage Register chan interfaces.ClientInterface Unregister chan interfaces.ClientInterface MessageCache *cache.MessageCache // contains filtered or unexported fields }
Hub manages all active client connections, routes messages, and handles broadcasting, registration, and unregistration.
func NewHub ΒΆ
func NewHub(db *pgxpool.Pool, cache *cache.MessageCache) *Hub
NewHub creates and returns a new Hub instance.
func (*Hub) Broadcast ΒΆ
func (h *Hub) Broadcast(msg messages.BaseMessage)
Broadcast sends the given message to all connected clients in the hub.
func (*Hub) FindUsernameByUserID ΒΆ
FindUsernameByUserID returns the username for a given user ID, if connected.
func (*Hub) GetCachedChatMessages ΒΆ
func (h *Hub) GetCachedChatMessages() []models.ChatMessage
GetCachedChatMessages returns a slice of chat messages from the message cache.
func (*Hub) GetConnectedUsers ΒΆ
func (h *Hub) GetConnectedUsers() []chat.UserStatusPayload
GetConnectedUsers returns a list of currently connected user payloads, excluding clients identified as "WebClient".
func (*Hub) RegisterClient ΒΆ
func (h *Hub) RegisterClient(client interfaces.ClientInterface, clientID string)
RegisterClient adds a client to the hub and tracks its connection start time.
func (*Hub) Run ΒΆ
func (h *Hub) Run()
Run starts the hub's main loop and handles registration, unregistration, and messages.
func (*Hub) SendMessage ΒΆ
func (h *Hub) SendMessage(msg messages.BaseMessage)
SendMessage sends a message into the hubβs internal message loop for handling.
func (*Hub) UnregisterClient ΒΆ
func (h *Hub) UnregisterClient(client interfaces.ClientInterface, clientID string)
UnregisterClient removes a client from the hub and logs the session duration.
func (*Hub) Whisper ΒΆ
func (h *Hub) Whisper(msg messages.BaseMessage)
Whisper sends a private message only to the sender and recipient clients.