interaction

package
v3.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WebSocket = iota
	Tcp
)
View Source
const (
	// MessageText is for UTF-8 encoded text messages like JSON.
	MessageText = iota + 1
	// MessageBinary is for binary messages like protobufs.
	MessageBinary
	// CloseMessage denotes a close control message. The optional message
	// payload contains a numeric code and text. Use the FormatCloseMessage
	// function to format a close message payload.
	CloseMessage = 8

	// PingMessage denotes a ping control message. The optional message payload
	// is UTF-8 encoded text.
	PingMessage = 9

	// PongMessage denotes a pong control message. The optional message payload
	// is UTF-8 encoded text.
	PongMessage = 10
)
View Source
const (
	DefaultNotConnect = iota
	Closed            = iota + 1
	Connecting
	Connected
)
View Source
const (
	SplitPullMsgNum = 100
)

Variables

View Source
var (
	ErrChanClosed                = errors.New("send channel closed")
	ErrConnClosed                = errors.New("conn has closed")
	ErrNotSupportMessageProtocol = errors.New("not support message protocol")
	ErrClientClosed              = errors.New("client actively close the connection")
	ErrPanic                     = errors.New("panic error")
)

Functions

func GenMsgIncr

func GenMsgIncr(userID string) string

func IsNotification

func IsNotification(conversationID string) bool

Types

type Compressor

type Compressor interface {
	Compress(rawData []byte) ([]byte, error)
	DeCompress(compressedData []byte) ([]byte, error)
}

type ConnContext

type ConnContext struct {
	RemoteAddr string
}

func (*ConnContext) Deadline

func (c *ConnContext) Deadline() (deadline time.Time, ok bool)

func (*ConnContext) Done

func (c *ConnContext) Done() <-chan struct{}

func (*ConnContext) Err

func (c *ConnContext) Err() error

func (*ConnContext) Value

func (c *ConnContext) Value(key any) any

type Default

type Default struct {
	ConnType int
	// contains filtered or unexported fields
}

func NewWebSocket

func NewWebSocket(connType int) *Default

func (*Default) Close

func (d *Default) Close() error

func (*Default) Dial

func (d *Default) Dial(urlStr string, requestHeader http.Header) (*http.Response, error)

func (*Default) IsNil

func (d *Default) IsNil() bool

func (*Default) LocalAddr

func (d *Default) LocalAddr() string

func (*Default) ReadMessage

func (d *Default) ReadMessage() (int, []byte, error)

func (*Default) SetPongHandler

func (d *Default) SetPongHandler(handler PongHandler)

func (*Default) SetReadDeadline

func (d *Default) SetReadDeadline(timeout time.Duration) error

func (*Default) SetReadLimit

func (d *Default) SetReadLimit(limit int64)

func (*Default) SetWriteDeadline

func (d *Default) SetWriteDeadline(timeout time.Duration) error

func (*Default) WriteMessage

func (d *Default) WriteMessage(messageType int, message []byte) error

type Encoder

type Encoder interface {
	Encode(data interface{}) ([]byte, error)
	Decode(encodeData []byte, decodeData interface{}) error
}

type ExponentialRetry added in v3.5.0

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

func NewExponentialRetry added in v3.5.0

func NewExponentialRetry() *ExponentialRetry

func (*ExponentialRetry) GetSleepInterval added in v3.5.0

func (rs *ExponentialRetry) GetSleepInterval() time.Duration

func (*ExponentialRetry) Reset added in v3.5.0

func (rs *ExponentialRetry) Reset()

type GeneralWsReq

type GeneralWsReq struct {
	ReqIdentifier int    `json:"reqIdentifier"`
	Token         string `json:"token"`
	SendID        string `json:"sendID"`
	OperationID   string `json:"operationID"`
	MsgIncr       string `json:"msgIncr"`
	Data          []byte `json:"data"`
}

type GeneralWsResp

type GeneralWsResp struct {
	ReqIdentifier int    `json:"reqIdentifier"`
	ErrCode       int    `json:"errCode"`
	ErrMsg        string `json:"errMsg"`
	MsgIncr       string `json:"msgIncr"`
	OperationID   string `json:"operationID"`
	Data          []byte `json:"data"`
}

type GobEncoder

type GobEncoder struct {
}

func NewGobEncoder

func NewGobEncoder() *GobEncoder

func (*GobEncoder) Decode

func (g *GobEncoder) Decode(encodeData []byte, decodeData interface{}) error

func (*GobEncoder) Encode

func (g *GobEncoder) Encode(data interface{}) ([]byte, error)

type GzipCompressor

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

func NewGzipCompressor

func NewGzipCompressor() *GzipCompressor

func (*GzipCompressor) Compress

func (g *GzipCompressor) Compress(rawData []byte) ([]byte, error)

