From 04fbae6ce38550fac2a8be3786405949563304d5 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Fri, 9 Jul 2021 03:15:05 +0200 Subject: Properly wait success callback before creating answers. --- src/WebRTCLibPeerConnection.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/WebRTCLibPeerConnection.cpp') diff --git a/src/WebRTCLibPeerConnection.cpp b/src/WebRTCLibPeerConnection.cpp index eedeff0..eb4e8cc 100644 --- a/src/WebRTCLibPeerConnection.cpp +++ b/src/WebRTCLibPeerConnection.cpp @@ -18,6 +18,14 @@ void WebRTCLibPeerConnection::GodotPCO::OnIceCandidate(const webrtc::IceCandidat parent->queue_signal("ice_candidate_created", 3, candidateSdpMidName, candidateSdpMlineIndexName, candidateSdpName); } +// SetSessionDescriptionObserver +void WebRTCLibPeerConnection::GodotSSDO::OnSuccess() { + if (make_offer) { + make_offer = false; + parent->peer_connection->CreateAnswer(parent->ptr_csdo, webrtc::PeerConnectionInterface::RTCOfferAnswerOptions()); + } +} + // CreateSessionDescriptionObserver void WebRTCLibPeerConnection::GodotCSDO::OnSuccess(webrtc::SessionDescriptionInterface *desc) { // serialize this offer and send it to the remote peer: @@ -161,8 +169,10 @@ godot_error WebRTCLibPeerConnection::create_offer() { godot_error WebRTCLibPeerConnection::set_remote_description(const char *type, const char *sdp) { ERR_FAIL_COND_V(peer_connection.get() == nullptr, GODOT_ERR_UNCONFIGURED); std::unique_ptr desc = _MAKE_DESC(type, sdp); + if (desc->GetType() == webrtc::SdpType::kOffer) { + ptr_ssdo->make_offer = true; + } peer_connection->SetRemoteDescription(ptr_ssdo, desc.release()); - peer_connection->CreateAnswer(ptr_csdo, webrtc::PeerConnectionInterface::RTCOfferAnswerOptions()); return GODOT_OK; } -- cgit v1.2.3