|
|
@@ -13,15 +13,14 @@ import {
|
|
|
} from './constant'
|
|
|
import {
|
|
|
GET_POWER_STATUS,
|
|
|
- GET_RECEIVER_TOPOLOGY,
|
|
|
GET_RECEIVER_INFO,
|
|
|
parseCachePower,
|
|
|
getPowerStatusByMessage,
|
|
|
- getReceivingCardTopologyByMessage,
|
|
|
getReceivingCardStatusByMessage
|
|
|
} from './nova'
|
|
|
|
|
|
const TIMEOUT_MILLISECOND = 120000
|
|
|
+const EXPIRED_MILLISECOND = 300000
|
|
|
|
|
|
const deviceCache = new Map()
|
|
|
const cbMap = new Map()
|
|
|
@@ -106,14 +105,6 @@ export function startMonitor () {
|
|
|
...data.data
|
|
|
})
|
|
|
}
|
|
|
- } else if (message.function === GET_RECEIVER_TOPOLOGY) {
|
|
|
- const data = getReceivingCardTopologyByMessage(message)
|
|
|
- if (data.success) {
|
|
|
- emit(id, 'topology', {
|
|
|
- timestamp,
|
|
|
- ...data.data
|
|
|
- })
|
|
|
- }
|
|
|
} else {
|
|
|
injectMap.get(id)?.forEach(cb => {
|
|
|
cb(message)
|
|
|
@@ -143,13 +134,46 @@ function getCacheById (id) {
|
|
|
status: Status.LOADING,
|
|
|
receivers: []
|
|
|
},
|
|
|
- topology: null,
|
|
|
screen: null
|
|
|
})
|
|
|
}
|
|
|
return cache
|
|
|
}
|
|
|
|
|
|
+function getFreshCacheById (id) {
|
|
|
+ const cache = deviceCache.get(id)
|
|
|
+ if (cache) {
|
|
|
+ let update = false
|
|
|
+ if (cache[ThirdPartyDevice.MULTI_FUNCTION_CARD].status > Status.LOADING && (Date.now() - cache[ThirdPartyDevice.MULTI_FUNCTION_CARD].timestamp > EXPIRED_MILLISECOND)) {
|
|
|
+ cache[ThirdPartyDevice.MULTI_FUNCTION_CARD] = {
|
|
|
+ status: Status.LOADING,
|
|
|
+ switchStatus: Power.LOADING,
|
|
|
+ powers: []
|
|
|
+ }
|
|
|
+ update = true
|
|
|
+ }
|
|
|
+ if (cache.screen && (Date.now() - cache.screen.timestamp > EXPIRED_MILLISECOND)) {
|
|
|
+ cache.screen = null
|
|
|
+ update = true
|
|
|
+ }
|
|
|
+ if (update) {
|
|
|
+ cbMap.get(id)?.forEach(cb => {
|
|
|
+ cb(cache)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return cache
|
|
|
+ }
|
|
|
+ return getCacheById(id)
|
|
|
+}
|
|
|
+
|
|
|
+export function resetCacheById (id) {
|
|
|
+ console.log('monitor', id, '->', 'reset cache')
|
|
|
+ const cache = deviceCache.get(id)
|
|
|
+ if (cache) {
|
|
|
+ deviceCache.delete(id)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
function checkMultiCard (id, multiCard) {
|
|
|
switch (multiCard.status) {
|
|
|
case Status.LOADING:
|
|
|
@@ -212,8 +236,8 @@ export function addListener (id, cb) {
|
|
|
return
|
|
|
}
|
|
|
console.log('monitor add', id, '->', 'success')
|
|
|
+ const cache = getFreshCacheById(id)
|
|
|
cbSet.add(cb)
|
|
|
- const cache = getCacheById(id)
|
|
|
checkMultiCard(id, cache[ThirdPartyDevice.MULTI_FUNCTION_CARD])
|
|
|
cb(cache)
|
|
|
}
|
|
|
@@ -231,7 +255,6 @@ function doUnsubscribe () {
|
|
|
)
|
|
|
cbMap.delete(id)
|
|
|
injectMap.delete(id)
|
|
|
- deviceCache.delete(id)
|
|
|
})
|
|
|
client.unsubscribe(topics)
|
|
|
unsubscribeIds = new Set()
|