-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathICEClient.hpp
More file actions
127 lines (108 loc) · 3.51 KB
/
Copy pathICEClient.hpp
File metadata and controls
127 lines (108 loc) · 3.51 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* This file is part of WebP2P.
*
* WebP2P is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WebP2P is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WebP2P. If not, see <http://www.gnu.org/licenses/>.
*
* Filename: ICEClient.hpp
* Author(s): Dries Staelens
* Copyright: Copyright (c) 2010 Dries Staelens
* Description: Header for the class that implements a simplified view of the
* PJICE library.
**/
#pragma once
/* STL headers */
#include <string>
#include <vector>
/* Fix architecture detection for Win32 by forcing i386 */
#ifdef WIN32
#define PJ_M_I386
#endif
/* PJPROJECT headers */
#include <pjnath.h>
#include <pjlib.h>
#include <pjlib-util.h>
class ICEClient {
class ServerConfiguration {
private:
std::string stunServerName;
int stunServerPort;
std::string turnServerName;
int turnServerPort;
std::string turnUsername;
std::string turnPassword;
public:
ServerConfiguration(const std::string& serverConfigString);
const std::string& getStunServerName();
int getStunServerPort();
const std::string& getTurnServerName();
int getTurnServerPort();
const std::string& getTurnUsername();
const std::string& getTurnPassword();
};
class RemoteConfiguration {
public:
std::string ufrag;
std::string pwd;
unsigned comp_cnt;
unsigned cand_cnt;
std::vector<pj_sockaddr> def_addr;
std::vector<pj_ice_sess_cand> cand;
};
public:
class Callbacks {
public:
virtual void setLocalCandidates(const std::string& localCandidates) = 0;
virtual void negotiationComplete() = 0;
virtual void dataReceived(const std::string& text) = 0;
};
private:
/* PJNATH related stuff */
pj_ice_strans_cfg ice_cfg;
pj_ice_strans* icest;
pj_caching_pool cp;
pj_thread_t* thread;
pj_bool_t thread_quit_flag;
pj_pool_t* pool;
struct rem_info
{
std::string ufrag;
std::string pwd;
unsigned comp_cnt;
pj_sockaddr def_addr[PJ_ICE_MAX_COMP];
unsigned cand_cnt;
pj_ice_sess_cand cand[PJ_ICE_ST_MAX_CAND];
} rem;
ServerConfiguration serverConfiguration;
RemoteConfiguration remoteConfiguration;
unsigned comp_cnt;
public:
Callbacks* callbacks;
public:
ICEClient(const std::string& server_cfg);
~ICEClient();
pj_bool_t handleEvents(unsigned max_msec, unsigned *p_count);
void setCallbacks(Callbacks* callbacks);
void deliverLocalCandidates();
void addRemoteCandidates(const std::string& remoteCandidates);
void sendMessage(std::string message);
private:
std::string initializeClient();
void shutdownClient();
void initializeTransport();
void shutdownTransport();
void initializeSession();
void shutdownSession();
std::string getLocalCandidates();
void resetRemoteCandidates();
};