websocket

package
v0.0.0-...-21faf40 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FNV32a

func FNV32a(s string) uint32

FNV32a 用來做切片 string -> int32

func NewGateway

func NewGateway() prelude.Gatewayer

NewGateway returns a Gateway instance

func RegisterRoute

func RegisterRoute(server *web.WebServer, handler *GatewayHTTPHandler) *web.WebServer

RegisterRoute return a router which handles all topics

Types

type Bucket

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

Bucket 是水桶,用來加速查詢用

func NewBucket

func NewBucket(ctx context.Context, id, workerCount int) *Bucket

NewBucket 會生成一個新的 Bucket

type Gateway

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

Gateway handles all websocket connections between client and server

func (*Gateway) ListenAndServe

func (g *Gateway) ListenAndServe(bind string, hub prelude.Huber) error

func (*Gateway) Shutdown

func (g *Gateway) Shutdown(ctx context.Context) error

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

func NewManager(hub prelude.Huber) *Manager

NewManager 用來產生一個新的 Manager 用來控制 Gateway

func (*Manager) AddEventToHub

func (m *Manager) AddEventToHub(event cloudevents.Event) error

AddEventToHub 把 event 送到 hub 讓 consumer 可以讀取 device 傳送過來的 event

func (*Manager) AddSession

func (m *Manager) AddSession(session *WSSession) error

AddSession 把 session 加到 gateway

func (*Manager) Context

func (m *Manager) Context() context.Context

Context 獲取 manager 目前的 context

func (*Manager) DeleteSession

func (m *Manager) DeleteSession(session *WSSession) error

DeleteSession 用來移除 Session

func (*Manager) IsActive

func (m *Manager) IsActive() bool

IsActive reprsent active status of manager

func (*Manager) Push

func (m *Manager) Push(sessionID string, event cloudevents.Event) error

Push 用來推播訊息到 client

func (*Manager) SetActive

func (m *Manager) SetActive(val bool)

SetActive update status of active

func (*Manager) Shutdown

func (m *Manager) Shutdown(ctx context.Context) error

Shutdown represent graceful shutdown manager

func (*Manager) Start

func (m *Manager) Start() error

Start 代表開啟背景工作,例如把 event 送到 hub

func (*Manager) Status

func (m *Manager) Status() *Status

Status 可以知道目前 Gateway 的狀態,例如連線人數等

func (*Manager) UpdateRouteInfo

func (m *Manager) UpdateRouteInfo(session *WSSession) error

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 WSMessage

type WSMessage struct {
	MsgType int
	MsgData []byte
}

WSMessage 代表 websocket 底層的 message

type WSSession

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

WSSession 代表 websocket 每一個 websocket 的連線

func NewWSSession

func NewWSSession(id string, clientIP string, conn *websocket.Conn, manager *Manager) *WSSession

NewWSSession 產生一個新的 websocket session

func (*WSSession) Close

func (s *WSSession) Close() error

Close func which closes websocket session and remove session from bucket and room.

func (*WSSession) ID

func (s *WSSession) ID() string

ID 可以取得 session 的唯一值

func (*WSSession) IsActive

func (s *WSSession) IsActive() bool

IsActive reprsent active status of manager

func (*WSSession) LastSeenAt

func (s *WSSession) LastSeenAt() time.Time

LastSeenAt 取得 session 的最後獲得 pong 的時間

func (*WSSession) Metadata

func (s *WSSession) Metadata() map[string]interface{}

Metadata returns session's metadata

func (*WSSession) SendEvent

func (s *WSSession) SendEvent(event cloudevents.Event) error

SendEvent 可以傳送 event 訊息給 client (設備)

func (*WSSession) SetActive

func (s *WSSession) SetActive(val bool)

SetActive update status of active

func (*WSSession) Start

func (s *WSSession) Start() error

Start 代表開始這個 websocket session 開始

Jump to

Keyboard shortcuts

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