Documentation
¶
Index ¶
- func DecodeSignal(data []byte) (*core.Signal, error)
- func EncodeSignal(signal core.Signal) ([]byte, error)
- func NewInMemoryPair(buffer int) (*InMemoryConn, *InMemoryConn)
- type AcceptConfig
- type Acceptor
- type CoderAcceptor
- type CoderConn
- type CoderDialer
- type Conn
- type ConnHandler
- type Dialer
- type Handler
- type HandlerConfig
- type InMemoryConn
- type InMemoryDialer
- type MessageType
- type ReadLimitConn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeSignal ¶
DecodeSignal unmarshals a signal from JSON bytes.
func EncodeSignal ¶
EncodeSignal marshals a signal to JSON bytes.
func NewInMemoryPair ¶
func NewInMemoryPair(buffer int) (*InMemoryConn, *InMemoryConn)
NewInMemoryPair creates two connected in-memory WebSocket-like endpoints.
Types ¶
type AcceptConfig ¶
AcceptConfig controls how a backend upgrades incoming HTTP requests to WebSocket connections.
type Acceptor ¶
type Acceptor interface {
Accept(w http.ResponseWriter, r *http.Request, cfg AcceptConfig) (Conn, error)
}
Acceptor upgrades inbound HTTP requests into framework connections.
type CoderAcceptor ¶
type CoderAcceptor struct{}
CoderAcceptor upgrades HTTP requests using github.com/coder/websocket.
func NewCoderAcceptor ¶
func NewCoderAcceptor() *CoderAcceptor
NewCoderAcceptor creates the default HTTP WebSocket acceptor.
func (*CoderAcceptor) Accept ¶
func (a *CoderAcceptor) Accept(w http.ResponseWriter, r *http.Request, cfg AcceptConfig) (Conn, error)
type CoderConn ¶
type CoderConn struct {
// contains filtered or unexported fields
}
CoderConn wraps github.com/coder/websocket.Conn to implement the Conn interface.
func NewCoderConn ¶
NewCoderConn creates a new CoderConn from a coder/websocket connection.
func (*CoderConn) SetReadLimit ¶
SetReadLimit sets the maximum message size that can be read. Messages exceeding this limit will cause a read error.
type CoderDialer ¶
type CoderDialer struct{}
CoderDialer implements Dialer using github.com/coder/websocket.
type Conn ¶
type Conn interface {
// Read reads a message from the connection.
// It blocks until a message is available or the context is cancelled.
Read(ctx context.Context) ([]byte, error)
// Write writes a message to the connection.
Write(ctx context.Context, data []byte) error
// Close closes the connection.
Close() error
}
Conn represents a WebSocket connection abstraction. Implementations must be safe for concurrent use.
type ConnHandler ¶
type ConnHandler func(conn Conn)
ConnHandler is a function that handles new WebSocket connections.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler manages WebSocket connections including auth, rate limiting, and message reading.
func NewHandler ¶
func NewHandler(cfg HandlerConfig) *Handler
NewHandler creates a new WebSocket handler.
type HandlerConfig ¶
type HandlerConfig struct {
EnableAuth bool
JWTAuth *auth.JWTAuth
RateLimiter *auth.RateLimiter
MaxMessageSize int64
AllowedOrigins []string
Acceptor Acceptor
OnConnect func(peerID, username, userRole string, conn Conn)
OnDisconnect func(peerID string)
OnMessage func(peerID, username, userRole string, data []byte)
}
HandlerConfig holds configuration for the WebSocket handler.
type InMemoryConn ¶
type InMemoryConn struct {
// contains filtered or unexported fields
}
InMemoryConn is an in-process Conn implementation useful for tests and embedded integrations.
func (*InMemoryConn) Close ¶
func (c *InMemoryConn) Close() error
type InMemoryDialer ¶
type InMemoryDialer struct {
// contains filtered or unexported fields
}
InMemoryDialer returns one side of a prebuilt in-memory pair on each Dial call.
func NewInMemoryDialer ¶
func NewInMemoryDialer(conns ...Conn) *InMemoryDialer
NewInMemoryDialer creates a dialer backed by a fixed queue of in-memory connections.
type MessageType ¶
type MessageType int
MessageType defines WebSocket message types.
const ( TextMessage MessageType = iota + 1 BinaryMessage )
type ReadLimitConn ¶
ReadLimitConn is implemented by connections that support inbound frame limits.