diff --git a/omnisharp.json b/omnisharp.json
index df0a93ff..5c7db117 100644
--- a/omnisharp.json
+++ b/omnisharp.json
@@ -1,7 +1,11 @@
{
"Dnx": {
"enabled": true,
- "enablePackageRestore": true
+ "enablePackageRestore": true,
+ "projects": "**/project.json"
+ },
+ "MSBuild": {
+ "enabled": false
},
"DotNet": {
"enabled": false,
@@ -12,4 +16,4 @@
}
},
"packages": "packages"
-}
+}
\ No newline at end of file
diff --git a/src/Yavsc/ApiControllers/LiveApiController.cs b/src/Yavsc/ApiControllers/LiveApiController.cs
index aa2b041b..365fe043 100644
--- a/src/Yavsc/ApiControllers/LiveApiController.cs
+++ b/src/Yavsc/ApiControllers/LiveApiController.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
+using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc;
@@ -59,12 +60,18 @@ namespace Yavsc.Controllers
{
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;
try
{
- await _context.SaveChangesAsync();
+ await _context.SaveChangesAsync(uid);
}
catch (DbUpdateConcurrencyException)
{
@@ -89,11 +96,14 @@ namespace Yavsc.Controllers
{
return HttpBadRequest(ModelState);
}
+
+ var uid = User.GetUserId();
+ liveFlow.OwnerId=uid;
_context.LiveFlow.Add(liveFlow);
try
{
- await _context.SaveChangesAsync();
+ await _context.SaveChangesAsync(uid);
}
catch (DbUpdateException)
{
@@ -125,8 +135,15 @@ namespace Yavsc.Controllers
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);
- await _context.SaveChangesAsync();
+ await _context.SaveChangesAsync(uid);
return Ok(liveFlow);
}
diff --git a/src/Yavsc/AppDataDevelopment/googledatastore/Google.Apis.Auth.OAuth2.Responses.TokenResponse-111395572362177872801 b/src/Yavsc/AppDataDevelopment/googledatastore/Google.Apis.Auth.OAuth2.Responses.TokenResponse-111395572362177872801
index 3ee6846a..3154cb98 100644
--- a/src/Yavsc/AppDataDevelopment/googledatastore/Google.Apis.Auth.OAuth2.Responses.TokenResponse-111395572362177872801
+++ b/src/Yavsc/AppDataDevelopment/googledatastore/Google.Apis.Auth.OAuth2.Responses.TokenResponse-111395572362177872801
@@ -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"}
\ No newline at end of file
+{"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"}
\ No newline at end of file
diff --git a/src/Yavsc/Controllers/Communicating/LiveController.cs b/src/Yavsc/Controllers/Communicating/LiveController.cs
index 0b380044..1c051912 100644
--- a/src/Yavsc/Controllers/Communicating/LiveController.cs
+++ b/src/Yavsc/Controllers/Communicating/LiveController.cs
@@ -6,10 +6,10 @@ using System.Security.Claims;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
-using Microsoft.Extensions.Logging;
using Yavsc.ViewModels.Streaming;
using Yavsc.Models;
using System.Linq;
+using Microsoft.Extensions.Logging;
namespace Yavsc.Controllers.Communicating
{
@@ -24,17 +24,15 @@ namespace Yavsc.Controllers.Communicating
///
///
///
- public LiveController(LoggerFactory loggerFactory,
+ public LiveController(ILoggerFactory loggerFactory,
ApplicationDbContext dbContext)
{
_logger = loggerFactory.CreateLogger();
_dbContext = dbContext;
}
-
- [Route("get/{?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 }));
var flow = _dbContext.LiveFlow.SingleOrDefault(f=>f.Id == id);
@@ -44,18 +42,37 @@ namespace Yavsc.Controllers.Communicating
}
- public async Task Cast()
+
+ public async Task 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 Cast(long id)
{
- var uname = User.GetUserName();
- // get some setup from user
-
// ensure this request is for a websocket
if (!HttpContext.WebSockets.IsWebSocketRequest) return new BadRequestResult();
+
+ var uname = User.GetUserName();
// ensure uniqueness of casting stream from this user
var existent = Casters[uname];
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() };
-
+ // Dispatch the flow
using (meta.Socket)
{
if (meta.Socket != null && meta.Socket.State == WebSocketState.Open)
diff --git a/src/Yavsc/ViewModels/Streaming/LiveCastMeta.cs b/src/Yavsc/ViewModels/Streaming/LiveCastMeta.cs
index 79e4b483..254af1e3 100644
--- a/src/Yavsc/ViewModels/Streaming/LiveCastMeta.cs
+++ b/src/Yavsc/ViewModels/Streaming/LiveCastMeta.cs
@@ -18,4 +18,5 @@ namespace Yavsc.ViewModels.Streaming
public WebSocket Socket { get; set; }
public ConcurrentDictionary Listeners { get; set; } = new ConcurrentDictionary();
}
+
}
\ No newline at end of file
diff --git a/src/Yavsc/omnisharp.json b/src/Yavsc/omnisharp.json
new file mode 100644
index 00000000..9960b2ee
--- /dev/null
+++ b/src/Yavsc/omnisharp.json
@@ -0,0 +1,14 @@
+{
+ "Dnx": {
+ "enabled": true,
+ "enablePackageRestore": true,
+ "projects": "project.json"
+ },
+ "MSBuild": {
+ "enabled": false
+ },
+ "DotNet": {
+ "enabled": false
+ },
+ "packages": "../../packages"
+}
diff --git a/src/omnisharp.json b/src/omnisharp.json
new file mode 100644
index 00000000..d13209ea
--- /dev/null
+++ b/src/omnisharp.json
@@ -0,0 +1,14 @@
+{
+ "Dnx": {
+ "enabled": true,
+ "enablePackageRestore": true,
+ "projects": "**/project.json"
+ },
+ "MSBuild": {
+ "enabled": false
+ },
+ "DotNet": {
+ "enabled": false
+ },
+ "packages": "../packages"
+}