|
@@ -1,10 +1,8 @@
|
|
|
import io from 'socket.io-client';
|
|
|
-import { ref, onMounted, onUnmounted } from 'vue';
|
|
|
+import { ref, onMounted, onUnmounted, onBeforeUnmount } from 'vue';
|
|
|
import useAppStore from '@/store/modules/app';
|
|
|
// import router from '@/router';
|
|
|
|
|
|
-
|
|
|
-
|
|
|
// let socketHand: any = null; //ws实例对象
|
|
|
// socketHand = io(address + '/', {
|
|
|
// transports: ['websocket', 'polling'],
|
|
@@ -14,7 +12,6 @@ import useAppStore from '@/store/modules/app';
|
|
|
// }
|
|
|
// });
|
|
|
|
|
|
-
|
|
|
export function useWebSocket() {
|
|
|
const address: any = import.meta.env.VITE_APP_BASE_API;
|
|
|
const token: any = localStorage.getItem('token');
|
|
@@ -80,7 +77,7 @@ export function useWebSocket() {
|
|
|
return false;
|
|
|
}
|
|
|
if (socketHand.connected) {
|
|
|
- callback = callback || function () { };
|
|
|
+ callback = callback || function () {};
|
|
|
socketHand.emit(type, data, callback);
|
|
|
}
|
|
|
}
|
|
@@ -94,7 +91,7 @@ export function useWebSocket() {
|
|
|
{
|
|
|
deviceid: deviceid ? deviceid : ''
|
|
|
},
|
|
|
- () => { }
|
|
|
+ () => {}
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -107,7 +104,7 @@ export function useWebSocket() {
|
|
|
{
|
|
|
data: data
|
|
|
},
|
|
|
- () => { }
|
|
|
+ () => {}
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -121,7 +118,7 @@ export function useWebSocket() {
|
|
|
hctrl_name: `handcontroller_${data}`,
|
|
|
cmd: 'open_handcontroller'
|
|
|
},
|
|
|
- () => { }
|
|
|
+ () => {}
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -135,7 +132,7 @@ export function useWebSocket() {
|
|
|
hctrl_name: `handcontroller_${data}`,
|
|
|
cmd: 'get_handcontroller_state'
|
|
|
},
|
|
|
- () => { }
|
|
|
+ () => {}
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -149,11 +146,11 @@ export function useWebSocket() {
|
|
|
hctrl_name: `handcontroller_${data}`,
|
|
|
cmd: 'terminate_handcontroller'
|
|
|
},
|
|
|
- () => { }
|
|
|
+ () => {}
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- onUnmounted(() => {
|
|
|
+ onBeforeUnmount(() => {
|
|
|
// if (socketHand) {
|
|
|
// // if(['/gesture'].includes(router.currentRoute.value.path)){
|
|
|
// // socketHand.close();
|
|
@@ -162,10 +159,10 @@ export function useWebSocket() {
|
|
|
// socketHand = null;
|
|
|
// }
|
|
|
// getClearTimer();
|
|
|
- // if (socketHand) {
|
|
|
- // socketHand.close();
|
|
|
- // socketHand = null;
|
|
|
- // }
|
|
|
+ if (socketHand) {
|
|
|
+ socketHand.close();
|
|
|
+ socketHand = null;
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
return { handWs, sendMessage, startLogin, startDevice, startHand, stateHand, closeHand };
|