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)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<Worker>();
services.AddSingleton<IConnectionManager>(x =>
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);
}
}
}

View File

@ -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<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()
{
return manager.getAllUsers();

View File

@ -2,60 +2,91 @@
<h3>Hub</h3>
@using System.Collections
@using Microsoft.AspNetCore.SignalR.Client
@using Squirrowse.Core.Models
@using Squirrowse.Core.Services
@inject IConnectionManager _connection;
<div class="card border-primary mb-3" style="max-width: 20rem;">
@if (agents.Any())
{
@foreach (var agent in agents)
{
<div class="card-body">
<div>
<h3 class="badge-primary">
@agent.AgentName -> @agent.UserType.ToString()
</h3>
<div style="padding-top:10px">
<button id="ViewCast" disabled="@(IsViewingCastOf(agent.AgentName))" class="btn btn-success btn-sm" @onclick="@(() => OnViewCastClicked(agent.ConnectionId))">
View cast
</button>
<button id="StopViewCast" disabled="@(!IsViewingCastOf(agent.AgentName))" class="btn btn-warning btn-sm" @onclick="@(() => OnStopViewCastClicked(agent.ConnectionId))">
Stop cast
</button>
</div>
</div>
</div>
}
}
else
@*<button id="LoadData"class="btn btn-success btn-sm" @onclick="@(() => loadData())">dupa123 </button>*@
<div class="card border-primary mb-3" style="max-width: 20rem;">
@if (agents != null && agents.Any())
{
@foreach (var agent in agents)
{
<div class="card-body">
<h3 class="card-header badge-warning">No Cams</h3>
<div>
<h3 class="badge-primary">
@agent.AgentName -> @agent.UserType.ToString()
</h3>
<div style="padding-top:10px">
<button id="ViewCast" disabled="@(IsViewingCastOf(agent.AgentName))" class="btn btn-success btn-sm" @onclick="@(() => OnViewCastClicked(agent.ConnectionId))">
View cast
</button>
<button id="StopViewCast" disabled="@(!IsViewingCastOf(agent.AgentName))" class="btn btn-warning btn-sm" @onclick="@(() => OnStopViewCastClicked(agent.ConnectionId))">
Stop cast
</button>
</div>
</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
{
<div class="card-body">
<h3 class="card-header badge-warning">No Cams</h3>
</div>
}
</div>
<div class="border">
<img id='screenImage' src="@imageSource" />
</div>
@code{
private IEnumerable<User> agents = new List<User>();
private List<User> agents;
HubConnection connection;
string imageSource = null;
string CurrentViewCastAgent = null;
protected async override Task OnInitializedAsync()
protected override async Task OnInitializedAsync()
{
agents=new List<User>();
await _connection.InitConnection(ConnectionType.Server);
connection = await _connection.GetConnection();
connection.On<IAsyncEnumerable<byte[]>>("RecData", OnStreamDataReceived);
agents = await connection.InvokeAsync<IEnumerable<User>>("GetListOfTypeUser",ConnectionType.Client);
//connection.On<string>("NewScreenCastAgent", NewScreenCastAgent);
//agents = await connection.InvokeAsync<string>("GetListOfTypeUserString");
//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>("OnStreamDataReceived", OnStreamDataReceived);
@ -67,6 +98,11 @@
return agentName == CurrentViewCastAgent;
}
//void NewUser(User agentName)
//{
// agents.Add(agentName);
// StateHasChanged();
//}
async void OnStreamDataReceived(IAsyncEnumerable<byte[]> streamData)
{
@ -83,6 +119,7 @@
{
CurrentViewCastAgent = agentName;
await connection.InvokeAsync("Startstream", agentName);
StateHasChanged();
}
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>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Squirrowse.Core\Squirrowse.Core.csproj" />
</ItemGroup>

View File

@ -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<WeatherForecastService>();
}