diff --git a/LTEMvcApp/Controllers/HomeController.cs b/LTEMvcApp/Controllers/HomeController.cs index 4847cd0..627a357 100644 --- a/LTEMvcApp/Controllers/HomeController.cs +++ b/LTEMvcApp/Controllers/HomeController.cs @@ -27,18 +27,9 @@ public class HomeController : Controller var configs = _webSocketManager.GetAllClientConfigs(); ViewBag.ClientConfigs = configs; - // 获取测试客户端配置 - var testConfig = _webSocketManager.GetDefaultTestClientConfig(); - var testClient = _webSocketManager.GetTestClient(); - var clientState = testClient?.State ?? LTEMvcApp.Models.ClientState.Stop; - - ViewBag.TestConfig = testConfig; - ViewBag.ClientState = clientState; - // 以后可以扩展为客户端列表 - ViewBag.Clients = new List - { - new { Config = testConfig, State = clientState } - }; + // 获取所有测试客户端配置和状态 + var allTestClients = _webSocketManager.GetAllTestClientsWithState(); + ViewBag.Clients = allTestClients; return View(); } diff --git a/LTEMvcApp/Controllers/TestConfigController.cs b/LTEMvcApp/Controllers/TestConfigController.cs index 83ffb9a..c0d58e7 100644 --- a/LTEMvcApp/Controllers/TestConfigController.cs +++ b/LTEMvcApp/Controllers/TestConfigController.cs @@ -61,6 +61,17 @@ namespace LTEMvcApp.Controllers return Ok(configs); } + /// + /// 获取所有测试客户端配置和状态 + /// + /// 测试客户端配置和状态列表 + [HttpGet("with-state")] + public ActionResult> GetAllTestClientsWithState() + { + var clientsWithState = _webSocketManager.GetAllTestClientsWithState(); + return Ok(clientsWithState); + } + /// /// 根据地址获取测试客户端配置 /// diff --git a/LTEMvcApp/Services/WebSocketManagerService.cs b/LTEMvcApp/Services/WebSocketManagerService.cs index 82b256d..da351a2 100644 --- a/LTEMvcApp/Services/WebSocketManagerService.cs +++ b/LTEMvcApp/Services/WebSocketManagerService.cs @@ -501,6 +501,44 @@ namespace LTEMvcApp.Services return GetClientInstance(defaultConfig.Name); } + /// + /// 获取所有测试客户端实例 + /// + /// 所有测试客户端的WebSocket实例列表 + public List GetAllTestClients() + { + var testClients = new List(); + + foreach (var config in _testClientConfigs) + { + if (_clients.TryGetValue(config.Name, out var client)) + { + testClients.Add(client); + } + } + + return testClients; + } + + /// + /// 获取所有测试客户端配置和状态 + /// + /// 测试客户端配置和状态列表 + public List GetAllTestClientsWithState() + { + var result = new List(); + + foreach (var config in _testClientConfigs) + { + var client = GetClientInstance(config.Name); + var state = client?.State ?? ClientState.Stop; + + result.Add(new { Config = config, State = state, Client = client }); + } + + return result; + } + /// /// 创建默认测试配置 ///