using Newtonsoft.Json; using Newtonsoft.Json.Linq; using PepperDash.Core; using PepperDash.Core.Logging; using PepperDash.Essentials.AppServer.Messengers; namespace PepperDash.Essentials.Touchpanel { /// /// Messenger for controlling the Zoom App on a TSW Panel that supports the Zoom Room Control Application /// public class ITswAppControlMessenger : MessengerBase { private readonly ITswAppControl _appControl; /// /// Create an instance of the class. /// /// The key for this messenger /// The message path for this messenger /// The device for this messenger public ITswAppControlMessenger(string key, string messagePath, Device device) : base(key, messagePath, device) { _appControl = device as ITswAppControl; } /// protected override void RegisterActions() { if (_appControl == null) { this.LogInformation("{deviceKey} does not implement ITswAppControl", _device.Key); return; } AddAction($"/fullStatus", (id, context) => SendFullStatus(id)); AddAction($"/openApp", (id, context) => _appControl.OpenApp()); AddAction($"/closeApp", (id, context) => _appControl.CloseOpenApp()); AddAction($"/hideApp", (id, context) => _appControl.HideOpenApp()); _appControl.AppOpenFeedback.OutputChange += (s, a) => { PostStatusMessage(JToken.FromObject(new { appOpen = a.BoolValue })); }; } private void SendFullStatus(string id = null) { var message = new TswAppStateMessage { AppOpen = _appControl.AppOpenFeedback.BoolValue, }; PostStatusMessage(message, id); } } /// /// Represents a TswAppStateMessage /// public class TswAppStateMessage : DeviceStateMessageBase { /// /// True if the Zoom app is open on a TSW panel /// [JsonProperty("appOpen", NullValueHandling = NullValueHandling.Ignore)] public bool? AppOpen { get; set; } } }