websocket

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ID       string
	Conn     *websocket.Conn
	Server   *Server
	Send     chan []byte
	Rooms    map[string]bool
	Metadata map[string]interface{}
	// contains filtered or unexported fields
}

Client represents a WebSocket client

func (*Client) JoinRoom

func (c *Client) JoinRoom(room string)

JoinRoom adds the client to a room

func (*Client) LeaveRoom

func (c *Client) LeaveRoom(room string)

LeaveRoom removes the client from a room

func (*Client) SendMessage

func (c *Client) SendMessage(message *Message)

Send sends a message to the client

type Message

type Message struct {
	Type      string                 `json:"type"`
	Room      string                 `json:"room,omitempty"`
	Data      interface{}            `json:"data"`
	From      string                 `json:"from,omitempty"`
	To        string                 `json:"to,omitempty"`
	Meta      map[string]interface{} `json:"meta,omitempty"`
	Timestamp time.Time              `json:"timestamp"`
}

Message represents a WebSocket message

type Server

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

Server manages WebSocket connections

func NewServer

func NewServer() *Server

NewServer creates a new WebSocket server

func (*Server) Broadcast

func (s *Server) Broadcast(message *Message)

Broadcast sends a message to all connected clients

func (*Server) BroadcastToRoom

func (s *Server) BroadcastToRoom(room string, message *Message)

BroadcastToRoom sends a message to all clients in a room

func (*Server) GetClientCount

func (s *Server) GetClientCount() int

GetClientCount returns the number of connected clients

func (*Server) GetClients

func (s *Server) GetClients() []*Client

GetClients returns all connected clients

func (*Server) GetRoomClients

func (s *Server) GetRoomClients(room string) []*Client

GetRoomClients returns all clients in a specific room

func (*Server) GetRoomCount

func (s *Server) GetRoomCount() int

GetRoomCount returns the number of rooms

func (*Server) HandleConnection

func (s *Server) HandleConnection(c *websocket.Conn)

HandleConnection creates a Fiber WebSocket handler

func (*Server) Run

func (s *Server) Run(ctx context.Context)

Run starts the WebSocket server

func (*Server) SendToClient

func (s *Server) SendToClient(clientID string, message *Message)

SendToClient sends a message to a specific client

func (*Server) Upgrade

func (s *Server) Upgrade() fiber.Handler

Upgrade creates a Fiber middleware to upgrade HTTP to WebSocket

func (*Server) Use

func (s *Server) Use(middleware func(*Client) error)

Use adds middleware to the WebSocket server

Jump to

Keyboard shortcuts

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