summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2022-09-11 17:31:57 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2022-09-16 13:07:06 +0200
commit1009e8bb1c822fbda2ae6d8178508b352cc6a5ff (patch)
tree191df97ffec9dbdf2836b230fabc074ddea9f82a
parent5fd359f67405d772f1a407e7a80b293d9e1f4b8b (diff)
downloadfork-godot-webrtc-native-1009e8bb1c822fbda2ae6d8178508b352cc6a5ff.tar.gz
fork-godot-webrtc-native-1009e8bb1c822fbda2ae6d8178508b352cc6a5ff.tar.bz2
fork-godot-webrtc-native-1009e8bb1c822fbda2ae6d8178508b352cc6a5ff.zip
Add methods to get gathering and signaling state.
-rw-r--r--src/WebRTCLibPeerConnection.cpp36
-rw-r--r--src/WebRTCLibPeerConnection.hpp2
-rw-r--r--src/net/WebRTCPeerConnectionNative.hpp17
3 files changed, 55 insertions, 0 deletions
diff --git a/src/WebRTCLibPeerConnection.cpp b/src/WebRTCLibPeerConnection.cpp
index 9b409a9..6f216e0 100644
--- a/src/WebRTCLibPeerConnection.cpp
+++ b/src/WebRTCLibPeerConnection.cpp
@@ -130,6 +130,42 @@ WebRTCPeerConnection::ConnectionState WebRTCLibPeerConnection::_get_connection_s
}
}
+WebRTCLibPeerConnection::GatheringState WebRTCLibPeerConnection::_get_gathering_state() const {
+ ERR_FAIL_COND_V(peer_connection == nullptr, GATHERING_STATE_NEW);
+
+ rtc::PeerConnection::GatheringState state = peer_connection->gatheringState();
+ switch (state) {
+ case rtc::PeerConnection::GatheringState::New:
+ return GATHERING_STATE_NEW;
+ case rtc::PeerConnection::GatheringState::InProgress:
+ return GATHERING_STATE_GATHERING;
+ case rtc::PeerConnection::GatheringState::Complete:
+ return GATHERING_STATE_COMPLETE;
+ default:
+ return GATHERING_STATE_NEW;
+ }
+}
+
+WebRTCLibPeerConnection::SignalingState WebRTCLibPeerConnection::_get_signaling_state() const {
+ ERR_FAIL_COND_V(peer_connection == nullptr, SIGNALING_STATE_CLOSED);
+
+ rtc::PeerConnection::SignalingState state = peer_connection->signalingState();
+ switch (state) {
+ case rtc::PeerConnection::SignalingState::Stable:
+ return SIGNALING_STATE_STABLE;
+ case rtc::PeerConnection::SignalingState::HaveLocalOffer:
+ return SIGNALING_STATE_HAVE_LOCAL_OFFER;
+ case rtc::PeerConnection::SignalingState::HaveRemoteOffer:
+ return SIGNALING_STATE_HAVE_REMOTE_OFFER;
+ case rtc::PeerConnection::SignalingState::HaveLocalPranswer:
+ return SIGNALING_STATE_HAVE_LOCAL_PRANSWER;
+ case rtc::PeerConnection::SignalingState::HaveRemotePranswer:
+ return SIGNALING_STATE_HAVE_REMOTE_PRANSWER;
+ default:
+ return SIGNALING_STATE_CLOSED;
+ }
+}
+
Error WebRTCLibPeerConnection::_initialize(const Dictionary &p_config) {
rtc::Configuration config = {};
if (p_config.has("iceServers") && p_config["iceServers"].get_type() == Variant::ARRAY) {
diff --git a/src/WebRTCLibPeerConnection.hpp b/src/WebRTCLibPeerConnection.hpp
index 2f7c6e3..5709996 100644
--- a/src/WebRTCLibPeerConnection.hpp
+++ b/src/WebRTCLibPeerConnection.hpp
@@ -73,6 +73,8 @@ public:
void _init();
ConnectionState _get_connection_state() const override;
+ GatheringState _get_gathering_state() const override;
+ SignalingState _get_signaling_state() const override;
godot::Error _initialize(const godot::Dictionary &p_config) override;
godot::Object *_create_data_channel(const godot::String &p_channel, const godot::Dictionary &p_channel_config) override;
diff --git a/src/net/WebRTCPeerConnectionNative.hpp b/src/net/WebRTCPeerConnectionNative.hpp
index 10c1c9e..e8238f4 100644
--- a/src/net/WebRTCPeerConnectionNative.hpp
+++ b/src/net/WebRTCPeerConnectionNative.hpp
@@ -75,6 +75,21 @@ protected:
};
public:
+ enum GatheringState {
+ GATHERING_STATE_NEW,
+ GATHERING_STATE_GATHERING,
+ GATHERING_STATE_COMPLETE,
+ };
+
+ enum SignalingState {
+ SIGNALING_STATE_STABLE,
+ SIGNALING_STATE_HAVE_LOCAL_OFFER,
+ SIGNALING_STATE_HAVE_REMOTE_OFFER,
+ SIGNALING_STATE_HAVE_LOCAL_PRANSWER,
+ SIGNALING_STATE_HAVE_REMOTE_PRANSWER,
+ SIGNALING_STATE_CLOSED,
+ };
+
static void _register_methods();
static const godot_gdnative_ext_net_3_2_api_struct *_net_api;
@@ -82,6 +97,8 @@ public:
void register_interface(const godot_net_webrtc_peer_connection *interface);
virtual ConnectionState _get_connection_state() const = 0;
+ virtual GatheringState _get_gathering_state() const = 0;
+ virtual SignalingState _get_signaling_state() const = 0;
virtual godot::Error _initialize(const godot::Dictionary &p_config) = 0;
virtual godot::Object *_create_data_channel(const godot::String &p_channel, const godot::Dictionary &p_channel_config) = 0;