78 lines
2.4 KiB
C#
78 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using Microsoft.Extensions.Logging;
|
|
using OpenCvSharp;
|
|
using Squirrowse.Core.Models;
|
|
using Squirrowse.Core.Services;
|
|
|
|
namespace Squirrowse.Service.Hubs
|
|
{
|
|
public class StreamHub : Hub, IStreamHub //fujka
|
|
{
|
|
private readonly ILogger<StreamHub> logger;
|
|
|
|
public StreamHub(ILogger<StreamHub> logger)
|
|
{
|
|
this.logger = logger;
|
|
}
|
|
|
|
public async Task AddClient()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task AddToGroup(Groups group, string user = "")
|
|
{
|
|
var connectionId = string.IsNullOrWhiteSpace(user) ? Context.ConnectionId : user;
|
|
await Groups.AddToGroupAsync(connectionId, group.ToString());
|
|
logger.LogInformation($"{nameof(AddToGroup)}: {connectionId} joined to {group}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// USE ONLY FOR DEBUG
|
|
/// </summary>
|
|
/// <param name="act"></param>
|
|
/// <returns>DESTRUCTION</returns>
|
|
public async Task ExecCommandOnAll(string command, object[] act)
|
|
{
|
|
await Clients.All.SendCoreAsync(command, act);
|
|
}
|
|
|
|
public async Task RemoveFromGroup(Groups group, string user = "")
|
|
{
|
|
var connectionId = string.IsNullOrWhiteSpace(user) ? Context.ConnectionId : user;
|
|
await Groups.RemoveFromGroupAsync(connectionId, group.ToString());
|
|
logger.LogInformation($"{nameof(AddToGroup)}: {connectionId} joined to {group}");
|
|
}
|
|
|
|
public async Task Startstream(string clientId)
|
|
{
|
|
var client = Clients.Client(clientId);
|
|
|
|
await client.SendAsync("Start");
|
|
}
|
|
|
|
|
|
public async Task StopStream(string clientId)
|
|
{
|
|
var client = Clients.Client(clientId);
|
|
|
|
await client.SendAsync("Stop");
|
|
}
|
|
public Window okno = new Window("test");
|
|
public async Task UploadByteStream(IAsyncEnumerable<byte[]> stream)
|
|
{
|
|
|
|
await foreach (var frame in stream)
|
|
{
|
|
using var imgbuffer = frame.ConvertByteToMat();
|
|
okno.ShowImage(imgbuffer);
|
|
Cv2.WaitKey(1);
|
|
// logger.LogInformation($"Got frame size: {frame.Length} ");
|
|
// await Task.Delay(100); //leave some delay for debug purpose
|
|
}
|
|
}
|
|
}
|
|
} |