Debian Codegraph @

modules/webrtc/webrtc_data_channel_js.h

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