More device session notification work.

This commit is contained in:
Ylian Saint-Hilaire 2020-05-11 18:44:46 -07:00
parent e3ad337e35
commit 1babb54ec5
6 changed files with 97 additions and 11 deletions

View File

@ -1403,6 +1403,7 @@ function createMeshCore(agent) {
if (this.httprequest.desktop.kvm.tunnels != null) { if (this.httprequest.desktop.kvm.tunnels != null) {
for (var i in this.httprequest.desktop.kvm.tunnels) { try { var userid = this.httprequest.desktop.kvm.tunnels[i].httprequest.userid; if (users[userid] == null) { users[userid] = 1; } else { users[userid]++; } } catch (ex) { } } for (var i in this.httprequest.desktop.kvm.tunnels) { try { var userid = this.httprequest.desktop.kvm.tunnels[i].httprequest.userid; if (users[userid] == null) { users[userid] = 1; } else { users[userid]++; } } catch (ex) { } }
for (var i in this.httprequest.desktop.kvm.tunnels) { try { this.httprequest.desktop.kvm.tunnels[i].write(JSON.stringify({ ctrlChannel: '102938', type: 'metadata', users: users })); } catch (ex) { } } for (var i in this.httprequest.desktop.kvm.tunnels) { try { this.httprequest.desktop.kvm.tunnels[i].write(JSON.stringify({ ctrlChannel: '102938', type: 'metadata', users: users })); } catch (ex) { } }
try { mesh.SendCommand({ action: 'sessions', type: 'kvm', value: users }); } catch (ex) { }
} }
this.end = function () { this.end = function () {
@ -1417,6 +1418,7 @@ function createMeshCore(agent) {
if (this.httprequest.desktop.kvm.tunnels != null) { if (this.httprequest.desktop.kvm.tunnels != null) {
for (var i in this.httprequest.desktop.kvm.tunnels) { try { var userid = this.httprequest.desktop.kvm.tunnels[i].httprequest.userid; if (users[userid] == null) { users[userid] = 1; } else { users[userid]++; } } catch (ex) { } } for (var i in this.httprequest.desktop.kvm.tunnels) { try { var userid = this.httprequest.desktop.kvm.tunnels[i].httprequest.userid; if (users[userid] == null) { users[userid] = 1; } else { users[userid]++; } } catch (ex) { } }
for (var i in this.httprequest.desktop.kvm.tunnels) { try { this.httprequest.desktop.kvm.tunnels[i].write(JSON.stringify({ ctrlChannel: '102938', type: 'metadata', users: users })); } catch (ex) { } } for (var i in this.httprequest.desktop.kvm.tunnels) { try { this.httprequest.desktop.kvm.tunnels[i].write(JSON.stringify({ ctrlChannel: '102938', type: 'metadata', users: users })); } catch (ex) { } }
try { mesh.SendCommand({ action: 'sessions', type: 'kvm', value: users }); } catch (ex) { }
} }
// Unpipe the web socket // Unpipe the web socket

View File

@ -1327,6 +1327,13 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
}); });
break; break;
} }
case 'sessions': {
// This is a list of sessions provided by the agent
if (obj.sessions == null) { obj.sessions = {}; }
if (command.type == 'kvm') { obj.sessions.kvm = command.value; }
obj.updateSessions();
break;
}
case 'plugin': { case 'plugin': {
if ((parent.parent.pluginHandler == null) || (typeof command.plugin != 'string')) break; if ((parent.parent.pluginHandler == null) || (typeof command.plugin != 'string')) break;
try { try {
@ -1350,6 +1357,17 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
} }
} }
// Notify update of sessions
obj.updateSessions = function () {
// Perform some clean up
for (var i in obj.sessions) { if (Object.keys(obj.sessions[i]).length == 0) { delete obj.sessions[i]; } }
if (Object.keys(obj.sessions).length == 0) { delete obj.sessions; }
// Event the new sessions, this will notify everyone that agent sessions have changed
var event = { etype: 'node', action: 'devicesessions', nodeid: obj.dbNodeKey, domain: domain.id, sessions: obj.sessions, nolog: 1 };
parent.parent.DispatchEvent(parent.CreateMeshDispatchTargets(obj.dbMeshKey, [obj.dbNodeKey]), obj, event);
}
// Change the current core information string and event it // Change the current core information string and event it
function ChangeAgentCoreInfo(command) { function ChangeAgentCoreInfo(command) {
if (obj.agentInfo.capabilities & 0x40) return; if (obj.agentInfo.capabilities & 0x40) return;

View File

@ -260,6 +260,9 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
obj.startTime = null; obj.startTime = null;
} }
// Send an updated list of all peers to all viewers
obj.sendSessionMetadata();
parent.parent.debug('relay', 'DesktopRelay: Disposing desktop multiplexor'); parent.parent.debug('relay', 'DesktopRelay: Disposing desktop multiplexor');
} }
@ -307,10 +310,20 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
// Send the list of all users currently vieweing this session to all viewers and servers // Send the list of all users currently vieweing this session to all viewers and servers
obj.sendSessionMetadata = function () { obj.sendSessionMetadata = function () {
var allUsers = {}; var allUsers = {};
for (var i in obj.viewers) { var v = obj.viewers[i]; if ((v.user != null) && (v.user._id != null)) { if (allUsers[v.user._id] == null) { allUsers[v.user._id] = 1; } else { allUsers[v.user._id]++; } } } if (obj.viewers != null) {
obj.sendToAllViewers(JSON.stringify({ type: 'metadata', 'ctrlChannel': '102938', users: allUsers, startTime: obj.startTime })); for (var i in obj.viewers) { var v = obj.viewers[i]; if ((v.user != null) && (v.user._id != null)) { if (allUsers[v.user._id] == null) { allUsers[v.user._id] = 1; } else { allUsers[v.user._id]++; } } }
obj.sendToAllViewers(JSON.stringify({ type: 'metadata', 'ctrlChannel': '102938', users: allUsers, startTime: obj.startTime }));
}
// TODO: Update the servers // Update the sessions attached the to agent
if (obj.nodeid != null) {
const xagent = parent.wsagents[obj.nodeid];
if (xagent != null) {
if (xagent.sessions == null) { xagent.sessions = {}; }
xagent.sessions.multidesk = allUsers;
xagent.updateSessions();
}
}
} }
// Send this command to all viewers // Send this command to all viewers

