websocketserver.hpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. };
  27. WebSocketServer();
  28. WebSocketServer(Configuration config);
  29. ~WebSocketServer();
  30. void stop();
  31. uint16_t port() const;
  32. void onClient(std::function<void(shared_ptr<WebSocket>)> callback);
  33. private:
  34. using CheshireCat<impl::WebSocketServer>::impl;
  35. };
  36. } // namespace rtc
  37. #endif
  38. #endif // RTC_WEBSOCKET_H