gate

package
v2.6.4 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 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 *ClientOptions) *Builder

func (*Builder) Build

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

Build returns a client for addr, reusing a cached client when one already exists.

type Client

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

func NewClient

func NewClient(cli *drpc.Client) *Client

func (*Client) Bind

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

Bind binds the connection cid and user uid together.

func (*Client) Broadcast

func (c *Client) Broadcast(ctx context.Context, kind session.Kind, disconnect bool, buf buffer.Buffer, ack bool) (int64, error)

Broadcast pushes a message to all sessions. When ack is true it waits for the response and returns the number of sessions that received the message.

func (*Client) Disconnect

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

Disconnect disconnects the target session.

func (*Client) GetIP

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

GetIP returns the client IP of the target session.

func (*Client) GetState

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

GetState returns the state of the gate.

func (*Client) IsOnline

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

IsOnline reports whether the target session is online.

func (*Client) Multicast

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

Multicast pushes a message to multiple targets. When ack is true it waits for the response and returns the number of targets that received the message.

func (*Client) Publish added in v2.3.0

func (c *Client) Publish(ctx context.Context, channel string, disconnect bool, buf buffer.Buffer, ack bool) (int64, error)

Publish publishes a message to a channel. When ack is true it waits for the response and returns the number of sessions that received the message.

func (*Client) Push

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

Push pushes a message to the target. When ack is true it waits for the response.

func (*Client) SetState

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

SetState sets the state of the gate.

func (*Client) Stat

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

Stat returns the total number of sessions of the given kind.

func (*Client) Subscribe added in v2.3.0

func (c *Client) Subscribe(ctx context.Context, kind session.Kind, targets []int64, channel string) error

Subscribe subscribes the targets to a channel.

func (*Client) Unbind

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

Unbind unbinds the user from its connection.

func (*Client) Unsubscribe added in v2.3.0

func (c *Client) Unsubscribe(ctx context.Context, kind session.Kind, targets []int64, channel string) error

Unsubscribe unsubscribes the targets from a channel.

type ClientOptions added in v2.5.4

type ClientOptions = drpc.ClientOptions

type Provider

type Provider interface {
	// Bind binds the relationship between the user and the gate.
	Bind(ctx context.Context, cid, uid int64) error
	// Unbind unbinds the relationship between the user and the gate.
	Unbind(ctx context.Context, uid int64) error
	// GetIP returns the client IP address.
	GetIP(ctx context.Context, kind session.Kind, target int64) (ip string, err error)
	// IsOnline reports whether the target is online.
	IsOnline(ctx context.Context, kind session.Kind, target int64) (isOnline bool, err error)
	// Stat returns the total number of sessions.
	Stat(ctx context.Context, kind session.Kind) (total int64, err error)
	// Disconnect disconnects the target session.
	Disconnect(ctx context.Context, kind session.Kind, target int64, force bool) error
	// Push sends a message.
	Push(ctx context.Context, kind session.Kind, target int64, disconnect bool, buf buffer.Buffer) error
	// Multicast pushes a multicast message.
	Multicast(ctx context.Context, kind session.Kind, targets []int64, disconnect bool, buf buffer.Buffer) (total int64, err error)
	// Broadcast pushes a broadcast message.
	Broadcast(ctx context.Context, kind session.Kind, disconnect bool, buf buffer.Buffer) (total int64, err error)
	// Publish publishes a channel message.
	Publish(ctx context.Context, channel string, disconnect bool, buf buffer.Buffer) (total int64, err error)
	// Subscribe subscribes to channels.
	Subscribe(ctx context.Context, kind session.Kind, targets []int64, channel string) error
	// Unsubscribe unsubscribes from channels.
	Unsubscribe(ctx context.Context, kind session.Kind, targets []int64, channel string) error
	// GetState returns the state.
	GetState() (cluster.State, error)
	// SetState sets the state.
	SetState(state cluster.State) error
}

type Server

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

func NewServer

func NewServer(provider Provider, opts *ServerOptions) (*Server, error)

type ServerOptions added in v2.3.0

type ServerOptions = drpc.ServerOptions

Jump to

Keyboard shortcuts

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