hubConnection.on('notify', function (message) {
console.log(message)
});
public class HomeController : Controller
{
private ApplicationDbContext _db;
private IHubContext<MoexHub> _hub;
public HomeController(ApplicationDbContext db, IHubContext<MoexHub> hub)
{
_db = db;
_hub = hub;
}
public IActionResult Index()
{
return View();
}
public async Task<IActionResult> MyData()
{
await _hub.Clients.All.SendAsync("notify", "this is my message");
return View();
}
}
MyScheduler.IntervalInMinutes(7, 0, 1,
async () =>
{
await _moexHub.Clients.All.SendAsync("notify", "message bla bla");
});
public class MyHub : Hub
{
public async Task SendData(MyData data)
{
await Clients.All.SendAsync("GetData", data);
}
}
private IHubContext<MoexHub> _myHub { get; set; }
public HomeController(IHubContext<MyHub > myHub)
{
_myHub= myHub;
}
public IActionResult Index()
{
await _myHub.Clients.All.SendAsync("GetData", data);
return View();
}
const hubConnection = new signalR.HubConnectionBuilder()
.withUrl("/myHub")
.build();
hubConnection.start();
//получаем данные
hubConnection.on("GetData", (data) => {
var tr = document.createElement("tr");
tr.innerHTML = `<th>${data.dateTime}</th>
<th >${data.data1}</th>
<th >${data.data2}</th>`;
document.getElementById("dataContainer").appendChild(tr);
console.log(data);
});
то браузере мобилки и так все будет прикручено?