28 lines
904 B
C#
28 lines
904 B
C#
using Microsoft.AspNetCore.SignalR;
|
|
using RobotApp.Common.Shares;
|
|
using RobotApp.VDA5050.State;
|
|
using System.Text.Json;
|
|
|
|
namespace RobotApp.Hubs
|
|
{
|
|
public class RobotHub : Hub
|
|
{
|
|
// Client gọi để theo dõi robot cụ thể
|
|
public async Task JoinRobot(string serialNumber)
|
|
{
|
|
await Groups.AddToGroupAsync(Context.ConnectionId, serialNumber);
|
|
}
|
|
|
|
public async Task LeaveRobot(string serialNumber)
|
|
{
|
|
await Groups.RemoveFromGroupAsync(Context.ConnectionId, serialNumber);
|
|
}
|
|
|
|
// Phương thức này sẽ được gọi từ service để broadcast
|
|
public async Task SendState(string serialNumber, StateMsg state)
|
|
{
|
|
var json = JsonSerializer.Serialize(state, JsonOptionExtends.Write);
|
|
await Clients.Group(serialNumber).SendAsync("ReceiveState", json);
|
|
}
|
|
}
|
|
} |