• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1.  Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  * 2.  Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16  * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24 
25 #ifndef RTCDataChannel_h
26 #define RTCDataChannel_h
27 
28 #include "bindings/v8/ScriptWrappable.h"
29 #include "core/events/EventTarget.h"
30 #include "core/platform/mediastream/RTCDataChannelHandlerClient.h"
31 #include "platform/Timer.h"
32 #include "wtf/RefCounted.h"
33 
34 namespace blink {
35 struct WebRTCDataChannelInit;
36 }
37 
38 namespace WebCore {
39 
40 class Blob;
41 class ExceptionState;
42 class RTCDataChannelHandler;
43 class RTCPeerConnectionHandler;
44 
45 class RTCDataChannel : public RefCounted<RTCDataChannel>, public ScriptWrappable, public EventTargetWithInlineData, public RTCDataChannelHandlerClient {
46     REFCOUNTED_EVENT_TARGET(RTCDataChannel);
47 public:
48     static PassRefPtr<RTCDataChannel> create(ExecutionContext*, PassOwnPtr<RTCDataChannelHandler>);
49     static PassRefPtr<RTCDataChannel> create(ExecutionContext*, RTCPeerConnectionHandler*, const String& label, const blink::WebRTCDataChannelInit&, ExceptionState&);
50     ~RTCDataChannel();
51 
52     String label() const;
53 
54     // DEPRECATED
55     bool reliable() const;
56 
57     bool ordered() const;
58     unsigned short maxRetransmitTime() const;
59     unsigned short maxRetransmits() const;
60     String protocol() const;
61     bool negotiated() const;
62     unsigned short id() const;
63     String readyState() const;
64     unsigned long bufferedAmount() const;
65 
66     String binaryType() const;
67     void setBinaryType(const String&, ExceptionState&);
68 
69     void send(const String&, ExceptionState&);
70     void send(PassRefPtr<ArrayBuffer>, ExceptionState&);
71     void send(PassRefPtr<ArrayBufferView>, ExceptionState&);
72     void send(PassRefPtr<Blob>, ExceptionState&);
73 
74     void close();
75 
76     DEFINE_ATTRIBUTE_EVENT_LISTENER(open);
77     DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
78     DEFINE_ATTRIBUTE_EVENT_LISTENER(close);
79     DEFINE_ATTRIBUTE_EVENT_LISTENER(message);
80 
81     void stop();
82 
83     // EventTarget
84     virtual const AtomicString& interfaceName() const OVERRIDE;
85     virtual ExecutionContext* executionContext() const OVERRIDE;
86 
87 private:
88     RTCDataChannel(ExecutionContext*, PassOwnPtr<RTCDataChannelHandler>);
89 
90     void scheduleDispatchEvent(PassRefPtr<Event>);
91     void scheduledEventTimerFired(Timer<RTCDataChannel>*);
92 
93     ExecutionContext* m_executionContext;
94 
95     // RTCDataChannelHandlerClient
96     virtual void didChangeReadyState(ReadyState) OVERRIDE;
97     virtual void didReceiveStringData(const String&) OVERRIDE;
98     virtual void didReceiveRawData(const char*, size_t) OVERRIDE;
99     virtual void didDetectError() OVERRIDE;
100 
101     OwnPtr<RTCDataChannelHandler> m_handler;
102 
103     bool m_stopped;
104 
105     ReadyState m_readyState;
106     enum BinaryType {
107         BinaryTypeBlob,
108         BinaryTypeArrayBuffer
109     };
110     BinaryType m_binaryType;
111 
112     Timer<RTCDataChannel> m_scheduledEventTimer;
113     Vector<RefPtr<Event> > m_scheduledEvents;
114 };
115 
116 } // namespace WebCore
117 
118 #endif // RTCDataChannel_h
119