From 91db03ea72852336ef91c3ad59447f95631fe890 Mon Sep 17 00:00:00 2001 From: Karl-Erik Gustafsson Date: Wed, 11 Jun 2025 23:28:36 +0300 Subject: [PATCH 1/3] feat: ws devices use description as a name instead of id --- .../src/views/Dashboard/Dashboard.js | 19 ++++++++++++++----- src/deltastats.ts | 7 +++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/server-admin-ui/src/views/Dashboard/Dashboard.js b/packages/server-admin-ui/src/views/Dashboard/Dashboard.js index 403322a22..d00347095 100644 --- a/packages/server-admin-ui/src/views/Dashboard/Dashboard.js +++ b/packages/server-admin-ui/src/views/Dashboard/Dashboard.js @@ -17,13 +17,15 @@ const Dashboard = (props) => { numberOfAvailablePaths, wsClients, providerStatistics, - uptime + uptime, + devices, } = props.serverStatistics || { deltaRate: 0, numberOfAvailablePaths: 0, wsClients: 0, providerStatistics: {}, - uptime: '' + uptime: '', + devices: [] } const providerStatus = props.providerStatus || [] const errorCount = providerStatus.filter((s) => s.type === 'error').length @@ -66,6 +68,13 @@ const Dashboard = (props) => { } const renderActivity = (providerId, providerStats, linkType) => { + let device = providerId + if (providerId.startsWith('ws.')) { + const found = devices.find( + (d) => d.clientId === providerId.slice(3) + ) + device = found && found.description ? found.description : providerId + } return (
  • props.history.push(`/dashboard`)}> { {linkType === 'plugin' ? pluginNameLink(providerId) - : providerIdLink(providerId)} + : providerIdLink(providerId, device)} {providerStats.writeRate > 0 && ( @@ -285,11 +294,11 @@ function pluginNameLink(id) { return {id} } -function providerIdLink(id) { +function providerIdLink(id, name) { if (id === 'defaults') { return {id} } else if (id.startsWith('ws.')) { - return {id} + return {name} } else { return {id} } diff --git a/src/deltastats.ts b/src/deltastats.ts index d59ede8da..0fa0e998d 100644 --- a/src/deltastats.ts +++ b/src/deltastats.ts @@ -17,7 +17,7 @@ import { isUndefined, values } from 'lodash' import { EventEmitter } from 'node:events' - +import { getSecurityConfig } from './security' const STATS_UPDATE_INTERVAL_SECONDS = 5 export const CONNECTION_WRITE_EVENT_NAME = 'connectionwrite' @@ -73,6 +73,8 @@ export function startDeltaStatistics( return setInterval(() => { updateProviderPeriodStats(app) const anyApp = app as any + const config = getSecurityConfig(anyApp) + const devices = anyApp.securityStrategy.getDevices(config) app.emit('serverevent', { type: 'SERVERSTATISTICS', from: 'signalk-server', @@ -83,7 +85,8 @@ export function startDeltaStatistics( numberOfAvailablePaths: anyApp.streambundle.getAvailablePaths().length, wsClients: anyApp.interfaces.ws ? anyApp.interfaces.ws.numClients() : 0, providerStatistics: app.providerStatistics, - uptime: process.uptime() + uptime: process.uptime(), + devices: devices } }) app.lastIntervalDeltaCount = app.deltaCount From cde66d8d2439d6f7d74fa0d02c6a8da4e4ef57b4 Mon Sep 17 00:00:00 2001 From: Karl-Erik Gustafsson Date: Thu, 12 Jun 2025 01:18:15 +0300 Subject: [PATCH 2/3] fix: ensure devices are retrieved safely from security strategy --- src/deltastats.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/deltastats.ts b/src/deltastats.ts index 0fa0e998d..ac00e1ec3 100644 --- a/src/deltastats.ts +++ b/src/deltastats.ts @@ -74,7 +74,10 @@ export function startDeltaStatistics( updateProviderPeriodStats(app) const anyApp = app as any const config = getSecurityConfig(anyApp) - const devices = anyApp.securityStrategy.getDevices(config) + let devices = []; + if ( anyApp && anyApp.securityStrategy && typeof anyApp.securityStrategy.getDevices === 'function' ) { + devices = anyApp.securityStrategy.getDevices(config); + } app.emit('serverevent', { type: 'SERVERSTATISTICS', from: 'signalk-server', From a747a8087438294483f2e4ba079d211ef92af068 Mon Sep 17 00:00:00 2001 From: Karl-Erik Gustafsson Date: Thu, 12 Jun 2025 01:25:14 +0300 Subject: [PATCH 3/3] fix: formatting --- .../server-admin-ui/src/views/Dashboard/Dashboard.js | 6 ++---- src/deltastats.ts | 10 +++++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/server-admin-ui/src/views/Dashboard/Dashboard.js b/packages/server-admin-ui/src/views/Dashboard/Dashboard.js index d00347095..e832159f8 100644 --- a/packages/server-admin-ui/src/views/Dashboard/Dashboard.js +++ b/packages/server-admin-ui/src/views/Dashboard/Dashboard.js @@ -18,7 +18,7 @@ const Dashboard = (props) => { wsClients, providerStatistics, uptime, - devices, + devices } = props.serverStatistics || { deltaRate: 0, numberOfAvailablePaths: 0, @@ -70,9 +70,7 @@ const Dashboard = (props) => { const renderActivity = (providerId, providerStats, linkType) => { let device = providerId if (providerId.startsWith('ws.')) { - const found = devices.find( - (d) => d.clientId === providerId.slice(3) - ) + const found = devices.find((d) => d.clientId === providerId.slice(3)) device = found && found.description ? found.description : providerId } return ( diff --git a/src/deltastats.ts b/src/deltastats.ts index ac00e1ec3..9e167b1bd 100644 --- a/src/deltastats.ts +++ b/src/deltastats.ts @@ -74,9 +74,13 @@ export function startDeltaStatistics( updateProviderPeriodStats(app) const anyApp = app as any const config = getSecurityConfig(anyApp) - let devices = []; - if ( anyApp && anyApp.securityStrategy && typeof anyApp.securityStrategy.getDevices === 'function' ) { - devices = anyApp.securityStrategy.getDevices(config); + let devices = [] + if ( + anyApp && + anyApp.securityStrategy && + typeof anyApp.securityStrategy.getDevices === 'function' + ) { + devices = anyApp.securityStrategy.getDevices(config) } app.emit('serverevent', { type: 'SERVERSTATISTICS',