Squirrowse/Squirrowse.Client/Service/StreamService.cs
2019-11-04 14:28:45 +01:00

38 lines
1.1 KiB
C#

using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Logging;
using Squirrowse.Core.Models;
namespace Squirrowse.Client.Service
{
public class StreamService : IStreamService
{
private readonly IConnectionManager connectionManager;
private readonly ILogger<StreamService> logger;
private readonly HubConnection session;
public StreamService(ILogger<StreamService> logger, IConnectionManager connectionManager)
{
this.connectionManager = connectionManager;
this.logger = logger;
session = connectionManager.Connect();
session.StartAsync();
}
public async Task SayHello()
{
await session.SendAsync("AddToGroup", Groups.debug);
}
public async Task SendStreamAsync(IAsyncEnumerable<byte[]> asb)
{
while (true)
{
logger.LogInformation($"{nameof(SendStreamAsync)} Start stream");
await session.SendAsync("UploadByteStream", asb);
}
}
}
}