Browse Source

mqttclient getTokenInfo mqtt增加监听频道 发送token多端

master
DIAMOND 11 months ago
parent
commit
a1413eaaeb
  1. 8
      src/utils/mqtt/mqttclient.js

8
src/utils/mqtt/mqttclient.js

@ -10,6 +10,7 @@
// const mqtt = require('mqtt'); // const mqtt = require('mqtt');
import mqtt from 'mqtt'; import mqtt from 'mqtt';
import $mitt from '@/utils/earthMap/mitt'; import $mitt from '@/utils/earthMap/mitt';
import { useUserStore } from '/@/store/modules/user';
const host = '192.168.1.200'; // 连接主机 const host = '192.168.1.200'; // 连接主机
const port = import.meta.env.VUE_APP_MQTT_PORT || 8083; // 连接端口 const port = import.meta.env.VUE_APP_MQTT_PORT || 8083; // 连接端口
@ -23,7 +24,7 @@ const options = {
password: 'public', // 密码 password: 'public', // 密码
}; };
const topics = '/server/radar,/track/deviceInfo'; // 订阅频道 const topics = '/server/radar,/track/deviceInfo,/getTokenInfo/'; // 订阅频道
const topicList = topics.split(','); // 订阅事件列表 const topicList = topics.split(','); // 订阅事件列表
/** /**
* /server/radar * /server/radar
@ -63,6 +64,11 @@ export default class MqttUnit {
if (topic.startsWith('/track/')) { if (topic.startsWith('/track/')) {
$mitt.emit('tailAfterRtsp', dataString); $mitt.emit('tailAfterRtsp', dataString);
} }
if (topic.startsWith('/getTokenInfo/')) {
const userStore = useUserStore();
// console.log("getTokenInfo数据");
this.client.publish('/tokenInfo/', userStore.token);
}
}); });
// 将client对象挂载window全局对象中 // 将client对象挂载window全局对象中
window.mqttClient = this.client; window.mqttClient = this.client;

Loading…
Cancel
Save