summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorserenitydev <ben.d.abraham@gmail.com>2022-02-11 03:43:03 -0500
committerAndreas Kling <kling@serenityos.org>2022-02-12 12:16:02 +0100
commit8c29cc879d9d67d81ca65d0b23bae601a877f942 (patch)
treeb3ea8ee98401d327cacf8c7b88f0dc5602301130 /Userland/Libraries/LibWeb
parent32053e8f25166625ba1331ac38d51658cf89a880 (diff)
downloadserenity-8c29cc879d9d67d81ca65d0b23bae601a877f942.zip
LibWeb: Add support for 'arraybuffer' message types on WebSockets
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/HTML/WebSocket.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/WebSocket.cpp b/Userland/Libraries/LibWeb/HTML/WebSocket.cpp
index f20fe1a87e..2c79cf52db 100644
--- a/Userland/Libraries/LibWeb/HTML/WebSocket.cpp
+++ b/Userland/Libraries/LibWeb/HTML/WebSocket.cpp
@@ -6,6 +6,7 @@
#include <LibJS/Interpreter.h>
#include <LibJS/Parser.h>
+#include <LibJS/Runtime/ArrayBuffer.h>
#include <LibJS/Runtime/FunctionObject.h>
#include <LibProtocol/WebSocket.h>
#include <LibProtocol/WebSocketClient.h>
@@ -209,14 +210,27 @@ void WebSocket::on_message(ByteBuffer message, bool is_text)
return;
if (is_text) {
auto text_message = String(ReadonlyBytes(message));
- MessageEventInit event_init {};
+ MessageEventInit event_init;
event_init.data = JS::js_string(wrapper()->vm(), text_message);
event_init.origin = url();
dispatch_event(MessageEvent::create(EventNames::message, event_init));
return;
}
- // type indicates that the data is Binary and binaryType is "blob"
- // type indicates that the data is Binary and binaryType is "arraybuffer"
+
+ if (m_binary_type == "blob") {
+ // type indicates that the data is Binary and binaryType is "blob"
+ TODO();
+ } else if (m_binary_type == "arraybuffer") {
+ // type indicates that the data is Binary and binaryType is "arraybuffer"
+ auto& global_object = wrapper()->global_object();
+ MessageEventInit event_init;
+ event_init.data = JS::ArrayBuffer::create(global_object, message);
+ event_init.origin = url();
+ dispatch_event(MessageEvent::create(EventNames::message, event_init));
+ return;
+ }
+
+ dbgln("Unsupported WebSocket message type {}", m_binary_type);
TODO();
}