@@ -221,6 +221,9 @@ const NetworkMonitor = () => {
221221 const [ isDraggingGroup , setIsDraggingGroup ] = useState ( false ) ;
222222 const [ groupDragStart , setGroupDragStart ] = useState ( { x : 0 , y : 0 } ) ;
223223
224+ // AVG latency stuff
225+ const [ deviceStats , setDeviceStats ] = useState ( { } ) ;
226+
224227 const devicesRef = React . useRef ( devices ) ;
225228
226229 // Load configuration on mount
@@ -291,7 +294,31 @@ const NetworkMonitor = () => {
291294
292295 const results = await Promise . all (
293296 currentDevices . map ( async ( device ) => {
294- const status = ( await pingDevice ( device . ip ) ) ? 'up' : 'down' ;
297+ const result = await fetch ( '/api/ping' , {
298+ method : 'POST' ,
299+ headers : { 'Content-Type' : 'application/json' } ,
300+ body : JSON . stringify ( { ip : device . ip } )
301+ } ) . then ( r => r . json ( ) ) . catch ( ( ) => ( { success : false , responseTime : null } ) ) ;
302+
303+ const status = result . success ? 'up' : 'down' ;
304+
305+ if ( result . success && result . responseTime ) {
306+ setDeviceStats ( prev => {
307+ const deviceData = prev [ device . id ] || { times : [ ] , count : 0 } ;
308+ const newTimes = [ ...deviceData . times , result . responseTime ] . slice ( - 10 ) ; // Keep last 10
309+ const avg = Math . round ( newTimes . reduce ( ( a , b ) => a + b , 0 ) / newTimes . length ) ;
310+
311+ return {
312+ ...prev ,
313+ [ device . id ] : {
314+ times : newTimes ,
315+ count : deviceData . count + 1 ,
316+ avg : avg
317+ }
318+ } ;
319+ } ) ;
320+ }
321+
295322 return { ...device , status } ;
296323 } )
297324 ) ;
@@ -966,6 +993,11 @@ showAddBox && React.createElement(
966993 'div' ,
967994 { className : 'text-gray-400 text-xs text-center' } ,
968995 device . ip
996+ ) ,
997+ device . status === 'up' && deviceStats [ device . id ] && React . createElement (
998+ 'div' ,
999+ { className : 'text-green-400 text-xs text-center' } ,
1000+ `${ deviceStats [ device . id ] . avg } ms avg`
9691001 )
9701002 )
9711003 )
0 commit comments