diff --git a/examples/androidnativeapi/jni/androidcallclient.cc b/examples/androidnativeapi/jni/androidcallclient.cc index 4da20b995a..f2cdbd0472 100644 --- a/examples/androidnativeapi/jni/androidcallclient.cc +++ b/examples/androidnativeapi/jni/androidcallclient.cc @@ -53,7 +53,7 @@ class CreateOfferObserver : public webrtc::CreateSessionDescriptionObserver { rtc::scoped_refptr pc); void OnSuccess(webrtc::SessionDescriptionInterface* desc) override; - void OnFailure(const std::string& error) override; + void OnFailure(webrtc::RTCError error) override; private: const rtc::scoped_refptr pc_; @@ -69,7 +69,7 @@ class SetLocalSessionDescriptionObserver : public webrtc::SetSessionDescriptionObserver { public: void OnSuccess() override; - void OnFailure(const std::string& error) override; + void OnFailure(webrtc::RTCError error) override; }; } // namespace @@ -260,8 +260,9 @@ void CreateOfferObserver::OnSuccess(webrtc::SessionDescriptionInterface* desc) { new rtc::RefCountedObject()); } -void CreateOfferObserver::OnFailure(const std::string& error) { - RTC_LOG(LS_INFO) << "Failed to create offer: " << error; +void CreateOfferObserver::OnFailure(webrtc::RTCError error) { + RTC_LOG(LS_INFO) << "Failed to create offer: " << ToString(error.type()) + << ": " << error.message(); } void SetRemoteSessionDescriptionObserver::OnSetRemoteDescriptionComplete( @@ -273,8 +274,9 @@ void SetLocalSessionDescriptionObserver::OnSuccess() { RTC_LOG(LS_INFO) << "Set local description success!"; } -void SetLocalSessionDescriptionObserver::OnFailure(const std::string& error) { - RTC_LOG(LS_INFO) << "Set local description failure: " << error; +void SetLocalSessionDescriptionObserver::OnFailure(webrtc::RTCError error) { + RTC_LOG(LS_INFO) << "Set local description failure: " + << ToString(error.type()) << ": " << error.message(); } static jlong JNI_CallClient_CreateClient( diff --git a/examples/objcnativeapi/objc/objccallclient.mm b/examples/objcnativeapi/objc/objccallclient.mm index 68c58e2621..7d9d78a47b 100644 --- a/examples/objcnativeapi/objc/objccallclient.mm +++ b/examples/objcnativeapi/objc/objccallclient.mm @@ -36,7 +36,7 @@ class CreateOfferObserver : public webrtc::CreateSessionDescriptionObserver { explicit CreateOfferObserver(rtc::scoped_refptr pc); void OnSuccess(webrtc::SessionDescriptionInterface* desc) override; - void OnFailure(const std::string& error) override; + void OnFailure(webrtc::RTCError error) override; private: const rtc::scoped_refptr pc_; @@ -50,7 +50,7 @@ class SetRemoteSessionDescriptionObserver : public webrtc::SetRemoteDescriptionO class SetLocalSessionDescriptionObserver : public webrtc::SetSessionDescriptionObserver { public: void OnSuccess() override; - void OnFailure(const std::string& error) override; + void OnFailure(webrtc::RTCError error) override; }; } // namespace @@ -218,8 +218,8 @@ void CreateOfferObserver::OnSuccess(webrtc::SessionDescriptionInterface* desc) { new rtc::RefCountedObject()); } -void CreateOfferObserver::OnFailure(const std::string& error) { - RTC_LOG(LS_INFO) << "Failed to create offer: " << error; +void CreateOfferObserver::OnFailure(webrtc::RTCError error) { + RTC_LOG(LS_INFO) << "Failed to create offer: " << error.message(); } void SetRemoteSessionDescriptionObserver::OnSetRemoteDescriptionComplete(webrtc::RTCError error) { @@ -230,8 +230,8 @@ void SetLocalSessionDescriptionObserver::OnSuccess() { RTC_LOG(LS_INFO) << "Set local description success!"; } -void SetLocalSessionDescriptionObserver::OnFailure(const std::string& error) { - RTC_LOG(LS_INFO) << "Set local description failure: " << error; +void SetLocalSessionDescriptionObserver::OnFailure(webrtc::RTCError error) { + RTC_LOG(LS_INFO) << "Set local description failure: " << error.message(); } } // namespace webrtc_examples diff --git a/examples/peerconnection/client/conductor.cc b/examples/peerconnection/client/conductor.cc index 2483e4846d..746936e779 100644 --- a/examples/peerconnection/client/conductor.cc +++ b/examples/peerconnection/client/conductor.cc @@ -45,8 +45,9 @@ class DummySetSessionDescriptionObserver new rtc::RefCountedObject(); } virtual void OnSuccess() { RTC_LOG(INFO) << __FUNCTION__; } - virtual void OnFailure(const std::string& error) { - RTC_LOG(INFO) << __FUNCTION__ << " " << error; + virtual void OnFailure(webrtc::RTCError error) { + RTC_LOG(INFO) << __FUNCTION__ << " " << ToString(error.type()) << ": " + << error.message(); } }; @@ -545,8 +546,8 @@ void Conductor::OnSuccess(webrtc::SessionDescriptionInterface* desc) { SendMessage(writer.write(jmessage)); } -void Conductor::OnFailure(const std::string& error) { - RTC_LOG(LERROR) << error; +void Conductor::OnFailure(webrtc::RTCError error) { + RTC_LOG(LERROR) << ToString(error.type()) << ": " << error.message(); } void Conductor::SendMessage(const std::string& json_object) { diff --git a/examples/peerconnection/client/conductor.h b/examples/peerconnection/client/conductor.h index 83d1b73920..c24bbac87d 100644 --- a/examples/peerconnection/client/conductor.h +++ b/examples/peerconnection/client/conductor.h @@ -116,7 +116,7 @@ class Conductor // CreateSessionDescriptionObserver implementation. void OnSuccess(webrtc::SessionDescriptionInterface* desc) override; - void OnFailure(const std::string& error) override; + void OnFailure(webrtc::RTCError error) override; protected: // Send a message to the remote peer. diff --git a/examples/unityplugin/simple_peer_connection.cc b/examples/unityplugin/simple_peer_connection.cc index 02911f6cd9..8374d0c1e2 100644 --- a/examples/unityplugin/simple_peer_connection.cc +++ b/examples/unityplugin/simple_peer_connection.cc @@ -76,8 +76,9 @@ class DummySetSessionDescriptionObserver return new rtc::RefCountedObject(); } virtual void OnSuccess() { RTC_LOG(INFO) << __FUNCTION__; } - virtual void OnFailure(const std::string& error) { - RTC_LOG(INFO) << __FUNCTION__ << " " << error; + virtual void OnFailure(webrtc::RTCError error) { + RTC_LOG(INFO) << __FUNCTION__ << " " << ToString(error.type()) << ": " + << error.message(); } protected: @@ -240,11 +241,12 @@ void SimplePeerConnection::OnSuccess( OnLocalSdpReady(desc->type().c_str(), sdp.c_str()); } -void SimplePeerConnection::OnFailure(const std::string& error) { - RTC_LOG(LERROR) << error; +void SimplePeerConnection::OnFailure(webrtc::RTCError error) { + RTC_LOG(LERROR) << ToString(error.type()) << ": " << error.message(); + // TODO(hta): include error.type in the message if (OnFailureMessage) - OnFailureMessage(error.c_str()); + OnFailureMessage(error.message()); } void SimplePeerConnection::OnIceCandidate( diff --git a/examples/unityplugin/simple_peer_connection.h b/examples/unityplugin/simple_peer_connection.h index 0c490253ee..5b30778711 100644 --- a/examples/unityplugin/simple_peer_connection.h +++ b/examples/unityplugin/simple_peer_connection.h @@ -88,7 +88,7 @@ class SimplePeerConnection : public webrtc::PeerConnectionObserver, // CreateSessionDescriptionObserver implementation. void OnSuccess(webrtc::SessionDescriptionInterface* desc) override; - void OnFailure(const std::string& error) override; + void OnFailure(webrtc::RTCError error) override; // DataChannelObserver implementation. void OnStateChange() override; diff --git a/pc/webrtcsessiondescriptionfactory.cc b/pc/webrtcsessiondescriptionfactory.cc index f6e5b96438..46e4129949 100644 --- a/pc/webrtcsessiondescriptionfactory.cc +++ b/pc/webrtcsessiondescriptionfactory.cc @@ -67,12 +67,12 @@ enum { struct CreateSessionDescriptionMsg : public rtc::MessageData { explicit CreateSessionDescriptionMsg( - webrtc::CreateSessionDescriptionObserver* observer) - : observer(observer) { - } + webrtc::CreateSessionDescriptionObserver* observer, + RTCError error_in) + : observer(observer), error(std::move(error_in)) {} rtc::scoped_refptr observer; - std::string error; + RTCError error; std::unique_ptr description; }; } // namespace @@ -297,7 +297,7 @@ void WebRtcSessionDescriptionFactory::OnMessage(rtc::Message* msg) { case MSG_CREATE_SESSIONDESCRIPTION_FAILED: { CreateSessionDescriptionMsg* param = static_cast(msg->pdata); - param->observer->OnFailure(param->error); + param->observer->OnFailure(std::move(param->error)); delete param; break; } @@ -432,8 +432,8 @@ void WebRtcSessionDescriptionFactory::FailPendingRequests( void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionFailed( CreateSessionDescriptionObserver* observer, const std::string& error) { - CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); - msg->error = error; + CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg( + observer, RTCError(RTCErrorType::INTERNAL_ERROR, std::string(error))); signaling_thread_->Post(RTC_FROM_HERE, this, MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg); RTC_LOG(LS_ERROR) << "Create SDP failed: " << error; @@ -442,7 +442,8 @@ void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionFailed( void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionSucceeded( CreateSessionDescriptionObserver* observer, std::unique_ptr description) { - CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); + CreateSessionDescriptionMsg* msg = + new CreateSessionDescriptionMsg(observer, RTCError::OK()); msg->description = std::move(description); signaling_thread_->Post(RTC_FROM_HERE, this, MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, msg); diff --git a/sdk/android/src/jni/pc/sdpobserver.cc b/sdk/android/src/jni/pc/sdpobserver.cc index a9fab94327..0ac602bc1f 100644 --- a/sdk/android/src/jni/pc/sdpobserver.cc +++ b/sdk/android/src/jni/pc/sdpobserver.cc @@ -36,10 +36,10 @@ void CreateSdpObserverJni::OnSuccess(SessionDescriptionInterface* desc) { delete desc; } -void CreateSdpObserverJni::OnFailure(const std::string& error) { +void CreateSdpObserverJni::OnFailure(webrtc::RTCError error) { JNIEnv* env = AttachCurrentThreadIfNeeded(); Java_SdpObserver_onCreateFailure(env, j_observer_global_, - NativeToJavaString(env, error)); + NativeToJavaString(env, error.message())); } SetSdpObserverJni::SetSdpObserverJni( @@ -54,10 +54,10 @@ void SetSdpObserverJni::OnSuccess() { Java_SdpObserver_onSetSuccess(env, j_observer_global_); } -void SetSdpObserverJni::OnFailure(const std::string& error) { +void SetSdpObserverJni::OnFailure(webrtc::RTCError error) { JNIEnv* env = AttachCurrentThreadIfNeeded(); Java_SdpObserver_onSetFailure(env, j_observer_global_, - NativeToJavaString(env, error)); + NativeToJavaString(env, error.message())); } } // namespace jni diff --git a/sdk/android/src/jni/pc/sdpobserver.h b/sdk/android/src/jni/pc/sdpobserver.h index ec8befe573..552b99d2c1 100644 --- a/sdk/android/src/jni/pc/sdpobserver.h +++ b/sdk/android/src/jni/pc/sdpobserver.h @@ -30,7 +30,7 @@ class CreateSdpObserverJni : public CreateSessionDescriptionObserver { MediaConstraintsInterface* constraints() { return constraints_.get(); } void OnSuccess(SessionDescriptionInterface* desc) override; - void OnFailure(const std::string& error) override; + void OnFailure(RTCError error) override; private: const ScopedJavaGlobalRef j_observer_global_; @@ -46,7 +46,7 @@ class SetSdpObserverJni : public SetSessionDescriptionObserver { MediaConstraintsInterface* constraints() { return constraints_.get(); } void OnSuccess() override; - void OnFailure(const std::string& error) override; + void OnFailure(RTCError error) override; private: const ScopedJavaGlobalRef j_observer_global_; diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnection.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnection.mm index 3e54e24819..9b2462e277 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnection.mm +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnection.mm @@ -61,9 +61,10 @@ class CreateSessionDescriptionObserverAdapter completion_handler_ = nil; } - void OnFailure(const std::string& error) override { + void OnFailure(RTCError error) override { RTC_DCHECK(completion_handler_); - NSString* str = [NSString stringForStdString:error]; + // TODO(hta): Add handling of error.type() + NSString *str = [NSString stringForStdString:error.message()]; NSError* err = [NSError errorWithDomain:kRTCPeerConnectionErrorDomain code:kRTCPeerConnnectionSessionDescriptionError @@ -95,9 +96,10 @@ class SetSessionDescriptionObserverAdapter : completion_handler_ = nil; } - void OnFailure(const std::string& error) override { + void OnFailure(RTCError error) override { RTC_DCHECK(completion_handler_); - NSString* str = [NSString stringForStdString:error]; + // TODO(hta): Add handling of error.type() + NSString *str = [NSString stringForStdString:error.message()]; NSError* err = [NSError errorWithDomain:kRTCPeerConnectionErrorDomain code:kRTCPeerConnnectionSessionDescriptionError