Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
MessageProcessor Class Referencefinal

Singleton class responsible for processing incoming WebSocket messages for specific wavelengths. More...

#include <message_processor.h>

Inheritance diagram for MessageProcessor:
Collaboration diagram for MessageProcessor:

Signals

void audioDataReceived (QString frequency, const QByteArray &audio_data)
 Emitted when raw audio data is received via a binary WebSocket message.
 
void messageReceived (QString frequency, const QString &formatted_message)
 Emitted when a regular chat message (text or attachment placeholder) is processed.
 
void pttDenied (QString frequency, QString reason)
 Emitted when the server denies permission to transmit audio (Push-to-Talk).
 
void pttGranted (QString frequency)
 Emitted when the server grants permission to transmit audio (Push-to-Talk).
 
void pttStartReceiving (QString frequency, QString sender_id)
 Emitted when another user starts transmitting audio on the frequency.
 
void pttStopReceiving (QString frequency)
 Emitted when the currently transmitting user stops sending audio.
 
void remoteAudioAmplitudeUpdate (QString frequency, qreal amplitude)
 Emitted when the server sends an update about the remote audio amplitude (optional).
 
void systemMessage (QString frequency, const QString &formatted_message)
 Emitted when a system event message (e.g., user join/leave) is processed.
 
void userKicked (QString frequency, const QString &reason)
 Emitted when the current user is kicked from a frequency.
 
void wavelengthClosed (QString frequency)
 Emitted when a wavelength is closed (either by host or server command).
 

Public Member Functions

 MessageProcessor (const MessageProcessor &)=delete
 Deleted copy constructor to prevent copying.
 
MessageProcessoroperator= (const MessageProcessor &)=delete
 Deleted assignment operator to prevent assignment.
 
void ProcessIncomingBinaryMessage (const QByteArray &message, const QString &frequency)
 Processes an incoming binary message (expected to be audio data) received from the WebSocket. Emits the audioDataReceived signal with the raw audio data.
 
void ProcessIncomingMessage (const QString &message, const QString &frequency)
 Processes an incoming text message (JSON) received from the WebSocket. Parses the JSON, checks message ID, validates frequency, determines a message type, and calls the corresponding private processing method (e.g., ProcessMessageContent, ProcessSystemCommand).
 
void SetSocketMessageHandlers (QWebSocket *socket, QString frequency)
 Connects the appropriate slots of this processor to the signals of a given QWebSocket. Disconnects any previous handlers for the socket first. Connects textMessageReceived and binaryMessageReceived signals to the respective processing methods of this class, capturing the associated frequency. Also connects the socket's error signal for logging.
 

Static Public Member Functions

static bool AreFrequenciesEqual (const QString &frequency1, const QString &frequency2)
 Compares two frequency strings for equality. Simple string comparison.
 
static MessageProcessorGetInstance ()
 Gets the singleton instance of the MessageProcessor.
 

Private Member Functions

 MessageProcessor (QObject *parent=nullptr)
 Private constructor to enforce the singleton pattern. Connects internal signals to the corresponding slots in WavelengthMessageService.
 
void ProcessMessageContent (const QJsonObject &message_object, const QString &frequency, const QString &message_id)
 Processes messages of type "message" or "send_message". Checks for duplicates, handles attachments (storing data and creating placeholders if necessary), formats the message using MessageFormatter, and emits the messageReceived signal.
 
void ProcessSystemCommand (const QJsonObject &message_object, const QString &frequency)
 Processes messages of type "system_command". Handles commands like "ping", "close_wavelength", "kick_user". Emits appropriate signals (e.g., userKicked, wavelengthClosed).
 
void ProcessUserJoined (const QJsonObject &message_object, const QString &frequency)
 Processes messages of type "user_joined". Formats a system message indicating a user joined and emits the systemMessage signal.
 
void ProcessUserLeft (const QJsonObject &message_object, const QString &frequency)
 Processes messages of type "user_left". Formats a system message indicating a user left and emits the systemMessage signal.
 
void ProcessWavelengthClosed (const QString &frequency)
 Processes messages indicating a wavelength was closed (e.g., "wavelength_closed", "close_wavelength" command). Updates the WavelengthRegistry and emits the wavelengthClosed signal.
 
 ~MessageProcessor () override=default
 Private destructor.
 

