MantisBase v0.4.9
Loading...
Searching...
No Matches
mb::MbWSMgr Class Reference

Tracks WebSocket connections, topic indexes, and broadcasts change events. More...

#include <ws.h>

Public Member Functions

 MbWSMgr (const MantisBase &)
 ~MbWSMgr ()=default
void addConnection (const drogon::WebSocketConnectionPtr &conn, RealtimeWsSession session)
void removeConnection (const drogon::WebSocketConnectionPtr &conn)
void setTopics (const drogon::WebSocketConnectionPtr &conn, const std::vector< std::string > &topics)
void unsubscribe (const drogon::WebSocketConnectionPtr &conn, const std::vector< std::string > &topics)
void broadcastChange (const json &change_event)
size_t connectionCount ()
void cleanupStaleConnections (const MantisBase &app, std::chrono::steady_clock::time_point now)
 Close expired, idle, or connect-only sessions.
RealtimeWsSession * getSession (const drogon::WebSocketConnectionPtr &conn)

Detailed Description

Tracks WebSocket connections, topic indexes, and broadcasts change events.

Thread-safe. One instance is owned by MbSSEMgr and shares the SSE cleanup loop via cleanupStaleConnections.

Constructor & Destructor Documentation

◆ MbWSMgr()

mb::MbWSMgr::MbWSMgr ( const MantisBase & app)
explicit

◆ ~MbWSMgr()

mb::MbWSMgr::~MbWSMgr ( )
default

Member Function Documentation

◆ addConnection()

void mb::MbWSMgr::addConnection ( const drogon::WebSocketConnectionPtr & conn,
RealtimeWsSession session )

Register a new connection and its session snapshot. Closes with 1008 if at capacity.

◆ broadcastChange()

void mb::MbWSMgr::broadcastChange ( const json & change_event)

Deliver a formatted change event to all connections subscribed to the matching topic.

◆ cleanupStaleConnections()

void mb::MbWSMgr::cleanupStaleConnections ( const MantisBase & app,
std::chrono::steady_clock::time_point now )

Close expired, idle, or connect-only sessions.

Parameters
appApplication instance (auth expiry checks).
nowCurrent steady clock time (shared with SSE cleanup).

◆ connectionCount()

size_t mb::MbWSMgr::connectionCount ( )
Returns
Number of active WebSocket sessions.

◆ getSession()

RealtimeWsSession * mb::MbWSMgr::getSession ( const drogon::WebSocketConnectionPtr & conn)
Returns
Mutable session for a connection, or nullptr if unknown.

◆ removeConnection()

void mb::MbWSMgr::removeConnection ( const drogon::WebSocketConnectionPtr & conn)

Remove connection from topic indexes and session map.

◆ setTopics()

void mb::MbWSMgr::setTopics ( const drogon::WebSocketConnectionPtr & conn,
const std::vector< std::string > & topics )

Replace the connection's topic set (subscribe replaces, does not merge).

◆ unsubscribe()

void mb::MbWSMgr::unsubscribe ( const drogon::WebSocketConnectionPtr & conn,
const std::vector< std::string > & topics )

Remove specific topics from a connection without affecting others.


The documentation for this class was generated from the following files:
  • /home/runner/work/mantisbase/mantisbase/include/mantisbase/core/ws.h
  • /home/runner/work/mantisbase/mantisbase/src/core/realtime_ws.cpp