mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
lib: Add plugin example + slightly change names
This commit is contained in:
parent
c8c6417d63
commit
959347337f
40
lib/example/simplest-plugin.c
Normal file
40
lib/example/simplest-plugin.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include <obs-module.h>
|
||||
|
||||
#include "../obs-websocket-api.h"
|
||||
|
||||
OBS_DECLARE_MODULE()
|
||||
OBS_MODULE_USE_DEFAULT_LOCALE(PLUGIN_NAME, "en-US")
|
||||
|
||||
obs_websocket_vendor vendor;
|
||||
|
||||
bool obs_module_load(void)
|
||||
{
|
||||
blog(LOG_INFO, "Example obs-websocket-api plugin loaded!");
|
||||
return true;
|
||||
}
|
||||
|
||||
void example_request_cb(obs_data_t *request_data, obs_data_t *response_data, void *priv_data);
|
||||
void obs_module_post_load(void)
|
||||
{
|
||||
vendor = obs_websocket_register_vendor("api_example_plugin");
|
||||
if (!vendor) {
|
||||
blog(LOG_ERROR, "Vendor registration failed! (obs-websocket should have logged something if installed properly.)");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!obs_websocket_vendor_register_request(vendor, "example_request", example_request_cb, NULL))
|
||||
blog(LOG_ERROR, "Failed to register `example_request` request with obs-websocket.");
|
||||
}
|
||||
|
||||
void obs_module_unload(void)
|
||||
{
|
||||
blog(LOG_INFO, "Example obs-websocket-api plugin unloaded!");
|
||||
}
|
||||
|
||||
void example_request_cb(obs_data_t *request_data, obs_data_t *response_data, void *priv_data)
|
||||
{
|
||||
if (obs_data_has_user_value(request_data, "ping"))
|
||||
obs_data_set_bool(response_data, "pong", true);
|
||||
|
||||
UNUSED_PARAMETER(priv_data);
|
||||
}
|
@ -81,7 +81,7 @@ inline obs_websocket_vendor obs_websocket_register_vendor(const char *vendor_nam
|
||||
}
|
||||
|
||||
// Registers a new request for a vendor
|
||||
inline bool obs_websocket_register_request(obs_websocket_vendor vendor, const char *request_type, obs_websocket_request_callback_function request_callback, void* priv_data)
|
||||
inline bool obs_websocket_vendor_register_request(obs_websocket_vendor vendor, const char *request_type, obs_websocket_request_callback_function request_callback, void* priv_data)
|
||||
{
|
||||
calldata_t cd = {0};
|
||||
|
||||
@ -99,7 +99,7 @@ inline bool obs_websocket_register_request(obs_websocket_vendor vendor, const ch
|
||||
}
|
||||
|
||||
// Unregisters an existing vendor request
|
||||
inline bool obs_websocket_unregister_request(obs_websocket_vendor vendor, const char *request_type)
|
||||
inline bool obs_websocket_vendor_unregister_request(obs_websocket_vendor vendor, const char *request_type)
|
||||
{
|
||||
calldata_t cd = {0};
|
||||
|
||||
@ -113,7 +113,7 @@ inline bool obs_websocket_unregister_request(obs_websocket_vendor vendor, const
|
||||
|
||||
// Does not affect event_data refcount.
|
||||
// Emits an event under the vendor's name
|
||||
inline bool obs_websocket_emit_event(obs_websocket_vendor vendor, const char *event_name, obs_data_t *event_data)
|
||||
inline bool obs_websocket_vendor_emit_event(obs_websocket_vendor vendor, const char *event_name, obs_data_t *event_data)
|
||||
{
|
||||
calldata_t cd = {0};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user