mirror of
https://github.com/godotengine/webrtc-native.git
synced 2026-01-03 14:09:58 +03:00
Add initial interface
This commit is contained in:
36
src/WebRTCPeer.cpp
Normal file
36
src/WebRTCPeer.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "WebRTCPeer.hpp"
|
||||
|
||||
godot_error WebRTCPeer::get_packet(const uint8_t **r_buffer, int &r_len) {
|
||||
printf("Get packet");
|
||||
r_len = 0;
|
||||
return GODOT_OK;
|
||||
}
|
||||
|
||||
godot_error WebRTCPeer::put_packet(const uint8_t *p_buffer, int p_len) {
|
||||
printf("Put packet");
|
||||
return GODOT_OK;
|
||||
}
|
||||
|
||||
godot_int WebRTCPeer::get_available_packet_count() const {
|
||||
printf("Get packet count");
|
||||
return 2;
|
||||
}
|
||||
|
||||
godot_int WebRTCPeer::get_max_packet_size() const {
|
||||
printf("Get max packet size");
|
||||
return 1024;
|
||||
}
|
||||
|
||||
void WebRTCPeer::_register_methods() { }
|
||||
|
||||
void WebRTCPeer::_init() {
|
||||
printf("Binding PacketPeer interface");
|
||||
godot_net_bind_webrtc_peer(_owner, &interface);
|
||||
}
|
||||
|
||||
WebRTCPeer::~WebRTCPeer() {
|
||||
if (_owner) {
|
||||
printf("Unbinding PacketPeer interface");
|
||||
godot_net_bind_webrtc_peer(_owner, NULL);
|
||||
}
|
||||
}
|
||||
36
src/WebRTCPeer.hpp
Normal file
36
src/WebRTCPeer.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef MY_PACKET_PEER
|
||||
#define MY_PACKET_PEER
|
||||
|
||||
#include <Godot.hpp>
|
||||
|
||||
#include "net/WebRTCPeerNative.hpp"
|
||||
|
||||
class WebRTCPeer : public WebRTCPeerNative {
|
||||
GODOT_CLASS(WebRTCPeer, WebRTCPeerNative);
|
||||
|
||||
public:
|
||||
static void _register_methods();
|
||||
|
||||
void _init();
|
||||
|
||||
void set_write_mode(godot_int mode);
|
||||
godot_int get_write_mode() const;
|
||||
bool was_string_packet() const;
|
||||
godot_int get_connection_state() const;
|
||||
|
||||
godot_error create_offer();
|
||||
godot_error set_remote_description(godot_string type, godot_string sdp);
|
||||
godot_error set_local_description(godot_string type, godot_string sdp);
|
||||
godot_error add_ice_candidate(godot_string sdpMidName, int sdpMlineIndexName, godot_string sdpName);
|
||||
godot_error poll();
|
||||
|
||||
/* WebRTCPeer */
|
||||
virtual godot_error get_packet(const uint8_t **r_buffer, int &r_len);
|
||||
virtual godot_error put_packet(const uint8_t *p_buffer, int p_len);
|
||||
virtual godot_int get_available_packet_count() const;
|
||||
virtual godot_int get_max_packet_size() const;
|
||||
|
||||
~WebRTCPeer();
|
||||
};
|
||||
|
||||
#endif // MY_PACKET_PEER
|
||||
16
src/init.cpp
Normal file
16
src/init.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "WebRTCPeer.hpp"
|
||||
|
||||
/* Godot export stuff */
|
||||
extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) {
|
||||
godot::Godot::gdnative_init(o);
|
||||
}
|
||||
|
||||
extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *o) {
|
||||
godot::Godot::gdnative_terminate(o);
|
||||
}
|
||||
|
||||
extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) {
|
||||
godot::Godot::nativescript_init(handle);
|
||||
|
||||
godot::register_class<WebRTCPeer>();
|
||||
}
|
||||
72
src/net/WebRTCPeerNative.cpp
Normal file
72
src/net/WebRTCPeerNative.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "WebRTCPeerNative.hpp"
|
||||
|
||||
void WebRTCPeerNative::_register_methods() { }
|
||||
|
||||
void WebRTCPeerNative::_init() {
|
||||
printf("Binding PacketPeer interface");
|
||||
godot_net_bind_webrtc_peer(_owner, &interface);
|
||||
}
|
||||
|
||||
WebRTCPeerNative::~WebRTCPeerNative() {
|
||||
if (_owner) {
|
||||
printf("Unbinding PacketPeer interface");
|
||||
godot_net_bind_webrtc_peer(_owner, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The C interface that implements WebRTCPeer.
|
||||
* In this case it forwards calls to our C++ class, but could be plain C,
|
||||
* and you could use void *user for any kind of state struct pointer you have.
|
||||
*/
|
||||
godot_error get_packet_wp(void *user, const uint8_t **r_buffer, int &r_len) {
|
||||
return ((WebRTCPeerNative *) user)->get_packet(r_buffer, r_len);
|
||||
}
|
||||
|
||||
godot_error put_packet_wp(void *user, const uint8_t *p_buffer, int p_len) {
|
||||
return ((WebRTCPeerNative *) user)->put_packet(p_buffer, p_len);
|
||||
}
|
||||
|
||||
godot_int get_available_packet_count_wp(const void *user) {
|
||||
return ((WebRTCPeerNative *) user)->get_available_packet_count();
|
||||
}
|
||||
|
||||
godot_int get_max_packet_size_wp(const void *user) {
|
||||
return ((WebRTCPeerNative *) user)->get_max_packet_size();
|
||||
}
|
||||
|
||||
void set_write_mode_wp(void *user, godot_int write_mode) {
|
||||
((WebRTCPeerNative *) user)->set_write_mode(write_mode);
|
||||
}
|
||||
|
||||
godot_int get_write_mode_wp(const void *user) {
|
||||
return ((WebRTCPeerNative *) user)->get_write_mode();
|
||||
}
|
||||
|
||||
bool was_string_packet_wp(const void *user) {
|
||||
return ((WebRTCPeerNative *) user)->was_string_packet();
|
||||
}
|
||||
|
||||
godot_int get_connection_state_wp(const void *user) {
|
||||
return ((WebRTCPeerNative *) user)->get_connection_state();
|
||||
}
|
||||
|
||||
godot_error create_offer_wp(void *user) {
|
||||
return ((WebRTCPeerNative *) user)->create_offer();
|
||||
}
|
||||
|
||||
godot_error set_remote_description_wp(void *user, godot_string type, godot_string sdp) {
|
||||
return ((WebRTCPeerNative *) user)->set_remote_description(type, sdp);
|
||||
}
|
||||
|
||||
godot_error set_local_description_wp(void *user, godot_string type, godot_string sdp) {
|
||||
return ((WebRTCPeerNative *) user)->set_local_description(type, sdp);
|
||||
}
|
||||
|
||||
godot_error add_ice_candidate_wp(void *user, godot_string sdpMidName, int sdpMlineIndexName, godot_string sdpName) {
|
||||
return ((WebRTCPeerNative *) user)->add_ice_candidate(sdpMidName, sdpMlineIndexName, sdpName);
|
||||
}
|
||||
|
||||
godot_error poll_wp(void *user) {
|
||||
return ((WebRTCPeerNative *) user)->poll();
|
||||
}
|
||||
66
src/net/WebRTCPeerNative.hpp
Normal file
66
src/net/WebRTCPeerNative.hpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef WEBRTC_PEER_NATIVE
|
||||
#define WEBRTC_PEER_NATIVE
|
||||
|
||||
#include <Godot.hpp>
|
||||
#include <Reference.hpp>
|
||||
#include <WebRTCPeer.hpp>
|
||||
|
||||
#include <net/godot_net.h>
|
||||
|
||||
/* Forward declare interface functions */
|
||||
godot_error get_packet_wp(void *, const uint8_t **, int &);
|
||||
godot_error put_packet_wp(void *, const uint8_t *, int);
|
||||
godot_int get_available_packet_count_wp(const void *);
|
||||
godot_int get_max_packet_size_wp(const void *);
|
||||
|
||||
void set_write_mode_wp(void *, godot_int);
|
||||
godot_int get_write_mode_wp(const void *);
|
||||
bool was_string_packet_wp(const void *);
|
||||
godot_int get_connection_state_wp(const void *);
|
||||
|
||||
godot_error create_offer_wp(void *);
|
||||
godot_error set_remote_description_wp(void *, godot_string, godot_string);
|
||||
godot_error set_local_description_wp(void *, godot_string, godot_string);
|
||||
godot_error add_ice_candidate_wp(void *, godot_string, int, godot_string);
|
||||
godot_error poll_wp(void *);
|
||||
|
||||
class WebRTCPeerNative : public godot::WebRTCPeer {
|
||||
GODOT_CLASS(WebRTCPeerNative, godot::WebRTCPeer);
|
||||
|
||||
protected:
|
||||
godot_net_webrtc_peer interface = {
|
||||
{3, 1},
|
||||
this,
|
||||
&get_packet_wp,
|
||||
&put_packet_wp,
|
||||
&get_available_packet_count_wp,
|
||||
&get_max_packet_size_wp,
|
||||
NULL
|
||||
};
|
||||
|
||||
public:
|
||||
static void _register_methods();
|
||||
|
||||
void _init();
|
||||
|
||||
virtual void set_write_mode(godot_int mode);
|
||||
virtual godot_int get_write_mode() const;
|
||||
virtual bool was_string_packet() const;
|
||||
virtual godot_int get_connection_state() const;
|
||||
|
||||
virtual godot_error create_offer() = 0;
|
||||
virtual godot_error set_remote_description(godot_string type, godot_string sdp) = 0;
|
||||
virtual godot_error set_local_description(godot_string type, godot_string sdp) = 0;
|
||||
virtual godot_error add_ice_candidate(godot_string sdpMidName, int sdpMlineIndexName, godot_string sdpName) = 0;
|
||||
virtual godot_error poll() = 0;
|
||||
|
||||
/* PacketPeer */
|
||||
virtual godot_error get_packet(const uint8_t **r_buffer, int &r_len) = 0;
|
||||
virtual godot_error put_packet(const uint8_t *p_buffer, int p_len) = 0;
|
||||
virtual godot_int get_available_packet_count() const = 0;
|
||||
virtual godot_int get_max_packet_size() const = 0;
|
||||
|
||||
~WebRTCPeerNative();
|
||||
};
|
||||
|
||||
#endif // WEBRTC_PEER_NATIVE
|
||||
2
webrtc/include/.gitignore
vendored
Normal file
2
webrtc/include/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
2
webrtc/lib/.gitignore
vendored
Normal file
2
webrtc/lib/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
Reference in New Issue
Block a user