From 8c95ec489fa18005ee410bfe988f2a3c9ea9a557 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 1 Jul 2024 12:04:45 -0500 Subject: [PATCH] fix: add null check for canceling lockout timer --- .../McVideoCodecUserInterfaceRouter.cs | 754 +++++++++--------- 1 file changed, 377 insertions(+), 377 deletions(-) diff --git a/src/UserInterface/CiscoCodecUserInterface/MobileControl/McVideoCodecUserInterfaceRouter.cs b/src/UserInterface/CiscoCodecUserInterface/MobileControl/McVideoCodecUserInterfaceRouter.cs index 5c5a807..77ac687 100644 --- a/src/UserInterface/CiscoCodecUserInterface/MobileControl/McVideoCodecUserInterfaceRouter.cs +++ b/src/UserInterface/CiscoCodecUserInterface/MobileControl/McVideoCodecUserInterfaceRouter.cs @@ -1,155 +1,150 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Crestron.SimplSharp.Net; +using Crestron.SimplSharp.Net; using epi_videoCodec_ciscoExtended.UserInterface.CiscoCodecUserInterface.RoomCombiner; using epi_videoCodec_ciscoExtended.UserInterface.UserInterfaceExtensions; -using epi_videoCodec_ciscoExtended.UserInterface.UserInterfaceExtensions.Panels; using epi_videoCodec_ciscoExtended.UserInterface.UserInterfaceWebViewDisplay; -using Independentsoft.Json.Parser; -using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core; -using PepperDash.Essentials.Core.Devices; using PepperDash.Essentials.Core.DeviceTypeInterfaces; -using PepperDash.Essentials.Devices.Common.VideoCodec.Interfaces; using Serilog.Events; +using System; +using System.Collections.Generic; +using System.Linq; namespace epi_videoCodec_ciscoExtended.UserInterface.CiscoCodecUserInterface.MobileControl { - internal class McVideoCodecUserInterfaceRouter : IKeyed - { - private McVideoCodecTouchpanelController _mcTpController; - - private ICiscoCodecUiExtensionsHandler _extensionsHandler; - - private IRoomCombinerHandler _combinerHandler; - private IMobileControlRoomMessenger _bridge; - - private McVideoCodecUserInterfaceConfig _props { get; } - - public string Key { get; } - - private System.Timers.Timer _lockoutPollTimer; - - private string _thisUisDefaultRoomKey; - private string _primaryRoomKey; - - private UiWebViewDisplayConfig _defaultUiWebViewDisplayConfig = new UiWebViewDisplayConfig() - { - Title = "Mobile Control", - Target = "Controller", - Mode = "Modal" - }; - - internal McVideoCodecUserInterfaceRouter( - McVideoCodecTouchpanelController ui, - IMobileControlRoomMessenger bridge, - McVideoCodecUserInterfaceConfig props - ) - { - _props = props; - _mcTpController = ui; - _bridge = bridge; - Key = ui.Key + "-McVcUiRouter"; - } - - internal void Activate(McVideoCodecTouchpanelController ui) - { - Debug.LogMessage( - LogEventLevel.Debug, - $"Activating VideoCodecMobileControlRouter for {ui.Key}", - this - ); - //set private props after activation so everything is instantiated - if (ui == null) - { - Debug.LogMessage(LogEventLevel.Debug, $"Error: {ui.Key} is null", this); - return; - } - _mcTpController = ui; - _extensionsHandler = ui.CiscoCodecUiExtensionsHandler; - Debug.LogMessage( - LogEventLevel.Debug, - "VideoCodecUiExtensionsHandler null: {0}", - this, - ui.CiscoCodecUiExtensionsHandler == null - ); - - _combinerHandler = ui.RoomCombinerHandler; - Debug.LogMessage( - LogEventLevel.Debug, - "EssentialsRoomCombiner null: {0}", - this, - ui.RoomCombinerHandler.EssentialsRoomCombiner == null - ); - Debug.LogMessage( - LogEventLevel.Debug, - "MobileControlRoomBridge null: {0}", - this, - _bridge == null - ); - - if (_extensionsHandler == null) - { - Debug.LogMessage( - LogEventLevel.Debug, - "[Warning]: VideoCodecUiExtensionsHandler is null. Skipping VideoCodecMobileControlRouter Subscriptions", - this - ); - return; - } - Debug.LogMessage( - LogEventLevel.Debug, - "VideoCodecMobileControlRouter Registering for VideoCodecUiExtensionsHandler.UiExtensionsClickedEvent", - this - ); - - - _mcTpController.UisCiscoCodec.IsReadyChange += (s, a) => - { - if (!_mcTpController.UisCiscoCodec.IsReady) return; - + internal class McVideoCodecUserInterfaceRouter : IKeyed + { + private McVideoCodecTouchpanelController _mcTpController; + + private ICiscoCodecUiExtensionsHandler _extensionsHandler; + + private IRoomCombinerHandler _combinerHandler; + private IMobileControlRoomMessenger _bridge; + + private McVideoCodecUserInterfaceConfig _props { get; } + + public string Key { get; } + + private System.Timers.Timer _lockoutPollTimer; + + private string _thisUisDefaultRoomKey; + private string _primaryRoomKey; + + private UiWebViewDisplayConfig _defaultUiWebViewDisplayConfig = new UiWebViewDisplayConfig() + { + Title = "Mobile Control", + Target = "Controller", + Mode = "Modal" + }; + + internal McVideoCodecUserInterfaceRouter( + McVideoCodecTouchpanelController ui, + IMobileControlRoomMessenger bridge, + McVideoCodecUserInterfaceConfig props + ) + { + _props = props; + _mcTpController = ui; + _bridge = bridge; + Key = ui.Key + "-McVcUiRouter"; + } + + internal void Activate(McVideoCodecTouchpanelController ui) + { + Debug.LogMessage( + LogEventLevel.Debug, + $"Activating VideoCodecMobileControlRouter for {ui.Key}", + this + ); + //set private props after activation so everything is instantiated + if (ui == null) + { + Debug.LogMessage(LogEventLevel.Debug, $"Error: {ui.Key} is null", this); + return; + } + _mcTpController = ui; + _extensionsHandler = ui.CiscoCodecUiExtensionsHandler; + Debug.LogMessage( + LogEventLevel.Debug, + "VideoCodecUiExtensionsHandler null: {0}", + this, + ui.CiscoCodecUiExtensionsHandler == null + ); + + _combinerHandler = ui.RoomCombinerHandler; + Debug.LogMessage( + LogEventLevel.Debug, + "EssentialsRoomCombiner null: {0}", + this, + ui.RoomCombinerHandler.EssentialsRoomCombiner == null + ); + Debug.LogMessage( + LogEventLevel.Debug, + "MobileControlRoomBridge null: {0}", + this, + _bridge == null + ); + + if (_extensionsHandler == null) + { + Debug.LogMessage( + LogEventLevel.Debug, + "[Warning]: VideoCodecUiExtensionsHandler is null. Skipping VideoCodecMobileControlRouter Subscriptions", + this + ); + return; + } + Debug.LogMessage( + LogEventLevel.Debug, + "VideoCodecMobileControlRouter Registering for VideoCodecUiExtensionsHandler.UiExtensionsClickedEvent", + this + ); + + + _mcTpController.UisCiscoCodec.IsReadyChange += (s, a) => + { + if (!_mcTpController.UisCiscoCodec.IsReady) return; + //send lockout if in lockout state - HandleRoomCombineScenarioChanged(); + HandleRoomCombineScenarioChanged(); }; - if (_combinerHandler.EssentialsRoomCombiner != null) - { - //subscribe to events for routing buttons from codec ui to mobile control - _combinerHandler.EssentialsRoomCombiner.RoomCombinationScenarioChanged += - Combiner_RoomCombinationScenarioChanged_Lockout_EventHandler; - } - - _extensionsHandler.UiExtensionsClickedEvent += - VideoCodecUiExtensionsClickedMcEventHandler; - - _thisUisDefaultRoomKey = _mcTpController?.DefaultRoomKey; - - Debug.LogMessage( - LogEventLevel.Debug, - "VideoCodecMobileControlRouter Registering for MobileControlRoomBridge.AppUrlChanged", - this - ); - - Debug.LogMessage( - LogEventLevel.Debug, - "VideoCodecMobileControlRouter initialized for {0}", - this, - ui.Key - ); - } - - private void Combiner_RoomCombinationScenarioChanged_Lockout_EventHandler( - object sender, - EventArgs e - ) - { - HandleRoomCombineScenarioChanged(); - } - - private void HandleRoomCombineScenarioChanged() - { + if (_combinerHandler.EssentialsRoomCombiner != null) + { + //subscribe to events for routing buttons from codec ui to mobile control + _combinerHandler.EssentialsRoomCombiner.RoomCombinationScenarioChanged += + Combiner_RoomCombinationScenarioChanged_Lockout_EventHandler; + } + + _extensionsHandler.UiExtensionsClickedEvent += + VideoCodecUiExtensionsClickedMcEventHandler; + + _thisUisDefaultRoomKey = _mcTpController?.DefaultRoomKey; + + Debug.LogMessage( + LogEventLevel.Debug, + "VideoCodecMobileControlRouter Registering for MobileControlRoomBridge.AppUrlChanged", + this + ); + + Debug.LogMessage( + LogEventLevel.Debug, + "VideoCodecMobileControlRouter initialized for {0}", + this, + ui.Key + ); + } + + private void Combiner_RoomCombinationScenarioChanged_Lockout_EventHandler( + object sender, + EventArgs e + ) + { + HandleRoomCombineScenarioChanged(); + } + + private void HandleRoomCombineScenarioChanged() + { try { Debug.LogMessage( @@ -218,24 +213,24 @@ private void HandleRoomCombineScenarioChanged() _mcTpController.UisCiscoCodec.EnqueueCommand(UiWebViewDisplay.xCommandStatus()); if (_mcTpController.EnableLockoutPoll) { - // Start the timer when lockout occurs - if (_lockoutPollTimer == null) - { - _lockoutPollTimer = new System.Timers.Timer( - _props?.Lockout?.PollIntervalMs > 0 ? _props.Lockout.PollIntervalMs : 5000 - ); - _lockoutPollTimer.Enabled = false; + // Start the timer when lockout occurs + if (_lockoutPollTimer == null) + { + _lockoutPollTimer = new System.Timers.Timer( + _props?.Lockout?.PollIntervalMs > 0 ? _props.Lockout.PollIntervalMs : 5000 + ); + _lockoutPollTimer.Enabled = false; _lockoutPollTimer.AutoReset = true; } _lockoutPollTimer.Start(); _lockoutPollTimer.Elapsed += (s, a) => { - Debug.LogMessage(LogEventLevel.Verbose, "Lockout Poll Timer Elapsed", null, null); + Debug.LogMessage(LogEventLevel.Verbose, "Lockout Poll Timer Elapsed", null, null); if (!_mcTpController.LockedOut) { Debug.LogMessage(LogEventLevel.Verbose, $"_mcTpController.LockedOut: {_mcTpController.LockedOut}", null, null); //if not in lockout state and was previously locked out - CancelLockoutTimer(); + CancelLockoutTimer(); return; } _mcTpController.UisCiscoCodec.EnqueueCommand(UiWebViewDisplay.xCommandStatus()); @@ -245,7 +240,7 @@ private void HandleRoomCombineScenarioChanged() return; } - CancelLockoutTimer(); + CancelLockoutTimer(); Debug.LogMessage( LogEventLevel.Debug, $"ui with default room key {_thisUisDefaultRoomKey} is not locked out", @@ -270,9 +265,14 @@ private void HandleRoomCombineScenarioChanged() } } - private void CancelLockoutTimer() - { - Debug.LogMessage(LogEventLevel.Verbose, $"Canceling Lockout Poll Timer for: {_mcTpController.Key}", null, _mcTpController.Key); + private void CancelLockoutTimer() + { + if (_lockoutPollTimer == null) + { + return; + } + + Debug.LogMessage(LogEventLevel.Verbose, $"Canceling Lockout Poll Timer for: {_mcTpController.Key}", null, _mcTpController.Key); _extensionsHandler.UiWebViewChanagedEvent -= LockoutUiWebViewChanagedEventHandler; _mcTpController.LockedOut = false; ClearCiscoCodecUiWebViewController(); @@ -280,229 +280,229 @@ private void CancelLockoutTimer() _lockoutPollTimer.Dispose(); } - public void LockoutUiWebViewChanagedEventHandler(object sender, UiWebViewChanagedEventArgs args) - { - bool isError = args?.UiWebViewStatus?.IsError ?? false; - if (isError) //isError means no webview open - { - Debug.LogMessage( - LogEventLevel.Debug, - $"Error in UiWebViewChanagedEventHandler. XPath: {args?.UiWebViewStatus?.ErrorStatus?.XPath?.Value}" + - $"Reason: {args?.UiWebViewStatus?.ErrorStatus?.Reason?.Value}", null, null); - - //if web view not open and in lockout send lockout to web view - if (_mcTpController.LockedOut == true) - { - SendLockout(_thisUisDefaultRoomKey, _primaryRoomKey); - } - return; - } - - if (_mcTpController.LockedOut == false) - { - UiWebView uiWebView = args?.UiWebViewStatus?.UiWebView; - _extensionsHandler.UiWebViewClearAction?.Invoke( - new UiWebViewDisplayClearActionArgs() { Target = "Controller" } - ); - } - } - - private void SendLockout(string thisUisDefaultRoomKey, string primaryRoomKey) - { - Debug.LogMessage( - LogEventLevel.Debug, - $"UiMap default room key: {thisUisDefaultRoomKey} is in lockout state", - null, - null - ); - var path = _props?.Lockout?.MobileControlPath; - Debug.LogMessage(LogEventLevel.Debug, $"Lockout path: {path}", null, null); - if (path == null || path.Length == 0) - path = "/lockout"; - Debug.LogMessage(LogEventLevel.Debug, $"Lockout path: {path}", null, null); - var webViewConfig = - _props?.Lockout?.UiWebViewDisplay == null - ? _defaultUiWebViewDisplayConfig - : _props.Lockout.UiWebViewDisplay; - if (!string.IsNullOrEmpty(primaryRoomKey)) - { - var room = DeviceManager.GetDeviceForKey(primaryRoomKey) as IKeyName; - Debug.LogMessage(LogEventLevel.Debug, $"room: {room?.Name}", null, null); - if (webViewConfig.QueryParams == null) - { - webViewConfig.QueryParams = new Dictionary(); - } - - webViewConfig.QueryParams["primaryRoomName"] = - room != null ? room.Name : primaryRoomKey; - } - SendCiscoCodecUiToWebViewMcUrl(path, webViewConfig); - } - - private void VideoCodecUiExtensionsClickedMcEventHandler( - object sender, - UiExtensionsClickedEventArgs e - ) - { - Debug.LogMessage( - LogEventLevel.Debug, - $"VideoCodecUiExtensionsClickedMcEventHandler: {e.Id}", - this - ); - try - { - //navigator button click build url and use VideoCodecUiExtensionsHandler action to send to mobile control - var panelId = e.Id; - var extensions = _props.Extensions; - if (extensions == null || !extensions.Panels.Any()) - { - Debug.LogMessage( - LogEventLevel.Debug, - "No extensions found for VideoCodecMobileControlRouter", - _mcTpController - ); - return; - } - var panels = extensions.Panels; - var mcPanel = panels.Find((pp) => pp.PanelId == panelId); - if (mcPanel == null) - { - Debug.LogMessage( - LogEventLevel.Debug, - "Panel not found for VideoCodecMobileControlRouter", - this - ); - return; - } - if (mcPanel.MobileControlPath == null || mcPanel.MobileControlPath.Length == 0) - { - Debug.LogMessage( - LogEventLevel.Debug, - $"MobileControlPath not found for {mcPanel.Name}", - this - ); - return; - } - if (mcPanel.UiWebViewDisplay == null) - { - Debug.LogMessage( - LogEventLevel.Debug, - $"[Warning] UiWebViewDisplay not found for {mcPanel.Name} using default Title: ${_defaultUiWebViewDisplayConfig.Title}, Mode: {_defaultUiWebViewDisplayConfig.Mode}, Target: {_defaultUiWebViewDisplayConfig}", - this - ); - } - SendCiscoCodecUiToWebViewMcUrl(mcPanel.MobileControlPath, mcPanel.UiWebViewDisplay); - } - catch (Exception ex) - { - Debug.LogMessage(ex, "Error Sending Mc URL to Cisco Ui", this); - Debug.LogMessage( - LogEventLevel.Debug, - $"Error Sending Mc URL to Cisco Ui: {ex.Message}", - this - ); - } - } - - /// - /// Send the cisco ui to a webview with mc app url + path using the webViewConfig - /// - /// - /// - public void SendCiscoCodecUiToWebViewMcUrl( - string mcPath, - UiWebViewDisplayConfig webViewConfig - ) - { - Debug.LogMessage( - LogEventLevel.Debug, - $"SendCiscoCodecUiToWebViewMcUrl: {mcPath}, webViewConfig null: {webViewConfig == null}, " - + $"_McTouchPanelController: {_mcTpController == null}, " - + $"AppUrlFeedback null: {_mcTpController?.AppUrlFeedback == null}, " - + $"appUrl: {_mcTpController?.AppUrlFeedback?.StringValue}", - this - ); - // Parse the _appUrl into a Uri object - var appUrl = _mcTpController.AppUrlFeedback.StringValue; - if (appUrl == null) - { - Debug.LogMessage( - LogEventLevel.Debug, - "AppUrl is null, cannot send to WebView", - this - ); - return; - } - //var printableAppUrl = _mcTpController?.AppUrlFeedback?.StringValue?.MaskQParamTokenInUrl(); - //Debug.LogMessage( - // LogEventLevel.Debug, - // $"SendCiscoCodecUiToWebViewMcUrl: {printableAppUrl}", - // this - //); - - UriBuilder uriBuilder = new UriBuilder(appUrl); - - //check for qparams - var qparams = webViewConfig.QueryParams; - if (qparams != null) - { - var parameters = HttpUtility.ParseQueryString(uriBuilder.Query); - foreach (var item in qparams) - { - parameters.Add(item.Key, item.Value); - } - uriBuilder.Query = parameters.ToString(); - } - - // Append suffix (i.e: "/lockout") to the path - uriBuilder.Path = uriBuilder.Path.TrimEnd('/') + mcPath; - - // Get the final URL - var url = uriBuilder.ToString(); - - var printableUrl = uriBuilder.ToString().MaskQParamTokenInUrl(); - - Debug.LogMessage( - LogEventLevel.Debug, - "[MobileControlClickedEvent] Sending Mobile Control URL: {0}", - this, - printableUrl - ); - - _extensionsHandler.UiWebViewDisplayAction?.Invoke( - new UiWebViewDisplayActionArgs() - { - Title = - webViewConfig.Title != null - ? webViewConfig.Title - : _defaultUiWebViewDisplayConfig.Title, - Url = url, - Target = - webViewConfig.Target != null - ? webViewConfig.Target - : _defaultUiWebViewDisplayConfig.Target, - Mode = - webViewConfig.Mode != null - ? webViewConfig.Mode - : _defaultUiWebViewDisplayConfig.Mode - } - ); - } - - public void ClearCiscoCodecUiWebViewController() - { - Debug.LogMessage(LogEventLevel.Debug, "ClearCiscoCodecUiWebViewController", this); - _extensionsHandler?.UiWebViewClearAction?.Invoke( - new UiWebViewDisplayClearActionArgs() { Target = "Controller" } - ); - } - - public void ClearCiscoCodecUiWebViewOsd() - { - Debug.LogMessage(LogEventLevel.Debug, "ClearCiscoCodecUiWebViewOsd", this); - _extensionsHandler?.UiWebViewClearAction?.Invoke( - new UiWebViewDisplayClearActionArgs() { Target = "OSD" } - ); - } - } + public void LockoutUiWebViewChanagedEventHandler(object sender, UiWebViewChanagedEventArgs args) + { + bool isError = args?.UiWebViewStatus?.IsError ?? false; + if (isError) //isError means no webview open + { + Debug.LogMessage( + LogEventLevel.Debug, + $"Error in UiWebViewChanagedEventHandler. XPath: {args?.UiWebViewStatus?.ErrorStatus?.XPath?.Value}" + + $"Reason: {args?.UiWebViewStatus?.ErrorStatus?.Reason?.Value}", null, null); + + //if web view not open and in lockout send lockout to web view + if (_mcTpController.LockedOut == true) + { + SendLockout(_thisUisDefaultRoomKey, _primaryRoomKey); + } + return; + } + + if (_mcTpController.LockedOut == false) + { + UiWebView uiWebView = args?.UiWebViewStatus?.UiWebView; + _extensionsHandler.UiWebViewClearAction?.Invoke( + new UiWebViewDisplayClearActionArgs() { Target = "Controller" } + ); + } + } + + private void SendLockout(string thisUisDefaultRoomKey, string primaryRoomKey) + { + Debug.LogMessage( + LogEventLevel.Debug, + $"UiMap default room key: {thisUisDefaultRoomKey} is in lockout state", + null, + null + ); + var path = _props?.Lockout?.MobileControlPath; + Debug.LogMessage(LogEventLevel.Debug, $"Lockout path: {path}", null, null); + if (path == null || path.Length == 0) + path = "/lockout"; + Debug.LogMessage(LogEventLevel.Debug, $"Lockout path: {path}", null, null); + var webViewConfig = + _props?.Lockout?.UiWebViewDisplay == null + ? _defaultUiWebViewDisplayConfig + : _props.Lockout.UiWebViewDisplay; + if (!string.IsNullOrEmpty(primaryRoomKey)) + { + var room = DeviceManager.GetDeviceForKey(primaryRoomKey) as IKeyName; + Debug.LogMessage(LogEventLevel.Debug, $"room: {room?.Name}", null, null); + if (webViewConfig.QueryParams == null) + { + webViewConfig.QueryParams = new Dictionary(); + } + + webViewConfig.QueryParams["primaryRoomName"] = + room != null ? room.Name : primaryRoomKey; + } + SendCiscoCodecUiToWebViewMcUrl(path, webViewConfig); + } + + private void VideoCodecUiExtensionsClickedMcEventHandler( + object sender, + UiExtensionsClickedEventArgs e + ) + { + Debug.LogMessage( + LogEventLevel.Debug, + $"VideoCodecUiExtensionsClickedMcEventHandler: {e.Id}", + this + ); + try + { + //navigator button click build url and use VideoCodecUiExtensionsHandler action to send to mobile control + var panelId = e.Id; + var extensions = _props.Extensions; + if (extensions == null || !extensions.Panels.Any()) + { + Debug.LogMessage( + LogEventLevel.Debug, + "No extensions found for VideoCodecMobileControlRouter", + _mcTpController + ); + return; + } + var panels = extensions.Panels; + var mcPanel = panels.Find((pp) => pp.PanelId == panelId); + if (mcPanel == null) + { + Debug.LogMessage( + LogEventLevel.Debug, + "Panel not found for VideoCodecMobileControlRouter", + this + ); + return; + } + if (mcPanel.MobileControlPath == null || mcPanel.MobileControlPath.Length == 0) + { + Debug.LogMessage( + LogEventLevel.Debug, + $"MobileControlPath not found for {mcPanel.Name}", + this + ); + return; + } + if (mcPanel.UiWebViewDisplay == null) + { + Debug.LogMessage( + LogEventLevel.Debug, + $"[Warning] UiWebViewDisplay not found for {mcPanel.Name} using default Title: ${_defaultUiWebViewDisplayConfig.Title}, Mode: {_defaultUiWebViewDisplayConfig.Mode}, Target: {_defaultUiWebViewDisplayConfig}", + this + ); + } + SendCiscoCodecUiToWebViewMcUrl(mcPanel.MobileControlPath, mcPanel.UiWebViewDisplay); + } + catch (Exception ex) + { + Debug.LogMessage(ex, "Error Sending Mc URL to Cisco Ui", this); + Debug.LogMessage( + LogEventLevel.Debug, + $"Error Sending Mc URL to Cisco Ui: {ex.Message}", + this + ); + } + } + + /// + /// Send the cisco ui to a webview with mc app url + path using the webViewConfig + /// + /// + /// + public void SendCiscoCodecUiToWebViewMcUrl( + string mcPath, + UiWebViewDisplayConfig webViewConfig + ) + { + Debug.LogMessage( + LogEventLevel.Debug, + $"SendCiscoCodecUiToWebViewMcUrl: {mcPath}, webViewConfig null: {webViewConfig == null}, " + + $"_McTouchPanelController: {_mcTpController == null}, " + + $"AppUrlFeedback null: {_mcTpController?.AppUrlFeedback == null}, " + + $"appUrl: {_mcTpController?.AppUrlFeedback?.StringValue}", + this + ); + // Parse the _appUrl into a Uri object + var appUrl = _mcTpController.AppUrlFeedback.StringValue; + if (appUrl == null) + { + Debug.LogMessage( + LogEventLevel.Debug, + "AppUrl is null, cannot send to WebView", + this + ); + return; + } + //var printableAppUrl = _mcTpController?.AppUrlFeedback?.StringValue?.MaskQParamTokenInUrl(); + //Debug.LogMessage( + // LogEventLevel.Debug, + // $"SendCiscoCodecUiToWebViewMcUrl: {printableAppUrl}", + // this + //); + + UriBuilder uriBuilder = new UriBuilder(appUrl); + + //check for qparams + var qparams = webViewConfig.QueryParams; + if (qparams != null) + { + var parameters = HttpUtility.ParseQueryString(uriBuilder.Query); + foreach (var item in qparams) + { + parameters.Add(item.Key, item.Value); + } + uriBuilder.Query = parameters.ToString(); + } + + // Append suffix (i.e: "/lockout") to the path + uriBuilder.Path = uriBuilder.Path.TrimEnd('/') + mcPath; + + // Get the final URL + var url = uriBuilder.ToString(); + + var printableUrl = uriBuilder.ToString().MaskQParamTokenInUrl(); + + Debug.LogMessage( + LogEventLevel.Debug, + "[MobileControlClickedEvent] Sending Mobile Control URL: {0}", + this, + printableUrl + ); + + _extensionsHandler.UiWebViewDisplayAction?.Invoke( + new UiWebViewDisplayActionArgs() + { + Title = + webViewConfig.Title != null + ? webViewConfig.Title + : _defaultUiWebViewDisplayConfig.Title, + Url = url, + Target = + webViewConfig.Target != null + ? webViewConfig.Target + : _defaultUiWebViewDisplayConfig.Target, + Mode = + webViewConfig.Mode != null + ? webViewConfig.Mode + : _defaultUiWebViewDisplayConfig.Mode + } + ); + } + + public void ClearCiscoCodecUiWebViewController() + { + Debug.LogMessage(LogEventLevel.Debug, "ClearCiscoCodecUiWebViewController", this); + _extensionsHandler?.UiWebViewClearAction?.Invoke( + new UiWebViewDisplayClearActionArgs() { Target = "Controller" } + ); + } + + public void ClearCiscoCodecUiWebViewOsd() + { + Debug.LogMessage(LogEventLevel.Debug, "ClearCiscoCodecUiWebViewOsd", this); + _extensionsHandler?.UiWebViewClearAction?.Invoke( + new UiWebViewDisplayClearActionArgs() { Target = "OSD" } + ); + } + } }