websocket

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BroadcastMessage

type BroadcastMessage struct {
	TicketID types.TicketID
	Message  []byte
}

BroadcastMessage represents a message to be broadcast to all clients of a ticket

type Client

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

Client is a middleman between the websocket connection and the hub

func (*Client) GetClientID

func (c *Client) GetClientID() string

GetClientID returns the client ID for a client

type Handler

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

Handler handles WebSocket connections for chat functionality

func NewHandler

func NewHandler(hub *Hub, repository interfaces.Repository, useCases *usecase.UseCases) *Handler

NewHandler creates a new WebSocket handler

func NewTestHandler

func NewTestHandler(hub *Hub, repository interfaces.Repository, useCases *usecase.UseCases) (*Handler, *httptest.Server)

NewTestHandler creates a WebSocket handler configured for testing It automatically sets the frontend URL to match the test server

func (*Handler) HandleTicketChat

func (h *Handler) HandleTicketChat(w http.ResponseWriter, r *http.Request)

HandleTicketChat handles WebSocket connections for ticket chat

func (*Handler) WithAllowedOrigins

func (h *Handler) WithAllowedOrigins(origins []string) *Handler

WithAllowedOrigins sets additional allowed origins (useful for development)

func (*Handler) WithFrontendURL

func (h *Handler) WithFrontendURL(url string) *Handler

WithFrontendURL sets the frontend URL for origin checking

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(ctx context.Context) *Hub

NewHub creates a new Hub

func (*Hub) BroadcastToTicket

func (h *Hub) BroadcastToTicket(ticketID types.TicketID, message []byte)

BroadcastToTicket sends a message to all clients of a specific ticket

func (*Hub) Close

func (h *Hub) Close() error

Close gracefully shuts down the hub

func (*Hub) GetActiveTickets

func (h *Hub) GetActiveTickets() []types.TicketID

GetActiveTickets returns a list of ticket IDs that have active clients

func (*Hub) GetClientCount

func (h *Hub) GetClientCount(ticketID types.TicketID) int

GetClientCount returns the number of clients connected to a specific ticket

func (*Hub) GetTotalClientCount

func (h *Hub) GetTotalClientCount() int

GetTotalClientCount returns the total number of connected clients across all tickets

func (*Hub) NewClient

func (h *Hub) NewClient(conn *websocket.Conn, ticketID types.TicketID, userID string) *Client

NewClient creates a new client (for backward compatibility)

func (*Hub) NewClientWithTabID

func (h *Hub) NewClientWithTabID(conn *websocket.Conn, ticketID types.TicketID, userID string, tabID string) *Client

NewClientWithTabID creates a new client with a specific tab ID

func (*Hub) Register

func (h *Hub) Register(client *Client)

Register registers a client with the hub

func (*Hub) Run

func (h *Hub) Run()

Run starts the hub's main loop

func (*Hub) SendErrorToTicket

func (h *Hub) SendErrorToTicket(ticketID types.TicketID, content string) error

SendErrorToTicket sends an error message to all clients of a ticket

func (*Hub) SendMessageToClient

func (h *Hub) SendMessageToClient(clientID string, content string, user *websocket_model.User) error

SendMessageToClient sends a chat message to a specific client

func (*Hub) SendMessageToTicket

func (h *Hub) SendMessageToTicket(ticketID types.TicketID, content string, user *websocket_model.User) error

SendMessageToTicket sends a chat message to all clients of a ticket

func (*Hub) SendStatusToTicket

func (h *Hub) SendStatusToTicket(ticketID types.TicketID, content string) error

SendStatusToTicket sends a status message to all clients of a ticket

func (*Hub) SendToClient

func (h *Hub) SendToClient(clientID string, response *websocket_model.ChatResponse) error

SendToClient sends a message to a specific client by client ID

func (*Hub) SendToTicket

func (h *Hub) SendToTicket(ticketID types.TicketID, response *websocket_model.ChatResponse) error

SendToTicket is a convenience method to send a WebSocket message to a ticket

func (*Hub) SendTraceToClient

func (h *Hub) SendTraceToClient(clientID string, content string, user *websocket_model.User) error

SendTraceToClient sends a trace message to a specific client

func (*Hub) Unregister

func (h *Hub) Unregister(client *Client)

Unregister removes a client from the hub

Jump to

Keyboard shortcuts

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