|
|
|
@ -51,11 +51,11 @@ namespace Yavsc
|
|
|
|
|
public static string AvatarsDirName { private set; get; }
|
|
|
|
|
public static string GitDirName { private set; get; }
|
|
|
|
|
public static string Authority { get; private set; }
|
|
|
|
|
public static string Temp { get; set; }
|
|
|
|
|
public static string Temp { get; set; }
|
|
|
|
|
public static SiteSettings SiteSetup { get; private set; }
|
|
|
|
|
public static GoogleServiceAccount GServiceAccount { get; private set; }
|
|
|
|
|
|
|
|
|
|
public static string HostingFullName { get; set; }
|
|
|
|
|
public static string HostingFullName { get; set; }
|
|
|
|
|
|
|
|
|
|
public static PayPalSettings PayPalSettings { get; private set; }
|
|
|
|
|
private static ILogger logger;
|
|
|
|
@ -340,7 +340,8 @@ namespace Yavsc
|
|
|
|
|
{
|
|
|
|
|
var logenvvar = Environment.GetEnvironmentVariable("ASPNET_LOG_LEVEL");
|
|
|
|
|
if (logenvvar != null)
|
|
|
|
|
switch (logenvvar) {
|
|
|
|
|
switch (logenvvar)
|
|
|
|
|
{
|
|
|
|
|
case "info":
|
|
|
|
|
loggerFactory.MinimumLevel = LogLevel.Information;
|
|
|
|
|
break;
|
|
|
|
@ -413,7 +414,15 @@ namespace Yavsc
|
|
|
|
|
app.UseRequestLocalization(localizationOptions.Value, (RequestCulture)new RequestCulture((string)"en-US"));
|
|
|
|
|
|
|
|
|
|
ConfigureWorkflow(app, SiteSetup, logger);
|
|
|
|
|
// Empty this odd chat user list from db
|
|
|
|
|
foreach (var p in dbContext.ChatConnection)
|
|
|
|
|
{
|
|
|
|
|
dbContext.Entry(p).State = EntityState.Deleted;
|
|
|
|
|
}
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
|
|
|
|
ConfigureWebSocketsApp(app, SiteSetup, env);
|
|
|
|
|
|
|
|
|
|
app.UseMvc(routes =>
|
|
|
|
|
{
|
|
|
|
|
routes.MapRoute(
|
|
|
|
@ -432,7 +441,8 @@ namespace Yavsc
|
|
|
|
|
{
|
|
|
|
|
if (!context.User.Identity.IsAuthenticated)
|
|
|
|
|
context.Response.StatusCode = 403;
|
|
|
|
|
else {
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// get the flow id from request path
|
|
|
|
|
var castid = long.Parse(context.Request.Path.Value.Substring(liveCastingPath.Value.Length + 1));
|
|
|
|
|
|
|
|
|
@ -448,16 +458,20 @@ namespace Yavsc
|
|
|
|
|
{
|
|
|
|
|
context.Response.StatusCode = 400;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LiveCastMeta meta = null;
|
|
|
|
|
if (LiveApiController.Casters.ContainsKey(uname))
|
|
|
|
|
{
|
|
|
|
|
meta = LiveApiController.Casters[uname];
|
|
|
|
|
if (meta.Socket.State != WebSocketState.Closed) {
|
|
|
|
|
if (meta.Socket.State != WebSocketState.Closed)
|
|
|
|
|
{
|
|
|
|
|
// FIXME loosed connexion should be detected & disposed else where
|
|
|
|
|
meta.Socket.Dispose();
|
|
|
|
|
meta.Socket = await context.WebSockets.AcceptWebSocketAsync();
|
|
|
|
|
} else {
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
meta.Socket.Dispose();
|
|
|
|
|
// Accept the socket
|
|
|
|
|
meta.Socket = await context.WebSockets.AcceptWebSocketAsync();
|
|
|
|
@ -470,7 +484,8 @@ namespace Yavsc
|
|
|
|
|
}
|
|
|
|
|
logger.LogInformation("Accepted web socket");
|
|
|
|
|
// Dispatch the flow
|
|
|
|
|
try {
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -489,13 +504,20 @@ namespace Yavsc
|
|
|
|
|
|
|
|
|
|
var hubContext = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();
|
|
|
|
|
|
|
|
|
|
hubContext.Clients.All.addPublicStream(new { id = flow.Id, sender = flow.Owner.UserName, title = flow.Title, url = flow.GetFileUrl(),
|
|
|
|
|
mediaType = flow.MediaType }, $"{flow.Owner.UserName} is starting a stream!");
|
|
|
|
|
hubContext.Clients.All.addPublicStream(new
|
|
|
|
|
{
|
|
|
|
|
id = flow.Id,
|
|
|
|
|
sender = flow.Owner.UserName,
|
|
|
|
|
title = flow.Title,
|
|
|
|
|
url = flow.GetFileUrl(),
|
|
|
|
|
mediaType = flow.MediaType
|
|
|
|
|
}, $"{flow.Owner.UserName} is starting a stream!");
|
|
|
|
|
|
|
|
|
|
// FIXME do we really need to close those one in invalid state ?
|
|
|
|
|
Stack<string> ToClose = new Stack<string>();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
while (received.MessageType != WebSocketMessageType.Close)
|
|
|
|
|
{
|
|
|
|
|
logger.LogInformation($"Echoing {received.Count} bytes received in a {received.MessageType} message; Fin={received.EndOfMessage}");
|
|
|
|
@ -527,7 +549,8 @@ namespace Yavsc
|
|
|
|
|
}
|
|
|
|
|
await meta.Socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "eof", CancellationToken.None);
|
|
|
|
|
LiveApiController.Casters[uname] = null;
|
|
|
|
|
} catch (Exception ex)
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger.LogError($"Exception occured : {ex.Message}");
|
|
|
|
|
logger.LogError(ex.StackTrace);
|
|
|
|
@ -535,8 +558,10 @@ namespace Yavsc
|
|
|
|
|
LiveApiController.Casters[uname] = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else { // not meta.Socket != null && meta.Socket.State == WebSocketState.Open
|
|
|
|
|
if (meta.Socket != null) {
|
|
|
|
|
else
|
|
|
|
|
{ // not meta.Socket != null && meta.Socket.State == WebSocketState.Open
|
|
|
|
|
if (meta.Socket != null)
|
|
|
|
|
{
|
|
|
|
|
logger.LogError($"meta.Socket.State not Open: {meta.Socket.State.ToString()} ");
|
|
|
|
|
meta.Socket.Dispose();
|
|
|
|
|
}
|
|
|
|
@ -550,14 +575,18 @@ namespace Yavsc
|
|
|
|
|
{
|
|
|
|
|
logger.LogError($"Unexpected end of stream");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.LogError($"Really unexpected end of stream");
|
|
|
|
|
}
|
|
|
|
|
await meta.Socket?.CloseAsync(WebSocketCloseStatus.EndpointUnavailable, ex.Message, CancellationToken.None);
|
|
|
|
|
meta.Socket?.Dispose();
|
|
|
|
|
LiveApiController.Casters[uname] = null;
|
|
|
|
|
}
|
|
|
|
|
}}}}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await next();
|
|
|
|
|