From 959347337fe75aa8832fe01592be4c522d1fa9c9 Mon Sep 17 00:00:00 2001
From: tt2468 <tt2468@gmail.com>
Date: Sun, 21 Nov 2021 00:32:50 -0800
Subject: [PATCH] lib: Add plugin example + slightly change names

---
 lib/example/simplest-plugin.c | 40 +++++++++++++++++++++++++++++++++++
 lib/obs-websocket-api.h       |  6 +++---
 2 files changed, 43 insertions(+), 3 deletions(-)
 create mode 100644 lib/example/simplest-plugin.c

diff --git a/lib/example/simplest-plugin.c b/lib/example/simplest-plugin.c
new file mode 100644
index 00000000..617736fd
--- /dev/null
+++ b/lib/example/simplest-plugin.c
@@ -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);
+}
diff --git a/lib/obs-websocket-api.h b/lib/obs-websocket-api.h
index 967af6d8..3ad6412f 100644
--- a/lib/obs-websocket-api.h
+++ b/lib/obs-websocket-api.h
@@ -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};