| | |
| | | |
| | | // 心跳 |
| | | const heartBeatSeq = ref(0) |
| | | const state = reactive({ |
| | | heartState: new Map<string, { |
| | | pingInterval: any; |
| | | }>(), |
| | | }) |
| | | const state = reactive({heartState: new Map()}) |
| | | |
| | | // 监听云控控制权 |
| | | watch(() => deviceTopicInfo, (val, oldVal) => { |
| | | if (val.subTopic !== '') { |
| | | // 1.订阅topic |
| | | subscribeMqtt(deviceTopicInfo.subTopic) |
| | | // 2.发心跳 |
| | | publishDrcPing(deviceTopicInfo.sn) |
| | | } else { |
| | | clearInterval(state.heartState.get(deviceTopicInfo.sn)?.pingInterval) |
| | | const heartState = state.heartState.get(deviceTopicInfo.sn) |
| | | if (heartState && heartState.pingInterval) { |
| | | clearInterval(heartState.pingInterval) |
| | | } |
| | | state.heartState.delete(deviceTopicInfo.sn) |
| | | heartBeatSeq.value = 0 |
| | | } |
| | | }, { immediate: true, deep: true }) |
| | | }, { immediate: true, deep: true }) |
| | | |
| | | function publishDrcPing (sn: string) { |
| | | const body = { |