[WIP] live
This commit is contained in:
@ -1,7 +1,11 @@
|
|||||||
{
|
{
|
||||||
"Dnx": {
|
"Dnx": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"enablePackageRestore": true
|
"enablePackageRestore": true,
|
||||||
|
"projects": "**/project.json"
|
||||||
|
},
|
||||||
|
"MSBuild": {
|
||||||
|
"enabled": false
|
||||||
},
|
},
|
||||||
"DotNet": {
|
"DotNet": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
@ -12,4 +16,4 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"packages": "packages"
|
"packages": "packages"
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Claims;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.Mvc;
|
using Microsoft.AspNet.Mvc;
|
||||||
@ -59,12 +60,18 @@ namespace Yavsc.Controllers
|
|||||||
{
|
{
|
||||||
return HttpBadRequest();
|
return HttpBadRequest();
|
||||||
}
|
}
|
||||||
|
var uid = User.GetUserId();
|
||||||
|
if (liveFlow.OwnerId!=uid)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("id","This flow isn't yours.");
|
||||||
|
return HttpBadRequest(ModelState);
|
||||||
|
}
|
||||||
|
|
||||||
_context.Entry(liveFlow).State = EntityState.Modified;
|
_context.Entry(liveFlow).State = EntityState.Modified;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync(uid);
|
||||||
}
|
}
|
||||||
catch (DbUpdateConcurrencyException)
|
catch (DbUpdateConcurrencyException)
|
||||||
{
|
{
|
||||||
@ -89,11 +96,14 @@ namespace Yavsc.Controllers
|
|||||||
{
|
{
|
||||||
return HttpBadRequest(ModelState);
|
return HttpBadRequest(ModelState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var uid = User.GetUserId();
|
||||||
|
liveFlow.OwnerId=uid;
|
||||||
|
|
||||||
_context.LiveFlow.Add(liveFlow);
|
_context.LiveFlow.Add(liveFlow);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync(uid);
|
||||||
}
|
}
|
||||||
catch (DbUpdateException)
|
catch (DbUpdateException)
|
||||||
{
|
{
|
||||||
@ -125,8 +135,15 @@ namespace Yavsc.Controllers
|
|||||||
return HttpNotFound();
|
return HttpNotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var uid = User.GetUserId();
|
||||||
|
if (liveFlow.OwnerId!=uid)
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("id","This flow isn't yours.");
|
||||||
|
return HttpBadRequest(ModelState);
|
||||||
|
}
|
||||||
|
|
||||||
_context.LiveFlow.Remove(liveFlow);
|
_context.LiveFlow.Remove(liveFlow);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync(uid);
|
||||||
|
|
||||||
return Ok(liveFlow);
|
return Ok(liveFlow);
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
{"access_token":"ya29.GlyDBrrh_ZyJtCj2W3pnh0tog0FUHKB6P-QFERmbUsYLJlPE5mO10LuSNUTlxv61gbudXzCG_4PimrGyfvLkx2urB_EBJ67RFzoUKc3j6g9LQjxHXQQ3UMGxijZxAA","token_type":"Bearer","expires_in":3599,"Issued":"2018-12-31T01:43:26.641+00:00","IssuedUtc":"2018-12-31T01:43:26.641+00:00"}
|
{"access_token":"ya29.GlySBkpfPVO_8wPu2SD3xU8RuXawtuRapvkeoLJ6bLNclFoiXXm-v16bWrOwoDa-WyPKjq2t_1XqOGwzkA5k5uBaEe5e8_yjhFOTqIZ6YCw8kctvi7mY-YJ6tbdG9g","token_type":"Bearer","expires_in":3599,"Issued":"2019-01-15T15:53:04.583+00:00","IssuedUtc":"2019-01-15T15:53:04.583+00:00"}
|
@ -6,10 +6,10 @@ using System.Security.Claims;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Mvc;
|
using Microsoft.AspNet.Mvc;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Yavsc.ViewModels.Streaming;
|
using Yavsc.ViewModels.Streaming;
|
||||||
using Yavsc.Models;
|
using Yavsc.Models;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Yavsc.Controllers.Communicating
|
namespace Yavsc.Controllers.Communicating
|
||||||
{
|
{
|
||||||
@ -24,17 +24,15 @@ namespace Yavsc.Controllers.Communicating
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="loggerFactory"></param>
|
/// <param name="loggerFactory"></param>
|
||||||
/// <param name="dbContext"></param>
|
/// <param name="dbContext"></param>
|
||||||
public LiveController(LoggerFactory loggerFactory,
|
public LiveController(ILoggerFactory loggerFactory,
|
||||||
ApplicationDbContext dbContext)
|
ApplicationDbContext dbContext)
|
||||||
{
|
{
|
||||||
_logger = loggerFactory.CreateLogger<LiveController>();
|
_logger = loggerFactory.CreateLogger<LiveController>();
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("get/{?id}")]
|
|
||||||
public IActionResult Index(long? id)
|
public IActionResult Index(long? id)
|
||||||
{
|
{
|
||||||
if (id==null)
|
if (id==0)
|
||||||
return View("Index", Casters.Select(c=> new { UserName = c.Key, Listenning = c.Value.Listeners.Count }));
|
return View("Index", Casters.Select(c=> new { UserName = c.Key, Listenning = c.Value.Listeners.Count }));
|
||||||
|
|
||||||
var flow = _dbContext.LiveFlow.SingleOrDefault(f=>f.Id == id);
|
var flow = _dbContext.LiveFlow.SingleOrDefault(f=>f.Id == id);
|
||||||
@ -44,18 +42,37 @@ namespace Yavsc.Controllers.Communicating
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> Cast()
|
|
||||||
|
public async Task<IActionResult> GetLive(string id)
|
||||||
|
{
|
||||||
|
if (!HttpContext.WebSockets.IsWebSocketRequest) return new BadRequestResult();
|
||||||
|
var uid = User.GetUserId();
|
||||||
|
var existent = Casters[id];
|
||||||
|
var socket = await HttpContext.WebSockets.AcceptWebSocketAsync();
|
||||||
|
if (existent.Listeners.TryAdd(uid,socket)) {
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await socket.CloseAsync(WebSocketCloseStatus.EndpointUnavailable,"Listeners.TryAdd failed",CancellationToken.None);
|
||||||
|
}
|
||||||
|
return HttpBadRequest("Listeners.TryAdd returned false");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> Cast(long id)
|
||||||
{
|
{
|
||||||
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();
|
||||||
|
|
||||||
|
var uname = User.GetUserName();
|
||||||
// ensure uniqueness of casting stream from this user
|
// ensure uniqueness of casting stream from this user
|
||||||
var existent = Casters[uname];
|
var existent = Casters[uname];
|
||||||
if (existent != null) return new BadRequestObjectResult("not supported, you already casting, there's support for one live streaming only");
|
if (existent != null) return new BadRequestObjectResult("not supported, you already casting, there's support for one live streaming only");
|
||||||
|
var uid = User.GetUserId();
|
||||||
|
// get some setup from user
|
||||||
|
var flow = _dbContext.LiveFlow.SingleOrDefault(f=> (f.OwnerId==uid && f.Id == id));
|
||||||
|
// Accept the socket
|
||||||
var meta = new LiveCastMeta { Socket = await HttpContext.WebSockets.AcceptWebSocketAsync() };
|
var meta = new LiveCastMeta { Socket = await HttpContext.WebSockets.AcceptWebSocketAsync() };
|
||||||
|
// Dispatch the flow
|
||||||
using (meta.Socket)
|
using (meta.Socket)
|
||||||
{
|
{
|
||||||
if (meta.Socket != null && meta.Socket.State == WebSocketState.Open)
|
if (meta.Socket != null && meta.Socket.State == WebSocketState.Open)
|
||||||
|
@ -18,4 +18,5 @@ namespace Yavsc.ViewModels.Streaming
|
|||||||
public WebSocket Socket { get; set; }
|
public WebSocket Socket { get; set; }
|
||||||
public ConcurrentDictionary<string, WebSocket> Listeners { get; set; } = new ConcurrentDictionary<string, WebSocket>();
|
public ConcurrentDictionary<string, WebSocket> Listeners { get; set; } = new ConcurrentDictionary<string, WebSocket>();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
14
src/Yavsc/omnisharp.json
Normal file
14
src/Yavsc/omnisharp.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"Dnx": {
|
||||||
|
"enabled": true,
|
||||||
|
"enablePackageRestore": true,
|
||||||
|
"projects": "project.json"
|
||||||
|
},
|
||||||
|
"MSBuild": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"DotNet": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"packages": "../../packages"
|
||||||
|
}
|
14
src/omnisharp.json
Normal file
14
src/omnisharp.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"Dnx": {
|
||||||
|
"enabled": true,
|
||||||
|
"enablePackageRestore": true,
|
||||||
|
"projects": "**/project.json"
|
||||||
|
},
|
||||||
|
"MSBuild": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"DotNet": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"packages": "../packages"
|
||||||
|
}
|
Reference in New Issue
Block a user