mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
websocket: handle endpoint changes
This commit is contained in:
parent
302dac284e
commit
d7afa7efb9
2 changed files with 22 additions and 11 deletions
|
@ -32,24 +32,27 @@ class SimulatorDataDataManager {
|
|||
|
||||
open(endpoint, identifier) {
|
||||
// pass signals to onOpen callback
|
||||
if (this._sockets[identifier] != null) {
|
||||
if (this._sockets[identifier].url !== WebsocketAPI.getURL(endpoint)) {
|
||||
// replace connection, since endpoint changed
|
||||
this._sockets.close();
|
||||
if (this._sockets[identifier] != null)
|
||||
return; // already open?
|
||||
|
||||
this._sockets[identifier] = new WebsocketAPI(endpoint, { onOpen: (event) => this.onOpen(event, identifier), onClose: (event) => this.onClose(event, identifier), onMessage: (event) => this.onMessage(event, identifier), onError: (error) => this.onError(error, identifier) });
|
||||
this._sockets[identifier] = new WebsocketAPI(endpoint, { onOpen: (event) => this.onOpen(event, identifier, true), onClose: (event) => this.onClose(event, identifier), onMessage: (event) => this.onMessage(event, identifier), onError: (error) => this.onError(error, identifier) });
|
||||
}
|
||||
|
||||
update(endpoint, identifier) {
|
||||
if (this._sockets[identifier] != null) {
|
||||
if (this._sockets[identifier].endpoint !== endpoint) {
|
||||
this._sockets[identifier].close();
|
||||
this._sockets[identifier] = new WebsocketAPI(endpoint, { onOpen: (event) => this.onOpen(event, identifier, false), onClose: (event) => this.onClose(event, identifier), onMessage: (event) => this.onMessage(event, identifier), onError: (error) => this.onError(error, identifier) });
|
||||
}
|
||||
} else {
|
||||
this._sockets[identifier] = new WebsocketAPI(endpoint, { onOpen: (event) => this.onOpen(event, identifier, false), onClose: (event) => this.onClose(event, identifier), onMessage: (event) => this.onMessage(event, identifier), onError: (error) => this.onError(error, identifier) });
|
||||
}
|
||||
}
|
||||
|
||||
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];
|
||||
for (var identifier in this._sockets) {
|
||||
if (this._sockets.hasOwnProperty(identifier)) {
|
||||
this._sockets[identifier].close(4000);
|
||||
delete this._sockets[identifier];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,14 @@ class SimulatorStore extends ArrayStore {
|
|||
return super.reduce(state, action);
|
||||
|
||||
case 'simulators/edited':
|
||||
// connect to each simulator
|
||||
const simulator = action.data;
|
||||
const endpoint = _.get(simulator, 'properties.endpoint') || _.get(simulator, 'rawProperties.endpoint');
|
||||
|
||||
if (endpoint != null && endpoint !== '') {
|
||||
SimulatorDataDataManager.update(endpoint, simulator._id);
|
||||
}
|
||||
|
||||
return super.reduce(state, action);
|
||||
|
||||
case 'simulators/fetched':
|
||||
|
|
Loading…
Add table
Reference in a new issue