浏览代码

Merge pull request #279 from paullouisageneau/fix-candidates-mid

Fix mid on local candidates
Paul-Louis Ageneau 4 年之前
父节点
当前提交
1620ddfb03
共有 4 个文件被更改,包括 19 次插入7 次删除
  1. 2 0
      include/rtc/peerconnection.hpp
  2. 6 2
      src/icetransport.cpp
  3. 1 1
      src/icetransport.hpp
  4. 10 4
      src/peerconnection.cpp

+ 2 - 0
include/rtc/peerconnection.hpp

@@ -157,6 +157,8 @@ private:
 	void processLocalCandidate(Candidate candidate);
 	void processRemoteDescription(Description description);
 	void processRemoteCandidate(Candidate candidate);
+	string localBundleMid() const;
+
 	void triggerDataChannel(std::weak_ptr<DataChannel> weakDataChannel);
 	void triggerTrack(std::shared_ptr<Track> track);
 	bool changeState(State state);

+ 6 - 2
src/icetransport.cpp

@@ -168,7 +168,9 @@ bool IceTransport::addRemoteCandidate(const Candidate &candidate) {
 	return juice_add_remote_candidate(mAgent.get(), string(candidate).c_str()) >= 0;
 }
 
-void IceTransport::gatherLocalCandidates() {
+void IceTransport::gatherLocalCandidates(string mid) {
+	mMid = std::move(mid);
+
 	// Change state now as candidates calls can be synchronous
 	changeGatheringState(GatheringState::InProgress);
 
@@ -582,7 +584,9 @@ bool IceTransport::addRemoteCandidate(const Candidate &candidate) {
 	return ret > 0;
 }
 
-void IceTransport::gatherLocalCandidates() {
+void IceTransport::gatherLocalCandidates(string mid) {
+	mMid = std::move(mid);
+
 	// Change state now as candidates calls can be synchronous
 	changeGatheringState(GatheringState::InProgress);
 

+ 1 - 1
src/icetransport.hpp

@@ -56,7 +56,7 @@ public:
 	Description getLocalDescription(Description::Type type) const;
 	void setRemoteDescription(const Description &description);
 	bool addRemoteCandidate(const Candidate &candidate);
-	void gatherLocalCandidates();
+	void gatherLocalCandidates(string mid);
 
 	std::optional<string> getLocalAddress() const;
 	std::optional<string> getRemoteAddress() const;

+ 10 - 4
src/peerconnection.cpp

@@ -189,13 +189,14 @@ void PeerConnection::setLocalDescription(Description::Type type) {
 
 	auto iceTransport = initIceTransport();
 
-	Description localDescription = iceTransport->getLocalDescription(type);
-	processLocalDescription(std::move(localDescription));
+	Description local = iceTransport->getLocalDescription(type);
+	processLocalDescription(std::move(local));
 
 	changeSignalingState(newSignalingState);
 
-	if (mGatheringState == GatheringState::New)
-		iceTransport->gatherLocalCandidates();
+	if (mGatheringState == GatheringState::New) {
+		iceTransport->gatherLocalCandidates(localBundleMid());
+	}
 }
 
 void PeerConnection::setRemoteDescription(Description description) {
@@ -1145,6 +1146,11 @@ void PeerConnection::processRemoteCandidate(Candidate candidate) {
 	}
 }
 
+string PeerConnection::localBundleMid() const {
+	std::lock_guard lock(mLocalDescriptionMutex);
+	return mLocalDescription ? mLocalDescription->bundleMid() : "0";
+}
+
 void PeerConnection::triggerDataChannel(weak_ptr<DataChannel> weakDataChannel) {
 	auto dataChannel = weakDataChannel.lock();
 	if (!dataChannel)