Added session termination for multiplex desktop sessions.

Ylian Saint-Hilaire committed Oct 19, 2021 at 14:33 UTC 38c9f5dbdd87506710a5b763ae0e3b81d02b83e8
1 file changed +8 -1
meshuser.js
+8 -1
@@ -5678,7 +5678,14 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5678 // Get the node and the rights for this node
5679 parent.GetNodeWithRights(domain, xuser, command.nodeid, function (node, rights, visible) {
5680 if ((rights != 0xFFFFFFFF) && (xuser._id != command.xuserid)) return;
5681 - //console.log('TODO');
5681 + const desktopRelay = parent.desktoprelays[command.nodeid];
5682 + if ((desktopRelay == null) || (desktopRelay === 1)) return; // If the desktopRelay is equal to 1, the relay is being constructed.
5683 + var viewersToClose = []; // Create a list of viewers to close. We don't want to close directly because it will change "desktopRelay.viewers" and we will not enumerate correctly.
5684 + for (var i = 0; i < desktopRelay.viewers.length; i++) {
5685 + const viewer = desktopRelay.viewers[i];
5686 + if ((viewer.user._id == command.xuserid) && (viewer.guestName == command.guestname)) { viewersToClose.push(viewer); } // Only close viewers that match the userid and guestname if present.
5687 + }
5688 + for (var i = 0; i < viewersToClose.length; i++) { viewersToClose[i].close(); } // Close any viewers we need closed.
5689 });
5690
5691 break;