1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:48:12 +00:00

Everywhere: Merge the WebSocket service into RequestServer

This keeps the APIs separate as they are wildly different, a future
improvement could be to somehow unify the APIs (if possible).

Closes #23080.
This commit is contained in:
Ali Mohammad Pur 2024-03-06 01:50:52 +01:00 committed by Jelle Raaijmakers
parent daf5484d6b
commit 6dfb2f9dc8
56 changed files with 231 additions and 845 deletions

View file

@ -4,12 +4,12 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibProtocol/RequestClient.h>
#include <LibProtocol/WebSocket.h>
#include <LibProtocol/WebSocketClient.h>
namespace Protocol {
WebSocket::WebSocket(WebSocketClient& client, i32 connection_id)
WebSocket::WebSocket(RequestClient& client, i32 connection_id)
: m_client(client)
, m_connection_id(connection_id)
{
@ -17,17 +17,17 @@ WebSocket::WebSocket(WebSocketClient& client, i32 connection_id)
WebSocket::ReadyState WebSocket::ready_state()
{
return (WebSocket::ReadyState)m_client->ready_state({}, *this);
return static_cast<WebSocket::ReadyState>(m_client->websocket_ready_state(m_connection_id));
}
ByteString WebSocket::subprotocol_in_use()
{
return m_client->subprotocol_in_use({}, *this);
return m_client->websocket_subprotocol_in_use(m_connection_id);
}
void WebSocket::send(ByteBuffer binary_or_text_message, bool is_text)
{
m_client->send({}, *this, move(binary_or_text_message), is_text);
m_client->async_websocket_send(m_connection_id, is_text, move(binary_or_text_message));
}
void WebSocket::send(StringView text_message)
@ -37,38 +37,38 @@ void WebSocket::send(StringView text_message)
void WebSocket::close(u16 code, ByteString reason)
{
m_client->close({}, *this, code, move(reason));
m_client->async_websocket_close(m_connection_id, code, move(reason));
}
void WebSocket::did_open(Badge<WebSocketClient>)
void WebSocket::did_open(Badge<RequestClient>)
{
if (on_open)
on_open();
}
void WebSocket::did_receive(Badge<WebSocketClient>, ByteBuffer data, bool is_text)
void WebSocket::did_receive(Badge<RequestClient>, ByteBuffer data, bool is_text)
{
if (on_message)
on_message(WebSocket::Message { move(data), is_text });
}
void WebSocket::did_error(Badge<WebSocketClient>, i32 error_code)
void WebSocket::did_error(Badge<RequestClient>, i32 error_code)
{
if (on_error)
on_error((WebSocket::Error)error_code);
}
void WebSocket::did_close(Badge<WebSocketClient>, u16 code, ByteString reason, bool was_clean)
void WebSocket::did_close(Badge<RequestClient>, u16 code, ByteString reason, bool was_clean)
{
if (on_close)
on_close(code, move(reason), was_clean);
}
void WebSocket::did_request_certificates(Badge<WebSocketClient>)
void WebSocket::did_request_certificates(Badge<RequestClient>)
{
if (on_certificate_requested) {
auto result = on_certificate_requested();
if (!m_client->set_certificate({}, *this, result.certificate, result.key))
if (!m_client->websocket_set_certificate(m_connection_id, result.certificate, result.key))
dbgln("WebSocket: set_certificate failed");
}
}