websockets

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 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 BroadcastServer

type BroadcastServer interface {
	Subscribe() <-chan Message
	CancelSubscription(<-chan Message)
	Close()
}

func NewBroadcastServer

func NewBroadcastServer(ctx context.Context, source <-chan Message) BroadcastServer

type Client

type Client struct {
	ID        string
	Conn      *websocket.Conn
	Broadcast BroadcastServer
}

type Message

type Message struct {
	ClientID string
	Type     string `json:"type"` // e.g., "command", "response"
	Content  string `json:"content"`
}

type Server

type Server struct {
	Clients    map[string]*Client
	ClientsMux sync.Mutex
}

func NewServer

func NewServer() *Server

func (*Server) HandleClientConnection

func (s *Server) HandleClientConnection(w http.ResponseWriter, r *http.Request)

func (*Server) RemoveClient

func (s *Server) RemoveClient(clientID string)

func (*Server) SendCommand

func (s *Server) SendCommand(clientID string, msg Message) error

func (*Server) SendCommandWithBroadcast

func (s *Server) SendCommandWithBroadcast(clientID string, msg Message) (BroadcastServer, error)

Jump to

Keyboard shortcuts

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