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

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

View File

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

View File

@ -56,8 +56,8 @@
{ {
await _connection.InitConnection(ConnectionType.Server); await _connection.InitConnection(ConnectionType.Server);
connection = await _connection.GetConnection(); connection = await _connection.GetConnection();
connection.On<string>("DUPA", DuPa);
connection.On<IAsyncEnumerable<byte[]>>("RecData", OnStreamDataReceived); connection.On<byte[]>("RecData", OnStreamDataReceived);
await foreach (var user in connection.StreamAsync<User>("GetListOfTypeUserAsync", ConnectionType.Client).ConfigureAwait(false)) await foreach (var user in connection.StreamAsync<User>("GetListOfTypeUserAsync", ConnectionType.Client).ConfigureAwait(false))
{ {
@ -73,14 +73,23 @@
return agentName == CurrentViewCastAgent; return agentName == CurrentViewCastAgent;
} }
async Task OnStreamDataReceived(IAsyncEnumerable<byte[]> streamData) public void DuPa(string duuupa)
{ {
await foreach (var t in streamData) var s= "DuPa";
}
async Task OnStreamDataReceived(byte[] streamData)
{ {
var base64 = Convert.ToBase64String(t); //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); imageSource = String.Format("data:image/jpg;base64,{0}", base64);
StateHasChanged(); StateHasChanged();
}
} }