mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-06-21 12:03:43 -05:00
Disconnect Twitch chat and event connection on plugin stop
This commit is contained in:
parent
1ce332a91d
commit
ed17c2ac6d
|
|
@ -3,6 +3,7 @@
|
|||
#include "twitch-helpers.hpp"
|
||||
|
||||
#include <log-helper.hpp>
|
||||
#include <plugin-state-helpers.hpp>
|
||||
|
||||
#undef DispatchMessage
|
||||
|
||||
|
|
@ -339,6 +340,24 @@ static constexpr std::string_view defaultURL =
|
|||
std::map<TwitchChatConnection::ChatMapKey, std::weak_ptr<TwitchChatConnection>>
|
||||
TwitchChatConnection::_chatMap = {};
|
||||
|
||||
void TwitchChatConnection::DisconnectAll()
|
||||
{
|
||||
for (auto &[key, weakConn] : _chatMap) {
|
||||
auto conn = weakConn.lock();
|
||||
if (conn) {
|
||||
conn->Disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool setupChatConnectionSupport()
|
||||
{
|
||||
AddStopStep(TwitchChatConnection::DisconnectAll);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool _chatSetup = setupChatConnectionSupport();
|
||||
|
||||
TwitchChatConnection::TwitchChatConnection(const TwitchToken &token,
|
||||
const TwitchChannel &channel)
|
||||
: QObject(nullptr),
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ public:
|
|||
static std::shared_ptr<TwitchChatConnection>
|
||||
GetChatConnection(const TwitchToken &token,
|
||||
const TwitchChannel &channel);
|
||||
static void DisconnectAll();
|
||||
[[nodiscard]] ChatMessageBuffer RegisterForMessages();
|
||||
[[nodiscard]] ChatMessageBuffer RegisterForWhispers();
|
||||
void SendChatMessage(const std::string &message);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "twitch-helpers.hpp"
|
||||
|
||||
#include <log-helper.hpp>
|
||||
#include <plugin-state-helpers.hpp>
|
||||
|
||||
#ifdef VERIFY_TIMESTAMPS
|
||||
#include "date/tz.h"
|
||||
|
|
@ -71,6 +72,22 @@ void EventSub::UnregisterInstance()
|
|||
_instances.erase(it, _instances.end());
|
||||
}
|
||||
|
||||
void EventSub::DisconnectAll()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_instancesMtx);
|
||||
for (auto *instance : _instances) {
|
||||
instance->Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
static bool setupEventSubSupport()
|
||||
{
|
||||
AddStopStep(EventSub::DisconnectAll);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool _eventSubSetup = setupEventSubSupport();
|
||||
|
||||
void EventSub::ConnectThread()
|
||||
{
|
||||
_client->reset();
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ public:
|
|||
|
||||
void Connect();
|
||||
void Disconnect();
|
||||
static void DisconnectAll();
|
||||
[[nodiscard]] EventSubMessageBuffer RegisterForEvents();
|
||||
bool SubscriptionIsActive(const std::string &id);
|
||||
static std::string AddEventSubscription(std::shared_ptr<TwitchToken>,
|
||||
|
|
|
|||
|
|
@ -547,16 +547,18 @@ bool MacroConditionTwitch::CheckChatMessageRemove(TwitchToken &token)
|
|||
|
||||
bool MacroConditionTwitch::ChatConnectionIsSetup(TwitchToken &token)
|
||||
{
|
||||
if (_chatConnection) {
|
||||
_chatConnection->ConnectToChat();
|
||||
return true;
|
||||
}
|
||||
|
||||
_chatConnection =
|
||||
TwitchChatConnection::GetChatConnection(token, _channel);
|
||||
if (!_chatConnection) {
|
||||
_chatConnection = TwitchChatConnection::GetChatConnection(
|
||||
token, _channel);
|
||||
if (!_chatConnection) {
|
||||
return false;
|
||||
}
|
||||
_chatBuffer = _chatConnection->RegisterForMessages();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
_chatBuffer = _chatConnection->RegisterForMessages();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MacroConditionTwitch::HandleChatEvents(
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user