2019-11-01 19:04:24 +01:00
|
|
|
|
using Microsoft.AspNetCore.SignalR.Client;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2019-11-02 21:06:44 +01:00
|
|
|
|
using Squirrowse.Core.Models;
|
2019-11-01 19:04:24 +01:00
|
|
|
|
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;
|
2019-11-02 21:06:44 +01:00
|
|
|
|
private readonly HubConnection session;
|
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()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await session.SendAsync("AddToGroup",Groups.debug);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2019-11-01 19:04:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task SendStreamAsync(IAsyncEnumerable<byte[]> asb)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
logger.LogInformation($"{nameof(SendStreamAsync)} Start stream");
|
2019-11-02 21:06:44 +01:00
|
|
|
|
await session.SendAsync("UploadByteStream", asb, default);
|
2019-11-01 19:04:24 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
logger.LogInformation($"{nameof(SendStreamAsync)} End stream");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|