diff --git a/p2p/base/dtls_transport.cc b/p2p/base/dtls_transport.cc index 4dadcf2517..c37cd0ff45 100644 --- a/p2p/base/dtls_transport.cc +++ b/p2p/base/dtls_transport.cc @@ -817,6 +817,7 @@ void DtlsTransport::set_dtls_state(DtlsTransportState state) { << " to " << state; dtls_state_ = state; SignalDtlsState(this, state); + SendDtlsState(this, state); } void DtlsTransport::OnDtlsHandshakeError(rtc::SSLHandshakeError error) { diff --git a/p2p/base/dtls_transport_internal.h b/p2p/base/dtls_transport_internal.h index 34f7a1a7fa..7771f1f4bb 100644 --- a/p2p/base/dtls_transport_internal.h +++ b/p2p/base/dtls_transport_internal.h @@ -115,6 +115,25 @@ class DtlsTransportInternal : public rtc::PacketTransportInternal { virtual IceTransportInternal* ice_transport() = 0; sigslot::signal2 SignalDtlsState; + // F: void(DtlsTransportInternal*, const DtlsTransportState) + template + void SubscribeDtlsState(F&& callback) { + dtls_state_callback_list_.AddReceiver(std::forward(callback)); + } + + template + void SubscribeDtlsState(const void* id, F&& callback) { + dtls_state_callback_list_.AddReceiver(id, std::forward(callback)); + } + // Unsubscribe the subscription with given id. + void UnsubscribeDtlsState(const void* id) { + dtls_state_callback_list_.RemoveReceivers(id); + } + + void SendDtlsState(DtlsTransportInternal* transport, + DtlsTransportState state) { + dtls_state_callback_list_.Send(transport, state); + } // Emitted whenever the Dtls handshake failed on some transport channel. // F: void(rtc::SSLHandshakeError) @@ -134,6 +153,8 @@ class DtlsTransportInternal : public rtc::PacketTransportInternal { RTC_DISALLOW_COPY_AND_ASSIGN(DtlsTransportInternal); webrtc::CallbackList dtls_handshake_error_callback_list_; + webrtc::CallbackList + dtls_state_callback_list_; }; } // namespace cricket diff --git a/p2p/base/fake_dtls_transport.h b/p2p/base/fake_dtls_transport.h index 7061ea4b3e..9ab8998729 100644 --- a/p2p/base/fake_dtls_transport.h +++ b/p2p/base/fake_dtls_transport.h @@ -86,6 +86,7 @@ class FakeDtlsTransport : public DtlsTransportInternal { void SetDtlsState(DtlsTransportState state) { dtls_state_ = state; SignalDtlsState(this, dtls_state_); + SendDtlsState(this, dtls_state_); } // Simulates the two DTLS transports connecting to each other. diff --git a/pc/dtls_srtp_transport.cc b/pc/dtls_srtp_transport.cc index dacbcb411d..69b0eebfc1 100644 --- a/pc/dtls_srtp_transport.cc +++ b/pc/dtls_srtp_transport.cc @@ -277,14 +277,17 @@ void DtlsSrtpTransport::SetDtlsTransport( } if (*old_dtls_transport) { - (*old_dtls_transport)->SignalDtlsState.disconnect(this); + (*old_dtls_transport)->UnsubscribeDtlsState(this); } *old_dtls_transport = new_dtls_transport; if (new_dtls_transport) { - new_dtls_transport->SignalDtlsState.connect( - this, &DtlsSrtpTransport::OnDtlsState); + new_dtls_transport->SubscribeDtlsState( + this, [this](cricket::DtlsTransportInternal* transport, + cricket::DtlsTransportState state) { + OnDtlsState(transport, state); + }); } } diff --git a/pc/dtls_transport.cc b/pc/dtls_transport.cc index a3ab58ffd5..0b6d367184 100644 --- a/pc/dtls_transport.cc +++ b/pc/dtls_transport.cc @@ -51,8 +51,11 @@ DtlsTransport::DtlsTransport( ice_transport_(new rtc::RefCountedObject( internal_dtls_transport_->ice_transport())) { RTC_DCHECK(internal_dtls_transport_.get()); - internal_dtls_transport_->SignalDtlsState.connect( - this, &DtlsTransport::OnInternalDtlsState); + internal_dtls_transport_->SubscribeDtlsState( + [this](cricket::DtlsTransportInternal* transport, + cricket::DtlsTransportState state) { + OnInternalDtlsState(transport, state); + }); UpdateInformation(); } diff --git a/pc/sctp_transport.cc b/pc/sctp_transport.cc index ad8a9f2792..14a09d77e0 100644 --- a/pc/sctp_transport.cc +++ b/pc/sctp_transport.cc @@ -94,8 +94,12 @@ void SctpTransport::SetDtlsTransport( if (internal_sctp_transport_) { if (transport) { internal_sctp_transport_->SetDtlsTransport(transport->internal()); - transport->internal()->SignalDtlsState.connect( - this, &SctpTransport::OnDtlsStateChange); + + transport->internal()->SubscribeDtlsState( + [this](cricket::DtlsTransportInternal* transport, + cricket::DtlsTransportState state) { + OnDtlsStateChange(transport, state); + }); if (info_.state() == SctpTransportState::kNew) { next_state = SctpTransportState::kConnecting; }