Detailed Description

Singleton class responsible for processing incoming WebSocket messages for specific wavelengths.

This class acts as the central hub for interpreting messages received from the server for a given frequency (wavelength). It parses JSON messages, identifies their type, checks for duplicates, validates frequency matching, and dispatches them to appropriate private handler methods. It also handles incoming binary data (audio). It emits signals based on the processed message content (e.g., new message, user joined/left, PTT events, audio data). It collaborates with MessageHandler for parsing and ID management, MessageFormatter for creating displayable HTML, and AttachmentDataStore for handling attachments.

Constructor & Destructor Documentation

◆ MessageProcessor() [1/2]

MessageProcessor::MessageProcessor ( const MessageProcessor & )
delete

Deleted copy constructor to prevent copying.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MessageProcessor() [2/2]

MessageProcessor::MessageProcessor ( QObject * parent = nullptr)
explicitprivate

Private constructor to enforce the singleton pattern. Connects internal signals to the corresponding slots in WavelengthMessageService.

Parameters
parentOptional parent QObject.
Here is the call graph for this function:

◆ ~MessageProcessor()

MessageProcessor::~MessageProcessor ( )
overrideprivatedefault

Private destructor.

Member Function Documentation

◆ AreFrequenciesEqual()

static bool MessageProcessor::AreFrequenciesEqual ( const QString & frequency1,
const QString & frequency2 )
inlinestatic

Compares two frequency strings for equality. Simple string comparison.

Parameters
frequency1The first frequency string.
frequency2The second frequency string.
Returns
True if the strings are identical, false otherwise.
Here is the caller graph for this function:

◆ audioDataReceived

void MessageProcessor::audioDataReceived ( QString frequency,
const QByteArray & audio_data )
signal

Emitted when raw audio data is received via a binary WebSocket message.

Parameters
frequencyThe frequency the audio data belongs to.
audio_dataThe raw audio data bytes.
Here is the caller graph for this function:

◆ GetInstance()

static MessageProcessor * MessageProcessor::GetInstance ( )
inlinestatic

Gets the singleton instance of the MessageProcessor.

Returns
Pointer to the singleton MessageProcessor instance.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ messageReceived

void MessageProcessor::messageReceived ( QString frequency,
const QString & formatted_message )
signal

Emitted when a regular chat message (text or attachment placeholder) is processed.

Parameters
frequencyThe frequency the message belongs to.
formatted_messageThe HTML-formatted message string for display.
Here is the caller graph for this function:

◆ operator=()

MessageProcessor & MessageProcessor::operator= ( const MessageProcessor & )
delete

Deleted assignment operator to prevent assignment.

Here is the call graph for this function:

◆ ProcessIncomingBinaryMessage()

void MessageProcessor::ProcessIncomingBinaryMessage ( const QByteArray & message,
const QString & frequency )

Processes an incoming binary message (expected to be audio data) received from the WebSocket. Emits the audioDataReceived signal with the raw audio data.

Parameters
messageThe raw binary data (QByteArray).
frequencyThe frequency/wavelength this data belongs to.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessIncomingMessage()

void MessageProcessor::ProcessIncomingMessage ( const QString & message,
const QString & frequency )

Processes an incoming text message (JSON) received from the WebSocket. Parses the JSON, checks message ID, validates frequency, determines a message type, and calls the corresponding private processing method (e.g., ProcessMessageContent, ProcessSystemCommand).

Parameters
messageThe raw JSON message string.
frequencyFrequency/wavelength this message belongs to.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessMessageContent()

void MessageProcessor::ProcessMessageContent ( const QJsonObject & message_object,
const QString & frequency,
const QString & message_id )
private

Processes messages of type "message" or "send_message". Checks for duplicates, handles attachments (storing data and creating placeholders if necessary), formats the message using MessageFormatter, and emits the messageReceived signal.

Parameters
message_objectThe parsed JSON object of the message.
frequencyThe frequency the message belongs to.
message_idThe unique ID of the message.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessSystemCommand()

void MessageProcessor::ProcessSystemCommand ( const QJsonObject & message_object,
const QString & frequency )
private

