Source/WebCore/ChangeLog

 12012-10-12 Tommy Widenflycht <tommyw@google.com>
 2
 3 MediaStream API: Implement RTCDataChannel
 4 https://bugs.webkit.org/show_bug.cgi?id=99080
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 This patch introduces RTCDataChannel which is a pipe for sending data between two RTCPeerConnections.
 9 Since the data channel belongs to a peer connection object I have reused part of its infrastructure.
 10
 11 Not currently testable. My next patch will add the chromium WebKit functionality, together with mocks and tests.
 12
 13 * CMakeLists.txt:
 14 * GNUmakefile.list.am:
 15 * Modules/mediastream/RTCDataChannel.cpp: Added.
 16 (WebCore):
 17 (WebCore::RTCDataChannel::create):
 18 (WebCore::RTCDataChannel::RTCDataChannel):
 19 (WebCore::RTCDataChannel::~RTCDataChannel):
 20 (WebCore::RTCDataChannel::label):
 21 (WebCore::RTCDataChannel::reliable):
 22 (WebCore::RTCDataChannel::readyState):
 23 (WebCore::RTCDataChannel::bufferedAmount):
 24 (WebCore::RTCDataChannel::binaryType):
 25 (WebCore::RTCDataChannel::setBinaryType):
 26 (WebCore::RTCDataChannel::send):
 27 (WebCore::RTCDataChannel::close):
 28 (WebCore::RTCDataChannel::readyStateChanged):
 29 (WebCore::RTCDataChannel::dataArrived):
 30 (WebCore::RTCDataChannel::error):
 31 (WebCore::RTCDataChannel::descriptor):
 32 (WebCore::RTCDataChannel::interfaceName):
 33 (WebCore::RTCDataChannel::scriptExecutionContext):
 34 (WebCore::RTCDataChannel::stop):
 35 (WebCore::RTCDataChannel::eventTargetData):
 36 (WebCore::RTCDataChannel::ensureEventTargetData):
 37 * Modules/mediastream/RTCDataChannel.h: Added.
 38 (WebCore):
 39 (RTCDataChannel):
 40 (WebCore::RTCDataChannel::refEventTarget):
 41 (WebCore::RTCDataChannel::derefEventTarget):
 42 * Modules/mediastream/RTCDataChannel.idl: Added.
 43 * Modules/mediastream/RTCDataChannelEvent.cpp: Added.
 44 (WebCore):
 45 (WebCore::RTCDataChannelEvent::create):
 46 (WebCore::RTCDataChannelEvent::RTCDataChannelEvent):
 47 (WebCore::RTCDataChannelEvent::~RTCDataChannelEvent):
 48 (WebCore::RTCDataChannelEvent::channel):
 49 (WebCore::RTCDataChannelEvent::interfaceName):
 50 * Modules/mediastream/RTCDataChannelEvent.h: Added.
 51 (WebCore):
 52 (RTCDataChannelEvent):
 53 * Modules/mediastream/RTCDataChannelEvent.idl: Added.
 54 * Modules/mediastream/RTCPeerConnection.cpp:
 55 (WebCore::RTCPeerConnection::createDataChannel):
 56 (WebCore):
 57 (WebCore::RTCPeerConnection::close):
 58 (WebCore::RTCPeerConnection::didAddRemoteDataChannel):
 59 (WebCore::RTCPeerConnection::stop):
 60 * Modules/mediastream/RTCPeerConnection.h:
 61 (WebCore):
 62 (RTCPeerConnection):
 63 * Modules/mediastream/RTCPeerConnection.idl:
 64 * WebCore.gypi:
 65 * dom/EventNames.h:
 66 (WebCore):
 67 * dom/EventNames.in:
 68 * dom/EventTargetFactory.in:
 69 * platform/mediastream/RTCDataChannelDescriptor.cpp: Added.
 70 (WebCore):
 71 (WebCore::RTCDataChannelDescriptor::create):
 72 (WebCore::RTCDataChannelDescriptor::RTCDataChannelDescriptor):
 73 (WebCore::RTCDataChannelDescriptor::~RTCDataChannelDescriptor):
 74 (WebCore::RTCDataChannelDescriptor::readyStateChanged):
 75 (WebCore::RTCDataChannelDescriptor::dataArrived):
 76 (WebCore::RTCDataChannelDescriptor::error):
 77 * platform/mediastream/RTCDataChannelDescriptor.h: Added.
 78 (WebCore):
 79 (RTCDataChannelDescriptorClient):
 80 (WebCore::RTCDataChannelDescriptorClient::~RTCDataChannelDescriptorClient):
 81 (RTCDataChannelDescriptor):
 82 (ExtraData):
 83 (WebCore::RTCDataChannelDescriptor::ExtraData::~ExtraData):
 84 (WebCore::RTCDataChannelDescriptor::client):
 85 (WebCore::RTCDataChannelDescriptor::setClient):
 86 (WebCore::RTCDataChannelDescriptor::label):
 87 (WebCore::RTCDataChannelDescriptor::reliable):
 88 (WebCore::RTCDataChannelDescriptor::readyState):
 89 (WebCore::RTCDataChannelDescriptor::bufferedAmount):
 90 (WebCore::RTCDataChannelDescriptor::setBufferedAmount):
 91 (WebCore::RTCDataChannelDescriptor::extraData):
 92 (WebCore::RTCDataChannelDescriptor::setExtraData):
 93 * platform/mediastream/RTCPeerConnectionHandler.cpp:
 94 (RTCPeerConnectionHandlerDummy):
 95 (WebCore::RTCPeerConnectionHandlerDummy::openDataChannel):
 96 (WebCore):
 97 (WebCore::RTCPeerConnectionHandlerDummy::sendStringData):
 98 (WebCore::RTCPeerConnectionHandlerDummy::sendRawData):
 99 (WebCore::RTCPeerConnectionHandlerDummy::closeDataChannel):
 100 * platform/mediastream/RTCPeerConnectionHandler.h:
 101 (WebCore):
 102 (RTCPeerConnectionHandler):
 103 * platform/mediastream/RTCPeerConnectionHandlerClient.h:
 104 (WebCore):
 105 (RTCPeerConnectionHandlerClient):
 106 * platform/mediastream/chromium/RTCPeerConnectionHandlerChromium.cpp:
 107 (WebCore::RTCPeerConnectionHandlerChromium::openDataChannel):
 108 (WebCore):
 109 (WebCore::RTCPeerConnectionHandlerChromium::sendStringData):
 110 (WebCore::RTCPeerConnectionHandlerChromium::sendRawData):
 111 (WebCore::RTCPeerConnectionHandlerChromium::closeDataChannel):
 112 * platform/mediastream/chromium/RTCPeerConnectionHandlerChromium.h:
 113 (RTCPeerConnectionHandlerChromium):
 114
