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();
|
2019-11-04 14:28:45 +01:00
|
|
|
|
session.StartAsync();
|
2019-11-02 21:06:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2019-11-04 14:28:45 +01:00
|
|
|
|
while (true)
|
2019-11-01 19:04:24 +01:00
|
|
|
|
{
|
2019-11-04 14:28:45 +01:00
|
|
|
|
|
|
|
|
|
logger.LogInformation($"{nameof(SendStreamAsync)} Start stream");
|
|
|
|
|
await session.SendAsync("UploadByteStream", asb);
|
2019-11-01 19:04:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-04 09:29:37 +01:00
|
|
|
|
}
|