106 lines
2.9 KiB
C#
106 lines
2.9 KiB
C#
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Logging;
|
|
using xPushService.Interfaces;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using xPushService.Constants;
|
|
using xCommons.Extensions;
|
|
using System.Threading;
|
|
|
|
namespace xPushService.Base
|
|
{
|
|
public abstract class XBaseWebRTCHub : XBaseHub, IXBaseWebRTCHub
|
|
{
|
|
//
|
|
#region Props ...
|
|
#endregion
|
|
|
|
//
|
|
#region Constructor ...
|
|
protected XBaseWebRTCHub(
|
|
ILogger<XBaseHub> logger
|
|
) : base(logger)
|
|
{ }
|
|
#endregion
|
|
|
|
//
|
|
#region WebRTCActions ...
|
|
/// <summary>
|
|
/// Sending WebRTC Offer To Specified Connection ...
|
|
/// </summary>
|
|
/// <param name="offer"></param>
|
|
/// <param name="to"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task Offer(
|
|
string offer,
|
|
string to,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
await Clients.Client(to).SendAsync(
|
|
XWebRTCAction.Offer.GetStringValue(),
|
|
offer,
|
|
cancellationToken
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sending WebRTC Answer to Specified Connection ...
|
|
/// </summary>
|
|
/// <param name="answer"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task Answer(
|
|
string answer,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
await Clients.All.SendAsync(
|
|
XWebRTCAction.Answer.GetStringValue(),
|
|
answer,
|
|
Context.ConnectionId,
|
|
cancellationToken
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sending WebRTC Candidate to Specified Connecton ...
|
|
/// </summary>
|
|
/// <param name="candidate"></param>
|
|
/// <param name="to"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task Candidate(
|
|
string candidate,
|
|
string to,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
string actionName = XWebRTCAction.Candidate.GetStringValue();
|
|
if (!string.IsNullOrEmpty(to))
|
|
{
|
|
//
|
|
await Clients.Client(to).SendAsync(
|
|
actionName,
|
|
candidate,
|
|
Context.ConnectionId,
|
|
cancellationToken
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
await Clients.All.SendAsync(
|
|
actionName,
|
|
candidate,
|
|
Context.ConnectionId,
|
|
cancellationToken
|
|
);
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |