|
@@ -21,17 +21,26 @@ export function useWebSocket() {
|
|
|
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: {
|
|
|
- type: 'hand',
|
|
|
- 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);
|
|
|
+ // }
|
|
|
+
|
|
|
+ let socketHand: any = null; //ws实例对象
|
|
|
+ socketHand = io(address + '/', {
|
|
|
+ transports: ['websocket', 'polling'],
|
|
|
+ query: {
|
|
|
+ type: 'hand',
|
|
|
+ Authorization: token ? myToken : ''
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
function handWs(callback: any) {
|
|
|
if (socketHand == null) {
|
|
@@ -153,10 +162,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 };
|