View File

@ -586,6 +586,10 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
if (docs[i].userloc != null) { delete docs[i].userloc; } if (docs[i].userloc != null) { delete docs[i].userloc; }
} }
// Add device sessions
const xagent = parent.wsagents[docs[i]._id];
if ((xagent != null) && (xagent.sessions != null)) { docs[i].sessions = xagent.sessions; }
r[meshid].push(docs[i]); r[meshid].push(docs[i]);
} }
try { ws.send(JSON.stringify({ action: 'nodes', responseid: command.responseid, nodes: r, tag: command.tag })); } catch (ex) { } try { ws.send(JSON.stringify({ action: 'nodes', responseid: command.responseid, nodes: r, tag: command.tag })); } catch (ex) { }

View File

@ -784,6 +784,25 @@ NoMeshesPanel img {
background-color:#44F; background-color:#44F;
} }
.deviceNotifyLargeDot {
text-align:center;
position:absolute;
right:10px;
top:140px;
width:40px;
height:40px;
color:#FFF;
padding:2px;
background-color:#00F;
border-radius:20px;
box-shadow: 2px 2px 10px black;
cursor:pointer;
}
.deviceNotifyLargeDot:hover {
background-color:#44F;
}
#xdevices { #xdevices {
max-height: calc(100vh - 242px); max-height: calc(100vh - 242px);
overflow-y: auto; overflow-y: auto;

View File

