interaction

package
v3.8.1-rc.15 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: Apache-2.0 Imports: 35 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)
	CompressWithPool(rawData []byte) ([]byte, error)
	DeCompress(compressedData []byte) ([]byte, error)
	DecompressWithPool(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) SetPingHandler added in v3.8.0

func (d *Default) SetPingHandler(handler PingPongHandler)

func (*Default) SetPongHandler

func (d *Default) SetPongHandler(handler PingPongHandler)

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) CompressWithPool added in v3.8.0

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

func (*GzipCompressor) DeCompress

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

func (*GzipCompressor) DecompressWithPool added in v3.8.0

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

type LongConn

type LongConn interface {
	// Close closes this connection.
	Close() error

	// WriteMessage writes a message to the connection.
	// messageType indicates the type of data and can be set to binary (2) or text (1).
	WriteMessage(messageType int, message []byte) error

	// ReadMessage reads a message from the connection.
	ReadMessage() (int, []byte, error)

	// SetReadDeadline sets the deadline for reading from the underlying network connection.
	// After a timeout, there will be an error in the writing process.
	SetReadDeadline(timeout time.Duration) error

	// SetWriteDeadline sets the deadline for writing to the connection.
	// After a timeout, there will be an error in the writing process.
	SetWriteDeadline(timeout time.Duration) error

	// Dial tries to establish a connection.
	// urlStr must include authentication arguments; requestHeader can control data compression.
	Dial(urlStr string, requestHeader http.Header) (*http.Response, error)

	// IsNil checks whether the current long connection is nil.
	IsNil() bool

	// SetReadLimit sets the maximum size for a message read from the peer in bytes.
	SetReadLimit(limit int64)

	// SetPingHandler sets the handler for ping messages.
	SetPingHandler(handler PingPongHandler)

	// SetPongHandler sets the handler for pong messages.
	SetPongHandler(handler PingPongHandler)

	// 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, userOnline func(map[string][]int32), 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) GetSubscribeUsersStatus added in v3.8.0

func (c *LongConnMgr) GetSubscribeUsersStatus(ctx context.Context) ([]*userPb.OnlineStatus, error)

func (*LongConnMgr) GetUserOnlinePlatformIDs added in v3.8.0

func (c *LongConnMgr) GetUserOnlinePlatformIDs(ctx context.Context, userIDs []string) (map[string][]int32, error)

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)

func (*LongConnMgr) SubscribeUsersStatus added in v3.8.0

func (c *LongConnMgr) SubscribeUsersStatus(ctx context.Context, userIDs []string) ([]*userPb.OnlineStatus, error)

func (*LongConnMgr) UnsubscribeUserOnlinePlatformIDs added in v3.8.0

func (c *LongConnMgr) UnsubscribeUserOnlinePlatformIDs(ctx context.Context, userIDs []string) error

func (*LongConnMgr) UnsubscribeUsersStatus added in v3.8.0

func (c *LongConnMgr) UnsubscribeUsersStatus(ctx context.Context, userIDs []string) error

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
}

MsgSyncer is a central hub for message relay, responsible for sequential message gap pulling, handling network events, and managing app foreground and background events.

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 PingPongHandler added in v3.8.0

type PingPongHandler 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