You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.5 KiB
45 lines
1.5 KiB
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}");
|
|
}
|
|
}
|
|
} |