1. Add latency timer and callback opportunity to CreateAgentRedirect

2. Add latency to Remote Desktop view
This commit is contained in:
Ryan Blenis 2020-04-14 01:48:20 -04:00
parent d0ad25795b
commit 9af543fe10
3 changed files with 29 additions and 2 deletions

View File

@ -1912,6 +1912,10 @@ function createMeshCore(agent) {
if (sdp != null) { ws.write({ type: 'answer', ctrlChannel: '102938', sdp: sdp }); }
break;
}
case 'latency': {
ws.write({ type: 'latency', ctrlChannel: '102938', time: obj.time });
break;
}
}
}

View File

@ -28,6 +28,7 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
obj.webrtc = null;
obj.debugmode = 0;
obj.serverIsRecording = false;
obj.latency = { timer: null, lastSend: 0, current: 0, send: false, callbacks: [] };
if (domainUrl == null) { domainUrl = '/'; }
// Console Message
@ -73,6 +74,9 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
if (controlMsg.type == 'console') {
obj.consoleMessage = controlMsg.msg;
if (obj.onConsoleMessageChange) { obj.onConsoleMessageChange(obj, obj.consoleMessage); }
} else if (controlMsg.type = 'latency') {
obj.latency.current = (new Date().getTime()) - controlMsg.time;
obj.latency.onUpdate();
} else if (obj.webrtc != null) {
if (controlMsg.type == 'answer') {
obj.webrtc.setRemoteDescription(new RTCSessionDescription(controlMsg), function () { /*console.log('WebRTC remote ok');*/ }, obj.xxCloseWebRTC);
@ -98,6 +102,17 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
}
}
obj.latencyTimer = function() {
obj.latency.send = true;
}
obj.latency.onUpdate = function(func) {
if (func != null) { obj.latency.callbacks.push(func); return; }
if (obj.latency.callbacks.length > 0) {
for (var x in obj.latency.callbacks) obj.latency.callbacks[x](obj.latency.current);
}
};
obj.xxOnMessage = function (e) {
//console.log('Recv', e.data, e.data.byteLength, obj.State);
if (obj.State < 3) {
@ -149,6 +164,11 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
}
if (typeof e.data == 'object') {
if (obj.latency.timer == null) {
obj.latency.timer = setInterval(obj.latencyTimer, 3000);
}
if (obj.latency.send) { obj.latency.send = false; obj.sendCtrlMsg('{"ctrlChannel":"102938","type":"latency","time":'+ new Date().getTime() +'}'); }
if (fileReaderInuse == true) { fileReaderAcc.push(e.data); return; }
if (fileReader.readAsBinaryString && (obj.m.ProcessBinaryData == null)) {
// Chrome & Firefox (Draft)
@ -248,7 +268,8 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
obj.Stop = function (x) {
if (obj.debugmode == 1) { console.log('stop', x); }
obj.latency.current = 0;
obj.latency.onUpdate();
// Clean up WebRTC
obj.xxCloseWebRTC();

View File

@ -515,6 +515,7 @@
<span id=connectbutton1hspan>&nbsp;<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>
<span id=disconnectbutton1span>&nbsp;<input type=button id=disconnectbutton1 value="Disconnect" onclick=connectDesktop(event,0) onkeypress="return false" onkeydown="return false" /></span>
&nbsp;<span id="deskstatus">Disconnected</span>
<span id="connectLatency">(Ping: <span id="connectLatencyTime">0</span>ms)</span>
</div>
</div>
<div id=deskarea2 style="">
@ -5860,6 +5861,7 @@
desktop.m.onDisplayinfo = deskDisplayInfo;
desktop.m.onScreenSizeChange = deskAdjust;
desktop.Start(desktopNode._id);
desktop.latency.onUpdate(function(ms) { QH('connectLatencyTime', ms); });
desktop.contype = 1;
} else if (contype == 3) {
// Ask for user sessions