1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 22:07:35 +00:00

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.
This commit is contained in:
Guilherme Gonçalves 2022-12-31 10:37:10 +00:00 committed by Andreas Kling
parent 9115e99e4b
commit 230c0b34d4
19 changed files with 107 additions and 34 deletions

View file

@ -75,6 +75,15 @@ Messages::WebSocketServer::ReadyStateResponse ConnectionFromClient::ready_state(
return (u32)ReadyState::Closed;
}
Messages::WebSocketServer::SubprotocolInUseResponse ConnectionFromClient::subprotocol_in_use(i32 connection_id)
{
RefPtr<WebSocket> connection = m_connections.get(connection_id).value_or({});
if (connection) {
return connection->subprotocol_in_use();
}
return DeprecatedString::empty();
}
void ConnectionFromClient::send(i32 connection_id, bool is_text, ByteBuffer const& data)
{
RefPtr<WebSocket> connection = m_connections.get(connection_id).value_or({});

View file

@ -28,6 +28,7 @@ private:
virtual Messages::WebSocketServer::ConnectResponse connect(URL const&, DeprecatedString const&, Vector<DeprecatedString> const&, Vector<DeprecatedString> const&, IPC::Dictionary const&) override;
virtual Messages::WebSocketServer::ReadyStateResponse ready_state(i32) override;
virtual Messages::WebSocketServer::SubprotocolInUseResponse subprotocol_in_use(i32) override;
virtual void send(i32, bool, ByteBuffer const&) override;
virtual void close(i32, u16, DeprecatedString const&) override;
virtual Messages::WebSocketServer::SetCertificateResponse set_certificate(i32, DeprecatedString const&, DeprecatedString const&) override;

View file

@ -5,6 +5,7 @@ endpoint WebSocketServer
// Connection API
connect(URL url, DeprecatedString origin, Vector<DeprecatedString> protocols, Vector<DeprecatedString> extensions, IPC::Dictionary additional_request_headers) => (i32 connection_id)
ready_state(i32 connection_id) => (u32 ready_state)
subprotocol_in_use(i32 connection_id) => (DeprecatedString subprotocol_in_use)
send(i32 connection_id, bool is_text, ByteBuffer data) =|
close(i32 connection_id, u16 code, DeprecatedString reason) =|