@@ -22,14 +22,15 @@ with this program. If not, see <https://www.gnu.org/licenses/>
22
22
23
23
#include <obs.h>
24
24
25
- #define OBS_WEBSOCKET_API_VERSION 2
25
+ #define OBS_WEBSOCKET_API_VERSION 3
26
26
27
27
#ifdef __cplusplus
28
28
extern "C" {
29
29
#endif
30
30
31
31
typedef void * obs_websocket_vendor ;
32
32
typedef void (* obs_websocket_request_callback_function )(obs_data_t * , obs_data_t * , void * );
33
+ typedef void (* obs_websocket_event_callback_function )(uint64_t , const char * , const char * , void * );
33
34
34
35
struct obs_websocket_request_response {
35
36
unsigned int status_code ;
@@ -44,6 +45,11 @@ struct obs_websocket_request_callback {
44
45
void * priv_data ;
45
46
};
46
47
48
+ struct obs_websocket_event_callback {
49
+ obs_websocket_event_callback_function callback ;
50
+ void * priv_data ;
51
+ };
52
+
47
53
static proc_handler_t * _ph ;
48
54
49
55
/* ==================== INTERNAL API FUNCTIONS ==================== */
@@ -118,7 +124,6 @@ static inline struct obs_websocket_request_response *obs_websocket_call_request(
118
124
request_data_string = obs_data_get_json (request_data );
119
125
120
126
calldata_t cd = {0 , 0 , 0 , 0 };
121
-
122
127
calldata_set_string (& cd , "request_type" , request_type );
123
128
calldata_set_string (& cd , "request_data" , request_data_string );
124
129
@@ -144,6 +149,46 @@ static inline void obs_websocket_request_response_free(struct obs_websocket_requ
144
149
bfree (response );
145
150
}
146
151
152
+ // Register an event handler to receive obs-websocket events
153
+ static inline bool obs_websocket_register_event_callback (obs_websocket_event_callback_function event_callback , void * priv_data )
154
+ {
155
+ if (!obs_websocket_ensure_ph ())
156
+ return false;
157
+
158
+ struct obs_websocket_event_callback cb = {event_callback , priv_data };
159
+
160
+ calldata_t cd = {0 , 0 , 0 , 0 };
161
+ calldata_set_ptr (& cd , "callback" , & cb );
162
+
163
+ proc_handler_call (_ph , "register_event_callback" , & cd );
164
+
165
+ bool ret = calldata_bool (& cd , "success" );
166
+
167
+ calldata_free (& cd );
168
+
169
+ return ret ;
170
+ }
171
+
172
+ // Unregister an existing event handler
173
+ static inline bool obs_websocket_unregister_event_callback (obs_websocket_event_callback_function event_callback , void * priv_data )
174
+ {
175
+ if (!obs_websocket_ensure_ph ())
176
+ return false;
177
+
178
+ struct obs_websocket_event_callback cb = {event_callback , priv_data };
179
+
180
+ calldata_t cd = {0 , 0 , 0 , 0 };
181
+ calldata_set_ptr (& cd , "callback" , & cb );
182
+
183
+ proc_handler_call (_ph , "unregister_event_callback" , & cd );
184
+
185
+ bool ret = calldata_bool (& cd , "success" );
186
+
187
+ calldata_free (& cd );
188
+
189
+ return ret ;
190
+ }
191
+
147
192
/* ==================== VENDOR API FUNCTIONS ==================== */
148
193
149
194
// ALWAYS CALL ONLY VIA `obs_module_post_load()` CALLBACK!
@@ -154,7 +199,6 @@ static inline obs_websocket_vendor obs_websocket_register_vendor(const char *ven
154
199
return NULL ;
155
200
156
201
calldata_t cd = {0 , 0 , 0 , 0 };
157
-
158
202
calldata_set_string (& cd , "name" , vendor_name );
159
203
160
204
proc_handler_call (_ph , "vendor_register" , & cd );
@@ -168,10 +212,9 @@ static inline obs_websocket_vendor obs_websocket_register_vendor(const char *ven
168
212
static inline bool obs_websocket_vendor_register_request (obs_websocket_vendor vendor , const char * request_type ,
169
213
obs_websocket_request_callback_function request_callback , void * priv_data )
170
214
{
171
- calldata_t cd = {0 , 0 , 0 , 0 };
172
-
173
215
struct obs_websocket_request_callback cb = {request_callback , priv_data };
174
216
217
+ calldata_t cd = {0 , 0 , 0 , 0 };
175
218
calldata_set_string (& cd , "type" , request_type );
176
219
calldata_set_ptr (& cd , "callback" , & cb );
177
220
@@ -185,7 +228,6 @@ static inline bool obs_websocket_vendor_register_request(obs_websocket_vendor ve
185
228
static inline bool obs_websocket_vendor_unregister_request (obs_websocket_vendor vendor , const char * request_type )
186
229
{
187
230
calldata_t cd = {0 , 0 , 0 , 0 };
188
-
189
231
calldata_set_string (& cd , "type" , request_type );
190
232
191
233
bool success = obs_websocket_vendor_run_simple_proc (vendor , "vendor_request_unregister" , & cd );
@@ -199,7 +241,6 @@ static inline bool obs_websocket_vendor_unregister_request(obs_websocket_vendor
199
241
static inline bool obs_websocket_vendor_emit_event (obs_websocket_vendor vendor , const char * event_name , obs_data_t * event_data )
200
242
{
201
243
calldata_t cd = {0 , 0 , 0 , 0 };
202
-
203
244
calldata_set_string (& cd , "type" , event_name );
204
245
calldata_set_ptr (& cd , "data" , (void * )event_data );
205
246
0 commit comments