small changes
This commit is contained in:
parent
7ee7ebc4b3
commit
71c437d8d7
@ -18,7 +18,7 @@ namespace Squirrowse.Client
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
services.AddHostedService<Worker>();
|
||||
services.AddSingleton<IConnectionManager>(x =>
|
||||
services.AddSingleton<IConnectionManager,ConnectionManager>(x =>
|
||||
new ConnectionManager("http://localhost", 5000)); //keep as transient for now
|
||||
services.AddSingleton<ICameraService, CameraService>(x => new CameraService(new Camera()));
|
||||
services.AddSingleton<IActionDispatcher, ActionDispatcher>();
|
||||
|
@ -21,6 +21,7 @@ namespace Squirrowse.Client.Service
|
||||
this.connectionManager = connectionManager;
|
||||
this.logger = logger;
|
||||
this.camera = camera;
|
||||
session = connectionManager.GetConnection().Result;
|
||||
session.On("Start", StartStream);
|
||||
session.On("Stop", StopStream);
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
@ -11,19 +12,31 @@ namespace Squirrowse.Client
|
||||
public class Worker : IHostedService
|
||||
{
|
||||
private readonly IConnectionManager _connectionManager;
|
||||
private readonly ICameraService camera;
|
||||
private readonly ILogger<Worker> logger;
|
||||
|
||||
public Worker(ILogger<Worker> logger, IConnectionManager connectionManager, ICameraService camera)
|
||||
private readonly IActionDispatcher _actionDispatcher;
|
||||
public Worker(ILogger<Worker> logger, IConnectionManager connectionManager,IActionDispatcher act)
|
||||
{
|
||||
this.logger = logger;
|
||||
_connectionManager = connectionManager;
|
||||
this.camera = camera;
|
||||
_actionDispatcher = act;
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
for (var i = 0; i < 100; i++) await _connectionManager.InitConnection(ConnectionType.Client);
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _connectionManager.InitConnection(ConnectionType.Client);
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
await Task.Delay(1111);
|
||||
}
|
||||
}
|
||||
// await Task.Delay(10000);//for debug
|
||||
|
||||
}
|
||||
|
||||
public async Task StopAsync(CancellationToken cancellationToken)
|
||||
|
@ -3,7 +3,9 @@
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"System": "Information",
|
||||
"Microsoft": "Information"
|
||||
"Microsoft": "Information",
|
||||
"Microsoft.AspNetCore.SignalR": "Debug",
|
||||
"Microsoft.AspNetCore.Http.Connections": "Debug"
|
||||
}
|
||||
}
|
||||
}
|
@ -22,17 +22,17 @@ namespace Squirrowse.Core.Services
|
||||
|
||||
public async Task<HubConnection> GetConnection()
|
||||
{
|
||||
if (Connected) return _connection;
|
||||
|
||||
throw new Exception();
|
||||
return _connection;
|
||||
}
|
||||
|
||||
public async Task InitConnection(ConnectionType type)
|
||||
{
|
||||
if (_connection.State == HubConnectionState.Connected) return;
|
||||
await _connection.StartAsync();
|
||||
await RegisterOnHub(type);
|
||||
Connected = true;
|
||||
if (_connection.State == HubConnectionState.Disconnected) await _connection.StartAsync();
|
||||
|
||||
await RegisterOnHub(type);
|
||||
Connected = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@ -21,6 +22,16 @@ namespace Squirrowse.Service.Hubs
|
||||
public async Task AddUser(string UserName, ConnectionType type)
|
||||
{
|
||||
await manager.AddUser(Context.ConnectionId, UserName, type);
|
||||
switch (type)
|
||||
{
|
||||
case ConnectionType.Client:
|
||||
await AddToGroup(Core.Models.Groups.normal);
|
||||
break;
|
||||
case ConnectionType.Server:
|
||||
await AddToGroup(Core.Models.Groups.superUser);
|
||||
break;
|
||||
}
|
||||
|
||||
logger.LogInformation($"{nameof(AddUser)}: {UserName} of {type}");
|
||||
}
|
||||
|
||||
@ -51,9 +62,9 @@ namespace Squirrowse.Service.Hubs
|
||||
|
||||
public async Task Startstream(string clientId)
|
||||
{
|
||||
var client = Clients.Client(clientId);
|
||||
|
||||
await client.SendAsync("Start");
|
||||
//var client = Clients.Client(clientId);
|
||||
await Clients.Groups(Core.Models.Groups.normal.ToString()).SendAsync("Start");
|
||||
// await client.SendAsync("Start");
|
||||
}
|
||||
|
||||
|
||||
@ -66,7 +77,7 @@ namespace Squirrowse.Service.Hubs
|
||||
|
||||
public async Task UploadByteStream(IAsyncEnumerable<byte[]> stream)
|
||||
{
|
||||
foreach (var user in manager.getServerSideUsers())
|
||||
foreach (var user in manager.getServerSideUsers().ToList())
|
||||
await Clients.Client(user.ConnectionId).SendAsync("RecData", stream);
|
||||
await foreach (var frame in stream)
|
||||
{
|
||||
|
@ -3,7 +3,9 @@
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"System": "Information",
|
||||
"Microsoft": "Information"
|
||||
"Microsoft": "Information",
|
||||
"Microsoft.AspNetCore.SignalR": "Debug",
|
||||
"Microsoft.AspNetCore.Http.Connections": "Debug"
|
||||
}
|
||||
}
|
||||
}
|
@ -3,7 +3,9 @@
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
"Microsoft.Hosting.Lifetime": "Information",
|
||||
"Microsoft.AspNetCore.SignalR": "Debug",
|
||||
"Microsoft.AspNetCore.Http.Connections": "Debug"
|
||||
}
|
||||
},
|
||||
"NLog": {
|
||||
|
@ -73,7 +73,7 @@
|
||||
return agentName == CurrentViewCastAgent;
|
||||
}
|
||||
|
||||
async void OnStreamDataReceived(IAsyncEnumerable<byte[]> streamData)
|
||||
async Task OnStreamDataReceived(IAsyncEnumerable<byte[]> streamData)
|
||||
{
|
||||
await foreach (var t in streamData)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user