2019-11-06 17:02:06 +01:00
|
|
|
@page "/hub"
|
|
|
|
|
|
|
|
<h3>Hub</h3>
|
|
|
|
|
2019-11-06 22:34:02 +01:00
|
|
|
@using System.Collections
|
2019-11-06 17:02:06 +01:00
|
|
|
@using Microsoft.AspNetCore.SignalR.Client
|
|
|
|
@using Squirrowse.Core.Models
|
|
|
|
@using Squirrowse.Core.Services
|
|
|
|
@inject IConnectionManager _connection;
|
2019-11-06 22:34:02 +01:00
|
|
|
|
|
|
|
@*<button id="LoadData"class="btn btn-success btn-sm" @onclick="@(() => loadData())">dupa123 </button>*@
|
|
|
|
|
2019-11-06 17:02:06 +01:00
|
|
|
<div class="card border-primary mb-3" style="max-width: 20rem;">
|
2019-11-06 22:34:02 +01:00
|
|
|
@if (agents != null && agents.Any())
|
|
|
|
{
|
|
|
|
@foreach (var agent in agents)
|
2019-11-06 17:02:06 +01:00
|
|
|
{
|
2019-11-06 22:34:02 +01:00
|
|
|
<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>
|
|
|
|
|
2019-11-08 16:36:20 +01:00
|
|
|
<button id="StopViewCast" disabled="@(IsViewingCastOf(agent.AgentName))" class="btn btn-warning btn-sm" @onclick="@(() => OnStopViewCastClicked(agent.ConnectionId))">
|
2019-11-06 22:34:02 +01:00
|
|
|
Stop cast
|
|
|
|
</button>
|
2019-11-16 13:07:20 +01:00
|
|
|
|
|
|
|
<button id="StartRecording" disabled="@(IsViewingCastOf(agent.AgentName))" class="btn btn-warning btn-sm" @onclick="@(() =>StartRecording(agent.ConnectionId))">
|
|
|
|
Stop cast
|
|
|
|
</button>
|
|
|
|
<button id="StartRecording" disabled="@(IsViewingCastOf(agent.AgentName))" class="btn btn-warning btn-sm" @onclick="@(() =>StopRecording(agent.ConnectionId))">
|
|
|
|
Stop cast
|
|
|
|
</button>
|
2019-11-06 17:02:06 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
2019-11-07 11:52:27 +01:00
|
|
|
}
|
|
|
|
else
|
2019-11-06 22:34:02 +01:00
|
|
|
{
|
|
|
|
<div class="card-body">
|
|
|
|
<h3 class="card-header badge-warning">No Cams</h3>
|
2019-11-06 17:02:06 +01:00
|
|
|
</div>
|
2019-11-06 22:34:02 +01:00
|
|
|
}
|
|
|
|
</div>
|
2019-11-06 17:02:06 +01:00
|
|
|
|
|
|
|
<div class="border">
|
|
|
|
<img id='screenImage' src="@imageSource" />
|
|
|
|
</div>
|
|
|
|
@code{
|
|
|
|
|
2019-11-06 23:06:47 +01:00
|
|
|
private List<User> agents=new List<User>();
|
2019-11-06 17:02:06 +01:00
|
|
|
|
|
|
|
HubConnection connection;
|
|
|
|
string imageSource = null;
|
|
|
|
string CurrentViewCastAgent = null;
|
|
|
|
|
2019-11-06 22:34:02 +01:00
|
|
|
protected override async Task OnInitializedAsync()
|
2019-11-06 17:02:06 +01:00
|
|
|
{
|
|
|
|
await _connection.InitConnection(ConnectionType.Server);
|
|
|
|
connection = await _connection.GetConnection();
|
2019-11-07 16:47:51 +01:00
|
|
|
connection.On<byte[]>("RecData", OnStreamDataReceived);
|
2019-11-07 11:52:27 +01:00
|
|
|
|
|
|
|
await foreach (var user in connection.StreamAsync<User>("GetListOfTypeUserAsync", ConnectionType.Client).ConfigureAwait(false))
|
2019-11-06 22:34:02 +01:00
|
|
|
{
|
2019-11-07 11:52:27 +01:00
|
|
|
agents.Add(user);
|
2019-11-06 22:34:02 +01:00
|
|
|
this.StateHasChanged();
|
|
|
|
}
|
2019-11-07 16:47:51 +01:00
|
|
|
|
2019-11-06 17:02:06 +01:00
|
|
|
}
|
2019-11-07 16:47:51 +01:00
|
|
|
|
2019-11-06 17:02:06 +01:00
|
|
|
|
|
|
|
bool IsViewingCastOf(string agentName)
|
|
|
|
{
|
|
|
|
return agentName == CurrentViewCastAgent;
|
|
|
|
}
|
2019-11-16 13:07:20 +01:00
|
|
|
async Task StartRecording(string agent)
|
|
|
|
{
|
|
|
|
await connection.SendAsync("StartRecord");
|
|
|
|
StateHasChanged();
|
|
|
|
}
|
|
|
|
async Task StopRecording(string agent)
|
|
|
|
{
|
|
|
|
await connection.SendAsync("StopRecord");
|
|
|
|
StateHasChanged();
|
|
|
|
}
|
2019-11-07 16:47:51 +01:00
|
|
|
|
|
|
|
async Task OnStreamDataReceived(byte[] streamData)
|
|
|
|
{
|
|
|
|
//await foreach (var t in streamData)
|
|
|
|
//{
|
|
|
|
// var base64 = Convert.ToBase64String(t);
|
|
|
|
// imageSource = String.Format("data:image/jpg;base64,{0}", base64);
|
|
|
|
// StateHasChanged();
|
|
|
|
//}
|
2019-11-16 13:07:20 +01:00
|
|
|
|
|
|
|
var base64 = Convert.ToBase64String(streamData);
|
|
|
|
imageSource = String.Format("data:image/jpg;base64,{0}", base64);
|
2019-11-07 16:47:51 +01:00
|
|
|
StateHasChanged();
|
2019-11-06 17:02:06 +01:00
|
|
|
|
2019-11-16 13:07:20 +01:00
|
|
|
}
|
2019-11-08 16:36:20 +01:00
|
|
|
async Task OnStreamDataReceivedEn(byte[] streamData)
|
|
|
|
{
|
|
|
|
//await foreach (var t in streamData)
|
|
|
|
//{
|
|
|
|
// var base64 = Convert.ToBase64String(t);
|
|
|
|
// imageSource = String.Format("data:image/jpg;base64,{0}", base64);
|
|
|
|
// StateHasChanged();
|
|
|
|
//}
|
2019-11-16 13:07:20 +01:00
|
|
|
|
|
|
|
var base64 = Convert.ToBase64String(streamData);
|
|
|
|
imageSource = String.Format("data:image/jpg;base64,{0}", base64);
|
2019-11-08 16:36:20 +01:00
|
|
|
StateHasChanged();
|
|
|
|
|
2019-11-06 17:02:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private async Task OnViewCastClicked(string agentName)
|
|
|
|
{
|
|
|
|
CurrentViewCastAgent = agentName;
|
2019-11-06 19:17:06 +01:00
|
|
|
await connection.InvokeAsync("Startstream", agentName);
|
2019-11-06 22:34:02 +01:00
|
|
|
StateHasChanged();
|
2019-11-06 17:02:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private async Task OnStopViewCastClicked(string agentName)
|
|
|
|
{
|
|
|
|
CurrentViewCastAgent = null;
|
2019-11-08 16:36:20 +01:00
|
|
|
await connection.InvokeAsync("StopStream", agentName);
|
2019-11-06 17:02:06 +01:00
|
|
|
imageSource = null;
|
|
|
|
StateHasChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|