diff --git a/agents/meshcore.js b/agents/meshcore.js index 96e08531..0077e145 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -1400,8 +1400,10 @@ function createMeshCore(agent) { // Send a metadata update to all desktop sessions var users = {}; - for (var i in this.httprequest.desktop.kvm.tunnels) { var userid = this.httprequest.desktop.kvm.tunnels[i].httprequest.userid; if (users[userid] == null) { users[userid] = 1; } else { users[userid]++; } } - for (var i in this.httprequest.desktop.kvm.tunnels) { this.httprequest.desktop.kvm.tunnels[i].write(JSON.stringify({ ctrlChannel: '102938', type: 'metadata', users: users })); } + 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) { } } + } this.end = function () { --this.desktop.kvm.connectionCount; @@ -1412,8 +1414,10 @@ function createMeshCore(agent) { // Send a metadata update to all desktop sessions var users = {}; - for (var i in this.httprequest.desktop.kvm.tunnels) { var userid = this.httprequest.desktop.kvm.tunnels[i].httprequest.userid; if (users[userid] == null) { users[userid] = 1; } else { users[userid]++; } } - for (var i in this.httprequest.desktop.kvm.tunnels) { this.httprequest.desktop.kvm.tunnels[i].write(JSON.stringify({ ctrlChannel: '102938', type: 'metadata', users: users })); } + 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) { } } + } // Unpipe the web socket try diff --git a/meshdesktopmultiplex.js b/meshdesktopmultiplex.js index 336c2808..4ea3be13 100644 --- a/meshdesktopmultiplex.js +++ b/meshdesktopmultiplex.js @@ -209,7 +209,7 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) { } // If this is the last viewer, disconnect the agent - if ((obj.viewers.length == 0) && (obj.agent != null)) { obj.agent.close(); dispose(); return true; } + if ((obj.viewers != null) && (obj.viewers.length == 0) && (obj.agent != null)) { obj.agent.close(); dispose(); return true; } // Send an updated list of all peers to all viewers obj.sendSessionMetadata(); diff --git a/views/default.handlebars b/views/default.handlebars index 7c9d4db5..85979d9c 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -6042,7 +6042,7 @@ function updateMetadata(conn, elementid) { var str = '', viewerCount = 0; if (conn && (conn.State == 3)) { - if (conn.metadata && conn.metadata.users) { for (var i in conn.metadata.users) { viewerCount++; } } + if (conn.metadata && conn.metadata.users) { for (var i in conn.metadata.users) { viewerCount += conn.metadata.users[i]; } } if (viewerCount > 1) { str = '' + format(", {0} watching", viewerCount) + ''; } } QH('deskmetadata', str);