summaryrefslogtreecommitdiff
path: root/modules/webrtc
diff options
context:
space:
mode:
Diffstat (limited to 'modules/webrtc')
-rw-r--r--modules/webrtc/doc_classes/WebRTCDataChannel.xml7
-rw-r--r--modules/webrtc/library_godot_webrtc.js13
-rw-r--r--modules/webrtc/webrtc_data_channel.cpp1
-rw-r--r--modules/webrtc/webrtc_data_channel.h2
-rw-r--r--modules/webrtc/webrtc_data_channel_gdnative.cpp5
-rw-r--r--modules/webrtc/webrtc_data_channel_gdnative.h1
-rw-r--r--modules/webrtc/webrtc_data_channel_js.cpp5
-rw-r--r--modules/webrtc/webrtc_data_channel_js.h1
-rw-r--r--modules/webrtc/webrtc_multiplayer_peer.cpp12
-rw-r--r--modules/webrtc/webrtc_peer_connection_js.cpp6
10 files changed, 40 insertions, 13 deletions
diff --git a/modules/webrtc/doc_classes/WebRTCDataChannel.xml b/modules/webrtc/doc_classes/WebRTCDataChannel.xml
index 5c90038b9a..3435dda982 100644
--- a/modules/webrtc/doc_classes/WebRTCDataChannel.xml
+++ b/modules/webrtc/doc_classes/WebRTCDataChannel.xml
@@ -14,6 +14,13 @@
Closes this data channel, notifying the other peer.
</description>
</method>
+ <method name="get_buffered_amount" qualifiers="const">
+ <return type="int">
+ </return>
+ <description>
+ Returns the number of bytes currently queued to be sent over this channel.
+ </description>
+ </method>
<method name="get_id" qualifiers="const">
<return type="int">
</return>
diff --git a/modules/webrtc/library_godot_webrtc.js b/modules/webrtc/library_godot_webrtc.js
index 404a116716..a0a6c21be3 100644
--- a/modules/webrtc/library_godot_webrtc.js
+++ b/modules/webrtc/library_godot_webrtc.js
@@ -133,12 +133,12 @@ const GodotRTCDataChannel = {
godot_js_rtc_datachannel_is_ordered__sig: 'ii',
godot_js_rtc_datachannel_is_ordered: function (p_id) {
- return IDHandler.get_prop(p_id, 'ordered', true);
+ return GodotRTCDataChannel.get_prop(p_id, 'ordered', true);
},
godot_js_rtc_datachannel_id_get__sig: 'ii',
godot_js_rtc_datachannel_id_get: function (p_id) {
- return IDHandler.get_prop(p_id, 'id', 65535);
+ return GodotRTCDataChannel.get_prop(p_id, 'id', 65535);
},
godot_js_rtc_datachannel_max_packet_lifetime_get__sig: 'ii',
@@ -158,12 +158,17 @@ const GodotRTCDataChannel = {
godot_js_rtc_datachannel_max_retransmits_get__sig: 'ii',
godot_js_rtc_datachannel_max_retransmits_get: function (p_id) {
- return IDHandler.get_prop(p_id, 'maxRetransmits', 65535);
+ return GodotRTCDataChannel.get_prop(p_id, 'maxRetransmits', 65535);
},
godot_js_rtc_datachannel_is_negotiated__sig: 'ii',
godot_js_rtc_datachannel_is_negotiated: function (p_id) {
- return IDHandler.get_prop(p_id, 'negotiated', 65535);
+ return GodotRTCDataChannel.get_prop(p_id, 'negotiated', 65535);
+ },
+
+ godot_js_rtc_datachannel_get_buffered_amount__sig: 'ii',
+ godot_js_rtc_datachannel_get_buffered_amount: function (p_id) {
+ return GodotRTCDataChannel.get_prop(p_id, 'bufferedAmount', 0);
},
godot_js_rtc_datachannel_label_get__sig: 'ii',
diff --git a/modules/webrtc/webrtc_data_channel.cpp b/modules/webrtc/webrtc_data_channel.cpp
index 004112f992..ca520a733d 100644
--- a/modules/webrtc/webrtc_data_channel.cpp
+++ b/modules/webrtc/webrtc_data_channel.cpp
@@ -46,6 +46,7 @@ void WebRTCDataChannel::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_max_retransmits"), &WebRTCDataChannel::get_max_retransmits);
ClassDB::bind_method(D_METHOD("get_protocol"), &WebRTCDataChannel::get_protocol);
ClassDB::bind_method(D_METHOD("is_negotiated"), &WebRTCDataChannel::is_negotiated);
+ ClassDB::bind_method(D_METHOD("get_buffered_amount"), &WebRTCDataChannel::get_buffered_amount);
ADD_PROPERTY(PropertyInfo(Variant::INT, "write_mode", PROPERTY_HINT_ENUM), "set_write_mode", "get_write_mode");
diff --git a/modules/webrtc/webrtc_data_channel.h b/modules/webrtc/webrtc_data_channel.h
index 20affc513f..809d35c6e3 100644
--- a/modules/webrtc/webrtc_data_channel.h
+++ b/modules/webrtc/webrtc_data_channel.h
@@ -70,6 +70,8 @@ public:
virtual String get_protocol() const = 0;
virtual bool is_negotiated() const = 0;
+ virtual int get_buffered_amount() const = 0;
+
virtual Error poll() = 0;
virtual void close() = 0;
diff --git a/modules/webrtc/webrtc_data_channel_gdnative.cpp b/modules/webrtc/webrtc_data_channel_gdnative.cpp
index f3009dde2f..10a3367557 100644
--- a/modules/webrtc/webrtc_data_channel_gdnative.cpp
+++ b/modules/webrtc/webrtc_data_channel_gdnative.cpp
@@ -111,6 +111,11 @@ bool WebRTCDataChannelGDNative::is_negotiated() const {
return interface->is_negotiated(interface->data);
}
+int WebRTCDataChannelGDNative::get_buffered_amount() const {
+ ERR_FAIL_COND_V(interface == NULL, 0);
+ return interface->get_buffered_amount(interface->data);
+}
+
Error WebRTCDataChannelGDNative::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED);
return (Error)interface->get_packet(interface->data, r_buffer, &r_buffer_size);
diff --git a/modules/webrtc/webrtc_data_channel_gdnative.h b/modules/webrtc/webrtc_data_channel_gdnative.h
index 7e02a32046..5c80edd48c 100644
--- a/modules/webrtc/webrtc_data_channel_gdnative.h
+++ b/modules/webrtc/webrtc_data_channel_gdnative.h
@@ -60,6 +60,7 @@ public:
virtual int get_max_retransmits() const override;
virtual String get_protocol() const override;
virtual bool is_negotiated() const override;
+ virtual int get_buffered_amount() const override;
virtual Error poll() override;
virtual void close() override;
diff --git a/modules/webrtc/webrtc_data_channel_js.cpp b/modules/webrtc/webrtc_data_channel_js.cpp
index dfbec80c86..31d6a0568c 100644
--- a/modules/webrtc/webrtc_data_channel_js.cpp
+++ b/modules/webrtc/webrtc_data_channel_js.cpp
@@ -46,6 +46,7 @@ extern int godot_js_rtc_datachannel_id_get(int p_id);
extern int godot_js_rtc_datachannel_max_packet_lifetime_get(int p_id);
extern int godot_js_rtc_datachannel_max_retransmits_get(int p_id);
extern int godot_js_rtc_datachannel_is_negotiated(int p_id);
+extern int godot_js_rtc_datachannel_get_buffered_amount(int p_id);
extern char *godot_js_rtc_datachannel_label_get(int p_id); // Must free the returned string.
extern char *godot_js_rtc_datachannel_protocol_get(int p_id); // Must free the returned string.
extern void godot_js_rtc_datachannel_destroy(int p_id);
@@ -181,6 +182,10 @@ bool WebRTCDataChannelJS::is_negotiated() const {
return godot_js_rtc_datachannel_is_negotiated(_js_id);
}
+int WebRTCDataChannelJS::get_buffered_amount() const {
+ return godot_js_rtc_datachannel_get_buffered_amount(_js_id);
+}
+
WebRTCDataChannelJS::WebRTCDataChannelJS() {
}
diff --git a/modules/webrtc/webrtc_data_channel_js.h b/modules/webrtc/webrtc_data_channel_js.h
index db58ebccff..5cd6a32ed9 100644
--- a/modules/webrtc/webrtc_data_channel_js.h
+++ b/modules/webrtc/webrtc_data_channel_js.h
@@ -72,6 +72,7 @@ public:
virtual int get_max_retransmits() const override;
virtual String get_protocol() const override;
virtual bool is_negotiated() const override;
+ virtual int get_buffered_amount() const override;
virtual Error poll() override;
virtual void close() override;
diff --git a/modules/webrtc/webrtc_multiplayer_peer.cpp b/modules/webrtc/webrtc_multiplayer_peer.cpp
index ac75f9e860..51101e3124 100644
--- a/modules/webrtc/webrtc_multiplayer_peer.cpp
+++ b/modules/webrtc/webrtc_multiplayer_peer.cpp
@@ -123,19 +123,19 @@ void WebRTCMultiplayerPeer::poll() {
// Already connected to server: simply notify new peer.
// NOTE: Mesh is always connected.
if (connection_status == CONNECTION_CONNECTED) {
- emit_signal("peer_connected", E->get());
+ emit_signal(SNAME("peer_connected"), E->get());
}
// Server emulation mode suppresses peer_conencted until server connects.
if (server_compat && E->get() == TARGET_PEER_SERVER) {
// Server connected.
connection_status = CONNECTION_CONNECTED;
- emit_signal("peer_connected", TARGET_PEER_SERVER);
- emit_signal("connection_succeeded");
+ emit_signal(SNAME("peer_connected"), TARGET_PEER_SERVER);
+ emit_signal(SNAME("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) {
- emit_signal("peer_connected", F->key());
+ emit_signal(SNAME("peer_connected"), F->key());
}
}
break; // Because we already notified of all newly added peers.
@@ -283,9 +283,9 @@ void WebRTCMultiplayerPeer::remove_peer(int p_peer_id) {
peer_map.erase(p_peer_id);
if (peer->connected) {
peer->connected = false;
- emit_signal("peer_disconnected", p_peer_id);
+ emit_signal(SNAME("peer_disconnected"), p_peer_id);
if (server_compat && p_peer_id == TARGET_PEER_SERVER) {
- emit_signal("server_disconnected");
+ emit_signal(SNAME("server_disconnected"));
connection_status = CONNECTION_DISCONNECTED;
}
}
diff --git a/modules/webrtc/webrtc_peer_connection_js.cpp b/modules/webrtc/webrtc_peer_connection_js.cpp
index 2b63e76358..ed3459d5f8 100644
--- a/modules/webrtc/webrtc_peer_connection_js.cpp
+++ b/modules/webrtc/webrtc_peer_connection_js.cpp
@@ -38,12 +38,12 @@
void WebRTCPeerConnectionJS::_on_ice_candidate(void *p_obj, const char *p_mid_name, int p_mline_idx, const char *p_candidate) {
WebRTCPeerConnectionJS *peer = static_cast<WebRTCPeerConnectionJS *>(p_obj);
- peer->emit_signal("ice_candidate_created", String(p_mid_name), p_mline_idx, String(p_candidate));
+ peer->emit_signal(SNAME("ice_candidate_created"), String(p_mid_name), p_mline_idx, String(p_candidate));
}
void WebRTCPeerConnectionJS::_on_session_created(void *p_obj, const char *p_type, const char *p_session) {
WebRTCPeerConnectionJS *peer = static_cast<WebRTCPeerConnectionJS *>(p_obj);
- peer->emit_signal("session_description_created", String(p_type), String(p_session));
+ peer->emit_signal(SNAME("session_description_created"), String(p_type), String(p_session));
}
void WebRTCPeerConnectionJS::_on_connection_state_changed(void *p_obj, int p_state) {
@@ -57,7 +57,7 @@ void WebRTCPeerConnectionJS::_on_error(void *p_obj) {
void WebRTCPeerConnectionJS::_on_data_channel(void *p_obj, int p_id) {
WebRTCPeerConnectionJS *peer = static_cast<WebRTCPeerConnectionJS *>(p_obj);
- peer->emit_signal("data_channel_received", Ref<WebRTCDataChannelJS>(new WebRTCDataChannelJS(p_id)));
+ peer->emit_signal(SNAME("data_channel_received"), Ref<WebRTCDataChannelJS>(new WebRTCDataChannelJS(p_id)));
}
void WebRTCPeerConnectionJS::close() {