11152012-10-12 Balazs Kelemen <kbalazs@webkit.org>
2116
3117 Unreviewed, rolling out r130389.

Source/WebCore/CMakeLists.txt

@@SET(WebCore_IDL_FILES
224224 Modules/mediastream/NavigatorUserMediaErrorCallback.idl
225225 Modules/mediastream/NavigatorUserMediaSuccessCallback.idl
226226 Modules/mediastream/PeerConnection00.idl
 227 Modules/mediastream/RTCDataChannel.idl
 228 Modules/mediastream/RTCDataChannelEvent.idl
227229 Modules/mediastream/RTCErrorCallback.idl
228230 Modules/mediastream/RTCIceCandidate.idl
229231 Modules/mediastream/RTCIceCandidateEvent.idl

@@SET(WebCore_SOURCES
862864 Modules/mediastream/MediaStreamTrackList.cpp
863865 Modules/mediastream/NavigatorMediaStream.cpp
864866 Modules/mediastream/PeerConnection00.cpp
 867 Modules/mediastream/RTCDataChannel.cpp
 868 Modules/mediastream/RTCDataChannelEvent.cpp
865869 Modules/mediastream/RTCIceCandidate.cpp
866870 Modules/mediastream/RTCIceCandidateEvent.cpp
867871 Modules/mediastream/RTCPeerConnection.cpp

@@SET(WebCore_SOURCES
19591963 platform/mediastream/MediaStreamCenter.cpp
19601964 platform/mediastream/MediaStreamSource.cpp
19611965 platform/mediastream/PeerConnection00Handler.cpp
 1966 platform/mediastream/RTCDataChannelDescriptor.cpp
19621967 platform/mediastream/RTCIceCandidateDescriptor.cpp
19631968 platform/mediastream/RTCPeerConnectionHandler.cpp
19641969 platform/mediastream/RTCSessionDescriptionDescriptor.cpp

Source/WebCore/GNUmakefile.list.am

@@webcore_built_sources += \
627627 DerivedSources/WebCore/JSRequestAnimationFrameCallback.h \
628628 DerivedSources/WebCore/JSRGBColor.cpp \
629629 DerivedSources/WebCore/JSRGBColor.h \
 630 DerivedSources/WebCore/JSRTCDataChannel.cpp \
 631 DerivedSources/WebCore/JSRTCDataChannel.h \
 632 DerivedSources/WebCore/JSRTCDataChannelEvent.cpp \
 633 DerivedSources/WebCore/JSRTCDataChannelEvent.h \
630634 DerivedSources/WebCore/JSRTCErrorCallback.cpp \
631635 DerivedSources/WebCore/JSRTCErrorCallback.h \
632636 DerivedSources/WebCore/JSRTCIceCandidate.cpp \

@@dom_binding_idls += \
12361240 $(WebCore)/Modules/mediastream/NavigatorUserMediaErrorCallback.idl \
12371241 $(WebCore)/Modules/mediastream/NavigatorUserMediaSuccessCallback.idl \
12381242 $(WebCore)/Modules/mediastream/PeerConnection00.idl \
 1243 $(WebCore)/Modules/mediastream/RTCDataChannel.idl \
 1244 $(WebCore)/Modules/mediastream/RTCDataChannelEvent.idl \
12391245 $(WebCore)/Modules/mediastream/RTCErrorCallback.idl \
12401246 $(WebCore)/Modules/mediastream/RTCIceCandidate.idl \
12411247 $(WebCore)/Modules/mediastream/RTCIceCandidateEvent.idl \

@@webcore_modules_sources += \
19341940 Source/WebCore/Modules/mediastream/NavigatorUserMediaSuccessCallback.h \
19351941 Source/WebCore/Modules/mediastream/PeerConnection00.cpp \
19361942 Source/WebCore/Modules/mediastream/PeerConnection00.h \
 1943 Source/WebCore/Modules/mediastream/RTCDataChannel.cpp \
 1944 Source/WebCore/Modules/mediastream/RTCDataChannel.h \
 1945 Source/WebCore/Modules/mediastream/RTCDataChannelEvent.cpp \
 1946 Source/WebCore/Modules/mediastream/RTCDataChannelEvent.h \
19371947 Source/WebCore/Modules/mediastream/RTCErrorCallback.h \
19381948 Source/WebCore/Modules/mediastream/RTCIceCandidate.cpp \
19391949 Source/WebCore/Modules/mediastream/RTCIceCandidate.h \

@@webcore_sources += \
46124622 Source/WebCore/platform/mediastream/PeerConnection00Handler.h \
46134623 Source/WebCore/platform/mediastream/PeerConnection00HandlerClient.h \
46144624 Source/WebCore/platform/mediastream/RTCConfiguration.h \
 4625 Source/WebCore/platform/mediastream/RTCDataChannelDescriptor.cpp \
 4626 Source/WebCore/platform/mediastream/RTCDataChannelDescriptor.h \
46154627 Source/WebCore/platform/mediastream/RTCIceCandidateDescriptor.cpp \
46164628 Source/WebCore/platform/mediastream/RTCIceCandidateDescriptor.h \
4617  Source/WebCore/platform/mediastream/SessionDescriptionDescriptor.h \
46184629 Source/WebCore/platform/mediastream/RTCPeerConnectionHandler.cpp \
46194630 Source/WebCore/platform/mediastream/RTCPeerConnectionHandler.h \
46204631 Source/WebCore/platform/mediastream/RTCPeerConnectionHandlerClient.h \

Source/WebCore/Modules/mediastream/RTCDataChannel.cpp

 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#include "config.h"
 26
 27#if ENABLE(MEDIA_STREAM)
 28
 29#include "RTCDataChannel.h"
 30
 31#include "Blob.h"
 32#include "Event.h"
 33#include "ExceptionCode.h"
 34#include "MessageEvent.h"
 35#include "RTCPeerConnectionHandler.h"
 36#include "ScriptExecutionContext.h"
 37#include <wtf/ArrayBuffer.h>
 38#include <wtf/ArrayBufferView.h>
 39
 40namespace WebCore {
 41
 42PassRefPtr<RTCDataChannel> RTCDataChannel::create(ScriptExecutionContext* context, RTCPeerConnectionHandler* handler, const String& label, bool reliable, ExceptionCode& ec)
 43{
 44 ASSERT(handler);
 45 RefPtr<RTCDataChannel> dataChannel = create(context, handler, RTCDataChannelDescriptor::create(label, reliable));
 46 if (!handler->openDataChannel(dataChannel->descriptor())) {
 47 ec = NOT_SUPPORTED_ERR;
 48 return 0;
 49 }
 50 return dataChannel.release();
 51}
 52
 53PassRefPtr<RTCDataChannel> RTCDataChannel::create(ScriptExecutionContext* context, RTCPeerConnectionHandler* handler, PassRefPtr<RTCDataChannelDescriptor> descriptor)
 54{
 55 ASSERT(handler);
 56 ASSERT(descriptor);
 57 return adoptRef(new RTCDataChannel(context, handler, descriptor));
 58}
 59
 60RTCDataChannel::RTCDataChannel(ScriptExecutionContext* context, RTCPeerConnectionHandler* handler, PassRefPtr<RTCDataChannelDescriptor> descriptor)
 61 : m_scriptExecutionContext(context)
 62 , m_stopped(false)
 63 , m_descriptor(descriptor)
 64 , m_binaryType(BinaryTypeArrayBuffer)
 65 , m_handler(handler)
 66{
 67 m_descriptor->setClient(this);
 68}
 69
 70RTCDataChannel::~RTCDataChannel()
 71{
 72 m_descriptor->setClient(0);
 73}
 74
 75String RTCDataChannel::label() const
 76{
 77 return m_descriptor->label();
 78}
 79
 80bool RTCDataChannel::reliable() const
 81{
 82 return m_descriptor->reliable();
 83}
 84
 85String RTCDataChannel::readyState() const
 86{
 87 switch (m_descriptor->readyState()) {
 88 case RTCDataChannelDescriptor::ReadyStateConnecting:
 89 return ASCIILiteral("connecting");
 90 case RTCDataChannelDescriptor::ReadyStateOpen:
 91 return ASCIILiteral("open");
 92 case RTCDataChannelDescriptor::ReadyStateClosing:
 93 return ASCIILiteral("closing");
 94 case RTCDataChannelDescriptor::ReadyStateClosed:
 95 return ASCIILiteral("closed");
 96 }
 97
 98 ASSERT_NOT_REACHED();
 99 return String();
 100}
 101
 102unsigned long RTCDataChannel::bufferedAmount() const
 103{
 104 return m_descriptor->bufferedAmount();
 105}
 106
 107String RTCDataChannel::binaryType() const
 108{
 109 switch (m_binaryType) {
 110 case BinaryTypeBlob:
 111 return ASCIILiteral("blob");
 112 case BinaryTypeArrayBuffer:
 113 return ASCIILiteral("arraybuffer");
 114 }
 115 ASSERT_NOT_REACHED();
 116 return String();
 117}
 118
 119void RTCDataChannel::setBinaryType(const String& binaryType, ExceptionCode& ec)
 120{
 121 if (binaryType == "blob")
 122 ec = NOT_SUPPORTED_ERR;
 123 else if (binaryType == "arraybuffer")
 124 m_binaryType = BinaryTypeArrayBuffer;
 125 else
 126 ec = TYPE_MISMATCH_ERR;
 127}
 128
 129void RTCDataChannel::send(const String& data, ExceptionCode& ec)
 130{
 131 if (m_descriptor->readyState() != RTCDataChannelDescriptor::ReadyStateOpen) {
 132 ec = INVALID_STATE_ERR;
 133 return;
 134 }
 135 if (!m_handler->sendStringData(descriptor(), data)) {
 136 // FIXME: Decide what the right exception here is.
 137 ec = SYNTAX_ERR;
 138 }
 139}
 140
 141void RTCDataChannel::send(PassRefPtr<ArrayBuffer> prpData, ExceptionCode& ec)
 142{
 143 if (m_descriptor->readyState() != RTCDataChannelDescriptor::ReadyStateOpen) {
 144 ec = INVALID_STATE_ERR;
 145 return;
 146 }
 147
 148 RefPtr<ArrayBuffer> data = prpData;
 149
 150 size_t dataLength = data->byteLength();
 151 if (!dataLength)
 152 return;
 153
 154 const char* dataPointer = static_cast<const char*>(data->data());
 155
 156 if (!m_handler->sendRawData(descriptor(), dataPointer, dataLength)) {
 157 // FIXME: Decide what the right exception here is.
 158 ec = SYNTAX_ERR;
 159 }
 160}
 161
 162void RTCDataChannel::send(PassRefPtr<ArrayBufferView> data, ExceptionCode& ec)
 163{
 164 RefPtr<ArrayBuffer> arrayBuffer(data->buffer());
 165 send(arrayBuffer.release(), ec);
 166}
 167
 168void RTCDataChannel::send(PassRefPtr<Blob> data, ExceptionCode& ec)
 169{
 170 // FIXME: implement
 171 ec = NOT_SUPPORTED_ERR;
 172}
 173
 174void RTCDataChannel::close()
 175{
 176 if (m_stopped)
 177 return;
 178
 179 m_handler->closeDataChannel(descriptor());
 180}
 181
 182void RTCDataChannel::readyStateChanged()
 183{
 184 if (m_stopped)
 185 return;
 186
 187 switch (m_descriptor->readyState()) {
 188 case RTCDataChannelDescriptor::ReadyStateOpen:
 189 dispatchEvent(Event::create(eventNames().openEvent, false, false));
 190 break;
 191 case RTCDataChannelDescriptor::ReadyStateClosed:
 192 dispatchEvent(Event::create(eventNames().closeEvent, false, false));
 193 break;
 194 default:
 195 break;
 196 }
 197}
 198
 199void RTCDataChannel::dataArrived(const String& text)
 200{
 201 if (m_stopped)
 202 return;
 203
 204 dispatchEvent(MessageEvent::create(text));
 205}
 206
 207void RTCDataChannel::dataArrived(const char* data, size_t dataLength)
 208{
 209 if (m_stopped)
 210 return;
 211
 212 if (m_binaryType == BinaryTypeBlob) {
 213 // FIXME: Implement.
 214 return;
 215 }
 216 if (m_binaryType == BinaryTypeArrayBuffer) {
 217 RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(data, dataLength);
 218 dispatchEvent(MessageEvent::create(buffer.release()));
 219 return;
 220 }
 221 ASSERT_NOT_REACHED();
 222}
 223
 224void RTCDataChannel::error()
 225{
 226 if (m_stopped)
 227 return;
 228
 229 dispatchEvent(Event::create(eventNames().errorEvent, false, false));
 230}
 231
 232RTCDataChannelDescriptor* RTCDataChannel::descriptor()
 233{
 234 return m_descriptor.get();
 235}
 236
 237const AtomicString& RTCDataChannel::interfaceName() const
 238{
 239 return eventNames().interfaceForRTCDataChannel;
 240}
 241
 242ScriptExecutionContext* RTCDataChannel::scriptExecutionContext() const
 243{
 244 return m_scriptExecutionContext;
 245}
 246
 247void RTCDataChannel::stop()
 248{
 249 m_stopped = true;
 250 m_handler = 0;
 251 m_descriptor->setClient(0);
 252 m_scriptExecutionContext = 0;
 253}
 254
 255EventTargetData* RTCDataChannel::eventTargetData()
 256{
 257 return &m_eventTargetData;
 258}
 259
 260EventTargetData* RTCDataChannel::ensureEventTargetData()
 261{
 262 return &m_eventTargetData;
 263}
 264
 265} // namespace WebCore
 266
 267#endif // ENABLE(MEDIA_STREAM)

Source/WebCore/Modules/mediastream/RTCDataChannel.h

 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#if ENABLE(MEDIA_STREAM)
 29
 30#include "ActiveDOMObject.h"
 31#include "EventTarget.h"
 32#include "RTCDataChannelDescriptor.h"
 33#include <wtf/RefCounted.h>
 34
 35namespace WebCore {
 36class Blob;
 37class RTCPeerConnectionHandler;
 38
 39class RTCDataChannel : public RefCounted<RTCDataChannel>, public EventTarget, public RTCDataChannelDescriptorClient {
 40public:
 41 static PassRefPtr<RTCDataChannel> create(ScriptExecutionContext*, RTCPeerConnectionHandler*, const String& label, bool reliable, ExceptionCode&);
 42 static PassRefPtr<RTCDataChannel> create(ScriptExecutionContext*, RTCPeerConnectionHandler*, PassRefPtr<RTCDataChannelDescriptor>);
 43 ~RTCDataChannel();
 44
 45 String label() const;
 46
 47 bool reliable() const;
 48
 49 String readyState() const;
 50
 51 unsigned long bufferedAmount() const;
 52
 53 String binaryType() const;
 54 void setBinaryType(const String&, ExceptionCode&);
 55
 56 void send(const String&, ExceptionCode&);
 57 void send(PassRefPtr<ArrayBuffer>, ExceptionCode&);
 58 void send(PassRefPtr<ArrayBufferView>, ExceptionCode&);
 59 void send(PassRefPtr<Blob>, ExceptionCode&);
 60
 61 void close();
 62
 63 DEFINE_ATTRIBUTE_EVENT_LISTENER(open);
 64 DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
 65 DEFINE_ATTRIBUTE_EVENT_LISTENER(close);
 66 DEFINE_ATTRIBUTE_EVENT_LISTENER(message);
 67
 68 RTCDataChannelDescriptor* descriptor();
 69 void stop();
 70
 71 // EventTarget
 72 virtual const AtomicString& interfaceName() const OVERRIDE;
 73 virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE;
 74
 75 using RefCounted<RTCDataChannel>::ref;
 76 using RefCounted<RTCDataChannel>::deref;
 77
 78private:
 79 RTCDataChannel(ScriptExecutionContext*, RTCPeerConnectionHandler*, PassRefPtr<RTCDataChannelDescriptor>);
 80
 81 // EventTarget
 82 virtual EventTargetData* eventTargetData();
 83 virtual EventTargetData* ensureEventTargetData();
 84 virtual void refEventTarget() { ref(); }
 85 virtual void derefEventTarget() { deref(); }
 86 EventTargetData m_eventTargetData;
 87 ScriptExecutionContext* m_scriptExecutionContext;
 88
 89 // RTCDataChannelDescriptor::Owner
 90 virtual void readyStateChanged() OVERRIDE;
 91 virtual void dataArrived(const String&) OVERRIDE;
 92 virtual void dataArrived(const char*, size_t) OVERRIDE;
 93 virtual void error() OVERRIDE;
 94
 95 bool m_stopped;
 96 RefPtr<RTCDataChannelDescriptor> m_descriptor;
 97
 98 enum BinaryType {
 99 BinaryTypeBlob,
 100 BinaryTypeArrayBuffer
 101 };
 102 BinaryType m_binaryType;
 103
 104 // Not owned by this class.
 105 RTCPeerConnectionHandler* m_handler;
 106};
 107
 108} // namespace WebCore
 109
 110#endif // ENABLE(MEDIA_STREAM)
 111
 112#endif // RTCDataChannel_h

Source/WebCore/Modules/mediastream/RTCDataChannel.idl

 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
 25interface [
 26 Conditional=MEDIA_STREAM,
 27 EventTarget
 28] RTCDataChannel {
 29 readonly attribute DOMString label;
 30 readonly attribute boolean reliable;
 31 readonly attribute DOMString readyState;
 32 readonly attribute unsigned long bufferedAmount;
 33
 34 attribute DOMString binaryType
 35 setter raises(DOMException);
 36
 37 void send(in ArrayBuffer data)
 38 raises(DOMException);
 39 void send(in ArrayBufferView data)
 40 raises(DOMException);
 41 void send(in Blob data)
 42 raises(DOMException);
 43 void send(in DOMString data)
 44 raises(DOMException);
 45
 46 void close();
 47
 48 attribute EventListener onopen;
 49 attribute EventListener onerror;
 50 attribute EventListener onclose;
 51 attribute EventListener onmessage;
 52
 53 // EventTarget interface
 54 void addEventListener(in DOMString type,
 55 in EventListener listener,
 56 in [Optional] boolean useCapture);
 57 void removeEventListener(in DOMString type,
 58 in EventListener listener,
 59 in [Optional] boolean useCapture);
 60 boolean dispatchEvent(in Event event)
 61 raises(EventException);
 62};

Source/WebCore/Modules/mediastream/RTCDataChannelEvent.cpp

 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#include "config.h"
 26#include "RTCDataChannelEvent.h"
 27
 28#if ENABLE(MEDIA_STREAM)
 29
 30#include "EventNames.h"
 31#include "RTCDataChannel.h"
 32
 33namespace WebCore {
 34
 35PassRefPtr<RTCDataChannelEvent> RTCDataChannelEvent::create()
 36{
 37 return adoptRef(new RTCDataChannelEvent);
 38}
 39
 40PassRefPtr<RTCDataChannelEvent> RTCDataChannelEvent::create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<RTCDataChannel> channel)
 41{
 42 return adoptRef(new RTCDataChannelEvent(type, canBubble, cancelable, channel));
 43}
 44
 45
 46RTCDataChannelEvent::RTCDataChannelEvent()
 47{
 48}
 49
 50RTCDataChannelEvent::RTCDataChannelEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<RTCDataChannel> channel)
 51 : Event(type, canBubble, cancelable)
 52 , m_channel(channel)
 53{
 54}
 55
 56RTCDataChannelEvent::~RTCDataChannelEvent()
 57{
 58}
 59
 60RTCDataChannel* RTCDataChannelEvent::channel() const
 61{
 62 return m_channel.get();
 63}
 64
 65const AtomicString& RTCDataChannelEvent::interfaceName() const
 66{
 67 return eventNames().interfaceForRTCDataChannelEvent;
 68}
 69
 70} // namespace WebCore
 71
 72#endif // ENABLE(MEDIA_STREAM)
 73

Source/WebCore/Modules/mediastream/RTCDataChannelEvent.h

 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 RTCDataChannelEvent_h
 26#define RTCDataChannelEvent_h
 27
 28#if ENABLE(MEDIA_STREAM)
 29
 30#include "Event.h"
 31#include "RTCDataChannel.h"
 32#include <wtf/text/AtomicString.h>
 33
 34namespace WebCore {
 35
 36class RTCDataChannelEvent : public Event {
 37public:
 38 virtual ~RTCDataChannelEvent();
 39
 40 static PassRefPtr<RTCDataChannelEvent> create();
 41 static PassRefPtr<RTCDataChannelEvent> create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<RTCDataChannel>);
 42
 43 RTCDataChannel* channel() const;
 44
 45 virtual const AtomicString& interfaceName() const;
 46
 47private:
 48 RTCDataChannelEvent();
 49 RTCDataChannelEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<RTCDataChannel>);
 50
 51 RefPtr<RTCDataChannel> m_channel;
 52};
 53
 54} // namespace WebCore
 55
 56#endif // ENABLE(MEDIA_STREAM)
 57
 58#endif // RTCDataChannelEvent_h

