Handle comms link closely whilst completing the initial connect

This commit is contained in:
Nick O'Leary 2016-06-30 00:44:06 +01:00
parent 6bc3f82afe
commit 6c00194d35
1 changed files with 14 additions and 9 deletions

View File

@ -88,16 +88,21 @@ function start() {
} }
} else { } else {
var completeConnection = function(userScope,sendAck) { var completeConnection = function(userScope,sendAck) {
if (!userScope || !Permissions.hasPermission(userScope,"status.read")) { try {
ws.send(JSON.stringify({auth:"fail"})); if (!userScope || !Permissions.hasPermission(userScope,"status.read")) {
ws.close(); ws.send(JSON.stringify({auth:"fail"}));
} else { ws.close();
pendingAuth = false; } else {
removePendingConnection(ws); pendingAuth = false;
activeConnections.push(ws); removePendingConnection(ws);
if (sendAck) { activeConnections.push(ws);
ws.send(JSON.stringify({auth:"ok"})); if (sendAck) {
ws.send(JSON.stringify({auth:"ok"}));
}
} }
} catch(err) {
// Just in case the socket closes before we attempt
// to send anything.
} }
} }
if (msg.auth) { if (msg.auth) {