- Implement UserCameraAccess entity and CRUD API (issues #131, #133) - Add CameraAccessPanel UI component for granular access management (issue #134) - Implement camera toggle UI (issues #59, #199) - Implement site filtering by user rights (issue #136) - Implement Groups camera access assignment (issue #138) - Implement audit logging for camera access changes (issue #140) - Add comprehensive camera access test coverage (issue #141) - Implement i18n/l10n localization infrastructure (issue #142) - Implement OpenTelemetry metrics infrastructure (issue #14) - Implement Agent GPU worker (issue #76) - Implement Agent remote sensor mode (issue #75) - Fix Docker GPU exposure in compose files (issues #76, #77) - Fix mDNS divergence by extracting shared MdnsClient library (issue #81) - Implement User email confirm/edit UI (issues #88, #89) - Implement Persons UI (issue #11) - Fix E2E test timing issues by increasing circuit delay - Add MdnsClient library with unified unicast/multicast mDNS support - Refactor MdnsProbeService and HomeKitMdnsProbe to use shared client - Add GroupCameraAccess entity for group-based camera access - Add comprehensive camera access test coverage - Add i18n localization infrastructure with fr/en support - Add Docker GPU exposure for NVIDIA/AMD/Intel - Update Docker compose files with GPU device exposure - Fix mDNS divergence between Central unicast and Agent multicast - Fix E2E test timing issues with increased circuit delay All 1700+ tests pass (unit + integration)
80 lines
2.8 KiB
C#
80 lines
2.8 KiB
C#
using Heimdall.Mdns;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Heimdall.Agent.Services;
|
|
|
|
/// <summary>
|
|
/// mDNS/HomeKit discovery probe (multicast) using the shared MdnsClient.
|
|
/// Discovers HomeKit cameras/doorbells on the local network.
|
|
/// </summary>
|
|
public sealed class HomeKitMdnsProbe
|
|
{
|
|
private readonly IMdnsClient _mdnsClient;
|
|
private readonly ILogger<HomeKitMdnsProbe> _logger;
|
|
|
|
public HomeKitMdnsProbe(IMdnsClient mdnsClient, ILogger<HomeKitMdnsProbe> logger)
|
|
{
|
|
_mdnsClient = mdnsClient;
|
|
_logger = logger;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructor for use with ILogger only (creates MdnsClient internally).
|
|
/// </summary>
|
|
public HomeKitMdnsProbe(ILogger<HomeKitMdnsProbe> logger)
|
|
{
|
|
_mdnsClient = new MdnsClient(Microsoft.Extensions.Logging.Abstractions.NullLogger<MdnsClient>.Instance);
|
|
_logger = logger;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Run a global multicast probe for HomeKit camera/doorbell accessories.
|
|
/// Returns devices deduplicated by IP. Never throws; failures are logged
|
|
/// and an empty list is returned (scan must never hang).
|
|
/// </summary>
|
|
public async Task<IReadOnlyList<HomeKitDevice>> DiscoverAsync(CancellationToken ct = default)
|
|
{
|
|
try
|
|
{
|
|
_logger.LogDebug("mDNS multicast discovery started");
|
|
|
|
var options = new MdnsDiscoverOptions
|
|
{
|
|
ServiceTypes = MdnsConstants.HomeKitServiceTypes,
|
|
ListenWindow = TimeSpan.FromSeconds(2),
|
|
ReplyDelay = TimeSpan.FromMilliseconds(250),
|
|
ProbeCount = 3
|
|
};
|
|
|
|
var devices = await _mdnsClient.DiscoverMulticastAsync(options, ct).ConfigureAwait(false);
|
|
|
|
// Convert to agent's HomeKitDevice format
|
|
var result = devices
|
|
.Where(d => d.HomeKitInfo?.Category is 17 or 18)
|
|
.Select(d => new HomeKitDevice(
|
|
d.Address.ToString(),
|
|
d.HomeKitInfo?.Name ?? d.InstanceName.Split('.')[0],
|
|
d.HomeKitInfo?.DeviceId ?? $"{d.Address}/{d.HomeKitInfo?.Model ?? "unknown"}",
|
|
d.HomeKitInfo?.Model ?? "HomeKit",
|
|
d.HomeKitInfo?.Category ?? 0,
|
|
d.HomeKitInfo?.IsPaired ?? false,
|
|
d.Port ?? MdnsConstants.Port
|
|
))
|
|
.ToList();
|
|
|
|
if (result.Count > 0)
|
|
_logger.LogInformation("Camera discovery: {Count} HomeKit accessory(ies) via mDNS multicast", result.Count);
|
|
|
|
return result;
|
|
}
|
|
catch (OperationCanceledException) when (ct.IsCancellationRequested)
|
|
{
|
|
return [];
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogWarning(ex, "mDNS multicast probe failed");
|
|
return [];
|
|
}
|
|
}
|
|
} |