123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- #ifndef API_DATA_CHANNEL_INTERFACE_H_
- #define API_DATA_CHANNEL_INTERFACE_H_
- #include <stddef.h>
- #include <stdint.h>
- #include <string>
- #include "absl/types/optional.h"
- #include "api/priority.h"
- #include "api/rtc_error.h"
- #include "rtc_base/checks.h"
- #include "rtc_base/copy_on_write_buffer.h"
- #include "rtc_base/ref_count.h"
- #include "rtc_base/system/rtc_export.h"
- namespace webrtc {
- struct DataChannelInit {
-
-
- bool reliable = false;
-
- bool ordered = true;
-
-
-
-
-
- absl::optional<int> maxRetransmitTime;
-
-
-
- absl::optional<int> maxRetransmits;
-
- std::string protocol;
-
-
-
-
- bool negotiated = false;
-
- int id = -1;
-
- absl::optional<Priority> priority;
- };
- struct DataBuffer {
- DataBuffer(const rtc::CopyOnWriteBuffer& data, bool binary)
- : data(data), binary(binary) {}
-
- explicit DataBuffer(const std::string& text)
- : data(text.data(), text.length()), binary(false) {}
- size_t size() const { return data.size(); }
- rtc::CopyOnWriteBuffer data;
-
-
-
- bool binary;
- };
- class DataChannelObserver {
- public:
-
- virtual void OnStateChange() = 0;
-
- virtual void OnMessage(const DataBuffer& buffer) = 0;
-
- virtual void OnBufferedAmountChange(uint64_t sent_data_size) {}
- protected:
- virtual ~DataChannelObserver() = default;
- };
- class RTC_EXPORT DataChannelInterface : public rtc::RefCountInterface {
- public:
-
-
-
- enum DataState {
- kConnecting,
- kOpen,
- kClosing,
- kClosed
- };
- static const char* DataStateString(DataState state) {
- switch (state) {
- case kConnecting:
- return "connecting";
- case kOpen:
- return "open";
- case kClosing:
- return "closing";
- case kClosed:
- return "closed";
- }
- RTC_CHECK(false) << "Unknown DataChannel state: " << state;
- return "";
- }
-
-
-
- virtual void RegisterObserver(DataChannelObserver* observer) = 0;
- virtual void UnregisterObserver() = 0;
-
-
- virtual std::string label() const = 0;
-
-
- virtual bool reliable() const = 0;
-
-
-
- virtual bool ordered() const;
-
- virtual uint16_t maxRetransmitTime() const;
- virtual uint16_t maxRetransmits() const;
- virtual absl::optional<int> maxRetransmitsOpt() const;
- virtual absl::optional<int> maxPacketLifeTime() const;
- virtual std::string protocol() const;
- virtual bool negotiated() const;
-
-
-
- virtual int id() const = 0;
- virtual Priority priority() const { return Priority::kLow; }
- virtual DataState state() const = 0;
-
-
-
- virtual RTCError error() const { return RTCError(); }
- virtual uint32_t messages_sent() const = 0;
- virtual uint64_t bytes_sent() const = 0;
- virtual uint32_t messages_received() const = 0;
- virtual uint64_t bytes_received() const = 0;
-
-
-
- virtual uint64_t buffered_amount() const = 0;
-
-
- virtual void Close() = 0;
-
-
-
-
-
-
-
-
- virtual bool Send(const DataBuffer& buffer) = 0;
- protected:
- ~DataChannelInterface() override = default;
- };
- }
- #endif // API_DATA_CHANNEL_INTERFACE_H_
|