From 71c437d8d79892f591dcfdd5d217d0b9065fc968 Mon Sep 17 00:00:00 2001 From: danielgrabowski Date: Thu, 7 Nov 2019 14:26:46 +0100 Subject: [PATCH] small changes --- Squirrowse.Client/Program.cs | 2 +- Squirrowse.Client/Service/ActionDispatcher.cs | 1 + Squirrowse.Client/Worker.cs | 23 +++++++++++++++---- .../appsettings.Development.json | 4 +++- Squirrowse.Core/Services/ConnectionManager.cs | 12 +++++----- Squirrowse.Service/Hubs/StreamHub.cs | 19 +++++++++++---- .../appsettings.Development.json | 4 +++- Squirrowse.Service/appsettings.json | 4 +++- Squirrowse.Web/Pages/Hub.razor | 2 +- 9 files changed, 51 insertions(+), 20 deletions(-) diff --git a/Squirrowse.Client/Program.cs b/Squirrowse.Client/Program.cs index acda457..2d8bf2f 100644 --- a/Squirrowse.Client/Program.cs +++ b/Squirrowse.Client/Program.cs @@ -18,7 +18,7 @@ namespace Squirrowse.Client .ConfigureServices((hostContext, services) => { services.AddHostedService(); - services.AddSingleton(x => + services.AddSingleton(x => new ConnectionManager("http://localhost", 5000)); //keep as transient for now services.AddSingleton(x => new CameraService(new Camera())); services.AddSingleton(); diff --git a/Squirrowse.Client/Service/ActionDispatcher.cs b/Squirrowse.Client/Service/ActionDispatcher.cs index 15466d2..4fcd257 100644 --- a/Squirrowse.Client/Service/ActionDispatcher.cs +++ b/Squirrowse.Client/Service/ActionDispatcher.cs @@ -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); } diff --git a/Squirrowse.Client/Worker.cs b/Squirrowse.Client/Worker.cs index 94d5b0c..77420ee 100644 --- a/Squirrowse.Client/Worker.cs +++ b/Squirrowse.Client/Worker.cs @@ -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 logger; - - public Worker(ILogger logger, IConnectionManager connectionManager, ICameraService camera) + private readonly IActionDispatcher _actionDispatcher; + public Worker(ILogger 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) diff --git a/Squirrowse.Client/appsettings.Development.json b/Squirrowse.Client/appsettings.Development.json index f999bc2..914088a 100644 --- a/Squirrowse.Client/appsettings.Development.json +++ b/Squirrowse.Client/appsettings.Development.json @@ -3,7 +3,9 @@ "LogLevel": { "Default": "Debug", "System": "Information", - "Microsoft": "Information" + "Microsoft": "Information", + "Microsoft.AspNetCore.SignalR": "Debug", + "Microsoft.AspNetCore.Http.Connections": "Debug" } } } \ No newline at end of file diff --git a/Squirrowse.Core/Services/ConnectionManager.cs b/Squirrowse.Core/Services/ConnectionManager.cs index 08d975d..996ac90 100644 --- a/Squirrowse.Core/Services/ConnectionManager.cs +++ b/Squirrowse.Core/Services/ConnectionManager.cs @@ -22,17 +22,17 @@ namespace Squirrowse.Core.Services public async Task 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; + } diff --git a/Squirrowse.Service/Hubs/StreamHub.cs b/Squirrowse.Service/Hubs/StreamHub.cs index 8c2be2f..dcd66c7 100644 --- a/Squirrowse.Service/Hubs/StreamHub.cs +++ b/Squirrowse.Service/Hubs/StreamHub.cs @@ -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 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) { diff --git a/Squirrowse.Service/appsettings.Development.json b/Squirrowse.Service/appsettings.Development.json index f999bc2..914088a 100644 --- a/Squirrowse.Service/appsettings.Development.json +++ b/Squirrowse.Service/appsettings.Development.json @@ -3,7 +3,9 @@ "LogLevel": { "Default": "Debug", "System": "Information", - "Microsoft": "Information" + "Microsoft": "Information", + "Microsoft.AspNetCore.SignalR": "Debug", + "Microsoft.AspNetCore.Http.Connections": "Debug" } } } \ No newline at end of file diff --git a/Squirrowse.Service/appsettings.json b/Squirrowse.Service/appsettings.json index 0a501d7..9626df6 100644 --- a/Squirrowse.Service/appsettings.json +++ b/Squirrowse.Service/appsettings.json @@ -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": { diff --git a/Squirrowse.Web/Pages/Hub.razor b/Squirrowse.Web/Pages/Hub.razor index 3e81ca0..4a5c4aa 100644 --- a/Squirrowse.Web/Pages/Hub.razor +++ b/Squirrowse.Web/Pages/Hub.razor @@ -73,7 +73,7 @@ return agentName == CurrentViewCastAgent; } - async void OnStreamDataReceived(IAsyncEnumerable streamData) + async Task OnStreamDataReceived(IAsyncEnumerable streamData) { await foreach (var t in streamData) {