From 0f303504e1311a2ac5526f9054e3ceef780351a6 Mon Sep 17 00:00:00 2001 From: tt2468 Date: Tue, 21 Dec 2021 17:52:46 -0800 Subject: [PATCH] Base: Nitpick cleanup for obs-websocket.cpp --- src/WebSocketApi.cpp | 11 +++++++++-- src/WebSocketApi.h | 4 +++- src/obs-websocket.cpp | 3 ++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/WebSocketApi.cpp b/src/WebSocketApi.cpp index bd5540ba..c7901764 100644 --- a/src/WebSocketApi.cpp +++ b/src/WebSocketApi.cpp @@ -16,8 +16,7 @@ WebSocketApi::Vendor *get_vendor(calldata_t *cd) return static_cast(voidVendor); } -WebSocketApi::WebSocketApi(EventCallback cb) : - _eventCallback(cb) +WebSocketApi::WebSocketApi() { blog_debug("[WebSocketApi::WebSocketApi] Setting up..."); @@ -50,6 +49,11 @@ WebSocketApi::~WebSocketApi() blog_debug("[WebSocketApi::~WebSocketApi] Finished."); } +void WebSocketApi::SetEventCallback(EventCallback cb) +{ + _eventCallback = cb; +} + enum WebSocketApi::RequestReturnCode WebSocketApi::PerformVendorRequest(std::string vendorName, std::string requestType, obs_data_t *requestData, obs_data_t *responseData) { std::shared_lock l(_mutex); @@ -196,6 +200,9 @@ void WebSocketApi::vendor_event_emit_cb(void *priv_data, calldata_t *cd) auto eventData = static_cast(voidEventData); + if (!c->_eventCallback) + RETURN_FAILURE(); + c->_eventCallback(v->_name, eventType, eventData); RETURN_SUCCESS(); diff --git a/src/WebSocketApi.h b/src/WebSocketApi.h index 78d02cea..5c18c678 100644 --- a/src/WebSocketApi.h +++ b/src/WebSocketApi.h @@ -25,9 +25,11 @@ class WebSocketApi { std::map _requests; }; - WebSocketApi(EventCallback cb); + WebSocketApi(); ~WebSocketApi(); + void SetEventCallback(EventCallback cb); + enum RequestReturnCode PerformVendorRequest(std::string vendorName, std::string requestName, obs_data_t *requestData, obs_data_t *responseData); static void get_ph_cb(void *priv_data, calldata_t *cd); diff --git a/src/obs-websocket.cpp b/src/obs-websocket.cpp index 81804c4b..58345e9a 100644 --- a/src/obs-websocket.cpp +++ b/src/obs-websocket.cpp @@ -56,7 +56,8 @@ bool obs_module_load(void) // Initialize event handler before server, as the server configures the event handler. _eventHandler = EventHandlerPtr(new EventHandler()); - _webSocketApi = WebSocketApiPtr(new WebSocketApi(WebSocketApiEventCallback)); + _webSocketApi = WebSocketApiPtr(new WebSocketApi()); + _webSocketApi->SetEventCallback(WebSocketApiEventCallback); _webSocketServer = WebSocketServerPtr(new WebSocketServer());