Source/WebCore/Modules/mediastream/RTCDataChannelEvent.idl

 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
 25interface [
 26 Conditional=MEDIA_STREAM,
 27] RTCDataChannelEvent : Event {
 28 readonly attribute RTCDataChannel channel;
 29};

Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp

4343#include "MediaConstraintsImpl.h"
4444#include "MediaStreamEvent.h"
4545#include "RTCConfiguration.h"
 46#include "RTCDataChannel.h"
 47#include "RTCDataChannelEvent.h"
4648#include "RTCErrorCallback.h"
4749#include "RTCIceCandidate.h"
4850#include "RTCIceCandidateDescriptor.h"

@@void RTCPeerConnection::getStats(PassRefPtr<RTCStatsCallback> successCallback, P
408410 m_peerHandler->getStats(statsRequest.release());
409411}
410412
 413PassRefPtr<RTCDataChannel> RTCPeerConnection::createDataChannel(String label, const Dictionary& options, ExceptionCode& ec)
 414{
 415 if (m_readyState == ReadyStateClosed) {
 416 ec = INVALID_STATE_ERR;
 417 return 0;
 418 }
 419
 420 bool reliable = true;
 421 options.get("reliable", reliable);
 422 RefPtr<RTCDataChannel> channel = RTCDataChannel::create(scriptExecutionContext(), m_peerHandler.get(), label, reliable, ec);
 423 if (ec)
 424 return 0;
 425 m_dataChannels.append(channel);
 426 return channel.release();
 427}
 428
