show latency in remote/terminal every 10 secs (#5750)
Signed-off-by: si458 <simonsmith5521@gmail.com>
Simon Smith committed
Jan 31, 2024 at 14:06 UTC
cdab5538003a2f951587a3c4e9dc873daf6b9607
2 files changed
+16
-2
public/scripts/agent-redir-ws-0.1.1.js
+15
-1
@@ -81,6 +81,17 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
81
obj.xxOnSocketConnected = function () {
82
if (obj.debugmode == 1) { console.log('onSocketConnected'); }
83
//obj.debug('Agent Redir Socket Connected');
84
+ if (!obj.latency.lastSend){
85
+ obj.latency.lastSend = setInterval(function(){
86
+ if (obj.latency.current == -1) {
87
+ clearInterval(obj.latency.lastSend);
88
+ obj.latency.lastSend = null;
89
+ } else {
90
+ obj.sendCtrlMsg(JSON.stringify({ctrlChannel:102938,type:"rtt",time:(new Date().getTime())}));
91
+ }
92
+ }, 10000);
93
+ }
94
+ obj.sendCtrlMsg(JSON.stringify({ctrlChannel:102938,type:"rtt",time:(new Date().getTime())}));
95
obj.xxStateChange(2);
96
}
97
@@ -97,7 +108,7 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
108
if (obj.onMetadataChange) obj.onMetadataChange(obj.metadata);
109
} else if ((controlMsg.type == 'rtt') && (typeof controlMsg.time == 'number')) {
110
obj.latency.current = (new Date().getTime()) - controlMsg.time;
100
- if (obj.latency.callbacks != null) { obj.latency.callback(obj.latency.current); }
111
+ if (obj.latency.callback != null) { obj.latency.callback(obj.latency.current); }
112
} else if (obj.webrtc != null) {
113
if (controlMsg.type == 'answer') {
114
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
303
304
// Clean up WebRTC
305
obj.xxCloseWebRTC();
306
+
307
+ // clear RTT timer
308
+ obj.latency.current = -1;
309
310
//obj.debug('Agent Redir Socket Stopped');
311
obj.connectstate = -1;
views/default.handlebars
+1
-1
@@ -9187,7 +9187,7 @@
9187
//desktop.m.onDisplayinfo = deskDisplayInfo;
9188
desktop.m.onScreenSizeChange = deskAdjust;
9189
desktop.Start(desktopNode._id);
9190
- desktop.latency.callback = function(ms) { console.log('latency', ms); updateSessionTime(); };
9190
+ desktop.latency.callback = function(ms) { /* console.log('latency', ms); */ updateSessionTime(); };
9191
desktop.contype = 1;
9192
} else if (contype == 3) {
9193
// Ask for user sessions