|
@@ -1,6 +1,7 @@
|
|
|
|
|
|
import { mqttUrl } from '@/settings'
|
|
import { mqttUrl } from '@/settings'
|
|
import mqtt from 'mqtt'
|
|
import mqtt from 'mqtt'
|
|
|
|
+import { mapGetters } from 'vuex'
|
|
export default {
|
|
export default {
|
|
destroyed() {
|
|
destroyed() {
|
|
if (this.client.connected) {
|
|
if (this.client.connected) {
|
|
@@ -13,6 +14,11 @@ export default {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ computed: {
|
|
|
|
+ ...mapGetters([
|
|
|
|
+ 'userData'
|
|
|
|
+ ])
|
|
|
|
+ },
|
|
methods: {
|
|
methods: {
|
|
initMqtt(
|
|
initMqtt(
|
|
params = {
|
|
params = {
|
|
@@ -34,19 +40,13 @@ export default {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
const client = mqtt.connect(mqttUrl, options)
|
|
const client = mqtt.connect(mqttUrl, options)
|
|
|
|
+ const subscribes = [`topic/iotplatform/update/all/${this.userData.ocId}`]
|
|
client.on('connect', function() {
|
|
client.on('connect', function() {
|
|
- client.subscribe('topic/goaf/waring/person', function(err) {
|
|
|
|
- if (!err) {
|
|
|
|
- client.publish('topic/goaf/waring/person', 'Hello mqtt')
|
|
|
|
- } else {
|
|
|
|
- client.publish('topic/goaf/waring/person', 'Hello mqtt err')
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- client.subscribe('topic/goaf/waring/sensor', function(err) {
|
|
|
|
|
|
+ client.subscribe(subscribes, function(err) {
|
|
if (!err) {
|
|
if (!err) {
|
|
- client.publish('topic/goaf/waring/sensor', 'Hello mqtt')
|
|
|
|
|
|
+ client.publish('topic/iotplatform/update/all', 'Hello mqtt')
|
|
} else {
|
|
} else {
|
|
- client.publish('topic/goaf/waring/sensor', 'Hello mqtt err')
|
|
|
|
|
|
+ client.publish('topic/iotplatform/update/all', 'Hello mqtt err')
|
|
}
|
|
}
|
|
})
|
|
})
|
|
})
|
|
})
|