1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Stop lost connection message bouncing when not authed

This commit is contained in:
Nick O'Leary 2014-12-08 16:25:38 +00:00
parent 9bbe0799bd
commit f5d7903ecb
2 changed files with 9 additions and 3 deletions

View File

@ -17,6 +17,8 @@
RED.comms = (function() { RED.comms = (function() {
var errornotification = null; var errornotification = null;
var clearErrorTimer = null;
var subscriptions = {}; var subscriptions = {};
var ws; var ws;
function connectWS() { function connectWS() {
@ -26,8 +28,10 @@ RED.comms = (function() {
ws = new WebSocket(path); ws = new WebSocket(path);
ws.onopen = function() { ws.onopen = function() {
if (errornotification) { if (errornotification) {
errornotification.close(); clearErrorTimer = setTimeout(function() {
errornotification = null; errornotification.close();
errornotification = null;
},1000);
} }
var auth_tokens = RED.settings.get("auth-tokens"); var auth_tokens = RED.settings.get("auth-tokens");
if (auth_tokens) { if (auth_tokens) {
@ -60,6 +64,9 @@ RED.comms = (function() {
ws.onclose = function() { ws.onclose = function() {
if (errornotification == null) { if (errornotification == null) {
errornotification = RED.notify("<b>Error</b>: Lost connection to server","error",true); errornotification = RED.notify("<b>Error</b>: Lost connection to server","error",true);
} else if (clearErrorTimer) {
clearTimeout(clearErrorTimer);
clearErrorTimer = null;
} }
setTimeout(connectWS,1000); setTimeout(connectWS,1000);
} }

View File

@ -28,7 +28,6 @@ var bearerStrategy = function (accessToken, done) {
Tokens.get(accessToken).then(function(token) { Tokens.get(accessToken).then(function(token) {
if (token) { if (token) {
Users.get(token.user).then(function(user) { Users.get(token.user).then(function(user) {
console.log(user);
if (user) { if (user) {
done(null,{username:user.username},{scope:token.scope}); done(null,{username:user.username},{scope:token.scope});
} else { } else {