Skip to content

Commit

Permalink
fix: updates to lockout logic to get polling working and also to get …
Browse files Browse the repository at this point in the history
…external sources working with new ui extensions logic
  • Loading branch information
ndorin committed May 15, 2024
1 parent d43a9c7 commit 2161398
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 128 deletions.
3 changes: 2 additions & 1 deletion src/CiscoRoomOsCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ public CiscoCodec(DeviceConfig config, IBasicCommunication comm)
this,
EnqueueCommand
);

}

_scheduleCheckTimer = new CTimer(ScheduleTimeCheck, null, 0, 15000);
Expand Down Expand Up @@ -1705,7 +1706,7 @@ public override void Initialize()
RegisterH323Configuration();
RegisterAutoAnswer();
RegisterDisconnectEvents();
RegisterUserInterfaceEvents();
//RegisterUserInterfaceEvents();

var socket = Communication as ISocketStatus;
if (socket != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,19 @@ internal void Activate(McVideoCodecTouchpanelController ui)
this
);


_mcTpController.UisCiscoCodec.IsReadyChange += (s, a) =>
{
if (!_mcTpController.UisCiscoCodec.IsReady) return;

//send lockout if in lockout state
HandleRoomCombineScenarioChanged();
};

//subscribe to events for routing buttons from codec ui to mobile control
_combinerHandler.EssentialsRoomCombiner.RoomCombinationScenarioChanged +=
Combiner_RoomCombinationScenarioChanged_Lockout_EventHandler;

_extensionsHandler.UiExtensionsClickedEvent +=
VideoCodecUiExtensionsClickedMcEventHandler;

Expand All @@ -132,121 +142,129 @@ private void Combiner_RoomCombinationScenarioChanged_Lockout_EventHandler(
EventArgs e
)
{
try
{
Debug.LogMessage(
LogEventLevel.Debug,
"Combiner_RoomCombinationScenarioChanged_Lockout_EventHandler",
null,
null
);

var combiner = _combinerHandler?.EssentialsRoomCombiner;
var curScenario = combiner?.CurrentScenario;
var uimap = curScenario?.UiMap;
if (uimap == null)
{
Debug.LogMessage(LogEventLevel.Debug, "uimap is null", null, null);
return;
}
Debug.LogMessage(
LogEventLevel.Debug,
$"thisUisDefaultRoomKey: {_thisUisDefaultRoomKey}",
null,
null
);
var thisUisUiMapRoomKeyValue = (
uimap?.FirstOrDefault((kv) => kv.Key == _thisUisDefaultRoomKey)
)?.Value;
Debug.LogMessage(
LogEventLevel.Debug,
$"thisUisUiMapRoomKeyValue: {thisUisUiMapRoomKeyValue}",
null,
null
);
var getPrimaryKeySuccess = uimap?.TryGetValue("primary", out _primaryRoomKey);
Debug.LogMessage(
LogEventLevel.Debug,
$"primaryRoomKey done: {_primaryRoomKey}",
null,
null
);

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);
_mcTpController.LockedOut = true;
//SendLockout(_thisUisDefaultRoomKey, _primaryRoomKey);
_extensionsHandler.UiWebViewChanagedEvent += LockoutUiWebViewChanagedEventHandler;
_mcTpController.UisCiscoCodec.EnqueueCommand(UiWebViewDisplay.xCommandStatus());
if (_mcTpController.EnableLockoutPoll)
{
// Start the timer when lockout occurs
_lockoutPollTimer = new System.Timers.Timer(
_props?.Lockout?.PollIntervalMs > 0 ? _props.Lockout.PollIntervalMs : 5000
);
_lockoutPollTimer.AutoReset = true;
_lockoutPollTimer.Enabled = true;
_lockoutPollTimer.Elapsed += (s, a) =>
{
if (!_mcTpController.LockedOut)
{
_extensionsHandler.UiWebViewChanagedEvent -= LockoutUiWebViewChanagedEventHandler;
_lockoutPollTimer.Enabled = false;
_lockoutPollTimer.Dispose();
return;
}
_mcTpController.UisCiscoCodec.EnqueueCommand(UiWebViewDisplay.xCommandStatus());
};
return;
}
return;
}
_extensionsHandler.UiWebViewChanagedEvent -= LockoutUiWebViewChanagedEventHandler;
_mcTpController.LockedOut = false;
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
);
}
HandleRoomCombineScenarioChanged();
}

