Add get_buffered_amount() to WebRTCDataChannel

This commit is contained in:
David Snopek 2021-07-20 11:44:40 -05:00
parent bb037de95c
commit abb45f5fe7
9 changed files with 28 additions and 0 deletions

View file

@ -101,6 +101,7 @@ typedef struct {
int (*get_max_retransmits)(const void *);
const char *(*get_protocol)(const void *);
bool (*is_negotiated)(const void *);
int (*get_buffered_amount)(const void *);
godot_error (*poll)(void *);
void (*close)(void *);

View file

@ -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>

View file

@ -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);

View file

@ -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");

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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() {
}

View file

@ -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;