diff --git a/pc/peer_connection_ice_unittest.cc b/pc/peer_connection_ice_unittest.cc index 59f5b5620d..c04ff8e204 100644 --- a/pc/peer_connection_ice_unittest.cc +++ b/pc/peer_connection_ice_unittest.cc @@ -800,7 +800,7 @@ TEST_P(PeerConnectionIceTest, std::move(jsep_candidate), [&operation_completed](RTCError result) { EXPECT_FALSE(result.ok()); EXPECT_EQ(result.message(), - std::string("Error processing ICE candidate")); + std::string("The remote description was null")); operation_completed = true; }); EXPECT_TRUE_WAIT(operation_completed, kWaitTimeout); diff --git a/pc/sdp_offer_answer.cc b/pc/sdp_offer_answer.cc index f80e7191da..e2be8e0116 100644 --- a/pc/sdp_offer_answer.cc +++ b/pc/sdp_offer_answer.cc @@ -2497,18 +2497,42 @@ void SdpOfferAnswerHandler::AddIceCandidate( : kAddIceCandidateFailClosed; NoteAddIceCandidateResult(result); operations_chain_callback(); - if (result == kAddIceCandidateFailClosed) { - callback(RTCError( - RTCErrorType::INVALID_STATE, - "AddIceCandidate failed because the session was shut down")); - } else if (result != kAddIceCandidateSuccess && - result != kAddIceCandidateFailNotReady) { - // Fail with an error type and message consistent with Chromium. - // TODO(hbos): Fail with error types according to spec. - callback(RTCError(RTCErrorType::UNSUPPORTED_OPERATION, - "Error processing ICE candidate")); - } else { - callback(RTCError::OK()); + switch (result) { + case AddIceCandidateResult::kAddIceCandidateSuccess: + case AddIceCandidateResult::kAddIceCandidateFailNotReady: + // Success! + callback(RTCError::OK()); + break; + case AddIceCandidateResult::kAddIceCandidateFailClosed: + // Note that the spec says to just abort without resolving the + // promise in this case, but this layer must return an RTCError. + callback(RTCError( + RTCErrorType::INVALID_STATE, + "AddIceCandidate failed because the session was shut down")); + break; + case AddIceCandidateResult::kAddIceCandidateFailNoRemoteDescription: + // Spec: "If remoteDescription is null return a promise rejected + // with a newly created InvalidStateError." + callback(RTCError(RTCErrorType::INVALID_STATE, + "The remote description was null")); + break; + case AddIceCandidateResult::kAddIceCandidateFailNullCandidate: + // TODO(https://crbug.com/935898): Handle end-of-candidates instead + // of treating null candidate as an error. + callback(RTCError(RTCErrorType::UNSUPPORTED_OPERATION, + "Error processing ICE candidate")); + break; + case AddIceCandidateResult::kAddIceCandidateFailNotValid: + case AddIceCandidateResult::kAddIceCandidateFailInAddition: + case AddIceCandidateResult::kAddIceCandidateFailNotUsable: + // Spec: "If candidate could not be successfully added [...] Reject + // p with a newly created OperationError and abort these steps." + // UNSUPPORTED_OPERATION maps to OperationError. + callback(RTCError(RTCErrorType::UNSUPPORTED_OPERATION, + "Error processing ICE candidate")); + break; + default: + RTC_DCHECK_NOTREACHED(); } }); }