Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_buffered_amount() to WebRTCDataChannel (GDNative) #43

Merged
merged 1 commit into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/WebRTCLibDataChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/WebRTCLibDataChannel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class WebRTCLibDataChannel : public WebRTCDataChannelNative {
int get_max_retransmits() const;
const char *get_protocol() const;
bool is_negotiated() const;
int get_buffered_amount() const;

godot_error poll();
void close();
Expand Down
4 changes: 4 additions & 0 deletions src/net/WebRTCDataChannelNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
20 changes: 19 additions & 1 deletion src/net/WebRTCDataChannelNative.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -84,7 +101,7 @@ class WebRTCDataChannelNative : public godot::WebRTCDataChannelGDNative {

&poll_wdc,
&close_wdc,
NULL,
&interface_ext,
};

public:
Expand All @@ -105,6 +122,7 @@ class WebRTCDataChannelNative : public godot::WebRTCDataChannelGDNative {
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;
Expand Down