From cdab5538003a2f951587a3c4e9dc873daf6b9607 Mon Sep 17 00:00:00 2001 From: Simon Smith Date: Wed, 31 Jan 2024 14:06:31 +0000 Subject: [PATCH] show latency in remote/terminal every 10 secs (#5750) Signed-off-by: si458 --- public/scripts/agent-redir-ws-0.1.1.js | 16 +++++++++++++++- views/default.handlebars | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/public/scripts/agent-redir-ws-0.1.1.js b/public/scripts/agent-redir-ws-0.1.1.js index d79a58f5..747860b7 100644 --- a/public/scripts/agent-redir-ws-0.1.1.js +++ b/public/scripts/agent-redir-ws-0.1.1.js @@ -81,6 +81,17 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au obj.xxOnSocketConnected = function () { if (obj.debugmode == 1) { console.log('onSocketConnected'); } //obj.debug('Agent Redir Socket Connected'); + if (!obj.latency.lastSend){ + obj.latency.lastSend = setInterval(function(){ + if (obj.latency.current == -1) { + clearInterval(obj.latency.lastSend); + obj.latency.lastSend = null; + } else { + obj.sendCtrlMsg(JSON.stringify({ctrlChannel:102938,type:"rtt",time:(new Date().getTime())})); + } + }, 10000); + } + obj.sendCtrlMsg(JSON.stringify({ctrlChannel:102938,type:"rtt",time:(new Date().getTime())})); obj.xxStateChange(2); } @@ -97,7 +108,7 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au if (obj.onMetadataChange) obj.onMetadataChange(obj.metadata); } else if ((controlMsg.type == 'rtt') && (typeof controlMsg.time == 'number')) { obj.latency.current = (new Date().getTime()) - controlMsg.time; - if (obj.latency.callbacks != null) { obj.latency.callback(obj.latency.current); } + if (obj.latency.callback != null) { obj.latency.callback(obj.latency.current); } } else if (obj.webrtc != null) { if (controlMsg.type == 'answer') { obj.webrtc.setRemoteDescription(new RTCSessionDescription(controlMsg), function () { /*console.log('WebRTC remote ok');*/ }, obj.xxCloseWebRTC); @@ -292,6 +303,9 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au // Clean up WebRTC obj.xxCloseWebRTC(); + + // clear RTT timer + obj.latency.current = -1; //obj.debug('Agent Redir Socket Stopped'); obj.connectstate = -1; diff --git a/views/default.handlebars b/views/default.handlebars index bf213b35..0d3cf119 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -9187,7 +9187,7 @@ //desktop.m.onDisplayinfo = deskDisplayInfo; desktop.m.onScreenSizeChange = deskAdjust; desktop.Start(desktopNode._id); - desktop.latency.callback = function(ms) { console.log('latency', ms); updateSessionTime(); }; + desktop.latency.callback = function(ms) { /* console.log('latency', ms); */ updateSessionTime(); }; desktop.contype = 1; } else if (contype == 3) { // Ask for user sessions