Processes messages of type "system_command". Handles commands like "ping", "close_wavelength", "kick_user". Emits appropriate signals (e.g., userKicked, wavelengthClosed).

Parameters
message_objectThe parsed JSON object of the command.
frequencyThe frequency the command applies to.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessUserJoined()

void MessageProcessor::ProcessUserJoined ( const QJsonObject & message_object,
const QString & frequency )
private

Processes messages of type "user_joined". Formats a system message indicating a user joined and emits the systemMessage signal.

Parameters
message_objectThe parsed JSON object of the event.
frequencyThe frequency the user joined.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessUserLeft()

void MessageProcessor::ProcessUserLeft ( const QJsonObject & message_object,
const QString & frequency )
private

Processes messages of type "user_left". Formats a system message indicating a user left and emits the systemMessage signal.

Parameters
message_objectThe parsed JSON object of the event.
frequencyThe frequency the user left.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessWavelengthClosed()

void MessageProcessor::ProcessWavelengthClosed ( const QString & frequency)
private

Processes messages indicating a wavelength was closed (e.g., "wavelength_closed", "close_wavelength" command). Updates the WavelengthRegistry and emits the wavelengthClosed signal.

Parameters
frequencyThe frequency that was closed.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pttDenied

void MessageProcessor::pttDenied ( QString frequency,
QString reason )
signal

Emitted when the server denies permission to transmit audio (Push-to-Talk).

Parameters
frequencyThe frequency for which PTT was denied.
reasonThe reason provided for the denial.
Here is the caller graph for this function:

◆ pttGranted

void MessageProcessor::pttGranted ( QString frequency)
signal

Emitted when the server grants permission to transmit audio (Push-to-Talk).

Parameters
frequencyThe frequency for which PTT was granted.
Here is the caller graph for this function:

◆ pttStartReceiving

void MessageProcessor::pttStartReceiving ( QString frequency,
QString sender_id )
signal

Emitted when another user starts transmitting audio on the frequency.

Parameters
frequencyThe frequency where transmission started.
sender_idThe ID of the user transmitting.
Here is the caller graph for this function:

◆ pttStopReceiving

void MessageProcessor::pttStopReceiving ( QString frequency)
signal

Emitted when the currently transmitting user stops sending audio.

Parameters
frequencyThe frequency where transmission stopped.
Here is the caller graph for this function:

◆ remoteAudioAmplitudeUpdate

void MessageProcessor::remoteAudioAmplitudeUpdate ( QString frequency,
qreal amplitude )
signal

Emitted when the server sends an update about the remote audio amplitude (optional).

Parameters
frequencyThe frequency the amplitude update is for.
amplitudeThe current amplitude level (typically 0.0 to 1.0).
Here is the caller graph for this function:

◆ SetSocketMessageHandlers()

void MessageProcessor::SetSocketMessageHandlers ( QWebSocket * socket,
QString frequency )

Connects the appropriate slots of this processor to the signals of a given QWebSocket. Disconnects any previous handlers for the socket first. Connects textMessageReceived and binaryMessageReceived signals to the respective processing methods of this class, capturing the associated frequency. Also connects the socket's error signal for logging.

Parameters
socketThe QWebSocket instance to connect handlers to.
frequencyThe frequency associated with this socket connection.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ systemMessage

void MessageProcessor::systemMessage ( QString frequency,
const QString & formatted_message )
signal

Emitted when a system event message (e.g., user join/leave) is processed.

Parameters
frequencyThe frequency the event occurred on.
formatted_messageThe HTML-formatted system message string.
Here is the caller graph for this function:

◆ userKicked

void MessageProcessor::userKicked ( QString frequency,
const QString & reason )
signal

Emitted when the current user is kicked from a frequency.

Parameters
frequencyThe frequency the user was kicked from.
reasonThe reason provided for the kick.
Here is the caller graph for this function:

◆ wavelengthClosed

void MessageProcessor::wavelengthClosed ( QString frequency)
signal

Emitted when a wavelength is closed (either by host or server command).

Parameters
frequencyThe frequency that was closed.
Here is the caller graph for this function:

The documentation for this class was generated from the following files: