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

61 lines
2.0 KiB
C#

using System;
using Microsoft.AspNetCore.SignalR;
using System.Threading.Tasks;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities.Interfaces;
using Nop.Plugin.Misc.AuctionPlugin.Services;
using Nop.Services.Logging;
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{
public class AuctionHub : Hub<IAuctionHubClient>
{
private readonly ILogger _logger;
private IAuctionService _auctionService;
//HubCallerContext _hubCallerContext;
public AuctionHub(IAuctionService auctionService, ILogger logger)
{
_logger = logger;
_auctionService = auctionService;
}
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.SendPrice(message); //SendAsync(nameof(IAuctionHubClient.SendPrice), message);
}
}
}