|
ORE Studio 0.0.4
|
Manages the lifecycle of the NATS client and login state. More...
#include <ClientManager.hpp>
Inherits QObject.

Signals | |
| void | connected () |
| void | loggedIn () |
| void | disconnected () |
| void | reconnecting () |
| void | reconnected () |
| void | connectionError (const QString &message) |
| void | sessionExpired () |
| Emitted when the session can no longer be refreshed. | |
| void | notificationReceived (const QString &eventType, const QDateTime ×tamp, const QStringList &entityIds, const QString &tenantId, int payloadType, const QByteArray &payload) |
| void | recordingStarted (const QString &filePath) |
| void | recordingStopped () |
| void | streamingStarted () |
| void | streamingStopped () |
Public Member Functions | |
| ClientManager (std::shared_ptr< eventing::service::event_bus > event_bus, QObject *parent=nullptr) | |
| void | setSubjectPrefix (const std::string &prefix) |
| Set the NATS subject prefix used for all outbound messages. | |
| const std::string & | subjectPrefix () const |
| Get the current NATS subject prefix. | |
| LoginResult | connect (const std::string &host, std::uint16_t port) |
| Connect to the NATS server without logging in. | |
| LoginResult | login (const std::string &username, const std::string &password) |
| Login on an already connected client. | |
| LoginResult | connectAndLogin (const std::string &host, std::uint16_t port, const std::string &username, const std::string &password) |
| Connect to the server and perform login. | |
| LoginResult | testConnection (const std::string &host, std::uint16_t port, const std::string &username, const std::string &password) |
| Test a connection without affecting main client state. | |
| SignupResult | signup (const std::string &host, std::uint16_t port, const std::string &username, const std::string &email, const std::string &password) |
| Connect to the server and attempt signup. | |
| void | disconnect () |
| Logout the current user and disconnect from the server. | |
| bool | logout () |
| Logout the current user without disconnecting. | |
| bool | isConnected () const |
| Check if currently connected. | |
| bool | isAdmin () const |
| bool | isLoggedIn () const |
| Check if currently logged in. | |
| nats::service::jetstream_admin | admin () |
| Create a JetStream admin handle for managing streams and consumers. | |
| std::string | currentUsername () const |
| Get the current logged-in user's username. | |
| std::string | currentEmail () const |
| Get the current logged-in user's email. | |
| void | setCurrentEmail (const std::string &email) |
| Set the current logged-in user's email. | |
| std::optional< boost::uuids::uuid > | accountId () const |
| Get the account ID if logged in. | |
| std::string | serverAddress () const |
| Get the server address string. | |
| std::string | connectedHost () const |
| Get the connected server hostname. | |
| std::uint16_t | connectedPort () const |
| Get the connected server port. | |
| std::string | storedUsername () const |
| Get the stored username used for the current session. | |
| std::string | storedPassword () const |
| Get the stored password used for the current session. | |
| boost::uuids::uuid | currentPartyId () const |
| Get the UUID of the currently selected party. | |
| QString | currentPartyName () const |
| Get the name of the currently selected party. | |
| QString | currentPartyCategory () const |
| Get the category of the currently selected party. | |
| bool | isSystemParty () const |
| Returns true if the currently selected party is the system party. | |
| bool | selectParty (const boost::uuids::uuid &party_id, const QString &party_name) |
| Select a party for the current session. | |
| template<nats_request RequestType> | |
| auto | process_request (RequestType request) -> std::expected< typename RequestType::response_type, std::string > |
| Process a request that does not require authentication. | |
| template<nats_request RequestType> | |
| auto | process_authenticated_request (RequestType request, std::chrono::milliseconds timeout=std::chrono::seconds(30)) -> std::expected< typename RequestType::response_type, std::string > |
| Process a request that requires authentication. | |
| std::optional< SessionListResult > | listSessions (const boost::uuids::uuid &accountId, std::uint32_t limit=100, std::uint32_t offset=0) |
| List sessions for an account. | |
| std::optional< std::vector< iam::domain::session > > | getActiveSessions () |
| Get active sessions for the current user. | |
| std::optional< std::vector< iam::messaging::session_sample_dto > > | getSessionSamples (const boost::uuids::uuid &sessionId) |
| Get time-series samples for a session. | |
| std::uint64_t | bytesSent () const |
| std::uint64_t | bytesReceived () const |
| std::uint64_t | lastRttMs () const |
| std::optional< std::chrono::steady_clock::time_point > | disconnectedSince () const |
| bool | enableRecording (const std::filesystem::path &) |
| void | disableRecording () |
| bool | isRecording () const |
| std::filesystem::path | recordingFilePath () const |
| void | setRecordingDirectory (const std::filesystem::path &dir) |
| std::filesystem::path | recordingDirectory () const |
| void | subscribeToEvent (const std::string &subject) |
| void | unsubscribeFromEvent (const std::string &subject) |
Static Public Attributes | |
| static constexpr std::chrono::seconds | fast_timeout {30} |
| static constexpr std::chrono::seconds | slow_timeout {120} |
Manages the lifecycle of the NATS client and login state.
Maintains a persistent NATS connection while allowing the authentication state to be established and torn down repeatedly. Signals changes in connection state to allow UI components to update accordingly.
| void setSubjectPrefix | ( | const std::string & | prefix | ) |
Set the NATS subject prefix used for all outbound messages.
Must be called before connect(). Format: "ores.{tier}.{instance}", e.g. "ores.dev.local1". Leave empty to use subjects without a prefix.
| bool isAdmin | ( | ) | const |
| nats::service::jetstream_admin admin | ( | ) |
Create a JetStream admin handle for managing streams and consumers.
Throws std::runtime_error if not connected.
| auto process_request | ( | RequestType | request | ) | -> std::expected<typename RequestType::response_type, std::string> |
Process a request that does not require authentication.
Serializes the request to JSON, sends it via NATS, and deserializes the response.
| RequestType | Request type (must satisfy nats_request concept) |
| request | The request to send |
| auto process_authenticated_request | ( | RequestType | request, |
| std::chrono::milliseconds | timeout = std::chrono::seconds(30) |
||
| ) | -> std::expected<typename RequestType::response_type, std::string> |
Process a request that requires authentication.
Checks if logged in before sending. Adds JWT to request headers.
| RequestType | Request type (must satisfy nats_request concept) |
| request | The request to send |
| timeout | Request timeout (default: 30 seconds) |

|
signal |
Emitted when the session can no longer be refreshed.
Fired either by the proactive refresh timer (max_session_exceeded) or reactively when authenticated_request() throws after a failed refresh. Connect to this signal to show the session-expired dialog and re-login.