Documentation ¶
Index ¶
- func FNV32a(s string) uint32
- func NewGateway() prelude.Gatewayer
- func RegisterRoute(server *web.WebServer, handler *GatewayHTTPHandler) *web.WebServer
- type Bucket
- type Gateway
- type GatewayHTTPHandler
- type Manager
- func (m *Manager) AddEventToHub(event cloudevents.Event) error
- func (m *Manager) AddSession(session *WSSession) error
- func (m *Manager) Context() context.Context
- func (m *Manager) DeleteSession(session *WSSession) error
- func (m *Manager) IsActive() bool
- func (m *Manager) Push(sessionID string, event cloudevents.Event) error
- func (m *Manager) SetActive(val bool)
- func (m *Manager) Shutdown(ctx context.Context) error
- func (m *Manager) Start() error
- func (m *Manager) Status() *Status
- func (m *Manager) UpdateRouteInfo(session *WSSession) error
- type RouteInfo
- type Status
- type WSMessage
- type WSSession
- func (s *WSSession) Close() error
- func (s *WSSession) ID() string
- func (s *WSSession) IsActive() bool
- func (s *WSSession) LastSeenAt() time.Time
- func (s *WSSession) Metadata() map[string]interface{}
- func (s *WSSession) SendEvent(event cloudevents.Event) error
- func (s *WSSession) SetActive(val bool)
- func (s *WSSession) Start() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterRoute ¶
func RegisterRoute(server *web.WebServer, handler *GatewayHTTPHandler) *web.WebServer
RegisterRoute return a router which handles all topics
Types ¶
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway handles all websocket connections between client and server
func (*Gateway) ListenAndServe ¶
type GatewayHTTPHandler ¶
type GatewayHTTPHandler struct {
// contains filtered or unexported fields
}
GatewayHTTPHandler 用來是 Gateway http 的 handler
func NewGatewayHTTPHandler ¶
func NewGatewayHTTPHandler(manager *Manager) *GatewayHTTPHandler
NewGatewayHTTPHandler 產生一個 GatewayHttpHander instance
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager 是用來控制 Gateway 的facade
func NewManager ¶
NewManager 用來產生一個新的 Manager 用來控制 Gateway
func (*Manager) AddEventToHub ¶
func (m *Manager) AddEventToHub(event cloudevents.Event) error
AddEventToHub 把 event 送到 hub 讓 consumer 可以讀取 device 傳送過來的 event
func (*Manager) AddSession ¶
AddSession 把 session 加到 gateway
func (*Manager) DeleteSession ¶
DeleteSession 用來移除 Session
func (*Manager) Push ¶
func (m *Manager) Push(sessionID string, event cloudevents.Event) error
Push 用來推播訊息到 client
func (*Manager) UpdateRouteInfo ¶
UpdateRouteInfo 用來更新目前 session 所在的 gateway 主機和最後一次收到 pong 的時間 (lastSeenAt)
type RouteInfo ¶
type RouteInfo struct { SessionID string GatewayAddr string LastSeenAt time.Time `json:"lastSeenAt"` }
RouteInfo 代表 session 最後看見的時間
type Status ¶
type Status struct {
OnlinePeople int64 `json:"online_people"`
}
Status 用來表示 Gateway 的狀態,例如: 連線人數
type WSSession ¶
type WSSession struct {
// contains filtered or unexported fields
}
WSSession 代表 websocket 每一個 websocket 的連線
func NewWSSession ¶
NewWSSession 產生一個新的 websocket session
func (*WSSession) Close ¶
Close func which closes websocket session and remove session from bucket and room.
func (*WSSession) LastSeenAt ¶
LastSeenAt 取得 session 的最後獲得 pong 的時間
func (*WSSession) SendEvent ¶
func (s *WSSession) SendEvent(event cloudevents.Event) error
SendEvent 可以傳送 event 訊息給 client (設備)