|
|
@@ -13,8 +13,9 @@ let productId = null
|
|
|
let deviceId = null
|
|
|
let cbs = null
|
|
|
|
|
|
-let download = null
|
|
|
+let running = '未知'
|
|
|
let screenshotPic = null
|
|
|
+let download = null
|
|
|
let sensor = null
|
|
|
|
|
|
export function start (device) {
|
|
|
@@ -28,8 +29,9 @@ export function start (device) {
|
|
|
subscribe([
|
|
|
`${productId}/${deviceId}/online`,
|
|
|
`${productId}/${deviceId}/offline`,
|
|
|
- `${productId}/${deviceId}/resource/progress`,
|
|
|
- `${productId}/${deviceId}/screenshot/reply`
|
|
|
+ `${productId}/${deviceId}/status/reply`,
|
|
|
+ `${productId}/${deviceId}/screenshot/reply`,
|
|
|
+ `${productId}/${deviceId}/resource/progress`
|
|
|
], onMessage)
|
|
|
if (__SENSOR__) {
|
|
|
updateSensors(sensor = { running: true })
|
|
|
@@ -41,13 +43,15 @@ export function stop () {
|
|
|
unsubscribe([
|
|
|
`${productId}/${deviceId}/online`,
|
|
|
`${productId}/${deviceId}/offline`,
|
|
|
- `${productId}/${deviceId}/resource/progress`,
|
|
|
- `${productId}/${deviceId}/screenshot/reply`
|
|
|
+ `${productId}/${deviceId}/status/reply`,
|
|
|
+ `${productId}/${deviceId}/screenshot/reply`,
|
|
|
+ `${productId}/${deviceId}/resource/progress`
|
|
|
], onMessage)
|
|
|
productId = null
|
|
|
deviceId = null
|
|
|
- download = null
|
|
|
+ running = '未知'
|
|
|
screenshotPic = null
|
|
|
+ download = null
|
|
|
if (__SENSOR__) {
|
|
|
sensor.running = false
|
|
|
sensor = null
|
|
|
@@ -72,22 +76,21 @@ export function removeListener (type, cb) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export function screenshot () {
|
|
|
- return publish(`${productId}/${deviceId}/screenshot/ask`, JSON.stringify({ timestamp: Date.now() }))
|
|
|
-}
|
|
|
-
|
|
|
export function send (topic, message) {
|
|
|
return publish(`${productId}/${deviceId}${topic}`, JSON.stringify(message || { timestamp: Date.now() }))
|
|
|
}
|
|
|
|
|
|
function invoke (type, cb) {
|
|
|
switch (type) {
|
|
|
- case 'download':
|
|
|
- cb(download.files)
|
|
|
+ case 'running':
|
|
|
+ cb(running)
|
|
|
break
|
|
|
case 'screenshot':
|
|
|
cb(screenshotPic)
|
|
|
break
|
|
|
+ case 'download':
|
|
|
+ cb(download.files)
|
|
|
+ break
|
|
|
case 'temperature':
|
|
|
case 'smoke':
|
|
|
case 'flooding':
|
|
|
@@ -126,17 +129,48 @@ function onUpdate (invoke, message) {
|
|
|
case 'offline':
|
|
|
emit('online', false)
|
|
|
break
|
|
|
- case 'resource/progress':
|
|
|
- onUpdateFile(message)
|
|
|
+ case 'status/reply':
|
|
|
+ onUpdateStatus(message)
|
|
|
break
|
|
|
case 'screenshot/reply':
|
|
|
onUpdateScreenShot(message)
|
|
|
break
|
|
|
+ case 'resource/progress':
|
|
|
+ onUpdateFile(message)
|
|
|
+ break
|
|
|
default:
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+function onUpdateStatus (message) {
|
|
|
+ try {
|
|
|
+ message = JSON.parse(message)
|
|
|
+ switch (message.status) {
|
|
|
+ case 1:
|
|
|
+ running = '未播放节目,处于默认状态'
|
|
|
+ break
|
|
|
+ case 2:
|
|
|
+ running = '正在播放节目'
|
|
|
+ break
|
|
|
+ case 3:
|
|
|
+ running = '解析节目异常,请重新发布'
|
|
|
+ break
|
|
|
+ default:
|
|
|
+ running = '未知'
|
|
|
+ break
|
|
|
+ }
|
|
|
+ } catch {
|
|
|
+ running = '未知'
|
|
|
+ }
|
|
|
+ emit('running')
|
|
|
+}
|
|
|
+
|
|
|
+function onUpdateScreenShot (message) {
|
|
|
+ screenshotPic = `data:image/jpeg;base64,${message.replace(/\s/g, '')}`
|
|
|
+ emit('screenshot')
|
|
|
+}
|
|
|
+
|
|
|
function onUpdateFile (message) {
|
|
|
try {
|
|
|
const { ossUrl, complete, errorReason, progress, rate, success } = JSON.parse(message)
|
|
|
@@ -169,11 +203,6 @@ function onUpdateFile (message) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function onUpdateScreenShot (message) {
|
|
|
- screenshotPic = `data:image/jpeg;base64,${message.replace(/\s/g, '')}`
|
|
|
- emit('screenshot')
|
|
|
-}
|
|
|
-
|
|
|
function transformValue (type, value, unit) {
|
|
|
switch (type) {
|
|
|
case 'temperature':
|