/* obs-websocket Copyright (C) 2016-2019 Stéphane Lepin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see */ #pragma once #include #include #include #include #include #include #include #include #include #include "ConnectionProperties.h" #include "WSRequestHandler.h" QT_FORWARD_DECLARE_CLASS(QWebSocketServer) QT_FORWARD_DECLARE_CLASS(QWebSocket) using websocketpp::connection_hdl; typedef websocketpp::server server; class WSServer : public QObject { Q_OBJECT public: explicit WSServer(); virtual ~WSServer(); void start(quint16 port); void stop(); void broadcast(std::string message); QThreadPool* threadPool() { return &_threadPool; } private: void onOpen(connection_hdl hdl); void onMessage(connection_hdl hdl, server::message_ptr message); void onClose(connection_hdl hdl); QString getRemoteEndpoint(connection_hdl hdl); void notifyConnection(QString clientIp); void notifyDisconnection(QString clientIp); server _server; quint16 _serverPort; std::set> _connections; std::map> _connectionProperties; QMutex _clMutex; QThreadPool _threadPool; };