Mango.Nop.Plugins/Nop.Plugin.Misc.AuctionPlugin/Hubs/AuctionHub.cs

57 lines
1.8 KiB
C#

using System;
using Microsoft.AspNetCore.SignalR;
using System.Threading.Tasks;
using Nop.Services.Logging;
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{
public class AuctionHub : Hub<IAuctionHubClient>
{
ILogger _logger;
//HubCallerContext _hubCallerContext;
public AuctionHub(ILogger logger)
{
_logger = logger;
}
public override async Task OnConnectedAsync()
{
//await _logger.InformationAsync($"Caller connected: id{_hubCallerContext.ConnectionId}");
var userId = Context.ConnectionId;
await _logger.InformationAsync($"Caller connected with id: {userId}");
var userName = Context.GetHttpContext().Request.Query["ConnectionId"];
if (!string.IsNullOrEmpty(userName))
{
await _logger.InformationAsync($"Caller connected with name: {userName}");
}
await base.OnConnectedAsync();
}
public async Task ReceiveMessageFromClient(string message)
{
await _logger.InformationAsync(message);
// Broadcast the message received from the client to all clients
Console.Write($"Received message: {message}");
await Clients.All.SendAsync("Send", message);
//await _signalRservice.TestHub();
}
//public async Task Send(string announcement)
//{
// await _logger.InformationAsync($" Hub Send method called with messgae: {announcement}");
// await Clients.All.SendAsync("send", announcement);
//}
public async Task SendPriceToUsers(string message)
{
await Clients.All.SendAsync("SendPrice", message);
}
}
}