#pragma once
#if ENABLE(WEB_RTC)
#include "ActiveDOMObject.h"
#include "Event.h"
#include "EventTarget.h"
#include "ExceptionOr.h"
#include "RTCDataChannelHandler.h"
#include "RTCDataChannelHandlerClient.h"
#include "ScriptWrappable.h"
#include "Timer.h"
namespace JSC {
class ArrayBuffer;
class ArrayBufferView;
}
namespace WebCore {
class Blob;
class RTCPeerConnectionHandler;
class RTCDataChannel final : public ActiveDOMObject, public RTCDataChannelHandlerClient, public EventTargetWithInlineData {
public:
static Ref<RTCDataChannel> create(ScriptExecutionContext&, std::unique_ptr<RTCDataChannelHandler>&&, String&&, RTCDataChannelInit&&);
bool ordered() const { return *m_options.ordered; }
std::optional<unsigned short> maxPacketLifeTime() const { return m_options.maxPacketLifeTime; }
std::optional<unsigned short> maxRetransmits() const { return m_options.maxRetransmits; }
String protocol() const { return m_options.protocol; }
bool negotiated() const { return *m_options.negotiated; };
std::optional<unsigned short> id() const { return m_options.id; };
String label() const { return m_label; }
RTCDataChannelState readyState() const {return m_readyState; }
size_t bufferedAmount() const;
size_t bufferedAmountLowThreshold() const { return m_bufferedAmountLowThreshold; }
void setBufferedAmountLowThreshold(size_t value) { m_bufferedAmountLowThreshold = value; }
const AtomicString& binaryType() const;
ExceptionOr<void> setBinaryType(const AtomicString&);
ExceptionOr<void> send(const String&);
ExceptionOr<void> send(JSC::ArrayBuffer&);
ExceptionOr<void> send(JSC::ArrayBufferView&);
ExceptionOr<void> send(Blob&);
void close();
using RTCDataChannelHandlerClient::ref;
using RTCDataChannelHandlerClient::deref;
private:
RTCDataChannel(ScriptExecutionContext&, std::unique_ptr<RTCDataChannelHandler>&&, String&&, RTCDataChannelInit&&);
void scheduleDispatchEvent(Ref<Event>&&);
void scheduledEventTimerFired();
EventTargetInterface eventTargetInterface() const final { return RTCDataChannelEventTargetInterfaceType; }
ScriptExecutionContext* scriptExecutionContext() const final { return m_scriptExecutionContext; }
void refEventTarget() final { ref(); }
void derefEventTarget() final { deref(); }
void stop() final;
const char* activeDOMObjectName() const final { return "RTCDataChannel"; }
bool canSuspendForDocumentSuspension() const final { return m_readyState == RTCDataChannelState::Closed; }
void didChangeReadyState(RTCDataChannelState) final;
void didReceiveStringData(const String&) final;
void didReceiveRawData(const char*, size_t) final;
void didDetectError() final;
void bufferedAmountIsDecreasing(size_t) final;
std::unique_ptr<RTCDataChannelHandler> m_handler;
bool m_stopped { false };
RTCDataChannelState m_readyState { RTCDataChannelState::Connecting };
enum class BinaryType { Blob, ArrayBuffer };
BinaryType m_binaryType { BinaryType::ArrayBuffer };
Timer m_scheduledEventTimer;
Vector<Ref<Event>> m_scheduledEvents;
String m_label;
RTCDataChannelInit m_options;
size_t m_bufferedAmountLowThreshold { 0 };
};
}
#endif // ENABLE(WEB_RTC)