-
Notifications
You must be signed in to change notification settings - Fork 0
/
DatachannelThread.h
50 lines (43 loc) · 1.28 KB
/
DatachannelThread.h
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
#pragma once
#include <thread>
#include <atomic>
#include <memory>
#include <unordered_map>
class AppDataManager;
namespace rtc
{
class PeerConnection;
struct Configuration;
class WebSocket;
class DataChannel;
} // namespace rtc
class DatachannelThread
{
public:
DatachannelThread(std::shared_ptr<AppDataManager>& appDataManager);
~DatachannelThread();
void Start();
void Stop();
void RestartIfNeed();
private:
enum ConnectStatus
{
UNDEFINED=0,
CONNECTED,
ERROR,
CLOSED
};
private:
void ThreadFunction();
void WaitForWebSockConnection(int millisecWait, ConnectStatus& connectStatus);
std::shared_ptr<rtc::PeerConnection> CreatePeerConnection(
const rtc::Configuration& config, std::weak_ptr<rtc::WebSocket> wws, std::string id,
std::shared_ptr<AppDataManager> appDataManager,
std::unordered_map<std::string, std::shared_ptr<rtc::PeerConnection>>& peerConnectionMap,
std::unordered_map<std::string, std::shared_ptr<rtc::DataChannel>>& dataChannelMap);
private:
std::thread mThread;
std::atomic_bool mIsStopped;
std::shared_ptr<AppDataManager> mAppDataManager;
std::atomic_bool mNeedToRestart;
};