feat(mobile-control): track and validate UI client app versions

Extend the /system/clientJoined handler to accept an optional
`appVersion` field reported by connecting UI clients (e.g. the
React app's build-time APP_VERSION), so Essentials can record and
validate what's actually running against the configured
versions.touchpanelWrapperApp version.

- Add ConnectedClientVersionInfo to capture clientId, roomKey,
  touchpanelKey, reported/expected app version, and last-seen time.
- Add MobileControlSystemController.TrackClientAppVersion(), storing
  results in a new thread-safe ConnectedClientVersions dictionary and
  logging a warning on version mismatch.
- Expose ConnectedClientVersions as a public read-only property for
  diagnostics.
- Surface reported vs. expected versions per client in the
  `mobileinfo` console command output.

No wire protocol changes required; content is passed as-is over the
existing clientJoined message.
This commit is contained in:
jkdevito 2026-07-07 17:41:04 -05:00
parent c323c872fc
commit 02216372bc
2 changed files with 136 additions and 0 deletions

View file

@ -69,11 +69,32 @@ namespace PepperDash.Essentials
private readonly Dictionary<string, IMobileControlMessenger> _defaultMessengers =
new Dictionary<string, IMobileControlMessenger>();
private readonly Dictionary<string, ConnectedClientVersionInfo> _connectedClientVersions =
new Dictionary<string, ConnectedClientVersionInfo>(StringComparer.InvariantCultureIgnoreCase);
private readonly object _connectedClientVersionsLock = new object();
/// <summary>
/// Get the custom messengers with subscriptions
/// </summary>
public ReadOnlyDictionary<string, IMobileControlMessengerWithSubscriptions> Messengers => new ReadOnlyDictionary<string, IMobileControlMessengerWithSubscriptions>(_messengers.Values.OfType<IMobileControlMessengerWithSubscriptions>().ToDictionary(k => k.Key, v => v));
/// <summary>
/// Gets the most recently reported UI app version for each connected client, keyed by clientId
/// </summary>
public ReadOnlyDictionary<string, ConnectedClientVersionInfo> ConnectedClientVersions
{
get
{
lock (_connectedClientVersionsLock)
{
return new ReadOnlyDictionary<string, ConnectedClientVersionInfo>(
new Dictionary<string, ConnectedClientVersionInfo>(_connectedClientVersions)
);
}
}
}
/// <summary>
/// Get the default messengers
/// </summary>
@ -1782,6 +1803,28 @@ namespace PepperDash.Essentials
" Not Enabled in Config.\r\n"
);
}
var connectedClientVersions = ConnectedClientVersions;
if (connectedClientVersions.Count == 0)
{
CrestronConsole.ConsoleCommandResponse("\r\nUI Client App Versions: None reported yet\r\n");
}
else
{
CrestronConsole.ConsoleCommandResponse("\r\nUI Client App Versions:\r\n");
foreach (var kv in connectedClientVersions)
{
var v = kv.Value;
var match = string.IsNullOrEmpty(v.ExpectedAppVersion) || string.Equals(v.ExpectedAppVersion, v.AppVersion, StringComparison.OrdinalIgnoreCase);
CrestronConsole.ConsoleCommandResponse(
$" Client: {v.ClientId} Touchpanel: {v.TouchpanelKey} Room: {v.RoomKey}\r\n" +
$" Reported: {v.AppVersion} Expected: {v.ExpectedAppVersion ?? "(not configured)"} Match: {(match ? "Yes" : "NO - MISMATCH")}\r\n" +
$" Last Seen (UTC): {v.LastSeen:yyyy-MM-dd HH:mm:ss}\r\n"
);
}
}
}
/// <summary>
@ -2181,6 +2224,8 @@ namespace PepperDash.Essentials
var roomKey = content["roomKey"].Value<string>();
var touchpanelKey = content.SelectToken("touchpanelKey");
TrackClientAppVersion(clientId, roomKey, touchpanelKey?.Value<string>(), content.SelectToken("appVersion")?.Value<string>());
if (_roomCombiner == null)
{
var message = new MobileControlMessage
@ -2252,6 +2297,50 @@ namespace PepperDash.Essentials
SendTouchpanelKey(clientId, touchpanelKey);
}
/// <summary>
/// Records the app version reported by a connecting UI client (e.g. the mobile control React app's
/// build-time APP_VERSION) and compares it against the configured versions.touchpanelWrapperApp version.
/// </summary>
private void TrackClientAppVersion(string clientId, string roomKey, string touchpanelKey, string appVersion)
{
if (string.IsNullOrEmpty(appVersion))
{
return;
}
var expectedVersion = ConfigReader.ConfigObject?.Versions?.TouchpanelWrapperApp?.Version;
var info = new ConnectedClientVersionInfo
{
ClientId = clientId,
RoomKey = roomKey,
TouchpanelKey = touchpanelKey,
AppVersion = appVersion,
ExpectedAppVersion = expectedVersion,
LastSeen = DateTime.UtcNow
};
lock (_connectedClientVersionsLock)
{
_connectedClientVersions[clientId] = info;
}
if (!string.IsNullOrEmpty(expectedVersion) && !string.Equals(expectedVersion, appVersion, StringComparison.OrdinalIgnoreCase))
{
this.LogWarning(
"Client {clientId} (touchpanel {touchpanelKey}) reported UI app version {appVersion}, which does not match configured versions.touchpanelWrapperApp version {expectedVersion}",
clientId, touchpanelKey, appVersion, expectedVersion
);
}
else
{
this.LogVerbose(
"Client {clientId} (touchpanel {touchpanelKey}) reported UI app version {appVersion}",
clientId, touchpanelKey, appVersion
);
}
}
private void SendTouchpanelKey(string clientId, JToken touchpanelKeyToken)
{
if (touchpanelKeyToken == null)