refactor: Twitch PubSub client (#5059)

* Remove unused `setAccountData` function

* Move PubSub out of TwitchIrcServer and into Application

* Add changelog entry

* fix: assert feedback

* Add PubSub::unlistenPrefix as per review suggestion

* Fix tests

* quit pubsub on exit

might conflict with exit removal, so can be reverted but this shows it's possible

* Don't manually call stop on clients, it's called when the connection is closed

* nit: rename `mainThread` to `thread`

* Join in a thread!!!!!!!!
This commit is contained in:
pajlada
2024-01-06 13:18:37 +01:00
committed by GitHub
parent e48d868e8c
commit 416806bb0a
14 changed files with 458 additions and 484 deletions
+5 -2
View File
@@ -22,6 +22,8 @@ PubSubClient::PubSubClient(WebsocketClient &websocketClient,
const PubSubClientOptions &clientOptions)
: websocketClient_(websocketClient)
, handle_(handle)
, heartbeatTimer_(std::make_shared<boost::asio::steady_timer>(
this->websocketClient_.get_io_service()))
, clientOptions_(clientOptions)
{
}
@@ -40,6 +42,7 @@ void PubSubClient::stop()
assert(this->started_);
this->started_ = false;
this->heartbeatTimer_->cancel();
}
void PubSubClient::close(const std::string &reason,
@@ -187,8 +190,8 @@ void PubSubClient::ping()
auto self = this->shared_from_this();
runAfter(this->websocketClient_.get_io_service(),
this->clientOptions_.pingInterval_, [self](auto timer) {
runAfter(this->heartbeatTimer_, this->clientOptions_.pingInterval_,
[self](auto timer) {
if (!self->started_)
{
return;