LANCommander/LANCommander.Server/Services/BeaconService.cs
2024-08-04 18:44:33 -05:00

35 lines
879 B
C#

using BeaconLib;
using LANCommander.Server.Models;
namespace LANCommander.Server.Services
{
public class BeaconService : IHostedService, IDisposable
{
private Beacon Beacon;
private LANCommanderSettings Settings;
public BeaconService() {
Settings = SettingService.GetSettings();
Beacon = new Beacon("LANCommander", Convert.ToUInt16(Settings.Port));
}
public void Dispose()
{
Beacon?.Dispose();
}
public Task StartAsync(CancellationToken cancellationToken)
{
Beacon.BeaconData = Settings.Beacon?.Address;
Beacon.Start();
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
Beacon.Stop();
return Task.CompletedTask;
}
}
}