42 lines
1.5 KiB
C++
42 lines
1.5 KiB
C++
#pragma once
|
|
#include "Plot.hpp"
|
|
#include <drogon/WebSocketController.h>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
namespace aethera::web {
|
|
class Graph_WebSocket final : public std::enable_shared_from_this<Graph_WebSocket> {
|
|
public:
|
|
Graph_WebSocket(drogon::WebSocketConnectionPtr connection, std::shared_ptr<Plot> plot);
|
|
~Graph_WebSocket();
|
|
Graph_WebSocket(const Graph_WebSocket&) = delete;
|
|
Graph_WebSocket& operator=(const Graph_WebSocket&) = delete;
|
|
void start();
|
|
void receive(std::string_view message);
|
|
void close();
|
|
private:
|
|
struct Private;
|
|
std::unique_ptr<Private> d;
|
|
};
|
|
|
|
class Graph_WebSocket_Controller final
|
|
: public drogon::WebSocketController<Graph_WebSocket_Controller, false> {
|
|
public:
|
|
using Plot_Resolver = std::function<std::shared_ptr<Plot>(std::string_view)>;
|
|
explicit Graph_WebSocket_Controller(Plot_Resolver resolver);
|
|
void handleNewMessage(const drogon::WebSocketConnectionPtr& connection,
|
|
std::string&& message,
|
|
const drogon::WebSocketMessageType& type) override;
|
|
void handleNewConnection(const drogon::HttpRequestPtr& request,
|
|
const drogon::WebSocketConnectionPtr& connection) override;
|
|
void handleConnectionClosed(const drogon::WebSocketConnectionPtr& connection) override;
|
|
WS_PATH_LIST_BEGIN
|
|
WS_ADD_PATH_VIA_REGEX("^/ws/plot/[^/]+$");
|
|
WS_PATH_LIST_END
|
|
private:
|
|
Plot_Resolver resolve_plot;
|
|
};
|
|
}
|