wksdk

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DISCONNECTED = ConnectStatus(iota)
	CONNECTED
	CLOSED
	RECONNECTING
	CONNECTING
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

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

NewClient creates a new client. addr is the address of the server. example: "tcp://localhost:5100"

func (*Client) Connect

func (c *Client) Connect() error

Connect connects to the server.

func (*Client) Disconnect

func (c *Client) Disconnect() error

Disconnect disconnects from the server.

func (*Client) OnConnect

func (c *Client) OnConnect(listener listenerConnFnc)

func (*Client) OnMessage

func (c *Client) OnMessage(listener listenerMsgFnc)

func (*Client) SendMessage

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

SendMessage sends a message to the server.

type ConnectStatus

type ConnectStatus int

Status represents the state of the connection.

func (ConnectStatus) String

func (s ConnectStatus) String() string

type Message

type Message struct {
	wkproto.RecvPacket
	Ack func() error
}

type Option

type Option func(opt *Options)

func WithAutoAck

func WithAutoAck(autoAck bool) Option

func WithConnectTimeout

func WithConnectTimeout(timeout time.Duration) Option

func WithPingInterval

func WithPingInterval(interval time.Duration) Option

func WithProtoVersion

func WithProtoVersion(version int) Option

func WithReconnect

func WithReconnect(reconnect bool) Option

func WithToken

func WithToken(token string) Option

func WithUID

func WithUID(uid string) Option

type Options

type Options struct {
	UID            string
	Token          string
	ConnectTimeout time.Duration // 连接超时

	ProtoVersion int
	PingInterval time.Duration // 心跳间隔
	Reconnect    bool          // 是否自动重连
	AutoAck      bool          // 是否自动ack
	// contains filtered or unexported fields
}

func NewOptions

func NewOptions() *Options

NewOptions creates a new options.

type SendOption

type SendOption func(*SendOptions) error

SendOption 参数项

func SendOptionWithClientMsgNo

func SendOptionWithClientMsgNo(clientMsgNo string) SendOption

SendOptionWithClientMsgNo 是否显示红点

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
	RedDot      bool // 是否显示红点 默认true
	NoEncrypt   bool // 是否不需要加密
	ClientMsgNo string
}

SendOptions SendOptions

func NewSendOptions

func NewSendOptions() *SendOptions

NewSendOptions NewSendOptions

Jump to

Keyboard shortcuts

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