1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-25 17:05:07 +00:00
serenity/Userland/Services/WebSocket/ClientConnection.h
Andreas Kling 971b3645ef LibIPC: Add IPC::take_over_accepted_client_from_system_server<Client>()
This is an encapsulation of the common work done by all of our
single-client IPC servers on startup:

    1. Create a Core::LocalSocket, taking over an accepted fd.
    2. Create an application-specific ClientConnection object,
       wrapping the socket.

It's not a huge change in terms of lines saved, but I do feel that it
improves expressiveness. :^)
2021-12-06 19:22:16 +01:00

45 lines
1.4 KiB
C++

/*
* Copyright (c) 2021, Dex♪ <dexes.ttp@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/HashMap.h>
#include <LibIPC/ClientConnection.h>
#include <LibWebSocket/WebSocket.h>
#include <WebSocket/WebSocketClientEndpoint.h>
#include <WebSocket/WebSocketServerEndpoint.h>
namespace WebSocket {
class ClientConnection final
: public IPC::ClientConnection<WebSocketClientEndpoint, WebSocketServerEndpoint> {
C_OBJECT(ClientConnection);
public:
~ClientConnection() override;
virtual void die() override;
private:
explicit ClientConnection(NonnullRefPtr<Core::LocalSocket>);
virtual Messages::WebSocketServer::ConnectResponse connect(URL const&, String const&, Vector<String> const&, Vector<String> const&, IPC::Dictionary const&) override;
virtual Messages::WebSocketServer::ReadyStateResponse ready_state(i32) override;
virtual void send(i32, bool, ByteBuffer const&) override;
virtual void close(i32, u16, String const&) override;
virtual Messages::WebSocketServer::SetCertificateResponse set_certificate(i32, String const&, String const&) override;
void did_connect(i32);
void did_receive_message(i32, Message);
void did_error(i32, i32 message);
void did_close(i32, u16 code, String reason, bool was_clean);
void did_request_certificates(i32);
i32 m_connection_ids { 0 };
HashMap<i32, RefPtr<WebSocket>> m_connections;
};
}