diff --git a/src/WSEvents.cpp b/src/WSEvents.cpp
index 7bf30dc7..4fbd1d73 100644
--- a/src/WSEvents.cpp
+++ b/src/WSEvents.cpp
@@ -64,7 +64,7 @@ void* calldata_get_ptr(const calldata_t* data, const char* name) {
WSEvents* WSEvents::Instance = nullptr;
-WSEvents::WSEvents(WSServer* srv) {
+WSEvents::WSEvents(WSServerPtr srv) {
_srv = srv;
obs_frontend_add_event_callback(WSEvents::FrontendEventHandler, this);
diff --git a/src/WSEvents.h b/src/WSEvents.h
index 7b7cf95e..086d8a4f 100644
--- a/src/WSEvents.h
+++ b/src/WSEvents.h
@@ -28,7 +28,7 @@ with this program. If not, see
class WSEvents : public QObject {
Q_OBJECT
public:
- explicit WSEvents(WSServer* srv);
+ explicit WSEvents(WSServerPtr srv);
~WSEvents();
static void FrontendEventHandler(
enum obs_frontend_event event, void* privateData);
@@ -51,7 +51,7 @@ class WSEvents : public QObject {
void TransitionDurationChanged(int ms);
private:
- WSServer* _srv;
+ WSServerPtr _srv;
OBSSource currentScene;
bool pulse;
diff --git a/src/WSServer.cpp b/src/WSServer.cpp
index a7098d64..0c1fe7e7 100644
--- a/src/WSServer.cpp
+++ b/src/WSServer.cpp
@@ -34,8 +34,6 @@ using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;
-WSServer* WSServer::Instance = nullptr;
-
QString decodeBase64(const QString& source)
{
return QString::fromUtf8(
@@ -45,8 +43,23 @@ QString decodeBase64(const QString& source)
);
}
-WSServer::WSServer(QObject* parent)
- : QObject(parent),
+WSServerPtr WSServer::_instance = WSServerPtr(nullptr);
+
+WSServerPtr WSServer::Current()
+{
+ if (!_instance) {
+ ResetCurrent();
+ }
+ return _instance;
+}
+
+void WSServer::ResetCurrent()
+{
+ _instance = WSServerPtr(new WSServer());
+}
+
+WSServer::WSServer()
+ : QObject(nullptr),
_connections(),
_clMutex(QMutex::Recursive)
{
diff --git a/src/WSServer.h b/src/WSServer.h
index 8c243700..6cfd120b 100644
--- a/src/WSServer.h
+++ b/src/WSServer.h
@@ -21,6 +21,7 @@ with this program. If not, see
#include
#include
+#include
#include
#include