diff options
Diffstat (limited to 'modules/webrtc')
-rw-r--r-- | modules/webrtc/doc_classes/WebRTCPeerConnection.xml | 2 | ||||
-rw-r--r-- | modules/webrtc/webrtc_data_channel.h | 7 | ||||
-rw-r--r-- | modules/webrtc/webrtc_data_channel_gdnative.h | 34 | ||||
-rw-r--r-- | modules/webrtc/webrtc_data_channel_js.cpp | 7 | ||||
-rw-r--r-- | modules/webrtc/webrtc_data_channel_js.h | 38 | ||||
-rw-r--r-- | modules/webrtc/webrtc_multiplayer.cpp | 35 | ||||
-rw-r--r-- | modules/webrtc/webrtc_multiplayer.h | 33 | ||||
-rw-r--r-- | modules/webrtc/webrtc_peer_connection.cpp | 5 | ||||
-rw-r--r-- | modules/webrtc/webrtc_peer_connection_gdnative.cpp | 1 | ||||
-rw-r--r-- | modules/webrtc/webrtc_peer_connection_gdnative.h | 18 | ||||
-rw-r--r-- | modules/webrtc/webrtc_peer_connection_js.h | 1 |
11 files changed, 89 insertions, 92 deletions
diff --git a/modules/webrtc/doc_classes/WebRTCPeerConnection.xml b/modules/webrtc/doc_classes/WebRTCPeerConnection.xml index 504b4705d8..2054276655 100644 --- a/modules/webrtc/doc_classes/WebRTCPeerConnection.xml +++ b/modules/webrtc/doc_classes/WebRTCPeerConnection.xml @@ -120,7 +120,7 @@ </argument> <description> Sets the SDP description of the local peer. This should be called in response to [signal session_description_created]. - If [code]type[/code] is [code]answer[/code] the peer will start emitting [signal ice_candidate_created]. + After calling this function the peer will start emitting [signal ice_candidate_created] (unless an [enum Error] different from [constant OK] is returned). </description> </method> <method name="set_remote_description"> diff --git a/modules/webrtc/webrtc_data_channel.h b/modules/webrtc/webrtc_data_channel.h index e61f786ca1..1407f1e3bd 100644 --- a/modules/webrtc/webrtc_data_channel.h +++ b/modules/webrtc/webrtc_data_channel.h @@ -73,13 +73,6 @@ public: virtual Error poll() = 0; virtual void close() = 0; - /** Inherited from PacketPeer: **/ - virtual int get_available_packet_count() const = 0; - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) = 0; ///< buffer is GONE after next get_packet - virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) = 0; - - virtual int get_max_packet_size() const = 0; - WebRTCDataChannel(); ~WebRTCDataChannel(); }; diff --git a/modules/webrtc/webrtc_data_channel_gdnative.h b/modules/webrtc/webrtc_data_channel_gdnative.h index be3ea13028..b578802250 100644 --- a/modules/webrtc/webrtc_data_channel_gdnative.h +++ b/modules/webrtc/webrtc_data_channel_gdnative.h @@ -48,28 +48,28 @@ private: public: void set_native_webrtc_data_channel(const godot_net_webrtc_data_channel *p_impl); - virtual void set_write_mode(WriteMode mode); - virtual WriteMode get_write_mode() const; - virtual bool was_string_packet() const; + virtual void set_write_mode(WriteMode mode) override; + virtual WriteMode get_write_mode() const override; + virtual bool was_string_packet() const override; - virtual ChannelState get_ready_state() const; - virtual String get_label() const; - virtual bool is_ordered() const; - virtual int get_id() const; - virtual int get_max_packet_life_time() const; - virtual int get_max_retransmits() const; - virtual String get_protocol() const; - virtual bool is_negotiated() const; + virtual ChannelState get_ready_state() const override; + virtual String get_label() const override; + virtual bool is_ordered() const override; + virtual int get_id() const override; + virtual int get_max_packet_life_time() const override; + virtual int get_max_retransmits() const override; + virtual String get_protocol() const override; + virtual bool is_negotiated() const override; - virtual Error poll(); - virtual void close(); + virtual Error poll() override; + virtual void close() override; /** Inherited from PacketPeer: **/ - virtual int get_available_packet_count() const; - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size); ///< buffer is GONE after next get_packet - virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size); + virtual int get_available_packet_count() const override; + virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; ///< buffer is GONE after next get_packet + virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; - virtual int get_max_packet_size() const; + virtual int get_max_packet_size() const override; WebRTCDataChannelGDNative(); ~WebRTCDataChannelGDNative(); diff --git a/modules/webrtc/webrtc_data_channel_js.cpp b/modules/webrtc/webrtc_data_channel_js.cpp index 1b360720a2..2c648ba9f9 100644 --- a/modules/webrtc/webrtc_data_channel_js.cpp +++ b/modules/webrtc/webrtc_data_channel_js.cpp @@ -68,7 +68,6 @@ void WebRTCDataChannelJS::_on_error() { } void WebRTCDataChannelJS::_on_message(uint8_t *p_data, uint32_t p_size, bool p_is_string) { - ERR_FAIL_COND_MSG(in_buffer.space_left() < (int)(p_size + 5), "Buffer full! Dropping data."); uint8_t is_string = p_is_string ? 1 : 0; @@ -312,14 +311,14 @@ WebRTCDataChannelJS::WebRTCDataChannelJS(int js_id) { return; } var len = buffer.length*buffer.BYTES_PER_ELEMENT; - var out = Module._malloc(len); - Module.HEAPU8.set(buffer, out); + var out = _malloc(len); + HEAPU8.set(buffer, out); ccall("_emrtc_on_ch_message", "void", ["number", "number", "number", "number"], [c_ptr, out, len, is_string] ); - Module._free(out); + _free(out); } }, this, js_id); diff --git a/modules/webrtc/webrtc_data_channel_js.h b/modules/webrtc/webrtc_data_channel_js.h index 00b5963ea1..455866cbf1 100644 --- a/modules/webrtc/webrtc_data_channel_js.h +++ b/modules/webrtc/webrtc_data_channel_js.h @@ -60,28 +60,28 @@ public: void _on_error(); void _on_message(uint8_t *p_data, uint32_t p_size, bool p_is_string); - virtual void set_write_mode(WriteMode mode); - virtual WriteMode get_write_mode() const; - virtual bool was_string_packet() const; - - virtual ChannelState get_ready_state() const; - virtual String get_label() const; - virtual bool is_ordered() const; - virtual int get_id() const; - virtual int get_max_packet_life_time() const; - virtual int get_max_retransmits() const; - virtual String get_protocol() const; - virtual bool is_negotiated() const; - - virtual Error poll(); - virtual void close(); + virtual void set_write_mode(WriteMode mode) override; + virtual WriteMode get_write_mode() const override; + virtual bool was_string_packet() const override; + + virtual ChannelState get_ready_state() const override; + virtual String get_label() const override; + virtual bool is_ordered() const override; + virtual int get_id() const override; + virtual int get_max_packet_life_time() const override; + virtual int get_max_retransmits() const override; + virtual String get_protocol() const override; + virtual bool is_negotiated() const override; + + virtual Error poll() override; + virtual void close() override; /** Inherited from PacketPeer: **/ - virtual int get_available_packet_count() const; - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size); ///< buffer is GONE after next get_packet - virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size); + virtual int get_available_packet_count() const override; + virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; ///< buffer is GONE after next get_packet + virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; - virtual int get_max_packet_size() const; + virtual int get_max_packet_size() const override; WebRTCDataChannelJS(); WebRTCDataChannelJS(int js_id); diff --git a/modules/webrtc/webrtc_multiplayer.cpp b/modules/webrtc/webrtc_multiplayer.cpp index 78a4d1e61a..e0c0cad68c 100644 --- a/modules/webrtc/webrtc_multiplayer.cpp +++ b/modules/webrtc/webrtc_multiplayer.cpp @@ -65,8 +65,9 @@ bool WebRTCMultiplayer::is_server() const { } void WebRTCMultiplayer::poll() { - if (peer_map.size() == 0) + if (peer_map.size() == 0) { return; + } List<int> remove; List<int> add; @@ -113,15 +114,17 @@ void WebRTCMultiplayer::poll() { // Remove disconnected peers for (List<int>::Element *E = remove.front(); E; E = E->next()) { remove_peer(E->get()); - if (next_packet_peer == E->get()) + if (next_packet_peer == E->get()) { next_packet_peer = 0; + } } // Signal newly connected peers for (List<int>::Element *E = add.front(); E; E = E->next()) { // Already connected to server: simply notify new peer. // NOTE: Mesh is always connected. - if (connection_status == CONNECTION_CONNECTED) + if (connection_status == CONNECTION_CONNECTED) { emit_signal("peer_connected", E->get()); + } // Server emulation mode suppresses peer_conencted until server connects. if (server_compat && E->get() == TARGET_PEER_SERVER) { @@ -131,20 +134,24 @@ void WebRTCMultiplayer::poll() { emit_signal("connection_succeeded"); // Notify of all previously connected peers for (Map<int, Ref<ConnectedPeer>>::Element *F = peer_map.front(); F; F = F->next()) { - if (F->key() != 1 && F->get()->connected) + if (F->key() != 1 && F->get()->connected) { emit_signal("peer_connected", F->key()); + } } break; // Because we already notified of all newly added peers. } } // Fetch next packet - if (next_packet_peer == 0) + if (next_packet_peer == 0) { _find_next_peer(); + } } void WebRTCMultiplayer::_find_next_peer() { Map<int, Ref<ConnectedPeer>>::Element *E = peer_map.find(next_packet_peer); - if (E) E = E->next(); + if (E) { + E = E->next(); + } // After last. while (E) { for (List<Ref<WebRTCDataChannel>>::Element *F = E->get()->channels.front(); F; F = F->next()) { @@ -164,8 +171,9 @@ void WebRTCMultiplayer::_find_next_peer() { return; } } - if (E->key() == (int)next_packet_peer) + if (E->key() == (int)next_packet_peer) { break; + } E = E->next(); } // No packet found @@ -190,10 +198,11 @@ Error WebRTCMultiplayer::initialize(int p_self_id, bool p_server_compat) { server_compat = p_server_compat; // Mesh and server are always connected - if (!server_compat || p_self_id == 1) + if (!server_compat || p_self_id == 1) { connection_status = CONNECTION_CONNECTED; - else + } else { connection_status = CONNECTION_CONNECTING; + } return OK; } @@ -319,7 +328,6 @@ Error WebRTCMultiplayer::put_packet(const uint8_t *p_buffer, int p_buffer_size) Map<int, Ref<ConnectedPeer>>::Element *E = nullptr; if (target_peer > 0) { - E = peer_map.find(target_peer); ERR_FAIL_COND_V_MSG(!E, ERR_INVALID_PARAMETER, "Invalid target peer: " + itos(target_peer) + "."); @@ -331,10 +339,10 @@ Error WebRTCMultiplayer::put_packet(const uint8_t *p_buffer, int p_buffer_size) int exclude = -target_peer; for (Map<int, Ref<ConnectedPeer>>::Element *F = peer_map.front(); F; F = F->next()) { - // Exclude packet. If target_peer == 0 then don't exclude any packets - if (target_peer != 0 && F->key() == exclude) + if (target_peer != 0 && F->key() == exclude) { continue; + } ERR_CONTINUE(F->value()->channels.size() <= ch || !F->value()->channels[ch].is_valid()); F->value()->channels[ch]->put_packet(p_buffer, p_buffer_size); @@ -344,8 +352,9 @@ Error WebRTCMultiplayer::put_packet(const uint8_t *p_buffer, int p_buffer_size) } int WebRTCMultiplayer::get_available_packet_count() const { - if (next_packet_peer == 0) + if (next_packet_peer == 0) { return 0; // To be sure next call to get_packet works if size > 0 . + } int size = 0; for (Map<int, Ref<ConnectedPeer>>::Element *E = peer_map.front(); E; E = E->next()) { for (List<Ref<WebRTCDataChannel>>::Element *F = E->get()->channels.front(); F; F = F->next()) { diff --git a/modules/webrtc/webrtc_multiplayer.h b/modules/webrtc/webrtc_multiplayer.h index 0e1335b8a8..bfdcf6daa1 100644 --- a/modules/webrtc/webrtc_multiplayer.h +++ b/modules/webrtc/webrtc_multiplayer.h @@ -35,7 +35,6 @@ #include "webrtc_peer_connection.h" class WebRTCMultiplayer : public NetworkedMultiplayerPeer { - GDCLASS(WebRTCMultiplayer, NetworkedMultiplayerPeer); protected: @@ -50,7 +49,6 @@ private: }; class ConnectedPeer : public Reference { - public: Ref<WebRTCPeerConnection> connection; List<Ref<WebRTCDataChannel>> channels; @@ -58,8 +56,9 @@ private: ConnectedPeer() { connected = false; - for (int i = 0; i < CH_RESERVED_MAX; i++) + for (int i = 0; i < CH_RESERVED_MAX; i++) { channels.push_front(Ref<WebRTCDataChannel>()); + } } }; @@ -90,27 +89,27 @@ public: void close(); // PacketPeer - Error get_packet(const uint8_t **r_buffer, int &r_buffer_size); ///< buffer is GONE after next get_packet - Error put_packet(const uint8_t *p_buffer, int p_buffer_size); - int get_available_packet_count() const; - int get_max_packet_size() const; + Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; ///< buffer is GONE after next get_packet + Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; + int get_available_packet_count() const override; + int get_max_packet_size() const override; // NetworkedMultiplayerPeer - void set_transfer_mode(TransferMode p_mode); - TransferMode get_transfer_mode() const; - void set_target_peer(int p_peer_id); + void set_transfer_mode(TransferMode p_mode) override; + TransferMode get_transfer_mode() const override; + void set_target_peer(int p_peer_id) override; - int get_unique_id() const; - int get_packet_peer() const; + int get_unique_id() const override; + int get_packet_peer() const override; - bool is_server() const; + bool is_server() const override; - void poll(); + void poll() override; - void set_refuse_new_connections(bool p_enable); - bool is_refusing_new_connections() const; + void set_refuse_new_connections(bool p_enable) override; + bool is_refusing_new_connections() const override; - ConnectionStatus get_connection_status() const; + ConnectionStatus get_connection_status() const override; }; #endif diff --git a/modules/webrtc/webrtc_peer_connection.cpp b/modules/webrtc/webrtc_peer_connection.cpp index 399e4f09ff..670924bca2 100644 --- a/modules/webrtc/webrtc_peer_connection.cpp +++ b/modules/webrtc/webrtc_peer_connection.cpp @@ -33,14 +33,13 @@ WebRTCPeerConnection *(*WebRTCPeerConnection::_create)() = nullptr; Ref<WebRTCPeerConnection> WebRTCPeerConnection::create_ref() { - return create(); } WebRTCPeerConnection *WebRTCPeerConnection::create() { - - if (!_create) + if (!_create) { return nullptr; + } return _create(); } diff --git a/modules/webrtc/webrtc_peer_connection_gdnative.cpp b/modules/webrtc/webrtc_peer_connection_gdnative.cpp index f082646629..aaa45d3a54 100644 --- a/modules/webrtc/webrtc_peer_connection_gdnative.cpp +++ b/modules/webrtc/webrtc_peer_connection_gdnative.cpp @@ -49,7 +49,6 @@ Error WebRTCPeerConnectionGDNative::set_default_library(const godot_net_webrtc_l } WebRTCPeerConnection *WebRTCPeerConnectionGDNative::_create() { - WebRTCPeerConnectionGDNative *obj = memnew(WebRTCPeerConnectionGDNative); ERR_FAIL_COND_V_MSG(!default_library, obj, "Default GDNative WebRTC implementation not defined."); diff --git a/modules/webrtc/webrtc_peer_connection_gdnative.h b/modules/webrtc/webrtc_peer_connection_gdnative.h index 8e59ad62ba..74b7db1307 100644 --- a/modules/webrtc/webrtc_peer_connection_gdnative.h +++ b/modules/webrtc/webrtc_peer_connection_gdnative.h @@ -53,16 +53,16 @@ public: void set_native_webrtc_peer_connection(const godot_net_webrtc_peer_connection *p_impl); - virtual ConnectionState get_connection_state() const; + virtual ConnectionState get_connection_state() const override; - virtual Error initialize(Dictionary p_config = Dictionary()); - virtual Ref<WebRTCDataChannel> create_data_channel(String p_label, Dictionary p_options = 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 p_config = Dictionary()) override; + virtual Ref<WebRTCDataChannel> create_data_channel(String p_label, Dictionary p_options = 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; WebRTCPeerConnectionGDNative(); ~WebRTCPeerConnectionGDNative(); diff --git a/modules/webrtc/webrtc_peer_connection_js.h b/modules/webrtc/webrtc_peer_connection_js.h index 6540077e84..cdaf3068e3 100644 --- a/modules/webrtc/webrtc_peer_connection_js.h +++ b/modules/webrtc/webrtc_peer_connection_js.h @@ -36,7 +36,6 @@ #include "webrtc_peer_connection.h" class WebRTCPeerConnectionJS : public WebRTCPeerConnection { - private: int _js_id; ConnectionState _conn_state; |