wsmanager

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddManager added in v0.0.13

func AddManager(manager *ConnectionManager, name string)

func RemoveManager added in v0.0.13

func RemoveManager(name string)

RemoveManager removes a manager from the global managers map.

func SendEvent added in v0.0.13

func SendEvent(managerName string, topic string, payload interface{}) error

SendEvent sends an event with the given topic and payload to all users subscribed to that topic.

func SendEventToUser added in v0.0.13

func SendEventToUser(managerName string, userID any, topic string, payload interface{}) error

SendEventToUser sends an event with the given topic and payload to a specific user.

Types

type Connection

type Connection struct {
	Conn net.Conn
	// contains filtered or unexported fields
}

func NewConnection

func NewConnection(conn net.Conn) *Connection

type ConnectionManager

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

func GetManager added in v0.0.13

func GetManager(name string) *ConnectionManager

func NewConnectionManager

func NewConnectionManager() *ConnectionManager

func (*ConnectionManager) AddClient

func (cm *ConnectionManager) AddClient(conn *Connection, userID any)

func (*ConnectionManager) Broadcast

func (cm *ConnectionManager) Broadcast(msg Message, sender *Connection)

func (*ConnectionManager) GetConnectionsForUser added in v0.0.13

func (cm *ConnectionManager) GetConnectionsForUser(userID any) []*Connection

GetConnectionsForUser retrieves all active connections for a given user ID.

func (*ConnectionManager) GetSubscribers added in v0.0.13

func (cm *ConnectionManager) GetSubscribers(topic any) map[*Connection]bool

GetSubscribers retrieves all connections subscribed to a given topic.

func (*ConnectionManager) RemoveClient

func (cm *ConnectionManager) RemoveClient(conn *Connection, userID any)

func (*ConnectionManager) SetDebug added in v0.0.16

func (cm *ConnectionManager) SetDebug(enabled bool)

SetDebug enables or disables debug logging

func (*ConnectionManager) Subscribe

func (cm *ConnectionManager) Subscribe(conn *Connection, topic string)

func (*ConnectionManager) Unsubscribe added in v0.0.13

func (cm *ConnectionManager) Unsubscribe(conn *Connection, topic string)

type Message

type Message struct {
	ID      string          `json:"id"`
	Topic   string          `json:"topic"`
	Payload json.RawMessage `json:"payload"`
	Sender  *Connection     `json:"-"`
}

Jump to

Keyboard shortcuts

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