// This file is part of Desktop App Toolkit, // a set of libraries for developing nice desktop applications. // // For license and copyright information please follow this link: // https://github.com/desktop-app/legal/blob/master/LEGAL // #pragma once #include "base/weak_ptr.h" #include "webrtc/webrtc_device_common.h" #include #include namespace Webrtc::Platform { class Environment; class EnvironmentDelegate { public: virtual void defaultChanged( DeviceType type, DeviceChangeReason reason, QString nowId) = 0; virtual void deviceStateChanged( DeviceType type, QString id, DeviceStateChange state) = 0; virtual void devicesForceRefresh(DeviceType type) = 0; }; } // namespace Webrtc::Platform namespace Webrtc { struct DeviceId; class Environment final : private Platform::EnvironmentDelegate , private base::has_weak_ptr { public: Environment(); ~Environment(); void forceRefresh(DeviceType type); [[nodiscard]] QString defaultId(DeviceType type) const; [[nodiscard]] std::vector devices(DeviceType type) const; [[nodiscard]] rpl::producer changes( DeviceType type) const; [[nodiscard]] rpl::producer defaultChanges( DeviceType type) const; [[nodiscard]] rpl::producer> devicesValue( DeviceType type) const; void validateDefaultId(DeviceType type) const; void validateDevices(DeviceType type) const; [[nodiscard]] bool desktopCaptureAllowed() const; [[nodiscard]] std::optional uniqueDesktopCaptureSource() const; [[nodiscard]] DeviceResolvedId threadSafeResolveId( const DeviceResolvedId &lastResolvedId, const QString &savedId) const; void setCaptureMuted(bool muted); void setCaptureMuteTracker( not_null tracker, bool track); [[nodiscard]] RecordAvailability recordAvailability() const; [[nodiscard]] auto recordAvailabilityValue() const -> rpl::producer; void refreshRecordAvailability(); private: static constexpr auto kTypeCount = 3; enum class LogType : uchar { Initial, Always, Debug, }; struct DevicesChangeEvent { DeviceChange defaultChange; bool listChanged = false; }; struct Devices { QString defaultId; rpl::event_stream changes; std::vector list; rpl::event_stream<> listChanges; std::optional defaultChangeFrom; DeviceChangeReason defaultChangeReason = DeviceChangeReason::Manual; bool refreshFullListOnChange = false; bool listChanged = false; }; [[nodiscard]] static int TypeToIndex(DeviceType type); [[nodiscard]] Devices resolveDevices(DeviceType type) const; [[nodiscard]] bool synced(DeviceType type) const; void validateAfterDefaultChange(DeviceType type); void validateAfterListChange(DeviceType type); void refreshDevices(DeviceType type); void maybeNotify(DeviceType type); void logSyncError(DeviceType type); void logState(DeviceType type, LogType log); void defaultChanged( DeviceType type, DeviceChangeReason reason, QString nowId) override; void deviceStateChanged( DeviceType type, QString id, DeviceStateChange state) override; void devicesForceRefresh(DeviceType type) override; void applyRecordAvailability(RecordAvailability value); const std::unique_ptr _platform; std::array _devices; rpl::variable _recordAvailability; bool _recordAvailabilityRefreshing = false; bool _recordAvailabilityRefreshPending = false; rpl::lifetime _lifetime; }; } // namespace Webrtc