Переглянути джерело

Turn server protocol & Consistency Changes

Murat Dogan 5 роки тому
батько
коміт
432be41b9a
3 змінених файлів з 12 додано та 9 видалено
  1. 3 2
      include/rtc/configuration.hpp
  2. 2 2
      src/configuration.cpp
  3. 7 5
      src/icetransport.cpp

+ 3 - 2
include/rtc/configuration.hpp

@@ -27,9 +27,10 @@
 namespace rtc {
 
 struct IceServer {
-	enum class Type { STUN, TURN };
+	enum class Type { Stun, Turn };
 
-	enum class RelayType { RELAY_TYPE_TURN_UDP, RELAY_TYPE_TURN_TCP, RELAY_TYPE_TURN_TLS };
+	// Don' Change It! It should be same order as enum NiceRelayType
+	enum class RelayType { TurnUdp, TurnTcp, TurnTls };
 
 	IceServer(const string &host_);
 	IceServer(const string &hostname_, uint16_t port_);

+ 2 - 2
src/configuration.cpp

@@ -22,7 +22,7 @@ namespace rtc {
 
 using std::to_string;
 
-IceServer::IceServer(const string &host) : type(Type::STUN) {
+IceServer::IceServer(const string &host) : type(Type::Stun) {
 	if (size_t pos = host.rfind(':'); pos != string::npos) {
 		hostname = host.substr(0, pos);
 		service = host.substr(pos + 1);
@@ -36,7 +36,7 @@ IceServer::IceServer(const string &hostname_, uint16_t port_)
     : IceServer(hostname_, to_string(port_)) {}
 
 IceServer::IceServer(const string &hostname_, const string &service_)
-    : hostname(hostname_), service(service_), type(Type::STUN) {}
+    : hostname(hostname_), service(service_), type(Type::Stun) {}
 
 IceServer::IceServer(const string &hostname_, const string &service_, Type type_, string username_,
                      string password_, RelayType relayType_)

+ 7 - 5
src/icetransport.cpp

@@ -76,7 +76,7 @@ IceTransport::IceTransport(const Configuration &config, Description::Role role,
 	for (auto &server : servers) {
 		if (server.hostname.empty())
 			continue;
-		if (server.type == IceServer::Type::TURN)
+		if (server.type == IceServer::Type::Turn)
 			continue;
 		if (server.service.empty())
 			server.service = "3478"; // STUN UDP port
@@ -134,15 +134,17 @@ IceTransport::IceTransport(const Configuration &config, Description::Role role,
 	for (auto &server : servers) {
 		if (server.hostname.empty())
 			continue;
-		if (server.type == IceServer::Type::STUN)
+		if (server.type == IceServer::Type::Stun)
 			continue;
 		if (server.service.empty())
 			server.service = "3478"; // TURN UDP port
 
 		struct addrinfo hints = {};
 		hints.ai_family = AF_INET; // IPv4
-		hints.ai_socktype = SOCK_DGRAM;
-		hints.ai_protocol = IPPROTO_UDP;
+		hints.ai_socktype =
+		    server.relayType == IceServer::RelayType::TurnUdp ? SOCK_DGRAM : SOCK_STREAM;
+		hints.ai_protocol =
+		    server.relayType == IceServer::RelayType::TurnUdp ? IPPROTO_UDP : IPPROTO_TCP;
 		hints.ai_flags = AI_ADDRCONFIG;
 		struct addrinfo *result = nullptr;
 		if (getaddrinfo(server.hostname.c_str(), server.service.c_str(), &hints, &result) != 0)
@@ -159,7 +161,7 @@ IceTransport::IceTransport(const Configuration &config, Description::Role role,
 					nice_agent_set_relay_info(mNiceAgent.get(), mStreamId, 1, nodebuffer,
 					                          std::stoul(servbuffer), server.username.c_str(),
 					                          server.password.c_str(),
-					                          (NiceRelayType)server.relayType);
+					                          static_cast<NiceRelayType>(server.relayType));
 					break;
 				}
 			}