websocket

package
v0.0.0-...-46646b9 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Upgrader = websocket.Upgrader{
	CheckOrigin: func(r *http.Request) bool {

		return true
	},
	ReadBufferSize:  1024,
	WriteBufferSize: 1024,
}

Upgrader specifies parameters for upgrading an HTTP connection to a WebSocket

Functions

This section is empty.

Types

type Client

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

Client represents a websocket client

func NewClient

func NewClient(conn *websocket.Conn, hub *Hub, id string) *Client

NewClient creates a new websocket client

func (*Client) Close

func (c *Client) Close()

Close closes the client connection

func (*Client) HandleGraphQLSubscription

func (c *Client) HandleGraphQLSubscription(message *GraphQLSubscriptionMessage)

HandleGraphQLSubscription handles GraphQL subscription protocol messages

func (*Client) ReadPump

func (c *Client) ReadPump()

ReadPump pumps messages from the websocket connection to the hub

func (*Client) WritePump

func (c *Client) WritePump()

WritePump pumps messages from the hub to the websocket connection

type GraphQLSubscription

type GraphQLSubscription struct {
	ID        string
	Query     string
	Variables map[string]interface{}
	Client    *Client
	Topics    []string
	CreatedAt time.Time
}

GraphQLSubscription represents a GraphQL subscription

type GraphQLSubscriptionHandler

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

GraphQLSubscriptionHandler handles GraphQL subscription connections

func NewGraphQLSubscriptionHandler

func NewGraphQLSubscriptionHandler(hub *Hub, logger *slog.Logger) *GraphQLSubscriptionHandler

NewGraphQLSubscriptionHandler creates a new GraphQL subscription handler

func (*GraphQLSubscriptionHandler) ServeHTTP

ServeHTTP handles GraphQL subscription WebSocket connections

type GraphQLSubscriptionMessage

type GraphQLSubscriptionMessage struct {
	ID      string                 `json:"id,omitempty"`
	Type    string                 `json:"type"`
	Payload map[string]interface{} `json:"payload,omitempty"`
}

GraphQLSubscriptionMessage represents a GraphQL subscription message

type Handler

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

Handler handles WebSocket connections for GraphQL subscriptions

func NewHandler

func NewHandler(hub *Hub, logger *slog.Logger) *Handler

NewHandler creates a new WebSocket handler

func (*Handler) ServeHTTP

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

ServeHTTP handles WebSocket upgrade requests

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(logger *slog.Logger) *Hub

NewHub creates a new websocket hub

func (*Hub) Broadcast

func (h *Hub) Broadcast(message []byte)

Broadcast broadcasts a message to all connected clients

func (*Hub) BroadcastGraphQLData

func (h *Hub) BroadcastGraphQLData(subscriptionID string, data interface{})

BroadcastGraphQLData broadcasts data to GraphQL subscribers

func (*Hub) BroadcastToTopic

func (h *Hub) BroadcastToTopic(topic string, data interface{})

BroadcastToTopic broadcasts a message to all clients subscribed to a specific topic

func (*Hub) GetClientCount

func (h *Hub) GetClientCount() int

GetClientCount returns the number of connected clients

func (*Hub) GetClients

func (h *Hub) GetClients() map[*Client]bool

GetClients returns all connected clients

func (*Hub) GetSubscriptionCount

func (h *Hub) GetSubscriptionCount(topic string) int

GetSubscriptionCount returns the number of subscriptions for a topic

func (*Hub) GetTopics

func (h *Hub) GetTopics() []string

GetTopics returns all active topics

func (*Hub) GetTotalConnections

func (h *Hub) GetTotalConnections() int

GetTotalConnections returns the total number of connections since startup

func (*Hub) Run

func (h *Hub) Run(ctx context.Context)

Run starts the hub

func (*Hub) Subscribe

func (h *Hub) Subscribe(client *Client, topic string)

Subscribe subscribes a client to a topic

func (*Hub) Unsubscribe

func (h *Hub) Unsubscribe(client *Client, topic string)

Unsubscribe unsubscribes a client from a topic

type Message

type Message struct {
	Type      string      `json:"type"`
	Topic     string      `json:"topic,omitempty"`
	Data      interface{} `json:"data,omitempty"`
	Timestamp time.Time   `json:"timestamp"`
	ClientID  string      `json:"clientId,omitempty"`
}

Message represents a websocket message

type SubscriptionManager

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

SubscriptionManager manages GraphQL subscriptions

func NewSubscriptionManager

func NewSubscriptionManager(hub *Hub, logger *slog.Logger) *SubscriptionManager

NewSubscriptionManager creates a new subscription manager

func (*SubscriptionManager) CreateSubscription

func (sm *SubscriptionManager) CreateSubscription(client *Client, query string, variables map[string]interface{}) (*GraphQLSubscription, error)

CreateSubscription creates a new GraphQL subscription

func (*SubscriptionManager) GetSubscription

func (sm *SubscriptionManager) GetSubscription(subscriptionID string) (*GraphQLSubscription, bool)

GetSubscription returns a subscription by ID

func (*SubscriptionManager) GetSubscriptionsByTopic

func (sm *SubscriptionManager) GetSubscriptionsByTopic(topic string) []*GraphQLSubscription

GetSubscriptionsByTopic returns all subscriptions for a specific topic

func (*SubscriptionManager) RemoveSubscription

func (sm *SubscriptionManager) RemoveSubscription(subscriptionID string)

RemoveSubscription removes a GraphQL subscription

Jump to

Keyboard shortcuts

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