2022-05-07 17:22:39 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "providers/twitch/PubSubClientOptions.hpp"
|
|
|
|
#include "providers/twitch/PubSubWebsocket.hpp"
|
|
|
|
|
|
|
|
#include <pajlada/signals/signal.hpp>
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include <QString>
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2022-12-31 15:41:01 +01:00
|
|
|
struct PubSubMessage;
|
|
|
|
struct PubSubListenMessage;
|
|
|
|
|
2022-05-07 17:22:39 +02:00
|
|
|
struct TopicData {
|
|
|
|
QString topic;
|
|
|
|
bool authed{false};
|
|
|
|
bool persistent{false};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Listener : TopicData {
|
|
|
|
bool confirmed{false};
|
|
|
|
};
|
|
|
|
|
|
|
|
class PubSubClient : public std::enable_shared_from_this<PubSubClient>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct UnlistenPrefixResponse {
|
|
|
|
std::vector<QString> topics;
|
|
|
|
QString nonce;
|
|
|
|
};
|
|
|
|
|
|
|
|
// The max amount of topics we may listen to with a single connection
|
|
|
|
static constexpr std::vector<QString>::size_type MAX_LISTENS = 50;
|
|
|
|
|
|
|
|
PubSubClient(WebsocketClient &_websocketClient, WebsocketHandle _handle,
|
|
|
|
const PubSubClientOptions &clientOptions);
|
|
|
|
|
|
|
|
void start();
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
void close(const std::string &reason,
|
|
|
|
websocketpp::close::status::value code =
|
|
|
|
websocketpp::close::status::normal);
|
|
|
|
|
2024-01-17 21:05:44 +01:00
|
|
|
bool listen(const PubSubListenMessage &msg);
|
2022-05-07 17:22:39 +02:00
|
|
|
UnlistenPrefixResponse unlistenPrefix(const QString &prefix);
|
|
|
|
|
|
|
|
void handleListenResponse(const PubSubMessage &message);
|
|
|
|
void handleUnlistenResponse(const PubSubMessage &message);
|
|
|
|
|
|
|
|
void handlePong();
|
|
|
|
|
|
|
|
bool isListeningToTopic(const QString &topic);
|
|
|
|
|
|
|
|
std::vector<Listener> getListeners() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ping();
|
|
|
|
bool send(const char *payload);
|
|
|
|
|
|
|
|
WebsocketClient &websocketClient_;
|
|
|
|
WebsocketHandle handle_;
|
|
|
|
uint16_t numListens_ = 0;
|
|
|
|
|
|
|
|
std::vector<Listener> listeners_;
|
|
|
|
|
|
|
|
std::atomic<bool> awaitingPong_{false};
|
|
|
|
std::atomic<bool> started_{false};
|
|
|
|
|
2024-01-06 13:18:37 +01:00
|
|
|
std::shared_ptr<boost::asio::steady_timer> heartbeatTimer_;
|
2022-05-07 17:22:39 +02:00
|
|
|
const PubSubClientOptions &clientOptions_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace chatterino
|