2
0

webrtc_data_channel_extension.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*************************************************************************/
  2. /* webrtc_data_channel_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_data_channel_extension.h"
  31. void WebRTCDataChannelExtension::_bind_methods() {
  32. ADD_PROPERTY_DEFAULT("write_mode", WRITE_MODE_BINARY);
  33. GDVIRTUAL_BIND(_get_packet, "r_buffer", "r_buffer_size");
  34. GDVIRTUAL_BIND(_put_packet, "p_buffer", "p_buffer_size");
  35. GDVIRTUAL_BIND(_get_available_packet_count);
  36. GDVIRTUAL_BIND(_get_max_packet_size);
  37. GDVIRTUAL_BIND(_poll);
  38. GDVIRTUAL_BIND(_close);
  39. GDVIRTUAL_BIND(_set_write_mode, "p_write_mode");
  40. GDVIRTUAL_BIND(_get_write_mode);
  41. GDVIRTUAL_BIND(_was_string_packet);
  42. GDVIRTUAL_BIND(_get_ready_state);
  43. GDVIRTUAL_BIND(_get_label);
  44. GDVIRTUAL_BIND(_is_ordered);
  45. GDVIRTUAL_BIND(_get_id);
  46. GDVIRTUAL_BIND(_get_max_packet_life_time);
  47. GDVIRTUAL_BIND(_get_max_retransmits);
  48. GDVIRTUAL_BIND(_get_protocol);
  49. GDVIRTUAL_BIND(_is_negotiated);
  50. GDVIRTUAL_BIND(_get_buffered_amount);
  51. }
  52. int WebRTCDataChannelExtension::get_available_packet_count() const {
  53. int count;
  54. if (GDVIRTUAL_CALL(_get_available_packet_count, count)) {
  55. return count;
  56. }
  57. WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_available_packet_count is unimplemented!");
  58. return -1;
  59. }
  60. Error WebRTCDataChannelExtension::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
  61. int err;
  62. if (GDVIRTUAL_CALL(_get_packet, r_buffer, &r_buffer_size, err)) {
  63. return (Error)err;
  64. }
  65. WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_packet_native is unimplemented!");
  66. return FAILED;
  67. }
  68. Error WebRTCDataChannelExtension::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
  69. int err;
  70. if (GDVIRTUAL_CALL(_put_packet, p_buffer, p_buffer_size, err)) {
  71. return (Error)err;
  72. }
  73. WARN_PRINT_ONCE("WebRTCDataChannelExtension::_put_packet_native is unimplemented!");
  74. return FAILED;
  75. }
  76. int WebRTCDataChannelExtension::get_max_packet_size() const {
  77. int size;
  78. if (GDVIRTUAL_CALL(_get_max_packet_size, size)) {
  79. return size;
  80. }
  81. WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_max_packet_size is unimplemented!");
  82. return 0;
  83. }
  84. Error WebRTCDataChannelExtension::poll() {
  85. int err;
  86. if (GDVIRTUAL_CALL(_poll, err)) {
  87. return (Error)err;
  88. }
  89. WARN_PRINT_ONCE("WebRTCDataChannelExtension::_poll is unimplemented!");
  90. return ERR_UNCONFIGURED;
  91. }
  92. void WebRTCDataChannelExtension::close() {
  93. if (GDVIRTUAL_CALL(_close)) {
  94. return;
  95. }
  96. WARN_PRINT_ONCE("WebRTCDataChannelExtension::_close is unimplemented!");
  97. }
  98. void WebRTCDataChannelExtension::set_write_mode(WriteMode p_mode) {
  99. if (GDVIRTUAL_CALL(_set_write_mode, p_mode)) {
  100. return;
  101. }
  102. WARN_PRINT_ONCE("WebRTCDataChannelExtension::_set_write_mode is unimplemented!");
  103. }
  104. WebRTCDataChannel::WriteMode WebRTCDataChannelExtension::get_write_mode() const {
  105. int mode;
  106. if (GDVIRTUAL_CALL(_get_write_mode, mode)) {
  107. return (WriteMode)mode;
  108. }
  109. WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_write_mode is unimplemented!");
  110. return WRITE_MODE_BINARY;
  111. }
  112. bool WebRTCDataChannelExtension::was_string_packet() const {
  113. bool was_string;
  114. if (GDVIRTUAL_CALL(_was_string_packet, was_string)) {
  115. return was_string;
  116. }
  117. WARN_PRINT_ONCE("WebRTCDataChannelExtension::_was_string_packet is unimplemented!");
  118. return false;
  119. }
  120. WebRTCDataChannel::ChannelState WebRTCDataChannelExtension::get_ready_state() const {
  121. int state;
  122. if (GDVIRTUAL_CALL(_get_ready_state, state)) {
  123. return (ChannelState)state;
  124. }
  125. WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_ready_state is unimplemented!");
  126. return STATE_CLOSED;
  127. }
  128. String WebRTCDataChannelExtension::get_label() const {
  129. String label;
  130. if (GDVIRTUAL_CALL(_get_label, label)) {
  131. return label;
  132. }
  133. WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_label is unimplemented!");
  134. return label;
  135. }
  136. bool WebRTCDataChannelExtension::is_ordered() const {
  137. bool ordered;
  138. if (GDVIRTUAL_CALL(_is_ordered, ordered)) {
  139. return ordered;
  140. }
  141. WARN_PRINT_ONCE("WebRTCDataChannelExtension::_is_ordered is unimplemented!");
  142. return false;
  143. }
  144. int WebRTCDataChannelExtension::get_id() const {
  145. int id;
  146. if (GDVIRTUAL_CALL(_get_id, id)) {
  147. return id;
  148. }
  149. WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_id is unimplemented!");
  150. return -1;
  151. }
  152. int WebRTCDataChannelExtension::get_max_packet_life_time() const {
  153. int lifetime;
  154. if (GDVIRTUAL_CALL(_get_max_packet_life_time, lifetime)) {
  155. return lifetime;
  156. }
  157. WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_max_packet_life_time is unimplemented!");
  158. return -1;
  159. }
  160. int WebRTCDataChannelExtension::get_max_retransmits() const {
  161. int retransmits;
  162. if (GDVIRTUAL_CALL(_get_max_retransmits, retransmits)) {
  163. return retransmits;
  164. }
  165. WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_max_retransmits is unimplemented!");
  166. return -1;
  167. }
  168. String WebRTCDataChannelExtension::get_protocol() const {
  169. String protocol;
  170. if (GDVIRTUAL_CALL(_get_protocol, protocol)) {
  171. return protocol;
  172. }
  173. WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_protocol is unimplemented!");
  174. return protocol;
  175. }
  176. bool WebRTCDataChannelExtension::is_negotiated() const {
  177. bool negotiated;
  178. if (GDVIRTUAL_CALL(_is_negotiated, negotiated)) {
  179. return negotiated;
  180. }
  181. WARN_PRINT_ONCE("WebRTCDataChannelExtension::_is_negotiated is unimplemented!");
  182. return false;
  183. }
  184. int WebRTCDataChannelExtension::get_buffered_amount() const {
  185. int amount;
  186. if (GDVIRTUAL_CALL(_get_buffered_amount, amount)) {
  187. return amount;
  188. }
  189. WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_buffered_amount is unimplemented!");
  190. return -1;
  191. }