Changeset 249710 in webkit


Ignore:
Timestamp:
Sep 10, 2019 5:04:45 AM (5 years ago)
Author:
youenn@apple.com
Message:

Add support to RTCDataChannel.send(Blob)
https://bugs.webkit.org/show_bug.cgi?id=201377

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

  • web-platform-tests/webrtc/RTCDataChannel-send-blob-order-expected.txt: Added.
  • web-platform-tests/webrtc/RTCDataChannel-send-blob-order.html: Added.
  • web-platform-tests/webrtc/RTCDataChannel-send-expected.txt:

Source/WebCore:

Make use of NetworkSendQueue to enqueue and send properly messages.
Test: imported/w3c/web-platform-tests/webrtc/RTCDataChannel-send-blob-order.html

  • Modules/mediastream/RTCDataChannel.cpp:

(WebCore::RTCDataChannel::createMessageQueue):
(WebCore::RTCDataChannel::RTCDataChannel):
(WebCore::RTCDataChannel::send):
(WebCore::RTCDataChannel::close):

  • Modules/mediastream/RTCDataChannel.h:
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r249686 r249710  
     12019-09-10  Youenn Fablet  <youenn@apple.com>
     2
     3        Add support to RTCDataChannel.send(Blob)
     4        https://bugs.webkit.org/show_bug.cgi?id=201377
     5
     6        Reviewed by Chris Dumez.
     7
     8        * web-platform-tests/webrtc/RTCDataChannel-send-blob-order-expected.txt: Added.
     9        * web-platform-tests/webrtc/RTCDataChannel-send-blob-order.html: Added.
     10        * web-platform-tests/webrtc/RTCDataChannel-send-expected.txt:
     11
    1122019-09-09  Joonghun Park  <jh718.park@samsung.com>
    213
  • trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCDataChannel-send-expected.txt

    r244196 r249710  
    66PASS Data channel should be able to send Uint8Array message and receive as ArrayBuffer
    77PASS Data channel should be able to send ArrayBuffer message and receive as ArrayBuffer
    8 FAIL Data channel should be able to send Blob message and receive as ArrayBuffer promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
     8PASS Data channel should be able to send Blob message and receive as ArrayBuffer
    99PASS Data channel should be able to send ArrayBuffer message and receive as Blob
    1010FAIL Data channel binaryType should receive message as Blob by default assert_equals: Expect initial binaryType value to be blob expected "blob" but got "arraybuffer"
    11 FAIL Sending multiple messages with different types should succeed and be received assert_unreached: Unexpected promise rejection: NotSupportedError: The operation is not supported. Reached unreachable code
     11PASS Sending multiple messages with different types should succeed and be received
    1212
  • trunk/Source/WebCore/ChangeLog

    r249709 r249710  
     12019-09-10  Youenn Fablet  <youenn@apple.com>
     2
     3        Add support to RTCDataChannel.send(Blob)
     4        https://bugs.webkit.org/show_bug.cgi?id=201377
     5
     6        Reviewed by Chris Dumez.
     7
     8        Make use of NetworkSendQueue to enqueue and send properly messages.
     9        Test: imported/w3c/web-platform-tests/webrtc/RTCDataChannel-send-blob-order.html
     10
     11        * Modules/mediastream/RTCDataChannel.cpp:
     12        (WebCore::RTCDataChannel::createMessageQueue):
     13        (WebCore::RTCDataChannel::RTCDataChannel):
     14        (WebCore::RTCDataChannel::send):
     15        (WebCore::RTCDataChannel::close):
     16        * Modules/mediastream/RTCDataChannel.h:
     17
    1182019-09-10  Ryosuke Niwa  <rniwa@webkit.org>
    219
  • trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.cpp

    r248503 r249710  
    3030
    3131#include "Blob.h"
    32 #include "Event.h"
    3332#include "EventNames.h"
    3433#include "MessageEvent.h"
    35 #include "RTCDataChannelHandler.h"
    3634#include "ScriptExecutionContext.h"
    3735#include "SharedBuffer.h"
    38 #include <JavaScriptCore/ArrayBuffer.h>
    3936#include <JavaScriptCore/ArrayBufferView.h>
    4037#include <wtf/IsoMallocInlines.h>
     
    6764}
    6865
     66NetworkSendQueue RTCDataChannel::createMessageQueue(Document& document, RTCDataChannel& channel)
     67{
     68    return { document, [&channel](const String& data) {
     69        if (!channel.m_handler->sendStringData(data))
     70            channel.scriptExecutionContext()->addConsoleMessage(MessageSource::JS, MessageLevel::Error, "Error sending string through RTCDataChannel."_s);
     71    }, [&channel](auto* data, size_t length) {
     72        if (!channel.m_handler->sendRawData(data, length))
     73            channel.scriptExecutionContext()->addConsoleMessage(MessageSource::JS, MessageLevel::Error, "Error sending binary data through RTCDataChannel."_s);
     74    }, [&channel](int errorCode) {
     75        if (auto* context = channel.scriptExecutionContext())
     76            context->addConsoleMessage(MessageSource::JS, MessageLevel::Error, makeString("Error ", errorCode, " in retrieving a blob data to be sent through RTCDataChannel."));
     77        return NetworkSendQueue::Continue::Yes;
     78    } };
     79}
     80
    6981RTCDataChannel::RTCDataChannel(ScriptExecutionContext& context, std::unique_ptr<RTCDataChannelHandler>&& handler, String&& label, RTCDataChannelInit&& options)
    7082    : ActiveDOMObject(&context)
     
    7385    , m_label(WTFMove(label))
    7486    , m_options(WTFMove(options))
     87    , m_messageQueue(createMessageQueue(downcast<Document>(context), *this))
    7588{
    7689}
     
    115128        return Exception { InvalidStateError };
    116129
    117     if (!m_handler->sendStringData(data)) {
    118         // FIXME: Decide what the right exception here is.
    119         return Exception { SyntaxError };
    120     }
    121 
    122     return { };
    123 }
    124 
    125 ExceptionOr<void> RTCDataChannel::sendRawData(const char* data, size_t length)
    126 {
    127     if (m_readyState != RTCDataChannelState::Open)
    128         return Exception { InvalidStateError };
    129 
    130     if (!length)
    131         return { };
    132 
    133     if (!m_handler->sendRawData(data, length)) {
    134         // FIXME: Decide what the right exception here is.
    135         return Exception { SyntaxError };
    136     }
    137 
    138     return { };
    139 }
    140 
     130    m_messageQueue.enqueue(data);
     131    return { };
     132}
    141133
    142134ExceptionOr<void> RTCDataChannel::send(ArrayBuffer& data)
    143135{
    144     return sendRawData(static_cast<const char*>(data.data()), data.byteLength());
     136    if (m_readyState != RTCDataChannelState::Open)
     137        return Exception { InvalidStateError };
     138
     139    m_messageQueue.enqueue(data, 0, data.byteLength());
     140    return { };
    145141}
    146142
    147143ExceptionOr<void> RTCDataChannel::send(ArrayBufferView& data)
    148144{
    149     return sendRawData(static_cast<const char*>(data.baseAddress()), data.byteLength());
    150 }
    151 
    152 ExceptionOr<void> RTCDataChannel::send(Blob&)
    153 {
    154     // FIXME: Implement.
    155     return Exception { NotSupportedError };
     145    if (m_readyState != RTCDataChannelState::Open)
     146        return Exception { InvalidStateError };
     147
     148    m_messageQueue.enqueue(*data.unsharedBuffer(), data.byteOffset(), data.byteLength());
     149    return { };
     150}
     151
     152ExceptionOr<void> RTCDataChannel::send(Blob& blob)
     153{
     154    if (m_readyState != RTCDataChannelState::Open)
     155        return Exception { InvalidStateError };
     156
     157    m_messageQueue.enqueue(blob);
     158    return { };
    156159}
    157160
     
    163166    m_stopped = true;
    164167    m_readyState = RTCDataChannelState::Closed;
     168
     169    m_messageQueue.clear();
    165170
    166171    m_handler->close();
  • trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.h

    r246490 r249710  
    3232#include "EventTarget.h"
    3333#include "ExceptionOr.h"
     34#include "NetworkSendQueue.h"
    3435#include "RTCDataChannelHandler.h"
    3536#include "RTCDataChannelHandlerClient.h"
     
    8182    RTCDataChannel(ScriptExecutionContext&, std::unique_ptr<RTCDataChannelHandler>&&, String&&, RTCDataChannelInit&&);
    8283
     84    static NetworkSendQueue createMessageQueue(Document&, RTCDataChannel&);
     85
    8386    void scheduleDispatchEvent(Ref<Event>&&);
    8487    void scheduledEventTimerFired();
     
    8992    void refEventTarget() final { ref(); }
    9093    void derefEventTarget() final { deref(); }
    91 
    92     ExceptionOr<void> sendRawData(const char* data, size_t length);
    9394
    9495    // ActiveDOMObject API
     
    119120    RTCDataChannelInit m_options;
    120121    size_t m_bufferedAmountLowThreshold { 0 };
     122
     123    NetworkSendQueue m_messageQueue;
    121124};
    122125
Note: See TracChangeset for help on using the changeset viewer.