411429void RTCPeerConnection::close(ExceptionCode& ec)
412430{
413431 if (m_readyState == ReadyStateClosing || m_readyState == ReadyStateClosed) {

@@void RTCPeerConnection::close(ExceptionCode& ec)
415433 return;
416434 }
417435
 436 m_peerHandler->stop();
 437
418438 changeIceState(IceStateClosed);
419439 changeReadyState(ReadyStateClosed);
420  stop();
421440}
422441
423442void RTCPeerConnection::negotiationNeeded()

@@void RTCPeerConnection::didRemoveRemoteStream(MediaStreamDescriptor* streamDescr
478497 dispatchEvent(MediaStreamEvent::create(eventNames().removestreamEvent, false, false, stream.release()));
479498}
480499
 500void RTCPeerConnection::didAddRemoteDataChannel(PassRefPtr<RTCDataChannelDescriptor> channelDescriptor)
 501{
 502 ASSERT(scriptExecutionContext()->isContextThread());
 503
 504 if (m_readyState == ReadyStateClosed)
 505 return;
 506
 507 RefPtr<RTCDataChannel> channel = RTCDataChannel::create(scriptExecutionContext(), m_peerHandler.get(), channelDescriptor);
 508 m_dataChannels.append(channel);
 509
 510 dispatchEvent(RTCDataChannelEvent::create(eventNames().datachannelEvent, false, false, channel.release()));
 511}
 512
