mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
WSEvents: remove singleton + refactor pointer handling in plugin entrypoint
This commit is contained in:
parent
3d9eac8e6d
commit
e352d9750d
@ -83,16 +83,6 @@ const char* calldata_get_string(const calldata_t* data, const char* name) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
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),
|
||||||
_streamStarttime(0),
|
_streamStarttime(0),
|
||||||
@ -144,6 +134,8 @@ WSEvents::~WSEvents() {
|
|||||||
|
|
||||||
obs_frontend_remove_event_callback(WSEvents::FrontendEventHandler, this);
|
obs_frontend_remove_event_callback(WSEvents::FrontendEventHandler, this);
|
||||||
os_cpu_usage_info_destroy(cpuUsageInfo);
|
os_cpu_usage_info_destroy(cpuUsageInfo);
|
||||||
|
|
||||||
|
blog(LOG_INFO, "wsevents destroyed");
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSEvents::FrontendEventHandler(enum obs_frontend_event event, void* private_data) {
|
void WSEvents::FrontendEventHandler(enum obs_frontend_event event, void* private_data) {
|
||||||
|
@ -29,17 +29,11 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
|||||||
|
|
||||||
#include "WSServer.h"
|
#include "WSServer.h"
|
||||||
|
|
||||||
class WSEvents;
|
|
||||||
typedef QSharedPointer<WSEvents> WSEventsPtr;
|
|
||||||
|
|
||||||
class WSEvents : public QObject
|
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();
|
||||||
|
|
||||||
@ -60,8 +54,6 @@ private slots:
|
|||||||
void TransitionDurationChanged(int ms);
|
void TransitionDurationChanged(int ms);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static WSEventsPtr _instance;
|
|
||||||
|
|
||||||
WSServerPtr _srv;
|
WSServerPtr _srv;
|
||||||
QTimer streamStatusTimer;
|
QTimer streamStatusTimer;
|
||||||
QTimer heartbeatTimer;
|
QTimer heartbeatTimer;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include "obs-websocket.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "WSEvents.h"
|
#include "WSEvents.h"
|
||||||
@ -114,7 +115,7 @@ HandlerResponse WSRequestHandler::HandleSetHeartbeat(WSRequestHandler* req) {
|
|||||||
return req->SendErrorResponse("Heartbeat <enable> parameter missing");
|
return req->SendErrorResponse("Heartbeat <enable> parameter missing");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto events = WSEvents::Current();
|
auto events = GetEventsSystem();
|
||||||
events->HeartbeatIsActive = 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();
|
||||||
@ -173,7 +174,7 @@ HandlerResponse WSRequestHandler::HandleGetFilenameFormatting(WSRequestHandler*
|
|||||||
* @since 4.6.0
|
* @since 4.6.0
|
||||||
*/
|
*/
|
||||||
HandlerResponse WSRequestHandler::HandleGetStats(WSRequestHandler* req) {
|
HandlerResponse WSRequestHandler::HandleGetStats(WSRequestHandler* req) {
|
||||||
OBSDataAutoRelease stats = WSEvents::Current()->GetStats();
|
OBSDataAutoRelease stats = GetEventsSystem()->GetStats();
|
||||||
|
|
||||||
OBSDataAutoRelease response = obs_data_create();
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
obs_data_set_obj(response, "stats", stats);
|
obs_data_set_obj(response, "stats", stats);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include "obs-websocket.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "WSEvents.h"
|
#include "WSEvents.h"
|
||||||
|
|
||||||
@ -20,7 +21,7 @@
|
|||||||
* @since 0.3
|
* @since 0.3
|
||||||
*/
|
*/
|
||||||
HandlerResponse WSRequestHandler::HandleGetStreamingStatus(WSRequestHandler* req) {
|
HandlerResponse WSRequestHandler::HandleGetStreamingStatus(WSRequestHandler* req) {
|
||||||
auto events = WSEvents::Current();
|
auto events = GetEventsSystem();
|
||||||
|
|
||||||
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());
|
||||||
|
@ -38,7 +38,9 @@ void ___output_dummy_addref(obs_output_t*) {}
|
|||||||
OBS_DECLARE_MODULE()
|
OBS_DECLARE_MODULE()
|
||||||
OBS_MODULE_USE_DEFAULT_LOCALE("obs-websocket", "en-US")
|
OBS_MODULE_USE_DEFAULT_LOCALE("obs-websocket", "en-US")
|
||||||
|
|
||||||
SettingsDialog* settings_dialog;
|
WSEventsPtr _eventsSystem;
|
||||||
|
|
||||||
|
std::unique_ptr<SettingsDialog> _settingsDialog;
|
||||||
|
|
||||||
bool obs_module_load(void) {
|
bool obs_module_load(void) {
|
||||||
blog(LOG_INFO, "you can haz websockets (version %s)", OBS_WEBSOCKET_VERSION);
|
blog(LOG_INFO, "you can haz websockets (version %s)", OBS_WEBSOCKET_VERSION);
|
||||||
@ -50,26 +52,27 @@ bool obs_module_load(void) {
|
|||||||
config->MigrateFromGlobalSettings(); // TODO remove this on the next minor jump
|
config->MigrateFromGlobalSettings(); // TODO remove this on the next minor jump
|
||||||
config->Load();
|
config->Load();
|
||||||
|
|
||||||
WSEvents::ResetCurrent(WSServer::Current());
|
_eventsSystem = WSEventsPtr(new WSEvents(WSServer::Current()));
|
||||||
|
|
||||||
if (config->ServerEnabled) {
|
if (config->ServerEnabled) {
|
||||||
WSServer::Current()->start(config->ServerPort);
|
WSServer::Current()->start(config->ServerPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
// UI setup
|
// UI setup
|
||||||
QAction* menu_action = (QAction*)obs_frontend_add_tools_menu_qaction(
|
|
||||||
obs_module_text("OBSWebsocket.Menu.SettingsItem")
|
|
||||||
);
|
|
||||||
|
|
||||||
obs_frontend_push_ui_translation(obs_module_get_string);
|
obs_frontend_push_ui_translation(obs_module_get_string);
|
||||||
QMainWindow* main_window = (QMainWindow*)obs_frontend_get_main_window();
|
QMainWindow* mainWindow = (QMainWindow*)obs_frontend_get_main_window();
|
||||||
settings_dialog = new SettingsDialog(main_window);
|
_settingsDialog = std::unique_ptr<SettingsDialog>(
|
||||||
|
new SettingsDialog(mainWindow)
|
||||||
|
);
|
||||||
obs_frontend_pop_ui_translation();
|
obs_frontend_pop_ui_translation();
|
||||||
|
|
||||||
auto menu_cb = [] {
|
const char* menuActionText =
|
||||||
settings_dialog->ToggleShowHide();
|
obs_module_text("OBSWebsocket.Menu.SettingsItem");
|
||||||
};
|
QAction* menuAction =
|
||||||
menu_action->connect(menu_action, &QAction::triggered, menu_cb);
|
(QAction*)obs_frontend_add_tools_menu_qaction(menuActionText);
|
||||||
|
QObject::connect(menuAction, &QAction::triggered, [] {
|
||||||
|
_settingsDialog->ToggleShowHide();
|
||||||
|
});
|
||||||
|
|
||||||
// Loading finished
|
// Loading finished
|
||||||
blog(LOG_INFO, "module loaded!");
|
blog(LOG_INFO, "module loaded!");
|
||||||
@ -82,3 +85,6 @@ void obs_module_unload() {
|
|||||||
blog(LOG_INFO, "goodbye!");
|
blog(LOG_INFO, "goodbye!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WSEventsPtr GetEventsSystem() {
|
||||||
|
return _eventsSystem;
|
||||||
|
}
|
||||||
|
@ -19,6 +19,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <obs.hpp>
|
#include <obs.hpp>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
void ___source_dummy_addref(obs_source_t*);
|
void ___source_dummy_addref(obs_source_t*);
|
||||||
void ___sceneitem_dummy_addref(obs_sceneitem_t*);
|
void ___sceneitem_dummy_addref(obs_sceneitem_t*);
|
||||||
@ -37,6 +38,11 @@ using OBSDataArrayAutoRelease =
|
|||||||
using OBSOutputAutoRelease =
|
using OBSOutputAutoRelease =
|
||||||
OBSRef<obs_output_t*, ___output_dummy_addref, obs_output_release>;
|
OBSRef<obs_output_t*, ___output_dummy_addref, obs_output_release>;
|
||||||
|
|
||||||
|
class WSEvents;
|
||||||
|
typedef std::shared_ptr<WSEvents> WSEventsPtr;
|
||||||
|
|
||||||
|
std::shared_ptr<WSEvents> GetEventsSystem();
|
||||||
|
|
||||||
#define OBS_WEBSOCKET_VERSION "4.6.0"
|
#define OBS_WEBSOCKET_VERSION "4.6.0"
|
||||||
|
|
||||||
#define blog(level, msg, ...) blog(level, "[obs-websocket] " msg, ##__VA_ARGS__)
|
#define blog(level, msg, ...) blog(level, "[obs-websocket] " msg, ##__VA_ARGS__)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user