Client discovery
This commit is contained in:
parent
5dd51cefb6
commit
6886afdeae
@ -15,4 +15,10 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Squirrowse.Core\Squirrowse.Core.csproj" />
|
<ProjectReference Include="..\Squirrowse.Core\Squirrowse.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Update="appsettings.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Squirrowse.Core.Models;
|
using Squirrowse.Core.Models;
|
||||||
|
|
||||||
@ -13,5 +14,7 @@ namespace Squirrowse.Service.Hubs
|
|||||||
Task ExecCommandOnAll(string command, object[] act); //gni
|
Task ExecCommandOnAll(string command, object[] act); //gni
|
||||||
Task AddToGroup(Groups group, string user = "");
|
Task AddToGroup(Groups group, string user = "");
|
||||||
Task RemoveFromGroup(Groups group, string user = "");
|
Task RemoveFromGroup(Groups group, string user = "");
|
||||||
|
Task<IEnumerable<User>> GetListOfTypeUser(ConnectionType t);
|
||||||
|
Task<IEnumerable<User>> GetAllUsers();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,5 +11,7 @@ namespace Squirrowse.Service.Hubs
|
|||||||
Task RemoveUserByUserName(string agentName);
|
Task RemoveUserByUserName(string agentName);
|
||||||
IEnumerable<User> getServerSideUsers();
|
IEnumerable<User> getServerSideUsers();
|
||||||
bool CheckUser(string agentName);
|
bool CheckUser(string agentName);
|
||||||
|
IEnumerable<User> getClientSideUsers();
|
||||||
|
IEnumerable<User> getAllUsers();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
@ -22,8 +23,11 @@ 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);
|
||||||
|
logger.LogInformation($"{nameof(AddUser)}: {UserName} of {type}");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task AddToGroup(Groups group, string user = "")
|
public async Task AddToGroup(Groups group, string user = "")
|
||||||
{
|
{
|
||||||
var connectionId = string.IsNullOrWhiteSpace(user) ? Context.ConnectionId : user;
|
var connectionId = string.IsNullOrWhiteSpace(user) ? Context.ConnectionId : user;
|
||||||
@ -67,7 +71,7 @@ namespace Squirrowse.Service.Hubs
|
|||||||
{
|
{
|
||||||
foreach (var user in manager.getServerSideUsers())
|
foreach (var user in manager.getServerSideUsers())
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
@ -75,5 +79,17 @@ namespace Squirrowse.Service.Hubs
|
|||||||
await Task.Delay(100); //leave some delay for debug purpose
|
await Task.Delay(100); //leave some delay for debug purpose
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<User>> GetListOfTypeUser(ConnectionType t)
|
||||||
|
{
|
||||||
|
if (t == ConnectionType.Client) return manager.getClientSideUsers();
|
||||||
|
if (t == ConnectionType.Server) return manager.getServerSideUsers();
|
||||||
|
throw new Exception("not found") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<User>> GetAllUsers()
|
||||||
|
{
|
||||||
|
return manager.getAllUsers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ namespace Squirrowse.Service.Hubs
|
|||||||
{
|
{
|
||||||
public class StreamManager : IStreamManager
|
public class StreamManager : IStreamManager
|
||||||
{
|
{
|
||||||
private readonly List<User> _users = new List<User>(); //temporary
|
private List<User> _users = new List<User>(); //temporary
|
||||||
|
|
||||||
public Task AddUser(string connectionId, string userName,ConnectionType type)
|
public Task AddUser(string connectionId, string userName,ConnectionType type)
|
||||||
{
|
{
|
||||||
@ -31,10 +31,19 @@ namespace Squirrowse.Service.Hubs
|
|||||||
{
|
{
|
||||||
return _users.Where(user => user.UserType == ConnectionType.Server);
|
return _users.Where(user => user.UserType == ConnectionType.Server);
|
||||||
}
|
}
|
||||||
|
public IEnumerable<User> getClientSideUsers()
|
||||||
|
{
|
||||||
|
return _users.Where(user => user.UserType == ConnectionType.Client);
|
||||||
|
}
|
||||||
public bool CheckUser(string userName)
|
public bool CheckUser(string userName)
|
||||||
{
|
{
|
||||||
return _users.Any(user => user.AgentName == userName);
|
return _users.Any(user => user.AgentName == userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<User> getAllUsers()
|
||||||
|
{
|
||||||
|
var t = _users;
|
||||||
|
return _users;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,7 +19,7 @@
|
|||||||
},
|
},
|
||||||
"Squirrowse.Service": {
|
"Squirrowse.Service": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"launchBrowser": true,
|
"launchBrowser": false,
|
||||||
"launchUrl": "weatherforecast",
|
"launchUrl": "weatherforecast",
|
||||||
"applicationUrl": "https://localhost:5001;http://localhost:5000",
|
"applicationUrl": "https://localhost:5001;http://localhost:5000",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
|
@ -22,4 +22,10 @@
|
|||||||
<ProjectReference Include="..\Squirrowse.Core\Squirrowse.Core.csproj" />
|
<ProjectReference Include="..\Squirrowse.Core\Squirrowse.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Update="appsettings.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -24,8 +24,8 @@ namespace Squirrowse.Service
|
|||||||
{
|
{
|
||||||
services.AddControllers();
|
services.AddControllers();
|
||||||
services.AddMediatR(Assembly.GetAssembly(typeof(Startup)));
|
services.AddMediatR(Assembly.GetAssembly(typeof(Startup)));
|
||||||
services.AddTransient<IStreamHub, StreamHub>();
|
services.AddSingleton<IStreamHub, StreamHub>();
|
||||||
services.AddTransient<IStreamManager, StreamManager>();
|
services.AddSingleton<IStreamManager, StreamManager>();
|
||||||
services.AddCoreModule();
|
services.AddCoreModule();
|
||||||
services.AddSignalR()
|
services.AddSignalR()
|
||||||
.AddHubOptions<StreamHub
|
.AddHubOptions<StreamHub
|
||||||
|
@ -7,21 +7,21 @@
|
|||||||
@using Squirrowse.Core.Services
|
@using Squirrowse.Core.Services
|
||||||
@inject IConnectionManager _connection;
|
@inject IConnectionManager _connection;
|
||||||
<div class="card border-primary mb-3" style="max-width: 20rem;">
|
<div class="card border-primary mb-3" style="max-width: 20rem;">
|
||||||
@if (agents.Count > 0)
|
@if (agents.Any())
|
||||||
{
|
{
|
||||||
@foreach (var agent in agents)
|
@foreach (var agent in agents)
|
||||||
{
|
{
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div>
|
<div>
|
||||||
<h3 class="badge-primary">
|
<h3 class="badge-primary">
|
||||||
@agent
|
@agent.AgentName -> @agent.UserType.ToString()
|
||||||
</h3>
|
</h3>
|
||||||
<div style="padding-top:10px">
|
<div style="padding-top:10px">
|
||||||
<button id="ViewCast" disabled="@(IsViewingCastOf(agent))" class="btn btn-success btn-sm" @onclick="@(() => OnViewCastClicked(agent))">
|
<button id="ViewCast" disabled="@(IsViewingCastOf(agent.AgentName))" class="btn btn-success btn-sm" @onclick="@(() => OnViewCastClicked(agent.ConnectionId))">
|
||||||
View cast
|
View cast
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button id="StopViewCast" disabled="@(!IsViewingCastOf(agent))" class="btn btn-warning btn-sm" @onclick="@(() => OnStopViewCastClicked(agent))">
|
<button id="StopViewCast" disabled="@(!IsViewingCastOf(agent.AgentName))" class="btn btn-warning btn-sm" @onclick="@(() => OnStopViewCastClicked(agent.ConnectionId))">
|
||||||
Stop cast
|
Stop cast
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@ -42,7 +42,7 @@
|
|||||||
</div>
|
</div>
|
||||||
@code{
|
@code{
|
||||||
|
|
||||||
private List<string> agents = new List<string>();
|
private IEnumerable<User> agents = new List<User>();
|
||||||
|
|
||||||
HubConnection connection;
|
HubConnection connection;
|
||||||
string imageSource = null;
|
string imageSource = null;
|
||||||
@ -52,9 +52,9 @@
|
|||||||
{
|
{
|
||||||
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);
|
||||||
//connection.On<string>("NewScreenCastAgent", NewScreenCastAgent);
|
//connection.On<string>("NewScreenCastAgent", NewScreenCastAgent);
|
||||||
//connection.On<string>("RemoveScreenCastAgent", RemoveScreenCastAgent);
|
//connection.On<string>("RemoveScreenCastAgent", RemoveScreenCastAgent);
|
||||||
//connection.On<string>("OnStreamDataReceived", OnStreamDataReceived);
|
//connection.On<string>("OnStreamDataReceived", OnStreamDataReceived);
|
||||||
@ -67,19 +67,6 @@
|
|||||||
return agentName == CurrentViewCastAgent;
|
return agentName == CurrentViewCastAgent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewScreenCastAgent(string agentName)
|
|
||||||
{
|
|
||||||
agents.Add(agentName);
|
|
||||||
StateHasChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RemoveScreenCastAgent(string agentName)
|
|
||||||
{
|
|
||||||
agents.Remove(agentName);
|
|
||||||
imageSource = null;
|
|
||||||
CurrentViewCastAgent = null;
|
|
||||||
StateHasChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
async void OnStreamDataReceived(IAsyncEnumerable<byte[]> streamData)
|
async void OnStreamDataReceived(IAsyncEnumerable<byte[]> streamData)
|
||||||
{
|
{
|
||||||
@ -95,13 +82,13 @@
|
|||||||
private async Task OnViewCastClicked(string agentName)
|
private async Task OnViewCastClicked(string agentName)
|
||||||
{
|
{
|
||||||
CurrentViewCastAgent = agentName;
|
CurrentViewCastAgent = agentName;
|
||||||
await connection.InvokeAsync("Start", agentName);
|
await connection.InvokeAsync("Startstream", agentName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OnStopViewCastClicked(string agentName)
|
private async Task OnStopViewCastClicked(string agentName)
|
||||||
{
|
{
|
||||||
CurrentViewCastAgent = null;
|
CurrentViewCastAgent = null;
|
||||||
await connection.InvokeAsync("RemoveScreenCastViewer", agentName);
|
await connection.InvokeAsync("Stopstream", agentName);
|
||||||
imageSource = null;
|
imageSource = null;
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
"Squirrowse.Web": {
|
"Squirrowse.Web": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"applicationUrl": "https://localhost:5001;http://localhost:5000",
|
"applicationUrl": "https://localhost:5003;http://localhost:5002",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,10 @@
|
|||||||
<ProjectReference Include="..\Squirrowse.Core\Squirrowse.Core.csproj" />
|
<ProjectReference Include="..\Squirrowse.Core\Squirrowse.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Update="appsettings.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
Loading…
Reference in New Issue
Block a user