#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 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 active_service_ids_; }; } // namespace connections } // namespace nearby } // namespace location #endif // CORE_INTERNAL_WEBRTC_BWU_HANDLER_H_