an index method

This commit is contained in:
2019-01-10 12:30:05 +00:00
parent b40a1889a9
commit 4a86694209

View File

@ -8,21 +8,47 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Yavsc.ViewModels.Streaming; using Yavsc.ViewModels.Streaming;
using Yavsc.Models;
using System.Linq;
namespace Yavsc.Controllers.Communicating namespace Yavsc.Controllers.Communicating
{ {
public class LiveController : Controller public class LiveController : Controller
{ {
ILogger _logger; ILogger _logger;
ApplicationDbContext _dbContext;
public static ConcurrentDictionary<string, LiveCastMeta> Casters = new ConcurrentDictionary<string, LiveCastMeta>(); public static ConcurrentDictionary<string, LiveCastMeta> Casters = new ConcurrentDictionary<string, LiveCastMeta>();
public LiveController(LoggerFactory loggerFactory)
/// <summary>
/// Controls the live !!!
/// </summary>
/// <param name="loggerFactory"></param>
/// <param name="dbContext"></param>
public LiveController(LoggerFactory loggerFactory,
ApplicationDbContext dbContext)
{ {
_logger = loggerFactory.CreateLogger<LiveController>(); _logger = loggerFactory.CreateLogger<LiveController>();
_dbContext = dbContext;
}
[Route("get/{?id}")]
public IActionResult Index(long? id)
{
if (id==null)
return View("Index", Casters.Select(c=> new { UserName = c.Key, Listenning = c.Value.Listeners.Count }));
var flow = _dbContext.LiveFlow.SingleOrDefault(f=>f.Id == id);
if (flow == null) return HttpNotFound();
return View("Flow", flow);
} }
public async Task<IActionResult> Cast() public async Task<IActionResult> Cast()
{ {
var uname = User.GetUserName(); var uname = User.GetUserName();
// get some setup from user
// ensure this request is for a websocket // ensure this request is for a websocket
if (!HttpContext.WebSockets.IsWebSocketRequest) return new BadRequestResult(); if (!HttpContext.WebSockets.IsWebSocketRequest) return new BadRequestResult();
// ensure uniqueness of casting stream from this user // ensure uniqueness of casting stream from this user