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.
37 lines
1.4 KiB
37 lines
1.4 KiB
using Infrastructure.Extensions;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Infrastructure.Web.SignalR
|
|
{
|
|
public class BasePageHub : Hub
|
|
{
|
|
public override Task OnConnectedAsync()
|
|
{
|
|
Console.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"))
|
|
{
|
|
this.Groups.AddToGroupAsync(Context.ConnectionId, Context.GetHttpContext().Request.Query["group"]);
|
|
}
|
|
this.Clients.Group(Context.ConnectionId).SendAsync("Connected", Context.ConnectionId);
|
|
return base.OnConnectedAsync();
|
|
}
|
|
|
|
public override Task OnDisconnectedAsync(Exception exception)
|
|
{
|
|
Console.WriteLine($"{Context.ConnectionId} has disconnected which request url is {Context.GetHttpContext().Request.GetUrl()}");
|
|
return base.OnDisconnectedAsync(exception);
|
|
}
|
|
|
|
public virtual void ServerToClient(string group, string method, string message, string fromConnectinId = null)
|
|
{
|
|
Clients.Group(group).SendAsync(method, message, fromConnectinId);
|
|
}
|
|
|
|
public virtual void OnClientToServer(string method, string message, string connectionId)
|
|
{
|
|
}
|
|
}
|
|
} |