2019-11-04 09:29:37 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.SignalR.Client;
|
2019-11-01 19:04:24 +01:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2019-11-02 21:06:44 +01:00
|
|
|
|
using Squirrowse.Core.Models;
|
2019-11-01 19:04:24 +01:00
|
|
|
|
|
|
|
|
|
namespace Squirrowse.Client.Service
|
|
|
|
|
{
|
|
|
|
|
public class StreamService : IStreamService
|
|
|
|
|
{
|
|
|
|
|
private readonly IConnectionManager connectionManager;
|
|
|
|
|
private readonly ILogger<StreamService> logger;
|
2019-11-02 21:06:44 +01:00
|
|
|
|
private readonly HubConnection session;
|
2019-11-04 09:29:37 +01:00
|
|
|
|
|
2019-11-01 19:04:24 +01:00
|
|
|
|
public StreamService(ILogger<StreamService> logger, IConnectionManager connectionManager)
|
|
|
|
|
{
|
|
|
|
|
this.connectionManager = connectionManager;
|
|
|
|
|
this.logger = logger;
|
2019-11-02 21:06:44 +01:00
|
|
|
|
session = connectionManager.Connect();
|
|
|
|
|
session.StartAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task SayHello()
|
|
|
|
|
{
|
2019-11-04 09:29:37 +01:00
|
|
|
|
await session.SendAsync("AddToGroup", Groups.debug);
|
2019-11-01 19:04:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task SendStreamAsync(IAsyncEnumerable<byte[]> asb)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
logger.LogInformation($"{nameof(SendStreamAsync)} Start stream");
|
2019-11-04 09:29:37 +01:00
|
|
|
|
await session.SendAsync("UploadByteStream", asb);
|
2019-11-01 19:04:24 +01:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
logger.LogInformation($"{nameof(SendStreamAsync)} End stream");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-04 09:29:37 +01:00
|
|
|
|
}
|