Debian Codegraph @

modules/webrtc/webrtc_peer_connection.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* webrtc_peer_connection.cpp */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #include "webrtc_peer_connection.h"
32
33 #ifdef WEB_ENABLED
34 #include "webrtc_peer_connection_js.h"
35 #endif
36
37 #include "webrtc_peer_connection_extension.h"
38
39 StringName WebRTCPeerConnection::default_extension;
40
41 void WebRTCPeerConnection::set_default_extension(const StringName &p_extension) {
42 ERR_FAIL_COND_MSG(!ClassDB::is_parent_class(p_extension, WebRTCPeerConnectionExtension::get_class_static()), vformat("Can't make %s the default WebRTC extension since it does not extend WebRTCPeerConnectionExtension.", p_extension));
43 default_extension = StringName(p_extension, true);
44 }
45
46 WebRTCPeerConnection *WebRTCPeerConnection::create(bool p_notify_postinitialize) {
47 #ifdef WEB_ENABLED
48 return static_cast<WebRTCPeerConnection *>(ClassDB::creator<WebRTCPeerConnectionJS>(p_notify_postinitialize));
49 #else
50 if (default_extension == StringName()) {
51 WARN_PRINT_ONCE("No default WebRTC extension configured.");
52 return static_cast<WebRTCPeerConnection *>(ClassDB::creator<WebRTCPeerConnectionExtension>(p_notify_postinitialize));
53 }
54 Object *obj = nullptr;
55 if (p_notify_postinitialize) {
56 obj = ClassDB::instantiate(default_extension);
57 } else {
58 obj = ClassDB::instantiate_without_postinitialization(default_extension);
59 }
60 return Object::cast_to<WebRTCPeerConnectionExtension>(obj);
61 #endif
62 }
63
64 void WebRTCPeerConnection::_bind_methods() {
65 ClassDB::bind_static_method(get_class_static(), D_METHOD("set_default_extension", "extension_class"), &WebRTCPeerConnectionExtension::set_default_extension);
66
67 ClassDB::bind_method(D_METHOD("initialize", "configuration"), &WebRTCPeerConnection::initialize, DEFVAL(Dictionary()));
68 ClassDB::bind_method(D_METHOD("create_data_channel", "label", "options"), &WebRTCPeerConnection::create_data_channel, DEFVAL(Dictionary()));
69 ClassDB::bind_method(D_METHOD("create_offer"), &WebRTCPeerConnection::create_offer);
70 ClassDB::bind_method(D_METHOD("set_local_description", "type", "sdp"), &WebRTCPeerConnection::set_local_description);
71 ClassDB::bind_method(D_METHOD("set_remote_description", "type", "sdp"), &WebRTCPeerConnection::set_remote_description);
72 ClassDB::bind_method(D_METHOD("add_ice_candidate", "media", "index", "name"), &WebRTCPeerConnection::add_ice_candidate);
73 ClassDB::bind_method(D_METHOD("poll"), &WebRTCPeerConnection::poll);
74 ClassDB::bind_method(D_METHOD("close"), &WebRTCPeerConnection::close);
75
76 ClassDB::bind_method(D_METHOD("get_connection_state"), &WebRTCPeerConnection::get_connection_state);
77 ClassDB::bind_method(D_METHOD("get_gathering_state"), &WebRTCPeerConnection::get_gathering_state);
78 ClassDB::bind_method(D_METHOD("get_signaling_state"), &WebRTCPeerConnection::get_signaling_state);
79
80 ADD_SIGNAL(MethodInfo("session_description_created", PropertyInfo(Variant::STRING, "type"), PropertyInfo(Variant::STRING, "sdp")));
81 ADD_SIGNAL(MethodInfo("ice_candidate_created", PropertyInfo(Variant::STRING, "media"), PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::STRING, "name")));
82 ADD_SIGNAL(MethodInfo("data_channel_received", PropertyInfo(Variant::OBJECT, "channel", PROPERTY_HINT_RESOURCE_TYPE, "WebRTCDataChannel")));
83
84 BIND_ENUM_CONSTANT(STATE_NEW);
85 BIND_ENUM_CONSTANT(STATE_CONNECTING);
86 BIND_ENUM_CONSTANT(STATE_CONNECTED);
87 BIND_ENUM_CONSTANT(STATE_DISCONNECTED);
88 BIND_ENUM_CONSTANT(STATE_FAILED);
89 BIND_ENUM_CONSTANT(STATE_CLOSED);
90
91 BIND_ENUM_CONSTANT(GATHERING_STATE_NEW);
92 BIND_ENUM_CONSTANT(GATHERING_STATE_GATHERING);
93 BIND_ENUM_CONSTANT(GATHERING_STATE_COMPLETE);
94
95 BIND_ENUM_CONSTANT(SIGNALING_STATE_STABLE);
96 BIND_ENUM_CONSTANT(SIGNALING_STATE_HAVE_LOCAL_OFFER);
97 BIND_ENUM_CONSTANT(SIGNALING_STATE_HAVE_REMOTE_OFFER);
98 BIND_ENUM_CONSTANT(SIGNALING_STATE_HAVE_LOCAL_PRANSWER);
99 BIND_ENUM_CONSTANT(SIGNALING_STATE_HAVE_REMOTE_PRANSWER);
100 BIND_ENUM_CONSTANT(SIGNALING_STATE_CLOSED);
101 }
102
103 WebRTCPeerConnection::WebRTCPeerConnection() {
104 }
105
106 WebRTCPeerConnection::~WebRTCPeerConnection() {
107 }