diff --git a/agents/meshcore.js b/agents/meshcore.js index 0077e145..7f66fd55 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -1403,6 +1403,7 @@ function createMeshCore(agent) { 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 { 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 () { @@ -1417,6 +1418,7 @@ function createMeshCore(agent) { 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 { 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 diff --git a/meshagent.js b/meshagent.js index edb2d34b..a0bc98e7 100644 --- a/meshagent.js +++ b/meshagent.js @@ -1327,6 +1327,13 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { }); 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': { if ((parent.parent.pluginHandler == null) || (typeof command.plugin != 'string')) break; 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 function ChangeAgentCoreInfo(command) { if (obj.agentInfo.capabilities & 0x40) return; diff --git a/meshdesktopmultiplex.js b/meshdesktopmultiplex.js index b4b3b6e2..fa5f0f8b 100644 --- a/meshdesktopmultiplex.js +++ b/meshdesktopmultiplex.js @@ -260,6 +260,9 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) { obj.startTime = null; } + // Send an updated list of all peers to all viewers + obj.sendSessionMetadata(); + 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 obj.sendSessionMetadata = function () { 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]++; } } } - obj.sendToAllViewers(JSON.stringify({ type: 'metadata', 'ctrlChannel': '102938', users: allUsers, startTime: obj.startTime })); + if (obj.viewers != null) { + 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 diff --git a/meshuser.js b/meshuser.js index 0d914a5d..b838425c 100644 --- a/meshuser.js +++ b/meshuser.js @@ -586,6 +586,10 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use 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]); } try { ws.send(JSON.stringify({ action: 'nodes', responseid: command.responseid, nodes: r, tag: command.tag })); } catch (ex) { } diff --git a/public/styles/style.css b/public/styles/style.css index 0ab7839e..e3bbe687 100644 --- a/public/styles/style.css +++ b/public/styles/style.css @@ -784,6 +784,25 @@ NoMeshesPanel img { 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 { max-height: calc(100vh - 242px); overflow-y: auto; diff --git a/views/default.handlebars b/views/default.handlebars index 5ac1fed3..c954afcf 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -485,7 +485,8 @@