Merge branch 'main' of http://123.132.248.154:10000/gitY/LinYeFangHuo
commit
63c0f3b819
|
|
@ -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);
|
||||
|
|
@ -84,9 +100,9 @@ const createConnection = (callback?) => {
|
|||
// 重连回调
|
||||
client.on('reconnect', () => {
|
||||
console.log('MQTT正在重连...');
|
||||
if(!client || !client.connected){
|
||||
client = mqtt.connect(connectUrl, options);
|
||||
}
|
||||
// if(!client || !client.connected){
|
||||
// client = mqtt.connect(connectUrl, options);
|
||||
// }
|
||||
});
|
||||
// 接收到消息
|
||||
client.on("messasge",()=>{
|
||||
|
|
@ -120,7 +136,7 @@ const destroyConnection = () => {
|
|||
};
|
||||
// 订阅事件
|
||||
const clientSubscribe = (topic: string, options?: any) => {
|
||||
if(!topic){
|
||||
if(topic.includes('/null/')){
|
||||
return
|
||||
}
|
||||
// if (!client || !client.connected) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue