websocket

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllSendMessages

func AllSendMessages(appId uint32, userId string, data string)

全员广播

func CheckUserOnline

func CheckUserOnline(appId uint32, userId string) (online bool)

查询用户是否在线

func ClearTimeoutConnections

func ClearTimeoutConnections()

定时清理超时连接

func GetAppIds

func GetAppIds() []uint32

func GetManagerInfo

func GetManagerInfo(isDebug string) (managerInfo map[string]interface{})

************************* manager info ************************************** 获取管理者信息

func GetServer

func GetServer() (server *models.Server)

func GetUserKey

func GetUserKey(appId uint32, userId string) (key string)

获取用户key

func GetUserList

func GetUserList() (userList []string)

获取全部用户

func HeartbeatController

func HeartbeatController(client *Client, seq string, message []byte) (code uint32, msg string, data interface{})

心跳接口

func InAppIds

func InAppIds(appId uint32) (inAppId bool)

func IsLocal

func IsLocal(server *models.Server) (isLocal bool)

func LoginController

func LoginController(client *Client, seq string, message []byte) (code uint32, msg string, data interface{})

用户登录

func ProcessData

func ProcessData(client *Client, message []byte)

处理数据

func Register

func Register(key string, value DisposeFunc)

注册

func SendUserMessage

func SendUserMessage(appId uint32, userId string, msgId, message string) (sendResults bool, err error)

给用户发送消息

func SendUserMessageAll

func SendUserMessageAll(appId uint32, userId string, msgId, cmd, message string) (sendResults bool, err error)

给全体用户发消息

func SendUserMessageLocal

func SendUserMessageLocal(appId uint32, userId string, data string) (sendResults bool, err error)

给本机用户发送消息

func StartWebSocket

func StartWebSocket()

启动程序

func UserList

func UserList() (userList []string)

查询所有用户

Types

type Client

type Client struct {
	Addr          string          // 客户端地址
	Socket        *websocket.Conn // 用户连接
	Send          chan []byte     // 待发送的数据
	AppId         uint32          // 登录的平台Id app/web/ios
	UserId        string          // 用户Id,用户登录以后才有
	FirstTime     uint64          // 首次连接事件
	HeartbeatTime uint64          // 用户上次心跳时间
	LoginTime     uint64          // 登录时间 登录以后才有
}

用户连接

func GetUserClient

func GetUserClient(appId uint32, userId string) (client *Client)

获取用户所在的连接

func NewClient

func NewClient(addr string, socket *websocket.Conn, firstTime uint64) (client *Client)

初始化

func (*Client) GetKey

func (c *Client) GetKey() (key string)

读取客户端数据

func (*Client) Heartbeat

func (c *Client) Heartbeat(currentTime uint64)

用户心跳

func (*Client) IsHeartbeatTimeout

func (c *Client) IsHeartbeatTimeout(currentTime uint64) (timeout bool)

心跳超时

func (*Client) IsLogin

func (c *Client) IsLogin() (isLogin bool)

是否登录了

func (*Client) Login

func (c *Client) Login(appId uint32, userId string, loginTime uint64)

用户登录

func (*Client) SendMsg

func (c *Client) SendMsg(msg []byte)

读取客户端数据

type ClientManager

type ClientManager struct {
	Clients     map[*Client]bool   // 全部的连接
	ClientsLock sync.RWMutex       // 读写锁
	Users       map[string]*Client // 登录的用户 // appId+uuid
	UserLock    sync.RWMutex       // 读写锁
	Register    chan *Client       // 连接连接处理
	Login       chan *login        // 用户登录处理
	Unregister  chan *Client       // 断开连接处理程序
	Broadcast   chan []byte        // 广播 向全部成员发送数据
}

连接管理

func NewClientManager

func NewClientManager() (clientManager *ClientManager)

func (*ClientManager) AddClients

func (manager *ClientManager) AddClients(client *Client)

添加客户端

func (*ClientManager) AddUsers

func (manager *ClientManager) AddUsers(key string, client *Client)

添加用户

func (*ClientManager) DelClients

func (manager *ClientManager) DelClients(client *Client)

删除客户端

func (*ClientManager) DelUsers

func (manager *ClientManager) DelUsers(key string)

删除用户

func (*ClientManager) EventLogin

func (manager *ClientManager) EventLogin(login *login)

用户登录

func (*ClientManager) EventRegister

func (manager *ClientManager) EventRegister(client *Client)

用户建立连接事件

func (*ClientManager) EventUnregister

func (manager *ClientManager) EventUnregister(client *Client)

用户断开连接

func (*ClientManager) GetUserClient

func (manager *ClientManager) GetUserClient(appId uint32, userId string) (client *Client)

获取用户的连接

type DisposeFunc

type DisposeFunc func(client *Client, seq string, message []byte) (code uint32, msg string, data interface{})

Jump to

Keyboard shortcuts

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