summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-07-09 03:15:05 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-07-09 03:46:25 +0200
commit04fbae6ce38550fac2a8be3786405949563304d5 (patch)
tree46051009da46064afab43fb816dc47db5c032a98 /src
parentce3f086ec46f23358df086005fa14558def0d12f (diff)
downloadfork-godot-webrtc-native-04fbae6ce38550fac2a8be3786405949563304d5.tar.gz
fork-godot-webrtc-native-04fbae6ce38550fac2a8be3786405949563304d5.tar.bz2
fork-godot-webrtc-native-04fbae6ce38550fac2a8be3786405949563304d5.zip
Properly wait success callback before creating answers.
Diffstat (limited to 'src')
-rw-r--r--src/WebRTCLibPeerConnection.cpp12
-rw-r--r--src/WebRTCLibPeerConnection.hpp6
2 files changed, 15 insertions, 3 deletions
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<webrtc::SessionDescriptionInterface> 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;
}
diff --git a/src/WebRTCLibPeerConnection.hpp b/src/WebRTCLibPeerConnection.hpp
index f6a92a7..85ef33f 100644
--- a/src/WebRTCLibPeerConnection.hpp
+++ b/src/WebRTCLibPeerConnection.hpp
@@ -40,7 +40,7 @@ public:
~WebRTCLibPeerConnection();
/* helper functions */
-
+private:
void queue_signal(godot::String p_name, int p_argc, const godot::Variant &p_arg1 = godot::Variant(), const godot::Variant &p_arg2 = godot::Variant(), const godot::Variant &p_arg3 = godot::Variant());
void queue_packet(uint8_t *, int);
@@ -81,12 +81,14 @@ public:
class GodotSSDO : public webrtc::SetSessionDescriptionObserver {
public:
WebRTCLibPeerConnection *parent = nullptr;
+ bool make_offer = false;
GodotSSDO(WebRTCLibPeerConnection *p_parent) {
parent = p_parent;
}
- void OnSuccess() override {}
+ void OnSuccess() override;
void OnFailure(webrtc::RTCError error) override {
+ make_offer = false;
ERR_PRINT(godot::String(error.message()));
}
};