Browse Source

Added support for non-trickled ICE candidates

Paul-Louis Ageneau 6 years ago
parent
commit
1f7e956eb9
3 changed files with 19 additions and 9 deletions
  1. 2 2
      include/rtc/description.hpp
  2. 15 4
      src/description.cpp
  3. 2 3
      src/peerconnection.cpp

+ 2 - 2
include/rtc/description.hpp

@@ -41,7 +41,7 @@ public:
 
 
 	void setFingerprint(string fingerprint);
 	void setFingerprint(string fingerprint);
 	void setSctpPort(uint16_t port);
 	void setSctpPort(uint16_t port);
-	void addCandidate(Candidate candidate);
+	void addCandidate(std::optional<Candidate> candidate);
 
 
 	operator string() const;
 	operator string() const;
 
 
@@ -52,8 +52,8 @@ private:
 	string mIceUfrag, mIcePwd;
 	string mIceUfrag, mIcePwd;
 	std::optional<string> mFingerprint;
 	std::optional<string> mFingerprint;
 	std::optional<uint16_t> mSctpPort;
 	std::optional<uint16_t> mSctpPort;
-
 	std::vector<Candidate> mCandidates;
 	std::vector<Candidate> mCandidates;
+	bool mTrickle;
 };
 };
 
 
 } // namespace rtc
 } // namespace rtc

+ 15 - 4
src/description.cpp

@@ -45,7 +45,7 @@ inline void trim_end(string &str) {
 namespace rtc {
 namespace rtc {
 
 
 Description::Description(const string &sdp, Role role)
 Description::Description(const string &sdp, Role role)
-    : mRole(role), mMid("0"), mIceUfrag("0"), mIcePwd("0") {
+    : mRole(role), mMid("0"), mIceUfrag("0"), mIcePwd("0"), mTrickle(true) {
 	auto seed = std::chrono::system_clock::now().time_since_epoch().count();
 	auto seed = std::chrono::system_clock::now().time_since_epoch().count();
 	std::default_random_engine generator(seed);
 	std::default_random_engine generator(seed);
 	std::uniform_int_distribution<uint32_t> uniform;
 	std::uniform_int_distribution<uint32_t> uniform;
@@ -75,6 +75,10 @@ Description::Description(const string &sdp, Role role)
 			mIcePwd = line.substr(line.find(':') + 1);
 			mIcePwd = line.substr(line.find(':') + 1);
 		} else if (hasprefix(line, "a=sctp-port")) {
 		} else if (hasprefix(line, "a=sctp-port")) {
 			mSctpPort = uint16_t(std::stoul(line.substr(line.find(':') + 1)));
 			mSctpPort = uint16_t(std::stoul(line.substr(line.find(':') + 1)));
+		} else if (hasprefix(line, "a=candidate")) {
+			mCandidates.emplace_back(Candidate(line, mMid));
+		} else if (hasprefix(line, "a=end-of-candidates")) {
+			mTrickle = false;
 		}
 		}
 	}
 	}
 }
 }
@@ -91,8 +95,11 @@ void Description::setFingerprint(string fingerprint) {
 
 
 void Description::setSctpPort(uint16_t port) { mSctpPort.emplace(port); }
 void Description::setSctpPort(uint16_t port) { mSctpPort.emplace(port); }
 
 
-void Description::addCandidate(Candidate candidate) {
-	mCandidates.emplace_back(std::move(candidate));
+void Description::addCandidate(std::optional<Candidate> candidate) {
+	if (candidate)
+		mCandidates.emplace_back(std::move(*candidate));
+	else
+		mTrickle = false;
 }
 }
 
 
 Description::operator string() const {
 Description::operator string() const {
@@ -119,9 +126,10 @@ Description::operator string() const {
 	sdp << "t=0 0\n";
 	sdp << "t=0 0\n";
 	sdp << "m=application 0 UDP/DTLS/SCTP webrtc-datachannel\n";
 	sdp << "m=application 0 UDP/DTLS/SCTP webrtc-datachannel\n";
 	sdp << "c=IN IP4 0.0.0.0\n";
 	sdp << "c=IN IP4 0.0.0.0\n";
-	sdp << "a=ice-options:trickle\n";
 	sdp << "a=ice-ufrag:" << mIceUfrag << "\n";
 	sdp << "a=ice-ufrag:" << mIceUfrag << "\n";
 	sdp << "a=ice-pwd:" << mIcePwd << "\n";
 	sdp << "a=ice-pwd:" << mIcePwd << "\n";
+	if (mTrickle)
+		sdp << "a=ice-options:trickle\n";
 	sdp << "a=mid:" << mMid << "\n";
 	sdp << "a=mid:" << mMid << "\n";
 	sdp << "a=setup:" << roleStr << "\n";
 	sdp << "a=setup:" << roleStr << "\n";
 	sdp << "a=dtls-id:1\n";
 	sdp << "a=dtls-id:1\n";
@@ -134,6 +142,9 @@ Description::operator string() const {
 		sdp << string(candidate) << "\n";
 		sdp << string(candidate) << "\n";
 	}
 	}
 
 
+	if (!mTrickle)
+		sdp << "a=end-of-candidates\n";
+
 	return sdp.str();
 	return sdp.str();
 }
 }
 
 

+ 2 - 3
src/peerconnection.cpp

@@ -62,7 +62,7 @@ void PeerConnection::addRemoteCandidate(Candidate candidate) {
 		throw std::logic_error("Remote candidate set without remote description");
 		throw std::logic_error("Remote candidate set without remote description");
 
 
 	if (mIceTransport->addRemoteCandidate(candidate))
 	if (mIceTransport->addRemoteCandidate(candidate))
-		mRemoteDescription->addCandidate(std::move(candidate));
+		mRemoteDescription->addCandidate(std::make_optional(std::move(candidate)));
 	else
 	else
 		std::cerr << "Failed to add remote ICE candidate" << std::endl;
 		std::cerr << "Failed to add remote ICE candidate" << std::endl;
 }
 }
@@ -181,8 +181,7 @@ void PeerConnection::processLocalCandidate(std::optional<Candidate> candidate) {
 	if (!mLocalDescription)
 	if (!mLocalDescription)
 		throw std::logic_error("Got a local candidate without local description");
 		throw std::logic_error("Got a local candidate without local description");
 
 
-	if (candidate)
-		mLocalDescription->addCandidate(*candidate);
+	mLocalDescription->addCandidate(candidate);
 
 
 	if (mLocalCandidateCallback)
 	if (mLocalCandidateCallback)
 		mLocalCandidateCallback(candidate);
 		mLocalCandidateCallback(candidate);