Squirrowse/Squirrowse.Client/Service/StreamService.cs
2019-11-02 21:06:44 +01:00

51 lines
1.4 KiB
C#

using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Logging;
using Squirrowse.Core.Models;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
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().ConfigureAwait(false);
}
public async Task SayHello()
{
try
{
await session.SendAsync("AddToGroup",Groups.debug);
}
finally
{
}
}
public async Task SendStreamAsync(IAsyncEnumerable<byte[]> asb)
{
try
{
logger.LogInformation($"{nameof(SendStreamAsync)} Start stream");
await session.SendAsync("UploadByteStream", asb, default);
}
finally
{
logger.LogInformation($"{nameof(SendStreamAsync)} End stream");
}
}
}
}