From e5008ee57f4f742eb8548a1d45d88a14c67207f3 Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Thu, 2 Jul 2020 14:17:47 +0800 Subject: [PATCH] FIX migrate project with websocket sidekiq --- src/forge/Main/Detail.js | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/forge/Main/Detail.js b/src/forge/Main/Detail.js index a177234ec..8f939b1be 100644 --- a/src/forge/Main/Detail.js +++ b/src/forge/Main/Detail.js @@ -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(); + } + } + }) }