summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-07-09 01:31:29 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-07-09 03:45:45 +0200
commitce3f086ec46f23358df086005fa14558def0d12f (patch)
treec95808afac69a6da684fe23b880edf6828a3ef3f /src
parent00ac03c8e7a96657de5b537cfc0396509546374e (diff)
downloadfork-godot-webrtc-native-ce3f086ec46f23358df086005fa14558def0d12f.tar.gz
fork-godot-webrtc-native-ce3f086ec46f23358df086005fa14558def0d12f.tar.bz2
fork-godot-webrtc-native-ce3f086ec46f23358df086005fa14558def0d12f.zip
Move observers implementations into PeerConnection.
Diffstat (limited to 'src')
-rw-r--r--src/WebRTCLibObservers.cpp53
-rw-r--r--src/WebRTCLibPeerConnection.cpp19
-rw-r--r--src/WebRTCLibPeerConnection.hpp41
3 files changed, 45 insertions, 68 deletions
diff --git a/src/WebRTCLibObservers.cpp b/src/WebRTCLibObservers.cpp
deleted file mode 100644
index 6d8f15f..0000000
--- a/src/WebRTCLibObservers.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-#include "WebRTCLibDataChannel.hpp"
-#include "WebRTCLibPeerConnection.hpp"
-
-using namespace godot_webrtc;
-
-// CreateSessionObseerver
-WebRTCLibPeerConnection::GodotCSDO::GodotCSDO(WebRTCLibPeerConnection *parent) {
- this->parent = parent;
-}
-
-void WebRTCLibPeerConnection::GodotCSDO::OnSuccess(webrtc::SessionDescriptionInterface *desc) {
- // serialize this offer and send it to the remote peer:
- std::string sdp; // sdp = session description protocol
- desc->ToString(&sdp);
- parent->queue_signal("session_description_created", 2, desc->type().c_str(), sdp.c_str());
-};
-
-void WebRTCLibPeerConnection::GodotCSDO::OnFailure(webrtc::RTCError error){};
-
-// SetSessionObseerver
-WebRTCLibPeerConnection::GodotSSDO::GodotSSDO(WebRTCLibPeerConnection *parent) {
- this->parent = parent;
-}
-
-void WebRTCLibPeerConnection::GodotSSDO::OnSuccess(){};
-void WebRTCLibPeerConnection::GodotSSDO::OnFailure(webrtc::RTCError error){};
-
-// PeerConnectionObserver
-WebRTCLibPeerConnection::GodotPCO::GodotPCO(WebRTCLibPeerConnection *parent) {
- this->parent = parent;
-}
-
-void WebRTCLibPeerConnection::GodotPCO::OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) {
- parent->queue_signal("data_channel_received", 1, WebRTCLibDataChannel::new_data_channel(data_channel));
-}
-
-void WebRTCLibPeerConnection::GodotPCO::OnIceCandidate(const webrtc::IceCandidateInterface *candidate) {
- godot::Dictionary candidateSDP;
- godot::String candidateSdpMidName = candidate->sdp_mid().c_str();
- int candidateSdpMlineIndexName = candidate->sdp_mline_index();
- std::string sdp;
- candidate->ToString(&sdp);
- godot::String candidateSdpName = sdp.c_str();
-
- parent->queue_signal("ice_candidate_created", 3, candidateSdpMidName, candidateSdpMlineIndexName, candidateSdpName);
-}
-
-void WebRTCLibPeerConnection::GodotPCO::OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) {}
-void WebRTCLibPeerConnection::GodotPCO::OnAddStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {}
-void WebRTCLibPeerConnection::GodotPCO::OnRemoveStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {}
-void WebRTCLibPeerConnection::GodotPCO::OnRenegotiationNeeded() {}
-void WebRTCLibPeerConnection::GodotPCO::OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state) {}
-void WebRTCLibPeerConnection::GodotPCO::OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) {}
diff --git a/src/WebRTCLibPeerConnection.cpp b/src/WebRTCLibPeerConnection.cpp
index 4b83ae6..eedeff0 100644
--- a/src/WebRTCLibPeerConnection.cpp
+++ b/src/WebRTCLibPeerConnection.cpp
@@ -7,6 +7,25 @@ using namespace godot_webrtc;
std::unique_ptr<rtc::Thread> WebRTCLibPeerConnection::signaling_thread = nullptr;
+// PeerConnectionObserver
+void WebRTCLibPeerConnection::GodotPCO::OnIceCandidate(const webrtc::IceCandidateInterface *candidate) {
+ godot::Dictionary candidateSDP;
+ godot::String candidateSdpMidName = candidate->sdp_mid().c_str();
+ int candidateSdpMlineIndexName = candidate->sdp_mline_index();
+ std::string sdp;
+ candidate->ToString(&sdp);
+ godot::String candidateSdpName = sdp.c_str();
+ parent->queue_signal("ice_candidate_created", 3, candidateSdpMidName, candidateSdpMlineIndexName, candidateSdpName);
+}
+
+// CreateSessionDescriptionObserver
+void WebRTCLibPeerConnection::GodotCSDO::OnSuccess(webrtc::SessionDescriptionInterface *desc) {
+ // serialize this offer and send it to the remote peer:
+ std::string sdp;
+ desc->ToString(&sdp);
+ parent->queue_signal("session_description_created", 2, desc->type().c_str(), sdp.c_str());
+}
+
void WebRTCLibPeerConnection::initialize_signaling() {
if (signaling_thread.get() == nullptr) {
signaling_thread = rtc::Thread::Create();
diff --git a/src/WebRTCLibPeerConnection.hpp b/src/WebRTCLibPeerConnection.hpp
index c209cf1..f6a92a7 100644
--- a/src/WebRTCLibPeerConnection.hpp
+++ b/src/WebRTCLibPeerConnection.hpp
@@ -49,35 +49,46 @@ public:
public:
WebRTCLibPeerConnection *parent;
- GodotPCO(WebRTCLibPeerConnection *parent);
- void OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) override;
- void OnAddStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override;
- void OnRemoveStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override;
- void OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override;
- void OnRenegotiationNeeded() override;
- void OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state) override;
- void OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) override;
+ GodotPCO(WebRTCLibPeerConnection *p_parent) {
+ parent = p_parent;
+ }
void OnIceCandidate(const webrtc::IceCandidateInterface *candidate) override;
+
+ void OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) override {}
+ void OnAddStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override {}
+ void OnRemoveStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override {}
+ void OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override {}
+ void OnRenegotiationNeeded() override {}
+ void OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state) override {}
+ void OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) override {}
};
/** CreateSessionDescriptionObserver callback functions **/
class GodotCSDO : public webrtc::CreateSessionDescriptionObserver {
public:
- WebRTCLibPeerConnection *parent;
+ WebRTCLibPeerConnection *parent = nullptr;
- GodotCSDO(WebRTCLibPeerConnection *parent);
+ GodotCSDO(WebRTCLibPeerConnection *p_parent) {
+ parent = p_parent;
+ }
void OnSuccess(webrtc::SessionDescriptionInterface *desc) override;
- void OnFailure(webrtc::RTCError error) override;
+ void OnFailure(webrtc::RTCError error) override {
+ ERR_PRINT(godot::String(error.message()));
+ }
};
/** SetSessionDescriptionObserver callback functions **/
class GodotSSDO : public webrtc::SetSessionDescriptionObserver {
public:
- WebRTCLibPeerConnection *parent;
+ WebRTCLibPeerConnection *parent = nullptr;
- GodotSSDO(WebRTCLibPeerConnection *parent);
- void OnSuccess() override;
- void OnFailure(webrtc::RTCError error) override;
+ GodotSSDO(WebRTCLibPeerConnection *p_parent) {
+ parent = p_parent;
+ }
+ void OnSuccess() override {}
+ void OnFailure(webrtc::RTCError error) override {
+ ERR_PRINT(godot::String(error.message()));
+ }
};
class Signal {