Codecleamup
This commit is contained in:
parent
b21b2c3678
commit
507e08ab19
@ -17,10 +17,10 @@ namespace Squirrowse.Client
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
services.AddHostedService<Worker>();
|
||||
services.AddSingleton<IConnectionManager>(x=> new ConnectionManager("http://localhost", 5000)); //keep as transient for now
|
||||
services.AddSingleton< ICameraService, CameraService >(x=>new CameraService(new Camera()));
|
||||
services.AddSingleton<IConnectionManager>(x =>
|
||||
new ConnectionManager("http://localhost", 5000)); //keep as transient for now
|
||||
services.AddSingleton<ICameraService, CameraService>(x => new CameraService(new Camera()));
|
||||
services.AddSingleton<IActionDispatcher, ActionDispatcher>();
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@ -16,13 +17,13 @@ namespace Squirrowse.Client.Service
|
||||
{
|
||||
this.connectionManager = connectionManager;
|
||||
this.logger = logger;
|
||||
session.On("Start",StartStream);
|
||||
session.On("Stop",StopStream);
|
||||
session.On("Start", StartStream);
|
||||
session.On("Stop", StopStream);
|
||||
}
|
||||
|
||||
public Task StopStream()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task SayHello()
|
||||
@ -40,7 +41,7 @@ namespace Squirrowse.Client.Service
|
||||
|
||||
public Task StartStream()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using OpenCvSharp;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace Squirrowse.Client.Service
|
||||
{
|
||||
public abstract class CameraFactory
|
||||
{
|
||||
public abstract VideoCapture GetCamera();
|
||||
}
|
||||
{
|
||||
public abstract VideoCapture GetCamera();
|
||||
}
|
||||
}
|
@ -17,25 +17,18 @@ namespace Squirrowse.Client.Service
|
||||
.AddMessagePackProtocol()
|
||||
.WithAutomaticReconnect()
|
||||
.Build();
|
||||
|
||||
}
|
||||
|
||||
public async Task<HubConnection> GetConnection()
|
||||
{
|
||||
if (Connected)
|
||||
{
|
||||
return _connection;
|
||||
}
|
||||
if (Connected) return _connection;
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
public async Task InitConnection()
|
||||
public async Task InitConnection()
|
||||
{
|
||||
if (_connection.State == HubConnectionState.Connected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_connection.State == HubConnectionState.Connected) return;
|
||||
await _connection.StartAsync();
|
||||
await RegisterOnHub();
|
||||
Connected = true;
|
||||
@ -50,7 +43,7 @@ namespace Squirrowse.Client.Service
|
||||
|
||||
private async Task RegisterOnHub()
|
||||
{
|
||||
await _connection.SendAsync("AddUser", Environment.UserName);
|
||||
await _connection.SendAsync("AddUser", Environment.UserName);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Squirrowse.Client.Service
|
||||
namespace Squirrowse.Client.Service
|
||||
{
|
||||
public interface ICameraFactory
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using OpenCvSharp;
|
||||
|
||||
|
@ -1,24 +1,21 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OpenCvSharp;
|
||||
using Squirrowse.Client.Service;
|
||||
|
||||
namespace Squirrowse.Client
|
||||
{
|
||||
public class Worker : IHostedService
|
||||
{
|
||||
private readonly ILogger<Worker> logger;
|
||||
private readonly IConnectionManager _connectionManager;
|
||||
private readonly ICameraService camera;
|
||||
private readonly ILogger<Worker> logger;
|
||||
|
||||
public Worker(ILogger<Worker> logger, IConnectionManager connectionManager, ICameraService camera)
|
||||
{
|
||||
this.logger = logger;
|
||||
this._connectionManager = connectionManager;
|
||||
_connectionManager = connectionManager;
|
||||
this.camera = camera;
|
||||
}
|
||||
|
||||
|
@ -2,13 +2,13 @@
|
||||
{
|
||||
public class User
|
||||
{
|
||||
public string ConnectionId { get; set; }
|
||||
public string AgentName { get; set; }
|
||||
|
||||
public User(string connectionId, string agentName)
|
||||
{
|
||||
ConnectionId = connectionId;
|
||||
AgentName = agentName;
|
||||
}
|
||||
|
||||
public string ConnectionId { get; set; }
|
||||
public string AgentName { get; set; }
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ namespace Squirrowse.Core.Services
|
||||
|
||||
public static Mat ConvertByteToMat(this byte[] bytearr)
|
||||
{
|
||||
var tempMat = Cv2.ImDecode(bytearr, ImreadModes.Unchanged); //keep as disposable
|
||||
var tempMat = Cv2.ImDecode(bytearr, ImreadModes.Unchanged); //keep as disposable
|
||||
return tempMat ?? new Mat();
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Squirrowse.Service.Hubs
|
||||
{
|
||||
public interface IStreamManager
|
||||
{
|
||||
Task AddUser(string connectionId, string agentName);
|
||||
Task RemoveUserbyConnectionId(string connectionId);
|
||||
Task RemoveUserByUserName(string agentName);
|
||||
bool CheckUser(string agentName);
|
||||
|
||||
Task AddUser(string connectionId, string agentName);
|
||||
Task RemoveUserbyConnectionId(string connectionId);
|
||||
Task RemoveUserByUserName(string agentName);
|
||||
bool CheckUser(string agentName);
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@ -13,6 +12,8 @@ namespace Squirrowse.Service.Hubs
|
||||
{
|
||||
private readonly ILogger<StreamHub> logger;
|
||||
private readonly IStreamManager manager;
|
||||
public Window okno = new Window("test");
|
||||
|
||||
public StreamHub(ILogger<StreamHub> logger, IStreamManager manager)
|
||||
{
|
||||
this.logger = logger;
|
||||
@ -21,7 +22,7 @@ namespace Squirrowse.Service.Hubs
|
||||
|
||||
public async Task AddUser(string UserName)
|
||||
{
|
||||
await manager.AddUser(Context.ConnectionId, UserName);
|
||||
await manager.AddUser(Context.ConnectionId, UserName);
|
||||
}
|
||||
|
||||
public async Task AddToGroup(Groups group, string user = "")
|
||||
@ -62,16 +63,15 @@ namespace Squirrowse.Service.Hubs
|
||||
|
||||
await client.SendAsync("Stop");
|
||||
}
|
||||
public Window okno = new Window("test");
|
||||
|
||||
public async Task UploadByteStream(IAsyncEnumerable<byte[]> stream)
|
||||
{
|
||||
|
||||
await foreach (var frame in stream)
|
||||
{
|
||||
using var imgbuffer = frame.ConvertByteToMat();
|
||||
okno.ShowImage(imgbuffer);
|
||||
Cv2.WaitKey(1);
|
||||
// logger.LogInformation($"Got frame size: {frame.Length} ");
|
||||
// logger.LogInformation($"Got frame size: {frame.Length} ");
|
||||
// await Task.Delay(100); //leave some delay for debug purpose
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ namespace Squirrowse.Service
|
||||
services.AddControllers();
|
||||
services.AddMediatR(Assembly.GetAssembly(typeof(Startup)));
|
||||
services.AddTransient<IStreamHub, StreamHub>();
|
||||
services.AddTransient<IStreamManager, StreamManager>();
|
||||
services.AddCoreModule();
|
||||
services.AddSignalR()
|
||||
.AddHubOptions<StreamHub
|
||||
|
Loading…
Reference in New Issue
Block a user