Skip to content

Commit

Permalink
fix: cleanup and fix lockout params
Browse files Browse the repository at this point in the history
  • Loading branch information
jgutenplan committed May 10, 2024
1 parent e9a877c commit 0eed1d1
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 81 deletions.
4 changes: 2 additions & 2 deletions src/CiscoRoomOsCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

namespace epi_videoCodec_ciscoExtended
{
#region enums
internal enum eCommandType
#region enums
internal enum eCommandType
{
SessionStart,
SessionEnd,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using PepperDash.Core;
using PepperDash.Essentials.Core;

namespace PepperDash.Essentials.Touchpanel
{
public interface IMcCiscoCodecUserInterfaceAppControl : IKeyed
{
//BoolFeedback WebViewOpenFeedback { get; }

void CloseWebViewController();
void CloseWebViewOsd();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
using PepperDash.Essentials.Devices.Common.VideoCodec.Interfaces;
using PepperDash.Essentials.Touchpanel;
using Serilog.Events;
using System;
using System.Linq;
using Feedback = PepperDash.Essentials.Core.Feedback;

namespace epi_videoCodec_ciscoExtended.UserInterface.CiscoCodecUserInterface.MobileControl
{
public class McTouchpanelController : CiscoCodecUserInterface, IMobileControlTouchpanelController
public class McVideoCodecTouchpanelController : CiscoCodecUserInterface, IMcCiscoCodecUserInterfaceAppControl, IMobileControlTouchpanelController
{
private readonly McCodecUserInterfaceConfig _props;
private readonly McVideoCodecUserInterfaceConfig _props;
private IMobileControlRoomMessenger _bridge;
private IMobileControl Mc;
private string _appUrl;
Expand All @@ -32,12 +33,14 @@ public class McTouchpanelController : CiscoCodecUserInterface, IMobileControlTou

bool IMobileControlTouchpanelController.ZoomRoomController => false;

//public BoolFeedback WebViewOpenFeedback => throw new NotImplementedException();

private McVideoCodecUserInterfaceRouter _router;

public McTouchpanelController(DeviceConfig config) : base(config)
public McVideoCodecTouchpanelController(DeviceConfig config) : base(config)
{
Debug.LogMessage(LogEventLevel.Debug, "McTouchpanelController Constructor", this);
_props = ParseConfigProps<McCodecUserInterfaceConfig>(config);
_props = ParseConfigProps<McVideoCodecUserInterfaceConfig>(config);

AddPostActivationAction(SubscribeForMobileControlUpdates);

Expand Down Expand Up @@ -101,8 +104,12 @@ private void SubscribeForMobileControlUpdates()

Debug.LogMessage(LogEventLevel.Debug, "[McTouchpanelController] Subscribing to Mobile Control Events: AppUrlChanged", this);

_bridge.AppUrlChanged += (s, a) => { Debug.Console(0, this, "[McTouchpanelController] AppURL changed"); SetAppUrl(_bridge.AppUrl); UpdateFeedbacks(s, a); };

//SetAppUrl here fixing AppUrlFeedback.StringValue null after initial event
_bridge.AppUrlChanged += (s, a) => { Debug.Console(0, this, "[McTouchpanelController] AppURL changed"); UpdateFeedbacks(s, a);
SetAppUrl(_bridge.AppUrl);
};


Debug.LogMessage(LogEventLevel.Debug, "[McTouchpanelController] Building McVideoCodecUserInterfaceRouter", this);
_router = new McVideoCodecUserInterfaceRouter(this, _bridge, _props);
_router.Activate(this);
Expand All @@ -119,7 +126,7 @@ public void SetAppUrl(string url)
{
try
{
Debug.LogMessage(LogEventLevel.Verbose, $"Setting AppUrl", this);
Debug.LogMessage(LogEventLevel.Debug, $"Setting AppUrl", this);
_appUrl = url;
AppUrlFeedback.FireUpdate();
}
Expand All @@ -138,5 +145,15 @@ private void UpdateFeedbacks()
{
foreach (var feedback in Feedbacks) { feedback.FireUpdate(); }
}

public void CloseWebViewController()
{
_router.ClearCiscoCodecUiWebViewController();
}

public void CloseWebViewOsd()
{
_router.ClearCiscoCodecUiWebViewOsd();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Lockout
public UiWebViewDisplayConfig UiWebViewDisplay { get; set; }
}

public class McCodecUserInterfaceConfig : CiscoCodecUserInterfaceConfig
public class McVideoCodecUserInterfaceConfig : CiscoCodecUserInterfaceConfig
{
[JsonProperty("defaultRoomKey")]
public string DefaultRoomKey { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PepperDash.Core;
using PepperDash.Essentials.AppServer.Messengers;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;

namespace PepperDash.Essentials.Touchpanel
{
public class McVideoCodecUserInterfaceControlMessenger : MessengerBase
{
private readonly IMcCiscoCodecUserInterfaceAppControl _appControl;

public McVideoCodecUserInterfaceControlMessenger(string key, string messagePath, Device device) : base(key, messagePath, device)
{
_appControl = device as IMcCiscoCodecUserInterfaceAppControl;
}

protected override void RegisterActions()
{
if (_appControl == null)
{
Debug.Console(0, this, $"{_device.Key} does not implement ITswAppControl");
return;
}

// AddAction($"/fullStatus", (id, context) => SendFullStatus());

AddAction($"/closeWebViewController", (id, context) => _appControl.CloseWebViewController());

//_appControl.WebViewOpenFeedback.OutputChange += (s, a) =>
//{
// PostStatusMessage(JToken.FromObject(new
// {
// appOpen = a.BoolValue
// }));
//};
}

//private void SendFullStatus()
//{
// var message = new TswAppStateMessage
// {
// AppOpen = _appControl.AppOpenFeedback.BoolValue,
// };

// PostStatusMessage(message);
//}
}

//public class VideoCodecUserInterfaceAppStateMessage : DeviceStateMessageBase
//{
// [JsonProperty("appOpen", NullValueHandling = NullValueHandling.Ignore)]
// public bool? AppOpen { get; set; }
//}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
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;
Expand All @@ -18,21 +19,17 @@ namespace epi_videoCodec_ciscoExtended.UserInterface.CiscoCodecUserInterface.Mob
{
internal class McVideoCodecUserInterfaceRouter : IKeyed
{
private McTouchpanelController _mcTpController;
private McVideoCodecTouchpanelController _mcTpController;

private IVideoCodecUiExtensionsHandler _extensionsHandler;

private IRoomCombinerHandler _combinerHandler;
private IMobileControlRoomMessenger _bridge;

private McCodecUserInterfaceConfig _props { get; }

private Room _primaryRoom;
private McVideoCodecUserInterfaceConfig _props { get; }

public string Key { get; }

public string Key { get; }

private UiWebViewDisplayConfig _defaultUiWebViewDisplayConfig = new UiWebViewDisplayConfig()
{
Title = "Mobile Control",
Expand All @@ -41,9 +38,9 @@ internal class McVideoCodecUserInterfaceRouter : IKeyed
};

internal McVideoCodecUserInterfaceRouter(
McTouchpanelController ui,
McVideoCodecTouchpanelController ui,
IMobileControlRoomMessenger bridge,
McCodecUserInterfaceConfig props
McVideoCodecUserInterfaceConfig props
)
{
_props = props;
Expand All @@ -52,7 +49,7 @@ McCodecUserInterfaceConfig props
Key = ui.Key + "-McVcUiRouter";
}

internal void Activate(McTouchpanelController ui)
internal void Activate(McVideoCodecTouchpanelController ui)
{
Debug.LogMessage(
LogEventLevel.Debug,
Expand Down Expand Up @@ -199,7 +196,9 @@ EventArgs e
);
var path = _props?.Lockout?.MobileControlPath;
Debug.LogMessage(LogEventLevel.Debug, $"Lockout path: {path}", null, null);
if (path == null || path.Length == 0)

// If path is null or empty, set it to "/lockout"
if (string.IsNullOrEmpty(path))
path = "/lockout";
Debug.LogMessage(LogEventLevel.Debug, $"Lockout path: {path}", null, null);
var webViewConfig =
Expand All @@ -217,55 +216,6 @@ EventArgs e
room != null ? room.Name : primaryRoomKey
);
SendCiscoCodecUiToWebViewMcUrl(path, webViewConfig);
if (!getPrimaryKeySuccess.GetValueOrDefault())
{
Debug.LogMessage(
LogEventLevel.Debug,
$"Primary room key not found in UiMap for scenario: {curScenario.Key}",
null, null
);
}
if (thisUisUiMapRoomKeyValue == null)
{
Debug.LogMessage(
LogEventLevel.Debug,
$"[ERROR] UiMap default room key: {thisUisDefaultRoomKey} Error: UiMap must have an entry keyed to default room key with value of room connection for room state {curScenario.Key} or lockout",
null, null
);
return;
}
if (thisUisUiMapRoomKeyValue == "lockout")
{
Debug.LogMessage(
LogEventLevel.Debug,
$"UiMap default room key: {thisUisDefaultRoomKey} is in lockout state",
null, null
);
var path = _props.Lockout.MobileControlPath;
if (path == null || path.Length == 0)
path = "/lockout";
var webViewConfig =
_props.Lockout.UiWebViewDisplay == null
? _defaultUiWebViewDisplayConfig
: _props.Lockout.UiWebViewDisplay;
var room = DeviceManager.GetDeviceForKey(primaryRoomKey) as EssentialsRoomBase;
webViewConfig.QueryParams.Add("primary", room?.Name?.Length > 0 ? room.Name : primaryRoomKey);
SendCiscoCodecUiToWebViewMcUrl(path, webViewConfig);
return;
}
Debug.LogMessage(
LogEventLevel.Debug,
$"ui with default room key {thisUisDefaultRoomKey} is not locked out",
null, null
);
}
catch (Exception ex)
{
Debug.LogMessage(ex, "Error in Combiner_RoomCombinationScenarioChanged_Lockout_EventHandler", null, null);
Debug.LogMessage(LogEventLevel.Debug,
$"Error in Combiner_RoomCombinationScenarioChanged_Lockout_EventHandler: {ex.Message}, {ex.StackTrace}", null, null);
}
}
return;
}
Debug.LogMessage(
Expand Down Expand Up @@ -377,7 +327,7 @@ UiWebViewDisplayConfig webViewConfig
);
// Parse the _appUrl into a Uri object
var appUrl = _mcTpController.AppUrlFeedback.StringValue;
if (appUrl == null)
if (appUrl == null)
{
Debug.LogMessage(
LogEventLevel.Debug,
Expand All @@ -388,9 +338,9 @@ UiWebViewDisplayConfig webViewConfig
}
//var printableAppUrl = _mcTpController?.AppUrlFeedback?.StringValue?.MaskQParamTokenInUrl();
//Debug.LogMessage(
// LogEventLevel.Debug,
// $"SendCiscoCodecUiToWebViewMcUrl: {printableAppUrl}",
// this
// LogEventLevel.Debug,
// $"SendCiscoCodecUiToWebViewMcUrl: {printableAppUrl}",
// this
//);

UriBuilder uriBuilder = new UriBuilder(appUrl);
Expand All @@ -399,7 +349,7 @@ UiWebViewDisplayConfig webViewConfig
var qparams = webViewConfig.QueryParams;
if (qparams != null)
{
var parameters = HttpUtility.ParseQueryString(appUrl);
var parameters = HttpUtility.ParseQueryString(uriBuilder.Query);
foreach (var item in qparams)
{
parameters.Add(item.Key, item.Value);
Expand All @@ -413,7 +363,7 @@ UiWebViewDisplayConfig webViewConfig
// Get the final URL
var url = uriBuilder.ToString();

var printableUrl = url.MaskQParamTokenInUrl();
var printableUrl = uriBuilder.ToString().MaskQParamTokenInUrl();

Debug.LogMessage(
LogEventLevel.Debug,
Expand Down Expand Up @@ -441,5 +391,18 @@ UiWebViewDisplayConfig webViewConfig
}
);
}
}

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" });
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using epi_videoCodec_ciscoExtended.UserInterface.UserInterfaceWebViewDisplay;
using PepperDash.Essentials.Devices.Common.VideoCodec.Interfaces;

namespace epi_videoCodec_ciscoExtended.UserInterface.UserInterfaceExtensions
{
public interface IVideoCodecUiExtensionsHandler : IVideoCodecUiExtensionsWebViewDisplayActions, IVideoCodecUiExtensionsClickedEvent
{
}

public interface IVideoCodecUiExtensions
{
IVideoCodecUiExtensionsHandler VideoCodecUiExtensionsHandler { get; set; }
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

namespace epi_videoCodec_ciscoExtended.UserInterface.UserInterfaceExtensions
{
public interface IVideoCodecUiExtensionsClickedEvent
{
event EventHandler<UiExtensionsClickedEventArgs> UiExtensionsClickedEvent;
}

public class UiExtensionsClickedEventArgs : EventArgs
{
public bool Clicked { get; set; }
public string Id { get; set; }

public UiExtensionsClickedEventArgs(bool clicked, string id)
{
Clicked = clicked;
Id = id;
}

public UiExtensionsClickedEventArgs()
{
}
}
}
Loading

0 comments on commit 0eed1d1

Please sign in to comment.