ws

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WebsocketManager = Manager{
	Group:            make(map[string]map[string]*Client),
	Register:         make(chan *Client, 128),
	UnRegister:       make(chan *Client, 128),
	GroupMessage:     make(chan *GroupMessageData, 128),
	Message:          make(chan *MessageData, 128),
	BroadCastMessage: make(chan *BroadCastMessageData, 128),
	// contains filtered or unexported fields
}

初始化 wsManager 管理器

Functions

func SendAll

func SendAll(msg []byte)

func SendGroup

func SendGroup(msg []byte)

func SendOne

func SendOne(ctx context.Context, id string, group string, msg []byte)

func WsLogout

func WsLogout(id string, group string)

Types

type BroadCastMessageData

type BroadCastMessageData struct {
	Message []byte
}

广播发送数据信息

type Client

type Client struct {
	Id, Group  string
	Context    context.Context
	CancelFunc context.CancelFunc
	Socket     *websocket.Conn
	Message    chan []byte
}

Client 单个 websocket 信息

func (*Client) Read

func (c *Client) Read(cxt context.Context)

读信息,从 websocket 连接直接读取数据

func (*Client) Write

func (c *Client) Write(cxt context.Context)

写信息,从 channel 变量 Send 中读取数据写入 websocket 连接

type GroupMessageData

type GroupMessageData struct {
	Group   string
	Message []byte
}

groupMessageData 组广播数据信息

type Manager

type Manager struct {
	Group map[string]map[string]*Client

	Lock                 sync.Mutex
	Register, UnRegister chan *Client
	Message              chan *MessageData
	GroupMessage         chan *GroupMessageData
	BroadCastMessage     chan *BroadCastMessageData
	// contains filtered or unexported fields
}

Manager 所有 websocket 信息

func (*Manager) Info

func (manager *Manager) Info() map[string]interface{}

获取 wsManager 管理器信息

func (*Manager) LenClient

func (manager *Manager) LenClient() uint

当前连接个数

func (*Manager) LenGroup

func (manager *Manager) LenGroup() uint

当前组个数

func (*Manager) RegisterClient

func (manager *Manager) RegisterClient(client *Client)

注册

func (*Manager) Send

func (manager *Manager) Send(cxt context.Context, id string, group string, message []byte)

向指定的 client 发送数据

func (*Manager) SendAll

func (manager *Manager) SendAll(message []byte)

广播

func (*Manager) SendAllService

func (manager *Manager) SendAllService()

处理广播数据

func (*Manager) SendGroup

func (manager *Manager) SendGroup(group string, message []byte)

向指定的 Group 广播

func (*Manager) SendGroupService

func (manager *Manager) SendGroupService()

处理 group 广播数据

func (*Manager) SendService

func (manager *Manager) SendService()

处理单个 client 发送数据

func (*Manager) Start

func (manager *Manager) Start()

启动 websocket 管理器

func (*Manager) UnRegisterClient

func (manager *Manager) UnRegisterClient(client *Client)

注销

func (*Manager) UnWsClient

func (manager *Manager) UnWsClient(c *gin.Context)

func (*Manager) WsClient

func (manager *Manager) WsClient(c *gin.Context)

gin 处理 websocket handler

type MessageData

type MessageData struct {
	Id, Group string
	Context   context.Context
	Message   []byte
}

messageData 单个发送数据信息

Jump to

Keyboard shortcuts

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