@ -485,7 +485,8 @@
<div id=p10html></div> <div id=p10html></div>
</td> </td>
<td style=width:20px></td> <td style=width:20px></td>
<td style=width:200px;vertical-align:top valign=top> <td style=width:200px;vertical-align:top;position:relative valign=top>
<img id="p10deviceNotify" onclick=showDeviceSessions() class=deviceNotifyLargeDot src=images/icon-relay-notify.png width=16 height=16>
<a href=# onclick=p10showiconselector()><img id=MainComputerImage></a> <a href=# onclick=p10showiconselector()><img id=MainComputerImage></a>
<div id=MainComputerState></div> <div id=MainComputerState></div>
</td> </td>
@ -2720,6 +2721,23 @@
} }
break; break;
} }
case 'devicesessions': {
// List of sessions for a given device
var node = getNodeFromId(message.event.nodeid);
if (node == null) break; // Unknown node
node.sessions = message.event.sessions;
if (node.sessions != null) {
for (var i in node.sessions) { if (Object.keys(node.sessions[i]).length == 0) { delete node.sessions[i]; } }
if (Object.keys(node.sessions).length == 0) { delete node.sessions; }
}
masterUpdate(4);
if ((currentNode != null) && (currentNode._id == message.event.nodeid)) { gotoDevice(currentNode._id, xxcurrentView, true); }
// If we are looking at the sessions dialog box for this device now, update it
if (xxdialogTag == ('SESSIONS-' + message.event.nodeid)) { showDeviceSessions(message.event.nodeid, true); }
break;
}
case 'stopped': { // Server is stopping. case 'stopped': { // Server is stopping.
// Disconnect // Disconnect
//console.log(message.msg); //console.log(message.msg);
@ -3404,13 +3422,21 @@
} }
// Show currently active sessions on this device // Show currently active sessions on this device
function showDeviceSessions(nodeid) { function showDeviceSessions(nodeid, force) {
if (xxdialogMode) return; if (xxdialogMode && !force) return;
var node = getNodeFromId(nodeid), x = ''; var node = null, x = '';
if (node == null) return; if (nodeid == null) { node = currentNode; } else { node = getNodeFromId(nodeid); }
console.log(node.sessions); if ((node == null) || (node.sessions == null)) { setDialogMode(0); return; }
x += addHtmlValue4("User", '1 session'); // TODO for (var i in node.sessions) {
setDialogMode(2, "Sessions - " + EscapeHtml(node.name), 1, null, x, 'SESSIONS-' + nodeid); if ((i == 'kvm') && (node.sessions.multidesk == null)) {
x += '<u>' + "Remote Desktop" + '</u>';
for (var j in node.sessions.kvm) { x += addHtmlValue4(getUserName(j), (node.sessions.kvm[j] == 1)?"1 session":nobreak(format("{0} sessions", node.sessions.kvm[j]))); }
} else if (i == 'multidesk') {
x += '<u>' + "Remote Desktop" + '</u>';
for (var j in node.sessions.multidesk) { x += addHtmlValue4(getUserName(j), ((node.sessions.multidesk[j] == 1)?"1 session":nobreak(format("{0} sessions", node.sessions.multidesk[j])))); }
}
}
if (x != '') setDialogMode(2, "Sessions - " + EscapeHtml(node.name), 1, null, x, 'SESSIONS-' + node._id);
} }
function toggleCollapseGroup(id, id2, type) { function toggleCollapseGroup(id, id2, type) {
@ -4950,6 +4976,9 @@
if (!currentNode || currentNode._id != node._id || refresh == true) { if (!currentNode || currentNode._id != node._id || refresh == true) {
currentNode = node; currentNode = node;
// Device Notification
QV('p10deviceNotify', currentNode.sessions != null);
// Add node name // Add node name
var nname = EscapeHtml(node.name), nnameEx; var nname = EscapeHtml(node.name), nnameEx;
if (nname.length == 0) { nname = '<i>' + "None" + '</i>'; } if (nname.length == 0) { nname = '<i>' + "None" + '</i>'; }
@ -12426,6 +12455,7 @@
function nobreak(x) { return x.split(' ').join('&nbsp;'); } function nobreak(x) { return x.split(' ').join('&nbsp;'); }
function pad2(num) { var s = '00' + num; return s.substr(s.length - 2); } function pad2(num) { var s = '00' + num; return s.substr(s.length - 2); }
function encodeURIComponentEx(txt) { return encodeURIComponent(txt).replace(/'/g,'%27'); }; function encodeURIComponentEx(txt) { return encodeURIComponent(txt).replace(/'/g,'%27'); };
function getUserName(userid) { if (users && users[userid] != null) return users[userid].name; return userid.split('/')[2]; }
</script> </script>
</body> </body>