Browse Source

Fixed bug where closing a track crashes the server

Staz M 4 years ago
parent
commit
dfe8436954
1 changed files with 14 additions and 12 deletions
  1. 14 12
      src/track.cpp

+ 14 - 12
src/track.cpp

@@ -146,18 +146,20 @@ void Track::incoming(message_ptr message) {
 
 void Track::setRtcpHandler(std::shared_ptr<RtcpHandler> handler) {
 	mRtcpHandler = std::move(handler);
-	mRtcpHandler->onOutgoing([&](const rtc::message_ptr& message) {
-        #if RTC_ENABLE_MEDIA
-                auto transport = mDtlsSrtpTransport.lock();
-                if (!transport)
-                    throw std::runtime_error("Track transport is not open");
-
-                return transport->sendMedia(message);
-        #else
-                PLOG_WARNING << "Ignoring track send (not compiled with SRTP support)";
-            return false;
-        #endif
-	});
+	if (mRtcpHandler) {
+        mRtcpHandler->onOutgoing([&](const rtc::message_ptr& message) {
+            #if RTC_ENABLE_MEDIA
+                    auto transport = mDtlsSrtpTransport.lock();
+                    if (!transport)
+                        throw std::runtime_error("Track transport is not open");
+
+                    return transport->sendMedia(message);
+            #else
+                    PLOG_WARNING << "Ignoring track send (not compiled with SRTP support)";
+                return false;
+            #endif
+        });
+    }
 }
 
 bool Track::requestKeyframe() {