small changes

This commit is contained in:
danielgrabowski 2019-11-07 14:26:46 +01:00
parent 7ee7ebc4b3
commit 71c437d8d7
9 changed files with 51 additions and 20 deletions

View File

@ -18,7 +18,7 @@ namespace Squirrowse.Client
.ConfigureServices((hostContext, services) => .ConfigureServices((hostContext, services) =>
{ {
services.AddHostedService<Worker>(); services.AddHostedService<Worker>();
services.AddSingleton<IConnectionManager>(x => services.AddSingleton<IConnectionManager,ConnectionManager>(x =>
new ConnectionManager("http://localhost", 5000)); //keep as transient for now new ConnectionManager("http://localhost", 5000)); //keep as transient for now
services.AddSingleton<ICameraService, CameraService>(x => new CameraService(new Camera())); services.AddSingleton<ICameraService, CameraService>(x => new CameraService(new Camera()));
services.AddSingleton<IActionDispatcher, ActionDispatcher>(); services.AddSingleton<IActionDispatcher, ActionDispatcher>();

View File

@ -21,6 +21,7 @@ namespace Squirrowse.Client.Service
this.connectionManager = connectionManager; this.connectionManager = connectionManager;
this.logger = logger; this.logger = logger;
this.camera = camera; this.camera = camera;
session = connectionManager.GetConnection().Result;
session.On("Start", StartStream); session.On("Start", StartStream);
session.On("Stop", StopStream); session.On("Stop", StopStream);
} }

View File

@ -1,3 +1,4 @@
using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
@ -11,19 +12,31 @@ namespace Squirrowse.Client
public class Worker : IHostedService public class Worker : IHostedService
{ {
private readonly IConnectionManager _connectionManager; private readonly IConnectionManager _connectionManager;
private readonly ICameraService camera;
private readonly ILogger<Worker> logger; private readonly ILogger<Worker> logger;
private readonly IActionDispatcher _actionDispatcher;
public Worker(ILogger<Worker> logger, IConnectionManager connectionManager, ICameraService camera) public Worker(ILogger<Worker> logger, IConnectionManager connectionManager,IActionDispatcher act)
{ {
this.logger = logger; this.logger = logger;
_connectionManager = connectionManager; _connectionManager = connectionManager;
this.camera = camera; _actionDispatcher = act;
} }
public async Task StartAsync(CancellationToken cancellationToken) 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) public async Task StopAsync(CancellationToken cancellationToken)

View File

@ -3,7 +3,9 @@
"LogLevel": { "LogLevel": {
"Default": "Debug", "Default": "Debug",
"System": "Information", "System": "Information",
"Microsoft": "Information" "Microsoft": "Information",
"Microsoft.AspNetCore.SignalR": "Debug",
"Microsoft.AspNetCore.Http.Connections": "Debug"
} }
} }
} }

View File

@ -22,17 +22,17 @@ namespace Squirrowse.Core.Services
public async Task<HubConnection> GetConnection() public async Task<HubConnection> GetConnection()
{ {
if (Connected) return _connection; return _connection;
throw new Exception();
} }
public async Task InitConnection(ConnectionType type) public async Task InitConnection(ConnectionType type)
{ {
if (_connection.State == HubConnectionState.Connected) return; if (_connection.State == HubConnectionState.Connected) return;
await _connection.StartAsync(); if (_connection.State == HubConnectionState.Disconnected) await _connection.StartAsync();
await RegisterOnHub(type);
Connected = true; await RegisterOnHub(type);
Connected = true;
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -21,6 +22,16 @@ namespace Squirrowse.Service.Hubs
public async Task AddUser(string UserName, ConnectionType type) public async Task AddUser(string UserName, ConnectionType type)
{ {
await manager.AddUser(Context.ConnectionId, UserName, 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}"); logger.LogInformation($"{nameof(AddUser)}: {UserName} of {type}");
} }
@ -51,9 +62,9 @@ namespace Squirrowse.Service.Hubs
public async Task Startstream(string clientId) public async Task Startstream(string clientId)
{ {
var client = Clients.Client(clientId); //var client = Clients.Client(clientId);
await Clients.Groups(Core.Models.Groups.normal.ToString()).SendAsync("Start");
await client.SendAsync("Start"); // await client.SendAsync("Start");
} }
@ -66,7 +77,7 @@ namespace Squirrowse.Service.Hubs
public async Task UploadByteStream(IAsyncEnumerable<byte[]> stream) 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 Clients.Client(user.ConnectionId).SendAsync("RecData", stream);
await foreach (var frame in stream) await foreach (var frame in stream)
{ {

View File

@ -3,7 +3,9 @@
"LogLevel": { "LogLevel": {
"Default": "Debug", "Default": "Debug",
"System": "Information", "System": "Information",
"Microsoft": "Information" "Microsoft": "Information",
"Microsoft.AspNetCore.SignalR": "Debug",
"Microsoft.AspNetCore.Http.Connections": "Debug"
} }
} }
} }

View File

@ -3,7 +3,9 @@
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",
"Microsoft": "Warning", "Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information" "Microsoft.Hosting.Lifetime": "Information",
"Microsoft.AspNetCore.SignalR": "Debug",
"Microsoft.AspNetCore.Http.Connections": "Debug"
} }
}, },
"NLog": { "NLog": {

View File

@ -73,7 +73,7 @@
return agentName == CurrentViewCastAgent; return agentName == CurrentViewCastAgent;
} }
async void OnStreamDataReceived(IAsyncEnumerable<byte[]> streamData) async Task OnStreamDataReceived(IAsyncEnumerable<byte[]> streamData)
{ {
await foreach (var t in streamData) await foreach (var t in streamData)
{ {