diff options
Diffstat (limited to 'modules/webrtc')
-rw-r--r-- | modules/webrtc/doc_classes/WebRTCPeerConnection.xml | 7 | ||||
-rw-r--r-- | modules/webrtc/doc_classes/WebRTCPeerConnectionExtension.xml | 5 | ||||
-rw-r--r-- | modules/webrtc/register_types.cpp | 14 | ||||
-rw-r--r-- | modules/webrtc/register_types.h | 6 | ||||
-rw-r--r-- | modules/webrtc/webrtc_data_channel.h | 2 | ||||
-rw-r--r-- | modules/webrtc/webrtc_multiplayer_peer.cpp | 40 | ||||
-rw-r--r-- | modules/webrtc/webrtc_multiplayer_peer.h | 2 | ||||
-rw-r--r-- | modules/webrtc/webrtc_peer_connection.cpp | 7 | ||||
-rw-r--r-- | modules/webrtc/webrtc_peer_connection_extension.cpp | 7 | ||||
-rw-r--r-- | modules/webrtc/webrtc_peer_connection_extension.h | 2 | ||||
-rw-r--r-- | modules/webrtc/webrtc_peer_connection_js.h | 18 |
11 files changed, 57 insertions, 53 deletions
diff --git a/modules/webrtc/doc_classes/WebRTCPeerConnection.xml b/modules/webrtc/doc_classes/WebRTCPeerConnection.xml index b4d97077e3..fed67397d1 100644 --- a/modules/webrtc/doc_classes/WebRTCPeerConnection.xml +++ b/modules/webrtc/doc_classes/WebRTCPeerConnection.xml @@ -95,6 +95,13 @@ Call this method frequently (e.g. in [method Node._process] or [method Node._physics_process]) to properly receive signals. </description> </method> + <method name="set_default_extension" qualifiers="static"> + <return type="void" /> + <argument index="0" name="extension_class" type="StringName" /> + <description> + Sets the [code]extension_class[/code] as the default [WebRTCPeerConnectionExtension] returned when creating a new [WebRTCPeerConnection]. + </description> + </method> <method name="set_local_description"> <return type="int" enum="Error" /> <argument index="0" name="type" type="String" /> diff --git a/modules/webrtc/doc_classes/WebRTCPeerConnectionExtension.xml b/modules/webrtc/doc_classes/WebRTCPeerConnectionExtension.xml index e88acdc845..163d939ac1 100644 --- a/modules/webrtc/doc_classes/WebRTCPeerConnectionExtension.xml +++ b/modules/webrtc/doc_classes/WebRTCPeerConnectionExtension.xml @@ -62,10 +62,5 @@ <description> </description> </method> - <method name="make_default"> - <return type="void" /> - <description> - </description> - </method> </methods> </class> diff --git a/modules/webrtc/register_types.cpp b/modules/webrtc/register_types.cpp index e6a8dcc31a..09cd538b96 100644 --- a/modules/webrtc/register_types.cpp +++ b/modules/webrtc/register_types.cpp @@ -37,7 +37,11 @@ #include "webrtc_data_channel_extension.h" #include "webrtc_peer_connection_extension.h" -void register_webrtc_types() { +void initialize_webrtc_module(ModuleInitializationLevel p_level) { + if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { + return; + } + #define SET_HINT(NAME, _VAL_, _MAX_) \ GLOBAL_DEF(NAME, _VAL_); \ ProjectSettings::get_singleton()->set_custom_property_info(NAME, PropertyInfo(Variant::INT, NAME, PROPERTY_HINT_RANGE, "2," #_MAX_ ",1,or_greater")); @@ -47,7 +51,7 @@ void register_webrtc_types() { ClassDB::register_custom_instance_class<WebRTCPeerConnection>(); GDREGISTER_CLASS(WebRTCPeerConnectionExtension); - GDREGISTER_VIRTUAL_CLASS(WebRTCDataChannel); + GDREGISTER_ABSTRACT_CLASS(WebRTCDataChannel); GDREGISTER_CLASS(WebRTCDataChannelExtension); GDREGISTER_CLASS(WebRTCMultiplayerPeer); @@ -55,4 +59,8 @@ void register_webrtc_types() { #undef SET_HINT } -void unregister_webrtc_types() {} +void uninitialize_webrtc_module(ModuleInitializationLevel p_level) { + if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { + return; + } +} diff --git a/modules/webrtc/register_types.h b/modules/webrtc/register_types.h index 2e4457beaf..17171d0e0b 100644 --- a/modules/webrtc/register_types.h +++ b/modules/webrtc/register_types.h @@ -31,7 +31,9 @@ #ifndef WEBRTC_REGISTER_TYPES_H #define WEBRTC_REGISTER_TYPES_H -void register_webrtc_types(); -void unregister_webrtc_types(); +#include "modules/register_module_types.h" + +void initialize_webrtc_module(ModuleInitializationLevel p_level); +void uninitialize_webrtc_module(ModuleInitializationLevel p_level); #endif // WEBRTC_REGISTER_TYPES_H diff --git a/modules/webrtc/webrtc_data_channel.h b/modules/webrtc/webrtc_data_channel.h index eac8f85a84..75e29283ec 100644 --- a/modules/webrtc/webrtc_data_channel.h +++ b/modules/webrtc/webrtc_data_channel.h @@ -33,7 +33,7 @@ #include "core/io/packet_peer.h" -#define WRTC_IN_BUF "network/limits/webrtc/max_channel_in_buffer_kb" +#define WRTC_IN_BUF PNAME("network/limits/webrtc/max_channel_in_buffer_kb") class WebRTCDataChannel : public PacketPeer { GDCLASS(WebRTCDataChannel, PacketPeer); diff --git a/modules/webrtc/webrtc_multiplayer_peer.cpp b/modules/webrtc/webrtc_multiplayer_peer.cpp index bc3c0d9265..6f68b84ad3 100644 --- a/modules/webrtc/webrtc_multiplayer_peer.cpp +++ b/modules/webrtc/webrtc_multiplayer_peer.cpp @@ -140,41 +140,41 @@ void WebRTCMultiplayerPeer::poll() { } void WebRTCMultiplayerPeer::_find_next_peer() { - Map<int, Ref<ConnectedPeer>>::Element *E = peer_map.find(next_packet_peer); + HashMap<int, Ref<ConnectedPeer>>::Iterator E = peer_map.find(next_packet_peer); if (E) { - E = E->next(); + ++E; } // After last. while (E) { - if (!E->get()->connected) { - E = E->next(); + if (!E->value->connected) { + ++E; continue; } - for (const Ref<WebRTCDataChannel> &F : E->get()->channels) { + for (const Ref<WebRTCDataChannel> &F : E->value->channels) { if (F->get_available_packet_count()) { - next_packet_peer = E->key(); + next_packet_peer = E->key; return; } } - E = E->next(); + ++E; } - E = peer_map.front(); + E = peer_map.begin(); // Before last while (E) { - if (!E->get()->connected) { - E = E->next(); + if (!E->value->connected) { + ++E; continue; } - for (const Ref<WebRTCDataChannel> &F : E->get()->channels) { + for (const Ref<WebRTCDataChannel> &F : E->value->channels) { if (F->get_available_packet_count()) { - next_packet_peer = E->key(); + next_packet_peer = E->key; return; } } - if (E->key() == (int)next_packet_peer) { + if (E->key == (int)next_packet_peer) { break; } - E = E->next(); + ++E; } // No packet found next_packet_peer = 0; @@ -353,15 +353,13 @@ Error WebRTCMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_si ch += CH_RESERVED_MAX - 1; } - Map<int, Ref<ConnectedPeer>>::Element *E = nullptr; - if (target_peer > 0) { - E = peer_map.find(target_peer); + HashMap<int, Ref<ConnectedPeer>>::Iterator E = peer_map.find(target_peer); ERR_FAIL_COND_V_MSG(!E, ERR_INVALID_PARAMETER, "Invalid target peer: " + itos(target_peer) + "."); - ERR_FAIL_COND_V_MSG(E->value()->channels.size() <= ch, ERR_INVALID_PARAMETER, vformat("Unable to send packet on channel %d, max channels: %d", ch, E->value()->channels.size())); - ERR_FAIL_COND_V(E->value()->channels[ch].is_null(), ERR_BUG); - return E->value()->channels[ch]->put_packet(p_buffer, p_buffer_size); + ERR_FAIL_COND_V_MSG(E->value->channels.size() <= ch, ERR_INVALID_PARAMETER, vformat("Unable to send packet on channel %d, max channels: %d", ch, E->value->channels.size())); + ERR_FAIL_COND_V(E->value->channels[ch].is_null(), ERR_BUG); + return E->value->channels[ch]->put_packet(p_buffer, p_buffer_size); } else { int exclude = -target_peer; @@ -372,7 +370,7 @@ Error WebRTCMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_si continue; } - ERR_CONTINUE_MSG(F.value->channels.size() <= ch, vformat("Unable to send packet on channel %d, max channels: %d", ch, E->value()->channels.size())); + ERR_CONTINUE_MSG(F.value->channels.size() <= ch, vformat("Unable to send packet on channel %d, max channels: %d", ch, F.value->channels.size())); ERR_CONTINUE(F.value->channels[ch].is_null()); F.value->channels[ch]->put_packet(p_buffer, p_buffer_size); } diff --git a/modules/webrtc/webrtc_multiplayer_peer.h b/modules/webrtc/webrtc_multiplayer_peer.h index 6675c67867..97550a3e9d 100644 --- a/modules/webrtc/webrtc_multiplayer_peer.h +++ b/modules/webrtc/webrtc_multiplayer_peer.h @@ -69,7 +69,7 @@ private: int next_packet_peer = 0; bool server_compat = false; - Map<int, Ref<ConnectedPeer>> peer_map; + HashMap<int, Ref<ConnectedPeer>> peer_map; List<Dictionary> channels_config; void _peer_to_dict(Ref<ConnectedPeer> p_connected_peer, Dictionary &r_dict); diff --git a/modules/webrtc/webrtc_peer_connection.cpp b/modules/webrtc/webrtc_peer_connection.cpp index 7fdf26d3cd..75716017d7 100644 --- a/modules/webrtc/webrtc_peer_connection.cpp +++ b/modules/webrtc/webrtc_peer_connection.cpp @@ -32,13 +32,14 @@ #ifdef JAVASCRIPT_ENABLED #include "webrtc_peer_connection_js.h" -#else -#include "webrtc_peer_connection_extension.h" #endif +#include "webrtc_peer_connection_extension.h" + StringName WebRTCPeerConnection::default_extension; void WebRTCPeerConnection::set_default_extension(const StringName &p_extension) { + ERR_FAIL_COND_MSG(!ClassDB::is_parent_class(p_extension, WebRTCPeerConnectionExtension::get_class_static()), vformat("Can't make %s the default WebRTC extension since it does not extend WebRTCPeerConnectionExtension.", p_extension)); default_extension = p_extension; } @@ -56,6 +57,8 @@ WebRTCPeerConnection *WebRTCPeerConnection::create() { } void WebRTCPeerConnection::_bind_methods() { + ClassDB::bind_static_method(get_class_static(), D_METHOD("set_default_extension", "extension_class"), &WebRTCPeerConnectionExtension::set_default_extension); + ClassDB::bind_method(D_METHOD("initialize", "configuration"), &WebRTCPeerConnection::initialize, DEFVAL(Dictionary())); ClassDB::bind_method(D_METHOD("create_data_channel", "label", "options"), &WebRTCPeerConnection::create_data_channel, DEFVAL(Dictionary())); ClassDB::bind_method(D_METHOD("create_offer"), &WebRTCPeerConnection::create_offer); diff --git a/modules/webrtc/webrtc_peer_connection_extension.cpp b/modules/webrtc/webrtc_peer_connection_extension.cpp index 3bc7de217e..85c04b3b19 100644 --- a/modules/webrtc/webrtc_peer_connection_extension.cpp +++ b/modules/webrtc/webrtc_peer_connection_extension.cpp @@ -31,8 +31,6 @@ #include "webrtc_peer_connection_extension.h" void WebRTCPeerConnectionExtension::_bind_methods() { - ClassDB::bind_method(D_METHOD("make_default"), &WebRTCPeerConnectionExtension::make_default); - GDVIRTUAL_BIND(_get_connection_state); GDVIRTUAL_BIND(_initialize, "p_config"); GDVIRTUAL_BIND(_create_data_channel, "p_label", "p_config"); @@ -44,11 +42,6 @@ void WebRTCPeerConnectionExtension::_bind_methods() { GDVIRTUAL_BIND(_close); } -void WebRTCPeerConnectionExtension::make_default() { - ERR_FAIL_COND_MSG(!_get_extension(), vformat("Can't make %s the default without extending it.", get_class())); - WebRTCPeerConnection::set_default_extension(get_class()); -} - WebRTCPeerConnection::ConnectionState WebRTCPeerConnectionExtension::get_connection_state() const { int state; if (GDVIRTUAL_CALL(_get_connection_state, state)) { diff --git a/modules/webrtc/webrtc_peer_connection_extension.h b/modules/webrtc/webrtc_peer_connection_extension.h index 82e32b5602..bde19c173b 100644 --- a/modules/webrtc/webrtc_peer_connection_extension.h +++ b/modules/webrtc/webrtc_peer_connection_extension.h @@ -44,8 +44,6 @@ protected: static void _bind_methods(); public: - void make_default(); - virtual ConnectionState get_connection_state() const override; virtual Error initialize(Dictionary p_config = Dictionary()) override; diff --git a/modules/webrtc/webrtc_peer_connection_js.h b/modules/webrtc/webrtc_peer_connection_js.h index 3d0b365355..8fa5ea7779 100644 --- a/modules/webrtc/webrtc_peer_connection_js.h +++ b/modules/webrtc/webrtc_peer_connection_js.h @@ -63,16 +63,16 @@ private: static void _on_error(void *p_obj); public: - virtual ConnectionState get_connection_state() const; + virtual ConnectionState get_connection_state() const override; - virtual Error initialize(Dictionary configuration = Dictionary()); - virtual Ref<WebRTCDataChannel> create_data_channel(String p_channel_name, Dictionary p_channel_config = Dictionary()); - virtual Error create_offer(); - virtual Error set_remote_description(String type, String sdp); - virtual Error set_local_description(String type, String sdp); - virtual Error add_ice_candidate(String sdpMidName, int sdpMlineIndexName, String sdpName); - virtual Error poll(); - virtual void close(); + virtual Error initialize(Dictionary configuration = Dictionary()) override; + virtual Ref<WebRTCDataChannel> create_data_channel(String p_channel_name, Dictionary p_channel_config = Dictionary()) override; + virtual Error create_offer() override; + virtual Error set_remote_description(String type, String sdp) override; + virtual Error set_local_description(String type, String sdp) override; + virtual Error add_ice_candidate(String sdpMidName, int sdpMlineIndexName, String sdpName) override; + virtual Error poll() override; + virtual void close() override; WebRTCPeerConnectionJS(); ~WebRTCPeerConnectionJS(); |