func (*GzipCompressor) DeCompress

func (g *GzipCompressor) DeCompress(compressedData []byte) ([]byte, error)

type LongConn

type LongConn interface {
	//Close this connection
	Close() error
	// WriteMessage Write message to connection,messageType means data type,can be set binary(2) and text(1).
	WriteMessage(messageType int, message []byte) error
	// ReadMessage Read message from connection.
	ReadMessage() (int, []byte, error)
	// SetReadDeadline sets the read deadline on the underlying network connection,
	//after a read has timed out, will return an error.
	SetReadDeadline(timeout time.Duration) error
	// SetWriteDeadline sets to write deadline when send message,when read has timed out,will return error.
	SetWriteDeadline(timeout time.Duration) error
	// Dial Try to dial a connection,url must set auth args,header can control compress data
	Dial(urlStr string, requestHeader http.Header) (*http.Response, error)
	// IsNil Whether the connection of the current long connection is nil
	IsNil() bool
	// SetReadLimit sets the maximum size for a message read from the peer.bytes
	SetReadLimit(limit int64)
	SetPongHandler(handler PongHandler)
	// LocalAddr returns the local network address.
	LocalAddr() string
}

type LongConnMgr

type LongConnMgr struct {
	IsCompression bool
	Syncer        *WsRespAsyn

	IsBackground bool
	// contains filtered or unexported fields
}

func NewLongConnMgr

func NewLongConnMgr(ctx context.Context, listener open_im_sdk_callback.OnConnListener, heartbeatCmdCh, pushMsgAndMaxSeqCh, loginMgrCh chan common.Cmd2Value) *LongConnMgr

func (*LongConnMgr) Close

func (c *LongConnMgr) Close(ctx context.Context)

func (*LongConnMgr) GetBackground added in v3.5.0

func (c *LongConnMgr) GetBackground() bool

func (*LongConnMgr) GetConnectionStatus

func (c *LongConnMgr) GetConnectionStatus() int

func (*LongConnMgr) IsConnected

func (c *LongConnMgr) IsConnected() bool

func (*LongConnMgr) Run

func (c *LongConnMgr) Run(ctx context.Context)

func (*LongConnMgr) SendReqWaitResp

func (c *LongConnMgr) SendReqWaitResp(ctx context.Context, m proto.Message, reqIdentifier int, resp proto.Message) error

func (*LongConnMgr) SetBackground

func (c *LongConnMgr) SetBackground(isBackground bool)

func (*LongConnMgr) SetConnectionStatus added in v3.5.0

func (c *LongConnMgr) SetConnectionStatus(status int)

type Message

type Message struct {
	Message GeneralWsReq
	Resp    chan *GeneralWsResp
}

type MsgSyncer

type MsgSyncer struct {
	PushMsgAndMaxSeqCh chan common.Cmd2Value // channel for receiving push messages and the maximum SEQ number
	// contains filtered or unexported fields
}

The callback synchronization starts. The reconnection ends

func NewMsgSyncer

func NewMsgSyncer(ctx context.Context, conversationCh, PushMsgAndMaxSeqCh chan common.Cmd2Value,
	loginUserID string, longConnMgr *LongConnMgr, db db_interface.DataBase, syncTimes int) (*MsgSyncer, error)

NewMsgSyncer creates a new instance of the message synchronizer.

func (*MsgSyncer) DoListener

func (m *MsgSyncer) DoListener(ctx context.Context)

DoListener Listen to the message pipe of the message synchronizer and process received and pushed messages

type PongHandler

type PongHandler func(string) error

type ReconnectStrategy added in v3.5.0

type ReconnectStrategy interface {
	GetSleepInterval() time.Duration
	Reset()
}

type WsRespAsyn

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

func NewWsRespAsyn

func NewWsRespAsyn() *WsRespAsyn

func (*WsRespAsyn) AddCh

func (u *WsRespAsyn) AddCh(userID string) (string, chan *GeneralWsResp)

func (*WsRespAsyn) AddChByIncr

func (u *WsRespAsyn) AddChByIncr(msgIncr string) chan *GeneralWsResp

func (*WsRespAsyn) DelCh

func (u *WsRespAsyn) DelCh(msgIncr string)

func (*WsRespAsyn) GetCh

func (u *WsRespAsyn) GetCh(msgIncr string) chan *GeneralWsResp

func (*WsRespAsyn) NotifyResp

func (u *WsRespAsyn) NotifyResp(ctx context.Context, wsResp GeneralWsResp) error

write a unit test for this function

func (*WsRespAsyn) WaitResp

func (u *WsRespAsyn) WaitResp(ctx context.Context, ch chan *GeneralWsResp, timeout int) (*GeneralWsResp, error)

Jump to

Keyboard shortcuts

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