mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 14:05:15 +00:00
This commit un-deprecates DeprecatedString, and repurposes it as a byte string. As the null state has already been removed, there are no other particularly hairy blockers in repurposing this type as a byte string (what it _really_ is). This commit is auto-generated: $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \ Meta Ports Ladybird Tests Kernel) $ perl -pie 's/\bDeprecatedString\b/ByteString/g; s/deprecated_string/byte_string/g' $xs $ clang-format --style=file -i \ $(git diff --name-only | grep \.cpp\|\.h) $ gn format $(git ls-files '*.gn' '*.gni')
75 lines
1.8 KiB
C++
75 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) 2021, Dex♪ <dexes.ttp@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibProtocol/WebSocket.h>
|
|
#include <LibProtocol/WebSocketClient.h>
|
|
|
|
namespace Protocol {
|
|
|
|
WebSocket::WebSocket(WebSocketClient& client, i32 connection_id)
|
|
: m_client(client)
|
|
, m_connection_id(connection_id)
|
|
{
|
|
}
|
|
|
|
WebSocket::ReadyState WebSocket::ready_state()
|
|
{
|
|
return (WebSocket::ReadyState)m_client->ready_state({}, *this);
|
|
}
|
|
|
|
ByteString 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);
|
|
}
|
|
|
|
void WebSocket::send(StringView text_message)
|
|
{
|
|
send(ByteBuffer::copy(text_message.bytes()).release_value_but_fixme_should_propagate_errors(), true);
|
|
}
|
|
|
|
void WebSocket::close(u16 code, ByteString reason)
|
|
{
|
|
m_client->close({}, *this, code, move(reason));
|
|
}
|
|
|
|
void WebSocket::did_open(Badge<WebSocketClient>)
|
|
{
|
|
if (on_open)
|
|
on_open();
|
|
}
|
|
|
|
void WebSocket::did_receive(Badge<WebSocketClient>, 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)
|
|
{
|
|
if (on_error)
|
|
on_error((WebSocket::Error)error_code);
|
|
}
|
|
|
|
void WebSocket::did_close(Badge<WebSocketClient>, u16 code, ByteString reason, bool was_clean)
|
|
{
|
|
if (on_close)
|
|
on_close(code, move(reason), was_clean);
|
|
}
|
|
|
|
void WebSocket::did_request_certificates(Badge<WebSocketClient>)
|
|
{
|
|
if (on_certificate_requested) {
|
|
auto result = on_certificate_requested();
|
|
if (!m_client->set_certificate({}, *this, result.certificate, result.key))
|
|
dbgln("WebSocket: set_certificate failed");
|
|
}
|
|
}
|
|
}
|