save
This commit is contained in:
29
RobotApp/Hubs/RobotHub.cs
Normal file
29
RobotApp/Hubs/RobotHub.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
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);
|
||||
Console.WriteLine($"Client {Context.ConnectionId} joined robot group: {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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user