wrapsocket

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	ID string

	Group string
	// contains filtered or unexported fields
}

func NewConn

func NewConn(ws *websocket.Conn) *Conn

func (*Conn) Close

func (c *Conn) Close(code websocket.StatusCode, reason string) error

func (*Conn) GetLastSeen

func (c *Conn) GetLastSeen() time.Time

func (*Conn) GetMetadata

func (c *Conn) GetMetadata(key string) (interface{}, bool)

func (*Conn) IsClosed

func (c *Conn) IsClosed() bool

func (*Conn) SetMetadata

func (c *Conn) SetMetadata(key string, value interface{})

func (*Conn) StartHeartbeat

func (c *Conn) StartHeartbeat(ctx context.Context, config *HeartbeatConfig)

func (*Conn) UpdateLastSeen

func (c *Conn) UpdateLastSeen()

func (*Conn) Write

func (c *Conn) Write(ctx context.Context, msgType websocket.MessageType, data []byte) error

type ConnManager

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

func NewConnManager

func NewConnManager() *ConnManager

func (*ConnManager) Add

func (m *ConnManager) Add(conn *Conn)

func (*ConnManager) Broadcast

func (m *ConnManager) Broadcast(ctx context.Context, msgType websocket.MessageType, data []byte) error

func (*ConnManager) CloseAll

func (m *ConnManager) CloseAll(code websocket.StatusCode, reason string)

func (*ConnManager) Count

func (m *ConnManager) Count() int

func (*ConnManager) Get

func (m *ConnManager) Get(id string) (*Conn, bool)

func (*ConnManager) GetAll

func (m *ConnManager) GetAll() []*Conn

func (*ConnManager) GetByGroup

func (m *ConnManager) GetByGroup(group string) []*Conn

func (*ConnManager) Remove

func (m *ConnManager) Remove(id string)

func (*ConnManager) SendTo

func (m *ConnManager) SendTo(ctx context.Context, connID string, msgType websocket.MessageType, data []byte) error

func (*ConnManager) SendToGroup

func (m *ConnManager) SendToGroup(ctx context.Context, group string, msgType websocket.MessageType, data []byte) error

type DefaultHandler

type DefaultHandler struct {
	ID string
	// contains filtered or unexported fields
}

func (*DefaultHandler) Manager

func (h *DefaultHandler) Manager() *ConnManager

func (*DefaultHandler) ServeHTTP

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

func (*DefaultHandler) SetHeartbeatConfig

func (h *DefaultHandler) SetHeartbeatConfig(config *HeartbeatConfig)

func (*DefaultHandler) SetOnConnect

func (h *DefaultHandler) SetOnConnect(fn func(*Conn))

func (*DefaultHandler) SetOnDisconnect

func (h *DefaultHandler) SetOnDisconnect(fn func(*Conn))

func (*DefaultHandler) SetOnError

func (h *DefaultHandler) SetOnError(fn func(*Conn, error))

func (*DefaultHandler) SetOnMessage

func (h *DefaultHandler) SetOnMessage(fn func(*Conn, *Message))

type Handler

type Handler interface {
	http.Handler

	SetOnConnect(func(*Conn))
	SetOnDisconnect(func(*Conn))
	SetOnMessage(func(*Conn, *Message))
	SetOnError(func(*Conn, error))
	SetHeartbeatConfig(*HeartbeatConfig)
	Manager() *ConnManager
}

func NewDefaultHandler

func NewDefaultHandler(opts *websocket.AcceptOptions) Handler

type Heartbeat

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

func NewHeartbeat

func NewHeartbeat(conn *Conn, config *HeartbeatConfig) *Heartbeat

func (*Heartbeat) LastPong

func (h *Heartbeat) LastPong() time.Time

func (*Heartbeat) MissedCount

func (h *Heartbeat) MissedCount() int

func (*Heartbeat) Start

func (h *Heartbeat) Start(ctx context.Context)

func (*Heartbeat) Stop

func (h *Heartbeat) Stop()

type HeartbeatConfig

type HeartbeatConfig struct {
	Interval  time.Duration
	Timeout   time.Duration
	MaxMissed int
}

func DefaultHeartbeatConfig

func DefaultHeartbeatConfig() *HeartbeatConfig

type Hooks

type Hooks struct {
	OnConnect    func(conn *Conn)
	OnDisconnect func(conn *Conn)
	OnMessage    func(conn *Conn, msg *Message)
	OnError      func(conn *Conn, err error)
}

type Message

type Message struct {
	ID        string                `json:"id"`
	Type      websocket.MessageType `json:"type"`
	Data      []byte                `json:"data"`
	Timestamp time.Time             `json:"timestamp"`
}

func NewMessage

func NewMessage(id string, msgType websocket.MessageType, data []byte) *Message

Jump to

Keyboard shortcuts

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