-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowserclient.cpp
62 lines (52 loc) · 1.72 KB
/
browserclient.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
#include "browserclient.h"
#include "logger.h"
BrowserClient::BrowserClient(std::string browserIp, int browserPort) {
client = new httplib::Client(browserIp, browserPort);
client->set_read_timeout(15, 0);
client->set_keep_alive(true);
}
BrowserClient::~BrowserClient() {
client->stop();
delete client;
}
bool BrowserClient::ProcessTSPacket(std::string packet) {
if (auto res = client->Post("/ProcessTSPacket", packet, "text/plain")) {
if (res->status != 200) {
INFO("[remotetranscoder] Http result(ProcessTSPacket): {}", res->status);
return false;
}
} else {
auto err = res.error();
ERROR("[remotetranscoder] Http error(ProcessTSPacket): {}", httplib::to_string(err));
return false;
}
return true;
}
bool BrowserClient::StreamError(std::string reason) {
httplib::Params params;
params.emplace("reason", reason);
if (auto res = client->Post("/StreamError", params)) {
if (res->status != 200) {
INFO("[remotetranscoder] Http result(StreamError): {}", res->status);
return false;
}
} else {
auto err = res.error();
ERROR("[remotetranscoder] Http error(StreamError): {}", httplib::to_string(err));
return false;
}
return true;
}
bool BrowserClient::Heartbeat() {
if (auto res = client->Get("/Heartbeat")) {
if (res->status != 200) {
INFO("[remotetranscoder] Heartbeat, Http result(StreamError): {}", res->status);
return false;
}
} else {
auto err = res.error();
ERROR("[remotetranscoder] Heartbeat, Http error(StreamError): {}", httplib::to_string(err));
return false;
}
return true;
}