|
|
@@ -22,8 +22,8 @@ import {
|
|
|
getReceivingCardStatusByMessage
|
|
|
} from './nova.js'
|
|
|
|
|
|
-export const TIMEOUT_MILLISECOND = 120000
|
|
|
-export const EXPIRED_MILLISECOND = 300000
|
|
|
+export const TIMEOUT_MILLISECOND = 300000
|
|
|
+export const EXPIRED_MILLISECOND = 600000
|
|
|
|
|
|
const deviceCache = new Map()
|
|
|
const cbMap = new Map()
|
|
|
@@ -169,6 +169,13 @@ function getFreshCacheById (id) {
|
|
|
}
|
|
|
update = true
|
|
|
}
|
|
|
+ if (cache[ThirdPartyDevice.RECEIVING_CARD].status > Status.LOADING && (Date.now() - cache[ThirdPartyDevice.RECEIVING_CARD].timestamp > EXPIRED_MILLISECOND)) {
|
|
|
+ cache[ThirdPartyDevice.MULTI_FUNCTION_CARD] = {
|
|
|
+ status: Status.LOADING,
|
|
|
+ receivers: []
|
|
|
+ }
|
|
|
+ update = true
|
|
|
+ }
|
|
|
if (cache.screen && (Date.now() - cache.screen.timestamp > EXPIRED_MILLISECOND)) {
|
|
|
cache.screen = null
|
|
|
update = true
|
|
|
@@ -191,15 +198,16 @@ export function resetCacheById (id) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function checkMultiCard (id, multiCard) {
|
|
|
- switch (multiCard.status) {
|
|
|
+function checkStatus (id, type, timeout = TIMEOUT_MILLISECOND) {
|
|
|
+ const data = getCacheById(id)[type]
|
|
|
+ switch (data.status) {
|
|
|
case Status.LOADING:
|
|
|
- console.log('monitor', id, '->', 'add task')
|
|
|
- addTask(id)
|
|
|
+ console.log('monitor', id, '->', 'add task', type)
|
|
|
+ addTask(id, type)
|
|
|
break
|
|
|
case Status.OK:
|
|
|
- if (Date.now() - multiCard.timestamp > TIMEOUT_MILLISECOND) {
|
|
|
- multiCard.status = Status.WARNING
|
|
|
+ if (timeout && Date.now() - data.timestamp > timeout) {
|
|
|
+ data.status = Status.WARNING
|
|
|
}
|
|
|
break
|
|
|
default:
|
|
|
@@ -255,7 +263,8 @@ export function addListener (id, cb) {
|
|
|
console.log('monitor add', id, '->', 'success')
|
|
|
const cache = getFreshCacheById(id)
|
|
|
cbSet.add(cb)
|
|
|
- checkMultiCard(id, cache[ThirdPartyDevice.MULTI_FUNCTION_CARD])
|
|
|
+ checkStatus(id, ThirdPartyDevice.MULTI_FUNCTION_CARD)
|
|
|
+ checkStatus(id, ThirdPartyDevice.RECEIVING_CARD)
|
|
|
cb(cache)
|
|
|
}
|
|
|
|
|
|
@@ -335,7 +344,14 @@ let queue = new Set()
|
|
|
let fetching = false
|
|
|
let started = false
|
|
|
|
|
|
-function addTask (id) {
|
|
|
+function addTask (id, type) {
|
|
|
+ // 暂只支持多功能卡
|
|
|
+ switch (type) {
|
|
|
+ case ThirdPartyDevice.MULTI_FUNCTION_CARD:
|
|
|
+ break
|
|
|
+ default:
|
|
|
+ return
|
|
|
+ }
|
|
|
if (fetching) {
|
|
|
if (queue.has(id)) {
|
|
|
console.log('task exsit', id)
|
|
|
@@ -442,16 +458,26 @@ function startTask () {
|
|
|
}
|
|
|
|
|
|
export function getReceivingCardStatusFromServer (id) {
|
|
|
- getReceivingCardStatusReport(id, { background: true, custom: true }).then(res => {
|
|
|
- if (res.data && getCacheById(id)[ThirdPartyDevice.RECEIVING_CARD].status !== Status.LOADING) {
|
|
|
- const message = JSON.parse(res.data)
|
|
|
- const data = getReceivingCardStatusByMessage(message)
|
|
|
- if (data.success) {
|
|
|
- emit(id, ThirdPartyDevice.RECEIVING_CARD, {
|
|
|
- timestamp: message.timestamp,
|
|
|
- ...data.data
|
|
|
- })
|
|
|
+ getReceivingCardStatusReport(id, { custom: true }).then(res => {
|
|
|
+ if (!res.data) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const message = JSON.parse(res.data)
|
|
|
+ const { timestamp } = getCacheById(id)[ThirdPartyDevice.RECEIVING_CARD]
|
|
|
+ console.log(timestamp, message.timestamp, message.timestamp <= timestamp)
|
|
|
+ if (timestamp && message.timestamp <= timestamp) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const data = getReceivingCardStatusByMessage(message)
|
|
|
+ if (data.success) {
|
|
|
+ const info = {
|
|
|
+ timestamp: message.timestamp,
|
|
|
+ ...data.data
|
|
|
+ }
|
|
|
+ if (Date.now() - message.timestamp > TIMEOUT_MILLISECOND) {
|
|
|
+ info.status = Status.WARNING
|
|
|
}
|
|
|
+ emit(id, ThirdPartyDevice.RECEIVING_CARD, info)
|
|
|
}
|
|
|
})
|
|
|
}
|