1 /**
2  * Copyright (c) 2021 Paul-Louis Ageneau
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef RTC_WEBSOCKETSERVER_H
20 #define RTC_WEBSOCKETSERVER_H
21 
22 #if RTC_ENABLE_WEBSOCKET
23 
24 #include "common.hpp"
25 #include "websocket.hpp"
26 
27 namespace rtc {
28 
29 namespace impl {
30 
31 struct WebSocketServer;
32 
33 }
34 
35 class RTC_CPP_EXPORT WebSocketServer final : private CheshireCat<impl::WebSocketServer> {
36 public:
37 	struct Configuration {
38 		uint16_t port = 8080;
39 		bool enableTls = false;
40 		optional<string> certificatePemFile;
41 		optional<string> keyPemFile;
42 		optional<string> keyPemPass;
43 	};
44 
45 	WebSocketServer();
46 	WebSocketServer(Configuration config);
47 	~WebSocketServer();
48 
49 	void stop();
50 
51 	uint16_t port() const;
52 
53 	void onClient(std::function<void(shared_ptr<WebSocket>)> callback);
54 
55 private:
56 	using CheshireCat<impl::WebSocketServer>::impl;
57 };
58 
59 } // namespace rtc
60 
61 #endif
62 
63 #endif // RTC_WEBSOCKET_H
64