Skip to content

Commit 8c18112

Browse files
authored
Merge pull request #43 from dsnopek/buffered-amount
Add get_buffered_amount() to WebRTCDataChannel (GDNative)
2 parents c37cc53 + 3bdf6cd commit 8c18112

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

src/WebRTCLibDataChannel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ bool WebRTCLibDataChannel::is_negotiated() const {
144144
return channel->negotiated();
145145
}
146146

147+
int WebRTCLibDataChannel::get_buffered_amount() const {
148+
ERR_FAIL_COND_V(channel.get() == nullptr, 0);
149+
return channel->buffered_amount();
150+
}
151+
147152
godot_error WebRTCLibDataChannel::poll() {
148153
return GODOT_OK;
149154
}

src/WebRTCLibDataChannel.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class WebRTCLibDataChannel : public WebRTCDataChannelNative {
8787
int get_max_retransmits() const;
8888
const char *get_protocol() const;
8989
bool is_negotiated() const;
90+
int get_buffered_amount() const;
9091

9192
godot_error poll();
9293
void close();

src/net/WebRTCDataChannelNative.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ bool is_negotiated_wdc(const void *user) {
113113
return ((WebRTCDataChannelNative *)user)->is_negotiated();
114114
}
115115

116+
int get_buffered_amount_wdc(const void *user) {
117+
return ((WebRTCDataChannelNative *)user)->get_buffered_amount();
118+
}
119+
116120
godot_error poll_wdc(void *user) {
117121
return ((WebRTCDataChannelNative *)user)->poll();
118122
}

src/net/WebRTCDataChannelNative.hpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,30 @@ int get_max_packet_life_time_wdc(const void *);
5454
int get_max_retransmits_wdc(const void *);
5555
const char *get_protocol_wdc(const void *);
5656
bool is_negotiated_wdc(const void *);
57+
int get_buffered_amount_wdc(const void *);
5758
godot_error poll_wdc(void *);
5859
void close_wdc(void *);
5960

61+
#if GODOT_NET_WEBRTC_API_MAJOR == 3 && GODOT_NET_WEBRTC_API_MINOR < 4
62+
extern "C" {
63+
/* Extensions to WebRTCDataChannel */
64+
typedef struct {
65+
int (*get_buffered_amount)(const void *);
66+
67+
void *next; /* For extension? */
68+
} godot_net_webrtc_data_channel_ext;
69+
}
70+
#endif
71+
6072
class WebRTCDataChannelNative : public godot::WebRTCDataChannelGDNative {
6173
GODOT_CLASS(WebRTCDataChannelNative, godot::WebRTCDataChannelGDNative);
6274

6375
protected:
76+
godot_net_webrtc_data_channel_ext interface_ext = {
77+
&get_buffered_amount_wdc,
78+
NULL,
79+
};
80+
6481
godot_net_webrtc_data_channel interface = {
6582
{ 3, 1 },
6683
this,
@@ -84,7 +101,7 @@ class WebRTCDataChannelNative : public godot::WebRTCDataChannelGDNative {
84101

85102
&poll_wdc,
86103
&close_wdc,
87-
NULL,
104+
&interface_ext,
88105
};
89106

90107
public:
@@ -105,6 +122,7 @@ class WebRTCDataChannelNative : public godot::WebRTCDataChannelGDNative {
105122
virtual int get_max_retransmits() const = 0;
106123
virtual const char *get_protocol() const = 0;
107124
virtual bool is_negotiated() const = 0;
125+
virtual int get_buffered_amount() const = 0;
108126

109127
virtual godot_error poll() = 0;
110128
virtual void close() = 0;

0 commit comments

Comments
 (0)