From fd80926607e536fffb4d6e9dd386376c54c6046b Mon Sep 17 00:00:00 2001 From: drastiq Date: Wed, 6 Nov 2019 22:34:02 +0100 Subject: [PATCH] Blazor is fun --- Squirrowse.Client/Program.cs | 1 + Squirrowse.Core/Services/ConnectionManager.cs | 1 + Squirrowse.Service/Hubs/StreamHub.cs | 30 ++++++ Squirrowse.Web/Pages/Hub.razor | 95 +++++++++++++------ Squirrowse.Web/Squirrowse.Web.csproj | 6 +- Squirrowse.Web/Startup.cs | 3 +- 6 files changed, 101 insertions(+), 35 deletions(-) diff --git a/Squirrowse.Client/Program.cs b/Squirrowse.Client/Program.cs index acda457..13759ee 100644 --- a/Squirrowse.Client/Program.cs +++ b/Squirrowse.Client/Program.cs @@ -17,6 +17,7 @@ namespace Squirrowse.Client return Host.CreateDefaultBuilder(args) .ConfigureServices((hostContext, services) => { + services.AddHostedService(); services.AddSingleton(x => new ConnectionManager("http://localhost", 5000)); //keep as transient for now diff --git a/Squirrowse.Core/Services/ConnectionManager.cs b/Squirrowse.Core/Services/ConnectionManager.cs index 6f0d876..594086f 100644 --- a/Squirrowse.Core/Services/ConnectionManager.cs +++ b/Squirrowse.Core/Services/ConnectionManager.cs @@ -47,5 +47,6 @@ namespace Squirrowse.Core.Services { await _connection.SendAsync("AddUser", Environment.UserName,type); } + } } \ No newline at end of file diff --git a/Squirrowse.Service/Hubs/StreamHub.cs b/Squirrowse.Service/Hubs/StreamHub.cs index 11e6a58..3da5cb8 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; @@ -86,7 +87,36 @@ namespace Squirrowse.Service.Hubs if (t == ConnectionType.Server) return manager.getServerSideUsers(); throw new Exception("not found") ; } +#warning DEBUG + public async Task GetListOfTypeUserString() + { + string t = ""; + var tasdf=manager.getClientSideUsers(); + foreach (var h in tasdf) + { + t +=h.AgentName; + } + return t; + } +#warning DEBUG + public async Task Getasuser() => manager.getClientSideUsers().FirstOrDefault(); +#warning Debug + public async Task> GetListOfTypeUserE(ConnectionType t) + { + if (t == ConnectionType.Client) return manager.getClientSideUsers().ToList(); + if (t == ConnectionType.Server) return manager.getServerSideUsers().ToList(); + throw new Exception("not found"); + } +#warning debug + public async IAsyncEnumerable GetListOfTypeUserAsync(ConnectionType t) + { + var client = manager.getClientSideUsers(); + foreach (var va in client) + { + yield return va; + } + } public async Task> GetAllUsers() { return manager.getAllUsers(); diff --git a/Squirrowse.Web/Pages/Hub.razor b/Squirrowse.Web/Pages/Hub.razor index 46e1042..a962a61 100644 --- a/Squirrowse.Web/Pages/Hub.razor +++ b/Squirrowse.Web/Pages/Hub.razor @@ -2,60 +2,91 @@

Hub

+@using System.Collections @using Microsoft.AspNetCore.SignalR.Client @using Squirrowse.Core.Models @using Squirrowse.Core.Services @inject IConnectionManager _connection; -
- @if (agents.Any()) - { - @foreach (var agent in agents) - { -
-
-

- @agent.AgentName -> @agent.UserType.ToString() -

-
- - -
-
-
- } - } - else +@**@ + +
+ @if (agents != null && agents.Any()) +{ + @foreach (var agent in agents) {
-

No Cams

+
+

+ @agent.AgentName -> @agent.UserType.ToString() +

+
+ + + +
+
} + } + + @*
+
+

+ @agents.AgentName -> @agents.UserType.ToString() +

+
+ + + +
+
+
*@ + + +else + { +
+

No Cams

+ } +
@code{ - private IEnumerable agents = new List(); + private List agents; HubConnection connection; string imageSource = null; string CurrentViewCastAgent = null; - protected async override Task OnInitializedAsync() + protected override async Task OnInitializedAsync() { + agents=new List(); await _connection.InitConnection(ConnectionType.Server); connection = await _connection.GetConnection(); - + connection.On>("RecData", OnStreamDataReceived); - agents = await connection.InvokeAsync>("GetListOfTypeUser",ConnectionType.Client); - //connection.On("NewScreenCastAgent", NewScreenCastAgent); + //agents = await connection.InvokeAsync("GetListOfTypeUserString"); + //agents = await connection.InvokeAsync("Getasuser"); + //agents = await connection.InvokeAsync>("GetListOfTypeUserAsync",ConnectionType.Client); + await foreach (var dupa in connection.StreamAsync("GetListOfTypeUserAsync", ConnectionType.Client)) + { + agents.Add(dupa); + this.StateHasChanged(); + } + //connection.On("NewUser", NewUser); //connection.On("RemoveScreenCastAgent", RemoveScreenCastAgent); //connection.On("OnStreamDataReceived", OnStreamDataReceived); @@ -67,6 +98,11 @@ return agentName == CurrentViewCastAgent; } + //void NewUser(User agentName) + //{ + // agents.Add(agentName); + // StateHasChanged(); + //} async void OnStreamDataReceived(IAsyncEnumerable streamData) { @@ -83,6 +119,7 @@ { CurrentViewCastAgent = agentName; await connection.InvokeAsync("Startstream", agentName); + StateHasChanged(); } private async Task OnStopViewCastClicked(string agentName) diff --git a/Squirrowse.Web/Squirrowse.Web.csproj b/Squirrowse.Web/Squirrowse.Web.csproj index effcb92..b0edf39 100644 --- a/Squirrowse.Web/Squirrowse.Web.csproj +++ b/Squirrowse.Web/Squirrowse.Web.csproj @@ -1,13 +1,9 @@ - + netcoreapp3.0 - - - - diff --git a/Squirrowse.Web/Startup.cs b/Squirrowse.Web/Startup.cs index fae4d30..896c2d5 100644 --- a/Squirrowse.Web/Startup.cs +++ b/Squirrowse.Web/Startup.cs @@ -28,9 +28,10 @@ namespace Squirrowse.Web public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); + services.AddServerSideBlazor().AddHubOptions(x=>x.MaximumReceiveMessageSize= 102400000); services.AddCoreModule(); - services.AddSignalR(); + services.AddSignalR().AddMessagePackProtocol(); services.AddSingleton(); } -- 2.20.1