mirror of
https://github.com/godotengine/godot.git
synced 2024-11-22 04:06:14 +00:00
[Net] Expose WebRTC classes to extensions.
This commit is contained in:
parent
25226329be
commit
6cb81543d4
@ -4,11 +4,6 @@ Import("env")
|
||||
Import("env_modules")
|
||||
|
||||
env_webrtc = env_modules.Clone()
|
||||
use_gdnative = env_webrtc["module_gdnative_enabled"]
|
||||
|
||||
if use_gdnative: # GDNative is retained in Javascript for export compatibility
|
||||
env_webrtc.Append(CPPDEFINES=["WEBRTC_GDNATIVE_ENABLED"])
|
||||
env_webrtc.Prepend(CPPPATH=["#modules/gdnative/include/"])
|
||||
|
||||
if env["platform"] == "javascript":
|
||||
# Our JavaScript/C++ interface.
|
||||
|
@ -11,6 +11,8 @@ def get_doc_classes():
|
||||
"WebRTCPeerConnection",
|
||||
"WebRTCDataChannel",
|
||||
"WebRTCMultiplayerPeer",
|
||||
"WebRTCPeerConnectionExtension",
|
||||
"WebRTCDataChannelExtension",
|
||||
]
|
||||
|
||||
|
||||
|
@ -31,17 +31,11 @@
|
||||
#include "register_types.h"
|
||||
#include "core/config/project_settings.h"
|
||||
#include "webrtc_data_channel.h"
|
||||
#include "webrtc_multiplayer_peer.h"
|
||||
#include "webrtc_peer_connection.h"
|
||||
|
||||
#ifdef JAVASCRIPT_ENABLED
|
||||
#include "emscripten.h"
|
||||
#include "webrtc_peer_connection_js.h"
|
||||
#endif
|
||||
#ifdef WEBRTC_GDNATIVE_ENABLED
|
||||
#include "webrtc_data_channel_gdnative.h"
|
||||
#include "webrtc_peer_connection_gdnative.h"
|
||||
#endif
|
||||
#include "webrtc_multiplayer_peer.h"
|
||||
#include "webrtc_data_channel_extension.h"
|
||||
#include "webrtc_peer_connection_extension.h"
|
||||
|
||||
void register_webrtc_types() {
|
||||
#define _SET_HINT(NAME, _VAL_, _MAX_) \
|
||||
@ -50,18 +44,12 @@ void register_webrtc_types() {
|
||||
|
||||
_SET_HINT(WRTC_IN_BUF, 64, 4096);
|
||||
|
||||
#ifdef JAVASCRIPT_ENABLED
|
||||
WebRTCPeerConnectionJS::make_default();
|
||||
#elif defined(WEBRTC_GDNATIVE_ENABLED)
|
||||
WebRTCPeerConnectionGDNative::make_default();
|
||||
#endif
|
||||
|
||||
ClassDB::register_custom_instance_class<WebRTCPeerConnection>();
|
||||
#ifdef WEBRTC_GDNATIVE_ENABLED
|
||||
GDREGISTER_CLASS(WebRTCPeerConnectionGDNative);
|
||||
GDREGISTER_CLASS(WebRTCDataChannelGDNative);
|
||||
#endif
|
||||
GDREGISTER_CLASS(WebRTCPeerConnectionExtension);
|
||||
|
||||
GDREGISTER_VIRTUAL_CLASS(WebRTCDataChannel);
|
||||
GDREGISTER_CLASS(WebRTCDataChannelExtension);
|
||||
|
||||
GDREGISTER_CLASS(WebRTCMultiplayerPeer);
|
||||
}
|
||||
|
||||
|
215
modules/webrtc/webrtc_data_channel_extension.cpp
Normal file
215
modules/webrtc/webrtc_data_channel_extension.cpp
Normal file
@ -0,0 +1,215 @@
|
||||
/*************************************************************************/
|
||||
/* webrtc_data_channel_extension.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "webrtc_data_channel_extension.h"
|
||||
|
||||
void WebRTCDataChannelExtension::_bind_methods() {
|
||||
ADD_PROPERTY_DEFAULT("write_mode", WRITE_MODE_BINARY);
|
||||
|
||||
GDVIRTUAL_BIND(_get_packet, "r_buffer", "r_buffer_size");
|
||||
GDVIRTUAL_BIND(_put_packet, "p_buffer", "p_buffer_size");
|
||||
GDVIRTUAL_BIND(_get_available_packet_count);
|
||||
GDVIRTUAL_BIND(_get_max_packet_size);
|
||||
|
||||
GDVIRTUAL_BIND(_poll);
|
||||
GDVIRTUAL_BIND(_close);
|
||||
|
||||
GDVIRTUAL_BIND(_set_write_mode, "p_write_mode");
|
||||
GDVIRTUAL_BIND(_get_write_mode);
|
||||
|
||||
GDVIRTUAL_BIND(_was_string_packet);
|
||||
GDVIRTUAL_BIND(_get_ready_state);
|
||||
GDVIRTUAL_BIND(_get_label);
|
||||
GDVIRTUAL_BIND(_is_ordered);
|
||||
GDVIRTUAL_BIND(_get_id);
|
||||
GDVIRTUAL_BIND(_get_max_packet_life_time);
|
||||
GDVIRTUAL_BIND(_get_max_retransmits);
|
||||
GDVIRTUAL_BIND(_get_protocol);
|
||||
GDVIRTUAL_BIND(_is_negotiated);
|
||||
GDVIRTUAL_BIND(_get_buffered_amount);
|
||||
}
|
||||
|
||||
int WebRTCDataChannelExtension::get_available_packet_count() const {
|
||||
int count;
|
||||
if (GDVIRTUAL_CALL(_get_available_packet_count, count)) {
|
||||
return count;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_available_packet_count is unimplemented!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
Error WebRTCDataChannelExtension::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
|
||||
int err;
|
||||
if (GDVIRTUAL_CALL(_get_packet, r_buffer, &r_buffer_size, err)) {
|
||||
return (Error)err;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_packet_native is unimplemented!");
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
Error WebRTCDataChannelExtension::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
|
||||
int err;
|
||||
if (GDVIRTUAL_CALL(_put_packet, p_buffer, p_buffer_size, err)) {
|
||||
return (Error)err;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_put_packet_native is unimplemented!");
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
int WebRTCDataChannelExtension::get_max_packet_size() const {
|
||||
int size;
|
||||
if (GDVIRTUAL_CALL(_get_max_packet_size, size)) {
|
||||
return size;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_max_packet_size is unimplemented!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Error WebRTCDataChannelExtension::poll() {
|
||||
int err;
|
||||
if (GDVIRTUAL_CALL(_poll, err)) {
|
||||
return (Error)err;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_poll is unimplemented!");
|
||||
return ERR_UNCONFIGURED;
|
||||
}
|
||||
|
||||
void WebRTCDataChannelExtension::close() {
|
||||
if (GDVIRTUAL_CALL(_close)) {
|
||||
return;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_close is unimplemented!");
|
||||
}
|
||||
|
||||
void WebRTCDataChannelExtension::set_write_mode(WriteMode p_mode) {
|
||||
if (GDVIRTUAL_CALL(_set_write_mode, p_mode)) {
|
||||
return;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_set_write_mode is unimplemented!");
|
||||
}
|
||||
|
||||
WebRTCDataChannel::WriteMode WebRTCDataChannelExtension::get_write_mode() const {
|
||||
int mode;
|
||||
if (GDVIRTUAL_CALL(_get_write_mode, mode)) {
|
||||
return (WriteMode)mode;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_write_mode is unimplemented!");
|
||||
return WRITE_MODE_BINARY;
|
||||
}
|
||||
|
||||
bool WebRTCDataChannelExtension::was_string_packet() const {
|
||||
bool was_string;
|
||||
if (GDVIRTUAL_CALL(_was_string_packet, was_string)) {
|
||||
return was_string;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_was_string_packet is unimplemented!");
|
||||
return false;
|
||||
}
|
||||
|
||||
WebRTCDataChannel::ChannelState WebRTCDataChannelExtension::get_ready_state() const {
|
||||
int state;
|
||||
if (GDVIRTUAL_CALL(_get_ready_state, state)) {
|
||||
return (ChannelState)state;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_ready_state is unimplemented!");
|
||||
return STATE_CLOSED;
|
||||
}
|
||||
|
||||
String WebRTCDataChannelExtension::get_label() const {
|
||||
String label;
|
||||
if (GDVIRTUAL_CALL(_get_label, label)) {
|
||||
return label;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_label is unimplemented!");
|
||||
return label;
|
||||
}
|
||||
|
||||
bool WebRTCDataChannelExtension::is_ordered() const {
|
||||
bool ordered;
|
||||
if (GDVIRTUAL_CALL(_is_ordered, ordered)) {
|
||||
return ordered;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_is_ordered is unimplemented!");
|
||||
return false;
|
||||
}
|
||||
|
||||
int WebRTCDataChannelExtension::get_id() const {
|
||||
int id;
|
||||
if (GDVIRTUAL_CALL(_get_id, id)) {
|
||||
return id;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_id is unimplemented!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int WebRTCDataChannelExtension::get_max_packet_life_time() const {
|
||||
int lifetime;
|
||||
if (GDVIRTUAL_CALL(_get_max_packet_life_time, lifetime)) {
|
||||
return lifetime;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_max_packet_life_time is unimplemented!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int WebRTCDataChannelExtension::get_max_retransmits() const {
|
||||
int retransmits;
|
||||
if (GDVIRTUAL_CALL(_get_max_retransmits, retransmits)) {
|
||||
return retransmits;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_max_retransmits is unimplemented!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
String WebRTCDataChannelExtension::get_protocol() const {
|
||||
String protocol;
|
||||
if (GDVIRTUAL_CALL(_get_protocol, protocol)) {
|
||||
return protocol;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_protocol is unimplemented!");
|
||||
return protocol;
|
||||
}
|
||||
|
||||
bool WebRTCDataChannelExtension::is_negotiated() const {
|
||||
bool negotiated;
|
||||
if (GDVIRTUAL_CALL(_is_negotiated, negotiated)) {
|
||||
return negotiated;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_is_negotiated is unimplemented!");
|
||||
return false;
|
||||
}
|
||||
|
||||
int WebRTCDataChannelExtension::get_buffered_amount() const {
|
||||
int amount;
|
||||
if (GDVIRTUAL_CALL(_get_buffered_amount, amount)) {
|
||||
return amount;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_buffered_amount is unimplemented!");
|
||||
return -1;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*************************************************************************/
|
||||
/* webrtc_data_channel_gdnative.h */
|
||||
/* webrtc_data_channel_extension.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
@ -28,26 +28,22 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef WEBRTC_DATA_CHANNEL_GDNATIVE_H
|
||||
#define WEBRTC_DATA_CHANNEL_GDNATIVE_H
|
||||
#ifndef WEBRTC_DATA_CHANNEL_EXTENSION_H
|
||||
#define WEBRTC_DATA_CHANNEL_EXTENSION_H
|
||||
|
||||
#ifdef WEBRTC_GDNATIVE_ENABLED
|
||||
|
||||
#include "modules/gdnative/include/net/godot_net.h"
|
||||
#include "webrtc_data_channel.h"
|
||||
|
||||
class WebRTCDataChannelGDNative : public WebRTCDataChannel {
|
||||
GDCLASS(WebRTCDataChannelGDNative, WebRTCDataChannel);
|
||||
#include "core/object/gdvirtual.gen.inc"
|
||||
#include "core/object/script_language.h"
|
||||
#include "core/variant/native_ptr.h"
|
||||
|
||||
class WebRTCDataChannelExtension : public WebRTCDataChannel {
|
||||
GDCLASS(WebRTCDataChannelExtension, WebRTCDataChannel);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
const godot_net_webrtc_data_channel *interface;
|
||||
|
||||
public:
|
||||
void set_native_webrtc_data_channel(const godot_net_webrtc_data_channel *p_impl);
|
||||
|
||||
virtual void set_write_mode(WriteMode mode) override;
|
||||
virtual WriteMode get_write_mode() const override;
|
||||
virtual bool was_string_packet() const override;
|
||||
@ -72,10 +68,31 @@ public:
|
||||
|
||||
virtual int get_max_packet_size() const override;
|
||||
|
||||
WebRTCDataChannelGDNative();
|
||||
~WebRTCDataChannelGDNative();
|
||||
/** GDExtension **/
|
||||
GDVIRTUAL0RC(int, _get_available_packet_count);
|
||||
GDVIRTUAL2R(int, _get_packet, GDNativeConstPtr<const uint8_t *>, GDNativePtr<int>);
|
||||
GDVIRTUAL2R(int, _put_packet, GDNativeConstPtr<const uint8_t>, int);
|
||||
GDVIRTUAL0RC(int, _get_max_packet_size);
|
||||
|
||||
GDVIRTUAL0R(int, _poll);
|
||||
GDVIRTUAL0(_close);
|
||||
|
||||
GDVIRTUAL1(_set_write_mode, int);
|
||||
GDVIRTUAL0RC(int, _get_write_mode);
|
||||
|
||||
GDVIRTUAL0RC(bool, _was_string_packet);
|
||||
|
||||
GDVIRTUAL0RC(int, _get_ready_state);
|
||||
GDVIRTUAL0RC(String, _get_label);
|
||||
GDVIRTUAL0RC(bool, _is_ordered);
|
||||
GDVIRTUAL0RC(int, _get_id);
|
||||
GDVIRTUAL0RC(int, _get_max_packet_life_time);
|
||||
GDVIRTUAL0RC(int, _get_max_retransmits);
|
||||
GDVIRTUAL0RC(String, _get_protocol);
|
||||
GDVIRTUAL0RC(bool, _is_negotiated);
|
||||
GDVIRTUAL0RC(int, _get_buffered_amount);
|
||||
|
||||
WebRTCDataChannelExtension() {}
|
||||
};
|
||||
|
||||
#endif // WEBRTC_GDNATIVE_ENABLED
|
||||
|
||||
#endif // WEBRTC_DATA_CHANNEL_GDNATIVE_H
|
||||
#endif // WEBRTC_DATA_CHANNEL_EXTENSION_H
|
@ -1,143 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* webrtc_data_channel_gdnative.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef WEBRTC_GDNATIVE_ENABLED
|
||||
|
||||
#include "webrtc_data_channel_gdnative.h"
|
||||
|
||||
#include "core/io/resource_loader.h"
|
||||
#include "modules/gdnative/nativescript/nativescript.h"
|
||||
|
||||
void WebRTCDataChannelGDNative::_bind_methods() {
|
||||
ADD_PROPERTY_DEFAULT("write_mode", WRITE_MODE_BINARY);
|
||||
}
|
||||
|
||||
WebRTCDataChannelGDNative::WebRTCDataChannelGDNative() {
|
||||
interface = nullptr;
|
||||
}
|
||||
|
||||
WebRTCDataChannelGDNative::~WebRTCDataChannelGDNative() {
|
||||
}
|
||||
|
||||
Error WebRTCDataChannelGDNative::poll() {
|
||||
ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED);
|
||||
return (Error)interface->poll(interface->data);
|
||||
}
|
||||
|
||||
void WebRTCDataChannelGDNative::close() {
|
||||
ERR_FAIL_COND(interface == nullptr);
|
||||
interface->close(interface->data);
|
||||
}
|
||||
|
||||
void WebRTCDataChannelGDNative::set_write_mode(WriteMode p_mode) {
|
||||
ERR_FAIL_COND(interface == nullptr);
|
||||
interface->set_write_mode(interface->data, p_mode);
|
||||
}
|
||||
|
||||
WebRTCDataChannel::WriteMode WebRTCDataChannelGDNative::get_write_mode() const {
|
||||
ERR_FAIL_COND_V(interface == nullptr, WRITE_MODE_BINARY);
|
||||
return (WriteMode)interface->get_write_mode(interface->data);
|
||||
}
|
||||
|
||||
bool WebRTCDataChannelGDNative::was_string_packet() const {
|
||||
ERR_FAIL_COND_V(interface == nullptr, false);
|
||||
return interface->was_string_packet(interface->data);
|
||||
}
|
||||
|
||||
WebRTCDataChannel::ChannelState WebRTCDataChannelGDNative::get_ready_state() const {
|
||||
ERR_FAIL_COND_V(interface == nullptr, STATE_CLOSED);
|
||||
return (ChannelState)interface->get_ready_state(interface->data);
|
||||
}
|
||||
|
||||
String WebRTCDataChannelGDNative::get_label() const {
|
||||
ERR_FAIL_COND_V(interface == nullptr, "");
|
||||
return String(interface->get_label(interface->data));
|
||||
}
|
||||
|
||||
bool WebRTCDataChannelGDNative::is_ordered() const {
|
||||
ERR_FAIL_COND_V(interface == nullptr, false);
|
||||
return interface->is_ordered(interface->data);
|
||||
}
|
||||
|
||||
int WebRTCDataChannelGDNative::get_id() const {
|
||||
ERR_FAIL_COND_V(interface == nullptr, -1);
|
||||
return interface->get_id(interface->data);
|
||||
}
|
||||
|
||||
int WebRTCDataChannelGDNative::get_max_packet_life_time() const {
|
||||
ERR_FAIL_COND_V(interface == nullptr, -1);
|
||||
return interface->get_max_packet_life_time(interface->data);
|
||||
}
|
||||
|
||||
int WebRTCDataChannelGDNative::get_max_retransmits() const {
|
||||
ERR_FAIL_COND_V(interface == nullptr, -1);
|
||||
return interface->get_max_retransmits(interface->data);
|
||||
}
|
||||
|
||||
String WebRTCDataChannelGDNative::get_protocol() const {
|
||||
ERR_FAIL_COND_V(interface == nullptr, "");
|
||||
return String(interface->get_protocol(interface->data));
|
||||
}
|
||||
|
||||
bool WebRTCDataChannelGDNative::is_negotiated() const {
|
||||
ERR_FAIL_COND_V(interface == nullptr, false);
|
||||
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);
|
||||
}
|
||||
|
||||
Error WebRTCDataChannelGDNative::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
|
||||
ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED);
|
||||
return (Error)interface->put_packet(interface->data, p_buffer, p_buffer_size);
|
||||
}
|
||||
|
||||
int WebRTCDataChannelGDNative::get_max_packet_size() const {
|
||||
ERR_FAIL_COND_V(interface == nullptr, 0);
|
||||
return interface->get_max_packet_size(interface->data);
|
||||
}
|
||||
|
||||
int WebRTCDataChannelGDNative::get_available_packet_count() const {
|
||||
ERR_FAIL_COND_V(interface == nullptr, 0);
|
||||
return interface->get_available_packet_count(interface->data);
|
||||
}
|
||||
|
||||
void WebRTCDataChannelGDNative::set_native_webrtc_data_channel(const godot_net_webrtc_data_channel *p_impl) {
|
||||
interface = p_impl;
|
||||
}
|
||||
|
||||
#endif // WEBRTC_GDNATIVE_ENABLED
|
@ -30,17 +30,29 @@
|
||||
|
||||
#include "webrtc_peer_connection.h"
|
||||
|
||||
WebRTCPeerConnection *(*WebRTCPeerConnection::_create)() = nullptr;
|
||||
#ifdef JAVASCRIPT_ENABLED
|
||||
#include "webrtc_peer_connection_js.h"
|
||||
#else
|
||||
#include "webrtc_peer_connection_extension.h"
|
||||
#endif
|
||||
|
||||
Ref<WebRTCPeerConnection> WebRTCPeerConnection::create_ref() {
|
||||
return create();
|
||||
StringName WebRTCPeerConnection::default_extension;
|
||||
|
||||
void WebRTCPeerConnection::set_default_extension(const StringName &p_extension) {
|
||||
default_extension = p_extension;
|
||||
}
|
||||
|
||||
WebRTCPeerConnection *WebRTCPeerConnection::create() {
|
||||
if (!_create) {
|
||||
return nullptr;
|
||||
#ifdef JAVASCRIPT_ENABLED
|
||||
return memnew(WebRTCPeerConnectionJS);
|
||||
#else
|
||||
if (default_extension == String()) {
|
||||
WARN_PRINT_ONCE("No default WebRTC extension configured.");
|
||||
return memnew(WebRTCPeerConnectionExtension);
|
||||
}
|
||||
return _create();
|
||||
Object *obj = ClassDB::instantiate(default_extension);
|
||||
return Object::cast_to<WebRTCPeerConnectionExtension>(obj);
|
||||
#endif
|
||||
}
|
||||
|
||||
void WebRTCPeerConnection::_bind_methods() {
|
||||
|
@ -47,11 +47,15 @@ public:
|
||||
STATE_CLOSED
|
||||
};
|
||||
|
||||
private:
|
||||
static StringName default_extension;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
static WebRTCPeerConnection *(*_create)();
|
||||
|
||||
public:
|
||||
static void set_default_extension(const StringName &p_name);
|
||||
|
||||
virtual ConnectionState get_connection_state() const = 0;
|
||||
|
||||
virtual Error initialize(Dictionary p_config = Dictionary()) = 0;
|
||||
@ -63,7 +67,6 @@ public:
|
||||
virtual Error poll() = 0;
|
||||
virtual void close() = 0;
|
||||
|
||||
static Ref<WebRTCPeerConnection> create_ref();
|
||||
static WebRTCPeerConnection *create();
|
||||
|
||||
WebRTCPeerConnection();
|
||||
|
131
modules/webrtc/webrtc_peer_connection_extension.cpp
Normal file
131
modules/webrtc/webrtc_peer_connection_extension.cpp
Normal file
@ -0,0 +1,131 @@
|
||||
/*************************************************************************/
|
||||
/* webrtc_peer_connection_extension.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "webrtc_peer_connection_extension.h"
|
||||
|
||||
void WebRTCPeerConnectionExtension::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("make_default"), &WebRTCPeerConnectionExtension::make_default);
|
||||
|
||||
GDVIRTUAL_BIND(_get_connection_state);
|
||||
GDVIRTUAL_BIND(_initialize, "p_config");
|
||||
GDVIRTUAL_BIND(_create_data_channel, "p_label", "p_config");
|
||||
GDVIRTUAL_BIND(_create_offer);
|
||||
GDVIRTUAL_BIND(_set_remote_description, "p_type", "p_sdp");
|
||||
GDVIRTUAL_BIND(_set_local_description, "p_type", "p_sdp");
|
||||
GDVIRTUAL_BIND(_add_ice_candidate, "p_sdp_mid_name", "p_sdp_mline_index", "p_sdp_name");
|
||||
GDVIRTUAL_BIND(_poll);
|
||||
GDVIRTUAL_BIND(_close);
|
||||
}
|
||||
|
||||
void WebRTCPeerConnectionExtension::make_default() {
|
||||
ERR_FAIL_COND_MSG(!_get_extension(), vformat("Can't make %s the default without extending it.", get_class()));
|
||||
WebRTCPeerConnection::set_default_extension(get_class());
|
||||
}
|
||||
|
||||
WebRTCPeerConnection::ConnectionState WebRTCPeerConnectionExtension::get_connection_state() const {
|
||||
int state;
|
||||
if (GDVIRTUAL_CALL(_get_connection_state, state)) {
|
||||
return (ConnectionState)state;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_get_connection_state is unimplemented!");
|
||||
return STATE_DISCONNECTED;
|
||||
}
|
||||
|
||||
Error WebRTCPeerConnectionExtension::initialize(Dictionary p_config) {
|
||||
int err;
|
||||
if (GDVIRTUAL_CALL(_initialize, p_config, err)) {
|
||||
return (Error)err;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_initialize is unimplemented!");
|
||||
return ERR_UNCONFIGURED;
|
||||
}
|
||||
|
||||
Ref<WebRTCDataChannel> WebRTCPeerConnectionExtension::create_data_channel(String p_label, Dictionary p_options) {
|
||||
Object *ret = nullptr;
|
||||
if (GDVIRTUAL_CALL(_create_data_channel, p_label, p_options, ret)) {
|
||||
WebRTCDataChannel *ch = Object::cast_to<WebRTCDataChannel>(ret);
|
||||
ERR_FAIL_COND_V_MSG(ret && !ch, nullptr, "Returned object must be an instance of WebRTCDataChannel.");
|
||||
return ch;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_create_data_channel is unimplemented!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Error WebRTCPeerConnectionExtension::create_offer() {
|
||||
int err;
|
||||
if (GDVIRTUAL_CALL(_create_offer, err)) {
|
||||
return (Error)err;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_create_offer is unimplemented!");
|
||||
return ERR_UNCONFIGURED;
|
||||
}
|
||||
|
||||
Error WebRTCPeerConnectionExtension::set_local_description(String p_type, String p_sdp) {
|
||||
int err;
|
||||
if (GDVIRTUAL_CALL(_set_local_description, p_type, p_sdp, err)) {
|
||||
return (Error)err;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_set_local_description is unimplemented!");
|
||||
return ERR_UNCONFIGURED;
|
||||
}
|
||||
|
||||
Error WebRTCPeerConnectionExtension::set_remote_description(String p_type, String p_sdp) {
|
||||
int err;
|
||||
if (GDVIRTUAL_CALL(_set_remote_description, p_type, p_sdp, err)) {
|
||||
return (Error)err;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_set_remote_description is unimplemented!");
|
||||
return ERR_UNCONFIGURED;
|
||||
}
|
||||
|
||||
Error WebRTCPeerConnectionExtension::add_ice_candidate(String p_sdp_mid_name, int p_sdp_mline_index, String p_sdp_name) {
|
||||
int err;
|
||||
if (GDVIRTUAL_CALL(_add_ice_candidate, p_sdp_mid_name, p_sdp_mline_index, p_sdp_name, err)) {
|
||||
return (Error)err;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_add_ice_candidate is unimplemented!");
|
||||
return ERR_UNCONFIGURED;
|
||||
}
|
||||
|
||||
Error WebRTCPeerConnectionExtension::poll() {
|
||||
int err;
|
||||
if (GDVIRTUAL_CALL(_poll, err)) {
|
||||
return (Error)err;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_poll is unimplemented!");
|
||||
return ERR_UNCONFIGURED;
|
||||
}
|
||||
|
||||
void WebRTCPeerConnectionExtension::close() {
|
||||
if (GDVIRTUAL_CALL(_close)) {
|
||||
return;
|
||||
}
|
||||
WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_close is unimplemented!");
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*************************************************************************/
|
||||
/* webrtc_peer_connection_gdnative.h */
|
||||
/* webrtc_peer_connection_extension.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
@ -28,30 +28,23 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef WEBRTC_PEER_CONNECTION_GDNATIVE_H
|
||||
#define WEBRTC_PEER_CONNECTION_GDNATIVE_H
|
||||
#ifndef WEBRTC_PEER_CONNECTION_EXTENSION_H
|
||||
#define WEBRTC_PEER_CONNECTION_EXTENSION_H
|
||||
|
||||
#ifdef WEBRTC_GDNATIVE_ENABLED
|
||||
|
||||
#include "modules/gdnative/include/net/godot_net.h"
|
||||
#include "webrtc_peer_connection.h"
|
||||
|
||||
class WebRTCPeerConnectionGDNative : public WebRTCPeerConnection {
|
||||
GDCLASS(WebRTCPeerConnectionGDNative, WebRTCPeerConnection);
|
||||
#include "core/object/gdvirtual.gen.inc"
|
||||
#include "core/object/script_language.h"
|
||||
#include "core/variant/native_ptr.h"
|
||||
|
||||
class WebRTCPeerConnectionExtension : public WebRTCPeerConnection {
|
||||
GDCLASS(WebRTCPeerConnectionExtension, WebRTCPeerConnection);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
static WebRTCPeerConnection *_create();
|
||||
|
||||
private:
|
||||
static const godot_net_webrtc_library *default_library;
|
||||
const godot_net_webrtc_peer_connection *interface;
|
||||
|
||||
public:
|
||||
static Error set_default_library(const godot_net_webrtc_library *p_library);
|
||||
static void make_default() { WebRTCPeerConnection::_create = WebRTCPeerConnectionGDNative::_create; }
|
||||
|
||||
void set_native_webrtc_peer_connection(const godot_net_webrtc_peer_connection *p_impl);
|
||||
void make_default();
|
||||
|
||||
virtual ConnectionState get_connection_state() const override;
|
||||
|
||||
@ -60,14 +53,22 @@ public:
|
||||
virtual Error create_offer() override;
|
||||
virtual Error set_remote_description(String type, String sdp) override;
|
||||
virtual Error set_local_description(String type, String sdp) override;
|
||||
virtual Error add_ice_candidate(String sdpMidName, int sdpMlineIndexName, String sdpName) override;
|
||||
virtual Error add_ice_candidate(String p_sdp_mid_name, int p_sdp_mline_index, String p_sdp_name) override;
|
||||
virtual Error poll() override;
|
||||
virtual void close() override;
|
||||
|
||||
WebRTCPeerConnectionGDNative();
|
||||
~WebRTCPeerConnectionGDNative();
|
||||
/** GDExtension **/
|
||||
GDVIRTUAL0RC(int, _get_connection_state);
|
||||
GDVIRTUAL1R(int, _initialize, Dictionary);
|
||||
GDVIRTUAL2R(Object *, _create_data_channel, String, Dictionary);
|
||||
GDVIRTUAL0R(int, _create_offer);
|
||||
GDVIRTUAL2R(int, _set_remote_description, String, String);
|
||||
GDVIRTUAL2R(int, _set_local_description, String, String);
|
||||
GDVIRTUAL3R(int, _add_ice_candidate, String, int, String);
|
||||
GDVIRTUAL0R(int, _poll);
|
||||
GDVIRTUAL0(_close);
|
||||
|
||||
WebRTCPeerConnectionExtension() {}
|
||||
};
|
||||
|
||||
#endif // WEBRTC_GDNATIVE_ENABLED
|
||||
|
||||
#endif // WEBRTC_PEER_CONNECTION_GDNATIVE_H
|
||||
#endif // WEBRTC_PEER_CONNECTION_EXTENSION_H
|
@ -1,121 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* webrtc_peer_connection_gdnative.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef WEBRTC_GDNATIVE_ENABLED
|
||||
|
||||
#include "webrtc_peer_connection_gdnative.h"
|
||||
|
||||
#include "core/io/resource_loader.h"
|
||||
#include "modules/gdnative/nativescript/nativescript.h"
|
||||
#include "webrtc_data_channel_gdnative.h"
|
||||
|
||||
const godot_net_webrtc_library *WebRTCPeerConnectionGDNative::default_library = nullptr;
|
||||
|
||||
Error WebRTCPeerConnectionGDNative::set_default_library(const godot_net_webrtc_library *p_lib) {
|
||||
if (default_library) {
|
||||
const godot_net_webrtc_library *old = default_library;
|
||||
default_library = nullptr;
|
||||
old->unregistered();
|
||||
}
|
||||
default_library = p_lib;
|
||||
return OK; // Maybe add version check and fail accordingly
|
||||
}
|
||||
|
||||
WebRTCPeerConnection *WebRTCPeerConnectionGDNative::_create() {
|
||||
WebRTCPeerConnectionGDNative *obj = memnew(WebRTCPeerConnectionGDNative);
|
||||
ERR_FAIL_COND_V_MSG(!default_library, obj, "Default GDNative WebRTC implementation not defined.");
|
||||
|
||||
// Call GDNative constructor
|
||||
Error err = (Error)default_library->create_peer_connection(obj);
|
||||
ERR_FAIL_COND_V_MSG(err != OK, obj, "GDNative default library constructor returned an error.");
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
void WebRTCPeerConnectionGDNative::_bind_methods() {
|
||||
}
|
||||
|
||||
WebRTCPeerConnectionGDNative::WebRTCPeerConnectionGDNative() {
|
||||
interface = nullptr;
|
||||
}
|
||||
|
||||
WebRTCPeerConnectionGDNative::~WebRTCPeerConnectionGDNative() {
|
||||
}
|
||||
|
||||
Error WebRTCPeerConnectionGDNative::initialize(Dictionary p_config) {
|
||||
ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED);
|
||||
return (Error)interface->initialize(interface->data, (const godot_dictionary *)&p_config);
|
||||
}
|
||||
|
||||
Ref<WebRTCDataChannel> WebRTCPeerConnectionGDNative::create_data_channel(String p_label, Dictionary p_options) {
|
||||
ERR_FAIL_COND_V(interface == nullptr, nullptr);
|
||||
return (WebRTCDataChannel *)interface->create_data_channel(interface->data, p_label.utf8().get_data(), (const godot_dictionary *)&p_options);
|
||||
}
|
||||
|
||||
Error WebRTCPeerConnectionGDNative::create_offer() {
|
||||
ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED);
|
||||
return (Error)interface->create_offer(interface->data);
|
||||
}
|
||||
|
||||
Error WebRTCPeerConnectionGDNative::set_local_description(String p_type, String p_sdp) {
|
||||
ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED);
|
||||
return (Error)interface->set_local_description(interface->data, p_type.utf8().get_data(), p_sdp.utf8().get_data());
|
||||
}
|
||||
|
||||
Error WebRTCPeerConnectionGDNative::set_remote_description(String p_type, String p_sdp) {
|
||||
ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED);
|
||||
return (Error)interface->set_remote_description(interface->data, p_type.utf8().get_data(), p_sdp.utf8().get_data());
|
||||
}
|
||||
|
||||
Error WebRTCPeerConnectionGDNative::add_ice_candidate(String sdpMidName, int sdpMlineIndexName, String sdpName) {
|
||||
ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED);
|
||||
return (Error)interface->add_ice_candidate(interface->data, sdpMidName.utf8().get_data(), sdpMlineIndexName, sdpName.utf8().get_data());
|
||||
}
|
||||
|
||||
Error WebRTCPeerConnectionGDNative::poll() {
|
||||
ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED);
|
||||
return (Error)interface->poll(interface->data);
|
||||
}
|
||||
|
||||
void WebRTCPeerConnectionGDNative::close() {
|
||||
ERR_FAIL_COND(interface == nullptr);
|
||||
interface->close(interface->data);
|
||||
}
|
||||
|
||||
WebRTCPeerConnection::ConnectionState WebRTCPeerConnectionGDNative::get_connection_state() const {
|
||||
ERR_FAIL_COND_V(interface == nullptr, STATE_DISCONNECTED);
|
||||
return (ConnectionState)interface->get_connection_state(interface->data);
|
||||
}
|
||||
|
||||
void WebRTCPeerConnectionGDNative::set_native_webrtc_peer_connection(const godot_net_webrtc_peer_connection *p_impl) {
|
||||
interface = p_impl;
|
||||
}
|
||||
|
||||
#endif // WEBRTC_GDNATIVE_ENABLED
|
@ -63,9 +63,6 @@ private:
|
||||
static void _on_error(void *p_obj);
|
||||
|
||||
public:
|
||||
static WebRTCPeerConnection *_create() { return memnew(WebRTCPeerConnectionJS); }
|
||||
static void make_default() { WebRTCPeerConnection::_create = WebRTCPeerConnectionJS::_create; }
|
||||
|
||||
virtual ConnectionState get_connection_state() const;
|
||||
|
||||
virtual Error initialize(Dictionary configuration = Dictionary());
|
||||
|
Loading…
Reference in New Issue
Block a user