summaryrefslogtreecommitdiff
path: root/modules/webrtc
diff options
context:
space:
mode:
Diffstat (limited to 'modules/webrtc')
-rw-r--r--modules/webrtc/doc_classes/WebRTCPeerConnection.xml2
-rw-r--r--modules/webrtc/webrtc_data_channel_js.cpp7
-rw-r--r--modules/webrtc/webrtc_multiplayer.cpp35
-rw-r--r--modules/webrtc/webrtc_multiplayer.h5
-rw-r--r--modules/webrtc/webrtc_peer_connection.cpp5
-rw-r--r--modules/webrtc/webrtc_peer_connection_gdnative.cpp1
-rw-r--r--modules/webrtc/webrtc_peer_connection_js.h1
7 files changed, 30 insertions, 26 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_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_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..906b90a1b6 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>());
+ }
}
};
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_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;