无人机及机场直播不稳定问题;多组件同时连接mqtt但是mqtt方法异步导致连接冲突一直重连问题修改

main
zhufu 2025-12-30 15:01:39 +08:00
parent a35729307d
commit dc728a4c0f
1 changed files with 17 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import { timestampToFormattedDate } from '@/utils/index';
const userStore = useUserStore();
const userInfo = userStore.getUserInfo;
let connectLock = false
const { createMessage } = useMessage();
const seizeClientId = 'mqtt_client_1581F8HGX254V00A0BUY_seize';
@ -55,6 +56,21 @@ const createConnection = (callback?) => {
// 连接mqtt的时候先用GetRedisUser查一下有没有
// 然后AddOrUpdateRedisUser更新或添加
// 控制的时候先查一下有没有锁定的用户GetLockedClients
if(connectLock){
if (callback) {
if(client && client.connected){
callback();
}else{
setTimeout(() => {
client.on('connect', () => {
callback();
});
}, 3000)
}
}
return
}
connectLock = true
try {
getRedisUser(userInfo.id).then((res) => {
console.log("getRedisUser",res);
@ -120,7 +136,7 @@ const destroyConnection = () => {
};
// 订阅事件
const clientSubscribe = (topic: string, options?: any) => {
if(!topic){
if(topic.includes('/null/')){
return
}
// if (!client || !client.connected) {