Stream work, client leak memory

This commit is contained in:
danielgrabowski 2019-11-07 16:47:51 +01:00
parent 71c437d8d7
commit 15112abac9
3 changed files with 29 additions and 14 deletions

View File

@ -46,7 +46,12 @@ namespace Squirrowse.Client.Service
public async Task StartStream()
{
await SendStreamAsync(camera.GetFramesAsyncEnumerator());
while (true)
{
await SendStreamAsync(camera.GetFramesAsyncEnumerator());
}
}
}
}

View File

@ -77,10 +77,11 @@ namespace Squirrowse.Service.Hubs
public async Task UploadByteStream(IAsyncEnumerable<byte[]> stream)
{
foreach (var user in manager.getServerSideUsers().ToList())
await Clients.Client(user.ConnectionId).SendAsync("RecData", stream);
//await Clients.Groups(Core.Models.Groups.superUser.ToString()).SendAsync("DUPA", "beniz");
//await Clients.Groups(Core.Models.Groups.superUser.ToString()).SendAsync("RecData", stream);
await foreach (var frame in stream)
{
await Clients.Groups(Core.Models.Groups.superUser.ToString()).SendAsync("RecData", frame);
logger.LogInformation($"Got frame size: {frame.Length} ");
await Task.Delay(100); //leave some delay for debug purpose
}
@ -90,7 +91,7 @@ namespace Squirrowse.Service.Hubs
{
if (t == ConnectionType.Client) return manager.getClientSideUsers();
if (t == ConnectionType.Server) return manager.getServerSideUsers();
throw new Exception("not found");
return manager.getAllUsers();
}
public async Task<IEnumerable<User>> GetAllUsers()

View File

@ -56,31 +56,40 @@
{
await _connection.InitConnection(ConnectionType.Server);
connection = await _connection.GetConnection();
connection.On<IAsyncEnumerable<byte[]>>("RecData", OnStreamDataReceived);
connection.On<string>("DUPA", DuPa);
connection.On<byte[]>("RecData", OnStreamDataReceived);
await foreach (var user in connection.StreamAsync<User>("GetListOfTypeUserAsync", ConnectionType.Client).ConfigureAwait(false))
{
agents.Add(user);
this.StateHasChanged();
}
}
bool IsViewingCastOf(string agentName)
{
return agentName == CurrentViewCastAgent;
}
async Task OnStreamDataReceived(IAsyncEnumerable<byte[]> streamData)
public void DuPa(string duuupa)
{
await foreach (var t in streamData)
{
var base64 = Convert.ToBase64String(t);
var s= "DuPa";
}
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();
}
StateHasChanged();
}