base

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 默认开始状态
	StatusStart = "start"
	// 初始状态
	StatusInit = "init"
	// 网关已获取
	StatusGateway = "gateway"
	// ws已经连接,等待hello包
	StatusWSConnected = "ws_connected"
	//已连接状态
	StatusConnected = "connected"
	//resume
	StatusRetry = "retry"
)
View Source
const (
	EventEnterPrefix           = "enter_"
	EventStart                 = "fsmStart"
	EventGotGateway            = "getGateWay"
	EventWsConnected           = "wsConnect"
	EventWsConnectFail         = "wsConnectFail"
	EventHelloReceived         = "helloReceived"
	EventHelloFail             = "helloFail"
	EventHelloGatewayErrFail   = "helloGatewayErrFail"
	EventPongReceived          = "pongReceived"
	EventHeartbeatTimeout      = "heartbeatTimeout"
	EventRetryHeartbeatTimeout = "retryHeartbeatTimeout"
	EventResumeReceivedOk      = "ResumeReceived"
)
View Source
const (
	NO_RETRY      = -1
	RETRY_INFINIT = 0
)
View Source
const EventDataFrameKey = "frame"
View Source
const EventDataSessionKey = "session"
View Source
const EventReceiveFrame = "EVENT-GLOBAL-RECEIVE_FRAME"

Variables

This section is empty.

Functions

This section is empty.

Types

type GateWayHttpApiResult

type GateWayHttpApiResult struct {
	Code    int32  `json:"code"`
	Message string `json:"message"`
	Data    struct {
		Url string `json:"url"`
	} `json:"data"`
}

type Session

type Session struct {
	Compressed          int
	ReceiveFrameHandler func(frame *event2.FrameMap) (error, []byte)
	ProcessDataHandler  func(data []byte) (error, []byte)
	EventSyncHandle     bool
}

func (*Session) On

func (s *Session) On(message string, handler event.Listener)

func (*Session) ReceiveData

func (s *Session) ReceiveData(data []byte) (error, []byte)

func (*Session) ReceiveFrame

func (s *Session) ReceiveFrame(frame *event2.FrameMap) (error, []byte)

func (*Session) Trigger

func (s *Session) Trigger(eventName string, params event.M)

type SessionInterface

type SessionInterface interface {
	//接收数据
	ReceiveData(data []byte)

	SendData(data []byte)

	//注册回调
	On(message string, handler event.Listener)
}

type State

type State struct {
	Name string
	Code int
}

type StateSession

type StateSession struct {
	Session
	SessionId string
	//Status           string
	GateWay      string
	Timeout      int
	RecvQueue    chan *event2.FrameMap
	MaxSn        int64
	FSM          *fsm.FSM
	NetworkProxy SystemInterface

	StatusParams    map[string]*StatusParam
	HeartBeatCron   *cron.Cron
	LastPongAt      time.Time
	LastPingAt      time.Time
	PongTimeoutChan chan time.Time
}

* _________________

  • 获取gateWay 连接ws 收到hello | 心跳超时 |
  • | | | | | |
  • v v v | V |
  • INIT --> GATEWAY --> WS_CONNECTED --> CONNECTED --> RETRY |
  • ^ | ^ | ^_______| |
  • | | |_____________|__________________________| |
  • | | | | |
  • |________|_________________|__________________________|____| *

func NewStateSession

func NewStateSession(gateway string, compressed int) *StateSession

func (*StateSession) GetGateway

func (s *StateSession) GetGateway() error

func (*StateSession) ReceiveFrameHandler

func (s *StateSession) ReceiveFrameHandler(frame *event2.FrameMap) (error, []byte)

func (*StateSession) Reconnect

func (s *StateSession) Reconnect()

func (*StateSession) ResumeOk

func (s *StateSession) ResumeOk()

func (*StateSession) Retry

func (s *StateSession) Retry(e *fsm.Event, handler func() error, errHandler func() error)

func (*StateSession) RetryHeartbeat

func (s *StateSession) RetryHeartbeat() error

func (*StateSession) SaveSessionId

func (s *StateSession) SaveSessionId(sessionId string)

func (*StateSession) SendHeartBeat

func (s *StateSession) SendHeartBeat() error

func (*StateSession) Start

func (s *StateSession) Start()

func (*StateSession) StartCheckHeartbeat

func (s *StateSession) StartCheckHeartbeat()

func (*StateSession) StartHeartbeat

func (s *StateSession) StartHeartbeat() error

func (*StateSession) StartProcessEvent

func (s *StateSession) StartProcessEvent()

func (*StateSession) WsConnect

func (s *StateSession) WsConnect() error

WsConnect : Try to websocket connect

type StatusParam

type StatusParam struct {
	StartTime  int
	MaxTime    int
	FirstDelay int
	Retry      int
	MaxRetry   int
}

type SystemInterface

type SystemInterface interface {
	ReqGateWay() (error, string)
	ConnectWebsocket(gateway string) error
	SendData(data []byte) error
	//ReceiveData(data []byte) (error, []byte)
	SaveSessionId(sessionId string) error
}

type WebSocketSession

type WebSocketSession struct {
	*StateSession
	Token       string
	BaseUrl     string
	SessionFile string
	WsConn      *websocket.Conn
	WsWriteLock *sync.Mutex
}

func NewWebSocketSession

func NewWebSocketSession(token, baseUrl, sessionFile, gateWay string, compressed int) *WebSocketSession

func (*WebSocketSession) ConnectWebsocket

func (ws *WebSocketSession) ConnectWebsocket(gateway string) error

func (*WebSocketSession) ReqGateWay

func (ws *WebSocketSession) ReqGateWay() (error, string)

func (*WebSocketSession) SaveSessionId

func (ws *WebSocketSession) SaveSessionId(sessionId string) error

func (*WebSocketSession) SendData

func (ws *WebSocketSession) SendData(data []byte) error

func (*WebSocketSession) Start

func (ws *WebSocketSession) Start()

type WebhookSession

type WebhookSession struct {
	Session
	EncryptKey  string
	VerifyToken string
}

func NewWebhookSession

func NewWebhookSession(encryptKey, verityToken string, compress int) *WebhookSession

func (*WebhookSession) ProcessData

func (s *WebhookSession) ProcessData(data []byte) (err error, data2 []byte)

func (*WebhookSession) ReceiveFrameHandler

func (s *WebhookSession) ReceiveFrameHandler(frame *event2.FrameMap) (error, []byte)

func (*WebhookSession) SendData

func (s *WebhookSession) SendData(data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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