diff --git a/modules/gdnative/include/net/godot_webrtc.h b/modules/gdnative/include/net/godot_webrtc.h index 25aa72dae1..f95f33e862 100644 --- a/modules/gdnative/include/net/godot_webrtc.h +++ b/modules/gdnative/include/net/godot_webrtc.h @@ -108,6 +108,13 @@ typedef struct { void *next; /* For extension? */ } godot_net_webrtc_data_channel; +/* Extensions to WebRTCDataChannel */ +typedef struct { + int (*get_buffered_amount)(const void *); + + void *next; /* For extension? */ +} godot_net_webrtc_data_channel_ext; + /* Set the default GDNative library */ godot_error GDAPI godot_net_set_webrtc_library(const godot_net_webrtc_library *); /* Binds a WebRTCPeerConnectionGDNative to the provided interface */ diff --git a/modules/webrtc/doc_classes/WebRTCDataChannel.xml b/modules/webrtc/doc_classes/WebRTCDataChannel.xml index e67296d87f..911eb68ac6 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. + + + + + Returns the number of bytes currently queued to be sent over this channel. + + diff --git a/modules/webrtc/library_godot_webrtc.js b/modules/webrtc/library_godot_webrtc.js index 5269117686..a0a6c21be3 100644 --- a/modules/webrtc/library_godot_webrtc.js +++ b/modules/webrtc/library_godot_webrtc.js @@ -166,6 +166,11 @@ const GodotRTCDataChannel = { 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', godot_js_rtc_datachannel_label_get: function (p_id) { const ref = IDHandler.get(p_id); diff --git a/modules/webrtc/webrtc_data_channel.cpp b/modules/webrtc/webrtc_data_channel.cpp index e4b46f4ebc..ab0754821b 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 47ff1007f1..d351a15c6f 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 d4cf464c7c..f4cd8df642 100644 --- a/modules/webrtc/webrtc_data_channel_gdnative.cpp +++ b/modules/webrtc/webrtc_data_channel_gdnative.cpp @@ -110,6 +110,13 @@ bool WebRTCDataChannelGDNative::is_negotiated() const { return interface->is_negotiated(interface->data); } +int WebRTCDataChannelGDNative::get_buffered_amount() const { + ERR_FAIL_COND_V(interface == nullptr, 0); + ERR_FAIL_COND_V(interface->next == nullptr, 0); + + return ((godot_net_webrtc_data_channel_ext *)interface->next)->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 e166c53d02..2320d764a2 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; virtual String get_protocol() const; virtual bool is_negotiated() const; + virtual int get_buffered_amount() const; virtual Error poll(); virtual void close(); diff --git a/modules/webrtc/webrtc_data_channel_js.cpp b/modules/webrtc/webrtc_data_channel_js.cpp index 9f2b084cb1..9dd01617c0 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() { queue_count = 0; _was_string = false; diff --git a/modules/webrtc/webrtc_data_channel_js.h b/modules/webrtc/webrtc_data_channel_js.h index 6a78ea13b7..63e68b3c88 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; virtual String get_protocol() const; virtual bool is_negotiated() const; + virtual int get_buffered_amount() const; virtual Error poll(); virtual void close();