Singleton service responsible for sending messages and files over WebSocket connections.
More...
#include <message_service.h>
|
| void | HandleSendJsonViaSocket (const QString &json_message, const QString &frequency, const QString &progress_message_id) |
| | Slot connected to the sendJsonViaSocket signal. Performs the actual sending of a JSON message. Finds the socket for the frequency and sends the message. Updates the progress message to indicate success or failure. This runs on the main thread.
|
| |
| void | UpdateProgressMessage (const QString &progress_message_id, const QString &message) |
| | Slot to update a progress message associated with a file transfer. Emits the progressMessageUpdated signal.
|
| |
|
| void | audioDataReceived (QString frequency, const QByteArray &audio_data) |
| | Emitted when raw audio data is received via a binary WebSocket message. Relayed from WavelengthMessageProcessor.
|
| |
| void | messageSent (QString frequency, const QString &formatted_message) |
| | Emitted immediately after a text message is successfully sent via the socket.
|
| |
| void | progressMessageUpdated (const QString &message_id, const QString &message) |
| | Emitted during file processing and sending to update the status display.
|
| |
| void | pttDenied (QString frequency, QString reason) |
| | Emitted when the server denies permission to transmit audio (Push-to-Talk). Relayed from WavelengthMessageProcessor.
|
| |
| void | pttGranted (QString frequency) |
| | Emitted when the server grants permission to transmit audio (Push-to-Talk). Relayed from WavelengthMessageProcessor.
|
| |
| void | pttStartReceiving (QString frequency, QString sender_id) |
| | Emitted when another user starts transmitting audio on the frequency. Relayed from WavelengthMessageProcessor.
|
| |
| void | pttStopReceiving (QString frequency) |
| | Emitted when the currently transmitting user stops sending audio. Relayed from WavelengthMessageProcessor.
|
| |
| void | remoteAudioAmplitudeUpdate (QString frequency, qreal amplitude) |
| | Emitted when the server sends an update about the remote audio amplitude (optional). Relayed from WavelengthMessageProcessor.
|
| |
| void | removeProgressMessage (const QString &message_id) |
| | Emitted after a file transfer is complete (success or failure) to remove the progress message.
|
| |
| void | sendJsonViaSocket (const QString &json_message, QString frequency, const QString &progress_message_id) |
| | Internal signal emitted by the background file processing task when the JSON message is ready to be sent. Connected to the HandleSendJsonViaSocket slot.
|
| |
|
| void | ClearSentMessageCache () |
| | Clears the internal cache of sent message contents.
|
| |
| QString | GetClientId () const |
| | Gets the client ID currently associated with this service instance.
|
| |
| QMap< QString, QString > * | GetSentMessageCache () |
| | Gets a pointer to the internal cache of sent message contents. The cache maps message ID to message content.
|
| |
| | MessageService (const MessageService &)=delete |
| | Deleted copy constructor to prevent copying.
|
| |
| MessageService & | operator= (const MessageService &)=delete |
| | Deleted assignment operator to prevent assignment.
|
| |
| bool | SendFile (const QString &file_path, const QString &progress_message_id=QString()) |
| | Initiates the process of sending a file to the currently active frequency. Reads the file, encodes it to base64, determines a file type, and constructs a JSON message of a type "send_file" containing the metadata and encoded data. This entire process (reading, encoding) is offloaded to a background thread using AttachmentQueueManager. Emits progressMessageUpdated signals to track the process. Finally, emits sendJsonViaSocket to trigger the actual sending on the main thread.
|
| |
| bool | SendFileToServer (const QString &json_message, const QString &frequency, const QString &progress_message_id) |
| | Sends a pre-formatted JSON message (typically containing file data) to the server. This method is intended to be called internally or via signals after file processing. Finds the socket for the given frequency and sends the JSON string. Updates the progress message to indicate success or failure. Schedules removal of the progress message.
|
| |
| bool | SendTextMessage (const QString &message) |
| | Sends a text message to the currently active frequency. Retrieves the active frequency and socket from WavelengthRegistry. Constructs a JSON message of type "send_message" including content, sender ID, timestamp, and a unique message ID. Sends the message via the socket. Caches sent message content locally.
|
| |
| void | SetClientId (const QString &clientId) |
| | Sets the client ID for this service instance.
|
| |
|
| static MessageService * | GetInstance () |
| | Gets the singleton instance of the MessageService.
|
| |
| static bool | SendAudioData (const QString &frequency, const QByteArray &audio_data) |
| | Sends raw audio data as a binary message for the specified frequency. Used for transmitting audio during an active PTT session.
|
| |
| static bool | SendPttRelease (const QString &frequency) |
| | Sends a Push-to-Talk (PTT) release message for the specified frequency. Constructs a JSON message of type "release_ptt" and sends it via the frequency's socket.
|
| |
| static bool | SendPttRequest (const QString &frequency) |
| | Sends a Push-to-Talk (PTT) request message for the specified frequency. Constructs a JSON message of type "request_ptt" and sends it via the frequency's socket.
|
| |
|
| | MessageService (QObject *parent=nullptr) |
| | Private constructor to enforce the singleton pattern. Connects the internal sendJsonViaSocket signal to the HandleSendJsonViaSocket slot.
|
| |
| | ~MessageService () override=default |
| | Private destructor.
|
| |
|
| static QWebSocket * | GetSocketForFrequency (const QString &frequency) |
| | Helper function to retrieve the active WebSocket connection for a given frequency. Uses WavelengthRegistry to look up the socket. Includes checks for validity.
|
| |
|
| QString | client_id_ |
| | Stores the client ID associated with this service instance.
|
| |
| QMap< QString, QString > | sent_messages_ |
| | Cache storing the content of recently sent text messages, mapped by message ID.
|
| |
Singleton service responsible for sending messages and files over WebSocket connections.
This class manages the sending of text messages, files (as base64 encoded JSON), Push-to-Talk (PTT) requests/releases, and raw audio data for specific frequencies (wavelengths). It interacts with WavelengthRegistry to find the appropriate WebSocket connection for a given frequency. File sending is handled asynchronously using AttachmentQueueManager to avoid blocking the main thread. It provides signals for tracking message sending progress and status, as well as PTT and audio events.
◆ MessageService() [1/2]
Deleted copy constructor to prevent copying.
◆ MessageService() [2/2]
| MessageService::MessageService |
( |
QObject * | parent = nullptr | ) |
|
|
explicitprivate |
Private constructor to enforce the singleton pattern. Connects the internal sendJsonViaSocket signal to the HandleSendJsonViaSocket slot.
- Parameters
-
| parent | Optional parent QObject. |
◆ ~MessageService()
| MessageService::~MessageService |
( |
| ) |
|
|
overrideprivatedefault |
◆ audioDataReceived
| void MessageService::audioDataReceived |
( |
QString | frequency, |
|
|
const QByteArray & | audio_data ) |
|
signal |
Emitted when raw audio data is received via a binary WebSocket message. Relayed from WavelengthMessageProcessor.
- Parameters
-
| frequency | The frequency the audio data belongs to. |
| audio_data | The raw audio data bytes. |
◆ ClearSentMessageCache()
| void MessageService::ClearSentMessageCache |
( |
| ) |
|
|
inline |
Clears the internal cache of sent message contents.
◆ GetClientId()
| QString MessageService::GetClientId |
( |
| ) |
const |
|
inlinenodiscard |
Gets the client ID currently associated with this service instance.
- Returns
- The client ID string.
◆ GetInstance()
◆ GetSentMessageCache()
| QMap< QString, QString > * MessageService::GetSentMessageCache |
( |
| ) |
|
|
inline |
Gets a pointer to the internal cache of sent message contents. The cache maps message ID to message content.
- Returns
- Pointer to the QMap storing sent message contents.
◆ GetSocketForFrequency()
| QWebSocket * MessageService::GetSocketForFrequency |
( |
const QString & | frequency | ) |
|
|
staticprivate |
Helper function to retrieve the active WebSocket connection for a given frequency. Uses WavelengthRegistry to look up the socket. Includes checks for validity.
- Parameters
-
| frequency | The frequency whose socket is needed. |
- Returns
- Pointer to the QWebSocket if found and valid, nullptr otherwise.
◆ HandleSendJsonViaSocket
| void MessageService::HandleSendJsonViaSocket |
( |
const QString & | json_message, |
|
|
const QString & | frequency, |
|
|
const QString & | progress_message_id ) |
|
slot |
Slot connected to the sendJsonViaSocket signal. Performs the actual sending of a JSON message. Finds the socket for the frequency and sends the message. Updates the progress message to indicate success or failure. This runs on the main thread.
- Parameters
-
| json_message | The JSON string message to send (usually containing file data). |
| frequency | The target frequency. |
| progress_message_id | The ID associated with the progress message for this transfer. |
◆ messageSent
| void MessageService::messageSent |
( |
QString | frequency, |
|
|
const QString & | formatted_message ) |
|
signal |
Emitted immediately after a text message is successfully sent via the socket.
- Parameters
-
| frequency | The frequency the message was sent to. |
| formatted_message | The HTML-formatted version of the sent message (for local display). |
◆ operator=()
Deleted assignment operator to prevent assignment.
◆ progressMessageUpdated
| void MessageService::progressMessageUpdated |
( |
const QString & | message_id, |
|
|
const QString & | message ) |
|
signal |
Emitted during file processing and sending to update the status display.
- Parameters
-
| message_id | The unique ID associated with this file transfer's progress messages. |
| message | The HTML-formatted status update message. |
◆ pttDenied
| void MessageService::pttDenied |
( |
QString | frequency, |
|
|
QString | reason ) |
|
signal |
Emitted when the server denies permission to transmit audio (Push-to-Talk). Relayed from WavelengthMessageProcessor.
- Parameters
-
| frequency | The frequency for which PTT was denied. |
| reason | The reason provided for the denial. |
◆ pttGranted
| void MessageService::pttGranted |
( |
QString | frequency | ) |
|
|
signal |
Emitted when the server grants permission to transmit audio (Push-to-Talk). Relayed from WavelengthMessageProcessor.
- Parameters
-
| frequency | The frequency for which PTT was granted. |
◆ pttStartReceiving
| void MessageService::pttStartReceiving |
( |
QString | frequency, |
|
|
QString | sender_id ) |
|
signal |
Emitted when another user starts transmitting audio on the frequency. Relayed from WavelengthMessageProcessor.
- Parameters
-
| frequency | The frequency where transmission started. |
| sender_id | The ID of the user transmitting. |
◆ pttStopReceiving
| void MessageService::pttStopReceiving |
( |
QString | frequency | ) |
|
|
signal |
Emitted when the currently transmitting user stops sending audio. Relayed from WavelengthMessageProcessor.
- Parameters
-
| frequency | The frequency where transmission stopped. |
◆ remoteAudioAmplitudeUpdate
| void MessageService::remoteAudioAmplitudeUpdate |
( |
QString | frequency, |
|
|
qreal | amplitude ) |
|
signal |
Emitted when the server sends an update about the remote audio amplitude (optional). Relayed from WavelengthMessageProcessor.
- Parameters
-
| frequency | The frequency the amplitude update is for. |
| amplitude | The current amplitude level (typically 0.0 to 1.0). |
◆ removeProgressMessage
| void MessageService::removeProgressMessage |
( |
const QString & | message_id | ) |
|
|
signal |
Emitted after a file transfer is complete (success or failure) to remove the progress message.
- Parameters
-
| message_id | The unique ID of the progress message to remove. |
◆ SendAudioData()
| bool MessageService::SendAudioData |
( |
const QString & | frequency, |
|
|
const QByteArray & | audio_data ) |
|
static |
Sends raw audio data as a binary message for the specified frequency. Used for transmitting audio during an active PTT session.
- Parameters
-
| frequency | The frequency the audio data belongs to. |
| audio_data | The raw audio data bytes. |
- Returns
- True if the binary message was sent successfully (socket valid and data sent), false otherwise.
◆ SendFile()
| bool MessageService::SendFile |
( |
const QString & | file_path, |
|
|
const QString & | progress_message_id = QString() ) |
Initiates the process of sending a file to the currently active frequency. Reads the file, encodes it to base64, determines a file type, and constructs a JSON message of a type "send_file" containing the metadata and encoded data. This entire process (reading, encoding) is offloaded to a background thread using AttachmentQueueManager. Emits progressMessageUpdated signals to track the process. Finally, emits sendJsonViaSocket to trigger the actual sending on the main thread.
- Parameters
-
| file_path | The local path to the file to be sent. |
| progress_message_id | Optional unique ID to associate with progress update messages. If empty, a new one is generated. |
- Returns
- True if the file sending a task was successfully queued, false otherwise (e.g., empty path).
◆ SendFileToServer()
| bool MessageService::SendFileToServer |
( |
const QString & | json_message, |
|
|
const QString & | frequency, |
|
|
const QString & | progress_message_id ) |
Sends a pre-formatted JSON message (typically containing file data) to the server. This method is intended to be called internally or via signals after file processing. Finds the socket for the given frequency and sends the JSON string. Updates the progress message to indicate success or failure. Schedules removal of the progress message.
- Parameters
-
| json_message | The JSON string message to send. |
| frequency | The target frequency. |
| progress_message_id | The ID associated with the progress message for this file transfer. |
- Returns
- True if the message was sent successfully, false if the socket is invalid.
- Deprecated
- This method seems redundant with HandleSendJsonViaSocket and might be removed.
◆ sendJsonViaSocket
| void MessageService::sendJsonViaSocket |
( |
const QString & | json_message, |
|
|
QString | frequency, |
|
|
const QString & | progress_message_id ) |
|
signal |
Internal signal emitted by the background file processing task when the JSON message is ready to be sent. Connected to the HandleSendJsonViaSocket slot.
- Parameters
-
| json_message | The complete JSON message string containing file metadata and base64 data. |
| frequency | The target frequency. |
| progress_message_id | The ID associated with the progress message for this transfer. |
◆ SendPttRelease()
| bool MessageService::SendPttRelease |
( |
const QString & | frequency | ) |
|
|
static |
Sends a Push-to-Talk (PTT) release message for the specified frequency. Constructs a JSON message of type "release_ptt" and sends it via the frequency's socket.
- Parameters
-
| frequency | The frequency for which PTT is being released. |
- Returns
- True if the release message was sent successfully (socket valid), false otherwise.
◆ SendPttRequest()
| bool MessageService::SendPttRequest |
( |
const QString & | frequency | ) |
|
|
static |
Sends a Push-to-Talk (PTT) request message for the specified frequency. Constructs a JSON message of type "request_ptt" and sends it via the frequency's socket.
- Parameters
-
| frequency | The frequency for which PTT is requested. |
- Returns
- True if the request was sent successfully (socket valid), false otherwise.
◆ SendTextMessage()
| bool MessageService::SendTextMessage |
( |
const QString & | message | ) |
|
Sends a text message to the currently active frequency. Retrieves the active frequency and socket from WavelengthRegistry. Constructs a JSON message of type "send_message" including content, sender ID, timestamp, and a unique message ID. Sends the message via the socket. Caches sent message content locally.
- Parameters
-
| message | The text content of the message to send. |
- Returns
- True if the message was sent successfully, false if no active frequency, socket invalid, etc.
◆ SetClientId()
| void MessageService::SetClientId |
( |
const QString & | clientId | ) |
|
|
inline |
Sets the client ID for this service instance.
- Parameters
-
| clientId | The client ID string to set. |
◆ UpdateProgressMessage
| void MessageService::UpdateProgressMessage |
( |
const QString & | progress_message_id, |
|
|
const QString & | message ) |
|
inlineslot |
Slot to update a progress message associated with a file transfer. Emits the progressMessageUpdated signal.
- Parameters
-
| progress_message_id | The ID of the progress message to update. |
| message | The new HTML-formatted status message. |
◆ client_id_
| QString MessageService::client_id_ |
|
private |
Stores the client ID associated with this service instance.
◆ sent_messages_
| QMap<QString, QString> MessageService::sent_messages_ |
|
private |
Cache storing the content of recently sent text messages, mapped by message ID.
The documentation for this class was generated from the following files: