diff --git a/editor/js/comms.js b/editor/js/comms.js index 6edd9afa0..6e6015870 100644 --- a/editor/js/comms.js +++ b/editor/js/comms.js @@ -1,5 +1,5 @@ /** - * Copyright 2014, 2015 IBM Corp. + * Copyright 2014, 2016 IBM Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,10 @@ RED.comms = (function() { var ws; var pendingAuth = false; var reconnectAttempts = 0; + var active = false; function connectWS() { + active = true; var path = location.hostname; var port = location.port; if (port.length !== 0) { @@ -63,9 +65,17 @@ RED.comms = (function() { } ws.onmessage = function(event) { var msg = JSON.parse(event.data); - if (pendingAuth && msg.auth == "ok") { - pendingAuth = false; - completeConnection(); + if (pendingAuth && msg.auth) { + if (msg.auth === "ok") { + pendingAuth = false; + completeConnection(); + } else if (msg.auth === "fail") { + // anything else is an error... + active = false; + RED.user.login({updateMenu:true},function() { + connectWS(); + }) + } } else if (msg.topic) { for (var t in subscriptions) { if (subscriptions.hasOwnProperty(t)) { @@ -83,6 +93,9 @@ RED.comms = (function() { } }; ws.onclose = function() { + if (!active) { + return; + } if (clearErrorTimer) { clearTimeout(clearErrorTimer); clearErrorTimer = null; diff --git a/editor/js/user.js b/editor/js/user.js index d2968a550..a079caf63 100644 --- a/editor/js/user.js +++ b/editor/js/user.js @@ -99,6 +99,9 @@ RED.user = (function() { }).done(function(data,textStatus,xhr) { RED.settings.set("auth-tokens",data); $("#node-dialog-login").dialog('destroy').remove(); + if (opts.updateMenu) { + updateUserMenu(); + } done(); }).fail(function(jqXHR,textStatus,errorThrown) { RED.settings.remove("auth-tokens"); @@ -133,7 +136,7 @@ RED.user = (function() { } function updateUserMenu() { - $("#usermenu-submenu li").remove(); + $("#btn-usermenu-submenu li").remove(); if (RED.settings.user.anonymous) { RED.menu.addItem("btn-usermenu",{ id:"usermenu-item-login", @@ -163,8 +166,6 @@ RED.user = (function() { } - - function init() { if (RED.settings.user) { if (!RED.settings.editorTheme || !RED.settings.editorTheme.hasOwnProperty("userMenu")) { diff --git a/red/api/comms.js b/red/api/comms.js index bd898e178..171e42860 100644 --- a/red/api/comms.js +++ b/red/api/comms.js @@ -89,6 +89,7 @@ function start() { } else { var completeConnection = function(userScope,sendAck) { if (!userScope || !Permissions.hasPermission(userScope,"status.read")) { + ws.send(JSON.stringify({auth:"fail"})); ws.close(); } else { pendingAuth = false;