From 4a866942093ee092a0105b40dac6a546225f7c47 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Thu, 10 Jan 2019 12:30:05 +0000 Subject: [PATCH] an index method --- .../Communicating/LiveController.cs | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Yavsc/Controllers/Communicating/LiveController.cs b/src/Yavsc/Controllers/Communicating/LiveController.cs index bd1e7300..0b380044 100644 --- a/src/Yavsc/Controllers/Communicating/LiveController.cs +++ b/src/Yavsc/Controllers/Communicating/LiveController.cs @@ -8,21 +8,47 @@ using System.Threading.Tasks; using Microsoft.AspNet.Mvc; using Microsoft.Extensions.Logging; using Yavsc.ViewModels.Streaming; +using Yavsc.Models; +using System.Linq; namespace Yavsc.Controllers.Communicating { public class LiveController : Controller { ILogger _logger; + ApplicationDbContext _dbContext; public static ConcurrentDictionary Casters = new ConcurrentDictionary(); - public LiveController(LoggerFactory loggerFactory) + + /// + /// Controls the live !!! + /// + /// + /// + public LiveController(LoggerFactory loggerFactory, + ApplicationDbContext dbContext) { _logger = loggerFactory.CreateLogger(); + _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 Cast() { var uname = User.GetUserName(); + // get some setup from user + // ensure this request is for a websocket if (!HttpContext.WebSockets.IsWebSocketRequest) return new BadRequestResult(); // ensure uniqueness of casting stream from this user