roar
Loading...
Searching...
No Matches
websocket_client.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#include <boost/asio/any_io_executor.hpp>
9#include <boost/asio/ssl/context.hpp>
10#include <boost/beast/http/field.hpp>
11#include <promise-cpp/promise.hpp>
12
13#include <memory>
14#include <optional>
15#include <chrono>
16#include <unordered_map>
17
18namespace Roar
19{
20 class WebsocketClient : public Detail::SharedFromBase<WebsocketBase, WebsocketClient>
21 {
22 public:
23 constexpr static std::chrono::seconds defaultTimeout{10};
24
26 {
28 boost::asio::any_io_executor executor;
29
31 std::optional<boost::asio::ssl::context> sslContext;
32 };
33
40
42 {
44 std::string const& host;
45
47 std::string const& port;
48
50 std::string path = "/";
51
53 std::chrono::seconds timeout = defaultTimeout;
54
55 // Additional Websocket handshake headers.
56 std::unordered_map<boost::beast::http::field, std::string> headers = {};
57 };
65 connect(ConnectParameters&& connectParameters);
66
67 private:
68 struct Implementation;
69 std::unique_ptr<Implementation> impl_;
70 };
71}
Definition websocket_client.hpp:21
WebsocketClient & operator=(WebsocketClient &&)=delete
std::unique_ptr< Implementation > impl_
Definition websocket_client.hpp:69
WebsocketClient(WebsocketClient const &)=delete
static constexpr std::chrono::seconds defaultTimeout
Definition websocket_client.hpp:23
Detail::PromiseTypeBind< Detail::PromiseTypeBindThen<>, Detail::PromiseTypeBindFail< Error > > connect(ConnectParameters &&connectParameters)
Connects the websocket to a server.
Definition websocket_client.cpp:136
WebsocketClient(WebsocketClient &&)=delete
WebsocketClient & operator=(WebsocketClient const &)=delete
Definition authorization.hpp:10
Definition promise_compat.hpp:67
Definition promise_compat.hpp:70
Definition shared_from_base.hpp:9
Definition websocket_client.hpp:42
std::unordered_map< boost::beast::http::field, std::string > headers
Definition websocket_client.hpp:56
std::string const & port
The port to connect.
Definition websocket_client.hpp:47
std::string const & host
The host to connect to.
Definition websocket_client.hpp:44
std::string path
The path to connect to.
Definition websocket_client.hpp:50
std::chrono::seconds timeout
A connect and ssl handshake timeout.
Definition websocket_client.hpp:53
Definition websocket_client.hpp:26
boost::asio::any_io_executor executor
Required io executor for boost::asio.
Definition websocket_client.hpp:28
std::optional< boost::asio::ssl::context > sslContext
Supply for SSL support.
Definition websocket_client.hpp:31