Merge cleanup #5

Merged
s421801 merged 1 commits from front into develop 2020-06-20 21:51:11 +02:00
6 changed files with 101 additions and 35 deletions

View File

@ -17,6 +17,7 @@ namespace Squirrowse.Client
return Host.CreateDefaultBuilder(args) return Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) => .ConfigureServices((hostContext, services) =>
{ {
services.AddHostedService<Worker>(); services.AddHostedService<Worker>();
services.AddSingleton<IConnectionManager>(x => services.AddSingleton<IConnectionManager>(x =>
new ConnectionManager("http://localhost", 5000)); //keep as transient for now new ConnectionManager("http://localhost", 5000)); //keep as transient for now

View File

@ -47,5 +47,6 @@ namespace Squirrowse.Core.Services
{ {
await _connection.SendAsync("AddUser", Environment.UserName,type); await _connection.SendAsync("AddUser", Environment.UserName,type);
} }
} }
} }

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;
@ -86,7 +87,36 @@ namespace Squirrowse.Service.Hubs
if (t == ConnectionType.Server) return manager.getServerSideUsers(); if (t == ConnectionType.Server) return manager.getServerSideUsers();
throw new Exception("not found") ; throw new Exception("not found") ;
} }
#warning DEBUG
public async Task<string> GetListOfTypeUserString()
{
string t = "";
var tasdf=manager.getClientSideUsers();
foreach (var h in tasdf)
{
t +=h.AgentName;
}
return t;
}
#warning DEBUG
public async Task<User> Getasuser() => manager.getClientSideUsers().FirstOrDefault();
#warning Debug
public async Task<List<User>> 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<User> GetListOfTypeUserAsync(ConnectionType t)
{
var client = manager.getClientSideUsers();
foreach (var va in client)
{
yield return va;
}
}
public async Task<IEnumerable<User>> GetAllUsers() public async Task<IEnumerable<User>> GetAllUsers()
{ {
return manager.getAllUsers(); return manager.getAllUsers();

View File

@ -2,12 +2,16 @@
<h3>Hub</h3> <h3>Hub</h3>
@using System.Collections
@using Microsoft.AspNetCore.SignalR.Client @using Microsoft.AspNetCore.SignalR.Client
@using Squirrowse.Core.Models @using Squirrowse.Core.Models
@using Squirrowse.Core.Services @using Squirrowse.Core.Services
@inject IConnectionManager _connection; @inject IConnectionManager _connection;
@*<button id="LoadData"class="btn btn-success btn-sm" @onclick="@(() => loadData())">dupa123 </button>*@
<div class="card border-primary mb-3" style="max-width: 20rem;"> <div class="card border-primary mb-3" style="max-width: 20rem;">
@if (agents.Any()) @if (agents != null && agents.Any())
{ {
@foreach (var agent in agents) @foreach (var agent in agents)
{ {
@ -29,6 +33,25 @@
</div> </div>
} }
} }
@*<div class="card-body">
<div>
<h3 class="badge-primary">
@agents.AgentName -> @agents.UserType.ToString()
</h3>
<div style="padding-top:10px">
<button id="ViewCast" disabled="@(IsViewingCastOf(agents.AgentName))" class="btn btn-success btn-sm" @onclick="@(() => OnViewCastClicked(agents.ConnectionId))">
View cast
</button>
<button id="StopViewCast" disabled="@(!IsViewingCastOf(agents.AgentName))" class="btn btn-warning btn-sm" @onclick="@(() => OnStopViewCastClicked(agents.ConnectionId))">
Stop cast
</button>
</div>
</div>
</div>*@
else else
{ {
<div class="card-body"> <div class="card-body">
@ -42,20 +65,28 @@
</div> </div>
@code{ @code{
private IEnumerable<User> agents = new List<User>(); private List<User> agents;
HubConnection connection; HubConnection connection;
string imageSource = null; string imageSource = null;
string CurrentViewCastAgent = null; string CurrentViewCastAgent = null;
protected async override Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
agents=new List<User>();
await _connection.InitConnection(ConnectionType.Server); await _connection.InitConnection(ConnectionType.Server);
connection = await _connection.GetConnection(); connection = await _connection.GetConnection();
connection.On<IAsyncEnumerable<byte[]>>("RecData", OnStreamDataReceived); connection.On<IAsyncEnumerable<byte[]>>("RecData", OnStreamDataReceived);
agents = await connection.InvokeAsync<IEnumerable<User>>("GetListOfTypeUser",ConnectionType.Client); //agents = await connection.InvokeAsync<string>("GetListOfTypeUserString");
//connection.On<string>("NewScreenCastAgent", NewScreenCastAgent); //agents = await connection.InvokeAsync<User>("Getasuser");
//agents = await connection.InvokeAsync<IAsyncEnumerable<User>>("GetListOfTypeUserAsync",ConnectionType.Client);
await foreach (var dupa in connection.StreamAsync<User>("GetListOfTypeUserAsync", ConnectionType.Client))
{
agents.Add(dupa);
this.StateHasChanged();
}
//connection.On<User>("NewUser", NewUser);
//connection.On<string>("RemoveScreenCastAgent", RemoveScreenCastAgent); //connection.On<string>("RemoveScreenCastAgent", RemoveScreenCastAgent);
//connection.On<string>("OnStreamDataReceived", OnStreamDataReceived); //connection.On<string>("OnStreamDataReceived", OnStreamDataReceived);
@ -67,6 +98,11 @@
return agentName == CurrentViewCastAgent; return agentName == CurrentViewCastAgent;
} }
//void NewUser(User agentName)
//{
// agents.Add(agentName);
// StateHasChanged();
//}
async void OnStreamDataReceived(IAsyncEnumerable<byte[]> streamData) async void OnStreamDataReceived(IAsyncEnumerable<byte[]> streamData)
{ {
@ -83,6 +119,7 @@
{ {
CurrentViewCastAgent = agentName; CurrentViewCastAgent = agentName;
await connection.InvokeAsync("Startstream", agentName); await connection.InvokeAsync("Startstream", agentName);
StateHasChanged();
} }
private async Task OnStopViewCastClicked(string agentName) private async Task OnStopViewCastClicked(string agentName)

View File

@ -1,13 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework> <TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.0.0" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Squirrowse.Core\Squirrowse.Core.csproj" /> <ProjectReference Include="..\Squirrowse.Core\Squirrowse.Core.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -28,9 +28,10 @@ namespace Squirrowse.Web
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddRazorPages(); services.AddRazorPages();
services.AddServerSideBlazor().AddHubOptions(x=>x.MaximumReceiveMessageSize= 102400000); services.AddServerSideBlazor().AddHubOptions(x=>x.MaximumReceiveMessageSize= 102400000);
services.AddCoreModule(); services.AddCoreModule();
services.AddSignalR(); services.AddSignalR().AddMessagePackProtocol();
services.AddSingleton<WeatherForecastService>(); services.AddSingleton<WeatherForecastService>();
} }