pkg

package
v0.0.0-...-591b2c9 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection struct {
	ConnMu         sync.Mutex
	ConnectionId   string
	Status         ConnectionStatus
	Conn           *websocket.Conn
	ConnectedAt    time.Time
	DisconnectedAt time.Time
}

func (*Connection) SendMessage

func (s *Connection) SendMessage(messageType int, message []byte) error

type ConnectionStatus

type ConnectionStatus uint8
const (
	ALIVE  ConnectionStatus = 0
	CLOSED ConnectionStatus = 1
)

type Hub

type Hub struct {
	Mu              sync.Mutex
	AvailableTopics map[string]bool
	Connections     map[string]*Connection
	UpgradedSubs    map[string]map[string]struct{} // using struct, it consumes 0 bytes
}

func (*Hub) AddConnection

func (h *Hub) AddConnection(name string, soc *Connection)

func (*Hub) Broadcast

func (h *Hub) Broadcast(topic string, event []byte)

func (*Hub) GetConnection

func (h *Hub) GetConnection(name string) *Connection

func (*Hub) GetSubscriptions

func (h *Hub) GetSubscriptions(conn string) []string

func (*Hub) RemoveConnection

func (h *Hub) RemoveConnection(name string)

func (*Hub) Subscribe

func (h *Hub) Subscribe(conn string, topic string) error

func (*Hub) UnSubscribe

func (h *Hub) UnSubscribe(conn string, topic string)

Jump to

Keyboard shortcuts

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