private void HandleRoomCombineScenarioChanged()
{
try
{
Debug.LogMessage(
LogEventLevel.Debug,
"Combiner_RoomCombinationScenarioChanged_Lockout_EventHandler",
null,
null
);

var combiner = _combinerHandler?.EssentialsRoomCombiner;
var curScenario = combiner?.CurrentScenario;
var uimap = curScenario?.UiMap;
if (uimap == null)
{
Debug.LogMessage(LogEventLevel.Debug, "uimap is null", null, null);
return;
}
Debug.LogMessage(
LogEventLevel.Debug,
$"thisUisDefaultRoomKey: {_thisUisDefaultRoomKey}",
null,
null
);
var thisUisUiMapRoomKeyValue = (
uimap?.FirstOrDefault((kv) => kv.Key == _thisUisDefaultRoomKey)
)?.Value;
Debug.LogMessage(
LogEventLevel.Debug,
$"thisUisUiMapRoomKeyValue: {thisUisUiMapRoomKeyValue}",
null,
null
);
var getPrimaryKeySuccess = uimap?.TryGetValue("primary", out _primaryRoomKey);
Debug.LogMessage(
LogEventLevel.Debug,
$"primaryRoomKey done: {_primaryRoomKey}",
null,
null
);

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);
_mcTpController.LockedOut = true;
//SendLockout(_thisUisDefaultRoomKey, _primaryRoomKey);
_extensionsHandler.UiWebViewChanagedEvent += LockoutUiWebViewChanagedEventHandler;
_mcTpController.UisCiscoCodec.EnqueueCommand(UiWebViewDisplay.xCommandStatus());
if (_mcTpController.EnableLockoutPoll)
{
// Start the timer when lockout occurs
_lockoutPollTimer = new System.Timers.Timer(
_props?.Lockout?.PollIntervalMs > 0 ? _props.Lockout.PollIntervalMs : 5000
);
_lockoutPollTimer.AutoReset = true;
_lockoutPollTimer.Enabled = true;
_lockoutPollTimer.Elapsed += (s, a) =>
{
if (!_mcTpController.LockedOut)
{
//if not in lockout state and was previously locked out
ClearCiscoCodecUiWebViewController();
_extensionsHandler.UiWebViewChanagedEvent -= LockoutUiWebViewChanagedEventHandler;
_lockoutPollTimer.Enabled = false;
_lockoutPollTimer.Dispose();
return;
}
_mcTpController.UisCiscoCodec.EnqueueCommand(UiWebViewDisplay.xCommandStatus());
};
return;
}
return;
}

_extensionsHandler.UiWebViewChanagedEvent -= LockoutUiWebViewChanagedEventHandler;
_mcTpController.LockedOut = false;
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
);
}
}

public void LockoutUiWebViewChanagedEventHandler(object sender, UiWebViewChanagedEventArgs args)
{
bool isError = args?.UiWebViewStatus?.IsError ?? false;
Expand All @@ -269,7 +287,7 @@ public void LockoutUiWebViewChanagedEventHandler(object sender, UiWebViewChanage
{
UiWebView uiWebView = args?.UiWebViewStatus?.UiWebView;
_extensionsHandler.UiWebViewClearAction?.Invoke(
new UiWEbViewDisplayClearActionArgs() { Target = "Controller" }
new UiWebViewDisplayClearActionArgs() { Target = "Controller" }
);
}
}
Expand Down Expand Up @@ -299,10 +317,9 @@ private void SendLockout(string thisUisDefaultRoomKey, string primaryRoomKey)
{
webViewConfig.QueryParams = new Dictionary<string, string>();
}
webViewConfig.QueryParams.Add(
"primaryRoomName",
room != null ? room.Name : primaryRoomKey
);

webViewConfig.QueryParams["primaryRoomName"] =
room != null ? room.Name : primaryRoomKey;
}
SendCiscoCodecUiToWebViewMcUrl(path, webViewConfig);
}
Expand Down Expand Up @@ -461,15 +478,15 @@ public void ClearCiscoCodecUiWebViewController()
{
Debug.LogMessage(LogEventLevel.Debug, "ClearCiscoCodecUiWebViewController", this);
_extensionsHandler?.UiWebViewClearAction?.Invoke(
new UiWEbViewDisplayClearActionArgs() { Target = "Controller" }
new UiWebViewDisplayClearActionArgs() { Target = "Controller" }
);
}

