forked from Glimesh/janus-ftl-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlimeshServiceConnection.h
More file actions
65 lines (59 loc) · 1.82 KB
/
GlimeshServiceConnection.h
File metadata and controls
65 lines (59 loc) · 1.82 KB
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
/**
* @file GlimeshServiceConnection.h
* @author Hayden McAfee (hayden@outlook.com)
* @version 0.1
* @date 2020-09-15
*
* @copyright Copyright (c) 2020 Hayden McAfee
*
*/
#pragma once
#include <string>
#include <chrono>
#include <ctime>
#include <httplib.h>
#include <mutex>
#include "ServiceConnection.h"
#include "JanssonPtr.h"
/**
* @brief
* GlimeshServiceConnection is a service connection implementation for the Glimesh.tv
* platform.
*/
class GlimeshServiceConnection :
public ServiceConnection
{
public:
/* Constructor/Destructor */
GlimeshServiceConnection(
std::string hostname,
uint16_t port,
bool useHttps,
std::string clientId,
std::string clientSecret);
/* ServiceConnection */
void Init() override;
std::string GetHmacKey(ftl_channel_id_t channelId) override;
ftl_stream_id_t StartStream(ftl_channel_id_t channelId) override;
void UpdateStreamMetadata(ftl_stream_id_t streamId, StreamMetadata metadata) override;
void EndStream(ftl_stream_id_t streamId) override;
void SendJpegPreviewImage(ftl_stream_id_t streamId, std::vector<uint8_t> jpegData) override;
private:
/* Private members */
const int MAX_RETRIES = 5;
const int TIME_BETWEEN_RETRIES_MS = 3000;
std::string hostname;
uint16_t port;
bool useHttps;
std::string clientId;
std::string clientSecret;
std::string accessToken;
std::time_t accessTokenExpirationTime;
std::mutex authMutex;
/* Private methods */
httplib::Client getHttpClient();
void ensureAuth();
JsonPtr runGraphQlQuery(std::string query, JsonPtr variables = nullptr, httplib::MultipartFormDataItems fileData = httplib::MultipartFormDataItems());
JsonPtr processGraphQlResponse(httplib::Result result);
tm parseIso8601DateTime(std::string dateTimeString);
};