-
Notifications
You must be signed in to change notification settings - Fork 1
/
gettally.c
84 lines (71 loc) · 2.23 KB
/
gettally.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "bin/gettally.h"
#include "bin/obs-websocket.h"
#include "bin/websocket.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <uuid/uuid.h>
#include "v8_setup.h"
// This supports ONLY the new 5.0 protocol.
void (*gProgramCallback)(const char *sceneName);
void (*gPreviewCallback)(const char *sceneName, bool alsoOnProgram);
void (*gInactiveCallback)(const char *sceneName);
void registerOBSProgramCallback(void (*callbackPointer)(const char *sceneName)) {
gProgramCallback = callbackPointer;
}
void registerOBSPreviewCallback(void (*callbackPointer)(const char *sceneName,
bool alsoOnProgram)) {
gPreviewCallback = callbackPointer;
}
void registerOBSInactiveCallback(void (*callbackPointer)(const char *sceneName)) {
gInactiveCallback = callbackPointer;
}
void runOBSTally(char *OBSWebSocketURL, char *password) {
setOBSURL(OBSWebSocketURL);
setOBSPassword(password);
#if 1
void *isolate = v8_setup();
#if 1
runScript(websocket_js);
runScript(obs_websocket_js);
runScript(gettally_js);
#else
runScriptAsModule("websocket_js", websocket_js);
runScriptAsModule("obs_websocket_js", obs_websocket_js);
runScriptAsModule("gettally_js", gettally_js);
#endif
while (true) {
v8_runLoopCallback(isolate);
usleep(1000); // 1000 callbacks per second.
}
#endif
}
void _setSceneIsProgram(const char *sceneName) {
fprintf(stderr, "Calling program callback.\n");
if (gProgramCallback != NULL) {
gProgramCallback(sceneName);
} else {
fprintf(stderr, "Not setting program (no callback)\n");
}
fprintf(stderr, "Done.\n");
}
void _setSceneIsPreview(const char *sceneName, bool alsoOnProgram) {
fprintf(stderr, "Calling preview callback.\n");
if (gPreviewCallback != NULL) {
gPreviewCallback(sceneName, alsoOnProgram);
} else {
fprintf(stderr, "Not setting preview (no callback)\n");
}
fprintf(stderr, "Done.\n");
}
void _setSceneIsInactive(const char *sceneName) {
fprintf(stderr, "Calling inactive callback.\n");
if (gInactiveCallback != NULL) {
gInactiveCallback(sceneName);
} else {
fprintf(stderr, "Not setting inactive (no callback)\n");
}
fprintf(stderr, "Done.\n");
}