webrtc_peer_connection_extension.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*************************************************************************/
  2. /* webrtc_peer_connection_extension.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_extension.h"
  31. void WebRTCPeerConnectionExtension::_bind_methods() {
  32. ClassDB::bind_method(D_METHOD("make_default"), &WebRTCPeerConnectionExtension::make_default);
  33. GDVIRTUAL_BIND(_get_connection_state);
  34. GDVIRTUAL_BIND(_initialize, "p_config");
  35. GDVIRTUAL_BIND(_create_data_channel, "p_label", "p_config");
  36. GDVIRTUAL_BIND(_create_offer);
  37. GDVIRTUAL_BIND(_set_remote_description, "p_type", "p_sdp");
  38. GDVIRTUAL_BIND(_set_local_description, "p_type", "p_sdp");
  39. GDVIRTUAL_BIND(_add_ice_candidate, "p_sdp_mid_name", "p_sdp_mline_index", "p_sdp_name");
  40. GDVIRTUAL_BIND(_poll);
  41. GDVIRTUAL_BIND(_close);
  42. }
  43. void WebRTCPeerConnectionExtension::make_default() {
  44. ERR_FAIL_COND_MSG(!_get_extension(), vformat("Can't make %s the default without extending it.", get_class()));
  45. WebRTCPeerConnection::set_default_extension(get_class());
  46. }
  47. WebRTCPeerConnection::ConnectionState WebRTCPeerConnectionExtension::get_connection_state() const {
  48. int state;
  49. if (GDVIRTUAL_CALL(_get_connection_state, state)) {
  50. return (ConnectionState)state;
  51. }
  52. WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_get_connection_state is unimplemented!");
  53. return STATE_DISCONNECTED;
  54. }
  55. Error WebRTCPeerConnectionExtension::initialize(Dictionary p_config) {
  56. int err;
  57. if (GDVIRTUAL_CALL(_initialize, p_config, err)) {
  58. return (Error)err;
  59. }
  60. WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_initialize is unimplemented!");
  61. return ERR_UNCONFIGURED;
  62. }
  63. Ref<WebRTCDataChannel> WebRTCPeerConnectionExtension::create_data_channel(String p_label, Dictionary p_options) {
  64. Object *ret = nullptr;
  65. if (GDVIRTUAL_CALL(_create_data_channel, p_label, p_options, ret)) {
  66. WebRTCDataChannel *ch = Object::cast_to<WebRTCDataChannel>(ret);
  67. ERR_FAIL_COND_V_MSG(ret && !ch, nullptr, "Returned object must be an instance of WebRTCDataChannel.");
  68. return ch;
  69. }
  70. WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_create_data_channel is unimplemented!");
  71. return nullptr;
  72. }
  73. Error WebRTCPeerConnectionExtension::create_offer() {
  74. int err;
  75. if (GDVIRTUAL_CALL(_create_offer, err)) {
  76. return (Error)err;
  77. }
  78. WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_create_offer is unimplemented!");
  79. return ERR_UNCONFIGURED;
  80. }
  81. Error WebRTCPeerConnectionExtension::set_local_description(String p_type, String p_sdp) {
  82. int err;
  83. if (GDVIRTUAL_CALL(_set_local_description, p_type, p_sdp, err)) {
  84. return (Error)err;
  85. }
  86. WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_set_local_description is unimplemented!");
  87. return ERR_UNCONFIGURED;
  88. }
  89. Error WebRTCPeerConnectionExtension::set_remote_description(String p_type, String p_sdp) {
  90. int err;
  91. if (GDVIRTUAL_CALL(_set_remote_description, p_type, p_sdp, err)) {
  92. return (Error)err;
  93. }
  94. WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_set_remote_description is unimplemented!");
  95. return ERR_UNCONFIGURED;
  96. }
  97. Error WebRTCPeerConnectionExtension::add_ice_candidate(String p_sdp_mid_name, int p_sdp_mline_index, String p_sdp_name) {
  98. int err;
  99. if (GDVIRTUAL_CALL(_add_ice_candidate, p_sdp_mid_name, p_sdp_mline_index, p_sdp_name, err)) {
  100. return (Error)err;
  101. }
  102. WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_add_ice_candidate is unimplemented!");
  103. return ERR_UNCONFIGURED;
  104. }
  105. Error WebRTCPeerConnectionExtension::poll() {
  106. int err;
  107. if (GDVIRTUAL_CALL(_poll, err)) {
  108. return (Error)err;
  109. }
  110. WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_poll is unimplemented!");
  111. return ERR_UNCONFIGURED;
  112. }
  113. void WebRTCPeerConnectionExtension::close() {
  114. if (GDVIRTUAL_CALL(_close)) {
  115. return;
  116. }
  117. WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_close is unimplemented!");
  118. }