Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
message_processor.h
Go to the documentation of this file.
1#ifndef WAVELENGTH_MESSAGE_PROCESSOR_H
2#define WAVELENGTH_MESSAGE_PROCESSOR_H
3
4#include <QObject>
5
6class QWebSocket;
8
20class MessageProcessor final : public QObject {
21 Q_OBJECT
22
23public:
29 static MessageProcessor instance;
30 return &instance;
31 }
32
37
42
50 static bool AreFrequenciesEqual(const QString &frequency1, const QString &frequency2) {
51 return frequency1 == frequency2;
52 }
53
61 void ProcessIncomingMessage(const QString &message, const QString &frequency);
62
69 void ProcessIncomingBinaryMessage(const QByteArray &message, const QString &frequency);
70
79 void SetSocketMessageHandlers(QWebSocket *socket, QString frequency);
80
81private:
90 void ProcessMessageContent(const QJsonObject &message_object, const QString &frequency, const QString &message_id);
91
99 void ProcessSystemCommand(const QJsonObject &message_object, const QString &frequency);
100
107 void ProcessUserJoined(const QJsonObject &message_object, const QString &frequency);
108
115 void ProcessUserLeft(const QJsonObject &message_object, const QString &frequency);
116
122 void ProcessWavelengthClosed(const QString &frequency);
123
124signals:
130 void messageReceived(QString frequency, const QString &formatted_message);
131
137 void systemMessage(QString frequency, const QString &formatted_message);
138
143 void wavelengthClosed(QString frequency);
144
150 void userKicked(QString frequency, const QString &reason);
151
156 void pttGranted(QString frequency);
157
163 void pttDenied(QString frequency, QString reason);
164
170 void pttStartReceiving(QString frequency, QString sender_id);
171
176 void pttStopReceiving(QString frequency);
177
183 void audioDataReceived(QString frequency, const QByteArray &audio_data);
184
190 void remoteAudioAmplitudeUpdate(QString frequency, qreal amplitude);
191
192private:
198 explicit MessageProcessor(QObject *parent = nullptr);
199
203 ~MessageProcessor() override = default;
204};
205
206#endif // WAVELENGTH_MESSAGE_PROCESSOR_H
~MessageProcessor() override=default
Private destructor.
void pttStartReceiving(QString frequency, QString sender_id)
Emitted when another user starts transmitting audio on the frequency.
static MessageProcessor * GetInstance()
Gets the singleton instance of the MessageProcessor.
Definition message_processor.h:28
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 (s...
Definition message_processor.cpp:99
void messageReceived(QString frequency, const QString &formatted_message)
Emitted when a regular chat message (text or attachment placeholder) is processed.
void systemMessage(QString frequency, const QString &formatted_message)
Emitted when a system event message (e.g., user join/leave) is processed.
static bool AreFrequenciesEqual(const QString &frequency1, const QString &frequency2)
Compares two frequency strings for equality. Simple string comparison.
Definition message_processor.h:50
void pttStopReceiving(QString frequency)
Emitted when the currently transmitting user stops sending audio.
void wavelengthClosed(QString frequency)
Emitted when a wavelength is closed (either by host or server command).
MessageProcessor & operator=(const MessageProcessor &)=delete
Deleted assignment operator to prevent assignment.
void pttDenied(QString frequency, QString reason)
Emitted when the server denies permission to transmit audio (Push-to-Talk).
void audioDataReceived(QString frequency, const QByteArray &audio_data)
Emitted when raw audio data is received via a binary WebSocket message.
void ProcessWavelengthClosed(const QString &frequency)
Processes messages indicating a wavelength was closed (e.g., "wavelength_closed", "close_wavelength" ...
Definition message_processor.cpp:148
void userKicked(QString frequency, const QString &reason)
Emitted when the current user is kicked from a frequency.
void ProcessSystemCommand(const QJsonObject &message_object, const QString &frequency)
Processes messages of type "system_command". Handles commands like "ping", "close_wavelength",...
Definition message_processor.cpp:126
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...
Definition message_processor.cpp:134
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...
Definition message_processor.cpp:141
void pttGranted(QString frequency)
Emitted when the server grants permission to transmit audio (Push-to-Talk).
void ProcessIncomingMessage(const QString &message, const QString &frequency)
Processes an incoming text message (JSON) received from the WebSocket. Parses the JSON,...
Definition message_processor.cpp:9
void ProcessIncomingBinaryMessage(const QByteArray &message, const QString &frequency)
Processes an incoming binary message (expected to be audio data) received from the WebSocket....
Definition message_processor.cpp:60
void SetSocketMessageHandlers(QWebSocket *socket, QString frequency)
Connects the appropriate slots of this processor to the signals of a given QWebSocket....
Definition message_processor.cpp:64
MessageProcessor(const MessageProcessor &)=delete
Deleted copy constructor to prevent copying.
void remoteAudioAmplitudeUpdate(QString frequency, qreal amplitude)
Emitted when the server sends an update about the remote audio amplitude (optional).
Singleton service responsible for sending messages and files over WebSocket connections.
Definition message_service.h:18