481513const AtomicString& RTCPeerConnection::interfaceName() const
482514{
483515 return eventNames().interfaceForRTCPeerConnection;

@@ScriptExecutionContext* RTCPeerConnection::scriptExecutionContext() const
490522
491523void RTCPeerConnection::stop()
492524{
 525 if (m_readyState != ReadyStateClosed)
 526 m_peerHandler->stop();
 527
 528 m_peerHandler.clear();
 529
493530 m_iceState = IceStateClosed;
494531 m_readyState = ReadyStateClosed;
495532
496  if (m_peerHandler) {
497  m_peerHandler->stop();
498  m_peerHandler.clear();
499  }
 533 Vector<RefPtr<RTCDataChannel> >::iterator i = m_dataChannels.begin();
 534 for (; i != m_dataChannels.end(); ++i)
 535 (*i)->stop();
500536}
501537
502538EventTargetData* RTCPeerConnection::eventTargetData()

Source/WebCore/Modules/mediastream/RTCPeerConnection.h

@@namespace WebCore {
4949class MediaConstraints;
5050class MediaStreamTrack;
5151class RTCConfiguration;
 52class RTCDataChannel;
5253class RTCErrorCallback;
5354class RTCSessionDescription;
5455class RTCSessionDescriptionCallback;

@@public:
8889
8990 void getStats(PassRefPtr<RTCStatsCallback> successCallback, PassRefPtr<MediaStreamTrack> selector);
9091
 92 PassRefPtr<RTCDataChannel> createDataChannel(String label, const Dictionary& dataChannelDict, ExceptionCode&);
 93
9194 void close(ExceptionCode&);
9295
9396 DEFINE_ATTRIBUTE_EVENT_LISTENER(negotiationneeded);

@@public:
97100 DEFINE_ATTRIBUTE_EVENT_LISTENER(addstream);
98101 DEFINE_ATTRIBUTE_EVENT_LISTENER(removestream);
99102 DEFINE_ATTRIBUTE_EVENT_LISTENER(icechange);
 103 DEFINE_ATTRIBUTE_EVENT_LISTENER(datachannel);
100104
101105 // RTCPeerConnectionHandlerClient
102106 virtual void negotiationNeeded() OVERRIDE;

@@public:
105109 virtual void didChangeIceState(IceState) OVERRIDE;
106110 virtual void didAddRemoteStream(PassRefPtr<MediaStreamDescriptor>) OVERRIDE;
107111 virtual void didRemoveRemoteStream(MediaStreamDescriptor*) OVERRIDE;
 112 virtual void didAddRemoteDataChannel(PassRefPtr<RTCDataChannelDescriptor>) OVERRIDE;
108113
109114 // EventTarget
110115 virtual const AtomicString& interfaceName() const OVERRIDE;

@@private:
137142 RefPtr<MediaStreamList> m_localStreams;
138143 RefPtr<MediaStreamList> m_remoteStreams;
139144
 145 Vector<RefPtr<RTCDataChannel> > m_dataChannels;
 146
140147 OwnPtr<RTCPeerConnectionHandler> m_peerHandler;
141148};
142149

Source/WebCore/Modules/mediastream/RTCPeerConnection.idl

@@interface [
7272
7373 void getStats(in [Callback] RTCStatsCallback successCallback, in [Optional=DefaultIsUndefined] MediaStreamTrack selector);
7474
 75 RTCDataChannel createDataChannel(in [TreatNullAs=NullString, TreatUndefinedAs=NullString] DOMString label, in [Optional=DefaultIsUndefined] Dictionary options)
 76 raises(DOMException);
 77
7578 void close()
7679 raises(DOMException);
7780

@@interface [
8285 attribute EventListener onaddstream;
8386 attribute EventListener onremovestream;
8487 attribute EventListener onicechange;
 88 attribute EventListener ondatachannel;
8589
8690 // EventTarget interface
8791 void addEventListener(in DOMString type,

Source/WebCore/WebCore.gypi

457457 'platform/mediastream/PeerConnection00Handler.h',
458458 'platform/mediastream/PeerConnection00HandlerClient.h',
459459 'platform/mediastream/RTCConfiguration.h',
 460 'platform/mediastream/RTCDataChannelDescriptor.cpp',
 461 'platform/mediastream/RTCDataChannelDescriptor.h',
460462 'platform/mediastream/RTCIceCandidateDescriptor.cpp',
461463 'platform/mediastream/RTCIceCandidateDescriptor.h',
462464 'platform/mediastream/RTCPeerConnectionHandler.h',

867869 'Modules/mediastream/NavigatorUserMediaErrorCallback.idl',
868870 'Modules/mediastream/NavigatorUserMediaSuccessCallback.idl',
869871 'Modules/mediastream/PeerConnection00.idl',
 872 'Modules/mediastream/RTCDataChannel.idl',
 873 'Modules/mediastream/RTCDataChannelEvent.idl',
870874 'Modules/mediastream/RTCErrorCallback.idl',
871875 'Modules/mediastream/RTCIceCandidate.idl',
872876 'Modules/mediastream/RTCIceCandidateEvent.idl',

16121616 'Modules/mediastream/NavigatorUserMediaSuccessCallback.h',
16131617 'Modules/mediastream/PeerConnection00.cpp',
16141618 'Modules/mediastream/PeerConnection00.h',
 1619 'Modules/mediastream/RTCDataChannel.h',
 1620 'Modules/mediastream/RTCDataChannel.cpp',
 1621 'Modules/mediastream/RTCDataChannelEvent.h',
 1622 'Modules/mediastream/RTCDataChannelEvent.cpp',
16151623 'Modules/mediastream/RTCErrorCallback.h',
16161624 'Modules/mediastream/RTCIceCandidate.cpp',
16171625 'Modules/mediastream/RTCIceCandidate.h',

Source/WebCore/dom/EventNames.h

@@namespace WebCore {
228228 macro(icechange) \
229229 macro(icecandidate) \
230230 macro(negotiationneeded) \
 231 macro(datachannel) \
231232 \
232233 macro(show) \
233234 \

Source/WebCore/dom/EventNames.in

@@OfflineAudioCompletionEvent conditional=WEB_AUDIO
3232MediaStreamEvent conditional=MEDIA_STREAM
3333MediaStreamTrackEvent conditional=MEDIA_STREAM
3434RTCIceCandidateEvent conditional=MEDIA_STREAM
 35RTCDataChannelEvent conditional=MEDIA_STREAM
3536SpeechInputEvent conditional=INPUT_SPEECH
3637SpeechRecognitionError conditional=SCRIPTED_SPEECH
3738SpeechRecognitionEvent conditional=SCRIPTED_SPEECH

Source/WebCore/dom/EventTargetFactory.in

@@Node
2626Notification conditional=NOTIFICATIONS|LEGACY_NOTIFICATIONS
2727PeerConnection00 conditional=MEDIA_STREAM
2828Performance conditional=WEB_TIMING
 29RTCDataChannel conditional=MEDIA_STREAM
2930RTCPeerConnection conditional=MEDIA_STREAM
3031SharedWorker conditional=SHARED_WORKERS
3132SharedWorkerContext conditional=SHARED_WORKERS

Source/WebCore/platform/mediastream/RTCDataChannelDescriptor.cpp

 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#include "config.h"
 26
 27#if ENABLE(MEDIA_STREAM)
 28
 29#include "RTCDataChannelDescriptor.h"
 30
 31namespace WebCore {
 32
 33PassRefPtr<RTCDataChannelDescriptor> RTCDataChannelDescriptor::create(const String& label, bool reliable)
 34{
 35 return adoptRef(new RTCDataChannelDescriptor(label, reliable));
 36}
 37
 38RTCDataChannelDescriptor::RTCDataChannelDescriptor(const String& label, bool reliable)
 39 : m_label(label)
 40 , m_reliable(reliable)
 41 , m_readyState(ReadyStateConnecting)
 42 , m_bufferedAmount(0)
 43{
 44}
 45
 46RTCDataChannelDescriptor::~RTCDataChannelDescriptor()
 47{
 48}
 49
 50void RTCDataChannelDescriptor::readyStateChanged(ReadyState readyState)
 51{
 52 ASSERT(m_readyState != ReadyStateClosed);
 53 if (m_readyState != readyState && m_client) {
 54 m_readyState = readyState;
 55 m_client->readyStateChanged();
 56 }
 57}
 58
 59void RTCDataChannelDescriptor::dataArrived(const String& data)
 60{
 61 ASSERT(m_readyState != ReadyStateClosed);
 62 if (m_client)
 63 m_client->dataArrived(data);
 64}
 65
 66void RTCDataChannelDescriptor::dataArrived(const char* data, size_t dataLength)
 67{
 68 ASSERT(m_readyState != ReadyStateClosed);
 69 if (m_client)
 70 m_client->dataArrived(data, dataLength);
 71}
 72
 73void RTCDataChannelDescriptor::error()
 74{
 75 ASSERT(m_readyState != ReadyStateClosed);
 76 if (m_client)
 77 m_client->error();
 78}
 79
 80} // namespace WebCore
 81
 82#endif // ENABLE(MEDIA_STREAM)

Source/WebCore/platform/mediastream/RTCDataChannelDescriptor.h

 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 RTCDataChannelDescriptor_h
 26#define RTCDataChannelDescriptor_h
 27
 28#if ENABLE(MEDIA_STREAM)
 29
 30#include <wtf/RefCounted.h>
 31#include <wtf/Vector.h>
 32#include <wtf/text/WTFString.h>
 33
 34namespace WebCore {
 35
 36class RTCDataChannelDescriptorClient {
 37public:
 38 virtual ~RTCDataChannelDescriptorClient() { }
 39
 40 virtual void readyStateChanged() = 0;
 41 virtual void dataArrived(const String&) = 0;
 42 virtual void dataArrived(const char*, size_t) = 0;
 43 virtual void error() = 0;
 44};
 45
 46class RTCDataChannelDescriptor : public RefCounted<RTCDataChannelDescriptor> {
 47public:
 48 class ExtraData : public RefCounted<ExtraData> {
 49 public:
 50 virtual ~ExtraData() { }
 51 };
 52
 53 enum ReadyState {
 54 ReadyStateConnecting = 0,
 55 ReadyStateOpen = 1,
 56 ReadyStateClosing = 2,
 57 ReadyStateClosed = 3,
 58 };
 59
 60 static PassRefPtr<RTCDataChannelDescriptor> create(const String& label, bool reliable);
 61 virtual ~RTCDataChannelDescriptor();
 62
 63 RTCDataChannelDescriptorClient* client() const { return m_client; }
 64 void setClient(RTCDataChannelDescriptorClient* client) { m_client = client; }
 65
 66 const String& label() const { return m_label; }
 67 bool reliable() const { return m_reliable; }
 68
 69 ReadyState readyState() const { return m_readyState; }
 70
 71 unsigned long bufferedAmount() const { return m_bufferedAmount; }
 72 void setBufferedAmount(unsigned long bufferedAmount) { m_bufferedAmount = bufferedAmount; }
 73
 74 void readyStateChanged(ReadyState);
 75 void dataArrived(const String&);
 76 void dataArrived(const char*, size_t);
 77 void error();
 78
 79 PassRefPtr<ExtraData> extraData() const { return m_extraData; }
 80 void setExtraData(PassRefPtr<ExtraData> extraData) { m_extraData = extraData; }
 81
 82private:
 83 RTCDataChannelDescriptor(const String& label, bool reliable);
 84
 85 RTCDataChannelDescriptorClient* m_client;
 86 String m_label;
 87 bool m_reliable;
 88 ReadyState m_readyState;
 89 unsigned long m_bufferedAmount;
 90 RefPtr<ExtraData> m_extraData;
 91};
 92
 93} // namespace WebCore
 94
 95#endif // ENABLE(MEDIA_STREAM)
 96
 97#endif // RTCDataChannelDescriptor_h

Source/WebCore/platform/mediastream/RTCPeerConnectionHandler.cpp

@@public:
6262 virtual void getStats(PassRefPtr<RTCStatsRequest>) OVERRIDE;
6363 virtual void stop() OVERRIDE;
6464
 65 // RTCDataChannel.
 66 virtual bool openDataChannel(PassRefPtr<RTCDataChannelDescriptor>) OVERRIDE;
 67 virtual bool sendStringData(PassRefPtr<RTCDataChannelDescriptor>, const String&) OVERRIDE;
 68 virtual bool sendRawData(PassRefPtr<RTCDataChannelDescriptor>, const char*, size_t) OVERRIDE;
 69 virtual void closeDataChannel(PassRefPtr<RTCDataChannelDescriptor>) OVERRIDE;
 70
6571private:
6672 RTCPeerConnectionHandlerClient* m_client;
6773};

@@void RTCPeerConnectionHandlerDummy::stop()
139145{
140146}
141147
 148bool RTCPeerConnectionHandlerDummy::openDataChannel(PassRefPtr<RTCDataChannelDescriptor>)
 149{
 150 return false;
 151}
 152
 153bool RTCPeerConnectionHandlerDummy::sendStringData(PassRefPtr<RTCDataChannelDescriptor>, const String&)
 154{
 155 return false;
 156}
 157
 158bool RTCPeerConnectionHandlerDummy::sendRawData(PassRefPtr<RTCDataChannelDescriptor>, const char*, size_t)
 159{
 160 return false;
 161}
 162
 163void RTCPeerConnectionHandlerDummy::closeDataChannel(PassRefPtr<RTCDataChannelDescriptor>)
 164{
 165}
 166
142167} // namespace WebCore
143168
144169#endif // ENABLE(MEDIA_STREAM)

Source/WebCore/platform/mediastream/RTCPeerConnectionHandler.h

@@namespace WebCore {
4141
4242class MediaConstraints;
4343class RTCConfiguration;
 44class RTCDataChannelDescriptor;
4445class RTCIceCandidateDescriptor;
4546class RTCPeerConnectionHandlerClient;
4647class RTCSessionDescriptionDescriptor;

@@public:
6869 virtual void getStats(PassRefPtr<RTCStatsRequest>) = 0;
6970 virtual void stop() = 0;
7071
 72 // RTCDataChannel.
 73 virtual bool openDataChannel(PassRefPtr<RTCDataChannelDescriptor>) = 0;
 74 virtual bool sendStringData(PassRefPtr<RTCDataChannelDescriptor>, const String&) = 0;
 75 virtual bool sendRawData(PassRefPtr<RTCDataChannelDescriptor>, const char*, size_t) = 0;
 76 virtual void closeDataChannel(PassRefPtr<RTCDataChannelDescriptor>) = 0;
 77
7178protected:
7279 RTCPeerConnectionHandler() { }
7380};

Source/WebCore/platform/mediastream/RTCPeerConnectionHandlerClient.h

3838namespace WebCore {
3939
4040class MediaStreamDescriptor;
 41class RTCDataChannelDescriptor;
4142class RTCIceCandidateDescriptor;
4243
4344class RTCPeerConnectionHandlerClient {

@@public:
6970 virtual void didChangeIceState(IceState) = 0;
7071 virtual void didAddRemoteStream(PassRefPtr<MediaStreamDescriptor>) = 0;
7172 virtual void didRemoveRemoteStream(MediaStreamDescriptor*) = 0;
 73
 74 // RTCDataChannel.
 75 virtual void didAddRemoteDataChannel(PassRefPtr<RTCDataChannelDescriptor>) = 0;
7276};
7377
7478} // namespace WebCore

Source/WebCore/platform/mediastream/chromium/RTCPeerConnectionHandlerChromium.cpp

3636
3737#include "MediaConstraints.h"
3838#include "RTCConfiguration.h"
 39#include "RTCDataChannelDescriptor.h"
3940#include "RTCIceCandidateDescriptor.h"
4041#include "RTCPeerConnectionHandlerClient.h"
4142#include "RTCSessionDescriptionDescriptor.h"

@@void RTCPeerConnectionHandlerChromium::didRemoveRemoteStream(const WebKit::WebMe
212213 m_client->didRemoveRemoteStream(webMediaStreamDescriptor);
213214}
214215
 216bool RTCPeerConnectionHandlerChromium::openDataChannel(PassRefPtr<RTCDataChannelDescriptor> dataChannel)
 217{
 218 // FIXME: Implement when WebKit changes have landed.
 219 return false;
 220}
 221
 222bool RTCPeerConnectionHandlerChromium::sendStringData(PassRefPtr<RTCDataChannelDescriptor> dataChannel, const String& data)
 223{
 224 // FIXME: Implement when WebKit changes have landed.
 225 return false;
 226}
 227
 228bool RTCPeerConnectionHandlerChromium::sendRawData(PassRefPtr<RTCDataChannelDescriptor> dataChannel, const char* data, size_t dataLength)
 229{
 230 // FIXME: Implement when WebKit changes have landed.
 231 return false;
 232}
 233
 234void RTCPeerConnectionHandlerChromium::closeDataChannel(PassRefPtr<RTCDataChannelDescriptor> dataChannel)
 235{
 236 // FIXME: Implement when WebKit changes have landed.
 237}
 238
215239} // namespace WebCore
216240
217241#endif // ENABLE(MEDIA_STREAM)

Source/WebCore/platform/mediastream/chromium/RTCPeerConnectionHandlerChromium.h

@@public:
6767 virtual void getStats(PassRefPtr<RTCStatsRequest>) OVERRIDE;
6868 virtual void stop() OVERRIDE;
6969
 70 virtual bool openDataChannel(PassRefPtr<RTCDataChannelDescriptor>) OVERRIDE;
 71 virtual bool sendStringData(PassRefPtr<RTCDataChannelDescriptor>, const String&) OVERRIDE;
 72 virtual bool sendRawData(PassRefPtr<RTCDataChannelDescriptor>, const char*, size_t) OVERRIDE;
 73 virtual void closeDataChannel(PassRefPtr<RTCDataChannelDescriptor>) OVERRIDE;
 74
7075 // WebKit::WebRTCPeerConnectionHandlerClient implementation.
7176 virtual void negotiationNeeded() OVERRIDE;
7277 virtual void didGenerateICECandidate(const WebKit::WebRTCICECandidate&) OVERRIDE;