|
|
@@ -82,7 +82,8 @@ import {
|
|
|
authCode,
|
|
|
getRecordConfig,
|
|
|
addRecordConfig,
|
|
|
- updateRecordConfig
|
|
|
+ updateRecordConfig,
|
|
|
+ getDevice
|
|
|
} from '@/api/device'
|
|
|
import { GATEWAY } from '@/constant'
|
|
|
import playerMixin from '../player'
|
|
|
@@ -115,10 +116,19 @@ export default {
|
|
|
device: {
|
|
|
type: Object,
|
|
|
required: true
|
|
|
+ },
|
|
|
+ checkOnline: {
|
|
|
+ type: [Boolean, String],
|
|
|
+ default: false
|
|
|
+ },
|
|
|
+ useInitial: {
|
|
|
+ type: [Boolean, String],
|
|
|
+ default: false
|
|
|
}
|
|
|
},
|
|
|
data () {
|
|
|
return {
|
|
|
+ online: false,
|
|
|
floating: true,
|
|
|
qualities: [
|
|
|
{ value: 'fff', label: '标清' },
|
|
|
@@ -132,7 +142,7 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
- online () {
|
|
|
+ deviceOnline () {
|
|
|
return this.device.onlineStatus === 1
|
|
|
},
|
|
|
canPlay () {
|
|
|
@@ -140,14 +150,11 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
watch: {
|
|
|
- online (val) {
|
|
|
- if (val) {
|
|
|
- this.$nextTick(this.createPlayer)
|
|
|
- } else {
|
|
|
- this.hideQualityMenu()
|
|
|
- this.onVideoReset()
|
|
|
- this.destroyPlayer()
|
|
|
+ deviceOnline (val) {
|
|
|
+ if (this.checkOnline) {
|
|
|
+ return
|
|
|
}
|
|
|
+ this.updateOnlineStatus(val)
|
|
|
},
|
|
|
isFullscreen () {
|
|
|
this.onMouseMove()
|
|
|
@@ -155,14 +162,18 @@ export default {
|
|
|
},
|
|
|
created () {
|
|
|
this.$delayMoveTimer = -1
|
|
|
+ this.$checkTimer = -1
|
|
|
},
|
|
|
mounted () {
|
|
|
- if (this.online) {
|
|
|
+ if (this.checkOnline && !this.useInitial) {
|
|
|
this.createPlayer()
|
|
|
+ } else {
|
|
|
+ this.updateOnlineStatus(this.deviceOnline)
|
|
|
}
|
|
|
},
|
|
|
beforeDestroy () {
|
|
|
clearTimeout(this.$delayMoveTimer)
|
|
|
+ clearTimeout(this.$checkTimer)
|
|
|
this.hideQualityMenu()
|
|
|
},
|
|
|
methods: {
|
|
|
@@ -197,7 +208,7 @@ export default {
|
|
|
const key = Object.keys(Quality).find(key => Quality[key].frameRate === frameRate) || 'fff'
|
|
|
this.quality = this.qualities.find(({ value }) => value === key) || this.qualities[0]
|
|
|
this.recordConfig = data
|
|
|
- this.createPlayer()
|
|
|
+ this.onCreatePlayer()
|
|
|
} else {
|
|
|
this.setRecordConfig(this.qualities[0])
|
|
|
}
|
|
|
@@ -218,7 +229,8 @@ export default {
|
|
|
this.loadingQuality = false
|
|
|
this.quality = quality
|
|
|
this.recordConfig = data
|
|
|
- this.createPlayer()
|
|
|
+ this.releasePlayer()
|
|
|
+ this.onCreatePlayer()
|
|
|
},
|
|
|
() => {
|
|
|
this.onVideoDestroyByError()
|
|
|
@@ -249,22 +261,60 @@ export default {
|
|
|
},
|
|
|
getAuthCode () {
|
|
|
this.$playerInfo = null
|
|
|
- authCode(this.recordConfig.stream).then(
|
|
|
+ authCode(this.recordConfig.stream, { custom: true }).then(
|
|
|
({ data }) => {
|
|
|
this.$playerInfo = data
|
|
|
- this.createPlayer()
|
|
|
+ this.onCreatePlayer()
|
|
|
},
|
|
|
() => {
|
|
|
this.onVideoDestroyByError()
|
|
|
}
|
|
|
)
|
|
|
},
|
|
|
+ updateOnlineStatus (online) {
|
|
|
+ this.online = online
|
|
|
+ if (online) {
|
|
|
+ this.$nextTick(this.onCreatePlayer)
|
|
|
+ } else {
|
|
|
+ this.hideQualityMenu()
|
|
|
+ this.onVideoReset()
|
|
|
+ this.destroyPlayer()
|
|
|
+ if (this.checkOnline) {
|
|
|
+ this.checkOnlineStatus(5000)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
createPlayer () {
|
|
|
if (this.$timer === null) {
|
|
|
return
|
|
|
}
|
|
|
+ clearTimeout(this.$checkTimer)
|
|
|
this.loading = true
|
|
|
- clearTimeout(this.$timer)
|
|
|
+ if (this.checkOnline) {
|
|
|
+ getDevice(this.device.id, { custom: true }).then(
|
|
|
+ ({ data }) => {
|
|
|
+ if (this.$timer === null) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (data) {
|
|
|
+ this.updateOnlineStatus(data.onlineStatus === 1)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ () => {
|
|
|
+ if (this.$timer === null) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.checkOnlineStatus(2000)
|
|
|
+ }
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ this.onCreatePlayer()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onCreatePlayer () {
|
|
|
+ if (this.$timer === null) {
|
|
|
+ return
|
|
|
+ }
|
|
|
if (!this.recordConfig) {
|
|
|
this.getRecordConfig()
|
|
|
return
|
|
|
@@ -280,6 +330,10 @@ export default {
|
|
|
// }
|
|
|
// this.playUrl(`${GATEWAY}/live/${this.recordConfig.stream}.flv?vhost=${vhost}&authorization=${token}×tamp=${timestamp}&expire=${expire}`)
|
|
|
this.playUrl(`${GATEWAY}/live/${this.recordConfig.stream}.flv?vhost=__defaultVhost__`)
|
|
|
+ },
|
|
|
+ checkOnlineStatus (delay = 5000) {
|
|
|
+ clearTimeout(this.$checkTimer)
|
|
|
+ this.$checkTimer = setTimeout(this.createPlayer, delay + Math.random() * delay | 0)
|
|
|
}
|
|
|
}
|
|
|
}
|