FIX migrate project with websocket sidekiq

This commit is contained in:
Jasder 2020-07-02 14:17:47 +08:00
parent 7d4f7e9f1f
commit e5008ee57f
1 changed files with 36 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import React, { Component } from 'react';
import React, { Component, Fragment } from 'react';
import { Spin, Tooltip } from 'antd';
import { Link, Route, Switch } from 'react-router-dom';
@ -154,6 +154,30 @@ class Detail extends Component {
this.getDetail();
}
canvasChannel = () => {
const actioncable = require("actioncable")
var project = this.state.project
var cable = actioncable.createConsumer('ws:/192.168.2.59:3000/cable');
this.canvasChannel1 = cable.subscriptions.create({
channel: `MirrorProjectChannel`,
id: project && project.identifier
},{
connected: () => {
console.log("###### channel connected! ######")
// this.getProject()
},
disconnected: () => {},
received: data => {
console.log(`###### ---received data--- ######`);
console.log(data);
if (data ) {
this.getDetail()
cable.subscriptions.consumer.disconnect();
}
}
})
}
componentDidUpdate = (prevState) => {
if ((prevState.match.params.projectsId !== this.props.match.params.projectsId)) {
this.getProject();
@ -165,9 +189,17 @@ class Detail extends Component {
const { projectsId } = this.props.match.params;
const url = `/projects/${projectsId}/simple.json`;
axios.get(url).then((result) => {
this.setState({
project: result.data
})
if(result && result.data){
this.setState({
project: result.data
})
if (result.data.type != 0 && result.data.mirror_status == 1){
console.log("--------start channel --------");
this.canvasChannel();
}
}
})
}