public void ClearCiscoCodecUiWebViewOsd()
{
Debug.LogMessage(LogEventLevel.Debug, "ClearCiscoCodecUiWebViewOsd", this);
_extensionsHandler?.UiWebViewClearAction?.Invoke(
new UiWEbViewDisplayClearActionArgs() { Target = "OSD" }
new UiWebViewDisplayClearActionArgs() { Target = "OSD" }
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface ICiscoCodecUiExtensionsHandler :
ICiscoCodecUiExtensionsWebViewDisplayHandler,
ICiscoCodecUiExtensionsClickedEvent,
ICiscoCodecUiExtensionsPanelClickedEventHandler
{
{
}

public interface ICiscoCodecUiExtensionsController
Expand All @@ -32,4 +32,5 @@ public interface ICiscoCodecUiExtensions

string xCommand();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class UserInterfaceExtensionsHandler : ICiscoCodecUiExtensionsHandler

public Action<UiWebViewDisplayActionArgs> UiWebViewDisplayAction { get; set; }

public Action<UiWEbViewDisplayClearActionArgs> UiWebViewClearAction { get; set; }
public Action<UiWebViewDisplayClearActionArgs> UiWebViewClearAction { get; set; }

public event EventHandler<UiExtensionsClickedEventArgs> UiExtensionsClickedEvent;
public event EventHandler<UiWebViewChanagedEventArgs> UiWebViewChanagedEvent;
Expand All @@ -43,7 +43,7 @@ public UserInterfaceExtensionsHandler(IKeyed parent, Action<string> enqueueComma
//coms.SendText(uwvd.xCommand());
EnqueueCommand(uwvd.xCommand());
});
UiWebViewClearAction = new Action<UiWEbViewDisplayClearActionArgs>((args) =>
UiWebViewClearAction = new Action<UiWebViewDisplayClearActionArgs>((args) =>
{
var target = args.Target;
if (args.Target == null || args.Target == "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace epi_videoCodec_ciscoExtended.UserInterface.UserInterfaceWebViewDisplay
public interface ICiscoCodecUiExtensionsWebViewDisplayActions
{
Action<UiWebViewDisplayActionArgs> UiWebViewDisplayAction { get; set; }
Action<UiWEbViewDisplayClearActionArgs> UiWebViewClearAction { get; set; }
Action<UiWebViewDisplayClearActionArgs> UiWebViewClearAction { get; set; }
}

public class UiWebViewDisplayActionArgs
Expand Down Expand Up @@ -39,7 +39,7 @@ public class UiWebViewDisplayActionArgs
public string Target { get; set; }
}

public class UiWEbViewDisplayClearActionArgs
public class UiWebViewDisplayClearActionArgs
{
/// <summary>
/// OSD, Controller, PersistentWebApp Controller: Only for Cisco internal use.
Expand Down
4 changes: 2 additions & 2 deletions src/xEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ public class UserInterface // /Event/UserInterface/

public UserInterface()
{
Presentation = new Presentation();
Extensions = new UiExtensions();
//Presentation = new Presentation();
//Extensions = new UiExtensions();
}
}
public class UiExtensions : ValueProperty // /Event/UserInterface/Extensions/
Expand Down

0 comments on commit 2161398

Please sign in to comment.