diff options
Diffstat (limited to 'Source/WebCore/Modules/mediastream/RTCDataChannel.h')
-rw-r--r-- | Source/WebCore/Modules/mediastream/RTCDataChannel.h | 118 |
1 files changed, 56 insertions, 62 deletions
diff --git a/Source/WebCore/Modules/mediastream/RTCDataChannel.h b/Source/WebCore/Modules/mediastream/RTCDataChannel.h index 54a21d441..cd860f184 100644 --- a/Source/WebCore/Modules/mediastream/RTCDataChannel.h +++ b/Source/WebCore/Modules/mediastream/RTCDataChannel.h @@ -22,16 +22,17 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef RTCDataChannel_h -#define RTCDataChannel_h +#pragma once -#if ENABLE(MEDIA_STREAM) +#if ENABLE(WEB_RTC) +#include "Event.h" #include "EventTarget.h" +#include "ExceptionOr.h" +#include "RTCDataChannelHandler.h" #include "RTCDataChannelHandlerClient.h" #include "ScriptWrappable.h" #include "Timer.h" -#include <wtf/RefCounted.h> namespace JSC { class ArrayBuffer; @@ -41,85 +42,78 @@ namespace JSC { namespace WebCore { class Blob; -class Dictionary; -class RTCDataChannelHandler; class RTCPeerConnectionHandler; -class RTCDataChannel final : public RefCounted<RTCDataChannel>, public ScriptWrappable, public EventTargetWithInlineData, public RTCDataChannelHandlerClient { +class RTCDataChannel final : public RTCDataChannelHandlerClient, public EventTargetWithInlineData { public: - static PassRefPtr<RTCDataChannel> create(ScriptExecutionContext*, std::unique_ptr<RTCDataChannelHandler>); - static PassRefPtr<RTCDataChannel> create(ScriptExecutionContext*, RTCPeerConnectionHandler*, const String& , const Dictionary&, ExceptionCode&); - ~RTCDataChannel(); - - String label() const; - bool ordered() const; - unsigned short maxRetransmitTime() const; - unsigned short maxRetransmits() const; - String protocol() const; - bool negotiated() const; - unsigned short id() const; - AtomicString readyState() const; - unsigned long bufferedAmount() const; - - AtomicString binaryType() const; - void setBinaryType(const AtomicString&, ExceptionCode&); - - void send(const String&, ExceptionCode&); - void send(PassRefPtr<JSC::ArrayBuffer>, ExceptionCode&); - void send(PassRefPtr<JSC::ArrayBufferView>, ExceptionCode&); - void send(PassRefPtr<Blob>, ExceptionCode&); + static Ref<RTCDataChannel> create(ScriptExecutionContext&, std::unique_ptr<RTCDataChannelHandler>&&, String&&, RTCDataChannelInit&&); - void close(); + bool ordered() const { return m_options.ordered; } + unsigned short maxRetransmitTime() const { return m_options.maxRetransmitTime; } + unsigned short maxRetransmits() const { return m_options.maxRetransmits; } + String protocol() const { return m_options.protocol; } + bool negotiated() const { return m_options.negotiated; }; + unsigned short id() const { return m_options.id; }; - DEFINE_ATTRIBUTE_EVENT_LISTENER(open); - DEFINE_ATTRIBUTE_EVENT_LISTENER(error); - DEFINE_ATTRIBUTE_EVENT_LISTENER(close); - DEFINE_ATTRIBUTE_EVENT_LISTENER(message); + String label() const { return m_label; } + const AtomicString& readyState() const; + size_t bufferedAmount() const; + size_t bufferedAmountLowThreshold() const { return m_bufferedAmountLowThreshold; } + void setBufferedAmountLowThreshold(size_t value) { m_bufferedAmountLowThreshold = value; } - void stop(); + 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(); - // EventTarget - virtual EventTargetInterface eventTargetInterface() const override { return RTCDataChannelEventTargetInterfaceType; } - virtual ScriptExecutionContext* scriptExecutionContext() const override { return m_scriptExecutionContext; } + void stop(); - using RefCounted<RTCDataChannel>::ref; - using RefCounted<RTCDataChannel>::deref; + using RTCDataChannelHandlerClient::ref; + using RTCDataChannelHandlerClient::deref; private: - RTCDataChannel(ScriptExecutionContext*, std::unique_ptr<RTCDataChannelHandler>); + RTCDataChannel(ScriptExecutionContext&, std::unique_ptr<RTCDataChannelHandler>&&, String&&, RTCDataChannelInit&&); + + void scheduleDispatchEvent(Ref<Event>&&); + void scheduledEventTimerFired(); - void scheduleDispatchEvent(PassRefPtr<Event>); - void scheduledEventTimerFired(Timer<RTCDataChannel>*); + EventTargetInterface eventTargetInterface() const final { return RTCDataChannelEventTargetInterfaceType; } + ScriptExecutionContext* scriptExecutionContext() const final { return m_scriptExecutionContext; } - // EventTarget - virtual void refEventTarget() override { ref(); } - virtual void derefEventTarget() override { deref(); } + void refEventTarget() final { ref(); } + void derefEventTarget() final { deref(); } ScriptExecutionContext* m_scriptExecutionContext; - // RTCDataChannelHandlerClient - virtual void didChangeReadyState(ReadyState) override; - virtual void didReceiveStringData(const String&) override; - virtual void didReceiveRawData(const char*, size_t) override; - virtual void didDetectError() override; + // RTCDataChannelHandlerClient API + void didChangeReadyState(ReadyState) final; + void didReceiveStringData(const String&) final; + void didReceiveRawData(const char*, size_t) final; + void didDetectError() final; + void bufferedAmountIsDecreasing() final; std::unique_ptr<RTCDataChannelHandler> m_handler; - bool m_stopped; + bool m_stopped { false }; + + ReadyState m_readyState { ReadyStateConnecting }; - ReadyState m_readyState; - enum BinaryType { - BinaryTypeBlob, - BinaryTypeArrayBuffer - }; - BinaryType m_binaryType; + enum class BinaryType { Blob, ArrayBuffer }; + BinaryType m_binaryType { BinaryType::ArrayBuffer }; - Timer<RTCDataChannel> m_scheduledEventTimer; - Vector<RefPtr<Event>> m_scheduledEvents; + Timer m_scheduledEventTimer; + Vector<Ref<Event>> m_scheduledEvents; + + String m_label; + RTCDataChannelInit m_options; + size_t m_bufferedAmountLowThreshold { 0 }; }; } // namespace WebCore -#endif // ENABLE(MEDIA_STREAM) - -#endif // RTCDataChannel_h +#endif // ENABLE(WEB_RTC) |