65 lines
1.8 KiB
C#
65 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using OpenCvSharp;
|
|
using Squirrowse.Core.Models;
|
|
using Squirrowse.Core.Services;
|
|
|
|
namespace Squirrowse.Service.Hubs
|
|
{
|
|
public class StreamManager : IStreamManager
|
|
{
|
|
private readonly List<User> _users = new List<User>(); //temporary
|
|
public bool StreamOn { get; set; }
|
|
public Task AddUser(string connectionId, string userName, ConnectionType type)
|
|
{
|
|
_users.Add(new User(connectionId, userName, type));
|
|
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;
|
|
}
|
|
|
|
public IEnumerable<User> getServerSideUsers()
|
|
{
|
|
return _users.Where(user => user.UserType == ConnectionType.Server);
|
|
}
|
|
|
|
|
|
public IEnumerable<User> getClientSideUsers()
|
|
{
|
|
return _users.Where(user => user.UserType == ConnectionType.Client);
|
|
}
|
|
|
|
public bool CheckUser(string userName)
|
|
{
|
|
return _users.Any(user => user.AgentName == userName);
|
|
}
|
|
|
|
public IEnumerable<User> getAllUsers()
|
|
{
|
|
// var t = _users;
|
|
return _users;
|
|
}
|
|
|
|
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());
|
|
}
|
|
}
|
|
}
|
|
} |