mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
events: singleton shared pointer refactor
This commit is contained in:
@ -62,7 +62,15 @@ void* calldata_get_ptr(const calldata_t* data, const char* name) {
|
|||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
WSEvents* WSEvents::Instance = nullptr;
|
WSEventsPtr WSEvents::_instance = WSEventsPtr(nullptr);
|
||||||
|
|
||||||
|
WSEventsPtr WSEvents::Current() {
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WSEvents::ResetCurrent(WSServerPtr srv) {
|
||||||
|
_instance = WSEventsPtr(new WSEvents(srv));
|
||||||
|
}
|
||||||
|
|
||||||
WSEvents::WSEvents(WSServerPtr srv) {
|
WSEvents::WSEvents(WSServerPtr srv) {
|
||||||
_srv = srv;
|
_srv = srv;
|
||||||
|
@ -22,17 +22,27 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
|||||||
|
|
||||||
#include <obs.hpp>
|
#include <obs.hpp>
|
||||||
#include <obs-frontend-api.h>
|
#include <obs-frontend-api.h>
|
||||||
|
|
||||||
#include <QListWidgetItem>
|
#include <QListWidgetItem>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
|
||||||
#include "WSServer.h"
|
#include "WSServer.h"
|
||||||
|
|
||||||
class WSEvents : public QObject {
|
class WSEvents;
|
||||||
|
typedef QSharedPointer<WSEvents> WSEventsPtr;
|
||||||
|
|
||||||
|
class WSEvents : public QObject
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static WSEventsPtr Current();
|
||||||
|
static void ResetCurrent(WSServerPtr srv);
|
||||||
|
|
||||||
explicit WSEvents(WSServerPtr srv);
|
explicit WSEvents(WSServerPtr srv);
|
||||||
~WSEvents();
|
~WSEvents();
|
||||||
static void FrontendEventHandler(
|
static void FrontendEventHandler(
|
||||||
enum obs_frontend_event event, void* privateData);
|
enum obs_frontend_event event, void* privateData);
|
||||||
static WSEvents* Instance;
|
|
||||||
void connectSceneSignals(obs_source_t* scene);
|
void connectSceneSignals(obs_source_t* scene);
|
||||||
|
|
||||||
void hookTransitionBeginEvent();
|
void hookTransitionBeginEvent();
|
||||||
@ -51,6 +61,8 @@ class WSEvents : public QObject {
|
|||||||
void TransitionDurationChanged(int ms);
|
void TransitionDurationChanged(int ms);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static WSEventsPtr _instance;
|
||||||
|
|
||||||
WSServerPtr _srv;
|
WSServerPtr _srv;
|
||||||
OBSSource currentScene;
|
OBSSource currentScene;
|
||||||
|
|
||||||
|
@ -121,12 +121,12 @@ void WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WSEvents::Instance->HeartbeatIsActive =
|
auto events = WSEvents::Current();
|
||||||
obs_data_get_bool(req->data, "enable");
|
|
||||||
|
events->HeartbeatIsActive = obs_data_get_bool(req->data, "enable");
|
||||||
|
|
||||||
OBSDataAutoRelease response = obs_data_create();
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
obs_data_set_bool(response, "enable",
|
obs_data_set_bool(response, "enable", events->HeartbeatIsActive);
|
||||||
WSEvents::Instance->HeartbeatIsActive);
|
|
||||||
req->SendOKResponse(response);
|
req->SendOKResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
* @since 0.3
|
* @since 0.3
|
||||||
*/
|
*/
|
||||||
void WSRequestHandler::HandleGetStreamingStatus(WSRequestHandler* req) {
|
void WSRequestHandler::HandleGetStreamingStatus(WSRequestHandler* req) {
|
||||||
|
auto events = WSEvents::Current();
|
||||||
|
|
||||||
OBSDataAutoRelease data = obs_data_create();
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
obs_data_set_bool(data, "streaming", obs_frontend_streaming_active());
|
obs_data_set_bool(data, "streaming", obs_frontend_streaming_active());
|
||||||
obs_data_set_bool(data, "recording", obs_frontend_recording_active());
|
obs_data_set_bool(data, "recording", obs_frontend_recording_active());
|
||||||
@ -28,13 +30,13 @@
|
|||||||
|
|
||||||
const char* tc = nullptr;
|
const char* tc = nullptr;
|
||||||
if (obs_frontend_streaming_active()) {
|
if (obs_frontend_streaming_active()) {
|
||||||
tc = WSEvents::Instance->GetStreamingTimecode();
|
tc = events->GetStreamingTimecode();
|
||||||
obs_data_set_string(data, "stream-timecode", tc);
|
obs_data_set_string(data, "stream-timecode", tc);
|
||||||
bfree((void*)tc);
|
bfree((void*)tc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obs_frontend_recording_active()) {
|
if (obs_frontend_recording_active()) {
|
||||||
tc = WSEvents::Instance->GetRecordingTimecode();
|
tc = events->GetRecordingTimecode();
|
||||||
obs_data_set_string(data, "rec-timecode", tc);
|
obs_data_set_string(data, "rec-timecode", tc);
|
||||||
bfree((void*)tc);
|
bfree((void*)tc);
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ bool obs_module_load(void) {
|
|||||||
auto config = Config::Current();
|
auto config = Config::Current();
|
||||||
config->Load();
|
config->Load();
|
||||||
|
|
||||||
WSEvents::Instance = new WSEvents(WSServer::Current());
|
WSEvents::ResetCurrent(WSServer::Current());
|
||||||
|
|
||||||
if (config->ServerEnabled) {
|
if (config->ServerEnabled) {
|
||||||
WSServer::Current()->start(config->ServerPort);
|
WSServer::Current()->start(config->ServerPort);
|
||||||
|
Reference in New Issue
Block a user