2019-11-12 16:47:20 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-11-05 17:00:36 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-11-12 16:47:20 +01:00
|
|
|
|
using OpenCvSharp;
|
2019-11-05 17:00:36 +01:00
|
|
|
|
using Squirrowse.Core.Models;
|
2019-11-12 16:47:20 +01:00
|
|
|
|
using Squirrowse.Core.Services;
|
2019-11-05 17:00:36 +01:00
|
|
|
|
|
|
|
|
|
namespace Squirrowse.Service.Hubs
|
|
|
|
|
{
|
|
|
|
|
public class StreamManager : IStreamManager
|
|
|
|
|
{
|
2019-11-07 11:52:27 +01:00
|
|
|
|
private readonly List<User> _users = new List<User>(); //temporary
|
2019-11-12 16:47:20 +01:00
|
|
|
|
public bool StreamOn { get; set; }
|
2019-11-07 11:52:27 +01:00
|
|
|
|
public Task AddUser(string connectionId, string userName, ConnectionType type)
|
2019-11-05 17:00:36 +01:00
|
|
|
|
{
|
2019-11-07 11:52:27 +01:00
|
|
|
|
_users.Add(new User(connectionId, userName, type));
|
2019-11-05 17:00:36 +01:00
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task RemoveUserbyConnectionId(string connectionId)
|
|
|
|
|
{
|
|
|
|
|
_users.Remove(_users.First(user => user.ConnectionId == connectionId));
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task RemoveUserByUserName(string userName)
|
|
|
|
|
{
|
|
|
|
|
_users.RemoveAll(user => user.AgentName == userName);
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-06 17:02:06 +01:00
|
|
|
|
public IEnumerable<User> getServerSideUsers()
|
|
|
|
|
{
|
|
|
|
|
return _users.Where(user => user.UserType == ConnectionType.Server);
|
|
|
|
|
}
|
2019-11-07 11:52:27 +01:00
|
|
|
|
|
2019-11-12 16:47:20 +01:00
|
|
|
|
|
2019-11-06 19:17:06 +01:00
|
|
|
|
public IEnumerable<User> getClientSideUsers()
|
|
|
|
|
{
|
|
|
|
|
return _users.Where(user => user.UserType == ConnectionType.Client);
|
|
|
|
|
}
|
2019-11-07 11:52:27 +01:00
|
|
|
|
|
2019-11-05 17:00:36 +01:00
|
|
|
|
public bool CheckUser(string userName)
|
|
|
|
|
{
|
|
|
|
|
return _users.Any(user => user.AgentName == userName);
|
|
|
|
|
}
|
2019-11-06 19:17:06 +01:00
|
|
|
|
|
|
|
|
|
public IEnumerable<User> getAllUsers()
|
|
|
|
|
{
|
2019-11-16 13:07:20 +01:00
|
|
|
|
// var t = _users;
|
2019-11-06 19:17:06 +01:00
|
|
|
|
return _users;
|
|
|
|
|
}
|
2019-11-12 16:47:20 +01:00
|
|
|
|
|
|
|
|
|
public async Task SaveData(IAsyncEnumerable<byte[]> stream)
|
|
|
|
|
{
|
|
|
|
|
VideoWriter output = new VideoWriter("m.avi",FourCC.DIVX,30,new Size(640,480));
|
|
|
|
|
|
|
|
|
|
await foreach (var b in stream)
|
|
|
|
|
{
|
|
|
|
|
output.Write(b.ConvertByteToMat());
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-05 17:00:36 +01:00
|
|
|
|
}
|
|
|
|
|
}
|