stream hub manager

prepare Interface for future hub development
This commit is contained in:
ziomus5555 2019-11-02 20:36:31 +01:00
parent 3de7aaab87
commit 6fed61be4a
6 changed files with 103 additions and 3 deletions

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Squirrowse.Core.Models
{
public enum Groups
{
debug=-1,
normal,
superUser
}
}

View File

@ -1,10 +1,19 @@
using System.Collections.Generic;
using Squirrowse.Core.Models;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Squirrowse.Service.Hubs
{
public interface IStreamHub
{
Task AddClient();
Task UploadByteStream(IAsyncEnumerable<byte[]> stream);
Task Startstream(string userId);
Task StopStream(string userId);
Task ExecCommandOnAll(string command,object[] act);//gni
Task AddToGroup(Groups group,string user="");
Task RemoveFromGroup(Groups group,string user="");
}
}

View File

@ -6,17 +6,63 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using NLog;
using Squirrowse.Core.Models;
namespace Squirrowse.Service.Hubs
{
public class StreamHub : Hub, IStreamHub
public class StreamHub : Hub, IStreamHub //fujka
{
private readonly ILogger<StreamHub> logger;
public StreamHub(ILogger<StreamHub> logger)
{
this.logger = logger;
}
public async Task AddClient()
{
throw new NotImplementedException();
}
public async Task AddToGroup(Groups group, string user = "")
{
string connectionId = string.IsNullOrWhiteSpace(user) ? Context.ConnectionId : user;
await Groups.AddToGroupAsync(connectionId, group.ToString());
logger.LogInformation($"{nameof(AddToGroup)}: {connectionId} joined to {group}");
}
/// <summary>
/// USE ONLY FOR DEBUG
/// </summary>
/// <param name="act"></param>
/// <returns>DESTRUCTION</returns>
public async Task ExecCommandOnAll(string command,object[] act)
{
await Clients.All.SendCoreAsync(command,act);
}
public async Task RemoveFromGroup(Groups group, string user = "")
{
string connectionId = string.IsNullOrWhiteSpace(user) ? Context.ConnectionId : user;
await Groups.RemoveFromGroupAsync(connectionId, group.ToString());
logger.LogInformation($"{nameof(AddToGroup)}: {connectionId} joined to {group}");
}
public async Task Startstream(string clientId)
{
var client = Clients.Client(clientId);
await client.SendAsync("Start");
}
public async Task StopStream(string clientId)
{
var client = Clients.Client(clientId);
await client.SendAsync("Stop");
}
public async Task UploadByteStream(IAsyncEnumerable<byte[]> stream)
{
await foreach (var frame in stream)
@ -25,5 +71,6 @@ namespace Squirrowse.Service.Hubs
await Task.Delay(100); //leave some delay for debug purpose
}
}
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Squirrowse.Service
{
public interface IUserProvider
{
string GetUserId();
}
}

View File

@ -18,4 +18,8 @@
<PackageReference Include="OpenCvSharp4.Windows" Version="4.1.1.20191021" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Squirrowse.Core\Squirrowse.Core.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Squirrowse.Service
{
public class UserProvider : IUserProvider
{
public string GetUserId()
{
throw new NotImplementedException();
}
}
}