69 lines
1.9 KiB
C#
69 lines
1.9 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using Microsoft.Extensions.Logging;
|
|
using xCommons.Extensions;
|
|
using xPushService.Constants;
|
|
using xPushService.Interfaces;
|
|
|
|
namespace xPushService.Base
|
|
{
|
|
public abstract class XBaseHub : Hub, IXBaseHub
|
|
{
|
|
//
|
|
#region Props ...
|
|
protected readonly ILogger<XBaseHub> logger;
|
|
#endregion
|
|
|
|
//
|
|
#region Constructor ...
|
|
public XBaseHub(
|
|
ILogger<XBaseHub> logger
|
|
)
|
|
{
|
|
this.logger = logger;
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Overrides ...
|
|
public override async Task OnConnectedAsync()
|
|
{
|
|
//
|
|
var connectionId = Context.ConnectionId;
|
|
if (!connectionId.IsNullOrEmpty())
|
|
{
|
|
//
|
|
// Notify Other Clients Which a new Connection Joins ...
|
|
await Clients.AllExcept(connectionId).SendAsync(XBaseHubAction.NewConnection.GetStringValue(), connectionId);
|
|
}
|
|
|
|
//
|
|
await base.OnConnectedAsync();
|
|
}
|
|
|
|
public override async Task OnDisconnectedAsync(Exception exception)
|
|
{
|
|
//
|
|
var connectionId = Context.ConnectionId;
|
|
if (!connectionId.IsNullOrEmpty())
|
|
{
|
|
//
|
|
// Notify Other Clients Which a Connection Closed ...
|
|
await Clients.AllExcept(connectionId).SendAsync(XBaseHubAction.ConnectionClosed.GetStringValue(), connectionId);
|
|
}
|
|
await base.OnDisconnectedAsync(exception);
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Actions ...
|
|
public async Task SendCustomAction(string actionName, string payLoad)
|
|
{
|
|
//
|
|
var connectionId = Context.ConnectionId;
|
|
await Clients.AllExcept(connectionId).SendAsync(actionName, payLoad, connectionId);
|
|
}
|
|
#endregion
|
|
}
|
|
} |