Files
nearby/cpp/core/internal/webrtc_bwu_handler.h
T
Alexey Polyudov 2155b3ddeb Roll forward to cl/338482889
Signed-off-by: Alexey Polyudov <apolyudov@google.com>
Change-Id: I9850950db8bd84f0904ea1a413151887f52098cf
2020-10-22 10:47:34 -07:00

82 lines
2.9 KiB
C++

#ifndef CORE_INTERNAL_WEBRTC_BWU_HANDLER_H_
#define CORE_INTERNAL_WEBRTC_BWU_HANDLER_H_
#include "core/internal/base_bwu_handler.h"
#include "core/internal/client_proxy.h"
#include "core/internal/endpoint_channel_manager.h"
#include "core/internal/mediums/mediums.h"
#include "core/internal/mediums/webrtc/webrtc_socket_wrapper.h"
namespace location {
namespace nearby {
namespace connections {
using BwuNegotiationFrame = BandwidthUpgradeNegotiationFrame;
// Defines the set of methods that need to be implemented to handle the
// per-Medium-specific operations needed to upgrade an EndpointChannel.
class WebrtcBwuHandler : public BaseBwuHandler {
public:
WebrtcBwuHandler(Mediums& mediums, EndpointChannelManager& channel_manager,
BwuNotifications notifications);
~WebrtcBwuHandler() override = default;
private:
// Called by the Initiator to setup the upgraded medium for this endpoint (if
// that hasn't already been done), and returns a serialized UpgradePathInfo
// that can be sent to the Responder.
// @BwuHandlerThread
ByteArray InitializeUpgradedMediumForEndpoint(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id) override;
// Called to revert any state changed by the Initiator to setup the upgraded
// medium for an endpoint.
// @BwuHandlerThread
void Revert() override;
// Called by the Responder to setup the upgraded medium for this endpoint (if
// that hasn't already been done) using the UpgradePathInfo sent by the
// Initiator, and returns a new EndpointChannel for the upgraded medium.
// @BwuHandlerThread
std::unique_ptr<EndpointChannel> CreateUpgradedEndpointChannel(
ClientProxy* client, const std::string& service_id,
const std::string& endpoint_id,
const UpgradePathInfo& upgrade_path_info) override;
// Returns the upgrade medium of the BwuHandler.
// @BwuHandlerThread
Medium GetUpgradeMedium() const override { return Medium::WEB_RTC; }
void OnIncomingWebrtcConnection(ClientProxy* client,
const std::string& service_id,
mediums::WebRtcSocketWrapper socket);
void OnEndpointDisconnect(ClientProxy* client,
const std::string& endpoint_id) override;
std::string GetCountryCode();
class WebrtcIncomingSocket : public BwuHandler::IncomingSocket {
public:
explicit WebrtcIncomingSocket(const std::string& name,
mediums::WebRtcSocketWrapper socket);
~WebrtcIncomingSocket() override = default;
std::string ToString() override;
void Close() override;
private:
std::string name_;
mediums::WebRtcSocketWrapper socket_;
};
Mediums& mediums_;
mediums::WebRtc& webrtc_{mediums_.GetWebRtc()};
absl::flat_hash_set<std::string> active_service_ids_;
};
} // namespace connections
} // namespace nearby
} // namespace location
#endif // CORE_INTERNAL_WEBRTC_BWU_HANDLER_H_