[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:
parent
19388a8802
commit
b7be44de64
|
@ -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
|
// 1. update connection status bar
|
||||||
gs.get.connection = 0;
|
gs.get.connection = 0;
|
||||||
|
|
||||||
// 2. Check connection offline
|
// 2. Do nothing if offline (online trigger will do the job when online again)
|
||||||
let online = navigator.onLine;
|
if( !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 )
|
|
||||||
return;
|
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
|
// 4. Try to reconnect
|
||||||
return setTimeout(gs.get.content.ws_connect.bind(gs.get.content), gs.get.content.attempt.timeout);
|
return setTimeout(gs.get.content.ws_connect.bind(gs.get.content), gs.get.content.attempt.timeout);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ body > #WRAPPER > #CONNECTION_STATUS{
|
||||||
|
|
||||||
padding: .3em 0;
|
padding: .3em 0;
|
||||||
|
|
||||||
// background-color: #d83636;
|
background-color: #32ce80;
|
||||||
|
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
Loading…
Reference in New Issue