Documentation
¶
Index ¶
- Constants
- type Hub
- func (h *Hub) AddServerChannel(channel string)
- func (h *Hub) Broadcast(channel, eventName string, payload any)
- func (h *Hub) HandleUpgrade(w http.ResponseWriter, r *http.Request)
- func (h *Hub) Run(ctx context.Context)
- func (h *Hub) SetMetrics(m *metrics.Collector)
- func (h *Hub) SetProjectProvider(p ProjectProvider)
- func (h *Hub) SetRPCHandler(handler RPCHandler)
- func (h *Hub) SetTokenValidator(v TokenValidator)
- type MuxRPCHandler
- type ProjectProvider
- type RPCHandler
- type TokenValidator
Constants ¶
const DefaultConnectTimeout = 10 * time.Second
DefaultConnectTimeout is how long, with auth on, a socket may stay open without a connect that passed.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub manages WebSocket connections and broadcasts messages using the Centrifugo v5 JSON protocol.
func (*Hub) AddServerChannel ¶
AddServerChannel subscribes every client to channel on connect (server-side subscription), like the project channels.
func (*Hub) HandleUpgrade ¶
func (h *Hub) HandleUpgrade(w http.ResponseWriter, r *http.Request)
HandleUpgrade is the HTTP handler for /connection/websocket.
func (*Hub) SetMetrics ¶
SetMetrics sets the metrics collector for the hub.
func (*Hub) SetProjectProvider ¶
func (h *Hub) SetProjectProvider(p ProjectProvider)
SetProjectProvider sets the function that returns project keys for auto-subscription.
func (*Hub) SetRPCHandler ¶
func (h *Hub) SetRPCHandler(handler RPCHandler)
SetRPCHandler sets the handler for Centrifugo RPC calls.
func (*Hub) SetTokenValidator ¶
func (h *Hub) SetTokenValidator(v TokenValidator)
SetTokenValidator turns on auth for the socket: a connect needs a token v accepts, only connected clients get commands answered and pushes, a socket without a passed connect is closed after the connect timeout, and a socket is closed when its token expires. Call it before serving.
type MuxRPCHandler ¶
type MuxRPCHandler struct {
// contains filtered or unexported fields
}
MuxRPCHandler routes Centrifugo RPC calls to the HTTP mux.
func NewMuxRPCHandler ¶
func NewMuxRPCHandler(mux *http.ServeMux) *MuxRPCHandler
func (*MuxRPCHandler) HandleRPC ¶
func (h *MuxRPCHandler) HandleRPC(method, uri string, data json.RawMessage) (json.RawMessage, error)
HandleRPC converts an RPC call (e.g., DELETE api/event/{id}) into an HTTP request, executes it against the mux, and returns the response.
type ProjectProvider ¶
type ProjectProvider func() []string
ProjectProvider returns the list of project keys for server-side subscriptions.
type RPCHandler ¶
type RPCHandler interface {
HandleRPC(method, uri string, data json.RawMessage) (json.RawMessage, error)
}
RPCHandler processes Centrifugo RPC calls (e.g., "delete:api/event/{id}").