ws

package
v0.0.0-...-ff28042 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2025 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RedisChannel     = "ws-broadcast"
	UserNodeMapKey   = "user_node_map"
	BroadcastChannel = "broadcast-all"
)

Variables

This section is empty.

Functions

func ConvertPositionUpdateToJSON

func ConvertPositionUpdateToJSON(update *proto.PositionUpdate) ([]byte, error)

func ConvertPositionsToJSON

func ConvertPositionsToJSON(updates []*proto.PositionUpdate) ([]byte, error)

Types

type MsgPayload

type MsgPayload struct {
	UserID  string `json:"user_id"`
	Message []byte `json:"message"`
	From    string `json:"from_node"`
	To      string `json:"to_node"`
}

type PositionMessage

type PositionMessage struct {
	Type      string  `json:"type"`
	UserID    string  `json:"user_id"`
	Lat       float64 `json:"lat"`
	Lon       float64 `json:"lon"`
	Speed     float64 `json:"speed"`
	Status    string  `json:"status"`
	Timestamp string  `json:"timestamp"`
}

type WsHub

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

func NewWsHub

func NewWsHub(nodeID string, redisClient *redis.Client) *WsHub

func (*WsHub) AddConnection

func (h *WsHub) AddConnection(ctx context.Context, userID string, conn *websocket.Conn) error

func (*WsHub) BroadcastMessage

func (h *WsHub) BroadcastMessage(ctx context.Context, message []byte) error

func (*WsHub) RemoveConnection

func (h *WsHub) RemoveConnection(ctx context.Context, userID string, conn *websocket.Conn)

func (*WsHub) SendMessageToUser

func (h *WsHub) SendMessageToUser(ctx context.Context, userID string, message []byte) error

Jump to

Keyboard shortcuts

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