webrtc_data_channel_js.h 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**************************************************************************/
  2. /* webrtc_data_channel_js.h */
  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. #ifndef WEBRTC_DATA_CHANNEL_JS_H
  31. #define WEBRTC_DATA_CHANNEL_JS_H
  32. #ifdef JAVASCRIPT_ENABLED
  33. #include "webrtc_data_channel.h"
  34. class WebRTCDataChannelJS : public WebRTCDataChannel {
  35. GDCLASS(WebRTCDataChannelJS, WebRTCDataChannel);
  36. private:
  37. String _label;
  38. String _protocol;
  39. bool _was_string;
  40. WriteMode _write_mode;
  41. enum {
  42. PACKET_BUFFER_SIZE = 65536 - 5 // 4 bytes for the size, 1 for for type
  43. };
  44. int _js_id;
  45. RingBuffer<uint8_t> in_buffer;
  46. int queue_count;
  47. uint8_t packet_buffer[PACKET_BUFFER_SIZE];
  48. static void _on_open(void *p_obj);
  49. static void _on_close(void *p_obj);
  50. static void _on_error(void *p_obj);
  51. static void _on_message(void *p_obj, const uint8_t *p_data, int p_size, int p_is_string);
  52. public:
  53. virtual void set_write_mode(WriteMode mode);
  54. virtual WriteMode get_write_mode() const;
  55. virtual bool was_string_packet() const;
  56. virtual ChannelState get_ready_state() const;
  57. virtual String get_label() const;
  58. virtual bool is_ordered() const;
  59. virtual int get_id() const;
  60. virtual int get_max_packet_life_time() const;
  61. virtual int get_max_retransmits() const;
  62. virtual String get_protocol() const;
  63. virtual bool is_negotiated() const;
  64. virtual int get_buffered_amount() const;
  65. virtual Error poll();
  66. virtual void close();
  67. /** Inherited from PacketPeer: **/
  68. virtual int get_available_packet_count() const;
  69. virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size); ///< buffer is GONE after next get_packet
  70. virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size);
  71. virtual int get_max_packet_size() const;
  72. WebRTCDataChannelJS();
  73. WebRTCDataChannelJS(int js_id);
  74. ~WebRTCDataChannelJS();
  75. };
  76. #endif // JAVASCRIPT_ENABLED
  77. #endif // WEBRTC_DATA_CHANNEL_JS_H