diff --git a/webrtc/Sdp.cpp b/webrtc/Sdp.cpp index a0562e7b..b8eb3304 100644 --- a/webrtc/Sdp.cpp +++ b/webrtc/Sdp.cpp @@ -1311,6 +1311,10 @@ void RtcSession::checkValid() const{ bool have_active_media = false; for (auto &item : media) { item.checkValid(); + + if (TrackApplication == item.type) { + have_active_media = true; + } switch (item.direction) { case RtpDirection::sendrecv: case RtpDirection::sendonly: @@ -1348,6 +1352,10 @@ bool RtcSession::supportSimulcast() const { return false; } +bool RtcSession::isOnlyDatachannel() const { + return 1 == media.size() && TrackApplication == media[0].type; +} + string const SdpConst::kTWCCRtcpFb = "transport-cc"; string const SdpConst::kRembRtcpFb = "goog-remb"; @@ -1596,6 +1604,10 @@ RETRY: #ifdef ENABLE_SCTP answer_media.direction = matchDirection(offer_media.direction, configure.direction); answer_media.candidate = configure.candidate; + answer_media.ice_ufrag = configure.ice_ufrag; + answer_media.ice_pwd = configure.ice_pwd; + answer_media.fingerprint = configure.fingerprint; + answer_media.ice_lite = configure.ice_lite; #else answer_media.direction = RtpDirection::inactive; #endif diff --git a/webrtc/Sdp.h b/webrtc/Sdp.h index 41e1d5d3..240a6a07 100644 --- a/webrtc/Sdp.h +++ b/webrtc/Sdp.h @@ -678,6 +678,7 @@ public: const RtcMedia *getMedia(mediakit::TrackType type) const; bool supportRtcpFb(const std::string &name, mediakit::TrackType type = mediakit::TrackType::TrackVideo) const; bool supportSimulcast() const; + bool isOnlyDatachannel() const; private: RtcSessionSdp::Ptr toRtcSessionSdp() const; diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index 1819c347..9f1dc284 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -377,7 +377,7 @@ void WebRtcTransportImp::onCreate() { return false; } if (strong_self->_alive_ticker.elapsedTime() > timeoutSec * 1000) { - strong_self->onShutdown(SockException(Err_timeout, "接受rtp和rtcp超时")); + strong_self->onShutdown(SockException(Err_timeout, "接受rtp/rtcp/datachannel超时")); } return true; }, @@ -386,6 +386,15 @@ void WebRtcTransportImp::onCreate() { _twcc_ctx.setOnSendTwccCB([this](uint32_t ssrc, string fci) { onSendTwcc(ssrc, fci); }); } +void WebRtcTransportImp::OnDtlsTransportApplicationDataReceived(const RTC::DtlsTransport *dtlsTransport, const uint8_t *data, size_t len) { + WebRtcTransport::OnDtlsTransportApplicationDataReceived(dtlsTransport, data, len); +#ifdef ENABLE_SCTP + if (_answer_sdp->isOnlyDatachannel()) { + _alive_ticker.resetTime(); + } +#endif +} + WebRtcTransportImp::WebRtcTransportImp(const EventPoller::Ptr &poller) : WebRtcTransport(poller) { InfoL << getIdentifier(); diff --git a/webrtc/WebRtcTransport.h b/webrtc/WebRtcTransport.h index c6570226..23f5880b 100644 --- a/webrtc/WebRtcTransport.h +++ b/webrtc/WebRtcTransport.h @@ -248,6 +248,7 @@ public: protected: WebRtcTransportImp(const EventPoller::Ptr &poller); + void OnDtlsTransportApplicationDataReceived(const RTC::DtlsTransport *dtlsTransport, const uint8_t *data, size_t len) override; void onStartWebRTC() override; void onSendSockData(Buffer::Ptr buf, bool flush = true, RTC::TransportTuple *tuple = nullptr) override; void onCheckSdp(SdpType type, RtcSession &sdp) override;