|
@@ -240,6 +240,10 @@ std::shared_ptr<Track> PeerConnection::createTrack(Description::Media descriptio
|
|
|
if (localDescription())
|
|
|
throw std::logic_error("Tracks must be created before local description");
|
|
|
|
|
|
+ if (auto it = mTracks.find(description.mid()); it != mTracks.end())
|
|
|
+ if (auto track = it->second.lock())
|
|
|
+ return track;
|
|
|
+
|
|
|
auto track = std::make_shared<Track>(std::move(description));
|
|
|
mTracks.emplace(std::make_pair(track->mid(), track));
|
|
|
return track;
|
|
@@ -638,6 +642,22 @@ void PeerConnection::openDataChannels() {
|
|
|
iterateDataChannels([&](shared_ptr<DataChannel> channel) { channel->open(transport); });
|
|
|
}
|
|
|
|
|
|
+void PeerConnection::closeDataChannels() {
|
|
|
+ iterateDataChannels([&](shared_ptr<DataChannel> channel) { channel->close(); });
|
|
|
+}
|
|
|
+
|
|
|
+void PeerConnection::remoteCloseDataChannels() {
|
|
|
+ iterateDataChannels([&](shared_ptr<DataChannel> channel) { channel->remoteClose(); });
|
|
|
+}
|
|
|
+
|
|
|
+void PeerConnection::incomingTrack(Description::Media description) {
|
|
|
+ std::unique_lock lock(mTracksMutex); // we are going to emplace
|
|
|
+ if (mTracks.find(description.mid()) == mTracks.end()) {
|
|
|
+ auto track = std::make_shared<Track>(std::move(description));
|
|
|
+ mTracks.emplace(std::make_pair(track->mid(), track));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void PeerConnection::openTracks() {
|
|
|
#if RTC_ENABLE_MEDIA
|
|
|
if (!hasMedia())
|
|
@@ -653,13 +673,6 @@ void PeerConnection::openTracks() {
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
-void PeerConnection::closeDataChannels() {
|
|
|
- iterateDataChannels([&](shared_ptr<DataChannel> channel) { channel->close(); });
|
|
|
-}
|
|
|
-
|
|
|
-void PeerConnection::remoteCloseDataChannels() {
|
|
|
- iterateDataChannels([&](shared_ptr<DataChannel> channel) { channel->remoteClose(); });
|
|
|
-}
|
|
|
|
|
|
void PeerConnection::processLocalDescription(Description description) {
|
|
|
if (auto remote = remoteDescription()) {
|
|
@@ -680,7 +693,10 @@ void PeerConnection::processLocalDescription(Description description) {
|
|
|
<< media->mid() << "\"";
|
|
|
|
|
|
auto reciprocated = media->reciprocate();
|
|
|
-#if !RTC_ENABLE_MEDIA
|
|
|
+#if RTC_ENABLE_MEDIA
|
|
|
+ if (reciprocated.direction() != Description::Direction::Inactive)
|
|
|
+ incomingTrack(reciprocated);
|
|
|
+#else
|
|
|
// No media support, mark as inactive
|
|
|
reciprocated.setDirection(Description::Direction::Inactive);
|
|
|
#endif
|