2
0

webrtc_peer_connection.cpp 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*************************************************************************/
  2. /* webrtc_peer_connection.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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. #include "webrtc_peer_connection.h"
  31. #ifdef JAVASCRIPT_ENABLED
  32. #include "webrtc_peer_connection_js.h"
  33. #else
  34. #include "webrtc_peer_connection_extension.h"
  35. #endif
  36. StringName WebRTCPeerConnection::default_extension;
  37. void WebRTCPeerConnection::set_default_extension(const StringName &p_extension) {
  38. default_extension = p_extension;
  39. }
  40. WebRTCPeerConnection *WebRTCPeerConnection::create() {
  41. #ifdef JAVASCRIPT_ENABLED
  42. return memnew(WebRTCPeerConnectionJS);
  43. #else
  44. if (default_extension == String()) {
  45. WARN_PRINT_ONCE("No default WebRTC extension configured.");
  46. return memnew(WebRTCPeerConnectionExtension);
  47. }
  48. Object *obj = ClassDB::instantiate(default_extension);
  49. return Object::cast_to<WebRTCPeerConnectionExtension>(obj);
  50. #endif
  51. }
  52. void WebRTCPeerConnection::_bind_methods() {
  53. ClassDB::bind_method(D_METHOD("initialize", "configuration"), &WebRTCPeerConnection::initialize, DEFVAL(Dictionary()));
  54. ClassDB::bind_method(D_METHOD("create_data_channel", "label", "options"), &WebRTCPeerConnection::create_data_channel, DEFVAL(Dictionary()));
  55. ClassDB::bind_method(D_METHOD("create_offer"), &WebRTCPeerConnection::create_offer);
  56. ClassDB::bind_method(D_METHOD("set_local_description", "type", "sdp"), &WebRTCPeerConnection::set_local_description);
  57. ClassDB::bind_method(D_METHOD("set_remote_description", "type", "sdp"), &WebRTCPeerConnection::set_remote_description);
  58. ClassDB::bind_method(D_METHOD("add_ice_candidate", "media", "index", "name"), &WebRTCPeerConnection::add_ice_candidate);
  59. ClassDB::bind_method(D_METHOD("poll"), &WebRTCPeerConnection::poll);
  60. ClassDB::bind_method(D_METHOD("close"), &WebRTCPeerConnection::close);
  61. ClassDB::bind_method(D_METHOD("get_connection_state"), &WebRTCPeerConnection::get_connection_state);
  62. ADD_SIGNAL(MethodInfo("session_description_created", PropertyInfo(Variant::STRING, "type"), PropertyInfo(Variant::STRING, "sdp")));
  63. ADD_SIGNAL(MethodInfo("ice_candidate_created", PropertyInfo(Variant::STRING, "media"), PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::STRING, "name")));
  64. ADD_SIGNAL(MethodInfo("data_channel_received", PropertyInfo(Variant::OBJECT, "channel")));
  65. BIND_ENUM_CONSTANT(STATE_NEW);
  66. BIND_ENUM_CONSTANT(STATE_CONNECTING);
  67. BIND_ENUM_CONSTANT(STATE_CONNECTED);
  68. BIND_ENUM_CONSTANT(STATE_DISCONNECTED);
  69. BIND_ENUM_CONSTANT(STATE_FAILED);
  70. BIND_ENUM_CONSTANT(STATE_CLOSED);
  71. }
  72. WebRTCPeerConnection::WebRTCPeerConnection() {
  73. }
  74. WebRTCPeerConnection::~WebRTCPeerConnection() {
  75. }