Browse Source

Made candidate mid non optional

Paul-Louis Ageneau 6 years ago
parent
commit
3780fa8646
3 changed files with 9 additions and 10 deletions
  1. 3 3
      include/rtc/candidate.hpp
  2. 2 2
      src/candidate.cpp
  3. 4 5
      src/rtc.cpp

+ 3 - 3
include/rtc/candidate.hpp

@@ -27,14 +27,14 @@ namespace rtc {
 
 class Candidate {
 public:
-	Candidate(string candidate, std::optional<string> mid = nullopt);
+	Candidate(string candidate, string mid = "");
 
-	std::optional<string> mid() const;
+	string mid() const;
 	operator string() const;
 
 private:
 	string mCandidate;
-	std::optional<string> mMid;
+	string mMid;
 };
 
 } // namespace rtc

+ 2 - 2
src/candidate.cpp

@@ -40,7 +40,7 @@ inline bool hasprefix(const string &str, const string &prefix) {
 
 namespace rtc {
 
-Candidate::Candidate(string candidate, std::optional<string> mid) {
+Candidate::Candidate(string candidate, string mid) {
 	const std::array prefixes{"a=", "candidate:"};
 	for (string prefix : prefixes)
 		if (hasprefix(candidate, prefix))
@@ -92,7 +92,7 @@ Candidate::Candidate(string candidate, std::optional<string> mid) {
 	}
 }
 
-std::optional<string> Candidate::mid() const { return mMid; }
+string Candidate::mid() const { return mMid; }
 
 Candidate::operator string() const {
 	std::ostringstream line;

+ 4 - 5
src/rtc.cpp

@@ -102,8 +102,8 @@ void rtcSetLocalCandidateCallback(int pc,
 		    if (auto jt = userPointerMap.find(pc); jt != userPointerMap.end())
 			    userPointer = jt->second;
 		    if (candidate) {
-			    auto mid = candidate->mid() ? *candidate->mid() : string();
-			    candidateCallback(string(*candidate).c_str(), mid.c_str(), userPointer);
+			    candidateCallback(string(*candidate).c_str(), candidate->mid().c_str(),
+			                      userPointer);
 		    } else {
 			    candidateCallback(nullptr, nullptr, userPointer);
 		    }
@@ -115,7 +115,7 @@ void rtcSetRemoteDescription(int pc, const char *sdp, const char *type) {
 	if (it == peerConnectionMap.end())
 		return;
 
-	it->second->setRemoteDescription(Description(string(sdp), string(type)));
+	it->second->setRemoteDescription(Description(string(sdp), type ? string(type) : ""));
 }
 
 void rtcAddRemoteCandidate(int pc, const char *candidate, const char *mid) {
@@ -123,8 +123,7 @@ void rtcAddRemoteCandidate(int pc, const char *candidate, const char *mid) {
 	if (it == peerConnectionMap.end())
 		return;
 
-	it->second->addRemoteCandidate(
-	    Candidate(string(candidate), mid ? make_optional(string(mid)) : nullopt));
+	it->second->addRemoteCandidate(Candidate(string(candidate), mid ? string(mid) : ""));
 }
 
 int rtcGetDataChannelLabel(int dc, char *buffer, int size) {