From 15112abac90dae11b865e15fac6ab1675c78af1c Mon Sep 17 00:00:00 2001 From: danielgrabowski Date: Thu, 7 Nov 2019 16:47:51 +0100 Subject: [PATCH] Stream work, client leak memory --- Squirrowse.Client/Service/ActionDispatcher.cs | 7 ++++- Squirrowse.Service/Hubs/StreamHub.cs | 7 +++-- Squirrowse.Web/Pages/Hub.razor | 29 ++++++++++++------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Squirrowse.Client/Service/ActionDispatcher.cs b/Squirrowse.Client/Service/ActionDispatcher.cs index 4fcd257..b54cf4d 100644 --- a/Squirrowse.Client/Service/ActionDispatcher.cs +++ b/Squirrowse.Client/Service/ActionDispatcher.cs @@ -46,7 +46,12 @@ namespace Squirrowse.Client.Service public async Task StartStream() { - await SendStreamAsync(camera.GetFramesAsyncEnumerator()); + while (true) + { + await SendStreamAsync(camera.GetFramesAsyncEnumerator()); + + } + } } } \ No newline at end of file diff --git a/Squirrowse.Service/Hubs/StreamHub.cs b/Squirrowse.Service/Hubs/StreamHub.cs index dcd66c7..d244697 100644 --- a/Squirrowse.Service/Hubs/StreamHub.cs +++ b/Squirrowse.Service/Hubs/StreamHub.cs @@ -77,10 +77,11 @@ namespace Squirrowse.Service.Hubs public async Task UploadByteStream(IAsyncEnumerable 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> GetAllUsers() diff --git a/Squirrowse.Web/Pages/Hub.razor b/Squirrowse.Web/Pages/Hub.razor index 4a5c4aa..2b7f4ff 100644 --- a/Squirrowse.Web/Pages/Hub.razor +++ b/Squirrowse.Web/Pages/Hub.razor @@ -56,31 +56,40 @@ { await _connection.InitConnection(ConnectionType.Server); connection = await _connection.GetConnection(); - - connection.On>("RecData", OnStreamDataReceived); + connection.On("DUPA", DuPa); + 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 OnStreamDataReceived(IAsyncEnumerable 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(); }