Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PubSub client creation/pending topic resolving #3037

Merged
merged 7 commits into from
Jul 25, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Minor: Received Twitch messages now use the exact same timestamp (obtained from Twitch's server) for every Chatterino user instead of assuming message timestamp on client's side. (#3021)
- Minor: Received IRC messages use `time` message tag for timestamp if it's available. (#3021)
- Bugfix: Fixed "smiley" emotes being unable to be "Tabbed" with autocompletion, introduced in v2.3.3. (#3010)
- Bugfix: PubSub didn't properly try to resolve pending listens when the pending listens list was larger than 50. (#3037)
zneix marked this conversation as resolved.
Show resolved Hide resolved
- Dev: Ubuntu packages are now available (#2936)

## 2.3.3
Expand Down
22 changes: 22 additions & 0 deletions src/providers/twitch/PubsubClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "providers/twitch/PubsubActions.hpp"
#include "providers/twitch/PubsubHelpers.hpp"
#include "singletons/Settings.hpp"
#include "util/DebugCount.hpp"
#include "util/Helpers.hpp"
#include "util/RapidjsonHelpers.hpp"

Expand Down Expand Up @@ -59,6 +60,7 @@ namespace detail {
// This PubSubClient is already at its peak listens
return false;
}
DebugCount::increase("PubSub topic pending listens");

this->numListens_ += numRequestedListens;

Expand Down Expand Up @@ -868,6 +870,13 @@ PubSub::PubSub()

void PubSub::addClient()
{
if (this->addingClient)
{
return;
}

this->addingClient = true;

websocketpp::lib::error_code ec;
auto con = this->websocketClient.get_connection(TWITCH_PUBSUB_URL, ec);

Expand Down Expand Up @@ -1002,6 +1011,8 @@ void PubSub::listen(rapidjson::Document &&msg)

this->requests.emplace_back(
std::make_unique<rapidjson::Document>(std::move(msg)));

DebugCount::increase("PubSub topic backlog");
}

bool PubSub::tryListen(rapidjson::Document &msg)
Expand Down Expand Up @@ -1110,6 +1121,9 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl,

void PubSub::onConnectionOpen(WebsocketHandle hdl)
{
DebugCount::increase("PubSub connections");
this->addingClient = false;

auto client =
std::make_shared<detail::PubSubClient>(this->websocketClient, hdl);

Expand All @@ -1126,17 +1140,24 @@ void PubSub::onConnectionOpen(WebsocketHandle hdl)
const auto &request = *it;
if (client->listen(*request))
{
DebugCount::decrease("PubSub topic backlog");
it = this->requests.erase(it);
}
else
{
++it;
}
}

if (!this->requests.empty())
{
this->addClient();
}
}

void PubSub::onConnectionClose(WebsocketHandle hdl)
{
DebugCount::decrease("PubSub connections");
auto clientIt = this->clients.find(hdl);

// If this assert goes off, there's something wrong with the connection
Expand Down Expand Up @@ -1183,6 +1204,7 @@ void PubSub::handleListenResponse(const rapidjson::Document &msg)

if (error.isEmpty())
{
DebugCount::decrease("PubSub topic pending listens");
qCDebug(chatterinoPubsub)
<< "Successfully listened to nonce" << nonce;
// Nothing went wrong
Expand Down
1 change: 1 addition & 0 deletions src/providers/twitch/PubsubClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class PubSub
bool isListeningToTopic(const QString &topic);

void addClient();
std::atomic<bool> addingClient{false};

State state = State::Connected;

Expand Down