From 430017879d665836af0fe17b0111f002edec538a Mon Sep 17 00:00:00 2001
From: songjun <leon0756@gmail.com>
Date: 星期五, 15 七月 2022 22:16:19 +0800
Subject: [PATCH] fix bug

---
 src/samples/sockteStomp.ts |   46 ++++++++++++++++++++++++++++------------------
 1 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/src/samples/sockteStomp.ts b/src/samples/sockteStomp.ts
index 1c8cd86..da7572d 100644
--- a/src/samples/sockteStomp.ts
+++ b/src/samples/sockteStomp.ts
@@ -1,7 +1,7 @@
 import Stomp from 'stompjs'
 import os from 'os'
 import { ipcRenderer } from 'electron'
-var stompClient: Stomp.Client | null=null
+let stompClient: Stomp.Client | null=null
 
 import { userInfoStore } from '@/stores/userInfo'
 import { patientInfoStore } from '@/stores/patient'
@@ -10,6 +10,7 @@
 const sound = require("sound-play");
 
 
+let sockteNum=0
 
 
 interface device{
@@ -160,8 +161,11 @@
         
     }
 }
+var isErrConnectBackCalled = false;
 const connectCallback=function(){
+    isErrConnectBackCalled = true
     const pcName= sockteStore().pcName
+    console.log("链接成功",stompClient,pcName)
     // 订阅患者信息服务
     if(stompClient!==null){
         // 订阅患者信息事件
@@ -172,38 +176,44 @@
         stompClient.send(`/app/workstation/config/set/${clientCode}/${pcName}`,{},JSON.stringify({"clientCode":clientCode,"machineName":pcName}))
         
     }
-    console.log("链接成功",stompClient,pcName)
     // 更新sockte链接状态
     sockteStore().setsockteIsLink(true)
     console.log(sockteStore().isLink)
-    console.log(devices)
-    if(devices!==undefined&&devices.length>0){
-        devices.forEach(de=>{
-            if(stompClient!==null){
-                stompClient.subscribe(`/queue/${clientCode}/${de.deviceName}/result`,callback)
-                stompClient.subscribe(`/queue/${clientCode}/${de.deviceName}/keepalive`,callbackState)
-                stompClient.send(`/app/device/request/${clientCode}/${de.deviceName}`, {}, JSON.stringify({"deviceNumber":de.deviceName}));
+    if(devices!==undefined &&devices!=null&&devices.length>0){
+        // 更新sockte链接状态
+        sockteStore().setsockteIsLink(true) 
+        console.log(sockteStore().isLink)
+        console.log(devices)
+        if(devices!==undefined&&devices!=null &&devices!=null &&devices.length>0){
+            devices.forEach(de=>{
+                if(stompClient!==null){
+                    stompClient.subscribe(`/queue/${clientCode}/${de.deviceName}/result`,callback)
+                    // stompClient.subscribe(`/queue/${clientCode}/${de.deviceName}/keepalive`,callbackState)
+                    stompClient.send(`/app/device/request/${clientCode}/${de.deviceName}`, {}, JSON.stringify({"deviceNumber":de.deviceName}));
 
-            } 
-        })
+                } 
+            })
+        }
     }
 }
+
 const error_callback=function(error:any){
     console.log('链接错误',error);
     setTimeout(()=>{
-        console.log('10秒之后重连')
-        console.log(devices,'设备列表')
+        console.log('60秒之后重连',sockteNum++) 
         const socket = new WebSocket('ws://hemobs.icoldchain.cn/broadcast')
-        stompClient = Stomp.over(socket)
-        stompClient.connect({}, connectCallback,error_callback)
-
-    },10000)
+        stompClient?.disconnect(()=>{
+            console.log("disconnected!");
+            stompClient = Stomp.over(socket)
+            stompClient.connect({}, connectCallback,error_callback)
+        },{})
+    },60000)
 }
 // 创建客户端链接
 const creatorClient=(devices2:any,clientCode2:any)=>{
     devices=devices2
     clientCode=clientCode2
-    console.log(devices,'设备列表')
+    console.log(devices,'设备列表','chong')
     const socket = new WebSocket('ws://hemobs.icoldchain.cn/broadcast')
     stompClient = Stomp.over(socket)
     stompClient.connect({}, connectCallback,error_callback)

--
Gitblit v1.8.0