gate

package
v2.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder(opts *Options) *Builder

func (*Builder) Build

func (b *Builder) Build(addr string) (*Client, error)

Build 构建客户端

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cli *client.Client) *Client

func (*Client) Bind

func (c *Client) Bind(ctx context.Context, cid, uid int64) (bool, error)

Bind 绑定用户与连接

func (*Client) Broadcast

func (c *Client) Broadcast(ctx context.Context, kind session.Kind, message buffer.Buffer) error

Broadcast 推送广播消息

func (*Client) Disconnect

func (c *Client) Disconnect(ctx context.Context, kind session.Kind, target int64, force bool) error

Disconnect 断开连接

func (*Client) GetIP

func (c *Client) GetIP(ctx context.Context, kind session.Kind, target int64) (string, bool, error)

GetIP 获取客户端IP

func (*Client) GetState

func (c *Client) GetState(ctx context.Context) (cluster.State, error)

GetState 获取状态

func (*Client) IsOnline

func (c *Client) IsOnline(ctx context.Context, kind session.Kind, target int64) (bool, bool, error)

IsOnline 检测是否在线

func (*Client) Multicast

func (c *Client) Multicast(ctx context.Context, kind session.Kind, targets []int64, message buffer.Buffer) error

Multicast 推送组播消息

func (*Client) Push

func (c *Client) Push(ctx context.Context, kind session.Kind, target int64, message buffer.Buffer) error

Push 异步推送消息

func (*Client) SetState

func (c *Client) SetState(ctx context.Context, state cluster.State) error

SetState 设置状态

func (*Client) Stat

func (c *Client) Stat(ctx context.Context, kind session.Kind) (int64, error)

Stat 推送广播消息

func (*Client) Unbind

func (c *Client) Unbind(ctx context.Context, uid int64) (bool, error)

Unbind 解绑用户与连接

type Options

type Options struct {
	InsID   string       // 实例ID
	InsKind cluster.Kind // 实例类型
}

type Provider

type Provider interface {
	// Bind 绑定用户与网关间的关系
	Bind(ctx context.Context, cid, uid int64) error
	// Unbind 解绑用户与网关间的关系
	Unbind(ctx context.Context, uid int64) error
	// GetIP 获取客户端IP地址
	GetIP(ctx context.Context, kind session.Kind, target int64) (ip string, err error)
	// IsOnline 检测是否在线
	IsOnline(ctx context.Context, kind session.Kind, target int64) (isOnline bool, err error)
	// Stat 统计会话总数
	Stat(ctx context.Context, kind session.Kind) (total int64, err error)
	// Disconnect 断开连接
	Disconnect(ctx context.Context, kind session.Kind, target int64, force bool) error
	// Push 发送消息
	Push(ctx context.Context, kind session.Kind, target int64, message []byte) error
	// Multicast 推送组播消息
	Multicast(ctx context.Context, kind session.Kind, targets []int64, message []byte) (total int64, err error)
	// Broadcast 推送广播消息
	Broadcast(ctx context.Context, kind session.Kind, message []byte) (total int64, err error)
	// GetState 获取状态
	GetState() (cluster.State, error)
	// SetState 设置状态
	SetState(state cluster.State) error
}

type Server

type Server struct {
	*server.Server
	// contains filtered or unexported fields
}

func NewServer

func NewServer(addr string, provider Provider) (*Server, error)

Jump to

Keyboard shortcuts

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