优化长连接
This commit is contained in:
@@ -1,14 +1,28 @@
|
||||
import { defineStore } from "pinia";
|
||||
import ReconnectingWebSocket from "reconnecting-websocket";
|
||||
|
||||
export const useSocket = defineStore({
|
||||
id: "socket",
|
||||
state: () => ({
|
||||
online: false,
|
||||
online: false, // 是否在线
|
||||
ws: null,
|
||||
}),
|
||||
actions: {
|
||||
// 登录
|
||||
// 改变在线状态
|
||||
changeOnline(state) {
|
||||
this.online = state;
|
||||
},
|
||||
// 初始化
|
||||
init(wsUrl = import.meta.env.VITE_API_WSS) {
|
||||
if (this.ws == null) {
|
||||
this.ws = new ReconnectingWebSocket(
|
||||
`${wsUrl}/shopId=${store.userInfo.shopId}/clientId=${uuid.value}`,
|
||||
null,
|
||||
{
|
||||
reconnectInterval: 10000,
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user