wsconn

package
v1.1.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetFrameInterceptor

func SetFrameInterceptor(i FrameInterceptor)

SetFrameInterceptor wires the plugin hook chain into every WebSocket connection. It must be called once at startup, before connections arrive.

Types

type ConnInfo

type ConnInfo struct {
	ID         int64
	Path       string
	RemoteIP   string
	UserAgent  string
	ClientUUID string
}

ConnInfo describes one WebSocket connection passed to interceptor callbacks. ID matches the owning SafeConn.

type FrameInterceptor

type FrameInterceptor interface {
	// OnConnect runs right after the upgrade. A denied connection is closed
	// by the caller; plugins bear the consequences of rejecting endpoints
	// such as /api/rpc2.
	OnConnect(info *ConnInfo) (deny bool, reason string)
	// OnMessage inspects one inbound frame; OnSend one outbound frame. They
	// return the possibly replaced payload and whether the frame is dropped.
	OnMessage(info *ConnInfo, frameType int, data []byte) (newType int, newData []byte, drop bool)
	OnSend(info *ConnInfo, frameType int, data []byte) (newType int, newData []byte, drop bool)
	// OnClose notifies that the connection ended.
	OnClose(info *ConnInfo)
}

FrameInterceptor is the optional hook chain around WebSocket connections and frames. The provider is wired once at startup by internal/app (the plugin manager); a nil interceptor leaves every connection untouched.

func Interceptor

func Interceptor() FrameInterceptor

Interceptor returns the process-wide frame interceptor, or nil when no provider is wired.

type SafeConn

type SafeConn struct {
	ID int64
	// contains filtered or unexported fields
}

SafeConn wraps a websocket connection with a mutex so concurrent writes cannot interleave frames, and funnels every frame through the optional plugin interceptor when one is attached.

func NewSafeConn

func NewSafeConn(conn *websocket.Conn) *SafeConn

func (*SafeConn) Close

func (sc *SafeConn) Close() error

func (*SafeConn) GetConn

func (sc *SafeConn) GetConn() *websocket.Conn

GetConn returns the underlying connection. Safe without locking: conn is set once at construction and never reassigned.

func (*SafeConn) ReadJSON

func (sc *SafeConn) ReadJSON(v any) error

func (*SafeConn) ReadMessage

func (sc *SafeConn) ReadMessage() (int, []byte, error)

func (*SafeConn) SetCloseHandler

func (sc *SafeConn) SetCloseHandler(h func(code int, text string) error)

SetCloseHandler forwards to the underlying connection (used by the terminal sessions to clean up on close).

func (*SafeConn) SetInterceptor

func (sc *SafeConn) SetInterceptor(info *ConnInfo, interceptor FrameInterceptor)

SetInterceptor attaches the hook provider and the connection identity. It must be called before any frame is read or written.

func (*SafeConn) SetReadDeadline

func (sc *SafeConn) SetReadDeadline(t time.Time) error

func (*SafeConn) WriteJSON

func (sc *SafeConn) WriteJSON(v any) error

WriteJSON encodes v then sends it as one text frame through the wsSend hook chain.

func (*SafeConn) WriteMessage

func (sc *SafeConn) WriteMessage(messageType int, data []byte) error

Jump to

Keyboard shortcuts

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