Base: Nitpick cleanup for obs-websocket.cpp

This commit is contained in:
tt2468 2021-12-21 17:52:46 -08:00
parent 91e3f5ee18
commit 0f303504e1
3 changed files with 14 additions and 4 deletions

View File

@ -16,8 +16,7 @@ WebSocketApi::Vendor *get_vendor(calldata_t *cd)
return static_cast<WebSocketApi::Vendor*>(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<obs_data_t*>(voidEventData);
if (!c->_eventCallback)
RETURN_FAILURE();
c->_eventCallback(v->_name, eventType, eventData);
RETURN_SUCCESS();

View File

@ -25,9 +25,11 @@ class WebSocketApi {
std::map<std::string, obs_websocket_request_callback> _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);

View File

@ -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());