From ca1d12b6b6f65e6339845e09865c752ec73b3dde Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 20 Mar 2022 08:43:41 +0100 Subject: [PATCH] Made WebrctPeerConnection instantiable by it's own. --- modules/webrtc/register_types.cpp | 2 ++ modules/webrtc/webrtc_peer_connection.cpp | 32 +++++++++++++++++++++++ modules/webrtc/webrtc_peer_connection.h | 24 ++++++++++------- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/modules/webrtc/register_types.cpp b/modules/webrtc/register_types.cpp index b74eb192d..c65960f26 100644 --- a/modules/webrtc/register_types.cpp +++ b/modules/webrtc/register_types.cpp @@ -49,6 +49,8 @@ void register_webrtc_types() { #ifdef JAVASCRIPT_ENABLED WebRTCPeerConnectionJS::make_default(); +#else + WebRTCPeerConnection::make_default(); #endif ClassDB::register_custom_instance_class(); diff --git a/modules/webrtc/webrtc_peer_connection.cpp b/modules/webrtc/webrtc_peer_connection.cpp index f69059ddc..563869610 100644 --- a/modules/webrtc/webrtc_peer_connection.cpp +++ b/modules/webrtc/webrtc_peer_connection.cpp @@ -43,6 +43,38 @@ WebRTCPeerConnection *WebRTCPeerConnection::create() { return _create(); } +WebRTCPeerConnection *WebRTCPeerConnection::_create_func() { + return memnew(WebRTCPeerConnection); +} + +WebRTCPeerConnection::ConnectionState WebRTCPeerConnection::get_connection_state() const { + return WebRTCPeerConnection::STATE_FAILED; +} +Error WebRTCPeerConnection::initialize(Dictionary p_config) { + ERR_FAIL_V(ERR_UNAVAILABLE); +} +Ref WebRTCPeerConnection::create_data_channel(String p_label, Dictionary p_options) { + ERR_FAIL_V(Ref()); +} +Error WebRTCPeerConnection::create_offer() { + ERR_FAIL_V(ERR_UNAVAILABLE); +} +Error WebRTCPeerConnection::set_remote_description(String type, String sdp) { + ERR_FAIL_V(ERR_UNAVAILABLE); +} +Error WebRTCPeerConnection::set_local_description(String type, String sdp) { + ERR_FAIL_V(ERR_UNAVAILABLE); +} +Error WebRTCPeerConnection::add_ice_candidate(String sdpMidName, int sdpMlineIndexName, String sdpName) { + ERR_FAIL_V(ERR_UNAVAILABLE); +} +Error WebRTCPeerConnection::poll() { + ERR_FAIL_V(ERR_UNAVAILABLE); +} +void WebRTCPeerConnection::close() { + ERR_FAIL(); +} + void WebRTCPeerConnection::_bind_methods() { ClassDB::bind_method(D_METHOD("initialize", "configuration"), &WebRTCPeerConnection::initialize, DEFVAL(Dictionary())); ClassDB::bind_method(D_METHOD("create_data_channel", "label", "options"), &WebRTCPeerConnection::create_data_channel, DEFVAL(Dictionary())); diff --git a/modules/webrtc/webrtc_peer_connection.h b/modules/webrtc/webrtc_peer_connection.h index ac18309a6..423581543 100644 --- a/modules/webrtc/webrtc_peer_connection.h +++ b/modules/webrtc/webrtc_peer_connection.h @@ -50,17 +50,21 @@ protected: static void _bind_methods(); static WebRTCPeerConnection *(*_create)(); -public: - virtual ConnectionState get_connection_state() const = 0; + static WebRTCPeerConnection *_create_func(); - virtual Error initialize(Dictionary p_config = Dictionary()) = 0; - virtual Ref create_data_channel(String p_label, Dictionary p_options = Dictionary()) = 0; - virtual Error create_offer() = 0; - virtual Error set_remote_description(String type, String sdp) = 0; - virtual Error set_local_description(String type, String sdp) = 0; - virtual Error add_ice_candidate(String sdpMidName, int sdpMlineIndexName, String sdpName) = 0; - virtual Error poll() = 0; - virtual void close() = 0; +public: + static void make_default() { WebRTCPeerConnection::_create = WebRTCPeerConnection::_create_func; } + + virtual ConnectionState get_connection_state() const; + + virtual Error initialize(Dictionary p_config = Dictionary()); + virtual Ref create_data_channel(String p_label, Dictionary p_options = Dictionary()); + virtual Error create_offer(); + virtual Error set_remote_description(String type, String sdp); + virtual Error set_local_description(String type, String sdp); + virtual Error add_ice_candidate(String sdpMidName, int sdpMlineIndexName, String sdpName); + virtual Error poll(); + virtual void close(); static Ref create_ref(); static WebRTCPeerConnection *create();