Parcourir la source

Throw exception if addTrack() is called when the transport is not initialized (instead of ignoring it)

Jonas Vautherin il y a 2 ans
Parent
commit
1d7dbe304f
1 fichiers modifiés avec 11 ajouts et 3 suppressions
  1. 11 3
      src/impl/peerconnection.cpp

+ 11 - 3
src/impl/peerconnection.cpp

@@ -758,9 +758,17 @@ void PeerConnection::openTracks() {
 #if RTC_ENABLE_MEDIA
 #if RTC_ENABLE_MEDIA
 	if (auto transport = std::atomic_load(&mDtlsTransport)) {
 	if (auto transport = std::atomic_load(&mDtlsTransport)) {
 		auto srtpTransport = std::dynamic_pointer_cast<DtlsSrtpTransport>(transport);
 		auto srtpTransport = std::dynamic_pointer_cast<DtlsSrtpTransport>(transport);
-		iterateTracks([&](shared_ptr<Track> track) {
-			if (!track->isOpen())
-				track->open(srtpTransport);
+
+		iterateTracks([&](const shared_ptr<Track>& track) {
+			if (!track->isOpen()) {
+				if (srtpTransport) {
+					track->open(srtpTransport);
+				} else {
+					auto errorMsg = "addTrack() was called, but srtp transport was not initialized. This is an optimization for use of the library with data channels only. Set config.forceMediaTransport to 'true' to get the transport initialized before dynamically adding tracks.";
+					PLOG_ERROR << errorMsg;
+					track->triggerError(errorMsg);
+				}
+			}
 		});
 		});
 	}
 	}
 #endif
 #endif