mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
Close simulator connections on logout
This commit is contained in:
parent
b2bd914752
commit
4f5e8e6774
5 changed files with 29 additions and 10 deletions
|
@ -108,6 +108,8 @@ class App extends Component {
|
|||
localStorage.setItem('token', '');
|
||||
|
||||
this.props.router.push('/login');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// open connection to each required simulator
|
||||
|
|
|
@ -34,6 +34,16 @@ class SimulatorDataDataManager {
|
|||
}
|
||||
}
|
||||
|
||||
closeAll() {
|
||||
// close every open socket
|
||||
for (var key in this._sockets) {
|
||||
if (this._sockets.hasOwnProperty(key)) {
|
||||
this._sockets[key].close(4000);
|
||||
delete this._sockets[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onOpen(event, identifier, signals, firstOpen) {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'simulatorData/opened',
|
||||
|
@ -46,11 +56,12 @@ class SimulatorDataDataManager {
|
|||
onClose(event, identifier) {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'simulatorData/closed',
|
||||
identifier: identifier
|
||||
identifier: identifier,
|
||||
notification: (event.code !== 4000)
|
||||
});
|
||||
|
||||
// remove from list, keep null reference for flag detection
|
||||
this._sockets[identifier] = null;
|
||||
delete this._sockets[identifier];
|
||||
}
|
||||
|
||||
onMessage(event, identifier) {
|
||||
|
|
|
@ -62,7 +62,7 @@ class SimulationDataStore extends ReduceStore {
|
|||
// explicit call to prevent array copy
|
||||
this.__emitChange();
|
||||
} else {
|
||||
console.log('same sequence');
|
||||
console.log('same sequence ' + state[action.identifier].sequence + ' ' + action.data.sequence);
|
||||
}
|
||||
|
||||
return state;
|
||||
|
|
|
@ -74,14 +74,16 @@ class SimulatorStore extends ArrayStore {
|
|||
// update running state
|
||||
simulator.running = false;
|
||||
|
||||
NotificationsDataManager.addNotification({
|
||||
title: 'Simulator offline',
|
||||
message: 'Simulator \'' + simulator.name + '\' went offline.',
|
||||
level: 'info'
|
||||
});
|
||||
if (action.notification) {
|
||||
NotificationsDataManager.addNotification({
|
||||
title: 'Simulator offline',
|
||||
message: 'Simulator \'' + simulator.name + '\' went offline.',
|
||||
level: 'info'
|
||||
});
|
||||
|
||||
// restart requesting again
|
||||
SimulatorsDataManager.startRunningDetection(simulator);
|
||||
// restart requesting again
|
||||
SimulatorsDataManager.startRunningDetection(simulator);
|
||||
}
|
||||
|
||||
return this.updateElements(state, [ simulator ]);
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import { ReduceStore } from 'flux/utils';
|
|||
import AppDispatcher from '../app-dispatcher';
|
||||
import UsersDataManager from '../data-managers/users-data-manager';
|
||||
import NotificationsDataManager from '../data-managers/notifications-data-manager';
|
||||
import SimulatorDataDataManager from '../data-managers/simulator-data-data-manager';
|
||||
|
||||
class UserStore extends ReduceStore {
|
||||
constructor() {
|
||||
|
@ -33,6 +34,9 @@ class UserStore extends ReduceStore {
|
|||
return state;
|
||||
|
||||
case 'users/logout':
|
||||
// disconnect from all simulators
|
||||
SimulatorDataDataManager.closeAll();
|
||||
|
||||
// delete user and token
|
||||
return Object.assign({}, state, { token: null });
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue