-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMicrophoneStatusSender.cpp
79 lines (70 loc) · 2.61 KB
/
MicrophoneStatusSender.cpp
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
#include <iostream>
#include <string>
#include <list>
#include <chrono>
#include <thread>
#include "WindowsMicScanner.h"
#include "StringUtils.h"
#include "ListUtils.h"
#include "MicrophoneStatusSender.h"
#include "HttpUtils.h"
#include "TimeUtils.h"
void callWebHook(std::wstring url);
int main(int argc, char** argv)
{
if (argc < 5) {
std::cerr << "Missing programm argument" << std::endl;
std::cerr << "Usage:" << std::endl;
std::cerr << "MicrophoneStatusSender.exe \"microphone name\" \"comma,separated,list,of,applications,to,ignore\" \"http://urlToTriggerOnActive\" \"http://urlToTriggerOnInactive\" :" << std::endl;
return -2;
}
std::wstring micToUse = StringUtils::s2ws(argv[1]);
std::list<std::wstring> blacklistApps = StringUtils::split(StringUtils::s2ws(argv[2]), L',');
std::wstring webHookActive = StringUtils::s2ws(argv[3]);
std::wstring webHookInactive = StringUtils::s2ws(argv[4]);
try {
WindowsMicScanner windowsMicScanner;
windowsMicScanner.getDeviceByMicrofoneName(micToUse);
bool lastState = false;
int i = -1;
while (true) {
std::list<std::wstring> activeDevices = ListUtils::filterList(
windowsMicScanner.getActiveDevices(),
blacklistApps
);
bool micIsActive = !activeDevices.empty();
if (lastState != micIsActive || i == -1 || i++ > 30) {
try {
if (micIsActive) {
std::cout << TimeUtils::currentDateTime() << ": Microphone is used by: " << std::endl << "\t";
std::cout << StringUtils::join(activeDevices, "\n\t") << std::endl;
callWebHook(webHookActive);
}
else {
std::cout << TimeUtils::currentDateTime() << ": No programm is using this microphone" << std::endl;
callWebHook(webHookInactive);
}
}
catch (...) {
}
i = 0;
}
activeDevices.clear();
lastState = micIsActive;
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
catch (const std::invalid_argument& ia) {
std::cerr << "Invalid argument: " << ia.what() << '\n';
return -1;
}
}
void callWebHook(std::wstring url) {
try {
LPWSTR wtUrl = const_cast<LPWSTR>(url.c_str());
HttpUtils::callGet(wtUrl);
}
catch (const std::invalid_argument& ia) {
std::cerr << "WebHook failed: " << ia.what() << '\n';
}
}