chat rooms join simplification
This commit is contained in:
parent
a532164997
commit
07267562bc
7 changed files with 211 additions and 183 deletions
|
|
@ -189,7 +189,7 @@ namespace Yavsc
|
|||
public string Topic;
|
||||
}
|
||||
|
||||
public void Join(string roomName)
|
||||
public ChatRoomInfo Join(string roomName)
|
||||
{
|
||||
_logger.LogInformation("a client for " + roomName);
|
||||
var userName = ChatUserNames[Context.ConnectionId];
|
||||
|
|
@ -214,13 +214,13 @@ namespace Yavsc
|
|||
Clients.Group("room_" + roomName).notify(NotificationTypes.UserJoin, Context.ConnectionId, Clients.Caller.UserName);
|
||||
|
||||
_logger.LogInformation("exiting ok.");
|
||||
return;
|
||||
return chanInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("room seemd to be avaible ... but we could get no info on it.");
|
||||
Clients.Caller.notify(NotificationTypes.Error, "join get chan failed ...");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// chan was almost empty
|
||||
|
|
@ -247,9 +247,10 @@ namespace Yavsc
|
|||
if (Channels.TryAdd(roomName, chanInfo))
|
||||
{
|
||||
Groups.Add(Context.ConnectionId, roomGroupName);
|
||||
Clients.Caller.onJoined(chanInfo);
|
||||
return(chanInfo);
|
||||
}
|
||||
else _logger.LogError("Chan create failed unexpectly...");
|
||||
return null;
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Data.Entity.Infrastructure;
|
||||
using Microsoft.Data.Entity.Metadata;
|
||||
using Microsoft.Data.Entity.Migrations;
|
||||
using Yavsc.Models;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Data.Entity.Migrations;
|
||||
|
||||
namespace Yavsc.Migrations
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
using System;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Data.Entity.Infrastructure;
|
||||
using Microsoft.Data.Entity.Metadata;
|
||||
using Microsoft.Data.Entity.Migrations;
|
||||
using Yavsc.Models;
|
||||
|
||||
namespace Yavsc.Migrations
|
||||
|
|
|
|||
|
|
@ -258,7 +258,9 @@ namespace Yavsc.Models
|
|||
|
||||
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<ChatRoom> ChatRoom { get; set; }
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -68,12 +68,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
chat.client.joint = function (rinfo)
|
||||
{
|
||||
console.log(rinfo);
|
||||
setActiveRoom(rinfo.Name);
|
||||
}
|
||||
|
||||
$.fn.filterByData = function (prop, val) {
|
||||
return this.filter(
|
||||
function () { return $(this).data(prop) == val; }
|
||||
|
|
@ -145,7 +139,10 @@
|
|||
$('#chatview').removeClass('disabled');
|
||||
|
||||
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 (this.value.length==0) return;
|
||||
buildRoom(this.value);
|
||||
chat.server.join(this.value);
|
||||
chat.server.join(this.value).done(function(chatInfo)
|
||||
{console.log(chatInfo);
|
||||
setActiveRoom(chatInfo.Name);
|
||||
});
|
||||
this.value=""
|
||||
} else {
|
||||
// TODO showRoomInfo(this.value);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue