mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-13 12:50:37 -05:00
Switch to message buffer / dispatcher for Twitch event sub messages
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include "twitch-helpers.hpp"
|
||||
|
||||
#include <log-helper.hpp>
|
||||
#include <plugin-state-helpers.hpp>
|
||||
|
||||
namespace advss {
|
||||
|
||||
@@ -27,6 +26,8 @@ static constexpr std::string_view registerSubscriptionPath =
|
||||
#endif
|
||||
static const int reconnectDelay = 15;
|
||||
|
||||
#undef DispatchMessage
|
||||
|
||||
EventSub::EventSub() : QObject(nullptr)
|
||||
{
|
||||
_client.get_alog().clear_channels(
|
||||
@@ -59,20 +60,6 @@ EventSub::~EventSub()
|
||||
UnregisterInstance();
|
||||
}
|
||||
|
||||
static bool setupEventSubMessageClear()
|
||||
{
|
||||
AddIntervalResetStep(&EventSub::ClearAllEvents);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EventSub::_setupDone = setupEventSubMessageClear();
|
||||
|
||||
void EventSub::ClearEvents()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_messageMtx);
|
||||
_messages.clear();
|
||||
}
|
||||
|
||||
std::mutex EventSub::_instancesMtx;
|
||||
std::vector<EventSub *> EventSub::_instances;
|
||||
|
||||
@@ -89,14 +76,6 @@ void EventSub::UnregisterInstance()
|
||||
_instances.erase(it, _instances.end());
|
||||
}
|
||||
|
||||
void EventSub::ClearAllEvents()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_instancesMtx);
|
||||
for (const auto &eventSub : _instances) {
|
||||
eventSub->ClearEvents();
|
||||
}
|
||||
}
|
||||
|
||||
void EventSub::ConnectThread()
|
||||
{
|
||||
while (!_disconnect) {
|
||||
@@ -169,10 +148,9 @@ void EventSub::Disconnect()
|
||||
ClearActiveSubscriptions();
|
||||
}
|
||||
|
||||
std::vector<Event> EventSub::Events()
|
||||
EventSubMessageBuffer EventSub::RegisterForEvents()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_messageMtx);
|
||||
return _messages;
|
||||
return _dispatcher.RegisterClient();
|
||||
}
|
||||
|
||||
bool EventSub::SubscriptionIsActive(const std::string &id)
|
||||
@@ -358,8 +336,7 @@ void EventSub::HandleNotification(obs_data_t *data)
|
||||
event.type = obs_data_get_string(subscription, "type");
|
||||
OBSDataAutoRelease eventData = obs_data_get_obj(data, "event");
|
||||
event.data = eventData;
|
||||
std::lock_guard<std::mutex> lock(_messageMtx);
|
||||
_messages.emplace_back(event);
|
||||
_dispatcher.DispatchMessage(event);
|
||||
}
|
||||
|
||||
void EventSub::HandleReconnect(obs_data_t *data)
|
||||
|
||||
Reference in New Issue
Block a user