gate

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: LGPL-2.1 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Get = definePlugin.Get

Get 获取插件

View Source
var Name = definePlugin.Name

Name 插件名称

View Source
var TryGet = definePlugin.TryGet

TryGet 尝试获取插件

Functions

This section is empty.

Types

type Gate

type Gate interface {
	SessionManager
	GroupManager
	// Broadcast 广播数据
	Broadcast(data []byte) error
	// Multicast 组播数据
	Multicast(groupId string, data []byte) error
	// Unicast 单播数据
	Unicast(sessionId string, data []byte) error
}

Gate 网关

type Group

type Group interface {
	// GetId 获取会话组Id
	GetId() string
	// RangeSessions 遍历组内所有会话
	RangeSessions(fun func(session Session) bool)
	// CountSessions 统计组内所有会话数量
	CountSessions() int
}

Group 客户端会话组

type GroupManager

type GroupManager interface {
	// RangeGroups 遍历所有组
	RangeGroups(fun func(group Group) bool)
	// CountGroups 统计所有会话组数量
	CountGroups() int
}

GroupManager 会话组管理器

type RecvData

type RecvData struct {
	Data      []byte // 数据
	Sequenced bool   // 是否有时序
	Error     error  // 错误信息
}

RecvData 接收的数据

type RecvDataHandler

type RecvDataHandler = func(session Session, data []byte, sequenced bool) error // 会话接收的数据的处理器

type RecvEvent

type RecvEvent struct {
	Event protocol.Event[transport.Msg] // 消息事件
	Error error                         // 错误信息
}

RecvEvent 接收的自定义事件

type RecvEventHandler

type RecvEventHandler = func(session Session, event protocol.Event[transport.Msg]) error // 会话接收的自定义事件的处理器

type Session

type Session interface {
	context.Context
	fmt.Stringer
	// GetId 获取会话Id
	GetId() string
	// GetToken 获取token
	GetToken() string
	// GetState 获取会话状态
	GetState() SessionState
	// GetGroups 获取所属的会话组Id
	GetGroups() []string
	// GetListenAddr 获取监听地址
	GetListenAddr() net.Addr
	// GetClientAddr 获取客户端地址
	GetClientAddr() net.Addr
	// SendData 发送数据
	SendData(data []byte, sequenced bool) error
	// SendEvent 发送自定义事件
	SendEvent(event protocol.Event[transport.Msg]) error
	// RecvDataChan 接收数据的chan
	RecvDataChan() <-chan RecvData
	// RecvEventChan 接收自定义事件的chan
	RecvEventChan() <-chan RecvEvent
	// Close 关闭
	Close(err error)
}

Session 客户端会话

type SessionManager

type SessionManager interface {
	// RangeSessions 遍历所有会话
	RangeSessions(fun func(session Session) bool)
	// CountSessions 统计所有会话数量
	CountSessions() int
}

SessionManager 会话管理器

type SessionSetting

type SessionSetting interface {
	// InitStateChangedHandlers 设置接收会话状态变化的处理器
	InitStateChangedHandlers(handlers []StateChangedHandler) error
	// InitRecvDataHandlers 设置接收数据的处理器
	InitRecvDataHandlers(handlers []RecvDataHandler) error
	// InitRecvEventHandlers 设置接收自定义事件的处理器
	InitRecvEventHandlers(handlers []RecvEventHandler) error
	// InitRecvDataChanSize 设置接收数据的chan的大小,<=0表示不使用chan
	InitRecvDataChanSize(size int) error
	// InitRecvEventSize 设置自定义事件的chan的大小,<=0表示不使用chan
	InitRecvEventSize(size int) error
}

SessionSetting 会话设置接口(在会话状态为握手中时可用)

type SessionState

type SessionState int32

SessionState 客户端会话状态

const (
	SessionState_Birth     SessionState = iota // 出生
	SessionState_Handshake                     // 与客户端握手中
	SessionState_Active                        // 活跃,客户端已连接
	SessionState_Inactive                      // 不活跃,客户端已断连,等待重连恢复中
	SessionState_Death                         // 已过期
)

type StateChangedHandler

type StateChangedHandler = func(session Session, old, new SessionState) // 会话状态变化的处理器

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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