From 4028181c2aa0339aa4fa96a85657a1c8012591aa Mon Sep 17 00:00:00 2001 From: hai007 Date: Mon, 5 Apr 2021 09:55:28 -0700 Subject: [PATCH] Internal change PiperOrigin-RevId: 366817227 --- .../mediums/webrtc/connection_flow.cc | 52 ++++++++++++++----- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/cpp/core/internal/mediums/webrtc/connection_flow.cc b/cpp/core/internal/mediums/webrtc/connection_flow.cc index 90f7f801..9230994b 100644 --- a/cpp/core/internal/mediums/webrtc/connection_flow.cc +++ b/cpp/core/internal/mediums/webrtc/connection_flow.cc @@ -61,20 +61,44 @@ class CreateSessionDescriptionObserverImpl std::unique_ptr> settable_future_; }; -class SetSessionDescriptionObserverImpl - : public webrtc::SetSessionDescriptionObserver { +class SetLocalDescriptionObserver + : public webrtc::SetLocalDescriptionObserverInterface { public: - explicit SetSessionDescriptionObserverImpl(Future* settable_future) + explicit SetLocalDescriptionObserver(Future* settable_future) : settable_future_(settable_future) {} - void OnSuccess() override { settable_future_->Set(true); } + void OnSetLocalDescriptionComplete(webrtc::RTCError error) override { + // On success, |error.ok()| is true. + if (error.ok()) { + settable_future_->Set(true); + return; + } - void OnFailure(webrtc::RTCError error) override { - NEARBY_LOG(ERROR, "Error when setting session description: %s", + NEARBY_LOG(ERROR, "Error when setting local session description: %s", error.message()); settable_future_->SetException({Exception::kFailed}); } + private: + std::unique_ptr> settable_future_; +}; +class SetRemoteDescriptionObserver + : public webrtc::SetRemoteDescriptionObserverInterface { + public: + explicit SetRemoteDescriptionObserver(Future* settable_future) + : settable_future_(settable_future) {} + + void OnSetRemoteDescriptionComplete(webrtc::RTCError error) override { + // On success, |error.ok()| is true. + if (error.ok()) { + settable_future_->Set(true); + return; + } + + NEARBY_LOG(ERROR, "Error when setting remote session description: %s", + error.message()); + settable_future_->SetException({Exception::kFailed}); + } private: std::unique_ptr> settable_future_; }; @@ -171,11 +195,13 @@ bool ConnectionFlow::SetLocalSessionDescription(SessionDescriptionWrapper sdp) { if (!sdp.IsValid()) return false; auto success_future = new Future(); - rtc::scoped_refptr observer = - new rtc::RefCountedObject( + rtc::scoped_refptr observer = + new rtc::RefCountedObject( success_future); - peer_connection_->SetLocalDescription(observer, sdp.Release()); + peer_connection_->SetLocalDescription( + std::unique_ptr(sdp.Release()), + observer); ExceptionOr result = success_future->Get(kTimeout); bool success = result.ok() && result.result(); @@ -191,11 +217,13 @@ bool ConnectionFlow::SetRemoteSessionDescription( if (!sdp.IsValid()) return false; auto success_future = new Future(); - rtc::scoped_refptr observer = - new rtc::RefCountedObject( + rtc::scoped_refptr observer = + new rtc::RefCountedObject( success_future); - peer_connection_->SetRemoteDescription(observer, sdp.Release()); + peer_connection_->SetRemoteDescription( + std::unique_ptr(sdp.Release()), + observer); ExceptionOr result = success_future->Get(kTimeout); bool success = result.ok() && result.result();