using System; using Newtonsoft.Json; using PepperDash.Essentials.Core; using PepperDash.Essentials.Devices.Common.VideoCodec; namespace PepperDash.Essentials.AppServer.Messengers { /// /// Messenger for devices implementing /// public class IHasCodecLayoutsMessenger : MessengerBase { private readonly IHasCodecLayouts _layouts; /// /// Initializes a new instance of the class. /// public IHasCodecLayoutsMessenger(string key, string messagePath, EssentialsDevice device) : base(key, messagePath, device) { _layouts = device as IHasCodecLayouts ?? throw new ArgumentException("device must implement IHasCodecLayouts", nameof(device)); _layouts.LocalLayoutFeedback.OutputChange += LocalLayoutFeedback_OutputChange; } private void LocalLayoutFeedback_OutputChange(object sender, FeedbackEventArgs e) { SendFullStatus(); } private void SendFullStatus(string id = null) { PostStatusMessage(new IHasCodecLayoutsStateMessage { CurrentLayout = _layouts.LocalLayoutFeedback.StringValue }, id); } /// protected override void RegisterActions() { base.RegisterActions(); AddAction("/fullStatus", (id, content) => SendFullStatus(id)); AddAction("/layoutStatus", (id, content) => SendFullStatus(id)); AddAction("/cameraRemoteView", (id, content) => _layouts.LocalLayoutToggle()); AddAction("/cameraLayout", (id, content) => _layouts.LocalLayoutToggle()); } } /// /// State message for /// public class IHasCodecLayoutsStateMessage : DeviceStateMessageBase { /// /// Gets or sets the current layout of the codec /// [JsonProperty("currentLayout", NullValueHandling = NullValueHandling.Ignore)] public string CurrentLayout { get; set; } } }