|
|
|
@ -9,21 +9,38 @@ 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 which request url is {Context.GetHttpContext().Request.GetUrl()}");
|
|
|
|
|
this.Groups.AddToGroupAsync(Context.ConnectionId, Context.ConnectionId);
|
|
|
|
|
if (Context.GetHttpContext().Request.Query.Keys.Contains("group"))
|
|
|
|
|
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))
|
|
|
|
|
{
|
|
|
|
|
this.Groups.AddToGroupAsync(Context.ConnectionId, Context.GetHttpContext().Request.Query["group"]);
|
|
|
|
|
Context.Items["type"] = type;
|
|
|
|
|
}
|
|
|
|
|
this.Clients.Group(Context.ConnectionId).SendAsync("Connected", Context.ConnectionId);
|
|
|
|
|
return base.OnConnectedAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Task OnDisconnectedAsync(Exception exception)
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine($"{Context.ConnectionId} has disconnected which request url is {Context.GetHttpContext().Request.GetUrl()}");
|
|
|
|
|
this.OnDisconnected(exception);
|
|
|
|
|
return base.OnDisconnectedAsync(exception);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnDisconnected(Exception exception)
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine($"{Context.ConnectionId} has disconnected which request url is {Context.GetHttpContext().Request.GetUrl()}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|