Add get_buffered_amount() to WebRTCDataChannel

This commit is contained in:
David Snopek
2021-07-20 11:54:25 -05:00
parent 072ba5c1d0
commit 3bdf6cdc13
4 changed files with 29 additions and 1 deletions

View File

@@ -144,6 +144,11 @@ bool WebRTCLibDataChannel::is_negotiated() const {
return channel->negotiated();
}
int WebRTCLibDataChannel::get_buffered_amount() const {
ERR_FAIL_COND_V(channel.get() == nullptr, 0);
return channel->buffered_amount();
}
godot_error WebRTCLibDataChannel::poll() {
return GODOT_OK;
}

View File

@@ -87,6 +87,7 @@ public:
int get_max_retransmits() const;
const char *get_protocol() const;
bool is_negotiated() const;
int get_buffered_amount() const;
godot_error poll();
void close();

View File

@@ -113,6 +113,10 @@ bool is_negotiated_wdc(const void *user) {
return ((WebRTCDataChannelNative *)user)->is_negotiated();
}
int get_buffered_amount_wdc(const void *user) {
return ((WebRTCDataChannelNative *)user)->get_buffered_amount();
}
godot_error poll_wdc(void *user) {
return ((WebRTCDataChannelNative *)user)->poll();
}

View File

@@ -54,13 +54,30 @@ int get_max_packet_life_time_wdc(const void *);
int get_max_retransmits_wdc(const void *);
const char *get_protocol_wdc(const void *);
bool is_negotiated_wdc(const void *);
int get_buffered_amount_wdc(const void *);
godot_error poll_wdc(void *);
void close_wdc(void *);
#if GODOT_NET_WEBRTC_API_MAJOR == 3 && GODOT_NET_WEBRTC_API_MINOR < 4
extern "C" {
/* Extensions to WebRTCDataChannel */
typedef struct {
int (*get_buffered_amount)(const void *);
void *next; /* For extension? */
} godot_net_webrtc_data_channel_ext;
}
#endif
class WebRTCDataChannelNative : public godot::WebRTCDataChannelGDNative {
GODOT_CLASS(WebRTCDataChannelNative, godot::WebRTCDataChannelGDNative);
protected:
godot_net_webrtc_data_channel_ext interface_ext = {
&get_buffered_amount_wdc,
NULL,
};
godot_net_webrtc_data_channel interface = {
{ 3, 1 },
this,
@@ -84,7 +101,7 @@ protected:
&poll_wdc,
&close_wdc,
NULL,
&interface_ext,
};
public:
@@ -105,6 +122,7 @@ public:
virtual int get_max_retransmits() const = 0;
virtual const char *get_protocol() const = 0;
virtual bool is_negotiated() const = 0;
virtual int get_buffered_amount() const = 0;
virtual godot_error poll() = 0;
virtual void close() = 0;