Added slowRelay debug option to desktop multiplexor
Ylian Saint-Hilaire committed
Apr 28, 2020 at 13:22 UTC
40683cd28cac4639f5331f8f1e2458a5974a85e2
2 files changed
+24
-8
meshdesktopmultiplex.js
+23
-8
@@ -107,6 +107,13 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
107
peer.sendQueue = [];
108
peer.paused = false;
109
110
+ // Setup slow relay is requested. This will show down sending any data to this viewer.
111
+ if ((peer.req.query.slowrelay != null)) {
112
+ var sr = null;
113
+ try { sr = parseInt(peer.req.query.slowrelay); } catch (ex) { }
114
+ if ((typeof sr == 'number') && (sr > 0) && (sr < 1000)) { peer.slowRelay = sr; }
115
+ }
116
+
117
// Indicated we are connected
118
obj.sendToViewer(peer, obj.recordingFile ? 'cr' : 'c');
119
@@ -268,7 +275,11 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
275
viewer.sendQueue.push(data);
276
} else {
277
viewer.sending = true;
271
- viewer.ws.send(data, function () { sendViewerNext(viewer); });
278
+ if (viewer.slowRelay) {
279
+ setTimeout(function () { try { viewer.ws.send(data, function () { sendViewerNext(viewer); }); } catch (ex) { } }, viewer.slowRelay);
280
+ } else {
281
+ try { viewer.ws.send(data, function () { sendViewerNext(viewer); }); } catch (ex) { }
282
+ }
283
284
// Flow control, pause the agent if needed
285
obj.viewersSendingCount++;
@@ -282,7 +293,11 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
293
if (viewer.sendQueue.length > 0) {
294
// Send from the pending send queue
295
if (viewer.sending == false) { viewer.sending = true; obj.viewersSendingCount++; }
285
- viewer.ws.send(viewer.sendQueue.shift(), function () { sendViewerNext(viewer); });
296
+ if (viewer.slowRelay) {
297
+ setTimeout(function () { try { viewer.ws.send(viewer.sendQueue.shift(), function () { sendViewerNext(viewer); }); } catch (ex) { } }, viewer.slowRelay);
298
+ } else {
299
+ try { viewer.ws.send(viewer.sendQueue.shift(), function () { sendViewerNext(viewer); }); } catch (ex) { }
300
+ }
301
} else {
302
if (viewer.dataPtr != null) {
303
// Send the next image
@@ -291,7 +306,11 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
306
viewer.lastImageNumberSent = viewer.dataPtr;
307
//if ((image.next != null) && ((viewer.dataPtr + 1) != image.next)) { console.log('SVIEW-S2', viewer.dataPtr, image.next); } // DEBUG
308
viewer.dataPtr = image.next;
294
- viewer.ws.send(image.data, function () { sendViewerNext(viewer); });
309
+ if (viewer.slowRelay) {
310
+ setTimeout(function () { try { viewer.ws.send(image.data, function () { sendViewerNext(viewer); }); } catch (ex) { } }, viewer.slowRelay);
311
+ } else {
312
+ try { viewer.ws.send(image.data, function () { sendViewerNext(viewer); }); } catch (ex) { }
313
+ }
314
315
// Flow control, pause the agent if needed
316
if (viewer.sending == false) {
@@ -478,8 +497,6 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
497
498
//console.log('Adding Image ' + obj.counter, x, y, dimensions.width, dimensions.height);
499
481
- var skips = [];
482
-
500
// Update the screen with the correct pointers.
501
for (var i = 0; i < sw; i++) {
502
for (var j = 0; j < sh; j++) {
@@ -497,13 +514,11 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
514
delete obj.imagesCounters[oi];
515
516
// If any viewers are currently on image "oi" must be moved to "d.next"
500
- for (var l in obj.viewers) { const v = obj.viewers[l]; if (v.dataPtr == oi) { skips.push(oi); v.dataPtr = d.next; } }
517
+ for (var l in obj.viewers) { const v = obj.viewers[l]; if (v.dataPtr == oi) { v.dataPtr = d.next; } }
518
}
519
}
520
}
521
505
- if (skips.length > 0) { console.log('SKIPS', skips.length); }
506
-
522
// Any viewer on dataPtr null, change to this image
523
for (var i in obj.viewers) {
524
const v = obj.viewers[i];
public/scripts/agent-redir-ws-0.1.1.js
+1
@@ -42,6 +42,7 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
42
var url2, url = window.location.protocol.replace('http', 'ws') + '//' + window.location.host + window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) + '/meshrelay.ashx?browser=1&p=' + obj.protocol + '&nodeid=' + nodeid + '&id=' + obj.tunnelid;
43
//if (serverPublicNamePort) { url2 = window.location.protocol.replace('http', 'ws') + '//' + serverPublicNamePort + '/meshrelay.ashx?id=' + obj.tunnelid; } else { url2 = url; }
44
if ((authCookie != null) && (authCookie != '')) { url += '&auth=' + authCookie; }
45
+ if ((urlargs != null) && (urlargs.slowrelay != null)) { url += '&slowrelay=' + urlargs.slowrelay; }
46
obj.nodeid = nodeid;
47
obj.connectstate = 0;
48
obj.socket = new WebSocket(url);