websocket

package
v2.0.50 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: MIT Imports: 10 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
}

Manager 初始化 wsManager 管理器

Functions

func SendAll

func SendAll(msg []byte)

SendAll 广播

func SendGroup

func SendGroup(msg []byte)

SendGroup 组播

func SendOne

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

SendOne 单播

func WsLogout

func WsLogout(id string, group string)

WsLogout 登出

Types

type BroadCastMessageData

type BroadCastMessageData struct {
	Message []byte
}

BroadCastMessageData 广播发送数据信息

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)

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

func (*Client) Write

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

Write 写信息,从 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{}

Info 获取 wsManager 管理器信息

func (*Manager) LenClient

func (manager *Manager) LenClient() uint

LenClient 当前连接个数

func (*Manager) LenGroup

func (manager *Manager) LenGroup() uint

LenGroup 当前组个数

func (*Manager) RegisterClient

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

RegisterClient 注册

func (*Manager) Send

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

Send 向指定的 client 发送数据

func (*Manager) SendAll

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

SendAll 广播

func (*Manager) SendAllService

func (manager *Manager) SendAllService()

SendAllService 处理广播数据

func (*Manager) SendGroup

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

SendGroup 向指定的 Group 广播

func (*Manager) SendGroupService

func (manager *Manager) SendGroupService()

SendGroupService 处理 group 广播数据

func (*Manager) SendService

func (manager *Manager) SendService()

SendService 处理单个 client 发送数据

func (*Manager) Start

func (manager *Manager) Start()

Start 启动 websocket 管理器

func (*Manager) UnRegisterClient

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

UnRegisterClient 注销

func (*Manager) UnWsClient

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

UnWsClient 注销

func (*Manager) WsClient

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

WsClient 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