feat: add websocket

This commit is contained in:
suxiaoxin 2017-08-25 17:19:34 +08:00
parent 22b59964b2
commit e0e364c4f0

View File

@ -61,27 +61,27 @@ class InterfaceEdit extends Component {
}
componentWillMount() {
// let domain = location.hostname + (location.port !== "" ? ":" + location.port : "");
// let s = new WebSocket('ws://' + domain + '/api/interface/solve_conflict?id=' + this.props.match.params.actionId);
// s.onopen = () => {
// this.WebSocket = s;
// }
let domain = location.hostname + (location.port !== "" ? ":" + location.port : "");
let s = new WebSocket('ws://' + domain + '/api/interface/solve_conflict?id=' + this.props.match.params.actionId);
s.onopen = () => {
this.WebSocket = s;
}
// s.onmessage = (e) => {
// let result = JSON.parse(e.data);
// if (result.errno === 0) {
// this.setState({
// curdata: result.data,
// status: 1
// })
// } else {
// this.setState({
// curdata: result.data,
// status: 2
// })
// }
s.onmessage = (e) => {
let result = JSON.parse(e.data);
if (result.errno === 0) {
this.setState({
curdata: result.data,
status: 1
})
} else {
this.setState({
curdata: result.data,
status: 2
})
}
// }
}
}