Chatterino
SeventvEventAPI.hpp
Go to the documentation of this file.
1 #pragma once
2 
7 #include "util/QStringHash.hpp"
8 
9 #include <pajlada/signals/signal.hpp>
10 
11 namespace chatterino {
12 
13 class SeventvEventAPI : public BasicPubSubManager<SeventvEventAPISubscription>
14 {
15  template <typename T>
16  using Signal =
17  pajlada::Signals::Signal<T>; // type-id is vector<T, Alloc<T>>
18 
19 public:
20  SeventvEventAPI(QString host,
21  std::chrono::milliseconds defaultHeartbeatInterval =
22  std::chrono::milliseconds(25000));
23 
24  struct {
25  Signal<SeventvEventAPIEmoteAddDispatch> emoteAdded;
26  Signal<SeventvEventAPIEmoteUpdateDispatch> emoteUpdated;
27  Signal<SeventvEventAPIEmoteRemoveDispatch> emoteRemoved;
28  Signal<SeventvEventAPIUserConnectionUpdateDispatch> userUpdated;
29  } signals_; // NOLINT(readability-identifier-naming)
30 
38  void subscribeUser(const QString &userID, const QString &emoteSetID);
39 
41  void unsubscribeUser(const QString &id);
43  void unsubscribeEmoteSet(const QString &id);
44 
45 protected:
46  std::shared_ptr<BasicPubSubClient<SeventvEventAPISubscription>>
48  websocketpp::connection_hdl hdl) override;
49  void onMessage(
50  websocketpp::connection_hdl hdl,
52  msg) override;
53 
54 private:
55  void handleDispatch(const SeventvEventAPIDispatch &dispatch);
56 
57  std::unordered_set<QString> subscribedEmoteSets_;
58  std::unordered_set<QString> subscribedUsers_;
59  std::chrono::milliseconds heartbeatInterval_;
60 };
61 
62 } // namespace chatterino
Signal< SeventvEventAPIEmoteAddDispatch > emoteAdded
Definition: SeventvEventAPI.hpp:25
void subscribeUser(const QString &userID, const QString &emoteSetID)
Definition: SeventvEventAPI.cpp:18
SeventvEventAPI(QString host, std::chrono::milliseconds defaultHeartbeatInterval=std::chrono::milliseconds(25000))
Definition: SeventvEventAPI.cpp:11
struct chatterino::SeventvEventAPI::@1 signals_
void unsubscribeEmoteSet(const QString &id)
Definition: SeventvEventAPI.cpp:33
std::shared_ptr< BasicPubSubClient< SeventvEventAPISubscription > > createClient(liveupdates::WebsocketClient &client, websocketpp::connection_hdl hdl) override
Definition: SeventvEventAPI.cpp:51
Definition: Application.cpp:48
void unsubscribeUser(const QString &id)
Definition: SeventvEventAPI.cpp:42
void onMessage(websocketpp::connection_hdl hdl, BasicPubSubManager< SeventvEventAPISubscription >::WebsocketMessagePtr msg) override
Definition: SeventvEventAPI.cpp:60
Signal< SeventvEventAPIEmoteUpdateDispatch > emoteUpdated
Definition: SeventvEventAPI.hpp:26
Definition: SeventvEventAPI.hpp:13
websocketpp::client< chatterino::BasicPubSubConfig > WebsocketClient
Definition: BasicPubSubWebsocket.hpp:31
Definition: BasicPubSubManager.hpp:58
Definition: SeventvEventAPIDispatch.hpp:11
Signal< SeventvEventAPIUserConnectionUpdateDispatch > userUpdated
Definition: SeventvEventAPI.hpp:28
Signal< SeventvEventAPIEmoteRemoveDispatch > emoteRemoved
Definition: SeventvEventAPI.hpp:27