websocketserver.hpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * Copyright (c) 2021 Paul-Louis Ageneau
  3. *
  4. * This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  7. */
  8. #ifndef RTC_WEBSOCKETSERVER_H
  9. #define RTC_WEBSOCKETSERVER_H
  10. #if RTC_ENABLE_WEBSOCKET
  11. #include "common.hpp"
  12. #include "websocket.hpp"
  13. namespace rtc {
  14. namespace impl {
  15. struct WebSocketServer;
  16. }
  17. class RTC_CPP_EXPORT WebSocketServer final : private CheshireCat<impl::WebSocketServer> {
  18. public:
  19. struct Configuration {
  20. uint16_t port = 8080;
  21. bool enableTls = false;
  22. optional<string> certificatePemFile;
  23. optional<string> keyPemFile;
  24. optional<string> keyPemPass;
  25. optional<string> bindAddress;
  26. optional<std::chrono::milliseconds> connectionTimeout;
  27. };
  28. WebSocketServer();
  29. WebSocketServer(Configuration config);
  30. ~WebSocketServer();
  31. void stop();
  32. uint16_t port() const;
  33. void onClient(std::function<void(shared_ptr<WebSocket>)> callback);
  34. private:
  35. using CheshireCat<impl::WebSocketServer>::impl;
  36. };
  37. } // namespace rtc
  38. #endif
  39. #endif // RTC_WEBSOCKET_H