ws心跳检查
This commit is contained in:
@@ -42,7 +42,7 @@ export function WsConnect(url, agentData, successCallback, errCallback) {
|
||||
this.lockReconnect = true;
|
||||
this.wsCreateHandler && clearTimeout(this.wsCreateHandler);
|
||||
// 关闭心跳检查
|
||||
// heartCheck.stop();
|
||||
heartCheck.stop();
|
||||
}
|
||||
};
|
||||
const initWsEventHandle = () => {
|
||||
@@ -50,13 +50,13 @@ export function WsConnect(url, agentData, successCallback, errCallback) {
|
||||
// 连接成功
|
||||
this.wsObj.onopen = (event) => {
|
||||
onWsOpen(event);
|
||||
// heartCheck.start();
|
||||
heartCheck.start();
|
||||
};
|
||||
|
||||
// 监听服务器端返回的信息
|
||||
this.wsObj.onmessage = (event) => {
|
||||
onWsMessage(event);
|
||||
// heartCheck.start();
|
||||
heartCheck.start();
|
||||
};
|
||||
|
||||
this.wsObj.onclose = (event) => {
|
||||
@@ -123,7 +123,7 @@ export function WsConnect(url, agentData, successCallback, errCallback) {
|
||||
if (this.lockReconnect) {
|
||||
return;
|
||||
}
|
||||
writeToScreen("3秒后重连");
|
||||
writeToScreen("5秒后重连");
|
||||
this.lockReconnect = true;
|
||||
// 没连接上会一直重连,设置延迟避免请求过多
|
||||
this.wsCreateHandler && clearTimeout(this.wsCreateHandler);
|
||||
@@ -132,10 +132,40 @@ export function WsConnect(url, agentData, successCallback, errCallback) {
|
||||
this.createWebSoket();
|
||||
this.lockReconnect = false;
|
||||
writeToScreen("重连完成");
|
||||
}, 3000);
|
||||
}, 5000);
|
||||
};
|
||||
|
||||
// 心跳检查(看看websocket是否还在正常连接中)
|
||||
// 心跳检查(看看websocket是否还在正常连接中,不需要服务端返回,单向的)
|
||||
let _this = this
|
||||
let heartCheck = {
|
||||
timeout: 55000,
|
||||
timeoutObj: null,
|
||||
// 重启
|
||||
reset() {
|
||||
clearTimeout(this.timeoutObj);
|
||||
this.start();
|
||||
},
|
||||
// 停止
|
||||
stop() {
|
||||
clearTimeout(this.timeoutObj);
|
||||
},
|
||||
// 开启定时器
|
||||
start() {
|
||||
this.timeoutObj && clearTimeout(this.timeoutObj);
|
||||
this.timeoutObj = setTimeout(() => {
|
||||
writeToScreen("心跳检查,发送ping到后台");
|
||||
try {
|
||||
const datas = { ping: true };
|
||||
_this.wsObj.send(JSON.stringify(datas));
|
||||
} catch (err) {
|
||||
writeToScreen("发送ping异常");
|
||||
}
|
||||
}, this.timeout);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
// 心跳检查(看看websocket是否还在正常连接中,和服务端通信,双向的)
|
||||
// let heartCheck = {
|
||||
// timeout: 15000,
|
||||
// timeoutObj: null,
|
||||
@@ -160,7 +190,7 @@ export function WsConnect(url, agentData, successCallback, errCallback) {
|
||||
// writeToScreen("心跳检查,发送ping到后台");
|
||||
// try {
|
||||
// const datas = { ping: true };
|
||||
// this.wsObj.send(JSON.stringify(datas));
|
||||
// _this.wsObj.send(JSON.stringify(datas));
|
||||
// } catch (err) {
|
||||
// writeToScreen("发送ping异常");
|
||||
// }
|
||||
|
||||
@@ -6,28 +6,33 @@ import store from "@/store";
|
||||
const timestr = new Date().getTime()
|
||||
const dcsConn = new WsConnect(
|
||||
// websocket地址
|
||||
process.env.VUE_APP_Socket_Dcs_API + '/xc-screen/websocket/dcsmsg'+timestr,
|
||||
process.env.VUE_APP_Socket_Dcs_API + '/xc-screen/websocket/dcsmsg' + timestr,
|
||||
// 传递给后台的数据
|
||||
'',
|
||||
(data) => {
|
||||
// console.log('dcs成功的回调函数, 接收到的data数据: ', data)
|
||||
let msgData = JSON.parse(data)
|
||||
let msgData = {}
|
||||
try {
|
||||
msgData = JSON.parse(data)
|
||||
} catch (error) {
|
||||
console.log("websocket: [unable to msgData] : ", data);
|
||||
}
|
||||
if (msgData == null) return;
|
||||
switch (msgData?.type) {
|
||||
case "FanFrequencyInfo": {
|
||||
store.dispatch({type: "websocket/setFanFrequencyInfo", payload:msgData.data.FanFrequencyInfo})
|
||||
store.dispatch({ type: "websocket/setFanFrequencyInfo", payload: msgData.data.FanFrequencyInfo })
|
||||
break;
|
||||
}
|
||||
case "KilnInfo": {
|
||||
store.dispatch({type: "websocket/setKilnInfo", payload: msgData.data})
|
||||
store.dispatch({ type: "websocket/setKilnInfo", payload: msgData.data })
|
||||
break;
|
||||
}
|
||||
case "GasInfo": {
|
||||
store.dispatch({type: "websocket/setGasInfo", payload: msgData.data})
|
||||
store.dispatch({ type: "websocket/setGasInfo", payload: msgData.data })
|
||||
break;
|
||||
}
|
||||
case "SumGasInfo": {
|
||||
store.dispatch({type: "websocket/setSumGasInfo", payload: msgData.data})
|
||||
store.dispatch({ type: "websocket/setSumGasInfo", payload: msgData.data })
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -39,16 +44,20 @@ const dcsConn = new WsConnect(
|
||||
)
|
||||
// ISRA
|
||||
const mesIsra = new WsConnect(
|
||||
process.env.VUE_APP_Socket_API + '/websocket/message?userId=KILN'+timestr,
|
||||
process.env.VUE_APP_Socket_API + '/websocket/message?userId=KILN' + timestr,
|
||||
'',
|
||||
(data) => {
|
||||
// console.log('mes ISRA成功的回调函数, 接收到的data数据: ', data)
|
||||
let msgData = JSON.parse(data)
|
||||
// console.log(msgData)
|
||||
let msgData = {}
|
||||
try {
|
||||
msgData = JSON.parse(data)
|
||||
} catch (error) {
|
||||
console.log("websocket: [unable to msgData] : ", data);
|
||||
}
|
||||
if (msgData == null) return;
|
||||
switch (msgData?.type) {
|
||||
case "israKiln": {
|
||||
store.dispatch({type: "websocket/setIsraKiln", payload:msgData.detData.dayStatistic})
|
||||
store.dispatch({ type: "websocket/setIsraKiln", payload: msgData.detData.dayStatistic })
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -61,15 +70,20 @@ const mesIsra = new WsConnect(
|
||||
|
||||
// 原料 MA
|
||||
const mesMA = new WsConnect(
|
||||
process.env.VUE_APP_Socket_API + '/websocket/message?userId=MA'+timestr,
|
||||
process.env.VUE_APP_Socket_API + '/websocket/message?userId=MA' + timestr,
|
||||
'',
|
||||
(data) => {
|
||||
// console.log('mes 原料成功的回调函数, 接收到的data数据: ', data)
|
||||
let msgData = JSON.parse(data)
|
||||
let msgData = {}
|
||||
try {
|
||||
msgData = JSON.parse(data)
|
||||
} catch (error) {
|
||||
console.log("websocket: [unable to msgData] : ", data);
|
||||
}
|
||||
if (msgData == null) return;
|
||||
switch (msgData?.type) {
|
||||
case "material": {
|
||||
store.dispatch({type: "websocket/setMaterial", payload:msgData.data})
|
||||
store.dispatch({ type: "websocket/setMaterial", payload: msgData.data })
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -82,25 +96,30 @@ const mesMA = new WsConnect(
|
||||
// 能耗 EN
|
||||
const mesEN = new WsConnect(
|
||||
// websocket地址
|
||||
process.env.VUE_APP_Socket_API + '/websocket/message?userId=ENERGY'+timestr,
|
||||
process.env.VUE_APP_Socket_API + '/websocket/message?userId=ENERGY' + timestr,
|
||||
// 传递给后台的数据
|
||||
'',
|
||||
// 成功拿到后台返回的数据的回调函数
|
||||
(data) => {
|
||||
// console.log('mes 能耗成功的回调函数, 接收到的data数据: ', data)
|
||||
let msgData = JSON.parse(data)
|
||||
let msgData = {}
|
||||
try {
|
||||
msgData = JSON.parse(data)
|
||||
} catch (error) {
|
||||
console.log("websocket: [unable to msgData] : ", data);
|
||||
}
|
||||
if (msgData == null) return;
|
||||
switch (msgData?.type) {
|
||||
case "EnergyInfo": {
|
||||
store.dispatch({type: "websocket/setEnergyInfo", payload:msgData.data})
|
||||
store.dispatch({ type: "websocket/setEnergyInfo", payload: msgData.data })
|
||||
break;
|
||||
}
|
||||
case "EnergyTrend": {
|
||||
store.dispatch({type: "websocket/setEnergyTrend", payload:msgData.data})
|
||||
store.dispatch({ type: "websocket/setEnergyTrend", payload: msgData.data })
|
||||
break;
|
||||
}
|
||||
case "EnergyMonitoring": {
|
||||
store.dispatch({type: "websocket/setEnergyMonitoring", payload:msgData.data})
|
||||
store.dispatch({ type: "websocket/setEnergyMonitoring", payload: msgData.data })
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -114,23 +133,30 @@ const mesEN = new WsConnect(
|
||||
// 烟气 GAS
|
||||
const mesGAS = new WsConnect(
|
||||
// websocket地址
|
||||
process.env.VUE_APP_Socket_API + '/websocket/message?userId=GAS'+timestr,
|
||||
process.env.VUE_APP_Socket_API + '/websocket/message?userId=GAS' + timestr,
|
||||
// 传递给后台的数据
|
||||
'',
|
||||
// 成功拿到后台返回的数据的回调函数
|
||||
(data) => {
|
||||
// console.log('mes 烟气成功的回调函数, 接收到的data数据: ', data)
|
||||
let msgData = JSON.parse(data)
|
||||
let msgData = {}
|
||||
try {
|
||||
msgData = JSON.parse(data)
|
||||
} catch (error) {
|
||||
console.log("websocket: [unable to msgData] : ", data);
|
||||
}
|
||||
if (msgData == null) return;
|
||||
switch (msgData?.type) {
|
||||
case "exhaustGas": {
|
||||
store.dispatch({type: "websocket/setExhaustGasInfo", payload:msgData.realtime})
|
||||
store.dispatch({type: "websocket/setExhaustGasChart", payload:{
|
||||
dayTrend: msgData.dayTrend,
|
||||
weekTrend: msgData.weekTrend,
|
||||
monthTrend: msgData.monthTrend,
|
||||
yearTrend: msgData.yearTrend,
|
||||
}})
|
||||
store.dispatch({ type: "websocket/setExhaustGasInfo", payload: msgData.realtime })
|
||||
store.dispatch({
|
||||
type: "websocket/setExhaustGasChart", payload: {
|
||||
dayTrend: msgData.dayTrend,
|
||||
weekTrend: msgData.weekTrend,
|
||||
monthTrend: msgData.monthTrend,
|
||||
yearTrend: msgData.yearTrend,
|
||||
}
|
||||
})
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -145,23 +171,30 @@ const mesGAS = new WsConnect(
|
||||
// 缺陷分类/统计 IS
|
||||
const mesIS = new WsConnect(
|
||||
// websocket地址
|
||||
process.env.VUE_APP_Socket_API + '/websocket/message?userId=IS'+timestr,
|
||||
process.env.VUE_APP_Socket_API + '/websocket/message?userId=IS' + timestr,
|
||||
// 传递给后台的数据
|
||||
'',
|
||||
// 成功拿到后台返回的数据的回调函数
|
||||
(data) => {
|
||||
// console.log('mes 缺陷成功的回调函数, 接收到的data数据: ', data)
|
||||
let msgData = JSON.parse(data)
|
||||
let msgData = {}
|
||||
try {
|
||||
msgData = JSON.parse(data)
|
||||
} catch (error) {
|
||||
console.log("websocket: [unable to msgData] : ", data);
|
||||
}
|
||||
if (msgData == null) return;
|
||||
switch (msgData?.type) {
|
||||
case "isra": {
|
||||
store.dispatch({type: "websocket/setDefectChart", payload:{
|
||||
checkType: msgData.detData.checkType,
|
||||
dayStatistic: msgData.detData.dayStatistic,
|
||||
weekStatistic: msgData.detData.weekStatistic,
|
||||
monthStatistic: msgData.detData.monthStatistic,
|
||||
yearStatistic: msgData.detData.yearStatistic,
|
||||
}})
|
||||
store.dispatch({
|
||||
type: "websocket/setDefectChart", payload: {
|
||||
checkType: msgData.detData.checkType,
|
||||
dayStatistic: msgData.detData.dayStatistic,
|
||||
weekStatistic: msgData.detData.weekStatistic,
|
||||
monthStatistic: msgData.detData.monthStatistic,
|
||||
yearStatistic: msgData.detData.yearStatistic,
|
||||
}
|
||||
})
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -176,29 +209,34 @@ const mesIS = new WsConnect(
|
||||
// 深加工生产运行驾驶舱(除能源) SJG
|
||||
const mesSJG = new WsConnect(
|
||||
// websocket地址
|
||||
process.env.VUE_APP_Socket_API + '/websocket/message?userId=SJG'+timestr,
|
||||
process.env.VUE_APP_Socket_API + '/websocket/message?userId=SJG' + timestr,
|
||||
// 传递给后台的数据
|
||||
'',
|
||||
// 成功拿到后台返回的数据的回调函数
|
||||
(data) => {
|
||||
// console.log('mes 产线产量及良品率成功的回调函数, 接收到的data数据: ', data)
|
||||
let msgData = JSON.parse(data)
|
||||
let msgData = {}
|
||||
try {
|
||||
msgData = JSON.parse(data)
|
||||
} catch (error) {
|
||||
console.log("websocket: [unable to msgData] : ", data);
|
||||
}
|
||||
if (msgData == null) return;
|
||||
switch (msgData?.type) {
|
||||
case "productline": {
|
||||
store.dispatch({type: "websocket/setProductline", payload:msgData.detData})
|
||||
store.dispatch({ type: "websocket/setProductline", payload: msgData.detData })
|
||||
break;
|
||||
}
|
||||
case "equipment": {
|
||||
store.dispatch({type: "websocket/setSJGEq", payload:msgData.detData})
|
||||
store.dispatch({ type: "websocket/setSJGEq", payload: msgData.detData })
|
||||
break;
|
||||
}
|
||||
case "order": {
|
||||
store.dispatch({type: "websocket/setWorkOrder", payload:msgData.detData})
|
||||
store.dispatch({ type: "websocket/setWorkOrder", payload: msgData.detData })
|
||||
break;
|
||||
}
|
||||
case "defectSum": {
|
||||
store.dispatch({type: "websocket/setDefectSum", payload:msgData.detData})
|
||||
store.dispatch({ type: "websocket/setDefectSum", payload: msgData.detData })
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -213,18 +251,23 @@ const mesSJG = new WsConnect(
|
||||
// 订单完成情况 OV
|
||||
const mesOV = new WsConnect(
|
||||
// websocket地址
|
||||
process.env.VUE_APP_Socket_API + '/websocket/message?userId=OV'+timestr,
|
||||
process.env.VUE_APP_Socket_API + '/websocket/message?userId=OV' + timestr,
|
||||
// 'ws://192.168.0.33:48082/websocket/message?userId=OV'+timestr,
|
||||
// 传递给后台的数据
|
||||
'',
|
||||
// 成功拿到后台返回的数据的回调函数
|
||||
(data) => {
|
||||
// console.log('mes 产线产量及良品率成功的回调函数, 接收到的data数据: ', data)
|
||||
let msgData = JSON.parse(data)
|
||||
let msgData = {}
|
||||
try {
|
||||
msgData = JSON.parse(data)
|
||||
} catch (error) {
|
||||
console.log("websocket: [unable to msgData] : ", data);
|
||||
}
|
||||
if (msgData == null) return;
|
||||
switch (msgData?.type) {
|
||||
case "order": {
|
||||
store.dispatch({type: "websocket/setOrder", payload:msgData.detData})
|
||||
store.dispatch({ type: "websocket/setOrder", payload: msgData.detData })
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -239,35 +282,39 @@ const mesOV = new WsConnect(
|
||||
// 本日生产良品率 CUTTING
|
||||
const mesCUTTING = new WsConnect(
|
||||
// websocket地址
|
||||
process.env.VUE_APP_Socket_API + '/websocket/message?userId=CUTTING'+timestr,
|
||||
process.env.VUE_APP_Socket_API + '/websocket/message?userId=CUTTING' + timestr,
|
||||
// 传递给后台的数据
|
||||
'',
|
||||
// 成功拿到后台返回的数据的回调函数
|
||||
(data) => {
|
||||
// console.log('mes 产线产量及良品率成功的回调函数, 接收到的data数据: ', data)
|
||||
let msgData = JSON.parse(data)
|
||||
let msgData = {}
|
||||
try {
|
||||
msgData = JSON.parse(data)
|
||||
} catch (error) {
|
||||
console.log("websocket: [unable to msgData] : ", data);
|
||||
}
|
||||
if (msgData == null) return;
|
||||
console.log(msgData)
|
||||
switch (msgData?.type) {
|
||||
case "cutting": {
|
||||
if (msgData?.name === 'table') {
|
||||
store.dispatch({type: "websocket/setYieldRateTable", payload:msgData.data})
|
||||
store.dispatch({ type: "websocket/setYieldRateTable", payload: msgData.data })
|
||||
return
|
||||
}
|
||||
if (msgData?.dateType === 'day') {
|
||||
store.dispatch({type: "websocket/setCutChartDay", payload:msgData.detData})
|
||||
store.dispatch({ type: "websocket/setCutChartDay", payload: msgData.detData })
|
||||
return
|
||||
}
|
||||
if (msgData?.dateType === 'weekly') {
|
||||
store.dispatch({type: "websocket/setCutChartWeek", payload:msgData.detData})
|
||||
store.dispatch({ type: "websocket/setCutChartWeek", payload: msgData.detData })
|
||||
return
|
||||
}
|
||||
if (msgData?.dateType === 'month') {
|
||||
store.dispatch({type: "websocket/setCutChartMonth", payload:msgData.detData})
|
||||
store.dispatch({ type: "websocket/setCutChartMonth", payload: msgData.detData })
|
||||
return
|
||||
}
|
||||
if (msgData?.dateType === 'year') {
|
||||
store.dispatch({type: "websocket/setCutChartYear", payload:msgData.detData})
|
||||
store.dispatch({ type: "websocket/setCutChartYear", payload: msgData.detData })
|
||||
return
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user