[lib.content-controller] listen to 'online' and 'offline' events not to attempt to reconnect while 'offline' + reconnect automatically when back 'online'

This commit is contained in:
xdrm-brackets 2018-04-04 15:30:43 +02:00
parent 19388a8802
commit b7be44de64
2 changed files with 15 additions and 6 deletions

View File

@ -17,6 +17,11 @@ export default class ContentController{
}
};
/* (2) Manage updates in connection status (ONLINE - OFFLINE) */
window.addEventListener('online', this.ws_connect.bind(this));
window.addEventListener('offline', function(){ gs.get.connection = 0; }); // connection status bar
}
@ -210,13 +215,17 @@ export default class ContentController{
// 1. update connection status bar
gs.get.connection = 0;
// 2. Check connection offline
let online = navigator.onLine;
// 3. do not reconnect if max attempt exceeded (and if not offline of course)
if( online && gs.get.content.attempt.count >= gs.get.content.attempt.max-1 )
// 2. Do nothing if offline (online trigger will do the job when online again)
if( !navigator.onLine )
return;
// 3. if max attempt exceeded -> logout user
if( gs.get.content.attempt.count >= gs.get.content.attempt.max-1 ){
auth.token = null;
gs.get.refresh();
return;
}
// 4. Try to reconnect
return setTimeout(gs.get.content.ws_connect.bind(gs.get.content), gs.get.content.attempt.timeout);
}

View File

@ -50,7 +50,7 @@ body > #WRAPPER > #CONNECTION_STATUS{
padding: .3em 0;
// background-color: #d83636;
background-color: #32ce80;
font-size: 1em;
text-align: center;