Initial Commit ...
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using xCommons.Extensions;
|
||||
using xPushService.Models;
|
||||
|
||||
namespace xPushService.Extensions {
|
||||
public static class XWebRTCConnectionExtensions {
|
||||
/// <summary>
|
||||
/// Validate Connection ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsValid (this XWebRTCConnectionDto source) {
|
||||
//
|
||||
var result = false;
|
||||
result = !source
|
||||
.IsNull () && !source.CallerConnectionId
|
||||
.IsNullOrEmpty () && (
|
||||
source.Callees
|
||||
.HasChild () ? source.Callees
|
||||
.All (callee => !callee.ConnectionId.IsNullOrDefault ()) :
|
||||
true
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check a ConnectionId is Caller of a connection ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsCaller (
|
||||
this XWebRTCConnectionDto source,
|
||||
string connectionId
|
||||
) {
|
||||
//
|
||||
var result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!source.IsValid () ||
|
||||
connectionId.IsNullOrEmpty ()
|
||||
) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = connectionId
|
||||
.ToNormalString () == source.CallerConnectionId
|
||||
.ToNormalString ();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check a ConnectionId is in Callees of a connection ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsInCallees (
|
||||
this XWebRTCConnectionDto source,
|
||||
string connectionId
|
||||
) {
|
||||
//
|
||||
var result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!source.IsValid () ||
|
||||
!source.Callees.HasChild () ||
|
||||
connectionId.IsNullOrEmpty ()
|
||||
) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = source.Callees.Any (callee => callee.ConnectionId
|
||||
.ToNormalString () == connectionId
|
||||
.ToNormalString ());
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Receivers ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static IReadOnlyList<string> GetReceivers (this XWebRTCConnectionDto source) {
|
||||
//
|
||||
var result = new List<string> ();
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!source.IsValid ()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Add Caller ...
|
||||
result.Add (source.CallerConnectionId);
|
||||
|
||||
//
|
||||
// Add Callees ...
|
||||
source.Callees
|
||||
.ToList ()
|
||||
.ForEach (callee => {
|
||||
result.Add (callee.ConnectionId);
|
||||
});
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Callee from Callees ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public static XWebRTCCalleeDto GetCallee (
|
||||
this XWebRTCConnectionDto source,
|
||||
string connectionId
|
||||
) {
|
||||
//
|
||||
// Validate Args ...
|
||||
if (!source.IsValid () ||
|
||||
connectionId.IsNullOrEmpty ()
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Connection Id is In Callees or not ...
|
||||
var isInCallees = source.IsInCallees (connectionId);
|
||||
if (!isInCallees) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//
|
||||
// retrieve result ...
|
||||
var result = source.Callees
|
||||
.FirstOrDefault (callee => callee.ConnectionId
|
||||
.ToNormalString () == connectionId
|
||||
.ToNormalString ()
|
||||
);
|
||||
|
||||
//
|
||||
// return result ...
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user