summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibProtocol
diff options
context:
space:
mode:
authorGuilherme Gonçalves <ggoncalves@google.com>2022-12-31 10:37:10 +0000
committerAndreas Kling <kling@serenityos.org>2023-02-02 14:41:34 +0100
commit230c0b34d4d87f4f7dc240d1e2aa236dd7b31399 (patch)
treef8b96ce4b0fe04aa8ad781730fed18bdbbf4a28a /Userland/Libraries/LibProtocol
parent9115e99e4b6e7f7f3624f4a12160d9859c30bbd3 (diff)
downloadserenity-230c0b34d4d87f4f7dc240d1e2aa236dd7b31399.zip
LibWeb+LibWebSocket: DOM WebSocket subprotocol support
This adds support for WebSocket subprotocols to WebSocket DOM objects, with some necessary plumbing to LibWebSocket and its clients. See the associated pull request for how this was tested.
Diffstat (limited to 'Userland/Libraries/LibProtocol')
-rw-r--r--Userland/Libraries/LibProtocol/WebSocket.cpp5
-rw-r--r--Userland/Libraries/LibProtocol/WebSocket.h2
-rw-r--r--Userland/Libraries/LibProtocol/WebSocketClient.cpp7
-rw-r--r--Userland/Libraries/LibProtocol/WebSocketClient.h1
4 files changed, 15 insertions, 0 deletions
diff --git a/Userland/Libraries/LibProtocol/WebSocket.cpp b/Userland/Libraries/LibProtocol/WebSocket.cpp
index fd85b64add..7d5b3cbe65 100644
--- a/Userland/Libraries/LibProtocol/WebSocket.cpp
+++ b/Userland/Libraries/LibProtocol/WebSocket.cpp
@@ -20,6 +20,11 @@ WebSocket::ReadyState WebSocket::ready_state()
return (WebSocket::ReadyState)m_client->ready_state({}, *this);
}
+DeprecatedString WebSocket::subprotocol_in_use()
+{
+ return m_client->subprotocol_in_use({}, *this);
+}
+
void WebSocket::send(ByteBuffer binary_or_text_message, bool is_text)
{
m_client->send({}, *this, move(binary_or_text_message), is_text);
diff --git a/Userland/Libraries/LibProtocol/WebSocket.h b/Userland/Libraries/LibProtocol/WebSocket.h
index d323a9edcf..eb7d859cba 100644
--- a/Userland/Libraries/LibProtocol/WebSocket.h
+++ b/Userland/Libraries/LibProtocol/WebSocket.h
@@ -53,6 +53,8 @@ public:
ReadyState ready_state();
+ DeprecatedString subprotocol_in_use();
+
void send(ByteBuffer binary_or_text_message, bool is_text);
void send(StringView text_message);
void close(u16 code = 1005, DeprecatedString reason = {});
diff --git a/Userland/Libraries/LibProtocol/WebSocketClient.cpp b/Userland/Libraries/LibProtocol/WebSocketClient.cpp
index b96d04951b..03e65268a3 100644
--- a/Userland/Libraries/LibProtocol/WebSocketClient.cpp
+++ b/Userland/Libraries/LibProtocol/WebSocketClient.cpp
@@ -34,6 +34,13 @@ u32 WebSocketClient::ready_state(Badge<WebSocket>, WebSocket& connection)
return IPCProxy::ready_state(connection.id());
}
+DeprecatedString WebSocketClient::subprotocol_in_use(Badge<WebSocket>, WebSocket& connection)
+{
+ if (!m_connections.contains(connection.id()))
+ return DeprecatedString::empty();
+ return IPCProxy::subprotocol_in_use(connection.id());
+}
+
void WebSocketClient::send(Badge<WebSocket>, WebSocket& connection, ByteBuffer data, bool is_text)
{
if (!m_connections.contains(connection.id()))
diff --git a/Userland/Libraries/LibProtocol/WebSocketClient.h b/Userland/Libraries/LibProtocol/WebSocketClient.h
index 60281c93c0..85d026ea6e 100644
--- a/Userland/Libraries/LibProtocol/WebSocketClient.h
+++ b/Userland/Libraries/LibProtocol/WebSocketClient.h
@@ -24,6 +24,7 @@ public:
RefPtr<WebSocket> connect(const URL&, DeprecatedString const& origin = {}, Vector<DeprecatedString> const& protocols = {}, Vector<DeprecatedString> const& extensions = {}, HashMap<DeprecatedString, DeprecatedString> const& request_headers = {});
u32 ready_state(Badge<WebSocket>, WebSocket&);
+ DeprecatedString subprotocol_in_use(Badge<WebSocket>, WebSocket&);
void send(Badge<WebSocket>, WebSocket&, ByteBuffer, bool is_text);
void close(Badge<WebSocket>, WebSocket&, u16 code, DeprecatedString reason);
bool set_certificate(Badge<WebSocket>, WebSocket&, DeprecatedString, DeprecatedString);