@page "/hub"

Hub

@using System.Collections @using Microsoft.AspNetCore.SignalR.Client @using Squirrowse.Core.Models @using Squirrowse.Core.Services @inject IConnectionManager _connection; @**@
@if (agents != null && agents.Any()) { @foreach (var agent in agents) {

@agent.AgentName -> @agent.UserType.ToString()

} } else {

No Cams

}
@code{ private List agents=new List(); HubConnection connection; string imageSource = null; string CurrentViewCastAgent = null; protected override async Task OnInitializedAsync() { await _connection.InitConnection(ConnectionType.Server); connection = await _connection.GetConnection(); connection.On("RecData", OnStreamDataReceived); await foreach (var user in connection.StreamAsync("GetListOfTypeUserAsync", ConnectionType.Client).ConfigureAwait(false)) { agents.Add(user); this.StateHasChanged(); } } bool IsViewingCastOf(string agentName) { return agentName == CurrentViewCastAgent; } async Task StartRecording(string agent) { await connection.SendAsync("StartRecord"); StateHasChanged(); } async Task StopRecording(string agent) { await connection.SendAsync("StopRecord"); StateHasChanged(); } 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(); //} var base64 = Convert.ToBase64String(streamData); imageSource = String.Format("data:image/jpg;base64,{0}", base64); StateHasChanged(); } 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(); //} var base64 = Convert.ToBase64String(streamData); imageSource = String.Format("data:image/jpg;base64,{0}", base64); StateHasChanged(); } private async Task OnViewCastClicked(string agentName) { CurrentViewCastAgent = agentName; await connection.InvokeAsync("Startstream", agentName); StateHasChanged(); } private async Task OnStopViewCastClicked(string agentName) { CurrentViewCastAgent = null; await connection.InvokeAsync("StopStream", agentName); imageSource = null; StateHasChanged(); } }