stream service
This commit is contained in:
parent
3de1b04cb4
commit
3de7aaab87
21
Squirrowse.Client/Service/CameraService.cs
Normal file
21
Squirrowse.Client/Service/CameraService.cs
Normal file
@ -0,0 +1,21 @@
|
||||
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()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<Mat> GetFrame(VideoCapture video)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -14,8 +14,9 @@ namespace Squirrowse.Client.Service
|
||||
.AddMessagePackProtocol()
|
||||
.WithAutomaticReconnect()
|
||||
.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();
|
||||
public Task<Mat> GetFrame(VideoCapture video);
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ namespace Squirrowse.Client.Service
|
||||
{
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
}
|
38
Squirrowse.Client/Service/StreamService.cs
Normal file
38
Squirrowse.Client/Service/StreamService.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using Microsoft.Extensions.Logging;
|
||||
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;
|
||||
|
||||
public StreamService(ILogger<StreamService> logger, IConnectionManager connectionManager)
|
||||
{
|
||||
this.connectionManager = connectionManager;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public async Task SendStreamAsync(IAsyncEnumerable<byte[]> asb)
|
||||
{
|
||||
var con = connectionManager.Connect();
|
||||
try
|
||||
{
|
||||
logger.LogInformation($"{nameof(SendStreamAsync)} Start stream");
|
||||
await con.StartAsync();
|
||||
await con.SendAsync("UploadByteStream", asb, default);
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
logger.LogInformation($"{nameof(SendStreamAsync)} End stream");
|
||||
await con.StopAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -5,16 +5,19 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Squirrowse.Client.Service;
|
||||
|
||||
namespace Squirrowse.Client
|
||||
{
|
||||
public class Worker : BackgroundService
|
||||
{
|
||||
private readonly ILogger<Worker> _logger;
|
||||
private readonly IStreamService _streamService;
|
||||
|
||||
public Worker(ILogger<Worker> logger)
|
||||
public Worker(ILogger<Worker> logger, IStreamService streamService)
|
||||
{
|
||||
_logger = logger;
|
||||
_streamService = streamService;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
@ -22,6 +25,7 @@ namespace Squirrowse.Client
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user