Browse Source

Added hasMedia() and addMedia()

Paul-Louis Ageneau 5 years ago
parent
commit
0f29ccf1c6
3 changed files with 16 additions and 4 deletions
  1. 3 1
      include/rtc/description.hpp
  2. 8 0
      src/description.cpp
  3. 5 3
      src/peerconnection.cpp

+ 3 - 1
include/rtc/description.hpp

@@ -57,8 +57,10 @@ public:
 	void endCandidates();
 	std::vector<Candidate> extractCandidates();
 
-	operator string() const;
+	bool hasMedia() const;
+	void addMedia(const Description &source);
 
+	operator string() const;
 	string generateSdp(const string &eol) const;
 
 private:

+ 8 - 0
src/description.cpp

@@ -152,6 +152,7 @@ std::optional<size_t> Description::maxMessageSize() const { return mData.maxMess
 
 bool Description::trickleEnabled() const { return mTrickle; }
 
+
 void Description::hintType(Type type) {
 	if (mType == Type::Unspec) {
 		mType = type;
@@ -181,6 +182,13 @@ std::vector<Candidate> Description::extractCandidates() {
 	return result;
 }
 
+bool Description::hasMedia() const { return !mMedia.empty(); }
+
+void Description::addMedia(const Description &source) {
+	for (auto [mid, media] : source.mMedia)
+		mMedia.emplace(mid, media);
+}
+
 Description::operator string() const { return generateSdp("\r\n"); }
 
 string Description::generateSdp(const string &eol) const {

+ 5 - 3
src/peerconnection.cpp

@@ -74,8 +74,8 @@ void PeerConnection::setLocalDescription(Description description) {
 		// See https://tools.ietf.org/html/rfc5763#section-5
 		iceTransport = initIceTransport(Description::Role::ActPass);
 		Description localDescription = iceTransport->getLocalDescription(Description::Type::Offer);
-		localDescription.addMedia(description); // TODO
-		processLocalDescription(description);
+		localDescription.addMedia(description);
+		processLocalDescription(localDescription);
 		iceTransport->gatherLocalCandidates();
 	}
 }
@@ -95,7 +95,9 @@ void PeerConnection::setRemoteDescription(Description description) {
 
 	if (mRemoteDescription->type() == Description::Type::Offer) {
 		// This is an offer and we are the answerer.
-		processLocalDescription(iceTransport->getLocalDescription(Description::Type::Answer));
+		Description localDescription = iceTransport->getLocalDescription(Description::Type::Answer);
+		localDescription.addMedia(description); // blindly accept media
+		processLocalDescription(localDescription);
 		iceTransport->gatherLocalCandidates();
 	} else {
 		// This is an answer and we are the offerer.