websocketserver.hpp 1.0 KB

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