fix(chat): KeyNotFoundException dans HubConnectionManager.OnConnected
ChatUserNames n'etait jamais alimente (relique d'un SetUserName disparu),
ce qui faisait lever KeyNotFoundException a chaque connexion SignalR et
fermait immediatement la connexion cote client ("Déconnecté (The server
closed the connection...)" dans PostIt).
- IConnexionManager.OnConnected prend desormais le userName en parametre
- HubConnectionManager.OnConnected alimente ChatUserNames et ChatCxIds
- ChatHub.OnConnectedAsync passe le userName resolu depuis les claims
Inclut aussi les changements PostIt lies (bandeau de statut avec
commande d'action, handlers Reconnecting/Reconnected/Closed).
This commit is contained in:
parent
b22a26f61e
commit
75bb2600b5
6 changed files with 70 additions and 16 deletions
|
|
@ -90,7 +90,7 @@ namespace Yavsc.Server.Hubs
|
|||
{
|
||||
await Groups.AddToGroupAsync(Context.ConnectionId, ChatHubConstants.HubGroupFollowingPrefix + uid);
|
||||
}
|
||||
_cxManager.OnConnected(Context.ConnectionId, isCop);
|
||||
_cxManager.OnConnected(Context.ConnectionId, userName, isCop);
|
||||
await base.OnConnectedAsync();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ namespace Yavsc.Services
|
|||
{
|
||||
public interface IConnexionManager {
|
||||
string GetUserName (string cxId);
|
||||
void OnConnected(string cxId, bool isCop);
|
||||
void OnConnected(string cxId, string userName, bool isCop);
|
||||
bool IsConnected(string candidate);
|
||||
|
||||
void OnDisconnected (string cxId);
|
||||
|
|
|
|||
|
|
@ -53,13 +53,15 @@ namespace Yavsc.Services
|
|||
_localizer = stringLocFactory.Create(typeof(HubConnectionManager));
|
||||
}
|
||||
|
||||
// Username must have been set before calling this method.
|
||||
public void OnConnected(string cxId, bool isCop)
|
||||
public void OnConnected(string cxId, string userName, bool isCop)
|
||||
{
|
||||
var username = ChatUserNames[cxId];
|
||||
if (!IsConnected(username))
|
||||
ChatRoomPresence[username] = new List<string>();
|
||||
_isCop[username] = isCop;
|
||||
ChatUserNames[cxId] = userName;
|
||||
ChatCxIds.AddOrUpdate(userName,
|
||||
_ => new List<string> { cxId },
|
||||
(_, list) => { lock (list) { if (!list.Contains(cxId)) list.Add(cxId); } return list; });
|
||||
if (!IsConnected(userName))
|
||||
ChatRoomPresence[userName] = new List<string>();
|
||||
_isCop[userName] = isCop;
|
||||
}
|
||||
|
||||
public bool IsConnected(string candidate)
|
||||
|
|
|
|||
Loading…
Reference in a new issue