chat rooms join simplification

vnext
Paul Schneider 5 years ago
parent 024f920812
commit dbafacefca
7 changed files with 211 additions and 183 deletions

@ -189,7 +189,7 @@ namespace Yavsc
public string Topic; public string Topic;
} }
public void Join(string roomName) public ChatRoomInfo Join(string roomName)
{ {
_logger.LogInformation("a client for " + roomName); _logger.LogInformation("a client for " + roomName);
var userName = ChatUserNames[Context.ConnectionId]; var userName = ChatUserNames[Context.ConnectionId];
@ -214,13 +214,13 @@ namespace Yavsc
Clients.Group("room_" + roomName).notify(NotificationTypes.UserJoin, Context.ConnectionId, Clients.Caller.UserName); Clients.Group("room_" + roomName).notify(NotificationTypes.UserJoin, Context.ConnectionId, Clients.Caller.UserName);
_logger.LogInformation("exiting ok."); _logger.LogInformation("exiting ok.");
return; return chanInfo;
} }
else else
{ {
_logger.LogInformation("room seemd to be avaible ... but we could get no info on it."); _logger.LogInformation("room seemd to be avaible ... but we could get no info on it.");
Clients.Caller.notify(NotificationTypes.Error, "join get chan failed ..."); Clients.Caller.notify(NotificationTypes.Error, "join get chan failed ...");
return; return null;
} }
} }
// chan was almost empty // chan was almost empty
@ -247,9 +247,10 @@ namespace Yavsc
if (Channels.TryAdd(roomName, chanInfo)) if (Channels.TryAdd(roomName, chanInfo))
{ {
Groups.Add(Context.ConnectionId, roomGroupName); Groups.Add(Context.ConnectionId, roomGroupName);
Clients.Caller.onJoined(chanInfo); return(chanInfo);
} }
else _logger.LogError("Chan create failed unexpectly..."); else _logger.LogError("Chan create failed unexpectly...");
return null;
} }
[Authorize] [Authorize]

@ -1,7 +1,6 @@
using System; using System;
using Microsoft.Data.Entity; using Microsoft.Data.Entity;
using Microsoft.Data.Entity.Infrastructure; using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Metadata;
using Microsoft.Data.Entity.Migrations; using Microsoft.Data.Entity.Migrations;
using Yavsc.Models; using Yavsc.Models;

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using Microsoft.Data.Entity.Migrations; using Microsoft.Data.Entity.Migrations;
namespace Yavsc.Migrations namespace Yavsc.Migrations

@ -1,8 +1,6 @@
using System; using System;
using Microsoft.Data.Entity; using Microsoft.Data.Entity;
using Microsoft.Data.Entity.Infrastructure; using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Metadata;
using Microsoft.Data.Entity.Migrations;
using Yavsc.Models; using Yavsc.Models;
namespace Yavsc.Migrations namespace Yavsc.Migrations

@ -258,7 +258,9 @@ namespace Yavsc.Models
public DbSet<Announce> Announce { get; set; } public DbSet<Announce> Announce { get; set; }
// TODO useless, to drop // TODO remove and opt for for memory only storing,
// as long as it must be set empty each time the service is restarted,
// and that chatting should be kept as must as possible independent from db context
public DbSet<ChatConnection> ChatConnection { get; set; } public DbSet<ChatConnection> ChatConnection { get; set; }
public DbSet<ChatRoom> ChatRoom { get; set; } public DbSet<ChatRoom> ChatRoom { get; set; }

@ -51,11 +51,11 @@ namespace Yavsc
public static string AvatarsDirName { private set; get; } public static string AvatarsDirName { private set; get; }
public static string GitDirName { private set; get; } public static string GitDirName { private set; get; }
public static string Authority { get; private set; } 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 SiteSettings SiteSetup { get; private set; }
public static GoogleServiceAccount GServiceAccount { 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; } public static PayPalSettings PayPalSettings { get; private set; }
private static ILogger logger; private static ILogger logger;
@ -66,9 +66,9 @@ namespace Yavsc
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{ {
var devtag = env.IsDevelopment()?"D":""; var devtag = env.IsDevelopment() ? "D" : "";
var prodtag = env.IsProduction()?"P":""; var prodtag = env.IsProduction() ? "P" : "";
var stagetag = env.IsStaging()?"S":""; var stagetag = env.IsStaging() ? "S" : "";
HostingFullName = $"{appEnv.RuntimeFramework.FullName} [{env.EnvironmentName}:{prodtag}{devtag}{stagetag}]"; HostingFullName = $"{appEnv.RuntimeFramework.FullName} [{env.EnvironmentName}:{prodtag}{devtag}{stagetag}]";
// Set up configuration sources. // Set up configuration sources.
@ -87,22 +87,22 @@ namespace Yavsc
builder.AddEnvironmentVariables(); builder.AddEnvironmentVariables();
Configuration = builder.Build(); Configuration = builder.Build();
var auth = Configuration["Site:Authority"]; var auth = Configuration["Site:Authority"];
var cxstr = Configuration["ConnectionStrings:Default"]; var cxstr = Configuration["ConnectionStrings:Default"];
ConnectionString = cxstr; ConnectionString = cxstr;
AppDomain.CurrentDomain.SetData(Constants.YavscConnectionStringEnvName, ConnectionString); AppDomain.CurrentDomain.SetData(Constants.YavscConnectionStringEnvName, ConnectionString);
var googleClientFile = Configuration["Authentication:Google:GoogleWebClientJson"]; var googleClientFile = Configuration["Authentication:Google:GoogleWebClientJson"];
var googleServiceAccountJsonFile = Configuration["Authentication:Google:GoogleServiceAccountJson"]; var googleServiceAccountJsonFile = Configuration["Authentication:Google:GoogleServiceAccountJson"];
if (googleClientFile!=null) if (googleClientFile != null)
GoogleWebClientConfiguration = new ConfigurationBuilder().AddJsonFile(googleClientFile).Build(); GoogleWebClientConfiguration = new ConfigurationBuilder().AddJsonFile(googleClientFile).Build();
if (googleServiceAccountJsonFile!=null) if (googleServiceAccountJsonFile != null)
{ {
var safile = new FileInfo(googleServiceAccountJsonFile); var safile = new FileInfo(googleServiceAccountJsonFile);
GServiceAccount = JsonConvert.DeserializeObject<GoogleServiceAccount>(safile.OpenText().ReadToEnd()); GServiceAccount = JsonConvert.DeserializeObject<GoogleServiceAccount>(safile.OpenText().ReadToEnd());
} }
} }
public static string ConnectionString { get; set; } public static string ConnectionString { get; set; }
@ -115,7 +115,7 @@ namespace Yavsc
{ {
// Database connection // Database connection
services.AddOptions(); services.AddOptions();
var siteSettings = Configuration.GetSection("Site"); var siteSettings = Configuration.GetSection("Site");
services.Configure<SiteSettings>(siteSettings); services.Configure<SiteSettings>(siteSettings);
@ -135,7 +135,7 @@ namespace Yavsc
services.Add(ServiceDescriptor.Singleton(typeof(IOptions<GoogleAuthSettings>), typeof(OptionsManager<GoogleAuthSettings>))); services.Add(ServiceDescriptor.Singleton(typeof(IOptions<GoogleAuthSettings>), typeof(OptionsManager<GoogleAuthSettings>)));
services.Add(ServiceDescriptor.Singleton(typeof(IOptions<CompanyInfoSettings>), typeof(OptionsManager<CompanyInfoSettings>))); services.Add(ServiceDescriptor.Singleton(typeof(IOptions<CompanyInfoSettings>), typeof(OptionsManager<CompanyInfoSettings>)));
services.Add(ServiceDescriptor.Singleton(typeof(IOptions<RequestLocalizationOptions>), typeof(OptionsManager<RequestLocalizationOptions>))); services.Add(ServiceDescriptor.Singleton(typeof(IOptions<RequestLocalizationOptions>), typeof(OptionsManager<RequestLocalizationOptions>)));
services.Configure<RequestLocalizationOptions>(options => services.Configure<RequestLocalizationOptions>(options =>
{ {
var supportedCultures = new[] var supportedCultures = new[]
@ -144,7 +144,7 @@ namespace Yavsc
new CultureInfo("fr"), new CultureInfo("fr"),
new CultureInfo("pt") new CultureInfo("pt")
}; };
var supportedUICultures = new[] var supportedUICultures = new[]
{ {
new CultureInfo("fr"), new CultureInfo("fr"),
@ -184,14 +184,14 @@ namespace Yavsc
// DataProtection // DataProtection
ConfigureProtectionServices(services); ConfigureProtectionServices(services);
// Add framework services. // Add framework services.
services.AddEntityFramework() services.AddEntityFramework()
.AddNpgsql() .AddNpgsql()
.AddDbContext<ApplicationDbContext>( .AddDbContext<ApplicationDbContext>(
db => db.UseNpgsql(ConnectionString) db => db.UseNpgsql(ConnectionString)
); );
ConfigureOAuthServices(services); ConfigureOAuthServices(services);
services.AddCors( services.AddCors(
@ -248,8 +248,8 @@ namespace Yavsc
.Build(); .Build();
config.Filters.Add(new AuthorizeFilter(policy)); config.Filters.Add(new AuthorizeFilter(policy));
config.Filters.Add(new ProducesAttribute("application/json")); config.Filters.Add(new ProducesAttribute("application/json"));
// config.ModelBinders.Insert(0,new MyDateTimeModelBinder()); // config.ModelBinders.Insert(0,new MyDateTimeModelBinder());
// config.ModelBinders.Insert(0,new MyDecimalModelBinder()); // config.ModelBinders.Insert(0,new MyDecimalModelBinder());
config.OutputFormatters.Add(new PdfFormatter()); config.OutputFormatters.Add(new PdfFormatter());
}).AddFormatterMappings( }).AddFormatterMappings(
@ -276,9 +276,9 @@ namespace Yavsc
services.AddTransient<IEmailSender, MailSender>(); services.AddTransient<IEmailSender, MailSender>();
services.AddTransient<IYavscMessageSender, YavscMessageSender>(); services.AddTransient<IYavscMessageSender, YavscMessageSender>();
services.AddTransient<IBillingService, BillingService>(); services.AddTransient<IBillingService, BillingService>();
services.AddTransient<IDataStore, FileDataStore>( (sp) => new FileDataStore("googledatastore",false) ); services.AddTransient<IDataStore, FileDataStore>((sp) => new FileDataStore("googledatastore", false));
services.AddTransient<ICalendarManager, CalendarManager>(); services.AddTransient<ICalendarManager, CalendarManager>();
// TODO for SMS: services.AddTransient<ISmsSender, AuthMessageSender>(); // TODO for SMS: services.AddTransient<ISmsSender, AuthMessageSender>();
services.AddLocalization(options => services.AddLocalization(options =>
@ -312,12 +312,12 @@ namespace Yavsc
SiteSetup = siteSettings.Value; SiteSetup = siteSettings.Value;
Authority = siteSettings.Value.Authority; Authority = siteSettings.Value.Authority;
var blogsDir = siteSettings.Value.Blog; var blogsDir = siteSettings.Value.Blog;
if (blogsDir==null) throw new Exception ("blogsDir is not set."); if (blogsDir == null) throw new Exception("blogsDir is not set.");
var billsDir = siteSettings.Value.Bills; var billsDir = siteSettings.Value.Bills;
if (billsDir==null) throw new Exception ("billsDir is not set."); if (billsDir == null) throw new Exception("billsDir is not set.");
AbstractFileSystemHelpers.UserFilesDirName = new DirectoryInfo(blogsDir).FullName; AbstractFileSystemHelpers.UserFilesDirName = new DirectoryInfo(blogsDir).FullName;
AbstractFileSystemHelpers.UserBillsDirName = new DirectoryInfo(billsDir).FullName; AbstractFileSystemHelpers.UserBillsDirName = new DirectoryInfo(billsDir).FullName;
Temp = siteSettings.Value.TempDir; Temp = siteSettings.Value.TempDir;
PayPalSettings = payPalSettings.Value; PayPalSettings = payPalSettings.Value;
@ -325,7 +325,7 @@ namespace Yavsc
// Create required directories // Create required directories
foreach (string dir in new string[] { AbstractFileSystemHelpers.UserFilesDirName, AbstractFileSystemHelpers.UserBillsDirName, SiteSetup.TempDir }) foreach (string dir in new string[] { AbstractFileSystemHelpers.UserFilesDirName, AbstractFileSystemHelpers.UserBillsDirName, SiteSetup.TempDir })
{ {
if (dir==null) throw new Exception (nameof(dir)); if (dir == null) throw new Exception(nameof(dir));
DirectoryInfo di = new DirectoryInfo(dir); DirectoryInfo di = new DirectoryInfo(dir);
if (!di.Exists) di.Create(); if (!di.Exists) di.Create();
@ -339,22 +339,23 @@ namespace Yavsc
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
var logenvvar = Environment.GetEnvironmentVariable("ASPNET_LOG_LEVEL"); var logenvvar = Environment.GetEnvironmentVariable("ASPNET_LOG_LEVEL");
if (logenvvar!=null) if (logenvvar != null)
switch (logenvvar) { switch (logenvvar)
case "info": {
loggerFactory.MinimumLevel = LogLevel.Information; case "info":
break; loggerFactory.MinimumLevel = LogLevel.Information;
case "warn": break;
loggerFactory.MinimumLevel = LogLevel.Warning; case "warn":
break; loggerFactory.MinimumLevel = LogLevel.Warning;
case "err": break;
loggerFactory.MinimumLevel = LogLevel.Error; case "err":
break; loggerFactory.MinimumLevel = LogLevel.Error;
case "debug": break;
default: case "debug":
loggerFactory.MinimumLevel = LogLevel.Debug; default:
break; loggerFactory.MinimumLevel = LogLevel.Debug;
} break;
}
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
@ -399,28 +400,36 @@ namespace Yavsc
// before fixing the security protocol, let beleive our lib it's done with it. // before fixing the security protocol, let beleive our lib it's done with it.
var cxmgr = ConnectionManager.Instance; var cxmgr = ConnectionManager.Instance;
// then, fix it. // then, fix it.
ServicePointManager.SecurityProtocol = (SecurityProtocolType) 0xC00; // Tls12, required by PayPal ServicePointManager.SecurityProtocol = (SecurityProtocolType)0xC00; // Tls12, required by PayPal
app.UseIISPlatformHandler(options => app.UseIISPlatformHandler(options =>
{ {
options.AuthenticationDescriptions.Clear(); options.AuthenticationDescriptions.Clear();
options.AutomaticAuthentication = false; options.AutomaticAuthentication = false;
}); });
app.UseSession(); app.UseSession();
ConfigureOAuthApp(app, SiteSetup, logger); ConfigureOAuthApp(app, SiteSetup, logger);
ConfigureFileServerApp(app, SiteSetup, env, authorizationService); ConfigureFileServerApp(app, SiteSetup, env, authorizationService);
app.UseRequestLocalization(localizationOptions.Value, (RequestCulture) new RequestCulture((string)"en-US")); app.UseRequestLocalization(localizationOptions.Value, (RequestCulture)new RequestCulture((string)"en-US"));
ConfigureWorkflow(app, SiteSetup, logger); 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); ConfigureWebSocketsApp(app, SiteSetup, env);
app.UseMvc(routes => app.UseMvc(routes =>
{ {
routes.MapRoute( routes.MapRoute(
name: "default", name: "default",
template: "{controller=Home}/{action=Index}/{id?}"); template: "{controller=Home}/{action=Index}/{id?}");
}); });
logger.LogInformation("LocalApplicationData: "+Environment.GetFolderPath(SpecialFolder.LocalApplicationData, SpecialFolderOption.DoNotVerify)); logger.LogInformation("LocalApplicationData: " + Environment.GetFolderPath(SpecialFolder.LocalApplicationData, SpecialFolderOption.DoNotVerify));
app.Use(async (context, next) => app.Use(async (context, next) =>
{ {
var liveCasting = context.Request.Path.StartsWithSegments(liveCastingPath); var liveCasting = context.Request.Path.StartsWithSegments(liveCastingPath);
@ -432,132 +441,152 @@ namespace Yavsc
{ {
if (!context.User.Identity.IsAuthenticated) if (!context.User.Identity.IsAuthenticated)
context.Response.StatusCode = 403; context.Response.StatusCode = 403;
else { else
{
// get the flow id from request path // get the flow id from request path
var castid = long.Parse(context.Request.Path.Value.Substring(liveCastingPath.Value.Length+1)); var castid = long.Parse(context.Request.Path.Value.Substring(liveCastingPath.Value.Length + 1));
var uname = context.User.GetUserName();
// ensure uniqueness of casting stream from this user
var uid = context.User.GetUserId();
// get some setup from user
var flow = _dbContext.LiveFlow.Include(f=>f.Owner).SingleOrDefault(f=> (f.OwnerId==uid && f.Id == castid));
if (flow == null)
{
context.Response.StatusCode = 400;
}
else {
LiveCastMeta meta=null;
if (LiveApiController.Casters.ContainsKey(uname))
{
meta = LiveApiController.Casters[uname];
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 {
meta.Socket.Dispose();
// Accept the socket
meta.Socket = await context.WebSockets.AcceptWebSocketAsync();
}
}
else
{
// Accept the socket
meta = new LiveCastMeta { Socket = await context.WebSockets.AcceptWebSocketAsync() };
}
logger.LogInformation("Accepted web socket");
// Dispatch the flow
try {
var uname = context.User.GetUserName();
if (meta.Socket != null && meta.Socket.State == WebSocketState.Open) // ensure uniqueness of casting stream from this user
{
LiveApiController.Casters[uname] = meta;
// TODO: Handle the socket here. var uid = context.User.GetUserId();
// Find receivers: others in the chat room // get some setup from user
// send them the flow var flow = _dbContext.LiveFlow.Include(f => f.Owner).SingleOrDefault(f => (f.OwnerId == uid && f.Id == castid));
if (flow == null)
var sBuffer = new ArraySegment<byte>(new byte[1024]);
logger.LogInformation("Receiving bytes...");
WebSocketReceiveResult received = await meta.Socket.ReceiveAsync(sBuffer, CancellationToken.None);
logger.LogInformation("Received bytes!!!!");
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!");
// FIXME do we really need to close those one in invalid state ?
Stack<string> ToClose = new Stack<string>();
try {
while (received.MessageType != WebSocketMessageType.Close)
{
logger.LogInformation($"Echoing {received.Count} bytes received in a {received.MessageType} message; Fin={received.EndOfMessage}");
// Echo anything we receive
// and send to all listner found
foreach (var cliItem in meta.Listeners)
{ {
var listenningSocket = cliItem.Value; context.Response.StatusCode = 400;
if (listenningSocket.State == WebSocketState.Open) }
await listenningSocket.SendAsync( else
sBuffer, received.MessageType, received.EndOfMessage, CancellationToken.None); {
else LiveCastMeta meta = null;
if (listenningSocket.State == WebSocketState.CloseReceived || listenningSocket.State == WebSocketState.CloseSent) if (LiveApiController.Casters.ContainsKey(uname))
{ {
ToClose.Push(cliItem.Key); meta = LiveApiController.Casters[uname];
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
{
meta.Socket.Dispose();
// Accept the socket
meta.Socket = await context.WebSockets.AcceptWebSocketAsync();
}
} }
} else
received = await meta.Socket.ReceiveAsync(sBuffer, CancellationToken.None); {
// Accept the socket
meta = new LiveCastMeta { Socket = await context.WebSockets.AcceptWebSocketAsync() };
}
logger.LogInformation("Accepted web socket");
// Dispatch the flow
try
{
string no;
do
{
no = ToClose.Pop();
WebSocket listenningSocket;
if (meta.Listeners.TryRemove(no, out listenningSocket))
await listenningSocket.CloseAsync(WebSocketCloseStatus.EndpointUnavailable, "State != WebSocketState.Open", CancellationToken.None);
} while (no != null); if (meta.Socket != null && meta.Socket.State == WebSocketState.Open)
{
LiveApiController.Casters[uname] = meta;
// TODO: Handle the socket here.
// Find receivers: others in the chat room
// send them the flow
var sBuffer = new ArraySegment<byte>(new byte[1024]);
logger.LogInformation("Receiving bytes...");
WebSocketReceiveResult received = await meta.Socket.ReceiveAsync(sBuffer, CancellationToken.None);
logger.LogInformation("Received bytes!!!!");
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!");
// FIXME do we really need to close those one in invalid state ?
Stack<string> ToClose = new Stack<string>();
try
{
while (received.MessageType != WebSocketMessageType.Close)
{
logger.LogInformation($"Echoing {received.Count} bytes received in a {received.MessageType} message; Fin={received.EndOfMessage}");
// Echo anything we receive
// and send to all listner found
foreach (var cliItem in meta.Listeners)
{
var listenningSocket = cliItem.Value;
if (listenningSocket.State == WebSocketState.Open)
await listenningSocket.SendAsync(
sBuffer, received.MessageType, received.EndOfMessage, CancellationToken.None);
else
if (listenningSocket.State == WebSocketState.CloseReceived || listenningSocket.State == WebSocketState.CloseSent)
{
ToClose.Push(cliItem.Key);
}
}
received = await meta.Socket.ReceiveAsync(sBuffer, CancellationToken.None);
string no;
do
{
no = ToClose.Pop();
WebSocket listenningSocket;
if (meta.Listeners.TryRemove(no, out listenningSocket))
await listenningSocket.CloseAsync(WebSocketCloseStatus.EndpointUnavailable, "State != WebSocketState.Open", CancellationToken.None);
} while (no != null);
}
await meta.Socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "eof", CancellationToken.None);
LiveApiController.Casters[uname] = null;
}
catch (Exception ex)
{
logger.LogError($"Exception occured : {ex.Message}");
logger.LogError(ex.StackTrace);
meta.Socket.Dispose();
LiveApiController.Casters[uname] = 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();
}
else
logger.LogError("socket object is null");
}
}
catch (IOException ex)
{
if (ex.Message == "Unexpected end of stream")
{
logger.LogError($"Unexpected end of stream");
}
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;
}
}
} }
await meta.Socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "eof", CancellationToken.None);
LiveApiController.Casters[uname] = null;
} catch (Exception ex)
{
logger.LogError($"Exception occured : {ex.Message}");
logger.LogError(ex.StackTrace);
meta.Socket.Dispose();
LiveApiController.Casters[uname] = 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();
} }
else
logger.LogError("socket object is null");
} }
}
catch (IOException ex)
{
if (ex.Message == "Unexpected end of stream")
{
logger.LogError($"Unexpected end of stream");
}
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 else
{ {
await next(); await next();

@ -68,12 +68,6 @@
} }
} }
chat.client.joint = function (rinfo)
{
console.log(rinfo);
setActiveRoom(rinfo.Name);
}
$.fn.filterByData = function (prop, val) { $.fn.filterByData = function (prop, val) {
return this.filter( return this.filter(
function () { return $(this).data(prop) == val; } function () { return $(this).data(prop) == val; }
@ -145,7 +139,10 @@
$('#chatview').removeClass('disabled'); $('#chatview').removeClass('disabled');
chans.forEach(function(room) { chans.forEach(function(room) {
chat.server.join(room); chat.server.join(room).done(function(chatInfo)
{console.log(chatInfo);
setActiveRoom(chatInfo.Name);
});
}) })
} }
@ -181,7 +178,10 @@
if (event.which == 13) { if (event.which == 13) {
if (this.value.length==0) return; if (this.value.length==0) return;
buildRoom(this.value); buildRoom(this.value);
chat.server.join(this.value); chat.server.join(this.value).done(function(chatInfo)
{console.log(chatInfo);
setActiveRoom(chatInfo.Name);
});
this.value="" this.value=""
} else { } else {
// TODO showRoomInfo(this.value); // TODO showRoomInfo(this.value);

Loading…