summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2019-04-21 04:57:53 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2019-05-16 10:32:51 +0200
commit3e64a42b1492e38bf033041c0eb1212542728cbd (patch)
treed187f873ecfdace0d127c6bc340ed295edcaa2f1 /src/net
parentf2cf2e5340c1aa20516aea4863b8f7a46f317bb6 (diff)
downloadfork-godot-webrtc-native-3e64a42b1492e38bf033041c0eb1212542728cbd.tar.gz
fork-godot-webrtc-native-3e64a42b1492e38bf033041c0eb1212542728cbd.tar.bz2
fork-godot-webrtc-native-3e64a42b1492e38bf033041c0eb1212542728cbd.zip
Update to new DataChannel API.
New WebRTCLibDataChannel class act as PacketPeer. Old WebRTCPeer (now WebRTCPeerConnection) now allows you to set configuration (STUN/TURN) and creating multiple data channels. Fixed many bugs and implemented most of the missing API.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/WebRTCDataChannelNative.cpp92
-rw-r--r--src/net/WebRTCDataChannelNative.hpp91
-rw-r--r--src/net/WebRTCPeerConnectionNative.cpp65
-rw-r--r--src/net/WebRTCPeerConnectionNative.hpp66
-rw-r--r--src/net/WebRTCPeerNative.cpp77
-rw-r--r--src/net/WebRTCPeerNative.hpp80
6 files changed, 314 insertions, 157 deletions
diff --git a/src/net/WebRTCDataChannelNative.cpp b/src/net/WebRTCDataChannelNative.cpp
new file mode 100644
index 0000000..8e1d3b1
--- /dev/null
+++ b/src/net/WebRTCDataChannelNative.cpp
@@ -0,0 +1,92 @@
+#include "WebRTCDataChannelNative.hpp"
+#include "net/WebRTCPeerConnectionNative.hpp"
+
+void WebRTCDataChannelNative::register_interface(const godot_net_webrtc_data_channel *p_interface) {
+ ERR_FAIL_COND(!WebRTCPeerConnectionNative::_net_api);
+ WebRTCPeerConnectionNative::_net_api->godot_net_bind_webrtc_data_channel(_owner, p_interface);
+}
+
+void WebRTCDataChannelNative::_register_methods() {}
+
+void WebRTCDataChannelNative::_init() {
+ register_interface(&interface);
+}
+
+WebRTCDataChannelNative::~WebRTCDataChannelNative() {
+ if (_owner) {
+ register_interface(NULL);
+ }
+}
+
+/*
+ * The C interface that implements WebRTCDataChannel.
+ * In this case it forwards calls to our C++ class, but could be plain C,
+ * and you could use void *user for any kind of state struct pointer you have.
+ */
+godot_error get_packet_wdc(void *user, const uint8_t **r_buffer, int *r_len) {
+ return ((WebRTCDataChannelNative *)user)->get_packet(r_buffer, r_len);
+}
+
+godot_error put_packet_wdc(void *user, const uint8_t *p_buffer, int p_len) {
+ return ((WebRTCDataChannelNative *)user)->put_packet(p_buffer, p_len);
+}
+
+godot_int get_available_packet_count_wdc(const void *user) {
+ return ((WebRTCDataChannelNative *)user)->get_available_packet_count();
+}
+
+godot_int get_max_packet_size_wdc(const void *user) {
+ return ((WebRTCDataChannelNative *)user)->get_max_packet_size();
+}
+
+void set_write_mode_wdc(void *user, godot_int write_mode) {
+ ((WebRTCDataChannelNative *)user)->set_write_mode(write_mode);
+}
+
+godot_int get_write_mode_wdc(const void *user) {
+ return ((WebRTCDataChannelNative *)user)->get_write_mode();
+}
+
+bool was_string_packet_wdc(const void *user) {
+ return ((WebRTCDataChannelNative *)user)->was_string_packet();
+}
+
+godot_int get_ready_state_wdc(const void *user) {
+ return (godot_int)(((WebRTCDataChannelNative *)user)->get_ready_state());
+}
+
+const char *get_label_wdc(const void *user) {
+ return ((WebRTCDataChannelNative *)user)->get_label();
+}
+
+bool is_ordered_wdc(const void *user) {
+ return ((WebRTCDataChannelNative *)user)->is_ordered();
+}
+
+int get_id_wdc(const void *user) {
+ return ((WebRTCDataChannelNative *)user)->get_id();
+}
+
+int get_max_packet_life_time_wdc(const void *user) {
+ return ((WebRTCDataChannelNative *)user)->get_max_packet_life_time();
+}
+
+int get_max_retransmits_wdc(const void *user) {
+ return ((WebRTCDataChannelNative *)user)->get_max_retransmits();
+}
+
+const char *get_protocol_wdc(const void *user) {
+ return ((WebRTCDataChannelNative *)user)->get_protocol();
+}
+
+bool is_negotiated_wdc(const void *user) {
+ return ((WebRTCDataChannelNative *)user)->is_negotiated();
+}
+
+godot_error poll_wdc(void *user) {
+ return ((WebRTCDataChannelNative *)user)->poll();
+}
+
+void close_wdc(void *user) {
+ ((WebRTCDataChannelNative *)user)->close();
+}
diff --git a/src/net/WebRTCDataChannelNative.hpp b/src/net/WebRTCDataChannelNative.hpp
new file mode 100644
index 0000000..eaeb95d
--- /dev/null
+++ b/src/net/WebRTCDataChannelNative.hpp
@@ -0,0 +1,91 @@
+#ifndef WEBRTC_DATA_CHANNEL_NATIVE
+#define WEBRTC_DATA_CHANNEL_NATIVE
+
+#include <Godot.hpp>
+#include <Reference.hpp>
+#include <WebRTCDataChannelGDNative.hpp>
+
+#include <net/godot_net.h>
+
+/* Forward declare interface functions */
+godot_error get_packet_wdc(void *, const uint8_t **, int *);
+godot_error put_packet_wdc(void *, const uint8_t *, int);
+godot_int get_available_packet_count_wdc(const void *);
+godot_int get_max_packet_size_wdc(const void *);
+
+void set_write_mode_wdc(void *, godot_int);
+godot_int get_write_mode_wdc(const void *);
+bool was_string_packet_wdc(const void *);
+godot_int get_ready_state_wdc(const void *);
+const char *get_label_wdc(const void *);
+bool is_ordered_wdc(const void *);
+int get_id_wdc(const void *);
+int get_max_packet_life_time_wdc(const void *);
+int get_max_retransmits_wdc(const void *);
+const char *get_protocol_wdc(const void *);
+bool is_negotiated_wdc(const void *);
+godot_error poll_wdc(void *);
+void close_wdc(void *);
+
+class WebRTCDataChannelNative : public godot::WebRTCDataChannelGDNative {
+ GODOT_CLASS(WebRTCDataChannelNative, godot::WebRTCDataChannelGDNative);
+
+protected:
+ godot_net_webrtc_data_channel interface = {
+ { 3, 1 },
+ this,
+
+ &get_packet_wdc,
+ &put_packet_wdc,
+ &get_available_packet_count_wdc,
+ &get_max_packet_size_wdc,
+
+ &set_write_mode_wdc,
+ &get_write_mode_wdc,
+ &was_string_packet_wdc,
+ &get_ready_state_wdc,
+ &get_label_wdc,
+ &is_ordered_wdc,
+ &get_id_wdc,
+ &get_max_packet_life_time_wdc,
+ &get_max_retransmits_wdc,
+ &get_protocol_wdc,
+ &is_negotiated_wdc,
+
+ &poll_wdc,
+ &close_wdc,
+ NULL,
+ };
+
+public:
+ static void _register_methods();
+
+ void _init();
+ void register_interface(const godot_net_webrtc_data_channel *interface);
+
+ virtual void set_write_mode(godot_int mode) = 0;
+ virtual godot_int get_write_mode() const = 0;
+ virtual bool was_string_packet() const = 0;
+
+ virtual ChannelState get_ready_state() const = 0;
+ virtual const char *get_label() const = 0;
+ virtual bool is_ordered() const = 0;
+ virtual int get_id() const = 0;
+ virtual int get_max_packet_life_time() const = 0;
+ virtual int get_max_retransmits() const = 0;
+ virtual const char *get_protocol() const = 0;
+ virtual bool is_negotiated() const = 0;
+
+ virtual godot_error poll() = 0;
+ virtual void close() = 0;
+
+ /* PacketPeer */
+ virtual godot_error get_packet(const uint8_t **r_buffer, int *r_len) = 0;
+ virtual godot_error put_packet(const uint8_t *p_buffer, int p_len) = 0;
+ virtual godot_int get_available_packet_count() const = 0;
+ virtual godot_int get_max_packet_size() const = 0;
+
+ ~WebRTCDataChannelNative();
+};
+
+#endif // WEBRTC_DATA_CHANNEL_NATIVE
diff --git a/src/net/WebRTCPeerConnectionNative.cpp b/src/net/WebRTCPeerConnectionNative.cpp
new file mode 100644
index 0000000..5f7d83e
--- /dev/null
+++ b/src/net/WebRTCPeerConnectionNative.cpp
@@ -0,0 +1,65 @@
+#include "WebRTCPeerConnectionNative.hpp"
+
+const godot_gdnative_ext_net_3_2_api_struct *WebRTCPeerConnectionNative::_net_api = NULL;
+
+void WebRTCPeerConnectionNative::register_interface(const godot_net_webrtc_peer_connection *p_interface) {
+ ERR_FAIL_COND(!_net_api);
+ _net_api->godot_net_bind_webrtc_peer_connection(_owner, p_interface);
+}
+
+void WebRTCPeerConnectionNative::_register_methods() {}
+
+void WebRTCPeerConnectionNative::_init() {
+ register_interface(&interface);
+}
+
+WebRTCPeerConnectionNative::~WebRTCPeerConnectionNative() {
+ if (_owner) {
+ register_interface(NULL);
+ }
+}
+
+/*
+ * The C interface that implements WebRTCPeerConnection.
+ * In this case it forwards calls to our C++ class, but could be plain C,
+ * and you could use void *user for any kind of state struct pointer you have.
+ */
+godot_int get_connection_state_wp(const void *user) {
+ return (godot_int)((WebRTCPeerConnectionNative *)user)->get_connection_state();
+}
+
+godot_error initialize_wp(void *user, const godot_dictionary *p_config) {
+ return ((WebRTCPeerConnectionNative *)user)->initialize(p_config);
+}
+
+godot_object *create_data_channel_wp(void *user, const char *p_channel, const godot_dictionary *p_channel_config) {
+ return ((WebRTCPeerConnectionNative *)user)->create_data_channel(p_channel, p_channel_config);
+}
+
+godot_error create_offer_wp(void *user) {
+ return ((WebRTCPeerConnectionNative *)user)->create_offer();
+}
+
+godot_error create_answer_wp(void *user) {
+ return GODOT_ERR_UNAVAILABLE; // Not implemented, not used yet.
+}
+
+godot_error set_remote_description_wp(void *user, const char *type, const char *sdp) {
+ return ((WebRTCPeerConnectionNative *)user)->set_remote_description(type, sdp);
+}
+
+godot_error set_local_description_wp(void *user, const char *type, const char *sdp) {
+ return ((WebRTCPeerConnectionNative *)user)->set_local_description(type, sdp);
+}
+
+godot_error add_ice_candidate_wp(void *user, const char *sdpMidName, int sdpMlineIndexName, const char *sdpName) {
+ return ((WebRTCPeerConnectionNative *)user)->add_ice_candidate(sdpMidName, sdpMlineIndexName, sdpName);
+}
+
+godot_error poll_wp(void *user) {
+ return ((WebRTCPeerConnectionNative *)user)->poll();
+}
+
+void close_wp(void *user) {
+ ((WebRTCPeerConnectionNative *)user)->close();
+}
diff --git a/src/net/WebRTCPeerConnectionNative.hpp b/src/net/WebRTCPeerConnectionNative.hpp
new file mode 100644
index 0000000..3b0ac79
--- /dev/null
+++ b/src/net/WebRTCPeerConnectionNative.hpp
@@ -0,0 +1,66 @@
+#ifndef WEBRTC_PEER_NATIVE
+#define WEBRTC_PEER_NATIVE
+
+#include <Godot.hpp>
+#include <Reference.hpp>
+#include <WebRTCPeerConnectionGDNative.hpp>
+
+#include <net/godot_net.h>
+
+/* Forward declare interface functions */
+godot_int get_connection_state_wp(const void *);
+
+godot_error initialize_wp(void *, const godot_dictionary *);
+godot_object *create_data_channel_wp(void *, const char *, const godot_dictionary *);
+godot_error create_offer_wp(void *);
+godot_error create_answer_wp(void *);
+godot_error set_remote_description_wp(void *, const char *, const char *);
+godot_error set_local_description_wp(void *, const char *, const char *);
+godot_error add_ice_candidate_wp(void *, const char *, int, const char *);
+godot_error poll_wp(void *);
+void close_wp(void *);
+
+class WebRTCPeerConnectionNative : public godot::WebRTCPeerConnectionGDNative {
+ GODOT_CLASS(WebRTCPeerConnectionNative, godot::WebRTCPeerConnectionGDNative);
+
+protected:
+ godot_net_webrtc_peer_connection interface = {
+ { 3, 1 },
+ this,
+
+ &get_connection_state_wp,
+
+ &initialize_wp,
+ &create_data_channel_wp,
+ &create_offer_wp,
+ &create_answer_wp,
+ &set_remote_description_wp,
+ &set_local_description_wp,
+ &add_ice_candidate_wp,
+ &poll_wp,
+ &close_wp,
+ NULL,
+ };
+
+public:
+ static void _register_methods();
+ static const godot_gdnative_ext_net_3_2_api_struct *_net_api;
+
+ void _init();
+ void register_interface(const godot_net_webrtc_peer_connection *interface);
+
+ virtual ConnectionState get_connection_state() const = 0;
+
+ virtual godot_error initialize(const godot_dictionary *p_config) = 0;
+ virtual godot_object *create_data_channel(const char *p_channel, const godot_dictionary *p_channel_config) = 0;
+ virtual godot_error create_offer() = 0;
+ virtual godot_error set_remote_description(const char *type, const char *sdp) = 0;
+ virtual godot_error set_local_description(const char *type, const char *sdp) = 0;
+ virtual godot_error add_ice_candidate(const char *sdpMidName, int sdpMlineIndexName, const char *sdpName) = 0;
+ virtual godot_error poll() = 0;
+ virtual void close() = 0;
+
+ ~WebRTCPeerConnectionNative();
+};
+
+#endif // WEBRTC_PEER_NATIVE
diff --git a/src/net/WebRTCPeerNative.cpp b/src/net/WebRTCPeerNative.cpp
deleted file mode 100644
index a0872bc..0000000
--- a/src/net/WebRTCPeerNative.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-#include "WebRTCPeerNative.hpp"
-
-const godot_gdnative_ext_net_3_2_api_struct *WebRTCPeerNative::_net_api = NULL;
-
-void WebRTCPeerNative::register_interface(const godot_net_webrtc_peer *p_interface) {
- ERR_FAIL_COND(!_net_api);
- _net_api->godot_net_bind_webrtc_peer(_owner, p_interface);
-}
-
-void WebRTCPeerNative::_register_methods() {}
-
-void WebRTCPeerNative::_init() {
- register_interface(&interface);
-}
-
-WebRTCPeerNative::~WebRTCPeerNative() {
- if (_owner) {
- register_interface(NULL);
- }
-}
-
-/*
- * The C interface that implements WebRTCPeer.
- * In this case it forwards calls to our C++ class, but could be plain C,
- * and you could use void *user for any kind of state struct pointer you have.
- */
-godot_error get_packet_wp(void *user, const uint8_t **r_buffer, int *r_len) {
- return ((WebRTCPeerNative *)user)->get_packet(r_buffer, r_len);
-}
-
-godot_error put_packet_wp(void *user, const uint8_t *p_buffer, int p_len) {
- return ((WebRTCPeerNative *)user)->put_packet(p_buffer, p_len);
-}
-
-godot_int get_available_packet_count_wp(const void *user) {
- return ((WebRTCPeerNative *)user)->get_available_packet_count();
-}
-
-godot_int get_max_packet_size_wp(const void *user) {
- return ((WebRTCPeerNative *)user)->get_max_packet_size();
-}
-
-void set_write_mode_wp(void *user, godot_int write_mode) {
- ((WebRTCPeerNative *)user)->set_write_mode(write_mode);
-}
-
-godot_int get_write_mode_wp(const void *user) {
- return ((WebRTCPeerNative *)user)->get_write_mode();
-}
-
-bool was_string_packet_wp(const void *user) {
- return ((WebRTCPeerNative *)user)->was_string_packet();
-}
-
-godot_int get_connection_state_wp(const void *user) {
- return ((WebRTCPeerNative *)user)->get_connection_state();
-}
-
-godot_error create_offer_wp(void *user) {
- return ((WebRTCPeerNative *)user)->create_offer();
-}
-
-godot_error set_remote_description_wp(void *user, const char *type, const char *sdp) {
- return ((WebRTCPeerNative *)user)->set_remote_description(type, sdp);
-}
-
-godot_error set_local_description_wp(void *user, const char *type, const char *sdp) {
- return ((WebRTCPeerNative *)user)->set_local_description(type, sdp);
-}
-
-godot_error add_ice_candidate_wp(void *user, const char *sdpMidName, int sdpMlineIndexName, const char *sdpName) {
- return ((WebRTCPeerNative *)user)->add_ice_candidate(sdpMidName, sdpMlineIndexName, sdpName);
-}
-
-godot_error poll_wp(void *user) {
- return ((WebRTCPeerNative *)user)->poll();
-}
diff --git a/src/net/WebRTCPeerNative.hpp b/src/net/WebRTCPeerNative.hpp
deleted file mode 100644
index d5f2c6f..0000000
--- a/src/net/WebRTCPeerNative.hpp
+++ /dev/null
@@ -1,80 +0,0 @@
-#ifndef WEBRTC_PEER_NATIVE
-#define WEBRTC_PEER_NATIVE
-
-#include <Godot.hpp>
-#include <Reference.hpp>
-#include <WebRTCPeerGDNative.hpp>
-
-#include <net/godot_net.h>
-
-/* Forward declare interface functions */
-godot_error get_packet_wp(void *, const uint8_t **, int *);
-godot_error put_packet_wp(void *, const uint8_t *, int);
-godot_int get_available_packet_count_wp(const void *);
-godot_int get_max_packet_size_wp(const void *);
-
-void set_write_mode_wp(void *, godot_int);
-godot_int get_write_mode_wp(const void *);
-bool was_string_packet_wp(const void *);
-godot_int get_connection_state_wp(const void *);
-
-godot_error create_offer_wp(void *);
-godot_error set_remote_description_wp(void *, const char *, const char *);
-godot_error set_local_description_wp(void *, const char *, const char *);
-godot_error add_ice_candidate_wp(void *, const char *, int, const char *);
-godot_error poll_wp(void *);
-
-class WebRTCPeerNative : public godot::WebRTCPeerGDNative {
- GODOT_CLASS(WebRTCPeerNative, godot::WebRTCPeerGDNative);
-
-protected:
- godot_net_webrtc_peer interface = {
- { 3, 1 },
- this,
-
- &get_packet_wp,
- &put_packet_wp,
- &get_available_packet_count_wp,
- &get_max_packet_size_wp,
-
- &set_write_mode_wp,
- &get_write_mode_wp,
- &was_string_packet_wp,
- &get_connection_state_wp,
-
- &create_offer_wp,
- &set_remote_description_wp,
- &set_local_description_wp,
- &add_ice_candidate_wp,
- &poll_wp,
- NULL,
- };
-
-public:
- static void _register_methods();
- static const godot_gdnative_ext_net_3_2_api_struct *_net_api;
-
- void _init();
- void register_interface(const godot_net_webrtc_peer *interface);
-
- virtual void set_write_mode(godot_int mode) = 0;
- virtual godot_int get_write_mode() const = 0;
- virtual bool was_string_packet() const = 0;
- virtual godot_int get_connection_state() const = 0;
-
- virtual godot_error create_offer() = 0;
- virtual godot_error set_remote_description(const char *type, const char *sdp) = 0;
- virtual godot_error set_local_description(const char *type, const char *sdp) = 0;
- virtual godot_error add_ice_candidate(const char *sdpMidName, int sdpMlineIndexName, const char *sdpName) = 0;
- virtual godot_error poll() = 0;
-
- /* PacketPeer */
- virtual godot_error get_packet(const uint8_t **r_buffer, int *r_len) = 0;
- virtual godot_error put_packet(const uint8_t *p_buffer, int p_len) = 0;
- virtual godot_int get_available_packet_count() const = 0;
- virtual godot_int get_max_packet_size() const = 0;
-
- ~WebRTCPeerNative();
-};
-
-#endif // WEBRTC_PEER_NATIVE