diff --git a/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.AppControl.cs b/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.AppControl.cs deleted file mode 100644 index 7556f8d2..00000000 --- a/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.AppControl.cs +++ /dev/null @@ -1,76 +0,0 @@ -using Crestron.SimplSharpPro.UI; -using PepperDash.Core; -using PepperDash.Core.Logging; - -namespace PepperDash.Essentials.Touchpanel -{ - /// - /// Partial class containing app control functionality for managing applications on the touchpanel. - /// - public partial class MobileControlTouchpanelController - { - /// - /// Sets the application URL for mobile control access. - /// - /// The URL to set for the mobile control application. - public void SetAppUrl(string url) - { - _appUrl = GetUrlWithCorrectIp(url); - AppUrlFeedback.FireUpdate(); - } - - /// - /// Hides the currently open application on the touchpanel. - /// - public void HideOpenApp() - { - if (Panel is TswX70Base x70Panel) - { - x70Panel.ExtenderApplicationControlReservedSigs.HideOpenedApplication(); - return; - } - - if (Panel is TswX60BaseClass x60Panel) - { - x60Panel.ExtenderApplicationControlReservedSigs.HideOpenApplication(); - return; - } - } - - /// - /// Opens an application on the touchpanel. - /// - public void OpenApp() - { - if (Panel is TswX70Base x70Panel) - { - x70Panel.ExtenderApplicationControlReservedSigs.OpenApplication(); - return; - } - - if (Panel is TswX60WithZoomRoomAppReservedSigs) - { - Debug.LogMessage(Serilog.Events.LogEventLevel.Information, this, $"X60 panel does not support zoom app"); - return; - } - } - - /// - /// Closes the currently open application on the touchpanel. - /// - public void CloseOpenApp() - { - if (Panel is TswX70Base x70Panel) - { - x70Panel.ExtenderApplicationControlReservedSigs.CloseOpenedApplication(); - return; - } - - if (Panel is TswX60WithZoomRoomAppReservedSigs x60Panel) - { - x60Panel.ExtenderApplicationControlReservedSigs.CloseOpenedApplication(); - return; - } - } - } -} \ No newline at end of file diff --git a/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.DeviceInfo.cs b/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.DeviceInfo.cs deleted file mode 100644 index bb7d5576..00000000 --- a/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.DeviceInfo.cs +++ /dev/null @@ -1,142 +0,0 @@ -using System; -using System.Linq; -using System.Text.RegularExpressions; -using Crestron.SimplSharp; -using Crestron.SimplSharpPro; -using Crestron.SimplSharpPro.UI; -using PepperDash.Core; -using PepperDash.Core.Logging; -using PepperDash.Essentials.Core; -using PepperDash.Essentials.Core.DeviceInfo; - -namespace PepperDash.Essentials.Touchpanel -{ - /// - /// Partial class containing device information, IP address handling, and network configuration functionality. - /// - public partial class MobileControlTouchpanelController - { - /// - /// Updates device information including MAC address and IP address from panel extenders. - /// - public void UpdateDeviceInfo() - { - if (Panel is TswXX70Base x70Panel) - { - DeviceInfo.MacAddress = x70Panel.ExtenderEthernetReservedSigs.MacAddressFeedback.StringValue; - DeviceInfo.IpAddress = x70Panel.ExtenderEthernetReservedSigs.IpAddressFeedback.StringValue; - - var handler = DeviceInfoChanged; - - if (handler == null) - { - return; - } - - handler(this, new DeviceInfoEventArgs(DeviceInfo)); - } - - if (Panel is TswX60WithZoomRoomAppReservedSigs x60Panel) - { - DeviceInfo.MacAddress = x60Panel.ExtenderEthernetReservedSigs.MacAddressFeedback.StringValue; - DeviceInfo.IpAddress = x60Panel.ExtenderEthernetReservedSigs.IpAddressFeedback.StringValue; - - var handler = DeviceInfoChanged; - - if (handler == null) - { - return; - } - - handler(this, new DeviceInfoEventArgs(DeviceInfo)); - } - - Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, this, $"MAC: {DeviceInfo.MacAddress} IP: {DeviceInfo.IpAddress}"); - } - - /// - /// Gets the URL with the correct IP address based on the connected devices and the Crestron processor's IP address. - /// - /// The original URL to process. - /// The URL with the correct IP address for the panel's network connection. - private string GetUrlWithCorrectIp(string url) - { - var lanAdapterId = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(EthernetAdapterType.EthernetLANAdapter); - - var processorIp = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, lanAdapterId); - - if (csIpAddress == null || csSubnetMask == null || url == null) - { - this.LogWarning("CS IP Address Subnet Mask or url is null, cannot determine correct IP for URL"); - return url; - } - - this.LogVerbose("Processor IP: {processorIp}, CS IP: {csIpAddress}, CS Subnet Mask: {csSubnetMask}", processorIp, csIpAddress, csSubnetMask); - this.LogVerbose("Connected IP Count: {connectedIps}", ConnectedIps.Count); - - var ip = ConnectedIps.Any(ipInfo => - { - if (System.Net.IPAddress.TryParse(ipInfo.DeviceIpAddress, out var parsedIp)) - { - return parsedIp.IsInSameSubnet(csIpAddress, csSubnetMask); - } - this.LogWarning("Invalid IP address: {deviceIpAddress}", ipInfo.DeviceIpAddress); - return false; - }) ? csIpAddress.ToString() : processorIp; - - var match = Regex.Match(url, @"^http://([^:/]+):\d+/mc/app\?token=.+$"); - if (match.Success) - { - string ipa = match.Groups[1].Value; - // ip will be "192.168.1.100" - } - - // replace ipa with ip but leave the rest of the string intact - var updatedUrl = Regex.Replace(url, @"^http://[^:/]+", $"http://{ip}"); - - this.LogVerbose("Updated URL: {updatedUrl}", updatedUrl); - - return updatedUrl; - } - - /// - /// Subscribes to mobile control updates and bridge events for feedback updates. - /// - private void SubscribeForMobileControlUpdates() - { - foreach (var dev in DeviceManager.AllDevices) - { - Debug.LogMessage(Serilog.Events.LogEventLevel.Information, this, $"{dev.Key}:{dev.GetType().Name}"); - } - - var mcList = DeviceManager.AllDevices.OfType().ToList(); - - if (mcList.Count == 0) - { - Debug.LogMessage(Serilog.Events.LogEventLevel.Information, this, $"No Mobile Control controller found"); - return; - } - - // use first in list, since there should only be one. - var mc = mcList[0]; - - var bridge = mc.GetRoomBridge(_config.DefaultRoomKey); - - if (bridge == null) - { - Debug.LogMessage(Serilog.Events.LogEventLevel.Information, this, $"No Mobile Control bridge for {_config.DefaultRoomKey} found "); - return; - } - - _bridge = bridge; - - _bridge.UserCodeChanged += UpdateFeedbacks; - _bridge.AppUrlChanged += (s, a) => - { - SetAppUrl(_bridge.AppUrl); - }; - - UpdateFeedbacks(); - } - } -} \ No newline at end of file diff --git a/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.PanelExtenders.cs b/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.PanelExtenders.cs deleted file mode 100644 index 5c3b2f42..00000000 --- a/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.PanelExtenders.cs +++ /dev/null @@ -1,160 +0,0 @@ -using System; -using Crestron.SimplSharpPro.UI; -using PepperDash.Core; -using PepperDash.Core.Logging; -using PepperDash.Essentials.Core.DeviceInfo; - -namespace PepperDash.Essentials.Touchpanel -{ - /// - /// Partial class containing panel extender registration and event handling functionality. - /// - public partial class MobileControlTouchpanelController - { - /// - /// Registers for extender signals based on the panel type and sets up event handlers - /// for app control, Zoom room, and Ethernet functionality. - /// - private void RegisterForExtenders() - { - if (Panel is TswXX70Base x70Panel) - { - RegisterX70PanelExtenders(x70Panel); - return; - } - - if (Panel is TswX60WithZoomRoomAppReservedSigs x60withZoomApp) - { - RegisterX60PanelExtenders(x60withZoomApp); - } - } - - /// - /// Registers extender signals and event handlers for TSW X70 series panels. - /// - /// The X70 panel to register extenders for. - private void RegisterX70PanelExtenders(TswXX70Base x70Panel) - { - // App Control Extender - x70Panel.ExtenderApplicationControlReservedSigs.DeviceExtenderSigChange += (e, a) => - { - Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, this, $"X70 App Control Device Extender args: {a.Event}:{a.Sig}:{a.Sig.Type}:{a.Sig.BoolValue}:{a.Sig.UShortValue}:{a.Sig.StringValue}"); - - UpdateZoomFeedbacks(); - - if (!x70Panel.ExtenderApplicationControlReservedSigs.HideOpenedApplicationFeedback.BoolValue) - { - x70Panel.ExtenderButtonToolbarReservedSigs.ShowButtonToolbar(); - x70Panel.ExtenderButtonToolbarReservedSigs.Button2On(); - } - else - { - x70Panel.ExtenderButtonToolbarReservedSigs.HideButtonToolbar(); - x70Panel.ExtenderButtonToolbarReservedSigs.Button2Off(); - } - }; - - // Zoom Room App Extender - x70Panel.ExtenderZoomRoomAppReservedSigs.DeviceExtenderSigChange += (e, a) => - { - Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, this, $"X70 Zoom Room App Device Extender args: {a.Event}:{a.Sig}:{a.Sig.Type}:{a.Sig.BoolValue}:{a.Sig.UShortValue}:{a.Sig.StringValue}"); - - if (a.Sig.Number == x70Panel.ExtenderZoomRoomAppReservedSigs.ZoomRoomIncomingCallFeedback.Number) - { - ZoomIncomingCallFeedback.FireUpdate(); - } - else if (a.Sig.Number == x70Panel.ExtenderZoomRoomAppReservedSigs.ZoomRoomActiveFeedback.Number) - { - ZoomInCallFeedback.FireUpdate(); - } - }; - - // Ethernet Extender - x70Panel.ExtenderEthernetReservedSigs.DeviceExtenderSigChange += (e, a) => - { - DeviceInfo.MacAddress = x70Panel.ExtenderEthernetReservedSigs.MacAddressFeedback.StringValue; - DeviceInfo.IpAddress = x70Panel.ExtenderEthernetReservedSigs.IpAddressFeedback.StringValue; - - Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, this, $"MAC: {DeviceInfo.MacAddress} IP: {DeviceInfo.IpAddress}"); - - var handler = DeviceInfoChanged; - - if (handler == null) - { - return; - } - - handler(this, new DeviceInfoEventArgs(DeviceInfo)); - }; - - // Initialize extenders - x70Panel.ExtenderApplicationControlReservedSigs.Use(); - x70Panel.ExtenderZoomRoomAppReservedSigs.Use(); - x70Panel.ExtenderEthernetReservedSigs.Use(); - x70Panel.ExtenderButtonToolbarReservedSigs.Use(); - - // Initialize button toolbar - x70Panel.ExtenderButtonToolbarReservedSigs.Button1Off(); - x70Panel.ExtenderButtonToolbarReservedSigs.Button3Off(); - x70Panel.ExtenderButtonToolbarReservedSigs.Button4Off(); - x70Panel.ExtenderButtonToolbarReservedSigs.Button5Off(); - x70Panel.ExtenderButtonToolbarReservedSigs.Button6Off(); - } - - /// - /// Registers extender signals and event handlers for TSW X60 series panels with Zoom room app support. - /// - /// The X60 panel with Zoom room app to register extenders for. - private void RegisterX60PanelExtenders(TswX60WithZoomRoomAppReservedSigs x60withZoomApp) - { - // App Control Extender - x60withZoomApp.ExtenderApplicationControlReservedSigs.DeviceExtenderSigChange += (e, a) => - { - Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, this, $"X60 App Control Device Extender args: {a.Event}:{a.Sig}:{a.Sig.Type}:{a.Sig.BoolValue}:{a.Sig.UShortValue}:{a.Sig.StringValue}"); - - if (a.Sig.Number == x60withZoomApp.ExtenderApplicationControlReservedSigs.HideOpenApplicationFeedback.Number) - { - AppOpenFeedback.FireUpdate(); - } - }; - - // Zoom Room App Extender - x60withZoomApp.ExtenderZoomRoomAppReservedSigs.DeviceExtenderSigChange += (e, a) => - { - Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, this, $"X60 Zoom Room App Device Extender args: {a.Event}:{a.Sig}:{a.Sig.Type}:{a.Sig.BoolValue}:{a.Sig.UShortValue}:{a.Sig.StringValue}"); - - if (a.Sig.Number == x60withZoomApp.ExtenderZoomRoomAppReservedSigs.ZoomRoomIncomingCallFeedback.Number) - { - ZoomIncomingCallFeedback.FireUpdate(); - } - else if (a.Sig.Number == x60withZoomApp.ExtenderZoomRoomAppReservedSigs.ZoomRoomActiveFeedback.Number) - { - ZoomInCallFeedback.FireUpdate(); - } - }; - - // Ethernet Extender - x60withZoomApp.ExtenderEthernetReservedSigs.DeviceExtenderSigChange += (e, a) => - { - DeviceInfo.MacAddress = x60withZoomApp.ExtenderEthernetReservedSigs.MacAddressFeedback.StringValue; - DeviceInfo.IpAddress = x60withZoomApp.ExtenderEthernetReservedSigs.IpAddressFeedback.StringValue; - - Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, this, $"MAC: {DeviceInfo.MacAddress} IP: {DeviceInfo.IpAddress}"); - - var handler = DeviceInfoChanged; - - if (handler == null) - { - return; - } - - handler(this, new DeviceInfoEventArgs(DeviceInfo)); - }; - - // Initialize extenders - x60withZoomApp.ExtenderZoomRoomAppReservedSigs.Use(); - x60withZoomApp.ExtenderApplicationControlReservedSigs.Use(); - x60withZoomApp.ExtenderEthernetReservedSigs.Use(); - } - } -} \ No newline at end of file diff --git a/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.ZoomIntegration.cs b/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.ZoomIntegration.cs deleted file mode 100644 index 20e2191f..00000000 --- a/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.ZoomIntegration.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Crestron.SimplSharpPro.UI; -using PepperDash.Core; -using PepperDash.Core.Logging; - -namespace PepperDash.Essentials.Touchpanel -{ - /// - /// Partial class containing Zoom integration functionality for managing Zoom calls and room control. - /// - public partial class MobileControlTouchpanelController - { - /// - /// Updates all Zoom-related feedback values to reflect current state. - /// - private void UpdateZoomFeedbacks() - { - foreach (var feedback in ZoomFeedbacks) - { - Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, this, $"Updating {feedback.Key}"); - feedback.FireUpdate(); - } - } - - /// - /// Ends the current Zoom call on the touchpanel. - /// - public void EndZoomCall() - { - if (Panel is TswX70Base x70Panel) - { - x70Panel.ExtenderZoomRoomAppReservedSigs.ZoomRoomEndCall(); - return; - } - - if (Panel is TswX60WithZoomRoomAppReservedSigs x60Panel) - { - x60Panel.ExtenderZoomRoomAppReservedSigs.ZoomRoomEndCall(); - return; - } - } - } -} \ No newline at end of file diff --git a/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.cs b/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.cs index 4995456a..a660b8b9 100644 --- a/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.cs +++ b/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.cs @@ -23,9 +23,8 @@ namespace PepperDash.Essentials.Touchpanel /// /// Mobile Control touchpanel controller that provides app control, Zoom integration, /// and mobile control functionality for Crestron touchpanels. - /// This is the main partial class containing core properties, constructor, and basic functionality. /// - public partial class MobileControlTouchpanelController : TouchpanelBase, IHasFeedback, ITswAppControl, ITswZoomControl, IDeviceInfoProvider, IMobileControlCrestronTouchpanelController, ITheme + public class MobileControlTouchpanelController : TouchpanelBase, IHasFeedback, ITswAppControl, ITswZoomControl, IDeviceInfoProvider, IMobileControlCrestronTouchpanelController, ITheme { private readonly MobileControlTouchpanelProperties localConfig; private IMobileControlRoomMessenger _bridge; @@ -234,6 +233,123 @@ namespace PepperDash.Essentials.Touchpanel ConfigWriter.UpdateDeviceConfig(deviceConfig); } + private void RegisterForExtenders() + { + if (Panel is TswXX70Base x70Panel) + { + x70Panel.ExtenderApplicationControlReservedSigs.DeviceExtenderSigChange += (e, a) => + { + Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, this, $"X70 App Control Device Extender args: {a.Event}:{a.Sig}:{a.Sig.Type}:{a.Sig.BoolValue}:{a.Sig.UShortValue}:{a.Sig.StringValue}"); + + UpdateZoomFeedbacks(); + + if (!x70Panel.ExtenderApplicationControlReservedSigs.HideOpenedApplicationFeedback.BoolValue) + { + x70Panel.ExtenderButtonToolbarReservedSigs.ShowButtonToolbar(); + x70Panel.ExtenderButtonToolbarReservedSigs.Button2On(); + } + else + { + x70Panel.ExtenderButtonToolbarReservedSigs.HideButtonToolbar(); + x70Panel.ExtenderButtonToolbarReservedSigs.Button2Off(); + } + }; + + + x70Panel.ExtenderZoomRoomAppReservedSigs.DeviceExtenderSigChange += (e, a) => + { + Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, this, $"X70 Zoom Room Ap Device Extender args: {a.Event}:{a.Sig}:{a.Sig.Type}:{a.Sig.BoolValue}:{a.Sig.UShortValue}:{a.Sig.StringValue}"); + + if (a.Sig.Number == x70Panel.ExtenderZoomRoomAppReservedSigs.ZoomRoomIncomingCallFeedback.Number) + { + ZoomIncomingCallFeedback.FireUpdate(); + } + else if (a.Sig.Number == x70Panel.ExtenderZoomRoomAppReservedSigs.ZoomRoomActiveFeedback.Number) + { + ZoomInCallFeedback.FireUpdate(); + } + }; + + + x70Panel.ExtenderEthernetReservedSigs.DeviceExtenderSigChange += (e, a) => + { + DeviceInfo.MacAddress = x70Panel.ExtenderEthernetReservedSigs.MacAddressFeedback.StringValue; + DeviceInfo.IpAddress = x70Panel.ExtenderEthernetReservedSigs.IpAddressFeedback.StringValue; + + Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, this, $"MAC: {DeviceInfo.MacAddress} IP: {DeviceInfo.IpAddress}"); + + var handler = DeviceInfoChanged; + + if (handler == null) + { + return; + } + + handler(this, new DeviceInfoEventArgs(DeviceInfo)); + }; + + x70Panel.ExtenderApplicationControlReservedSigs.Use(); + x70Panel.ExtenderZoomRoomAppReservedSigs.Use(); + x70Panel.ExtenderEthernetReservedSigs.Use(); + x70Panel.ExtenderButtonToolbarReservedSigs.Use(); + + x70Panel.ExtenderButtonToolbarReservedSigs.Button1Off(); + x70Panel.ExtenderButtonToolbarReservedSigs.Button3Off(); + x70Panel.ExtenderButtonToolbarReservedSigs.Button4Off(); + x70Panel.ExtenderButtonToolbarReservedSigs.Button5Off(); + x70Panel.ExtenderButtonToolbarReservedSigs.Button6Off(); + + return; + } + + if (Panel is TswX60WithZoomRoomAppReservedSigs x60withZoomApp) + { + x60withZoomApp.ExtenderApplicationControlReservedSigs.DeviceExtenderSigChange += (e, a) => + { + Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, this, $"X60 App Control Device Extender args: {a.Event}:{a.Sig}:{a.Sig.Type}:{a.Sig.BoolValue}:{a.Sig.UShortValue}:{a.Sig.StringValue}"); + + if (a.Sig.Number == x60withZoomApp.ExtenderApplicationControlReservedSigs.HideOpenApplicationFeedback.Number) + { + AppOpenFeedback.FireUpdate(); + } + }; + x60withZoomApp.ExtenderZoomRoomAppReservedSigs.DeviceExtenderSigChange += (e, a) => + { + Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, this, $"X60 Zoom Room App Device Extender args: {a.Event}:{a.Sig}:{a.Sig.Type}:{a.Sig.BoolValue}:{a.Sig.UShortValue}:{a.Sig.StringValue}"); + + if (a.Sig.Number == x60withZoomApp.ExtenderZoomRoomAppReservedSigs.ZoomRoomIncomingCallFeedback.Number) + { + ZoomIncomingCallFeedback.FireUpdate(); + } + else if (a.Sig.Number == x60withZoomApp.ExtenderZoomRoomAppReservedSigs.ZoomRoomActiveFeedback.Number) + { + ZoomInCallFeedback.FireUpdate(); + } + }; + + x60withZoomApp.ExtenderEthernetReservedSigs.DeviceExtenderSigChange += (e, a) => + { + DeviceInfo.MacAddress = x60withZoomApp.ExtenderEthernetReservedSigs.MacAddressFeedback.StringValue; + DeviceInfo.IpAddress = x60withZoomApp.ExtenderEthernetReservedSigs.IpAddressFeedback.StringValue; + + Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, this, $"MAC: {DeviceInfo.MacAddress} IP: {DeviceInfo.IpAddress}"); + + var handler = DeviceInfoChanged; + + if (handler == null) + { + return; + } + + handler(this, new DeviceInfoEventArgs(DeviceInfo)); + }; + + x60withZoomApp.ExtenderZoomRoomAppReservedSigs.Use(); + x60withZoomApp.ExtenderApplicationControlReservedSigs.Use(); + x60withZoomApp.ExtenderEthernetReservedSigs.Use(); + } + } + /// /// Performs custom activation setup for the touchpanel controller, including /// registering messengers and linking to mobile control. @@ -323,26 +439,232 @@ namespace PepperDash.Essentials.Touchpanel } /// - /// Updates feedbacks in response to state changes. + /// Gets the URL with the correct IP address based on the connected devices and the Crestron processor's IP address. /// - /// The event sender. - /// The event arguments. + /// + /// + private string GetUrlWithCorrectIp(string url) + { + var lanAdapterId = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(EthernetAdapterType.EthernetLANAdapter); + + var processorIp = CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, lanAdapterId); + + if (csIpAddress == null || csSubnetMask == null || url == null) + { + this.LogWarning("CS IP Address Subnet Mask or url is null, cannot determine correct IP for URL"); + return url; + } + + this.LogVerbose("Processor IP: {processorIp}, CS IP: {csIpAddress}, CS Subnet Mask: {csSubnetMask}", processorIp, csIpAddress, csSubnetMask); + this.LogVerbose("Connected IP Count: {connectedIps}", ConnectedIps.Count); + + var ip = ConnectedIps.Any(ipInfo => + { + if (System.Net.IPAddress.TryParse(ipInfo.DeviceIpAddress, out var parsedIp)) + { + return csIpAddress.IsInSameSubnet(parsedIp, csSubnetMask); + } + this.LogWarning("Invalid IP address: {deviceIpAddress}", ipInfo.DeviceIpAddress); + return false; + }) ? csIpAddress.ToString() : processorIp; + + var match = Regex.Match(url, @"^http://([^:/]+):\d+/mc/app\?token=.+$"); + if (match.Success) + { + string ipa = match.Groups[1].Value; + // ip will be "192.168.1.100" + } + + // replace ipa with ip but leave the rest of the string intact + var updatedUrl = Regex.Replace(url, @"^http://[^:/]+", $"http://{ip}"); + + this.LogVerbose("Updated URL: {updatedUrl}", updatedUrl); + + return updatedUrl; + } + + private void SubscribeForMobileControlUpdates() + { + foreach (var dev in DeviceManager.AllDevices) + { + Debug.LogMessage(Serilog.Events.LogEventLevel.Information, this, $"{dev.Key}:{dev.GetType().Name}"); + } + + var mcList = DeviceManager.AllDevices.OfType().ToList(); + + if (mcList.Count == 0) + { + Debug.LogMessage(Serilog.Events.LogEventLevel.Information, this, $"No Mobile Control controller found"); + + return; + } + + // use first in list, since there should only be one. + var mc = mcList[0]; + + var bridge = mc.GetRoomBridge(_config.DefaultRoomKey); + + if (bridge == null) + { + Debug.LogMessage(Serilog.Events.LogEventLevel.Information, this, $"No Mobile Control bridge for {_config.DefaultRoomKey} found "); + return; + } + + _bridge = bridge; + + _bridge.UserCodeChanged += UpdateFeedbacks; + _bridge.AppUrlChanged += (s, a) => + { + this.LogInformation("AppURL changed"); + SetAppUrl(_bridge.AppUrl); + UpdateFeedbacks(s, a); + }; + + SetAppUrl(_bridge.AppUrl); + } + + /// + /// Sets the application URL and updates the corresponding feedback. + /// + /// The new application URL to set. + /// + /// SetAppUrl method + /// + public void SetAppUrl(string url) + { + _appUrl = GetUrlWithCorrectIp(url); + + AppUrlFeedback.FireUpdate(); + } + private void UpdateFeedbacks(object sender, EventArgs args) { UpdateFeedbacks(); } - /// - /// Updates all feedback values to reflect current state. - /// private void UpdateFeedbacks() { - foreach (var feedback in Feedbacks) + foreach (var feedback in Feedbacks) { this.LogDebug("Updating {feedbackKey}", feedback.Key); feedback.FireUpdate(); } + } + + private void UpdateZoomFeedbacks() + { + foreach (var feedback in ZoomFeedbacks) { - this.LogDebug("Updating {feedbackKey}", feedback.Key); + Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, this, $"Updating {feedback.Key}"); feedback.FireUpdate(); } } + + /// + /// HideOpenApp method + /// + public void HideOpenApp() + { + if (Panel is TswX70Base x70Panel) + { + x70Panel.ExtenderApplicationControlReservedSigs.HideOpenedApplication(); + return; + } + + if (Panel is TswX60BaseClass x60Panel) + { + x60Panel.ExtenderApplicationControlReservedSigs.HideOpenApplication(); + return; + } + } + + /// + /// OpenApp method + /// + public void OpenApp() + { + if (Panel is TswX70Base x70Panel) + { + x70Panel.ExtenderApplicationControlReservedSigs.OpenApplication(); + return; + } + + if (Panel is TswX60WithZoomRoomAppReservedSigs) + { + Debug.LogMessage(Serilog.Events.LogEventLevel.Information, this, $"X60 panel does not support zoom app"); + return; + } + } + + /// + /// CloseOpenApp method + /// + public void CloseOpenApp() + { + if (Panel is TswX70Base x70Panel) + { + x70Panel.ExtenderApplicationControlReservedSigs.CloseOpenedApplication(); + return; + } + + if (Panel is TswX60WithZoomRoomAppReservedSigs x60Panel) + { + x60Panel.ExtenderApplicationControlReservedSigs.CloseOpenedApplication(); + return; + } + } + + /// + /// EndZoomCall method + /// + public void EndZoomCall() + { + if (Panel is TswX70Base x70Panel) + { + x70Panel.ExtenderZoomRoomAppReservedSigs.ZoomRoomEndCall(); + return; + } + + if (Panel is TswX60WithZoomRoomAppReservedSigs x60Panel) + { + x60Panel.ExtenderZoomRoomAppReservedSigs.ZoomRoomEndCall(); + return; + } + } + + /// + /// UpdateDeviceInfo method + /// + public void UpdateDeviceInfo() + { + if (Panel is TswXX70Base x70Panel) + { + DeviceInfo.MacAddress = x70Panel.ExtenderEthernetReservedSigs.MacAddressFeedback.StringValue; + DeviceInfo.IpAddress = x70Panel.ExtenderEthernetReservedSigs.IpAddressFeedback.StringValue; + + var handler = DeviceInfoChanged; + + if (handler == null) + { + return; + } + + handler(this, new DeviceInfoEventArgs(DeviceInfo)); + } + + if (Panel is TswX60WithZoomRoomAppReservedSigs x60Panel) + { + DeviceInfo.MacAddress = x60Panel.ExtenderEthernetReservedSigs.MacAddressFeedback.StringValue; + DeviceInfo.IpAddress = x60Panel.ExtenderEthernetReservedSigs.IpAddressFeedback.StringValue; + + var handler = DeviceInfoChanged; + + if (handler == null) + { + return; + } + + handler(this, new DeviceInfoEventArgs(DeviceInfo)); + } + + Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, this, $"MAC: {DeviceInfo.MacAddress} IP: {DeviceInfo.IpAddress}"); + } } ///