Browse Source

Guess the description type from the context (useful for tests)

Paul-Louis Ageneau 5 years ago
parent
commit
7d21b4b42b
3 changed files with 16 additions and 9 deletions
  1. 13 4
      src/description.cpp
  2. 0 3
      src/icetransport.cpp
  3. 3 2
      src/peerconnection.cpp

+ 13 - 4
src/description.cpp

@@ -45,12 +45,13 @@ inline void trim_end(string &str) {
 namespace rtc {
 
 Description::Description(const string &sdp, const string &typeString)
-    : Description(sdp, stringToType(typeString), Description::Role::ActPass) {}
+    : Description(sdp, stringToType(typeString)) {}
+
+Description::Description(const string &sdp, Type type) : Description(sdp, type, Role::ActPass) {}
 
 Description::Description(const string &sdp, Type type, Role role)
-    : mType(type), mRole(role), mMid("0"), mIceUfrag("0"), mIcePwd("0"), mTrickle(true) {
-	if (mType == Type::Answer && mRole == Role::ActPass)
-		mRole = Role::Passive; // ActPass is illegal for an answer, so default to passive
+    : mType(Type::Unspec), mRole(role), mMid("0"), mIceUfrag(""), mIcePwd(""), mTrickle(true) {
+	hintType(type);
 
 	auto seed = std::chrono::system_clock::now().time_since_epoch().count();
 	std::default_random_engine generator(seed);
@@ -109,6 +110,14 @@ std::optional<size_t> Description::maxMessageSize() const { return mMaxMessageSi
 
 bool Description::trickleEnabled() const { return mTrickle; }
 
+void Description::hintType(Type type) {
+	if (mType == Type::Unspec) {
+		mType = type;
+		if (mType == Type::Answer && mRole == Role::ActPass)
+			mRole = Role::Passive; // ActPass is illegal for an answer, so default to passive
+	}
+}
+
 void Description::setFingerprint(string fingerprint) {
 	mFingerprint.emplace(std::move(fingerprint));
 }

+ 0 - 3
src/icetransport.cpp

@@ -114,9 +114,6 @@ void IceTransport::setRemoteDescription(const Description &description) {
 	mRole = description.role() == Description::Role::Active ? Description::Role::Passive
 	                                                        : Description::Role::Active;
 	mMid = description.mid();
-	// TODO
-	// mTrickleTimeout = description.trickleEnabled() ? 30s : 0s;
-
 	if (juice_set_remote_description(mAgent.get(), string(description).c_str()) < 0)
 		throw std::runtime_error("Failed to parse remote SDP");
 }

+ 3 - 2
src/peerconnection.cpp

@@ -79,9 +79,10 @@ std::optional<Description> PeerConnection::remoteDescription() const {
 }
 
 void PeerConnection::setRemoteDescription(Description description) {
-	std::lock_guard lock(mRemoteDescriptionMutex);
-
+	description.hintType(localDescription() ? Description::Type::Answer : Description::Type::Offer);
 	auto remoteCandidates = description.extractCandidates();
+
+	std::lock_guard lock(mRemoteDescriptionMutex);
 	mRemoteDescription.emplace(std::move(description));
 
 	auto iceTransport = std::atomic_load(&mIceTransport);