forked from shanselman/PowerPointToOBSSceneSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TallyLight.cs
49 lines (37 loc) · 1.2 KB
/
TallyLight.cs
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
namespace SceneSwitcher {
using System;
using Flurl;
using Flurl.Http;
public class TallyLight {
private static bool skipRequests;
public string BaseUrl { get; set; }
public float Brightness { get; set; }
public string LiveColor { get; set; }
public string ObsScene { get; set; }
public static void SetSkipRequests(bool skip) {
skipRequests = skip;
}
public void TurnOn() {
Toggle("on", new {
brightness = Brightness,
color = LiveColor,
state = "live",
});
}
public void TurnOff() {
Toggle("off", new { state = "off" });
}
private async void Toggle(string state, object queryParams) {
var url = BaseUrl.SetQueryParams(queryParams);
Console.WriteLine($" Turning {state} tally light for \"{ObsScene}\" camera");
if (skipRequests) {
return;
}
try {
await url.GetAsync();
} catch (FlurlHttpException ex) {
Console.Error.WriteLine($" ERROR: {ex.Message}");
}
}
}
}