1. Add latency timer and callback opportunity to CreateAgentRedirect 2. Add latency to Remote Desktop view
1. Add latency timer and callback opportunity to CreateAgentRedirect 2. Add latency to Remote Desktop view
Ryan Blenis committed
Apr 14, 2020 at 01:48 UTC
48da88854072a96d611c450229888cd8229717cc
3 files changed
+29
-2
agents/meshcore.js
+4
@@ -1912,6 +1912,10 @@ function createMeshCore(agent) {
1912
if (sdp != null) { ws.write({ type: 'answer', ctrlChannel: '102938', sdp: sdp }); }
1913
break;
1914
}
1915
+ case 'latency': {
1916
+ ws.write({ type: 'latency', ctrlChannel: '102938', time: obj.time });
1917
+ break;
1918
+ }
1919
}
1920
}
1921
public/scripts/agent-redir-ws-0.1.1.js
+23
-2
@@ -28,6 +28,7 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
28
obj.webrtc = null;
29
obj.debugmode = 0;
30
obj.serverIsRecording = false;
31
+ obj.latency = { timer: null, lastSend: 0, current: 0, send: false, callbacks: [] };
32
if (domainUrl == null) { domainUrl = '/'; }
33
34
// Console Message
@@ -73,6 +74,9 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
74
if (controlMsg.type == 'console') {
75
obj.consoleMessage = controlMsg.msg;
76
if (obj.onConsoleMessageChange) { obj.onConsoleMessageChange(obj, obj.consoleMessage); }
77
+ } else if (controlMsg.type = 'latency') {
78
+ obj.latency.current = (new Date().getTime()) - controlMsg.time;
79
+ obj.latency.onUpdate();
80
} else if (obj.webrtc != null) {
81
if (controlMsg.type == 'answer') {
82
obj.webrtc.setRemoteDescription(new RTCSessionDescription(controlMsg), function () { /*console.log('WebRTC remote ok');*/ }, obj.xxCloseWebRTC);
@@ -97,7 +101,18 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
101
if (obj.onStateChanged != null) { obj.onStateChanged(obj, obj.State); }
102
}
103
}
100
-
104
+
105
+ obj.latencyTimer = function() {
106
+ obj.latency.send = true;
107
+ }
108
+
109
+ obj.latency.onUpdate = function(func) {
110
+ if (func != null) { obj.latency.callbacks.push(func); return; }
111
+ if (obj.latency.callbacks.length > 0) {
112
+ for (var x in obj.latency.callbacks) obj.latency.callbacks[x](obj.latency.current);
113
+ }
114
+ };
115
+
116
obj.xxOnMessage = function (e) {
117
//console.log('Recv', e.data, e.data.byteLength, obj.State);
118
if (obj.State < 3) {
@@ -149,6 +164,11 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
164
}
165
166
if (typeof e.data == 'object') {
167
+ if (obj.latency.timer == null) {
168
+ obj.latency.timer = setInterval(obj.latencyTimer, 3000);
169
+ }
170
+ if (obj.latency.send) { obj.latency.send = false; obj.sendCtrlMsg('{"ctrlChannel":"102938","type":"latency","time":'+ new Date().getTime() +'}'); }
171
+
172
if (fileReaderInuse == true) { fileReaderAcc.push(e.data); return; }
173
if (fileReader.readAsBinaryString && (obj.m.ProcessBinaryData == null)) {
174
// Chrome & Firefox (Draft)
@@ -248,7 +268,8 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
268
269
obj.Stop = function (x) {
270
if (obj.debugmode == 1) { console.log('stop', x); }
251
-
271
+ obj.latency.current = 0;
272
+ obj.latency.onUpdate();
273
// Clean up WebRTC
274
obj.xxCloseWebRTC();
275
views/default.handlebars
+2
@@ -515,6 +515,7 @@
515
<span id=connectbutton1hspan> <input type=button id=connectbutton1h value="HW Connect" title="Connect using Intel AMT hardware KVM" onclick=connectDesktop(event,2) onkeypress="return false" onkeydown="return false" disabled="disabled" /></span>
516
<span id=disconnectbutton1span> <input type=button id=disconnectbutton1 value="Disconnect" onclick=connectDesktop(event,0) onkeypress="return false" onkeydown="return false" /></span>
517
<span id="deskstatus">Disconnected</span>
518
+ <span id="connectLatency">(Ping: <span id="connectLatencyTime">0</span>ms)</span>
519
</div>
520
</div>
521
<div id=deskarea2 style="">
@@ -5860,6 +5861,7 @@
5861
desktop.m.onDisplayinfo = deskDisplayInfo;
5862
desktop.m.onScreenSizeChange = deskAdjust;
5863
desktop.Start(desktopNode._id);
5864
+ desktop.latency.onUpdate(function(ms) { QH('connectLatencyTime', ms); });
5865
desktop.contype = 1;
5866
} else if (contype == 3) {
5867
// Ask for user sessions