|
@@ -1,35 +1,37 @@
|
|
|
import io from 'socket.io-client';
|
|
|
import { ref, onMounted, onUnmounted } from 'vue';
|
|
|
import useAppStore from '@/store/modules/app';
|
|
|
-import router from '@/router';
|
|
|
+// import router from '@/router';
|
|
|
|
|
|
-const address: any = import.meta.env.VITE_APP_BASE_API;
|
|
|
-const token: any = localStorage.getItem('token');
|
|
|
-const deviceid: any = localStorage.getItem('deviceid');
|
|
|
-const myToken: any = 'JWT ' + token;
|
|
|
|
|
|
-let socketHand: any = null; //ws实例对象
|
|
|
-socketHand = io(address + '/', {
|
|
|
- transports: ['websocket', 'polling'],
|
|
|
- query: {
|
|
|
- Authorization: token ? myToken : ''
|
|
|
- }
|
|
|
-});
|
|
|
|
|
|
+// let socketHand: any = null; //ws实例对象
|
|
|
+// socketHand = io(address + '/', {
|
|
|
+// transports: ['websocket', 'polling'],
|
|
|
+// query: {
|
|
|
+// type: 'hand',
|
|
|
+// Authorization: token ? myToken : ''
|
|
|
+// }
|
|
|
+// });
|
|
|
|
|
|
-export function useWebSocket() {
|
|
|
|
|
|
+export function useWebSocket() {
|
|
|
+ const address: any = import.meta.env.VITE_APP_BASE_API;
|
|
|
+ const token: any = localStorage.getItem('token');
|
|
|
+ const deviceid: any = localStorage.getItem('deviceid');
|
|
|
+ const myToken: any = 'JWT ' + token;
|
|
|
|
|
|
- // let socketHand: any = useAppStore().getSocketHand() || null; //ws实例对象
|
|
|
- // if (socketHand == null) {
|
|
|
- // socketHand = io(address + '/', {
|
|
|
- // transports: ['websocket', 'polling'],
|
|
|
- // query: {
|
|
|
- // Authorization: token ? myToken : '',
|
|
|
- // }
|
|
|
- // });
|
|
|
- // useAppStore().setSocketHand(socketHand);
|
|
|
- // }
|
|
|
+ let socketHand: any = useAppStore().getSocketHand() || null; //ws实例对象
|
|
|
+ if (socketHand == null) {
|
|
|
+ socketHand = io(address + '/', {
|
|
|
+ transports: ['websocket', 'polling'],
|
|
|
+ query: {
|
|
|
+ type: 'hand',
|
|
|
+ Authorization: token ? myToken : '',
|
|
|
+ }
|
|
|
+ });
|
|
|
+ useAppStore().setSocketHand(socketHand);
|
|
|
+ }
|
|
|
|
|
|
function handWs(callback: any) {
|
|
|
if (socketHand == null) {
|
|
@@ -69,7 +71,7 @@ export function useWebSocket() {
|
|
|
return false;
|
|
|
}
|
|
|
if (socketHand.connected) {
|
|
|
- callback = callback || function () {};
|
|
|
+ callback = callback || function () { };
|
|
|
socketHand.emit(type, data, callback);
|
|
|
}
|
|
|
}
|
|
@@ -83,7 +85,7 @@ export function useWebSocket() {
|
|
|
{
|
|
|
deviceid: deviceid ? deviceid : ''
|
|
|
},
|
|
|
- () => {}
|
|
|
+ () => { }
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -96,7 +98,7 @@ export function useWebSocket() {
|
|
|
{
|
|
|
data: data
|
|
|
},
|
|
|
- () => {}
|
|
|
+ () => { }
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -110,7 +112,7 @@ export function useWebSocket() {
|
|
|
hctrl_name: `handcontroller_${data}`,
|
|
|
cmd: 'open_handcontroller'
|
|
|
},
|
|
|
- () => {}
|
|
|
+ () => { }
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -124,7 +126,7 @@ export function useWebSocket() {
|
|
|
hctrl_name: `handcontroller_${data}`,
|
|
|
cmd: 'get_handcontroller_state'
|
|
|
},
|
|
|
- () => {}
|
|
|
+ () => { }
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -138,7 +140,7 @@ export function useWebSocket() {
|
|
|
hctrl_name: `handcontroller_${data}`,
|
|
|
cmd: 'terminate_handcontroller'
|
|
|
},
|
|
|
- () => {}
|
|
|
+ () => { }
|
|
|
);
|
|
|
}
|
|
|
|