mirror of
https://github.com/badaix/snapcast.git
synced 2025-07-26 21:08:54 +02:00
Use HTTPS, support for HTTP missing
This commit is contained in:
parent
f7bd5e733f
commit
a796bb2032
14 changed files with 121 additions and 54 deletions
|
@ -21,7 +21,6 @@
|
|||
|
||||
// local headers
|
||||
#include "common/aixlog.hpp"
|
||||
#include "common/message/pcm_chunk.hpp"
|
||||
|
||||
// 3rd party headers
|
||||
|
||||
|
@ -33,8 +32,8 @@ using namespace std;
|
|||
static constexpr auto LOG_TAG = "StreamSessionWS";
|
||||
|
||||
|
||||
StreamSessionWebsocket::StreamSessionWebsocket(StreamMessageReceiver* receiver, websocket::stream<beast::tcp_stream>&& socket)
|
||||
: StreamSession(socket.get_executor(), receiver), ws_(std::move(socket))
|
||||
StreamSessionWebsocket::StreamSessionWebsocket(StreamMessageReceiver* receiver, websocket::stream<ssl_socket>&& wss)
|
||||
: StreamSession(wss.get_executor(), receiver), wss_(std::move(wss))
|
||||
{
|
||||
LOG(DEBUG, LOG_TAG) << "StreamSessionWS\n";
|
||||
}
|
||||
|
@ -51,17 +50,17 @@ void StreamSessionWebsocket::start()
|
|||
{
|
||||
// Read a message
|
||||
LOG(DEBUG, LOG_TAG) << "start\n";
|
||||
ws_.binary(true);
|
||||
wss_.binary(true);
|
||||
do_read_ws();
|
||||
}
|
||||
|
||||
|
||||
void StreamSessionWebsocket::stop()
|
||||
{
|
||||
if (ws_.is_open())
|
||||
if (wss_.is_open())
|
||||
{
|
||||
boost::beast::error_code ec;
|
||||
ws_.close(beast::websocket::close_code::normal, ec);
|
||||
wss_.close(beast::websocket::close_code::normal, ec);
|
||||
if (ec)
|
||||
LOG(ERROR, LOG_TAG) << "Error in socket close: " << ec.message() << "\n";
|
||||
}
|
||||
|
@ -72,7 +71,7 @@ std::string StreamSessionWebsocket::getIP()
|
|||
{
|
||||
try
|
||||
{
|
||||
return ws_.next_layer().socket().remote_endpoint().address().to_string();
|
||||
return wss_.next_layer().lowest_layer().remote_endpoint().address().to_string();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
@ -84,14 +83,14 @@ std::string StreamSessionWebsocket::getIP()
|
|||
void StreamSessionWebsocket::sendAsync(const shared_const_buffer& buffer, const WriteHandler& handler)
|
||||
{
|
||||
LOG(TRACE, LOG_TAG) << "sendAsync: " << buffer.message().type << "\n";
|
||||
ws_.async_write(buffer, [self = shared_from_this(), buffer, handler](boost::system::error_code ec, std::size_t length) { handler(ec, length); });
|
||||
wss_.async_write(buffer, [self = shared_from_this(), buffer, handler](boost::system::error_code ec, std::size_t length) { handler(ec, length); });
|
||||
}
|
||||
|
||||
|
||||
void StreamSessionWebsocket::do_read_ws()
|
||||
{
|
||||
// Read a message into our buffer
|
||||
ws_.async_read(buffer_, [this, self = shared_from_this()](beast::error_code ec, std::size_t bytes_transferred) { on_read_ws(ec, bytes_transferred); });
|
||||
wss_.async_read(buffer_, [this, self = shared_from_this()](beast::error_code ec, std::size_t bytes_transferred) { on_read_ws(ec, bytes_transferred); });
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue