ws

package
v0.0.0-...-e0866c7 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 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 Hub

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

func NewHub

func NewHub() *Hub

func (*Hub) Add

func (h *Hub) Add(clientId string, wsChan *WsChannal)

func (*Hub) AddGroup

func (h *Hub) AddGroup(groupId string, wsChan *WsChannal)

func (*Hub) All

func (h *Hub) All() []*WsChannal

func (*Hub) Closed

func (h *Hub) Closed() bool

func (*Hub) Del

func (h *Hub) Del(clientId string)

func (*Hub) DelFromGroup

func (h *Hub) DelFromGroup(groupId string, wsChan *WsChannal)

func (*Hub) Get

func (h *Hub) Get(clientId string) *WsChannal

func (*Hub) GetGroup

func (h *Hub) GetGroup(groupId string) []*WsChannal

func (*Hub) Len

func (h *Hub) Len() int

type Msg

type Msg struct {
	WsType int
	Data   []byte `json:"data"`
}

func NewBinaryMsg

func NewBinaryMsg(data []byte) *Msg

func NewMsg

func NewMsg(msType int, data []byte) *Msg

func NewTextMsg

func NewTextMsg(data []byte) *Msg

type WsChannal

type WsChannal struct {
	Conn   *websocket.Conn //socket链接
	Ctx    map[string]any  //上下文
	Output chan *Msg       //写队列

	CloseChan chan byte // 关闭通知
	WsHandler WsHandler //处理器
	// contains filtered or unexported fields
}

func NewWsChannl

func NewWsChannl(conn *websocket.Conn, wsHandler WsHandler, heartbeatEnabled bool, heartbeatDuration time.Duration, heartbeatFailCount uint8) *WsChannal

func (*WsChannal) Close

func (c *WsChannal) Close()

func (*WsChannal) Del

func (wsc *WsChannal) Del(key string)

func (*WsChannal) Get

func (wsc *WsChannal) Get(key string) (value any, exists bool)

func (*WsChannal) GetBool

func (wsc *WsChannal) GetBool(key string) bool

func (*WsChannal) GetId

func (c *WsChannal) GetId() string

func (*WsChannal) GetInt

func (wsc *WsChannal) GetInt(key string) int

func (*WsChannal) GetString

func (wsc *WsChannal) GetString(key string) string

func (*WsChannal) IsClosed

func (wsc *WsChannal) IsClosed() bool

func (*WsChannal) LocalAddr

func (wsc *WsChannal) LocalAddr() net.Addr

func (*WsChannal) MustGet

func (wsc *WsChannal) MustGet(key string) any

func (*WsChannal) RemoteAddr

func (wsc *WsChannal) RemoteAddr() net.Addr

func (*WsChannal) Set

func (wsc *WsChannal) Set(key string, value interface{})

func (*WsChannal) SetId

func (c *WsChannal) SetId(id string)

func (*WsChannal) Write

func (c *WsChannal) Write(msg *Msg) error

type WsConfig

type WsConfig struct {
	CheckOrigin   bool
	PingEnabled   bool
	PingPeriod    time.Duration
	PingFailCount uint8
}

type WsHandler

type WsHandler interface {
	ConnectGin(c *gin.Context)
	Connect(w http.ResponseWriter, r *http.Request)
	Heartbeat(wsc *WsChannal) error
	Send(deviceId string, data []byte) error
	SendToGroup(groupId string, data []byte) error
	Broadcast(data []byte) error
	MsgHandler(wsc *WsChannal, msg *Msg)
	Disconnect(wsc *WsChannal) error
	GetConfig() *WsConfig
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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