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