1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

Add relative endpoint for nodes

This commit is contained in:
Markus Grigull 2017-09-24 15:48:13 +02:00
parent 884f59369a
commit 94003207f3
6 changed files with 57 additions and 21 deletions

View file

@ -20,9 +20,9 @@
******************************************************************************/
class WebsocketAPI {
addSocket(endpoint, callbacks) {
addSocket(node, callbacks) {
// create web socket client
var socket = new WebSocket(this.getURL(endpoint), 'live');
const socket = new WebSocket(this.getURL(node), 'live');
socket.binaryType = 'arraybuffer';
// register callbacks
@ -34,8 +34,12 @@ class WebsocketAPI {
return socket;
}
getURL(endpoint) {
return 'ws://' + endpoint;
getURL(node) {
if (node.relativeEndpoint) {
return 'ws://' + window.location.host + '/' + node.endpoint;
} else {
return 'ws://' + node.endpoint;
}
}
}

View file

@ -20,7 +20,7 @@
******************************************************************************/
import React from 'react';
import { FormGroup, FormControl, ControlLabel } from 'react-bootstrap';
import { FormGroup, FormControl, ControlLabel, Checkbox } from 'react-bootstrap';
import Dialog from './dialog';
@ -35,6 +35,7 @@ class NewNodeDialog extends React.Component {
endpoint: '',
config: {},
simulators: [],
relativeEndpoint: false,
_id: ''
};
}
@ -50,11 +51,15 @@ class NewNodeDialog extends React.Component {
}
handleChange(e) {
this.setState({ [e.target.id]: e.target.value });
if (e.target.type === 'checkbox') {
this.setState({ [e.target.id]: e.target.checked });
} else {
this.setState({ [e.target.id]: e.target.value });
}
}
resetState() {
this.setState({ name: this.props.node.name, endpoint: this.props.node.endpoint, config: this.props.node.config, simulators: this.props.node.simulators, _id: this.props.node._id });
this.setState({ name: this.props.node.name, endpoint: this.props.node.endpoint, config: this.props.node.config, simulators: this.props.node.simulators, _id: this.props.node._id, relativeEndpoint: this.props.node.relativeEndpoint });
}
validateForm(target) {
@ -91,6 +96,9 @@ class NewNodeDialog extends React.Component {
<FormControl type="text" placeholder="Enter endpoint" value={this.state.endpoint} onChange={(e) => this.handleChange(e)} />
<FormControl.Feedback />
</FormGroup>
<FormGroup>
<Checkbox id="relativeEndpoint" checked={this.state.relativeEndpoint} onChange={e => this.handleChange(e)}>Relative Endpoint</Checkbox>
</FormGroup>
</form>
</Dialog>
);

View file

@ -20,7 +20,7 @@
******************************************************************************/
import React from 'react';
import { FormGroup, FormControl, ControlLabel } from 'react-bootstrap';
import { FormGroup, FormControl, ControlLabel, Checkbox } from 'react-bootstrap';
import Dialog from './dialog';
@ -34,7 +34,8 @@ class ImportNodeDialog extends React.Component {
this.state = {
name: '',
endpoint: '',
simulators: []
simulators: [],
relativeEndpoint: false
};
}
@ -47,11 +48,15 @@ class ImportNodeDialog extends React.Component {
}
handleChange(e) {
this.setState({ [e.target.id]: e.target.value });
if (e.target.type === 'checkbox') {
this.setState({ [e.target.id]: e.target.checked });
} else {
this.setState({ [e.target.id]: e.target.value });
}
}
resetState() {
this.setState({ name: '', endpoint: '' });
this.setState({ name: '', endpoint: '', relativeEndpoint: false });
this.imported = false;
}
@ -71,7 +76,7 @@ class ImportNodeDialog extends React.Component {
// read simulator
const node = JSON.parse(event.target.result);
self.imported = true;
self.setState({ name: node.name, endpoint: node.endpoint, simulators: node.simulators });
self.setState({ name: node.name, endpoint: node.endpoint, simulators: node.simulators, relativeEndpoint: node.relativeEndpoint });
};
reader.readAsText(file);
@ -116,6 +121,9 @@ class ImportNodeDialog extends React.Component {
<FormControl readOnly={!this.imported} type="text" placeholder="Enter endpoint" value={this.state.endpoint} onChange={(e) => this.handleChange(e)} />
<FormControl.Feedback />
</FormGroup>
<FormGroup>
<Checkbox id="relativeEndpoint" checked={this.state.relativeEndpoint} onChange={e => this.handleChange(e)}>Relative Endpoint</Checkbox>
</FormGroup>
</form>
</Dialog>
);

View file

@ -20,7 +20,7 @@
******************************************************************************/
import React from 'react';
import { FormGroup, FormControl, ControlLabel } from 'react-bootstrap';
import { FormGroup, FormControl, ControlLabel, Checkbox } from 'react-bootstrap';
import Dialog from './dialog';
@ -34,7 +34,8 @@ class NewNodeDialog extends React.Component {
name: '',
endpoint: '',
config: {},
simulators: []
simulators: [],
relativeEndpoint: false
};
}
@ -49,11 +50,15 @@ class NewNodeDialog extends React.Component {
}
handleChange(e) {
this.setState({ [e.target.id]: e.target.value });
if (e.target.type === 'checkbox') {
this.setState({ [e.target.id]: e.target.checked });
} else {
this.setState({ [e.target.id]: e.target.value });
}
}
resetState() {
this.setState({ name: '', endpoint: '', config: {}, simulators: [] });
this.setState({ name: '', endpoint: '', config: {}, simulators: [], relativeEndpoint: false });
}
validateForm(target) {
@ -90,6 +95,9 @@ class NewNodeDialog extends React.Component {
<FormControl type="text" placeholder="Enter endpoint" value={this.state.endpoint} onChange={(e) => this.handleChange(e)} />
<FormControl.Feedback />
</FormGroup>
<FormGroup>
<Checkbox id="relativeEndpoint" checked={this.state.relativeEndpoint} onChange={e => this.handleChange(e)}>Relative Endpoint</Checkbox>
</FormGroup>
</form>
</Dialog>
);

View file

@ -28,8 +28,16 @@ class NodesDataManager extends RestDataManager {
super('node', '/nodes');
}
getURL(node) {
if (node.relativeEndpoint) {
return 'http://' + window.location.host + '/' + node.endpoint + '/api/v1';
} else {
return 'http://' + node.endpoint + '/api/v1';
}
}
getSimulators(node) {
RestAPI.post('http://' + node.endpoint + '/api/v1', {
RestAPI.post(this.getURL(node), {
action: 'nodes',
id: node._id
}).then(response => {

View file

@ -30,18 +30,18 @@ class SimulatorDataDataManager {
open(endpoint, node) {
// pass signals to onOpen callback
if (this._sockets[node._id] != null) {
if (this._sockets[node._id].url !== WebsocketAPI.getURL(endpoint)) {
if (this._sockets[node._id].url !== WebsocketAPI.getURL(node)) {
// replace connection, since endpoint changed
this._sockets.close();
this._sockets[node._id] = WebsocketAPI.addSocket(endpoint, { onOpen: (event) => this.onOpen(event, node), onClose: (event) => this.onClose(event, node), onMessage: (event) => this.onMessage(event, node) });
this._sockets[node._id] = WebsocketAPI.addSocket(node, { onOpen: (event) => this.onOpen(event, node), onClose: (event) => this.onClose(event, node), onMessage: (event) => this.onMessage(event, node) });
}
} else {
// set flag if a socket to this simulator was already create before
if (this._sockets[node._id] === null) {
this._sockets[node._id] = WebsocketAPI.addSocket(endpoint, { onOpen: (event) => this.onOpen(event, node, false), onClose: (event) => this.onClose(event, node), onMessage: (event) => this.onMessage(event, node) });
this._sockets[node._id] = WebsocketAPI.addSocket(node, { onOpen: (event) => this.onOpen(event, node, false), onClose: (event) => this.onClose(event, node), onMessage: (event) => this.onMessage(event, node) });
} else {
this._sockets[node._id] = WebsocketAPI.addSocket(endpoint, { onOpen: (event) => this.onOpen(event, node, true), onClose: (event) => this.onClose(event, node), onMessage: (event) => this.onMessage(event, node) });
this._sockets[node._id] = WebsocketAPI.addSocket(node, { onOpen: (event) => this.onOpen(event, node, true), onClose: (event) => this.onClose(event, node), onMessage: (event) => this.onMessage(event, node) });
}
}
}