client

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DISCONNECTED = Status(iota)
	CONNECTED
	CLOSED
	RECONNECTING
	CONNECTING
)
View Source
const (
	STALE_CONNECTION = "stale connection"
)

Variables

View Source
var (
	ErrStaleConnection  = errors.New("wukongim " + STALE_CONNECTION)
	ErrNoServers        = errors.New("wukongim no servers available for connection")
	ErrBadTimeout       = errors.New("wukongim timeout invalid")
	ErrConnectionClosed = errors.New("wukongim connection closed")
	ErrTimeout          = errors.New("wukongim timeout")
)

Functions

This section is empty.

Types

type Channel

type Channel struct {
	ChannelID   string
	ChannelType uint8
}

Channel Channel

func NewChannel

func NewChannel(channelID string, channelType uint8) *Channel

NewChannel 创建频道

type Client

type Client struct {
	Statistics
	wklog.Log
	// contains filtered or unexported fields
}

func New

func New(addr string, opt ...Option) *Client

func (*Client) Close

func (c *Client) Close()

func (*Client) Connect

func (c *Client) Connect() error

Connect 连接到IM

func (*Client) Flush

func (c *Client) Flush() error

Flush will perform a round trip to the server and return when it receives the internal reply.

func (*Client) FlushTimeout

func (c *Client) FlushTimeout(timeout time.Duration) (err error)

FlushTimeout allows a Flush operation to have an associated timeout.

func (*Client) SendMessage

func (c *Client) SendMessage(channel *Channel, payload []byte, opt ...SendOption) error

func (*Client) SetOnRecv

func (c *Client) SetOnRecv(onRecv OnRecv)

SetOnRecv 设置收消息事件

func (*Client) SetOnSendack

func (c *Client) SetOnSendack(onSendack OnSendack)

type OnRecv

type OnRecv func(recv *wkproto.RecvPacket) error

OnRecv 收到消息事件

type OnSendack

type OnSendack func(sendackPacket *wkproto.SendackPacket)

type Option

type Option func(*Options) error

Option 参数项

func WithAutoReconn

func WithAutoReconn(autoReconn bool) Option

WithAutoReconn WithAutoReconn

func WithProtoVersion

func WithProtoVersion(version uint8) Option

WithProtoVersion 设置协议版本

func WithToken

func WithToken(token string) Option

WithToken 用户token

func WithUID

func WithUID(uid string) Option

WithUID 用户UID

type Options

type Options struct {
	ProtoVersion   uint8  // 协议版本
	UID            string // 用户uid
	Token          string // 连接IM的token
	AutoReconn     bool   //是否开启自动重连
	DefaultBufSize int    // The size of the bufio reader/writer on top of the socket.

	// ReconnectBufSize is the size of the backing bufio during reconnect.
	// Once this has been exhausted publish operations will return an error.
	// Defaults to 8388608 bytes (8MB).
	ReconnectBufSize int

	// FlusherTimeout is the maximum time to wait for write operations
	// to the underlying connection to complete (including the flusher loop).
	FlusherTimeout time.Duration

	// Timeout sets the timeout for a Dial operation on a connection.
	Timeout time.Duration

	PingInterval time.Duration

	MaxPingCount int // 最大ping的次数

	// ReconnectJitter sets the upper bound for a random delay added to
	// ReconnectWait during a reconnect when no TLS is used.
	ReconnectJitter time.Duration

	// ReconnectWait sets the time to backoff after attempting a reconnect
	// to a server that we were already connected to previously.
	ReconnectWait time.Duration
}

Options Options

func NewOptions

func NewOptions() *Options

NewOptions 创建默认配置

type SendOption

type SendOption func(*SendOptions) error

SendOption 参数项

func SendOptionWithClientMsgNo

func SendOptionWithClientMsgNo(clientMsgNo string) SendOption

SendOptionWithClientMsgNo 是否显示红点

func SendOptionWithFlush

func SendOptionWithFlush(flush bool) SendOption

SendOptionWithFlush 是否 io flush

func SendOptionWithNoEncrypt

func SendOptionWithNoEncrypt(noEncrypt bool) SendOption

SendOptionWithNoEncrypt 是否不需要加密

func SendOptionWithNoPersist

func SendOptionWithNoPersist(noPersist bool) SendOption

SendOptionWithNoPersist 是否不存储

func SendOptionWithRedDot

func SendOptionWithRedDot(redDot bool) SendOption

SendOptionWithRedDot 是否显示红点

func SendOptionWithSyncOnce

func SendOptionWithSyncOnce(syncOnce bool) SendOption

SendOptionWithSyncOnce 是否只同步一次(写模式)

type SendOptions

type SendOptions struct {
	NoPersist   bool // 是否不存储 默认 false
	SyncOnce    bool // 是否同步一次(写模式) 默认 false
	Flush       bool // 是否io flush 默认true
	RedDot      bool // 是否显示红点 默认true
	NoEncrypt   bool // 是否不需要加密
	ClientMsgNo string
}

SendOptions SendOptions

func NewSendOptions

func NewSendOptions() *SendOptions

NewSendOptions NewSendOptions

type Statistics

type Statistics struct {
	InMsgs     atomic.Uint64
	OutMsgs    atomic.Uint64
	InBytes    atomic.Uint64
	OutBytes   atomic.Uint64
	Reconnects atomic.Uint64
}

type Status

type Status int

Status represents the state of the connection.

func (Status) String

func (s Status) String() string

Jump to

Keyboard shortcuts

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