67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
using System;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
using System.Threading.Tasks;
|
|
using Nop.Services.Logging;
|
|
using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages;
|
|
using Nop.Plugin.Misc.AuctionPlugin.Models;
|
|
using Newtonsoft.Json.Serialization;
|
|
using Newtonsoft.Json;
|
|
using Nop.Web.Models.Media;
|
|
using Nop.Services.Catalog;
|
|
using Nop.Plugin.Misc.AuctionPlugin.Services;
|
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
|
{
|
|
|
|
public class AuctionHub : Hub<IAuctionHubClient>
|
|
{
|
|
protected readonly SignalRMessageHandler _signalRMessageHandler;
|
|
|
|
ILogger _logger;
|
|
//HubCallerContext _hubCallerContext;
|
|
|
|
public AuctionHub(ILogger logger, SignalRMessageHandler signalRMessageHandler)
|
|
{
|
|
_logger = logger;
|
|
_signalRMessageHandler = signalRMessageHandler;
|
|
}
|
|
|
|
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 ReceiveRegularMessageFromClient(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 ReceiveMessageFromClient(MessageWrapper message)
|
|
{
|
|
// Log the message type and data
|
|
await _logger.InformationAsync($"Received message of type: {message.MessageType}");
|
|
await _signalRMessageHandler.HandleMessage(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|