2020-11-09 18:12:07 +01:00
|
|
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Birdmap.API.Services.Hubs
|
|
|
|
|
{
|
|
|
|
|
public class DevicesHub : Hub<IDevicesHubClient>
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<DevicesHub> _logger;
|
|
|
|
|
|
|
|
|
|
public DevicesHub(ILogger<DevicesHub> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Task OnConnectedAsync()
|
|
|
|
|
{
|
2020-11-11 20:35:26 +01:00
|
|
|
|
_logger.LogInformation("Hub Client connected.");
|
2020-11-09 18:12:07 +01:00
|
|
|
|
|
|
|
|
|
return base.OnConnectedAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Task OnDisconnectedAsync(Exception exception)
|
|
|
|
|
{
|
2020-11-11 20:35:26 +01:00
|
|
|
|
_logger.LogInformation("Hub Client disconnected.");
|
2020-11-09 18:12:07 +01:00
|
|
|
|
|
|
|
|
|
return base.OnDisconnectedAsync(exception);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-11 20:35:26 +01:00
|
|
|
|
public Task SendProbabilityAsync(Guid deviceId, DateTime date, double probability)
|
2020-11-09 18:12:07 +01:00
|
|
|
|
{
|
|
|
|
|
return Clients.All.NotifyDeviceAsync(deviceId, date, probability);
|
|
|
|
|
}
|
2020-11-11 20:35:26 +01:00
|
|
|
|
|
|
|
|
|
public Task SendDeviceUpdateAsync(Guid deviceId)
|
|
|
|
|
{
|
|
|
|
|
return Clients.All.NotifyDeviceUpdatedAsync(deviceId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task SendAllUpdatedAsync()
|
|
|
|
|
{
|
|
|
|
|
return Clients.All.NotifyAllUpdatedAsync();
|
|
|
|
|
}
|
2020-11-09 18:12:07 +01:00
|
|
|
|
}
|
|
|
|
|
}
|