Merge branch 'Stream' of s421801/Squirrowse into master
This commit is contained in:
commit
0f05560c45
28
Squirrowse.Client/Service/CameraService.cs
Normal file
28
Squirrowse.Client/Service/CameraService.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using OpenCvSharp;
|
||||||
|
|
||||||
|
namespace Squirrowse.Client.Service
|
||||||
|
{
|
||||||
|
public class CameraService : ICameraService
|
||||||
|
{
|
||||||
|
public VideoCapture GetCamera(int height=480,int widght=640,double fps=15f,bool disposable = false)
|
||||||
|
{
|
||||||
|
|
||||||
|
var cam = new VideoCapture(CaptureDevice.Any);
|
||||||
|
cam.Fps = fps;
|
||||||
|
cam.FrameHeight = height;
|
||||||
|
cam.FrameWidth = widght;
|
||||||
|
cam.IsEnabledDispose = disposable;
|
||||||
|
|
||||||
|
return cam;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Mat> GetFrame(VideoCapture video)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -14,8 +14,9 @@ namespace Squirrowse.Client.Service
|
|||||||
.AddMessagePackProtocol()
|
.AddMessagePackProtocol()
|
||||||
.WithAutomaticReconnect()
|
.WithAutomaticReconnect()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HubConnection EstablishHubConnection() => _connection;
|
public HubConnection Connect() => _connection;
|
||||||
}
|
}
|
||||||
}
|
}
|
14
Squirrowse.Client/Service/ICameraService.cs
Normal file
14
Squirrowse.Client/Service/ICameraService.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using OpenCvSharp;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Squirrowse.Client.Service
|
||||||
|
{
|
||||||
|
public interface ICameraService
|
||||||
|
{
|
||||||
|
public VideoCapture GetCamera(int height = 480, int widght = 640, double fps = 15f, bool disposable = false);
|
||||||
|
public Task<Mat> GetFrame(VideoCapture video);
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@ namespace Squirrowse.Client.Service
|
|||||||
{
|
{
|
||||||
public interface IConnectionManager
|
public interface IConnectionManager
|
||||||
{
|
{
|
||||||
HubConnection EstablishHubConnection();
|
HubConnection Connect();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
14
Squirrowse.Client/Service/IStreamService.cs
Normal file
14
Squirrowse.Client/Service/IStreamService.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Squirrowse.Client.Service
|
||||||
|
{
|
||||||
|
public interface IStreamService
|
||||||
|
{
|
||||||
|
Task SendStreamAsync(IAsyncEnumerable<byte[]> asb);
|
||||||
|
Task SayHello();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
50
Squirrowse.Client/Service/StreamService.cs
Normal file
50
Squirrowse.Client/Service/StreamService.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using Microsoft.AspNetCore.SignalR.Client;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Squirrowse.Core.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Squirrowse.Client.Service
|
||||||
|
{
|
||||||
|
public class StreamService : IStreamService
|
||||||
|
{
|
||||||
|
private readonly IConnectionManager connectionManager;
|
||||||
|
private readonly ILogger<StreamService> logger;
|
||||||
|
private readonly HubConnection session;
|
||||||
|
public StreamService(ILogger<StreamService> logger, IConnectionManager connectionManager)
|
||||||
|
{
|
||||||
|
this.connectionManager = connectionManager;
|
||||||
|
this.logger = logger;
|
||||||
|
session = connectionManager.Connect();
|
||||||
|
session.StartAsync().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SayHello()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await session.SendAsync("AddToGroup",Groups.debug);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SendStreamAsync(IAsyncEnumerable<byte[]> asb)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
logger.LogInformation($"{nameof(SendStreamAsync)} Start stream");
|
||||||
|
await session.SendAsync("UploadByteStream", asb, default);
|
||||||
|
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
logger.LogInformation($"{nameof(SendStreamAsync)} End stream");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,4 +11,8 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.0.0" />
|
||||||
<PackageReference Include="OpenCvSharp4.Windows" Version="4.1.1.20191021" />
|
<PackageReference Include="OpenCvSharp4.Windows" Version="4.1.1.20191021" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Squirrowse.Core\Squirrowse.Core.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -5,16 +5,19 @@ using System.Threading;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Squirrowse.Client.Service;
|
||||||
|
|
||||||
namespace Squirrowse.Client
|
namespace Squirrowse.Client
|
||||||
{
|
{
|
||||||
public class Worker : BackgroundService
|
public class Worker : BackgroundService
|
||||||
{
|
{
|
||||||
private readonly ILogger<Worker> _logger;
|
private readonly ILogger<Worker> _logger;
|
||||||
|
private readonly IStreamService _streamService;
|
||||||
|
|
||||||
public Worker(ILogger<Worker> logger)
|
public Worker(ILogger<Worker> logger, IStreamService streamService)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_streamService = streamService;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
@ -22,6 +25,7 @@ namespace Squirrowse.Client
|
|||||||
while (!stoppingToken.IsCancellationRequested)
|
while (!stoppingToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||||
|
|
||||||
await Task.Delay(1000, stoppingToken);
|
await Task.Delay(1000, stoppingToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
Squirrowse.Core/Models/Groups.cs
Normal file
13
Squirrowse.Core/Models/Groups.cs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,19 @@
|
|||||||
using System.Collections.Generic;
|
using Squirrowse.Core.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Squirrowse.Service.Hubs
|
namespace Squirrowse.Service.Hubs
|
||||||
{
|
{
|
||||||
public interface IStreamHub
|
public interface IStreamHub
|
||||||
{
|
{
|
||||||
|
Task AddClient();
|
||||||
Task UploadByteStream(IAsyncEnumerable<byte[]> stream);
|
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="");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,17 +6,63 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using Squirrowse.Core.Models;
|
||||||
|
|
||||||
namespace Squirrowse.Service.Hubs
|
namespace Squirrowse.Service.Hubs
|
||||||
{
|
{
|
||||||
public class StreamHub : Hub, IStreamHub
|
public class StreamHub : Hub, IStreamHub //fujka
|
||||||
{
|
{
|
||||||
private readonly ILogger<StreamHub> logger;
|
private readonly ILogger<StreamHub> logger;
|
||||||
|
|
||||||
public StreamHub(ILogger<StreamHub> logger)
|
public StreamHub(ILogger<StreamHub> logger)
|
||||||
{
|
{
|
||||||
this.logger = 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)
|
public async Task UploadByteStream(IAsyncEnumerable<byte[]> stream)
|
||||||
{
|
{
|
||||||
await foreach (var frame in 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
|
await Task.Delay(100); //leave some delay for debug purpose
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
Squirrowse.Service/IUserProvider.cs
Normal file
12
Squirrowse.Service/IUserProvider.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
@ -18,4 +18,8 @@
|
|||||||
<PackageReference Include="OpenCvSharp4.Windows" Version="4.1.1.20191021" />
|
<PackageReference Include="OpenCvSharp4.Windows" Version="4.1.1.20191021" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Squirrowse.Core\Squirrowse.Core.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
15
Squirrowse.Service/UserProvider.cs
Normal file
15
Squirrowse.Service/UserProvider.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user