websocket

package
v0.0.0-...-d296f3d Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNeedReconnect  = NewWSError(errCodeConnNeedReconnect, "need reconnect")
	ErrInvalidSession = NewWSError(errCodeConnNeedReIdentify, "invalid session")
)
View Source
var DefaultHandlers struct {
	ATMessage ATMessageEventHandler
}

DefaultHandlers 默认的 websocket event handler

Functions

func IsNeedPanicError

func IsNeedPanicError(err error) bool

func IsNeedReIdentifyError

func IsNeedReIdentifyError(err error) bool

func IsNeedReconnectError

func IsNeedReconnectError(err error) bool

func NewWSError

func NewWSError(code int, text string) error

func RegisterHandlers

func RegisterHandlers(handlers ...interface{}) dto.Intent

RegisterHandlers 注册事件处理 handler

Types

type ATMessageEventHandler

type ATMessageEventHandler func(event *dto.WSPayload, data *dto.WSATMessageData) error

ATMessageEventHandler at 机器人消息事件 handler

type WSClient

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

func NewWSClient

func NewWSClient(session *dto.WSSession) *WSClient

func (*WSClient) Close

func (c *WSClient) Close()

Close 关闭链接

func (*WSClient) Connect

func (c *WSClient) Connect() error

Connect 建立 websocket 链接

func (*WSClient) Identify

func (c *WSClient) Identify() error

Identify 对链接进行鉴权

func (*WSClient) Listening

func (c *WSClient) Listening() error

Listening 已阻塞的形式开始监听 websocket 的所有事件

func (*WSClient) Resume

func (c *WSClient) Resume() error

Resume 重连

func (*WSClient) SendMessage

func (c *WSClient) SendMessage(message *dto.WSPayload) error

SendMessage 消息发送

type WSError

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

func (WSError) Code

func (e WSError) Code() int

func (WSError) Error

func (e WSError) Error() string

func (WSError) Text

func (e WSError) Text() string

type WSManager

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

WSManager 用于启动和管理 websocket 链接

func NewWSManager

func NewWSManager() *WSManager

func (*WSManager) Start

func (m *WSManager) Start(wsAp *dto.WSAccessPoint, token *token.Token, intent dto.Intent) error

Jump to

Keyboard shortcuts

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