using Microsoft.AspNetCore.SignalR; using System; using System.Diagnostics; using System.Threading.Tasks; namespace Infrastructure.Web.SignalR { public class BasePageHub : Hub { public override Task OnConnectedAsync() { this.OnConnected(); return base.OnConnectedAsync(); } protected void OnConnected() { Debug.WriteLine($"{Context.ConnectionId} has connected: {Context.GetHttpContext().Request.QueryString}"); this.Groups.AddToGroupAsync(Context.ConnectionId, Context.ConnectionId); var group = Context.GetHttpContext().Request.Query["group"].ToString(); if (!string.IsNullOrEmpty(group)) { this.Groups.AddToGroupAsync(Context.ConnectionId, group); Context.Items["group"] = group; } var type = Context.GetHttpContext().Request.Query["type"].ToString(); if (!string.IsNullOrEmpty(type)) { Context.Items["type"] = type; } this.Clients.Group(Context.ConnectionId).SendAsync("Connected", Context.ConnectionId); } public override Task OnDisconnectedAsync(Exception exception) { this.OnDisconnected(exception); return base.OnDisconnectedAsync(exception); } protected void OnDisconnected(Exception exception) { Debug.WriteLine($"{Context.ConnectionId} has disconnected: {exception}"); } } }