wssvr

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WebsocketServer added in v0.9.0

func WebsocketServer(opts ...WsServerOption) register.RegisterOption

Types

type BroadcastInput added in v0.9.0

type BroadcastInput struct {
	ClientId string
	GroupId  string
	Msg      []byte
}

type BroadcastOutput added in v0.9.0

type BroadcastOutput struct {
	Type   MessageType `json:"type"`
	Value  string      `json:"value"`
	Values []string    `json:"values"`
	Msg    []byte      `json:"msg"`
}

type Client added in v0.9.0

type Client struct {
	ClientId string
	GroupId  string
	// contains filtered or unexported fields
}

func NewClient added in v0.9.0

func NewClient(uid, groupId string, hub *WsServer, w http.ResponseWriter, r *http.Request) (*Client, error)

func (*Client) Close added in v0.9.2

func (c *Client) Close()

func (*Client) Start added in v0.9.0

func (c *Client) Start()

type Config added in v0.9.0

type Config struct {
	Name              string
	WriteWait         time.Duration
	PongWait          time.Duration
	PingPeriod        time.Duration
	MaxMessageSize    int64
	ReadBufferSize    int64
	WriteBufferSize   int64
	MaxMsgChannelSize int64
}

type MessageBox added in v0.9.0

type MessageBox struct {
	Title struct {
		SysMsg int    `json:"sys_msg"`
		Source string `json:"source"`
		Target string `json:"target"`
	} `json:"title"`
	Body string `json:"body"`
}

前端约定的消息实体

type MessageType added in v0.9.0

type MessageType string
var (
	MessageAll     MessageType = "all"     // 全局消息
	MessageGroup   MessageType = "room"    // 房间消息
	MessageClient  MessageType = "client"  // 单点客户端消息
	MessageClients MessageType = "clients" // 一组客户目标消息
	MessageSys     MessageType = "sys"     // 系统消息
)

type WsServer added in v0.9.0

type WsServer struct {
	WriteWait         time.Duration `toml:"write_wait"`
	PongWait          time.Duration `toml:"pong_wait"`
	PingPeriod        time.Duration `toml:"ping_period"`
	ReadBufferSize    int64         `toml:"read_buffer_size"`
	WriteBufferSize   int64         `toml:"write_buffer_size"`
	MaxMessageSize    int64         `toml:"max_message_size"`
	MaxMsgChannelSize int64         `toml:"max_msg_channel_size"`
	// contains filtered or unexported fields
}
var (
	WsSvc *WsServer
)

func (*WsServer) ExitRoom added in v0.9.0

func (ws *WsServer) ExitRoom(uid, groupId string) error

func (*WsServer) JoinRoom added in v0.9.0

func (ws *WsServer) JoinRoom(uid, groupId string) error

func (*WsServer) Name added in v0.9.0

func (ws *WsServer) Name() string

func (*WsServer) Ready added in v0.9.0

func (ws *WsServer) Ready()

func (*WsServer) SendMessage added in v0.9.6

func (ws *WsServer) SendMessage(uid string, targets []string, msg string)

func (*WsServer) Start added in v0.9.0

func (ws *WsServer) Start(ctx context.Context) error

func (*WsServer) Watch added in v0.9.5

func (ws *WsServer) Watch() map[string]int

type WsServerOption added in v0.9.0

type WsServerOption func(*WsServer)

func SetWsConfig added in v0.9.0

func SetWsConfig(cfgs ...Config) WsServerOption

func SetWsName added in v0.9.0

func SetWsName(name string) WsServerOption

Jump to

Keyboard shortcuts

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