mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-01 13:55:05 +00:00
fix: mobileinfo & CWS info call report the correct data
This commit is contained in:
@@ -61,6 +61,11 @@ namespace PepperDash.Essentials.WebSocketServer
|
||||
|
||||
private readonly Dictionary<string, UiClient> uiClients = new Dictionary<string, UiClient>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of UI clients
|
||||
/// </summary>
|
||||
public ReadOnlyDictionary<string, UiClient> UiClients => new ReadOnlyDictionary<string, UiClient>(uiClients);
|
||||
|
||||
private readonly MobileControlSystemController _parent;
|
||||
|
||||
private WebSocketServerSecretProvider _secretProvider;
|
||||
@@ -130,17 +135,7 @@ namespace PepperDash.Essentials.WebSocketServer
|
||||
{
|
||||
get
|
||||
{
|
||||
var count = 0;
|
||||
|
||||
foreach (var client in UiClientContexts)
|
||||
{
|
||||
if (client.Value.Client != null && client.Value.Client.Context.WebSocket.IsAlive)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
return uiClients.Values.Where(c => c.Context.WebSocket.IsAlive).Count();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -736,7 +731,7 @@ namespace PepperDash.Essentials.WebSocketServer
|
||||
|
||||
private UiClient BuildUiClient(string roomKey, JoinToken token, string key)
|
||||
{
|
||||
var c = new UiClient($"uiclient-{key}-{roomKey}-{token.Id}", token.Id);
|
||||
var c = new UiClient($"uiclient-{key}-{roomKey}-{token.Id}", token.Id, token.Token);
|
||||
this.LogInformation("Constructing UiClient with key {key} and ID {id}", key, token.Id);
|
||||
c.Controller = _parent;
|
||||
c.RoomKey = roomKey;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using PepperDash.Core;
|
||||
@@ -22,6 +21,16 @@ namespace PepperDash.Essentials.WebSocketServer
|
||||
/// <inheritdoc />
|
||||
public string Key { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Client ID used by client for this connection
|
||||
/// </summary>
|
||||
public string Id { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Token associated with this client
|
||||
/// </summary>
|
||||
public string Token { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the mobile control system controller that handles this client's messages
|
||||
/// </summary>
|
||||
@@ -32,11 +41,6 @@ namespace PepperDash.Essentials.WebSocketServer
|
||||
/// </summary>
|
||||
public string RoomKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The unique identifier for this client instance
|
||||
/// </summary>
|
||||
private string _clientId;
|
||||
|
||||
/// <summary>
|
||||
/// The timestamp when this client connection was established
|
||||
/// </summary>
|
||||
@@ -60,15 +64,22 @@ namespace PepperDash.Essentials.WebSocketServer
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when this client closes it's connection
|
||||
/// </summary>
|
||||
public event EventHandler<ConnectionClosedEventArgs> ConnectionClosed;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the UiClient class with the specified key
|
||||
/// </summary>
|
||||
/// <param name="key">The unique key to identify this client</param>
|
||||
/// <param name="id">The client ID used by the client for this connection</param>
|
||||
public UiClient(string key, string id)
|
||||
/// <param name="token"></param>
|
||||
public UiClient(string key, string id, string token)
|
||||
{
|
||||
Key = key;
|
||||
Id = id;
|
||||
Token = token;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -76,34 +87,11 @@ namespace PepperDash.Essentials.WebSocketServer
|
||||
{
|
||||
base.OnOpen();
|
||||
|
||||
_connectionTime = DateTime.Now;
|
||||
|
||||
Log.Output = (data, message) => Utilities.ConvertWebsocketLog(data, message);
|
||||
Log.Level = LogLevel.Trace;
|
||||
|
||||
try
|
||||
{
|
||||
this.LogDebug("Current session count on open {count}", Sessions.Count);
|
||||
this.LogDebug("Current WebsocketServiceCount on open: {count}", Controller.DirectServer.WebsocketServiceCount);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.LogError("Error getting service count: {message}", ex.Message);
|
||||
this.LogDebug(ex, "Stack Trace: ");
|
||||
}
|
||||
|
||||
// var url = Context.WebSocket.Url;
|
||||
// this.LogInformation("New WebSocket Connection from: {url}", url);
|
||||
|
||||
// var match = Regex.Match(url.AbsoluteUri, "(?:ws|wss):\\/\\/.*(?:\\/mc\\/api\\/ui\\/join\\/)(.*)");
|
||||
|
||||
// if (!match.Success)
|
||||
// {
|
||||
// _connectionTime = DateTime.Now;
|
||||
// return;
|
||||
// }
|
||||
|
||||
// var clientId = match.Groups[1].Value;
|
||||
// _clientId = clientId;
|
||||
|
||||
if (Controller == null)
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Verbose, "WebSocket UiClient Controller is null");
|
||||
@@ -141,7 +129,7 @@ namespace PepperDash.Essentials.WebSocketServer
|
||||
/// <param name="e">Event arguments</param>
|
||||
private void Bridge_UserCodeChanged(object sender, EventArgs e)
|
||||
{
|
||||
SendUserCodeToClient((MobileControlEssentialsRoomBridge)sender, _clientId);
|
||||
SendUserCodeToClient((MobileControlEssentialsRoomBridge)sender, Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -184,17 +172,6 @@ namespace PepperDash.Essentials.WebSocketServer
|
||||
{
|
||||
base.OnClose(e);
|
||||
|
||||
try
|
||||
{
|
||||
this.LogDebug("Current session count on close {count}", Sessions.Count);
|
||||
this.LogDebug("Current WebsocketServiceCount on close: {count}", Controller.DirectServer.WebsocketServiceCount);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.LogError("Error getting service count: {message}", ex.Message);
|
||||
this.LogDebug(ex, "Stack Trace: ");
|
||||
}
|
||||
|
||||
this.LogInformation("WebSocket UiClient Closing: {code} reason: {reason}", e.Code, e.Reason);
|
||||
|
||||
foreach (var messenger in Controller.Messengers)
|
||||
|
||||
Reference in New Issue
Block a user